@spark-web/text-input 1.2.1 → 2.0.2

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.
@@ -1,6 +1,6 @@
1
1
  export { InputAdornment } from './InputAdornment';
2
2
  export { InputContainer } from './InputContainer';
3
- export { TextInput, useInput } from './TextInput';
3
+ export { TextInput, useInputStyles } from './TextInput';
4
4
  export type { AdornmentChild } from './childrenToAdornments';
5
5
  export type { InputContainerProps } from './InputContainer';
6
- export type { TextInputProps, UseInputProps } from './TextInput';
6
+ export type { TextInputProps, UseInputStylesProps } from './TextInput';
@@ -208,34 +208,43 @@ var TextInput = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
208
208
  startAdornment = _childrenToAdornments.startAdornment,
209
209
  endAdornment = _childrenToAdornments.endAdornment;
210
210
 
211
+ var _useInputStyles = useInputStyles({
212
+ disabled: disabled,
213
+ invalid: invalid,
214
+ startAdornment: Boolean(startAdornment),
215
+ endAdornment: Boolean(endAdornment)
216
+ }),
217
+ _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
218
+ boxProps = _useInputStyles2[0],
219
+ inputStyles = _useInputStyles2[1];
220
+
211
221
  return /*#__PURE__*/jsxRuntime.jsx(InputContainer, {
212
222
  display: "inline-flex",
213
223
  alignItems: "center",
214
224
  startAdornment: startAdornment,
215
225
  endAdornment: endAdornment,
216
- children: /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread({}, consumerProps), a11yProps), {}, {
226
+ children: /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, boxProps), consumerProps), a11yProps), {}, {
217
227
  as: "input",
218
- ref: forwardedRef,
228
+ className: css.css(inputStyles),
219
229
  data: data,
220
230
  disabled: disabled,
221
- position: "relative" // Styles
222
- ,
223
- flex: 1,
224
- height: "medium",
225
- paddingX: "medium",
226
- paddingLeft: startAdornment ? 'none' : 'medium',
227
- paddingRight: endAdornment ? 'none' : 'medium',
228
- className: css.css(useInput({
229
- disabled: disabled,
230
- invalid: invalid
231
- }))
231
+ ref: forwardedRef
232
232
  }))
233
233
  });
234
234
  });
235
235
  TextInput.displayName = 'TextInput';
236
- var useInput = function useInput(_ref2) {
237
- var disabled = _ref2.disabled;
236
+
237
+ /**
238
+ * Returns a tuple where the first item is an object of props to spread onto the
239
+ * underlying Box component that our inputs are created with, and the second
240
+ * item is a CSS object to be passed to Emotion's `css` function
241
+ **/
242
+ var useInputStyles = function useInputStyles(_ref2) {
243
+ var disabled = _ref2.disabled,
244
+ startAdornment = _ref2.startAdornment,
245
+ endAdornment = _ref2.endAdornment;
238
246
  var theme$1 = theme.useTheme();
247
+ var overflowStyles = text.useOverflowStrategy('truncate');
239
248
  var focusRingStyles = a11y.useFocusRing({
240
249
  always: true
241
250
  });
@@ -250,19 +259,30 @@ var useInput = function useInput(_ref2) {
250
259
  typographyStyles = _textStyles[0],
251
260
  responsiveStyles = _textStyles[1];
252
261
 
253
- return _objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), {}, {
254
- ':focus': {
255
- outline: 'none'
256
- },
262
+ return [{
263
+ flex: 1,
264
+ position: 'relative',
265
+ height: 'medium',
266
+ paddingLeft: startAdornment ? 'none' : 'medium',
267
+ paddingRight: endAdornment ? 'none' : 'medium',
268
+ shadow: 'small',
269
+ width: 'full'
270
+ }, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), overflowStyles), {}, {
257
271
  ':enabled': {
258
272
  ':focus + [data-focus-indicator]': _objectSpread({
259
273
  borderColor: theme$1.border.color.fieldAccent
260
274
  }, focusRingStyles)
275
+ },
276
+ ':focus': {
277
+ outline: 'none'
278
+ },
279
+ '&[aria-invalid=true]': {
280
+ color: theme$1.color.foreground.muted
261
281
  }
262
- });
282
+ })];
263
283
  };
264
284
 
265
285
  exports.InputAdornment = InputAdornment;
266
286
  exports.InputContainer = InputContainer;
267
287
  exports.TextInput = TextInput;
268
- exports.useInput = useInput;
288
+ exports.useInputStyles = useInputStyles;
@@ -208,34 +208,43 @@ var TextInput = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
208
208
  startAdornment = _childrenToAdornments.startAdornment,
209
209
  endAdornment = _childrenToAdornments.endAdornment;
210
210
 
211
+ var _useInputStyles = useInputStyles({
212
+ disabled: disabled,
213
+ invalid: invalid,
214
+ startAdornment: Boolean(startAdornment),
215
+ endAdornment: Boolean(endAdornment)
216
+ }),
217
+ _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
218
+ boxProps = _useInputStyles2[0],
219
+ inputStyles = _useInputStyles2[1];
220
+
211
221
  return /*#__PURE__*/jsxRuntime.jsx(InputContainer, {
212
222
  display: "inline-flex",
213
223
  alignItems: "center",
214
224
  startAdornment: startAdornment,
215
225
  endAdornment: endAdornment,
216
- children: /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread({}, consumerProps), a11yProps), {}, {
226
+ children: /*#__PURE__*/jsxRuntime.jsx(box.Box, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, boxProps), consumerProps), a11yProps), {}, {
217
227
  as: "input",
218
- ref: forwardedRef,
228
+ className: css.css(inputStyles),
219
229
  data: data,
220
230
  disabled: disabled,
221
- position: "relative" // Styles
222
- ,
223
- flex: 1,
224
- height: "medium",
225
- paddingX: "medium",
226
- paddingLeft: startAdornment ? 'none' : 'medium',
227
- paddingRight: endAdornment ? 'none' : 'medium',
228
- className: css.css(useInput({
229
- disabled: disabled,
230
- invalid: invalid
231
- }))
231
+ ref: forwardedRef
232
232
  }))
233
233
  });
234
234
  });
235
235
  TextInput.displayName = 'TextInput';
236
- var useInput = function useInput(_ref2) {
237
- var disabled = _ref2.disabled;
236
+
237
+ /**
238
+ * Returns a tuple where the first item is an object of props to spread onto the
239
+ * underlying Box component that our inputs are created with, and the second
240
+ * item is a CSS object to be passed to Emotion's `css` function
241
+ **/
242
+ var useInputStyles = function useInputStyles(_ref2) {
243
+ var disabled = _ref2.disabled,
244
+ startAdornment = _ref2.startAdornment,
245
+ endAdornment = _ref2.endAdornment;
238
246
  var theme$1 = theme.useTheme();
247
+ var overflowStyles = text.useOverflowStrategy('truncate');
239
248
  var focusRingStyles = a11y.useFocusRing({
240
249
  always: true
241
250
  });
@@ -250,19 +259,30 @@ var useInput = function useInput(_ref2) {
250
259
  typographyStyles = _textStyles[0],
251
260
  responsiveStyles = _textStyles[1];
252
261
 
253
- return _objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), {}, {
254
- ':focus': {
255
- outline: 'none'
256
- },
262
+ return [{
263
+ flex: 1,
264
+ position: 'relative',
265
+ height: 'medium',
266
+ paddingLeft: startAdornment ? 'none' : 'medium',
267
+ paddingRight: endAdornment ? 'none' : 'medium',
268
+ shadow: 'small',
269
+ width: 'full'
270
+ }, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), overflowStyles), {}, {
257
271
  ':enabled': {
258
272
  ':focus + [data-focus-indicator]': _objectSpread({
259
273
  borderColor: theme$1.border.color.fieldAccent
260
274
  }, focusRingStyles)
275
+ },
276
+ ':focus': {
277
+ outline: 'none'
278
+ },
279
+ '&[aria-invalid=true]': {
280
+ color: theme$1.color.foreground.muted
261
281
  }
262
- });
282
+ })];
263
283
  };
264
284
 
265
285
  exports.InputAdornment = InputAdornment;
266
286
  exports.InputContainer = InputContainer;
267
287
  exports.TextInput = TextInput;
268
- exports.useInput = useInput;
288
+ exports.useInputStyles = useInputStyles;
@@ -8,7 +8,7 @@ import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
8
8
  import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
9
9
  import { css } from '@emotion/css';
10
10
  import { useFocusRing } from '@spark-web/a11y';
11
- import { useText } from '@spark-web/text';
11
+ import { useOverflowStrategy, useText } from '@spark-web/text';
12
12
 
13
13
  /**
14
14
  * Components like the `SelectInput` may subscribe to the adornment context and
@@ -204,34 +204,43 @@ var TextInput = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
204
204
  startAdornment = _childrenToAdornments.startAdornment,
205
205
  endAdornment = _childrenToAdornments.endAdornment;
206
206
 
207
+ var _useInputStyles = useInputStyles({
208
+ disabled: disabled,
209
+ invalid: invalid,
210
+ startAdornment: Boolean(startAdornment),
211
+ endAdornment: Boolean(endAdornment)
212
+ }),
213
+ _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
214
+ boxProps = _useInputStyles2[0],
215
+ inputStyles = _useInputStyles2[1];
216
+
207
217
  return /*#__PURE__*/jsx(InputContainer, {
208
218
  display: "inline-flex",
209
219
  alignItems: "center",
210
220
  startAdornment: startAdornment,
211
221
  endAdornment: endAdornment,
212
- children: /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread(_objectSpread({}, consumerProps), a11yProps), {}, {
222
+ children: /*#__PURE__*/jsx(Box, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, boxProps), consumerProps), a11yProps), {}, {
213
223
  as: "input",
214
- ref: forwardedRef,
224
+ className: css(inputStyles),
215
225
  data: data,
216
226
  disabled: disabled,
217
- position: "relative" // Styles
218
- ,
219
- flex: 1,
220
- height: "medium",
221
- paddingX: "medium",
222
- paddingLeft: startAdornment ? 'none' : 'medium',
223
- paddingRight: endAdornment ? 'none' : 'medium',
224
- className: css(useInput({
225
- disabled: disabled,
226
- invalid: invalid
227
- }))
227
+ ref: forwardedRef
228
228
  }))
229
229
  });
230
230
  });
231
231
  TextInput.displayName = 'TextInput';
232
- var useInput = function useInput(_ref2) {
233
- var disabled = _ref2.disabled;
232
+
233
+ /**
234
+ * Returns a tuple where the first item is an object of props to spread onto the
235
+ * underlying Box component that our inputs are created with, and the second
236
+ * item is a CSS object to be passed to Emotion's `css` function
237
+ **/
238
+ var useInputStyles = function useInputStyles(_ref2) {
239
+ var disabled = _ref2.disabled,
240
+ startAdornment = _ref2.startAdornment,
241
+ endAdornment = _ref2.endAdornment;
234
242
  var theme = useTheme();
243
+ var overflowStyles = useOverflowStrategy('truncate');
235
244
  var focusRingStyles = useFocusRing({
236
245
  always: true
237
246
  });
@@ -246,16 +255,27 @@ var useInput = function useInput(_ref2) {
246
255
  typographyStyles = _textStyles[0],
247
256
  responsiveStyles = _textStyles[1];
248
257
 
249
- return _objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), {}, {
250
- ':focus': {
251
- outline: 'none'
252
- },
258
+ return [{
259
+ flex: 1,
260
+ position: 'relative',
261
+ height: 'medium',
262
+ paddingLeft: startAdornment ? 'none' : 'medium',
263
+ paddingRight: endAdornment ? 'none' : 'medium',
264
+ shadow: 'small',
265
+ width: 'full'
266
+ }, _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), overflowStyles), {}, {
253
267
  ':enabled': {
254
268
  ':focus + [data-focus-indicator]': _objectSpread({
255
269
  borderColor: theme.border.color.fieldAccent
256
270
  }, focusRingStyles)
271
+ },
272
+ ':focus': {
273
+ outline: 'none'
274
+ },
275
+ '&[aria-invalid=true]': {
276
+ color: theme.color.foreground.muted
257
277
  }
258
- });
278
+ })];
259
279
  };
260
280
 
261
- export { InputAdornment, InputContainer, TextInput, useInput };
281
+ export { InputAdornment, InputContainer, TextInput, useInputStyles };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-web/text-input",
3
- "version": "1.2.1",
3
+ "version": "2.0.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/spark-web-text-input.cjs.js",
6
6
  "module": "dist/spark-web-text-input.esm.js",
@@ -8,20 +8,21 @@
8
8
  "dist"
9
9
  ],
10
10
  "dependencies": {
11
- "@babel/runtime": "^7.18.0",
11
+ "@babel/runtime": "^7.18.9",
12
12
  "@emotion/css": "^11.9.0",
13
- "@spark-web/a11y": "^1.0.5",
14
- "@spark-web/box": "^1.0.5",
15
- "@spark-web/field": "^3.0.0",
16
- "@spark-web/text": "^1.0.5",
17
- "@spark-web/theme": "^3.0.1",
18
- "@spark-web/utils": "^1.1.3"
13
+ "@spark-web/a11y": "^1.3.0",
14
+ "@spark-web/box": "^1.0.8",
15
+ "@spark-web/text": "^1.1.0",
16
+ "@spark-web/theme": "^3.0.5",
17
+ "@spark-web/utils": "^1.2.1"
19
18
  },
20
19
  "devDependencies": {
20
+ "@spark-web/field": "^3.0.4",
21
21
  "@types/react": "^17.0.12",
22
22
  "react": "^17.0.2"
23
23
  },
24
24
  "peerDependencies": {
25
+ "@spark-web/field": "^3.0.4",
25
26
  "react": ">=17.0.2"
26
27
  },
27
28
  "engines": {