@comicrelief/component-library 8.32.0 → 8.33.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.
|
@@ -15,7 +15,7 @@ var _spacing = _interopRequireDefault(require("../../../theme/shared/spacing"));
|
|
|
15
15
|
const StyledSelect = _styledComponents.default.select.withConfig({
|
|
16
16
|
displayName: "Select__StyledSelect",
|
|
17
17
|
componentId: "sc-1atp8e3-0"
|
|
18
|
-
})(["width:100%;font-size:", ";display:block;box-sizing:border-box;padding:0 ", ";padding-right:", ";margin:0;position:relative;height:48px;font-weight:400;font-family:", ";background:", "
|
|
18
|
+
})(["width:100%;font-size:", ";display:block;box-sizing:border-box;padding:0 ", ";padding-right:", ";margin:0;position:relative;height:48px;font-weight:400;font-family:", ";background:", ";border:1px solid;border-color:", ";box-shadow:none;appearance:none;color:", ";border-radius:0.5rem;cursor:pointer;:focus{border:1px solid ", ";}@media ", "{max-width:290px;}"], _ref => {
|
|
19
19
|
let {
|
|
20
20
|
theme
|
|
21
21
|
} = _ref;
|
|
@@ -27,10 +27,11 @@ const StyledSelect = _styledComponents.default.select.withConfig({
|
|
|
27
27
|
return theme.fontFamilies(theme.font.regular);
|
|
28
28
|
}, _ref3 => {
|
|
29
29
|
let {
|
|
30
|
-
theme
|
|
30
|
+
theme,
|
|
31
|
+
hideArrow
|
|
31
32
|
} = _ref3;
|
|
32
|
-
return theme.color('grey_light')
|
|
33
|
-
},
|
|
33
|
+
return hideArrow ? theme.color('grey_light') : `${theme.color('grey_light')} url(${_dropDownDarkPurple.default}) calc(100% - 1.5rem) 14px/20px 1.5rem no-repeat`;
|
|
34
|
+
}, _ref4 => {
|
|
34
35
|
let {
|
|
35
36
|
theme,
|
|
36
37
|
error
|
|
@@ -66,9 +67,11 @@ const Select = /*#__PURE__*/_react.default.forwardRef((_ref8, ref) => {
|
|
|
66
67
|
greyDescription = false,
|
|
67
68
|
className = '',
|
|
68
69
|
optional = false,
|
|
70
|
+
hideArrow = false,
|
|
69
71
|
...rest
|
|
70
72
|
} = _ref8;
|
|
71
|
-
const
|
|
73
|
+
const initialValue = hideArrow ? options[0].value : defaultValue;
|
|
74
|
+
const [value, setValue] = (0, _react.useState)(initialValue);
|
|
72
75
|
return /*#__PURE__*/_react.default.createElement(_Label.default, {
|
|
73
76
|
label: label,
|
|
74
77
|
hideLabel: hideLabel,
|
|
@@ -88,8 +91,10 @@ const Select = /*#__PURE__*/_react.default.forwardRef((_ref8, ref) => {
|
|
|
88
91
|
required: optional === false,
|
|
89
92
|
hasValue: !!value,
|
|
90
93
|
greyDescription: greyDescription,
|
|
91
|
-
ref: ref
|
|
92
|
-
|
|
94
|
+
ref: ref,
|
|
95
|
+
hideArrow: hideArrow
|
|
96
|
+
}), /* empty string "" is falsy so will show */
|
|
97
|
+
!initialValue && /*#__PURE__*/_react.default.createElement("option", {
|
|
93
98
|
disabled: true,
|
|
94
99
|
value: ""
|
|
95
100
|
}, description), options.map(option => /*#__PURE__*/_react.default.createElement("option", {
|
|
@@ -32,4 +32,16 @@
|
|
|
32
32
|
{ value: 'Option four', displayValue: 'The fourth option' }
|
|
33
33
|
]}
|
|
34
34
|
/>
|
|
35
|
+
|
|
36
|
+
<h4>DROPDOWN MENU - hide arrow / just one option</h4>
|
|
37
|
+
<Select
|
|
38
|
+
label="Label"
|
|
39
|
+
errorMsg="This is an error message"
|
|
40
|
+
description="Select an option"
|
|
41
|
+
greyDescription
|
|
42
|
+
hideArrow={true}
|
|
43
|
+
options={[
|
|
44
|
+
{ value: 'Option one', displayValue: 'The first option' }
|
|
45
|
+
]}
|
|
46
|
+
/>
|
|
35
47
|
```
|
package/package.json
CHANGED
|
@@ -19,8 +19,9 @@ const StyledSelect = styled.select`
|
|
|
19
19
|
height: 48px;
|
|
20
20
|
font-weight: 400;
|
|
21
21
|
font-family: ${({ theme }) => theme.fontFamilies(theme.font.regular)};
|
|
22
|
-
background: ${({ theme }) =>
|
|
23
|
-
|
|
22
|
+
background: ${({ theme, hideArrow }) => (hideArrow
|
|
23
|
+
? theme.color('grey_light')
|
|
24
|
+
: `${theme.color('grey_light')} url(${dropDownIcon}) calc(100% - 1.5rem) 14px/20px 1.5rem no-repeat`)};
|
|
24
25
|
border: 1px solid;
|
|
25
26
|
border-color: ${({ theme, error }) => (error ? theme.color('red') : theme.color('grey_medium'))};
|
|
26
27
|
box-shadow: none;
|
|
@@ -50,11 +51,13 @@ const Select = React.forwardRef(
|
|
|
50
51
|
greyDescription = false,
|
|
51
52
|
className = '',
|
|
52
53
|
optional = false,
|
|
54
|
+
hideArrow = false,
|
|
53
55
|
...rest
|
|
54
56
|
},
|
|
55
57
|
ref
|
|
56
58
|
) => {
|
|
57
|
-
const [value
|
|
59
|
+
const initialValue = hideArrow ? options[0].value : defaultValue;
|
|
60
|
+
const [value, setValue] = useState(initialValue);
|
|
58
61
|
|
|
59
62
|
return (
|
|
60
63
|
<Label
|
|
@@ -78,10 +81,16 @@ const Select = React.forwardRef(
|
|
|
78
81
|
hasValue={!!value}
|
|
79
82
|
greyDescription={greyDescription}
|
|
80
83
|
ref={ref}
|
|
84
|
+
hideArrow={hideArrow}
|
|
81
85
|
>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
86
|
+
|
|
87
|
+
{/* empty string "" is falsy so will show */
|
|
88
|
+
!initialValue && (
|
|
89
|
+
<option disabled value="">
|
|
90
|
+
{description}
|
|
91
|
+
</option>
|
|
92
|
+
)}
|
|
93
|
+
|
|
85
94
|
{options.map(option => (
|
|
86
95
|
<option key={option.value} value={option.value}>
|
|
87
96
|
{option.displayValue}
|
|
@@ -111,7 +120,8 @@ Select.propTypes = {
|
|
|
111
120
|
// className is needed so that styled(`Select`) will work
|
|
112
121
|
// (as `rest` is not spread on the outermost component)
|
|
113
122
|
className: PropTypes.string,
|
|
114
|
-
optional: PropTypes.bool
|
|
123
|
+
optional: PropTypes.bool,
|
|
124
|
+
hideArrow: PropTypes.bool
|
|
115
125
|
};
|
|
116
126
|
|
|
117
127
|
export default Select;
|
|
@@ -32,4 +32,16 @@
|
|
|
32
32
|
{ value: 'Option four', displayValue: 'The fourth option' }
|
|
33
33
|
]}
|
|
34
34
|
/>
|
|
35
|
+
|
|
36
|
+
<h4>DROPDOWN MENU - hide arrow / just one option</h4>
|
|
37
|
+
<Select
|
|
38
|
+
label="Label"
|
|
39
|
+
errorMsg="This is an error message"
|
|
40
|
+
description="Select an option"
|
|
41
|
+
greyDescription
|
|
42
|
+
hideArrow={true}
|
|
43
|
+
options={[
|
|
44
|
+
{ value: 'Option one', displayValue: 'The first option' }
|
|
45
|
+
]}
|
|
46
|
+
/>
|
|
35
47
|
```
|