Skip to content

Commit

Permalink
refactor(components): ♻️ update slider, badge, circular & linear prog…
Browse files Browse the repository at this point in the history
…ress (#241)
  • Loading branch information
navin-moorthy authored Dec 28, 2021
1 parent 285472d commit b15bb44
Show file tree
Hide file tree
Showing 51 changed files with 173 additions and 93 deletions.
2 changes: 2 additions & 0 deletions preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ module.exports = {
cxs: ["13px", "115%"],
sm: ["14px", "115%"],
base: ["16px", "115%"],
lg: ["18px", "115%"],
xl: ["20px", "115%"],
"paragraph-cxs": ["13px", "150%"],
"paragraph-sm": ["14px", "150%"],
"2base": ["32px", "115%"],
Expand Down
45 changes: 35 additions & 10 deletions src/badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createComponent, createHook } from "reakit-system";

import { BoxHTMLProps, BoxOptions, useBox } from "../box";
import { useTheme } from "../theme";
import { cx } from "../utils";
import { cx, RenderPropType, withIconA11y } from "../utils";

import { BADGE_KEYS } from "./__keys";

Expand All @@ -12,7 +12,7 @@ export type BadgeOptions = BoxOptions & {
*
* @default md
*/
size?: keyof Renderlesskit.GetThemeValue<"badge", "size">;
size?: keyof Renderlesskit.GetThemeValue<"badge", "size", "common">;

/**
* How the badge should look?
Expand All @@ -27,9 +27,14 @@ export type BadgeOptions = BoxOptions & {
* @default default
*/
themeColor?: keyof Renderlesskit.GetThemeValue<"badge", "variant", "solid">;

/**
* If added, the tag will show an icon before the tag's text.
*/
prefix?: RenderPropType;
};

export type BadgeHTMLProps = BoxHTMLProps;
export type BadgeHTMLProps = Omit<BoxHTMLProps, "prefix">;

export type BadgeProps = BadgeOptions & BadgeHTMLProps;

Expand All @@ -50,18 +55,38 @@ export const useBadge = createHook<BadgeOptions, BadgeHTMLProps>({
},

useProps(options, htmlProps) {
const { size = "md", variant = "solid", themeColor = "default" } = options;
const { className: htmlClassName, ...restHtmlProps } = htmlProps;
const {
size = "md",
variant = "solid",
themeColor = "default",
prefix,
} = options;
const {
className: htmlClassName,
children: htmlChildren,
...restHtmlProps
} = htmlProps;

const badge = useTheme("badge");
const theme = useTheme("badge");
const className = cx(
badge.base,
badge.size[size],
badge.variant[variant][themeColor],
theme.base,
theme.size.common[size],
theme.variant[variant][themeColor],
htmlClassName,
);

return { className, ...restHtmlProps };
const prefixStyles = cx(theme.size.prefix[size]);

const children = (
<>
{prefix ? (
<>{withIconA11y(prefix, { className: prefixStyles })}</>
) : null}
<span>{htmlChildren}</span>
</>
);

return { className, children, ...restHtmlProps };
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/badge/__keys.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Automatically generated
export const BADGE_KEYS = ["size", "variant", "themeColor"] as const;
export const BADGE_KEYS = ["size", "variant", "themeColor", "prefix"] as const;
4 changes: 3 additions & 1 deletion src/badge/__tests__/__snapshots__/Badge.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ exports[`<Badge /> should render properly 1`] = `
<div
class="inline-flex items-center justify-center relative whitespace-nowrap align-middle transition-all px-1.5 py-[3px] rounded-2xl text-xs font-medium bg-gray-800 text-white"
>
Hello world
<span>
Hello world
</span>
</div>
</DocumentFragment>
`;
10 changes: 10 additions & 0 deletions src/badge/stories/BadgeBasic.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentMeta, ComponentStoryObj } from "@storybook/react";

import { createControls, createPreviewTabs } from "../../../.storybook/utils";
import { SlotIcon } from "../..";

import js from "./templates/BadgeBasicJsx";
import ts from "./templates/BadgeBasicTsx";
Expand Down Expand Up @@ -66,3 +67,12 @@ export const Danger: Story = {
...Default,
args: { ...Default.args, themeColor: "danger" },
};

export const Prefix: Story = {
args: {
size: "md",
variant: "solid",
themeColor: "default",
prefix: <SlotIcon />,
},
};
4 changes: 4 additions & 0 deletions src/badge/stories/BadgeStack.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ComponentMeta, ComponentStoryObj } from "@storybook/react";

import { createControls, createPreviewTabs } from "../../../.storybook/utils";
import { SlotIcon } from "../..";

import js from "./templates/BadgeStackJsx";
import ts from "./templates/BadgeStackTsx";
Expand Down Expand Up @@ -30,3 +31,6 @@ export default {
} as Meta;

export const Default: Story = {};
export const Prefix: Story = {
args: { prefix: <SlotIcon /> },
};
10 changes: 5 additions & 5 deletions src/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export type ButtonOptions = BoxOptions &
*
* @default md
*/
size?: keyof Renderlesskit.GetThemeValue<"button", "size", "default">;
size?: keyof Renderlesskit.GetThemeValue<"button", "size", "common">;

/**
* How the button should look?
*
* @default solid
*/
variant?: keyof Renderlesskit.GetThemeValue<"button", "variant", "default">;
variant?: keyof Renderlesskit.GetThemeValue<"button", "variant", "common">;

/**
* If added, the button will only show an icon ignoring other childrens.
Expand Down Expand Up @@ -110,15 +110,15 @@ export const useButton = createHook<ButtonOptions, ButtonHTMLProps>({

const button = useTheme("button");
const className = cx(
button.base.normal,
button.base.common,
groupcontext?.collapsed ? "" : button.base.notCollapsed,
!iconOnly
? button.size.default[size]
? button.size.common[size]
: tcm(
button.size.iconOnly.base[size],
button.size.iconOnly.spinner[size],
),
button.variant.default[variant],
button.variant.common[variant],
button.variant.hover[variant],
button.variant.active[variant],
button.variant.focus[variant],
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox-group/CheckboxGroupWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useCheckboxGroupContextWrapper = createHook<

const theme = useTheme("checkbox");
const className = cx(
theme.group[stack].base,
theme.group[stack].common,
theme.group[stack].size[size],
htmlClassName,
);
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox-group/CheckboxShowMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CheckboxShowMore: React.FC<CheckboxShowMoreProps> = props => {

const theme = useTheme("checkbox");
const buttonClassName = cx(
theme.group.showMore.button.base[stack],
theme.group.showMore.button.common[stack],
hasExpandStarted ? "" : theme.group.showMore.button.expanded[stack],
);
const contentClassName = cx(theme.group.showMore.content[stack]);
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/CheckboxDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useCheckboxDescription = createHook<

const theme = useTheme("checkbox");
const className = cx(
theme.description.base,
theme.description.common,
theme.description.size[size],
htmlClassName,
);
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/CheckboxIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const useCheckboxIcon = createHook<

const theme = useTheme("checkbox");
const className = cx(
theme.icon.base,
theme.icon.common,
theme.icon.size[size],
isUnchecked
? cx(
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/CheckboxLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useCheckboxLabel = createHook<

const theme = useTheme("checkbox");
const className = cx(
theme.label.base,
theme.label.common,
label && !description ? theme.label.size[size] : "",
label && !description ? (disabled ? "" : theme.label.only) : "",
disabled ? theme.label.disabled : "",
Expand Down
6 changes: 5 additions & 1 deletion src/checkbox/CheckboxText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export const useCheckboxText = createHook<
const { className: htmlClassName, ...restHtmlProps } = htmlProps;

const theme = useTheme("checkbox");
const className = cx(theme.text.base, theme.text.size[size], htmlClassName);
const className = cx(
theme.text.common,
theme.text.size[size],
htmlClassName,
);

return { className, ...restHtmlProps };
},
Expand Down
2 changes: 1 addition & 1 deletion src/checkbox/stories/CheckboxControlled.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function capitalizeFirstLetter(string: string) {

const RadioComponent: React.FC<RadioGroupProps> = props => {
return (
<RadioGroup aria-label="checkbox state" {...props}>
<RadioGroup aria-label="checkbox state" className="space-x-2" {...props}>
<Radio value="checked" label="Checked" />
<Radio value="unchecked" label="Unchecked" />
<Radio value="indeterminate" label="Indeterminate" />
Expand Down
4 changes: 2 additions & 2 deletions src/circular-progress/CircularProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const useCircularProgressBar = createHook<

const theme = useTheme("circularProgress");
const className = cx(
theme.bar.base,
theme.bar.common,
isIndeterminate ? theme.bar.indeterminate : "",
htmlClassName,
);
Expand All @@ -45,7 +45,7 @@ export const useCircularProgressBar = createHook<
viewBox: "0 0 100 100",
cx: 50,
cy: 50,
r: 42,
r: 44,
fill: "transparent",
stroke: "currentColor",
strokeWidth: hint ? "5px" : "15px",
Expand Down
2 changes: 1 addition & 1 deletion src/circular-progress/CircularProgressBarWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useCircularProgressBarWrapper = createHook<
const className = cx(
hint
? theme.barWrapper.hint.size[size]
: theme.barWrapper.base.size[size],
: theme.barWrapper.common.size[size],
isIndeterminate ? theme.barWrapper.indeterminate : "",
htmlClassName,
);
Expand Down
6 changes: 5 additions & 1 deletion src/circular-progress/CircularProgressHint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export const useCircularProgressHint = createHook<
const { className: htmlClassName, ...restHtmlProps } = htmlProps;

const theme = useTheme("circularProgress");
const className = cx(theme.hint.base, theme.hint.size[size], htmlClassName);
const className = cx(
theme.hint.common,
theme.hint.size[size],
htmlClassName,
);

return { className, ...restHtmlProps };
},
Expand Down
2 changes: 1 addition & 1 deletion src/circular-progress/CircularProgressState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type CircularProgressState = RenderlesskitProgressState & {
size: keyof Renderlesskit.GetThemeValue<
"circularProgress",
"barWrapper",
"base",
"common",
"size"
>;

Expand Down
2 changes: 1 addition & 1 deletion src/circular-progress/CircularProgressTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useCircularProgressTrack = createHook<
viewBox: "0 0 100 100",
cx: 50,
cy: 50,
r: 42,
r: 44,
fill: "transparent",
stroke: "currentColor",
strokeWidth: hint ? "5px" : "15px",
Expand Down
2 changes: 1 addition & 1 deletion src/progress/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const useProgressBar = createHook<

const progress = useTheme("progress");
const className = cx(
progress.bar.base,
progress.bar.common,
isIndeterminate ? progress.bar.indeterminate : "",
htmlClassName,
);
Expand Down
6 changes: 5 additions & 1 deletion src/progress/ProgressHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export const useProgressHint = createHook<
const { className: htmlClassName, ...restHtmlProps } = htmlProps;

const theme = useTheme("progress");
const className = cx(theme.hint.base, theme.hint.size[size], htmlClassName);
const className = cx(
theme.hint.common,
theme.hint.size[size],
htmlClassName,
);

return { className, ...restHtmlProps };
},
Expand Down
2 changes: 1 addition & 1 deletion src/progress/ProgressLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useProgressLabel = createHook<

const theme = useTheme("progress");
const className = cx(
theme.label.base,
theme.label.common,
theme.label.size[size],
htmlClassName,
);
Expand Down
2 changes: 1 addition & 1 deletion src/progress/ProgressTrack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useProgressTrack = createHook<

const theme = useTheme("progress");
const className = cx(
theme.track.base,
theme.track.common,
theme.track.size[size],
htmlClassName,
);
Expand Down
2 changes: 1 addition & 1 deletion src/radio-group/RadioGroupWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useRadioGroupWrapper = createHook<

const theme = useTheme("radio");
const className = cx(
theme.group[stack].base,
theme.group[stack].common,
theme.group[stack].size[size],
htmlClassName,
);
Expand Down
2 changes: 1 addition & 1 deletion src/radio-group/RadioShowMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const RadioShowMore: React.FC<RadioShowMoreProps> = props => {
const [hasExpandStarted, setHasExpandStarted] = React.useState(false);

const theme = useTheme("radio");
const buttonClassName = cx(theme.group.showMore.button.base[stack]);
const buttonClassName = cx(theme.group.showMore.button.common[stack]);
const contentClassName = cx(
theme.group.showMore.content[stack],
hasExpandStarted ? "" : theme.group.showMore.button.expanded[stack],
Expand Down
2 changes: 1 addition & 1 deletion src/radio/RadioDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useRadioDescription = createHook<

const theme = useTheme("radio");
const className = cx(
theme.description.base,
theme.description.common,
theme.description.size[size],
htmlClassName,
);
Expand Down
2 changes: 1 addition & 1 deletion src/radio/RadioIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useRadioIcon = createHook<RadioIconOptions, RadioIconHTMLProps>({

const theme = useTheme("radio");
const className = cx(
theme.icon.base,
theme.icon.common,
description ? theme.icon.description : "",
theme.icon.size[size],
isChecked
Expand Down
2 changes: 1 addition & 1 deletion src/radio/RadioLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useRadioLabel = createHook<RadioLabelOptions, RadioLabelHTMLProps>(

const theme = useTheme("radio");
const className = cx(
theme.label.base,
theme.label.common,
label && !description ? theme.label.size[size] : "",
label && !description ? (disabled ? "" : theme.label.only) : "",
disabled ? theme.label.disabled : "",
Expand Down
6 changes: 5 additions & 1 deletion src/radio/RadioText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ export const useRadioText = createHook<RadioTextOptions, RadioTextHTMLProps>({
const { className: htmlClassName, ...restHtmlProps } = htmlProps;

const theme = useTheme("radio");
const className = cx(theme.text.base, theme.text.size[size], htmlClassName);
const className = cx(
theme.text.common,
theme.text.size[size],
htmlClassName,
);

return { className, ...restHtmlProps };
},
Expand Down
Loading

1 comment on commit b15bb44

@vercel
Copy link

@vercel vercel bot commented on b15bb44 Dec 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.