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

feat: add clear button in services select #158

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ type RenderSwitcherType = ({
export const renderSwitcher: RenderSwitcherType =
({initial, list, defaultLabel}) =>
// eslint-disable-next-line react/display-name
({onClick, ref, onKeyDown, open}) => (
({onClick, ref, onKeyDown, open, renderClear}) => (
<CustomSwitcher
initial={initial}
defaultLabel={defaultLabel}
list={list}
controlRef={ref}
onClick={onClick}
onKeyDown={onKeyDown}
renderClear={renderClear}
open={open}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

$block: '.#{$namespace}feed-custom-switcher';

$clearIconSize: 11px;

#{$block} {
$root: &;

Expand Down Expand Up @@ -33,6 +35,12 @@ $block: '.#{$namespace}feed-custom-switcher';
//stylelint-disable-next-line declaration-no-important
transform: translate3d(0, 4px, 0) !important;
}

.g-select-clear {
width: $clearIconSize;
height: $clearIconSize;
margin-right: 9px;
}
}

&__custom-switcher:hover {
Expand Down Expand Up @@ -75,4 +83,9 @@ $block: '.#{$namespace}feed-custom-switcher';
width: $indentXS;
height: $indentXS;
}

&__clear {
width: $clearIconSize;
height: $clearIconSize;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {LegacyRef, useMemo} from 'react';
import {Icon, SelectProps} from '@gravity-ui/uikit';

import {DropdownArrow} from '../../../../icons/DropdownArrow';
import {Close} from '../../../../icons/Close';
import {block} from '../../../../utils/cn';
import {SelectItem} from '../Controls/Controls';

Expand All @@ -20,6 +21,7 @@ export type CustomSwitcherProps = {
} & Omit<RenderControlParameters, 'ref'>;

const ICON_SIZE = 12;
const CLEAR_ICON_SIZE = 11;

export const CustomSwitcher = ({
initial,
Expand All @@ -29,6 +31,7 @@ export const CustomSwitcher = ({
controlRef,
onKeyDown,
open,
renderClear,
}: CustomSwitcherProps) => {
const itemsNames = useMemo(() => {
const items = list
Expand All @@ -50,6 +53,12 @@ export const CustomSwitcher = ({
<div className={b('custom-switcher-element', {content: true})}>
{itemsNames?.join(', ')}
</div>
{renderClear &&
renderClear({
renderIcon: () => (
<Icon data={Close} size={CLEAR_ICON_SIZE} className={b('clear')} />
),
})}
{hasCounter && (
<div className={b('custom-switcher-element', {counter: true})}>
{itemsNames.length}
Expand Down
Loading