/
MenuItemSwitch.tsx
50 lines (47 loc) · 1.23 KB
/
MenuItemSwitch.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React, { forwardRef } from "react";
import {
BaseMenuItemInputToggleProps,
MenuItemInputToggle,
} from "./MenuItemInputToggle";
/** @remarks \@since 2.8.0 */
export type MenuItemSwitchProps = Omit<BaseMenuItemInputToggleProps, "icon">;
/**
* This is a simple wrapper for the {@link MenuItemInputToggle} component to
* render it as a switch.
*
* @example
* Simple Example
* ```tsx
* import { ReactElement, useState } from "react";
* import { DropdownMenu } from "@react-md/menu";
* import { MenuItemSwitch } from "@react-md/form";
*
* function Example(): ReactElement {
* const [checked, setChecked] = useState(false);
*
* return (
* <DropdownMenu
* id="dropdown-menu-id"
* items={[
* <MenuItemSwitch
* id="switch-1"
* checked={checked}
* onCheckedChange={(nextChecked) => setChecked(nextChecked)}
* >
* Switch
* </MenuItemSwitch>,
* ]}
* >
* Button
* </DropdownMenu>
* );
* }
* ```
*
* @remarks \@since 2.8.0
*/
export const MenuItemSwitch = forwardRef<HTMLLIElement, MenuItemSwitchProps>(
function MenuItemSwitch(props, ref) {
return <MenuItemInputToggle {...props} ref={ref} type="switch" />;
}
);