@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,69 @@
|
|
|
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 { SkeletonRectangleProps, SkeletonRectangleStyle } from './props'
|
|
30
|
+
|
|
31
|
+
type StyleParams = {
|
|
32
|
+
animate: SkeletonRectangleProps['animate']
|
|
33
|
+
aspectRatio: SkeletonRectangleProps['aspectRatio']
|
|
34
|
+
height: SkeletonRectangleProps['height']
|
|
35
|
+
radius: SkeletonRectangleProps['radius']
|
|
36
|
+
width: SkeletonRectangleProps['width']
|
|
37
|
+
textDirection: 'ltr' | 'rtl' | 'auto'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const generateStyle = (
|
|
41
|
+
componentTheme: SkeletonLoaderTheme,
|
|
42
|
+
params: StyleParams,
|
|
43
|
+
_sharedTokens?: SharedTokens
|
|
44
|
+
): SkeletonRectangleStyle => {
|
|
45
|
+
const {
|
|
46
|
+
animate = true,
|
|
47
|
+
aspectRatio = '16 / 9',
|
|
48
|
+
height,
|
|
49
|
+
radius,
|
|
50
|
+
width,
|
|
51
|
+
textDirection
|
|
52
|
+
} = params
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
skeletonRectangle: {
|
|
56
|
+
label: 'skeletonRectangle',
|
|
57
|
+
display: 'block',
|
|
58
|
+
boxSizing: 'border-box',
|
|
59
|
+
width: width ?? '100%',
|
|
60
|
+
...(height ? { height } : { aspectRatio }),
|
|
61
|
+
borderRadius: radius ?? componentTheme.imageBorderRadius,
|
|
62
|
+
...shimmerStyles(componentTheme, textDirection === 'rtl', animate)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default generateStyle
|
|
68
|
+
export { generateStyle }
|
|
69
|
+
export type { StyleParams }
|
|
@@ -0,0 +1,74 @@
|
|
|
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 { SkeletonTextProps } from './props'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
---
|
|
38
|
+
parent: SkeletonLoader
|
|
39
|
+
id: SkeletonLoader.Text
|
|
40
|
+
---
|
|
41
|
+
A placeholder for one or more lines of text. It's hidden from screen readers.
|
|
42
|
+
**/
|
|
43
|
+
function SkeletonText(props: SkeletonTextProps) {
|
|
44
|
+
const { animate, elementRef, lineHeight, lines, size, width } = props
|
|
45
|
+
|
|
46
|
+
const textDirection = useContext(TextDirectionContext)
|
|
47
|
+
|
|
48
|
+
const styles = useStyleNew<SkeletonLoaderTheme, typeof generateStyle>({
|
|
49
|
+
generateStyle,
|
|
50
|
+
componentId: 'SkeletonLoader',
|
|
51
|
+
displayName: 'SkeletonText',
|
|
52
|
+
params: { animate, lineHeight, lines, size, width, textDirection }
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<span
|
|
57
|
+
{...omitProps(props, allowedProps)}
|
|
58
|
+
ref={elementRef}
|
|
59
|
+
css={styles.skeletonText}
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
data-skeleton-shape="text"
|
|
62
|
+
>
|
|
63
|
+
{styles.rows.map((rowStyle, i) => (
|
|
64
|
+
<span key={i} css={rowStyle} />
|
|
65
|
+
))}
|
|
66
|
+
</span>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
SkeletonText.displayName = 'SkeletonText'
|
|
71
|
+
SkeletonText.allowedProps = allowedProps
|
|
72
|
+
|
|
73
|
+
export default SkeletonText
|
|
74
|
+
export { SkeletonText }
|
|
@@ -0,0 +1,91 @@
|
|
|
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, StyleObject } from '@instructure/emotion'
|
|
27
|
+
|
|
28
|
+
type SkeletonSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
|
|
29
|
+
type SkeletonLineHeight = 'heading' | 'text'
|
|
30
|
+
|
|
31
|
+
type SkeletonTextOwnProps = {
|
|
32
|
+
/**
|
|
33
|
+
* Set to `false` to turn off the animation, whatever the user's motion
|
|
34
|
+
* setting. Useful for snapshot and visual regression tests.
|
|
35
|
+
*/
|
|
36
|
+
animate?: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Provides a reference to the underlying HTML element.
|
|
40
|
+
*/
|
|
41
|
+
elementRef?: (element: Element | null) => void
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Line height of the text this placeholder replaces: `heading` is 1.25,
|
|
45
|
+
* `text` (body copy) is 1.5. Match it to the real text so the page doesn't
|
|
46
|
+
* jump when the content loads.
|
|
47
|
+
*/
|
|
48
|
+
lineHeight?: SkeletonLineHeight
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Number of lines to draw. The last line is shorter so it reads as a
|
|
52
|
+
* paragraph.
|
|
53
|
+
*/
|
|
54
|
+
lines?: number
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Font size of the text this placeholder replaces.
|
|
58
|
+
*/
|
|
59
|
+
size?: SkeletonSize
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Width of the placeholder. Defaults to the full width of its container.
|
|
63
|
+
*/
|
|
64
|
+
width?: string | number
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type SkeletonTextStyle = ComponentStyle<'skeletonText'> & {
|
|
68
|
+
/** One style per line. Empty when there's only one line. */
|
|
69
|
+
rows: StyleObject[]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
type SkeletonTextProps = SkeletonTextOwnProps &
|
|
73
|
+
OtherHTMLAttributes<SkeletonTextOwnProps>
|
|
74
|
+
|
|
75
|
+
const allowedProps: (keyof SkeletonTextOwnProps)[] = [
|
|
76
|
+
'animate',
|
|
77
|
+
'elementRef',
|
|
78
|
+
'lineHeight',
|
|
79
|
+
'lines',
|
|
80
|
+
'size',
|
|
81
|
+
'width'
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
export { allowedProps }
|
|
85
|
+
export type {
|
|
86
|
+
SkeletonLineHeight,
|
|
87
|
+
SkeletonSize,
|
|
88
|
+
SkeletonTextOwnProps,
|
|
89
|
+
SkeletonTextProps,
|
|
90
|
+
SkeletonTextStyle
|
|
91
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
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 { SkeletonTextProps, SkeletonTextStyle } from './props'
|
|
30
|
+
|
|
31
|
+
type StyleParams = {
|
|
32
|
+
animate: SkeletonTextProps['animate']
|
|
33
|
+
lineHeight: SkeletonTextProps['lineHeight']
|
|
34
|
+
lines: SkeletonTextProps['lines']
|
|
35
|
+
size: SkeletonTextProps['size']
|
|
36
|
+
width: SkeletonTextProps['width']
|
|
37
|
+
textDirection: 'ltr' | 'rtl' | 'auto'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const LINE_HEIGHTS = {
|
|
41
|
+
heading: 1.25,
|
|
42
|
+
text: 1.5
|
|
43
|
+
} as const
|
|
44
|
+
|
|
45
|
+
const generateStyle = (
|
|
46
|
+
componentTheme: SkeletonLoaderTheme,
|
|
47
|
+
params: StyleParams,
|
|
48
|
+
_sharedTokens?: SharedTokens
|
|
49
|
+
): SkeletonTextStyle => {
|
|
50
|
+
const {
|
|
51
|
+
animate = true,
|
|
52
|
+
lineHeight = 'heading',
|
|
53
|
+
lines = 1,
|
|
54
|
+
size = 'md',
|
|
55
|
+
width,
|
|
56
|
+
textDirection
|
|
57
|
+
} = params
|
|
58
|
+
|
|
59
|
+
const shimmer = shimmerStyles(
|
|
60
|
+
componentTheme,
|
|
61
|
+
textDirection === 'rtl',
|
|
62
|
+
animate
|
|
63
|
+
)
|
|
64
|
+
const fontSizes = {
|
|
65
|
+
xs: componentTheme.textHeightXs,
|
|
66
|
+
sm: componentTheme.textHeightSm,
|
|
67
|
+
md: componentTheme.textHeightMd,
|
|
68
|
+
lg: componentTheme.textHeightLg,
|
|
69
|
+
xl: componentTheme.textHeightXl,
|
|
70
|
+
xxl: componentTheme.textHeightXxl
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Each bar is as tall as the font size (1em). The rest of the line height is
|
|
74
|
+
// split into equal padding above and below it, so a line takes up exactly
|
|
75
|
+
// `lineHeight x font-size`, the same as a line of real text.
|
|
76
|
+
const row = `${LINE_HEIGHTS[lineHeight]}em`
|
|
77
|
+
const bar = {
|
|
78
|
+
display: 'block',
|
|
79
|
+
boxSizing: 'content-box',
|
|
80
|
+
height: '1em',
|
|
81
|
+
padding: `calc((${row} - 1em) / 2) 0`,
|
|
82
|
+
backgroundClip: 'content-box',
|
|
83
|
+
borderRadius: componentTheme.textBorderRadius,
|
|
84
|
+
...shimmer
|
|
85
|
+
} as const
|
|
86
|
+
|
|
87
|
+
const block = {
|
|
88
|
+
label: 'skeletonText',
|
|
89
|
+
display: 'block',
|
|
90
|
+
fontSize: fontSizes[size] ?? componentTheme.textHeightMd,
|
|
91
|
+
width: width ?? '100%'
|
|
92
|
+
} as const
|
|
93
|
+
|
|
94
|
+
if (lines <= 1) {
|
|
95
|
+
return { skeletonText: { ...block, ...bar }, rows: [] }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Each line is its own element so every bar gets rounded ends.
|
|
99
|
+
return {
|
|
100
|
+
skeletonText: {
|
|
101
|
+
...block,
|
|
102
|
+
boxSizing: 'border-box',
|
|
103
|
+
height: `calc(${lines} * ${row})`
|
|
104
|
+
},
|
|
105
|
+
rows: Array.from({ length: lines }, (_unused, i) => ({
|
|
106
|
+
label: 'skeletonText__row',
|
|
107
|
+
...bar,
|
|
108
|
+
width: i === lines - 1 ? '75%' : '100%'
|
|
109
|
+
}))
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default generateStyle
|
|
114
|
+
export { generateStyle }
|
|
115
|
+
export type { StyleParams }
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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'
|
|
26
|
+
|
|
27
|
+
export type {
|
|
28
|
+
SkeletonLoaderProps,
|
|
29
|
+
SkeletonShapeType
|
|
30
|
+
} from './SkeletonLoader/props'
|
|
31
|
+
export type {
|
|
32
|
+
SkeletonTextProps,
|
|
33
|
+
SkeletonSize,
|
|
34
|
+
SkeletonLineHeight
|
|
35
|
+
} from './SkeletonText/props'
|
|
36
|
+
export type { SkeletonRectangleProps } from './SkeletonRectangle/props'
|
|
37
|
+
export type { SkeletonCircleProps } from './SkeletonCircle/props'
|
|
38
|
+
export type { SkeletonLoaderTheme } from './utils/shimmer'
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
import type { NewComponentTypes } from '@instructure/ui-themes'
|
|
27
|
+
|
|
28
|
+
type SkeletonLoaderTheme = ReturnType<NewComponentTypes['SkeletonLoader']>
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The gradient is twice as wide as the shape. A percentage
|
|
32
|
+
* `background-position` can't move a background that is exactly as wide as
|
|
33
|
+
* its element, so it needs the extra width to slide across.
|
|
34
|
+
*/
|
|
35
|
+
const GRADIENT_SCALE = 2
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Highlight positions, as a fraction of the shape's width. At `ENTER` and
|
|
39
|
+
* `EXIT` the highlight is fully outside the shape, so the jump from the end of
|
|
40
|
+
* one loop to the start of the next isn't visible. `REST` is where it sits when
|
|
41
|
+
* the shape isn't animating.
|
|
42
|
+
*/
|
|
43
|
+
const HIGHLIGHT_ENTER = -0.5
|
|
44
|
+
const HIGHLIGHT_EXIT = 1.5
|
|
45
|
+
const HIGHLIGHT_REST = 0.3
|
|
46
|
+
|
|
47
|
+
/** Converts a highlight position into a `background-position` percentage. */
|
|
48
|
+
const positionFor = (highlight: number) =>
|
|
49
|
+
`${(1 - highlight) * 100 * (GRADIENT_SCALE - 1)}% 0`
|
|
50
|
+
|
|
51
|
+
// Defined once at module scope. Creating keyframes inside a style function
|
|
52
|
+
// generates a new animation name on every render (same as Spinner v2).
|
|
53
|
+
const sweep = (isRtl: boolean) => keyframes`
|
|
54
|
+
from { background-position: ${positionFor(
|
|
55
|
+
isRtl ? HIGHLIGHT_EXIT : HIGHLIGHT_ENTER
|
|
56
|
+
)}; }
|
|
57
|
+
to { background-position: ${positionFor(
|
|
58
|
+
isRtl ? HIGHLIGHT_ENTER : HIGHLIGHT_EXIT
|
|
59
|
+
)}; }
|
|
60
|
+
`
|
|
61
|
+
const sweepLtr = sweep(false)
|
|
62
|
+
const sweepRtl = sweep(true)
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The fill shared by every shape: a base color with a highlight that sweeps
|
|
66
|
+
* across it. The gradient fades back to the base color rather than to
|
|
67
|
+
* `transparent`, which would show a dark band in some browsers.
|
|
68
|
+
*/
|
|
69
|
+
const shimmerStyles = (
|
|
70
|
+
componentTheme: SkeletonLoaderTheme,
|
|
71
|
+
isRtl: boolean,
|
|
72
|
+
animate: boolean
|
|
73
|
+
) => {
|
|
74
|
+
const base = componentTheme.backgroundColor
|
|
75
|
+
const highlight = componentTheme.shimmerColor
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
backgroundColor: base,
|
|
79
|
+
backgroundImage: `linear-gradient(90deg, ${base} 0%, ${base} 25%, ${highlight} 50%, ${base} 75%, ${base} 100%)`,
|
|
80
|
+
backgroundRepeat: 'no-repeat',
|
|
81
|
+
backgroundSize: `${GRADIENT_SCALE * 100}% 100%`,
|
|
82
|
+
backgroundPosition: positionFor(
|
|
83
|
+
isRtl ? 1 - HIGHLIGHT_REST : HIGHLIGHT_REST
|
|
84
|
+
),
|
|
85
|
+
...(animate
|
|
86
|
+
? {
|
|
87
|
+
// The animation loops until the skeleton is removed, so it only runs
|
|
88
|
+
// when the user hasn't asked for reduced motion (WCAG 2.2.2).
|
|
89
|
+
'@media (prefers-reduced-motion: no-preference)': {
|
|
90
|
+
animationName: isRtl ? sweepRtl : sweepLtr,
|
|
91
|
+
animationDuration: componentTheme.duration,
|
|
92
|
+
animationTimingFunction: `cubic-bezier(${componentTheme.bezier})`,
|
|
93
|
+
animationIterationCount: 'infinite'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
: {})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { shimmerStyles }
|
|
101
|
+
export type { SkeletonLoaderTheme }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.build.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./types",
|
|
5
|
+
"composite": true,
|
|
6
|
+
"rootDir": "./src"
|
|
7
|
+
},
|
|
8
|
+
"include": ["src"],
|
|
9
|
+
"references": [
|
|
10
|
+
{
|
|
11
|
+
"path": "../emotion/tsconfig.build.json"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"path": "../shared-types/tsconfig.build.json"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"path": "../ui-axe-check/tsconfig.build.json"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "../ui-babel-preset/tsconfig.build.json"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"path": "../ui-i18n/tsconfig.build.json"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"path": "../ui-react-utils/tsconfig.build.json"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "../ui-themes/tsconfig.build.json"
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|