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

chore(app): Adding small switch size per design #1667

Merged
merged 4 commits into from
May 21, 2024
Merged
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
20 changes: 15 additions & 5 deletions weave-js/src/components/Switch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import * as Switch from '@radix-ui/react-switch';
import React from 'react';
import {twMerge} from 'tailwind-merge';

export type SwitchSize = 'small' | 'medium';
export const Root = ({
className,
size = 'medium',
...props
}: React.ComponentProps<typeof Switch.Root>) => (
}: React.ComponentProps<typeof Switch.Root> & {size?: SwitchSize}) => (
<Switch.Root
className={twMerge(
'flex h-[24px] w-[44px] items-center rounded-[12px] p-[1px] transition-colors duration-100 ease-out',
'flex items-center rounded-[12px] p-[1px] transition-colors duration-100 ease-out',
'focus-visible:outline focus-visible:outline-[2px] focus-visible:outline-teal-500',
props.checked ? ' bg-teal-500' : 'bg-moon-350',
size === 'small' ? 'h-[16px] w-[28px]' : 'h-[24px] w-[44px]',
className
)}
{...props}
Expand All @@ -19,12 +22,19 @@ export const Root = ({

export const Thumb = ({
className,
size = 'medium',
...props
}: React.ComponentProps<typeof Switch.Thumb> & {checked: boolean}) => (
}: React.ComponentProps<typeof Switch.Thumb> & {
checked: boolean;
size?: SwitchSize;
}) => (
<Switch.Thumb
className={twMerge(
'h-[22px] w-[22px] rounded-full bg-white transition-transform duration-100 ease-out',
props.checked ? 'translate-x-20' : 'translate-x-0',
'rounded-full bg-white transition-transform duration-100 ease-out',
size === 'small' ? 'h-[14px] w-[14px]' : 'h-[22px] w-[22px]',
size === 'small' && props.checked ? 'translate-x-12' : '',
size === 'medium' && props.checked ? 'translate-x-20' : '',
!props.checked && 'translate-x-0',
className
)}
{...props}
Expand Down
Loading