@spark-web/text-input 1.0.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 +20 -0
- package/README.md +29 -0
- package/dist/declarations/src/TextInput.d.ts +964 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/spark-web-text-input.cjs.d.ts +1 -0
- package/dist/spark-web-text-input.cjs.dev.js +90 -0
- package/dist/spark-web-text-input.cjs.js +7 -0
- package/dist/spark-web-text-input.cjs.prod.js +90 -0
- package/dist/spark-web-text-input.esm.js +81 -0
- package/package.json +24 -0
- package/src/TextInput.stories.tsx +35 -0
- package/src/TextInput.tsx +95 -0
- package/src/index.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/esm/defineProperty');
|
|
6
|
+
var _slicedToArray = require('@babel/runtime/helpers/esm/slicedToArray');
|
|
7
|
+
var _extends = require('@babel/runtime/helpers/esm/extends');
|
|
8
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/esm/objectWithoutProperties');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var css = require('@emotion/css');
|
|
11
|
+
var a11y = require('@spark-web/a11y');
|
|
12
|
+
var box = require('@spark-web/box');
|
|
13
|
+
var field = require('@spark-web/field');
|
|
14
|
+
var text = require('@spark-web/text');
|
|
15
|
+
var theme = require('@spark-web/theme');
|
|
16
|
+
var internal = require('@spark-web/utils/internal');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
21
|
+
|
|
22
|
+
var _excluded = ["data"],
|
|
23
|
+
_excluded2 = ["disabled", "invalid"];
|
|
24
|
+
var __jsx = React__default["default"].createElement;
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
+
|
|
30
|
+
/** Organize and emphasize information quickly and effectively in a list of text elements. */
|
|
31
|
+
var TextInput = /*#__PURE__*/React.forwardRef(function (_ref, forwardedRef) {
|
|
32
|
+
var data = _ref.data,
|
|
33
|
+
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
34
|
+
|
|
35
|
+
var _useFieldContext = field.useFieldContext(),
|
|
36
|
+
disabled = _useFieldContext.disabled,
|
|
37
|
+
invalid = _useFieldContext.invalid,
|
|
38
|
+
a11yProps = _objectWithoutProperties(_useFieldContext, _excluded2);
|
|
39
|
+
|
|
40
|
+
var inputStyles = useInput({
|
|
41
|
+
disabled: disabled,
|
|
42
|
+
invalid: invalid
|
|
43
|
+
});
|
|
44
|
+
return __jsx(box.Box, _extends({
|
|
45
|
+
as: "input",
|
|
46
|
+
disabled: disabled,
|
|
47
|
+
ref: forwardedRef // styles
|
|
48
|
+
,
|
|
49
|
+
background: disabled ? 'inputDisabled' : 'input',
|
|
50
|
+
border: invalid ? 'critical' : 'field',
|
|
51
|
+
borderRadius: "small",
|
|
52
|
+
height: "medium",
|
|
53
|
+
paddingX: "medium",
|
|
54
|
+
className: css.css(inputStyles)
|
|
55
|
+
}, data ? internal.buildDataAttributes(data) : null, a11yProps, consumerProps));
|
|
56
|
+
});
|
|
57
|
+
TextInput.displayName = 'TextInput'; // Styled components
|
|
58
|
+
// ------------------------------
|
|
59
|
+
|
|
60
|
+
function useInput(_ref2) {
|
|
61
|
+
var disabled = _ref2.disabled;
|
|
62
|
+
var theme$1 = theme.useTheme();
|
|
63
|
+
var focusRingStyles = a11y.useFocusRing({
|
|
64
|
+
always: true
|
|
65
|
+
});
|
|
66
|
+
var textStyles = text.useText({
|
|
67
|
+
baseline: false,
|
|
68
|
+
tone: disabled ? 'disabled' : 'neutral',
|
|
69
|
+
size: 'standard',
|
|
70
|
+
weight: 'regular'
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
var _textStyles = _slicedToArray(textStyles, 2),
|
|
74
|
+
typographyStyles = _textStyles[0],
|
|
75
|
+
responsiveStyles = _textStyles[1];
|
|
76
|
+
|
|
77
|
+
return _objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), {}, {
|
|
78
|
+
':enabled': {
|
|
79
|
+
'&:hover': {
|
|
80
|
+
borderColor: theme$1.border.color.fieldHover
|
|
81
|
+
},
|
|
82
|
+
'&:focus': _objectSpread(_objectSpread({}, focusRingStyles), {}, {
|
|
83
|
+
borderColor: theme$1.border.color.fieldAccent
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.TextInput = TextInput;
|
|
90
|
+
exports.useInput = useInput;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/esm/defineProperty');
|
|
6
|
+
var _slicedToArray = require('@babel/runtime/helpers/esm/slicedToArray');
|
|
7
|
+
var _extends = require('@babel/runtime/helpers/esm/extends');
|
|
8
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/esm/objectWithoutProperties');
|
|
9
|
+
var React = require('react');
|
|
10
|
+
var css = require('@emotion/css');
|
|
11
|
+
var a11y = require('@spark-web/a11y');
|
|
12
|
+
var box = require('@spark-web/box');
|
|
13
|
+
var field = require('@spark-web/field');
|
|
14
|
+
var text = require('@spark-web/text');
|
|
15
|
+
var theme = require('@spark-web/theme');
|
|
16
|
+
var internal = require('@spark-web/utils/internal');
|
|
17
|
+
|
|
18
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
19
|
+
|
|
20
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
21
|
+
|
|
22
|
+
var _excluded = ["data"],
|
|
23
|
+
_excluded2 = ["disabled", "invalid"];
|
|
24
|
+
var __jsx = React__default["default"].createElement;
|
|
25
|
+
|
|
26
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
27
|
+
|
|
28
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
29
|
+
|
|
30
|
+
/** Organize and emphasize information quickly and effectively in a list of text elements. */
|
|
31
|
+
var TextInput = /*#__PURE__*/React.forwardRef(function (_ref, forwardedRef) {
|
|
32
|
+
var data = _ref.data,
|
|
33
|
+
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
34
|
+
|
|
35
|
+
var _useFieldContext = field.useFieldContext(),
|
|
36
|
+
disabled = _useFieldContext.disabled,
|
|
37
|
+
invalid = _useFieldContext.invalid,
|
|
38
|
+
a11yProps = _objectWithoutProperties(_useFieldContext, _excluded2);
|
|
39
|
+
|
|
40
|
+
var inputStyles = useInput({
|
|
41
|
+
disabled: disabled,
|
|
42
|
+
invalid: invalid
|
|
43
|
+
});
|
|
44
|
+
return __jsx(box.Box, _extends({
|
|
45
|
+
as: "input",
|
|
46
|
+
disabled: disabled,
|
|
47
|
+
ref: forwardedRef // styles
|
|
48
|
+
,
|
|
49
|
+
background: disabled ? 'inputDisabled' : 'input',
|
|
50
|
+
border: invalid ? 'critical' : 'field',
|
|
51
|
+
borderRadius: "small",
|
|
52
|
+
height: "medium",
|
|
53
|
+
paddingX: "medium",
|
|
54
|
+
className: css.css(inputStyles)
|
|
55
|
+
}, data ? internal.buildDataAttributes(data) : null, a11yProps, consumerProps));
|
|
56
|
+
});
|
|
57
|
+
TextInput.displayName = 'TextInput'; // Styled components
|
|
58
|
+
// ------------------------------
|
|
59
|
+
|
|
60
|
+
function useInput(_ref2) {
|
|
61
|
+
var disabled = _ref2.disabled;
|
|
62
|
+
var theme$1 = theme.useTheme();
|
|
63
|
+
var focusRingStyles = a11y.useFocusRing({
|
|
64
|
+
always: true
|
|
65
|
+
});
|
|
66
|
+
var textStyles = text.useText({
|
|
67
|
+
baseline: false,
|
|
68
|
+
tone: disabled ? 'disabled' : 'neutral',
|
|
69
|
+
size: 'standard',
|
|
70
|
+
weight: 'regular'
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
var _textStyles = _slicedToArray(textStyles, 2),
|
|
74
|
+
typographyStyles = _textStyles[0],
|
|
75
|
+
responsiveStyles = _textStyles[1];
|
|
76
|
+
|
|
77
|
+
return _objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), {}, {
|
|
78
|
+
':enabled': {
|
|
79
|
+
'&:hover': {
|
|
80
|
+
borderColor: theme$1.border.color.fieldHover
|
|
81
|
+
},
|
|
82
|
+
'&:focus': _objectSpread(_objectSpread({}, focusRingStyles), {}, {
|
|
83
|
+
borderColor: theme$1.border.color.fieldAccent
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
exports.TextInput = TextInput;
|
|
90
|
+
exports.useInput = useInput;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
|
+
import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
|
|
3
|
+
import _extends from '@babel/runtime/helpers/esm/extends';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
5
|
+
import React, { forwardRef } from 'react';
|
|
6
|
+
import { css } from '@emotion/css';
|
|
7
|
+
import { useFocusRing } from '@spark-web/a11y';
|
|
8
|
+
import { Box } from '@spark-web/box';
|
|
9
|
+
import { useFieldContext } from '@spark-web/field';
|
|
10
|
+
import { useText } from '@spark-web/text';
|
|
11
|
+
import { useTheme } from '@spark-web/theme';
|
|
12
|
+
import { buildDataAttributes } from '@spark-web/utils/internal';
|
|
13
|
+
|
|
14
|
+
var _excluded = ["data"],
|
|
15
|
+
_excluded2 = ["disabled", "invalid"];
|
|
16
|
+
var __jsx = React.createElement;
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
/** Organize and emphasize information quickly and effectively in a list of text elements. */
|
|
23
|
+
var TextInput = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
24
|
+
var data = _ref.data,
|
|
25
|
+
consumerProps = _objectWithoutProperties(_ref, _excluded);
|
|
26
|
+
|
|
27
|
+
var _useFieldContext = useFieldContext(),
|
|
28
|
+
disabled = _useFieldContext.disabled,
|
|
29
|
+
invalid = _useFieldContext.invalid,
|
|
30
|
+
a11yProps = _objectWithoutProperties(_useFieldContext, _excluded2);
|
|
31
|
+
|
|
32
|
+
var inputStyles = useInput({
|
|
33
|
+
disabled: disabled,
|
|
34
|
+
invalid: invalid
|
|
35
|
+
});
|
|
36
|
+
return __jsx(Box, _extends({
|
|
37
|
+
as: "input",
|
|
38
|
+
disabled: disabled,
|
|
39
|
+
ref: forwardedRef // styles
|
|
40
|
+
,
|
|
41
|
+
background: disabled ? 'inputDisabled' : 'input',
|
|
42
|
+
border: invalid ? 'critical' : 'field',
|
|
43
|
+
borderRadius: "small",
|
|
44
|
+
height: "medium",
|
|
45
|
+
paddingX: "medium",
|
|
46
|
+
className: css(inputStyles)
|
|
47
|
+
}, data ? buildDataAttributes(data) : null, a11yProps, consumerProps));
|
|
48
|
+
});
|
|
49
|
+
TextInput.displayName = 'TextInput'; // Styled components
|
|
50
|
+
// ------------------------------
|
|
51
|
+
|
|
52
|
+
function useInput(_ref2) {
|
|
53
|
+
var disabled = _ref2.disabled;
|
|
54
|
+
var theme = useTheme();
|
|
55
|
+
var focusRingStyles = useFocusRing({
|
|
56
|
+
always: true
|
|
57
|
+
});
|
|
58
|
+
var textStyles = useText({
|
|
59
|
+
baseline: false,
|
|
60
|
+
tone: disabled ? 'disabled' : 'neutral',
|
|
61
|
+
size: 'standard',
|
|
62
|
+
weight: 'regular'
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
var _textStyles = _slicedToArray(textStyles, 2),
|
|
66
|
+
typographyStyles = _textStyles[0],
|
|
67
|
+
responsiveStyles = _textStyles[1];
|
|
68
|
+
|
|
69
|
+
return _objectSpread(_objectSpread(_objectSpread({}, typographyStyles), responsiveStyles), {}, {
|
|
70
|
+
':enabled': {
|
|
71
|
+
'&:hover': {
|
|
72
|
+
borderColor: theme.border.color.fieldHover
|
|
73
|
+
},
|
|
74
|
+
'&:focus': _objectSpread(_objectSpread({}, focusRingStyles), {}, {
|
|
75
|
+
borderColor: theme.border.color.fieldAccent
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { TextInput, useInput };
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spark-web/text-input",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"main": "dist/spark-web-text-input.cjs.js",
|
|
6
|
+
"module": "dist/spark-web-text-input.esm.js",
|
|
7
|
+
"devDependencies": {
|
|
8
|
+
"@types/react": "^17.0.12"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@babel/runtime": "^7.14.6",
|
|
12
|
+
"@emotion/css": "^11.7.1",
|
|
13
|
+
"@spark-web/a11y": "^1.0.0",
|
|
14
|
+
"@spark-web/box": "^1.0.0",
|
|
15
|
+
"@spark-web/field": "^1.0.0",
|
|
16
|
+
"@spark-web/text": "^1.0.0",
|
|
17
|
+
"@spark-web/theme": "^1.0.0",
|
|
18
|
+
"@spark-web/utils": "^1.0.0",
|
|
19
|
+
"react": "^17.0.2"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">= 14.13"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Field } from '@spark-web/field';
|
|
2
|
+
import { InformationCircleIcon } from '@spark-web/icon';
|
|
3
|
+
import { Inline } from '@spark-web/inline';
|
|
4
|
+
import { Stack } from '@spark-web/stack';
|
|
5
|
+
import { Text } from '@spark-web/text';
|
|
6
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
7
|
+
|
|
8
|
+
import type { TextInputProps } from './TextInput';
|
|
9
|
+
import { TextInput } from './TextInput';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Forms / TextInput',
|
|
13
|
+
component: TextInput,
|
|
14
|
+
} as ComponentMeta<typeof TextInput>;
|
|
15
|
+
|
|
16
|
+
const TextInputStory: ComponentStory<typeof TextInput> = (
|
|
17
|
+
args: TextInputProps
|
|
18
|
+
) => (
|
|
19
|
+
<Stack gap="large">
|
|
20
|
+
<Inline gap="xsmall" alignY="center">
|
|
21
|
+
<InformationCircleIcon tone="info" size="xsmall" />
|
|
22
|
+
<Text weight="medium" tone="info" baseline={false}>
|
|
23
|
+
{`Must be used inside of a <Field/>`}
|
|
24
|
+
</Text>
|
|
25
|
+
</Inline>
|
|
26
|
+
<Field label="Text input">
|
|
27
|
+
<TextInput {...args} />
|
|
28
|
+
</Field>
|
|
29
|
+
</Stack>
|
|
30
|
+
);
|
|
31
|
+
export const Default = TextInputStory.bind({});
|
|
32
|
+
|
|
33
|
+
Default.args = {
|
|
34
|
+
displayName: 'Display name',
|
|
35
|
+
} as TextInputProps;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { css } from '@emotion/css';
|
|
2
|
+
import { useFocusRing } from '@spark-web/a11y';
|
|
3
|
+
import { Box } from '@spark-web/box';
|
|
4
|
+
import type { FieldContextType } from '@spark-web/field';
|
|
5
|
+
import { useFieldContext } from '@spark-web/field';
|
|
6
|
+
import { useText } from '@spark-web/text';
|
|
7
|
+
import { useTheme } from '@spark-web/theme';
|
|
8
|
+
import type { DataAttributeMap } from '@spark-web/utils/internal';
|
|
9
|
+
import { buildDataAttributes } from '@spark-web/utils/internal';
|
|
10
|
+
import type { AllHTMLAttributes } from 'react';
|
|
11
|
+
import { forwardRef } from 'react';
|
|
12
|
+
|
|
13
|
+
const validTypes = {
|
|
14
|
+
text: 'text',
|
|
15
|
+
password: 'password',
|
|
16
|
+
email: 'email',
|
|
17
|
+
search: 'search',
|
|
18
|
+
number: 'number',
|
|
19
|
+
tel: 'tel',
|
|
20
|
+
url: 'url',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
type NativeInputProps = Pick<
|
|
24
|
+
AllHTMLAttributes<HTMLInputElement>,
|
|
25
|
+
'onBlur' | 'onFocus' | 'onChange' | 'placeholder' | 'value'
|
|
26
|
+
>;
|
|
27
|
+
|
|
28
|
+
export type TextInputProps = {
|
|
29
|
+
/** Map of data attributes. */
|
|
30
|
+
data?: DataAttributeMap;
|
|
31
|
+
/**
|
|
32
|
+
* How an input behaves varies considerably depending on the value of its type
|
|
33
|
+
* attribute. If this attribute is not specified, the default type "text".
|
|
34
|
+
*/
|
|
35
|
+
type?: keyof typeof validTypes;
|
|
36
|
+
} & NativeInputProps;
|
|
37
|
+
|
|
38
|
+
/** Organize and emphasize information quickly and effectively in a list of text elements. */
|
|
39
|
+
export const TextInput = forwardRef<HTMLInputElement, TextInputProps>(
|
|
40
|
+
({ data, ...consumerProps }, forwardedRef) => {
|
|
41
|
+
const { disabled, invalid, ...a11yProps } = useFieldContext();
|
|
42
|
+
const inputStyles = useInput({ disabled, invalid });
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<Box
|
|
46
|
+
as="input"
|
|
47
|
+
disabled={disabled}
|
|
48
|
+
ref={forwardedRef}
|
|
49
|
+
// styles
|
|
50
|
+
background={disabled ? 'inputDisabled' : 'input'}
|
|
51
|
+
border={invalid ? 'critical' : 'field'}
|
|
52
|
+
borderRadius="small"
|
|
53
|
+
height="medium"
|
|
54
|
+
paddingX="medium"
|
|
55
|
+
className={css(inputStyles)}
|
|
56
|
+
{...(data ? buildDataAttributes(data) : null)}
|
|
57
|
+
{...a11yProps}
|
|
58
|
+
{...consumerProps}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
TextInput.displayName = 'TextInput';
|
|
64
|
+
|
|
65
|
+
// Styled components
|
|
66
|
+
// ------------------------------
|
|
67
|
+
|
|
68
|
+
export type UseInputProps = Pick<FieldContextType, 'disabled' | 'invalid'>;
|
|
69
|
+
|
|
70
|
+
export function useInput({ disabled }: UseInputProps) {
|
|
71
|
+
const theme = useTheme();
|
|
72
|
+
const focusRingStyles = useFocusRing({ always: true });
|
|
73
|
+
const textStyles = useText({
|
|
74
|
+
baseline: false,
|
|
75
|
+
tone: disabled ? 'disabled' : 'neutral',
|
|
76
|
+
size: 'standard',
|
|
77
|
+
weight: 'regular',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const [typographyStyles, responsiveStyles] = textStyles;
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
...typographyStyles,
|
|
84
|
+
...responsiveStyles,
|
|
85
|
+
':enabled': {
|
|
86
|
+
'&:hover': {
|
|
87
|
+
borderColor: theme.border.color.fieldHover,
|
|
88
|
+
},
|
|
89
|
+
'&:focus': {
|
|
90
|
+
...focusRingStyles,
|
|
91
|
+
borderColor: theme.border.color.fieldAccent,
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|