1
|
|
|
import { DEMO_COMMON_PROPS } from "app/constants/demo-props"; |
2
|
|
|
|
3
|
|
|
import OnIcon from "./on.svg"; |
4
|
|
|
import OffIcon from "./off.svg"; |
5
|
|
|
|
6
|
|
|
import { BooleanProp, Demo, StringProp } from "@cianciarusocataldo/demo-ui"; |
7
|
|
|
|
8
|
|
|
import { Toggle } from "modular-ui-preview"; |
9
|
|
|
import { ComponentPage } from "app/components/ComponentPage"; |
10
|
|
|
|
11
|
|
|
const TogglePage = () => ( |
12
|
|
|
<ComponentPage |
13
|
|
|
name="Toggle" |
14
|
|
|
translations |
15
|
|
|
render={(t, componentLabel) => { |
16
|
|
|
const iconLabel = t("props_icons"); |
17
|
|
|
|
18
|
|
|
return ( |
19
|
|
|
<Demo |
20
|
|
|
label={componentLabel} |
21
|
|
|
startColor="#999" |
22
|
|
|
props={{ |
23
|
|
|
value: BooleanProp(true), |
24
|
|
|
[iconLabel]: BooleanProp(false), |
25
|
|
|
label: StringProp("label"), |
26
|
|
|
...DEMO_COMMON_PROPS, |
27
|
|
|
}} |
28
|
|
|
rows={[ |
29
|
|
|
["value", "Custom icons", "label", "dark"], |
30
|
|
|
["className", "shadow", "unstyled", "hide"], |
31
|
|
|
]} |
32
|
|
|
> |
33
|
|
|
{(props: any, setProps: (props: any) => void) => { |
34
|
|
|
let actualProps = { ...props }; |
35
|
|
|
delete actualProps[iconLabel]; |
36
|
|
|
if (props[iconLabel]) { |
37
|
|
|
actualProps.onIcon = <img alt="" src={OnIcon} width={30} />; |
38
|
|
|
actualProps.offIcon = <img alt="" src={OffIcon} width={30} />; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return ( |
42
|
|
|
<div className="flex flex-col items-center"> |
43
|
|
|
<Toggle |
44
|
|
|
{...actualProps} |
45
|
|
|
onChange={() => setProps({ ...props, value: !props.value })} |
46
|
|
|
/> |
47
|
|
|
</div> |
48
|
|
|
); |
49
|
|
|
}} |
50
|
|
|
</Demo> |
51
|
|
|
); |
52
|
|
|
}} |
53
|
|
|
/> |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
export default TogglePage; |
57
|
|
|
|