@primer/react 34.0.0 → 34.0.1
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/browser.esm.js +2 -2
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +2 -2
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Item.js +3 -3
- package/lib/ActionList/List.js +2 -2
- package/lib/ActionList2/Selection.js +0 -1
- package/lib/ActionMenu2.d.ts +0 -2
- package/lib/ActionMenu2.js +1 -3
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
- package/lib/Autocomplete/Autocomplete.d.ts +12 -3
- package/lib/Autocomplete/AutocompleteInput.d.ts +12 -3
- package/lib/Autocomplete/AutocompleteMenu.js +10 -5
- package/lib/Dialog/ConfirmationDialog.js +2 -2
- package/lib/Dialog/Dialog.js +2 -2
- package/lib/FilteredActionList/FilteredActionList.js +10 -3
- package/lib/NewButton/button-base.d.ts +6 -0
- package/lib/NewButton/button-base.js +69 -0
- package/lib/NewButton/button-link.d.ts +27 -0
- package/lib/NewButton/button-link.js +31 -0
- package/lib/NewButton/button.d.ts +2 -11
- package/lib/NewButton/button.js +6 -283
- package/lib/NewButton/icon-button.d.ts +4 -0
- package/lib/NewButton/icon-button.js +62 -0
- package/lib/NewButton/index.d.ts +6 -11
- package/lib/NewButton/index.js +18 -0
- package/lib/NewButton/styles.d.ts +204 -0
- package/lib/NewButton/styles.js +249 -0
- package/lib/NewButton/types.d.ts +28 -8
- package/lib/NewButton/types.js +19 -1
- package/lib/Overlay.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +12 -3
- package/lib/TextInput.d.ts +8 -1
- package/lib/TextInput.js +19 -6
- package/lib/TextInputWithTokens.d.ts +12 -3
- package/lib/TextInputWithTokens.js +14 -11
- package/lib/_TextInputWrapper.d.ts +6 -1
- package/lib/_TextInputWrapper.js +21 -8
- package/lib/hooks/useAnchoredPosition.d.ts +1 -1
- package/lib/hooks/useAnchoredPosition.js +2 -2
- package/lib/hooks/useFocusTrap.js +2 -2
- package/lib/hooks/useFocusZone.d.ts +3 -1
- package/lib/hooks/useFocusZone.js +8 -2
- package/lib/hooks/useOpenAndCloseFocus.js +2 -2
- package/lib-esm/ActionList/Item.js +1 -1
- package/lib-esm/ActionList/List.js +1 -1
- package/lib-esm/ActionList2/Selection.js +0 -1
- package/lib-esm/ActionMenu2.d.ts +0 -2
- package/lib-esm/ActionMenu2.js +1 -1
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +1 -1
- package/lib-esm/Autocomplete/Autocomplete.d.ts +12 -3
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +12 -3
- package/lib-esm/Autocomplete/AutocompleteMenu.js +9 -4
- package/lib-esm/Dialog/ConfirmationDialog.js +1 -1
- package/lib-esm/Dialog/Dialog.js +1 -1
- package/lib-esm/FilteredActionList/FilteredActionList.js +9 -3
- package/lib-esm/NewButton/button-base.d.ts +6 -0
- package/lib-esm/NewButton/button-base.js +47 -0
- package/lib-esm/NewButton/button-link.d.ts +27 -0
- package/lib-esm/NewButton/button-link.js +15 -0
- package/lib-esm/NewButton/button.d.ts +2 -11
- package/lib-esm/NewButton/button.js +4 -275
- package/lib-esm/NewButton/icon-button.d.ts +4 -0
- package/lib-esm/NewButton/icon-button.js +39 -0
- package/lib-esm/NewButton/index.d.ts +6 -11
- package/lib-esm/NewButton/index.js +4 -1
- package/lib-esm/NewButton/styles.d.ts +204 -0
- package/lib-esm/NewButton/styles.js +230 -0
- package/lib-esm/NewButton/types.d.ts +28 -8
- package/lib-esm/NewButton/types.js +6 -1
- package/lib-esm/Overlay.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +12 -3
- package/lib-esm/TextInput.d.ts +8 -1
- package/lib-esm/TextInput.js +19 -6
- package/lib-esm/TextInputWithTokens.d.ts +12 -3
- package/lib-esm/TextInputWithTokens.js +12 -9
- package/lib-esm/_TextInputWrapper.d.ts +6 -1
- package/lib-esm/_TextInputWrapper.js +19 -7
- package/lib-esm/hooks/useAnchoredPosition.d.ts +1 -1
- package/lib-esm/hooks/useAnchoredPosition.js +1 -1
- package/lib-esm/hooks/useFocusTrap.js +1 -1
- package/lib-esm/hooks/useFocusZone.d.ts +3 -1
- package/lib-esm/hooks/useFocusZone.js +2 -1
- package/lib-esm/hooks/useOpenAndCloseFocus.js +1 -1
- package/package.json +6 -10
- package/lib/behaviors/anchoredPosition.d.ts +0 -89
- package/lib/behaviors/anchoredPosition.js +0 -316
- package/lib/behaviors/focusTrap.d.ts +0 -12
- package/lib/behaviors/focusTrap.js +0 -179
- package/lib/behaviors/focusZone.d.ts +0 -137
- package/lib/behaviors/focusZone.js +0 -578
- package/lib/behaviors/scrollIntoViewingArea.d.ts +0 -1
- package/lib/behaviors/scrollIntoViewingArea.js +0 -39
- package/lib/utils/iterateFocusableElements.d.ts +0 -42
- package/lib/utils/iterateFocusableElements.js +0 -113
- package/lib/utils/uniqueId.d.ts +0 -1
- package/lib/utils/uniqueId.js +0 -12
- package/lib/utils/userAgent.d.ts +0 -1
- package/lib/utils/userAgent.js +0 -15
- package/lib-esm/behaviors/anchoredPosition.d.ts +0 -89
- package/lib-esm/behaviors/anchoredPosition.js +0 -309
- package/lib-esm/behaviors/focusTrap.d.ts +0 -12
- package/lib-esm/behaviors/focusTrap.js +0 -170
- package/lib-esm/behaviors/focusZone.d.ts +0 -137
- package/lib-esm/behaviors/focusZone.js +0 -560
- package/lib-esm/behaviors/scrollIntoViewingArea.d.ts +0 -1
- package/lib-esm/behaviors/scrollIntoViewingArea.js +0 -30
- package/lib-esm/utils/iterateFocusableElements.d.ts +0 -42
- package/lib-esm/utils/iterateFocusableElements.js +0 -102
- package/lib-esm/utils/uniqueId.d.ts +0 -1
- package/lib-esm/utils/uniqueId.js +0 -5
- package/lib-esm/utils/userAgent.d.ts +0 -1
- package/lib-esm/utils/userAgent.js +0 -8
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
export const TEXT_ROW_HEIGHT = '20px'; // custom value off the scale
|
|
2
|
+
|
|
3
|
+
export const getVariantStyles = (variant = 'default', theme) => {
|
|
4
|
+
const style = {
|
|
5
|
+
default: {
|
|
6
|
+
color: 'btn.text',
|
|
7
|
+
backgroundColor: 'btn.bg',
|
|
8
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadow}, ${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.insetShadow}`,
|
|
9
|
+
'&:hover:not([disabled])': {
|
|
10
|
+
backgroundColor: 'btn.hoverBg'
|
|
11
|
+
},
|
|
12
|
+
// focus must come before :active so that the active box shadow overrides
|
|
13
|
+
'&:focus:not([disabled])': {
|
|
14
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.focusShadow}`
|
|
15
|
+
},
|
|
16
|
+
'&:active:not([disabled])': {
|
|
17
|
+
backgroundColor: 'btn.selectedBg',
|
|
18
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadowActive}`
|
|
19
|
+
},
|
|
20
|
+
'&:disabled': {
|
|
21
|
+
color: 'primer.fg.disabled',
|
|
22
|
+
backgroundColor: 'btn.disabledBg'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
primary: {
|
|
26
|
+
color: 'btn.primary.text',
|
|
27
|
+
backgroundColor: 'btn.primary.bg',
|
|
28
|
+
borderColor: 'border.subtle',
|
|
29
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.primary.shadow}`,
|
|
30
|
+
'&:hover:not([disabled])': {
|
|
31
|
+
color: 'btn.primary.hoverText',
|
|
32
|
+
backgroundColor: 'btn.primary.hoverBg'
|
|
33
|
+
},
|
|
34
|
+
// focus must come before :active so that the active box shadow overrides
|
|
35
|
+
'&:focus:not([disabled])': {
|
|
36
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.primary.focusShadow}`
|
|
37
|
+
},
|
|
38
|
+
'&:active:not([disabled])': {
|
|
39
|
+
backgroundColor: 'btn.primary.selectedBg',
|
|
40
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.primary.selectedShadow}`
|
|
41
|
+
},
|
|
42
|
+
'&:disabled': {
|
|
43
|
+
color: 'btn.primary.disabledText',
|
|
44
|
+
backgroundColor: 'btn.primary.disabledBg'
|
|
45
|
+
},
|
|
46
|
+
'[data-component="ButtonCounter"]': {
|
|
47
|
+
backgroundColor: 'btn.primary.counterBg',
|
|
48
|
+
color: 'btn.primary.text'
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
danger: {
|
|
52
|
+
color: 'btn.danger.text',
|
|
53
|
+
backgroundColor: 'btn.bg',
|
|
54
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadow}`,
|
|
55
|
+
'&:hover:not([disabled])': {
|
|
56
|
+
color: 'btn.danger.hoverText',
|
|
57
|
+
backgroundColor: 'btn.danger.hoverBg',
|
|
58
|
+
borderColor: 'btn.danger.hoverBorder',
|
|
59
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.danger.hoverShadow}`,
|
|
60
|
+
'[data-component="ButtonCounter"]': {
|
|
61
|
+
backgroundColor: 'btn.danger.hoverCounterBg',
|
|
62
|
+
color: 'btn.danger.hoverText'
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
// focus must come before :active so that the active box shadow overrides
|
|
66
|
+
'&:focus:not([disabled])': {
|
|
67
|
+
borderColor: 'btn.danger.focusBorder',
|
|
68
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.danger.focusShadow}`
|
|
69
|
+
},
|
|
70
|
+
'&:active:not([disabled])': {
|
|
71
|
+
color: 'btn.danger.selectedText',
|
|
72
|
+
backgroundColor: 'btn.danger.selectedBg',
|
|
73
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.danger.selectedShadow}`,
|
|
74
|
+
borderColor: 'btn.danger.selectedBorder'
|
|
75
|
+
},
|
|
76
|
+
'&:disabled': {
|
|
77
|
+
color: 'btn.danger.disabledText',
|
|
78
|
+
backgroundColor: 'btn.danger.disabledBg',
|
|
79
|
+
borderColor: 'btn.danger.disabledBorder',
|
|
80
|
+
'[data-component="ButtonCounter"]': {
|
|
81
|
+
backgroundColor: 'btn.danger.disabledCounterBg'
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
'[data-component="ButtonCounter"]': {
|
|
85
|
+
color: 'btn.danger.text',
|
|
86
|
+
backgroundColor: 'btn.danger.counterBg'
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
invisible: {
|
|
90
|
+
color: 'accent.fg',
|
|
91
|
+
backgroundColor: 'transparent',
|
|
92
|
+
border: '0',
|
|
93
|
+
boxShadow: 'none',
|
|
94
|
+
'&:hover:not([disabled])': {
|
|
95
|
+
backgroundColor: 'btn.hoverBg'
|
|
96
|
+
},
|
|
97
|
+
// focus must come before :active so that the active box shadow overrides
|
|
98
|
+
'&:focus:not([disabled])': {
|
|
99
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.focusShadow}`
|
|
100
|
+
},
|
|
101
|
+
'&:active:not([disabled])': {
|
|
102
|
+
backgroundColor: 'btn.selectedBg'
|
|
103
|
+
},
|
|
104
|
+
'&:disabled': {
|
|
105
|
+
color: 'primer.fg.disabled'
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
outline: {
|
|
109
|
+
color: 'btn.outline.text',
|
|
110
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.shadow}`,
|
|
111
|
+
'&:hover:not([disabled])': {
|
|
112
|
+
color: 'btn.outline.hoverText',
|
|
113
|
+
backgroundColor: 'btn.outline.hoverBg',
|
|
114
|
+
borderColor: 'outline.hoverBorder',
|
|
115
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.hoverShadow}`,
|
|
116
|
+
'[data-component="ButtonCounter"]': {
|
|
117
|
+
backgroundColor: 'btn.outline.hoverCounterBg',
|
|
118
|
+
color: 'btn.outline.hoverText'
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
// focus must come before :active so that the active box shadow overrides
|
|
122
|
+
'&:focus:not([disabled])': {
|
|
123
|
+
borderColor: 'btn.outline.focusBorder',
|
|
124
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.focusShadow}`
|
|
125
|
+
},
|
|
126
|
+
'&:active:not([disabled])': {
|
|
127
|
+
color: 'btn.outline.selectedText',
|
|
128
|
+
backgroundColor: 'btn.outline.selectedBg',
|
|
129
|
+
boxShadow: `${theme === null || theme === void 0 ? void 0 : theme.shadows.btn.outline.selectedShadow}`,
|
|
130
|
+
borderColor: 'btn.outline.selectedBorder'
|
|
131
|
+
},
|
|
132
|
+
'&:disabled': {
|
|
133
|
+
color: 'btn.outline.disabledText',
|
|
134
|
+
backgroundColor: 'btn.outline.disabledBg',
|
|
135
|
+
borderColor: 'btn.border',
|
|
136
|
+
'[data-component="ButtonCounter"]': {
|
|
137
|
+
backgroundColor: 'btn.outline.disabledCounterBg'
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
'[data-component="ButtonCounter"]': {
|
|
141
|
+
backgroundColor: 'btn.outline.counterBg',
|
|
142
|
+
color: 'btn.outline.text'
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
return style[variant];
|
|
147
|
+
};
|
|
148
|
+
export const getSizeStyles = (size = 'medium', variant = 'default', iconOnly) => {
|
|
149
|
+
let paddingY, paddingX, fontSize;
|
|
150
|
+
|
|
151
|
+
switch (size) {
|
|
152
|
+
case 'small':
|
|
153
|
+
paddingY = 3;
|
|
154
|
+
paddingX = 12;
|
|
155
|
+
fontSize = 0;
|
|
156
|
+
break;
|
|
157
|
+
|
|
158
|
+
case 'large':
|
|
159
|
+
paddingY = 9;
|
|
160
|
+
paddingX = 20;
|
|
161
|
+
fontSize = 2;
|
|
162
|
+
break;
|
|
163
|
+
|
|
164
|
+
case 'medium':
|
|
165
|
+
default:
|
|
166
|
+
paddingY = 5;
|
|
167
|
+
paddingX = 16;
|
|
168
|
+
fontSize = 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (iconOnly) {
|
|
172
|
+
paddingX = paddingY + 2;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (variant === 'invisible') {
|
|
176
|
+
paddingY = paddingY + 1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
paddingY: `${paddingY}px`,
|
|
181
|
+
paddingX: `${paddingX}px`,
|
|
182
|
+
fontSize,
|
|
183
|
+
'[data-component="ButtonCounter"]': {
|
|
184
|
+
fontSize
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
export const getBaseStyles = theme => ({
|
|
189
|
+
borderRadius: '2',
|
|
190
|
+
border: '1px solid',
|
|
191
|
+
borderColor: theme === null || theme === void 0 ? void 0 : theme.colors.btn.border,
|
|
192
|
+
fontFamily: 'inherit',
|
|
193
|
+
fontWeight: 'bold',
|
|
194
|
+
lineHeight: TEXT_ROW_HEIGHT,
|
|
195
|
+
whiteSpace: 'nowrap',
|
|
196
|
+
verticalAlign: 'middle',
|
|
197
|
+
cursor: 'pointer',
|
|
198
|
+
appearance: 'none',
|
|
199
|
+
userSelect: 'none',
|
|
200
|
+
textDecoration: 'none',
|
|
201
|
+
textAlign: 'center',
|
|
202
|
+
'&:focus': {
|
|
203
|
+
outline: 'none'
|
|
204
|
+
},
|
|
205
|
+
'&:disabled': {
|
|
206
|
+
cursor: 'default'
|
|
207
|
+
},
|
|
208
|
+
'&:disabled svg': {
|
|
209
|
+
opacity: '0.6'
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
export const getButtonStyles = theme => {
|
|
213
|
+
const styles = { ...getBaseStyles(theme),
|
|
214
|
+
display: 'grid',
|
|
215
|
+
gridTemplateAreas: '"leadingIcon text trailingIcon"',
|
|
216
|
+
'& > :not(:last-child)': {
|
|
217
|
+
mr: '2'
|
|
218
|
+
},
|
|
219
|
+
'[data-component="leadingIcon"]': {
|
|
220
|
+
gridArea: 'leadingIcon'
|
|
221
|
+
},
|
|
222
|
+
'[data-component="text"]': {
|
|
223
|
+
gridArea: 'text'
|
|
224
|
+
},
|
|
225
|
+
'[data-component="trailingIcon"]': {
|
|
226
|
+
gridArea: 'trailingIcon'
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
return styles;
|
|
230
|
+
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from 'react';
|
|
1
|
+
import React, { HTMLAttributes, ComponentPropsWithRef } from 'react';
|
|
2
2
|
import { IconProps } from '@primer/octicons-react';
|
|
3
3
|
import { SxProp } from '../sx';
|
|
4
|
+
export declare const StyledButton: import("styled-components").StyledComponent<"button", any, SxProp, never>;
|
|
4
5
|
export declare type VariantType = 'default' | 'primary' | 'invisible' | 'danger' | 'outline';
|
|
5
6
|
export declare type Size = 'small' | 'medium' | 'large';
|
|
6
|
-
|
|
7
|
+
declare type StyledButtonProps = ComponentPropsWithRef<typeof StyledButton>;
|
|
8
|
+
export declare type ButtonBaseProps = {
|
|
7
9
|
/**
|
|
8
10
|
* Determine's the styles on a button one of 'default' | 'primary' | 'invisible' | 'danger'
|
|
9
11
|
*/
|
|
@@ -13,9 +15,11 @@ export declare type ButtonProps = {
|
|
|
13
15
|
*/
|
|
14
16
|
size?: Size;
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
18
|
+
* Items that are disabled can not be clicked, selected, or navigated through.
|
|
17
19
|
*/
|
|
18
|
-
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
} & SxProp & HTMLAttributes<HTMLButtonElement> & StyledButtonProps;
|
|
22
|
+
export declare type ButtonProps = {
|
|
19
23
|
/**
|
|
20
24
|
* The leading icon comes before button content
|
|
21
25
|
*/
|
|
@@ -24,9 +28,25 @@ export declare type ButtonProps = {
|
|
|
24
28
|
* The trailing icon comes after button content
|
|
25
29
|
*/
|
|
26
30
|
trailingIcon?: React.FunctionComponent<IconProps>;
|
|
31
|
+
children: React.ReactNode;
|
|
32
|
+
} & ButtonBaseProps;
|
|
33
|
+
export declare type IconButtonProps = {
|
|
27
34
|
/**
|
|
28
|
-
*
|
|
35
|
+
* This is to be used if it is an icon-only button. Will make text visually hidden
|
|
29
36
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} &
|
|
37
|
+
icon: React.FunctionComponent<IconProps>;
|
|
38
|
+
iconLabel: string;
|
|
39
|
+
} & ButtonBaseProps;
|
|
40
|
+
export declare type LinkButtonProps = {
|
|
41
|
+
underline?: boolean;
|
|
42
|
+
download?: string;
|
|
43
|
+
href?: string;
|
|
44
|
+
hrefLang?: string;
|
|
45
|
+
media?: string;
|
|
46
|
+
ping?: string;
|
|
47
|
+
rel?: string;
|
|
48
|
+
target?: string;
|
|
49
|
+
type?: string;
|
|
50
|
+
referrerPolicy?: React.AnchorHTMLAttributes<HTMLAnchorElement>['referrerPolicy'];
|
|
51
|
+
};
|
|
52
|
+
export {};
|
package/lib-esm/Overlay.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React, { ComponentPropsWithRef } from 'react';
|
|
|
2
2
|
import { AriaRole, Merge } from './utils/types';
|
|
3
3
|
import { TouchOrMouseEvent } from './hooks';
|
|
4
4
|
import { SxProp } from './sx';
|
|
5
|
-
import { AnchorSide } from '
|
|
5
|
+
import type { AnchorSide } from '@primer/behaviors';
|
|
6
6
|
import { ForwardRefComponent as PolymorphicForwardRefComponent } from '@radix-ui/react-polymorphic';
|
|
7
7
|
declare type StyledOverlayProps = {
|
|
8
8
|
width?: keyof typeof widthMap;
|
|
@@ -40,11 +40,17 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
|
40
40
|
} & {
|
|
41
41
|
as?: string | React.ComponentType<any> | undefined;
|
|
42
42
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
|
43
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "
|
|
43
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "size" | "block" | "icon" | "variant" | "sx" | "className" | "disabled" | "leadingVisual" | "trailingVisual" | "contrast"> & {
|
|
44
44
|
className?: string | undefined;
|
|
45
45
|
icon?: React.ComponentType<{
|
|
46
46
|
className?: string | undefined;
|
|
47
47
|
}> | undefined;
|
|
48
|
+
leadingVisual?: string | React.ComponentType<{
|
|
49
|
+
className?: string | undefined;
|
|
50
|
+
}> | undefined;
|
|
51
|
+
trailingVisual?: string | React.ComponentType<{
|
|
52
|
+
className?: string | undefined;
|
|
53
|
+
}> | undefined;
|
|
48
54
|
} & Pick<{
|
|
49
55
|
color?: string | undefined;
|
|
50
56
|
property?: string | undefined;
|
|
@@ -58,6 +64,7 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
|
58
64
|
slot?: string | undefined;
|
|
59
65
|
style?: React.CSSProperties | undefined;
|
|
60
66
|
title?: string | undefined;
|
|
67
|
+
size?: "small" | "large" | undefined;
|
|
61
68
|
block?: boolean | undefined;
|
|
62
69
|
variant?: "small" | "large" | undefined;
|
|
63
70
|
role?: React.AriaRole | undefined;
|
|
@@ -312,11 +319,13 @@ declare const _default: React.ForwardRefExoticComponent<Pick<SelectMenuInternalP
|
|
|
312
319
|
onTransitionEndCapture?: React.TransitionEventHandler<HTMLSpanElement> | undefined;
|
|
313
320
|
css?: import("@emotion/core").InterpolationWithTheme<any>;
|
|
314
321
|
disabled?: boolean | undefined;
|
|
315
|
-
|
|
322
|
+
validationStatus?: "error" | "warning" | undefined;
|
|
323
|
+
hasLeadingVisual?: boolean | undefined;
|
|
324
|
+
hasTrailingVisual?: boolean | undefined;
|
|
316
325
|
contrast?: boolean | undefined;
|
|
317
326
|
} & {
|
|
318
327
|
theme?: any;
|
|
319
|
-
}, "maxWidth" | "minWidth" | "width" | "
|
|
328
|
+
}, "maxWidth" | "minWidth" | "width" | "size" | "block" | "variant" | "sx" | "disabled" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement>, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
|
320
329
|
Footer: import("styled-components").StyledComponent<"footer", any, SxProp, never>;
|
|
321
330
|
Item: React.ForwardRefExoticComponent<Pick<{
|
|
322
331
|
as?: React.ElementType<any> | undefined;
|
package/lib-esm/TextInput.d.ts
CHANGED
|
@@ -4,10 +4,17 @@ import UnstyledTextInput from './_UnstyledTextInput';
|
|
|
4
4
|
import TextInputWrapper from './_TextInputWrapper';
|
|
5
5
|
declare type NonPassthroughProps = {
|
|
6
6
|
className?: string;
|
|
7
|
+
/** @deprecated Use `leadingVisual` or `trailingVisual` prop instead */
|
|
7
8
|
icon?: React.ComponentType<{
|
|
8
9
|
className?: string;
|
|
9
10
|
}>;
|
|
10
|
-
|
|
11
|
+
leadingVisual?: string | React.ComponentType<{
|
|
12
|
+
className?: string;
|
|
13
|
+
}>;
|
|
14
|
+
trailingVisual?: string | React.ComponentType<{
|
|
15
|
+
className?: string;
|
|
16
|
+
}>;
|
|
17
|
+
} & Pick<ComponentProps<typeof TextInputWrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'width' | 'maxWidth' | 'minWidth' | 'variant' | 'size'>;
|
|
11
18
|
declare type TextInputInternalProps = Merge<React.ComponentPropsWithoutRef<typeof UnstyledTextInput>, NonPassthroughProps>;
|
|
12
19
|
declare const TextInput: React.ForwardRefExoticComponent<Pick<TextInputInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
|
13
20
|
export declare type TextInputProps = ComponentProps<typeof TextInput>;
|
package/lib-esm/TextInput.js
CHANGED
|
@@ -7,16 +7,21 @@ import TextInputWrapper from './_TextInputWrapper';
|
|
|
7
7
|
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
|
|
8
8
|
const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
9
9
|
icon: IconComponent,
|
|
10
|
+
leadingVisual: LeadingVisual,
|
|
11
|
+
trailingVisual: TrailingVisual,
|
|
10
12
|
block,
|
|
11
13
|
className,
|
|
12
14
|
contrast,
|
|
13
15
|
disabled,
|
|
16
|
+
validationStatus,
|
|
14
17
|
sx: sxProp,
|
|
15
|
-
|
|
18
|
+
size: sizeProp,
|
|
19
|
+
// start deprecated props
|
|
16
20
|
width: widthProp,
|
|
17
21
|
minWidth: minWidthProp,
|
|
18
22
|
maxWidth: maxWidthProp,
|
|
19
23
|
variant: variantProp,
|
|
24
|
+
// end deprecated props
|
|
20
25
|
...inputProps
|
|
21
26
|
}, ref) => {
|
|
22
27
|
// this class is necessary to style FilterSearch, plz no touchy!
|
|
@@ -24,21 +29,29 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
|
24
29
|
return /*#__PURE__*/React.createElement(TextInputWrapper, {
|
|
25
30
|
block: block,
|
|
26
31
|
className: wrapperClasses,
|
|
32
|
+
validationStatus: validationStatus,
|
|
27
33
|
contrast: contrast,
|
|
28
34
|
disabled: disabled,
|
|
29
|
-
hasIcon: !!IconComponent,
|
|
30
35
|
sx: sxProp,
|
|
31
|
-
|
|
36
|
+
size: sizeProp,
|
|
32
37
|
width: widthProp,
|
|
33
38
|
minWidth: minWidthProp,
|
|
34
39
|
maxWidth: maxWidthProp,
|
|
35
|
-
variant: variantProp
|
|
40
|
+
variant: variantProp,
|
|
41
|
+
hasLeadingVisual: Boolean(LeadingVisual),
|
|
42
|
+
hasTrailingVisual: Boolean(TrailingVisual)
|
|
36
43
|
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
|
37
44
|
className: "TextInput-icon"
|
|
38
|
-
}), /*#__PURE__*/React.createElement(
|
|
45
|
+
}), LeadingVisual && /*#__PURE__*/React.createElement("span", {
|
|
46
|
+
className: "TextInput-icon"
|
|
47
|
+
}, typeof LeadingVisual === 'function' ? /*#__PURE__*/React.createElement(LeadingVisual, null) : LeadingVisual), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
|
39
48
|
ref: ref,
|
|
40
49
|
disabled: disabled
|
|
41
|
-
}, inputProps
|
|
50
|
+
}, inputProps, {
|
|
51
|
+
"data-component": "input"
|
|
52
|
+
})), TrailingVisual && /*#__PURE__*/React.createElement("span", {
|
|
53
|
+
className: "TextInput-icon"
|
|
54
|
+
}, typeof TrailingVisual === 'function' ? /*#__PURE__*/React.createElement(TrailingVisual, null) : TrailingVisual));
|
|
42
55
|
});
|
|
43
56
|
TextInput.defaultProps = {
|
|
44
57
|
type: 'text'
|
|
@@ -45,11 +45,17 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
|
|
|
45
45
|
} & {
|
|
46
46
|
as?: string | React.ComponentType<any> | undefined;
|
|
47
47
|
forwardedAs?: string | React.ComponentType<any> | undefined;
|
|
48
|
-
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "
|
|
48
|
+
}, string | number | symbol>, "maxWidth" | "minWidth" | "width" | "size" | "block" | "icon" | "variant" | "sx" | "className" | "disabled" | "leadingVisual" | "trailingVisual" | "contrast"> & {
|
|
49
49
|
className?: string | undefined;
|
|
50
50
|
icon?: React.ComponentType<{
|
|
51
51
|
className?: string | undefined;
|
|
52
52
|
}> | undefined;
|
|
53
|
+
leadingVisual?: string | React.ComponentType<{
|
|
54
|
+
className?: string | undefined;
|
|
55
|
+
}> | undefined;
|
|
56
|
+
trailingVisual?: string | React.ComponentType<{
|
|
57
|
+
className?: string | undefined;
|
|
58
|
+
}> | undefined;
|
|
53
59
|
} & Pick<{
|
|
54
60
|
color?: string | undefined;
|
|
55
61
|
property?: string | undefined;
|
|
@@ -63,6 +69,7 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
|
|
|
63
69
|
slot?: string | undefined;
|
|
64
70
|
style?: React.CSSProperties | undefined;
|
|
65
71
|
title?: string | undefined;
|
|
72
|
+
size?: "small" | "large" | undefined;
|
|
66
73
|
block?: boolean | undefined;
|
|
67
74
|
variant?: "small" | "large" | undefined;
|
|
68
75
|
role?: React.AriaRole | undefined;
|
|
@@ -317,11 +324,13 @@ declare const TextInputWithTokens: React.ForwardRefExoticComponent<Pick<{
|
|
|
317
324
|
onTransitionEndCapture?: React.TransitionEventHandler<HTMLSpanElement> | undefined;
|
|
318
325
|
css?: import("@emotion/core").InterpolationWithTheme<any>;
|
|
319
326
|
disabled?: boolean | undefined;
|
|
320
|
-
|
|
327
|
+
validationStatus?: "error" | "warning" | undefined;
|
|
328
|
+
hasLeadingVisual?: boolean | undefined;
|
|
329
|
+
hasTrailingVisual?: boolean | undefined;
|
|
321
330
|
contrast?: boolean | undefined;
|
|
322
331
|
} & {
|
|
323
332
|
theme?: any;
|
|
324
|
-
}, "maxWidth" | "minWidth" | "width" | "
|
|
333
|
+
}, "maxWidth" | "minWidth" | "width" | "size" | "block" | "variant" | "sx" | "disabled" | "contrast">, string | number | symbol> & React.RefAttributes<HTMLInputElement> & {
|
|
325
334
|
selectedTokenIndex: number | undefined;
|
|
326
335
|
setSelectedTokenIndex: React.Dispatch<React.SetStateAction<number | undefined>>;
|
|
327
336
|
}, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -2,16 +2,16 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
2
2
|
|
|
3
3
|
import React, { useRef, useState } from 'react';
|
|
4
4
|
import { omit } from '@styled-system/props';
|
|
5
|
-
import { FocusKeys } from '
|
|
5
|
+
import { FocusKeys } from '@primer/behaviors';
|
|
6
6
|
import { useCombinedRefs } from './hooks/useCombinedRefs';
|
|
7
7
|
import { useFocusZone } from './hooks/useFocusZone';
|
|
8
8
|
import Token from './Token/Token';
|
|
9
9
|
import { useProvidedRefOrCreate } from './hooks';
|
|
10
10
|
import UnstyledTextInput from './_UnstyledTextInput';
|
|
11
|
-
import TextInputWrapper from './_TextInputWrapper';
|
|
11
|
+
import TextInputWrapper, { textInputHorizPadding } from './_TextInputWrapper';
|
|
12
12
|
import Box from './Box';
|
|
13
13
|
import Text from './Text';
|
|
14
|
-
import { isFocusable } from '
|
|
14
|
+
import { isFocusable } from '@primer/behaviors/utils'; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
15
|
|
|
16
16
|
const overflowCountFontSizeMap = {
|
|
17
17
|
small: 0,
|
|
@@ -205,14 +205,17 @@ function TextInputWithTokensInnerComponent({
|
|
|
205
205
|
className: className,
|
|
206
206
|
contrast: contrast,
|
|
207
207
|
disabled: disabled,
|
|
208
|
-
|
|
208
|
+
hasLeadingVisual: Boolean(IconComponent),
|
|
209
209
|
theme: theme,
|
|
210
210
|
width: widthProp,
|
|
211
211
|
minWidth: minWidthProp,
|
|
212
212
|
maxWidth: maxWidthProp,
|
|
213
213
|
variant: variantProp,
|
|
214
214
|
onClick: focusInput,
|
|
215
|
-
sx: {
|
|
215
|
+
sx: {
|
|
216
|
+
paddingLeft: textInputHorizPadding,
|
|
217
|
+
py: `calc(${textInputHorizPadding} / 2)`,
|
|
218
|
+
...(block ? {
|
|
216
219
|
display: 'flex',
|
|
217
220
|
width: '100%'
|
|
218
221
|
} : {}),
|
|
@@ -240,14 +243,14 @@ function TextInputWithTokensInnerComponent({
|
|
|
240
243
|
marginBottom: '0.25rem'
|
|
241
244
|
}
|
|
242
245
|
}
|
|
243
|
-
}, /*#__PURE__*/React.createElement(
|
|
246
|
+
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
|
247
|
+
className: "TextInput-icon"
|
|
248
|
+
}), /*#__PURE__*/React.createElement(Box, {
|
|
244
249
|
sx: {
|
|
245
250
|
order: 1,
|
|
246
251
|
flexGrow: 1
|
|
247
252
|
}
|
|
248
|
-
},
|
|
249
|
-
className: "TextInput-icon"
|
|
250
|
-
}), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
|
253
|
+
}, /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
|
251
254
|
ref: combinedInputRef,
|
|
252
255
|
disabled: disabled,
|
|
253
256
|
onFocus: handleInputFocus,
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
|
2
2
|
import { SxProp } from './sx';
|
|
3
|
+
export declare const textInputHorizPadding = "12px";
|
|
3
4
|
declare const TextInputWrapper: import("styled-components").StyledComponent<"span", any, {
|
|
4
5
|
disabled?: boolean | undefined;
|
|
5
|
-
|
|
6
|
+
hasLeadingVisual?: boolean | undefined;
|
|
7
|
+
hasTrailingVisual?: boolean | undefined;
|
|
6
8
|
block?: boolean | undefined;
|
|
7
9
|
contrast?: boolean | undefined;
|
|
10
|
+
validationStatus?: "error" | "warning" | undefined;
|
|
11
|
+
/** @deprecated Use `size` prop instead */
|
|
8
12
|
variant?: "small" | "large" | undefined;
|
|
13
|
+
size?: "small" | "large" | undefined;
|
|
9
14
|
} & WidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Width<import("styled-system").TLengthStyledSystem>> & MinWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MinWidth<import("styled-system").TLengthStyledSystem>> & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
|
|
10
15
|
export default TextInputWrapper;
|
|
@@ -2,7 +2,24 @@ import styled, { css } from 'styled-components';
|
|
|
2
2
|
import { maxWidth, minWidth, variant, width } from 'styled-system';
|
|
3
3
|
import { get } from './constants';
|
|
4
4
|
import sx from './sx';
|
|
5
|
+
const sizeDeprecatedVariants = variant({
|
|
6
|
+
variants: {
|
|
7
|
+
small: {
|
|
8
|
+
minHeight: '28px',
|
|
9
|
+
px: 2,
|
|
10
|
+
py: '3px',
|
|
11
|
+
fontSize: 0,
|
|
12
|
+
lineHeight: '20px'
|
|
13
|
+
},
|
|
14
|
+
large: {
|
|
15
|
+
px: 2,
|
|
16
|
+
py: '10px',
|
|
17
|
+
fontSize: 3
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
5
21
|
const sizeVariants = variant({
|
|
22
|
+
prop: 'size',
|
|
6
23
|
variants: {
|
|
7
24
|
small: {
|
|
8
25
|
minHeight: '28px',
|
|
@@ -18,14 +35,9 @@ const sizeVariants = variant({
|
|
|
18
35
|
}
|
|
19
36
|
}
|
|
20
37
|
});
|
|
38
|
+
export const textInputHorizPadding = '12px';
|
|
21
39
|
const TextInputWrapper = styled.span.withConfig({
|
|
22
40
|
displayName: "_TextInputWrapper__TextInputWrapper",
|
|
23
41
|
componentId: "sc-apywy2-0"
|
|
24
|
-
})(["
|
|
25
|
-
if (props.hasIcon) {
|
|
26
|
-
return css(["padding:0;"]);
|
|
27
|
-
} else {
|
|
28
|
-
return css(["padding:6px 12px;"]);
|
|
29
|
-
}
|
|
30
|
-
}, get('colors.fg.muted'), get('space.2'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.primer.fg.disabled'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), props => props.block && props.hasIcon && css(["display:flex;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx);
|
|
42
|
+
})(["min-height:32px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-color:", ";background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";cursor:text;display:inline-flex;align-items:stretch;& >:not(:last-child){margin-right:", ";}", " .TextInput-icon{align-self:center;color:", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.canvas.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), get('space.2'), props => css(["padding-left:", ";padding-right:", ";> input{padding-left:", ";padding-right:", ";}"], props.hasLeadingVisual ? textInputHorizPadding : 0, props.hasTrailingVisual ? textInputHorizPadding : 0, !props.hasLeadingVisual ? textInputHorizPadding : 0, !props.hasTrailingVisual ? textInputHorizPadding : 0), get('colors.fg.muted'), get('colors.accent.emphasis'), get('shadows.primer.shadow.focus'), props => props.contrast && css(["background-color:", ";"], get('colors.canvas.inset')), props => props.disabled && css(["color:", ";background-color:", ";border-color:", ";"], get('colors.primer.fg.disabled'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.validationStatus === 'error' && css(["border-color:", ";&:focus-within{border-color:", ";box-shadow:", ";}"], get('colors.danger.emphasis'), get('colors.danger.emphasis'), get('shadows.btn.danger.focusShadow')), props => props.validationStatus === 'warning' && css(["border-color:", ";&:focus-within{border-color:", ";box-shadow:0 0 0 3px ", ";}"], get('colors.attention.emphasis'), get('colors.attention.emphasis'), get('colors.attention.muted')), props => props.block && css(["width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeDeprecatedVariants, sizeVariants, sx);
|
|
31
43
|
export default TextInputWrapper;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import type { AnchorPosition, PositionSettings } from '@primer/behaviors';
|
|
3
3
|
export interface AnchoredPositionHookSettings extends Partial<PositionSettings> {
|
|
4
4
|
floatingElementRef?: React.RefObject<Element>;
|
|
5
5
|
anchorElementRef?: React.RefObject<Element>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { getAnchoredPosition } from '
|
|
2
|
+
import { getAnchoredPosition } from '@primer/behaviors';
|
|
3
3
|
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
|
4
4
|
import { useResizeObserver } from './useResizeObserver';
|
|
5
5
|
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FocusZoneSettings } from '
|
|
2
|
+
import type { FocusZoneSettings } from '@primer/behaviors';
|
|
3
|
+
export { FocusKeys } from '@primer/behaviors';
|
|
4
|
+
export type { Direction } from '@primer/behaviors';
|
|
3
5
|
export interface FocusZoneHookSettings extends Omit<FocusZoneSettings, 'activeDescendantControl'> {
|
|
4
6
|
/**
|
|
5
7
|
* Optional ref for the container that holds all elements participating in arrow key focus.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useEffect } from 'react';
|
|
2
|
-
import { focusZone } from '
|
|
2
|
+
import { focusZone } from '@primer/behaviors';
|
|
3
3
|
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
|
4
|
+
export { FocusKeys } from '@primer/behaviors';
|
|
4
5
|
export function useFocusZone(settings = {}, dependencies = []) {
|
|
5
6
|
const containerRef = useProvidedRefOrCreate(settings.containerRef);
|
|
6
7
|
const useActiveDescendant = !!settings.activeDescendantFocus;
|