tinywidgets 1.5.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 +1 -1
- 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 +28 -28
- 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 +5 -1
- package/src/stores/RouteStore.tsx +52 -14
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {createTheme, fallbackVar, style} from '@vanilla-extract/css';
|
|
2
2
|
|
|
3
3
|
const classAndObject = createTheme({
|
|
4
|
-
logo: fallbackVar('var(--tinyWidgets-logo)', '2rem'),
|
|
5
4
|
avatar: fallbackVar('var(--tinyWidgets-avatar)', '2rem'),
|
|
5
|
+
footerHeight: fallbackVar('var(--tinyWidgets-footerHeight)', '2rem'),
|
|
6
6
|
icon: fallbackVar('var(--tinyWidgets-icon)', '1rem'),
|
|
7
|
+
logo: fallbackVar('var(--tinyWidgets-logo)', '2rem'),
|
|
7
8
|
padding: fallbackVar('var(--tinyWidgets-padding)', '1rem'),
|
|
8
9
|
radius: fallbackVar('var(--tinyWidgets-radius)', '0.5rem'),
|
|
9
10
|
sideNavWidth: fallbackVar('var(--tinyWidgets-sideNavWidth)', '20rem'),
|
|
10
11
|
topNavHeight: fallbackVar('var(--tinyWidgets-topNavHeight)', '4rem'),
|
|
11
|
-
footerHeight: fallbackVar('var(--tinyWidgets-footerHeight)', '2rem'),
|
|
12
12
|
});
|
|
13
13
|
export const dimensionsClass = classAndObject[0];
|
|
14
14
|
|
package/src/css/global.css.ts
CHANGED
|
@@ -2,10 +2,10 @@ import {globalStyle} from '@vanilla-extract/css';
|
|
|
2
2
|
import {small} from '../common/functions';
|
|
3
3
|
|
|
4
4
|
globalStyle('*', {
|
|
5
|
-
margin: 0,
|
|
6
|
-
padding: 0,
|
|
7
5
|
boxSizing: 'border-box',
|
|
8
6
|
color: 'inherit',
|
|
9
7
|
fontSize: 'inherit',
|
|
8
|
+
margin: 0,
|
|
9
|
+
padding: 0,
|
|
10
10
|
...small({fontSize: '0.9rem'}),
|
|
11
11
|
});
|
package/src/index.css.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -21,4 +21,8 @@ export {TextInput} from './components/TextInput/index.tsx';
|
|
|
21
21
|
|
|
22
22
|
export {classNames} from './common/functions.tsx';
|
|
23
23
|
export {useDark} from './stores/LocalStore.tsx';
|
|
24
|
-
export {
|
|
24
|
+
export {
|
|
25
|
+
useRoute,
|
|
26
|
+
useRouteParts,
|
|
27
|
+
useSetRouteCallback,
|
|
28
|
+
} from './stores/RouteStore.tsx';
|
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
import {createCustomPersister} from 'tinybase/persisters/with-schemas';
|
|
2
2
|
import * as UiReact from 'tinybase/ui-react/with-schemas';
|
|
3
|
-
import {type
|
|
3
|
+
import {createStore, type Store} from 'tinybase/with-schemas';
|
|
4
4
|
import {READY, READY_SCHEMA} from './common';
|
|
5
5
|
|
|
6
6
|
const ROUTE_STORE = 'tinywidgets/Route';
|
|
7
|
-
const
|
|
7
|
+
const ROUTE_PARTS = 'routeParts';
|
|
8
|
+
const PARTS = 'parts';
|
|
8
9
|
|
|
10
|
+
const TABLES_SCHEMA = {
|
|
11
|
+
[ROUTE_PARTS]: {[PARTS]: {type: 'string', default: ''}},
|
|
12
|
+
} as const;
|
|
9
13
|
const VALUES_SCHEMA = {
|
|
10
14
|
...READY_SCHEMA,
|
|
11
|
-
[ROUTE]: {type: 'string', default: ''},
|
|
12
15
|
} as const;
|
|
13
|
-
type Schemas = [
|
|
16
|
+
type Schemas = [typeof TABLES_SCHEMA, typeof VALUES_SCHEMA];
|
|
17
|
+
type RouteStore = Store<Schemas>;
|
|
14
18
|
|
|
15
19
|
const {
|
|
20
|
+
useCell,
|
|
16
21
|
useCreateStore,
|
|
17
|
-
useProvideStore,
|
|
18
22
|
useCreatePersister,
|
|
23
|
+
useSetTablesCallback,
|
|
24
|
+
useProvideStore,
|
|
19
25
|
useValue,
|
|
20
|
-
useSetValueCallback,
|
|
21
26
|
} = UiReact as UiReact.WithSchemas<Schemas>;
|
|
22
27
|
|
|
28
|
+
const getRouteTables = (route: string) => {
|
|
29
|
+
const parts = route.split('/');
|
|
30
|
+
return {
|
|
31
|
+
[ROUTE_PARTS]: Object.fromEntries([
|
|
32
|
+
['0', {[PARTS]: route}],
|
|
33
|
+
...parts.map((_, index) => [
|
|
34
|
+
index + 1 + '',
|
|
35
|
+
{[PARTS]: parts.slice(0, index + 1).join('/')},
|
|
36
|
+
]),
|
|
37
|
+
]),
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
23
41
|
/**
|
|
24
42
|
* The useRoute hook returns the current route, assuming the app is using the
|
|
25
43
|
* basic TinyWidgets routing system.
|
|
@@ -37,7 +55,30 @@ const {
|
|
|
37
55
|
* ```
|
|
38
56
|
* This example shows the hook returning the current route.
|
|
39
57
|
*/
|
|
40
|
-
export const useRoute = () =>
|
|
58
|
+
export const useRoute = () => useRouteParts(0).join('/');
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The useRouteParts hook returns the current route truncated to a number of
|
|
62
|
+
* slash-separated parts.
|
|
63
|
+
*
|
|
64
|
+
* This hook will only cause a rerender when the relevant part of the route
|
|
65
|
+
* changes. For example, if the route is `a/b/c/d`, then `useRouteParts(2)` will
|
|
66
|
+
* return `['a', 'b']` and will only cause a rerender when the first or second
|
|
67
|
+
* part of the route changes, but not when the third or fourth part changes.
|
|
68
|
+
*
|
|
69
|
+
* @param length The number of route parts to include. Use 0 for the full route.
|
|
70
|
+
* @returns The route path, or an empty string if it does not exist.
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* <ul>
|
|
74
|
+
* <li>{useRouteParts(1).join(' » ')}</li>
|
|
75
|
+
* <li>{useRouteParts(2).join(' » ')}</li>
|
|
76
|
+
* <li>{useRouteParts(0).join(' » ')}</li>
|
|
77
|
+
* </ul>
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export const useRouteParts = (length: number) =>
|
|
81
|
+
useCell(ROUTE_PARTS, length + '', PARTS, ROUTE_STORE)?.split('/') ?? [];
|
|
41
82
|
|
|
42
83
|
/**
|
|
43
84
|
* The useSetRouteCallback hook a callback for setting the current route,
|
|
@@ -60,14 +101,14 @@ export const useRoute = () => useValue(ROUTE, ROUTE_STORE);
|
|
|
60
101
|
* route when called as a click handler.
|
|
61
102
|
*/
|
|
62
103
|
export const useSetRouteCallback = () =>
|
|
63
|
-
|
|
104
|
+
useSetTablesCallback(getRouteTables, [], ROUTE_STORE);
|
|
64
105
|
|
|
65
106
|
export const useRouteStoreIsReady = () =>
|
|
66
107
|
useValue(READY, ROUTE_STORE) as boolean;
|
|
67
108
|
|
|
68
109
|
export const RouteStore = () => {
|
|
69
110
|
const routeStore = useCreateStore(() =>
|
|
70
|
-
createStore().
|
|
111
|
+
createStore().setSchema(TABLES_SCHEMA, VALUES_SCHEMA),
|
|
71
112
|
);
|
|
72
113
|
useProvideStore(ROUTE_STORE, routeStore);
|
|
73
114
|
|
|
@@ -76,12 +117,9 @@ export const RouteStore = () => {
|
|
|
76
117
|
(routeStore) =>
|
|
77
118
|
createCustomPersister(
|
|
78
119
|
routeStore,
|
|
79
|
-
async () => [
|
|
120
|
+
async () => [getRouteTables(location.hash.slice(1)), {ready: true}],
|
|
80
121
|
async (getContent) => {
|
|
81
|
-
|
|
82
|
-
if (route) {
|
|
83
|
-
location.hash = route;
|
|
84
|
-
}
|
|
122
|
+
location.hash = getContent()[0][ROUTE_PARTS]?.['0']?.[PARTS] ?? '';
|
|
85
123
|
},
|
|
86
124
|
(listener) => {
|
|
87
125
|
const hashListener = () => listener();
|