Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add isError prop to Select #722

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nordcloud/gnui",
"description": "Nordcloud Design System - a collection of reusable React components used in Nordcloud's SaaS products",
"version": "10.3.0",
"version": "10.3.3",
raczyk marked this conversation as resolved.
Show resolved Hide resolved
"license": "MIT",
"repository": {
"type": "git",
Expand Down
8 changes: 7 additions & 1 deletion src/components/select/Select.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ https://react-select.com/props
<Story of={SelectStories.Basic} />
</Canvas>

## Basic Select
## Disabled

<Canvas>
<Story of={SelectStories.Disabled} />
</Canvas>

## Error

<Canvas>
<Story of={SelectStories.isError} />
</Canvas>

## Multiselect

<Canvas>
Expand Down
22 changes: 22 additions & 0 deletions src/components/select/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ export const Disabled: StoryObj = {

name: "disabled",
};
export const isError: StoryObj = {
render: () => {
const options = [
{
value: "chocolate",
label: "Chocolate",
},
];

return (
<div
style={{
height: "150px",
}}
>
<Select isError options={options} />
</div>
);
},

name: "isError",
};

export const Multiselect: StoryObj = {
render: () => {
Expand Down
18 changes: 13 additions & 5 deletions src/components/select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ import ReactSelect, {
type StylesConfig,
type Props as ReactSelectProps,
} from "react-select";
import styled from "styled-components";
import styled, { css } from "styled-components";
import theme from "../../theme";

const SelectContainer = styled.div`
const SelectContainer = styled.div<{ isError?: boolean }>`
.react-select {
&-container {
& > .react-select__control {
background: ${theme.color.field.default};
border: 1px solid ${theme.color.border.input};
${({ isError }) =>
isError &&
css`
border: 1px solid ${theme.color.border.error};
`}
&:hover {
border: 1px solid ${theme.color.border.border02};
}
Expand Down Expand Up @@ -57,7 +62,7 @@ const SelectContainer = styled.div`
}
}
&__placeholder {
color: ${theme.color.text.text03};
color: ${theme.color.text.text02};
}
&__single-value {
color: ${theme.color.text.text01};
Expand Down Expand Up @@ -111,6 +116,7 @@ export type SelectOption = {

export type SelectColoredOption = SelectOption & {
color: string;
isError?: boolean;
};

function getDefaultStyles<
Expand Down Expand Up @@ -242,11 +248,13 @@ function SelectInner<
{
styles = getDefaultStyles(),
...props
}: ReactSelectProps<Option, IsMulti, Group>,
}: ReactSelectProps<Option, IsMulti, Group> & {
isError?: boolean;
},
ref: React.ForwardedRef<SelectInstance<Option, IsMulti, Group>>
) {
return (
<SelectContainer>
<SelectContainer isError={props.isError}>
<ReactSelect
ref={ref}
className="react-select-container"
Expand Down
Loading