src/components/atoms/Link/index.tsx   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 47
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 17
mnd 1
bc 1
fnc 0
dl 0
loc 47
ccs 5
cts 5
cp 1
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1 1
import "./styles.css";
2
3
import { LinkComponent } from "./types";
4
5 1
import { buildComponent } from "../../../utils";
6
7
/**
8
 * A re-defined `<a>` component, designed to be better used with links
9
 *
10
 * @since 0.2.0
11
 *
12
 * @param {string} to Link url
13
 * @param {boolean} newTab if true, the link will be opened in a new tab
14
 * @param {string} children Link text to click
15
 * @param {string} className `common modular-ui prop` - custom className (to better customize it)
16
 * @param {boolean} unstyled `common modular-ui prop` - Style/unstyle component (to better customize it)
17
 * @param {string} id `common modular-ui prop` - `data-id` parameter (for testing purpose, to easily find the component into the DOM)
18
 * @param {boolean} dark `common modular-ui prop` - Enable/disable dark mode
19
 * @param {boolean} hide `common modular-ui prop` - Hide/show component
20
 * @param {boolean} shadow `common modular-ui prop` - Enable/disable shadow behind component (to better customize it)
21
 *
22
 * @example <caption>Example Link usage</caption>
23
 * import { render } from "react-dom";
24
 * import { Link } from '@cianciarusocataldo/modular-ui';
25
 *
26
 * render(<Link to="https://github.com/CianciarusoCataldo/modular-ui" newTab />, document.getElementById("root"));
27
 *
28
 * @see https://cianciarusocataldo.github.io/modular-ui/components/atoms/Link
29
 *
30
 * @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo>
31
 *
32
 * @copyright 2022 Cataldo Cianciaruso
33
 */
34 2
const Link: LinkComponent = ({ to, children, newTab, ...commonProps }) =>
35 2
  buildComponent({
36
    name: "modular-link",
37
    Component: children,
38
    commonProps,
39
    additionalProps: {
40
      href: to,
41
      target: newTab ? "_blank" : undefined,
42
    },
43
    wrapper: "a",
44
  });
45
46
export default Link;
47