@spark-web/text-input 3.0.0 → 4.0.0-rc.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/CHANGELOG.md +16 -0
- package/dist/spark-web-text-input.cjs.d.ts +2 -1
- package/dist/spark-web-text-input.cjs.js +15 -6
- package/package.json +10 -10
- package/dist/declarations/src/children-to-adornments.d.ts +0 -12
- package/dist/declarations/src/index.d.ts +0 -6
- package/dist/declarations/src/input-adornment.d.ts +0 -46
- package/dist/declarations/src/input-container.d.ts +0 -10
- package/dist/declarations/src/text-input.d.ts +0 -2858
- package/dist/spark-web-text-input.cjs.dev.js +0 -268
- package/dist/spark-web-text-input.cjs.prod.js +0 -268
- package/dist/spark-web-text-input.esm.js +0 -261
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
|
2
|
-
import { Box } from '@spark-web/box';
|
|
3
|
-
import { useFieldContext, FieldContextProvider } from '@spark-web/field';
|
|
4
|
-
import { useTheme } from '@spark-web/theme';
|
|
5
|
-
import { useMemo, createContext, Children, isValidElement, forwardRef } from 'react';
|
|
6
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
7
|
-
import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
|
|
8
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
9
|
-
import { css } from '@emotion/css';
|
|
10
|
-
import { useFocusRing } from '@spark-web/a11y';
|
|
11
|
-
import { useOverflowStrategy, useText } from '@spark-web/text';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Components like the `SelectInput` may subscribe to the adornment context and
|
|
15
|
-
* change their appearance or behaviour.
|
|
16
|
-
*/
|
|
17
|
-
var InputAdornmentContext = /*#__PURE__*/createContext(null);
|
|
18
|
-
var placementToPadding = {
|
|
19
|
-
start: {
|
|
20
|
-
paddingLeft: 'medium',
|
|
21
|
-
paddingRight: 'xsmall'
|
|
22
|
-
},
|
|
23
|
-
end: {
|
|
24
|
-
paddingLeft: 'xsmall',
|
|
25
|
-
paddingRight: 'medium'
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Places an element at the "start" or "end" of the input, only one adornment
|
|
30
|
-
* may be provided for each placement. By default, the adornment element will be
|
|
31
|
-
* wrapped to provide alignment and spacing, use the "raw" property to opt-out
|
|
32
|
-
* of this behaviour.
|
|
33
|
-
*
|
|
34
|
-
* @example
|
|
35
|
-
* <TextInput>
|
|
36
|
-
* <InputAdornment placement="start">
|
|
37
|
-
* <Text tone="placeholder">$</Text>
|
|
38
|
-
* </InputAdornment>
|
|
39
|
-
* </TextInput>
|
|
40
|
-
*/
|
|
41
|
-
var InputAdornment = function InputAdornment(_ref) {
|
|
42
|
-
var children = _ref.children,
|
|
43
|
-
fieldLabel = _ref.fieldLabel,
|
|
44
|
-
placement = _ref.placement,
|
|
45
|
-
raw = _ref.raw;
|
|
46
|
-
var theme = useTheme();
|
|
47
|
-
var adornmentContext = useMemo(function () {
|
|
48
|
-
return {
|
|
49
|
-
placement: placement
|
|
50
|
-
};
|
|
51
|
-
}, [placement]);
|
|
52
|
-
var _placementToPadding$p = placementToPadding[placement],
|
|
53
|
-
paddingLeft = _placementToPadding$p.paddingLeft,
|
|
54
|
-
paddingRight = _placementToPadding$p.paddingRight;
|
|
55
|
-
var content = children;
|
|
56
|
-
if (!raw) {
|
|
57
|
-
content = /*#__PURE__*/jsx(Box, {
|
|
58
|
-
paddingLeft: paddingLeft,
|
|
59
|
-
paddingRight: paddingRight,
|
|
60
|
-
children: /*#__PURE__*/jsx(Box, {
|
|
61
|
-
display: "flex",
|
|
62
|
-
alignItems: "center",
|
|
63
|
-
justifyContent: "center",
|
|
64
|
-
style: {
|
|
65
|
-
minWidth: theme.sizing.xxsmall
|
|
66
|
-
},
|
|
67
|
-
children: children
|
|
68
|
-
})
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
var wrappedContent = /*#__PURE__*/jsx(InputAdornmentContext.Provider, {
|
|
72
|
-
value: adornmentContext,
|
|
73
|
-
children: content
|
|
74
|
-
});
|
|
75
|
-
if (fieldLabel) {
|
|
76
|
-
return /*#__PURE__*/jsx(FieldAdornment, {
|
|
77
|
-
fieldLabel: fieldLabel,
|
|
78
|
-
children: wrappedContent
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return wrappedContent;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Wrap the element with a field provider to override the parent field label.
|
|
86
|
-
* Only split-out from `InputAdornment` to avoid the conditional hook rule.
|
|
87
|
-
*/
|
|
88
|
-
var FieldAdornment = function FieldAdornment(_ref2) {
|
|
89
|
-
var children = _ref2.children,
|
|
90
|
-
fieldLabel = _ref2.fieldLabel;
|
|
91
|
-
var parentFieldContext = useFieldContext();
|
|
92
|
-
var fieldContext = useMemo(function () {
|
|
93
|
-
return _objectSpread(_objectSpread({}, parentFieldContext), {}, {
|
|
94
|
-
accessibilityLabel: fieldLabel
|
|
95
|
-
});
|
|
96
|
-
}, [fieldLabel, parentFieldContext]);
|
|
97
|
-
return /*#__PURE__*/jsx(FieldContextProvider, {
|
|
98
|
-
value: fieldContext,
|
|
99
|
-
children: children
|
|
100
|
-
});
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
var _excluded$1 = ["children", "startAdornment", "endAdornment"];
|
|
104
|
-
var InputContainer = function InputContainer(_ref) {
|
|
105
|
-
var children = _ref.children,
|
|
106
|
-
startAdornment = _ref.startAdornment,
|
|
107
|
-
endAdornment = _ref.endAdornment,
|
|
108
|
-
boxProps = _objectWithoutProperties(_ref, _excluded$1);
|
|
109
|
-
var _useFieldContext = useFieldContext(),
|
|
110
|
-
_useFieldContext2 = _slicedToArray(_useFieldContext, 1),
|
|
111
|
-
_useFieldContext2$ = _useFieldContext2[0],
|
|
112
|
-
disabled = _useFieldContext2$.disabled,
|
|
113
|
-
invalid = _useFieldContext2$.invalid;
|
|
114
|
-
return /*#__PURE__*/jsxs(Box, _objectSpread(_objectSpread({
|
|
115
|
-
borderRadius: "small",
|
|
116
|
-
position: "relative",
|
|
117
|
-
background: disabled ? 'inputDisabled' : 'input'
|
|
118
|
-
}, boxProps), {}, {
|
|
119
|
-
children: [startAdornment, children, /*#__PURE__*/jsx(FocusIndicator, {
|
|
120
|
-
invalid: invalid
|
|
121
|
-
}), endAdornment]
|
|
122
|
-
}));
|
|
123
|
-
};
|
|
124
|
-
var FocusIndicator = function FocusIndicator(_ref2) {
|
|
125
|
-
var invalid = _ref2.invalid;
|
|
126
|
-
return /*#__PURE__*/jsx(Box, {
|
|
127
|
-
"aria-hidden": "true",
|
|
128
|
-
as: "span",
|
|
129
|
-
data: {
|
|
130
|
-
'focus-indicator': 'true'
|
|
131
|
-
}
|
|
132
|
-
// Styles
|
|
133
|
-
,
|
|
134
|
-
border: invalid ? 'critical' : 'field',
|
|
135
|
-
borderRadius: "small",
|
|
136
|
-
position: "absolute",
|
|
137
|
-
bottom: 0,
|
|
138
|
-
left: 0,
|
|
139
|
-
right: 0,
|
|
140
|
-
top: 0,
|
|
141
|
-
shadow: "small",
|
|
142
|
-
className: css({
|
|
143
|
-
pointerEvents: 'none'
|
|
144
|
-
})
|
|
145
|
-
});
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Map children for placement within the `TextInput` flex container. Ensures that
|
|
150
|
-
* placeholders are provided for unused placements.
|
|
151
|
-
*/
|
|
152
|
-
var childrenToAdornments = function childrenToAdornments(children) {
|
|
153
|
-
var startAdornment = null;
|
|
154
|
-
var endAdornment = null;
|
|
155
|
-
if (!children) {
|
|
156
|
-
return {
|
|
157
|
-
startAdornment: startAdornment,
|
|
158
|
-
endAdornment: endAdornment
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
Children.forEach(children, function (child) {
|
|
162
|
-
if ( /*#__PURE__*/isValidElement(child)) {
|
|
163
|
-
if (child.props.placement === 'end') {
|
|
164
|
-
endAdornment = child;
|
|
165
|
-
}
|
|
166
|
-
if (child.props.placement === 'start') {
|
|
167
|
-
startAdornment = child;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
return {
|
|
172
|
-
startAdornment: startAdornment,
|
|
173
|
-
endAdornment: endAdornment
|
|
174
|
-
};
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
var _excluded = ["children", "data"];
|
|
178
|
-
/** Organize and emphasize information quickly and effectively in a list of text elements. */
|
|
179
|
-
var TextInput = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
180
|
-
var children = _ref.children,
|
|
181
|
-
data = _ref.data,
|
|
182
|
-
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
183
|
-
var _useFieldContext = useFieldContext(),
|
|
184
|
-
_useFieldContext2 = _slicedToArray(_useFieldContext, 2),
|
|
185
|
-
_useFieldContext2$ = _useFieldContext2[0],
|
|
186
|
-
disabled = _useFieldContext2$.disabled,
|
|
187
|
-
invalid = _useFieldContext2$.invalid,
|
|
188
|
-
a11yProps = _useFieldContext2[1];
|
|
189
|
-
var _childrenToAdornments = childrenToAdornments(children),
|
|
190
|
-
startAdornment = _childrenToAdornments.startAdornment,
|
|
191
|
-
endAdornment = _childrenToAdornments.endAdornment;
|
|
192
|
-
var _useInputStyles = useInputStyles({
|
|
193
|
-
disabled: disabled,
|
|
194
|
-
invalid: invalid,
|
|
195
|
-
startAdornment: Boolean(startAdornment),
|
|
196
|
-
endAdornment: Boolean(endAdornment)
|
|
197
|
-
}),
|
|
198
|
-
_useInputStyles2 = _slicedToArray(_useInputStyles, 2),
|
|
199
|
-
boxProps = _useInputStyles2[0],
|
|
200
|
-
inputStyles = _useInputStyles2[1];
|
|
201
|
-
return /*#__PURE__*/jsx(InputContainer, {
|
|
202
|
-
display: "inline-flex",
|
|
203
|
-
alignItems: "center",
|
|
204
|
-
startAdornment: startAdornment,
|
|
205
|
-
endAdornment: endAdornment,
|
|
206
|
-
children: /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, boxProps), consumerProps), a11yProps), {}, {
|
|
207
|
-
as: "input",
|
|
208
|
-
className: css(inputStyles),
|
|
209
|
-
data: data,
|
|
210
|
-
disabled: disabled,
|
|
211
|
-
ref: forwardedRef
|
|
212
|
-
}))
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
TextInput.displayName = 'TextInput';
|
|
216
|
-
/**
|
|
217
|
-
* Returns a tuple where the first item is an object of props to spread onto the
|
|
218
|
-
* underlying Box component that our inputs are created with, and the second
|
|
219
|
-
* item is a CSS object to be passed to Emotion's `css` function
|
|
220
|
-
**/
|
|
221
|
-
var useInputStyles = function useInputStyles(_ref2) {
|
|
222
|
-
var disabled = _ref2.disabled,
|
|
223
|
-
startAdornment = _ref2.startAdornment,
|
|
224
|
-
endAdornment = _ref2.endAdornment;
|
|
225
|
-
var theme = useTheme();
|
|
226
|
-
var overflowStyles = useOverflowStrategy('truncate');
|
|
227
|
-
var focusRingStyles = useFocusRing({
|
|
228
|
-
always: true
|
|
229
|
-
});
|
|
230
|
-
var textStyles = useText({
|
|
231
|
-
baseline: false,
|
|
232
|
-
tone: disabled ? 'disabled' : 'neutral',
|
|
233
|
-
size: 'standard',
|
|
234
|
-
weight: 'regular'
|
|
235
|
-
});
|
|
236
|
-
var _textStyles = _slicedToArray(textStyles, 2),
|
|
237
|
-
typographyStyles = _textStyles[0],
|
|
238
|
-
responsiveStyles = _textStyles[1];
|
|
239
|
-
return [{
|
|
240
|
-
flex: 1,
|
|
241
|
-
position: 'relative',
|
|
242
|
-
height: 'medium',
|
|
243
|
-
paddingLeft: startAdornment ? 'none' : 'medium',
|
|
244
|
-
paddingRight: endAdornment ? 'none' : 'medium',
|
|
245
|
-
width: 'full'
|
|
246
|
-
}, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), overflowStyles), {}, {
|
|
247
|
-
':enabled': {
|
|
248
|
-
':focus + [data-focus-indicator]': _objectSpread({
|
|
249
|
-
borderColor: theme.border.color.fieldAccent
|
|
250
|
-
}, focusRingStyles)
|
|
251
|
-
},
|
|
252
|
-
':focus': {
|
|
253
|
-
outline: 'none'
|
|
254
|
-
},
|
|
255
|
-
'&[aria-invalid=true]': {
|
|
256
|
-
color: theme.color.foreground.muted
|
|
257
|
-
}
|
|
258
|
-
})];
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
export { InputAdornment, InputContainer, TextInput, useInputStyles };
|