-
Notifications
You must be signed in to change notification settings - Fork 844
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
[EuiSelectable] Enable CodeSandbox links and misc documentation improvements #6074
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
857c65c
Remove shared dependency in favor of simply copying and pasting
cee-chen 9265163
Greatly simplify popover/flyout example + convert to TSX
cee-chen c66e4a9
Simplify custom render example and convert to TSX
cee-chen 96f6ecb
[Organization] Move EuiSelectableTemplateSitewide to its own folder
cee-chen 0f44ac8
Improve singleSelection example
cee-chen 79d72e1
Improve snippets documentation
cee-chen bc080e3
Standardize props tab display
cee-chen c529cdb
Misc documentation fixes
cee-chen 7ad7b6e
[PR feedback] Just import from 'src'
cee-chen cfe5447
[PR feedback] Remove Fragment
cee-chen fc001b2
[PR feedback] Misc snippet feedback
cee-chen 444733c
[PR feedback] Fix EuiSwitch label
cee-chen f55de07
[PR feedback] TSX
constancecchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
This file was deleted.
Oops, something went wrong.
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
112 changes: 0 additions & 112 deletions
112
src-docs/src/views/selectable/selectable_custom_render.js
This file was deleted.
Oops, something went wrong.
122 changes: 122 additions & 0 deletions
122
src-docs/src/views/selectable/selectable_custom_render.tsx
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,122 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { | ||
EuiBadge, | ||
EuiHighlight, | ||
EuiSpacer, | ||
EuiText, | ||
EuiSwitch, | ||
EuiSelectable, | ||
EuiSelectableOption, | ||
} from '../../../../src/components'; | ||
|
||
const countryData = [ | ||
{ code: 'NL', name: 'Netherlands', flag: '🇳🇱' }, | ||
{ code: 'CZ', name: 'Czech Republic', flag: '🇨🇿' }, | ||
{ code: 'ZA', name: 'South Africa', flag: '🇿🇦' }, | ||
{ code: 'US', name: 'United States', flag: '🇺🇲' }, | ||
{ code: 'AU', name: 'Australia', flag: '🇦🇺' }, | ||
{ code: 'IL', name: 'Israel', flag: '🇮🇱' }, | ||
{ code: 'NO', name: 'Norway', flag: '🇳🇴' }, | ||
{ code: 'IT', name: 'Italy', flag: '🇮🇹' }, | ||
{ code: 'CA', name: 'Canada', flag: '🇨🇦' }, | ||
{ code: 'CG', name: 'Congo', flag: '🇨🇬' }, | ||
{ code: 'CL', name: 'Chile', flag: '🇨🇱' }, | ||
{ code: 'FJ', name: 'Fiji', flag: '🇫🇯' }, | ||
{ code: 'GB', name: 'United Kingdom', flag: '🇬🇧' }, | ||
{ code: 'GR', name: 'Greece', flag: '🇬🇷' }, | ||
{ code: 'HT', name: 'Haiti', flag: '🇭🇹' }, | ||
{ code: 'LB', name: 'Lebanon', flag: '🇱🇧' }, | ||
{ code: 'MM', name: 'Myanmar', flag: '🇲🇲' }, | ||
{ code: 'MX', name: 'Mexico', flag: '🇲🇽' }, | ||
{ code: 'NG', name: 'Nigeria', flag: '🇳🇬' }, | ||
{ code: 'SG', name: 'Singapore', flag: '🇸🇬' }, | ||
{ code: 'SO', name: 'Somalia', flag: '🇸🇴' }, | ||
{ code: 'TN', name: 'Tunisia', flag: '🇹🇳' }, | ||
{ code: 'VE', name: 'Venezuela', flag: '🇻🇪' }, | ||
{ code: 'ZM', name: 'Zambia', flag: '🇿🇲' }, | ||
]; | ||
|
||
interface OptionData { | ||
secondaryContent?: string; | ||
} | ||
|
||
export default () => { | ||
const [options, setOptions] = useState< | ||
Array<EuiSelectableOption<OptionData>> | ||
>([ | ||
{ | ||
label: 'Country options', | ||
isGroupLabel: true, | ||
}, | ||
...countryData.map( | ||
(country): EuiSelectableOption => ({ | ||
label: `${country.name}`, | ||
searchableLabel: `${country.name} ${'I am secondary content, I am!'}`, | ||
prepend: country.flag, | ||
append: <EuiBadge>{country.code}</EuiBadge>, | ||
data: { | ||
secondaryContent: 'I am secondary content, I am!', | ||
}, | ||
}) | ||
), | ||
]); | ||
|
||
const renderCountryOption = ( | ||
option: EuiSelectableOption<OptionData>, | ||
searchValue: string | ||
) => { | ||
return ( | ||
<> | ||
<EuiHighlight search={searchValue}>{option.label}</EuiHighlight> | ||
<EuiText size="xs" color="subdued" className="eui-displayBlock"> | ||
<small> | ||
<EuiHighlight search={searchValue}> | ||
{option.secondaryContent || ''} | ||
</EuiHighlight> | ||
</small> | ||
</EuiText> | ||
</> | ||
); | ||
}; | ||
|
||
const [useCustomContent, setUseCustomContent] = useState(true); | ||
const [isVirtualized, setIsVirtualized] = useState(true); | ||
|
||
return ( | ||
<> | ||
<EuiSwitch | ||
label="Virtualized" | ||
checked={isVirtualized} | ||
onChange={(e) => setIsVirtualized(e.target.checked)} | ||
/> | ||
   | ||
<EuiSwitch | ||
label="Custom content" | ||
checked={useCustomContent} | ||
onChange={(e) => setUseCustomContent(e.target.checked)} | ||
/> | ||
<EuiSpacer /> | ||
<EuiSelectable | ||
aria-label="Selectable example with custom list items" | ||
searchable | ||
options={options} | ||
onChange={(options) => setOptions(options)} | ||
listProps={{ | ||
isVirtualized, | ||
rowHeight: useCustomContent ? 50 : undefined, | ||
showIcons: false, | ||
}} | ||
renderOption={useCustomContent ? renderCountryOption : undefined} | ||
height={240} | ||
> | ||
{(list, search) => ( | ||
<> | ||
{search} | ||
{list} | ||
</> | ||
)} | ||
</EuiSelectable> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Optional:
Should we move these styles to Emotion so they render in the code sandbox?
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 gave this a shot but unfortunately there are a few limitations:
useEuiTheme()
, meaning I can't just pass a staticcss
prop into the list ofsearchData
array variablescss={}
prop into<EuiSelectableTemplateSitewide>
directly, I have to pass it intolistProps={{}}
listProps={{ css: css`...` }}
works in actual UI, but Typescript complains about thecss
prop not existing on our types, which is odd. We may need to addcss
in ourCommonProps
declaration. Which I'm fine to do, but I was really hoping to keep this PR as src-doc changes only, so I'll check in with Greg about the implications of that and then tackle it in another PR, if that's cool!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.
Yep, that's fine. 👍