@instructure/ui-skeleton 0.0.0-stage → 11.7.11-snapshot-4

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE.md +28 -0
  3. package/README.md +50 -2
  4. package/es/SkeletonCircle/index.js +68 -0
  5. package/es/SkeletonCircle/props.js +26 -0
  6. package/es/SkeletonCircle/styles.js +47 -0
  7. package/es/SkeletonLoader/index.js +104 -0
  8. package/es/SkeletonLoader/props.js +26 -0
  9. package/es/SkeletonLoader/styles.js +45 -0
  10. package/es/SkeletonRectangle/index.js +74 -0
  11. package/es/SkeletonRectangle/props.js +26 -0
  12. package/es/SkeletonRectangle/styles.js +52 -0
  13. package/es/SkeletonText/index.js +76 -0
  14. package/es/SkeletonText/props.js +26 -0
  15. package/es/SkeletonText/styles.js +95 -0
  16. package/es/index.js +25 -0
  17. package/es/utils/shimmer.js +81 -0
  18. package/lib/SkeletonCircle/index.js +75 -0
  19. package/lib/SkeletonCircle/props.js +31 -0
  20. package/lib/SkeletonCircle/styles.js +53 -0
  21. package/lib/SkeletonLoader/index.js +110 -0
  22. package/lib/SkeletonLoader/props.js +31 -0
  23. package/lib/SkeletonLoader/styles.js +51 -0
  24. package/lib/SkeletonRectangle/index.js +81 -0
  25. package/lib/SkeletonRectangle/props.js +31 -0
  26. package/lib/SkeletonRectangle/styles.js +58 -0
  27. package/lib/SkeletonText/index.js +83 -0
  28. package/lib/SkeletonText/props.js +31 -0
  29. package/lib/SkeletonText/styles.js +101 -0
  30. package/lib/index.js +12 -0
  31. package/lib/package.json +1 -0
  32. package/lib/utils/shimmer.js +87 -0
  33. package/package.json +70 -3
  34. package/src/SkeletonCircle/index.tsx +71 -0
  35. package/src/SkeletonCircle/props.ts +58 -0
  36. package/src/SkeletonCircle/styles.ts +61 -0
  37. package/src/SkeletonLoader/README.md +237 -0
  38. package/src/SkeletonLoader/index.tsx +126 -0
  39. package/src/SkeletonLoader/props.ts +100 -0
  40. package/src/SkeletonLoader/styles.ts +51 -0
  41. package/src/SkeletonRectangle/index.tsx +71 -0
  42. package/src/SkeletonRectangle/props.ts +81 -0
  43. package/src/SkeletonRectangle/styles.ts +69 -0
  44. package/src/SkeletonText/index.tsx +74 -0
  45. package/src/SkeletonText/props.ts +91 -0
  46. package/src/SkeletonText/styles.ts +115 -0
  47. package/src/index.ts +38 -0
  48. package/src/utils/shimmer.ts +101 -0
  49. package/tsconfig.build.json +32 -0
  50. package/tsconfig.build.tsbuildinfo +1 -0
  51. package/tsconfig.json +4 -0
  52. package/types/SkeletonCircle/index.d.ts +18 -0
  53. package/types/SkeletonCircle/index.d.ts.map +1 -0
  54. package/types/SkeletonCircle/props.d.ts +23 -0
  55. package/types/SkeletonCircle/props.d.ts.map +1 -0
  56. package/types/SkeletonCircle/styles.d.ts +13 -0
  57. package/types/SkeletonCircle/styles.d.ts.map +1 -0
  58. package/types/SkeletonLoader/index.d.ts +27 -0
  59. package/types/SkeletonLoader/index.d.ts.map +1 -0
  60. package/types/SkeletonLoader/props.d.ts +52 -0
  61. package/types/SkeletonLoader/props.d.ts.map +1 -0
  62. package/types/SkeletonLoader/styles.d.ts +11 -0
  63. package/types/SkeletonLoader/styles.d.ts.map +1 -0
  64. package/types/SkeletonRectangle/index.d.ts +18 -0
  65. package/types/SkeletonRectangle/index.d.ts.map +1 -0
  66. package/types/SkeletonRectangle/props.d.ts +36 -0
  67. package/types/SkeletonRectangle/props.d.ts.map +1 -0
  68. package/types/SkeletonRectangle/styles.d.ts +16 -0
  69. package/types/SkeletonRectangle/styles.d.ts.map +1 -0
  70. package/types/SkeletonText/index.d.ts +17 -0
  71. package/types/SkeletonText/index.d.ts.map +1 -0
  72. package/types/SkeletonText/props.d.ts +43 -0
  73. package/types/SkeletonText/props.d.ts.map +1 -0
  74. package/types/SkeletonText/styles.d.ts +16 -0
  75. package/types/SkeletonText/styles.d.ts.map +1 -0
  76. package/types/index.d.ts +7 -0
  77. package/types/index.d.ts.map +1 -0
  78. package/types/utils/shimmer.d.ts +28 -0
  79. package/types/utils/shimmer.d.ts.map +1 -0
@@ -0,0 +1,95 @@
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 { shimmerStyles } from '../utils/shimmer.js';
26
+ const LINE_HEIGHTS = {
27
+ heading: 1.25,
28
+ text: 1.5
29
+ };
30
+ const generateStyle = (componentTheme, params, _sharedTokens) => {
31
+ const {
32
+ animate = true,
33
+ lineHeight = 'heading',
34
+ lines = 1,
35
+ size = 'md',
36
+ width,
37
+ textDirection
38
+ } = params;
39
+ const shimmer = shimmerStyles(componentTheme, textDirection === 'rtl', animate);
40
+ const fontSizes = {
41
+ xs: componentTheme.textHeightXs,
42
+ sm: componentTheme.textHeightSm,
43
+ md: componentTheme.textHeightMd,
44
+ lg: componentTheme.textHeightLg,
45
+ xl: componentTheme.textHeightXl,
46
+ xxl: componentTheme.textHeightXxl
47
+ };
48
+
49
+ // Each bar is as tall as the font size (1em). The rest of the line height is
50
+ // split into equal padding above and below it, so a line takes up exactly
51
+ // `lineHeight x font-size`, the same as a line of real text.
52
+ const row = `${LINE_HEIGHTS[lineHeight]}em`;
53
+ const bar = {
54
+ display: 'block',
55
+ boxSizing: 'content-box',
56
+ height: '1em',
57
+ padding: `calc((${row} - 1em) / 2) 0`,
58
+ backgroundClip: 'content-box',
59
+ borderRadius: componentTheme.textBorderRadius,
60
+ ...shimmer
61
+ };
62
+ const block = {
63
+ label: 'skeletonText',
64
+ display: 'block',
65
+ fontSize: fontSizes[size] ?? componentTheme.textHeightMd,
66
+ width: width ?? '100%'
67
+ };
68
+ if (lines <= 1) {
69
+ return {
70
+ skeletonText: {
71
+ ...block,
72
+ ...bar
73
+ },
74
+ rows: []
75
+ };
76
+ }
77
+
78
+ // Each line is its own element so every bar gets rounded ends.
79
+ return {
80
+ skeletonText: {
81
+ ...block,
82
+ boxSizing: 'border-box',
83
+ height: `calc(${lines} * ${row})`
84
+ },
85
+ rows: Array.from({
86
+ length: lines
87
+ }, (_unused, i) => ({
88
+ label: 'skeletonText__row',
89
+ ...bar,
90
+ width: i === lines - 1 ? '75%' : '100%'
91
+ }))
92
+ };
93
+ };
94
+ export default generateStyle;
95
+ export { generateStyle };
package/es/index.js ADDED
@@ -0,0 +1,25 @@
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
+ export { SkeletonLoader } from './SkeletonLoader/index.js';
@@ -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 { keyframes } from '@instructure/emotion';
26
+ /**
27
+ * The gradient is twice as wide as the shape. A percentage
28
+ * `background-position` can't move a background that is exactly as wide as
29
+ * its element, so it needs the extra width to slide across.
30
+ */
31
+ const GRADIENT_SCALE = 2;
32
+
33
+ /**
34
+ * Highlight positions, as a fraction of the shape's width. At `ENTER` and
35
+ * `EXIT` the highlight is fully outside the shape, so the jump from the end of
36
+ * one loop to the start of the next isn't visible. `REST` is where it sits when
37
+ * the shape isn't animating.
38
+ */
39
+ const HIGHLIGHT_ENTER = -0.5;
40
+ const HIGHLIGHT_EXIT = 1.5;
41
+ const HIGHLIGHT_REST = 0.3;
42
+
43
+ /** Converts a highlight position into a `background-position` percentage. */
44
+ const positionFor = highlight => `${(1 - highlight) * 100 * (GRADIENT_SCALE - 1)}% 0`;
45
+
46
+ // Defined once at module scope. Creating keyframes inside a style function
47
+ // generates a new animation name on every render (same as Spinner v2).
48
+ const sweep = isRtl => keyframes`
49
+ from { background-position: ${positionFor(isRtl ? HIGHLIGHT_EXIT : HIGHLIGHT_ENTER)}; }
50
+ to { background-position: ${positionFor(isRtl ? HIGHLIGHT_ENTER : HIGHLIGHT_EXIT)}; }
51
+ `;
52
+ const sweepLtr = sweep(false);
53
+ const sweepRtl = sweep(true);
54
+
55
+ /**
56
+ * The fill shared by every shape: a base color with a highlight that sweeps
57
+ * across it. The gradient fades back to the base color rather than to
58
+ * `transparent`, which would show a dark band in some browsers.
59
+ */
60
+ const shimmerStyles = (componentTheme, isRtl, animate) => {
61
+ const base = componentTheme.backgroundColor;
62
+ const highlight = componentTheme.shimmerColor;
63
+ return {
64
+ backgroundColor: base,
65
+ backgroundImage: `linear-gradient(90deg, ${base} 0%, ${base} 25%, ${highlight} 50%, ${base} 75%, ${base} 100%)`,
66
+ backgroundRepeat: 'no-repeat',
67
+ backgroundSize: `${GRADIENT_SCALE * 100}% 100%`,
68
+ backgroundPosition: positionFor(isRtl ? 1 - HIGHLIGHT_REST : HIGHLIGHT_REST),
69
+ ...(animate ? {
70
+ // The animation loops until the skeleton is removed, so it only runs
71
+ // when the user hasn't asked for reduced motion (WCAG 2.2.2).
72
+ '@media (prefers-reduced-motion: no-preference)': {
73
+ animationName: isRtl ? sweepRtl : sweepLtr,
74
+ animationDuration: componentTheme.duration,
75
+ animationTimingFunction: `cubic-bezier(${componentTheme.bezier})`,
76
+ animationIterationCount: 'infinite'
77
+ }
78
+ } : {})
79
+ };
80
+ };
81
+ export { shimmerStyles };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SkeletonCircle = SkeletonCircle;
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.Circle
44
+ ---
45
+ A placeholder for avatars and other round content. It's hidden from screen
46
+ readers.
47
+ **/
48
+ function SkeletonCircle(props) {
49
+ const {
50
+ animate,
51
+ diameter,
52
+ elementRef
53
+ } = props;
54
+ const textDirection = (0, _react.useContext)(_uiI18n.TextDirectionContext);
55
+ const styles = (0, _emotion.useStyleNew)({
56
+ generateStyle: _styles.default,
57
+ componentId: 'SkeletonLoader',
58
+ displayName: 'SkeletonCircle',
59
+ params: {
60
+ animate,
61
+ diameter,
62
+ textDirection
63
+ }
64
+ });
65
+ return (0, _jsxRuntime.jsx)("span", {
66
+ ...(0, _uiReactUtils.omitProps)(props, _props.allowedProps),
67
+ ref: elementRef,
68
+ css: styles.skeletonCircle,
69
+ "aria-hidden": "true",
70
+ "data-skeleton-shape": "circle"
71
+ });
72
+ }
73
+ SkeletonCircle.displayName = 'SkeletonCircle';
74
+ SkeletonCircle.allowedProps = _props.allowedProps;
75
+ var _default = exports.default = SkeletonCircle;
@@ -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', 'diameter', 'elementRef'];
@@ -0,0 +1,53 @@
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
+ diameter = '2rem',
36
+ textDirection
37
+ } = params;
38
+ return {
39
+ skeletonCircle: {
40
+ label: 'skeletonCircle',
41
+ display: 'inline-block',
42
+ verticalAlign: 'middle',
43
+ boxSizing: 'border-box',
44
+ width: diameter,
45
+ height: diameter,
46
+ flex: '0 0 auto',
47
+ borderRadius: componentTheme.avatarBorderRadius,
48
+ ...(0, _shimmer.shimmerStyles)(componentTheme, textDirection === 'rtl', animate)
49
+ }
50
+ };
51
+ };
52
+ exports.generateStyle = generateStyle;
53
+ var _default = exports.default = generateStyle;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SkeletonLoader = SkeletonLoader;
8
+ exports.default = void 0;
9
+ var _react = require("react");
10
+ var _uiReactUtils = require("@instructure/ui-react-utils");
11
+ var _styles = _interopRequireDefault(require("./styles.js"));
12
+ var _props = require("./props.js");
13
+ var _SkeletonText = require("../SkeletonText");
14
+ var _SkeletonRectangle = require("../SkeletonRectangle");
15
+ var _SkeletonCircle = require("../SkeletonCircle");
16
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
17
+ /*
18
+ * The MIT License (MIT)
19
+ *
20
+ * Copyright (c) 2015 - present Instructure, Inc.
21
+ *
22
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ * of this software and associated documentation files (the "Software"), to deal
24
+ * in the Software without restriction, including without limitation the rights
25
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ * copies of the Software, and to permit persons to whom the Software is
27
+ * furnished to do so, subject to the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be included in all
30
+ * copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38
+ * SOFTWARE.
39
+ */
40
+
41
+ /**
42
+ ---
43
+ category: components
44
+ ---
45
+ Shows a placeholder while part of the page is loading, and tells screen reader
46
+ users when loading starts and finishes.
47
+
48
+ Use one `SkeletonLoader` for each loading area, not one per card or row, so
49
+ screen readers announce it once.
50
+ @module SkeletonLoader
51
+ **/function SkeletonLoader(props) {
52
+ const {
53
+ announcementDelay = 400,
54
+ children,
55
+ elementRef,
56
+ errorLabel,
57
+ isError = false,
58
+ isLoading,
59
+ loadedLabel,
60
+ loadingLabel,
61
+ skeleton
62
+ } = props;
63
+ const isHydrated = (0, _uiReactUtils.useIsHydratedContext)();
64
+
65
+ // If `isLoading` is set, it decides. If not, we're loading until hydration
66
+ // finishes. An error always ends loading, so the skeleton is never shown
67
+ // together with an error.
68
+ const loading = isError ? false : isLoading ?? !isHydrated;
69
+
70
+ // Starts empty so screen readers treat the first label as a change and
71
+ // announce it.
72
+ const [status, setStatus] = (0, _react.useState)('');
73
+ const styles = (0, _styles.default)();
74
+ (0, _react.useEffect)(() => {
75
+ if (isError) {
76
+ setStatus('');
77
+ return;
78
+ }
79
+ if (loading) {
80
+ const timeout = setTimeout(() => setStatus(loadingLabel), announcementDelay);
81
+ return () => clearTimeout(timeout);
82
+ }
83
+ setStatus(loadedLabel);
84
+ return undefined;
85
+ }, [loading, isError, loadingLabel, loadedLabel, announcementDelay]);
86
+ return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
87
+ children: [(0, _jsxRuntime.jsx)("span", {
88
+ role: "status",
89
+ "aria-live": "polite",
90
+ "aria-atomic": "true",
91
+ css: styles.srOnly,
92
+ children: status
93
+ }), (0, _jsxRuntime.jsx)("div", {
94
+ ...(0, _uiReactUtils.omitProps)(props, _props.allowedProps),
95
+ ref: elementRef,
96
+ "aria-busy": loading || undefined,
97
+ children: loading ? skeleton : children
98
+ }), isError && errorLabel ? (0, _jsxRuntime.jsx)("span", {
99
+ role: "alert",
100
+ css: styles.srOnly,
101
+ children: errorLabel
102
+ }) : null]
103
+ });
104
+ }
105
+ SkeletonLoader.displayName = 'SkeletonLoader';
106
+ SkeletonLoader.allowedProps = _props.allowedProps;
107
+ SkeletonLoader.Text = _SkeletonText.SkeletonText;
108
+ SkeletonLoader.Rectangle = _SkeletonRectangle.SkeletonRectangle;
109
+ SkeletonLoader.Circle = _SkeletonCircle.SkeletonCircle;
110
+ var _default = exports.default = SkeletonLoader;
@@ -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 = ['announcementDelay', 'children', 'elementRef', 'errorLabel', 'isError', 'isLoading', 'loadedLabel', 'loadingLabel', 'skeleton'];
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateStyle = exports.default = 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
+ /**
32
+ * Visually hidden but still announced. Not `display: none`, which would remove
33
+ * the live region from the accessibility tree and stop it announcing at all.
34
+ */
35
+ const generateStyle = () => ({
36
+ srOnly: {
37
+ label: 'skeletonLoader__srOnly',
38
+ position: 'absolute',
39
+ width: '1px',
40
+ height: '1px',
41
+ margin: '-1px',
42
+ padding: 0,
43
+ border: 0,
44
+ overflow: 'hidden',
45
+ clip: 'rect(0 0 0 0)',
46
+ clipPath: 'inset(50%)',
47
+ whiteSpace: 'nowrap'
48
+ }
49
+ });
50
+ exports.generateStyle = generateStyle;
51
+ var _default = exports.default = generateStyle;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SkeletonRectangle = SkeletonRectangle;
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.Rectangle
44
+ ---
45
+ A placeholder for images, video, and other media. It's hidden from screen
46
+ readers.
47
+ **/
48
+ function SkeletonRectangle(props) {
49
+ const {
50
+ animate,
51
+ aspectRatio,
52
+ elementRef,
53
+ height,
54
+ radius,
55
+ width
56
+ } = props;
57
+ const textDirection = (0, _react.useContext)(_uiI18n.TextDirectionContext);
58
+ const styles = (0, _emotion.useStyleNew)({
59
+ generateStyle: _styles.default,
60
+ componentId: 'SkeletonLoader',
61
+ displayName: 'SkeletonRectangle',
62
+ params: {
63
+ animate,
64
+ aspectRatio,
65
+ height,
66
+ radius,
67
+ width,
68
+ textDirection
69
+ }
70
+ });
71
+ return (0, _jsxRuntime.jsx)("span", {
72
+ ...(0, _uiReactUtils.omitProps)(props, _props.allowedProps),
73
+ ref: elementRef,
74
+ css: styles.skeletonRectangle,
75
+ "aria-hidden": "true",
76
+ "data-skeleton-shape": "rectangle"
77
+ });
78
+ }
79
+ SkeletonRectangle.displayName = 'SkeletonRectangle';
80
+ SkeletonRectangle.allowedProps = _props.allowedProps;
81
+ var _default = exports.default = SkeletonRectangle;
@@ -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', 'aspectRatio', 'elementRef', 'height', 'radius', 'width'];