src/components/molecules/Card/index.tsx
last analyzed

Complexity

Total Complexity 0
Complexity/F 0

Size

Lines of Code 83
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 0
eloc 36
mnd 0
bc 0
fnc 0
dl 0
loc 83
ccs 16
cts 16
cp 1
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1 1
import "./styles.css";
2
3 1
import React from "react";
4
5
import { CardComponent } from "./types";
6
7 1
import { buildBoxComponent } from "../../../utils";
8
9 1
import Divider from "../../atoms/Divider";
10
11
/**
12
 * A Card component. Its UI depends on given parameters (header, body and footer)
13
 *
14
 * @since 0.3.0
15
 *
16
 * @param {JSX.Element | Element} icon A custom icon showed before the Card header
17
 * @param {JSX.Element | Element | string} header Card header content
18
 * @param {JSX.Element | Element | string} body Card body content
19
 * @param {JSX.Element | Element | string} footer Card footer content
20
 * @param {JSX.Element | Element | string} label Component label, showed at the top
21
 * @param {string} className `common modular-ui prop` - custom className (to better customize it)
22
 * @param {boolean} unstyled `common modular-ui prop` - Style/unstyle component (to better customize it)
23
 * @param {string} id `common modular-ui prop` - `data-id` parameter (for testing purpose, to easily find the component into the DOM)
24
 * @param {boolean} dark `common modular-ui prop` - Enable/disable dark mode
25
 * @param {boolean} hide `common modular-ui prop` - Hide/show component
26
 * @param {boolean} shadow `common modular-ui prop` - Enable/disable shadow behind component (to better customize it)
27
 *
28
 * @example <caption>Example Card usage</caption>
29
 * import { render } from "react-dom";
30
 * import { Card } from '@cianciarusocataldo/modular-ui';
31
 *
32
 * render(<Card header="Example header" body="Example body" footer="Example footer" />, document.getElementById("root"));
33
 *
34
 * @see https://cianciarusocataldo.github.io/modular-ui/components/molecules/Card
35
 *
36
 * @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo>
37
 *
38
 * @copyright 2022 Cataldo Cianciaruso
39
 */
40 1
const Card: CardComponent = ({
41 2
  icon,
42 2
  header,
43 2
  body,
44 2
  footer,
45 2
  children,
46 2
  className,
47 2
  label,
48 2
  ...commonProps
49
}) => {
50 2
  return buildBoxComponent({
51 2
    callBack: () => ({
52
      name: "modular-card",
53
      Component: [
54
        header && (
55
          <div key="modular_card_header">
56
            <div className="container-header">
57
              {icon}
58
              <div className="header">{header}</div>
59
            </div>
60
            <Divider />
61
          </div>
62
        ),
63
        <div className="body" key="modular_card_body">
64
          {body}
65
        </div>,
66
        children,
67
        footer && (
68
          <div key="modular_card_footer">
69
            <Divider />
70
            <div className="footer">{footer}</div>
71
          </div>
72
        ),
73
      ],
74
      commonProps: {
75
        ...commonProps,
76
      },
77
    }),
78
    defaultValue: "",
79
    label,
80
  });
81
};
82
83
export default Card;
84