aidos-ui 4.0.4 → 4.0.6
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/LICENSE +1 -1
- package/README.md +23 -3
- package/dist/index.d.ts +801 -68
- package/dist/index.js +3934 -68
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +6 -2
- package/dist/jsx-dev-runtime.js +87 -42
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/vite-plugin-jss-debug.d.ts +3 -1
- package/dist/vite-plugin-jss-debug.js +57 -74
- package/dist/vite-plugin-jss-debug.js.map +1 -1
- package/package.json +61 -27
- package/.prettierrc +0 -4
- package/CLAUDE.md +0 -72
- package/dist/Badge.d.ts +0 -6
- package/dist/Badge.js +0 -22
- package/dist/Badge.js.map +0 -1
- package/dist/BaseButton.d.ts +0 -14
- package/dist/BaseButton.js +0 -23
- package/dist/BaseButton.js.map +0 -1
- package/dist/BaseInput.d.ts +0 -14
- package/dist/BaseInput.js +0 -15
- package/dist/BaseInput.js.map +0 -1
- package/dist/BaseLink.d.ts +0 -18
- package/dist/BaseLink.js +0 -29
- package/dist/BaseLink.js.map +0 -1
- package/dist/BaseList.d.ts +0 -6
- package/dist/BaseList.js +0 -14
- package/dist/BaseList.js.map +0 -1
- package/dist/BaseListAddOn.d.ts +0 -5
- package/dist/BaseListAddOn.js +0 -7
- package/dist/BaseListAddOn.js.map +0 -1
- package/dist/BaseListItem.d.ts +0 -26
- package/dist/BaseListItem.js +0 -29
- package/dist/BaseListItem.js.map +0 -1
- package/dist/BaseView.d.ts +0 -12
- package/dist/BaseView.js +0 -26
- package/dist/BaseView.js.map +0 -1
- package/dist/Box.d.ts +0 -4
- package/dist/Box.js +0 -6
- package/dist/Box.js.map +0 -1
- package/dist/Button.d.ts +0 -20
- package/dist/Button.js +0 -19
- package/dist/Button.js.map +0 -1
- package/dist/Calendar.d.ts +0 -18
- package/dist/Calendar.js +0 -57
- package/dist/Calendar.js.map +0 -1
- package/dist/Card.d.ts +0 -4
- package/dist/Card.js +0 -14
- package/dist/Card.js.map +0 -1
- package/dist/Checkbox.d.ts +0 -11
- package/dist/Checkbox.js +0 -32
- package/dist/Checkbox.js.map +0 -1
- package/dist/Circle.d.ts +0 -5
- package/dist/Circle.js +0 -12
- package/dist/Circle.js.map +0 -1
- package/dist/Column.d.ts +0 -6
- package/dist/Column.js +0 -7
- package/dist/Column.js.map +0 -1
- package/dist/DarkMode.d.ts +0 -13
- package/dist/DarkMode.js +0 -62
- package/dist/DarkMode.js.map +0 -1
- package/dist/DateInput.d.ts +0 -13
- package/dist/DateInput.js +0 -29
- package/dist/DateInput.js.map +0 -1
- package/dist/DatePicker.d.ts +0 -11
- package/dist/DatePicker.js +0 -34
- package/dist/DatePicker.js.map +0 -1
- package/dist/DatetimeInput.d.ts +0 -13
- package/dist/DatetimeInput.js +0 -31
- package/dist/DatetimeInput.js.map +0 -1
- package/dist/DesignBook.d.ts +0 -1
- package/dist/DesignBook.js +0 -55
- package/dist/DesignBook.js.map +0 -1
- package/dist/Dialog.d.ts +0 -17
- package/dist/Dialog.js +0 -92
- package/dist/Dialog.js.map +0 -1
- package/dist/Dropdown.d.ts +0 -14
- package/dist/Dropdown.js +0 -65
- package/dist/Dropdown.js.map +0 -1
- package/dist/Emitter.d.ts +0 -6
- package/dist/Emitter.js +0 -19
- package/dist/Emitter.js.map +0 -1
- package/dist/FlexLayout.d.ts +0 -11
- package/dist/FlexLayout.js +0 -18
- package/dist/FlexLayout.js.map +0 -1
- package/dist/Icon.d.ts +0 -12
- package/dist/Icon.js +0 -60
- package/dist/Icon.js.map +0 -1
- package/dist/IconButton.d.ts +0 -11
- package/dist/IconButton.js +0 -34
- package/dist/IconButton.js.map +0 -1
- package/dist/IconLink.d.ts +0 -9
- package/dist/IconLink.js +0 -32
- package/dist/IconLink.js.map +0 -1
- package/dist/IconType.d.ts +0 -1
- package/dist/IconType.js +0 -2
- package/dist/IconType.js.map +0 -1
- package/dist/Interactable.d.ts +0 -50
- package/dist/Interactable.js +0 -169
- package/dist/Interactable.js.map +0 -1
- package/dist/JSSComment.d.ts +0 -10
- package/dist/JSSComment.js +0 -52
- package/dist/JSSComment.js.map +0 -1
- package/dist/Link.d.ts +0 -22
- package/dist/Link.js +0 -29
- package/dist/Link.js.map +0 -1
- package/dist/List.d.ts +0 -15
- package/dist/List.js +0 -29
- package/dist/List.js.map +0 -1
- package/dist/ListButtonItem.d.ts +0 -14
- package/dist/ListButtonItem.js +0 -11
- package/dist/ListButtonItem.js.map +0 -1
- package/dist/ListDivider.d.ts +0 -1
- package/dist/ListDivider.js +0 -12
- package/dist/ListDivider.js.map +0 -1
- package/dist/ListHeaderItem.d.ts +0 -10
- package/dist/ListHeaderItem.js +0 -15
- package/dist/ListHeaderItem.js.map +0 -1
- package/dist/ListItem.d.ts +0 -9
- package/dist/ListItem.js +0 -9
- package/dist/ListItem.js.map +0 -1
- package/dist/ListLinkItem.d.ts +0 -16
- package/dist/ListLinkItem.js +0 -11
- package/dist/ListLinkItem.js.map +0 -1
- package/dist/ListSpacer.d.ts +0 -1
- package/dist/ListSpacer.js +0 -13
- package/dist/ListSpacer.js.map +0 -1
- package/dist/MenuIcon.d.ts +0 -5
- package/dist/MenuIcon.js +0 -31
- package/dist/MenuIcon.js.map +0 -1
- package/dist/NextJSRouter.d.ts +0 -1
- package/dist/NextJSRouter.js +0 -37
- package/dist/NextJSRouter.js.map +0 -1
- package/dist/NextJSRouterState.d.ts +0 -38
- package/dist/NextJSRouterState.js +0 -111
- package/dist/NextJSRouterState.js.map +0 -1
- package/dist/OnVisible.d.ts +0 -5
- package/dist/OnVisible.js +0 -28
- package/dist/OnVisible.js.map +0 -1
- package/dist/Popover.d.ts +0 -22
- package/dist/Popover.js +0 -90
- package/dist/Popover.js.map +0 -1
- package/dist/ProgressBar.d.ts +0 -7
- package/dist/ProgressBar.js +0 -42
- package/dist/ProgressBar.js.map +0 -1
- package/dist/ProgressCircle.d.ts +0 -5
- package/dist/ProgressCircle.js +0 -12
- package/dist/ProgressCircle.js.map +0 -1
- package/dist/Providers.d.ts +0 -9
- package/dist/Providers.js +0 -16
- package/dist/Providers.js.map +0 -1
- package/dist/RangeInput.d.ts +0 -14
- package/dist/RangeInput.js +0 -32
- package/dist/RangeInput.js.map +0 -1
- package/dist/ResultOrError.d.ts +0 -13
- package/dist/ResultOrError.js +0 -7
- package/dist/ResultOrError.js.map +0 -1
- package/dist/RootView.d.ts +0 -5
- package/dist/RootView.js +0 -35
- package/dist/RootView.js.map +0 -1
- package/dist/Row.d.ts +0 -6
- package/dist/Row.js +0 -7
- package/dist/Row.js.map +0 -1
- package/dist/Select.d.ts +0 -9
- package/dist/Select.js +0 -17
- package/dist/Select.js.map +0 -1
- package/dist/StackContext.d.ts +0 -8
- package/dist/StackContext.js +0 -25
- package/dist/StackContext.js.map +0 -1
- package/dist/StaticCheckbox.d.ts +0 -16
- package/dist/StaticCheckbox.js +0 -48
- package/dist/StaticCheckbox.js.map +0 -1
- package/dist/Storage.d.ts +0 -13
- package/dist/Storage.js +0 -146
- package/dist/Storage.js.map +0 -1
- package/dist/Stream.d.ts +0 -9
- package/dist/Stream.js +0 -36
- package/dist/Stream.js.map +0 -1
- package/dist/Sublist.d.ts +0 -12
- package/dist/Sublist.js +0 -18
- package/dist/Sublist.js.map +0 -1
- package/dist/SubmitIconInput.d.ts +0 -8
- package/dist/SubmitIconInput.js +0 -25
- package/dist/SubmitIconInput.js.map +0 -1
- package/dist/Tabs.d.ts +0 -23
- package/dist/Tabs.js +0 -39
- package/dist/Tabs.js.map +0 -1
- package/dist/Text.d.ts +0 -25
- package/dist/Text.js +0 -52
- package/dist/Text.js.map +0 -1
- package/dist/TextArea.d.ts +0 -11
- package/dist/TextArea.js +0 -27
- package/dist/TextArea.js.map +0 -1
- package/dist/TextInput.d.ts +0 -15
- package/dist/TextInput.js +0 -61
- package/dist/TextInput.js.map +0 -1
- package/dist/TextInputWithState.d.ts +0 -8
- package/dist/TextInputWithState.js +0 -14
- package/dist/TextInputWithState.js.map +0 -1
- package/dist/TextPairing.d.ts +0 -21
- package/dist/TextPairing.js +0 -26
- package/dist/TextPairing.js.map +0 -1
- package/dist/TimeInput.d.ts +0 -15
- package/dist/TimeInput.js +0 -58
- package/dist/TimeInput.js.map +0 -1
- package/dist/Tooltip.d.ts +0 -11
- package/dist/Tooltip.js +0 -73
- package/dist/Tooltip.js.map +0 -1
- package/dist/aria.d.ts +0 -8
- package/dist/aria.js +0 -42
- package/dist/aria.js.map +0 -1
- package/dist/guid.d.ts +0 -1
- package/dist/guid.js +0 -7
- package/dist/guid.js.map +0 -1
- package/dist/hash.d.ts +0 -1
- package/dist/hash.js +0 -20
- package/dist/hash.js.map +0 -1
- package/dist/isServer.d.ts +0 -1
- package/dist/isServer.js +0 -4
- package/dist/isServer.js.map +0 -1
- package/dist/jss.d.ts +0 -122
- package/dist/jss.js +0 -515
- package/dist/jss.js.map +0 -1
- package/dist/numberToBase.d.ts +0 -1
- package/dist/numberToBase.js +0 -44
- package/dist/numberToBase.js.map +0 -1
- package/dist/stateMachineContextFactory.d.ts +0 -36
- package/dist/stateMachineContextFactory.js +0 -48
- package/dist/stateMachineContextFactory.js.map +0 -1
- package/dist/useCookie.d.ts +0 -9
- package/dist/useCookie.js +0 -67
- package/dist/useCookie.js.map +0 -1
- package/dist/useKeyboard.d.ts +0 -8
- package/dist/useKeyboard.js +0 -26
- package/dist/useKeyboard.js.map +0 -1
- package/dist/useNavigation.d.ts +0 -5
- package/dist/useNavigation.js +0 -79
- package/dist/useNavigation.js.map +0 -1
- package/dist/usePromise.d.ts +0 -1
- package/dist/usePromise.js +0 -12
- package/dist/usePromise.js.map +0 -1
- package/dist/useRefEffect.d.ts +0 -1
- package/dist/useRefEffect.js +0 -15
- package/dist/useRefEffect.js.map +0 -1
- package/jss-debug-loader.mjs +0 -44
- package/next-env.d.ts +0 -6
- package/next.config.js +0 -33
- package/scripts/embeddings.js +0 -93
- package/scripts/openai_embeddings.js +0 -100
- package/scripts/publish.js +0 -28
- package/scripts/test_embeddings.js +0 -47
- package/src/Badge.tsx +0 -36
- package/src/BaseButton.tsx +0 -62
- package/src/BaseInput.tsx +0 -63
- package/src/BaseLink.tsx +0 -80
- package/src/BaseList.tsx +0 -26
- package/src/BaseListAddOn.tsx +0 -10
- package/src/BaseListItem.tsx +0 -119
- package/src/BaseView.tsx +0 -57
- package/src/Box.tsx +0 -20
- package/src/Button.tsx +0 -90
- package/src/Calendar.tsx +0 -123
- package/src/Card.tsx +0 -30
- package/src/Checkbox.tsx +0 -63
- package/src/Circle.tsx +0 -24
- package/src/Column.tsx +0 -12
- package/src/DarkMode.tsx +0 -100
- package/src/DateInput.tsx +0 -63
- package/src/DatePicker.tsx +0 -67
- package/src/DatetimeInput.tsx +0 -64
- package/src/DesignBook.tsx +0 -677
- package/src/Dialog.tsx +0 -150
- package/src/Dropdown.tsx +0 -146
- package/src/Emitter.ts +0 -26
- package/src/FlexLayout.tsx +0 -53
- package/src/Icon.tsx +0 -80
- package/src/IconButton.tsx +0 -81
- package/src/IconLink.tsx +0 -59
- package/src/IconType.ts +0 -787
- package/src/Interactable.tsx +0 -210
- package/src/JSSComment.tsx +0 -56
- package/src/Link.tsx +0 -110
- package/src/List.tsx +0 -58
- package/src/ListButtonItem.tsx +0 -69
- package/src/ListDivider.tsx +0 -13
- package/src/ListHeaderItem.tsx +0 -45
- package/src/ListItem.tsx +0 -24
- package/src/ListLinkItem.tsx +0 -76
- package/src/ListSpacer.tsx +0 -14
- package/src/MenuIcon.tsx +0 -50
- package/src/NextJSRouter.tsx +0 -60
- package/src/NextJSRouterState.tsx +0 -154
- package/src/OnVisible.tsx +0 -42
- package/src/Popover.tsx +0 -145
- package/src/ProgressBar.tsx +0 -63
- package/src/ProgressCircle.tsx +0 -38
- package/src/Providers.tsx +0 -33
- package/src/RangeInput.tsx +0 -82
- package/src/ResultOrError.ts +0 -15
- package/src/RootView.tsx +0 -55
- package/src/Row.tsx +0 -12
- package/src/Select.tsx +0 -39
- package/src/StackContext.tsx +0 -52
- package/src/StaticCheckbox.tsx +0 -72
- package/src/Storage.tsx +0 -198
- package/src/Stream.tsx +0 -50
- package/src/Sublist.tsx +0 -61
- package/src/SubmitIconInput.tsx +0 -45
- package/src/Tabs.tsx +0 -110
- package/src/Text.tsx +0 -111
- package/src/TextArea.tsx +0 -58
- package/src/TextInput.tsx +0 -123
- package/src/TextInputWithState.tsx +0 -32
- package/src/TextPairing.tsx +0 -115
- package/src/TimeInput.tsx +0 -109
- package/src/Tooltip.tsx +0 -109
- package/src/aria.ts +0 -72
- package/src/docs/mdx.tsx +0 -137
- package/src/docs/pages.ts +0 -115
- package/src/docs/searchIndex.ts +0 -1
- package/src/examples/ExampleDialog.tsx +0 -28
- package/src/guid.ts +0 -7
- package/src/hash.ts +0 -21
- package/src/index.ts +0 -68
- package/src/isServer.ts +0 -3
- package/src/jss.tsx +0 -712
- package/src/jsx-dev-runtime.ts +0 -74
- package/src/jsx-runtime.ts +0 -2
- package/src/numberToBase.ts +0 -52
- package/src/pages/Badge.mdx +0 -152
- package/src/pages/Button.mdx +0 -163
- package/src/pages/Calendar.mdx +0 -254
- package/src/pages/Card.mdx +0 -147
- package/src/pages/Checkbox.mdx +0 -131
- package/src/pages/Dialog.mdx +0 -197
- package/src/pages/FlexLayout.mdx +0 -211
- package/src/pages/Hashing.mdx +0 -211
- package/src/pages/Icon.mdx +0 -171
- package/src/pages/IconButton.mdx +0 -155
- package/src/pages/Link.mdx +0 -160
- package/src/pages/List.mdx +0 -262
- package/src/pages/ListHeader.mdx +0 -220
- package/src/pages/Popover.mdx +0 -223
- package/src/pages/ProgressBar.mdx +0 -200
- package/src/pages/ProgressCircle.mdx +0 -218
- package/src/pages/RangeInput.mdx +0 -237
- package/src/pages/Tabs.mdx +0 -281
- package/src/pages/Text.mdx +0 -154
- package/src/pages/TextInput.mdx +0 -235
- package/src/pages/TextPairing.mdx +0 -204
- package/src/pages/TimeInput.mdx +0 -178
- package/src/pages/Tooltip.mdx +0 -115
- package/src/pages/_app.tsx +0 -466
- package/src/pages/_document.tsx +0 -30
- package/src/pages/css-in-js.mdx +0 -240
- package/src/pages/index.mdx +0 -58
- package/src/pages/navigation.mdx +0 -158
- package/src/pages/prism.css +0 -3
- package/src/pages/useCookie.mdx +0 -176
- package/src/pages/useKeyboard.mdx +0 -257
- package/src/pages/useNavigation.mdx +0 -258
- package/src/pages/usePromise.mdx +0 -280
- package/src/pages/useRefEffect.mdx +0 -251
- package/src/stateMachineContextFactory.tsx +0 -111
- package/src/useCookie.tsx +0 -95
- package/src/useKeyboard.tsx +0 -43
- package/src/useNavigation.tsx +0 -89
- package/src/usePromise.tsx +0 -18
- package/src/useRefEffect.tsx +0 -18
- package/src/vite-plugin-jss-debug.ts +0 -77
- package/tsconfig.build.json +0 -23
- package/tsconfig.json +0 -38
package/src/pages/css-in-js.mdx
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { Button } from "../Button";
|
|
2
|
-
import { Row } from "../Row";
|
|
3
|
-
import { Column } from "../Column";
|
|
4
|
-
import { BaseView } from "../BaseView";
|
|
5
|
-
import { Span } from "../Text";
|
|
6
|
-
import { cssVar, mobile, tablet } from "../jss";
|
|
7
|
-
|
|
8
|
-
# CSS in JS
|
|
9
|
-
|
|
10
|
-
Aidos UI uses a custom CSS-in-JS system called `jss`. Every component accepts a `jss` prop for styling, and the library includes utilities for theming, responsive design, and type-safe CSS variables.
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## The jss prop
|
|
15
|
-
|
|
16
|
-
All components accept a `jss` prop that works like inline styles but with additional capabilities:
|
|
17
|
-
|
|
18
|
-
```js
|
|
19
|
-
<BaseView jss={{ backgroundColor: "red", padding: 12 }} />
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Internally, each property becomes an atomic CSS class with a deterministic hash, enabling server-side rendering and hydration:
|
|
23
|
-
|
|
24
|
-
```html
|
|
25
|
-
<style>
|
|
26
|
-
.x1uc1pme { background: red; }
|
|
27
|
-
.x1kbdebd { padding: 12px; }
|
|
28
|
-
</style>
|
|
29
|
-
<div class="x1uc1pme x1kbdebd" />
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## Arrays and conditionals
|
|
35
|
-
|
|
36
|
-
The `jss` prop accepts arrays and falsy values for conditional styling:
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
<BaseView
|
|
40
|
-
jss={[
|
|
41
|
-
{ padding: 16 },
|
|
42
|
-
isActive && { backgroundColor: "blue" },
|
|
43
|
-
isDisabled && { opacity: 0.5 },
|
|
44
|
-
]}
|
|
45
|
-
/>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
## Automatic pixel conversion
|
|
51
|
-
|
|
52
|
-
Numeric values are automatically converted to pixels for dimensional properties:
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
<BaseView jss={{ padding: 16, fontSize: 14, opacity: 0.5 }} />
|
|
56
|
-
// Results in: padding: 16px; font-size: 14px; opacity: 0.5;
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
## Pseudo-selectors
|
|
62
|
-
|
|
63
|
-
Use string keys for pseudo-classes and pseudo-elements:
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
// Hover state
|
|
67
|
-
jss({ ":hover": { backgroundColor: "blue" } })
|
|
68
|
-
|
|
69
|
-
// Focus state
|
|
70
|
-
jss({ ":focus": { outline: "2px solid blue" } })
|
|
71
|
-
|
|
72
|
-
// First child
|
|
73
|
-
jss({ ":first-child": { marginTop: 0 } })
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
---
|
|
77
|
-
|
|
78
|
-
## Descendant selectors
|
|
79
|
-
|
|
80
|
-
Target child elements with space-prefixed selectors:
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
// All child divs
|
|
84
|
-
jss({ " div": { padding: 8 } })
|
|
85
|
-
|
|
86
|
-
// Direct children
|
|
87
|
-
jss({ " > span": { color: "red" } })
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
---
|
|
91
|
-
|
|
92
|
-
## Media queries
|
|
93
|
-
|
|
94
|
-
Use media query strings as keys:
|
|
95
|
-
|
|
96
|
-
```js
|
|
97
|
-
jss({
|
|
98
|
-
padding: 8,
|
|
99
|
-
"@media (min-width: 750px)": {
|
|
100
|
-
padding: 16,
|
|
101
|
-
},
|
|
102
|
-
})
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
---
|
|
106
|
-
|
|
107
|
-
## Responsive helpers
|
|
108
|
-
|
|
109
|
-
The library provides helper functions for common breakpoints:
|
|
110
|
-
|
|
111
|
-
```js
|
|
112
|
-
import { mobile, tablet, laptop, desktop } from "aidos-ui";
|
|
113
|
-
|
|
114
|
-
<BaseView
|
|
115
|
-
jss={[
|
|
116
|
-
{ padding: 8 },
|
|
117
|
-
tablet({ padding: 16 }),
|
|
118
|
-
desktop({ padding: 24 }),
|
|
119
|
-
]}
|
|
120
|
-
/>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
| Helper | Breakpoint |
|
|
124
|
-
|--------|------------|
|
|
125
|
-
| `mobile()` | max-width: 479px |
|
|
126
|
-
| `tablet()` | min-width: 480px |
|
|
127
|
-
| `laptop()` | min-width: 1024px |
|
|
128
|
-
| `desktop()` | min-width: 1280px |
|
|
129
|
-
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
## CSS variables
|
|
133
|
-
|
|
134
|
-
Use the `cssVar()` helper for type-safe access to theme variables:
|
|
135
|
-
|
|
136
|
-
<Row justify="center" padding="medium">
|
|
137
|
-
<Button
|
|
138
|
-
jss={{ border: `4px solid ${cssVar("--warning")}` }}
|
|
139
|
-
color="positive"
|
|
140
|
-
onClick={() => {}}
|
|
141
|
-
>
|
|
142
|
-
Styled button
|
|
143
|
-
</Button>
|
|
144
|
-
</Row>
|
|
145
|
-
|
|
146
|
-
```js
|
|
147
|
-
import { cssVar } from "aidos-ui";
|
|
148
|
-
|
|
149
|
-
<BaseView jss={{
|
|
150
|
-
backgroundColor: cssVar("--primary-background"),
|
|
151
|
-
color: cssVar("--primary-text"),
|
|
152
|
-
padding: cssVar("--spacing-m"),
|
|
153
|
-
}} />
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
---
|
|
157
|
-
|
|
158
|
-
## Available CSS variables
|
|
159
|
-
|
|
160
|
-
### Colors
|
|
161
|
-
|
|
162
|
-
| Variable | Purpose |
|
|
163
|
-
|----------|---------|
|
|
164
|
-
| `--primary-background` | Main background |
|
|
165
|
-
| `--secondary-background` | Alternate background |
|
|
166
|
-
| `--overlay-background` | Modal/popover background |
|
|
167
|
-
| `--divider` | Border/divider color |
|
|
168
|
-
| `--highlight` | Accent/brand color |
|
|
169
|
-
| `--warning` | Warning indicator |
|
|
170
|
-
|
|
171
|
-
### Text colors
|
|
172
|
-
|
|
173
|
-
| Variable | Purpose |
|
|
174
|
-
|----------|---------|
|
|
175
|
-
| `--primary-text` | Main text |
|
|
176
|
-
| `--secondary-text` | Supporting text |
|
|
177
|
-
| `--subtle-text` | Muted/disabled text |
|
|
178
|
-
| `--highlight-text` | Accent text |
|
|
179
|
-
| `--negative-text` | Error/destructive text |
|
|
180
|
-
| `--light-text` | Text on dark backgrounds |
|
|
181
|
-
|
|
182
|
-
### Interactive states
|
|
183
|
-
|
|
184
|
-
| Variable | Purpose |
|
|
185
|
-
|----------|---------|
|
|
186
|
-
| `--hovered-background` | Hover state |
|
|
187
|
-
| `--pressed-background` | Active/pressed state |
|
|
188
|
-
| `--selected-background` | Selected item |
|
|
189
|
-
|
|
190
|
-
### Button backgrounds
|
|
191
|
-
|
|
192
|
-
| Variable | Purpose |
|
|
193
|
-
|----------|---------|
|
|
194
|
-
| `--background-button-positive` | Positive action buttons |
|
|
195
|
-
| `--background-button-secondary` | Secondary buttons |
|
|
196
|
-
| `--background-button-negative` | Destructive buttons |
|
|
197
|
-
| `--background-button-disabled` | Disabled buttons |
|
|
198
|
-
|
|
199
|
-
### Spacing
|
|
200
|
-
|
|
201
|
-
| Variable | Size |
|
|
202
|
-
|----------|------|
|
|
203
|
-
| `--spacing-xs` | 4px |
|
|
204
|
-
| `--spacing-s` | 8px |
|
|
205
|
-
| `--spacing-m` | 12px |
|
|
206
|
-
| `--spacing-l` | 16px |
|
|
207
|
-
| `--spacing-xl` | 24px |
|
|
208
|
-
| `--spacing-xxl` | 32px |
|
|
209
|
-
| `--spacing-xxxl` | 48px |
|
|
210
|
-
|
|
211
|
-
### Border radius
|
|
212
|
-
|
|
213
|
-
| Variable | Size |
|
|
214
|
-
|----------|------|
|
|
215
|
-
| `--border-radius-s` | 4px |
|
|
216
|
-
| `--border-radius-m` | 8px |
|
|
217
|
-
| `--border-radius-l` | 12px |
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
## Using toClassnames directly
|
|
222
|
-
|
|
223
|
-
For custom components, use `toClassnames()` to convert style objects to class names:
|
|
224
|
-
|
|
225
|
-
```js
|
|
226
|
-
import { toClassnames } from "aidos-ui";
|
|
227
|
-
|
|
228
|
-
function CustomComponent({ active }) {
|
|
229
|
-
return (
|
|
230
|
-
<div
|
|
231
|
-
className={toClassnames([
|
|
232
|
-
{ padding: 16, borderRadius: 8 },
|
|
233
|
-
active && { backgroundColor: "blue" },
|
|
234
|
-
])}
|
|
235
|
-
>
|
|
236
|
-
Content
|
|
237
|
-
</div>
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
```
|
package/src/pages/index.mdx
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# Aidos UI
|
|
2
|
-
|
|
3
|
-
This is a React design system library with many utilities and zero dependencies. It was built with the aim to be simple, lightweight and beautiful.
|
|
4
|
-
|
|
5
|
-
- [Why](/#why)
|
|
6
|
-
- [Who is this for](/#who-is-this-for)
|
|
7
|
-
- [Design philosophy](/#design-philosophy)
|
|
8
|
-
- [Installation](/#installation)
|
|
9
|
-
- [How to use](/#how-to-use)
|
|
10
|
-
|
|
11
|
-
## Why?
|
|
12
|
-
|
|
13
|
-
Over the years I have always have many side projects, and many of them needed a UI. I disliked every available library because they had so much code to support many cases I did not care about. Back in 2019 I thought, maybe I could make my own design system, with just enough javascript to do things exactly how I wanted them to be, and so I did. Since then it has changed quite a bit and it is now something I am more or less proud of. It has everything I have ever needed and it is done in the way I find simplest and least convoluted. This is all ultimately very subjective, and that is fine, because the first design decision of this library was that it would be extremely opinionated. With that said, although this library does not lend it self to modification, it does tend to be fairly easy to extend and compose with it. I am now making this documentation with the vague weak conviction that someone out there may benefit from it. I still dislike other design libraries not because they are not capable but becuse they are too general purpose. I wanted this library to be not-general purpose, but if this happens to fit your needs, it should be the lightest and simplest option available. This will not try to solve all your problems but it will solve a few problems really well.
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## Who is this for?
|
|
18
|
-
|
|
19
|
-
I initially only planned to use this myself so its features and design have so far reflected the things I have been working on. However I keep extending this library, and I think that with more users it may be possible to add more ideas and usecases so that this becomes a really complete system.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## Design philosophy
|
|
24
|
-
|
|
25
|
-
1. <b>Opinionated</b>
|
|
26
|
-
|
|
27
|
-
First and foremost, this library is extremely opinionated. This is so because I believe HTML is too low level and error prone, CSS defaults are not beautiful enough, and the web in general too big a toolkit to make simple things work in the way you expect. So, for the sake of simplicity, this library imposes opinions at every step. These opinions will not fit everyone's needs, and that is a sacrifice that can be made for the sake of simplicity.
|
|
28
|
-
|
|
29
|
-
3. <b>Modular</b>
|
|
30
|
-
|
|
31
|
-
There is no limit to the number of features and components that can be added, as long as every piece remains modular, or at most, composed out of its simpler parts. This is important to keep bundle sizes under control and also to keep the API sane. Modular components imply abstractions that do not depend on each other. This helps keep overall complexity low, so that it is simpler to extend the system.
|
|
32
|
-
|
|
33
|
-
3. <b>Accessible</b>
|
|
34
|
-
|
|
35
|
-
By design every component should be accessible, paying attention to keyboard navigation, focusable elements, adding helpful aria properties and following wcag specificaitons as faithfully as possible.
|
|
36
|
-
|
|
37
|
-
4. <b>Dependency free</b>
|
|
38
|
-
|
|
39
|
-
As few dependencies as possible, to keep things light and under control. The only dependency right now is [iconify](https://github.com/iconify/iconify) because I am not able to re-create all icons myself.
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## Installation
|
|
44
|
-
|
|
45
|
-
This library can be installed through npm
|
|
46
|
-
|
|
47
|
-
```bash
|
|
48
|
-
npm install --save aidos-ui
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
---
|
|
52
|
-
|
|
53
|
-
## How to use
|
|
54
|
-
|
|
55
|
-
- The `Providers` component somewhere in the application.
|
|
56
|
-
- If the application is running in nextjs, the `JSServerStyles` component has to be used in the \_document `<Head />`, this enables jss to work also server side.
|
|
57
|
-
|
|
58
|
-
---
|
package/src/pages/navigation.mdx
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { List } from "../List";
|
|
2
|
-
import { ListButtonItem } from "../ListButtonItem";
|
|
3
|
-
|
|
4
|
-
# List Navigation
|
|
5
|
-
|
|
6
|
-
Lists support built-in keyboard navigation using the `useNavigation` hook. This creates an accessible, keyboard-friendly experience following WAI-ARIA patterns.
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## Enabling navigation
|
|
11
|
-
|
|
12
|
-
Use the `navigation` prop to enable or disable keyboard navigation:
|
|
13
|
-
|
|
14
|
-
<List ariaLabel="example" navigation={true}>
|
|
15
|
-
<ListButtonItem color="secondary" headline="Headline 1" onClick={() => {}} />
|
|
16
|
-
<ListButtonItem color="secondary" headline="Headline 2" onClick={() => {}} />
|
|
17
|
-
<ListButtonItem
|
|
18
|
-
withDivider={false}
|
|
19
|
-
color="secondary"
|
|
20
|
-
headline="Headline 3"
|
|
21
|
-
onClick={() => {}}
|
|
22
|
-
/>
|
|
23
|
-
</List>
|
|
24
|
-
|
|
25
|
-
```js
|
|
26
|
-
<List ariaLabel="example" navigation={true}>
|
|
27
|
-
<ListButtonItem headline="Headline 1" onClick={() => {}} />
|
|
28
|
-
<ListButtonItem headline="Headline 2" onClick={() => {}} />
|
|
29
|
-
<ListButtonItem headline="Headline 3" onClick={() => {}} />
|
|
30
|
-
</List>
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## Without navigation
|
|
36
|
-
|
|
37
|
-
When `navigation` is `false`, each item is a separate tab stop:
|
|
38
|
-
|
|
39
|
-
<List ariaLabel="example" navigation={false}>
|
|
40
|
-
<ListButtonItem color="secondary" headline="Headline 1" onClick={() => {}} />
|
|
41
|
-
<ListButtonItem color="secondary" headline="Headline 2" onClick={() => {}} />
|
|
42
|
-
<ListButtonItem
|
|
43
|
-
withDivider={false}
|
|
44
|
-
color="secondary"
|
|
45
|
-
headline="Headline 3"
|
|
46
|
-
onClick={() => {}}
|
|
47
|
-
/>
|
|
48
|
-
</List>
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
<List ariaLabel="example" navigation={false}>
|
|
52
|
-
<ListButtonItem headline="Headline 1" onClick={() => {}} />
|
|
53
|
-
<ListButtonItem headline="Headline 2" onClick={() => {}} />
|
|
54
|
-
<ListButtonItem headline="Headline 3" onClick={() => {}} />
|
|
55
|
-
</List>
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
## Keyboard controls
|
|
61
|
-
|
|
62
|
-
When navigation is enabled:
|
|
63
|
-
|
|
64
|
-
| Key | Action |
|
|
65
|
-
|-----|--------|
|
|
66
|
-
| **Arrow Down** | Move to next item |
|
|
67
|
-
| **Arrow Up** | Move to previous item |
|
|
68
|
-
| **Arrow Right** | Move to next item |
|
|
69
|
-
| **Arrow Left** | Move to previous item |
|
|
70
|
-
| **Enter / Space** | Activate the focused item |
|
|
71
|
-
| **Tab** | Move focus out of the list |
|
|
72
|
-
|
|
73
|
-
Navigation wraps around - pressing down on the last item moves to the first.
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## How it works
|
|
78
|
-
|
|
79
|
-
The navigation system uses `tabIndex` management:
|
|
80
|
-
|
|
81
|
-
1. **Single tab stop**: The entire list is one tab stop
|
|
82
|
-
2. **Active item**: Gets `tabIndex="0"` (focusable)
|
|
83
|
-
3. **Other items**: Get `tabIndex="-1"` (not in tab order)
|
|
84
|
-
4. **Arrow keys**: Move the active state between items
|
|
85
|
-
|
|
86
|
-
This follows the [WAI-ARIA grid layout pattern](https://www.w3.org/WAI/ARIA/apg/patterns/grid/examples/layout-grids/).
|
|
87
|
-
|
|
88
|
-
---
|
|
89
|
-
|
|
90
|
-
## Benefits
|
|
91
|
-
|
|
92
|
-
**With navigation enabled:**
|
|
93
|
-
- Faster keyboard navigation (single Tab to enter list)
|
|
94
|
-
- Arrow keys to move between items
|
|
95
|
-
- Better for long lists
|
|
96
|
-
- More efficient for power users
|
|
97
|
-
|
|
98
|
-
**With navigation disabled:**
|
|
99
|
-
- Standard Tab behavior between items
|
|
100
|
-
- Simpler mental model
|
|
101
|
-
- Better for short lists (2-3 items)
|
|
102
|
-
- Each item is independently focusable
|
|
103
|
-
|
|
104
|
-
---
|
|
105
|
-
|
|
106
|
-
## Accessibility considerations
|
|
107
|
-
|
|
108
|
-
Always provide an `ariaLabel` for the list:
|
|
109
|
-
|
|
110
|
-
```js
|
|
111
|
-
<List ariaLabel="Search results" navigation={true}>
|
|
112
|
-
{/* items */}
|
|
113
|
-
</List>
|
|
114
|
-
|
|
115
|
-
<List ariaLabel="User menu options" navigation={true}>
|
|
116
|
-
{/* items */}
|
|
117
|
-
</List>
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
This helps screen reader users understand the list's purpose.
|
|
121
|
-
|
|
122
|
-
---
|
|
123
|
-
|
|
124
|
-
## When to use navigation
|
|
125
|
-
|
|
126
|
-
**Enable navigation for:**
|
|
127
|
-
- Long lists (5+ items)
|
|
128
|
-
- Menu-like interfaces
|
|
129
|
-
- Search results
|
|
130
|
-
- Option lists
|
|
131
|
-
- File browsers
|
|
132
|
-
|
|
133
|
-
**Disable navigation for:**
|
|
134
|
-
- Short action lists (2-3 items)
|
|
135
|
-
- Form field groups
|
|
136
|
-
- Simple button groups
|
|
137
|
-
- When each item needs independent focus
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## Implementation
|
|
142
|
-
|
|
143
|
-
Lists use the `useNavigation` hook internally:
|
|
144
|
-
|
|
145
|
-
```js
|
|
146
|
-
// Simplified internal implementation
|
|
147
|
-
function List({ navigation = true, children, ariaLabel }) {
|
|
148
|
-
const rootRef = useNavigation({ enabled: navigation });
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
<ul ref={rootRef} aria-label={ariaLabel}>
|
|
152
|
-
{children}
|
|
153
|
-
</ul>
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
See the [useNavigation documentation](/useNavigation) for more details on the underlying hook.
|
package/src/pages/prism.css
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/* PrismJS 1.29.0
|
|
2
|
-
https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+jsx+tsx+typescript */
|
|
3
|
-
code[class*=language-],pre[class*=language-]{color:#ccc;background:0 0;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#2d2d2d}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.block-comment,.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#999}.token.punctuation{color:#ccc}.token.attr-name,.token.deleted,.token.namespace,.token.tag{color:#e2777a}.token.function-name{color:#6196cc}.token.boolean,.token.function,.token.number{color:#f08d49}.token.class-name,.token.constant,.token.property,.token.symbol{color:#f8c555}.token.atrule,.token.builtin,.token.important,.token.keyword,.token.selector{color:#cc99cd}.token.attr-value,.token.char,.token.regex,.token.string,.token.variable{color:#7ec699}.token.entity,.token.operator,.token.url{color:#67cdcc}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.inserted{color:green}
|
package/src/pages/useCookie.mdx
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
# useCookie
|
|
2
|
-
|
|
3
|
-
A React hook for reading and writing browser cookies with React state-like API. Handles SSR gracefully and persists values across page reloads.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## Signature
|
|
8
|
-
|
|
9
|
-
```ts
|
|
10
|
-
function useCookie<T, L>(
|
|
11
|
-
key: string,
|
|
12
|
-
options: {
|
|
13
|
-
initialValue: T;
|
|
14
|
-
loadingValue: L;
|
|
15
|
-
serialize?: (value: T) => string;
|
|
16
|
-
deserialize?: (value: string) => T;
|
|
17
|
-
maxAge?: number;
|
|
18
|
-
}
|
|
19
|
-
): [T | L, (value: T | ((prev: T | L) => T)) => void]
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
## Parameters
|
|
25
|
-
|
|
26
|
-
| Parameter | Type | Default | Description |
|
|
27
|
-
|-----------|------|---------|-------------|
|
|
28
|
-
| `key` | `string` | Required | Cookie name |
|
|
29
|
-
| `options.initialValue` | `T` | Required | Value to set if cookie doesn't exist |
|
|
30
|
-
| `options.loadingValue` | `L` | Required | Value to use during SSR or initial load |
|
|
31
|
-
| `options.serialize` | `(T) => string` | `JSON.stringify` | Custom serialization function |
|
|
32
|
-
| `options.deserialize` | `(string) => T` | `JSON.parse` | Custom deserialization function |
|
|
33
|
-
| `options.maxAge` | `number` | 1 year | Cookie expiration in seconds |
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## Returns
|
|
38
|
-
|
|
39
|
-
Returns a tuple similar to `useState`:
|
|
40
|
-
|
|
41
|
-
1. **Current value** - The cookie value (or `loadingValue` during SSR)
|
|
42
|
-
2. **Setter function** - Updates the cookie (accepts value or callback)
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## Basic usage
|
|
47
|
-
|
|
48
|
-
```js
|
|
49
|
-
import { useCookie } from "aidos-ui";
|
|
50
|
-
|
|
51
|
-
function Settings() {
|
|
52
|
-
const [theme, setTheme] = useCookie("theme", {
|
|
53
|
-
initialValue: "light",
|
|
54
|
-
loadingValue: "light",
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<Button onClick={() => setTheme(theme === "light" ? "dark" : "light")}>
|
|
59
|
-
Current: {theme}
|
|
60
|
-
</Button>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
## With callback setter
|
|
68
|
-
|
|
69
|
-
Like `useState`, the setter accepts a callback function:
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
const [count, setCount] = useCookie("visit-count", {
|
|
73
|
-
initialValue: 0,
|
|
74
|
-
loadingValue: 0,
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// Increment based on previous value
|
|
78
|
-
setCount((prev) => prev + 1);
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
---
|
|
82
|
-
|
|
83
|
-
## SSR handling
|
|
84
|
-
|
|
85
|
-
The `loadingValue` is used during server-side rendering when cookies aren't available:
|
|
86
|
-
|
|
87
|
-
```js
|
|
88
|
-
const [user, setUser] = useCookie("user-preferences", {
|
|
89
|
-
initialValue: { notifications: true },
|
|
90
|
-
loadingValue: null, // Renders nothing during SSR
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
if (user === null) {
|
|
94
|
-
return <Spinner />;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return <Settings preferences={user} />;
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## Custom serialization
|
|
103
|
-
|
|
104
|
-
For complex data or non-JSON formats:
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
const [date, setDate] = useCookie("last-visit", {
|
|
108
|
-
initialValue: new Date(),
|
|
109
|
-
loadingValue: null,
|
|
110
|
-
serialize: (d) => d.toISOString(),
|
|
111
|
-
deserialize: (s) => new Date(s),
|
|
112
|
-
});
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## Custom expiration
|
|
118
|
-
|
|
119
|
-
Set cookie expiration with `maxAge` (in seconds):
|
|
120
|
-
|
|
121
|
-
```js
|
|
122
|
-
// Expire in 1 hour
|
|
123
|
-
const [session, setSession] = useCookie("session", {
|
|
124
|
-
initialValue: null,
|
|
125
|
-
loadingValue: null,
|
|
126
|
-
maxAge: 60 * 60, // 1 hour
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
// Expire in 30 days
|
|
130
|
-
const [preferences, setPreferences] = useCookie("prefs", {
|
|
131
|
-
initialValue: {},
|
|
132
|
-
loadingValue: {},
|
|
133
|
-
maxAge: 60 * 60 * 24 * 30, // 30 days
|
|
134
|
-
});
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
---
|
|
138
|
-
|
|
139
|
-
## Helper functions
|
|
140
|
-
|
|
141
|
-
The module also exports utility functions:
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
import { hasCookie, getCookie } from "aidos-ui";
|
|
145
|
-
|
|
146
|
-
// Check if cookie exists
|
|
147
|
-
if (hasCookie("user-token")) {
|
|
148
|
-
// ...
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Get cookie value directly
|
|
152
|
-
const token = getCookie("user-token");
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
---
|
|
156
|
-
|
|
157
|
-
## Dark mode example
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
function App() {
|
|
161
|
-
const [darkMode, setDarkMode] = useCookie("dark-mode", {
|
|
162
|
-
initialValue: false,
|
|
163
|
-
loadingValue: false,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
document.body.classList.toggle("dark-mode", darkMode);
|
|
168
|
-
}, [darkMode]);
|
|
169
|
-
|
|
170
|
-
return (
|
|
171
|
-
<Button onClick={() => setDarkMode(!darkMode)}>
|
|
172
|
-
{darkMode ? "Light mode" : "Dark mode"}
|
|
173
|
-
</Button>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
```
|