-
Notifications
You must be signed in to change notification settings - Fork 429
/
Copy pathindex.jsx
154 lines (138 loc) · 3.74 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// # Spinner Component --- SLDS for React
// Implements the [Spinner design pattern - 2.1.0-beta.3 (204)](https://latest-204.lightningdesignsystem.com/components/spinners) in React.
// ### React
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import checkProps from './check-props';
// ## Constants
import { SPINNER } from '../../utilities/constants';
import componentDoc from './component.json';
// ### Prop Types
const propTypes = {
/**
* **Assistive text for accessibility.**
* This object is merged with the default props object on every render.
* * `label`: Assistive text that is read out loud to screen readers.
*/
assistiveText: PropTypes.shape({
label: PropTypes.string,
}),
/**
* Custom css classes applied to Spinner container
*/
containerClassName: PropTypes.string,
/**
* Custom css properties applied to Spinner container
*/
containerStyle: PropTypes.object,
/**
* Render the spinner inside of a container.
*/
hasContainer: PropTypes.bool,
/**
* Unique html id placed on div with role="status".
*/
id: PropTypes.string,
/**
* Adds delay of 300ms to the spinner
*/
isDelayed: PropTypes.bool,
/**
* Add styling to support a spinner inside an input field.
*/
isInput: PropTypes.bool,
/**
* Add styling to support an inline spinner inside of the document flow.
*/
isInline: PropTypes.bool,
/**
* Determines the size of the spinner
*/
size: PropTypes.oneOf(['xx-small', 'x-small', 'small', 'medium', 'large']),
/**
* Determines the color of the spinner: `base` is gray, `brand` is blue, and `inverse` is white.
*/
variant: PropTypes.oneOf(['base', 'brand', 'inverse']),
};
const defaultProps = {
assistiveText: { label: 'Loading...' },
isDelayed: false,
isInline: false,
isInput: false,
hasContainer: true,
size: 'medium',
variant: 'base',
};
/**
* Spinners are CSS loading indicators that should be shown when retrieving data or performing slow computations. In some cases, the first time a parent component loads, a stencil is preferred to indicate network activity.
*/
const Spinner = ({
containerClassName,
containerStyle,
id,
isDelayed = defaultProps.isDelayed,
isInline = defaultProps.isInline,
isInput = defaultProps.isInput,
hasContainer = defaultProps.hasContainer,
size = defaultProps.size,
variant = defaultProps.variant,
assistiveText = defaultProps.assistiveText,
...restProps
}) => {
checkProps(
SPINNER,
{
containerClassName,
containerStyle,
id,
isDelayed,
isInline,
isInput,
hasContainer,
size,
variant,
...restProps,
},
componentDoc
);
const mergedAssistiveText =
typeof assistiveText === 'string'
? assistiveText
: {
...defaultProps.assistiveText,
...assistiveText,
}.label;
const spinnerClassName = classNames('slds-spinner', {
'slds-spinner_inline': isInline,
'slds-input__spinner': isInput,
'slds-spinner_brand': variant === 'brand',
'slds-spinner_inverse': variant === 'inverse',
'slds-spinner_delayed': isDelayed,
[`slds-spinner_${size}`]: size,
});
const spinner = (
<div aria-hidden="false" className={spinnerClassName} id={id} role="status">
{mergedAssistiveText && (
<span className="slds-assistive-text">{mergedAssistiveText}</span>
)}
<div className="slds-spinner__dot-a" />
<div className="slds-spinner__dot-b" />
</div>
);
return hasContainer ? (
<div
className={classNames(containerClassName, 'slds-spinner_container')}
style={containerStyle}
>
{spinner}
</div>
) : (
spinner
);
};
Spinner.displayName = SPINNER;
Spinner.propTypes = propTypes;
export default Spinner;