Skip to content

Commit

Permalink
feat(plasma-new-hope): resolve circular dependency in components
Browse files Browse the repository at this point in the history
  • Loading branch information
TitanKuzmich committed Dec 22, 2024
1 parent fa79299 commit 67943f6
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import type { BreadcrumbsProps } from './Breadcrumbs.types';
import { base as sizeCSS } from './variations/_size/base';
import { base as viewCSS } from './variations/_view/base';
import { base, Separator } from './Breadcrumbs.styles';
import { addSeparator, convertIconSize, getRenderItems } from './utils';
import { addSeparator, convertIconSize } from './utils';
import { getRenderItems } from './utils/getShortItems';

export const breadcrumbsRoot = (Root: RootProps<HTMLDivElement, BreadcrumbsProps>) =>
forwardRef<HTMLDivElement, BreadcrumbsProps>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactNode } from 'react';
import React from 'react';
import type { ReactNode } from 'react';

import { BreadcrumbShorter } from '../ui/BreadcrumbShorter/BreadcrumbShorter';
import { StyledLink } from '../Breadcrumbs.styles';
Expand All @@ -18,16 +19,6 @@ export const shortItems = (items: ReactNode[], renderSeparator: ReactNode, showI
return items;
};

export const convertIconSize = (size?: string) => {
switch (size) {
case 's':
case 'xs':
return 'xs';
default:
return 's';
}
};

export const getRenderItems = (items: BreadcrumbsItem[], renderSeparator: ReactNode, showItems?: number) => {
const renderItems = shortItems(
items.map((item: BreadcrumbsItem) => {
Expand Down Expand Up @@ -55,7 +46,3 @@ export const getRenderItems = (items: BreadcrumbsItem[], renderSeparator: ReactN

return renderItems;
};

export const addSeparator = (items: ReactNode[], renderSeparator: ReactNode) => {
return items.flatMap((item, idx) => (idx < items.length - 1 ? [item, renderSeparator] : [item]));
};
15 changes: 15 additions & 0 deletions packages/plasma-new-hope/src/components/Breadcrumbs/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ReactNode } from 'react';

export const convertIconSize = (size?: string) => {
switch (size) {
case 's':
case 'xs':
return 'xs';
default:
return 's';
}
};

export const addSeparator = (items: ReactNode[], renderSeparator: ReactNode) => {
return items.flatMap((item, idx) => (idx < items.length - 1 ? [item, renderSeparator] : [item]));
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import type { DateItem, DateObject, DisabledDay, EventDay } from '../Calendar.types';
import type { CalendarStateType } from '..';
import { CalendarState } from '../store/types';
import { CalendarState, CalendarStateType } from '../store/types';

import { getPropsMap } from '.';
import { getPropsMap } from './calendarGridHelper';

type GetDatesWithModificationsArgs = {
dates: DateItem[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from 'react';

import type { ItemContext } from './Combobox.types';

export const Context = createContext<ItemContext>({} as ItemContext);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useState, useReducer, useMemo, createContext, useLayoutEffect, useRef } from 'react';
import React, { forwardRef, useState, useReducer, useMemo, useLayoutEffect, useRef } from 'react';
import type { ChangeEvent, ForwardedRef } from 'react';
import { safeUseId, useForkRef } from '@salutejs/plasma-core';

Expand All @@ -23,13 +23,12 @@ import { Inner, StyledTextField } from './ui';
import { pathReducer, focusedPathReducer } from './reducers';
import { getPathMap, getTreeMaps } from './hooks/getPathMaps';
import { Ul, base, StyledArrow, IconArrowWrapper, StyledEmptyState } from './Combobox.styles';
import type { ItemContext, ComboboxProps } from './Combobox.types';
import type { ComboboxProps } from './Combobox.types';
import { base as viewCSS } from './variations/_view/base';
import { base as sizeCSS } from './variations/_size/base';
import type { ItemOptionTransformed } from './ui/Inner/ui/Item/Item.types';
import { SelectNative } from './ui/SelectNative/SelectNative';

export const Context = createContext<ItemContext>({} as ItemContext);
import { Context } from './Combobox.context';

/**
* Поле ввода с выпадающим списком и возможностью фильтрации и выбора элементов.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sizeToIconSize, getItemId } from '../../../../utils';
import { classes } from '../../../../Combobox.tokens';
import { cx, isEmpty } from '../../../../../../../utils';
import { IconDisclosureRightCentered, IconDone } from '../../../../../../_Icon';
import { Context } from '../../../../Combobox';
import { Context } from '../../../../Combobox.context';
import { useDidMountEffect } from '../../../../../../../hooks';

import { ItemProps } from './Item.types';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from 'react';

import type { ItemContext } from './Dropdown.types';

export const Context = createContext<ItemContext>({} as ItemContext);
7 changes: 3 additions & 4 deletions packages/plasma-new-hope/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { createContext, forwardRef, useReducer, useRef } from 'react';
import React, { forwardRef, useReducer, useRef } from 'react';
import { safeUseId } from '@salutejs/plasma-core';

import { RootProps } from '../../engines';
Expand All @@ -12,13 +12,12 @@ import { base as viewCSS } from './variations/_view/base';
import { base as sizeCSS } from './variations/_size/base';
import { Ul, base } from './Dropdown.styles';
import { childrenWithProps, getItemByFocused, getItemId, getPlacement } from './utils';
import type { DropdownProps, HandleGlobalToggleType, ItemContext } from './Dropdown.types';
import type { DropdownProps, HandleGlobalToggleType } from './Dropdown.types';
import { classes } from './Dropdown.tokens';
import { useKeyNavigation } from './hooks/useKeyboardNavigation';
import { useHashMaps } from './hooks/useHashMaps';
import { FloatingPopover } from './FloatingPopover';

export const Context = createContext<ItemContext>({} as ItemContext);
import { Context } from './Dropdown.context';

/**
* Выпадающий список.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import type { FC } from 'react';
import { safeUseId } from '@salutejs/plasma-core';

import { DropdownItem } from '..';
import { DropdownItem } from '../DropdownItem/DropdownItem';
import { Ul } from '../../Dropdown.styles';
import { FloatingPopover } from '../../FloatingPopover';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useRef, FC, useContext } from 'react';
import { classes } from '../../Dropdown.tokens';
import { cx } from '../../../../utils';
import { IconDisclosureRight } from '../../../_Icon';
import { Context } from '../../Dropdown';
import { Context } from '../../Dropdown.context';
import { getItemId } from '../../utils';

import {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from 'react';

import type { ItemContext } from './Select.types';

export const Context = createContext<ItemContext>({} as ItemContext);
6 changes: 2 additions & 4 deletions packages/plasma-new-hope/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {
useState,
useReducer,
useMemo,
createContext,
useLayoutEffect,
useRef,
ChangeEvent,
Expand All @@ -28,12 +27,11 @@ import { Inner, Target } from './ui';
import { pathReducer, focusedPathReducer } from './reducers';
import { usePathMaps } from './hooks/usePathMaps';
import { Ul, base } from './Select.styles';
import type { ItemContext, MergedSelectProps, RequiredProps } from './Select.types';
import type { MergedSelectProps, RequiredProps } from './Select.types';
import type { MergedDropdownNodeTransformed } from './ui/Inner/ui/Item/Item.types';
import { FloatingPopover } from './FloatingPopover';
import { SelectNative } from './ui/SelectNative/SelectNative';

export const Context = createContext<ItemContext>({} as ItemContext);
import { Context } from './Select.context';

/**
* Выпадающий список. Поддерживает выбор одного или нескольких значений.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Ul } from '../../Select.styles';
import { FloatingPopover } from '../../FloatingPopover';

import type { MergedDropdownNodeTransformed } from './ui/Item/Item.types';
import { Item } from './ui';
import { Item } from './ui/Item/Item';
import { InnerProps } from './Inner.type';

export const Inner: FC<InnerProps> = ({ item, currentLevel, path, dispatchPath, index, listWidth }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { sizeToIconSize, getItemId } from '../../../../utils';
import { classes } from '../../../../Select.tokens';
import { cx, isEmpty } from '../../../../../../utils';
import { IconDisclosureRightCentered, IconDone } from '../../../../../_Icon';
import { Context } from '../../../../Select';
import { Context } from '../../../../Select.context';
import { useDidMountEffect } from '../../../../../../hooks';

import { ItemProps } from './Item.types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { KeyboardEvent, FC, useState, useCallback } from 'react';

import { DoubleSlider } from '../index';
import { DoubleSlider } from '../Double/Double';
import { FormTypeString } from '../../../../types/FormType';

import { DoubleUncontrolledProps } from './DoubleUncontrolled.types';
Expand Down

0 comments on commit 67943f6

Please sign in to comment.