tinywidgets 1.4.0 → 1.5.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/package.json +15 -11
- package/src/components/Loading/index.css.ts +84 -0
- package/src/components/Loading/index.tsx +137 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinywidgets",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"author": "jamesgpearce",
|
|
5
5
|
"repository": "github:tinyplex/tinywidgets",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,26 +22,30 @@
|
|
|
22
22
|
"@eslint/js": "^9.30.1",
|
|
23
23
|
"@types/react": "^19.2.14",
|
|
24
24
|
"@types/react-dom": "^19.2.3",
|
|
25
|
-
"cspell": "^
|
|
25
|
+
"cspell": "^10.0.0",
|
|
26
26
|
"eslint": "^9.30.1",
|
|
27
27
|
"eslint-plugin-import": "^2.32.0",
|
|
28
28
|
"eslint-plugin-react": "^7.37.5",
|
|
29
29
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
30
|
-
"globals": "^17.
|
|
31
|
-
"prettier": "^3.8.
|
|
30
|
+
"globals": "^17.5.0",
|
|
31
|
+
"prettier": "^3.8.3",
|
|
32
32
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"react": "^19.2.5",
|
|
34
|
+
"react-dom": "^19.2.5",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"typescript-eslint": "^8.58.2"
|
|
35
37
|
},
|
|
36
38
|
"exports": {
|
|
37
39
|
".": "./src/index.ts",
|
|
38
40
|
"./css": "./src/index.css.ts"
|
|
39
41
|
},
|
|
40
42
|
"dependencies": {
|
|
41
|
-
"@vanilla-extract/css": "^1.20.
|
|
42
|
-
"lucide-react": "^
|
|
43
|
+
"@vanilla-extract/css": "^1.20.1",
|
|
44
|
+
"lucide-react": "^1.8.0",
|
|
45
|
+
"tinybase": "^8.2.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
43
48
|
"react": "^19.2.4",
|
|
44
|
-
"react-dom": "^19.2.4"
|
|
45
|
-
"tinybase": "^8.0.2"
|
|
49
|
+
"react-dom": "^19.2.4"
|
|
46
50
|
}
|
|
47
|
-
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {keyframes, style} from '@vanilla-extract/css';
|
|
2
|
+
import {colors} from '../../css/colors.css';
|
|
3
|
+
import {dimensions} from '../../css/dimensions.css';
|
|
4
|
+
|
|
5
|
+
const spin = keyframes({
|
|
6
|
+
from: {transform: 'rotate(0deg)'},
|
|
7
|
+
to: {transform: 'rotate(360deg)'},
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const shimmer = keyframes({
|
|
11
|
+
from: {transform: 'translateX(-100%)'},
|
|
12
|
+
to: {transform: 'translateX(100%)'},
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export const loading = style({
|
|
16
|
+
display: 'grid',
|
|
17
|
+
gridTemplateRows: 'auto minmax(0, 1fr)',
|
|
18
|
+
gap: `calc(${dimensions.padding} / 1.5)`,
|
|
19
|
+
alignContent: 'start',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const header = style({
|
|
23
|
+
display: 'flex',
|
|
24
|
+
alignItems: 'center',
|
|
25
|
+
gap: `calc(${dimensions.padding} / 2)`,
|
|
26
|
+
color: colors.foregroundDim,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const spinner = style({
|
|
30
|
+
width: dimensions.icon,
|
|
31
|
+
height: dimensions.icon,
|
|
32
|
+
borderRadius: '999px',
|
|
33
|
+
border: `2px solid ${colors.backgroundHover}`,
|
|
34
|
+
borderTopColor: colors.accent,
|
|
35
|
+
animation: `${spin} .9s linear infinite`,
|
|
36
|
+
'@media': {
|
|
37
|
+
'(prefers-reduced-motion: reduce)': {
|
|
38
|
+
animation: 'none',
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const label = style({
|
|
44
|
+
fontSize: '.95rem',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const rows = style({
|
|
48
|
+
position: 'relative',
|
|
49
|
+
display: 'grid',
|
|
50
|
+
gap: `calc(${dimensions.padding} / 2)`,
|
|
51
|
+
minHeight: 0,
|
|
52
|
+
overflow: 'hidden',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const row = style({
|
|
56
|
+
position: 'relative',
|
|
57
|
+
overflow: 'hidden',
|
|
58
|
+
height: '.875rem',
|
|
59
|
+
borderRadius: dimensions.radius,
|
|
60
|
+
background: colors.background2,
|
|
61
|
+
selectors: {
|
|
62
|
+
'&::after': {
|
|
63
|
+
content: '""',
|
|
64
|
+
position: 'absolute',
|
|
65
|
+
inset: 0,
|
|
66
|
+
background: `linear-gradient(
|
|
67
|
+
90deg,
|
|
68
|
+
transparent,
|
|
69
|
+
${colors.backgroundHover},
|
|
70
|
+
transparent
|
|
71
|
+
)`,
|
|
72
|
+
animation: `${shimmer} 1.6s ease-in-out infinite`,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
'@media': {
|
|
76
|
+
'(prefers-reduced-motion: reduce)': {
|
|
77
|
+
selectors: {
|
|
78
|
+
'&::after': {
|
|
79
|
+
animation: 'none',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import {useEffect, useRef, useState} from 'react';
|
|
2
|
+
import {classNames} from '../../common/functions';
|
|
3
|
+
import {
|
|
4
|
+
header,
|
|
5
|
+
label,
|
|
6
|
+
loading,
|
|
7
|
+
row,
|
|
8
|
+
rows as rowsClass,
|
|
9
|
+
spinner,
|
|
10
|
+
} from './index.css';
|
|
11
|
+
|
|
12
|
+
const WIDTHS = ['100%', '92%', '84%', '96%', '72%', '88%', '67%', '81%'];
|
|
13
|
+
const DEFAULT_ROW_COUNT = 5;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The `Loading` component displays a compact spinner with optional shimmer rows
|
|
17
|
+
* to reserve space while content is loading.
|
|
18
|
+
*
|
|
19
|
+
* @param props The props for the component.
|
|
20
|
+
* @returns The Loading component.
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <Loading labelText="Loading dependencies" />
|
|
24
|
+
* ```
|
|
25
|
+
* This example shows the default loading panel. Add a CSS height to the
|
|
26
|
+
* component to fit more placeholder rows automatically.
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <>
|
|
30
|
+
* <style>{`
|
|
31
|
+
* .tallLoading {
|
|
32
|
+
* height: 12rem;
|
|
33
|
+
* }
|
|
34
|
+
* `}</style>
|
|
35
|
+
* <Loading className="tallLoading" labelText="Loading dependencies" />
|
|
36
|
+
* </>
|
|
37
|
+
* ```
|
|
38
|
+
* This example uses CSS to make the loading panel taller, allowing more
|
|
39
|
+
* placeholder rows to fit automatically.
|
|
40
|
+
* @icon Lucide.LoaderCircle
|
|
41
|
+
*/
|
|
42
|
+
export const Loading = ({
|
|
43
|
+
labelText = 'Loading',
|
|
44
|
+
className,
|
|
45
|
+
}: {
|
|
46
|
+
/**
|
|
47
|
+
* The label shown beside the spinner.
|
|
48
|
+
*/
|
|
49
|
+
readonly labelText?: string;
|
|
50
|
+
/**
|
|
51
|
+
* An extra CSS class name for the component.
|
|
52
|
+
*/
|
|
53
|
+
readonly className?: string;
|
|
54
|
+
}) => {
|
|
55
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
56
|
+
const headerRef = useRef<HTMLDivElement>(null);
|
|
57
|
+
const rowsRef = useRef<HTMLDivElement>(null);
|
|
58
|
+
const measureRowRef = useRef<HTMLDivElement>(null);
|
|
59
|
+
|
|
60
|
+
const [rowCount, setRowCount] = useState(DEFAULT_ROW_COUNT);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
const updateRowCount = () => {
|
|
64
|
+
const root = rootRef.current;
|
|
65
|
+
const header = headerRef.current;
|
|
66
|
+
const rows = rowsRef.current;
|
|
67
|
+
const measureRow = measureRowRef.current;
|
|
68
|
+
if (
|
|
69
|
+
root == null ||
|
|
70
|
+
header == null ||
|
|
71
|
+
rows == null ||
|
|
72
|
+
measureRow == null
|
|
73
|
+
) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const rootStyles = getComputedStyle(root);
|
|
78
|
+
const rowsStyles = getComputedStyle(rows);
|
|
79
|
+
const rootGap =
|
|
80
|
+
parseFloat(rootStyles.rowGap || rootStyles.gap || '0') || 0;
|
|
81
|
+
const rowsGap =
|
|
82
|
+
parseFloat(rowsStyles.rowGap || rowsStyles.gap || '0') || 0;
|
|
83
|
+
const availableHeight =
|
|
84
|
+
root.getBoundingClientRect().height -
|
|
85
|
+
header.getBoundingClientRect().height -
|
|
86
|
+
rootGap;
|
|
87
|
+
const rowHeight = measureRow.getBoundingClientRect().height;
|
|
88
|
+
|
|
89
|
+
const nextRowCount = Math.max(
|
|
90
|
+
0,
|
|
91
|
+
Math.floor((availableHeight + rowsGap) / (rowHeight + rowsGap)),
|
|
92
|
+
);
|
|
93
|
+
setRowCount((currentRowCount) =>
|
|
94
|
+
currentRowCount === nextRowCount ? currentRowCount : nextRowCount,
|
|
95
|
+
);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
updateRowCount();
|
|
99
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const resizeObserver = new ResizeObserver(updateRowCount);
|
|
104
|
+
if (rootRef.current != null) {
|
|
105
|
+
resizeObserver.observe(rootRef.current);
|
|
106
|
+
}
|
|
107
|
+
if (headerRef.current != null) {
|
|
108
|
+
resizeObserver.observe(headerRef.current);
|
|
109
|
+
}
|
|
110
|
+
return () => resizeObserver.disconnect();
|
|
111
|
+
}, []);
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div ref={rootRef} className={classNames(loading, className)}>
|
|
115
|
+
<div ref={headerRef} className={header}>
|
|
116
|
+
<span className={spinner} />
|
|
117
|
+
<span className={label}>{labelText}</span>
|
|
118
|
+
</div>
|
|
119
|
+
<div ref={rowsRef} className={rowsClass}>
|
|
120
|
+
<div
|
|
121
|
+
ref={measureRowRef}
|
|
122
|
+
className={row}
|
|
123
|
+
style={{position: 'absolute', width: 0, visibility: 'hidden'}}
|
|
124
|
+
/>
|
|
125
|
+
{rowCount > 0
|
|
126
|
+
? Array.from({length: rowCount}, (_, index) => (
|
|
127
|
+
<div
|
|
128
|
+
key={index}
|
|
129
|
+
className={row}
|
|
130
|
+
style={{width: WIDTHS[index % WIDTHS.length]}}
|
|
131
|
+
/>
|
|
132
|
+
))
|
|
133
|
+
: null}
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
);
|
|
137
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export {Flyout} from './components/Flyout/index.tsx';
|
|
|
10
10
|
export {Hr} from './components/Hr/index.tsx';
|
|
11
11
|
export {Image} from './components/Image/index.tsx';
|
|
12
12
|
export {ImageLabel} from './components/ImageLabel/index.tsx';
|
|
13
|
+
export {Loading} from './components/Loading/index.tsx';
|
|
13
14
|
export {Metric} from './components/Metric/index.tsx';
|
|
14
15
|
export {Row} from './components/Row/index.tsx';
|
|
15
16
|
export {Select} from './components/Select/index.tsx';
|