@primer/components 0.0.0-20219818205 → 0.0.0-202198182941
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/CHANGELOG.md +1 -1
- package/dist/browser.esm.js +101 -99
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +96 -94
- package/dist/browser.umd.js.map +1 -1
- package/lib/TextInput.d.ts +4 -12
- package/lib/TextInput.js +4 -46
- package/lib/TextInputWithTokens.d.ts +323 -0
- package/lib/TextInputWithTokens.js +244 -0
- package/lib/_TextInputWrapper.d.ts +10 -0
- package/lib/_TextInputWrapper.js +51 -0
- package/lib/_UnstyledTextInput.d.ts +2 -0
- package/lib/_UnstyledTextInput.js +20 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib-esm/TextInput.d.ts +4 -12
- package/lib-esm/TextInput.js +4 -37
- package/lib-esm/TextInputWithTokens.d.ts +323 -0
- package/lib-esm/TextInputWithTokens.js +219 -0
- package/lib-esm/_TextInputWrapper.d.ts +10 -0
- package/lib-esm/_TextInputWrapper.js +31 -0
- package/lib-esm/_UnstyledTextInput.d.ts +2 -0
- package/lib-esm/_UnstyledTextInput.js +7 -0
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.js +1 -0
- package/package.json +1 -1
@@ -0,0 +1,244 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
9
|
+
|
10
|
+
var _props = require("@styled-system/props");
|
11
|
+
|
12
|
+
var _focusZone = require("./behaviors/focusZone");
|
13
|
+
|
14
|
+
var _useCombinedRefs = require("./hooks/useCombinedRefs");
|
15
|
+
|
16
|
+
var _useFocusZone = require("./hooks/useFocusZone");
|
17
|
+
|
18
|
+
var _Token = _interopRequireDefault(require("./Token/Token"));
|
19
|
+
|
20
|
+
var _hooks = require("./hooks");
|
21
|
+
|
22
|
+
var _UnstyledTextInput = _interopRequireDefault(require("./_UnstyledTextInput"));
|
23
|
+
|
24
|
+
var _TextInputWrapper = _interopRequireDefault(require("./_TextInputWrapper"));
|
25
|
+
|
26
|
+
var _Box = _interopRequireDefault(require("./Box"));
|
27
|
+
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
29
|
+
|
30
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
31
|
+
|
32
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
33
|
+
|
34
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
35
|
+
|
36
|
+
// using forwardRef is important so that other components (ex. Autocomplete) can use the ref
|
37
|
+
function TextInputWithTokensInnerComponent({
|
38
|
+
icon: IconComponent,
|
39
|
+
contrast,
|
40
|
+
className,
|
41
|
+
block,
|
42
|
+
disabled,
|
43
|
+
theme,
|
44
|
+
sx: sxProp,
|
45
|
+
tokens,
|
46
|
+
onTokenRemove,
|
47
|
+
tokenComponent: TokenComponent,
|
48
|
+
preventTokenWrapping,
|
49
|
+
size,
|
50
|
+
hideTokenRemoveButtons,
|
51
|
+
maxHeight,
|
52
|
+
width: widthProp,
|
53
|
+
minWidth: minWidthProp,
|
54
|
+
maxWidth: maxWidthProp,
|
55
|
+
variant: variantProp,
|
56
|
+
...rest
|
57
|
+
}, externalRef) {
|
58
|
+
const {
|
59
|
+
onFocus,
|
60
|
+
onKeyDown,
|
61
|
+
...inputPropsRest
|
62
|
+
} = (0, _props.omit)(rest);
|
63
|
+
const ref = (0, _hooks.useProvidedRefOrCreate)(externalRef);
|
64
|
+
const localInputRef = (0, _react.useRef)(null);
|
65
|
+
const combinedInputRef = (0, _useCombinedRefs.useCombinedRefs)(localInputRef, ref);
|
66
|
+
const [selectedTokenIndex, setSelectedTokenIndex] = (0, _react.useState)();
|
67
|
+
const {
|
68
|
+
containerRef
|
69
|
+
} = (0, _useFocusZone.useFocusZone)({
|
70
|
+
focusOutBehavior: 'wrap',
|
71
|
+
bindKeys: _focusZone.FocusKeys.ArrowHorizontal | _focusZone.FocusKeys.HomeAndEnd,
|
72
|
+
focusableElementFilter: element => {
|
73
|
+
return !element.getAttributeNames().includes('aria-hidden');
|
74
|
+
},
|
75
|
+
getNextFocusable: direction => {
|
76
|
+
var _containerRef$current;
|
77
|
+
|
78
|
+
if (!selectedTokenIndex && selectedTokenIndex !== 0) {
|
79
|
+
return undefined;
|
80
|
+
}
|
81
|
+
|
82
|
+
let nextIndex = selectedTokenIndex + 1; // "+ 1" accounts for the first element: the text input
|
83
|
+
|
84
|
+
if (direction === 'next') {
|
85
|
+
nextIndex += 1;
|
86
|
+
}
|
87
|
+
|
88
|
+
if (direction === 'previous') {
|
89
|
+
nextIndex -= 1;
|
90
|
+
}
|
91
|
+
|
92
|
+
if (nextIndex > tokens.length || nextIndex < 1) {
|
93
|
+
return combinedInputRef.current || undefined;
|
94
|
+
}
|
95
|
+
|
96
|
+
return (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.children[nextIndex];
|
97
|
+
}
|
98
|
+
}, [selectedTokenIndex]);
|
99
|
+
|
100
|
+
const handleTokenRemove = tokenId => {
|
101
|
+
onTokenRemove(tokenId);
|
102
|
+
|
103
|
+
if (selectedTokenIndex) {
|
104
|
+
var _containerRef$current2;
|
105
|
+
|
106
|
+
const nextElementToFocus = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.children[selectedTokenIndex];
|
107
|
+
nextElementToFocus.focus();
|
108
|
+
}
|
109
|
+
};
|
110
|
+
|
111
|
+
const handleTokenFocus = tokenIndex => () => {
|
112
|
+
setSelectedTokenIndex(tokenIndex);
|
113
|
+
};
|
114
|
+
|
115
|
+
const handleTokenBlur = () => {
|
116
|
+
setSelectedTokenIndex(undefined);
|
117
|
+
};
|
118
|
+
|
119
|
+
const handleTokenKeyUp = e => {
|
120
|
+
if (e.key === 'Escape') {
|
121
|
+
var _ref$current;
|
122
|
+
|
123
|
+
(_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.focus();
|
124
|
+
}
|
125
|
+
};
|
126
|
+
|
127
|
+
const handleInputFocus = e => {
|
128
|
+
onFocus && onFocus(e);
|
129
|
+
setSelectedTokenIndex(undefined);
|
130
|
+
};
|
131
|
+
|
132
|
+
const handleInputKeyDown = e => {
|
133
|
+
var _ref$current2;
|
134
|
+
|
135
|
+
if (onKeyDown) {
|
136
|
+
onKeyDown(e);
|
137
|
+
}
|
138
|
+
|
139
|
+
if ((_ref$current2 = ref.current) !== null && _ref$current2 !== void 0 && _ref$current2.value) {
|
140
|
+
return;
|
141
|
+
}
|
142
|
+
|
143
|
+
const lastToken = tokens[tokens.length - 1];
|
144
|
+
|
145
|
+
if (e.key === 'Backspace' && lastToken) {
|
146
|
+
handleTokenRemove(lastToken.id);
|
147
|
+
|
148
|
+
if (ref.current) {
|
149
|
+
// TODO: eliminate the first hack by making changes to the Autocomplete component
|
150
|
+
//
|
151
|
+
// HACKS:
|
152
|
+
// 1. Directly setting `ref.current.value` instead of updating state because the autocomplete
|
153
|
+
// highlight behavior doesn't work correctly if we update the value with a setState action in onChange
|
154
|
+
// 2. Adding an extra space so that when I backspace, it doesn't delete the last letter
|
155
|
+
ref.current.value = `${lastToken.text} `;
|
156
|
+
} // HACK: for some reason we need to wait a tick for `.select()` to work
|
157
|
+
|
158
|
+
|
159
|
+
setTimeout(() => {
|
160
|
+
var _ref$current3;
|
161
|
+
|
162
|
+
(_ref$current3 = ref.current) === null || _ref$current3 === void 0 ? void 0 : _ref$current3.select();
|
163
|
+
}, 0);
|
164
|
+
}
|
165
|
+
};
|
166
|
+
|
167
|
+
return /*#__PURE__*/_react.default.createElement(_TextInputWrapper.default, {
|
168
|
+
block: block,
|
169
|
+
className: className,
|
170
|
+
contrast: contrast,
|
171
|
+
disabled: disabled,
|
172
|
+
hasIcon: !!IconComponent,
|
173
|
+
theme: theme,
|
174
|
+
width: widthProp,
|
175
|
+
minWidth: minWidthProp,
|
176
|
+
maxWidth: maxWidthProp,
|
177
|
+
variant: variantProp,
|
178
|
+
ref: containerRef,
|
179
|
+
sx: {
|
180
|
+
alignItems: 'center',
|
181
|
+
flexWrap: preventTokenWrapping ? 'nowrap' : 'wrap',
|
182
|
+
gap: '0.25rem',
|
183
|
+
'> *': {
|
184
|
+
flexShrink: 0
|
185
|
+
},
|
186
|
+
...(block ? {
|
187
|
+
display: 'flex',
|
188
|
+
width: '100%'
|
189
|
+
} : {}),
|
190
|
+
...(maxHeight ? {
|
191
|
+
maxHeight,
|
192
|
+
overflow: 'auto'
|
193
|
+
} : {}),
|
194
|
+
...(preventTokenWrapping ? {
|
195
|
+
overflow: 'auto'
|
196
|
+
} : {}),
|
197
|
+
...sxProp
|
198
|
+
}
|
199
|
+
}, /*#__PURE__*/_react.default.createElement(_Box.default, {
|
200
|
+
sx: {
|
201
|
+
order: 1,
|
202
|
+
flexGrow: 1
|
203
|
+
}
|
204
|
+
}, IconComponent && /*#__PURE__*/_react.default.createElement(IconComponent, {
|
205
|
+
className: "TextInput-icon"
|
206
|
+
}), /*#__PURE__*/_react.default.createElement(_UnstyledTextInput.default, _extends({
|
207
|
+
ref: combinedInputRef,
|
208
|
+
disabled: disabled,
|
209
|
+
onFocus: handleInputFocus,
|
210
|
+
onKeyDown: handleInputKeyDown,
|
211
|
+
type: "text",
|
212
|
+
sx: {
|
213
|
+
height: '100%'
|
214
|
+
}
|
215
|
+
}, inputPropsRest))), tokens.length && TokenComponent ? tokens.map(({
|
216
|
+
id,
|
217
|
+
...tokenRest
|
218
|
+
}, i) => /*#__PURE__*/_react.default.createElement(TokenComponent, _extends({
|
219
|
+
key: id,
|
220
|
+
onFocus: handleTokenFocus(i),
|
221
|
+
onBlur: handleTokenBlur,
|
222
|
+
onKeyUp: handleTokenKeyUp,
|
223
|
+
isSelected: selectedTokenIndex === i,
|
224
|
+
onRemove: () => {
|
225
|
+
handleTokenRemove(id);
|
226
|
+
},
|
227
|
+
hideRemoveButton: hideTokenRemoveButtons,
|
228
|
+
size: size,
|
229
|
+
tabIndex: 0
|
230
|
+
}, tokenRest))) : null);
|
231
|
+
}
|
232
|
+
|
233
|
+
TextInputWithTokensInnerComponent.displayName = "TextInputWithTokensInnerComponent";
|
234
|
+
|
235
|
+
const TextInputWithTokens = /*#__PURE__*/_react.default.forwardRef(TextInputWithTokensInnerComponent);
|
236
|
+
|
237
|
+
TextInputWithTokens.defaultProps = {
|
238
|
+
tokenComponent: _Token.default,
|
239
|
+
size: 'extralarge',
|
240
|
+
hideTokenRemoveButtons: false
|
241
|
+
};
|
242
|
+
TextInputWithTokens.displayName = 'TextInputWithTokens';
|
243
|
+
var _default = TextInputWithTokens;
|
244
|
+
exports.default = _default;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
2
|
+
import { SxProp } from './sx';
|
3
|
+
declare const TextInputWrapper: import("styled-components").StyledComponent<"span", any, {
|
4
|
+
disabled?: boolean | undefined;
|
5
|
+
hasIcon?: boolean | undefined;
|
6
|
+
block?: boolean | undefined;
|
7
|
+
contrast?: boolean | undefined;
|
8
|
+
variant?: "large" | "small" | undefined;
|
9
|
+
} & 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
|
+
export default TextInputWrapper;
|
@@ -0,0 +1,51 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
9
|
+
|
10
|
+
var _styledSystem = require("styled-system");
|
11
|
+
|
12
|
+
var _constants = require("./constants");
|
13
|
+
|
14
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
19
|
+
|
20
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
21
|
+
|
22
|
+
const sizeVariants = (0, _styledSystem.variant)({
|
23
|
+
variants: {
|
24
|
+
small: {
|
25
|
+
minHeight: '28px',
|
26
|
+
px: 2,
|
27
|
+
py: '3px',
|
28
|
+
fontSize: 0,
|
29
|
+
lineHeight: '20px'
|
30
|
+
},
|
31
|
+
large: {
|
32
|
+
px: 2,
|
33
|
+
py: '10px',
|
34
|
+
fontSize: 3
|
35
|
+
}
|
36
|
+
}
|
37
|
+
});
|
38
|
+
|
39
|
+
const TextInputWrapper = _styledComponents.default.span.withConfig({
|
40
|
+
displayName: "_TextInputWrapper__TextInputWrapper",
|
41
|
+
componentId: "sc-5vfcis-0"
|
42
|
+
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('colors.fg.default'), (0, _constants.get)('colors.border.default'), (0, _constants.get)('radii.2'), (0, _constants.get)('shadows.primer.shadow.inset'), props => {
|
43
|
+
if (props.hasIcon) {
|
44
|
+
return (0, _styledComponents.css)(["padding:0;"]);
|
45
|
+
} else {
|
46
|
+
return (0, _styledComponents.css)(["padding:6px 12px;"]);
|
47
|
+
}
|
48
|
+
}, (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('space.2'), (0, _constants.get)('colors.accent.emphasis'), (0, _constants.get)('shadows.primer.shadow.focus'), props => props.contrast && (0, _styledComponents.css)(["background-color:", ";"], (0, _constants.get)('colors.canvas.inset')), props => props.disabled && (0, _styledComponents.css)(["color:", ";background-color:", ";border-color:", ";"], (0, _constants.get)('colors.fg.muted'), (0, _constants.get)('colors.input.disabledBg'), (0, _constants.get)('colors.border.default')), props => props.block && (0, _styledComponents.css)(["display:block;width:100%;"]), (0, _constants.get)('breakpoints.1'), (0, _constants.get)('fontSizes.1'), _styledSystem.width, _styledSystem.minWidth, _styledSystem.maxWidth, sizeVariants, _sx.default);
|
49
|
+
|
50
|
+
var _default = TextInputWrapper;
|
51
|
+
exports.default = _default;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
9
|
+
|
10
|
+
var _sx = _interopRequireDefault(require("./sx"));
|
11
|
+
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
|
+
|
14
|
+
const UnstyledTextInput = _styledComponents.default.input.withConfig({
|
15
|
+
displayName: "_UnstyledTextInput__UnstyledTextInput",
|
16
|
+
componentId: "sc-1jgl33s-0"
|
17
|
+
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}", ";"], _sx.default);
|
18
|
+
|
19
|
+
var _default = UnstyledTextInput;
|
20
|
+
exports.default = _default;
|
package/lib/index.d.ts
CHANGED
@@ -98,6 +98,8 @@ export { default as TabNav } from './TabNav';
|
|
98
98
|
export type { TabNavProps, TabNavLinkProps } from './TabNav';
|
99
99
|
export { default as TextInput } from './TextInput';
|
100
100
|
export type { TextInputProps } from './TextInput';
|
101
|
+
export { default as TextInputWithTokens } from './TextInputWithTokens';
|
102
|
+
export type { TextInputWithTokensProps } from './TextInputWithTokens';
|
101
103
|
export { default as Text } from './Text';
|
102
104
|
export type { TextProps } from './Text';
|
103
105
|
export { default as Timeline } from './Timeline';
|
package/lib/index.js
CHANGED
@@ -429,6 +429,12 @@ Object.defineProperty(exports, "TextInput", {
|
|
429
429
|
return _TextInput.default;
|
430
430
|
}
|
431
431
|
});
|
432
|
+
Object.defineProperty(exports, "TextInputWithTokens", {
|
433
|
+
enumerable: true,
|
434
|
+
get: function () {
|
435
|
+
return _TextInputWithTokens.default;
|
436
|
+
}
|
437
|
+
});
|
432
438
|
Object.defineProperty(exports, "Text", {
|
433
439
|
enumerable: true,
|
434
440
|
get: function () {
|
@@ -600,6 +606,8 @@ var _TabNav = _interopRequireDefault(require("./TabNav"));
|
|
600
606
|
|
601
607
|
var _TextInput = _interopRequireDefault(require("./TextInput"));
|
602
608
|
|
609
|
+
var _TextInputWithTokens = _interopRequireDefault(require("./TextInputWithTokens"));
|
610
|
+
|
603
611
|
var _Text = _interopRequireDefault(require("./Text"));
|
604
612
|
|
605
613
|
var _Timeline = _interopRequireDefault(require("./Timeline"));
|
package/lib-esm/TextInput.d.ts
CHANGED
@@ -1,22 +1,14 @@
|
|
1
1
|
import React from 'react';
|
2
|
-
import { MaxWidthProps, MinWidthProps, WidthProps } from 'styled-system';
|
3
|
-
import { SxProp } from './sx';
|
4
2
|
import { ComponentProps, Merge } from './utils/types';
|
5
|
-
|
6
|
-
|
7
|
-
disabled?: boolean | undefined;
|
8
|
-
hasIcon?: boolean | undefined;
|
9
|
-
block?: boolean | undefined;
|
10
|
-
contrast?: boolean | undefined;
|
11
|
-
variant?: "large" | "small" | undefined;
|
12
|
-
} & 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>;
|
3
|
+
import UnstyledTextInput from './_UnstyledTextInput';
|
4
|
+
import TextInputWrapper from './_TextInputWrapper';
|
13
5
|
declare type NonPassthroughProps = {
|
14
6
|
className?: string;
|
15
7
|
icon?: React.ComponentType<{
|
16
8
|
className?: string;
|
17
9
|
}>;
|
18
|
-
} & Pick<ComponentProps<typeof
|
19
|
-
declare type TextInputInternalProps = Merge<React.ComponentPropsWithoutRef<typeof
|
10
|
+
} & Pick<ComponentProps<typeof TextInputWrapper>, 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant'>;
|
11
|
+
declare type TextInputInternalProps = Merge<React.ComponentPropsWithoutRef<typeof UnstyledTextInput>, NonPassthroughProps>;
|
20
12
|
declare const TextInput: React.ForwardRefExoticComponent<Pick<TextInputInternalProps, string | number | symbol> & React.RefAttributes<HTMLInputElement>>;
|
21
13
|
export declare type TextInputProps = ComponentProps<typeof TextInput>;
|
22
14
|
export default TextInput;
|
package/lib-esm/TextInput.js
CHANGED
@@ -2,41 +2,8 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
2
2
|
|
3
3
|
import classnames from 'classnames';
|
4
4
|
import React from 'react';
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import { get } from './constants';
|
8
|
-
import sx from './sx';
|
9
|
-
const sizeVariants = variant({
|
10
|
-
variants: {
|
11
|
-
small: {
|
12
|
-
minHeight: '28px',
|
13
|
-
px: 2,
|
14
|
-
py: '3px',
|
15
|
-
fontSize: 0,
|
16
|
-
lineHeight: '20px'
|
17
|
-
},
|
18
|
-
large: {
|
19
|
-
px: 2,
|
20
|
-
py: '10px',
|
21
|
-
fontSize: 3
|
22
|
-
}
|
23
|
-
}
|
24
|
-
});
|
25
|
-
const Input = styled.input.withConfig({
|
26
|
-
displayName: "TextInput__Input",
|
27
|
-
componentId: "sc-1apmpmt-0"
|
28
|
-
})(["border:0;font-size:inherit;font-family:inherit;background-color:transparent;-webkit-appearance:none;color:inherit;width:100%;&:focus{outline:0;}"]);
|
29
|
-
const Wrapper = styled.span.withConfig({
|
30
|
-
displayName: "TextInput__Wrapper",
|
31
|
-
componentId: "sc-1apmpmt-1"
|
32
|
-
})(["display:inline-flex;align-items:stretch;min-height:34px;font-size:", ";line-height:20px;color:", ";vertical-align:middle;background-repeat:no-repeat;background-position:right 8px center;border:1px solid ", ";border-radius:", ";outline:none;box-shadow:", ";", " .TextInput-icon{align-self:center;color:", ";margin:0 ", ";flex-shrink:0;}&:focus-within{border-color:", ";box-shadow:", ";}", " ", " ", " @media (min-width:", "){font-size:", ";}", " ", " ", " ", " ", ";"], get('fontSizes.1'), get('colors.fg.default'), get('colors.border.default'), get('radii.2'), get('shadows.primer.shadow.inset'), props => {
|
33
|
-
if (props.hasIcon) {
|
34
|
-
return css(["padding:0;"]);
|
35
|
-
} else {
|
36
|
-
return css(["padding:6px 12px;"]);
|
37
|
-
}
|
38
|
-
}, 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.fg.muted'), get('colors.input.disabledBg'), get('colors.border.default')), props => props.block && css(["display:block;width:100%;"]), get('breakpoints.1'), get('fontSizes.1'), width, minWidth, maxWidth, sizeVariants, sx); // Props that are not passed through to Input:
|
39
|
-
|
5
|
+
import UnstyledTextInput from './_UnstyledTextInput';
|
6
|
+
import TextInputWrapper from './_TextInputWrapper';
|
40
7
|
// using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input
|
41
8
|
const TextInput = /*#__PURE__*/React.forwardRef(({
|
42
9
|
icon: IconComponent,
|
@@ -54,7 +21,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
54
21
|
}, ref) => {
|
55
22
|
// this class is necessary to style FilterSearch, plz no touchy!
|
56
23
|
const wrapperClasses = classnames(className, 'TextInput-wrapper');
|
57
|
-
return /*#__PURE__*/React.createElement(
|
24
|
+
return /*#__PURE__*/React.createElement(TextInputWrapper, {
|
58
25
|
block: block,
|
59
26
|
className: wrapperClasses,
|
60
27
|
contrast: contrast,
|
@@ -68,7 +35,7 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
68
35
|
variant: variantProp
|
69
36
|
}, IconComponent && /*#__PURE__*/React.createElement(IconComponent, {
|
70
37
|
className: "TextInput-icon"
|
71
|
-
}), /*#__PURE__*/React.createElement(
|
38
|
+
}), /*#__PURE__*/React.createElement(UnstyledTextInput, _extends({
|
72
39
|
ref: ref,
|
73
40
|
disabled: disabled
|
74
41
|
}, inputProps)));
|