@instructure/ui-spinner 11.6.0 → 11.6.1-snapshot-129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -282
- package/es/Spinner/{index.js → v1/index.js} +2 -2
- package/es/Spinner/v2/index.js +117 -0
- package/es/Spinner/v2/props.js +26 -0
- package/es/Spinner/v2/styles.js +191 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/Spinner/{index.js → v1/index.js} +4 -4
- package/lib/Spinner/v2/index.js +124 -0
- package/lib/Spinner/v2/props.js +31 -0
- package/lib/Spinner/v2/styles.js +197 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +41 -19
- package/src/Spinner/{index.tsx → v1/index.tsx} +2 -2
- package/src/Spinner/v2/README.md +63 -0
- package/src/Spinner/v2/index.tsx +134 -0
- package/src/Spinner/v2/props.ts +81 -0
- package/src/Spinner/v2/styles.ts +208 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Spinner/v1/index.d.ts.map +1 -0
- package/types/Spinner/v1/props.d.ts.map +1 -0
- package/types/Spinner/v1/styles.d.ts.map +1 -0
- package/types/Spinner/v1/theme.d.ts.map +1 -0
- package/types/Spinner/v2/index.d.ts +31 -0
- package/types/Spinner/v2/index.d.ts.map +1 -0
- package/types/Spinner/v2/props.d.ts +38 -0
- package/types/Spinner/v2/props.d.ts.map +1 -0
- package/types/Spinner/v2/styles.d.ts +20 -0
- package/types/Spinner/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Spinner/index.d.ts.map +0 -1
- package/types/Spinner/props.d.ts.map +0 -1
- package/types/Spinner/styles.d.ts.map +0 -1
- package/types/Spinner/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Spinner/{props.js → v1/props.js} +0 -0
- /package/es/Spinner/{styles.js → v1/styles.js} +0 -0
- /package/es/Spinner/{theme.js → v1/theme.js} +0 -0
- /package/lib/Spinner/{props.js → v1/props.js} +0 -0
- /package/lib/Spinner/{styles.js → v1/styles.js} +0 -0
- /package/lib/Spinner/{theme.js → v1/theme.js} +0 -0
- /package/src/Spinner/{README.md → v1/README.md} +0 -0
- /package/src/Spinner/{props.ts → v1/props.ts} +0 -0
- /package/src/Spinner/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Spinner/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Spinner/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/Spinner/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Spinner/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Spinner/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _emotion = require("@instructure/emotion");
|
|
8
|
+
/*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
* copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
+
* SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
// keyframes have to be outside of 'generateStyle',
|
|
33
|
+
// since it is causing problems in style recalculation
|
|
34
|
+
const rotate = (0, _emotion.keyframes)`
|
|
35
|
+
to {
|
|
36
|
+
transform: rotate(360deg)
|
|
37
|
+
}`;
|
|
38
|
+
const morph = (0, _emotion.keyframes)`
|
|
39
|
+
0% {
|
|
40
|
+
stroke-dashoffset: 190%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
50% {
|
|
44
|
+
stroke-dashoffset: 00%;
|
|
45
|
+
transform: rotate(90deg);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
100% {
|
|
49
|
+
stroke-dashoffset: 190%;
|
|
50
|
+
transform: rotate(360deg);
|
|
51
|
+
}`;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* ---
|
|
55
|
+
* private: true
|
|
56
|
+
* ---
|
|
57
|
+
* Generates the style object from the theme and provided additional information
|
|
58
|
+
* @param {Object} componentTheme The theme variable object.
|
|
59
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
60
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
61
|
+
* @return {Object} The final style object, which will be used in the component
|
|
62
|
+
*/
|
|
63
|
+
const generateStyle = (componentTheme, params, sharedTokens) => {
|
|
64
|
+
const size = params.size,
|
|
65
|
+
variant = params.variant,
|
|
66
|
+
margin = params.margin;
|
|
67
|
+
const spinnerSizes = {
|
|
68
|
+
'x-small': {
|
|
69
|
+
width: componentTheme.containerSizeXs,
|
|
70
|
+
height: componentTheme.containerSizeXs
|
|
71
|
+
},
|
|
72
|
+
small: {
|
|
73
|
+
width: componentTheme.containerSizeSm,
|
|
74
|
+
height: componentTheme.containerSizeSm
|
|
75
|
+
},
|
|
76
|
+
medium: {
|
|
77
|
+
width: componentTheme.containerSizeMd,
|
|
78
|
+
height: componentTheme.containerSizeMd
|
|
79
|
+
},
|
|
80
|
+
large: {
|
|
81
|
+
width: componentTheme.containerSizeLg,
|
|
82
|
+
height: componentTheme.containerSizeLg
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const circleSizes = {
|
|
86
|
+
'x-small': {
|
|
87
|
+
width: componentTheme.spinnerSizeXs,
|
|
88
|
+
height: componentTheme.spinnerSizeXs
|
|
89
|
+
},
|
|
90
|
+
small: {
|
|
91
|
+
width: componentTheme.spinnerSizeSm,
|
|
92
|
+
height: componentTheme.spinnerSizeSm
|
|
93
|
+
},
|
|
94
|
+
medium: {
|
|
95
|
+
width: componentTheme.spinnerSizeMd,
|
|
96
|
+
height: componentTheme.spinnerSizeMd
|
|
97
|
+
},
|
|
98
|
+
large: {
|
|
99
|
+
width: componentTheme.spinnerSizeLg,
|
|
100
|
+
height: componentTheme.spinnerSizeLg
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const circleTrackSizes = {
|
|
104
|
+
'x-small': {
|
|
105
|
+
strokeWidth: componentTheme.strokeWidthXs
|
|
106
|
+
},
|
|
107
|
+
small: {
|
|
108
|
+
strokeWidth: componentTheme.strokeWidthSm
|
|
109
|
+
},
|
|
110
|
+
medium: {
|
|
111
|
+
strokeWidth: componentTheme.strokeWidthMd
|
|
112
|
+
},
|
|
113
|
+
large: {
|
|
114
|
+
strokeWidth: componentTheme.strokeWidthLg
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const radii = {
|
|
118
|
+
'x-small': `calc(50% - ${componentTheme.strokeWidthXs} / 2)`,
|
|
119
|
+
small: `calc(50% - ${componentTheme.strokeWidthSm} / 2)`,
|
|
120
|
+
medium: `calc(50% - ${componentTheme.strokeWidthMd} / 2)`,
|
|
121
|
+
large: `calc(50% - ${componentTheme.strokeWidthLg} / 2)`
|
|
122
|
+
};
|
|
123
|
+
const circleSpinSizes = {
|
|
124
|
+
'x-small': {
|
|
125
|
+
strokeWidth: componentTheme.strokeWidthXs,
|
|
126
|
+
transformOrigin: `calc(${componentTheme.spinnerSizeXs} / 2) calc(${componentTheme.spinnerSizeXs} / 2)`
|
|
127
|
+
},
|
|
128
|
+
small: {
|
|
129
|
+
strokeWidth: componentTheme.strokeWidthSm,
|
|
130
|
+
transformOrigin: `calc(${componentTheme.spinnerSizeSm} / 2) calc(${componentTheme.spinnerSizeSm} / 2)`
|
|
131
|
+
},
|
|
132
|
+
medium: {
|
|
133
|
+
strokeWidth: componentTheme.strokeWidthMd,
|
|
134
|
+
transformOrigin: `calc(${componentTheme.spinnerSizeMd} / 2) calc(${componentTheme.spinnerSizeMd} / 2)`
|
|
135
|
+
},
|
|
136
|
+
large: {
|
|
137
|
+
strokeWidth: componentTheme.strokeWidthLg,
|
|
138
|
+
transformOrigin: `calc(${componentTheme.spinnerSizeLg} / 2) calc(${componentTheme.spinnerSizeLg} / 2)` //7em
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const circleSpinVariant = {
|
|
142
|
+
default: {
|
|
143
|
+
stroke: componentTheme.color
|
|
144
|
+
},
|
|
145
|
+
inverse: {
|
|
146
|
+
stroke: componentTheme.inverseColor
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
spinner: {
|
|
151
|
+
label: 'spinner',
|
|
152
|
+
display: 'inline-flex',
|
|
153
|
+
justifyContent: 'center',
|
|
154
|
+
alignItems: 'center',
|
|
155
|
+
boxSizing: 'border-box',
|
|
156
|
+
overflow: 'hidden',
|
|
157
|
+
verticalAlign: 'middle',
|
|
158
|
+
...spinnerSizes[size],
|
|
159
|
+
// TODO handle the merging on tokens inside the util
|
|
160
|
+
margin: (0, _emotion.calcSpacingFromShorthand)(margin, {
|
|
161
|
+
...sharedTokens.spacing,
|
|
162
|
+
...sharedTokens.legacy.spacing
|
|
163
|
+
})
|
|
164
|
+
},
|
|
165
|
+
circle: {
|
|
166
|
+
label: 'spinner__circle',
|
|
167
|
+
display: 'block',
|
|
168
|
+
animationName: rotate,
|
|
169
|
+
animationDuration: '2.25s',
|
|
170
|
+
animationIterationCount: 'infinite',
|
|
171
|
+
animationTimingFunction: 'linear',
|
|
172
|
+
...circleSizes[size]
|
|
173
|
+
},
|
|
174
|
+
circleTrack: {
|
|
175
|
+
label: 'spinner__circleTrack',
|
|
176
|
+
stroke: componentTheme.trackColor,
|
|
177
|
+
fill: 'none',
|
|
178
|
+
width: '100%',
|
|
179
|
+
height: '100%',
|
|
180
|
+
...circleTrackSizes[size]
|
|
181
|
+
},
|
|
182
|
+
circleSpin: {
|
|
183
|
+
label: 'spinner__circleSpin',
|
|
184
|
+
fill: 'none',
|
|
185
|
+
strokeLinecap: 'round',
|
|
186
|
+
animationName: morph,
|
|
187
|
+
animationDuration: '1.75s',
|
|
188
|
+
animationIterationCount: 'infinite',
|
|
189
|
+
animationTimingFunction: 'ease',
|
|
190
|
+
strokeDasharray: `calc(${radii[size]} * 2 * 3.14159 * 0.75) 1000px`,
|
|
191
|
+
...circleSpinSizes[size],
|
|
192
|
+
...circleSpinVariant[variant]
|
|
193
|
+
},
|
|
194
|
+
radius: radii[size]
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
var _default = exports.default = generateStyle;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "Spinner", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _v.Spinner;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
var
|
|
12
|
+
var _v = require("../Spinner/v1");
|
package/lib/exports/b.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-spinner",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A spinner/loading component",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,22 +15,22 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/console": "11.6.
|
|
19
|
-
"@instructure/emotion": "11.6.
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/
|
|
22
|
-
"@instructure/ui-react-utils": "11.6.
|
|
23
|
-
"@instructure/ui-utils": "11.6.
|
|
24
|
-
"@instructure/
|
|
25
|
-
"@instructure/
|
|
18
|
+
"@instructure/console": "11.6.1-snapshot-129",
|
|
19
|
+
"@instructure/emotion": "11.6.1-snapshot-129",
|
|
20
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/ui-color-utils": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/ui-react-utils": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-utils": "11.6.1-snapshot-129",
|
|
24
|
+
"@instructure/ui-view": "11.6.1-snapshot-129",
|
|
25
|
+
"@instructure/uid": "11.6.1-snapshot-129"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@testing-library/jest-dom": "^6.6.3",
|
|
29
29
|
"@testing-library/react": "15.0.7",
|
|
30
30
|
"vitest": "^3.2.2",
|
|
31
|
-
"@instructure/ui-axe-check": "11.6.
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-
|
|
31
|
+
"@instructure/ui-axe-check": "11.6.1-snapshot-129",
|
|
32
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129",
|
|
33
|
+
"@instructure/ui-themes": "11.6.1-snapshot-129"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18 <=19"
|
|
@@ -40,17 +40,39 @@
|
|
|
40
40
|
},
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"exports": {
|
|
43
|
-
".": {
|
|
44
|
-
"types": "./types/index.d.ts",
|
|
45
|
-
"import": "./es/index.js",
|
|
46
|
-
"require": "./lib/index.js",
|
|
47
|
-
"default": "./es/index.js"
|
|
48
|
-
},
|
|
49
43
|
"./lib/*": "./lib/*",
|
|
50
44
|
"./es/*": "./es/*",
|
|
51
45
|
"./types/*": "./types/*",
|
|
52
46
|
"./package.json": "./package.json",
|
|
53
|
-
"./src/*": "./src/*"
|
|
47
|
+
"./src/*": "./src/*",
|
|
48
|
+
".": {
|
|
49
|
+
"src": "./src/exports/a.ts",
|
|
50
|
+
"types": "./types/exports/a.d.ts",
|
|
51
|
+
"import": "./es/exports/a.js",
|
|
52
|
+
"require": "./lib/exports/a.js",
|
|
53
|
+
"default": "./es/exports/a.js"
|
|
54
|
+
},
|
|
55
|
+
"./v11_6": {
|
|
56
|
+
"src": "./src/exports/a.ts",
|
|
57
|
+
"types": "./types/exports/a.d.ts",
|
|
58
|
+
"import": "./es/exports/a.js",
|
|
59
|
+
"require": "./lib/exports/a.js",
|
|
60
|
+
"default": "./es/exports/a.js"
|
|
61
|
+
},
|
|
62
|
+
"./v11_7": {
|
|
63
|
+
"src": "./src/exports/b.ts",
|
|
64
|
+
"types": "./types/exports/b.d.ts",
|
|
65
|
+
"import": "./es/exports/b.js",
|
|
66
|
+
"require": "./lib/exports/b.js",
|
|
67
|
+
"default": "./es/exports/b.js"
|
|
68
|
+
},
|
|
69
|
+
"./latest": {
|
|
70
|
+
"src": "./src/exports/b.ts",
|
|
71
|
+
"types": "./types/exports/b.d.ts",
|
|
72
|
+
"import": "./es/exports/b.js",
|
|
73
|
+
"require": "./lib/exports/b.js",
|
|
74
|
+
"default": "./es/exports/b.js"
|
|
75
|
+
}
|
|
54
76
|
},
|
|
55
77
|
"scripts": {
|
|
56
78
|
"lint": "ui-scripts lint",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import { Component } from 'react'
|
|
26
26
|
|
|
27
|
-
import { View } from '@instructure/ui-view'
|
|
27
|
+
import { View } from '@instructure/ui-view/v11_6'
|
|
28
28
|
import {
|
|
29
29
|
callRenderProp,
|
|
30
30
|
omitProps,
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
} from '@instructure/ui-react-utils'
|
|
33
33
|
import { logError as error } from '@instructure/console'
|
|
34
34
|
|
|
35
|
-
import { withStyle } from '@instructure/emotion'
|
|
35
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
36
36
|
|
|
37
37
|
import generateStyle from './styles'
|
|
38
38
|
import generateComponentTheme from './theme'
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Spinner
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
### Choose from four sizes and add margin as needed
|
|
6
|
+
|
|
7
|
+
The `size` prop allows you to select from `x-small`, `small`, `medium` and `large`
|
|
8
|
+
-sized spinners. Margin can be added as needed using the `margin` prop.
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
---
|
|
12
|
+
type: example
|
|
13
|
+
---
|
|
14
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
|
|
15
|
+
<Spinner renderTitle="Loading" size="x-small" />
|
|
16
|
+
<Spinner renderTitle="Loading" size="small" />
|
|
17
|
+
<Spinner renderTitle="Loading" />
|
|
18
|
+
<Spinner renderTitle="Loading" size="large" />
|
|
19
|
+
</div>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### Different color schemes for use with light and dark backgrounds
|
|
23
|
+
|
|
24
|
+
Spinner provides an `inverse` color scheme designed to be used with
|
|
25
|
+
dark backgrounds.
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
---
|
|
29
|
+
type: example
|
|
30
|
+
---
|
|
31
|
+
<View background="primary-inverse" as="div" >
|
|
32
|
+
<Spinner renderTitle="Loading" variant="inverse" />
|
|
33
|
+
</View>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Delay rendering
|
|
37
|
+
|
|
38
|
+
The `delay` prop allows you to delay the rendering of the spinner a desired time to prevent flickering in cases of very fast load times.
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
---
|
|
42
|
+
type: example
|
|
43
|
+
---
|
|
44
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
|
|
45
|
+
<Spinner renderTitle="Loading" size="x-small" delay={1000} />
|
|
46
|
+
<Spinner renderTitle="Loading" size="small" delay={2000} />
|
|
47
|
+
<Spinner renderTitle="Loading" delay={3000} />
|
|
48
|
+
<Spinner renderTitle="Loading" size="large" delay={4000} />
|
|
49
|
+
</div>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Screen reader support
|
|
53
|
+
|
|
54
|
+
The `renderTitle` prop is read to screen readers.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
---
|
|
58
|
+
type: example
|
|
59
|
+
---
|
|
60
|
+
<div>
|
|
61
|
+
<Spinner renderTitle={() => "Hello world"} />
|
|
62
|
+
</div>
|
|
63
|
+
```
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { useState, useEffect, forwardRef } from 'react'
|
|
26
|
+
|
|
27
|
+
import { useStyle } from '@instructure/emotion'
|
|
28
|
+
import {
|
|
29
|
+
callRenderProp,
|
|
30
|
+
omitProps,
|
|
31
|
+
useDeterministicId
|
|
32
|
+
} from '@instructure/ui-react-utils'
|
|
33
|
+
import { logError as error } from '@instructure/console'
|
|
34
|
+
|
|
35
|
+
import generateStyle from './styles'
|
|
36
|
+
import type { SpinnerProps } from './props'
|
|
37
|
+
import { allowedProps } from './props'
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
---
|
|
41
|
+
category: components
|
|
42
|
+
---
|
|
43
|
+
**/
|
|
44
|
+
const Spinner = forwardRef<HTMLDivElement, SpinnerProps>((props, ref) => {
|
|
45
|
+
const {
|
|
46
|
+
size = 'medium',
|
|
47
|
+
variant = 'default',
|
|
48
|
+
delay,
|
|
49
|
+
renderTitle,
|
|
50
|
+
margin,
|
|
51
|
+
themeOverride
|
|
52
|
+
} = props
|
|
53
|
+
|
|
54
|
+
const [shouldRender, setShouldRender] = useState(!delay)
|
|
55
|
+
// Deterministic ID generation
|
|
56
|
+
const [titleId, setTitleId] = useState<string | undefined>()
|
|
57
|
+
const getId = useDeterministicId('Spinner')
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
setTitleId(getId())
|
|
60
|
+
}, [])
|
|
61
|
+
|
|
62
|
+
const styles = useStyle({
|
|
63
|
+
generateStyle,
|
|
64
|
+
themeOverride,
|
|
65
|
+
params: {
|
|
66
|
+
size,
|
|
67
|
+
variant,
|
|
68
|
+
margin
|
|
69
|
+
},
|
|
70
|
+
componentId: 'Spinner',
|
|
71
|
+
displayName: 'Spinner'
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (delay) {
|
|
76
|
+
const delayTimeout = setTimeout(() => {
|
|
77
|
+
setShouldRender(true)
|
|
78
|
+
}, delay)
|
|
79
|
+
|
|
80
|
+
return () => clearTimeout(delayTimeout)
|
|
81
|
+
}
|
|
82
|
+
return undefined
|
|
83
|
+
}, [delay])
|
|
84
|
+
|
|
85
|
+
const renderSpinner = () => {
|
|
86
|
+
error(
|
|
87
|
+
!!renderTitle,
|
|
88
|
+
'[Spinner] The `renderTitle` prop is necessary for screen reader support.'
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
const passthroughProps = omitProps(props, allowedProps)
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<div
|
|
95
|
+
{...passthroughProps}
|
|
96
|
+
css={styles?.spinner}
|
|
97
|
+
ref={ref}
|
|
98
|
+
data-cid="Spinner"
|
|
99
|
+
>
|
|
100
|
+
<svg
|
|
101
|
+
css={styles?.circle}
|
|
102
|
+
role="img"
|
|
103
|
+
aria-labelledby={titleId}
|
|
104
|
+
focusable="false"
|
|
105
|
+
>
|
|
106
|
+
<title id={titleId}>{callRenderProp(renderTitle)}</title>
|
|
107
|
+
<g role="presentation">
|
|
108
|
+
{variant !== 'inverse' && (
|
|
109
|
+
<circle
|
|
110
|
+
css={styles?.circleTrack}
|
|
111
|
+
cx="50%"
|
|
112
|
+
cy="50%"
|
|
113
|
+
r={styles?.radius as string}
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
<circle
|
|
117
|
+
css={styles?.circleSpin}
|
|
118
|
+
cx="50%"
|
|
119
|
+
cy="50%"
|
|
120
|
+
r={styles?.radius as string}
|
|
121
|
+
/>
|
|
122
|
+
</g>
|
|
123
|
+
</svg>
|
|
124
|
+
</div>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return shouldRender ? renderSpinner() : null
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
Spinner.displayName = 'Spinner'
|
|
132
|
+
|
|
133
|
+
export default Spinner
|
|
134
|
+
export { Spinner }
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type {
|
|
26
|
+
Spacing,
|
|
27
|
+
ComponentStyle,
|
|
28
|
+
ThemeOverrideValue
|
|
29
|
+
} from '@instructure/emotion'
|
|
30
|
+
import type { OtherHTMLAttributes } from '@instructure/shared-types'
|
|
31
|
+
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
|
|
32
|
+
import { Renderable } from '@instructure/shared-types'
|
|
33
|
+
|
|
34
|
+
type SpinnerOwnProps = {
|
|
35
|
+
/**
|
|
36
|
+
* delay spinner rendering for a time (in ms). Used to prevent flickering in case of very fast load times
|
|
37
|
+
*/
|
|
38
|
+
delay?: number
|
|
39
|
+
/**
|
|
40
|
+
* Valid values are `0`, `none`, `auto`, and Spacing token values,
|
|
41
|
+
* see https://instructure.design/layout-spacing. Apply these values via
|
|
42
|
+
* familiar CSS-like shorthand. For example, `gap="small auto large"`.
|
|
43
|
+
*/
|
|
44
|
+
margin?: Spacing
|
|
45
|
+
/**
|
|
46
|
+
* Give the spinner a title to be read by screenreaders
|
|
47
|
+
*/
|
|
48
|
+
renderTitle?: Renderable
|
|
49
|
+
/**
|
|
50
|
+
* Different-sized spinners
|
|
51
|
+
*/
|
|
52
|
+
size?: 'x-small' | 'small' | 'medium' | 'large'
|
|
53
|
+
/**
|
|
54
|
+
* Different color schemes for use with light or dark backgrounds
|
|
55
|
+
*/
|
|
56
|
+
variant?: 'default' | 'inverse'
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type PropKeys = keyof SpinnerOwnProps
|
|
60
|
+
|
|
61
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
62
|
+
|
|
63
|
+
type SpinnerProps = SpinnerOwnProps & {
|
|
64
|
+
themeOverride?: ThemeOverrideValue
|
|
65
|
+
} & OtherHTMLAttributes<SpinnerOwnProps> &
|
|
66
|
+
WithDeterministicIdProps
|
|
67
|
+
|
|
68
|
+
type SpinnerStyle = ComponentStyle<
|
|
69
|
+
'spinner' | 'circle' | 'circleTrack' | 'circleSpin' | 'radius'
|
|
70
|
+
>
|
|
71
|
+
|
|
72
|
+
const allowedProps: AllowedPropKeys = [
|
|
73
|
+
'delay',
|
|
74
|
+
'renderTitle',
|
|
75
|
+
'size',
|
|
76
|
+
'variant',
|
|
77
|
+
'margin'
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
export type { SpinnerProps, SpinnerStyle }
|
|
81
|
+
export { allowedProps }
|