-
Notifications
You must be signed in to change notification settings - Fork 25
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
filters design modifications for async select input #2980
base: main
Are you sure you want to change the base?
Changes from 5 commits
455ee9b
68ca38c
16450a0
e252fca
55d0982
0f719bb
66e84c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@commercetools-uikit/async-select-input': minor | ||
'@commercetools-uikit/select-utils': minor | ||
--- | ||
|
||
As the filters component is being built, there are some visual modifications that need to happen in the async select input to support the designs and ux of the filters pattern. most of these changes are dependent on new props to set these options when the async-select component is used as in a filter component. |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,10 @@ import { | |
messages, | ||
createSelectStyles, | ||
warnIfMenuPortalPropsAreMissing, | ||
optionStyleCheckboxComponents, | ||
optionsStyleCheckboxSelectProps, | ||
} from '@commercetools-uikit/select-utils'; | ||
import { SearchIcon } from '@commercetools-uikit/icons'; | ||
|
||
const LoadingIndicator = () => <LoadingSpinner scale="s" />; | ||
LoadingIndicator.displayName = 'LoadingIndicator'; | ||
|
@@ -317,18 +320,32 @@ export type TAsyncSelectInputProps = { | |
* Icon to display on the left of the placeholder text and selected value. Has no effect when `isMulti` is enabled. | ||
*/ | ||
iconLeft?: ReactNode; | ||
/** defines how options are rendered */ | ||
optionStyle: 'list' | 'checkbox'; | ||
/** | ||
* Indicates the appearance of the input. | ||
* Filter appearance is meant to be used when the async-select is used as a filter. | ||
*/ | ||
appearance?: 'default' | 'filter'; | ||
}; | ||
|
||
const defaultProps: Pick< | ||
TAsyncSelectInputProps, | ||
'value' | 'isSearchable' | 'menuPortalZIndex' | 'controlShouldRenderValue' | ||
| 'value' | ||
| 'isSearchable' | ||
| 'menuPortalZIndex' | ||
| 'controlShouldRenderValue' | ||
| 'appearance' | ||
| 'optionStyle' | ||
> = { | ||
// Using "null" will ensure that the currently selected value disappears in | ||
// case "undefined" gets passed as the next value | ||
value: null, | ||
isSearchable: true, | ||
menuPortalZIndex: 1, | ||
controlShouldRenderValue: true, | ||
appearance: 'default', | ||
optionStyle: 'list', | ||
}; | ||
|
||
const AsyncSelectInput = (props: TAsyncSelectInputProps) => { | ||
|
@@ -347,8 +364,20 @@ const AsyncSelectInput = (props: TAsyncSelectInputProps) => { | |
componentName: 'AsyncSelectInput', | ||
}); | ||
|
||
const placeholder = | ||
props.placeholder || intl.formatMessage(messages.placeholder); | ||
// const placeholder = | ||
// props.placeholder || intl.formatMessage(messages.placeholder); | ||
|
||
const placeholder = props.placeholder | ||
? props.placeholder | ||
: props.appearance === 'filter' | ||
? 'Search' | ||
: intl.formatMessage(messages.placeholder); | ||
|
||
// TODO: uncomment to replace placeholder logic once select-input PR for this has been merged. | ||
// const placeholder = | ||
// props.appearance === 'filter' && !props.placeholder | ||
// ? intl.formatMessage(messages.selectInputAsFilterPlaceholder) | ||
// : props.placeholder || intl.formatMessage(messages.placeholder); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can simplify this condition. Only if there is no props.placeholder you need to check which default-placeholder to pick:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated here: 66e84c2 |
||
|
||
const loadingMessage = () => { | ||
if (typeof props.loadingMessage === 'function') { | ||
|
@@ -383,6 +412,13 @@ const AsyncSelectInput = (props: TAsyncSelectInputProps) => { | |
), | ||
} | ||
: {}), | ||
...(props.appearance === 'filter' && { | ||
DropdownIndicator: () => <SearchIcon color="neutral60" />, | ||
ClearIndicator: null, | ||
}), | ||
...(props.optionStyle === 'checkbox' | ||
? optionStyleCheckboxComponents() | ||
: {}), | ||
...props.components, | ||
} as ReactSelectAsyncProps['components'] | ||
} | ||
|
@@ -404,7 +440,6 @@ const AsyncSelectInput = (props: TAsyncSelectInputProps) => { | |
}) as ReactSelectAsyncProps['styles'] | ||
} | ||
filterOption={props.filterOption} | ||
hideSelectedOptions={props.hideSelectedOptions} | ||
// react-select uses "id" (for the container) and "inputId" (for the input), | ||
// but we use "id" (for the input) and "containerId" (for the container) | ||
// instead. | ||
|
@@ -415,6 +450,9 @@ const AsyncSelectInput = (props: TAsyncSelectInputProps) => { | |
isClearable={props.isReadOnly ? false : props.isClearable} | ||
isDisabled={props.isDisabled} | ||
isOptionDisabled={props.isOptionDisabled} | ||
{...(props.optionStyle === 'checkbox' | ||
? optionsStyleCheckboxSelectProps() | ||
: { hideSelectedOptions: props.hideSelectedOptions })} | ||
isMulti={props.isMulti} | ||
isSearchable={props.isSearchable} | ||
maxMenuHeight={props.maxMenuHeight} | ||
|
@@ -485,7 +523,12 @@ const AsyncSelectInput = (props: TAsyncSelectInputProps) => { | |
// @ts-ignore: passed to the react-select components via `selectProps`. | ||
isCondensed={props.isCondensed} | ||
iconLeft={props.iconLeft} | ||
controlShouldRenderValue={props.controlShouldRenderValue} | ||
controlShouldRenderValue={ | ||
props.appearance === 'filter' | ||
? false | ||
: props.controlShouldRenderValue | ||
} | ||
appea | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some leftover There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated here: 66e84c2 |
||
/> | ||
</div> | ||
</Constraints.Horizontal> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { SELECT_DROPDOWN_OPTION_TYPES } from './constants'; | ||
export * from './custom-styled-select-options'; | ||
export * from './options-style-checkbox-components'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { type Props as ReactSelectProps } from 'react-select'; | ||
import CheckboxInput from '@commercetools-uikit/checkbox-input'; | ||
import { css } from '@emotion/react'; | ||
import { designTokens } from '@commercetools-uikit/design-system'; | ||
|
||
/** | ||
* Returns custom components to be used with react-select, when optionStyle is set to "checkbox" | ||
*/ | ||
export const optionStyleCheckboxComponents = () => { | ||
return { | ||
Option: (props) => { | ||
const { | ||
innerRef, | ||
innerProps, | ||
label, | ||
isDisabled, | ||
isFocused, | ||
isSelected, | ||
className, | ||
} = props; | ||
|
||
return ( | ||
<div | ||
data-component="option" | ||
ref={innerRef} | ||
{...innerProps} | ||
css={css` | ||
padding: ${designTokens.spacing10} ${designTokens.spacing20}; | ||
${isFocused && | ||
`background-color: ${designTokens.backgroundColorForInputWhenHovered};`} | ||
`} | ||
className={className} | ||
aria-disabled={isDisabled} | ||
> | ||
<CheckboxInput | ||
isDisabled={isDisabled} | ||
isChecked={isSelected} | ||
onChange={() => {}} | ||
> | ||
{label} | ||
</CheckboxInput> | ||
</div> | ||
); | ||
}, | ||
} as ReactSelectProps['components']; | ||
}; | ||
|
||
/** | ||
* Returns react-select props to be used with the <Select> component, when optionStyle is set to "checkbox" | ||
*/ | ||
export const optionsStyleCheckboxSelectProps = () => { | ||
return { | ||
// selected options should still be visible in the option-list, otherwise you cant toggle them | ||
hideSelectedOptions: false, | ||
// don't close the menu on check / uncheck of a checkbox | ||
closeMenuOnSelect: false, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3086,7 +3086,7 @@ __metadata: | |
languageName: unknown | ||
linkType: soft | ||
|
||
"@commercetools-uikit/[email protected], @commercetools-uikit/checkbox-input@workspace:packages/components/inputs/checkbox-input": | ||
"@commercetools-uikit/[email protected], @commercetools-uikit/checkbox-input@workspace:^, @commercetools-uikit/checkbox-input@workspace:packages/components/inputs/checkbox-input": | ||
version: 0.0.0-use.local | ||
resolution: "@commercetools-uikit/checkbox-input@workspace:packages/components/inputs/checkbox-input" | ||
dependencies: | ||
|
@@ -4751,6 +4751,7 @@ __metadata: | |
"@babel/runtime": ^7.20.13 | ||
"@babel/runtime-corejs3": ^7.20.13 | ||
"@commercetools-uikit/accessible-button": 19.13.0 | ||
"@commercetools-uikit/checkbox-input": "workspace:^" | ||
"@commercetools-uikit/design-system": 19.13.0 | ||
"@commercetools-uikit/icons": 19.13.0 | ||
"@commercetools-uikit/spacings": 19.13.0 | ||
|
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.
When the select-input PR is merged, I will uncomment this since they will be using the same messages keys.