Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-instant committed Oct 20, 2020
2 parents c19a4b0 + 063dc88 commit 5021bce
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 35 deletions.
25 changes: 13 additions & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions dist/index.modern.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.modern.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/components/Form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ Select components are used for collecting user provided information from a list

| props | Description | type | valeur par défaut |
|---------------|---------------|--------|---------------------|
| options | An object of the form `"{" [ opt1: "{" "value": val1, [ attr: attr_value ].. "}" ].. "}"`. The Object key is used as the option's name, the rest of its sub-keys are set as attributes to the option. In the presense of this prop, the `children` are not rendered. | object of objects with a mandatory `value` key | `undefined` |
| variant | La nom ou le chemin de `variant` pour styler le composant via `Theme Object` | `string` | `radio` |
| Box's props | Vous pouvez utiliser toutes le proporiétés de `Box` | | - |
21 changes: 12 additions & 9 deletions src/components/Form/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,17 @@ const SelectIcon = ({ icon }) => {
</Flex>;
};

const Select = forwardRef(({ variant, ...props }, ref) => {
const Select = forwardRef(({ variant, children, options, ...props }, ref) => {

const selectRef = ref || useRef();

const handleOnChange = (ev) => {
const value = selectRef.current.value;
props.onChange(value);
}
return <Flex {...getMarginProps(props)} {...getLayoutProps(props)} __css={{ width: 'fit-content',
position: 'relative' }}>
<Box
ref={selectRef}
as='select'
variant={`select${variant ? '.' + variant : ''}`}
{...omitMarginProps(props)}
onChange={handleOnChange}
__css={{
display: 'block',
width: 'auto',
Expand All @@ -72,9 +67,17 @@ const Select = forwardRef(({ variant, ...props }, ref) => {
outline: 'none',
boxShadow: t => `0 0 0 2px ${t.colors.primary500}`,
}
}}
/>
<SelectIcon {...props} />
}} >

{ options
? Object.entries(options).map( ([option, attrs], i) => (
<option key={i} {...attrs}>{option}</option>
) )
: children
}

</Box>
<SelectIcon />

</Flex>
});
Expand Down
23 changes: 23 additions & 0 deletions src/components/Form/stories/select.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,29 @@ export const DefaultSelect = () => {
</Box>);
}

export const UsingOptionsProp = () => {
return (
<Box p="medium">
<Label alignItems="center">Villes</Label>
<Select
id='ville'
name='ville'
mt="small"
options={{
"Agadir": {value: "Agadir"},
"EL Jadida": {value: "EL Jadida"},
"Casablanca": {
value: "Casablanca",
},
"Tanger": {
value: "Tanger",
disabled: true,
},
}}
/>
</Box>);
}

export const CustomDownarrow = () => {
return (
<Box p="medium">
Expand Down

0 comments on commit 5021bce

Please sign in to comment.