@spothero/ui 15.9.1 → 15.9.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spothero/ui",
3
- "version": "15.9.1",
3
+ "version": "15.9.3",
4
4
  "description": "SpotHero's React component UI library.",
5
5
  "main": "v2/index.js",
6
6
  "repository": "https://github.com/spothero/fe-monorepo",
@@ -1,4 +1,4 @@
1
- import React, {forwardRef, useState} from 'react';
1
+ import React, {forwardRef} from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import FormControl from '../FormControl/FormControl';
4
4
  import AsyncSelect from 'react-select/async';
@@ -15,7 +15,6 @@ const AutoSuggestSelect = forwardRef(
15
15
  isInvalid,
16
16
  isDisabled,
17
17
  isRequired,
18
- isOptional,
19
18
  getOptions,
20
19
  onChange,
21
20
  iconSrc,
@@ -23,13 +22,10 @@ const AutoSuggestSelect = forwardRef(
23
22
  },
24
23
  ref
25
24
  ) => {
26
- const [query, setQuery] = useState('');
27
25
  const {colors, fontSizes, sizes} = useTheme();
28
26
 
29
- const handleInputChange = value => setQuery(value);
30
-
31
- const loadOptions = () => {
32
- return getOptions(query);
27
+ const handleChange = selectedOption => {
28
+ onChange(selectedOption);
33
29
  };
34
30
 
35
31
  const icon = (color = 'transparent') => ({
@@ -136,7 +132,6 @@ const AutoSuggestSelect = forwardRef(
136
132
  <FormControl
137
133
  errorMessage={errorMessage}
138
134
  isRequired={isRequired}
139
- isOptional={isOptional}
140
135
  helperText={helperText}
141
136
  label={label}
142
137
  inputId={id}
@@ -144,15 +139,15 @@ const AutoSuggestSelect = forwardRef(
144
139
  <AsyncSelect
145
140
  closeMenuOnSelect
146
141
  isClearable
142
+ cacheOptions
147
143
  components={{
148
144
  DropdownIndicator: () => null,
149
145
  IndicatorSeparator: () => null,
150
146
  ClearIndicator,
151
147
  }}
152
148
  openMenuOnClick={false}
153
- loadOptions={loadOptions}
154
- onInputChange={handleInputChange}
155
- onChange={onChange}
149
+ loadOptions={getOptions}
150
+ onChange={handleChange}
156
151
  isDisabled={isDisabled}
157
152
  id={id}
158
153
  placeholder={placeholder}
@@ -173,7 +168,7 @@ AutoSuggestSelect.propTypes = {
173
168
  placeholder: PropTypes.string,
174
169
  /** Optional helper text displayed below the select */
175
170
  helperText: PropTypes.string,
176
- /** Error message that would display under the select */
171
+ /** Error message that would dispplay under the select */
177
172
  errorMessage: PropTypes.string,
178
173
  /** Boolean that sets whether the select is valid */
179
174
  isInvalid: PropTypes.bool,
@@ -181,8 +176,6 @@ AutoSuggestSelect.propTypes = {
181
176
  isDisabled: PropTypes.bool,
182
177
  /** Boolean that sets whether the select is required */
183
178
  isRequired: PropTypes.bool,
184
- /** Boolean that sets whether the select is optional */
185
- isOptional: PropTypes.bool,
186
179
  /** Function that is called with the value typed into the input that returns a list of options for the select */
187
180
  getOptions: PropTypes.func.isRequired,
188
181
  /** Function that is called when an option is selected, it returns the label and value of the selection */
@@ -1,8 +1,7 @@
1
- import React, {forwardRef} from 'react';
2
1
  import cn from 'classnames';
3
2
  import PropTypes from 'prop-types';
4
- import ReactSelect from 'react-select';
5
-
3
+ import React, {forwardRef} from 'react';
4
+ import {Select as ChakraSelect} from '@chakra-ui/react';
6
5
  import IconChevronDown from '@spothero/icons/chevron-down';
7
6
 
8
7
  import Icon from '../Icon/Icon';
@@ -18,127 +17,12 @@ const Select = forwardRef(
18
17
  isDisabled,
19
18
  isRequired,
20
19
  isOptional,
21
- options,
22
20
  ...props
23
21
  },
24
22
  ref
25
23
  ) => {
26
24
  const classes = cn({'FormElement-contains-error': isInvalid});
27
25
 
28
- const baseText = {
29
- fontSize: 'var(--chakra-fontSizes-base)',
30
- color: 'var(--chakra-colors-text-primary-light)',
31
- };
32
-
33
- /** React Select doesn't use Chakra but it does use Emotion so it's not too difficult to use values from our Chakra theme. Here is the documentation for React Select styling: https://react-select.com/styles */
34
- const customStyles = {
35
- select: (provided, state) => ({
36
- ...provided,
37
-
38
- '&:hover': {
39
- cursor: state.isDisabled ? 'not-allowed' : 'auto',
40
- },
41
- }),
42
- menu: provided => ({
43
- ...provided,
44
- ...baseText,
45
- borderColor: 'var(--chakra-colors-gray-200)',
46
- borderWidth: '1px',
47
- boxShadow: 'none',
48
- }),
49
- control: (provided, state) => ({
50
- ...provided,
51
- borderColor: isInvalid
52
- ? 'var(--chakra-colors-error)'
53
- : state.isFocused
54
- ? 'var(--chakra-colors-primary-default)'
55
- : 'var(--chakra-colors-gray-200)',
56
- borderWidth: '1px',
57
- borderRadius: '4px',
58
- backgroundColor: state.isDisabled
59
- ? 'var(--chakra-colors-gray-50)'
60
- : 'transparent',
61
- boxShadow: 'none',
62
- height: 'var(--chakra-sizes-10)',
63
- minWidth: 'var(--chakra-sizes-48)',
64
- width: props.width && props.width,
65
-
66
- '&:hover': {
67
- borderColor: isInvalid
68
- ? 'var(--chakra-colors-error)'
69
- : state.isFocused
70
- ? 'var(--chakra-colors-primary-default)'
71
- : 'var(--chakra-colors-gray-200)',
72
- },
73
- }),
74
- input: (provided, state) => ({
75
- ...provided,
76
- ...baseText,
77
- borderRadius: '4px',
78
- color: state.isDisabled
79
- ? 'var(--chakra-colors-text-secondary-light)'
80
- : 'var(--chakra-colors-text-primary-light)',
81
- backgroundColor: state.isDisabled
82
- ? 'var(--chakra-colors-gray-50)'
83
- : 'transparent',
84
- }),
85
- placeholder: provided => ({
86
- ...provided,
87
- fontSize: 'var(--chakra-fontSizes-base)',
88
- color: 'var(--chakra-colors-gray-600)',
89
- }),
90
- singleValue: (provided, state) => ({
91
- ...provided,
92
- ...baseText,
93
- color: state.isDisabled
94
- ? 'var(--chakra-colors-text-secondary-light)'
95
- : 'var(--chakra-colors-text-primary-light)',
96
-
97
- '&:hover': {
98
- cursor: state.isDisabled ? 'not-allowed' : 'auto',
99
- },
100
- }),
101
- option: (provided, state) => ({
102
- ...provided,
103
- backgroundColor: state.isSelected
104
- ? 'var(--chakra-colors-gray-200)'
105
- : state.isFocused
106
- ? 'var(--chakra-colors-gray-50)'
107
- : 'transparent',
108
- color: 'var(--chakra-colors-text-primary-light)',
109
- fontWeight: state.isSelected
110
- ? 'var(--chakra-fontWeights-semibold)'
111
- : 'var(--chakra-fontWeights-normal)',
112
-
113
- ':active': {
114
- fontWeight: 'var(--chakra-fontWeights-semibold)',
115
- color: 'var(--chakra-colors-text-primary-light)',
116
- backgroundColor:
117
- !state.isDisabled && 'var(--chakra-colors-gray-200)',
118
- },
119
- }),
120
- };
121
-
122
- const dropdownIndicatorStyles = {
123
- width: 18,
124
- display: 'flex',
125
- marginRight: 'var(--chakra-space-4)',
126
- marginLeft: 'var(--chakra-space-7)',
127
- color: 'var(--chakra-colors-gray-600)',
128
- '&:hover': {
129
- color: 'var(--chakra-colors-gray-600)',
130
- },
131
- };
132
-
133
- const DropdownIndicator = ({innerRef, innerProps}) => (
134
- <Icon
135
- as={IconChevronDown}
136
- style={dropdownIndicatorStyles}
137
- ref={innerRef}
138
- {...innerProps}
139
- />
140
- );
141
-
142
26
  return (
143
27
  <FormControl
144
28
  isInvalid={isInvalid}
@@ -149,19 +33,12 @@ const Select = forwardRef(
149
33
  helperText={helperText}
150
34
  label={label}
151
35
  inputId={props.id}
152
- minWidth={48}
153
- width={props.width && props.width}
154
36
  >
155
- <ReactSelect
156
- options={options?.length && options}
157
- isSearchable={false}
158
- isDisabled={isDisabled}
159
- components={{
160
- DropdownIndicator,
161
- IndicatorSeparator: () => null,
162
- }}
163
- maxMenuHeight={280}
164
- styles={customStyles}
37
+ <ChakraSelect
38
+ icon={<Icon as={IconChevronDown} />}
39
+ iconSize={12}
40
+ fontWeight="regular"
41
+ fontSize="sm"
165
42
  ref={ref}
166
43
  className={classes}
167
44
  {...props}
@@ -173,11 +50,8 @@ const Select = forwardRef(
173
50
 
174
51
  Select.propTypes = {
175
52
  id: PropTypes.string.isRequired,
176
- options: PropTypes.array,
177
53
  label: PropTypes.string,
178
- isRequired: PropTypes.bool,
179
54
  helperText: PropTypes.string,
180
- placeholder: PropTypes.string,
181
55
  errorMessage: PropTypes.string,
182
56
  isInvalid: PropTypes.bool,
183
57
  isDisabled: PropTypes.bool,
@@ -11,7 +11,14 @@ export default {
11
11
  },
12
12
  };
13
13
 
14
- const SelectTemplate = props => <Component options {...props} />;
14
+ const SelectTemplate = props => (
15
+ <Component variant="outline" maxWidth="200px" {...props}>
16
+ <option value="one">One</option>
17
+ <option value="two">Two</option>
18
+ <option value="three">Three</option>
19
+ <option value="four">Four</option>
20
+ </Component>
21
+ );
15
22
 
16
23
  SelectTemplate.propTypes = {
17
24
  placeholder: PropTypes.string,
@@ -21,54 +28,33 @@ SelectTemplate.propTypes = {
21
28
  isInvalid: PropTypes.bool,
22
29
  isDisabled: PropTypes.bool,
23
30
  isReadOnly: PropTypes.bool,
24
- isOptional: PropTypes.bool,
25
31
  };
26
32
 
27
33
  export const Select = SelectTemplate.bind({});
28
34
 
29
35
  Select.argTypes = {
30
- id: {control: {type: 'text'}},
31
- options: {
32
- control: {type: 'object'},
36
+ placeholder: {
37
+ control: {type: 'text'},
33
38
  },
34
39
  label: {
35
40
  control: {type: 'text'},
36
41
  },
37
- isRequired: {control: {type: 'boolean'}},
38
42
  helperText: {
39
43
  control: {type: 'text'},
40
44
  },
41
- placeholder: {
42
- control: {type: 'text'},
43
- },
44
45
  errorMessage: {
45
46
  control: {type: 'text'},
46
47
  },
47
- isInvalid: {control: {type: 'boolean'}},
48
- isDisabled: {control: {type: 'boolean'}},
49
48
  };
50
49
 
51
50
  Select.args = {
52
- id: 'input_id',
53
- options: [
54
- {value: 'One', label: 'Option One'},
55
- {value: 'Two', label: 'Option Two'},
56
- {value: 'Three', label: 'Option Three'},
57
- {value: 'Four', label: 'Option Four'},
58
- {value: 'Five', label: 'Option Five'},
59
- {value: 'Six', label: 'Option Six'},
60
- {value: 'Seven', label: 'Option Seven'},
61
- {value: 'Eight', label: 'Option Eight'},
62
- {value: 'Nine', label: 'Option Nine'},
63
- {value: 'Ten', label: 'Option Ten'},
64
- ],
51
+ placeholder: 'Placeholder text',
65
52
  label: 'Label',
66
- isRequired: false,
67
53
  helperText: 'Helper text',
68
- placeholder: 'Select One...',
69
54
  errorMessage: 'Error message',
70
55
  isInvalid: false,
71
56
  isDisabled: false,
72
57
  isReadOnly: false,
58
+ isRequired: false,
73
59
  isOptional: false,
74
60
  };
@@ -0,0 +1,29 @@
1
+ import merge from 'lodash/merge';
2
+ import chakraDefaultTheme from '@chakra-ui/theme';
3
+
4
+ const variants = {
5
+ outline: {
6
+ field: {
7
+ border: '1px solid',
8
+ borderColor: 'inherit',
9
+ bg: 'inherit',
10
+ _hover: {borderColor: 'gray.300'},
11
+ _readOnly: {boxShadow: 'none !important', userSelect: 'all'},
12
+ _disabled: {opacity: 0.4, cursor: 'not-allowed'},
13
+ _invalid: {
14
+ borderColor: 'error',
15
+ boxShadow: t => `0 0 0 1px ${t.colors.error}`,
16
+ },
17
+ _focus: {
18
+ zIndex: 1,
19
+ borderColor: 'primary.400',
20
+ boxShadow: t => `0 0 0 1px ${t.colors.primary['400']}`,
21
+ },
22
+ },
23
+ addon: {border: '1px solid', borderColor: 'inherit', bg: 'gray.100'},
24
+ },
25
+ };
26
+
27
+ export default merge(chakraDefaultTheme.components.Select, {
28
+ variants,
29
+ });
@@ -9,6 +9,7 @@ export {default as Spinner} from './Spinner/Spinner.styles';
9
9
  export {default as Heading} from './Heading/Heading.styles';
10
10
  export {default as Divider} from './Divider/Divider.styles';
11
11
  export {default as Tabs} from './Tabs/styles';
12
+ export {default as Select} from './Select/styles';
12
13
  export {default as Checkbox} from './Checkbox/styles';
13
14
  export {default as Switch} from './Switch/styles';
14
15
  export {default as Popover} from './Popover/styles';