Skip to content
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
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/calm-brooms-chew.md
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.
96 changes: 49 additions & 47 deletions packages/components/inputs/async-select-input/README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => {
Expand All @@ -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.
Copy link
Contributor Author

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.

// const placeholder =
// props.appearance === 'filter' && !props.placeholder
// ? intl.formatMessage(messages.selectInputAsFilterPlaceholder)
// : props.placeholder || intl.formatMessage(messages.placeholder);
Copy link
Contributor

@misama-ct misama-ct Nov 1, 2024

Choose a reason for hiding this comment

The 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:

const placeholder = props.placeholder || intl.formatMessage(props.appearance === 'filter' ? messages.selectInputAsFilterPlaceholder : messages.placeholder);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated here: 66e84c2
Thank you


const loadingMessage = () => {
if (typeof props.loadingMessage === 'function') {
Expand Down Expand Up @@ -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']
}
Expand All @@ -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.
Expand All @@ -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}
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some leftover

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated here: 66e84c2
Thank you

/>
</div>
</Constraints.Horizontal>
Expand Down
1 change: 1 addition & 0 deletions packages/components/inputs/select-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type TProps = {
hasValue?: boolean;
isCondensed?: boolean;
controlShouldRenderValue?: boolean;
appearance?: 'default' | 'quiet';
appearance?: 'default' | 'quiet' | 'filter';
minMenuWidth?:
| 2
| 3
Expand Down
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,
};
};
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading