@sanity/ui 3.0.0-static.17 → 3.0.0-static.18
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 +2 -2
- package/dist/_chunks-cjs/_visual-editing.cjs.map +1 -1
- package/dist/_chunks-es/_visual-editing.js +3 -3
- package/dist/_chunks-es/_visual-editing.js.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/css.cjs +1 -0
- package/dist/css.cjs.map +1 -1
- package/dist/css.d.cts +7 -3
- package/dist/css.d.ts +7 -3
- package/dist/css.js +1 -0
- package/dist/css.js.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/package.json +1 -1
- package/src/core/hooks/useMediaIndex/useMediaIndex.test.tsx +2 -18
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +9 -9
- package/src/css/constants.ts +1 -0
- package/src/css/types.ts +23 -18
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,7 @@ import {BoxHeight} from '@sanity/ui/css'
|
|
|
5
5
|
import {BoxOverflow} from '@sanity/ui/css'
|
|
6
6
|
import {BoxSizing} from '@sanity/ui/css'
|
|
7
7
|
import type {BoxStyleProps} from '@sanity/ui/css'
|
|
8
|
+
import {Breakpoint} from '@sanity/ui/css'
|
|
8
9
|
import type {ButtonStyleProps} from '@sanity/ui/css'
|
|
9
10
|
import {CardContextValue as CardContextValue_2} from './types'
|
|
10
11
|
import {CardStyleProps as CardStyleProps_2} from '@sanity/ui/css'
|
|
@@ -1666,7 +1667,7 @@ export declare interface LayerProviderProps {
|
|
|
1666
1667
|
*/
|
|
1667
1668
|
export declare interface _MediaStore {
|
|
1668
1669
|
subscribe: (onStoreChange: () => void) => () => void
|
|
1669
|
-
getSnapshot: () =>
|
|
1670
|
+
getSnapshot: () => Breakpoint
|
|
1670
1671
|
}
|
|
1671
1672
|
|
|
1672
1673
|
/**
|
|
@@ -3264,7 +3265,7 @@ export declare function useMatchMedia(
|
|
|
3264
3265
|
* This API might change. DO NOT USE IN PRODUCTION.
|
|
3265
3266
|
* @beta
|
|
3266
3267
|
*/
|
|
3267
|
-
export declare function useMediaIndex():
|
|
3268
|
+
export declare function useMediaIndex(): Breakpoint
|
|
3268
3269
|
|
|
3269
3270
|
/** @public */
|
|
3270
3271
|
export declare function usePortal(): PortalContextValue
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {BoxHeight} from '@sanity/ui/css'
|
|
|
5
5
|
import {BoxOverflow} from '@sanity/ui/css'
|
|
6
6
|
import {BoxSizing} from '@sanity/ui/css'
|
|
7
7
|
import type {BoxStyleProps} from '@sanity/ui/css'
|
|
8
|
+
import {Breakpoint} from '@sanity/ui/css'
|
|
8
9
|
import type {ButtonStyleProps} from '@sanity/ui/css'
|
|
9
10
|
import {CardContextValue as CardContextValue_2} from './types'
|
|
10
11
|
import {CardStyleProps as CardStyleProps_2} from '@sanity/ui/css'
|
|
@@ -1666,7 +1667,7 @@ export declare interface LayerProviderProps {
|
|
|
1666
1667
|
*/
|
|
1667
1668
|
export declare interface _MediaStore {
|
|
1668
1669
|
subscribe: (onStoreChange: () => void) => () => void
|
|
1669
|
-
getSnapshot: () =>
|
|
1670
|
+
getSnapshot: () => Breakpoint
|
|
1670
1671
|
}
|
|
1671
1672
|
|
|
1672
1673
|
/**
|
|
@@ -3264,7 +3265,7 @@ export declare function useMatchMedia(
|
|
|
3264
3265
|
* This API might change. DO NOT USE IN PRODUCTION.
|
|
3265
3266
|
* @beta
|
|
3266
3267
|
*/
|
|
3267
|
-
export declare function useMediaIndex():
|
|
3268
|
+
export declare function useMediaIndex(): Breakpoint
|
|
3268
3269
|
|
|
3269
3270
|
/** @public */
|
|
3270
3271
|
export declare function usePortal(): PortalContextValue
|
package/package.json
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/** @jest-environment node */
|
|
2
2
|
|
|
3
|
-
import {buildTheme} from '@sanity/ui/theme'
|
|
4
3
|
import {renderToStaticMarkup, renderToString} from 'react-dom/server'
|
|
5
4
|
|
|
6
|
-
import {ThemeProvider} from '../../_compat'
|
|
7
5
|
import {useMediaIndex} from './useMediaIndex'
|
|
8
6
|
|
|
9
|
-
const theme = buildTheme()
|
|
10
|
-
|
|
11
7
|
function Log() {
|
|
12
8
|
const mediaIndex = useMediaIndex()
|
|
13
9
|
|
|
@@ -16,21 +12,9 @@ function Log() {
|
|
|
16
12
|
|
|
17
13
|
describe('useMediaIndex', () => {
|
|
18
14
|
it(`SSR to static markup returns 0`, () => {
|
|
19
|
-
expect(
|
|
20
|
-
renderToStaticMarkup(
|
|
21
|
-
<ThemeProvider theme={theme}>
|
|
22
|
-
<Log />
|
|
23
|
-
</ThemeProvider>,
|
|
24
|
-
),
|
|
25
|
-
).toBe('mediaIndex: 0')
|
|
15
|
+
expect(renderToStaticMarkup(<Log />)).toBe('mediaIndex: 0')
|
|
26
16
|
})
|
|
27
17
|
it(`SSR to markup for hydration doesn't throw`, () => {
|
|
28
|
-
expect(
|
|
29
|
-
renderToString(
|
|
30
|
-
<ThemeProvider theme={theme}>
|
|
31
|
-
<Log />
|
|
32
|
-
</ThemeProvider>,
|
|
33
|
-
),
|
|
34
|
-
).toMatchInlineSnapshot(`"mediaIndex: <!-- -->0"`)
|
|
18
|
+
expect(renderToString(<Log />)).toMatchInlineSnapshot(`"mediaIndex: <!-- -->0"`)
|
|
35
19
|
})
|
|
36
20
|
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import {Breakpoint, BREAKPOINTS} from '@sanity/ui/css'
|
|
1
2
|
import {useMemo, useSyncExternalStore} from 'react'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const media = [360, 600, 900, 1200, 1800, 2400]
|
|
4
|
+
const media = Object.values(BREAKPOINTS)
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export interface _MediaStore {
|
|
10
10
|
subscribe: (onStoreChange: () => void) => () => void
|
|
11
|
-
getSnapshot: () =>
|
|
11
|
+
getSnapshot: () => Breakpoint
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
type MediaQueryMinWidth = `(min-width: ${number}px)`
|
|
@@ -18,14 +18,14 @@ type MediaQuery = `screen and ${MediaQueryMinWidth | MediaQueryMaxWidth | MediaQ
|
|
|
18
18
|
|
|
19
19
|
function _getMediaQuery(media: number[], index: number): MediaQuery {
|
|
20
20
|
if (index === 0) {
|
|
21
|
-
return `screen and (max-width: ${media[index] - 1}px)`
|
|
21
|
+
return `screen and (max-width: ${media[index + 1] - 1}px)`
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (index === media.length) {
|
|
25
|
-
return `screen and (min-width: ${media[index
|
|
25
|
+
return `screen and (min-width: ${media[index]}px)`
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
return `screen and (min-width: ${media[index
|
|
28
|
+
return `screen and (min-width: ${media[index]}px) and (max-width: ${media[index + 1] - 1}px)`
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
function _createMediaStore(): _MediaStore {
|
|
@@ -51,7 +51,7 @@ function _createMediaStore(): _MediaStore {
|
|
|
51
51
|
|
|
52
52
|
const getSnapshot = () => {
|
|
53
53
|
for (const {index, mq} of getSizes()) {
|
|
54
|
-
if (mq.matches) return index
|
|
54
|
+
if (mq.matches) return index as Breakpoint
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
return 0
|
|
@@ -87,7 +87,7 @@ function _createMediaStore(): _MediaStore {
|
|
|
87
87
|
*
|
|
88
88
|
* @link https://beta.reactjs.org/apis/react/useSyncExternalStore#adding-support-for-server-rendering
|
|
89
89
|
*/
|
|
90
|
-
function getServerSnapshot() {
|
|
90
|
+
function getServerSnapshot(): Breakpoint {
|
|
91
91
|
return 0
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -95,7 +95,7 @@ function getServerSnapshot() {
|
|
|
95
95
|
* This API might change. DO NOT USE IN PRODUCTION.
|
|
96
96
|
* @beta
|
|
97
97
|
*/
|
|
98
|
-
export function useMediaIndex():
|
|
98
|
+
export function useMediaIndex(): Breakpoint {
|
|
99
99
|
const store = useMemo(() => _createMediaStore(), [])
|
|
100
100
|
|
|
101
101
|
return useSyncExternalStore(store.subscribe, store.getSnapshot, getServerSnapshot)
|
package/src/css/constants.ts
CHANGED
package/src/css/types.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
import {ColorTintKey} from '@sanity/color'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import type {ColorTintKey} from '@sanity/color'
|
|
2
|
+
import type {
|
|
3
|
+
AvatarSize,
|
|
4
|
+
ContainerWidth,
|
|
5
|
+
FontCodeSize,
|
|
6
|
+
FontHeadingSize,
|
|
7
|
+
FontLabelSize,
|
|
8
|
+
FontTextSize,
|
|
9
|
+
FontWeight,
|
|
10
|
+
Hue,
|
|
11
|
+
Radius,
|
|
12
|
+
Shadow,
|
|
13
|
+
Space,
|
|
14
|
+
ThemeColorAvatarColorKey as AvatarColor,
|
|
15
|
+
ThemeColorCardToneKey as CardTone,
|
|
16
|
+
ThemeColorSchemeKey as Scheme,
|
|
17
|
+
ThemeColorStateToneKey as ElementTone,
|
|
18
|
+
Tint,
|
|
19
19
|
} from '@sanity/ui/theme'
|
|
20
20
|
import CSS from 'csstype'
|
|
21
21
|
|
|
22
|
+
import type {BREAKPOINTS} from './constants'
|
|
23
|
+
|
|
24
|
+
/** @public */
|
|
25
|
+
export type Breakpoint = keyof typeof BREAKPOINTS
|
|
26
|
+
|
|
22
27
|
/** @public */
|
|
23
28
|
export type ResponsiveProp<T> = T | Array<T | null | undefined>
|
|
24
29
|
|