@spark-web/select 3.0.0-rc.2 → 3.0.0-rc.20

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 CHANGED
@@ -1,5 +1,275 @@
1
1
  # @spark-web/select
2
2
 
3
+ ## 3.0.0-rc.20
4
+
5
+ ### Minor Changes
6
+
7
+ - Support for component-level theming; button-level theming
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies []:
12
+ - @spark-web/text-input@4.0.0-rc.20
13
+ - @spark-web/field@4.0.0-rc.20
14
+ - @spark-web/theme@4.0.0-rc.20
15
+ - @spark-web/icon@2.0.0-rc.20
16
+ - @spark-web/box@2.0.0-rc.20
17
+
18
+ ## 3.0.0-rc.19
19
+
20
+ ### Major Changes
21
+
22
+ - test
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies []:
27
+ - @spark-web/text-input@4.0.0-rc.19
28
+ - @spark-web/field@4.0.0-rc.19
29
+ - @spark-web/theme@4.0.0-rc.19
30
+ - @spark-web/icon@2.0.0-rc.19
31
+ - @spark-web/box@2.0.0-rc.19
32
+
33
+ ## 3.0.0-rc.18
34
+
35
+ ### Major Changes
36
+
37
+ - tests
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies []:
42
+ - @spark-web/text-input@4.0.0-rc.18
43
+ - @spark-web/field@4.0.0-rc.18
44
+ - @spark-web/theme@4.0.0-rc.18
45
+ - @spark-web/icon@2.0.0-rc.18
46
+ - @spark-web/box@2.0.0-rc.18
47
+
48
+ ## 3.0.0-rc.17
49
+
50
+ ### Major Changes
51
+
52
+ - test
53
+
54
+ ### Patch Changes
55
+
56
+ - Updated dependencies []:
57
+ - @spark-web/text-input@4.0.0-rc.17
58
+ - @spark-web/field@4.0.0-rc.17
59
+ - @spark-web/theme@4.0.0-rc.17
60
+ - @spark-web/icon@2.0.0-rc.17
61
+ - @spark-web/box@2.0.0-rc.17
62
+
63
+ ## 3.0.0-rc.16
64
+
65
+ ### Major Changes
66
+
67
+ - test
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies []:
72
+ - @spark-web/text-input@4.0.0-rc.16
73
+ - @spark-web/field@4.0.0-rc.16
74
+ - @spark-web/theme@4.0.0-rc.16
75
+ - @spark-web/icon@2.0.0-rc.16
76
+ - @spark-web/box@2.0.0-rc.16
77
+
78
+ ## 3.0.0-rc.15
79
+
80
+ ### Major Changes
81
+
82
+ - test
83
+
84
+ ### Patch Changes
85
+
86
+ - Updated dependencies []:
87
+ - @spark-web/text-input@4.0.0-rc.15
88
+ - @spark-web/field@4.0.0-rc.15
89
+ - @spark-web/theme@4.0.0-rc.15
90
+ - @spark-web/icon@2.0.0-rc.15
91
+ - @spark-web/box@2.0.0-rc.15
92
+
93
+ ## 3.0.0-rc.14
94
+
95
+ ### Major Changes
96
+
97
+ - test
98
+
99
+ ### Patch Changes
100
+
101
+ - Updated dependencies []:
102
+ - @spark-web/text-input@4.0.0-rc.14
103
+ - @spark-web/field@4.0.0-rc.14
104
+ - @spark-web/theme@4.0.0-rc.14
105
+ - @spark-web/icon@2.0.0-rc.14
106
+ - @spark-web/box@2.0.0-rc.14
107
+
108
+ ## 3.0.0-rc.13
109
+
110
+ ### Major Changes
111
+
112
+ - test
113
+
114
+ ### Patch Changes
115
+
116
+ - Updated dependencies []:
117
+ - @spark-web/text-input@4.0.0-rc.13
118
+ - @spark-web/field@4.0.0-rc.13
119
+ - @spark-web/theme@4.0.0-rc.13
120
+ - @spark-web/icon@2.0.0-rc.13
121
+ - @spark-web/box@2.0.0-rc.13
122
+
123
+ ## 3.0.0-rc.12
124
+
125
+ ### Major Changes
126
+
127
+ - test
128
+
129
+ ### Patch Changes
130
+
131
+ - Updated dependencies []:
132
+ - @spark-web/text-input@4.0.0-rc.12
133
+ - @spark-web/field@4.0.0-rc.12
134
+ - @spark-web/theme@4.0.0-rc.12
135
+ - @spark-web/icon@2.0.0-rc.12
136
+ - @spark-web/box@2.0.0-rc.12
137
+
138
+ ## 3.0.0-rc.11
139
+
140
+ ### Major Changes
141
+
142
+ - test
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies []:
147
+ - @spark-web/text-input@4.0.0-rc.11
148
+ - @spark-web/field@4.0.0-rc.11
149
+ - @spark-web/theme@4.0.0-rc.11
150
+ - @spark-web/icon@2.0.0-rc.11
151
+ - @spark-web/box@2.0.0-rc.11
152
+
153
+ ## 3.0.0-rc.10
154
+
155
+ ### Major Changes
156
+
157
+ - test
158
+
159
+ ### Patch Changes
160
+
161
+ - Updated dependencies []:
162
+ - @spark-web/text-input@4.0.0-rc.10
163
+ - @spark-web/field@4.0.0-rc.10
164
+ - @spark-web/theme@4.0.0-rc.10
165
+ - @spark-web/icon@2.0.0-rc.10
166
+ - @spark-web/box@2.0.0-rc.10
167
+
168
+ ## 3.0.0-rc.9
169
+
170
+ ### Major Changes
171
+
172
+ - test
173
+
174
+ ### Patch Changes
175
+
176
+ - Updated dependencies []:
177
+ - @spark-web/text-input@4.0.0-rc.9
178
+ - @spark-web/field@4.0.0-rc.9
179
+ - @spark-web/theme@4.0.0-rc.9
180
+ - @spark-web/icon@2.0.0-rc.9
181
+ - @spark-web/box@2.0.0-rc.9
182
+
183
+ ## 3.0.0-rc.8
184
+
185
+ ### Major Changes
186
+
187
+ - test
188
+
189
+ ### Patch Changes
190
+
191
+ - Updated dependencies []:
192
+ - @spark-web/text-input@4.0.0-rc.8
193
+ - @spark-web/field@4.0.0-rc.8
194
+ - @spark-web/theme@4.0.0-rc.8
195
+ - @spark-web/icon@2.0.0-rc.8
196
+ - @spark-web/box@2.0.0-rc.8
197
+
198
+ ## 3.0.0-rc.7
199
+
200
+ ### Major Changes
201
+
202
+ - test
203
+
204
+ ### Patch Changes
205
+
206
+ - Updated dependencies []:
207
+ - @spark-web/text-input@4.0.0-rc.7
208
+ - @spark-web/field@4.0.0-rc.7
209
+ - @spark-web/theme@4.0.0-rc.7
210
+ - @spark-web/icon@2.0.0-rc.7
211
+ - @spark-web/box@2.0.0-rc.7
212
+
213
+ ## 3.0.0-rc.6
214
+
215
+ ### Major Changes
216
+
217
+ - test
218
+
219
+ ### Patch Changes
220
+
221
+ - Updated dependencies []:
222
+ - @spark-web/text-input@4.0.0-rc.6
223
+ - @spark-web/field@4.0.0-rc.6
224
+ - @spark-web/theme@4.0.0-rc.6
225
+ - @spark-web/icon@2.0.0-rc.6
226
+ - @spark-web/box@2.0.0-rc.6
227
+
228
+ ## 3.0.0-rc.5
229
+
230
+ ### Major Changes
231
+
232
+ - test
233
+
234
+ ### Patch Changes
235
+
236
+ - Updated dependencies []:
237
+ - @spark-web/text-input@4.0.0-rc.5
238
+ - @spark-web/field@4.0.0-rc.5
239
+ - @spark-web/theme@4.0.0-rc.5
240
+ - @spark-web/icon@2.0.0-rc.5
241
+ - @spark-web/box@2.0.0-rc.5
242
+
243
+ ## 3.0.0-rc.4
244
+
245
+ ### Major Changes
246
+
247
+ - bug
248
+
249
+ ### Patch Changes
250
+
251
+ - Updated dependencies []:
252
+ - @spark-web/text-input@4.0.0-rc.4
253
+ - @spark-web/field@4.0.0-rc.4
254
+ - @spark-web/theme@4.0.0-rc.4
255
+ - @spark-web/icon@2.0.0-rc.4
256
+ - @spark-web/box@2.0.0-rc.4
257
+
258
+ ## 3.0.0-rc.3
259
+
260
+ ### Major Changes
261
+
262
+ - upgrade package
263
+
264
+ ### Patch Changes
265
+
266
+ - Updated dependencies []:
267
+ - @spark-web/text-input@4.0.0-rc.3
268
+ - @spark-web/field@4.0.0-rc.3
269
+ - @spark-web/theme@4.0.0-rc.3
270
+ - @spark-web/icon@2.0.0-rc.3
271
+ - @spark-web/box@2.0.0-rc.3
272
+
3
273
  ## 3.0.0-rc.2
4
274
 
5
275
  ### Major Changes
@@ -1,2 +1,2 @@
1
- export * from "./declarations/src/index";
2
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLXNlbGVjdC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4vZGVjbGFyYXRpb25zL3NyYy9pbmRleC5kLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBIn0=
1
+ export * from "../src/index";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3Bhcmstd2ViLXNlbGVjdC5janMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -1,7 +1,16 @@
1
- 'use strict';
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
2
9
 
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./spark-web-select.cjs.prod.js");
5
- } else {
6
- module.exports = require("./spark-web-select.cjs.dev.js");
7
- }
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-web/select",
3
- "version": "3.0.0-rc.2",
3
+ "version": "3.0.0-rc.20",
4
4
  "homepage": "https://github.com/brighte-labs/spark-web#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,20 +16,20 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.25.0",
19
- "@emotion/react": "^11.13.5",
20
- "@spark-web/box": "^2.0.0-rc.2",
21
- "@spark-web/icon": "^2.0.0-rc.2",
22
- "@spark-web/text-input": "^4.0.0-rc.2",
23
- "@spark-web/theme": "^4.0.0-rc.2"
19
+ "@emotion/react": "^11.14.0",
20
+ "@spark-web/box": "^2.0.0-rc.20",
21
+ "@spark-web/icon": "^2.0.0-rc.20",
22
+ "@spark-web/text-input": "^4.0.0-rc.20",
23
+ "@spark-web/theme": "^4.0.0-rc.20"
24
24
  },
25
25
  "devDependencies": {
26
- "@spark-web/field": "^4.0.0-rc.2",
27
- "@spark-web/utils": "^2.0.0-rc.2",
26
+ "@spark-web/field": "^4.0.0-rc.20",
27
+ "@spark-web/utils": "^2.0.0-rc.20",
28
28
  "@types/react": "^18.2.0",
29
29
  "react": "^18.2.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "@spark-web/field": "^4.0.0-rc.2",
32
+ "@spark-web/field": "^4.0.0-rc.20",
33
33
  "react": ">=17.0.2"
34
34
  },
35
35
  "engines": {
@@ -1,2 +0,0 @@
1
- export { Select } from "./select.js";
2
- export type { SelectProps } from "./select.js";
@@ -1,34 +0,0 @@
1
- import type { DataAttributeMap } from '@spark-web/utils/internal';
2
- import type { SelectHTMLAttributes } from 'react';
3
- export declare type Option = {
4
- /** Whether or not the option is disabled. */
5
- disabled?: boolean;
6
- /** Label for the option. */
7
- label: string;
8
- /** Value of the option. */
9
- value: string | number;
10
- };
11
- export declare type Group = {
12
- /** List of options for the group. */
13
- options: Array<Option>;
14
- /** Label for the group. */
15
- label: string;
16
- };
17
- export declare type OptionsOrGroups = Array<Option | Group>;
18
- export declare type NativeSelectProps = Pick<SelectHTMLAttributes<HTMLSelectElement>, 'defaultValue' | 'name' | 'onBlur' | 'onChange' | 'required' | 'value'>;
19
- export declare type SelectProps = NativeSelectProps & {
20
- /** Sets data attributes for the element. */
21
- data?: DataAttributeMap;
22
- /** The values that can be selected by the input. */
23
- options: OptionsOrGroups;
24
- /** Placeholder text for when the input does not have an initial value. */
25
- placeholder?: string;
26
- };
27
- export declare const Select: import("react").ForwardRefExoticComponent<NativeSelectProps & {
28
- /** Sets data attributes for the element. */
29
- data?: DataAttributeMap | undefined;
30
- /** The values that can be selected by the input. */
31
- options: OptionsOrGroups;
32
- /** Placeholder text for when the input does not have an initial value. */
33
- placeholder?: string | undefined;
34
- } & import("react").RefAttributes<HTMLSelectElement>>;
@@ -1,111 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
- var react$1 = require('@emotion/react');
8
- var box = require('@spark-web/box');
9
- var field = require('@spark-web/field');
10
- var icon = require('@spark-web/icon');
11
- var textInput = require('@spark-web/text-input');
12
- var theme = require('@spark-web/theme');
13
- var react = require('react');
14
- var jsxRuntime = require('@emotion/react/jsx-runtime');
15
-
16
- var Select = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
17
- var data = _ref.data,
18
- defaultValue = _ref.defaultValue,
19
- name = _ref.name,
20
- onBlur = _ref.onBlur,
21
- onChange = _ref.onChange,
22
- optionsOrGroups = _ref.options,
23
- placeholder = _ref.placeholder,
24
- required = _ref.required,
25
- value = _ref.value;
26
- var _useFieldContext = field.useFieldContext(),
27
- _useFieldContext2 = _slicedToArray(_useFieldContext, 2),
28
- _useFieldContext2$ = _useFieldContext2[0],
29
- disabled = _useFieldContext2$.disabled,
30
- invalid = _useFieldContext2$.invalid,
31
- a11yProps = _useFieldContext2[1];
32
- var _useSelectStyles = useSelectStyles({
33
- disabled: disabled,
34
- invalid: invalid
35
- }),
36
- _useSelectStyles2 = _slicedToArray(_useSelectStyles, 2),
37
- boxProps = _useSelectStyles2[0],
38
- inputStyles = _useSelectStyles2[1];
39
- var mapOptions = react.useCallback(function (opt) {
40
- return jsxRuntime.jsx("option", {
41
- value: opt.value,
42
- disabled: opt.disabled,
43
- children: opt.label
44
- }, opt.value);
45
- }, []);
46
- return jsxRuntime.jsxs(textInput.InputContainer, {
47
- children: [jsxRuntime.jsx(Indicator, {}), jsxRuntime.jsxs(box.Box, _objectSpread(_objectSpread(_objectSpread({}, boxProps), a11yProps), {}, {
48
- as: "select",
49
- css: react$1.css(inputStyles),
50
- data: data,
51
- defaultValue: (defaultValue !== null && defaultValue !== void 0 ? defaultValue : placeholder) ? '' : undefined,
52
- disabled: disabled,
53
- name: name,
54
- onBlur: onBlur,
55
- onChange: onChange,
56
- ref: forwardedRef,
57
- required: required,
58
- value: value,
59
- width: "full",
60
- children: [!value || placeholder ? jsxRuntime.jsx("option", {
61
- value: "",
62
- disabled: true,
63
- children: placeholder
64
- }) : null, optionsOrGroups.map(function (optionOrGroup) {
65
- if ('options' in optionOrGroup) {
66
- return jsxRuntime.jsx("optgroup", {
67
- label: optionOrGroup.label,
68
- children: optionOrGroup.options.map(function (option) {
69
- return mapOptions(option);
70
- })
71
- }, optionOrGroup.label);
72
- }
73
- return mapOptions(optionOrGroup);
74
- })]
75
- }))]
76
- });
77
- });
78
- Select.displayName = 'Select';
79
- var Indicator = function Indicator() {
80
- return jsxRuntime.jsx(box.Box, {
81
- position: "absolute",
82
- top: 0,
83
- bottom: 0,
84
- right: 0,
85
- display: "flex",
86
- alignItems: "center",
87
- padding: "medium",
88
- css: react$1.css({
89
- pointerEvents: 'none'
90
- }),
91
- children: jsxRuntime.jsx(icon.ChevronDownIcon, {
92
- size: "xxsmall",
93
- tone: "placeholder"
94
- })
95
- });
96
- };
97
- function useSelectStyles(props) {
98
- var _useInputStyles = textInput.useInputStyles(props),
99
- _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
100
- boxProps = _useInputStyles2[0],
101
- inputStyles = _useInputStyles2[1];
102
- var theme$1 = theme.useTheme();
103
- return [boxProps, _objectSpread(_objectSpread({}, inputStyles), {}, {
104
- // Prevent text going underneath the chevron icon
105
- paddingRight: theme$1.sizing.xxsmall +
106
- // size of chevron icon
107
- theme$1.spacing.medium * 2 // paddingX value
108
- })];
109
- }
110
-
111
- exports.Select = Select;
@@ -1,111 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
7
- var react$1 = require('@emotion/react');
8
- var box = require('@spark-web/box');
9
- var field = require('@spark-web/field');
10
- var icon = require('@spark-web/icon');
11
- var textInput = require('@spark-web/text-input');
12
- var theme = require('@spark-web/theme');
13
- var react = require('react');
14
- var jsxRuntime = require('@emotion/react/jsx-runtime');
15
-
16
- var Select = /*#__PURE__*/react.forwardRef(function (_ref, forwardedRef) {
17
- var data = _ref.data,
18
- defaultValue = _ref.defaultValue,
19
- name = _ref.name,
20
- onBlur = _ref.onBlur,
21
- onChange = _ref.onChange,
22
- optionsOrGroups = _ref.options,
23
- placeholder = _ref.placeholder,
24
- required = _ref.required,
25
- value = _ref.value;
26
- var _useFieldContext = field.useFieldContext(),
27
- _useFieldContext2 = _slicedToArray(_useFieldContext, 2),
28
- _useFieldContext2$ = _useFieldContext2[0],
29
- disabled = _useFieldContext2$.disabled,
30
- invalid = _useFieldContext2$.invalid,
31
- a11yProps = _useFieldContext2[1];
32
- var _useSelectStyles = useSelectStyles({
33
- disabled: disabled,
34
- invalid: invalid
35
- }),
36
- _useSelectStyles2 = _slicedToArray(_useSelectStyles, 2),
37
- boxProps = _useSelectStyles2[0],
38
- inputStyles = _useSelectStyles2[1];
39
- var mapOptions = react.useCallback(function (opt) {
40
- return jsxRuntime.jsx("option", {
41
- value: opt.value,
42
- disabled: opt.disabled,
43
- children: opt.label
44
- }, opt.value);
45
- }, []);
46
- return jsxRuntime.jsxs(textInput.InputContainer, {
47
- children: [jsxRuntime.jsx(Indicator, {}), jsxRuntime.jsxs(box.Box, _objectSpread(_objectSpread(_objectSpread({}, boxProps), a11yProps), {}, {
48
- as: "select",
49
- css: react$1.css(inputStyles),
50
- data: data,
51
- defaultValue: (defaultValue !== null && defaultValue !== void 0 ? defaultValue : placeholder) ? '' : undefined,
52
- disabled: disabled,
53
- name: name,
54
- onBlur: onBlur,
55
- onChange: onChange,
56
- ref: forwardedRef,
57
- required: required,
58
- value: value,
59
- width: "full",
60
- children: [!value || placeholder ? jsxRuntime.jsx("option", {
61
- value: "",
62
- disabled: true,
63
- children: placeholder
64
- }) : null, optionsOrGroups.map(function (optionOrGroup) {
65
- if ('options' in optionOrGroup) {
66
- return jsxRuntime.jsx("optgroup", {
67
- label: optionOrGroup.label,
68
- children: optionOrGroup.options.map(function (option) {
69
- return mapOptions(option);
70
- })
71
- }, optionOrGroup.label);
72
- }
73
- return mapOptions(optionOrGroup);
74
- })]
75
- }))]
76
- });
77
- });
78
- Select.displayName = 'Select';
79
- var Indicator = function Indicator() {
80
- return jsxRuntime.jsx(box.Box, {
81
- position: "absolute",
82
- top: 0,
83
- bottom: 0,
84
- right: 0,
85
- display: "flex",
86
- alignItems: "center",
87
- padding: "medium",
88
- css: react$1.css({
89
- pointerEvents: 'none'
90
- }),
91
- children: jsxRuntime.jsx(icon.ChevronDownIcon, {
92
- size: "xxsmall",
93
- tone: "placeholder"
94
- })
95
- });
96
- };
97
- function useSelectStyles(props) {
98
- var _useInputStyles = textInput.useInputStyles(props),
99
- _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
100
- boxProps = _useInputStyles2[0],
101
- inputStyles = _useInputStyles2[1];
102
- var theme$1 = theme.useTheme();
103
- return [boxProps, _objectSpread(_objectSpread({}, inputStyles), {}, {
104
- // Prevent text going underneath the chevron icon
105
- paddingRight: theme$1.sizing.xxsmall +
106
- // size of chevron icon
107
- theme$1.spacing.medium * 2 // paddingX value
108
- })];
109
- }
110
-
111
- exports.Select = Select;
@@ -1,107 +0,0 @@
1
- import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
2
- import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
3
- import { css } from '@emotion/react';
4
- import { Box } from '@spark-web/box';
5
- import { useFieldContext } from '@spark-web/field';
6
- import { ChevronDownIcon } from '@spark-web/icon';
7
- import { InputContainer, useInputStyles } from '@spark-web/text-input';
8
- import { useTheme } from '@spark-web/theme';
9
- import { forwardRef, useCallback } from 'react';
10
- import { jsx, jsxs } from '@emotion/react/jsx-runtime';
11
-
12
- var Select = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
13
- var data = _ref.data,
14
- defaultValue = _ref.defaultValue,
15
- name = _ref.name,
16
- onBlur = _ref.onBlur,
17
- onChange = _ref.onChange,
18
- optionsOrGroups = _ref.options,
19
- placeholder = _ref.placeholder,
20
- required = _ref.required,
21
- value = _ref.value;
22
- var _useFieldContext = useFieldContext(),
23
- _useFieldContext2 = _slicedToArray(_useFieldContext, 2),
24
- _useFieldContext2$ = _useFieldContext2[0],
25
- disabled = _useFieldContext2$.disabled,
26
- invalid = _useFieldContext2$.invalid,
27
- a11yProps = _useFieldContext2[1];
28
- var _useSelectStyles = useSelectStyles({
29
- disabled: disabled,
30
- invalid: invalid
31
- }),
32
- _useSelectStyles2 = _slicedToArray(_useSelectStyles, 2),
33
- boxProps = _useSelectStyles2[0],
34
- inputStyles = _useSelectStyles2[1];
35
- var mapOptions = useCallback(function (opt) {
36
- return jsx("option", {
37
- value: opt.value,
38
- disabled: opt.disabled,
39
- children: opt.label
40
- }, opt.value);
41
- }, []);
42
- return jsxs(InputContainer, {
43
- children: [jsx(Indicator, {}), jsxs(Box, _objectSpread(_objectSpread(_objectSpread({}, boxProps), a11yProps), {}, {
44
- as: "select",
45
- css: css(inputStyles),
46
- data: data,
47
- defaultValue: (defaultValue !== null && defaultValue !== void 0 ? defaultValue : placeholder) ? '' : undefined,
48
- disabled: disabled,
49
- name: name,
50
- onBlur: onBlur,
51
- onChange: onChange,
52
- ref: forwardedRef,
53
- required: required,
54
- value: value,
55
- width: "full",
56
- children: [!value || placeholder ? jsx("option", {
57
- value: "",
58
- disabled: true,
59
- children: placeholder
60
- }) : null, optionsOrGroups.map(function (optionOrGroup) {
61
- if ('options' in optionOrGroup) {
62
- return jsx("optgroup", {
63
- label: optionOrGroup.label,
64
- children: optionOrGroup.options.map(function (option) {
65
- return mapOptions(option);
66
- })
67
- }, optionOrGroup.label);
68
- }
69
- return mapOptions(optionOrGroup);
70
- })]
71
- }))]
72
- });
73
- });
74
- Select.displayName = 'Select';
75
- var Indicator = function Indicator() {
76
- return jsx(Box, {
77
- position: "absolute",
78
- top: 0,
79
- bottom: 0,
80
- right: 0,
81
- display: "flex",
82
- alignItems: "center",
83
- padding: "medium",
84
- css: css({
85
- pointerEvents: 'none'
86
- }),
87
- children: jsx(ChevronDownIcon, {
88
- size: "xxsmall",
89
- tone: "placeholder"
90
- })
91
- });
92
- };
93
- function useSelectStyles(props) {
94
- var _useInputStyles = useInputStyles(props),
95
- _useInputStyles2 = _slicedToArray(_useInputStyles, 2),
96
- boxProps = _useInputStyles2[0],
97
- inputStyles = _useInputStyles2[1];
98
- var theme = useTheme();
99
- return [boxProps, _objectSpread(_objectSpread({}, inputStyles), {}, {
100
- // Prevent text going underneath the chevron icon
101
- paddingRight: theme.sizing.xxsmall +
102
- // size of chevron icon
103
- theme.spacing.medium * 2 // paddingX value
104
- })];
105
- }
106
-
107
- export { Select };