@sanity/ui 2.0.0-alpha.29 → 2.0.0-alpha.30

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": "2.0.0-alpha.29",
3
+ "version": "2.0.0-alpha.30",
4
4
  "sideEffects": false,
5
5
  "types": "./dist/index.d.ts",
6
6
  "source": "./exports/index.ts",
@@ -89,20 +89,20 @@
89
89
  "@sanity/pkg-utils": "^2.4.8",
90
90
  "@sanity/semantic-release-preset": "^4.1.4",
91
91
  "@sanity/ui-workshop": "^2.0.2",
92
- "@storybook/addon-a11y": "^7.4.5",
93
- "@storybook/addon-docs": "^7.4.5",
94
- "@storybook/addon-essentials": "^7.4.5",
95
- "@storybook/addon-interactions": "^7.4.5",
96
- "@storybook/addon-links": "^7.4.5",
97
- "@storybook/addon-storysource": "^7.4.5",
98
- "@storybook/addon-themes": "^7.4.5",
99
- "@storybook/blocks": "^7.4.5",
100
- "@storybook/jest": "^0.2.2",
101
- "@storybook/manager-api": "^7.4.5",
102
- "@storybook/react": "^7.4.5",
103
- "@storybook/react-vite": "^7.4.5",
104
- "@storybook/testing-library": "^0.2.1",
105
- "@storybook/theming": "^7.4.5",
92
+ "@storybook/addon-a11y": "^7.6.1",
93
+ "@storybook/addon-docs": "^7.6.1",
94
+ "@storybook/addon-essentials": "^7.6.1",
95
+ "@storybook/addon-interactions": "^7.6.1",
96
+ "@storybook/addon-links": "^7.6.1",
97
+ "@storybook/addon-storysource": "^7.6.1",
98
+ "@storybook/addon-themes": "^7.6.1",
99
+ "@storybook/blocks": "^7.6.1",
100
+ "@storybook/jest": "^0.2.3",
101
+ "@storybook/manager-api": "^7.6.1",
102
+ "@storybook/react": "^7.6.1",
103
+ "@storybook/react-vite": "^7.6.1",
104
+ "@storybook/testing-library": "^0.2.2",
105
+ "@storybook/theming": "^7.6.1",
106
106
  "@testing-library/dom": "^9.3.1",
107
107
  "@testing-library/jest-dom": "^5.17.0",
108
108
  "@testing-library/react": "^14.0.0",
@@ -128,7 +128,7 @@
128
128
  "eslint-plugin-prettier": "^5.0.0",
129
129
  "eslint-plugin-react": "^7.33.2",
130
130
  "eslint-plugin-react-hooks": "^4.6.0",
131
- "eslint-plugin-storybook": "^0.6.14",
131
+ "eslint-plugin-storybook": "^0.6.15",
132
132
  "http-server": "^14.1.1",
133
133
  "husky": "^8.0.3",
134
134
  "jest": "^29.6.4",
@@ -145,7 +145,7 @@
145
145
  "rimraf": "^5.0.1",
146
146
  "semantic-release": "^21.1.1",
147
147
  "start-server-and-test": "^2.0.0",
148
- "storybook": "^7.5.2",
148
+ "storybook": "^7.6.1",
149
149
  "styled-components": "^6.0.7",
150
150
  "tsconfig-paths": "^4.2.0",
151
151
  "typescript": "^5.2.2",
@@ -9,13 +9,12 @@ import {
9
9
  isHTMLElement,
10
10
  } from '../../helpers'
11
11
  import {useArrayProp, useClickOutside, useForwardedRef, useGlobalKeyDown} from '../../hooks'
12
- import {Box, Button, Card, CardProps, Container, Flex, Text} from '../../primitives'
12
+ import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
13
13
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
14
14
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
15
15
  import {useTheme} from '../../theme'
16
16
  import {DialogPosition, Radius} from '../../types'
17
17
  import {Layer, LayerProps, Portal, useBoundaryElement, useLayer, usePortal} from '../../utils'
18
- import {BORDER_OFFSET_X} from './constants'
19
18
  import {
20
19
  animationDialogStyle,
21
20
  AnimationDialogStyleProps,
@@ -82,15 +81,6 @@ interface DialogCardProps extends ResponsiveWidthProps {
82
81
  shadow: number | number[]
83
82
  }
84
83
 
85
- interface DialogHeaderProps extends CardProps {
86
- $hasScrolledFromTop: boolean
87
- $isContentScrollable: boolean
88
- }
89
- interface DialogFooterProps extends CardProps {
90
- $hasScrolledToBottom: boolean
91
- $isContentScrollable: boolean
92
- }
93
-
94
84
  function isTargetWithinScope(
95
85
  boundaryElement: HTMLElement | null,
96
86
  portalElement: HTMLElement | null,
@@ -136,22 +126,9 @@ const DialogLayout = styled(Flex)`
136
126
  width: 100%;
137
127
  `
138
128
 
139
- const DialogHeader = styled(Box)<DialogHeaderProps>`
129
+ const DialogHeader = styled(Box)`
140
130
  position: relative;
141
131
  z-index: 2;
142
-
143
- &:after {
144
- content: '';
145
- display: block;
146
- position: absolute;
147
- left: ${BORDER_OFFSET_X}px;
148
- right: ${BORDER_OFFSET_X}px;
149
- bottom: -1px;
150
- border-bottom: 1px solid var(--card-border-color);
151
- width: auto;
152
- opacity: ${(props) => (props.$isContentScrollable && props.$hasScrolledFromTop ? 1 : 0)};
153
- transition: opacity 200ms ease-in;
154
- }
155
132
  `
156
133
 
157
134
  const DialogContent = styled(Box)`
@@ -161,22 +138,9 @@ const DialogContent = styled(Box)`
161
138
  outline: none;
162
139
  `
163
140
 
164
- const DialogFooter = styled(Box)<DialogFooterProps>`
141
+ const DialogFooter = styled(Box)`
165
142
  position: relative;
166
143
  z-index: 3;
167
-
168
- &:before {
169
- content: '';
170
- display: block;
171
- position: absolute;
172
- left: ${BORDER_OFFSET_X}px;
173
- right: ${BORDER_OFFSET_X}px;
174
- top: -1px;
175
- border-top: 1px solid var(--card-border-color);
176
- width: auto;
177
- opacity: ${(props) => (props.$isContentScrollable && !props.$hasScrolledToBottom ? 1 : 0)};
178
- transition: opacity 200ms ease-in;
179
- }
180
144
  `
181
145
 
182
146
  const DialogCard = forwardRef(function DialogCard(
@@ -213,9 +177,6 @@ const DialogCard = forwardRef(function DialogCard(
213
177
  const labelId = `${id}_label`
214
178
  const showCloseButton = Boolean(onClose) && hideCloseButton === false
215
179
  const showHeader = Boolean(header) || showCloseButton
216
- const [isContentScrollable, setIsContentScrollable] = useState(false)
217
- const [hasScrolledFromTop, setHasScrolledFromTop] = useState(false)
218
- const [hasScrolledToBottom, setHasScrolledToBottom] = useState(false)
219
180
 
220
181
  useEffect(() => {
221
182
  if (!autoFocus) return
@@ -284,40 +245,12 @@ const DialogCard = forwardRef(function DialogCard(
284
245
  [contentRef],
285
246
  )
286
247
 
287
- const handleContentUpdate = useCallback(() => {
288
- if (localContentRef.current) {
289
- setIsContentScrollable(
290
- localContentRef.current.clientHeight < localContentRef.current.scrollHeight,
291
- )
292
- setHasScrolledFromTop(localContentRef.current.scrollTop > 0)
293
- setHasScrolledToBottom(
294
- localContentRef.current.scrollTop >=
295
- localContentRef.current.scrollHeight - localContentRef.current.clientHeight,
296
- )
297
- }
298
- }, [])
299
-
300
- useEffect(() => {
301
- const resizeObserver = new ResizeObserver(handleContentUpdate)
302
-
303
- if (localContentRef.current) {
304
- resizeObserver.observe(localContentRef.current)
305
- }
306
-
307
- return () => {
308
- resizeObserver.disconnect()
309
- }
310
- }, [contentRef, handleContentUpdate])
311
-
312
248
  return (
313
249
  <DialogContainer data-ui="DialogCard" width={width}>
314
250
  <DialogCardRoot radius={radius} ref={setRef} scheme={scheme} shadow={shadow}>
315
251
  <DialogLayout direction="column">
316
252
  {showHeader && (
317
- <DialogHeader
318
- $isContentScrollable={isContentScrollable}
319
- $hasScrolledFromTop={hasScrolledFromTop}
320
- >
253
+ <DialogHeader>
321
254
  <Flex align="center" padding={3}>
322
255
  <Box flex={1} padding={2}>
323
256
  {header && (
@@ -342,18 +275,11 @@ const DialogCard = forwardRef(function DialogCard(
342
275
  </DialogHeader>
343
276
  )}
344
277
 
345
- <DialogContent flex={1} ref={setContentRef} tabIndex={-1} onScroll={handleContentUpdate}>
278
+ <DialogContent flex={1} ref={setContentRef} tabIndex={-1}>
346
279
  {children}
347
280
  </DialogContent>
348
281
 
349
- {footer && (
350
- <DialogFooter
351
- $isContentScrollable={isContentScrollable}
352
- $hasScrolledToBottom={hasScrolledToBottom}
353
- >
354
- {footer}
355
- </DialogFooter>
356
- )}
282
+ {footer && <DialogFooter>{footer}</DialogFooter>}
357
283
  </DialogLayout>
358
284
  </DialogCardRoot>
359
285
  </DialogContainer>
@@ -1,4 +0,0 @@
1
- /**
2
- * Left/right border offsets for header + footer components (in px).
3
- */
4
- export const BORDER_OFFSET_X: number = 12