chore: fix switch on clipper

This commit is contained in:
Aman Harwara
2023-05-16 18:29:56 +05:30
parent aceeeb7e7d
commit 058a2c69a3
3 changed files with 26 additions and 4 deletions

View File

@@ -374,6 +374,7 @@ const ClipperView = ({
setIsScreenshotMode(checked) setIsScreenshotMode(checked)
}} }}
className="flex-row-reverse gap-2" className="flex-row-reverse gap-2"
forceDesktopStyle={true}
> >
Clip as screenshot Clip as screenshot
</MenuSwitchButtonItem> </MenuSwitchButtonItem>

View File

@@ -11,11 +11,23 @@ type Props = {
children: ReactNode children: ReactNode
onChange: (checked: boolean) => void onChange: (checked: boolean) => void
shortcut?: PlatformedKeyboardShortcut shortcut?: PlatformedKeyboardShortcut
forceDesktopStyle?: boolean
} & Omit<ComponentPropsWithoutRef<'button'>, 'onChange'> } & Omit<ComponentPropsWithoutRef<'button'>, 'onChange'>
const MenuSwitchButtonItem = forwardRef( const MenuSwitchButtonItem = forwardRef(
( (
{ checked, onChange, disabled, onBlur, tabIndex, children, shortcut, className, ...props }: Props, {
checked,
onChange,
disabled,
onBlur,
tabIndex,
children,
shortcut,
className,
forceDesktopStyle,
...props
}: Props,
ref: ForwardedRef<HTMLButtonElement>, ref: ForwardedRef<HTMLButtonElement>,
) => { ) => {
return ( return (
@@ -47,6 +59,7 @@ const MenuSwitchButtonItem = forwardRef(
checked={checked} checked={checked}
onChange={onChange} onChange={onChange}
tabIndex={FOCUSABLE_BUT_NOT_TABBABLE} tabIndex={FOCUSABLE_BUT_NOT_TABBABLE}
forceDesktopStyle={forceDesktopStyle}
/> />
</div> </div>
</button> </button>

View File

@@ -7,22 +7,25 @@ const Switch = ({
className, className,
disabled = false, disabled = false,
tabIndex, tabIndex,
forceDesktopStyle,
}: { }: {
checked: boolean checked: boolean
onChange: (checked: boolean) => void onChange: (checked: boolean) => void
className?: string className?: string
disabled?: boolean disabled?: boolean
tabIndex?: number tabIndex?: number
forceDesktopStyle?: boolean
}) => { }) => {
const isActive = checked && !disabled const isActive = checked && !disabled
return ( return (
<label <label
className={classNames( className={classNames(
'relative box-content inline-block h-8 w-13 flex-shrink-0 cursor-pointer rounded-full border-2 border-solid border-transparent bg-clip-padding transition-colors duration-150 ease-out md:h-4.5 md:w-8', 'relative box-content inline-block flex-shrink-0 cursor-pointer rounded-full border-2 border-solid border-transparent bg-clip-padding transition-colors duration-150 ease-out',
'ring-2 ring-transparent focus-within:border-default focus-within:shadow-none focus-within:outline-none focus-within:ring-info', 'ring-2 ring-transparent focus-within:border-default focus-within:shadow-none focus-within:outline-none focus-within:ring-info',
disabled ? 'opacity-50' : '', disabled ? 'opacity-50' : '',
isActive ? 'bg-info' : 'bg-neutral', isActive ? 'bg-info' : 'bg-neutral',
forceDesktopStyle ? 'h-4.5 w-8' : 'h-8 w-13 md:h-4.5 md:w-8',
className, className,
)} )}
> >
@@ -37,8 +40,13 @@ const Switch = ({
</VisuallyHidden> </VisuallyHidden>
<div <div
className={classNames( className={classNames(
'absolute left-[0.275rem] top-1/2 block h-6 w-6 -translate-y-1/2 rounded-full bg-default transition-transform duration-150 ease-out md:left-[2px] md:h-3.5 md:w-3.5', 'absolute left-[0.275rem] top-1/2 block -translate-y-1/2 rounded-full bg-default transition-transform duration-150 ease-out',
checked ? 'translate-x-[calc(3.25rem-1.5rem-0.5rem)] md:translate-x-[calc(2rem-1.125rem)]' : '', forceDesktopStyle ? 'left-[2px] h-3.5 w-3.5' : 'h-6 w-6 md:left-[2px] md:h-3.5 md:w-3.5',
checked
? forceDesktopStyle
? 'translate-x-[calc(2rem-1.125rem)]'
: 'translate-x-[calc(3.25rem-1.5rem-0.5rem)] md:translate-x-[calc(2rem-1.125rem)]'
: '',
)} )}
/> />
</label> </label>