tinywidgets 1.4.0 → 1.6.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/App/index.css.ts +35 -26
- package/src/components/App/index.tsx +31 -6
- package/src/components/Axis/index.css.ts +1 -1
- package/src/components/Button/index.css.ts +37 -23
- package/src/components/Button/index.tsx +14 -0
- package/src/components/Card/index.css.ts +2 -2
- package/src/components/Checkbox/index.css.ts +27 -8
- package/src/components/Checkbox/index.tsx +17 -2
- package/src/components/Code/index.css.ts +2 -2
- package/src/components/Collapsible/index.css.ts +6 -6
- package/src/components/Detail/index.css.ts +2 -2
- package/src/components/Flyout/index.css.ts +5 -5
- package/src/components/Hr/index.css.ts +1 -1
- package/src/components/Image/index.css.ts +12 -12
- package/src/components/Loading/index.css.ts +84 -0
- package/src/components/Loading/index.tsx +137 -0
- package/src/components/Row/index.css.ts +8 -8
- package/src/components/Select/index.css.ts +20 -9
- package/src/components/Select/index.tsx +22 -3
- package/src/components/Summary/index.css.ts +1 -1
- package/src/components/Table/index.css.ts +8 -8
- package/src/components/Tag/index.css.ts +8 -8
- package/src/components/TextInput/index.css.ts +48 -17
- package/src/components/TextInput/index.tsx +39 -5
- package/src/css/classes.css.ts +42 -0
- package/src/css/code.css.ts +18 -18
- package/src/css/colors.css.ts +17 -17
- package/src/css/dimensions.css.ts +2 -2
- package/src/css/global.css.ts +2 -2
- package/src/index.css.ts +1 -0
- package/src/index.ts +6 -1
- package/src/stores/RouteStore.tsx +52 -14
|
@@ -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
|
+
alignContent: 'start',
|
|
17
|
+
display: 'grid',
|
|
18
|
+
gap: `calc(${dimensions.padding} / 1.5)`,
|
|
19
|
+
gridTemplateRows: 'auto minmax(0, 1fr)',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const header = style({
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
color: colors.foregroundDim,
|
|
25
|
+
display: 'flex',
|
|
26
|
+
gap: `calc(${dimensions.padding} / 2)`,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const spinner = style({
|
|
30
|
+
'@media': {
|
|
31
|
+
'(prefers-reduced-motion: reduce)': {
|
|
32
|
+
animation: 'none',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
animation: `${spin} .9s linear infinite`,
|
|
36
|
+
border: `2px solid ${colors.backgroundHover}`,
|
|
37
|
+
borderRadius: '999px',
|
|
38
|
+
borderTopColor: colors.accent,
|
|
39
|
+
height: dimensions.icon,
|
|
40
|
+
width: dimensions.icon,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const label = style({
|
|
44
|
+
fontSize: '.95rem',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export const rows = style({
|
|
48
|
+
display: 'grid',
|
|
49
|
+
gap: `calc(${dimensions.padding} / 2)`,
|
|
50
|
+
minHeight: 0,
|
|
51
|
+
overflow: 'hidden',
|
|
52
|
+
position: 'relative',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export const row = style({
|
|
56
|
+
'@media': {
|
|
57
|
+
'(prefers-reduced-motion: reduce)': {
|
|
58
|
+
selectors: {
|
|
59
|
+
'&::after': {
|
|
60
|
+
animation: 'none',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
background: colors.background2,
|
|
66
|
+
borderRadius: dimensions.radius,
|
|
67
|
+
height: '.875rem',
|
|
68
|
+
overflow: 'hidden',
|
|
69
|
+
position: 'relative',
|
|
70
|
+
selectors: {
|
|
71
|
+
'&::after': {
|
|
72
|
+
animation: `${shimmer} 1.6s ease-in-out infinite`,
|
|
73
|
+
background: `linear-gradient(
|
|
74
|
+
90deg,
|
|
75
|
+
transparent,
|
|
76
|
+
${colors.backgroundHover},
|
|
77
|
+
transparent
|
|
78
|
+
)`,
|
|
79
|
+
content: '""',
|
|
80
|
+
inset: 0,
|
|
81
|
+
position: 'absolute',
|
|
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
|
+
};
|
|
@@ -4,27 +4,27 @@ import {dimensions} from '../../css/dimensions.css.ts';
|
|
|
4
4
|
|
|
5
5
|
export const row = style({
|
|
6
6
|
display: 'grid',
|
|
7
|
-
width: '100%',
|
|
8
7
|
gap: dimensions.padding,
|
|
8
|
+
width: '100%',
|
|
9
9
|
...notLarge({gridTemplateColumns: '1fr'}),
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
export const rowVariants = styleVariants({
|
|
13
13
|
'1|1': {gridTemplateColumns: `calc((100% - ${dimensions.padding})/2) 1fr`},
|
|
14
|
-
'1|2': {
|
|
15
|
-
gridTemplateColumns: `calc((100% - ${dimensions.padding}*2)/3) 1fr`,
|
|
16
|
-
},
|
|
17
|
-
'2|1': {
|
|
18
|
-
gridTemplateColumns: `1fr calc((100% - ${dimensions.padding}*2)/3)`,
|
|
19
|
-
},
|
|
20
14
|
'1|1|1': {
|
|
21
15
|
gridTemplateColumns: `1fr 1fr 1fr`,
|
|
22
16
|
},
|
|
17
|
+
'1|1|1|1': {gridTemplateColumns: '1fr 1fr 1fr 1fr'},
|
|
18
|
+
'1|2': {
|
|
19
|
+
gridTemplateColumns: `calc((100% - ${dimensions.padding}*2)/3) 1fr`,
|
|
20
|
+
},
|
|
23
21
|
'1|3': {
|
|
24
22
|
gridTemplateColumns: `calc((100% - ${dimensions.padding}*3)/4) 1fr`,
|
|
25
23
|
},
|
|
24
|
+
'2|1': {
|
|
25
|
+
gridTemplateColumns: `1fr calc((100% - ${dimensions.padding}*2)/3)`,
|
|
26
|
+
},
|
|
26
27
|
'3|1': {
|
|
27
28
|
gridTemplateColumns: `1fr calc((100% - ${dimensions.padding}*3)/4)`,
|
|
28
29
|
},
|
|
29
|
-
'1|1|1|1': {gridTemplateColumns: '1fr 1fr 1fr 1fr'},
|
|
30
30
|
});
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import {style} from '@vanilla-extract/css';
|
|
1
|
+
import {style, styleVariants} from '@vanilla-extract/css';
|
|
2
2
|
import {colors} from '../../css/colors.css';
|
|
3
3
|
import {dimensions} from '../../css/dimensions.css';
|
|
4
4
|
|
|
5
5
|
export const select = style({
|
|
6
|
+
backgroundColor: colors.background,
|
|
7
|
+
border: colors.border,
|
|
6
8
|
borderRadius: dimensions.radius,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
boxSizing: 'border-box',
|
|
10
|
+
boxShadow: colors.shadow,
|
|
9
11
|
color: 'inherit',
|
|
10
|
-
fontWeight: 'inherit',
|
|
11
12
|
fontFamily: 'inherit',
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
fontWeight: 'inherit',
|
|
14
|
+
outlineOffset: '2px',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const selectVariants = styleVariants({
|
|
18
|
+
default: {
|
|
19
|
+
height: '2.5rem',
|
|
20
|
+
padding: '0.5rem',
|
|
21
|
+
},
|
|
22
|
+
small: {
|
|
23
|
+
fontSize: '0.75rem',
|
|
24
|
+
height: '1.5rem',
|
|
25
|
+
lineHeight: '0.875rem',
|
|
26
|
+
padding: '0.1875rem 0.375rem',
|
|
27
|
+
},
|
|
17
28
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {useCallback, useEffect, useState} from 'react';
|
|
2
2
|
import {classNames} from '../../common/functions.tsx';
|
|
3
|
-
import {select} from './index.css.ts';
|
|
3
|
+
import {select, selectVariants} from './index.css.ts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The `Select` component displays a managed select input with an existing
|
|
@@ -16,6 +16,15 @@ import {select} from './index.css.ts';
|
|
|
16
16
|
* onChange={(option) => console.log(option)}
|
|
17
17
|
* />
|
|
18
18
|
* ```
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <Select
|
|
22
|
+
* initialOption="CA"
|
|
23
|
+
* options={{AL: 'Albania', BE: 'Belgium', CA: 'Canada'}}
|
|
24
|
+
* variant="small"
|
|
25
|
+
* />
|
|
26
|
+
* ```
|
|
27
|
+
* This example shows the `small` variant of the Select component.
|
|
19
28
|
* @icon Lucide.Combine
|
|
20
29
|
*/
|
|
21
30
|
export const Select = ({
|
|
@@ -24,6 +33,7 @@ export const Select = ({
|
|
|
24
33
|
onChange,
|
|
25
34
|
alt,
|
|
26
35
|
className,
|
|
36
|
+
variant = 'default',
|
|
27
37
|
ref,
|
|
28
38
|
}: {
|
|
29
39
|
/**
|
|
@@ -46,6 +56,15 @@ export const Select = ({
|
|
|
46
56
|
* An extra CSS class name for the component.
|
|
47
57
|
*/
|
|
48
58
|
readonly className?: string;
|
|
59
|
+
/**
|
|
60
|
+
* A variant of the select, one of:
|
|
61
|
+
* - `default`
|
|
62
|
+
* - `small`
|
|
63
|
+
*/
|
|
64
|
+
readonly variant?: keyof typeof selectVariants;
|
|
65
|
+
/**
|
|
66
|
+
* A ref to the underlying select element.
|
|
67
|
+
*/
|
|
49
68
|
ref?: React.RefObject<HTMLSelectElement | null>;
|
|
50
69
|
}) => {
|
|
51
70
|
const [option, setOption] = useState(initialOption ?? '');
|
|
@@ -63,12 +82,12 @@ export const Select = ({
|
|
|
63
82
|
[change],
|
|
64
83
|
);
|
|
65
84
|
|
|
66
|
-
useEffect(() =>
|
|
85
|
+
useEffect(() => setOption(initialOption ?? ''), [initialOption]);
|
|
67
86
|
|
|
68
87
|
return (
|
|
69
88
|
<select
|
|
70
89
|
value={option}
|
|
71
|
-
className={classNames(select, className)}
|
|
90
|
+
className={classNames(select, selectVariants[variant], className)}
|
|
72
91
|
onChange={handleChange}
|
|
73
92
|
title={alt}
|
|
74
93
|
ref={ref}
|
|
@@ -4,9 +4,9 @@ import {dimensions} from '../../css/dimensions.css.ts';
|
|
|
4
4
|
|
|
5
5
|
export const summary = style({
|
|
6
6
|
display: 'grid',
|
|
7
|
-
width: '100%',
|
|
8
7
|
gap: dimensions.padding,
|
|
9
8
|
gridTemplateColumns: `6rem 1fr`,
|
|
9
|
+
width: '100%',
|
|
10
10
|
...notLarge({gridTemplateColumns: '1fr'}),
|
|
11
11
|
});
|
|
12
12
|
|
|
@@ -2,25 +2,25 @@ import {globalStyle, style} from '@vanilla-extract/css';
|
|
|
2
2
|
import {colors} from '../../css/colors.css';
|
|
3
3
|
|
|
4
4
|
export const table = style({
|
|
5
|
-
|
|
5
|
+
borderCollapse: 'collapse',
|
|
6
6
|
height: '100%',
|
|
7
7
|
padding: 0,
|
|
8
|
-
borderCollapse: 'collapse',
|
|
9
8
|
tableLayout: 'fixed',
|
|
9
|
+
width: '100%',
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
globalStyle(`${table} th, ${table} td`, {
|
|
13
|
+
borderColor: colors.borderColor,
|
|
14
|
+
borderStyle: 'solid',
|
|
15
|
+
borderWidth: '1px 0',
|
|
13
16
|
overflow: 'hidden',
|
|
14
17
|
padding: '0.25rem 1rem',
|
|
15
|
-
whiteSpace: 'nowrap',
|
|
16
|
-
textOverflow: 'ellipsis',
|
|
17
|
-
borderWidth: '1px 0',
|
|
18
|
-
borderStyle: 'solid',
|
|
19
|
-
borderColor: colors.borderColor,
|
|
20
18
|
textAlign: 'left',
|
|
19
|
+
textOverflow: 'ellipsis',
|
|
20
|
+
whiteSpace: 'nowrap',
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
globalStyle(`${table} th`, {
|
|
24
|
-
fontWeight: 'inherit',
|
|
25
24
|
backgroundColor: colors.backgroundHover,
|
|
25
|
+
fontWeight: 'inherit',
|
|
26
26
|
});
|
|
@@ -2,26 +2,26 @@ import {style, styleVariants} from '@vanilla-extract/css';
|
|
|
2
2
|
import {colors} from '../../css/colors.css';
|
|
3
3
|
|
|
4
4
|
export const tag = style({
|
|
5
|
+
borderRadius: '0.25rem',
|
|
6
|
+
flexShrink: 0,
|
|
5
7
|
fontSize: '0.625rem',
|
|
8
|
+
gap: '0.25rem',
|
|
6
9
|
lineHeight: '0.625rem',
|
|
7
10
|
padding: '0.1rem 0.25rem',
|
|
8
|
-
borderRadius: '0.25rem',
|
|
9
|
-
gap: '0.25rem',
|
|
10
|
-
flexShrink: 0,
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
export const tagVariants = styleVariants({
|
|
14
|
-
default: {
|
|
15
|
-
backgroundColor: colors.backgroundHover,
|
|
16
|
-
color: colors.foregroundDim,
|
|
17
|
-
},
|
|
18
14
|
accent: {
|
|
19
15
|
backgroundColor: colors.accent,
|
|
20
16
|
color: colors.accentContrast,
|
|
21
17
|
},
|
|
18
|
+
default: {
|
|
19
|
+
backgroundColor: colors.backgroundHover,
|
|
20
|
+
color: colors.foregroundDim,
|
|
21
|
+
},
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
export const tagIcon = style({
|
|
25
|
-
width: '0.7rem',
|
|
26
25
|
height: '0.7rem',
|
|
26
|
+
width: '0.7rem',
|
|
27
27
|
});
|
|
@@ -1,37 +1,68 @@
|
|
|
1
|
-
import {style} from '@vanilla-extract/css';
|
|
1
|
+
import {style, styleVariants} from '@vanilla-extract/css';
|
|
2
2
|
import {colors} from '../../css/colors.css';
|
|
3
3
|
import {dimensions} from '../../css/dimensions.css';
|
|
4
4
|
|
|
5
5
|
export const wrapper = style({
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
alignSelf: 'stretch',
|
|
7
|
+
display: 'block',
|
|
8
|
+
flex: '1 1 auto',
|
|
9
|
+
minWidth: 0,
|
|
8
10
|
position: 'relative',
|
|
9
|
-
display: 'inline-block',
|
|
10
11
|
});
|
|
11
12
|
|
|
12
13
|
export const input = style({
|
|
14
|
+
backgroundColor: colors.background,
|
|
15
|
+
border: colors.border,
|
|
13
16
|
borderRadius: dimensions.radius,
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
boxSizing: 'border-box',
|
|
18
|
+
boxShadow: colors.shadow + ' inset',
|
|
16
19
|
color: 'inherit',
|
|
17
|
-
fontWeight: 'inherit',
|
|
18
20
|
fontFamily: 'inherit',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
fontWeight: 'inherit',
|
|
22
|
+
outlineOffset: '2px',
|
|
23
|
+
width: '100%',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const inputVariants = styleVariants({
|
|
27
|
+
default: {
|
|
28
|
+
height: '2.5rem',
|
|
29
|
+
lineHeight: '1.5rem',
|
|
30
|
+
padding: '0.5rem',
|
|
31
|
+
},
|
|
32
|
+
small: {
|
|
33
|
+
fontSize: '0.75rem',
|
|
34
|
+
height: '1.5rem',
|
|
35
|
+
lineHeight: '0.875rem',
|
|
36
|
+
padding: '0.1875rem 0.375rem',
|
|
37
|
+
},
|
|
23
38
|
});
|
|
24
39
|
|
|
25
|
-
export const
|
|
26
|
-
|
|
40
|
+
export const inputWithIconVariants = styleVariants({
|
|
41
|
+
default: {
|
|
42
|
+
textIndent: `calc(${dimensions.icon} * 1.3)`,
|
|
43
|
+
},
|
|
44
|
+
small: {
|
|
45
|
+
textIndent: '1rem',
|
|
46
|
+
},
|
|
27
47
|
});
|
|
28
48
|
|
|
29
49
|
export const icon = style({
|
|
30
|
-
position: 'absolute',
|
|
31
|
-
left: `calc(${dimensions.icon} * .5)`,
|
|
32
|
-
top: `calc(${dimensions.icon} * .8)`,
|
|
33
|
-
color: colors.foregroundDim,
|
|
34
50
|
backgroundColor: colors.background,
|
|
35
51
|
borderRight: `calc(${dimensions.icon} * .25) solid ${colors.background}`,
|
|
36
52
|
boxSizing: 'content-box',
|
|
53
|
+
color: colors.foregroundDim,
|
|
54
|
+
left: `calc(${dimensions.icon} * .5)`,
|
|
55
|
+
position: 'absolute',
|
|
56
|
+
top: `calc(${dimensions.icon} * .8)`,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const iconVariants = styleVariants({
|
|
60
|
+
default: {},
|
|
61
|
+
small: {
|
|
62
|
+
borderRight: `calc(${dimensions.icon} * .2) solid ${colors.background}`,
|
|
63
|
+
height: '0.75rem',
|
|
64
|
+
left: '0.375rem',
|
|
65
|
+
top: '0.4375rem',
|
|
66
|
+
width: '0.75rem',
|
|
67
|
+
},
|
|
37
68
|
});
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import {useCallback, useEffect, useState, type ComponentType} from 'react';
|
|
2
2
|
import {classNames} from '../../common/functions.tsx';
|
|
3
3
|
import {iconSize} from '../../css/dimensions.css.ts';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
icon,
|
|
6
|
+
iconVariants,
|
|
7
|
+
input,
|
|
8
|
+
inputVariants,
|
|
9
|
+
inputWithIconVariants,
|
|
10
|
+
wrapper,
|
|
11
|
+
} from './index.css.ts';
|
|
5
12
|
|
|
6
13
|
/**
|
|
7
14
|
* The `TextInput` component displays a managed text input with an existing
|
|
@@ -23,6 +30,17 @@ import {icon, input, inputWithIcon, wrapper} from './index.css.ts';
|
|
|
23
30
|
* ```
|
|
24
31
|
* This example shows the TextInput component with an inset icon and
|
|
25
32
|
* placeholder.
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <TextInput initialText="42" variant="small" />
|
|
36
|
+
* ```
|
|
37
|
+
* This example shows the `small` variant of the TextInput component.
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* <TextInput icon={Lucide.Search} placeholder="Search..." variant="small" />
|
|
41
|
+
* ```
|
|
42
|
+
* This example shows the `small` variant of the TextInput component with an
|
|
43
|
+
* inset icon and placeholder.
|
|
26
44
|
* @icon Lucide.TextCursorInput
|
|
27
45
|
*/
|
|
28
46
|
export const TextInput = ({
|
|
@@ -32,6 +50,7 @@ export const TextInput = ({
|
|
|
32
50
|
icon: Icon,
|
|
33
51
|
alt,
|
|
34
52
|
className,
|
|
53
|
+
variant = 'default',
|
|
35
54
|
ref,
|
|
36
55
|
}: {
|
|
37
56
|
/**
|
|
@@ -59,6 +78,15 @@ export const TextInput = ({
|
|
|
59
78
|
* An extra CSS class name for the component.
|
|
60
79
|
*/
|
|
61
80
|
readonly className?: string;
|
|
81
|
+
/**
|
|
82
|
+
* A variant of the input, one of:
|
|
83
|
+
* - `default`
|
|
84
|
+
* - `small`
|
|
85
|
+
*/
|
|
86
|
+
readonly variant?: keyof typeof inputVariants;
|
|
87
|
+
/**
|
|
88
|
+
* A ref to the underlying input element.
|
|
89
|
+
*/
|
|
62
90
|
ref?: React.RefObject<HTMLInputElement | null>;
|
|
63
91
|
}) => {
|
|
64
92
|
const [text, setText] = useState(initialText ?? '');
|
|
@@ -76,15 +104,21 @@ export const TextInput = ({
|
|
|
76
104
|
[change],
|
|
77
105
|
);
|
|
78
106
|
|
|
79
|
-
useEffect(() =>
|
|
107
|
+
useEffect(() => setText(initialText ?? ''), [initialText]);
|
|
80
108
|
|
|
81
109
|
return (
|
|
82
|
-
<div className={wrapper}>
|
|
83
|
-
{Icon ?
|
|
110
|
+
<div className={classNames(wrapper, className)}>
|
|
111
|
+
{Icon ? (
|
|
112
|
+
<Icon className={classNames(iconSize, icon, iconVariants[variant])} />
|
|
113
|
+
) : null}
|
|
84
114
|
<input
|
|
85
115
|
value={text}
|
|
86
116
|
placeholder={placeholder}
|
|
87
|
-
className={classNames(
|
|
117
|
+
className={classNames(
|
|
118
|
+
input,
|
|
119
|
+
inputVariants[variant],
|
|
120
|
+
Icon && inputWithIconVariants[variant],
|
|
121
|
+
)}
|
|
88
122
|
onChange={handleChange}
|
|
89
123
|
title={alt}
|
|
90
124
|
ref={ref}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {table} from '../components/Table/index.css.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `classes` object exposes reusable TinyWidgets CSS classes so they can be
|
|
5
|
+
* applied to markup rendered by other libraries.
|
|
6
|
+
*
|
|
7
|
+
* The current members are:
|
|
8
|
+
* - `table`
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <table className={classes.table}>
|
|
13
|
+
* <thead>
|
|
14
|
+
* <tr>
|
|
15
|
+
* <th>Name</th>
|
|
16
|
+
* <th>Species</th>
|
|
17
|
+
* <th>Color</th>
|
|
18
|
+
* </tr>
|
|
19
|
+
* </thead>
|
|
20
|
+
* <tbody>
|
|
21
|
+
* <tr>
|
|
22
|
+
* <td>Fido</td>
|
|
23
|
+
* <td>Dog</td>
|
|
24
|
+
* <td>Brown</td>
|
|
25
|
+
* </tr>
|
|
26
|
+
* <tr>
|
|
27
|
+
* <td>Felix</td>
|
|
28
|
+
* <td>Cat</td>
|
|
29
|
+
* <td>Black</td>
|
|
30
|
+
* </tr>
|
|
31
|
+
* <tr>
|
|
32
|
+
* <td>Cujo</td>
|
|
33
|
+
* <td>Wolf</td>
|
|
34
|
+
* <td>Gray</td>
|
|
35
|
+
* </tr>
|
|
36
|
+
* </tbody>
|
|
37
|
+
* </table>
|
|
38
|
+
* ```
|
|
39
|
+
* This example applies the TinyWidgets table style to existing table markup.
|
|
40
|
+
* @icon Lucide.Shapes
|
|
41
|
+
*/
|
|
42
|
+
export const classes = {table};
|