@cognitap/radiant 0.0.9 → 0.0.10
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 +5 -2
- package/dist/library/Switch.d.ts +15 -0
- package/dist/library/Switch.d.ts.map +1 -0
- package/dist/library/Switch.js +81 -0
- package/dist/library/Switch.js.map +1 -0
- package/dist/library/cn.d.ts.map +1 -1
- package/dist/library/cn.js +25 -8
- package/dist/library/cn.js.map +1 -1
- package/dist/library/index.d.ts +2 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +1 -0
- package/dist/library/index.js.map +1 -1
- package/dist/library/internal/switchDrag.d.ts +9 -0
- package/dist/library/internal/switchDrag.d.ts.map +1 -0
- package/dist/library/internal/switchDrag.js +170 -0
- package/dist/library/internal/switchDrag.js.map +1 -0
- package/dist/library/react/useSwitchDrag.d.ts +7 -0
- package/dist/library/react/useSwitchDrag.d.ts.map +1 -0
- package/dist/library/react/useSwitchDrag.js +34 -0
- package/dist/library/react/useSwitchDrag.js.map +1 -0
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +26 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +26 -0
- package/dist/library/themes/components.js.map +1 -1
- package/docs/architecture.md +16 -15
- package/docs/theming.md +10 -10
- package/package.json +3 -5
- package/src/Switch.tsx +174 -0
- package/src/cn.ts +25 -8
- package/src/index.ts +2 -0
- package/src/internal/switchDrag.ts +188 -0
- package/src/react/useSwitchDrag.ts +49 -0
- package/src/themes/components.ts +26 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useLayoutEffect, useRef, type RefObject } from 'react'
|
|
4
|
+
import { bindSwitchDrag, type SwitchDragBinding } from '../internal/switchDrag.js'
|
|
5
|
+
|
|
6
|
+
/** The input owns checked state; the private rail/handle own the transient drag. */
|
|
7
|
+
export function useSwitchDrag(
|
|
8
|
+
input: RefObject<HTMLInputElement | null>,
|
|
9
|
+
rail: RefObject<HTMLElement | null>,
|
|
10
|
+
handle: RefObject<HTMLElement | null>
|
|
11
|
+
) {
|
|
12
|
+
const binding = useRef<{
|
|
13
|
+
input: HTMLInputElement
|
|
14
|
+
rail: HTMLElement
|
|
15
|
+
handle: HTMLElement
|
|
16
|
+
control: SwitchDragBinding
|
|
17
|
+
} | null>(null)
|
|
18
|
+
useLayoutEffect(() => {
|
|
19
|
+
if (
|
|
20
|
+
binding.current &&
|
|
21
|
+
(binding.current.input !== input.current ||
|
|
22
|
+
binding.current.rail !== rail.current ||
|
|
23
|
+
binding.current.handle !== handle.current)
|
|
24
|
+
) {
|
|
25
|
+
binding.current.control.dispose()
|
|
26
|
+
binding.current = null
|
|
27
|
+
}
|
|
28
|
+
if (!binding.current && input.current && rail.current && handle.current) {
|
|
29
|
+
binding.current = {
|
|
30
|
+
input: input.current,
|
|
31
|
+
rail: rail.current,
|
|
32
|
+
handle: handle.current,
|
|
33
|
+
control: bindSwitchDrag(input.current, rail.current, handle.current)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
binding.current?.control.reconcile()
|
|
37
|
+
})
|
|
38
|
+
useLayoutEffect(
|
|
39
|
+
() => () => {
|
|
40
|
+
binding.current?.control.dispose()
|
|
41
|
+
binding.current = null
|
|
42
|
+
},
|
|
43
|
+
[]
|
|
44
|
+
)
|
|
45
|
+
return {
|
|
46
|
+
start: (event: PointerEvent) => binding.current?.control.start(event),
|
|
47
|
+
escape: (event: KeyboardEvent) => binding.current?.control.escape(event) ?? false
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/themes/components.ts
CHANGED
|
@@ -164,6 +164,32 @@ export const componentRegistry = {
|
|
|
164
164
|
focusOffset: 'css',
|
|
165
165
|
focusStyle: 'css'
|
|
166
166
|
},
|
|
167
|
+
switch: {
|
|
168
|
+
width: 'css',
|
|
169
|
+
height: 'css',
|
|
170
|
+
radius: 'css',
|
|
171
|
+
cornerShape: 'css',
|
|
172
|
+
borderWidth: 'css',
|
|
173
|
+
borderStyle: 'css',
|
|
174
|
+
borderColor: 'css',
|
|
175
|
+
background: 'css',
|
|
176
|
+
checkedBackground: 'css',
|
|
177
|
+
checkedBorder: 'css',
|
|
178
|
+
thumb: 'css',
|
|
179
|
+
checkedThumb: 'css',
|
|
180
|
+
thumbRadius: 'css',
|
|
181
|
+
invalidBorder: 'css',
|
|
182
|
+
gap: 'css',
|
|
183
|
+
labelColor: 'css',
|
|
184
|
+
labelSize: 'css',
|
|
185
|
+
disabledBorder: 'css',
|
|
186
|
+
disabledBackground: 'css',
|
|
187
|
+
disabledThumb: 'css',
|
|
188
|
+
focusColor: 'css',
|
|
189
|
+
focusWidth: 'css',
|
|
190
|
+
focusOffset: 'css',
|
|
191
|
+
focusStyle: 'css'
|
|
192
|
+
},
|
|
167
193
|
radio: {
|
|
168
194
|
size: 'css',
|
|
169
195
|
radius: 'css',
|