mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix TOV-280 experimental features ui - enabled in the workspace settings for a cloud workspace; only show for workspace owner + early access - a disclaimer prompt will be shown before going to the next feature setting page - for now only show the ai poc switch, which controls the display of the ai tab in editor's sidepanel
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
// components/switch.tsx
|
|
import clsx from 'clsx';
|
|
import {
|
|
type HTMLAttributes,
|
|
type ReactNode,
|
|
useCallback,
|
|
useState,
|
|
} from 'react';
|
|
|
|
import * as styles from './index.css';
|
|
|
|
export type SwitchProps = Omit<HTMLAttributes<HTMLLabelElement>, 'onChange'> & {
|
|
checked?: boolean;
|
|
onChange?: (checked: boolean) => void;
|
|
children?: ReactNode;
|
|
};
|
|
|
|
export const Switch = ({
|
|
checked: checkedProp = false,
|
|
onChange: onChangeProp,
|
|
children,
|
|
className,
|
|
...otherProps
|
|
}: SwitchProps) => {
|
|
const [checkedState, setCheckedState] = useState(checkedProp);
|
|
|
|
const checked = onChangeProp ? checkedProp : checkedState;
|
|
const onChange = useCallback(
|
|
(event: React.ChangeEvent<HTMLInputElement>) => {
|
|
const newChecked = event.target.checked;
|
|
if (onChangeProp) onChangeProp(newChecked);
|
|
else setCheckedState(newChecked);
|
|
},
|
|
[onChangeProp]
|
|
);
|
|
|
|
return (
|
|
<label className={clsx(styles.labelStyle, className)} {...otherProps}>
|
|
{children}
|
|
<input
|
|
className={clsx(styles.inputStyle)}
|
|
type="checkbox"
|
|
value={checked ? 'on' : 'off'}
|
|
checked={checked}
|
|
onChange={onChange}
|
|
/>
|
|
<span
|
|
className={clsx(styles.switchStyle, {
|
|
[styles.switchCheckedStyle]: checked,
|
|
})}
|
|
/>
|
|
</label>
|
|
);
|
|
};
|