Completed
Push — main ( 8ca39d...9cc399 )
by Cataldo
03:32
created

src/components/molecules/Spinner/index.tsx   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 60
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 31
mnd 1
bc 1
fnc 0
dl 0
loc 60
ccs 10
cts 10
cp 1
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1 1
import "./styles.css";
2 1
import React from "react";
3
4
import { SpinnerProps } from "./types";
5
6 1
import ICONS from "./icons";
7
8 1
import { buildBoxComponent } from "../../../utils";
9
10 1
import Container from "../Container";
11
12
/**
13
 * A smart status indicator
14
 *
15
 * @param {number} value Spinner status
16
 * @param {JSX.Element | Element | string} label Component label, showed at the top
17
 * @param {string} className `common modular-ui prop` - custom className (to better customize it)
18
 * @param {boolean} unstyled `common modular-ui prop` - Style/unstyle component (to better customize it)
19
 * @param {string} id `common modular-ui prop` - `data-id` parameter (for testing purpose, to easily find the component into the DOM)
20
 * @param {boolean} dark `common modular-ui prop` - Enable/disable dark mode
21
 * @param {boolean} hide `common modular-ui prop` - Hide/show component
22
 * @param {boolean} shadow `common modular-ui prop` - Enable/disable shadow behind component (to better customize it)
23
 *
24
 *@example <caption>Example Dropdown usage</caption>
25
 *import { render } from "react-dom";
26
 *import { Spinner } from '@cianciarusocataldo/modular-ui';
27
 *
28
 * render(<Spinner value="error" />, document.getElementById("root"));
29
 *
30
 * @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo>
31
 *
32
 * @copyright 2022 Cataldo Cianciaruso
33
 */
34 3
const Spinner = ({ value, icon, label, ...commonProps }: SpinnerProps) => {
35 3
  return buildBoxComponent({
36
    label,
37
    value,
38
    defaultValue: "loading",
39
    callBack: (value, setValue) => {
40 3
      const StatusIcon = () => (
41
        <Container unstyled animated>
42
          {value && ICONS[value] ? ICONS[value] : ICONS.loading}
43
        </Container>
44
      );
45
46 3
      return {
47
        commonProps,
48
        Component: (
49
          <Container unstyled animated>
50
            <StatusIcon />
51
          </Container>
52
        ),
53
        name: "modular-spinner",
54
      };
55
    },
56
  });
57
};
58
59
export default Spinner;
60