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

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 89
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 70
mnd 2
bc 2
fnc 0
dl 0
loc 89
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import { BooleanProp, Demo, SelectProp } from "@cianciarusocataldo/demo-ui";
2
3
import ReactImage from "./react.svg";
4
import ReduxImage from "./redux.svg";
5
6
import { DEMO_COMMON_PROPS } from "app/constants/demo-props";
7
8
import { Spinner } from "modular-ui-preview";
9
import { ComponentPage } from "app/components/ComponentPage";
10
11
const SpinnerPage = () => (
12
  <ComponentPage
13
    name="Spinner"
14
    translations
15
    render={(t, componentLabel) => {
16
      const notSetLabel = t("props_value_notSet");
17
      const customValueLabel = t("props_value_custom");
18
      const customStatesLabel = t("props_statuses_custom");
19
20
      return (
21
        <Demo
22
          label={componentLabel}
23
          props={{
24
            value: SelectProp({
25
              [notSetLabel]: undefined,
26
              success: "success",
27
              error: "error",
28
              loading: "loading",
29
            }),
30
            [customStatesLabel]: BooleanProp(false),
31
            [customValueLabel]: SelectProp({
32
              [notSetLabel]: undefined,
33
              react: "react",
34
              redux: "redux",
35
            }),
36
            ...DEMO_COMMON_PROPS,
37
            shadow: BooleanProp(false),
38
          }}
39
        >
40
          {(props: any) => {
41
            let componentProps = { ...props };
42
43
            delete componentProps[customStatesLabel];
44
            delete componentProps[customValueLabel];
45
46
            if (props[customStatesLabel]) {
47
              componentProps.statuses = {
48
                react: (
49
                  <div style={{ width: "8rem", height: "8rem" }}>
50
                    <img src={ReactImage} width="125px" height="125px" alt="" />
51
                  </div>
52
                ),
53
                redux: (
54
                  <div style={{ width: "8rem", height: "8rem" }}>
55
                    <img src={ReduxImage} alt="" width="125px" height="125px" />
56
                  </div>
57
                ),
58
              };
59
              componentProps.value = props[customValueLabel];
60
            } else {
61
              componentProps.statuses = undefined;
62
              componentProps.value = props.value;
63
            }
64
65
            return (
66
              <div
67
                style={{
68
                  display: "flex",
69
                  flexDirection: "column",
70
                  alignItems: "center",
71
                }}
72
              >
73
                <Spinner
74
                  {...componentProps}
75
                  className={
76
                    props.className.length > 0 ? props.className : "w-32"
77
                  }
78
                />
79
              </div>
80
            );
81
          }}
82
        </Demo>
83
      );
84
    }}
85
  />
86
);
87
88
export default SpinnerPage;
89