@sanity/ui 3.0.0-static.30 → 3.0.0-static.32
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/_chunks-cjs/_visual-editing.cjs +62 -61
- package/dist/_chunks-cjs/_visual-editing.cjs.map +1 -1
- package/dist/_chunks-cjs/refractor.cjs.map +1 -1
- package/dist/_chunks-es/_visual-editing.js +62 -61
- package/dist/_chunks-es/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/refractor.js.map +1 -1
- package/dist/css/index.cjs +1 -3
- package/dist/css/index.cjs.map +1 -1
- package/dist/css/index.css +1 -1
- package/dist/css/index.d.cts +7228 -7228
- package/dist/css/index.d.ts +7228 -7228
- package/dist/css/index.js +1 -3
- package/dist/css/index.js.map +1 -1
- package/dist/index.cjs +91 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +93 -90
- package/dist/index.js.map +1 -1
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.js.map +1 -1
- package/package.json +25 -25
- package/src/core/{primitives/root/Root.tsx → Root.tsx} +5 -3
- package/src/core/{primitives/root/RootProvider.tsx → RootProvider.tsx} +5 -5
- package/src/core/__DEV__.ts +0 -1
- package/src/core/__workshop__/boundary.tsx +28 -0
- package/src/core/__workshop__/index.ts +14 -0
- package/src/core/_compat/theme/theme.test.tsx +4 -3
- package/src/core/components/dialog/dialogCard.tsx +9 -2
- package/src/core/components/menu/menu.test.tsx +8 -7
- package/src/core/components/toast/toast.test.tsx +8 -7
- package/src/core/hooks/usePrefersDark.hydration.test.tsx +1 -1
- package/src/core/hooks/usePrefersReducedMotion.hydration.test.tsx +1 -1
- package/src/core/index.ts +4 -2
- package/src/core/lib/createGlobalScopedContext.ts +5 -2
- package/src/core/lib/globalScope.ts +1 -1
- package/src/core/primitives/card/card.tsx +4 -3
- package/src/core/primitives/card/useCard.ts +8 -2
- package/src/core/primitives/code/refractor.tsx +1 -1
- package/src/core/primitives/grid/types.ts +1 -1
- package/src/core/primitives/layer/layer.test.tsx +8 -7
- package/src/core/primitives/popover/popover.tsx +5 -33
- package/src/core/primitives/textArea/textArea.tsx +0 -2
- package/src/core/primitives/tooltip/tooltip.tsx +1 -4
- package/src/core/primitives/types.ts +11 -11
- package/src/core/types/props.ts +1 -0
- package/src/core/utils/boundaryElement/boundaryElement.test.tsx +8 -7
- package/src/core/utils/getElementRef.ts +2 -0
- package/src/core/utils/portal/portal.test.tsx +8 -7
- package/src/core/utils/portal/portal.tsx +1 -5
- package/src/core/utils/portal/portalContext.ts +10 -7
- package/src/css/components/dialog/dialog.css.ts +2 -2
- package/src/css/components/toast/toast.css.ts +2 -2
- package/src/css/primitives/button/button.css.ts +0 -2
- package/src/css/primitives/root/root.css.ts +5 -1
- package/src/css/primitives/root/root.ts +1 -1
- package/src/css/props/gridColumnStart/types.ts +1 -1
- package/src/theme/v0/css.ts +2 -0
- package/src/theme/v2/build/merge.ts +2 -0
- package/src/theme/v3/merge.ts +2 -0
- package/src/core/primitives/root/__workshop__/boundary.tsx +0 -5
- package/src/core/primitives/root/__workshop__/index.ts +0 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "3.0.0-static.
|
|
3
|
+
"version": "3.0.0-static.32",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react",
|
|
6
6
|
"ui",
|
|
@@ -99,45 +99,45 @@
|
|
|
99
99
|
"extends": "@sanity/semantic-release-preset"
|
|
100
100
|
},
|
|
101
101
|
"dependencies": {
|
|
102
|
-
"@floating-ui/react-dom": "^2.1.
|
|
102
|
+
"@floating-ui/react-dom": "^2.1.3",
|
|
103
103
|
"@juggle/resize-observer": "^3.4.0",
|
|
104
104
|
"@sanity/color": "^3.0.6",
|
|
105
105
|
"@sanity/icons": "^3.7.0",
|
|
106
|
-
"@vanilla-extract/css": "^1.17.
|
|
107
|
-
"@vanilla-extract/dynamic": "^2.1.
|
|
106
|
+
"@vanilla-extract/css": "^1.17.4",
|
|
107
|
+
"@vanilla-extract/dynamic": "^2.1.5",
|
|
108
108
|
"csstype": "^3.1.3",
|
|
109
|
-
"framer-motion": "^12.
|
|
109
|
+
"framer-motion": "^12.18.1",
|
|
110
110
|
"gzip-size": "^7.0.0",
|
|
111
111
|
"react-compiler-runtime": "19.1.0-rc.2",
|
|
112
112
|
"react-refractor": "^2.2.0",
|
|
113
113
|
"use-effect-event": "^1.0.2"
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
116
|
-
"@babel/core": "^7.27.
|
|
117
|
-
"@babel/preset-env": "^7.27.
|
|
116
|
+
"@babel/core": "^7.27.4",
|
|
117
|
+
"@babel/preset-env": "^7.27.2",
|
|
118
118
|
"@babel/preset-react": "^7.27.1",
|
|
119
119
|
"@babel/preset-typescript": "^7.27.1",
|
|
120
120
|
"@commitlint/cli": "19.5.0",
|
|
121
121
|
"@commitlint/config-conventional": "19.5.0",
|
|
122
|
-
"@eslint/js": "^9.
|
|
122
|
+
"@eslint/js": "^9.29.0",
|
|
123
123
|
"@sanity/browserslist-config": "^1.0.5",
|
|
124
|
-
"@sanity/pkg-utils": "^7.2.
|
|
125
|
-
"@sanity/prettier-config": "^1.0.
|
|
124
|
+
"@sanity/pkg-utils": "^7.2.6",
|
|
125
|
+
"@sanity/prettier-config": "^1.0.4",
|
|
126
126
|
"@sanity/semantic-release-preset": "^5.0.0",
|
|
127
127
|
"@sanity/ui-workshop": "^3.0.0",
|
|
128
128
|
"@testing-library/dom": "^10.4.0",
|
|
129
129
|
"@testing-library/jest-dom": "^6.6.3",
|
|
130
130
|
"@testing-library/react": "^16.3.0",
|
|
131
131
|
"@testing-library/user-event": "^14.6.1",
|
|
132
|
-
"@types/node": "^
|
|
133
|
-
"@types/react": "^19.1.
|
|
134
|
-
"@types/react-dom": "^19.1.
|
|
132
|
+
"@types/node": "^24.0.3",
|
|
133
|
+
"@types/react": "^19.1.8",
|
|
134
|
+
"@types/react-dom": "^19.1.6",
|
|
135
135
|
"@types/react-is": "^19.0.0",
|
|
136
136
|
"@types/refractor": "^3.4.1",
|
|
137
|
-
"@vanilla-extract/rollup-plugin": "^1.3.
|
|
138
|
-
"@vanilla-extract/vite-plugin": "^5.0.
|
|
139
|
-
"@vitejs/plugin-react": "^4.
|
|
140
|
-
"@vitest/browser": "^3.
|
|
137
|
+
"@vanilla-extract/rollup-plugin": "^1.3.17",
|
|
138
|
+
"@vanilla-extract/vite-plugin": "^5.0.6",
|
|
139
|
+
"@vitejs/plugin-react": "^4.5.2",
|
|
140
|
+
"@vitest/browser": "^3.2.3",
|
|
141
141
|
"autoprefixer": "^10.4.21",
|
|
142
142
|
"babel-plugin-react-compiler": "19.1.0-rc.2",
|
|
143
143
|
"cac": "^6.7.14",
|
|
@@ -147,8 +147,8 @@
|
|
|
147
147
|
"cypress-real-events": "^1.14.0",
|
|
148
148
|
"cz-conventional-changelog": "^3.3.0",
|
|
149
149
|
"dotenv-flow": "^4.1.0",
|
|
150
|
-
"eslint": "^9.
|
|
151
|
-
"eslint-config-prettier": "^10.1.
|
|
150
|
+
"eslint": "^9.29.0",
|
|
151
|
+
"eslint-config-prettier": "^10.1.5",
|
|
152
152
|
"eslint-formatter-compact": "^8.40.0",
|
|
153
153
|
"eslint-plugin-boundaries": "^5.0.1",
|
|
154
154
|
"eslint-plugin-import": "^2.31.0",
|
|
@@ -157,15 +157,15 @@
|
|
|
157
157
|
"eslint-plugin-react-hooks": "0.0.0-experimental-4448b187-20250515",
|
|
158
158
|
"eslint-plugin-react-refresh": "^0.4.20",
|
|
159
159
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
160
|
-
"eslint-plugin-storybook": "^9.0.
|
|
161
|
-
"globals": "^16.
|
|
160
|
+
"eslint-plugin-storybook": "^9.0.11",
|
|
161
|
+
"globals": "^16.2.0",
|
|
162
162
|
"husky": "^8.0.3",
|
|
163
163
|
"lightningcss": "^1.30.1",
|
|
164
164
|
"lint-staged": "^14.0.1",
|
|
165
165
|
"mkdirp": "^3.0.1",
|
|
166
166
|
"npm-run-all2": "^8.0.4",
|
|
167
|
-
"postcss": "^8.5.
|
|
168
|
-
"postcss-preset-env": "^10.2.
|
|
167
|
+
"postcss": "^8.5.6",
|
|
168
|
+
"postcss-preset-env": "^10.2.3",
|
|
169
169
|
"prettier": "^3.5.3",
|
|
170
170
|
"prettier-plugin-packagejson": "^2.5.15",
|
|
171
171
|
"react": "^19.1.0",
|
|
@@ -178,10 +178,10 @@
|
|
|
178
178
|
"styled-components": "^6.1.17",
|
|
179
179
|
"tsconfig-paths": "^4.2.0",
|
|
180
180
|
"typescript": "5.8.3",
|
|
181
|
-
"typescript-eslint": "^8.
|
|
181
|
+
"typescript-eslint": "^8.34.1",
|
|
182
182
|
"vite": "^6.3.5",
|
|
183
183
|
"vite-tsconfig-paths": "^5.1.4",
|
|
184
|
-
"vitest": "^3.2.
|
|
184
|
+
"vitest": "^3.2.3",
|
|
185
185
|
"vitest-axe": "1.0.0-pre.5"
|
|
186
186
|
},
|
|
187
187
|
"peerDependencies": {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {box, root, type RootStyleProps} from '@sanity/ui/css'
|
|
2
2
|
import {useCallback, useImperativeHandle, useRef, useState} from 'react'
|
|
3
3
|
|
|
4
|
-
import type
|
|
5
|
-
import {Box, type BoxOwnProps} from '../box/box'
|
|
4
|
+
import {Box, type BoxOwnProps} from './primitives/box/box'
|
|
6
5
|
import {RootProvider} from './RootProvider'
|
|
6
|
+
import type {Props} from './types/props'
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
9
|
export const DEFAULT_ROOT_ELEMENT = 'html'
|
|
@@ -27,7 +27,8 @@ export function Root<E extends RootElementType = typeof DEFAULT_ROOT_ELEMENT>(pr
|
|
|
27
27
|
as: as = DEFAULT_ROOT_ELEMENT,
|
|
28
28
|
children,
|
|
29
29
|
className,
|
|
30
|
-
height = 'fill',
|
|
30
|
+
height, // = 'fill',
|
|
31
|
+
overflow = 'hidden',
|
|
31
32
|
ref: forwardedRef,
|
|
32
33
|
scheme = 'light',
|
|
33
34
|
tone = 'transparent',
|
|
@@ -76,6 +77,7 @@ export function Root<E extends RootElementType = typeof DEFAULT_ROOT_ELEMENT>(pr
|
|
|
76
77
|
scheme,
|
|
77
78
|
tone,
|
|
78
79
|
})}
|
|
80
|
+
overflow={overflow}
|
|
79
81
|
ref={handleRef}
|
|
80
82
|
>
|
|
81
83
|
{node}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type {ThemeColorCardToneKey, ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
2
2
|
import type {ReactNode} from 'react'
|
|
3
3
|
|
|
4
|
-
import {ToastProvider} from '
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import {ToastProvider} from './components/toast/toastProvider'
|
|
5
|
+
import {CardProvider} from './primitives/card/cardProvider'
|
|
6
|
+
import {LayerProvider} from './primitives/layer/layerProvider'
|
|
7
|
+
import {BoundaryElementProvider} from './utils/boundaryElement/boundaryElementProvider'
|
|
8
|
+
import {PortalProvider} from './utils/portal/portalProvider'
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
11
|
export interface RootProviderProps {
|
package/src/core/__DEV__.ts
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {Box, Button, Root, Stack, Text, useCard, useToast} from '@sanity/ui'
|
|
2
|
+
|
|
3
|
+
export default function BoundaryStory() {
|
|
4
|
+
const {scheme} = useCard()
|
|
5
|
+
|
|
6
|
+
return (
|
|
7
|
+
<Box padding={5}>
|
|
8
|
+
<Root as="div" padding={5} radius={4} scheme={scheme}>
|
|
9
|
+
<Layout />
|
|
10
|
+
</Root>
|
|
11
|
+
</Box>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function Layout() {
|
|
16
|
+
const toast = useToast()
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Stack gap={4}>
|
|
20
|
+
<Text size={1}>
|
|
21
|
+
Testing the root component. Toast messages will be rendered here, and should be contained
|
|
22
|
+
within the root element.
|
|
23
|
+
</Text>
|
|
24
|
+
|
|
25
|
+
<Button onClick={() => toast.push({title: 'Hello!'})} text="Push toast message" width="min" />
|
|
26
|
+
</Stack>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {defineScope} from '@sanity/ui-workshop'
|
|
2
|
+
import {lazy} from 'react'
|
|
3
|
+
|
|
4
|
+
export default defineScope({
|
|
5
|
+
name: 'root',
|
|
6
|
+
title: 'Root',
|
|
7
|
+
stories: [
|
|
8
|
+
{
|
|
9
|
+
name: 'boundary',
|
|
10
|
+
title: 'Boundary',
|
|
11
|
+
component: lazy(() => import('./boundary')),
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
})
|
|
@@ -55,10 +55,11 @@ describe('theme', () => {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function Root() {
|
|
58
|
-
const value = undefined
|
|
59
|
-
|
|
60
58
|
return (
|
|
61
|
-
<ThemeContext.Provider
|
|
59
|
+
<ThemeContext.Provider
|
|
60
|
+
// @ts-expect-error - we want to test the error case
|
|
61
|
+
value={undefined}
|
|
62
|
+
>
|
|
62
63
|
<Debug />
|
|
63
64
|
</ThemeContext.Provider>
|
|
64
65
|
)
|
|
@@ -96,6 +96,8 @@ export function DialogCard<E extends DialogCardElementType = typeof DEFAULT_DIAL
|
|
|
96
96
|
const showCloseButton = Boolean(onClose) && hideCloseButton === false
|
|
97
97
|
const showHeader = Boolean(header) || showCloseButton
|
|
98
98
|
const [scrollTop, setScrollTop] = useState(0)
|
|
99
|
+
const [scrollHeight, setScrollHeight] = useState(0)
|
|
100
|
+
const scrollBottom = scrollHeight - scrollTop
|
|
99
101
|
|
|
100
102
|
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
101
103
|
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(
|
|
@@ -156,8 +158,8 @@ export function DialogCard<E extends DialogCardElementType = typeof DEFAULT_DIAL
|
|
|
156
158
|
if (!el) return
|
|
157
159
|
|
|
158
160
|
const handleScroll = () => {
|
|
159
|
-
// console.log('scroll', el.scrollTop)
|
|
160
161
|
setScrollTop(el.scrollTop)
|
|
162
|
+
setScrollHeight(el.scrollHeight - el.offsetHeight)
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
el.addEventListener('scroll', handleScroll, {passive: true})
|
|
@@ -213,7 +215,12 @@ export function DialogCard<E extends DialogCardElementType = typeof DEFAULT_DIAL
|
|
|
213
215
|
{children}
|
|
214
216
|
</Box>
|
|
215
217
|
|
|
216
|
-
{footer &&
|
|
218
|
+
{footer && (
|
|
219
|
+
<div
|
|
220
|
+
className={dialogScrollerShadowBottom()}
|
|
221
|
+
style={{opacity: Math.min(scrollBottom, 32) / 32}}
|
|
222
|
+
/>
|
|
223
|
+
)}
|
|
217
224
|
</Box>
|
|
218
225
|
|
|
219
226
|
{footer && (
|
|
@@ -79,10 +79,11 @@ describe('components/menu', () => {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function Root() {
|
|
82
|
-
const value: any = undefined
|
|
83
|
-
|
|
84
82
|
return (
|
|
85
|
-
<MenuContext.Provider
|
|
83
|
+
<MenuContext.Provider
|
|
84
|
+
// @ts-expect-error - we want to test the error case
|
|
85
|
+
value={undefined}
|
|
86
|
+
>
|
|
86
87
|
<Debug />
|
|
87
88
|
</MenuContext.Provider>
|
|
88
89
|
)
|
|
@@ -108,12 +109,12 @@ describe('components/menu', () => {
|
|
|
108
109
|
|
|
109
110
|
function Root() {
|
|
110
111
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
111
|
-
const value: any = () => {
|
|
112
|
-
return {version: 1}
|
|
113
|
-
}
|
|
114
112
|
|
|
115
113
|
return (
|
|
116
|
-
<MenuContext.Provider
|
|
114
|
+
<MenuContext.Provider
|
|
115
|
+
// @ts-expect-error - we want to test the error case
|
|
116
|
+
value={() => ({version: 1})}
|
|
117
|
+
>
|
|
117
118
|
<Debug />
|
|
118
119
|
</MenuContext.Provider>
|
|
119
120
|
)
|
|
@@ -51,10 +51,11 @@ describe('components/toast', () => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
function Root() {
|
|
54
|
-
const value = undefined
|
|
55
|
-
|
|
56
54
|
return (
|
|
57
|
-
<ToastContext.Provider
|
|
55
|
+
<ToastContext.Provider
|
|
56
|
+
// @ts-expect-error - we want to test the error case
|
|
57
|
+
value={undefined}
|
|
58
|
+
>
|
|
58
59
|
<Debug />
|
|
59
60
|
</ToastContext.Provider>
|
|
60
61
|
)
|
|
@@ -80,12 +81,12 @@ describe('components/toast', () => {
|
|
|
80
81
|
|
|
81
82
|
function Root() {
|
|
82
83
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
83
|
-
const value = () => {
|
|
84
|
-
return {version: 1}
|
|
85
|
-
}
|
|
86
84
|
|
|
87
85
|
return (
|
|
88
|
-
<ToastContext.Provider
|
|
86
|
+
<ToastContext.Provider
|
|
87
|
+
// @ts-expect-error - we want to test the error case
|
|
88
|
+
value={() => ({version: 1})}
|
|
89
|
+
>
|
|
89
90
|
<Debug />
|
|
90
91
|
</ToastContext.Provider>
|
|
91
92
|
)
|
package/src/core/index.ts
CHANGED
|
@@ -96,8 +96,6 @@ export * from './primitives/layer/useLayer'
|
|
|
96
96
|
export * from './primitives/popover/popover'
|
|
97
97
|
export * from './primitives/popover/types'
|
|
98
98
|
export * from './primitives/radio/radio'
|
|
99
|
-
export * from './primitives/root/Root'
|
|
100
|
-
export * from './primitives/root/RootProvider'
|
|
101
99
|
export * from './primitives/select/select'
|
|
102
100
|
export * from './primitives/selectable/selectable'
|
|
103
101
|
export * from './primitives/selectable/types'
|
|
@@ -128,6 +126,10 @@ export * from './utils/portal/portalProvider'
|
|
|
128
126
|
export * from './utils/portal/types'
|
|
129
127
|
export * from './utils/portal/usePortal'
|
|
130
128
|
|
|
129
|
+
// root
|
|
130
|
+
export * from './Root'
|
|
131
|
+
export * from './RootProvider'
|
|
132
|
+
|
|
131
133
|
// types
|
|
132
134
|
export * from './types/gridItem'
|
|
133
135
|
export * from './types/placement'
|
|
@@ -28,7 +28,10 @@ export function createGlobalScopedContext<ContextType, const T extends ContextTy
|
|
|
28
28
|
return createContext<ContextType>(defaultValue)
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// Use the global scope as a map of symbols to contexts
|
|
32
|
+
const symbolMap = globalScope as Record<symbol, Context<ContextType>>
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
symbolMap[symbol] = symbolMap[symbol] || createContext<T>(defaultValue)
|
|
35
|
+
|
|
36
|
+
return symbolMap[symbol]
|
|
34
37
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {card, type CardStyleProps} from '@sanity/ui/css'
|
|
2
|
+
import {useContext} from 'react'
|
|
2
3
|
|
|
3
4
|
import type {Props} from '../../types/props'
|
|
4
5
|
import {Box, type BoxElementType, type BoxOwnProps} from '../box/box'
|
|
6
|
+
import {CardContext} from './cardContext'
|
|
5
7
|
import {CardProvider} from './cardProvider'
|
|
6
|
-
import {useCard} from './useCard'
|
|
7
8
|
|
|
8
9
|
/** @public */
|
|
9
10
|
export const DEFAULT_CARD_ELEMENT = 'div'
|
|
@@ -54,7 +55,7 @@ export function Card<E extends CardElementType = typeof DEFAULT_CARD_ELEMENT>(pr
|
|
|
54
55
|
...rest
|
|
55
56
|
} = props as CardProps<typeof DEFAULT_CARD_ELEMENT>
|
|
56
57
|
|
|
57
|
-
const parent =
|
|
58
|
+
const parent = useContext(CardContext)
|
|
58
59
|
const tone = toneProp === 'inherit' ? parent?.tone : toneProp
|
|
59
60
|
const scheme = schemeProp === undefined ? parent?.scheme : schemeProp
|
|
60
61
|
|
|
@@ -96,7 +97,7 @@ export function Card<E extends CardElementType = typeof DEFAULT_CARD_ELEMENT>(pr
|
|
|
96
97
|
const CompatProvider = parent.unstable_CompatProvider
|
|
97
98
|
|
|
98
99
|
return (
|
|
99
|
-
<CompatProvider scheme={scheme ?? 'light'} tone={tone ?? parent
|
|
100
|
+
<CompatProvider scheme={scheme ?? 'light'} tone={tone ?? parent.tone}>
|
|
100
101
|
{node}
|
|
101
102
|
</CompatProvider>
|
|
102
103
|
)
|
|
@@ -4,6 +4,12 @@ import {CardContext} from './cardContext'
|
|
|
4
4
|
import type {CardContextValue} from './types'
|
|
5
5
|
|
|
6
6
|
/** @public */
|
|
7
|
-
export function useCard(): CardContextValue
|
|
8
|
-
|
|
7
|
+
export function useCard(): CardContextValue {
|
|
8
|
+
const card = useContext(CardContext)
|
|
9
|
+
|
|
10
|
+
if (!card) {
|
|
11
|
+
throw new Error('useCard(): missing context value')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return card
|
|
9
15
|
}
|
|
@@ -7,7 +7,7 @@ export default function LazyRefractor(
|
|
|
7
7
|
) {
|
|
8
8
|
const {language: languageProp, value} = props
|
|
9
9
|
const language = typeof languageProp === 'string' ? languageProp : undefined
|
|
10
|
-
const registered = language ? Refractor.hasLanguage(language
|
|
10
|
+
const registered = language ? Refractor.hasLanguage(language) : false
|
|
11
11
|
|
|
12
12
|
return (
|
|
13
13
|
<>
|
|
@@ -58,10 +58,11 @@ describe('primitives/layer', () => {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function Root() {
|
|
61
|
-
const value = undefined
|
|
62
|
-
|
|
63
61
|
return (
|
|
64
|
-
<LayerContext.Provider
|
|
62
|
+
<LayerContext.Provider
|
|
63
|
+
// @ts-expect-error - we want to test the error case
|
|
64
|
+
value={undefined}
|
|
65
|
+
>
|
|
65
66
|
<Debug />
|
|
66
67
|
</LayerContext.Provider>
|
|
67
68
|
)
|
|
@@ -87,12 +88,12 @@ describe('primitives/layer', () => {
|
|
|
87
88
|
|
|
88
89
|
function Root() {
|
|
89
90
|
// NOTE: we’re testing this because the context value may be a function in the future
|
|
90
|
-
const value = () => {
|
|
91
|
-
return {version: 1}
|
|
92
|
-
}
|
|
93
91
|
|
|
94
92
|
return (
|
|
95
|
-
<LayerContext.Provider
|
|
93
|
+
<LayerContext.Provider
|
|
94
|
+
// @ts-expect-error - we want to test the error case
|
|
95
|
+
value={() => ({version: 1})}
|
|
96
|
+
>
|
|
96
97
|
<Debug />
|
|
97
98
|
</LayerContext.Provider>
|
|
98
99
|
)
|
|
@@ -31,6 +31,7 @@ import {origin} from '../../middleware/origin'
|
|
|
31
31
|
import type {Placement} from '../../types/placement'
|
|
32
32
|
import type {ComponentType, Props} from '../../types/props'
|
|
33
33
|
import {useBoundaryElement} from '../../utils/boundaryElement/useBoundaryElement'
|
|
34
|
+
import {getElementRef} from '../../utils/getElementRef'
|
|
34
35
|
import {Portal} from '../../utils/portal/portal'
|
|
35
36
|
import {CardProvider} from '../card/cardProvider'
|
|
36
37
|
import {useCard} from '../card/useCard'
|
|
@@ -327,7 +328,9 @@ export function Popover<E extends PopoverElementType = typeof DEFAULT_POPOVER_EL
|
|
|
327
328
|
(node: HTMLElement | null) => {
|
|
328
329
|
refs.setReference(node)
|
|
329
330
|
|
|
330
|
-
|
|
331
|
+
if (!childProp) return
|
|
332
|
+
|
|
333
|
+
const childRef = getElementRef(childProp)
|
|
331
334
|
|
|
332
335
|
if (typeof childRef === 'function') {
|
|
333
336
|
childRef(node)
|
|
@@ -402,10 +405,7 @@ export function Popover<E extends PopoverElementType = typeof DEFAULT_POPOVER_EL
|
|
|
402
405
|
open &&
|
|
403
406
|
(portal ? (
|
|
404
407
|
<Portal __unstable_name={typeof portal === 'string' ? portal : undefined}>
|
|
405
|
-
<CardProvider
|
|
406
|
-
tone={tone === 'inherit' ? (card?.tone ?? 'default') : tone}
|
|
407
|
-
scheme={scheme ?? 'light'}
|
|
408
|
-
>
|
|
408
|
+
<CardProvider tone={tone === 'inherit' ? card.tone : tone} scheme={scheme ?? 'light'}>
|
|
409
409
|
{node}
|
|
410
410
|
</CardProvider>
|
|
411
411
|
</Portal>
|
|
@@ -423,31 +423,3 @@ export function Popover<E extends PopoverElementType = typeof DEFAULT_POPOVER_EL
|
|
|
423
423
|
</>
|
|
424
424
|
)
|
|
425
425
|
}
|
|
426
|
-
|
|
427
|
-
// Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`
|
|
428
|
-
// After React 19 accessing `element.ref` does the opposite.
|
|
429
|
-
// https://github.com/facebook/react/pull/28348
|
|
430
|
-
//
|
|
431
|
-
// Access the ref using the method that doesn't yield a warning.
|
|
432
|
-
function getElementRef(
|
|
433
|
-
element: ReactElement<{ref: ForwardedRef<HTMLElement>}>,
|
|
434
|
-
): ForwardedRef<HTMLElement> {
|
|
435
|
-
// React <=18 in DEV
|
|
436
|
-
let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get
|
|
437
|
-
let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning
|
|
438
|
-
|
|
439
|
-
if (mayWarn) {
|
|
440
|
-
return (element as any).ref
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// React 19 in DEV
|
|
444
|
-
getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get
|
|
445
|
-
mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning
|
|
446
|
-
|
|
447
|
-
if (mayWarn) {
|
|
448
|
-
return element.props.ref
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
// Not DEV
|
|
452
|
-
return element.props.ref || (element as any).ref
|
|
453
|
-
}
|
|
@@ -419,10 +419,7 @@ export function Tooltip<E extends TooltipElementType = typeof DEFAULT_TOOLTIP_EL
|
|
|
419
419
|
showTooltip &&
|
|
420
420
|
(portalProp ? (
|
|
421
421
|
<Portal __unstable_name={typeof portalProp === 'string' ? portalProp : undefined}>
|
|
422
|
-
<CardProvider
|
|
423
|
-
tone={tone === 'inherit' ? (card?.tone ?? 'default') : tone}
|
|
424
|
-
scheme={scheme ?? 'light'}
|
|
425
|
-
>
|
|
422
|
+
<CardProvider tone={tone === 'inherit' ? card.tone : tone} scheme={scheme ?? 'light'}>
|
|
426
423
|
{node}
|
|
427
424
|
</CardProvider>
|
|
428
425
|
</Portal>
|