@cognitap/radiant 0.0.11 → 0.0.13

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +11 -3
  2. package/RELEASE_POLICY.md +5 -4
  3. package/dist/library/Combobox.d.ts +88 -0
  4. package/dist/library/Combobox.d.ts.map +1 -0
  5. package/dist/library/Combobox.js +365 -0
  6. package/dist/library/Combobox.js.map +1 -0
  7. package/dist/library/Select.js +1 -1
  8. package/dist/library/Select.js.map +1 -1
  9. package/dist/library/Tabs.d.ts +52 -0
  10. package/dist/library/Tabs.d.ts.map +1 -0
  11. package/dist/library/Tabs.js +234 -0
  12. package/dist/library/Tabs.js.map +1 -0
  13. package/dist/library/cn.d.ts.map +1 -1
  14. package/dist/library/cn.js +51 -14
  15. package/dist/library/cn.js.map +1 -1
  16. package/dist/library/comboboxStyles.d.ts +6 -0
  17. package/dist/library/comboboxStyles.d.ts.map +1 -0
  18. package/dist/library/comboboxStyles.js +38 -0
  19. package/dist/library/comboboxStyles.js.map +1 -0
  20. package/dist/library/index.d.ts +4 -0
  21. package/dist/library/index.d.ts.map +1 -1
  22. package/dist/library/index.js +2 -0
  23. package/dist/library/index.js.map +1 -1
  24. package/dist/library/motion/popup.js +5 -5
  25. package/dist/library/motion/popup.js.map +1 -1
  26. package/dist/library/react/useComboboxPopup.d.ts +4 -0
  27. package/dist/library/react/useComboboxPopup.d.ts.map +1 -0
  28. package/dist/library/react/useComboboxPopup.js +118 -0
  29. package/dist/library/react/useComboboxPopup.js.map +1 -0
  30. package/dist/library/styles.css +1 -1
  31. package/dist/library/themes/components.d.ts +55 -0
  32. package/dist/library/themes/components.d.ts.map +1 -1
  33. package/dist/library/themes/components.js +55 -0
  34. package/dist/library/themes/components.js.map +1 -1
  35. package/docs/architecture.md +27 -18
  36. package/docs/theming.md +1 -1
  37. package/package.json +1 -1
  38. package/src/Combobox.tsx +752 -0
  39. package/src/Select.tsx +1 -1
  40. package/src/Tabs.tsx +437 -0
  41. package/src/cn.ts +51 -14
  42. package/src/comboboxStyles.ts +41 -0
  43. package/src/index.ts +30 -0
  44. package/src/motion/popup.ts +5 -5
  45. package/src/react/useComboboxPopup.ts +130 -0
  46. package/src/themes/components.ts +55 -0
@@ -12,11 +12,11 @@ export function bindPopupMotion(node: HTMLElement, initial: MotionProfile): Moti
12
12
  ...resolveMotion(profile, 'dialog', query.matches),
13
13
  reducedValue: 0
14
14
  })
15
- const previous = node.style.getPropertyValue('--_rad-select-enter')
15
+ const previous = node.style.getPropertyValue('--_rad-popup-enter')
16
16
  let owned = previous
17
17
  const render = (value: number) => {
18
18
  owned = String(Math.max(0, Math.min(1, value)))
19
- node.style.setProperty('--_rad-select-enter', owned)
19
+ node.style.setProperty('--_rad-popup-enter', owned)
20
20
  }
21
21
  const off = spring.subscribe(render)
22
22
  render(spring.get())
@@ -46,9 +46,9 @@ export function bindPopupMotion(node: HTMLElement, initial: MotionProfile): Moti
46
46
  query.removeEventListener('change', sync)
47
47
  off()
48
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')
49
+ if (node.style.getPropertyValue('--_rad-popup-enter') === owned) {
50
+ if (previous) node.style.setProperty('--_rad-popup-enter', previous)
51
+ else node.style.removeProperty('--_rad-popup-enter')
52
52
  }
53
53
  }
54
54
  }
@@ -0,0 +1,130 @@
1
+ 'use client'
2
+
3
+ import { useLayoutEffect, useRef, type RefObject } from 'react'
4
+ import { positionSelect } from '../internal/select.js'
5
+
6
+ /** Local top-layer popup: preserve theme/modal ancestry and place before its first paint. */
7
+ export function useComboboxPopup(
8
+ nodeRef: RefObject<HTMLDivElement | null>,
9
+ input: HTMLInputElement | null,
10
+ open: boolean,
11
+ dismiss: () => void,
12
+ sideOffset: number,
13
+ collisionPadding: number
14
+ ) {
15
+ const latest = useRef(dismiss)
16
+ useLayoutEffect(() => {
17
+ latest.current = dismiss
18
+ })
19
+ useLayoutEffect(() => {
20
+ const node = nodeRef.current
21
+ if (!node || !input) return
22
+ if (!open) {
23
+ if (node.matches(':popover-open')) node.hidePopover()
24
+ return
25
+ }
26
+ const doc = input.ownerDocument
27
+ const win = doc.defaultView!
28
+ const seedWidth = () => {
29
+ const available =
30
+ (win.visualViewport?.width ?? win.innerWidth) - 2 * Math.max(0, collisionPadding)
31
+ node.style.setProperty(
32
+ '--_rad-combobox-width',
33
+ `${Math.min(input.getBoundingClientRect().width, Math.max(0, available))}px`
34
+ )
35
+ }
36
+ seedWidth()
37
+ node.showPopover()
38
+ const place = () => {
39
+ if (!node.isConnected || !node.matches(':popover-open')) return
40
+ seedWidth()
41
+ const viewport = win.visualViewport
42
+ const css = win.getComputedStyle(node)
43
+ const anchor = input.getBoundingClientRect()
44
+ const padding = Math.max(0, collisionPadding)
45
+ const list = node.querySelector<HTMLElement>('[data-slot="combobox-listbox"]')
46
+ const status = node.querySelector<HTMLElement>('[data-slot="combobox-status"]')
47
+ const naturalHeight =
48
+ (list?.scrollHeight ?? node.scrollHeight) +
49
+ (status?.offsetHeight ?? 0) +
50
+ parseFloat(css.paddingTop) +
51
+ parseFloat(css.paddingBottom) +
52
+ parseFloat(css.borderTopWidth) +
53
+ parseFloat(css.borderBottomWidth)
54
+ const above = anchor.top - (viewport?.offsetTop ?? 0) - padding - sideOffset
55
+ const below =
56
+ (viewport?.offsetTop ?? 0) +
57
+ (viewport?.height ?? win.innerHeight) -
58
+ anchor.bottom -
59
+ padding -
60
+ sideOffset
61
+ const next = positionSelect({
62
+ trigger: anchor,
63
+ width: node.getBoundingClientRect().width,
64
+ height: Math.min(naturalHeight, Math.max(0, above, below)),
65
+ selectedOffset: 0,
66
+ viewport: {
67
+ top: viewport?.offsetTop ?? 0,
68
+ left: viewport?.offsetLeft ?? 0,
69
+ width: viewport?.width ?? win.innerWidth,
70
+ height: viewport?.height ?? win.innerHeight
71
+ },
72
+ padding: Math.max(0, collisionPadding),
73
+ offset: sideOffset,
74
+ aligned: false,
75
+ rtl: win.getComputedStyle(input).direction === 'rtl'
76
+ })
77
+ for (const [key, value] of Object.entries({
78
+ top: next.top,
79
+ left: next.left,
80
+ width: next.width,
81
+ 'max-height': next.maxHeight
82
+ })) {
83
+ const property = `--_rad-combobox-${key}`
84
+ if (node.style.getPropertyValue(property) !== `${value}px`)
85
+ node.style.setProperty(property, `${value}px`)
86
+ }
87
+ }
88
+ place()
89
+ let frame = 0
90
+ const schedule = () => {
91
+ if (!frame)
92
+ frame = win.requestAnimationFrame(() => {
93
+ frame = 0
94
+ place()
95
+ })
96
+ }
97
+ const outside = (event: PointerEvent | FocusEvent) => {
98
+ const target = event.target
99
+ if (
100
+ target instanceof win.Node &&
101
+ !node.contains(target) &&
102
+ !input.parentElement?.contains(target)
103
+ )
104
+ latest.current()
105
+ }
106
+ const observer = new win.ResizeObserver(schedule)
107
+ const mutations = new win.MutationObserver(schedule)
108
+ observer.observe(input)
109
+ observer.observe(node)
110
+ mutations.observe(node, { childList: true, subtree: true, characterData: true })
111
+ doc.addEventListener('pointerdown', outside, true)
112
+ doc.addEventListener('focusin', outside)
113
+ doc.addEventListener('scroll', schedule, true)
114
+ win.addEventListener('resize', schedule)
115
+ win.visualViewport?.addEventListener('resize', schedule)
116
+ win.visualViewport?.addEventListener('scroll', schedule)
117
+ return () => {
118
+ observer.disconnect()
119
+ mutations.disconnect()
120
+ win.cancelAnimationFrame(frame)
121
+ doc.removeEventListener('pointerdown', outside, true)
122
+ doc.removeEventListener('focusin', outside)
123
+ doc.removeEventListener('scroll', schedule, true)
124
+ win.removeEventListener('resize', schedule)
125
+ win.visualViewport?.removeEventListener('resize', schedule)
126
+ win.visualViewport?.removeEventListener('scroll', schedule)
127
+ if (node.matches(':popover-open')) node.hidePopover()
128
+ }
129
+ }, [nodeRef, input, open, sideOffset, collisionPadding])
130
+ }
@@ -139,6 +139,61 @@ export const componentRegistry = {
139
139
  focusOffset: 'css',
140
140
  focusStyle: 'css'
141
141
  },
142
+ tabs: {
143
+ gap: 'css',
144
+ listGap: 'css',
145
+ listRadius: 'css',
146
+ listBackground: 'css',
147
+ listPadding: 'css',
148
+ triggerHeight: 'css',
149
+ triggerPadding: 'css',
150
+ triggerRadius: 'css',
151
+ triggerBorderWidth: 'css',
152
+ cornerShape: 'css',
153
+ fontFamily: 'css',
154
+ fontWeight: 'weight',
155
+ fontSize: 'css',
156
+ triggerColor: 'css',
157
+ triggerBackground: 'css',
158
+ triggerHoverBackground: 'css',
159
+ triggerActiveBackground: 'css',
160
+ triggerActiveColor: 'css',
161
+ triggerActiveBorder: 'css',
162
+ focusColor: 'css',
163
+ focusWidth: 'css',
164
+ focusOffset: 'css',
165
+ focusStyle: 'css',
166
+ disabledOpacity: 'opacity',
167
+ contentRadius: 'css',
168
+ contentPadding: 'css',
169
+ contentColor: 'css',
170
+ contentBackground: 'css'
171
+ },
172
+ combobox: {
173
+ placeholder: 'css',
174
+ height: 'css',
175
+ padding: 'css',
176
+ fontFamily: 'css',
177
+ fontSize: 'css',
178
+ fontWeight: 'weight',
179
+ color: 'css',
180
+ background: 'css',
181
+ borderWidth: 'css',
182
+ borderStyle: 'css',
183
+ borderColor: 'css',
184
+ radius: 'css',
185
+ cornerShape: 'css',
186
+ shadow: 'css',
187
+ focusColor: 'css',
188
+ contentPadding: 'css',
189
+ contentRadius: 'css',
190
+ contentBackground: 'css',
191
+ contentBackdropFilter: 'css',
192
+ contentShadow: 'css',
193
+ itemRadius: 'css',
194
+ itemBackground: 'css',
195
+ itemColor: 'css'
196
+ },
142
197
  select: {
143
198
  height: 'css',
144
199
  padding: 'css',