@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.
@@ -17,8 +17,9 @@ export function getProps(
17
17
  ): ComponentProps {
18
18
  const {allComponentProps, allPropDefs} = flattenCompositeProps(componentProps, propDefs)
19
19
  const restProps: ComponentProps = {}
20
- let className = componentProps?.className || ''
21
- let style = componentProps?.style || {}
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 = clsx(className, getClassName(propValue[i], resolvedPropDef, i))
45
- style = {...style, ...getStyle(propValue[i], resolvedPropDef, i)}
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 = clsx(className, getClassName(propValue, resolvedPropDef))
56
- style = {...style, ...getStyle(propValue, resolvedPropDef)}
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 {...restProps, className, style}
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 getStyle(propValue: any, propDef: PropDef, bp?: number) {
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 = '500alpha25'
3
- export const HASH = '13d200'
2
+ export const VERSION = '500alpha26'
3
+ export const HASH = 'f11fdc'