1
|
1 |
|
import "./styles.css"; |
2
|
1 |
|
import React from "react"; |
3
|
|
|
|
4
|
|
|
import { SpinnerComponent } from "./types"; |
5
|
|
|
|
6
|
1 |
|
import DEFAULT_ICONS from "./icons"; |
7
|
|
|
|
8
|
1 |
|
import { buildBoxComponent } from "../../../utils"; |
9
|
|
|
|
10
|
1 |
|
import Container from "../Container"; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* A smart status indicator, optionally with custom images showed for every state (defaults are `loading`,`success` and `error`) |
14
|
|
|
* |
15
|
|
|
* @since 5.1.0 |
16
|
|
|
* |
17
|
|
|
* @param {number} value Spinner status |
18
|
|
|
* @param {JSX.Element | Element | string} label Component label, showed at the top |
19
|
|
|
* @param {string} className `common modular-ui prop` - custom className (to better customize it) |
20
|
|
|
* @param {boolean} unstyled `common modular-ui prop` - Style/unstyle component (to better customize it) |
21
|
|
|
* @param {string} id `common modular-ui prop` - `data-id` parameter (for testing purpose, to easily find the component into the DOM) |
22
|
|
|
* @param {boolean} dark `common modular-ui prop` - Enable/disable dark mode |
23
|
|
|
* @param {boolean} hide `common modular-ui prop` - Hide/show component |
24
|
|
|
* @param {boolean} shadow `common modular-ui prop` - Enable/disable shadow behind component (to better customize it) |
25
|
|
|
* |
26
|
|
|
* @example <caption>Example Dropdown usage</caption> |
27
|
|
|
* |
28
|
|
|
* import { render } from "react-dom"; |
29
|
|
|
* import { Spinner } from '@cianciarusocataldo/modular-ui'; |
30
|
|
|
* |
31
|
|
|
* render(<Spinner value="error" />, document.getElementById("root")); |
32
|
|
|
* |
33
|
|
|
* @see https://cianciarusocataldo.github.io/modular-ui/components/molecules/Spinner |
34
|
|
|
* |
35
|
|
|
* @author Cataldo Cianciaruso <https://github.com/CianciarusoCataldo> |
36
|
|
|
* |
37
|
|
|
* @copyright 2022 Cataldo Cianciaruso |
38
|
|
|
*/ |
39
|
1 |
|
const Spinner: SpinnerComponent = ({ |
40
|
7 |
|
value, |
41
|
7 |
|
label, |
42
|
7 |
|
statuses, |
43
|
7 |
|
...commonProps |
44
|
|
|
}) => { |
45
|
7 |
|
return buildBoxComponent({ |
46
|
|
|
label, |
47
|
|
|
value, |
48
|
|
|
defaultValue: "loading", |
49
|
|
|
callBack: (value, setValue) => { |
50
|
7 |
|
const ICONS = statuses || DEFAULT_ICONS; |
51
|
7 |
|
const StatusIcon = () => ( |
52
|
|
|
<Container unstyled animated> |
53
|
|
|
{value && ICONS[value] ? ICONS[value] : ICONS.loading} |
54
|
|
|
</Container> |
55
|
|
|
); |
56
|
|
|
|
57
|
7 |
|
return { |
58
|
|
|
commonProps, |
59
|
|
|
Component: ( |
60
|
|
|
<Container unstyled animated> |
61
|
|
|
<StatusIcon /> |
62
|
|
|
</Container> |
63
|
|
|
), |
64
|
|
|
name: "modular-spinner", |
65
|
|
|
}; |
66
|
|
|
}, |
67
|
|
|
}); |
68
|
|
|
}; |
69
|
|
|
|
70
|
|
|
export default Spinner; |
71
|
|
|
|