Skip to content

Commit

Permalink
feat(Button): adding support for radius prop (#813)
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Dec 28, 2024
1 parent 29ca970 commit 6a0719e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
14 changes: 14 additions & 0 deletions packages/api/src/stories/Components/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ export const Truncate: Story = {
);
},
};

export const Square: Story = {
...commonControlsSetup,
args: { radius: "small" },
render: (args) => (
<div className="flex flex-wrap gap-2">
<Button {...args}>1</Button>
<Button {...args}>2</Button>
<Button {...args}>3</Button>
<Button {...args}>...</Button>
<Button {...args}>101</Button>
</div>
),
};
2 changes: 2 additions & 0 deletions packages/ui-button/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonTypes.Props>(
spacing,
variant = "primary",
noTruncate = false,
radius = "large",

...otherProps
},
Expand All @@ -37,6 +38,7 @@ export const Button = React.forwardRef<HTMLButtonElement, ButtonTypes.Props>(
spacing,
variant,
noTruncate,
radius,
});

return (
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-button/src/components/Button/ButtonIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const ButtonIcon = React.forwardRef<
spacing,
noBackground = false,
align = "center",
radius = "large",

...otherProps
},
Expand All @@ -48,6 +49,7 @@ export const ButtonIcon = React.forwardRef<
spacing,
noBackground,
align,
radius,
});
const iconClass = clsx({
"text-copy-accent-dark": mode === "light" && !raw,
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-button/src/components/Button/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ButtonLink = React.forwardRef<
noTruncate = false,
noNewWindowIcon = false,
spacing,
radius = "large",

...otherProps
},
Expand All @@ -39,6 +40,7 @@ export const ButtonLink = React.forwardRef<
noBorder,
spacing,
noTruncate,
radius,
});

const newWindow = target === "_blank";
Expand Down
33 changes: 28 additions & 5 deletions packages/ui-button/src/components/Button/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type getButtonClassesProps = {
noBackground?: boolean;
noTruncate?: boolean;
variant?: "primary" | "secondary" | "danger";
radius?: "small" | "medium" | "large";
} & SpacingTypes.Props;

const getButtonSizesClasses = ({
Expand Down Expand Up @@ -83,18 +84,27 @@ const getButtonBaseClasses = ({
noBackground,
noTruncate,
variant,
radius,
}: {
mode: "dark" | "light" | "system" | "alt-system";
variant: "primary" | "secondary" | "danger";
noBackground?: boolean;
noTruncate?: boolean;
radius?: "small" | "medium" | "large";
}) => {
if (noBackground) {
return "not-prose rounded-full";
return clsx("not-prose", {
"rounded-full": radius === "large",
"rounded-md": radius === "medium",
"rounded-sm": radius === "small",
});
}

if (variant === "primary") {
return clsx("not-prose rounded-full", {
return clsx("not-prose", {
"rounded-full": radius === "large",
"rounded-md": radius === "medium",
"rounded-sm": radius === "small",
truncate: !noTruncate,
"bg-action-dark text-copy-light": mode === "dark",
"bg-action-light text-copy-lighter": mode === "light",
Expand All @@ -105,7 +115,10 @@ const getButtonBaseClasses = ({
});
}
if (variant === "secondary") {
return clsx("not-prose rounded-full", {
return clsx("not-prose", {
"rounded-full": radius === "large",
"rounded-md": radius === "medium",
"rounded-sm": radius === "small",
truncate: !noTruncate,
"bg-action-dark text-copy-light": mode === "light",
"bg-action-light text-copy-lighter": mode === "dark",
Expand All @@ -116,7 +129,10 @@ const getButtonBaseClasses = ({
});
}
if (variant === "danger") {
return clsx("not-prose rounded-full", {
return clsx("not-prose", {
"rounded-full": radius === "large",
"rounded-md": radius === "medium",
"rounded-sm": radius === "small",
truncate: !noTruncate,
"bg-action-danger-dark text-copy-light": mode === "dark",
"bg-action-danger-light text-copy-lighter": mode === "light",
Expand Down Expand Up @@ -286,6 +302,7 @@ export const getButtonClasses = ({
variant,
noTruncate,
align,
radius,
}: getButtonClassesProps) => {
if (!variant) {
variant = "primary";
Expand All @@ -296,7 +313,13 @@ export const getButtonClasses = ({
BUTTON_CLASSNAME,
className,
getSpacing(spacing),
getButtonBaseClasses({ mode, variant, noBackground, noTruncate }),
getButtonBaseClasses({
mode,
variant,
noBackground,
noTruncate,
radius,
}),
getButtonSizesClasses({ type, size, labelRight, labelLeft, align }),
getButtonBorderClasses({ mode, variant, noBorder }),
getButtonFocusClasses({ focusMode }),
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-button/src/components/private/ButtonSort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const ButtonSort_private = React.forwardRef<
noBackground = false,
align = "center",
active = false,
radius = "large",

...otherProps
},
Expand All @@ -49,6 +50,7 @@ export const ButtonSort_private = React.forwardRef<
spacing,
noBackground,
align,
radius,
});
const iconClass = clsx({
"text-copy-accent-dark": mode === "light" && !raw,
Expand Down
4 changes: 4 additions & 0 deletions packages/ui-types/src/button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type CommonButtonProps = {
* The size of the Button.
*/
size?: "small" | "medium" | "large";
/**
* The rounded style of the Button.
*/
radius?: "small" | "medium" | "large";
} & SpacingTypes.Props;

declare namespace ButtonTypes {
Expand Down

0 comments on commit 6a0719e

Please sign in to comment.