-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
3,377 additions
and
2,277 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
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 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 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,42 @@ | ||
import { colors, spacers } from '@dhis2/ui-constants' | ||
import { Input } from '@dhis2-ui/input' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import i18n from '../locales/index.js' | ||
|
||
export function MenuFilter({ value, onChange, placeholder, label }) { | ||
return ( | ||
<div> | ||
<Input | ||
ariaLabel={label || i18n.t('Search options')} | ||
dense | ||
value={value} | ||
onChange={({ value }) => onChange(value)} | ||
type="text" | ||
name="filter" | ||
placeholder={placeholder} | ||
initialFocus | ||
/> | ||
|
||
<style jsx>{` | ||
div { | ||
position: sticky; | ||
inset-block-start: 0; | ||
background: ${colors.white}; | ||
padding-block-start: ${spacers.dp8}; | ||
padding-inline-end: ${spacers.dp8}; | ||
padding-block-end: ${spacers.dp4}; | ||
padding-inline-start: ${spacers.dp8}; | ||
z-index: 1; | ||
} | ||
`}</style> | ||
</div> | ||
) | ||
} | ||
|
||
MenuFilter.propTypes = { | ||
value: PropTypes.string.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
label: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
} |
116 changes: 116 additions & 0 deletions
116
components/select/src/single-select-a11y/menu-options-list.js
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,116 @@ | ||
import { colors, spacers, theme } from '@dhis2/ui-constants' | ||
import { CircularLoader } from '@dhis2-ui/loader' | ||
import PropTypes from 'prop-types' | ||
import React from 'react' | ||
import { Option } from './option.js' | ||
import { optionsProp } from './shared-prop-types.js' | ||
|
||
function Loading({ message }) { | ||
return ( | ||
<div className="container"> | ||
<div> | ||
<CircularLoader small /> | ||
</div> | ||
|
||
{message} | ||
|
||
<style jsx>{` | ||
.container { | ||
display: flex; | ||
gap: ${spacers.dp16}; | ||
align-items: center; | ||
justify-content: center; | ||
color: ${colors.grey700}; | ||
font-family: ${theme.fonts}; | ||
font-size: 13px; | ||
padding-block: ${spacers.dp8}; | ||
padding-inline: ${spacers.dp24}; | ||
} | ||
`}</style> | ||
</div> | ||
) | ||
} | ||
|
||
Loading.propTypes = { | ||
message: PropTypes.string, | ||
} | ||
|
||
export function MenuOptionsList({ | ||
comboBoxId, | ||
idPrefix, | ||
labelledBy, | ||
options, | ||
selected, | ||
disabled, | ||
empty, | ||
loading, | ||
loadingText, | ||
onChange, | ||
onBlur, | ||
onKeyDown, | ||
}) { | ||
return ( | ||
<div | ||
role="listbox" | ||
id={`listbox-${idPrefix}`} | ||
aria-labelledby={labelledBy} | ||
aria-live="polite" | ||
aria-busy={loading.toString()} | ||
tabIndex="-1" | ||
onBlur={onBlur} | ||
onKeyDown={onKeyDown} | ||
> | ||
{!options.length && empty} | ||
|
||
{options.map( | ||
( | ||
{ | ||
value, | ||
label, | ||
component, | ||
disabled: optionDisabled = false, | ||
}, | ||
index | ||
) => { | ||
const isSelected = value === selected | ||
return ( | ||
<Option | ||
key={value} | ||
value={value} | ||
label={label} | ||
index={index} | ||
comboBoxId={comboBoxId} | ||
disabled={disabled || optionDisabled} | ||
selected={isSelected} | ||
onClick={isSelected ? () => null : onChange} | ||
component={component} | ||
/> | ||
) | ||
} | ||
)} | ||
|
||
{loading && <Loading message={loadingText} />} | ||
|
||
<style jsx>{` | ||
div:empty { | ||
height: 16px; | ||
} | ||
`}</style> | ||
</div> | ||
) | ||
} | ||
|
||
MenuOptionsList.propTypes = { | ||
comboBoxId: PropTypes.string.isRequired, | ||
idPrefix: PropTypes.string.isRequired, | ||
options: optionsProp.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
disabled: PropTypes.bool, | ||
empty: PropTypes.node, | ||
labelledBy: PropTypes.string, | ||
loading: PropTypes.bool, | ||
loadingText: PropTypes.string, | ||
selected: PropTypes.string, | ||
onBlur: PropTypes.func, | ||
onKeyDown: PropTypes.func, | ||
} |
Oops, something went wrong.