@cognitap/radiant 0.0.6 → 0.0.8
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 +82 -395
- package/README.md +41 -1014
- package/RELEASE_POLICY.md +3 -3
- package/dist/library/Accordion.d.ts +3 -0
- package/dist/library/Accordion.d.ts.map +1 -1
- package/dist/library/Accordion.js +1 -1
- package/dist/library/Accordion.js.map +1 -1
- package/dist/library/Button.d.ts +5 -0
- package/dist/library/Button.d.ts.map +1 -1
- package/dist/library/Button.js +8 -7
- package/dist/library/Button.js.map +1 -1
- package/dist/library/Card.d.ts +2 -0
- package/dist/library/Card.d.ts.map +1 -1
- package/dist/library/Card.js +1 -1
- package/dist/library/Card.js.map +1 -1
- package/dist/library/Checkbox.d.ts +5 -0
- package/dist/library/Checkbox.d.ts.map +1 -1
- package/dist/library/Checkbox.js +3 -2
- package/dist/library/Checkbox.js.map +1 -1
- package/dist/library/Collapsible.d.ts +4 -0
- package/dist/library/Collapsible.d.ts.map +1 -1
- package/dist/library/Collapsible.js +22 -4
- package/dist/library/Collapsible.js.map +1 -1
- package/dist/library/Dialog.d.ts +3 -0
- package/dist/library/Dialog.d.ts.map +1 -1
- package/dist/library/Dialog.js.map +1 -1
- package/dist/library/Field.d.ts +8 -0
- package/dist/library/Field.d.ts.map +1 -1
- package/dist/library/Field.js +2 -0
- package/dist/library/Field.js.map +1 -1
- package/dist/library/Input.d.ts +3 -0
- package/dist/library/Input.d.ts.map +1 -1
- package/dist/library/Input.js +1 -0
- package/dist/library/Input.js.map +1 -1
- package/dist/library/Link.d.ts +5 -0
- package/dist/library/Link.d.ts.map +1 -1
- package/dist/library/Link.js.map +1 -1
- package/dist/library/RadioGroup.d.ts +8 -0
- package/dist/library/RadioGroup.d.ts.map +1 -1
- package/dist/library/RadioGroup.js +4 -2
- package/dist/library/RadioGroup.js.map +1 -1
- package/dist/library/Select.d.ts +87 -0
- package/dist/library/Select.d.ts.map +1 -0
- package/dist/library/Select.js +454 -0
- package/dist/library/Select.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +20 -3
- package/dist/library/cn.js.map +1 -1
- package/dist/library/examples/expressive.d.ts +4 -0
- package/dist/library/examples/expressive.d.ts.map +1 -0
- package/dist/library/{themes → examples}/expressive.js +4 -3
- package/dist/library/examples/expressive.js.map +1 -0
- package/dist/library/examples/glass.d.ts +4 -0
- package/dist/library/examples/glass.d.ts.map +1 -0
- package/dist/library/{themes → examples}/glass.js +9 -3
- package/dist/library/examples/glass.js.map +1 -0
- package/dist/library/examples/index.d.ts +13 -0
- package/dist/library/examples/index.d.ts.map +1 -0
- package/dist/library/examples/index.js +32 -0
- package/dist/library/examples/index.js.map +1 -0
- package/dist/library/examples/jelly.d.ts +4 -0
- package/dist/library/examples/jelly.d.ts.map +1 -0
- package/dist/library/{themes → examples}/jelly.js +4 -3
- package/dist/library/examples/jelly.js.map +1 -0
- package/dist/library/examples/preset-values.d.ts.map +1 -0
- package/dist/library/examples/preset-values.js.map +1 -0
- package/dist/library/examples/radiant.d.ts +4 -0
- package/dist/library/examples/radiant.d.ts.map +1 -0
- package/dist/library/{themes → examples}/radiant.js +4 -3
- package/dist/library/examples/radiant.js.map +1 -0
- package/dist/library/examples/sharp-3d.d.ts +4 -0
- package/dist/library/examples/sharp-3d.d.ts.map +1 -0
- package/dist/library/{themes → examples}/sharp-3d.js +4 -3
- package/dist/library/examples/sharp-3d.js.map +1 -0
- package/dist/library/examples/soft-squircle.d.ts +4 -0
- package/dist/library/examples/soft-squircle.d.ts.map +1 -0
- package/dist/library/{themes → examples}/soft-squircle.js +4 -3
- package/dist/library/examples/soft-squircle.js.map +1 -0
- package/dist/library/examples/ticket.d.ts +4 -0
- package/dist/library/examples/ticket.d.ts.map +1 -0
- package/dist/library/{themes → examples}/ticket.js +4 -3
- package/dist/library/examples/ticket.js.map +1 -0
- package/dist/library/index.d.ts +3 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +2 -1
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/select.d.ts +37 -0
- package/dist/library/internal/select.d.ts.map +1 -0
- package/dist/library/internal/select.js +42 -0
- package/dist/library/internal/select.js.map +1 -0
- package/dist/library/motion/MotionLink.d.ts +1 -0
- package/dist/library/motion/MotionLink.d.ts.map +1 -1
- package/dist/library/motion/MotionLink.js +9 -10
- package/dist/library/motion/MotionLink.js.map +1 -1
- package/dist/library/motion/host.d.ts +7 -3
- package/dist/library/motion/host.d.ts.map +1 -1
- package/dist/library/motion/host.js +13 -5
- package/dist/library/motion/host.js.map +1 -1
- package/dist/library/motion/popup.d.ts +5 -0
- package/dist/library/motion/popup.d.ts.map +1 -0
- package/dist/library/motion/popup.js +60 -0
- package/dist/library/motion/popup.js.map +1 -0
- package/dist/library/motion/press.d.ts.map +1 -1
- package/dist/library/motion/press.js +41 -14
- package/dist/library/motion/press.js.map +1 -1
- package/dist/library/motion/pressPolicy.d.ts.map +1 -1
- package/dist/library/motion/pressPolicy.js +2 -2
- package/dist/library/motion/pressPolicy.js.map +1 -1
- package/dist/library/motion/react.d.ts.map +1 -1
- package/dist/library/motion/react.js +3 -1
- package/dist/library/motion/react.js.map +1 -1
- package/dist/library/motion/transitions.d.ts.map +1 -1
- package/dist/library/motion/transitions.js +48 -15
- package/dist/library/motion/transitions.js.map +1 -1
- package/dist/library/react/useControllableState.d.ts +1 -0
- package/dist/library/react/useControllableState.d.ts.map +1 -1
- package/dist/library/react/useControllableState.js +8 -1
- package/dist/library/react/useControllableState.js.map +1 -1
- package/dist/library/selectStyles.d.ts +4 -0
- package/dist/library/selectStyles.d.ts.map +1 -0
- package/dist/library/selectStyles.js +32 -0
- package/dist/library/selectStyles.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +24 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +24 -0
- package/dist/library/themes/components.js.map +1 -1
- package/dist/library/themes/index.d.ts +1 -11
- package/dist/library/themes/index.d.ts.map +1 -1
- package/dist/library/themes/index.js +1 -19
- package/dist/library/themes/index.js.map +1 -1
- package/docs/accessibility.md +76 -142
- package/docs/architecture.md +208 -0
- package/docs/motion.md +115 -396
- package/docs/theming.md +275 -882
- package/package.json +9 -5
- package/src/Accordion.tsx +4 -1
- package/src/Button.tsx +13 -7
- package/src/Card.tsx +3 -1
- package/src/Checkbox.tsx +7 -2
- package/src/Collapsible.tsx +28 -4
- package/src/Dialog.tsx +3 -0
- package/src/Field.tsx +8 -0
- package/src/Input.tsx +3 -0
- package/src/Link.tsx +5 -0
- package/src/RadioGroup.tsx +10 -2
- package/src/Select.tsx +781 -0
- package/src/cn.ts +20 -3
- package/src/{themes → examples}/expressive.ts +5 -3
- package/src/{themes → examples}/glass.ts +10 -3
- package/src/examples/index.ts +35 -0
- package/src/{themes → examples}/jelly.ts +5 -3
- package/src/{themes → examples}/radiant.ts +5 -3
- package/src/{themes → examples}/sharp-3d.ts +5 -3
- package/src/{themes → examples}/soft-squircle.ts +5 -3
- package/src/{themes → examples}/ticket.ts +5 -3
- package/src/index.ts +28 -13
- package/src/internal/select.ts +80 -0
- package/src/motion/MotionLink.tsx +16 -11
- package/src/motion/host.ts +16 -7
- package/src/motion/popup.ts +55 -0
- package/src/motion/press.ts +32 -12
- package/src/motion/pressPolicy.ts +4 -2
- package/src/motion/react.ts +3 -1
- package/src/motion/transitions.ts +45 -14
- package/src/react/useControllableState.ts +7 -1
- package/src/selectStyles.ts +34 -0
- package/src/themes/components.ts +24 -0
- package/src/themes/index.ts +1 -22
- package/dist/library/themes/expressive.d.ts +0 -2
- package/dist/library/themes/expressive.d.ts.map +0 -1
- package/dist/library/themes/expressive.js.map +0 -1
- package/dist/library/themes/glass.d.ts +0 -2
- package/dist/library/themes/glass.d.ts.map +0 -1
- package/dist/library/themes/glass.js.map +0 -1
- package/dist/library/themes/jelly.d.ts +0 -2
- package/dist/library/themes/jelly.d.ts.map +0 -1
- package/dist/library/themes/jelly.js.map +0 -1
- package/dist/library/themes/preset-values.d.ts.map +0 -1
- package/dist/library/themes/preset-values.js.map +0 -1
- package/dist/library/themes/radiant.d.ts +0 -2
- package/dist/library/themes/radiant.d.ts.map +0 -1
- package/dist/library/themes/radiant.js.map +0 -1
- package/dist/library/themes/sharp-3d.d.ts +0 -2
- package/dist/library/themes/sharp-3d.d.ts.map +0 -1
- package/dist/library/themes/sharp-3d.js.map +0 -1
- package/dist/library/themes/soft-squircle.d.ts +0 -2
- package/dist/library/themes/soft-squircle.d.ts.map +0 -1
- package/dist/library/themes/soft-squircle.js.map +0 -1
- package/dist/library/themes/ticket.d.ts +0 -2
- package/dist/library/themes/ticket.d.ts.map +0 -1
- package/dist/library/themes/ticket.js.map +0 -1
- package/docs/system.md +0 -264
- /package/dist/library/{themes → examples}/preset-values.d.ts +0 -0
- /package/dist/library/{themes → examples}/preset-values.js +0 -0
- /package/src/{themes → examples}/preset-values.ts +0 -0
package/src/cn.ts
CHANGED
|
@@ -9,9 +9,26 @@ const roleClasses = (prefix: string, leaf: string) =>
|
|
|
9
9
|
export const cn: CnFunction = createCn({
|
|
10
10
|
extend: {
|
|
11
11
|
classGroups: {
|
|
12
|
-
'font-family': roleClasses('font', 'family'),
|
|
13
|
-
'font-weight': roleClasses('font', 'weight'),
|
|
14
|
-
'font-size': [
|
|
12
|
+
'font-family': [...roleClasses('font', 'family'), 'font-(--rad-select-font-family)'],
|
|
13
|
+
'font-weight': [...roleClasses('font', 'weight'), 'font-(--rad-select-font-weight)'],
|
|
14
|
+
'font-size': [
|
|
15
|
+
...roleClasses('text', 'size'),
|
|
16
|
+
...roleClasses('text', 'fluid-size'),
|
|
17
|
+
'text-(--rad-select-font-size)'
|
|
18
|
+
],
|
|
19
|
+
h: ['h-(--rad-select-height)'],
|
|
20
|
+
px: ['px-(--rad-select-padding)'],
|
|
21
|
+
p: ['p-(--rad-select-content-padding)'],
|
|
22
|
+
rounded: [
|
|
23
|
+
'rounded-(--rad-select-radius)',
|
|
24
|
+
'rounded-(--rad-select-content-radius)',
|
|
25
|
+
'rounded-(--rad-select-item-radius)'
|
|
26
|
+
],
|
|
27
|
+
'border-w': ['border-(--rad-select-border-width)'],
|
|
28
|
+
'border-style': ['border-(--rad-select-border-style)'],
|
|
29
|
+
shadow: ['shadow-(--rad-select-shadow)', 'shadow-(--rad-select-content-shadow)'],
|
|
30
|
+
'corner-shape': ['[corner-shape:var(--rad-select-corner-shape)]'],
|
|
31
|
+
'backdrop-filter': ['[backdrop-filter:var(--rad-select-content-backdrop-filter)]'],
|
|
15
32
|
leading: roleClasses('leading', 'line-height'),
|
|
16
33
|
tracking: roleClasses('tracking', 'letter-spacing'),
|
|
17
34
|
'max-inline-size': roleClasses('max-inline', 'measure'),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { spring } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const expressiveDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'expressive',
|
|
6
6
|
name: 'Expressive',
|
|
7
7
|
tokens: {
|
|
@@ -129,4 +129,6 @@ export const expressive = defineTheme({
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export const expressive = defineTheme(expressiveDefinition)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { snap, spring } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const glassDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'glass',
|
|
6
6
|
name: 'Glass',
|
|
7
7
|
tokens: {
|
|
@@ -87,6 +87,10 @@ export const glass = defineTheme({
|
|
|
87
87
|
state: { disabledOpacity: 0.5 }
|
|
88
88
|
},
|
|
89
89
|
components: {
|
|
90
|
+
select: {
|
|
91
|
+
contentBackground: 'rgb(255 255 255 / 0.92)',
|
|
92
|
+
contentBackdropFilter: 'blur(18px) saturate(190%)'
|
|
93
|
+
},
|
|
90
94
|
dialog: { backdropFilter: 'blur(18px) saturate(190%)' },
|
|
91
95
|
button: {
|
|
92
96
|
fontWeight: 700,
|
|
@@ -102,6 +106,7 @@ export const glass = defineTheme({
|
|
|
102
106
|
},
|
|
103
107
|
modes: {
|
|
104
108
|
dark: {
|
|
109
|
+
components: { select: { contentBackground: 'rgb(27 25 48 / 0.94)' } },
|
|
105
110
|
tokens: {
|
|
106
111
|
color: {
|
|
107
112
|
surface: 'rgb(27 25 48 / 0.9)',
|
|
@@ -132,4 +137,6 @@ export const glass = defineTheme({
|
|
|
132
137
|
}
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
|
-
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const glass = defineTheme(glassDefinition)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { defaultTheme } from '../themes/default.js'
|
|
2
|
+
import type { Theme, ThemeDefinition } from '../themes/types.js'
|
|
3
|
+
import { freezeTree } from '../themes/tokens.js'
|
|
4
|
+
import { radiant, radiantDefinition } from './radiant.js'
|
|
5
|
+
import { soft, softDefinition } from './soft-squircle.js'
|
|
6
|
+
import { expressive, expressiveDefinition } from './expressive.js'
|
|
7
|
+
import { glass, glassDefinition } from './glass.js'
|
|
8
|
+
import { sharp, sharpDefinition } from './sharp-3d.js'
|
|
9
|
+
import { jelly, jellyDefinition } from './jelly.js'
|
|
10
|
+
import { ticket, ticketDefinition } from './ticket.js'
|
|
11
|
+
|
|
12
|
+
export { radiant, soft, expressive, glass, sharp, jelly, ticket }
|
|
13
|
+
|
|
14
|
+
export const themes: readonly Theme[] = Object.freeze([
|
|
15
|
+
radiant,
|
|
16
|
+
defaultTheme,
|
|
17
|
+
soft,
|
|
18
|
+
expressive,
|
|
19
|
+
glass,
|
|
20
|
+
sharp,
|
|
21
|
+
jelly,
|
|
22
|
+
ticket
|
|
23
|
+
])
|
|
24
|
+
|
|
25
|
+
/** The source of each theme in `themes`, in the same order, for editors that start from one. */
|
|
26
|
+
export const themeDefinitions: readonly ThemeDefinition[] = freezeTree([
|
|
27
|
+
radiantDefinition,
|
|
28
|
+
{ id: defaultTheme.id, name: defaultTheme.name },
|
|
29
|
+
softDefinition,
|
|
30
|
+
expressiveDefinition,
|
|
31
|
+
glassDefinition,
|
|
32
|
+
sharpDefinition,
|
|
33
|
+
jellyDefinition,
|
|
34
|
+
ticketDefinition
|
|
35
|
+
])
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { snap, spring } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const jellyDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'jelly',
|
|
6
6
|
name: 'Jelly',
|
|
7
7
|
tokens: {
|
|
@@ -127,4 +127,6 @@ export const jelly = defineTheme({
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export const jelly = defineTheme(jellyDefinition)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { snap, settle } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const radiantDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'radiant',
|
|
6
6
|
name: 'Radiant',
|
|
7
7
|
tokens: {
|
|
@@ -126,4 +126,6 @@ export const radiant = defineTheme({
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export const radiant = defineTheme(radiantDefinition)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { snap, settle } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const sharpDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'sharp-3d',
|
|
6
6
|
name: 'Sharp 3D',
|
|
7
7
|
tokens: {
|
|
@@ -139,4 +139,6 @@ export const sharp = defineTheme({
|
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export const sharp = defineTheme(sharpDefinition)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { snap, spring } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const softDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'soft-squircle',
|
|
6
6
|
name: 'Soft squircle',
|
|
7
7
|
tokens: {
|
|
@@ -128,4 +128,6 @@ export const soft = defineTheme({
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
-
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export const soft = defineTheme(softDefinition)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineTheme } from '
|
|
1
|
+
import { defineTheme, type ThemeDefinition } from '../themes/defineTheme.js'
|
|
2
2
|
import { snap, settle } from './preset-values.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const ticketDefinition: ThemeDefinition = {
|
|
5
5
|
id: 'ticket',
|
|
6
6
|
name: 'Ticket',
|
|
7
7
|
tokens: {
|
|
@@ -138,4 +138,6 @@ export const ticket = defineTheme({
|
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
|
-
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export const ticket = defineTheme(ticketDefinition)
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,33 @@ export { Field, useField } from './Field.js'
|
|
|
5
5
|
export type { FieldControlProps, FieldLayout, FieldProps, FieldState } from './Field.js'
|
|
6
6
|
export { Input } from './Input.js'
|
|
7
7
|
export type { InputProps } from './Input.js'
|
|
8
|
+
export {
|
|
9
|
+
Select,
|
|
10
|
+
SelectTrigger,
|
|
11
|
+
SelectValue,
|
|
12
|
+
SelectIcon,
|
|
13
|
+
SelectPortal,
|
|
14
|
+
SelectContent,
|
|
15
|
+
SelectViewport,
|
|
16
|
+
SelectItem,
|
|
17
|
+
SelectItemText,
|
|
18
|
+
SelectItemIndicator,
|
|
19
|
+
SelectGroup,
|
|
20
|
+
useSelect
|
|
21
|
+
} from './Select.js'
|
|
22
|
+
export type {
|
|
23
|
+
SelectProps,
|
|
24
|
+
SelectOption,
|
|
25
|
+
SelectState,
|
|
26
|
+
SelectTriggerProps,
|
|
27
|
+
SelectValueProps,
|
|
28
|
+
SelectIconProps,
|
|
29
|
+
SelectContentProps,
|
|
30
|
+
SelectViewportProps,
|
|
31
|
+
SelectItemProps,
|
|
32
|
+
SelectItemTextProps,
|
|
33
|
+
SelectGroupProps
|
|
34
|
+
} from './Select.js'
|
|
8
35
|
export { Checkbox } from './Checkbox.js'
|
|
9
36
|
export type { CheckboxProps } from './Checkbox.js'
|
|
10
37
|
export { Radio, RadioGroup } from './RadioGroup.js'
|
|
@@ -66,19 +93,7 @@ export type {
|
|
|
66
93
|
CardProps,
|
|
67
94
|
CardTitleProps
|
|
68
95
|
} from './Card.js'
|
|
69
|
-
export {
|
|
70
|
-
defineTheme,
|
|
71
|
-
updateThemeAppearance,
|
|
72
|
-
themes,
|
|
73
|
-
radiant,
|
|
74
|
-
defaultTheme,
|
|
75
|
-
soft,
|
|
76
|
-
expressive,
|
|
77
|
-
glass,
|
|
78
|
-
sharp,
|
|
79
|
-
jelly,
|
|
80
|
-
ticket
|
|
81
|
-
} from './themes/index.js'
|
|
96
|
+
export { defineTheme, updateThemeAppearance, defaultTheme } from './themes/index.js'
|
|
82
97
|
export type {
|
|
83
98
|
SharedTokens,
|
|
84
99
|
ThemeAppearanceSettings,
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export type SelectEntry = { value: string; textValue: string; disabled?: boolean }
|
|
2
|
+
|
|
3
|
+
/** Native-like text matching, including repeated-letter cycling. */
|
|
4
|
+
export function matchSelectText(
|
|
5
|
+
items: readonly SelectEntry[],
|
|
6
|
+
text: string,
|
|
7
|
+
current: string | null
|
|
8
|
+
) {
|
|
9
|
+
const search = text.toLocaleLowerCase()
|
|
10
|
+
const repeated = search.length > 1 && [...search].every(letter => letter === search[0])
|
|
11
|
+
const query = repeated ? search[0] : search
|
|
12
|
+
const index = items.findIndex(item => item.value === current)
|
|
13
|
+
const ordered = [...items.slice(index + 1), ...items.slice(0, index + 1)]
|
|
14
|
+
if (query.length > 1 && index >= 0) ordered.unshift(items[index])
|
|
15
|
+
return ordered.find(
|
|
16
|
+
item => !item.disabled && item.textValue.toLocaleLowerCase().startsWith(query)
|
|
17
|
+
)?.value
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function moveSelectFocus(
|
|
21
|
+
items: readonly SelectEntry[],
|
|
22
|
+
current: string | null,
|
|
23
|
+
key: string
|
|
24
|
+
) {
|
|
25
|
+
const enabled = items.filter(item => !item.disabled)
|
|
26
|
+
if (key === 'Home') return enabled[0]?.value
|
|
27
|
+
if (key === 'End') return enabled.at(-1)?.value
|
|
28
|
+
const index = enabled.findIndex(item => item.value === current)
|
|
29
|
+
return enabled[Math.max(0, Math.min(enabled.length - 1, index + (key === 'ArrowUp' ? -1 : 1)))]
|
|
30
|
+
?.value
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function positionSelect(input: {
|
|
34
|
+
trigger: {
|
|
35
|
+
top: number
|
|
36
|
+
bottom: number
|
|
37
|
+
left: number
|
|
38
|
+
right: number
|
|
39
|
+
height: number
|
|
40
|
+
width: number
|
|
41
|
+
}
|
|
42
|
+
width: number
|
|
43
|
+
height: number
|
|
44
|
+
selectedOffset: number
|
|
45
|
+
viewport: { top: number; left: number; width: number; height: number }
|
|
46
|
+
padding: number
|
|
47
|
+
offset: number
|
|
48
|
+
aligned: boolean
|
|
49
|
+
rtl: boolean
|
|
50
|
+
}) {
|
|
51
|
+
const { trigger, viewport, padding } = input
|
|
52
|
+
const width = Math.min(
|
|
53
|
+
Math.max(input.width, trigger.width),
|
|
54
|
+
Math.max(0, viewport.width - 2 * padding)
|
|
55
|
+
)
|
|
56
|
+
const height = Math.min(input.height, Math.max(0, viewport.height - 2 * padding))
|
|
57
|
+
let top = input.aligned
|
|
58
|
+
? trigger.top + trigger.height / 2 - input.selectedOffset
|
|
59
|
+
: trigger.bottom + input.offset
|
|
60
|
+
if (
|
|
61
|
+
!input.aligned &&
|
|
62
|
+
top + height > viewport.top + viewport.height - padding &&
|
|
63
|
+
trigger.top - input.offset - height >= viewport.top + padding
|
|
64
|
+
)
|
|
65
|
+
top = trigger.top - input.offset - height
|
|
66
|
+
top = Math.max(
|
|
67
|
+
viewport.top + padding,
|
|
68
|
+
Math.min(top, viewport.top + viewport.height - height - padding)
|
|
69
|
+
)
|
|
70
|
+
const preferredLeft = input.rtl ? trigger.right - width : trigger.left
|
|
71
|
+
return {
|
|
72
|
+
top,
|
|
73
|
+
left: Math.max(
|
|
74
|
+
viewport.left + padding,
|
|
75
|
+
Math.min(preferredLeft, viewport.left + viewport.width - width - padding)
|
|
76
|
+
),
|
|
77
|
+
width,
|
|
78
|
+
maxHeight: height
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { useContext } from 'react'
|
|
3
2
|
import { Link, type LinkProps } from '../Link.js'
|
|
4
3
|
import { cn } from '../cn.js'
|
|
5
|
-
import { MotionHostContext } from './host.js'
|
|
6
4
|
import { usePressHost } from './host.js'
|
|
7
5
|
import { callerOwnsPress, springPressClass, offPressClass } from './pressPolicy.js'
|
|
8
|
-
export type MotionLinkProps = LinkProps & {
|
|
6
|
+
export type MotionLinkProps = LinkProps & {
|
|
7
|
+
/** Inherit the theme's spring policy; off suppresses spatial feedback. Requires MotionProvider. */
|
|
8
|
+
motion?: 'inherit' | 'off'
|
|
9
|
+
}
|
|
9
10
|
/** Optional client adapter for action-shaped Link; ordinary Link stays server-renderable. */
|
|
10
11
|
export function MotionLink({ ref, motion = 'inherit', className, ...props }: MotionLinkProps) {
|
|
11
12
|
const owns = callerOwnsPress(props.style, className)
|
|
@@ -15,12 +16,12 @@ export function MotionLink({ ref, motion = 'inherit', className, ...props }: Mot
|
|
|
15
16
|
props.variant === undefined ||
|
|
16
17
|
props.variant === 'inline' ||
|
|
17
18
|
props.variant === 'subtle'
|
|
18
|
-
const runtime = useContext(MotionHostContext)
|
|
19
|
-
const active = runtime !== null && !disabled
|
|
20
19
|
const {
|
|
21
20
|
ref: motionRef,
|
|
22
21
|
press: startPress,
|
|
23
|
-
release
|
|
22
|
+
release,
|
|
23
|
+
off,
|
|
24
|
+
active
|
|
24
25
|
} = usePressHost<HTMLAnchorElement>(ref, disabled)
|
|
25
26
|
return (
|
|
26
27
|
<Link
|
|
@@ -28,7 +29,7 @@ export function MotionLink({ ref, motion = 'inherit', className, ...props }: Mot
|
|
|
28
29
|
ref={active ? motionRef : ref}
|
|
29
30
|
className={cn(
|
|
30
31
|
active && springPressClass,
|
|
31
|
-
motion === 'off' && !owns && offPressClass,
|
|
32
|
+
(motion === 'off' || off) && !owns && offPressClass,
|
|
32
33
|
className
|
|
33
34
|
)}
|
|
34
35
|
onPointerDown={event => {
|
|
@@ -37,15 +38,19 @@ export function MotionLink({ ref, motion = 'inherit', className, ...props }: Mot
|
|
|
37
38
|
}}
|
|
38
39
|
onPointerUp={event => {
|
|
39
40
|
props.onPointerUp?.(event)
|
|
40
|
-
release()
|
|
41
|
+
release(event.nativeEvent)
|
|
41
42
|
}}
|
|
42
43
|
onPointerCancel={event => {
|
|
43
44
|
props.onPointerCancel?.(event)
|
|
44
|
-
release()
|
|
45
|
+
release(event.nativeEvent)
|
|
45
46
|
}}
|
|
46
47
|
onPointerLeave={event => {
|
|
47
48
|
props.onPointerLeave?.(event)
|
|
48
|
-
release()
|
|
49
|
+
release(event.nativeEvent)
|
|
50
|
+
}}
|
|
51
|
+
onLostPointerCapture={event => {
|
|
52
|
+
props.onLostPointerCapture?.(event)
|
|
53
|
+
release(event.nativeEvent)
|
|
49
54
|
}}
|
|
50
55
|
onBlur={event => {
|
|
51
56
|
props.onBlur?.(event)
|
|
@@ -57,7 +62,7 @@ export function MotionLink({ ref, motion = 'inherit', className, ...props }: Mot
|
|
|
57
62
|
}}
|
|
58
63
|
onKeyUp={event => {
|
|
59
64
|
props.onKeyUp?.(event)
|
|
60
|
-
release()
|
|
65
|
+
release(event.nativeEvent)
|
|
61
66
|
}}
|
|
62
67
|
/>
|
|
63
68
|
)
|
package/src/motion/host.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import { createContext, useContext, useEffect, useRef, type Ref } from 'react'
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, useState, type Ref } from 'react'
|
|
3
3
|
import type { MotionProfile } from './config.js'
|
|
4
4
|
import { MotionProfileContext } from './context.js'
|
|
5
5
|
import { useComposedRefs } from '../react/useComposedRefs.js'
|
|
@@ -7,13 +7,14 @@ import { useComposedRefs } from '../react/useComposedRefs.js'
|
|
|
7
7
|
export interface MotionHostBinding {
|
|
8
8
|
update(profile: MotionProfile): void
|
|
9
9
|
press?(event: PointerEvent | KeyboardEvent): void
|
|
10
|
-
release?(): void
|
|
10
|
+
release?(event?: PointerEvent | KeyboardEvent): void
|
|
11
11
|
destroy(): void
|
|
12
12
|
}
|
|
13
13
|
export interface MotionHostRuntime {
|
|
14
14
|
press(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
15
15
|
disclosure?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
16
16
|
dialog?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
17
|
+
popup?(node: HTMLElement, profile: MotionProfile): MotionHostBinding
|
|
17
18
|
}
|
|
18
19
|
export const MotionHostContext = createContext<MotionHostRuntime | null>(null)
|
|
19
20
|
/** Engine-free bridge: only the opt-in provider supplies implementation. */
|
|
@@ -46,18 +47,19 @@ export function usePressHost<Node extends HTMLElement>(
|
|
|
46
47
|
return {
|
|
47
48
|
ref: composed,
|
|
48
49
|
active: runtime !== null && !disabled,
|
|
50
|
+
off: profile.mode === 'off',
|
|
49
51
|
press(event: PointerEvent | KeyboardEvent) {
|
|
50
52
|
binding.current?.value.press?.(event)
|
|
51
53
|
},
|
|
52
|
-
release() {
|
|
53
|
-
binding.current?.value.release?.()
|
|
54
|
+
release(event?: PointerEvent | KeyboardEvent) {
|
|
55
|
+
binding.current?.value.release?.(event)
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/** Shared lifecycle for native presentation adapters; no engine enters the root path. */
|
|
59
61
|
export function useTransitionHost<Node extends HTMLElement>(
|
|
60
|
-
kind: 'disclosure' | 'dialog',
|
|
62
|
+
kind: 'disclosure' | 'dialog' | 'popup',
|
|
61
63
|
ref: Ref<Node> | undefined,
|
|
62
64
|
disabled: boolean
|
|
63
65
|
) {
|
|
@@ -66,6 +68,7 @@ export function useTransitionHost<Node extends HTMLElement>(
|
|
|
66
68
|
const node = useRef<Node>(null)
|
|
67
69
|
const binding = useRef<{ node: Node; value: MotionHostBinding } | null>(null)
|
|
68
70
|
const composed = useComposedRefs(node, ref)
|
|
71
|
+
const [ready, setReady] = useState(false)
|
|
69
72
|
useEffect(() => {
|
|
70
73
|
const attach = runtime?.[kind]
|
|
71
74
|
if (disabled || !attach || !node.current || binding.current?.node !== node.current) {
|
|
@@ -76,7 +79,8 @@ export function useTransitionHost<Node extends HTMLElement>(
|
|
|
76
79
|
binding.current ??= { node: node.current, value: attach(node.current, profile) }
|
|
77
80
|
binding.current.value.update(profile)
|
|
78
81
|
}
|
|
79
|
-
|
|
82
|
+
setReady(binding.current !== null)
|
|
83
|
+
}, [disabled, kind, runtime, profile, composed])
|
|
80
84
|
useEffect(
|
|
81
85
|
() => () => {
|
|
82
86
|
binding.current?.value.destroy()
|
|
@@ -84,5 +88,10 @@ export function useTransitionHost<Node extends HTMLElement>(
|
|
|
84
88
|
},
|
|
85
89
|
[]
|
|
86
90
|
)
|
|
87
|
-
return {
|
|
91
|
+
return {
|
|
92
|
+
ref: composed,
|
|
93
|
+
active: !disabled && runtime?.[kind] !== undefined,
|
|
94
|
+
ready,
|
|
95
|
+
off: profile.mode === 'off'
|
|
96
|
+
}
|
|
88
97
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createSpring } from './runtime.js'
|
|
2
|
+
import { resolveMotion, type MotionProfile } from './config.js'
|
|
3
|
+
import type { MotionHostBinding } from './host.js'
|
|
4
|
+
|
|
5
|
+
/** Enter presentation only. Closing, focus and top-layer removal are immediate. */
|
|
6
|
+
export function bindPopupMotion(node: HTMLElement, initial: MotionProfile): MotionHostBinding {
|
|
7
|
+
let profile = initial
|
|
8
|
+
let open = false
|
|
9
|
+
const win = node.ownerDocument.defaultView!
|
|
10
|
+
const query = win.matchMedia('(prefers-reduced-motion: reduce)')
|
|
11
|
+
const spring = createSpring(0, {
|
|
12
|
+
...resolveMotion(profile, 'dialog', query.matches),
|
|
13
|
+
reducedValue: 0
|
|
14
|
+
})
|
|
15
|
+
const previous = node.style.getPropertyValue('--_rad-select-enter')
|
|
16
|
+
let owned = previous
|
|
17
|
+
const render = (value: number) => {
|
|
18
|
+
owned = String(Math.max(0, Math.min(1, value)))
|
|
19
|
+
node.style.setProperty('--_rad-select-enter', owned)
|
|
20
|
+
}
|
|
21
|
+
const off = spring.subscribe(render)
|
|
22
|
+
render(spring.get())
|
|
23
|
+
const sync = () => {
|
|
24
|
+
const next = node.dataset.state === 'open'
|
|
25
|
+
const resolved = resolveMotion(profile, 'dialog', query.matches)
|
|
26
|
+
spring.configure({ ...resolved, reducedValue: next ? 1 : 0 })
|
|
27
|
+
if (next !== open) {
|
|
28
|
+
open = next
|
|
29
|
+
if (next) {
|
|
30
|
+
spring.jump(0)
|
|
31
|
+
spring.to(1)
|
|
32
|
+
} else spring.jump(0)
|
|
33
|
+
} else if (!resolved.enabled) spring.jump(next ? 1 : 0)
|
|
34
|
+
}
|
|
35
|
+
const observer = new win.MutationObserver(sync)
|
|
36
|
+
observer.observe(node, { attributes: true, attributeFilter: ['data-state'] })
|
|
37
|
+
query.addEventListener('change', sync)
|
|
38
|
+
sync()
|
|
39
|
+
return {
|
|
40
|
+
update(next) {
|
|
41
|
+
profile = next
|
|
42
|
+
sync()
|
|
43
|
+
},
|
|
44
|
+
destroy() {
|
|
45
|
+
observer.disconnect()
|
|
46
|
+
query.removeEventListener('change', sync)
|
|
47
|
+
off()
|
|
48
|
+
spring.destroy()
|
|
49
|
+
if (node.style.getPropertyValue('--_rad-select-enter') === owned) {
|
|
50
|
+
if (previous) node.style.setProperty('--_rad-select-enter', previous)
|
|
51
|
+
else node.style.removeProperty('--_rad-select-enter')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/src/motion/press.ts
CHANGED
|
@@ -15,24 +15,40 @@ export function bindPressMotion(
|
|
|
15
15
|
reducedValue: 1
|
|
16
16
|
})
|
|
17
17
|
const unbind = bindSpringStyle(node, spring, 'scale')
|
|
18
|
+
let pressed: { key: string } | { pointerId: number } | null = null
|
|
18
19
|
const blocked = () =>
|
|
20
|
+
(node.tagName === 'A' && !node.hasAttribute('href')) ||
|
|
19
21
|
node.matches(':disabled') ||
|
|
20
22
|
node.getAttribute('aria-busy') === 'true' ||
|
|
21
23
|
node.getAttribute('aria-disabled') === 'true'
|
|
22
|
-
|
|
24
|
+
function release(event?: PointerEvent | KeyboardEvent) {
|
|
25
|
+
if (!pressed) return
|
|
26
|
+
if (event) {
|
|
27
|
+
if ('key' in event) {
|
|
28
|
+
if (!('key' in pressed) || event.key !== pressed.key) return
|
|
29
|
+
} else if (!('pointerId' in pressed) || event.pointerId !== pressed.pointerId) return
|
|
30
|
+
}
|
|
31
|
+
pressed = null
|
|
32
|
+
spring.to(1)
|
|
33
|
+
}
|
|
34
|
+
function reset() {
|
|
35
|
+
pressed = null
|
|
36
|
+
spring.jump(1)
|
|
37
|
+
}
|
|
23
38
|
function update(next: MotionProfile) {
|
|
24
39
|
profile = next
|
|
25
|
-
|
|
26
|
-
|
|
40
|
+
const resolved = resolveMotion(profile, 'press', query.matches)
|
|
41
|
+
spring.configure({ ...resolved, reducedValue: 1 })
|
|
42
|
+
if (blocked() || !resolved.enabled) reset()
|
|
27
43
|
}
|
|
28
44
|
const changed = () => update(profile)
|
|
29
45
|
query.addEventListener('change', changed)
|
|
30
46
|
const observer = new MutationObserver(() => {
|
|
31
|
-
if (blocked())
|
|
47
|
+
if (blocked()) reset()
|
|
32
48
|
})
|
|
33
49
|
observer.observe(node, {
|
|
34
50
|
attributes: true,
|
|
35
|
-
attributeFilter: ['disabled', 'aria-busy', 'aria-disabled']
|
|
51
|
+
attributeFilter: ['disabled', 'aria-busy', 'aria-disabled', 'href']
|
|
36
52
|
})
|
|
37
53
|
for (let parent = node.parentElement; parent; parent = parent.parentElement) {
|
|
38
54
|
if (parent.tagName === 'FIELDSET')
|
|
@@ -42,21 +58,25 @@ export function bindPressMotion(
|
|
|
42
58
|
document.addEventListener('pointerup', release)
|
|
43
59
|
document.addEventListener('pointercancel', release)
|
|
44
60
|
document.addEventListener('keyup', release)
|
|
45
|
-
|
|
61
|
+
const blur = () => release()
|
|
62
|
+
document.defaultView!.addEventListener('blur', blur)
|
|
46
63
|
return {
|
|
47
64
|
update,
|
|
48
65
|
press(event) {
|
|
49
|
-
if (event.defaultPrevented || blocked())
|
|
50
|
-
|
|
51
|
-
return
|
|
52
|
-
}
|
|
66
|
+
if (event.defaultPrevented || blocked()) return
|
|
67
|
+
if (!resolveMotion(profile, 'press', query.matches).enabled) return
|
|
53
68
|
if ('key' in event) {
|
|
54
69
|
if (
|
|
55
70
|
event.repeat ||
|
|
56
71
|
!['Enter', ...(node.tagName === 'BUTTON' ? [' '] : [])].includes(event.key)
|
|
57
72
|
)
|
|
58
73
|
return
|
|
59
|
-
|
|
74
|
+
if (pressed) return
|
|
75
|
+
pressed = { key: event.key }
|
|
76
|
+
} else {
|
|
77
|
+
if (event.button !== 0 || event.isPrimary === false || pressed) return
|
|
78
|
+
pressed = { pointerId: event.pointerId }
|
|
79
|
+
}
|
|
60
80
|
const scale = Number(
|
|
61
81
|
getComputedStyle(node).getPropertyValue('--rad-button-press-scale').trim() || '.97'
|
|
62
82
|
)
|
|
@@ -69,7 +89,7 @@ export function bindPressMotion(
|
|
|
69
89
|
document.removeEventListener('pointerup', release)
|
|
70
90
|
document.removeEventListener('pointercancel', release)
|
|
71
91
|
document.removeEventListener('keyup', release)
|
|
72
|
-
document.defaultView!.removeEventListener('blur',
|
|
92
|
+
document.defaultView!.removeEventListener('blur', blur)
|
|
73
93
|
spring.destroy()
|
|
74
94
|
unbind()
|
|
75
95
|
}
|
|
@@ -2,8 +2,10 @@ import type { CSSProperties } from 'react'
|
|
|
2
2
|
export function callerOwnsPress(style: CSSProperties | undefined, className: string | undefined) {
|
|
3
3
|
return (
|
|
4
4
|
style?.scale !== undefined ||
|
|
5
|
-
/(
|
|
6
|
-
|
|
5
|
+
/(?:^|[\s:!])(?:-?scale-|\[scale:|transition-all(?:$|[\s!])|transition-\[[^\]]*(?:\bscale\b|\ball\b))/.test(
|
|
6
|
+
className ?? ''
|
|
7
|
+
) ||
|
|
8
|
+
/\b(?:scale|all)\b/.test(`${style?.transition ?? ''} ${style?.transitionProperty ?? ''}`)
|
|
7
9
|
)
|
|
8
10
|
}
|
|
9
11
|
export const springPressClass =
|
package/src/motion/react.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { createElement, type ReactNode } from 'react'
|
|
|
12
12
|
import { MotionHostContext } from './host.js'
|
|
13
13
|
import { bindDisclosureMotion, bindDialogMotion } from './transitions.js'
|
|
14
14
|
import { bindPressMotion } from './press.js'
|
|
15
|
+
import { bindPopupMotion } from './popup.js'
|
|
15
16
|
import { MotionProfileContext } from './context.js'
|
|
16
17
|
import { resolveMotion, type MotionInteraction } from './config.js'
|
|
17
18
|
import { createSpringDrag, type SpringDragController, type SpringDragOptions } from './drag.js'
|
|
@@ -134,7 +135,8 @@ export function useSpringStyle(
|
|
|
134
135
|
const hostRuntime = {
|
|
135
136
|
press: bindPressMotion,
|
|
136
137
|
disclosure: bindDisclosureMotion,
|
|
137
|
-
dialog: bindDialogMotion
|
|
138
|
+
dialog: bindDialogMotion,
|
|
139
|
+
popup: bindPopupMotion
|
|
138
140
|
}
|
|
139
141
|
/** Opt into native Radiant spring interactions without adding a DOM wrapper. */
|
|
140
142
|
export function MotionProvider({ children }: { children?: ReactNode }) {
|