playground/src/pages/Toggle/index.tsx   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 57
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 45
mnd 1
bc 1
fnc 0
dl 0
loc 57
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
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