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 new Select component #219

Merged
merged 1 commit into from
Jun 20, 2018
Merged

Add new Select component #219

merged 1 commit into from
Jun 20, 2018

Conversation

williamkolmacka
Copy link
Collaborator

This Pull Request meets the following criteria:

  • Tests have been added/adjusted for my new feature
  • New Components are registered in index.js of my project

Add a new Select component. There are still some values in CSS that are not in tokens.

@williamkolmacka williamkolmacka added the Review needed Pull Requests that are considered complete label Jun 19, 2018
@williamkolmacka williamkolmacka added this to the Orbit Components 0.2 milestone Jun 19, 2018
@williamkolmacka williamkolmacka self-assigned this Jun 19, 2018
@tomashapl tomashapl requested a review from vepor June 19, 2018 08:14
Copy link
Contributor

@vepor vepor left a 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 🙏

<ChevronDown />
</SelectSuffix>
</SelectContainer>
{help ? <Feedback type="help">{help}</Feedback> : <Feedback type="error">{error}</Feedback>}
Copy link
Contributor

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.

pointer-events: none;
`;

const SelectSizeCondition = (theme, size) => {
Copy link
Contributor

@vepor vepor Jun 19, 2018

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.

this.props.onChange(e);
};

renderOption = ({ value, label, visible = true }: Option) => {
Copy link
Contributor

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.

cursor: default;
}
/* placeholder */
&:invalid {
Copy link
Contributor

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.

value: string | number,
label?: string,
disabled?: boolean,
visible?: boolean, // eslint-disable-line react/no-unused-prop-types
Copy link
Contributor

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.

const { value } = this.state;
return (
<React.Fragment>
{label && <Text>{label}</Text>}
Copy link
Contributor

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.

describe("Select", () => {
const component = shallow(<Select value="1" options={objectOptions} onChange={mockChange} />);
const componentWithPlaceholder = shallow(
Copy link
Contributor

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.

@vepor vepor removed the Review needed Pull Requests that are considered complete label Jun 19, 2018
@williamkolmacka williamkolmacka force-pushed the new-select branch 2 times, most recently from ee3fcb1 to 3ee0295 Compare June 19, 2018 12:49
margin-bottom: ${({ theme }) => theme.spaceXXSmall};
`;

const SelectContainer = styled(({ theme, ...props }) => <div {...props} />)`
Copy link
Contributor

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>
))`

box-sizing: border-box;
cursor: pointer;
&:hover {
border-color: ${({ theme, active, error }) =>
Copy link
Contributor

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

return (
<React.Fragment>
{label && (
<SelectLabel theme={theme} value={value}>
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

@vepor vepor left a 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,
Copy link
Contributor

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.

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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 = [
Copy link
Contributor

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.

Copy link
Contributor

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 }) =>
Copy link
Contributor

@vepor vepor Jun 20, 2018

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

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :)

}
`;

const SelectContainer = styled.div`
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

pointer-events: none;
`;

const SelectSuffix = styled.div`
Copy link
Contributor

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

@tomashapl tomashapl force-pushed the new-select branch 3 times, most recently from 13afa56 to 7a7613e Compare June 20, 2018 12:20
vepor
vepor previously approved these changes Jun 20, 2018
Copy link
Contributor

@vepor vepor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 👏

@vepor vepor removed the Review needed Pull Requests that are considered complete label Jun 20, 2018
@tomashapl tomashapl merged commit 3a091ec into master Jun 20, 2018
@tomashapl tomashapl deleted the new-select branch June 20, 2018 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants