Skip to content

Commit

Permalink
Change the size default and remove the component not necessary to dis…
Browse files Browse the repository at this point in the history
…play

Update based on review and add type

add default value for Toogle size
  • Loading branch information
aralovelace committed Dec 5, 2024
1 parent 3d65468 commit 84d6f05
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
16 changes: 11 additions & 5 deletions src/core/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ import cn from "./utils/cn";

type ToggleProps = {
id: string;
size?: string;
size?: "sm" | "lg";
label?: string;
className?: string;
onCheckedChange?: (checked: boolean) => void;
} & React.ButtonHTMLAttributes<HTMLButtonElement>;

const Toggle: React.FC<ToggleProps> = ({
id,
size,
size = "lg",
label,
className,
...props
}) => {
const rootSize = size === "small" ? "w-[42px] h-[24px]" : "w-[56px] h-32";
const rootSize = size === "sm" ? "w-[42px] h-[24]" : "w-[56px] h-32";
const thumbSize =
size === "small" ? "w-[21px] h-[21px] translate-x-1 data-[state=checked]:translate-x-[20px]" : "h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]";
size === "sm"
? "w-[21px] h-[21px] translate-x-1 data-[state=checked]:translate-x-[20px]"
: "h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]";

return (
<div className="flex items-center">
Expand All @@ -32,7 +35,10 @@ const Toggle: React.FC<ToggleProps> = ({
{...props}
>
<Switch.Thumb
className={`block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform ${thumbSize}`}
className={cn(
`block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform`,
thumbSize,
)}
/>
</Switch.Root>
{label ? (
Expand Down
9 changes: 2 additions & 7 deletions src/core/Toggle/Toggle.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ Default.args = {};

export const Checked = Template.bind({});
Checked.args = {
checked: true,
defaultChecked: true,
disabled: false,
};

export const Disabled = Template.bind({});
Disabled.args = {
checked: false,
defaultChecked: false,
disabled: true,
};

export const Small = Template.bind({});
Small.args = {
size: "small",
};
23 changes: 3 additions & 20 deletions src/core/Toggle/__snapshots__/Toggle.stories.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`Components/Toggle Checked smoke-test 1`] = `
class="p-0 bg-neutral-600 rounded-full relative inline-block transition-colors data-[disabled]:bg-gui-unavailable data-[disabled]:cursor-not-allowed data-[state=checked]:bg-orange-600 focus:outline-none focus-visible:outline-offset-0 focus-visible:outline-4 focus-visible:outline-gui-focus w-[56px] h-32"
>
<span data-state="checked"
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]"
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]"
>
</span>
</button>
Expand All @@ -27,7 +27,7 @@ exports[`Components/Toggle Default smoke-test 1`] = `
class="p-0 bg-neutral-600 rounded-full relative inline-block transition-colors data-[disabled]:bg-gui-unavailable data-[disabled]:cursor-not-allowed data-[state=checked]:bg-orange-600 focus:outline-none focus-visible:outline-offset-0 focus-visible:outline-4 focus-visible:outline-gui-focus w-[56px] h-32"
>
<span data-state="unchecked"
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]"
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]"
>
</span>
</button>
Expand All @@ -47,24 +47,7 @@ exports[`Components/Toggle Disabled smoke-test 1`] = `
>
<span data-state="unchecked"
data-disabled
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]"
>
</span>
</button>
</div>
`;

exports[`Components/Toggle Small smoke-test 1`] = `
<div class="flex items-center">
<button type="button"
role="switch"
aria-checked="false"
data-state="unchecked"
value="on"
class="p-0 bg-neutral-600 rounded-full relative inline-block transition-colors data-[disabled]:bg-gui-unavailable data-[disabled]:cursor-not-allowed data-[state=checked]:bg-orange-600 focus:outline-none focus-visible:outline-offset-0 focus-visible:outline-4 focus-visible:outline-gui-focus w-[42px] h-[24px]"
>
<span data-state="unchecked"
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform w-[21px] h-[21px] translate-x-1 data-[state=checked]:translate-x-[20px]"
class="block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform h-[28px] w-[28px] translate-x-2 data-[state=checked]:translate-x-[26px]"
>
</span>
</button>
Expand Down

0 comments on commit 84d6f05

Please sign in to comment.