* feat: improve 2fa styles based on feedback * fix: preferences panes and dialogs electron compatibility * fix: no horizontal line when opening two factor activation * feat: improve two factor activation styles * feat: further 2fa style improvements * feat: padding 2fa widgets * feat: add padding between QR code and content * feat: refresh 2fa after passcode confirmation * feat: don't autocomplete passwords for DecoratedInput
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { ComponentChildren, FunctionalComponent } from 'preact';
|
|
import { useState } from 'preact/hooks';
|
|
import { HTMLProps } from 'react';
|
|
import {
|
|
CustomCheckboxContainer,
|
|
CustomCheckboxInput,
|
|
CustomCheckboxInputProps,
|
|
} from '@reach/checkbox';
|
|
import '@reach/checkbox/styles.css';
|
|
|
|
export type SwitchProps = HTMLProps<HTMLInputElement> & {
|
|
checked?: boolean;
|
|
onChange: (checked: boolean) => void;
|
|
className?: string;
|
|
children?: ComponentChildren;
|
|
};
|
|
|
|
export const Switch: FunctionalComponent<SwitchProps> = (
|
|
props: SwitchProps
|
|
) => {
|
|
const [checkedState, setChecked] = useState(props.checked || false);
|
|
const checked = props.checked ?? checkedState;
|
|
const className = props.className ?? '';
|
|
return (
|
|
<label
|
|
className={`sn-component flex justify-between items-center cursor-pointer px-3 ${className}`}
|
|
>
|
|
{props.children}
|
|
<CustomCheckboxContainer
|
|
checked={checked}
|
|
onChange={(event) => {
|
|
setChecked(event.target.checked);
|
|
props.onChange(event.target.checked);
|
|
}}
|
|
className={`sn-switch ${checked ? 'bg-info' : 'bg-neutral'}`}
|
|
>
|
|
<CustomCheckboxInput
|
|
{...({
|
|
...props,
|
|
className: undefined,
|
|
children: undefined,
|
|
} as CustomCheckboxInputProps)}
|
|
/>
|
|
<span
|
|
aria-hidden
|
|
className={`sn-switch-handle ${
|
|
checked ? 'sn-switch-handle--right' : ''
|
|
}`}
|
|
/>
|
|
</CustomCheckboxContainer>
|
|
</label>
|
|
);
|
|
};
|