Skip to content

Commit

Permalink
add prop to give Select's dropdown full width (#125)
Browse files Browse the repository at this point in the history
* prop to give the dropdown full width

* update yarn.lock

* rename prop
  • Loading branch information
l3satwik authored and ritz078 committed Oct 18, 2018
1 parent 77c5cea commit 17f7e5f
Show file tree
Hide file tree
Showing 5 changed files with 1,843 additions and 37 deletions.
17 changes: 13 additions & 4 deletions src/components/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
inputWrapper,
selectInput,
selectInputWrapper,
selectWrapper
selectWrapper,
fullWidth,
relativePosition
} from "./styles/Select.styles";
import DropDown from "./DropDown";
import Input from "./Input";
Expand All @@ -32,15 +34,22 @@ const Select: React.SFC<SelectProps> = props => {
dropdownClassName,
inputProps,
searchBox,
searchBoxProps
searchBoxProps,
fullWidthDropdown
} = props;

const OptionGroup: any = multiSelect ? OptionGroupCheckBox : OptionGroupRadio;

return (
<div className={cx(selectWrapper, className)}>
<div
className={cx(selectWrapper, className, {
[relativePosition]: fullWidthDropdown
})}
>
<DropDown
dropDownClassName={cx(dropDownClass, dropdownClassName)}
dropDownClassName={cx(dropDownClass, dropdownClassName, {
[fullWidth]: fullWidthDropdown
})}
labelComponent={({ toggleDropdown, isOpen }) => {
const chevron = cx(chevronStyle, "pi", "pi-arrow-drop-down", {
__pebble__select__open: isOpen
Expand Down
8 changes: 8 additions & 0 deletions src/components/styles/Select.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const selectWrapper = css({
marginBottom: 20
});

export const relativePosition = css({
position: "relative"
});

export const selectInputWrapper = css({
pointerEvents: "none"
});
Expand All @@ -18,6 +22,10 @@ export const dropDownClass = css({
marginTop: -40
});

export const fullWidth = css({
width: "100%"
});

export const inputWrapper = css({
cursor: "pointer",
position: "relative"
Expand Down
1 change: 1 addition & 0 deletions src/components/typings/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface SelectProps {
searchBoxProps?: Partial<SearchProps>;
dropdownClassName?: string;
inputProps?: Partial<InputProps>;
fullWidthDropdown?: boolean;
}
69 changes: 36 additions & 33 deletions stories/select.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,43 @@ storiesOf("Select", module)
.add(
"Single Select",
withState({ searchQuery: "" })(({ store }) => (
<Select
selected={store.state.selected} // The value selected
value={store.state.value} // To show in input box after selection
onChange={(selected, e) => {
if (selected) {
store.set({
selected: selected,
value: options.find(option => option.value === selected)!.label // Yes, we save the label in value
});
}
action("onSelect")(selected, e);
}}
placeholder="Choose Option"
searchBox={boolean("searchBox")}
searchBoxProps={{
placeholder: text("searchBoxProps.placeholder", "Search"),
onChange: query => store.set({ searchQuery: query })
}}
>
{options
.filter(option => {
if (!boolean("searchBox") || !store.state.searchQuery) {
return true;
<div style={{ width: "330px" }}>
<Select
selected={store.state.selected} // The value selected
value={store.state.value} // To show in input box after selection
fullWidthDropdown
onChange={(selected, e) => {
if (selected) {
store.set({
selected: selected,
value: options.find(option => option.value === selected)!.label // Yes, we save the label in value
});
}
return option.label.includes(store.state.searchQuery);
})
.map(option => (
<Option
key={option.value}
value={option.value}
label={option.label}
/>
))}
</Select>
action("onSelect")(selected, e);
}}
placeholder="Choose Option"
searchBox={boolean("searchBox")}
searchBoxProps={{
placeholder: text("searchBoxProps.placeholder", "Search"),
onChange: query => store.set({ searchQuery: query })
}}
>
{options
.filter(option => {
if (!boolean("searchBox") || !store.state.searchQuery) {
return true;
}
return option.label.includes(store.state.searchQuery);
})
.map(option => (
<Option
key={option.value}
value={option.value}
label={option.label}
/>
))}
</Select>
</div>
))
)
.add("Multi Select", () => (
Expand Down
Loading

1 comment on commit 17f7e5f

@vercel
Copy link

@vercel vercel bot commented on 17f7e5f Oct 18, 2018

Choose a reason for hiding this comment

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

Successfully aliased the URL https://pebble-ydsgcjmfbr.now.sh to the following alias.

Please sign in to comment.