@seeqdev/qomponents 0.0.132 → 0.0.133
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/README.md +135 -135
- package/dist/Accordion/Accordion.js +8 -8
- package/dist/Accordion/Accordion.stories.js +114 -114
- package/dist/Accordion/Accordion.test.js +54 -54
- package/dist/Accordion/Accordion.types.js +1 -1
- package/dist/Accordion/index.js +1 -1
- package/dist/Alert/Alert.js +33 -33
- package/dist/Alert/Alert.stories.js +51 -51
- package/dist/Alert/Alert.test.js +50 -50
- package/dist/Alert/Alert.types.js +1 -1
- package/dist/Alert/index.js +1 -1
- package/dist/Button/Button.js +91 -91
- package/dist/Button/Button.stories.js +99 -99
- package/dist/Button/Button.test.js +48 -48
- package/dist/Button/Button.types.js +4 -4
- package/dist/Button/index.js +1 -1
- package/dist/ButtonGroup/ButtonGroup.js +32 -32
- package/dist/ButtonGroup/ButtonGroup.stories.js +384 -384
- package/dist/ButtonGroup/ButtonGroup.test.js +66 -66
- package/dist/ButtonGroup/ButtonGroup.types.js +1 -1
- package/dist/ButtonGroup/index.js +1 -1
- package/dist/ButtonWithDropdown/ButtonWithDropdown.js +59 -59
- package/dist/ButtonWithDropdown/ButtonWithDropdown.stories.js +142 -142
- package/dist/ButtonWithDropdown/ButtonWithDropdown.test.js +92 -92
- package/dist/ButtonWithDropdown/ButtonWithDropdown.types.js +1 -1
- package/dist/ButtonWithDropdown/index.js +1 -1
- package/dist/ButtonWithPopover/ButtonWithPopover.js +61 -61
- package/dist/ButtonWithPopover/ButtonWithPopover.stories.js +74 -74
- package/dist/ButtonWithPopover/ButtonWithPopover.test.js +81 -81
- package/dist/ButtonWithPopover/ButtonWithPopover.types.js +1 -1
- package/dist/ButtonWithPopover/index.js +1 -1
- package/dist/Carousel/Carousel.js +66 -66
- package/dist/Carousel/Carousel.stories.js +114 -114
- package/dist/Carousel/Carousel.test.js +47 -47
- package/dist/Carousel/Carousel.types.js +1 -1
- package/dist/Carousel/index.js +1 -1
- package/dist/Checkbox/Checkbox.js +25 -25
- package/dist/Checkbox/Checkbox.stories.js +33 -33
- package/dist/Checkbox/Checkbox.test.js +93 -93
- package/dist/Checkbox/Checkbox.types.js +1 -1
- package/dist/Checkbox/index.js +1 -1
- package/dist/Collapse/Collapse.js +17 -17
- package/dist/Collapse/Collapse.stories.js +36 -36
- package/dist/Collapse/Collapse.test.js +18 -18
- package/dist/Collapse/Collapse.types.js +1 -1
- package/dist/Collapse/index.js +1 -1
- package/dist/Icon/Icon.js +54 -54
- package/dist/Icon/Icon.stories.js +46 -46
- package/dist/Icon/Icon.test.js +54 -54
- package/dist/Icon/Icon.types.js +15 -15
- package/dist/Icon/index.js +1 -1
- package/dist/InputGroup/InputGroup.js +31 -31
- package/dist/InputGroup/InputGroup.stories.js +167 -167
- package/dist/InputGroup/InputGroup.test.js +42 -42
- package/dist/InputGroup/InputGroup.types.js +1 -1
- package/dist/InputGroup/index.js +1 -1
- package/dist/Modal/Modal.js +99 -99
- package/dist/Modal/Modal.js.map +1 -1
- package/dist/Modal/Modal.stories.js +126 -126
- package/dist/Modal/Modal.test.js +107 -107
- package/dist/Modal/Modal.types.js +1 -1
- package/dist/Modal/index.js +1 -1
- package/dist/ProgressBar/ProgressBar.js +49 -29
- package/dist/ProgressBar/ProgressBar.js.map +1 -1
- package/dist/ProgressBar/ProgressBar.stories.js +80 -72
- package/dist/ProgressBar/ProgressBar.stories.js.map +1 -1
- package/dist/ProgressBar/ProgressBar.test.js +43 -37
- package/dist/ProgressBar/ProgressBar.test.js.map +1 -1
- package/dist/ProgressBar/ProgressBar.types.d.ts +2 -0
- package/dist/ProgressBar/ProgressBar.types.js +1 -1
- package/dist/ProgressBar/index.js +1 -1
- package/dist/SeeqActionDropdown/SeeqActionDropdown.js +47 -47
- package/dist/SeeqActionDropdown/SeeqActionDropdown.stories.js +79 -79
- package/dist/SeeqActionDropdown/SeeqActionDropdown.test.js +72 -72
- package/dist/SeeqActionDropdown/SeeqActionDropdown.types.js +1 -1
- package/dist/SeeqActionDropdown/index.js +1 -1
- package/dist/SeeqActionDropdown/variants.js +22 -22
- package/dist/Select/Select.js +173 -173
- package/dist/Select/Select.stories.js +79 -79
- package/dist/Select/Select.test.js +181 -181
- package/dist/Select/Select.types.js +1 -1
- package/dist/Select/index.js +2 -2
- package/dist/Slider/Slider.js +12 -12
- package/dist/Slider/Slider.stories.js +57 -57
- package/dist/Slider/Slider.test.js +32 -32
- package/dist/Slider/Slider.types.js +1 -1
- package/dist/Slider/index.js +1 -1
- package/dist/Tabs/Tabs.js +21 -21
- package/dist/Tabs/Tabs.stories.js +90 -90
- package/dist/Tabs/Tabs.test.js +90 -90
- package/dist/Tabs/Tabs.types.js +1 -1
- package/dist/Tabs/index.js +1 -1
- package/dist/TextArea/TextArea.js +24 -24
- package/dist/TextArea/TextArea.stories.js +45 -45
- package/dist/TextArea/TextArea.test.js +67 -67
- package/dist/TextArea/TextArea.types.js +1 -1
- package/dist/TextArea/index.js +1 -1
- package/dist/TextField/TextField.js +78 -78
- package/dist/TextField/TextField.stories.js +69 -69
- package/dist/TextField/TextField.test.js +38 -38
- package/dist/TextField/TextField.types.js +1 -1
- package/dist/TextField/index.js +1 -1
- package/dist/ToolbarButton/ToolbarButton.js +74 -74
- package/dist/ToolbarButton/ToolbarButton.stories.js +93 -93
- package/dist/ToolbarButton/ToolbarButton.test.js +92 -92
- package/dist/ToolbarButton/ToolbarButton.types.js +1 -1
- package/dist/ToolbarButton/index.js +1 -1
- package/dist/Tooltip/QTip.stories.js +44 -44
- package/dist/Tooltip/QTip.types.js +1 -1
- package/dist/Tooltip/QTipPerformance.stories.js +29 -29
- package/dist/Tooltip/Qtip.js +167 -167
- package/dist/Tooltip/Tooltip.js +35 -35
- package/dist/Tooltip/Tooltip.stories.js +31 -31
- package/dist/Tooltip/Tooltip.types.js +2 -2
- package/dist/Tooltip/TooltipPerformance.stories.js +29 -29
- package/dist/Tooltip/index.js +2 -2
- package/dist/Tooltip/qTip.utilities.js +10 -10
- package/dist/example/.eslintrc.cjs +14 -14
- package/dist/example/README.md +33 -33
- package/dist/example/index.html +13 -13
- package/dist/example/package.json +30 -30
- package/dist/example/src/ComplexSelectExample.tsx +81 -81
- package/dist/example/src/Example.tsx +408 -408
- package/dist/example/src/index.css +102 -102
- package/dist/example/src/main.tsx +10 -10
- package/dist/example/src/vite-env.d.ts +1 -1
- package/dist/example/tsconfig.json +33 -33
- package/dist/example/tsconfig.node.json +12 -12
- package/dist/example/vite.config.ts +12 -12
- package/dist/index.esm.js +1229 -31
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1229 -31
- package/dist/index.js.map +1 -1
- package/dist/styles.css +3714 -3709
- package/dist/types.js +1 -1
- package/dist/utils/browserId.js +28 -28
- package/dist/utils/svg.js +19 -19
- package/dist/utils/validateStyleDimension.js +13 -13
- package/dist/utils/validateStyleDimension.test.js +19 -19
- package/package.json +88 -86
package/dist/Select/Select.js
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import '../styles.css';
|
|
3
|
-
import { createFilter, default as ReactSelect } from 'react-select';
|
|
4
|
-
import CreatableSelect from 'react-select/creatable';
|
|
5
|
-
const baseClasses = ['focus:tw-ring-0', 'disabled:tw-cursor-not-allowed'].join(' ');
|
|
6
|
-
const containerStyles = ['tw-bg-white', 'dark:tw-bg-sq-dark-background'].join(' ');
|
|
7
|
-
const errorClasses = 'tw-border-sq-danger-color';
|
|
8
|
-
const borderColorClasses = ['tw-border-sq-disabled-gray', 'dark:tw-border-sq-dark-disabled-gray'].join(' ');
|
|
9
|
-
const borderStyles = [
|
|
10
|
-
'tw-border-solid',
|
|
11
|
-
'tw-border',
|
|
12
|
-
'hover:tw-border-sq-color-dark',
|
|
13
|
-
'focus:tw-border-sq-color-dark',
|
|
14
|
-
'active:tw-border-sq-color-dark',
|
|
15
|
-
'dark:hover:tw-border-sq-color-dark-dark',
|
|
16
|
-
'dark:focus:tw-border-sq-color-dark-dark',
|
|
17
|
-
'dark:active:tw-border-sq-color-dark-dark',
|
|
18
|
-
].join(' ');
|
|
19
|
-
const textStyles = ['tw-text-sq-text-color', 'dark:tw-text-sq-dark-text', 'tw-text-sm'].join(' ');
|
|
20
|
-
const textActiveStyles = [
|
|
21
|
-
'hover:tw-text-sq-color-dark',
|
|
22
|
-
'focus:tw-text-sq-color-dark',
|
|
23
|
-
'active:tw-text-sq-color-dark',
|
|
24
|
-
'dark:tw-text-sq-dark-disabled-gray',
|
|
25
|
-
'dark:hover:tw-text-sq-color-dark-dark',
|
|
26
|
-
'dark:focus:tw-text-sq-color-dark-dark',
|
|
27
|
-
'dark:active:tw-text-sq-color-dark-dark',
|
|
28
|
-
].join(' ');
|
|
29
|
-
const menuStyles = [
|
|
30
|
-
'tw-border-solid',
|
|
31
|
-
'tw-border',
|
|
32
|
-
'tw-rounded-b',
|
|
33
|
-
'tw-border-sq-disabled-gray',
|
|
34
|
-
'dark:tw-border-sq-dark-disabled-gray',
|
|
35
|
-
'tw-whitespace-nowrap',
|
|
36
|
-
'tw-min-w-fit',
|
|
37
|
-
'!tw-z-[9999]',
|
|
38
|
-
].join(' ');
|
|
39
|
-
const menuListStyles = [
|
|
40
|
-
'tw-rounded-b',
|
|
41
|
-
'tw-bg-white',
|
|
42
|
-
'dark:tw-bg-sq-dark-background',
|
|
43
|
-
'tw-min-w-fit',
|
|
44
|
-
'!tw-z-[9999]',
|
|
45
|
-
'specSelectMenu',
|
|
46
|
-
].join(' ');
|
|
47
|
-
const groupHeadingStyles = [
|
|
48
|
-
'tw-bg-sq-light-gray',
|
|
49
|
-
'dark:tw-bg-sq-dark-disabled-gray',
|
|
50
|
-
'tw-text-sq-darkish-gray',
|
|
51
|
-
'tw-py-1',
|
|
52
|
-
'tw-px-2.5',
|
|
53
|
-
'specSelectGroupHeading',
|
|
54
|
-
].join(' ');
|
|
55
|
-
const optionStyles = [
|
|
56
|
-
'hover:tw-bg-sq-gray-highlight',
|
|
57
|
-
'hover:tw-cursor-pointer',
|
|
58
|
-
'dark:hover:tw-bg-sq-gray-highlight-dark',
|
|
59
|
-
'tw-py-1',
|
|
60
|
-
'tw-px-2.5',
|
|
61
|
-
'specSelectOption',
|
|
62
|
-
].join(' ');
|
|
63
|
-
const disabledClasses = ['tw-bg-sq-field-disabled-gray', 'tw-cursor-not-allowed'].join(' ');
|
|
64
|
-
const dropDownIndicatorStyles = `tw-text-sq-disabled-gray ${textActiveStyles} specOpenIt`;
|
|
65
|
-
const placeholderStyles = ['tw-text-gray-400', 'dark:tw-text-sq-dark-text-lighter', 'specOpenSelect'].join(' ');
|
|
66
|
-
const multiValueStyles = [
|
|
67
|
-
'tw-bg-sq-disabled-gray',
|
|
68
|
-
'dark:tw-bg-sq-multi-gray-dark',
|
|
69
|
-
'tw-text-sm',
|
|
70
|
-
'tw-py-0.5',
|
|
71
|
-
'tw-px-1',
|
|
72
|
-
'tw-m-0.5',
|
|
73
|
-
'tw-rounded-sm',
|
|
74
|
-
'specOpenSelect',
|
|
75
|
-
].join(' ');
|
|
76
|
-
/**
|
|
77
|
-
* Select Component
|
|
78
|
-
* - based on react-select (https://react-select.com/)
|
|
79
|
-
*
|
|
80
|
-
* For ease of testing most of the elements of this select can be identified by classNames prefixed with "spec".
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
const Select = ({ options, value, placeholder = 'select', noOptionsMessage = 'no matching options', isSearchable = true, creatable = false, isMulti = false, isClearable = false, closeMenuOnSelect = true, id, inputId, menuPortalTarget, getOptionLabel, getSelectedValueLabel, getOptionValue, onChange, menuIsOpen, menuPlacement = 'auto', extraClassNames, inputGroup, filterConfig, filterOption, small = false, isDisabled = false, showError = false, isLoading = false, formatGroupLabel, onRemove, defaultValue, onMenuOpen, onMenuClose, components, onMenuInputFocus, onInputChange, inputValue, }) => {
|
|
84
|
-
const getOptionOrSelectedLabel = (option, { context }) => {
|
|
85
|
-
const getSelectedOptionLabel = getSelectedValueLabel ? getSelectedValueLabel : getOptionLabel;
|
|
86
|
-
if (getOptionLabel || getSelectedValueLabel) {
|
|
87
|
-
if (context === 'value') {
|
|
88
|
-
return getSelectedOptionLabel ? getSelectedOptionLabel(option) : option.label;
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
return getOptionLabel ? getOptionLabel(option) : option.label;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
return option.label;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
const interceptOnChange = (newValue, actionMeta) => {
|
|
99
|
-
if (isMulti && onRemove && actionMeta.action === 'remove-value') {
|
|
100
|
-
onRemove({ id: actionMeta.removedValue });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
onChange(newValue);
|
|
104
|
-
};
|
|
105
|
-
const props = {
|
|
106
|
-
id,
|
|
107
|
-
value,
|
|
108
|
-
inputId,
|
|
109
|
-
placeholder,
|
|
110
|
-
closeMenuOnSelect,
|
|
111
|
-
blurInputOnSelect: closeMenuOnSelect,
|
|
112
|
-
isSearchable: creatable ? true : isSearchable,
|
|
113
|
-
isMulti,
|
|
114
|
-
isClearable,
|
|
115
|
-
isLoading,
|
|
116
|
-
defaultValue,
|
|
117
|
-
noOptionsMessage: () => noOptionsMessage,
|
|
118
|
-
menuPortalTarget,
|
|
119
|
-
menuIsOpen,
|
|
120
|
-
onChange: interceptOnChange,
|
|
121
|
-
unstyled: true,
|
|
122
|
-
menuPlacement,
|
|
123
|
-
formatOptionLabel: getOptionOrSelectedLabel,
|
|
124
|
-
formatGroupLabel,
|
|
125
|
-
getOptionValue,
|
|
126
|
-
options,
|
|
127
|
-
isDisabled,
|
|
128
|
-
onMenuOpen,
|
|
129
|
-
onMenuClose,
|
|
130
|
-
components,
|
|
131
|
-
onMenuInputFocus,
|
|
132
|
-
onInputChange,
|
|
133
|
-
inputValue,
|
|
134
|
-
hideSelectedOptions: isMulti,
|
|
135
|
-
filterOption: filterOption ? filterOption : filterConfig ? createFilter(filterConfig) : undefined,
|
|
136
|
-
classNames: {
|
|
137
|
-
control: ({ menuIsOpen }) => {
|
|
138
|
-
let border = menuIsOpen ? 'tw-rounded-t-sm' : 'tw-rounded-sm';
|
|
139
|
-
// if it's on the left side of the input group make sure the right side is straight and not curved
|
|
140
|
-
if (inputGroup === 'left') {
|
|
141
|
-
border = menuIsOpen ? 'tw-rounded-tl-sm' : 'tw-rounded-l-sm';
|
|
142
|
-
}
|
|
143
|
-
else if (inputGroup === 'right') {
|
|
144
|
-
border = menuIsOpen ? 'tw-rounded-tr-sm' : 'tw-rounded-r-sm';
|
|
145
|
-
}
|
|
146
|
-
const appliedClasses = `${borderStyles} ${border} ${showError ? errorClasses : borderColorClasses} ${small ? 'reactSelectMinHeightSmall' : 'reactSelectMinHeight'} `;
|
|
147
|
-
return `${appliedClasses} ${baseClasses} specSelectControl ${isDisabled ? disabledClasses : ''} ${small ? 'tw-pl-2 tw-pr-1' : 'tw-pl-2.5 tw-pr-1.5'}`;
|
|
148
|
-
},
|
|
149
|
-
placeholder: () => placeholderStyles,
|
|
150
|
-
container: () => `${textStyles} ${containerStyles} ${extraClassNames}`,
|
|
151
|
-
input: () => textStyles + ' specSelectInput',
|
|
152
|
-
menuList: () => menuListStyles,
|
|
153
|
-
menu: () => menuStyles,
|
|
154
|
-
menuPortal: () => '!tw-z-[9000]',
|
|
155
|
-
dropdownIndicator: () => dropDownIndicatorStyles,
|
|
156
|
-
option: ({ isSelected, isDisabled }) => {
|
|
157
|
-
let classes = optionStyles;
|
|
158
|
-
if (isDisabled) {
|
|
159
|
-
classes += ' specDisabledOption ';
|
|
160
|
-
}
|
|
161
|
-
return isSelected ? classes + ' tw-bg-sq-colored-hover dark:tw-bg-sq-colored-hover-dark' : classes;
|
|
162
|
-
},
|
|
163
|
-
singleValue: () => 'specOpenSelect',
|
|
164
|
-
multiValue: () => multiValueStyles,
|
|
165
|
-
multiValueRemove: () => 'hover:tw-text-sq-danger-color specSelectMultiValueRemove',
|
|
166
|
-
clearIndicator: () => 'tw-text-sq-disabled-gray hover:tw-text-sq-danger-color specClearSelect',
|
|
167
|
-
group: () => 'specSelectGroup',
|
|
168
|
-
groupHeading: () => groupHeadingStyles,
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
return creatable ? React.createElement(CreatableSelect, { ...props }) : React.createElement(ReactSelect, { ...props });
|
|
172
|
-
};
|
|
173
|
-
export default Select;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '../styles.css';
|
|
3
|
+
import { createFilter, default as ReactSelect } from 'react-select';
|
|
4
|
+
import CreatableSelect from 'react-select/creatable';
|
|
5
|
+
const baseClasses = ['focus:tw-ring-0', 'disabled:tw-cursor-not-allowed'].join(' ');
|
|
6
|
+
const containerStyles = ['tw-bg-white', 'dark:tw-bg-sq-dark-background'].join(' ');
|
|
7
|
+
const errorClasses = 'tw-border-sq-danger-color';
|
|
8
|
+
const borderColorClasses = ['tw-border-sq-disabled-gray', 'dark:tw-border-sq-dark-disabled-gray'].join(' ');
|
|
9
|
+
const borderStyles = [
|
|
10
|
+
'tw-border-solid',
|
|
11
|
+
'tw-border',
|
|
12
|
+
'hover:tw-border-sq-color-dark',
|
|
13
|
+
'focus:tw-border-sq-color-dark',
|
|
14
|
+
'active:tw-border-sq-color-dark',
|
|
15
|
+
'dark:hover:tw-border-sq-color-dark-dark',
|
|
16
|
+
'dark:focus:tw-border-sq-color-dark-dark',
|
|
17
|
+
'dark:active:tw-border-sq-color-dark-dark',
|
|
18
|
+
].join(' ');
|
|
19
|
+
const textStyles = ['tw-text-sq-text-color', 'dark:tw-text-sq-dark-text', 'tw-text-sm'].join(' ');
|
|
20
|
+
const textActiveStyles = [
|
|
21
|
+
'hover:tw-text-sq-color-dark',
|
|
22
|
+
'focus:tw-text-sq-color-dark',
|
|
23
|
+
'active:tw-text-sq-color-dark',
|
|
24
|
+
'dark:tw-text-sq-dark-disabled-gray',
|
|
25
|
+
'dark:hover:tw-text-sq-color-dark-dark',
|
|
26
|
+
'dark:focus:tw-text-sq-color-dark-dark',
|
|
27
|
+
'dark:active:tw-text-sq-color-dark-dark',
|
|
28
|
+
].join(' ');
|
|
29
|
+
const menuStyles = [
|
|
30
|
+
'tw-border-solid',
|
|
31
|
+
'tw-border',
|
|
32
|
+
'tw-rounded-b',
|
|
33
|
+
'tw-border-sq-disabled-gray',
|
|
34
|
+
'dark:tw-border-sq-dark-disabled-gray',
|
|
35
|
+
'tw-whitespace-nowrap',
|
|
36
|
+
'tw-min-w-fit',
|
|
37
|
+
'!tw-z-[9999]',
|
|
38
|
+
].join(' ');
|
|
39
|
+
const menuListStyles = [
|
|
40
|
+
'tw-rounded-b',
|
|
41
|
+
'tw-bg-white',
|
|
42
|
+
'dark:tw-bg-sq-dark-background',
|
|
43
|
+
'tw-min-w-fit',
|
|
44
|
+
'!tw-z-[9999]',
|
|
45
|
+
'specSelectMenu',
|
|
46
|
+
].join(' ');
|
|
47
|
+
const groupHeadingStyles = [
|
|
48
|
+
'tw-bg-sq-light-gray',
|
|
49
|
+
'dark:tw-bg-sq-dark-disabled-gray',
|
|
50
|
+
'tw-text-sq-darkish-gray',
|
|
51
|
+
'tw-py-1',
|
|
52
|
+
'tw-px-2.5',
|
|
53
|
+
'specSelectGroupHeading',
|
|
54
|
+
].join(' ');
|
|
55
|
+
const optionStyles = [
|
|
56
|
+
'hover:tw-bg-sq-gray-highlight',
|
|
57
|
+
'hover:tw-cursor-pointer',
|
|
58
|
+
'dark:hover:tw-bg-sq-gray-highlight-dark',
|
|
59
|
+
'tw-py-1',
|
|
60
|
+
'tw-px-2.5',
|
|
61
|
+
'specSelectOption',
|
|
62
|
+
].join(' ');
|
|
63
|
+
const disabledClasses = ['tw-bg-sq-field-disabled-gray', 'tw-cursor-not-allowed'].join(' ');
|
|
64
|
+
const dropDownIndicatorStyles = `tw-text-sq-disabled-gray ${textActiveStyles} specOpenIt`;
|
|
65
|
+
const placeholderStyles = ['tw-text-gray-400', 'dark:tw-text-sq-dark-text-lighter', 'specOpenSelect'].join(' ');
|
|
66
|
+
const multiValueStyles = [
|
|
67
|
+
'tw-bg-sq-disabled-gray',
|
|
68
|
+
'dark:tw-bg-sq-multi-gray-dark',
|
|
69
|
+
'tw-text-sm',
|
|
70
|
+
'tw-py-0.5',
|
|
71
|
+
'tw-px-1',
|
|
72
|
+
'tw-m-0.5',
|
|
73
|
+
'tw-rounded-sm',
|
|
74
|
+
'specOpenSelect',
|
|
75
|
+
].join(' ');
|
|
76
|
+
/**
|
|
77
|
+
* Select Component
|
|
78
|
+
* - based on react-select (https://react-select.com/)
|
|
79
|
+
*
|
|
80
|
+
* For ease of testing most of the elements of this select can be identified by classNames prefixed with "spec".
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
const Select = ({ options, value, placeholder = 'select', noOptionsMessage = 'no matching options', isSearchable = true, creatable = false, isMulti = false, isClearable = false, closeMenuOnSelect = true, id, inputId, menuPortalTarget, getOptionLabel, getSelectedValueLabel, getOptionValue, onChange, menuIsOpen, menuPlacement = 'auto', extraClassNames, inputGroup, filterConfig, filterOption, small = false, isDisabled = false, showError = false, isLoading = false, formatGroupLabel, onRemove, defaultValue, onMenuOpen, onMenuClose, components, onMenuInputFocus, onInputChange, inputValue, }) => {
|
|
84
|
+
const getOptionOrSelectedLabel = (option, { context }) => {
|
|
85
|
+
const getSelectedOptionLabel = getSelectedValueLabel ? getSelectedValueLabel : getOptionLabel;
|
|
86
|
+
if (getOptionLabel || getSelectedValueLabel) {
|
|
87
|
+
if (context === 'value') {
|
|
88
|
+
return getSelectedOptionLabel ? getSelectedOptionLabel(option) : option.label;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return getOptionLabel ? getOptionLabel(option) : option.label;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return option.label;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const interceptOnChange = (newValue, actionMeta) => {
|
|
99
|
+
if (isMulti && onRemove && actionMeta.action === 'remove-value') {
|
|
100
|
+
onRemove({ id: actionMeta.removedValue });
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
onChange(newValue);
|
|
104
|
+
};
|
|
105
|
+
const props = {
|
|
106
|
+
id,
|
|
107
|
+
value,
|
|
108
|
+
inputId,
|
|
109
|
+
placeholder,
|
|
110
|
+
closeMenuOnSelect,
|
|
111
|
+
blurInputOnSelect: closeMenuOnSelect,
|
|
112
|
+
isSearchable: creatable ? true : isSearchable,
|
|
113
|
+
isMulti,
|
|
114
|
+
isClearable,
|
|
115
|
+
isLoading,
|
|
116
|
+
defaultValue,
|
|
117
|
+
noOptionsMessage: () => noOptionsMessage,
|
|
118
|
+
menuPortalTarget,
|
|
119
|
+
menuIsOpen,
|
|
120
|
+
onChange: interceptOnChange,
|
|
121
|
+
unstyled: true,
|
|
122
|
+
menuPlacement,
|
|
123
|
+
formatOptionLabel: getOptionOrSelectedLabel,
|
|
124
|
+
formatGroupLabel,
|
|
125
|
+
getOptionValue,
|
|
126
|
+
options,
|
|
127
|
+
isDisabled,
|
|
128
|
+
onMenuOpen,
|
|
129
|
+
onMenuClose,
|
|
130
|
+
components,
|
|
131
|
+
onMenuInputFocus,
|
|
132
|
+
onInputChange,
|
|
133
|
+
inputValue,
|
|
134
|
+
hideSelectedOptions: isMulti,
|
|
135
|
+
filterOption: filterOption ? filterOption : filterConfig ? createFilter(filterConfig) : undefined,
|
|
136
|
+
classNames: {
|
|
137
|
+
control: ({ menuIsOpen }) => {
|
|
138
|
+
let border = menuIsOpen ? 'tw-rounded-t-sm' : 'tw-rounded-sm';
|
|
139
|
+
// if it's on the left side of the input group make sure the right side is straight and not curved
|
|
140
|
+
if (inputGroup === 'left') {
|
|
141
|
+
border = menuIsOpen ? 'tw-rounded-tl-sm' : 'tw-rounded-l-sm';
|
|
142
|
+
}
|
|
143
|
+
else if (inputGroup === 'right') {
|
|
144
|
+
border = menuIsOpen ? 'tw-rounded-tr-sm' : 'tw-rounded-r-sm';
|
|
145
|
+
}
|
|
146
|
+
const appliedClasses = `${borderStyles} ${border} ${showError ? errorClasses : borderColorClasses} ${small ? 'reactSelectMinHeightSmall' : 'reactSelectMinHeight'} `;
|
|
147
|
+
return `${appliedClasses} ${baseClasses} specSelectControl ${isDisabled ? disabledClasses : ''} ${small ? 'tw-pl-2 tw-pr-1' : 'tw-pl-2.5 tw-pr-1.5'}`;
|
|
148
|
+
},
|
|
149
|
+
placeholder: () => placeholderStyles,
|
|
150
|
+
container: () => `${textStyles} ${containerStyles} ${extraClassNames}`,
|
|
151
|
+
input: () => textStyles + ' specSelectInput',
|
|
152
|
+
menuList: () => menuListStyles,
|
|
153
|
+
menu: () => menuStyles,
|
|
154
|
+
menuPortal: () => '!tw-z-[9000]',
|
|
155
|
+
dropdownIndicator: () => dropDownIndicatorStyles,
|
|
156
|
+
option: ({ isSelected, isDisabled }) => {
|
|
157
|
+
let classes = optionStyles;
|
|
158
|
+
if (isDisabled) {
|
|
159
|
+
classes += ' specDisabledOption ';
|
|
160
|
+
}
|
|
161
|
+
return isSelected ? classes + ' tw-bg-sq-colored-hover dark:tw-bg-sq-colored-hover-dark' : classes;
|
|
162
|
+
},
|
|
163
|
+
singleValue: () => 'specOpenSelect',
|
|
164
|
+
multiValue: () => multiValueStyles,
|
|
165
|
+
multiValueRemove: () => 'hover:tw-text-sq-danger-color specSelectMultiValueRemove',
|
|
166
|
+
clearIndicator: () => 'tw-text-sq-disabled-gray hover:tw-text-sq-danger-color specClearSelect',
|
|
167
|
+
group: () => 'specSelectGroup',
|
|
168
|
+
groupHeading: () => groupHeadingStyles,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
return creatable ? React.createElement(CreatableSelect, { ...props }) : React.createElement(ReactSelect, { ...props });
|
|
172
|
+
};
|
|
173
|
+
export default Select;
|
|
174
174
|
//# sourceMappingURL=Select.js.map
|
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import Select from './Select';
|
|
3
|
-
import TextField from '../TextField';
|
|
4
|
-
export default {
|
|
5
|
-
title: 'Select',
|
|
6
|
-
};
|
|
7
|
-
export const AllSelectVariants = () => {
|
|
8
|
-
const options = [
|
|
9
|
-
{ value: 'a', label: 'Chocolate' },
|
|
10
|
-
{ value: 'b', label: 'Strawberry' },
|
|
11
|
-
{ value: 'c', label: 'Vanilla' },
|
|
12
|
-
{ value: 'd', label: 'Rocky Road' },
|
|
13
|
-
{ value: 'e', label: 'Crazy Cow' },
|
|
14
|
-
{ value: 'f', label: 'Almond Joy' },
|
|
15
|
-
{ value: 'g', label: 'All of the above' },
|
|
16
|
-
];
|
|
17
|
-
const colorOptions = [
|
|
18
|
-
{ value: 'h', label: 'pink' },
|
|
19
|
-
{ value: 'i', label: 'purple' },
|
|
20
|
-
{ value: 'j', label: 'green' },
|
|
21
|
-
{ value: 'k', label: 'red' },
|
|
22
|
-
];
|
|
23
|
-
const groupedOptions = [
|
|
24
|
-
{
|
|
25
|
-
label: 'Ice Cream Flavors',
|
|
26
|
-
options: options,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
label: 'Colors',
|
|
30
|
-
options: colorOptions,
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
const customColorOption = (dropdownProps) => {
|
|
34
|
-
return (React.createElement("div", { style: { color: dropdownProps.data.label } }, dropdownProps.data.label));
|
|
35
|
-
};
|
|
36
|
-
const allSelects = () => (React.createElement(React.Fragment, null,
|
|
37
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
38
|
-
React.createElement(Select, { id: "hello", onChange: () => { }, options: options, placeholder: "single value" })),
|
|
39
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
40
|
-
React.createElement(Select, { id: "hello", onChange: () => { }, options: options, placeholder: "single value - small", small: true })),
|
|
41
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
42
|
-
React.createElement(Select, { id: "disabled", onChange: () => { }, options: options, placeholder: "disabled", isDisabled: true })),
|
|
43
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
44
|
-
React.createElement(Select, { id: "error", onChange: () => { }, options: options, placeholder: "error", showError: true })),
|
|
45
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
46
|
-
React.createElement(Select, { onChange: () => { }, options: options, placeholder: "stays open", closeMenuOnSelect: false, creatable: true })),
|
|
47
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
48
|
-
React.createElement(Select, { onChange: () => { }, options: groupedOptions, placeholder: "grouped" })),
|
|
49
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
50
|
-
React.createElement(Select, { onChange: () => { }, options: options, creatable: true, placeholder: "create option" })),
|
|
51
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
52
|
-
React.createElement(Select, { onChange: () => { }, options: options, isClearable: true, placeholder: "clearable" })),
|
|
53
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
54
|
-
React.createElement(Select, { onChange: () => { }, options: options, placeholder: "multi-select", isMulti: true, isSearchable: false })),
|
|
55
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
56
|
-
React.createElement(Select, { onChange: () => { }, placeholder: "type to search", options: options, isSearchable: true })),
|
|
57
|
-
React.createElement("div", { className: "tw-p-5 tw-flex tw-flex-row" },
|
|
58
|
-
React.createElement(Select, { onChange: () => { }, placeholder: "type to search", options: options, inputGroup: "left", extraClassNames: "tw-w-[200px]" }),
|
|
59
|
-
React.createElement(TextField, { onChange: () => { }, placeholder: "text goes here", inputGroup: "right" })),
|
|
60
|
-
React.createElement("div", { className: "tw-p-5" },
|
|
61
|
-
React.createElement(Select, { onChange: () => { }, options: colorOptions, placeholder: "custom option", components: { Option: (dropdownProps) => customColorOption(dropdownProps) } }))));
|
|
62
|
-
const renderAllVariations = () => (React.createElement(React.Fragment, null,
|
|
63
|
-
React.createElement("div", { className: "tw-grid tw-gap-4" },
|
|
64
|
-
allSelects(),
|
|
65
|
-
React.createElement("div", { className: "tw-dark tw-bg-sq-dark-background" }, allSelects()))));
|
|
66
|
-
return (React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4" },
|
|
67
|
-
React.createElement("div", { className: "color_topic" },
|
|
68
|
-
React.createElement("b", null, "Topic Colors"),
|
|
69
|
-
renderAllVariations()),
|
|
70
|
-
React.createElement("div", { className: "color_analysis" },
|
|
71
|
-
React.createElement("b", null, "Analysis Colors"),
|
|
72
|
-
renderAllVariations()),
|
|
73
|
-
React.createElement("div", { className: "color_datalab" },
|
|
74
|
-
React.createElement("b", null, "Datalab Colors"),
|
|
75
|
-
renderAllVariations()),
|
|
76
|
-
React.createElement("div", { className: "color_vantage" },
|
|
77
|
-
React.createElement("b", null, "Vantage Colors"),
|
|
78
|
-
renderAllVariations())));
|
|
79
|
-
};
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Select from './Select';
|
|
3
|
+
import TextField from '../TextField';
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Select',
|
|
6
|
+
};
|
|
7
|
+
export const AllSelectVariants = () => {
|
|
8
|
+
const options = [
|
|
9
|
+
{ value: 'a', label: 'Chocolate' },
|
|
10
|
+
{ value: 'b', label: 'Strawberry' },
|
|
11
|
+
{ value: 'c', label: 'Vanilla' },
|
|
12
|
+
{ value: 'd', label: 'Rocky Road' },
|
|
13
|
+
{ value: 'e', label: 'Crazy Cow' },
|
|
14
|
+
{ value: 'f', label: 'Almond Joy' },
|
|
15
|
+
{ value: 'g', label: 'All of the above' },
|
|
16
|
+
];
|
|
17
|
+
const colorOptions = [
|
|
18
|
+
{ value: 'h', label: 'pink' },
|
|
19
|
+
{ value: 'i', label: 'purple' },
|
|
20
|
+
{ value: 'j', label: 'green' },
|
|
21
|
+
{ value: 'k', label: 'red' },
|
|
22
|
+
];
|
|
23
|
+
const groupedOptions = [
|
|
24
|
+
{
|
|
25
|
+
label: 'Ice Cream Flavors',
|
|
26
|
+
options: options,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'Colors',
|
|
30
|
+
options: colorOptions,
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
const customColorOption = (dropdownProps) => {
|
|
34
|
+
return (React.createElement("div", { style: { color: dropdownProps.data.label } }, dropdownProps.data.label));
|
|
35
|
+
};
|
|
36
|
+
const allSelects = () => (React.createElement(React.Fragment, null,
|
|
37
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
38
|
+
React.createElement(Select, { id: "hello", onChange: () => { }, options: options, placeholder: "single value" })),
|
|
39
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
40
|
+
React.createElement(Select, { id: "hello", onChange: () => { }, options: options, placeholder: "single value - small", small: true })),
|
|
41
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
42
|
+
React.createElement(Select, { id: "disabled", onChange: () => { }, options: options, placeholder: "disabled", isDisabled: true })),
|
|
43
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
44
|
+
React.createElement(Select, { id: "error", onChange: () => { }, options: options, placeholder: "error", showError: true })),
|
|
45
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
46
|
+
React.createElement(Select, { onChange: () => { }, options: options, placeholder: "stays open", closeMenuOnSelect: false, creatable: true })),
|
|
47
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
48
|
+
React.createElement(Select, { onChange: () => { }, options: groupedOptions, placeholder: "grouped" })),
|
|
49
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
50
|
+
React.createElement(Select, { onChange: () => { }, options: options, creatable: true, placeholder: "create option" })),
|
|
51
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
52
|
+
React.createElement(Select, { onChange: () => { }, options: options, isClearable: true, placeholder: "clearable" })),
|
|
53
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
54
|
+
React.createElement(Select, { onChange: () => { }, options: options, placeholder: "multi-select", isMulti: true, isSearchable: false })),
|
|
55
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
56
|
+
React.createElement(Select, { onChange: () => { }, placeholder: "type to search", options: options, isSearchable: true })),
|
|
57
|
+
React.createElement("div", { className: "tw-p-5 tw-flex tw-flex-row" },
|
|
58
|
+
React.createElement(Select, { onChange: () => { }, placeholder: "type to search", options: options, inputGroup: "left", extraClassNames: "tw-w-[200px]" }),
|
|
59
|
+
React.createElement(TextField, { onChange: () => { }, placeholder: "text goes here", inputGroup: "right" })),
|
|
60
|
+
React.createElement("div", { className: "tw-p-5" },
|
|
61
|
+
React.createElement(Select, { onChange: () => { }, options: colorOptions, placeholder: "custom option", components: { Option: (dropdownProps) => customColorOption(dropdownProps) } }))));
|
|
62
|
+
const renderAllVariations = () => (React.createElement(React.Fragment, null,
|
|
63
|
+
React.createElement("div", { className: "tw-grid tw-gap-4" },
|
|
64
|
+
allSelects(),
|
|
65
|
+
React.createElement("div", { className: "tw-dark tw-bg-sq-dark-background" }, allSelects()))));
|
|
66
|
+
return (React.createElement("div", { className: "tw-grid tw-grid-cols-4 tw-gap-4" },
|
|
67
|
+
React.createElement("div", { className: "color_topic" },
|
|
68
|
+
React.createElement("b", null, "Topic Colors"),
|
|
69
|
+
renderAllVariations()),
|
|
70
|
+
React.createElement("div", { className: "color_analysis" },
|
|
71
|
+
React.createElement("b", null, "Analysis Colors"),
|
|
72
|
+
renderAllVariations()),
|
|
73
|
+
React.createElement("div", { className: "color_datalab" },
|
|
74
|
+
React.createElement("b", null, "Datalab Colors"),
|
|
75
|
+
renderAllVariations()),
|
|
76
|
+
React.createElement("div", { className: "color_vantage" },
|
|
77
|
+
React.createElement("b", null, "Vantage Colors"),
|
|
78
|
+
renderAllVariations())));
|
|
79
|
+
};
|
|
80
80
|
//# sourceMappingURL=Select.stories.js.map
|