-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added icon as an option * add changelog * fix * Remove `renderPill` types * Change `option.icon` prop to `option.prepend` and `option.append` * Add styles for margins + vertical alignment + cleanup - flatten more `euiComboBoxOption` selectors * Fix new `option` keys being spread to pill DOM + other misc cleanup - remove unnecessary eslint disable (accounts for rest spread), add some newlines * Revert EuiBadge changes * Documentation - Use just one demo that switches between single selection and multi selection - Reuse as much copy from `EuiSelectable` as possible - misc cleanup - remove `Fragment`s * changelog * [PR feedback] Pill line height --------- Co-authored-by: Cee Chen <[email protected]>
- Loading branch information
Showing
11 changed files
with
442 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import React, { useState, useMemo } from 'react'; | ||
|
||
import { | ||
EuiComboBox, | ||
EuiIcon, | ||
EuiSwitch, | ||
EuiSpacer, | ||
} from '../../../../src/components'; | ||
|
||
const options = [ | ||
{ | ||
label: 'Titan', | ||
'data-test-subj': 'titanOption', | ||
prepend: <EuiIcon size="s" type="bell" />, | ||
}, | ||
{ | ||
label: 'Enceladus', | ||
prepend: <EuiIcon size="s" type="bolt" />, | ||
}, | ||
{ | ||
label: 'Mimas', | ||
prepend: <EuiIcon size="s" type="bug" />, | ||
}, | ||
{ | ||
label: | ||
"Pandora is one of Saturn's moons, named for a Titaness of Greek mythology", | ||
prepend: <EuiIcon size="s" type="discuss" />, | ||
append: '(10)', | ||
}, | ||
{ | ||
label: 'Iapetus', | ||
prepend: <EuiIcon size="s" type="flag" color="danger" />, | ||
append: '(2)', | ||
}, | ||
{ | ||
label: 'Phoebe', | ||
prepend: <EuiIcon size="s" type="tag" color="success" />, | ||
append: '(5)', | ||
}, | ||
]; | ||
|
||
export default () => { | ||
const [selectedOptions, setSelected] = useState([options[0], options[5]]); | ||
const [singleSelection, setSingleSelection] = useState(false); | ||
|
||
const singleSelectedOption = useMemo(() => { | ||
return selectedOptions.length ? [selectedOptions[0]] : []; | ||
}, [selectedOptions]); | ||
|
||
const onChange = (selectedOptions) => { | ||
setSelected(selectedOptions); | ||
}; | ||
|
||
return ( | ||
<> | ||
<EuiSwitch | ||
checked={singleSelection} | ||
onChange={() => setSingleSelection(!singleSelection)} | ||
label="Single selection" | ||
/> | ||
<EuiSpacer /> | ||
<EuiComboBox | ||
aria-label="Combo box demo with option prepend/append nodes" | ||
options={options} | ||
onChange={onChange} | ||
singleSelection={singleSelection ? { asPlainText: true } : false} | ||
selectedOptions={ | ||
singleSelection ? singleSelectedOption : selectedOptions | ||
} | ||
placeholder={`Select one ${ | ||
singleSelection ? 'option' : 'or more options' | ||
}`} | ||
/> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.