@sanity/ui 5.0.0-alpha.24 → 5.0.0-alpha.26
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/index.d.ts +145 -147
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +256 -179
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/avatar/avatar.props.ts +4 -2
- package/src/components/avatar-counter/avatarCounter.props.ts +4 -2
- package/src/components/avatar-stack/avatarStack.props.ts +4 -2
- package/src/components/badge/Badge.tsx +2 -5
- package/src/components/badge/badge.props.ts +15 -15
- package/src/components/box/Box.tsx +2 -5
- package/src/components/box/box.props.ts +18 -12
- package/src/components/button/Button.tsx +2 -2
- package/src/components/button/button.props.ts +49 -43
- package/src/components/card/Card.tsx +2 -2
- package/src/components/card/card.props.ts +19 -13
- package/src/components/checkbox/Checkbox.tsx +3 -2
- package/src/components/checkbox/checkbox.props.ts +4 -2
- package/src/components/code/code.props.ts +5 -3
- package/src/components/container/Container.tsx +2 -2
- package/src/components/container/container.props.ts +17 -11
- package/src/components/dialog/Dialog.tsx +13 -7
- package/src/components/dialog/dialog.props.ts +11 -3
- package/src/components/divider/divider.props.ts +4 -2
- package/src/components/eyebrow/Eyebrow.tsx +2 -5
- package/src/components/eyebrow/eyebrow.props.ts +19 -12
- package/src/components/flex/Flex.tsx +2 -5
- package/src/components/flex/flex.props.ts +19 -12
- package/src/components/grid/Grid.tsx +2 -5
- package/src/components/grid/grid.props.ts +20 -16
- package/src/components/h-stack/HStack.tsx +2 -5
- package/src/components/h-stack/hStack.props.ts +7 -4
- package/src/components/heading/Heading.tsx +2 -5
- package/src/components/heading/heading.props.ts +18 -13
- package/src/components/hotkeys/hotkeys.props.ts +4 -2
- package/src/components/icon/icon.props.ts +3 -3
- package/src/components/icon-button/IconButton.tsx +2 -4
- package/src/components/icon-button/iconButton.props.ts +17 -17
- package/src/components/index.css +1 -0
- package/src/components/indicator/Indicator.tsx +2 -2
- package/src/components/indicator/indicator.props.ts +17 -11
- package/src/components/indicator-stack/IndicatorStack.tsx +2 -4
- package/src/components/indicator-stack/indicatorStack.props.ts +13 -7
- package/src/components/inline/Inline.tsx +2 -2
- package/src/components/inline/inline.props.ts +17 -11
- package/src/components/kbd/kbd.props.ts +4 -2
- package/src/components/link/link.props.ts +4 -2
- package/src/components/list/List.tsx +47 -97
- package/src/components/list/list.css +28 -9
- package/src/components/list/list.props.ts +59 -68
- package/src/components/popover/popover.props.ts +7 -5
- package/src/components/press-area/PressArea.tsx +2 -4
- package/src/components/press-area/press-area.css +9 -3
- package/src/components/press-area/pressArea.props.ts +13 -7
- package/src/components/radio/radio.props.ts +2 -1
- package/src/components/search-input/SearchInput.tsx +90 -0
- package/src/components/search-input/search-input.css +125 -0
- package/src/components/search-input/searchInput.props.ts +18 -0
- package/src/components/select/Select.tsx +6 -1
- package/src/components/select/select.css +10 -12
- package/src/components/select/select.props.ts +4 -2
- package/src/components/skip-to-content/skipToContent.props.ts +4 -2
- package/src/components/spinner/spinner.props.ts +4 -2
- package/src/components/switch/switch.props.ts +4 -2
- package/src/components/tabs/tabs.props.ts +8 -9
- package/src/components/text/Text.tsx +2 -5
- package/src/components/text/text.props.ts +19 -12
- package/src/components/text-area/textArea.props.ts +4 -5
- package/src/components/text-input/textInput.props.ts +5 -3
- package/src/components/tooltip/tooltip.props.ts +7 -5
- package/src/components/tooltip-group/TooltipGroup.tsx +8 -9
- package/src/components/tooltip-group/tooltipGroup.props.ts +13 -7
- package/src/components/v-stack/VStack.tsx +2 -5
- package/src/components/v-stack/vStack.props.ts +7 -4
- package/src/components/visually-hidden/VisuallyHidden.tsx +2 -4
- package/src/components/visually-hidden/visuallyHidden.props.ts +18 -12
- package/src/index.ts +1 -0
- package/src/types/Interactive.ts +3 -1
- package/src/types/Polymorphic.ts +9 -0
- package/src/types/Tone.ts +1 -1
- package/src/utils/composeRefs.test.ts +130 -0
- package/src/utils/composeRefs.ts +52 -0
- package/src/utils/getProps.test.ts +18 -0
- package/src/utils/getProps.ts +31 -16
- package/src/version.ts +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import clsx from 'clsx'
|
|
2
|
-
import type {
|
|
2
|
+
import type {ElementType} from 'react'
|
|
3
3
|
|
|
4
4
|
import type {ListTag} from '../../types/List'
|
|
5
5
|
import {getProps} from '../../utils/getProps'
|
|
@@ -9,25 +9,20 @@ import {PressArea} from '../press-area/PressArea'
|
|
|
9
9
|
import {Text} from '../text/Text'
|
|
10
10
|
import {VStack} from '../v-stack/VStack'
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
type
|
|
12
|
+
listButtonProps,
|
|
13
|
+
type ListItemButtonProps,
|
|
14
|
+
type ListImageProps,
|
|
14
15
|
type ListItemProps,
|
|
15
|
-
listItemProps,
|
|
16
|
-
type ListItemTextProps,
|
|
17
|
-
listItemTextProps,
|
|
18
16
|
type ListProps,
|
|
19
17
|
listProps,
|
|
20
18
|
} from './list.props'
|
|
21
19
|
|
|
22
20
|
const listClassName = suffixClassName('sui-List')
|
|
23
21
|
const listItemClassName = suffixClassName('sui-ListItem')
|
|
24
|
-
const
|
|
25
|
-
const listItemTextClassName = suffixClassName('sui-ListItemText')
|
|
22
|
+
const listButtonClassName = suffixClassName('sui-ListItemButton')
|
|
26
23
|
const listItemImageClassName = suffixClassName('sui-ListItemImage')
|
|
27
24
|
|
|
28
|
-
function ListRoot<T extends ListTag = 'ul'>(
|
|
29
|
-
props: ListProps<T> & Omit<ComponentPropsWithRef<T>, keyof ListProps<T>>,
|
|
30
|
-
) {
|
|
25
|
+
function ListRoot<T extends ListTag = 'ul'>(props: ListProps<T>) {
|
|
31
26
|
const {as, children, className, style, ...rest} = getProps(props, listProps)
|
|
32
27
|
const Component = as || 'ul'
|
|
33
28
|
|
|
@@ -44,110 +39,66 @@ function ListRoot<T extends ListTag = 'ul'>(
|
|
|
44
39
|
)
|
|
45
40
|
}
|
|
46
41
|
|
|
47
|
-
function ListItem({
|
|
48
|
-
const {children, className, style, end, start, ...rest} = getProps(
|
|
49
|
-
{density, ...props},
|
|
50
|
-
listItemProps,
|
|
51
|
-
)
|
|
52
|
-
|
|
42
|
+
function ListItem({className, ...rest}: ListItemProps) {
|
|
53
43
|
return (
|
|
54
44
|
<li
|
|
55
|
-
className={clsx(
|
|
56
|
-
listItemClassName,
|
|
57
|
-
'sui-width-full sui-display-flex sui-align-items-center',
|
|
58
|
-
className,
|
|
59
|
-
)}
|
|
60
|
-
style={style}
|
|
61
45
|
data-ui="ListItem"
|
|
46
|
+
className={clsx(listItemClassName, 'sui-text-body1', className)}
|
|
62
47
|
{...rest}
|
|
63
|
-
|
|
64
|
-
{start}
|
|
65
|
-
|
|
66
|
-
<Flex flexGrow={1} gap="inherit">
|
|
67
|
-
{children}
|
|
68
|
-
</Flex>
|
|
69
|
-
|
|
70
|
-
{end}
|
|
71
|
-
</li>
|
|
48
|
+
/>
|
|
72
49
|
)
|
|
73
50
|
}
|
|
74
51
|
|
|
75
|
-
function
|
|
52
|
+
function ListItemButton<T extends ElementType = 'button'>({
|
|
76
53
|
density = 'regular',
|
|
77
54
|
...props
|
|
78
|
-
}:
|
|
79
|
-
const {as, children, className, style, end, start,
|
|
55
|
+
}: ListItemButtonProps<T>) {
|
|
56
|
+
const {as, children, className, style, text, subtext, end, start, current, ...rest} = getProps(
|
|
80
57
|
{density, ...props},
|
|
81
|
-
|
|
58
|
+
listButtonProps,
|
|
82
59
|
)
|
|
83
60
|
const Component = as || 'button'
|
|
84
61
|
|
|
85
62
|
return (
|
|
86
|
-
<
|
|
87
|
-
<PressArea
|
|
88
|
-
as={Component}
|
|
89
|
-
className={clsx(
|
|
90
|
-
listButtonItemClassName,
|
|
91
|
-
'sui-width-full sui-display-flex sui-align-items-center sui-radius2',
|
|
92
|
-
className,
|
|
93
|
-
)}
|
|
94
|
-
style={style}
|
|
95
|
-
data-ui="ListButtonItem"
|
|
96
|
-
data-selected={selected}
|
|
97
|
-
{...rest}
|
|
98
|
-
>
|
|
99
|
-
{start}
|
|
100
|
-
|
|
101
|
-
<Flex flexGrow={1} gap="inherit">
|
|
102
|
-
{children}
|
|
103
|
-
</Flex>
|
|
104
|
-
|
|
105
|
-
{end}
|
|
106
|
-
</PressArea>
|
|
107
|
-
</li>
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function ListItemText<T extends ElementType = 'div'>(
|
|
112
|
-
props: ListItemTextProps<T> & Omit<ComponentPropsWithRef<T>, keyof ListItemTextProps<T>>,
|
|
113
|
-
) {
|
|
114
|
-
const {as, className, style, title, subtitle, ...rest} = getProps(props, listItemTextProps)
|
|
115
|
-
const Component = as || 'div'
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<Flex
|
|
63
|
+
<PressArea
|
|
119
64
|
as={Component}
|
|
120
|
-
className={clsx(
|
|
65
|
+
className={clsx(
|
|
66
|
+
listButtonClassName,
|
|
67
|
+
'sui-width-full sui-display-flex sui-align-items-center sui-radius2',
|
|
68
|
+
className,
|
|
69
|
+
)}
|
|
121
70
|
style={style}
|
|
122
|
-
data-ui="
|
|
123
|
-
|
|
124
|
-
justifyContent="center"
|
|
125
|
-
gap={2}
|
|
126
|
-
flexGrow={1}
|
|
71
|
+
data-ui="ListItemButton"
|
|
72
|
+
aria-current={current}
|
|
127
73
|
{...rest}
|
|
128
74
|
>
|
|
129
|
-
{
|
|
130
|
-
<Text size={1} weight="medium" trim truncate={1}>
|
|
131
|
-
{title}
|
|
132
|
-
</Text>
|
|
133
|
-
)}
|
|
75
|
+
{start}
|
|
134
76
|
|
|
135
|
-
{
|
|
136
|
-
|
|
137
|
-
{
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
77
|
+
<Flex flexDirection="column" justifyContent="center" gap={2} flexGrow={1}>
|
|
78
|
+
{text && (
|
|
79
|
+
<Text size={1} weight="medium" trim truncate={1}>
|
|
80
|
+
{text}
|
|
81
|
+
</Text>
|
|
82
|
+
)}
|
|
83
|
+
|
|
84
|
+
{subtext && (
|
|
85
|
+
<Text size={1} muted trim truncate={1}>
|
|
86
|
+
{subtext}
|
|
87
|
+
</Text>
|
|
88
|
+
)}
|
|
89
|
+
|
|
90
|
+
{children}
|
|
91
|
+
</Flex>
|
|
92
|
+
|
|
93
|
+
{end}
|
|
94
|
+
</PressArea>
|
|
141
95
|
)
|
|
142
96
|
}
|
|
143
97
|
|
|
144
|
-
function ListItemImage(
|
|
145
|
-
const {className, style, ...rest} = getProps(props, {})
|
|
146
|
-
|
|
98
|
+
function ListItemImage({className, ...rest}: ListImageProps) {
|
|
147
99
|
return (
|
|
148
100
|
<img
|
|
149
101
|
className={clsx(listItemImageClassName, 'sui-radius2', className)}
|
|
150
|
-
style={style}
|
|
151
102
|
data-ui="ListItemImage"
|
|
152
103
|
{...rest}
|
|
153
104
|
/>
|
|
@@ -157,11 +108,10 @@ function ListItemImage(props: ComponentProps<'img'>) {
|
|
|
157
108
|
ListRoot.displayName = 'List'
|
|
158
109
|
|
|
159
110
|
/** @beta */
|
|
160
|
-
export const List = ListRoot
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
ListRoot.ItemImage = ListItemImage
|
|
111
|
+
export const List = Object.assign(ListRoot, {
|
|
112
|
+
Item: ListItem,
|
|
113
|
+
ItemButton: ListItemButton,
|
|
114
|
+
ItemImage: ListItemImage,
|
|
115
|
+
})
|
|
166
116
|
|
|
167
|
-
export type {ListProps, ListItemProps,
|
|
117
|
+
export type {ListProps, ListItemProps, ListItemButtonProps, ListImageProps}
|
|
@@ -2,19 +2,38 @@
|
|
|
2
2
|
list-style-type: none;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
.sui-
|
|
6
|
-
.sui-
|
|
7
|
-
|
|
5
|
+
.sui-ListItem,
|
|
6
|
+
.sui-ListItemButton {
|
|
7
|
+
--list-color: var(--foreground-high);
|
|
8
|
+
--list-color-muted: var(--foreground-low);
|
|
9
|
+
/*
|
|
10
|
+
* ListItemButton uses PressArea under the hood and can hook into
|
|
11
|
+
* its variables to set Text and Icon colors
|
|
12
|
+
*/
|
|
13
|
+
--press-area-color: var(--list-color);
|
|
14
|
+
--press-area-color-muted: var(--list-color-muted);
|
|
15
|
+
color: var(--list-color);
|
|
8
16
|
}
|
|
9
17
|
|
|
10
|
-
.sui-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
.sui-ListItemButton {
|
|
19
|
+
--background-color: transparent;
|
|
20
|
+
background: var(--background-color);
|
|
13
21
|
}
|
|
14
22
|
|
|
15
|
-
.sui-
|
|
16
|
-
|
|
17
|
-
color: var(--
|
|
23
|
+
.sui-ListItemButton:hover,
|
|
24
|
+
.sui-ListItemButton:focus-visible {
|
|
25
|
+
--background-color: var(--background-low);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.sui-ListItemButton:disabled {
|
|
29
|
+
--list-color: var(--inert-foreground);
|
|
30
|
+
--list-color-muted: var(--inert-foreground);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.sui-ListItemButton[aria-current="true"] {
|
|
34
|
+
--background-color: var(--active-background-emphasized);
|
|
35
|
+
--list-color: var(--active-foreground-emphasized);
|
|
36
|
+
--list-color-muted: var(--active-background-normal);
|
|
18
37
|
}
|
|
19
38
|
|
|
20
39
|
.sui-ListItemImage {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type {ComponentProps, ReactNode, ElementType} from 'react'
|
|
2
2
|
|
|
3
3
|
import {type GapProps, gapProps} from '../../props/gap'
|
|
4
4
|
import {heightProps} from '../../props/height'
|
|
@@ -6,16 +6,20 @@ import {paddingProps} from '../../props/padding'
|
|
|
6
6
|
import {DENSITY, type Density} from '../../types/Density'
|
|
7
7
|
import type {InteractiveAs} from '../../types/Interactive'
|
|
8
8
|
import type {ListTag} from '../../types/List'
|
|
9
|
-
import
|
|
9
|
+
import type {Polymorphic} from '../../types/Polymorphic'
|
|
10
|
+
import type {PropDef} from '../../types/PropDef'
|
|
10
11
|
import type {Responsive} from '../../types/Responsive'
|
|
11
12
|
|
|
12
13
|
/** @beta */
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
export type ListProps<T extends ListTag = 'ul'> = Polymorphic<
|
|
15
|
+
T,
|
|
16
|
+
Pick<GapProps, 'gap'> & {
|
|
17
|
+
/**
|
|
18
|
+
* HTML element to render.
|
|
19
|
+
*/
|
|
20
|
+
as?: T
|
|
21
|
+
}
|
|
22
|
+
>
|
|
19
23
|
|
|
20
24
|
export const listProps: Record<string, PropDef> = {
|
|
21
25
|
as: {
|
|
@@ -25,22 +29,50 @@ export const listProps: Record<string, PropDef> = {
|
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
/** @beta */
|
|
28
|
-
export interface ListItemProps extends
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
export interface ListItemProps extends ComponentProps<'li'> {}
|
|
33
|
+
|
|
34
|
+
/** @beta */
|
|
35
|
+
export type ListItemButtonProps<T extends ElementType = 'button'> = Polymorphic<
|
|
36
|
+
T,
|
|
37
|
+
{
|
|
38
|
+
/**
|
|
39
|
+
* Element or component to render for the press target.
|
|
40
|
+
*/
|
|
41
|
+
as?: InteractiveAs<T>
|
|
42
|
+
/**
|
|
43
|
+
* Marks the row as the current selection.
|
|
44
|
+
*/
|
|
45
|
+
current?: boolean
|
|
46
|
+
/**
|
|
47
|
+
* Sets horizontal padding, gap, and minimum row height together.
|
|
48
|
+
*/
|
|
49
|
+
density?: Responsive<Density>
|
|
50
|
+
/**
|
|
51
|
+
* Slot at the left edge of the row.
|
|
52
|
+
*/
|
|
53
|
+
start?: ReactNode
|
|
54
|
+
/**
|
|
55
|
+
* Slot at the right edge of the row.
|
|
56
|
+
*/
|
|
57
|
+
end?: ReactNode
|
|
58
|
+
/**
|
|
59
|
+
* Main label.
|
|
60
|
+
*/
|
|
61
|
+
text?: ReactNode
|
|
62
|
+
/**
|
|
63
|
+
* Text below the title.
|
|
64
|
+
*/
|
|
65
|
+
subtext?: ReactNode
|
|
66
|
+
}
|
|
67
|
+
>
|
|
42
68
|
|
|
43
|
-
export const
|
|
69
|
+
export const listButtonProps: Record<string, PropDef> = {
|
|
70
|
+
as: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
},
|
|
73
|
+
current: {
|
|
74
|
+
type: 'boolean',
|
|
75
|
+
},
|
|
44
76
|
density: {
|
|
45
77
|
type: 'composite',
|
|
46
78
|
values: DENSITY,
|
|
@@ -77,54 +109,13 @@ export const listItemProps: Record<string, PropDef> = {
|
|
|
77
109
|
start: {
|
|
78
110
|
type: 'string',
|
|
79
111
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/** @beta */
|
|
83
|
-
export interface ListButtonItemProps<T extends React.ElementType = 'button'> extends ListItemProps {
|
|
84
|
-
/**
|
|
85
|
-
* Element or component to render for the press target.
|
|
86
|
-
*/
|
|
87
|
-
as?: InteractiveAs<T>
|
|
88
|
-
/**
|
|
89
|
-
* Marks the row as the current selection.
|
|
90
|
-
*/
|
|
91
|
-
selected?: boolean
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export const listButtonItemProps: Record<string, PropDef> = {
|
|
95
|
-
as: {
|
|
112
|
+
text: {
|
|
96
113
|
type: 'string',
|
|
97
114
|
},
|
|
98
|
-
|
|
99
|
-
type: '
|
|
115
|
+
subtext: {
|
|
116
|
+
type: 'string',
|
|
100
117
|
},
|
|
101
|
-
...listItemProps,
|
|
102
118
|
}
|
|
103
119
|
|
|
104
120
|
/** @beta */
|
|
105
|
-
export interface
|
|
106
|
-
/**
|
|
107
|
-
* HTML element to render.
|
|
108
|
-
*/
|
|
109
|
-
as?: T
|
|
110
|
-
/**
|
|
111
|
-
* Main label.
|
|
112
|
-
*/
|
|
113
|
-
title?: React.ReactNode
|
|
114
|
-
/**
|
|
115
|
-
* Text below the title.
|
|
116
|
-
*/
|
|
117
|
-
subtitle?: React.ReactNode
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export const listItemTextProps: Record<string, PropDef> = {
|
|
121
|
-
as: {
|
|
122
|
-
type: 'string',
|
|
123
|
-
},
|
|
124
|
-
title: {
|
|
125
|
-
type: 'string',
|
|
126
|
-
},
|
|
127
|
-
subtitle: {
|
|
128
|
-
type: 'string',
|
|
129
|
-
},
|
|
130
|
-
}
|
|
121
|
+
export interface ListImageProps extends ComponentProps<'img'> {}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
+
import type {ComponentProps, ReactElement, ReactNode} from 'react'
|
|
2
|
+
|
|
1
3
|
import {type PlacementProps, placementProps} from '../../props/placement'
|
|
2
|
-
import
|
|
4
|
+
import type {PropDef} from '../../types/PropDef'
|
|
3
5
|
|
|
4
6
|
/** @beta */
|
|
5
7
|
export interface PopoverProps
|
|
6
|
-
extends Omit<
|
|
8
|
+
extends Omit<ComponentProps<'div'>, 'children' | 'content'>, PlacementProps {
|
|
7
9
|
/**
|
|
8
10
|
* Shared anchor identifier.
|
|
9
11
|
* @remarks Set the same value on a Tooltip and a Popover to point both at one trigger.
|
|
10
12
|
*/
|
|
11
|
-
anchorName?:
|
|
13
|
+
anchorName?: ReactNode
|
|
12
14
|
/**
|
|
13
15
|
* The trigger element.
|
|
14
16
|
* @remarks Popover clones it and attaches the `popovertarget` attribute that opens the floating layer.
|
|
15
17
|
*/
|
|
16
|
-
children:
|
|
18
|
+
children: ReactElement<Record<string, unknown>>
|
|
17
19
|
/**
|
|
18
20
|
* The floating content.
|
|
19
21
|
*/
|
|
20
|
-
content?:
|
|
22
|
+
content?: ReactNode
|
|
21
23
|
/**
|
|
22
24
|
* Removes popover padding.
|
|
23
25
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import clsx from 'clsx'
|
|
2
|
-
import type {
|
|
2
|
+
import type {ElementType} from 'react'
|
|
3
3
|
|
|
4
4
|
import {getProps} from '../../utils/getProps'
|
|
5
5
|
import {suffixClassName} from '../../utils/suffixClassName'
|
|
@@ -8,9 +8,7 @@ import {type PressAreaProps, pressAreaProps} from './pressArea.props'
|
|
|
8
8
|
const pressAreaClassName = suffixClassName('sui-PressArea')
|
|
9
9
|
|
|
10
10
|
/** @public */
|
|
11
|
-
export function PressArea<T extends ElementType = 'button'>(
|
|
12
|
-
props: PressAreaProps<T> & Omit<ComponentPropsWithRef<T>, keyof PressAreaProps<T>>,
|
|
13
|
-
) {
|
|
11
|
+
export function PressArea<T extends ElementType = 'button'>(props: PressAreaProps<T>) {
|
|
14
12
|
const {as, children, className, style, ...rest} = getProps(props, pressAreaProps)
|
|
15
13
|
const Component = as || 'button'
|
|
16
14
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.sui-PressArea {
|
|
1
|
+
:where(.sui-PressArea) {
|
|
2
2
|
background: none;
|
|
3
3
|
font: inherit;
|
|
4
4
|
color: inherit;
|
|
@@ -16,7 +16,13 @@
|
|
|
16
16
|
pointer-events: none;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
.sui-PressArea .sui-Text
|
|
19
|
+
.sui-PressArea .sui-Text {
|
|
20
|
+
--press-area-color: inherit;
|
|
21
|
+
color: var(--press-area-color);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.sui-PressArea .sui-Text:where(.sui-text-muted),
|
|
20
25
|
.sui-PressArea [data-sanity-icon] {
|
|
21
|
-
color: inherit;
|
|
26
|
+
--press-area-color-muted: inherit;
|
|
27
|
+
color: var(--press-area-color-muted);
|
|
22
28
|
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
+
import type {ElementType} from 'react'
|
|
2
|
+
|
|
1
3
|
import type {InteractiveAs} from '../../types/Interactive'
|
|
2
|
-
import
|
|
4
|
+
import type {Polymorphic} from '../../types/Polymorphic'
|
|
5
|
+
import type {PropDef} from '../../types/PropDef'
|
|
3
6
|
|
|
4
7
|
/** @public */
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
export type PressAreaProps<T extends ElementType = 'button'> = Polymorphic<
|
|
9
|
+
T,
|
|
10
|
+
{
|
|
11
|
+
/**
|
|
12
|
+
* Element or component to render.
|
|
13
|
+
*/
|
|
14
|
+
as?: InteractiveAs<T>
|
|
15
|
+
}
|
|
16
|
+
>
|
|
11
17
|
|
|
12
18
|
export const pressAreaProps: Record<string, PropDef> = {
|
|
13
19
|
as: {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import CloseIcon from '@sanity/icons/Close'
|
|
2
|
+
import SearchIcon from '@sanity/icons/Search'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import {useId, useRef} from 'react'
|
|
5
|
+
|
|
6
|
+
import {composeRefs} from '../../utils/composeRefs'
|
|
7
|
+
import {getProps} from '../../utils/getProps'
|
|
8
|
+
import {suffixClassName} from '../../utils/suffixClassName'
|
|
9
|
+
import {Icon} from '../icon/Icon'
|
|
10
|
+
import {PressArea} from '../press-area/PressArea'
|
|
11
|
+
import {Spinner} from '../spinner/Spinner'
|
|
12
|
+
import {type SearchInputProps, searchInputProps} from './searchInput.props'
|
|
13
|
+
|
|
14
|
+
const searchInputClassName = suffixClassName('sui-SearchInput')
|
|
15
|
+
const searchInputClearClassName = suffixClassName('sui-SearchInput-Clear')
|
|
16
|
+
const searchInputIconClassName = suffixClassName('sui-SearchInput-Icon')
|
|
17
|
+
|
|
18
|
+
/** @public */
|
|
19
|
+
export function SearchInput({
|
|
20
|
+
density = 'regular',
|
|
21
|
+
loading,
|
|
22
|
+
// A non-null placeholder to ensure that, if no placeholder is passed, the custom clear button's display logic still works (see search-input.css)
|
|
23
|
+
placeholder = ' ',
|
|
24
|
+
ref,
|
|
25
|
+
...props
|
|
26
|
+
}: SearchInputProps) {
|
|
27
|
+
const {className, style, ...rest} = getProps({density, ...props}, searchInputProps)
|
|
28
|
+
|
|
29
|
+
const searchInputClasses = clsx(searchInputClassName, 'sui-radius2', 'sui-width-full', className)
|
|
30
|
+
const iconClasses = `sui-position-absolute sui-display-flex sui-align-items-center sui-px1`
|
|
31
|
+
|
|
32
|
+
const anchorId = useId()
|
|
33
|
+
const anchorName = `--anchor-${anchorId}`
|
|
34
|
+
|
|
35
|
+
const inputRef = useRef<HTMLInputElement>(null)
|
|
36
|
+
|
|
37
|
+
// Custom 'clear input' handler:
|
|
38
|
+
// Gets the input's native value setter, resets to an empty string with that setter,
|
|
39
|
+
// and dispatches an `input` event to notify React of the change. See:
|
|
40
|
+
// https://github.com/facebook/react/issues/10135#issuecomment-401496776
|
|
41
|
+
function handleClear() {
|
|
42
|
+
const input = inputRef.current
|
|
43
|
+
if (!input) return
|
|
44
|
+
|
|
45
|
+
// oxlint-disable-next-line typescript/unbound-method -- called with an explicit `this` below
|
|
46
|
+
const set = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(input), 'value')?.set
|
|
47
|
+
set?.call(input, '')
|
|
48
|
+
input.dispatchEvent(new Event('input', {bubbles: true}))
|
|
49
|
+
// Focus the input after clearing, as native clear does
|
|
50
|
+
input.focus()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
<input
|
|
56
|
+
className={searchInputClasses}
|
|
57
|
+
style={{anchorName, ...style}}
|
|
58
|
+
{...rest}
|
|
59
|
+
aria-busy={loading}
|
|
60
|
+
data-ui="SearchInput"
|
|
61
|
+
type="search"
|
|
62
|
+
placeholder={placeholder}
|
|
63
|
+
ref={composeRefs(inputRef, ref)}
|
|
64
|
+
/>
|
|
65
|
+
<div
|
|
66
|
+
className={clsx(searchInputIconClassName, iconClasses)}
|
|
67
|
+
data-ui="Search-Icon"
|
|
68
|
+
style={{positionAnchor: anchorName}}
|
|
69
|
+
>
|
|
70
|
+
{loading ? <Spinner size={1} /> : <Icon icon={SearchIcon} size={1} />}
|
|
71
|
+
</div>
|
|
72
|
+
<div
|
|
73
|
+
className={clsx(searchInputClearClassName, iconClasses)}
|
|
74
|
+
data-ui="Search-Clear"
|
|
75
|
+
style={{positionAnchor: anchorName}}
|
|
76
|
+
>
|
|
77
|
+
<PressArea
|
|
78
|
+
type="button"
|
|
79
|
+
onClick={handleClear}
|
|
80
|
+
aria-label="Clear search query"
|
|
81
|
+
className="sui-display-inline-flex sui-align-items-center sui-justify-content-center"
|
|
82
|
+
>
|
|
83
|
+
<Icon icon={CloseIcon} size={0} />
|
|
84
|
+
</PressArea>
|
|
85
|
+
</div>
|
|
86
|
+
</>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type {SearchInputProps}
|