@sanity/ui 5.0.0-alpha.25 → 5.0.0-alpha.26
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 +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +193 -81
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/checkbox/Checkbox.tsx +3 -2
- package/src/components/dialog/Dialog.tsx +3 -2
- package/src/components/index.css +1 -0
- package/src/components/search-input/SearchInput.tsx +90 -0
- package/src/components/search-input/search-input.css +125 -0
- package/src/components/search-input/searchInput.props.ts +18 -0
- package/src/components/select/Select.tsx +6 -1
- package/src/components/select/select.css +10 -12
- package/src/components/tooltip-group/TooltipGroup.tsx +6 -5
- package/src/components/visually-hidden/visuallyHidden.props.ts +1 -1
- package/src/index.ts +1 -0
- package/src/types/Tone.ts +1 -1
- package/src/utils/composeRefs.test.ts +130 -0
- package/src/utils/composeRefs.ts +52 -0
- package/src/utils/getProps.test.ts +18 -0
- package/src/utils/getProps.ts +31 -16
- package/src/version.ts +2 -2
package/src/utils/getProps.ts
CHANGED
|
@@ -17,8 +17,9 @@ export function getProps(
|
|
|
17
17
|
): ComponentProps {
|
|
18
18
|
const {allComponentProps, allPropDefs} = flattenCompositeProps(componentProps, propDefs)
|
|
19
19
|
const restProps: ComponentProps = {}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const classNames: string[] = []
|
|
21
|
+
const style = (componentProps?.style ? {...componentProps.style} : {}) as React.CSSProperties &
|
|
22
|
+
Record<string, string | number | undefined>
|
|
22
23
|
|
|
23
24
|
for (const key in allComponentProps) {
|
|
24
25
|
const propDef = allPropDefs?.[key]
|
|
@@ -32,32 +33,48 @@ export function getProps(
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
if (Array.isArray(propValue)) {
|
|
35
|
-
// @TODO: consider fixing this O(n^2) time complexity
|
|
36
|
-
// oxlint-disable-next-line no-accumulating-spread
|
|
37
36
|
for (let i = 0, len = Math.min(propValue.length, BREAKPOINTS_LENGTH); i < len; i++) {
|
|
38
37
|
const resolvedPropDef = getResolvedPropDef(propValue[i], propDef)
|
|
39
38
|
|
|
40
|
-
if (!resolvedPropDef) {
|
|
39
|
+
if (!resolvedPropDef || propValue[i] === null || propValue[i] === undefined) {
|
|
41
40
|
continue
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
className =
|
|
45
|
-
|
|
43
|
+
const className = getClassName(propValue[i], resolvedPropDef, i)
|
|
44
|
+
if (className) {
|
|
45
|
+
classNames.push(className)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const styleKey = getStyleKey(resolvedPropDef, i)
|
|
49
|
+
if (styleKey) {
|
|
50
|
+
style[styleKey] = propValue[i] as string | number
|
|
51
|
+
}
|
|
46
52
|
}
|
|
47
53
|
} else {
|
|
48
54
|
const resolvedPropDef = getResolvedPropDef(propValue, propDef)
|
|
49
55
|
|
|
50
|
-
if (!resolvedPropDef) {
|
|
56
|
+
if (!resolvedPropDef || propValue === null || propValue === undefined) {
|
|
51
57
|
restProps[key] = propValue
|
|
52
58
|
continue
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
className =
|
|
56
|
-
|
|
61
|
+
const className = getClassName(propValue, resolvedPropDef)
|
|
62
|
+
if (className) {
|
|
63
|
+
classNames.push(className)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const styleKey = getStyleKey(resolvedPropDef)
|
|
67
|
+
if (styleKey) {
|
|
68
|
+
style[styleKey] = propValue as string | number
|
|
69
|
+
}
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
72
|
|
|
60
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
...restProps,
|
|
75
|
+
className: clsx(componentProps?.className, ...classNames),
|
|
76
|
+
style,
|
|
77
|
+
}
|
|
61
78
|
}
|
|
62
79
|
|
|
63
80
|
function getResolvedPropDef(propValue: any, propDef?: PropDef) {
|
|
@@ -97,14 +114,12 @@ function getClassName(propValue: any, propDef: PropDef, bp?: number) {
|
|
|
97
114
|
return ''
|
|
98
115
|
}
|
|
99
116
|
|
|
100
|
-
function
|
|
117
|
+
function getStyleKey(propDef: PropDef, bp?: number): string | undefined {
|
|
101
118
|
if ((propDef.type === 'string' || propDef.type === 'number') && propDef.variable) {
|
|
102
|
-
return {
|
|
103
|
-
[`${propDef.variable}${bp ? `-bp-${bp}` : ''}`]: propValue,
|
|
104
|
-
}
|
|
119
|
+
return `${propDef.variable}${bp ? `-bp-${bp}` : ''}`
|
|
105
120
|
}
|
|
106
121
|
|
|
107
|
-
return
|
|
122
|
+
return undefined
|
|
108
123
|
}
|
|
109
124
|
|
|
110
125
|
export function flattenCompositeProps(
|
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 = '500alpha26'
|
|
3
|
+
export const HASH = 'f11fdc'
|