@sanity/ui 5.0.0-alpha.5 → 5.0.0-alpha.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/dist/index.d.ts +54 -9
- package/dist/index.js +197 -79
- package/dist/index.js.map +1 -1
- package/dist/polyfills.d.ts +1 -0
- package/dist/polyfills.js +5 -0
- package/dist/polyfills.js.map +1 -0
- package/dist/styles.css +1 -1
- package/package.json +8 -2
- package/src/components/checkbox/Checkbox.tsx +1 -1
- package/src/components/index.css +1 -0
- package/src/components/modal/Modal.tsx +5 -10
- package/src/components/modal/modal.css +3 -3
- package/src/components/modal/modal.props.ts +9 -0
- package/src/components/popover/Popover.tsx +85 -0
- package/src/components/popover/popover.css +21 -0
- package/src/components/popover/popover.props.ts +28 -0
- package/src/components/radio/Radio.tsx +1 -1
- package/src/components/switch/Switch.tsx +1 -1
- package/src/components/tooltip/Tooltip.tsx +59 -55
- package/src/components/tooltip/tooltip.css +19 -40
- package/src/components/tooltip/tooltip.props.ts +16 -8
- package/src/components/tooltip-group/TooltipGroup.tsx +2 -5
- package/src/css/classes/generic/placement.css +31 -0
- package/src/css/tokens/semantic.css +4 -0
- package/src/hooks/useIsClient.ts +10 -0
- package/src/index.ts +3 -0
- package/src/polyfills.ts +15 -0
- package/src/utils/mergeTriggerProps.ts +66 -0
- package/src/utils/renderPortal.tsx +14 -0
- package/src/version.ts +2 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
function isReactEventHandler(key: string, value: unknown): value is (e: never) => void {
|
|
2
|
+
return /^on[A-Z]/.test(key) && typeof value === 'function'
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function chainEventHandlers<E>(
|
|
6
|
+
...handlers: (((e: E) => void) | undefined)[]
|
|
7
|
+
): ((e: E) => void) | undefined {
|
|
8
|
+
const defined = handlers.filter(Boolean) as ((e: E) => void)[]
|
|
9
|
+
|
|
10
|
+
if (defined.length === 0) {
|
|
11
|
+
return undefined
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (defined.length === 1) {
|
|
15
|
+
return defined[0]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (e: E) => {
|
|
19
|
+
for (const handler of defined) {
|
|
20
|
+
handler(e)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function mergeTriggerProps(
|
|
26
|
+
childProps: Record<string, unknown>,
|
|
27
|
+
forwardedProps?: Record<string, unknown>,
|
|
28
|
+
ownProps?: Record<string, unknown>,
|
|
29
|
+
) {
|
|
30
|
+
const result: Record<string, unknown> = {}
|
|
31
|
+
|
|
32
|
+
for (const source of [forwardedProps, ownProps]) {
|
|
33
|
+
if (!source) {
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (const [key, value] of Object.entries(source)) {
|
|
38
|
+
if (key === 'style') {
|
|
39
|
+
continue
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isReactEventHandler(key, value)) {
|
|
43
|
+
result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
|
|
44
|
+
continue
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (value !== undefined) {
|
|
48
|
+
result[key] = value
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
result['style'] = {
|
|
54
|
+
...(childProps['style'] as object),
|
|
55
|
+
...(forwardedProps?.['style'] as object),
|
|
56
|
+
...(ownProps?.['style'] as object),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const [key, value] of Object.entries(childProps)) {
|
|
60
|
+
if (isReactEventHandler(key, value)) {
|
|
61
|
+
result[key] = chainEventHandlers(result[key] as (e: never) => void, value)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return result
|
|
66
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {type ReactNode} from 'react'
|
|
2
|
+
import {createPortal} from 'react-dom'
|
|
3
|
+
|
|
4
|
+
export function renderPortal(node: ReactNode, mounted: boolean, portal?: boolean) {
|
|
5
|
+
if (!portal) {
|
|
6
|
+
return node
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (!mounted) {
|
|
10
|
+
return null
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return createPortal(node, document.body)
|
|
14
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// This file is generated by scripts/write-version.js. Do not edit.
|
|
2
|
-
export const VERSION = '
|
|
3
|
-
export const HASH = '
|
|
2
|
+
export const VERSION = '500alpha6'
|
|
3
|
+
export const HASH = '71d7e5'
|