Skip to content

Commit 80bddf2

Browse files
authored
Add isError prop to Select (#722)
* Add isError prop to Select * fix naming * fix version
1 parent 207af97 commit 80bddf2

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nordcloud/gnui",
33
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
4-
"version": "10.3.0",
4+
"version": "10.3.1",
55
"license": "MIT",
66
"repository": {
77
"type": "git",

src/components/select/Select.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ https://react-select.com/props
1515
<Story of={SelectStories.Basic} />
1616
</Canvas>
1717

18-
## Basic Select
18+
## Disabled
1919

2020
<Canvas>
2121
<Story of={SelectStories.Disabled} />
2222
</Canvas>
2323

24+
## Error
25+
26+
<Canvas>
27+
<Story of={SelectStories.isError} />
28+
</Canvas>
29+
2430
## Multiselect
2531

2632
<Canvas>

src/components/select/Select.stories.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,28 @@ export const Disabled: StoryObj = {
7070

7171
name: "disabled",
7272
};
73+
export const isError: StoryObj = {
74+
render: () => {
75+
const options = [
76+
{
77+
value: "chocolate",
78+
label: "Chocolate",
79+
},
80+
];
81+
82+
return (
83+
<div
84+
style={{
85+
height: "150px",
86+
}}
87+
>
88+
<Select isError options={options} />
89+
</div>
90+
);
91+
},
92+
93+
name: "isError",
94+
};
7395

7496
export const Multiselect: StoryObj = {
7597
render: () => {

src/components/select/Select.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@ import ReactSelect, {
66
type StylesConfig,
77
type Props as ReactSelectProps,
88
} from "react-select";
9-
import styled from "styled-components";
9+
import styled, { css } from "styled-components";
1010
import theme from "../../theme";
1111

12-
const SelectContainer = styled.div`
12+
const SelectContainer = styled.div<{ isError?: boolean }>`
1313
.react-select {
1414
&-container {
1515
& > .react-select__control {
1616
background: ${theme.color.field.default};
1717
border: 1px solid ${theme.color.border.input};
18+
${({ isError }) =>
19+
isError &&
20+
css`
21+
border: 1px solid ${theme.color.border.error};
22+
`}
1823
&:hover {
1924
border: 1px solid ${theme.color.border.border02};
2025
}
@@ -57,7 +62,7 @@ const SelectContainer = styled.div`
5762
}
5863
}
5964
&__placeholder {
60-
color: ${theme.color.text.text03};
65+
color: ${theme.color.text.text02};
6166
}
6267
&__single-value {
6368
color: ${theme.color.text.text01};
@@ -111,6 +116,7 @@ export type SelectOption = {
111116

112117
export type SelectColoredOption = SelectOption & {
113118
color: string;
119+
isError?: boolean;
114120
};
115121

116122
function getDefaultStyles<
@@ -242,11 +248,13 @@ function SelectInner<
242248
{
243249
styles = getDefaultStyles(),
244250
...props
245-
}: ReactSelectProps<Option, IsMulti, Group>,
251+
}: ReactSelectProps<Option, IsMulti, Group> & {
252+
isError?: boolean;
253+
},
246254
ref: React.ForwardedRef<SelectInstance<Option, IsMulti, Group>>
247255
) {
248256
return (
249-
<SelectContainer>
257+
<SelectContainer isError={props.isError}>
250258
<ReactSelect
251259
ref={ref}
252260
className="react-select-container"

0 commit comments

Comments
 (0)