-
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
Open
ddouglasz
wants to merge
7
commits into
main
Choose a base branch
from
FCT-1264-checkbox-displays-for-async-select-input
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
455ee9b
feat(filters): testing a commit issue
68ca38c
feat(filters): add appearance and option styles features to asyn sele…
16450a0
feat(filters): add appearance and option styles features to asyn sele…
e252fca
feat(filters): add appearance and option styles features to asyn sele…
55d0982
feat(filters): add changeset
0f719bb
feat(filters): debug
66e84c2
feat(filters): remove leftover code
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
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.
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
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 |
---|---|---|
|
@@ -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,23 @@ 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. | ||
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. When the select-input PR is merged, I will uncomment this since they will be using the same messages keys. |
||
// const placeholder = | ||
// props.placeholder || | ||
// intl.formatMessage( | ||
// props.appearance === 'filter' | ||
// ? messages.selectInputAsFilterPlaceholder | ||
// : messages.placeholder | ||
// ); | ||
|
||
const loadingMessage = () => { | ||
if (typeof props.loadingMessage === 'function') { | ||
|
@@ -383,6 +415,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 +443,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 +453,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 +526,11 @@ 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 | ||
} | ||
/> | ||
</div> | ||
</Constraints.Horizontal> | ||
|
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
1 change: 1 addition & 0 deletions
1
packages/components/inputs/select-utils/src/custom-styled-select-options/index.ts
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { SELECT_DROPDOWN_OPTION_TYPES } from './constants'; | ||
export * from './custom-styled-select-options'; | ||
export * from './options-style-checkbox-components'; |
58 changes: 58 additions & 0 deletions
58
...nputs/select-utils/src/custom-styled-select-options/options-style-checkbox-components.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,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, | ||
}; | ||
}; |
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 |
---|---|---|
|
@@ -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 | ||
|
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.
This is mainly for testing simplicity and will be removed before merging.
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.
For some reason, label/placeholder and input break lines after selection: