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/select update #1405

Merged
merged 4 commits into from
Oct 11, 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
9 changes: 9 additions & 0 deletions .changeset/fuzzy-windows-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'@alfalab/core-components-select': minor
---

1. Добавлен пропс `onSelectAllClick` в хук `useSelectWithApply`
2. Исправлена прокидка пропса `headerProps` в компонент `Header` хуке `useSelectWithApply`
3. Добавлен параметр `name` в обработчик `onChange` для кнопок "Применить" и "Сбросить"
hextion marked this conversation as resolved.
Show resolved Hide resolved
4. Добавлен пропс `dataTestId` для чекбокса "Выбрать все"
5. Исправлена ситуация с пустым списком опций и отображаемым футером
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const OptionsList = forwardRef<HTMLDivElement, OptionsListProps>(

{nativeScrollbar ? renderWithNativeScrollbar() : renderWithCustomScrollbar()}

{showFooter && footer && (
{showFooter && footer && flatOptions.length !== 0 && (
<div
onMouseEnter={resetHighlightedIndex}
className={cn(styles.optionsListFooter, {
Expand Down
6 changes: 3 additions & 3 deletions packages/select/src/docs/development.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {

## Использование dataTestId

В компоненте используются модификаторы для `dataTestId`.
Для удобного поиска элементов можно воспользоваться функцией `getSelectTestIds`.
В компоненте используются модификаторы для `dataTestId`.
Для удобного поиска элементов можно воспользоваться функцией `getSelectTestIds`.
Импорт из `@alfalab/core-components/select/shared`.

Функция возвращает объект:
Expand All @@ -52,7 +52,7 @@ import {

// Для SelectModalMobile
modal: `${dataTestId}-modal`,
modalHeader: `${dataTestId}-modalt-header`,
modalHeader: `${dataTestId}-modal-header`,
modalContent: `${dataTestId}-modal-content`,

field: `${dataTestId}-field`,
Expand Down
14 changes: 13 additions & 1 deletion packages/select/src/presets/useSelectWithApply/hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export type UseSelectWithApplyProps = {
*/
onChange: BaseSelectProps['onChange'];

/**
* Дополнительный обработчик клика на чекбокс выбрать все
*/
onSelectAllClick?: (selectedMultiple: OptionShape[]) => void;

/**
* Компонент выпадающего меню
*/
Expand Down Expand Up @@ -72,6 +77,7 @@ export function useSelectWithApply({
options,
selected,
onChange = () => null,
onSelectAllClick = () => null,
OptionsList,
optionsListProps = {},
showClear = true,
Expand Down Expand Up @@ -125,6 +131,7 @@ export function useSelectWithApply({
selected: selectedDraft[0],
selectedMultiple: selectedDraft,
initiator: null,
name: 'apply-footer',
});
};

Expand All @@ -134,11 +141,15 @@ export function useSelectWithApply({
selected: null,
selectedMultiple: [],
initiator: null,
name: 'reset-footer',
});
};

const handleToggleAll = () => {
setSelectedDraft(flatOptions.length === selectedDraft.length ? [] : flatOptions);
const optionsToSet = flatOptions.length === selectedDraft.length ? [] : flatOptions;

onSelectAllClick(optionsToSet);
setSelectedDraft(optionsToSet);
};

const handleChange: Required<BaseSelectProps>['onChange'] = ({ initiator, ...restArgs }) => {
Expand Down Expand Up @@ -197,6 +208,7 @@ export function useSelectWithApply({
setSelectedDraft,
showHeaderWithSelectAll,
headerProps: {
...(optionsListProps as AnyObject)?.headerProps,
indeterminate: !!selectedDraft.length && selectedDraft.length < flatOptions.length,
checked: selectedDraft.length === flatOptions.length,
onChange: handleToggleAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ export type HeaderProps = {
indeterminate?: boolean;
onChange?: CheckboxProps['onChange'];
mobile?: boolean;
dataTestId?: string;
};

export const Header: React.FC<HeaderProps> = ({ onChange, checked, indeterminate, mobile }) => (
export const Header: React.FC<HeaderProps> = ({
onChange,
checked,
indeterminate,
mobile,
dataTestId,
}) => (
<div className={cn({ [styles.desktop]: !mobile, [styles.mobile]: mobile })}>
<Checkbox
block={true}
Expand All @@ -21,6 +28,7 @@ export const Header: React.FC<HeaderProps> = ({ onChange, checked, indeterminate
onChange={onChange}
checked={checked}
label='Выбрать все'
dataTestId={dataTestId}
/>
</div>
);
Loading