@stenajs-webui/select 15.7.0 → 16.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 CHANGED
@@ -1,3 +1,16 @@
1
+ # v16.0.0 (Wed Jun 15 2022)
2
+
3
+ #### 💥 Breaking Change
4
+
5
+ - Add variant to Select and date inputs [#463](https://github.com/StenaIT/stenajs-webui/pull/463) ([@nikteg](https://github.com/nikteg) [@lindskogen](https://github.com/lindskogen))
6
+
7
+ #### Authors: 2
8
+
9
+ - Johan Lindskogen ([@lindskogen](https://github.com/lindskogen))
10
+ - Niklas ([@nikteg](https://github.com/nikteg))
11
+
12
+ ---
13
+
1
14
  # v15.0.3 (Fri Feb 25 2022)
2
15
 
3
16
  #### 🐛 Bug Fix
@@ -17,11 +17,16 @@ export interface SelectTheme {
17
17
  input: {
18
18
  backgroundColor: string;
19
19
  border: string;
20
- borderFocused: string;
21
20
  borderColor: string;
22
21
  borderColorFocused: string;
23
22
  borderRadius: string;
24
23
  disabledBackgroundColor: string;
24
+ warningBackgroundColor: string;
25
+ errorBackgroundColor: string;
26
+ successBackgroundColor: string;
27
+ warningBorderColor: string;
28
+ errorBorderColor: string;
29
+ successBorderColor: string;
25
30
  boxShadowFocused: string;
26
31
  fontFamily: string;
27
32
  fontSize: string;
@@ -68,4 +73,3 @@ export interface SelectTheme {
68
73
  };
69
74
  }
70
75
  export declare const defaultSelectTheme: SelectTheme;
71
- export declare const selectThemeDark: SelectTheme;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { AsyncProps } from "react-select/async";
3
+ import { SelectVariant } from "../../util/StylesBuilder";
3
4
  import { GroupBase } from "react-select/dist/declarations/src/types";
4
5
  export interface AsyncMultiSelectProps<T = {
5
6
  label: string;
6
7
  value: string;
7
8
  }> extends AsyncProps<T, true, GroupBase<T>> {
8
- variant?: "dark" | "light";
9
+ variant?: SelectVariant;
9
10
  isMulti?: true;
10
11
  }
11
12
  export declare const AsyncMultiSelect: <T extends {}>({ variant, styles, isMulti, ...selectProps }: AsyncMultiSelectProps<T>) => JSX.Element;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { AsyncProps } from "react-select/async";
3
+ import { SelectVariant } from "../../util/StylesBuilder";
3
4
  import { GroupBase } from "react-select/dist/declarations/src/types";
4
5
  export interface AsyncSelectProps<T = {
5
6
  label: string;
6
7
  value: string;
7
8
  }> extends AsyncProps<T, false, GroupBase<T>> {
8
- variant?: "dark" | "light";
9
+ variant?: SelectVariant;
9
10
  isMulti?: false;
10
11
  }
11
12
  export declare const AsyncSelect: <T extends {}>({ variant, styles, isMulti, ...selectProps }: AsyncSelectProps<T>) => JSX.Element;
@@ -5,4 +5,3 @@ declare const _default: {
5
5
  };
6
6
  export default _default;
7
7
  export declare const _AsyncSelect: () => JSX.Element;
8
- export declare const AsyncSelectDark: () => JSX.Element;
@@ -5,5 +5,5 @@ declare const _default: {
5
5
  };
6
6
  export default _default;
7
7
  export declare const Standard: () => JSX.Element;
8
- export declare const StandardDark: () => JSX.Element;
8
+ export declare const WithVariant: () => JSX.Element;
9
9
  export declare const Disabled: () => JSX.Element;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { Props, SelectComponentsConfig } from "react-select";
3
+ import { SelectVariant } from "../../util/StylesBuilder";
3
4
  import { GroupBase } from "react-select/dist/declarations/src/types";
4
5
  export interface MultiSelectProps<TOption = {
5
6
  label: string;
6
7
  value: string;
7
8
  }> extends Props<TOption, true> {
8
- variant?: "dark" | "light";
9
+ variant?: SelectVariant;
9
10
  isMulti?: true;
10
11
  }
11
12
  export declare type MultiSelectComponentsConfig<TOption> = SelectComponentsConfig<TOption, true, GroupBase<TOption>>;
@@ -5,6 +5,6 @@ declare const _default: {
5
5
  };
6
6
  export default _default;
7
7
  export declare const Standard: () => JSX.Element;
8
+ export declare const WithVariant: () => JSX.Element;
8
9
  export declare const WithGroupHeadings: () => JSX.Element;
9
- export declare const MultiselectDark: () => JSX.Element;
10
10
  export declare const Disabled: () => JSX.Element;
@@ -1,10 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { Props } from "react-select";
3
+ import { SelectVariant } from "../../util/StylesBuilder";
3
4
  export interface SelectProps<T = {
4
5
  label: string;
5
6
  value: string;
6
7
  }> extends Props<T, false> {
7
- variant?: "dark" | "light";
8
+ variant?: SelectVariant;
8
9
  isMulti?: false;
9
10
  }
10
11
  export declare const Select: <T extends {}>({ variant, styles, isMulti, ...selectProps }: SelectProps<T>) => JSX.Element;
@@ -5,7 +5,7 @@ declare const _default: {
5
5
  };
6
6
  export default _default;
7
7
  export declare const Standard: () => JSX.Element;
8
+ export declare const WithVariant: () => JSX.Element;
8
9
  export declare const LongLabels: () => JSX.Element;
9
- export declare const StandardDark: () => JSX.Element;
10
10
  export declare const WithGroupHeadings: () => JSX.Element;
11
11
  export declare const Disabled: () => JSX.Element;
package/dist/index.d.ts CHANGED
@@ -7,5 +7,4 @@ export * from "./components/ui/ChipMultiSelect/ChipMultiSelect";
7
7
  export * from "./components/ui/ChipMultiSelect/GroupedChipMultiSelect";
8
8
  export * from "./SelectTheme";
9
9
  export * from "./util/StylesBuilder";
10
- export * from "./util/StylesMerger";
11
10
  export { DropdownOption } from "./components/ui/GroupedMultiSelectTypes";
package/dist/index.es.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import { useMemo } from 'react';
3
- import SelectComponent, { mergeStyles as mergeStyles$1, components } from 'react-select';
3
+ import SelectComponent, { mergeStyles, components } from 'react-select';
4
4
  import AsyncComponent from 'react-select/async';
5
5
  import { faCheck } from '@fortawesome/free-solid-svg-icons/faCheck';
6
6
  import { Row, Space, Text, Column, Spacing } from '@stenajs-webui/core';
7
7
  import { Icon, Chip, FlatButton } from '@stenajs-webui/elements';
8
- import { differenceWith, isEqual, uniqWith, intersectionWith, merge } from 'lodash';
8
+ import { differenceWith, isEqual, uniqWith, intersectionWith } from 'lodash';
9
9
 
10
10
  /*! *****************************************************************************
11
11
  Copyright (c) Microsoft Corporation.
@@ -72,11 +72,16 @@ var defaultSelectTheme = {
72
72
  },
73
73
  input: {
74
74
  backgroundColor: "var(--swui-field-bg-enabled)",
75
- border: "1px solid var(--swui-field-border-color)",
76
- borderFocused: "1px solid var(--swui-field-border-color-hover)",
75
+ border: "1px solid var(--swui-select-border-color)",
77
76
  borderColor: "var(--swui-field-border-color)",
78
77
  borderColorFocused: "var(--swui-field-border-color-hover)",
79
78
  disabledBackgroundColor: "var(--swui-field-bg-disabled)",
79
+ warningBackgroundColor: "var(--swui-state-alert-light-color)",
80
+ errorBackgroundColor: "var(--swui-state-error-light-color)",
81
+ successBackgroundColor: "var(--swui-state-success-light-color)",
82
+ warningBorderColor: "var(--swui-state-alert-color)",
83
+ errorBorderColor: "var(--swui-state-error-color)",
84
+ successBorderColor: "var(--swui-state-success-color)",
80
85
  boxShadowFocused: "var(--swui-field-focus-shadow)",
81
86
  fontFamily: "var(--swui-font-primary)",
82
87
  fontSize: "var(--swui-font-size-inputs)",
@@ -122,74 +127,6 @@ var defaultSelectTheme = {
122
127
  removeButtonHoverBackgroundColor: "var(--swui-primary-action-color-hover)",
123
128
  removeButtonHoverTextColor: "var(--swui-white)",
124
129
  },
125
- };
126
- var selectThemeDark = {
127
- arrowColor: {
128
- focused: {
129
- hover: "white",
130
- standard: "var(--lhds-color-ui-500)",
131
- },
132
- closed: {
133
- hover: "white",
134
- standard: "var(--lhds-color-ui-500)",
135
- },
136
- },
137
- clearButtonColor: {
138
- standard: "var(--lhds-color-ui-400)",
139
- hover: "white",
140
- },
141
- input: {
142
- backgroundColor: "#4a5d73",
143
- border: "1px solid transparent",
144
- borderFocused: "1px solid #92a3b5",
145
- borderColor: "transparent",
146
- borderColorFocused: "#92a3b5",
147
- disabledBackgroundColor: "var(--swui-field-bg-disabled)",
148
- boxShadowFocused: "var(--swui-field-focus-shadow)",
149
- fontFamily: "var(--swui-font-primary)",
150
- fontSize: "var(--swui-font-size-inputs)",
151
- height: "32px",
152
- minHeight: "32px",
153
- placeholderColor: "white",
154
- textColor: "white",
155
- borderRadius: "4px",
156
- },
157
- loadingIndicator: {
158
- textColor: "white",
159
- },
160
- menu: {
161
- activeBackgroundColor: "#6F7E90",
162
- activeTextColor: "white",
163
- selectedItemActiveBackgroundColor: "#6F7E90",
164
- selectedItemActiveTextColor: "white",
165
- disabledTextColor: "var(--swui-text-disabled-color)",
166
- disabledBackgroundColor: "var(--swui-field-bg-disabled)",
167
- backgroundColor: "#4a5d73",
168
- textColor: "white",
169
- hoverTextColor: "white",
170
- hoverBackgroundColor: "#6F7E90",
171
- selectedItemTextColor: "white",
172
- selectedItemIconColor: "white",
173
- selectedItemHoverTextColor: "white",
174
- selectedItemHoverIconColor: "white",
175
- selectedItemBackgroundColor: "#4a5d73",
176
- selectedItemHoverBackgroundColor: "#6F7E90",
177
- zIndex: 1,
178
- width: "auto",
179
- minWidth: "100%",
180
- whiteSpace: "nowrap",
181
- },
182
- menuPortal: {
183
- zIndex: 1,
184
- },
185
- multiSelect: {
186
- backgroundColor: "#B9D8DF",
187
- textColor: "var(--lhds-color-ui-700)",
188
- removeButtonBackgroundColor: "#B9D8DF",
189
- removeButtonTextColor: "var(--lhds-color-ui-700)",
190
- removeButtonHoverBackgroundColor: "#226F81",
191
- removeButtonHoverTextColor: "white",
192
- },
193
130
  };
194
131
 
195
132
  var resolveOptionBackgroundColor = function (colors, isDisabled, isSelected, isFocused) {
@@ -226,7 +163,53 @@ var resolveOptionColor = function (colors, isDisabled, isSelected, isFocused) {
226
163
  return undefined;
227
164
  }
228
165
  };
229
- var createStylesFromTheme = function (_a) {
166
+ var resolveInputBackgroundColor = function (colors, isDisabled, isFocused, variant) {
167
+ if (isDisabled) {
168
+ return colors.disabledBackgroundColor;
169
+ }
170
+ else if (isFocused) {
171
+ return colors.backgroundColor;
172
+ }
173
+ else if (variant === "warning") {
174
+ return colors.warningBackgroundColor;
175
+ }
176
+ else if (variant === "success") {
177
+ return colors.successBackgroundColor;
178
+ }
179
+ else if (variant === "error") {
180
+ return colors.errorBackgroundColor;
181
+ }
182
+ else {
183
+ return colors.backgroundColor;
184
+ }
185
+ };
186
+ var resolveInputBorderColor = function (colors, isDisabled, isFocused, isHovered, variant) {
187
+ if (isDisabled) {
188
+ return colors.borderColor;
189
+ }
190
+ else if (isFocused) {
191
+ return colors.borderColorFocused;
192
+ }
193
+ else if (variant === "warning") {
194
+ return colors.warningBorderColor;
195
+ }
196
+ else if (variant === "success") {
197
+ return colors.successBorderColor;
198
+ }
199
+ else if (variant === "error") {
200
+ return colors.errorBorderColor;
201
+ }
202
+ else if (isHovered) {
203
+ return colors.borderColorFocused;
204
+ }
205
+ else {
206
+ return colors.borderColor;
207
+ }
208
+ };
209
+ /**
210
+ * @deprecated
211
+ */
212
+ var createStylesFromTheme = function (_a, variant) {
230
213
  var menu = _a.menu, menuPortal = _a.menuPortal, input = _a.input, multiSelect = _a.multiSelect, clearButtonColor = _a.clearButtonColor, arrowColor = _a.arrowColor, loadingIndicator = _a.loadingIndicator;
231
214
  return ({
232
215
  option: function (base, _a) {
@@ -245,14 +228,11 @@ var createStylesFromTheme = function (_a) {
245
228
  } }));
246
229
  },
247
230
  control: function (base, _a) {
248
- var isFocused = _a.isFocused, isDisabled = _a.isDisabled;
231
+ var isFocused = _a.isFocused, isDisabled = _a.isDisabled, menuIsOpen = _a.menuIsOpen;
249
232
  return (__assign(__assign({}, base), {
250
233
  // none of react-selects styles are passed to <View />
251
- fontFamily: input.fontFamily, fontSize: input.fontSize, minHeight: input.minHeight, backgroundColor: isDisabled
252
- ? input.disabledBackgroundColor
253
- : input.backgroundColor, borderRadius: input.borderRadius, border: isFocused ? input.borderFocused : input.border, borderColor: isFocused ? input.borderColorFocused : input.borderColor, boxShadow: isFocused ? input.boxShadowFocused : undefined, "&:hover": {
254
- border: input.borderFocused,
255
- borderColor: input.borderColorFocused,
234
+ fontFamily: input.fontFamily, fontSize: input.fontSize, minHeight: input.minHeight, backgroundColor: resolveInputBackgroundColor(input, isDisabled, isFocused, variant), borderRadius: input.borderRadius, border: input.border, "--swui-select-border-color": resolveInputBorderColor(input, isDisabled, isFocused || menuIsOpen, false, variant), boxShadow: isFocused ? input.boxShadowFocused : undefined, "&:hover": {
235
+ "--swui-select-border-color": resolveInputBorderColor(input, false, isFocused || menuIsOpen, true, variant),
256
236
  } }));
257
237
  },
258
238
  singleValue: function (base) { return (__assign(__assign({}, base), { fontFamily: input.fontFamily, fontSize: input.fontSize, color: input.textColor })); },
@@ -276,7 +256,7 @@ var createStylesFromTheme = function (_a) {
276
256
  height: 14,
277
257
  } }));
278
258
  },
279
- menu: function (base) { return (__assign(__assign({}, base), { backgroundColor: menu.backgroundColor, color: menu.textColor, minWidth: menu.minWidth || base.minWidth, zIndex: menu.zIndex, width: menu.width || base.width, border: input.borderFocused })); },
259
+ menu: function (base) { return (__assign(__assign({}, base), { backgroundColor: menu.backgroundColor, color: menu.textColor, minWidth: menu.minWidth || base.minWidth, zIndex: menu.zIndex, width: menu.width || base.width, border: input.border, borderColor: input.borderColorFocused })); },
280
260
  menuPortal: function (base) { return (__assign(__assign({}, base), { zIndex: menuPortal.zIndex })); },
281
261
  multiValueRemove: function (styles) { return (__assign(__assign({}, styles), { backgroundColor: multiSelect.removeButtonBackgroundColor, ":hover": {
282
262
  color: multiSelect.removeButtonHoverTextColor,
@@ -285,40 +265,43 @@ var createStylesFromTheme = function (_a) {
285
265
  multiValue: function (base) { return (__assign(__assign({}, base), { backgroundColor: multiSelect.backgroundColor, color: multiSelect.textColor, fontFamily: input.fontFamily, fontSize: "12px", alignItems: "center", margin: 0, marginRight: 2 })); },
286
266
  loadingMessage: function (base) { return (__assign(__assign({}, base), { color: loadingIndicator.textColor, fontFamily: input.fontFamily, fontSize: input.fontSize })); },
287
267
  });
268
+ };
269
+ var createStylesFromVariant = function (variant) {
270
+ return createStylesFromTheme(defaultSelectTheme, variant);
288
271
  };
289
272
 
290
273
  var AsyncMultiSelect = function (_a) {
291
- var _b = _a.variant, variant = _b === void 0 ? "light" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
274
+ var _b = _a.variant, variant = _b === void 0 ? "standard" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
292
275
  var selectStyles = useMemo(function () {
293
- var sourceStyles = createStylesFromTheme(variant === "light" ? defaultSelectTheme : selectThemeDark);
294
- return styles ? mergeStyles$1(sourceStyles, styles) : sourceStyles;
276
+ var sourceStyles = createStylesFromVariant(variant);
277
+ return styles ? mergeStyles(sourceStyles, styles) : sourceStyles;
295
278
  }, [variant, styles]);
296
279
  return (React.createElement(AsyncComponent, __assign({ styles: selectStyles }, selectProps, { isMulti: true })));
297
280
  };
298
281
 
299
282
  var AsyncSelect = function (_a) {
300
- var _b = _a.variant, variant = _b === void 0 ? "light" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
283
+ var _b = _a.variant, variant = _b === void 0 ? "standard" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
301
284
  var selectStyles = useMemo(function () {
302
- var sourceStyles = createStylesFromTheme(variant === "light" ? defaultSelectTheme : selectThemeDark);
303
- return styles ? mergeStyles$1(sourceStyles, styles) : sourceStyles;
285
+ var sourceStyles = createStylesFromVariant(variant);
286
+ return styles ? mergeStyles(sourceStyles, styles) : sourceStyles;
304
287
  }, [variant, styles]);
305
288
  return (React.createElement(AsyncComponent, __assign({ styles: selectStyles }, selectProps, { isMulti: false })));
306
289
  };
307
290
 
308
291
  var MultiSelect = function (_a) {
309
- var _b = _a.variant, variant = _b === void 0 ? "light" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
292
+ var _b = _a.variant, variant = _b === void 0 ? "standard" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
310
293
  var selectStyles = useMemo(function () {
311
- var sourceStyles = createStylesFromTheme(variant === "light" ? defaultSelectTheme : selectThemeDark);
312
- return styles ? mergeStyles$1(sourceStyles, styles) : sourceStyles;
294
+ var sourceStyles = createStylesFromVariant(variant);
295
+ return styles ? mergeStyles(sourceStyles, styles) : sourceStyles;
313
296
  }, [variant, styles]);
314
297
  return (React.createElement(SelectComponent, __assign({ styles: selectStyles }, selectProps, { isMulti: true })));
315
298
  };
316
299
 
317
300
  var Select = function (_a) {
318
- var _b = _a.variant, variant = _b === void 0 ? "light" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
301
+ var _b = _a.variant, variant = _b === void 0 ? "standard" : _b, styles = _a.styles; _a.isMulti; var selectProps = __rest(_a, ["variant", "styles", "isMulti"]);
319
302
  var selectStyles = useMemo(function () {
320
- var sourceStyles = createStylesFromTheme(variant === "light" ? defaultSelectTheme : selectThemeDark);
321
- return styles ? mergeStyles$1(sourceStyles, styles) : sourceStyles;
303
+ var sourceStyles = createStylesFromVariant(variant);
304
+ return styles ? mergeStyles(sourceStyles, styles) : sourceStyles;
322
305
  }, [variant, styles]);
323
306
  return (React.createElement(SelectComponent, __assign({ styles: selectStyles }, selectProps, { isMulti: false })));
324
307
  };
@@ -449,15 +432,14 @@ function formatInnerOptionLabel(props) {
449
432
  : props.label;
450
433
  }
451
434
  var GroupedMultiSelect = function (_a) {
452
- var onChange = _a.onChange, options = _a.options, value = _a.value, _b = _a.variant, variant = _b === void 0 ? "light" : _b; _a.formatGroupLabel; _a.formatOptionLabel; var selectProps = __rest(_a, ["onChange", "options", "value", "variant", "formatGroupLabel", "formatOptionLabel"]);
453
- var theme = variant === "light" ? defaultSelectTheme : selectThemeDark;
435
+ var onChange = _a.onChange, options = _a.options, value = _a.value, _b = _a.variant, variant = _b === void 0 ? "standard" : _b; _a.formatGroupLabel; _a.formatOptionLabel; var selectProps = __rest(_a, ["onChange", "options", "value", "variant", "formatGroupLabel", "formatOptionLabel"]);
454
436
  var Option = function (props) {
455
437
  var label = formatInnerOptionLabel(props);
456
438
  var isGroupOption = "internalOptions" in props.data;
457
439
  return (React.createElement(components.Option, __assign({}, props),
458
440
  React.createElement(Row, null,
459
441
  !isGroupOption && React.createElement(Space, null),
460
- React.createElement(InnerOption, { theme: theme, size: !isGroupOption ? "small" : undefined, label: label, selected: props.isSelected, focused: props.isFocused }))));
442
+ React.createElement(InnerOption, { theme: defaultSelectTheme, size: !isGroupOption ? "small" : undefined, label: label, selected: props.isSelected, focused: props.isFocused }))));
461
443
  };
462
444
  var MultiValue = function (props) {
463
445
  return !("internalOptions" in props.data) ? (React.createElement(components.MultiValue, __assign({}, props))) : null;
@@ -507,12 +489,5 @@ var GroupedChipMultiSelect = React.memo(function (_a) {
507
489
  React.createElement(GroupedMultiSelect, __assign({}, selectProps, { isClearable: false, value: value, onChange: onValueChange, backspaceRemovesValue: false, hideSelectedOptions: true, controlShouldRenderValue: false, placeholder: placeholder, isLoading: loading, inputValue: inputValue, onInputChange: onInputChange }))));
508
490
  });
509
491
 
510
- var mergeStyles = function (themeStyle, userStyle) {
511
- if (!userStyle) {
512
- return themeStyle;
513
- }
514
- return merge({}, themeStyle, userStyle);
515
- };
516
-
517
- export { AsyncMultiSelect, AsyncSelect, ChipMultiSelect, GroupedChipMultiSelect, GroupedMultiSelect, MultiSelect, Select, createStylesFromTheme, defaultSelectTheme, mergeStyles, selectThemeDark };
492
+ export { AsyncMultiSelect, AsyncSelect, ChipMultiSelect, GroupedChipMultiSelect, GroupedMultiSelect, MultiSelect, Select, createStylesFromTheme, createStylesFromVariant, defaultSelectTheme };
518
493
  //# sourceMappingURL=index.es.js.map