Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Size small for toogle #571

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ably/ui",
"version": "15.1.3",
"version": "15.1.4",
"description": "Home of the Ably design system library ([design.ably.com](https://design.ably.com)). It provides a showcase, development/test environment and a publishing pipeline for different distributables.",
"repository": {
"type": "git",
Expand Down
26 changes: 23 additions & 3 deletions src/core/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,42 @@ import cn from "./utils/cn";

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

const Toggle: React.FC<ToggleProps> = ({ id, label, className, ...props }) => {
const Toggle: React.FC<ToggleProps> = ({
id,
size = "lg",
label,
className,
...props
}) => {
const rootSize = size === "sm" ? "w-[42px] h-24" : "w-[56px] h-32";
const thumbSize =
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">
<Switch.Root
className={cn(
"p-0 h-32 w-[56px] 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-base",
"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-base",
className,
rootSize,
)}
id={id}
{...props}
>
<Switch.Thumb className="block h-[28px] w-[28px] bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle translate-x-2 data-[state=checked]:translate-x-[26px] transition-transform" />
<Switch.Thumb
className={cn(
`block bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle transition-transform`,
thumbSize,
)}
/>
</Switch.Root>
{label ? (
<label className="ml-16" htmlFor={id}>
Expand Down
4 changes: 2 additions & 2 deletions src/core/Toggle/Toggle.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +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,
};
12 changes: 6 additions & 6 deletions src/core/Toggle/__snapshots__/Toggle.stories.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ exports[`Components/Toggle Checked smoke-test 1`] = `
aria-checked="true"
data-state="checked"
value="on"
class="p-0 h-32 w-[56px] 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-base"
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-base w-[56px] h-32"
>
<span data-state="checked"
class="block h-[28px] w-[28px] bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle translate-x-2 data-[state=checked]:translate-x-[26px] transition-transform"
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 @@ -24,10 +24,10 @@ exports[`Components/Toggle Default smoke-test 1`] = `
aria-checked="false"
data-state="unchecked"
value="on"
class="p-0 h-32 w-[56px] 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-base"
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-base w-[56px] h-32"
>
<span data-state="unchecked"
class="block h-[28px] w-[28px] bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle translate-x-2 data-[state=checked]:translate-x-[26px] transition-transform"
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 @@ -43,11 +43,11 @@ exports[`Components/Toggle Disabled smoke-test 1`] = `
data-disabled
disabled
value="on"
class="p-0 h-32 w-[56px] 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-base"
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-base w-[56px] h-32"
>
<span data-state="unchecked"
data-disabled
class="block h-[28px] w-[28px] bg-white data-[disabled]:bg-neutral-500 rounded-full drop-shadow-toggle translate-x-2 data-[state=checked]:translate-x-[26px] transition-transform"
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
Loading