-
Notifications
You must be signed in to change notification settings - Fork 151
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 new Select component #219
Conversation
cd8b05f
to
a009d91
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@williamkolmacka and pls rebase 🙏
src/Select/Select.js
Outdated
<ChevronDown /> | ||
</SelectSuffix> | ||
</SelectContainer> | ||
{help ? <Feedback type="help">{help}</Feedback> : <Feedback type="error">{error}</Feedback>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evaluate if help
or error
is defined. It renders empty component now.
src/Select/Select.js
Outdated
pointer-events: none; | ||
`; | ||
|
||
const SelectSizeCondition = (theme, size) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that you will use this condition directly on line 88 and delete this const. Also please add TODO for token create.
src/Select/Select.js
Outdated
this.props.onChange(e); | ||
}; | ||
|
||
renderOption = ({ value, label, visible = true }: Option) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You defined disabled
in Option type but you are not rendering it anywhere.
src/Select/Select.js
Outdated
cursor: default; | ||
} | ||
/* placeholder */ | ||
&:invalid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please for placeholder
style use another way. Required attr will probably render native browser error. Do this like:
const isPlaceholder = this.props.placeholder && this.state.value === ""
You then pass this const to StyledSelect
and it'll decide which color should apply.
src/Select/Select.js
Outdated
value: string | number, | ||
label?: string, | ||
disabled?: boolean, | ||
visible?: boolean, // eslint-disable-line react/no-unused-prop-types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is no logical reason to use visible
more, please delete it everywhere.
src/Select/Select.js
Outdated
const { value } = this.state; | ||
return ( | ||
<React.Fragment> | ||
{label && <Text>{label}</Text>} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm completely missing label
knob in stories. Don't forget that label's color is changing on the selected value.
src/Select/__tests__/Select.test.js
Outdated
describe("Select", () => { | ||
const component = shallow(<Select value="1" options={objectOptions} onChange={mockChange} />); | ||
const componentWithPlaceholder = shallow( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can merge these two shallow wrappers into one.
ee3fcb1
to
3ee0295
Compare
src/Select/Select.js
Outdated
margin-bottom: ${({ theme }) => theme.spaceXXSmall}; | ||
`; | ||
|
||
const SelectContainer = styled(({ theme, ...props }) => <div {...props} />)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit error
or:
const SelectContainer = styled(({ children, className }) => (
<div className={className}>{children}</div>
))`
src/Select/Select.js
Outdated
box-sizing: border-box; | ||
cursor: pointer; | ||
&:hover { | ||
border-color: ${({ theme, active, error }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disable hover
when select is disabled
src/Select/Select.js
Outdated
return ( | ||
<React.Fragment> | ||
{label && ( | ||
<SelectLabel theme={theme} value={value}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be select
focused and opened after clicking on label
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can make this when we will have custom select ready. For now, it is not so much important.
3ee0295
to
f27fd45
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And don't forget to rebase 🙏
label?: string, | ||
placeholder?: string, | ||
value: string, | ||
disabled?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When select is disabled, styles are not changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch 👏
const placeholder = text("Placeholder", "Select value from list"); | ||
const size = select("Size", Object.values(SIZE_OPTIONS), SIZE_OPTIONS.NORMAL); | ||
const disabled = boolean("Disabled", false); | ||
const option = object("Options", objectOptions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add value
knob to playground.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
@@ -5,6 +5,8 @@ import { shallow } from "enzyme"; | |||
|
|||
import Select from "../Select"; | |||
|
|||
const mockChange = jest.fn(); | |||
const placeholder = "Default placeholder"; | |||
const objectOptions = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visible
is not needed in this object more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
padding-left: ${({ prefix }) => prefix && "48px"}; // TODO: Create token | ||
|
||
/* Based on state of select */ | ||
border-color: ${({ theme, error }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
border: 1px solid ....
and delete line 44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It defines basic style of border, so I want to let it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok :)
src/Select/Select.js
Outdated
} | ||
`; | ||
|
||
const SelectContainer = styled.div` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disabled
attr is render for this div
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/Select/Select.js
Outdated
pointer-events: none; | ||
`; | ||
|
||
const SelectSuffix = styled.div` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
disabled
attr is render for this div
13afa56
to
7a7613e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job 👏
This Pull Request meets the following criteria:
Add a new Select component. There are still some values in CSS that are not in tokens.