Skip to content

Commit

Permalink
feat(plasma-new-hope): part 57
Browse files Browse the repository at this point in the history
  • Loading branch information
shuga2704 committed Jul 15, 2024
1 parent 152ad8c commit 483f64c
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 122 deletions.
4 changes: 0 additions & 4 deletions packages/plasma-b2c/api/plasma-b2c.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,6 @@ accent: PolymorphicClassName;
multiselect?: false | undefined;
value?: string | undefined;
onChange?: ((value: string) => void) | undefined;
separator?: undefined;
isTargetAmount?: false | undefined;
} & {
target?: "textfield-like" | undefined;
Expand All @@ -2011,7 +2010,6 @@ helperText?: string | undefined;
multiselect?: false | undefined;
value?: string | undefined;
onChange?: ((value: string) => void) | undefined;
separator?: undefined;
isTargetAmount?: false | undefined;
} & {
target?: "button-like" | undefined;
Expand All @@ -2025,7 +2023,6 @@ helperText?: undefined;
multiselect: true;
value?: string[] | undefined;
onChange?: ((value: string[]) => void) | undefined;
separator?: string | undefined;
isTargetAmount?: boolean | undefined;
} & {
target?: "textfield-like" | undefined;
Expand All @@ -2039,7 +2036,6 @@ helperText?: string | undefined;
multiselect: true;
value?: string[] | undefined;
onChange?: ((value: string[]) => void) | undefined;
separator?: string | undefined;
isTargetAmount?: boolean | undefined;
} & {
target?: "button-like" | undefined;
Expand Down
52 changes: 22 additions & 30 deletions packages/plasma-new-hope/src/components/SelectNew/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isEmpty, getPlacements } from '../../utils';
import { useOutsideClick } from '../../hooks';

import { useKeyNavigation } from './hooks/useKeyboardNavigation';
import { initialItemsTransform, updateAncestors, updateDescendants, updateSingleAncestors, getView } from './utils';
import { initialItemsTransform, updateAncestors, updateDescendants, updateSingleAncestors } from './utils';
import { Inner, Target } from './ui';
import { pathReducer, focusedPathReducer, focusedChipIndexReducer } from './reducers';
import { usePathMaps } from './hooks/usePathMaps';
Expand All @@ -27,7 +27,6 @@ export const selectNewRoot = (Root: RootProps<HTMLButtonElement, Omit<SelectProp
value: outerValue,
onChange: outerOnChange,
target = 'textfield-like',
separator,
items,
placement = 'bottom',
label,
Expand All @@ -38,15 +37,11 @@ export const selectNewRoot = (Root: RootProps<HTMLButtonElement, Omit<SelectProp
disabled = false,
view,
size,
isOpen,
listOverflow,
listHeight,
listWidth,
status,
contentLeft,
onScrollBottom,
isInfiniteLoading,
notFoundContent,
chipView,
variant = 'normal',
portal,
Expand Down Expand Up @@ -218,7 +213,7 @@ export const selectNewRoot = (Root: RootProps<HTMLButtonElement, Omit<SelectProp
}, [value]);

return (
<Root ref={ref} size={size} view={getView(view, status)} chipView={chipView} {...(rest as any)}>
<Root ref={ref} size={size} view={view} chipView={chipView} {...(rest as any)}>
{label && labelPlacement === 'outer' && target !== 'button-like' && <OuterLabel>{label}</OuterLabel>}
<Context.Provider
value={{
Expand Down Expand Up @@ -260,35 +255,32 @@ export const selectNewRoot = (Root: RootProps<HTMLButtonElement, Omit<SelectProp
contentLeft={contentLeft}
disabled={disabled}
renderValue={renderValue}
separator={separator}
/>
}
preventOverflow={false}
closeOnOverlayClick
>
<Root size={size} {...(rest as any)}>
{notFoundContent || (
<Ul
role="tree"
id="tree_level_1"
listHeight={listHeight}
listOverflow={listOverflow}
onScroll={handleScroll}
listWidth={listWidth}
>
{transformedItems.map((item, index) => (
<Inner
key={`${index}/0`}
item={item}
currentLevel={0}
path={path}
dispatchPath={dispatchPath}
index={index}
listWidth={listWidth}
/>
))}
</Ul>
)}
<Ul
role="tree"
id="tree_level_1"
listHeight={listHeight}
listOverflow={listOverflow}
onScroll={handleScroll}
listWidth={listWidth}
>
{transformedItems.map((item, index) => (
<Inner
key={`${index}/0`}
item={item}
currentLevel={0}
path={path}
dispatchPath={dispatchPath}
index={index}
listWidth={listWidth}
/>
))}
</Ul>
</Root>
</StyledPopover>
</Context.Provider>
Expand Down
30 changes: 0 additions & 30 deletions packages/plasma-new-hope/src/components/SelectNew/Select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ type IsMultiselect =
multiselect?: false;
value?: string;
onChange?: (value: string) => void;
/**
* Разделитель выбранных значений.
* @deprecated Использовать renderValue
*/
separator?: never;
/**
* Если включено - будет выведено общее количество выбранных элементов вместо перечисления.
* @default false
Expand All @@ -78,7 +73,6 @@ type IsMultiselect =
multiselect: true;
value?: Array<string>;
onChange?: (value: Array<string>) => void;
separator?: string;
isTargetAmount?: boolean;
};

Expand All @@ -101,14 +95,6 @@ export interface BasicProps {
* Коллбэк для определения достижения скроллом конца списка.
*/
onScrollBottom?: (e: React.UIEvent<HTMLUListElement>) => void;
/**
* Флаг лоадинга в конце списка.
*/
isInfiniteLoading?: boolean;
/**
* Компонент выпадающего списка при пустом массиве items.
*/
notFoundContent?: React.ReactElement;
/**
* Вариант: обычный или сжатый
* @default normal
Expand Down Expand Up @@ -154,22 +140,6 @@ export interface BasicProps {
* Внешний вид чипа в варианте textfield-like multiselect.
*/
chipView?: string;

/**
* Выбор нескольких значений.
* @deprecated Множественны выбор зависит от типа value и onChange.
*/
multiselect?: boolean;
/**
* @default false
* @deprecated
*/
isOpen?: boolean;
/**
* Статус селекта.
* @deprecated
*/
status?: 'warning' | 'success' | 'error';
}

export type SelectProps = BasicProps &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const useKeyNavigation = ({
break;
}

if (!currentItem || currentItem?.isDisabled || currentItem?.disabled) {
if (!currentItem || currentItem?.disabled) {
break;
}

Expand All @@ -219,7 +219,7 @@ export const useKeyNavigation = ({

const currentItem = getFurtherPath(focusedPath, focusedToValueMap)!;

if (currentItem?.isDisabled || currentItem?.disabled) {
if (currentItem?.disabled) {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const Item: FC<ItemProps> = ({
ariaLevel,
ariaLabel,
}) => {
const { value, label, disabled, isDisabled, contentLeft, contentRight } = item;
const { value, label, disabled, contentLeft, contentRight } = item;
const ref = useRef<HTMLLIElement | null>(null);

const {
Expand All @@ -43,7 +43,7 @@ export const Item: FC<ItemProps> = ({
renderItem,
} = useContext(Context);

const isDisabledClassName = disabled || isDisabled ? classes.dropdownItemIsDisabled : undefined;
const isDisabledClassName = disabled ? classes.dropdownItemIsDisabled : undefined;
const focusedClass =
currentLevel === focusedPath.length - 1 && index === focusedPath?.[currentLevel]
? classes.dropdownItemIsFocused
Expand All @@ -61,15 +61,15 @@ export const Item: FC<ItemProps> = ({
}, [focusedClass]);

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (disabled || isDisabled) return;
if (disabled) return;

e.stopPropagation();

handleCheckboxChange(item);
};

const handleClick = (e: React.MouseEvent<HTMLElement>) => {
if (disabled || isDisabled) return;
if (disabled) return;

handleItemClick(item, e);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ export type ItemOption = {
* Слот для контента справа
*/
contentRight?: ReactNode;
/**
* Выбранный item.
* @deprecated
*/
isActive?: boolean;
/**
* Кастомный цвет текста
* @deprecated
*/
color?: string;
/**
* Айтем не активен
* @deprecated использовать disabled
*/
isDisabled?: boolean;
};

export type ItemOptionTransformed = ItemOption & { parent?: ItemOption | null };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const Target: React.FC<TargetProps> = ({
renderValue,
focusedPath,
focusedToValueMap,
separator,
}) => {
return target === 'button-like' ? (
<Button
Expand All @@ -38,7 +37,6 @@ export const Target: React.FC<TargetProps> = ({
renderValue={renderValue}
focusedPath={focusedPath}
focusedToValueMap={focusedToValueMap}
separator={separator}
/>
) : (
<Textfield
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export type TargetProps = Pick<
| 'contentLeft'
| 'disabled'
| 'renderValue'
| 'separator'
> & {
value: string | string[];
opened: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Button: React.FC<ButtonProps> = ({
renderValue,
focusedPath,
focusedToValueMap,
separator,
}) => {
const withArrowInverse = opened ? classes.arrowInverse : undefined;

Expand Down Expand Up @@ -61,7 +60,6 @@ export const Button: React.FC<ButtonProps> = ({
valueToItemMap,
label,
renderValue,
separator,
})}
</Label>
</StyledButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const getButtonLabel = ({
multiselect,
valueToItemMap,
renderValue,
separator,
}: GetButtonLabelProps) => {
if (isEmpty(value)) {
return label;
Expand All @@ -33,7 +32,7 @@ export const getButtonLabel = ({
valueToItemMap,
}),
)
.join(separator || ', ');
.join(', ');
}

return getLabel({
Expand Down
21 changes: 0 additions & 21 deletions packages/plasma-new-hope/src/components/SelectNew/utils/getView.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ export { updateAncestors } from './updateAncestors';
export { updateSingleAncestors } from './updateSingleAncestors';
export { sizeToIconSize } from './sizeToIconSize';
export { getCorrectHeight } from './getCorrectHeight';
export { getView } from './getView';
export { getButtonLabel } from './getButtonLabel';
4 changes: 0 additions & 4 deletions packages/plasma-web/api/plasma-web.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1999,7 +1999,6 @@ accent: PolymorphicClassName;
multiselect?: false | undefined;
value?: string | undefined;
onChange?: ((value: string) => void) | undefined;
separator?: undefined;
isTargetAmount?: false | undefined;
} & {
target?: "textfield-like" | undefined;
Expand All @@ -2013,7 +2012,6 @@ helperText?: string | undefined;
multiselect?: false | undefined;
value?: string | undefined;
onChange?: ((value: string) => void) | undefined;
separator?: undefined;
isTargetAmount?: false | undefined;
} & {
target?: "button-like" | undefined;
Expand All @@ -2027,7 +2025,6 @@ helperText?: undefined;
multiselect: true;
value?: string[] | undefined;
onChange?: ((value: string[]) => void) | undefined;
separator?: string | undefined;
isTargetAmount?: boolean | undefined;
} & {
target?: "textfield-like" | undefined;
Expand All @@ -2041,7 +2038,6 @@ helperText?: string | undefined;
multiselect: true;
value?: string[] | undefined;
onChange?: ((value: string[]) => void) | undefined;
separator?: string | undefined;
isTargetAmount?: boolean | undefined;
} & {
target?: "button-like" | undefined;
Expand Down
Loading

0 comments on commit 483f64c

Please sign in to comment.