@sanity/ui 0.37.21 → 0.38.0
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/lib/dts/src/components/breadcrumbs/breadcrumbs.d.ts.map +1 -1
- package/lib/dts/src/components/dialog/dialog.d.ts.map +1 -1
- package/lib/dts/src/components/dialog/styles.d.ts +1 -1
- package/lib/dts/src/components/dialog/styles.d.ts.map +1 -1
- package/lib/dts/src/components/hotkeys/hotkeys.d.ts.map +1 -1
- package/lib/dts/src/components/menu/menuGroup.d.ts.map +1 -1
- package/lib/dts/src/components/skeleton/skeleton.d.ts.map +1 -1
- package/lib/dts/src/hooks/index.d.ts +2 -1
- package/lib/dts/src/hooks/index.d.ts.map +1 -1
- package/lib/dts/src/hooks/useArrayProp.d.ts +7 -0
- package/lib/dts/src/hooks/useArrayProp.d.ts.map +1 -0
- package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts +1 -1
- package/lib/dts/src/hooks/useElementRect/useElementRect.d.ts.map +1 -1
- package/lib/dts/src/hooks/useElementSize.d.ts +7 -0
- package/lib/dts/src/hooks/useElementSize.d.ts.map +1 -0
- package/lib/dts/src/index.d.ts +1 -0
- package/lib/dts/src/index.d.ts.map +1 -1
- package/lib/dts/src/observers/elementSizeObserver.d.ts +37 -0
- package/lib/dts/src/observers/elementSizeObserver.d.ts.map +1 -0
- package/lib/dts/src/observers/index.d.ts +3 -0
- package/lib/dts/src/observers/index.d.ts.map +1 -0
- package/lib/dts/src/observers/resizeObserver.d.ts +5 -0
- package/lib/dts/src/observers/resizeObserver.d.ts.map +1 -0
- package/lib/dts/src/primitives/_selectable/selectable.d.ts +1 -2
- package/lib/dts/src/primitives/_selectable/selectable.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/avatar.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/avatarCounter.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/avatarStack.d.ts.map +1 -1
- package/lib/dts/src/primitives/avatar/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/badge/badge.d.ts.map +1 -1
- package/lib/dts/src/primitives/box/box.d.ts.map +1 -1
- package/lib/dts/src/primitives/button/button.d.ts.map +1 -1
- package/lib/dts/src/primitives/card/card.d.ts.map +1 -1
- package/lib/dts/src/primitives/code/code.d.ts.map +1 -1
- package/lib/dts/src/primitives/container/container.d.ts.map +1 -1
- package/lib/dts/src/primitives/container/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/container/types.d.ts +1 -1
- package/lib/dts/src/primitives/container/types.d.ts.map +1 -1
- package/lib/dts/src/primitives/flex/flex.d.ts.map +1 -1
- package/lib/dts/src/primitives/grid/grid.d.ts.map +1 -1
- package/lib/dts/src/primitives/heading/heading.d.ts.map +1 -1
- package/lib/dts/src/primitives/inline/inline.d.ts.map +1 -1
- package/lib/dts/src/primitives/inline/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/inline/types.d.ts +1 -1
- package/lib/dts/src/primitives/inline/types.d.ts.map +1 -1
- package/lib/dts/src/primitives/kbd/kbd.d.ts.map +1 -1
- package/lib/dts/src/primitives/label/label.d.ts.map +1 -1
- package/lib/dts/src/primitives/popover/popover.d.ts.map +1 -1
- package/lib/dts/src/primitives/select/styles.d.ts +5 -1
- package/lib/dts/src/primitives/select/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/stack/stack.d.ts.map +1 -1
- package/lib/dts/src/primitives/stack/styles.d.ts +1 -1
- package/lib/dts/src/primitives/stack/styles.d.ts.map +1 -1
- package/lib/dts/src/primitives/text/text.d.ts.map +1 -1
- package/lib/dts/src/primitives/textArea/textArea.d.ts.map +1 -1
- package/lib/dts/src/primitives/textInput/textInput.d.ts.map +1 -1
- package/lib/dts/src/primitives/tooltip/tooltip.d.ts.map +1 -1
- package/lib/dts/src/primitives/types.d.ts +1 -1
- package/lib/dts/src/primitives/types.d.ts.map +1 -1
- package/lib/dts/src/styles/border/types.d.ts +5 -5
- package/lib/dts/src/styles/border/types.d.ts.map +1 -1
- package/lib/dts/src/styles/box/types.d.ts +4 -4
- package/lib/dts/src/styles/box/types.d.ts.map +1 -1
- package/lib/dts/src/styles/flex/flexItemStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/flex/types.d.ts +6 -6
- package/lib/dts/src/styles/flex/types.d.ts.map +1 -1
- package/lib/dts/src/styles/font/responsiveFont.d.ts.map +1 -1
- package/lib/dts/src/styles/font/types.d.ts +3 -3
- package/lib/dts/src/styles/font/types.d.ts.map +1 -1
- package/lib/dts/src/styles/grid/types.d.ts +14 -14
- package/lib/dts/src/styles/grid/types.d.ts.map +1 -1
- package/lib/dts/src/styles/helpers.d.ts +4 -4
- package/lib/dts/src/styles/helpers.d.ts.map +1 -1
- package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts +12 -12
- package/lib/dts/src/styles/input/responsiveInputPaddingStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/input/textInputStyle.d.ts +7 -2
- package/lib/dts/src/styles/input/textInputStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/margin/types.d.ts +7 -7
- package/lib/dts/src/styles/margin/types.d.ts.map +1 -1
- package/lib/dts/src/styles/padding/types.d.ts +7 -7
- package/lib/dts/src/styles/padding/types.d.ts.map +1 -1
- package/lib/dts/src/styles/radius/types.d.ts +1 -1
- package/lib/dts/src/styles/radius/types.d.ts.map +1 -1
- package/lib/dts/src/styles/shadow/shadowStyle.d.ts.map +1 -1
- package/lib/dts/src/styles/shadow/types.d.ts +1 -1
- package/lib/dts/src/styles/shadow/types.d.ts.map +1 -1
- package/lib/dts/src/theme/studioTheme/color.d.ts.map +1 -1
- package/lib/dts/src/utils/elementQuery/elementQuery.d.ts.map +1 -1
- package/lib/dts/src/utils/index.d.ts +0 -1
- package/lib/dts/src/utils/index.d.ts.map +1 -1
- package/lib/dts/src/utils/virtualList/virtualList.d.ts.map +1 -1
- package/lib/sanity-ui.js +734 -573
- package/lib/sanity-ui.js.map +1 -1
- package/lib/sanity-ui.modern.js +763 -592
- package/lib/sanity-ui.modern.js.map +1 -1
- package/lib/sanity-ui.module.js +728 -569
- package/lib/sanity-ui.module.js.map +1 -1
- package/package.json +11 -11
- package/src/__workshop__/color/overview.tsx +9 -11
- package/src/components/autocomplete/__workshop__/async.tsx +14 -12
- package/src/components/autocomplete/__workshop__/constrainedHeight.tsx +36 -0
- package/src/components/autocomplete/autocomplete.tsx +2 -2
- package/src/components/breadcrumbs/breadcrumbs.tsx +3 -2
- package/src/components/dialog/dialog.tsx +17 -9
- package/src/components/dialog/styles.ts +4 -4
- package/src/components/hotkeys/hotkeys.tsx +3 -1
- package/src/components/menu/__workshop__/constrainedInBoundary.tsx +11 -14
- package/src/components/menu/__workshop__/groups.tsx +1 -1
- package/src/components/menu/menuGroup.tsx +3 -2
- package/src/components/menu/menuItem.tsx +3 -3
- package/src/components/skeleton/skeleton.tsx +10 -1
- package/src/components/skeleton/textSkeleton.tsx +7 -7
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useArrayProp.ts +23 -0
- package/src/hooks/useElementRect/useElementRect.ts +4 -16
- package/src/hooks/useElementSize.ts +18 -0
- package/src/index.ts +1 -0
- package/src/observers/elementSizeObserver.ts +116 -0
- package/src/observers/index.ts +2 -0
- package/src/{utils → observers}/resizeObserver.ts +1 -3
- package/src/primitives/_selectable/selectable.tsx +5 -4
- package/src/primitives/avatar/avatar.tsx +7 -5
- package/src/primitives/avatar/avatarCounter.tsx +12 -11
- package/src/primitives/avatar/avatarStack.tsx +15 -10
- package/src/primitives/avatar/styles.ts +2 -2
- package/src/primitives/badge/badge.tsx +3 -2
- package/src/primitives/box/box.tsx +26 -25
- package/src/primitives/button/button.tsx +22 -10
- package/src/primitives/card/card.tsx +8 -7
- package/src/primitives/checkbox/__workshop__/example.tsx +4 -2
- package/src/primitives/checkbox/__workshop__/props.tsx +4 -2
- package/src/primitives/checkbox/__workshop__/readOnly.tsx +4 -2
- package/src/primitives/code/__workshop__/props.tsx +1 -1
- package/src/primitives/code/code.tsx +2 -1
- package/src/primitives/container/container.tsx +10 -1
- package/src/primitives/container/styles.ts +2 -2
- package/src/primitives/container/types.ts +1 -1
- package/src/primitives/flex/flex.tsx +6 -5
- package/src/primitives/grid/__workshop__/responsive.tsx +13 -12
- package/src/primitives/grid/grid.tsx +9 -8
- package/src/primitives/heading/__workshop__/opticalAlignment.tsx +19 -7
- package/src/primitives/heading/heading.tsx +3 -2
- package/src/primitives/inline/inline.tsx +12 -6
- package/src/primitives/inline/styles.ts +2 -2
- package/src/primitives/inline/types.ts +1 -1
- package/src/primitives/kbd/kbd.tsx +2 -1
- package/src/primitives/label/label.tsx +4 -3
- package/src/primitives/popover/__workshop__/{margins.tsx → MarginsStory.tsx} +1 -1
- package/src/primitives/popover/__workshop__/{matchReferenceWidth.tsx → MatchReferenceWidthStory.tsx} +0 -0
- package/src/primitives/popover/__workshop__/{plain.tsx → PlainStory.tsx} +12 -14
- package/src/primitives/popover/__workshop__/{recursive.tsx → RecursiveStory.tsx} +4 -1
- package/src/primitives/popover/__workshop__/RightAlignedStory.tsx +60 -0
- package/src/primitives/popover/__workshop__/TestStory.tsx +79 -0
- package/src/primitives/popover/__workshop__/index.ts +10 -5
- package/src/primitives/popover/popover.tsx +29 -10
- package/src/primitives/select/select.tsx +9 -9
- package/src/primitives/select/styles.ts +10 -4
- package/src/primitives/stack/stack.tsx +2 -1
- package/src/primitives/stack/styles.ts +3 -3
- package/src/primitives/text/__workshop__/opticalAlignment.tsx +15 -5
- package/src/primitives/text/text.tsx +3 -2
- package/src/primitives/textArea/__workshop__/plain.tsx +23 -18
- package/src/primitives/textArea/textArea.tsx +21 -5
- package/src/primitives/textInput/__workshop__/clearButton.tsx +14 -8
- package/src/primitives/textInput/__workshop__/index.ts +2 -2
- package/src/primitives/textInput/__workshop__/plain.tsx +39 -32
- package/src/primitives/textInput/__workshop__/tones.tsx +234 -95
- package/src/primitives/textInput/__workshop__/typed.tsx +8 -2
- package/src/primitives/textInput/textInput.tsx +47 -12
- package/src/primitives/tooltip/__workshop__/props.tsx +7 -2
- package/src/primitives/tooltip/tooltip.tsx +19 -9
- package/src/primitives/types.ts +1 -1
- package/src/styles/border/borderStyle.ts +6 -6
- package/src/styles/border/types.ts +5 -5
- package/src/styles/box/boxStyle.ts +5 -5
- package/src/styles/box/types.ts +4 -4
- package/src/styles/flex/flexItemStyle.ts +5 -4
- package/src/styles/flex/flexStyle.ts +6 -6
- package/src/styles/flex/types.ts +6 -6
- package/src/styles/font/responsiveFont.ts +2 -4
- package/src/styles/font/textAlignStyle.ts +2 -2
- package/src/styles/font/types.ts +4 -3
- package/src/styles/grid/gridItemStyle.ts +7 -7
- package/src/styles/grid/gridStyle.ts +9 -9
- package/src/styles/grid/types.ts +14 -14
- package/src/styles/helpers.ts +9 -9
- package/src/styles/input/responsiveInputPaddingStyle.ts +24 -27
- package/src/styles/input/textInputStyle.ts +92 -80
- package/src/styles/margin/marginStyle.ts +8 -8
- package/src/styles/margin/marginsStyle.test.ts +1 -1
- package/src/styles/margin/types.ts +7 -7
- package/src/styles/padding/paddingStyle.test.ts +1 -1
- package/src/styles/padding/paddingStyle.ts +8 -8
- package/src/styles/padding/types.ts +7 -7
- package/src/styles/radius/radiusStyle.ts +2 -2
- package/src/styles/radius/types.ts +1 -1
- package/src/styles/shadow/shadowStyle.ts +2 -5
- package/src/styles/shadow/types.ts +1 -1
- package/src/theme/studioTheme/color.ts +15 -14
- package/src/theme/studioTheme/fonts.ts +4 -4
- package/src/utils/elementQuery/elementQuery.tsx +5 -18
- package/src/utils/index.ts +0 -1
- package/src/utils/layer/layerProvider.tsx +2 -2
- package/src/utils/virtualList/virtualList.tsx +3 -1
- package/lib/dts/src/hooks/useResponsiveProp.d.ts +0 -6
- package/lib/dts/src/hooks/useResponsiveProp.d.ts.map +0 -1
- package/lib/dts/src/utils/resizeObserver.d.ts +0 -6
- package/lib/dts/src/utils/resizeObserver.d.ts.map +0 -1
- package/src/hooks/useResponsiveProp.ts +0 -10
- package/src/primitives/popover/__workshop__/rightAligned.tsx +0 -57
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Property} from 'csstype'
|
|
2
2
|
import {CSSObject} from 'styled-components'
|
|
3
|
-
import {
|
|
3
|
+
import {_responsive} from '../helpers'
|
|
4
4
|
import {ThemeProps} from '../types'
|
|
5
5
|
import {ResponsiveBoxStyleProps} from './types'
|
|
6
6
|
|
|
@@ -39,7 +39,7 @@ function responsiveBoxDisplayStyle(props: ResponsiveBoxStyleProps & ThemeProps)
|
|
|
39
39
|
const {theme} = props
|
|
40
40
|
const {media} = theme.sanity
|
|
41
41
|
|
|
42
|
-
return
|
|
42
|
+
return _responsive(media, props.$display, (display) => ({
|
|
43
43
|
'&:not([hidden])': {display},
|
|
44
44
|
}))
|
|
45
45
|
}
|
|
@@ -48,7 +48,7 @@ function responsiveBoxSizingStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
|
|
|
48
48
|
const {theme} = props
|
|
49
49
|
const {media} = theme.sanity
|
|
50
50
|
|
|
51
|
-
return
|
|
51
|
+
return _responsive(media, props.$sizing, (sizing) => ({
|
|
52
52
|
boxSizing: BOX_SIZING[sizing],
|
|
53
53
|
}))
|
|
54
54
|
}
|
|
@@ -57,7 +57,7 @@ function responsiveBoxHeightStyle(props: ResponsiveBoxStyleProps & ThemeProps) {
|
|
|
57
57
|
const {theme} = props
|
|
58
58
|
const {media} = theme.sanity
|
|
59
59
|
|
|
60
|
-
return
|
|
60
|
+
return _responsive(media, props.$height, (height) => ({
|
|
61
61
|
height: BOX_HEIGHT[height],
|
|
62
62
|
}))
|
|
63
63
|
}
|
|
@@ -66,7 +66,7 @@ function responsiveBoxOverflowStyle(props: ResponsiveBoxStyleProps & ThemeProps)
|
|
|
66
66
|
const {theme} = props
|
|
67
67
|
const {media} = theme.sanity
|
|
68
68
|
|
|
69
|
-
return
|
|
69
|
+
return _responsive(media, props.$overflow, (overflow) => ({
|
|
70
70
|
overflow,
|
|
71
71
|
}))
|
|
72
72
|
}
|
package/src/styles/box/types.ts
CHANGED
|
@@ -4,8 +4,8 @@ import {BoxDisplay, BoxHeight, BoxOverflow, BoxSizing} from '../../types'
|
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export interface ResponsiveBoxStyleProps {
|
|
7
|
-
$display
|
|
8
|
-
$height
|
|
9
|
-
$overflow
|
|
10
|
-
$sizing
|
|
7
|
+
$display: BoxDisplay[]
|
|
8
|
+
$height: BoxHeight[]
|
|
9
|
+
$overflow: BoxOverflow[]
|
|
10
|
+
$sizing: BoxSizing[]
|
|
11
11
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
|
-
import {
|
|
2
|
+
import {EMPTY_ARRAY} from '../../constants'
|
|
3
|
+
import {_responsive} from '../helpers'
|
|
3
4
|
import {ThemeProps} from '../types'
|
|
4
5
|
import {ResponsiveFlexItemStyleProps} from './types'
|
|
5
6
|
|
|
@@ -20,7 +21,7 @@ export function responsiveFlexItemStyle(
|
|
|
20
21
|
const {theme} = props
|
|
21
22
|
const {media} = theme.sanity
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
24
|
+
if (!props.$flex) return EMPTY_ARRAY
|
|
25
|
+
|
|
26
|
+
return _responsive(media, props.$flex, (flex) => ({flex}))
|
|
26
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
|
-
import {
|
|
2
|
+
import {rem, _responsive} from '../helpers'
|
|
3
3
|
import {ThemeProps} from '../types'
|
|
4
4
|
import {ResponsiveFlexStyleProps} from './types'
|
|
5
5
|
|
|
@@ -28,7 +28,7 @@ export function responsiveFlexAlignStyle(
|
|
|
28
28
|
const {theme} = props
|
|
29
29
|
const {media} = theme.sanity
|
|
30
30
|
|
|
31
|
-
return
|
|
31
|
+
return _responsive(media, props.$align, (align) => {
|
|
32
32
|
return {alignItems: align}
|
|
33
33
|
})
|
|
34
34
|
}
|
|
@@ -37,7 +37,7 @@ function responsiveFlexGapStyle(props: ResponsiveFlexStyleProps & ThemeProps) {
|
|
|
37
37
|
const {theme} = props
|
|
38
38
|
const {media, space} = theme.sanity
|
|
39
39
|
|
|
40
|
-
return
|
|
40
|
+
return _responsive(media, props.$gap, (gap) => ({
|
|
41
41
|
gap: gap ? rem(space[gap]) : undefined,
|
|
42
42
|
}))
|
|
43
43
|
}
|
|
@@ -46,7 +46,7 @@ export function responsiveFlexWrapStyle(props: ResponsiveFlexStyleProps & ThemeP
|
|
|
46
46
|
const {theme} = props
|
|
47
47
|
const {media} = theme.sanity
|
|
48
48
|
|
|
49
|
-
return
|
|
49
|
+
return _responsive(media, props.$wrap, (wrap) => {
|
|
50
50
|
return {flexWrap: wrap}
|
|
51
51
|
})
|
|
52
52
|
}
|
|
@@ -57,7 +57,7 @@ export function responsiveFlexJustifyStyle(
|
|
|
57
57
|
const {theme} = props
|
|
58
58
|
const {media} = theme.sanity
|
|
59
59
|
|
|
60
|
-
return
|
|
60
|
+
return _responsive(media, props.$justify, (justify) => {
|
|
61
61
|
return {justifyContent: justify}
|
|
62
62
|
})
|
|
63
63
|
}
|
|
@@ -68,7 +68,7 @@ export function responsiveFlexDirectionStyle(
|
|
|
68
68
|
const {theme} = props
|
|
69
69
|
const {media} = theme.sanity
|
|
70
70
|
|
|
71
|
-
return
|
|
71
|
+
return _responsive(media, props.$direction, (direction) => {
|
|
72
72
|
return {flexDirection: direction}
|
|
73
73
|
})
|
|
74
74
|
}
|
package/src/styles/flex/types.ts
CHANGED
|
@@ -4,18 +4,18 @@ import {FlexAlign, FlexDirection, FlexJustify, FlexValue, FlexWrap} from '../../
|
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
6
6
|
export interface ResponsiveFlexStyleProps {
|
|
7
|
-
$align
|
|
8
|
-
$direction
|
|
9
|
-
$gap
|
|
10
|
-
$justify
|
|
11
|
-
$wrap
|
|
7
|
+
$align: FlexAlign[]
|
|
8
|
+
$direction: FlexDirection[]
|
|
9
|
+
$gap: number[]
|
|
10
|
+
$justify: FlexJustify[]
|
|
11
|
+
$wrap: FlexWrap[]
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @internal
|
|
16
16
|
*/
|
|
17
17
|
export interface ResponsiveFlexItemStyleProps {
|
|
18
|
-
$flex
|
|
18
|
+
$flex: FlexValue[]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
2
|
import {ThemeFontSize, ThemeFontKey} from '../../theme'
|
|
3
|
-
import {
|
|
3
|
+
import {rem, _responsive} from '../helpers'
|
|
4
4
|
import {ThemeProps} from '../types'
|
|
5
5
|
import {ResponsiveFontStyleProps} from './types'
|
|
6
6
|
|
|
@@ -48,9 +48,7 @@ export function responsiveFont(
|
|
|
48
48
|
},
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const resp =
|
|
52
|
-
fontSize(sizes[sizeIndex] || defaultSize)
|
|
53
|
-
)
|
|
51
|
+
const resp = _responsive(media, $size, (sizeIndex) => fontSize(sizes[sizeIndex] || defaultSize))
|
|
54
52
|
|
|
55
53
|
return [base, ...resp]
|
|
56
54
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
|
-
import {
|
|
2
|
+
import {_responsive} from '../helpers'
|
|
3
3
|
import {ThemeProps} from '../types'
|
|
4
4
|
import {ResponsiveTextAlignStyleProps} from './types'
|
|
5
5
|
|
|
@@ -12,7 +12,7 @@ export function responsiveTextAlignStyle(
|
|
|
12
12
|
): CSSObject[] {
|
|
13
13
|
const {theme} = props
|
|
14
14
|
|
|
15
|
-
return
|
|
15
|
+
return _responsive(theme.sanity.media, props.$align, (textAlign) => {
|
|
16
16
|
return {textAlign}
|
|
17
17
|
})
|
|
18
18
|
}
|
package/src/styles/font/types.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {TextAlign} from '../../types'
|
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
7
|
export interface ResponsiveFontSizeStyleProps {
|
|
8
|
-
$size
|
|
8
|
+
$size: number[]
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -19,7 +19,7 @@ export interface FontWeightStyleProps {
|
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
export interface ResponsiveTextAlignStyleProps {
|
|
22
|
-
$align
|
|
22
|
+
$align: TextAlign[]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
@@ -27,7 +27,8 @@ export interface ResponsiveTextAlignStyleProps {
|
|
|
27
27
|
*/
|
|
28
28
|
export interface ResponsiveFontStyleProps
|
|
29
29
|
extends FontWeightStyleProps,
|
|
30
|
-
ResponsiveFontSizeStyleProps
|
|
30
|
+
ResponsiveFontSizeStyleProps,
|
|
31
|
+
ResponsiveTextAlignStyleProps {
|
|
31
32
|
$accent?: boolean
|
|
32
33
|
$muted?: boolean
|
|
33
34
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
|
-
import {
|
|
2
|
+
import {_responsive} from '../helpers'
|
|
3
3
|
import {ThemeProps} from '../types'
|
|
4
4
|
import {ResponsiveGridItemStyleProps} from './types'
|
|
5
5
|
|
|
@@ -30,7 +30,7 @@ function responsiveGridItemRowStyle(props: ResponsiveGridItemStyleProps & ThemeP
|
|
|
30
30
|
const {theme} = props
|
|
31
31
|
const {media} = theme.sanity
|
|
32
32
|
|
|
33
|
-
return
|
|
33
|
+
return _responsive(media, props.$row, (row) => {
|
|
34
34
|
if (typeof row === 'number') {
|
|
35
35
|
return {gridRow: `span ${row} / span ${row}`}
|
|
36
36
|
}
|
|
@@ -43,7 +43,7 @@ function responsiveGridItemRowStartStyle(props: ResponsiveGridItemStyleProps & T
|
|
|
43
43
|
const {theme} = props
|
|
44
44
|
const {media} = theme.sanity
|
|
45
45
|
|
|
46
|
-
return
|
|
46
|
+
return _responsive(media, props.$rowStart, (rowStart) => ({
|
|
47
47
|
gridRowStart: rowStart,
|
|
48
48
|
}))
|
|
49
49
|
}
|
|
@@ -52,14 +52,14 @@ function responsiveGridItemRowEndStyle(props: ResponsiveGridItemStyleProps & The
|
|
|
52
52
|
const {theme} = props
|
|
53
53
|
const {media} = theme.sanity
|
|
54
54
|
|
|
55
|
-
return
|
|
55
|
+
return _responsive(media, props.$rowEnd, (rowEnd) => ({gridRowEnd: rowEnd}))
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
function responsiveGridItemColumnStyle(props: ResponsiveGridItemStyleProps & ThemeProps) {
|
|
59
59
|
const {theme} = props
|
|
60
60
|
const {media} = theme.sanity
|
|
61
61
|
|
|
62
|
-
return
|
|
62
|
+
return _responsive(media, props.$column, (column) => {
|
|
63
63
|
if (typeof column === 'number') {
|
|
64
64
|
return {gridColumn: `span ${column} / span ${column}`}
|
|
65
65
|
}
|
|
@@ -72,7 +72,7 @@ function responsiveGridItemColumnStartStyle(props: ResponsiveGridItemStyleProps
|
|
|
72
72
|
const {theme} = props
|
|
73
73
|
const {media} = theme.sanity
|
|
74
74
|
|
|
75
|
-
return
|
|
75
|
+
return _responsive(media, props.$columnStart, (columnStart) => ({
|
|
76
76
|
gridColumnStart: columnStart,
|
|
77
77
|
}))
|
|
78
78
|
}
|
|
@@ -81,7 +81,7 @@ function responsiveGridItemColumnEndStyle(props: ResponsiveGridItemStyleProps &
|
|
|
81
81
|
const {theme} = props
|
|
82
82
|
const {media} = theme.sanity
|
|
83
83
|
|
|
84
|
-
return
|
|
84
|
+
return _responsive(media, props.$columnEnd, (columnEnd) => ({
|
|
85
85
|
gridColumnEnd: columnEnd,
|
|
86
86
|
}))
|
|
87
87
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
|
-
import {
|
|
2
|
+
import {rem, _responsive} from '../helpers'
|
|
3
3
|
import {ThemeProps} from '../types'
|
|
4
4
|
import {ResponsiveGridStyleProps} from './types'
|
|
5
5
|
|
|
@@ -46,7 +46,7 @@ function responsiveGridAutoFlowStyle(props: ResponsiveGridStyleProps & ThemeProp
|
|
|
46
46
|
const {theme} = props
|
|
47
47
|
const {media} = theme.sanity
|
|
48
48
|
|
|
49
|
-
return
|
|
49
|
+
return _responsive(media, props.$autoFlow, (autoFlow) => ({
|
|
50
50
|
gridAutoFlow: autoFlow,
|
|
51
51
|
}))
|
|
52
52
|
}
|
|
@@ -55,7 +55,7 @@ function responsiveGridAutoRowsStyle(props: ResponsiveGridStyleProps & ThemeProp
|
|
|
55
55
|
const {theme} = props
|
|
56
56
|
const {media} = theme.sanity
|
|
57
57
|
|
|
58
|
-
return
|
|
58
|
+
return _responsive(media, props.$autoRows, (autoRows) => ({
|
|
59
59
|
gridAutoRows: autoRows && GRID_AUTO_ROWS[autoRows],
|
|
60
60
|
}))
|
|
61
61
|
}
|
|
@@ -64,7 +64,7 @@ function responsiveGridAutoColsStyle(props: ResponsiveGridStyleProps & ThemeProp
|
|
|
64
64
|
const {theme} = props
|
|
65
65
|
const {media} = theme.sanity
|
|
66
66
|
|
|
67
|
-
return
|
|
67
|
+
return _responsive(media, props.$autoCols, (autoCols) => ({
|
|
68
68
|
gridAutoColumns: autoCols && GRID_AUTO_COLUMS[autoCols],
|
|
69
69
|
}))
|
|
70
70
|
}
|
|
@@ -73,7 +73,7 @@ function responsiveGridColumnsStyle(props: ResponsiveGridStyleProps & ThemeProps
|
|
|
73
73
|
const {theme} = props
|
|
74
74
|
const {media} = theme.sanity
|
|
75
75
|
|
|
76
|
-
return
|
|
76
|
+
return _responsive(media, props.$columns, (columns) => ({
|
|
77
77
|
gridTemplateColumns: columns && `repeat(${columns},minmax(0,1fr));`,
|
|
78
78
|
}))
|
|
79
79
|
}
|
|
@@ -82,7 +82,7 @@ function responsiveGridRowsStyle(props: ResponsiveGridStyleProps & ThemeProps) {
|
|
|
82
82
|
const {theme} = props
|
|
83
83
|
const {media} = theme.sanity
|
|
84
84
|
|
|
85
|
-
return
|
|
85
|
+
return _responsive(media, props.$rows, (rows) => ({
|
|
86
86
|
gridTemplateRows: rows && `repeat(${rows},minmax(0,1fr));`,
|
|
87
87
|
}))
|
|
88
88
|
}
|
|
@@ -91,7 +91,7 @@ function responsiveGridGapStyle(props: ResponsiveGridStyleProps & ThemeProps) {
|
|
|
91
91
|
const {theme} = props
|
|
92
92
|
const {media, space} = theme.sanity
|
|
93
93
|
|
|
94
|
-
return
|
|
94
|
+
return _responsive(media, props.$gap, (gap) => ({
|
|
95
95
|
gridGap: gap ? rem(space[gap]) : undefined,
|
|
96
96
|
}))
|
|
97
97
|
}
|
|
@@ -100,7 +100,7 @@ function responsiveGridGapXStyle(props: ResponsiveGridStyleProps & ThemeProps) {
|
|
|
100
100
|
const {theme} = props
|
|
101
101
|
const {media, space} = theme.sanity
|
|
102
102
|
|
|
103
|
-
return
|
|
103
|
+
return _responsive(media, props.$gapX, (gapX) => ({
|
|
104
104
|
columnGap: gapX ? rem(space[gapX]) : undefined,
|
|
105
105
|
}))
|
|
106
106
|
}
|
|
@@ -109,7 +109,7 @@ function responsiveGridGapYStyle(props: ResponsiveGridStyleProps & ThemeProps) {
|
|
|
109
109
|
const {theme} = props
|
|
110
110
|
const {media, space} = theme.sanity
|
|
111
111
|
|
|
112
|
-
return
|
|
112
|
+
return _responsive(media, props.$gapY, (gapY) => ({
|
|
113
113
|
rowGap: gapY ? rem(space[gapY]) : undefined,
|
|
114
114
|
}))
|
|
115
115
|
}
|
package/src/styles/grid/types.ts
CHANGED
|
@@ -14,24 +14,24 @@ import {
|
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
16
|
export interface ResponsiveGridStyleProps {
|
|
17
|
-
$autoRows
|
|
18
|
-
$autoCols
|
|
19
|
-
$autoFlow
|
|
20
|
-
$columns
|
|
21
|
-
$gap
|
|
22
|
-
$gapX
|
|
23
|
-
$gapY
|
|
24
|
-
$rows
|
|
17
|
+
$autoRows: GridAutoRows[]
|
|
18
|
+
$autoCols: GridAutoCols[]
|
|
19
|
+
$autoFlow: GridAutoFlow[]
|
|
20
|
+
$columns: number[]
|
|
21
|
+
$gap: number[]
|
|
22
|
+
$gapX: number[]
|
|
23
|
+
$gapY: number[]
|
|
24
|
+
$rows: number[]
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @internal
|
|
29
29
|
*/
|
|
30
30
|
export interface ResponsiveGridItemStyleProps {
|
|
31
|
-
$column
|
|
32
|
-
$columnStart
|
|
33
|
-
$columnEnd
|
|
34
|
-
$row
|
|
35
|
-
$rowStart
|
|
36
|
-
$rowEnd
|
|
31
|
+
$column: GridItemColumn[]
|
|
32
|
+
$columnStart: GridItemColumnStart[]
|
|
33
|
+
$columnEnd: GridItemColumnEnd[]
|
|
34
|
+
$row: GridItemRow[]
|
|
35
|
+
$rowStart: GridItemRowStart[]
|
|
36
|
+
$rowEnd: GridItemRowEnd[]
|
|
37
37
|
}
|
package/src/styles/helpers.ts
CHANGED
|
@@ -5,11 +5,11 @@ import {Theme} from '../theme'
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
7
7
|
*/
|
|
8
|
-
export function
|
|
9
|
-
return
|
|
10
|
-
|
|
8
|
+
export function _fillCSSObject(keys: string[], value: string | number | CSSObject): CSSObject {
|
|
9
|
+
return keys.reduce<CSSObject>((style, key) => {
|
|
10
|
+
style[key] = value
|
|
11
11
|
|
|
12
|
-
return
|
|
12
|
+
return style
|
|
13
13
|
}, {})
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -25,7 +25,7 @@ export function rem(pixelValue: number): string | 0 {
|
|
|
25
25
|
/**
|
|
26
26
|
* @internal
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function _responsive<T>(
|
|
29
29
|
media: number[],
|
|
30
30
|
values: T[],
|
|
31
31
|
callback: (value: T, index: number, array: T[]) => CSSObject
|
|
@@ -42,7 +42,7 @@ export function responsive<T>(
|
|
|
42
42
|
/**
|
|
43
43
|
* @internal
|
|
44
44
|
*/
|
|
45
|
-
export function
|
|
45
|
+
export function _getArrayProp<T = number>(val: T | T[] | undefined, defaultVal?: T[]): T[] {
|
|
46
46
|
if (val === undefined) return defaultVal || EMPTY_ARRAY
|
|
47
47
|
|
|
48
48
|
return Array.isArray(val) ? val : [val]
|
|
@@ -51,7 +51,7 @@ export function getResponsiveProp<T = number>(val: T | T[] | undefined, defaultV
|
|
|
51
51
|
/**
|
|
52
52
|
* @internal
|
|
53
53
|
*/
|
|
54
|
-
export function
|
|
54
|
+
export function _getResponsiveSpace(
|
|
55
55
|
theme: Theme,
|
|
56
56
|
props: string[],
|
|
57
57
|
spaceIndexes: number[] = EMPTY_ARRAY
|
|
@@ -64,7 +64,7 @@ export function getResponsiveSpace(
|
|
|
64
64
|
return null
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
return
|
|
68
|
-
|
|
67
|
+
return _responsive(theme.sanity.media, spaceIndexes, (spaceIndex) =>
|
|
68
|
+
_fillCSSObject(props, rem(theme.sanity.space[spaceIndex]))
|
|
69
69
|
)
|
|
70
70
|
}
|
|
@@ -1,44 +1,41 @@
|
|
|
1
1
|
import {CSSObject} from 'styled-components'
|
|
2
|
-
import {
|
|
2
|
+
import {rem, _responsive} from '../helpers'
|
|
3
3
|
import {ThemeProps} from '../types'
|
|
4
4
|
|
|
5
5
|
export interface TextInputResponsivePaddingStyleProps {
|
|
6
|
-
$fontSize
|
|
6
|
+
$fontSize: number[]
|
|
7
7
|
$iconLeft?: boolean
|
|
8
8
|
$iconRight?: boolean
|
|
9
|
-
$padding
|
|
10
|
-
$space
|
|
9
|
+
$padding: number[]
|
|
10
|
+
$space: number[]
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function responsiveInputPaddingStyle(
|
|
14
14
|
props: TextInputResponsivePaddingStyleProps & ThemeProps
|
|
15
15
|
): CSSObject[] {
|
|
16
|
-
const {$iconLeft, $iconRight, theme} = props
|
|
16
|
+
const {$fontSize, $iconLeft, $iconRight, $padding, $space, theme} = props
|
|
17
17
|
const {fonts, media, space: spaceScale} = theme.sanity
|
|
18
|
-
const
|
|
19
|
-
const space = getResponsiveProp(props.$space, [0])
|
|
20
|
-
const size = getResponsiveProp(props.$fontSize, [0])
|
|
21
|
-
const len = Math.max(padding.length, space.length, size.length)
|
|
18
|
+
const len = Math.max($padding.length, $space.length, $fontSize.length)
|
|
22
19
|
const _padding: number[] = []
|
|
23
20
|
const _space: number[] = []
|
|
24
|
-
const
|
|
21
|
+
const _fontSize: number[] = []
|
|
25
22
|
|
|
26
23
|
for (let i = 0; i < len; i += 1) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
_fontSize[i] = $fontSize[i] === undefined ? _fontSize[i - 1] : $fontSize[i]
|
|
25
|
+
_padding[i] = $padding[i] === undefined ? _padding[i - 1] : $padding[i]
|
|
26
|
+
_space[i] = $space[i] === undefined ? _space[i - 1] : $space[i]
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
return
|
|
33
|
-
const
|
|
34
|
-
const emSize =
|
|
29
|
+
return _responsive(media, _padding, (_, i) => {
|
|
30
|
+
const size = fonts.text.sizes[_fontSize[i]] || fonts.text.sizes[2]
|
|
31
|
+
const emSize = size.lineHeight - size.ascenderHeight - size.descenderHeight
|
|
35
32
|
const p = spaceScale[_padding[i]]
|
|
36
33
|
const s = spaceScale[_space[i]]
|
|
37
34
|
|
|
38
35
|
const styles = {
|
|
39
|
-
paddingTop: rem(p -
|
|
36
|
+
paddingTop: rem(p - size.ascenderHeight),
|
|
40
37
|
paddingRight: rem(p),
|
|
41
|
-
paddingBottom: rem(p -
|
|
38
|
+
paddingBottom: rem(p - size.descenderHeight),
|
|
42
39
|
paddingLeft: rem(p),
|
|
43
40
|
}
|
|
44
41
|
|
|
@@ -51,9 +48,9 @@ export function responsiveInputPaddingStyle(
|
|
|
51
48
|
|
|
52
49
|
export function responsiveInputPaddingIconsStyle(
|
|
53
50
|
props: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
space
|
|
51
|
+
$fontSize: number[]
|
|
52
|
+
$padding: number[]
|
|
53
|
+
$space: number[]
|
|
57
54
|
} & ThemeProps
|
|
58
55
|
): CSSObject[] {
|
|
59
56
|
return responsiveInputPaddingStyle({...props, $iconLeft: true, $iconRight: true})
|
|
@@ -61,9 +58,9 @@ export function responsiveInputPaddingIconsStyle(
|
|
|
61
58
|
|
|
62
59
|
export function responsiveInputPaddingIconLeftStyle(
|
|
63
60
|
props: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
space
|
|
61
|
+
$fontSize: number[]
|
|
62
|
+
$padding: number[]
|
|
63
|
+
$space: number[]
|
|
67
64
|
} & ThemeProps
|
|
68
65
|
): CSSObject[] {
|
|
69
66
|
return responsiveInputPaddingStyle({...props, $iconLeft: true})
|
|
@@ -71,9 +68,9 @@ export function responsiveInputPaddingIconLeftStyle(
|
|
|
71
68
|
|
|
72
69
|
export function responsiveInputPaddingIconRightStyle(
|
|
73
70
|
props: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
space
|
|
71
|
+
$fontSize: number[]
|
|
72
|
+
$padding: number[]
|
|
73
|
+
$space: number[]
|
|
77
74
|
} & ThemeProps
|
|
78
75
|
): CSSObject[] {
|
|
79
76
|
return responsiveInputPaddingStyle({...props, $iconRight: true})
|