@sanity/ui 3.0.0-static.5 → 3.0.0-static.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "3.0.0-static.5",
3
+ "version": "3.0.0-static.6",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -125,7 +125,7 @@
125
125
  "@rollup/plugin-replace": "^6.0.2",
126
126
  "@sanity/pkg-utils": "^7.2.2",
127
127
  "@sanity/prettier-config": "^1.0.3",
128
- "@sanity/ui-workshop": "^2.1.2",
128
+ "@sanity/ui-workshop": "^2.1.3",
129
129
  "@storybook/addon-a11y": "^8.6.12",
130
130
  "@storybook/addon-docs": "^8.6.12",
131
131
  "@storybook/addon-essentials": "^8.6.12",
@@ -2,7 +2,7 @@ import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
4
  export default defineScope({
5
- name: './css/input',
5
+ name: 'css/input',
6
6
  title: 'Input',
7
7
  stories: [
8
8
  {
@@ -2,7 +2,7 @@ import {defineScope} from '@sanity/ui-workshop'
2
2
  import {lazy} from 'react'
3
3
 
4
4
  export default defineScope({
5
- name: './components/autocomplete',
5
+ name: 'components/autocomplete',
6
6
  title: 'Autocomplete',
7
7
  stories: [
8
8
  {
@@ -26,7 +26,7 @@ import {
26
26
  useRef,
27
27
  } from 'react'
28
28
 
29
- import {useTheme_v2} from '../../_compat'
29
+ import {Z_OFFSETS} from '../../constants'
30
30
  import {
31
31
  containsOrEqualsElement,
32
32
  focusFirstDescendant,
@@ -282,7 +282,6 @@ export const Dialog = forwardRef(function Dialog(
282
282
  ref: ForwardedRef<HTMLDivElement>,
283
283
  ) {
284
284
  const context = useDialog()
285
- const {layer} = useTheme_v2()
286
285
  const {
287
286
  __unstable_autoFocus: autoFocus = true,
288
287
  __unstable_hideCloseButton: hideCloseButton = false,
@@ -309,8 +308,8 @@ export const Dialog = forwardRef(function Dialog(
309
308
  tone,
310
309
  ...restProps
311
310
  } = props
312
- const positionProp = _positionProp ?? (context.position || 'fixed')
313
- const zOffsetProp = _zOffsetProp ?? (context.zOffset || layer.dialog.zOffset)
311
+ const positionProp = _positionProp ?? context.position ?? 'fixed'
312
+ const zOffsetProp = _zOffsetProp ?? context.zOffset ?? Z_OFFSETS.dialog
314
313
  const prefersReducedMotion = usePrefersReducedMotion()
315
314
  const animate = prefersReducedMotion ? false : _animate
316
315
  const portal = usePortal()
@@ -77,3 +77,9 @@ export const FLOATING_STATIC_SIDES: Record<string, 'bottom' | 'left' | 'top' | '
77
77
  bottom: 'top',
78
78
  left: 'right',
79
79
  }
80
+
81
+ export const Z_OFFSETS = {
82
+ dialog: 600,
83
+ popover: 400,
84
+ tooltip: 200,
85
+ }
@@ -96,8 +96,6 @@ function getServerSnapshot() {
96
96
  * @beta
97
97
  */
98
98
  export function useMediaIndex(): number {
99
- // const {media} = useTheme_v2()
100
- // const media = MEDIA
101
99
  const store = useMemo(() => _createMediaStore(), [])
102
100
 
103
101
  return useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot)
@@ -26,7 +26,7 @@ export const Code = forwardRef(function Code(
26
26
  children,
27
27
  className,
28
28
  language: languageProp,
29
- size = 1,
29
+ size = 2,
30
30
  weight,
31
31
  ...restProps
32
32
  } = props
@@ -26,13 +26,8 @@ import {
26
26
  useRef,
27
27
  } from 'react'
28
28
 
29
- // import {useTheme_v2} from '../../_compat'
30
- import {
31
- useArrayProp,
32
- // useElementSize,
33
- // useMediaIndex,
34
- usePrefersReducedMotion,
35
- } from '../../hooks'
29
+ import {Z_OFFSETS} from '../../constants'
30
+ import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
36
31
  import {origin} from '../../middleware/origin'
37
32
  import {Placement, PopoverMargins, Props} from '../../types'
38
33
  import {LayerProps, LayerProvider, Portal, useBoundaryElement, useLayer} from '../../utils'
@@ -44,7 +39,6 @@ import {
44
39
  DEFAULT_POPOVER_PADDING,
45
40
  } from './constants'
46
41
  import {size} from './floating-ui/size'
47
- // import {calcCurrentWidth, calcMaxWidth} from './helpers'
48
42
  import {PopoverCard} from './popoverCard'
49
43
  import {PopoverUpdateCallback} from './types'
50
44
 
@@ -67,7 +61,7 @@ export interface PopoverProps extends CardProps, LayerProps {
67
61
  * When `true`, prevent overflow within the current boundary:
68
62
  * - by flipping on its side axis
69
63
  * - by resizing
70
- /*
64
+ *
71
65
  * Note that:
72
66
  * - setting `preventOverflow` to `true` also prevents overflow on its side axis
73
67
  * - setting `matchReferenceWidth` to `true` also causes the popover to resize
@@ -128,13 +122,13 @@ export const Popover = memo(
128
122
  props: Props<PopoverProps, 'div'>,
129
123
  forwardedRef: ForwardedRef<HTMLDivElement>,
130
124
  ): ReactElement {
131
- // const {container, layer} = useTheme_v2()
132
125
  const boundaryElementContext = useBoundaryElement()
133
126
 
134
127
  const {
135
128
  __unstable_margins: margins = DEFAULT_POPOVER_MARGINS,
136
129
  animate: _animate = false,
137
130
  arrow: arrowProp = false,
131
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
138
132
  boundaryElement = boundaryElementContext.element,
139
133
  children: childProp,
140
134
  constrainSize = false,
@@ -161,17 +155,12 @@ export const Popover = memo(
161
155
  tone = 'inherit',
162
156
  width: widthProp = 'auto',
163
157
  // zOffset: zOffsetProp = layer.popover.zOffset,
164
- zOffset: zOffsetProp,
158
+ zOffset: zOffsetProp = Z_OFFSETS.popover,
165
159
  updateRef,
166
160
  ...restProps
167
161
  } = props
168
162
  const prefersReducedMotion = usePrefersReducedMotion()
169
163
  const animate = prefersReducedMotion ? false : _animate
170
- // const boundarySize = useElementSize(boundaryElement)?.border
171
- // const padding = useArrayProp(paddingProp)
172
- // const radius = useArrayProp(radiusProp)
173
- // const shadow = useArrayProp(shadowProp)
174
- // const widthArrayProp = useArrayProp(widthProp)
175
164
  const zOffset = useArrayProp(zOffsetProp)
176
165
  const ref = useRef<HTMLDivElement | null>(null)
177
166
  const arrowRef = useRef<HTMLDivElement | null>(null)
@@ -182,57 +171,9 @@ export const Popover = memo(
182
171
  () => ref.current,
183
172
  )
184
173
 
185
- // const mediaIndex = useMediaIndex()
186
- // const boundaryWidth = constrainSize || preventOverflow ? boundarySize?.width : undefined
187
-
188
- // Update width when
189
- // - media index changes
190
- // - `width` property changes
191
- // const width = calcCurrentWidth({
192
- // container,
193
- // mediaIndex,
194
- // width: widthArrayProp,
195
- // })
196
- // const widthRef = useRef(width)
197
-
198
- // useEffect(() => {
199
- // widthRef.current = width
200
- // }, [width])
201
-
202
- // Update max width when
203
- // - boundary width changes
204
- // - `width` property changes
205
- // const maxWidth = calcMaxWidth({boundaryWidth, currentWidth: width})
206
- // const maxWidthRef = useRef(maxWidth)
207
-
208
- // useEffect(() => {
209
- // maxWidthRef.current = maxWidth
210
- // }, [maxWidth])
211
-
212
174
  // Keep track of reference element width (see `size` middleware below)
213
175
  const referenceWidthRef = useRef<number>(undefined)
214
176
 
215
- // // Force apply width & max width to floating element
216
- // useEffect(() => {
217
- // const floatingElement = ref.current
218
-
219
- // if (!open || !floatingElement) return
220
-
221
- // const referenceWidth = referenceWidthRef.current
222
-
223
- // if (matchReferenceWidth) {
224
- // if (referenceWidth !== undefined) {
225
- // floatingElement.style.width = `${referenceWidth}px`
226
- // }
227
- // } else if (width !== undefined) {
228
- // floatingElement.style.width = `${width}px`
229
- // }
230
-
231
- // if (typeof maxWidth === 'number') {
232
- // floatingElement.style.maxWidth = `${maxWidth}px`
233
- // }
234
- // }, [width, matchReferenceWidth, maxWidth, open])
235
-
236
177
  const middleware = useMemo(() => {
237
178
  const ret: Middleware[] = []
238
179
 
@@ -260,22 +201,11 @@ export const Popover = memo(
260
201
 
261
202
  referenceWidthRef.current = referenceWidth
262
203
 
263
- // const _currentWidth = widthRef.current
264
- // const _maxWidth = maxWidthRef.current
265
-
266
204
  if (matchReferenceWidth) {
267
205
  elements.floating.style.width = `${referenceWidth}px`
268
206
  }
269
- // else if (_currentWidth !== undefined) {
270
- // elements.floating.style.width = `${_currentWidth}px`
271
- // }
272
207
 
273
208
  if (constrainSize) {
274
- // elements.floating.style.maxWidth = `${Math.min(
275
- // availableWidth,
276
- // _maxWidth ?? Infinity,
277
- // )}px`
278
-
279
209
  elements.floating.style.maxWidth = `${availableWidth}px`
280
210
  elements.floating.style.maxHeight = `${availableHeight}px`
281
211
  }
@@ -106,7 +106,7 @@ export const TextInput = forwardRef(function TextInput(
106
106
  className,
107
107
  clearButton,
108
108
  disabled = false,
109
- fontSize = 1,
109
+ fontSize = 2,
110
110
  gap,
111
111
  icon: IconComponent,
112
112
  iconRight: IconRightComponent,
@@ -28,7 +28,7 @@ import {
28
28
  } from 'react'
29
29
  import {useEffectEvent} from 'use-effect-event'
30
30
 
31
- import {useTheme_v2} from '../../_compat'
31
+ import {Z_OFFSETS} from '../../constants'
32
32
  import {useArrayProp, usePrefersReducedMotion} from '../../hooks'
33
33
  import {useDelayedState} from '../../hooks/useDelayedState'
34
34
  import {origin} from '../../middleware/origin'
@@ -91,7 +91,6 @@ export const Tooltip = forwardRef(function Tooltip(
91
91
  forwardedRef: ForwardedRef<HTMLDivElement>,
92
92
  ) {
93
93
  const boundaryElementContext = useBoundaryElement()
94
- const {layer} = useTheme_v2()
95
94
  const {
96
95
  animate: _animate = false,
97
96
  arrow: arrowProp = false,
@@ -109,7 +108,7 @@ export const Tooltip = forwardRef(function Tooltip(
109
108
  radius = 3,
110
109
  scheme,
111
110
  shadow = 2,
112
- zOffset = layer.tooltip.zOffset,
111
+ zOffset = Z_OFFSETS.tooltip,
113
112
  tone,
114
113
  ...restProps
115
114
  } = props