Switch
Toggles between on/off states and makes the state visible in settings.
Last updated 11/1/2024
Example
Switch toggle triggers events. Implement handling in onCheckedChange.
import { Switch } from "@serendie/ui";
import { useState } from "react";
export function TypeSample() {
const [checked, setChecked] = useState(false);
const handleClick = () => {
setChecked(!checked);
};
return (
<Switch
checked={checked}
onCheckedChange={handleClick}
label={"スイッチラベル"}
/>
);
} States
Five states. Use the disabled prop when non-interactive.
- Enabled
- Checked
- Disabled
- Selected - Disabled
- Focused
import { Switch } from "@serendie/ui";
import { Dd, Dl, Dt } from "src/components/LayoutUtils";
export function StateSample() {
return (
<Dl>
<Dt>Enabled</Dt>
<Dd>
<Switch label={"スイッチラベル"} />
</Dd>
<Dt>Checked</Dt>
<Dd>
<Switch checked={true} label={"スイッチラベル"} />
</Dd>
<Dt>Disabled</Dt>
<Dd>
<Switch checked={false} disabled label={"スイッチラベル"} />
</Dd>
<Dt>Selected - Disabled</Dt>
<Dd>
<Switch checked={true} disabled label={"スイッチラベル"} />
</Dd>
<Dt>Focused</Dt>
<Dd>
<Switch checked={false} data-focus label={"スイッチラベル"} />
</Dd>
</Dl>
);
}