@instructure/ui-skeleton 0.0.0-stage → 0.0.1-bootstrap-0
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 +0 -0
- package/LICENSE.md +28 -0
- package/README.md +50 -2
- package/es/SkeletonCircle/index.js +68 -0
- package/es/SkeletonCircle/props.js +26 -0
- package/es/SkeletonCircle/styles.js +47 -0
- package/es/SkeletonLoader/index.js +104 -0
- package/es/SkeletonLoader/props.js +26 -0
- package/es/SkeletonLoader/styles.js +45 -0
- package/es/SkeletonRectangle/index.js +74 -0
- package/es/SkeletonRectangle/props.js +26 -0
- package/es/SkeletonRectangle/styles.js +52 -0
- package/es/SkeletonText/index.js +76 -0
- package/es/SkeletonText/props.js +26 -0
- package/es/SkeletonText/styles.js +95 -0
- package/es/index.js +25 -0
- package/es/utils/shimmer.js +81 -0
- package/lib/SkeletonCircle/index.js +75 -0
- package/lib/SkeletonCircle/props.js +31 -0
- package/lib/SkeletonCircle/styles.js +53 -0
- package/lib/SkeletonLoader/index.js +110 -0
- package/lib/SkeletonLoader/props.js +31 -0
- package/lib/SkeletonLoader/styles.js +51 -0
- package/lib/SkeletonRectangle/index.js +81 -0
- package/lib/SkeletonRectangle/props.js +31 -0
- package/lib/SkeletonRectangle/styles.js +58 -0
- package/lib/SkeletonText/index.js +83 -0
- package/lib/SkeletonText/props.js +31 -0
- package/lib/SkeletonText/styles.js +101 -0
- package/lib/index.js +12 -0
- package/lib/package.json +1 -0
- package/lib/utils/shimmer.js +87 -0
- package/package.json +70 -3
- package/src/SkeletonCircle/index.tsx +71 -0
- package/src/SkeletonCircle/props.ts +58 -0
- package/src/SkeletonCircle/styles.ts +61 -0
- package/src/SkeletonLoader/README.md +237 -0
- package/src/SkeletonLoader/index.tsx +126 -0
- package/src/SkeletonLoader/props.ts +100 -0
- package/src/SkeletonLoader/styles.ts +51 -0
- package/src/SkeletonRectangle/index.tsx +71 -0
- package/src/SkeletonRectangle/props.ts +81 -0
- package/src/SkeletonRectangle/styles.ts +69 -0
- package/src/SkeletonText/index.tsx +74 -0
- package/src/SkeletonText/props.ts +91 -0
- package/src/SkeletonText/styles.ts +115 -0
- package/src/index.ts +38 -0
- package/src/utils/shimmer.ts +101 -0
- package/tsconfig.build.json +32 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +4 -0
- package/types/SkeletonCircle/index.d.ts +18 -0
- package/types/SkeletonCircle/index.d.ts.map +1 -0
- package/types/SkeletonCircle/props.d.ts +23 -0
- package/types/SkeletonCircle/props.d.ts.map +1 -0
- package/types/SkeletonCircle/styles.d.ts +13 -0
- package/types/SkeletonCircle/styles.d.ts.map +1 -0
- package/types/SkeletonLoader/index.d.ts +27 -0
- package/types/SkeletonLoader/index.d.ts.map +1 -0
- package/types/SkeletonLoader/props.d.ts +52 -0
- package/types/SkeletonLoader/props.d.ts.map +1 -0
- package/types/SkeletonLoader/styles.d.ts +11 -0
- package/types/SkeletonLoader/styles.d.ts.map +1 -0
- package/types/SkeletonRectangle/index.d.ts +18 -0
- package/types/SkeletonRectangle/index.d.ts.map +1 -0
- package/types/SkeletonRectangle/props.d.ts +36 -0
- package/types/SkeletonRectangle/props.d.ts.map +1 -0
- package/types/SkeletonRectangle/styles.d.ts +16 -0
- package/types/SkeletonRectangle/styles.d.ts.map +1 -0
- package/types/SkeletonText/index.d.ts +17 -0
- package/types/SkeletonText/index.d.ts.map +1 -0
- package/types/SkeletonText/props.d.ts +43 -0
- package/types/SkeletonText/props.d.ts.map +1 -0
- package/types/SkeletonText/styles.d.ts +16 -0
- package/types/SkeletonText/styles.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
- package/types/utils/shimmer.d.ts +28 -0
- package/types/utils/shimmer.d.ts.map +1 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateStyle = exports.default = void 0;
|
|
7
|
+
var _shimmer = require("../utils/shimmer.js");
|
|
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
|
+
const generateStyle = (componentTheme, params, _sharedTokens) => {
|
|
33
|
+
const {
|
|
34
|
+
animate = true,
|
|
35
|
+
aspectRatio = '16 / 9',
|
|
36
|
+
height,
|
|
37
|
+
radius,
|
|
38
|
+
width,
|
|
39
|
+
textDirection
|
|
40
|
+
} = params;
|
|
41
|
+
return {
|
|
42
|
+
skeletonRectangle: {
|
|
43
|
+
label: 'skeletonRectangle',
|
|
44
|
+
display: 'block',
|
|
45
|
+
boxSizing: 'border-box',
|
|
46
|
+
width: width ?? '100%',
|
|
47
|
+
...(height ? {
|
|
48
|
+
height
|
|
49
|
+
} : {
|
|
50
|
+
aspectRatio
|
|
51
|
+
}),
|
|
52
|
+
borderRadius: radius ?? componentTheme.imageBorderRadius,
|
|
53
|
+
...(0, _shimmer.shimmerStyles)(componentTheme, textDirection === 'rtl', animate)
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
exports.generateStyle = generateStyle;
|
|
58
|
+
var _default = exports.default = generateStyle;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SkeletonText = SkeletonText;
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _emotion = require("@instructure/emotion");
|
|
11
|
+
var _uiI18n = require("@instructure/ui-i18n");
|
|
12
|
+
var _uiReactUtils = require("@instructure/ui-react-utils");
|
|
13
|
+
var _styles = _interopRequireDefault(require("./styles.js"));
|
|
14
|
+
var _props = require("./props.js");
|
|
15
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
16
|
+
/*
|
|
17
|
+
* The MIT License (MIT)
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
* in the Software without restriction, including without limitation the rights
|
|
24
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
* furnished to do so, subject to the following conditions:
|
|
27
|
+
*
|
|
28
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
* copies or substantial portions of the Software.
|
|
30
|
+
*
|
|
31
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
* SOFTWARE.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
---
|
|
42
|
+
parent: SkeletonLoader
|
|
43
|
+
id: SkeletonLoader.Text
|
|
44
|
+
---
|
|
45
|
+
A placeholder for one or more lines of text. It's hidden from screen readers.
|
|
46
|
+
**/
|
|
47
|
+
function SkeletonText(props) {
|
|
48
|
+
const {
|
|
49
|
+
animate,
|
|
50
|
+
elementRef,
|
|
51
|
+
lineHeight,
|
|
52
|
+
lines,
|
|
53
|
+
size,
|
|
54
|
+
width
|
|
55
|
+
} = props;
|
|
56
|
+
const textDirection = (0, _react.useContext)(_uiI18n.TextDirectionContext);
|
|
57
|
+
const styles = (0, _emotion.useStyleNew)({
|
|
58
|
+
generateStyle: _styles.default,
|
|
59
|
+
componentId: 'SkeletonLoader',
|
|
60
|
+
displayName: 'SkeletonText',
|
|
61
|
+
params: {
|
|
62
|
+
animate,
|
|
63
|
+
lineHeight,
|
|
64
|
+
lines,
|
|
65
|
+
size,
|
|
66
|
+
width,
|
|
67
|
+
textDirection
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return (0, _jsxRuntime.jsx)("span", {
|
|
71
|
+
...(0, _uiReactUtils.omitProps)(props, _props.allowedProps),
|
|
72
|
+
ref: elementRef,
|
|
73
|
+
css: styles.skeletonText,
|
|
74
|
+
"aria-hidden": "true",
|
|
75
|
+
"data-skeleton-shape": "text",
|
|
76
|
+
children: styles.rows.map((rowStyle, i) => (0, _jsxRuntime.jsx)("span", {
|
|
77
|
+
css: rowStyle
|
|
78
|
+
}, i))
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
SkeletonText.displayName = 'SkeletonText';
|
|
82
|
+
SkeletonText.allowedProps = _props.allowedProps;
|
|
83
|
+
var _default = exports.default = SkeletonText;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const allowedProps = exports.allowedProps = ['animate', 'elementRef', 'lineHeight', 'lines', 'size', 'width'];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateStyle = exports.default = void 0;
|
|
7
|
+
var _shimmer = require("../utils/shimmer.js");
|
|
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
|
+
const LINE_HEIGHTS = {
|
|
33
|
+
heading: 1.25,
|
|
34
|
+
text: 1.5
|
|
35
|
+
};
|
|
36
|
+
const generateStyle = (componentTheme, params, _sharedTokens) => {
|
|
37
|
+
const {
|
|
38
|
+
animate = true,
|
|
39
|
+
lineHeight = 'heading',
|
|
40
|
+
lines = 1,
|
|
41
|
+
size = 'md',
|
|
42
|
+
width,
|
|
43
|
+
textDirection
|
|
44
|
+
} = params;
|
|
45
|
+
const shimmer = (0, _shimmer.shimmerStyles)(componentTheme, textDirection === 'rtl', animate);
|
|
46
|
+
const fontSizes = {
|
|
47
|
+
xs: componentTheme.textHeightXs,
|
|
48
|
+
sm: componentTheme.textHeightSm,
|
|
49
|
+
md: componentTheme.textHeightMd,
|
|
50
|
+
lg: componentTheme.textHeightLg,
|
|
51
|
+
xl: componentTheme.textHeightXl,
|
|
52
|
+
xxl: componentTheme.textHeightXxl
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// Each bar is as tall as the font size (1em). The rest of the line height is
|
|
56
|
+
// split into equal padding above and below it, so a line takes up exactly
|
|
57
|
+
// `lineHeight x font-size`, the same as a line of real text.
|
|
58
|
+
const row = `${LINE_HEIGHTS[lineHeight]}em`;
|
|
59
|
+
const bar = {
|
|
60
|
+
display: 'block',
|
|
61
|
+
boxSizing: 'content-box',
|
|
62
|
+
height: '1em',
|
|
63
|
+
padding: `calc((${row} - 1em) / 2) 0`,
|
|
64
|
+
backgroundClip: 'content-box',
|
|
65
|
+
borderRadius: componentTheme.textBorderRadius,
|
|
66
|
+
...shimmer
|
|
67
|
+
};
|
|
68
|
+
const block = {
|
|
69
|
+
label: 'skeletonText',
|
|
70
|
+
display: 'block',
|
|
71
|
+
fontSize: fontSizes[size] ?? componentTheme.textHeightMd,
|
|
72
|
+
width: width ?? '100%'
|
|
73
|
+
};
|
|
74
|
+
if (lines <= 1) {
|
|
75
|
+
return {
|
|
76
|
+
skeletonText: {
|
|
77
|
+
...block,
|
|
78
|
+
...bar
|
|
79
|
+
},
|
|
80
|
+
rows: []
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Each line is its own element so every bar gets rounded ends.
|
|
85
|
+
return {
|
|
86
|
+
skeletonText: {
|
|
87
|
+
...block,
|
|
88
|
+
boxSizing: 'border-box',
|
|
89
|
+
height: `calc(${lines} * ${row})`
|
|
90
|
+
},
|
|
91
|
+
rows: Array.from({
|
|
92
|
+
length: lines
|
|
93
|
+
}, (_unused, i) => ({
|
|
94
|
+
label: 'skeletonText__row',
|
|
95
|
+
...bar,
|
|
96
|
+
width: i === lines - 1 ? '75%' : '100%'
|
|
97
|
+
}))
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.generateStyle = generateStyle;
|
|
101
|
+
var _default = exports.default = generateStyle;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "SkeletonLoader", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _index.SkeletonLoader;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _index = require("./SkeletonLoader/index.js");
|
package/lib/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.shimmerStyles = 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
|
+
/**
|
|
33
|
+
* The gradient is twice as wide as the shape. A percentage
|
|
34
|
+
* `background-position` can't move a background that is exactly as wide as
|
|
35
|
+
* its element, so it needs the extra width to slide across.
|
|
36
|
+
*/
|
|
37
|
+
const GRADIENT_SCALE = 2;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Highlight positions, as a fraction of the shape's width. At `ENTER` and
|
|
41
|
+
* `EXIT` the highlight is fully outside the shape, so the jump from the end of
|
|
42
|
+
* one loop to the start of the next isn't visible. `REST` is where it sits when
|
|
43
|
+
* the shape isn't animating.
|
|
44
|
+
*/
|
|
45
|
+
const HIGHLIGHT_ENTER = -0.5;
|
|
46
|
+
const HIGHLIGHT_EXIT = 1.5;
|
|
47
|
+
const HIGHLIGHT_REST = 0.3;
|
|
48
|
+
|
|
49
|
+
/** Converts a highlight position into a `background-position` percentage. */
|
|
50
|
+
const positionFor = highlight => `${(1 - highlight) * 100 * (GRADIENT_SCALE - 1)}% 0`;
|
|
51
|
+
|
|
52
|
+
// Defined once at module scope. Creating keyframes inside a style function
|
|
53
|
+
// generates a new animation name on every render (same as Spinner v2).
|
|
54
|
+
const sweep = isRtl => (0, _emotion.keyframes)`
|
|
55
|
+
from { background-position: ${positionFor(isRtl ? HIGHLIGHT_EXIT : HIGHLIGHT_ENTER)}; }
|
|
56
|
+
to { background-position: ${positionFor(isRtl ? HIGHLIGHT_ENTER : HIGHLIGHT_EXIT)}; }
|
|
57
|
+
`;
|
|
58
|
+
const sweepLtr = sweep(false);
|
|
59
|
+
const sweepRtl = sweep(true);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The fill shared by every shape: a base color with a highlight that sweeps
|
|
63
|
+
* across it. The gradient fades back to the base color rather than to
|
|
64
|
+
* `transparent`, which would show a dark band in some browsers.
|
|
65
|
+
*/
|
|
66
|
+
const shimmerStyles = (componentTheme, isRtl, animate) => {
|
|
67
|
+
const base = componentTheme.backgroundColor;
|
|
68
|
+
const highlight = componentTheme.shimmerColor;
|
|
69
|
+
return {
|
|
70
|
+
backgroundColor: base,
|
|
71
|
+
backgroundImage: `linear-gradient(90deg, ${base} 0%, ${base} 25%, ${highlight} 50%, ${base} 75%, ${base} 100%)`,
|
|
72
|
+
backgroundRepeat: 'no-repeat',
|
|
73
|
+
backgroundSize: `${GRADIENT_SCALE * 100}% 100%`,
|
|
74
|
+
backgroundPosition: positionFor(isRtl ? 1 - HIGHLIGHT_REST : HIGHLIGHT_REST),
|
|
75
|
+
...(animate ? {
|
|
76
|
+
// The animation loops until the skeleton is removed, so it only runs
|
|
77
|
+
// when the user hasn't asked for reduced motion (WCAG 2.2.2).
|
|
78
|
+
'@media (prefers-reduced-motion: no-preference)': {
|
|
79
|
+
animationName: isRtl ? sweepRtl : sweepLtr,
|
|
80
|
+
animationDuration: componentTheme.duration,
|
|
81
|
+
animationTimingFunction: `cubic-bezier(${componentTheme.bezier})`,
|
|
82
|
+
animationIterationCount: 'infinite'
|
|
83
|
+
}
|
|
84
|
+
} : {})
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.shimmerStyles = shimmerStyles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-skeleton",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.1-bootstrap-0",
|
|
4
|
+
"description": "Skeleton loader primitives that render a correctly sized placeholder from server HTML, with no DOM measurement.",
|
|
5
|
+
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
|
+
"module": "./es/index.js",
|
|
7
|
+
"main": "./lib/index.js",
|
|
8
|
+
"types": "./types/index.d.ts",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/instructure/instructure-ui.git"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://instructure.github.io/instructure-ui/",
|
|
14
|
+
"bugs": "https://github.com/instructure/instructure-ui/issues",
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/runtime": "^7.29.7",
|
|
18
|
+
"@instructure/emotion": "11.7.10",
|
|
19
|
+
"@instructure/shared-types": "11.7.10",
|
|
20
|
+
"@instructure/ui-i18n": "11.7.10",
|
|
21
|
+
"@instructure/ui-react-utils": "11.7.10",
|
|
22
|
+
"@instructure/ui-themes": "11.7.10"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@instructure/ui-axe-check": "11.7.10",
|
|
26
|
+
"@instructure/ui-babel-preset": "11.7.10",
|
|
27
|
+
"vitest": "^5.0.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"react": ">=18 <=19"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"exports": {
|
|
37
|
+
"./lib/*": "./lib/*",
|
|
38
|
+
"./es/*": "./es/*",
|
|
39
|
+
"./types/*": "./types/*",
|
|
40
|
+
"./package.json": "./package.json",
|
|
41
|
+
"./src/*": "./src/*",
|
|
42
|
+
".": {
|
|
43
|
+
"src": "./src/index.ts",
|
|
44
|
+
"types": "./types/index.d.ts",
|
|
45
|
+
"import": "./es/index.js",
|
|
46
|
+
"require": "./lib/index.js",
|
|
47
|
+
"default": "./es/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./v11_7": {
|
|
50
|
+
"src": "./src/index.ts",
|
|
51
|
+
"types": "./types/index.d.ts",
|
|
52
|
+
"import": "./es/index.js",
|
|
53
|
+
"require": "./lib/index.js",
|
|
54
|
+
"default": "./es/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./latest": {
|
|
57
|
+
"src": "./src/index.ts",
|
|
58
|
+
"types": "./types/index.d.ts",
|
|
59
|
+
"import": "./es/index.js",
|
|
60
|
+
"require": "./lib/index.js",
|
|
61
|
+
"default": "./es/index.js"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"lint": "ui-scripts lint",
|
|
66
|
+
"lint:fix": "ui-scripts lint --fix",
|
|
67
|
+
"clean": "ui-scripts clean",
|
|
68
|
+
"build": "ui-scripts build --modules es,cjs",
|
|
69
|
+
"build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
|
|
70
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
71
|
+
"ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
|
|
72
|
+
}
|
|
6
73
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { useContext } from 'react'
|
|
26
|
+
|
|
27
|
+
import { useStyleNew } from '@instructure/emotion'
|
|
28
|
+
import { TextDirectionContext } from '@instructure/ui-i18n'
|
|
29
|
+
import { omitProps } from '@instructure/ui-react-utils'
|
|
30
|
+
|
|
31
|
+
import generateStyle from './styles.js'
|
|
32
|
+
import { allowedProps } from './props.js'
|
|
33
|
+
import type { SkeletonLoaderTheme } from '../utils/shimmer'
|
|
34
|
+
import type { SkeletonCircleProps } from './props'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
---
|
|
38
|
+
parent: SkeletonLoader
|
|
39
|
+
id: SkeletonLoader.Circle
|
|
40
|
+
---
|
|
41
|
+
A placeholder for avatars and other round content. It's hidden from screen
|
|
42
|
+
readers.
|
|
43
|
+
**/
|
|
44
|
+
function SkeletonCircle(props: SkeletonCircleProps) {
|
|
45
|
+
const { animate, diameter, elementRef } = props
|
|
46
|
+
|
|
47
|
+
const textDirection = useContext(TextDirectionContext)
|
|
48
|
+
|
|
49
|
+
const styles = useStyleNew<SkeletonLoaderTheme, typeof generateStyle>({
|
|
50
|
+
generateStyle,
|
|
51
|
+
componentId: 'SkeletonLoader',
|
|
52
|
+
displayName: 'SkeletonCircle',
|
|
53
|
+
params: { animate, diameter, textDirection }
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<span
|
|
58
|
+
{...omitProps(props, allowedProps)}
|
|
59
|
+
ref={elementRef}
|
|
60
|
+
css={styles.skeletonCircle}
|
|
61
|
+
aria-hidden="true"
|
|
62
|
+
data-skeleton-shape="circle"
|
|
63
|
+
/>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
SkeletonCircle.displayName = 'SkeletonCircle'
|
|
68
|
+
SkeletonCircle.allowedProps = allowedProps
|
|
69
|
+
|
|
70
|
+
export default SkeletonCircle
|
|
71
|
+
export { SkeletonCircle }
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { OtherHTMLAttributes } from '@instructure/shared-types'
|
|
26
|
+
import type { ComponentStyle } from '@instructure/emotion'
|
|
27
|
+
|
|
28
|
+
type SkeletonCircleOwnProps = {
|
|
29
|
+
/**
|
|
30
|
+
* Set to `false` to turn off the animation, whatever the user's motion
|
|
31
|
+
* setting. Useful for snapshot and visual regression tests.
|
|
32
|
+
*/
|
|
33
|
+
animate?: boolean
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Diameter of the circle.
|
|
37
|
+
*/
|
|
38
|
+
diameter?: string | number
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Provides a reference to the underlying HTML element.
|
|
42
|
+
*/
|
|
43
|
+
elementRef?: (element: Element | null) => void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type SkeletonCircleStyle = ComponentStyle<'skeletonCircle'>
|
|
47
|
+
|
|
48
|
+
type SkeletonCircleProps = SkeletonCircleOwnProps &
|
|
49
|
+
OtherHTMLAttributes<SkeletonCircleOwnProps>
|
|
50
|
+
|
|
51
|
+
const allowedProps: (keyof SkeletonCircleOwnProps)[] = [
|
|
52
|
+
'animate',
|
|
53
|
+
'diameter',
|
|
54
|
+
'elementRef'
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
export { allowedProps }
|
|
58
|
+
export type { SkeletonCircleOwnProps, SkeletonCircleProps, SkeletonCircleStyle }
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { SharedTokens } from '@instructure/ui-themes'
|
|
26
|
+
|
|
27
|
+
import { shimmerStyles } from '../utils/shimmer.js'
|
|
28
|
+
import type { SkeletonLoaderTheme } from '../utils/shimmer'
|
|
29
|
+
import type { SkeletonCircleProps, SkeletonCircleStyle } from './props'
|
|
30
|
+
|
|
31
|
+
type StyleParams = {
|
|
32
|
+
animate: SkeletonCircleProps['animate']
|
|
33
|
+
diameter: SkeletonCircleProps['diameter']
|
|
34
|
+
textDirection: 'ltr' | 'rtl' | 'auto'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const generateStyle = (
|
|
38
|
+
componentTheme: SkeletonLoaderTheme,
|
|
39
|
+
params: StyleParams,
|
|
40
|
+
_sharedTokens?: SharedTokens
|
|
41
|
+
): SkeletonCircleStyle => {
|
|
42
|
+
const { animate = true, diameter = '2rem', textDirection } = params
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
skeletonCircle: {
|
|
46
|
+
label: 'skeletonCircle',
|
|
47
|
+
display: 'inline-block',
|
|
48
|
+
verticalAlign: 'middle',
|
|
49
|
+
boxSizing: 'border-box',
|
|
50
|
+
width: diameter,
|
|
51
|
+
height: diameter,
|
|
52
|
+
flex: '0 0 auto',
|
|
53
|
+
borderRadius: componentTheme.avatarBorderRadius,
|
|
54
|
+
...shimmerStyles(componentTheme, textDirection === 'rtl', animate)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default generateStyle
|
|
60
|
+
export { generateStyle }
|
|
61
|
+
export type { StyleParams }
|