Skip to content

Commit

Permalink
Add fillWidth option to button group
Browse files Browse the repository at this point in the history
  • Loading branch information
vineethasok committed Oct 31, 2023
1 parent 9e3d7d8 commit a374288
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface ButtonGroupElementProps
extends Omit<HTMLAttributes<HTMLButtonElement>, "children"> {
value: string;
label?: ReactNode;
fillWidth?: boolean;
}

export interface ButtonGroupProps
Expand All @@ -21,14 +22,15 @@ export const ButtonGroup = ({
...props
}: ButtonGroupProps) => {
const lastIndex = options.length - 1;
const btns = options.map(({ value, label, ...props }, index) => {
const btns = options.map(({ value, label, fillWidth, ...props }, index) => {
const position: ButtonPosition =
index === 0 ? "left" : index === lastIndex ? "right" : "center";
return (
<Button
key={value}
$active={value === selected}
$position={position}
$fillWidth={fillWidth}
onClick={() => onClick?.(value)}
role="button"
{...props}
Expand All @@ -46,6 +48,7 @@ interface ButtonProps {
$active: boolean;
$position: ButtonPosition;
theme: DefaultTheme;
$fillWidth?: boolean;
}

const ButtonGroupWrapper = styled.div`
Expand Down Expand Up @@ -82,6 +85,7 @@ const Button = styled.button<ButtonProps>`
padding: ${({ theme }) => theme.click.button.basic.space.y}
${({ theme }) => theme.click.button.basic.space.x};
gap: ${({ theme }) => theme.click.button.basic.space.group};
${({ $fillWidth = false }) => ($fillWidth ? "flex: 1;" : "")}
cursor: pointer;
&:hover {
Expand Down

0 comments on commit a374288

Please sign in to comment.