Skip to content

Commit

Permalink
Fix Button Group fillWidth (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethasok authored Nov 2, 2023
1 parent 26e22d0 commit 20e25a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/ButtonGroup/ButtonGroup.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export const Playground = {
{ label: "Option 2", value: "option2" },
{ label: "Option 3", value: "option3" },
],
fillWidth: false,
},
};
17 changes: 13 additions & 4 deletions src/components/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ export interface ButtonGroupElementProps
extends Omit<HTMLAttributes<HTMLButtonElement>, "children"> {
value: string;
label?: ReactNode;
fillWidth?: boolean;
}

export interface ButtonGroupProps
extends Omit<HTMLAttributes<HTMLDivElement>, "onClick"> {
options: Array<ButtonGroupElementProps>;
selected?: string;
onClick?: (value: string) => void;
fillWidth?: boolean;
}

export const ButtonGroup = ({
options,
selected,
fillWidth,
onClick,
...props
}: ButtonGroupProps) => {
const lastIndex = options.length - 1;
const btns = options.map(({ value, label, fillWidth, ...props }, index) => {
const btns = options.map(({ value, label, ...props }, index) => {
const position: ButtonPosition =
index === 0 ? "left" : index === lastIndex ? "right" : "center";
return (
Expand All @@ -39,7 +40,14 @@ export const ButtonGroup = ({
</Button>
);
});
return <ButtonGroupWrapper {...props}>{btns}</ButtonGroupWrapper>;
return (
<ButtonGroupWrapper
$fillWidth={fillWidth}
{...props}
>
{btns}
</ButtonGroupWrapper>
);
};

type ButtonPosition = "left" | "center" | "right";
Expand All @@ -51,7 +59,7 @@ interface ButtonProps {
$fillWidth?: boolean;
}

const ButtonGroupWrapper = styled.div`
const ButtonGroupWrapper = styled.div<{ $fillWidth?: boolean }>`
box-sizing: border-box;
display: inline-flex;
flex-direction: row;
Expand All @@ -61,6 +69,7 @@ const ButtonGroupWrapper = styled.div`
border: 1px solid ${({ theme }) => theme.click.button.group.color.stroke.panel};
background: ${({ theme }) => theme.click.button.group.color.background.panel};
border-radius: ${({ theme }) => theme.click.button.group.radii.end};
width: ${({ $fillWidth }) => ($fillWidth ? "100%" : "auto")};
`;

const endRadii = "var(--click-button-button-group-radii-end)";
Expand Down

1 comment on commit 20e25a9

@vercel
Copy link

@vercel vercel bot commented on 20e25a9 Nov 2, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

click-ui – ./

click-ui-clickhouse.vercel.app
click-ui-git-main-clickhouse.vercel.app
click-ui.vercel.app

Please sign in to comment.