@spark-web/text-input 4.0.0-rc.0 → 4.0.0-rc.10

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