@hh.ru/magritte-ui-tree-selector 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Action.d.ts +4 -2
- package/Action.js +4 -1
- package/Action.js.map +1 -1
- package/Item.d.ts +6 -6
- package/Item.js +8 -2
- package/Item.js.map +1 -1
- package/ItemContent-B8bmjnfm.js +36 -0
- package/ItemContent-B8bmjnfm.js.map +1 -0
- package/ItemContent.d.ts +5 -4
- package/ItemContent.js +2 -1
- package/ItemContent.js.map +1 -1
- package/ItemsList.d.ts +4 -4
- package/ItemsList.js +2 -1
- package/ItemsList.js.map +1 -1
- package/MobileItem.d.ts +3 -3
- package/MobileItem.js +1 -1
- package/MobileItem.js.map +1 -1
- package/MobileItemsList.d.ts +18 -6
- package/MobileItemsList.js +4 -4
- package/MobileItemsList.js.map +1 -1
- package/MobileParentItem.d.ts +4 -4
- package/MobileParentItem.js +1 -1
- package/MobileParentItem.js.map +1 -1
- package/TreeSelector.d.ts +7 -5
- package/TreeSelector.js +2 -1
- package/TreeSelector.js.map +1 -1
- package/TreeSelectorDummy.d.ts +7 -4
- package/TreeSelectorDummy.js +6 -5
- package/TreeSelectorDummy.js.map +1 -1
- package/TreeSelectorItemBase.d.ts +2 -2
- package/TreeSelectorItemBase.js.map +1 -1
- package/collection/treeCollection.d.ts +1 -1
- package/collection/treeCollection.js.map +1 -1
- package/collection/treeCollectionHelper.d.ts +2 -2
- package/collection/types.d.ts +4 -2
- package/index.css +60 -48
- package/index.d.ts +4 -4
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/package.json +20 -18
- package/strategy/createSingleValueToggler.d.ts +1 -1
- package/strategy/createTreeCollectionToggler.d.ts +3 -3
- package/strategy/dummyToggle.d.ts +1 -1
- package/strategy/immutableSelectionStrategy.d.ts +3 -3
- package/strategy/selectionStrategy.d.ts +3 -3
- package/strategy/types.d.ts +1 -1
- package/types.d.ts +9 -10
- package/useAnimationTimeout.js +1 -1
- package/useDisabled.d.ts +2 -2
- package/useIndeterminate.d.ts +2 -2
- package/useRenderInput.js +1 -1
- package/useRenderInput.js.map +1 -1
- package/useSelected.d.ts +3 -3
- package/ItemContent-3b32dc50.js +0 -24
- package/ItemContent-3b32dc50.js.map +0 -1
package/Action.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { TreeModel } from '
|
|
1
|
+
import { FC, KeyboardEventHandler } from 'react';
|
|
2
|
+
import { TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
3
3
|
interface ActionProps {
|
|
4
4
|
singleChoice?: boolean;
|
|
5
5
|
onChange: (id: string, isSelected: boolean) => void;
|
|
6
6
|
id: TreeModel['id'];
|
|
7
|
+
name?: string;
|
|
7
8
|
selected: boolean;
|
|
8
9
|
indeterminate?: boolean;
|
|
10
|
+
onKeyDown?: KeyboardEventHandler;
|
|
9
11
|
}
|
|
10
12
|
export declare const Action: FC<ActionProps>;
|
|
11
13
|
export {};
|
package/Action.js
CHANGED
|
@@ -3,13 +3,16 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { memo, useCallback } from 'react';
|
|
4
4
|
import { Radio, Checkbox } from '@hh.ru/magritte-ui-checkbox-radio';
|
|
5
5
|
|
|
6
|
-
const Action = memo(({ id, singleChoice, indeterminate, selected, onChange }) => {
|
|
6
|
+
const Action = memo(({ id, name, singleChoice, indeterminate, selected, onChange, onKeyDown }) => {
|
|
7
7
|
const handleChange = useCallback((event) => {
|
|
8
8
|
onChange(id, event.target.checked);
|
|
9
9
|
}, [id, onChange]);
|
|
10
10
|
const inputProps = {
|
|
11
11
|
checked: selected,
|
|
12
12
|
onChange: handleChange,
|
|
13
|
+
name,
|
|
14
|
+
onKeyDown,
|
|
15
|
+
'data-qa': `tree-selector-input-${id}`,
|
|
13
16
|
};
|
|
14
17
|
return singleChoice ? jsx(Radio, { ...inputProps }) : jsx(Checkbox, { ...inputProps, indeterminate: indeterminate });
|
|
15
18
|
});
|
package/Action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.js","sources":["../src/Action.tsx"],"sourcesContent":["import { ChangeEventHandler, FC, useCallback, memo } from 'react';\n\nimport { Checkbox, Radio } from '@hh.ru/magritte-ui-checkbox-radio';\nimport { TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\n\ninterface ActionProps {\n singleChoice?: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n id: TreeModel['id'];\n selected: boolean;\n indeterminate?: boolean;\n}\n\nexport const Action: FC<ActionProps> = memo(({ id, singleChoice, indeterminate, selected, onChange }) => {\n
|
|
1
|
+
{"version":3,"file":"Action.js","sources":["../src/Action.tsx"],"sourcesContent":["import { ChangeEventHandler, FC, useCallback, memo, KeyboardEventHandler } from 'react';\n\nimport { Checkbox, Radio } from '@hh.ru/magritte-ui-checkbox-radio';\nimport { TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\n\ninterface ActionProps {\n singleChoice?: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n id: TreeModel['id'];\n name?: string;\n selected: boolean;\n indeterminate?: boolean;\n onKeyDown?: KeyboardEventHandler;\n}\n\nexport const Action: FC<ActionProps> = memo(\n ({ id, name, singleChoice, indeterminate, selected, onChange, onKeyDown }) => {\n const handleChange: ChangeEventHandler<HTMLInputElement> = useCallback(\n (event) => {\n onChange(id, event.target.checked);\n },\n [id, onChange]\n );\n\n const inputProps = {\n checked: selected,\n onChange: handleChange,\n name,\n onKeyDown,\n 'data-qa': `tree-selector-input-${id}`,\n };\n\n return singleChoice ? <Radio {...inputProps} /> : <Checkbox {...inputProps} indeterminate={indeterminate} />;\n }\n);\n\nAction.displayName = 'TreeSelectorAction';\n"],"names":["_jsx"],"mappings":";;;;MAea,MAAM,GAAoB,IAAI,CACvC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAI;AACzE,IAAA,MAAM,YAAY,GAAyC,WAAW,CAClE,CAAC,KAAK,KAAI;QACN,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACvC,KAAC,EACD,CAAC,EAAE,EAAE,QAAQ,CAAC,CACjB,CAAC;AAEF,IAAA,MAAM,UAAU,GAAG;AACf,QAAA,OAAO,EAAE,QAAQ;AACjB,QAAA,QAAQ,EAAE,YAAY;QACtB,IAAI;QACJ,SAAS;QACT,SAAS,EAAE,CAAuB,oBAAA,EAAA,EAAE,CAAE,CAAA;KACzC,CAAC;IAEF,OAAO,YAAY,GAAGA,IAAC,KAAK,EAAA,EAAA,GAAK,UAAU,EAAI,CAAA,GAAGA,GAAA,CAAC,QAAQ,EAAK,EAAA,GAAA,UAAU,EAAE,aAAa,EAAE,aAAa,EAAA,CAAI,CAAC;AACjH,CAAC,EACH;AAEF,MAAM,CAAC,WAAW,GAAG,oBAAoB;;;;"}
|
package/Item.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PropsWithChildren, ReactElement } from 'react';
|
|
2
|
-
import TreeCollection from '
|
|
3
|
-
import { AdditionalDefault, IdCollectionPredicate, TreeModel } from '
|
|
4
|
-
import { RenderItem } from '
|
|
2
|
+
import TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';
|
|
3
|
+
import { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
4
|
+
import { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
5
5
|
interface ItemProps<A extends AdditionalDefault> extends PropsWithChildren {
|
|
6
6
|
collection: TreeCollection<A>;
|
|
7
|
-
parentId?:
|
|
7
|
+
parentId?: TreeModel<A>['id'];
|
|
8
8
|
item: TreeModel<A>;
|
|
9
9
|
leavesOnly?: boolean;
|
|
10
10
|
checkSelectable?: IdCollectionPredicate;
|
|
@@ -16,8 +16,8 @@ interface ItemProps<A extends AdditionalDefault> extends PropsWithChildren {
|
|
|
16
16
|
isSearch: boolean;
|
|
17
17
|
onExpansion: (id: string) => void;
|
|
18
18
|
onChange: (id: string, isSelected: boolean) => void;
|
|
19
|
-
renderItemForDesktop?: RenderItem
|
|
19
|
+
renderItemForDesktop?: RenderItem<A>;
|
|
20
20
|
animationTimeout: number;
|
|
21
21
|
}
|
|
22
|
-
export declare const Item:
|
|
22
|
+
export declare const Item: <A extends AdditionalDefault>(props: ItemProps<A>) => ReactElement;
|
|
23
23
|
export {};
|
package/Item.js
CHANGED
|
@@ -3,7 +3,8 @@ import { jsxs, jsx } from 'react/jsx-runtime';
|
|
|
3
3
|
import { memo, useMemo, useRef, Children } from 'react';
|
|
4
4
|
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
5
5
|
import classnames from 'classnames';
|
|
6
|
-
import { s as styles, I as ItemContent } from './ItemContent-
|
|
6
|
+
import { s as styles, I as ItemContent } from './ItemContent-B8bmjnfm.js';
|
|
7
|
+
import '@hh.ru/magritte-common-keyboard';
|
|
7
8
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
8
9
|
import './Action.js';
|
|
9
10
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
@@ -66,7 +67,12 @@ const ItemComponent = ({ collection, item, parentId, isExpanded, isSelected, isI
|
|
|
66
67
|
[styles.withThreeBoxes]: allBoxesCount === 3,
|
|
67
68
|
[styles.withShift]: hasShift && parentId,
|
|
68
69
|
[styles.withIndent]: allBoxesCount === 0,
|
|
69
|
-
}), children: [jsx(ItemContent, { item: item, hasChildren: hasChildren, hasAction: !!hasAction, letter: hasLetter ? item.additional?.char : undefined, isExpanded: isExpanded, onExpansion: onExpansion, isSelected: isSelected, onChange: onChange, singleChoice: singleChoice, isIndeterminate: isIndeterminate, isDisabled: isDisabled, hasLetterOnLevel: hasLetterOnLevel, hasDot: hasDot, maxControlsOnLevel: maxControlsOnLevel, isSearch: isSearch, renderItemForDesktop: renderItemForDesktop }), jsx(TransitionGroup, { component: null, children: Children.toArray(children).map((child, index) => (jsx(CSSTransition, { nodeRef: childrenContentRef, timeout: animationTimeout, onEnter: handleEnter, onEntering: handleEntering, onEntered: handleEntered, onExit: handleExit, onExiting: handleExiting,
|
|
70
|
+
}), "data-qa": `tree-selector-item-${item.id}`, children: [jsx(ItemContent, { item: item, parentId: parentId, hasChildren: hasChildren, hasAction: !!hasAction, letter: hasLetter ? item.additional?.char : undefined, isExpanded: isExpanded, onExpansion: onExpansion, isSelected: isSelected, onChange: onChange, singleChoice: singleChoice, isIndeterminate: isIndeterminate, isDisabled: isDisabled, hasLetterOnLevel: hasLetterOnLevel, hasDot: hasDot, maxControlsOnLevel: maxControlsOnLevel, isSearch: isSearch, renderItemForDesktop: renderItemForDesktop }), jsx(TransitionGroup, { component: null, children: Children.toArray(children).map((child, index) => (jsx(CSSTransition, { nodeRef: childrenContentRef, timeout: animationTimeout, onEnter: handleEnter, onEntering: handleEntering, onEntered: handleEntered, onExit: handleExit, onExiting: handleExiting, classNames: {
|
|
71
|
+
enter: styles.itemAnimationEnter,
|
|
72
|
+
enterActive: styles.itemAnimationEnterActive,
|
|
73
|
+
exit: styles.itemAnimationExit,
|
|
74
|
+
exitActive: styles.itemAnimationExitActive,
|
|
75
|
+
}, children: jsx("div", { ref: childrenContentRef, className: styles.children, children: child }) }, index))) })] }));
|
|
70
76
|
};
|
|
71
77
|
const Item = memo(ItemComponent);
|
|
72
78
|
|
package/Item.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.js","sources":["../src/Item.tsx"],"sourcesContent":["import { PropsWithChildren, ReactElement, useMemo, useRef, Children, memo } from 'react';\nimport { TransitionGroup, CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { ItemContent } from '@hh.ru/magritte-ui-tree-selector/ItemContent';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\nimport styles from './tree-selector-item.less';\n\ninterface ItemProps<A extends AdditionalDefault> extends PropsWithChildren {\n collection: TreeCollection<A>;\n parentId?: string;\n item: TreeModel<A>;\n leavesOnly?: boolean;\n checkSelectable?: IdCollectionPredicate;\n isExpanded: boolean;\n isSelected: boolean;\n isDisabled: boolean;\n singleChoice?: boolean;\n isIndeterminate: boolean;\n isSearch: boolean;\n onExpansion: (id: string) => void;\n onChange: (id: string, isSelected: boolean) => void;\n renderItemForDesktop?: RenderItem;\n animationTimeout: number;\n}\n\nconst ItemComponent = <A extends AdditionalDefault>({\n collection,\n item,\n parentId,\n isExpanded,\n isSelected,\n isIndeterminate,\n isDisabled,\n leavesOnly,\n singleChoice,\n isSearch,\n checkSelectable,\n onExpansion,\n onChange,\n renderItemForDesktop,\n animationTimeout,\n children,\n}: ItemProps<A>): ReactElement => {\n const modelsOnLevel = useMemo(\n () => (parentId ? collection.getChildren(parentId) : collection.getTopLevel()),\n [parentId, collection]\n );\n\n const hasLetterOnLevel = useMemo(() => {\n return !isSearch && modelsOnLevel.some((model) => model.additional?.char);\n }, [modelsOnLevel, isSearch]);\n\n // максимальное кол-во контролов на уровне, максимум может быть 2 - шеврон + чекбокс/радио\n const maxControlsOnLevel = useMemo(() => {\n return modelsOnLevel.reduce((currentMax, model) => {\n const hasChildren = collection.hasChildren(model.id);\n const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(model.id, collection);\n const actionCount = +hasChildren + +!!hasAction;\n return Math.max(currentMax, actionCount);\n }, 0);\n }, [modelsOnLevel, checkSelectable, leavesOnly, collection]);\n\n const hasChildren = collection.hasChildren(item.id);\n const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(item.id, collection);\n const hasLetter = item.additional?.char && !isSearch;\n const realControlsCount = +hasChildren + +!!hasAction;\n\n // точка заменяет недостающий контрол, если их суммарное кол-во на уровне больше суммарного значения на текущем уровне\n const hasDot = realControlsCount < maxControlsOnLevel && (hasAction || hasChildren);\n const hasParentAction = parentId ? !leavesOnly && checkSelectable?.(parentId, collection) : false;\n\n const allBoxesCount = +hasLetterOnLevel + maxControlsOnLevel;\n\n const hasShift =\n allBoxesCount > 1 &&\n ((hasParentAction && (hasLetterOnLevel || hasChildren || hasDot)) || (!hasParentAction && hasLetterOnLevel));\n\n const childrenContentRef = useRef<HTMLDivElement>(null);\n const handleEnter = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = '0';\n }\n };\n const handleEntering = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = `${childrenContentRef.current.scrollHeight}px`;\n }\n };\n\n const handleEntered = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = `auto`;\n }\n };\n const handleExit = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = `${childrenContentRef.current.scrollHeight}px`;\n }\n };\n const handleExiting = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = '0';\n }\n };\n\n return (\n <div\n className={classnames(styles.item, {\n [styles.withTwoBoxes]: allBoxesCount === 2,\n [styles.withThreeBoxes]: allBoxesCount === 3,\n [styles.withShift]: hasShift && parentId,\n [styles.withIndent]: allBoxesCount === 0,\n })}\n >\n <ItemContent\n item={item}\n hasChildren={hasChildren}\n hasAction={!!hasAction}\n letter={hasLetter ? item.additional?.char : undefined}\n isExpanded={isExpanded}\n onExpansion={onExpansion}\n isSelected={isSelected}\n onChange={onChange}\n singleChoice={singleChoice}\n isIndeterminate={isIndeterminate}\n isDisabled={isDisabled}\n hasLetterOnLevel={hasLetterOnLevel}\n hasDot={hasDot}\n maxControlsOnLevel={maxControlsOnLevel}\n isSearch={isSearch}\n renderItemForDesktop={renderItemForDesktop}\n />\n\n <TransitionGroup component={null}>\n {Children.toArray(children).map((child, index) => (\n <CSSTransition\n key={index}\n nodeRef={childrenContentRef}\n timeout={animationTimeout}\n onEnter={handleEnter}\n onEntering={handleEntering}\n onEntered={handleEntered}\n onExit={handleExit}\n onExiting={handleExiting}\n >\n <div ref={childrenContentRef} className={styles.children}>\n {child}\n </div>\n </CSSTransition>\n ))}\n </TransitionGroup>\n </div>\n );\n};\n\nexport const Item = memo(ItemComponent);\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;AA6BA,MAAM,aAAa,GAAG,CAA8B,EAChD,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,gBAAgB,EAChB,QAAQ,GACG,KAAkB;AAC7B,IAAA,MAAM,aAAa,GAAG,OAAO,CACzB,OAAO,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,EAC9E,CAAC,QAAQ,EAAE,UAAU,CAAC,CACzB,CAAC;AAEF,IAAA,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAK;AAClC,QAAA,OAAO,CAAC,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAC9E,KAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;;AAG9B,IAAA,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAK;QACpC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,KAAK,KAAI;YAC9C,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACrD,YAAA,MAAM,SAAS,GAAG,EAAE,UAAU,IAAI,WAAW,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;YAC1F,MA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S,EACtB,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,GAAG,SAAS,EACrD,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,UAAU,EACtB,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,EACtC,QAAQ,EAAE,QAAQ,EAClB,oBAAoB,EAAE,oBAAoB,GAC5C,EAEFA,GAAA,CAAC,eAAe,EAAA,EAAC,SAAS,EAAE,IAAI,EAC3B,QAAA,EAAA,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,MACzCA,GAAC,CAAA,aAAa,EAEV,EAAA,OAAO,EAAE,kBAAkB,EAC3B,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,WAAW,EACpB,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,aAAa,EACxB,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,aAAa,YAExBA,GAAK,CAAA,KAAA,EAAA,EAAA,GAAG,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,EACnD,QAAA,EAAA,KAAK,EACJ,CAAA,EAAA,EAXD,KAAK,CAYE,CACnB,CAAC,EACY,CAAA,CAAA,EAAA,CAChB,EACR;AACN,CAAC,CAAC;MAEW,IAAI,GAAG,IAAI,CAAC,aAAa;;;;"}
|
|
1
|
+
{"version":3,"file":"Item.js","sources":["../src/Item.tsx"],"sourcesContent":["import { PropsWithChildren, ReactElement, useMemo, useRef, Children, memo } from 'react';\nimport { TransitionGroup, CSSTransition } from 'react-transition-group';\nimport classnames from 'classnames';\n\nimport { ItemContent } from '@hh.ru/magritte-ui-tree-selector/ItemContent';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\nimport styles from './tree-selector-item.less';\n\ninterface ItemProps<A extends AdditionalDefault> extends PropsWithChildren {\n collection: TreeCollection<A>;\n parentId?: TreeModel<A>['id'];\n item: TreeModel<A>;\n leavesOnly?: boolean;\n checkSelectable?: IdCollectionPredicate;\n isExpanded: boolean;\n isSelected: boolean;\n isDisabled: boolean;\n singleChoice?: boolean;\n isIndeterminate: boolean;\n isSearch: boolean;\n onExpansion: (id: string) => void;\n onChange: (id: string, isSelected: boolean) => void;\n renderItemForDesktop?: RenderItem<A>;\n animationTimeout: number;\n}\n\nconst ItemComponent = <A extends AdditionalDefault>({\n collection,\n item,\n parentId,\n isExpanded,\n isSelected,\n isIndeterminate,\n isDisabled,\n leavesOnly,\n singleChoice,\n isSearch,\n checkSelectable,\n onExpansion,\n onChange,\n renderItemForDesktop,\n animationTimeout,\n children,\n}: ItemProps<A>): ReactElement => {\n const modelsOnLevel = useMemo(\n () => (parentId ? collection.getChildren(parentId) : collection.getTopLevel()),\n [parentId, collection]\n );\n\n const hasLetterOnLevel = useMemo(() => {\n return !isSearch && modelsOnLevel.some((model) => model.additional?.char);\n }, [modelsOnLevel, isSearch]);\n\n // максимальное кол-во контролов на уровне, максимум может быть 2 - шеврон + чекбокс/радио\n const maxControlsOnLevel = useMemo(() => {\n return modelsOnLevel.reduce((currentMax, model) => {\n const hasChildren = collection.hasChildren(model.id);\n const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(model.id, collection);\n const actionCount = +hasChildren + +!!hasAction;\n return Math.max(currentMax, actionCount);\n }, 0);\n }, [modelsOnLevel, checkSelectable, leavesOnly, collection]);\n\n const hasChildren = collection.hasChildren(item.id);\n const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(item.id, collection);\n const hasLetter = item.additional?.char && !isSearch;\n const realControlsCount = +hasChildren + +!!hasAction;\n\n // точка заменяет недостающий контрол, если их суммарное кол-во на уровне больше суммарного значения на текущем уровне\n const hasDot = realControlsCount < maxControlsOnLevel && (hasAction || hasChildren);\n const hasParentAction = parentId ? !leavesOnly && checkSelectable?.(parentId, collection) : false;\n\n const allBoxesCount = +hasLetterOnLevel + maxControlsOnLevel;\n\n const hasShift =\n allBoxesCount > 1 &&\n ((hasParentAction && (hasLetterOnLevel || hasChildren || hasDot)) || (!hasParentAction && hasLetterOnLevel));\n\n const childrenContentRef = useRef<HTMLDivElement>(null);\n const handleEnter = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = '0';\n }\n };\n const handleEntering = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = `${childrenContentRef.current.scrollHeight}px`;\n }\n };\n\n const handleEntered = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = `auto`;\n }\n };\n const handleExit = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = `${childrenContentRef.current.scrollHeight}px`;\n }\n };\n const handleExiting = () => {\n if (childrenContentRef.current) {\n childrenContentRef.current.style.height = '0';\n }\n };\n\n return (\n <div\n className={classnames(styles.item, {\n [styles.withTwoBoxes]: allBoxesCount === 2,\n [styles.withThreeBoxes]: allBoxesCount === 3,\n [styles.withShift]: hasShift && parentId,\n [styles.withIndent]: allBoxesCount === 0,\n })}\n data-qa={`tree-selector-item-${item.id}`}\n >\n <ItemContent\n item={item}\n parentId={parentId}\n hasChildren={hasChildren}\n hasAction={!!hasAction}\n letter={hasLetter ? item.additional?.char : undefined}\n isExpanded={isExpanded}\n onExpansion={onExpansion}\n isSelected={isSelected}\n onChange={onChange}\n singleChoice={singleChoice}\n isIndeterminate={isIndeterminate}\n isDisabled={isDisabled}\n hasLetterOnLevel={hasLetterOnLevel}\n hasDot={hasDot}\n maxControlsOnLevel={maxControlsOnLevel}\n isSearch={isSearch}\n renderItemForDesktop={renderItemForDesktop}\n />\n\n <TransitionGroup component={null}>\n {Children.toArray(children).map((child, index) => (\n <CSSTransition\n key={index}\n nodeRef={childrenContentRef}\n timeout={animationTimeout}\n onEnter={handleEnter}\n onEntering={handleEntering}\n onEntered={handleEntered}\n onExit={handleExit}\n onExiting={handleExiting}\n classNames={{\n enter: styles.itemAnimationEnter,\n enterActive: styles.itemAnimationEnterActive,\n exit: styles.itemAnimationExit,\n exitActive: styles.itemAnimationExitActive,\n }}\n >\n <div ref={childrenContentRef} className={styles.children}>\n {child}\n </div>\n </CSSTransition>\n ))}\n </TransitionGroup>\n </div>\n );\n};\n\nexport const Item = memo(ItemComponent) as <A extends AdditionalDefault>(props: ItemProps<A>) => ReactElement;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;;AA6BA,MAAM,aAAa,GAAG,CAA8B,EAChD,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,gBAAgB,EAChB,QAAQ,GACG,KAAkB;AAC7B,IAAA,MAAM,aAAa,GAAG,OAAO,CACzB,OAAO,QAAQ,GAAG,UAAU,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,EAC9E,CAAC,QAAQ,EAAE,UAAU,CAAC,CACzB,CAAC;AAEF,IAAA,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAK;AAClC,QAAA,OAAO,CAAC,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AAC9E,KAAC,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;;AAG9B,IAAA,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAK;QACpC,OAAO,aAAa,CAAC,MAAM,CAAC,CA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B,UAAU,EAAE,MAAM,CAAC,uBAAuB;qBAC7C,EAED,QAAA,EAAAA,GAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,CAAC,QAAQ,YACnD,KAAK,EAAA,CACJ,IAjBD,KAAK,CAkBE,CACnB,CAAC,EAAA,CACY,CAChB,EAAA,CAAA,EACR;AACN,CAAC,CAAC;MAEW,IAAI,GAAG,IAAI,CAAC,aAAa;;;;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { memo, useCallback } from 'react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { keyboardMatch, keyboardKeys } from '@hh.ru/magritte-common-keyboard';
|
|
6
|
+
import { DotFilledSize24, ChevronUpOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
7
|
+
import { Action } from './Action.js';
|
|
8
|
+
import { TreeSelectorItemBase } from './TreeSelectorItemBase.js';
|
|
9
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
10
|
+
|
|
11
|
+
var styles = {"item-animation-timeout":"magritte-item-animation-timeout___pbOyZ_1-7-0","itemAnimationTimeout":"magritte-item-animation-timeout___pbOyZ_1-7-0","wrapper":"magritte-wrapper___GHKV6_1-7-0","letter":"magritte-letter___yZOCU_1-7-0","icon":"magritte-icon___kO3Fj_1-7-0","space":"magritte-space___xTO79_1-7-0","iconActive":"magritte-iconActive___4yrG5_1-7-0","iconUp":"magritte-iconUp___mpXV6_1-7-0","content":"magritte-content___ZRc6R_1-7-0","with-shift":"magritte-with-shift___ZErxZ_1-7-0","withShift":"magritte-with-shift___ZErxZ_1-7-0","with-indent":"magritte-with-indent___MH9Vy_1-7-0","withIndent":"magritte-with-indent___MH9Vy_1-7-0","item":"magritte-item___2LtOL_1-7-0","children":"magritte-children___kq-eq_1-7-0","with-two-boxes":"magritte-with-two-boxes___LWOy2_1-7-0","withTwoBoxes":"magritte-with-two-boxes___LWOy2_1-7-0","with-three-boxes":"magritte-with-three-boxes___cyVao_1-7-0","withThreeBoxes":"magritte-with-three-boxes___cyVao_1-7-0","item-animation-enter":"magritte-item-animation-enter___14KlM_1-7-0","itemAnimationEnter":"magritte-item-animation-enter___14KlM_1-7-0","item-animation-enter-active":"magritte-item-animation-enter-active___oEWbW_1-7-0","itemAnimationEnterActive":"magritte-item-animation-enter-active___oEWbW_1-7-0","item-animation-exit":"magritte-item-animation-exit___a-Low_1-7-0","itemAnimationExit":"magritte-item-animation-exit___a-Low_1-7-0","item-animation-exit-active":"magritte-item-animation-exit-active___MhBnn_1-7-0","itemAnimationExitActive":"magritte-item-animation-exit-active___MhBnn_1-7-0"};
|
|
12
|
+
|
|
13
|
+
const ItemContentComponent = ({ item, parentId, hasAction, hasChildren, letter, isExpanded, isDisabled, onExpansion, hasLetterOnLevel, isSelected, onChange, isIndeterminate, singleChoice, hasDot, maxControlsOnLevel, isSearch, renderItemForDesktop = TreeSelectorItemBase, }) => {
|
|
14
|
+
const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);
|
|
15
|
+
const currentActionCount = +hasDot + +hasAction + +hasChildren;
|
|
16
|
+
const neededSpacesCount = maxControlsOnLevel - currentActionCount;
|
|
17
|
+
const handleExpandableKeyDown = useCallback((event) => {
|
|
18
|
+
if (keyboardMatch(event.nativeEvent, keyboardKeys.ArrowLeft)) {
|
|
19
|
+
isExpanded && onExpansion(item.id);
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (keyboardMatch(event.nativeEvent, keyboardKeys.ArrowRight)) {
|
|
24
|
+
!isExpanded && onExpansion(item.id);
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
}
|
|
27
|
+
}, [isExpanded, onExpansion, item.id]);
|
|
28
|
+
const input = hasAction ? (jsx(Action, { selected: isSelected, onChange: onChange, id: item.id, onKeyDown: handleExpandableKeyDown, indeterminate: isIndeterminate, singleChoice: singleChoice, name: `tree-selector-item-${parentId || 'top'}-${item.id}` })) : undefined;
|
|
29
|
+
return (jsxs("div", { className: styles.wrapper, children: [(letter || hasLetterOnLevel) && (jsx("div", { className: styles.letter, children: letter && (jsx(Text, { typography: "subtitle-1-semibold", style: "secondary", Element: "span", children: letter })) })), hasDot && (jsx("div", { className: styles.icon, children: jsx(DotFilledSize24, { initial: "tertiary" }) })), [...Array(neededSpacesCount).keys()].map((_, i) => (jsx("div", { className: styles.space }, i))), hasChildren && (jsx("div", { className: classnames(styles.icon, styles.iconActive, {
|
|
30
|
+
[styles.iconUp]: isExpanded,
|
|
31
|
+
}), "data-qa": `tree-selector-chevron-${item.id}`, onClick: handleExpandableClick, children: jsx(ChevronUpOutlinedSize24, { initial: "tertiary" }) })), renderItemForDesktop({ disabled: isDisabled, input, item, isSearch, isParent: hasChildren })] }));
|
|
32
|
+
};
|
|
33
|
+
const ItemContent = memo(ItemContentComponent);
|
|
34
|
+
|
|
35
|
+
export { ItemContent as I, styles as s };
|
|
36
|
+
//# sourceMappingURL=ItemContent-B8bmjnfm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemContent-B8bmjnfm.js","sources":["../src/ItemContent.tsx"],"sourcesContent":["import { ReactElement, useCallback, memo, KeyboardEventHandler } from 'react';\nimport classnames from 'classnames';\n\nimport { keyboardKeys, keyboardMatch } from '@hh.ru/magritte-common-keyboard';\nimport { ChevronUpOutlinedSize24, DotFilledSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { Text } from '@hh.ru/magritte-ui-typography';\n\nimport styles from './tree-selector-item.less';\n\ninterface ItemContent<A extends AdditionalDefault> {\n item: TreeModel<A>;\n parentId?: TreeModel<A>['id'];\n hasChildren: boolean;\n hasAction: boolean;\n letter?: string;\n onExpansion: (id: string) => void;\n isExpanded: boolean;\n isSelected: boolean;\n isDisabled: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n isIndeterminate: boolean;\n singleChoice?: boolean;\n hasLetterOnLevel: boolean;\n hasDot: boolean;\n maxControlsOnLevel: number;\n renderItemForDesktop?: RenderItem<A>;\n isSearch: boolean;\n}\n\nconst ItemContentComponent = <A extends AdditionalDefault>({\n item,\n parentId,\n hasAction,\n hasChildren,\n letter,\n isExpanded,\n isDisabled,\n onExpansion,\n hasLetterOnLevel,\n isSelected,\n onChange,\n isIndeterminate,\n singleChoice,\n hasDot,\n maxControlsOnLevel,\n isSearch,\n renderItemForDesktop = TreeSelectorItemBase,\n}: ItemContent<A>): ReactElement => {\n const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);\n const currentActionCount = +hasDot + +hasAction + +hasChildren;\n const neededSpacesCount = maxControlsOnLevel - currentActionCount;\n\n const handleExpandableKeyDown = useCallback<KeyboardEventHandler>(\n (event) => {\n if (keyboardMatch(event.nativeEvent, keyboardKeys.ArrowLeft)) {\n isExpanded && onExpansion(item.id);\n event.preventDefault();\n return;\n }\n if (keyboardMatch(event.nativeEvent, keyboardKeys.ArrowRight)) {\n !isExpanded && onExpansion(item.id);\n event.preventDefault();\n }\n },\n [isExpanded, onExpansion, item.id]\n );\n\n const input = hasAction ? (\n <Action\n selected={isSelected}\n onChange={onChange}\n id={item.id}\n onKeyDown={handleExpandableKeyDown}\n indeterminate={isIndeterminate}\n singleChoice={singleChoice}\n name={`tree-selector-item-${parentId || 'top'}-${item.id}`}\n />\n ) : undefined;\n\n return (\n <div className={styles.wrapper}>\n {(letter || hasLetterOnLevel) && (\n <div className={styles.letter}>\n {letter && (\n <Text typography=\"subtitle-1-semibold\" style=\"secondary\" Element=\"span\">\n {letter}\n </Text>\n )}\n </div>\n )}\n {hasDot && (\n <div className={styles.icon}>\n <DotFilledSize24 initial=\"tertiary\" />\n </div>\n )}\n\n {[...Array(neededSpacesCount).keys()].map((_, i) => (\n <div key={i} className={styles.space} />\n ))}\n\n {hasChildren && (\n <div\n className={classnames(styles.icon, styles.iconActive, {\n [styles.iconUp]: isExpanded,\n })}\n data-qa={`tree-selector-chevron-${item.id}`}\n onClick={handleExpandableClick}\n >\n <ChevronUpOutlinedSize24 initial=\"tertiary\" />\n </div>\n )}\n {renderItemForDesktop({ disabled: isDisabled, input, item, isSearch, isParent: hasChildren })}\n </div>\n );\n};\n\nexport const ItemContent = memo(ItemContentComponent) as <A extends AdditionalDefault>(\n props: ItemContent<A>\n) => ReactElement;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;;AAiCA,MAAM,oBAAoB,GAAG,CAA8B,EACvD,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,MAAM,EACN,UAAU,EACV,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,eAAe,EACf,YAAY,EACZ,MAAM,EACN,kBAAkB,EAClB,QAAQ,EACR,oBAAoB,GAAG,oBAAoB,GAC9B,KAAkB;IAC/B,MAAM,qBAAqB,GAAG,WAAW,CAAC,MAAM,WAAW,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC,CAAC;IAC7G,MAAM,kBAAkB,GAAG,CAAC,MAAM,GAAG,CAAC,SAAS,GAAG,CAAC,WAAW,CAAC;AAC/D,IAAA,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAElE,IAAA,MAAM,uBAAuB,GAAG,WAAW,CACvC,CAAC,KAAK,KAAI;QACN,IAAI,aAAa,CAAC,KAAK,CAAC,WAAW,EAAE,YAAY,CAAC,SAAS,CAAC,EAAE;AAC1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Ae,EAAC,EAAA,OAAO,EAAC,UAAU,EAAG,CAAA,EAAA,CACpC,CACT,EAEA,CAAC,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAC3CA,GAAa,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,KAAK,EAA1B,EAAA,CAAC,CAA6B,CAC3C,CAAC,EAED,WAAW,KACRA,GACI,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE;AAClD,oBAAA,CAAC,MAAM,CAAC,MAAM,GAAG,UAAU;AAC9B,iBAAA,CAAC,aACO,CAAyB,sBAAA,EAAA,IAAI,CAAC,EAAE,CAAA,CAAE,EAC3C,OAAO,EAAE,qBAAqB,EAAA,QAAA,EAE9BA,IAAC,uBAAuB,EAAA,EAAC,OAAO,EAAC,UAAU,GAAG,EAC5C,CAAA,CACT,EACA,oBAAoB,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA,EAAA,CAC3F,EACR;AACN,CAAC,CAAC;MAEW,WAAW,GAAG,IAAI,CAAC,oBAAoB;;;;"}
|
package/ItemContent.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { AdditionalDefault, TreeModel } from '
|
|
3
|
-
import { RenderItem } from '
|
|
2
|
+
import { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
3
|
+
import { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
4
4
|
interface ItemContent<A extends AdditionalDefault> {
|
|
5
5
|
item: TreeModel<A>;
|
|
6
|
+
parentId?: TreeModel<A>['id'];
|
|
6
7
|
hasChildren: boolean;
|
|
7
8
|
hasAction: boolean;
|
|
8
9
|
letter?: string;
|
|
@@ -16,8 +17,8 @@ interface ItemContent<A extends AdditionalDefault> {
|
|
|
16
17
|
hasLetterOnLevel: boolean;
|
|
17
18
|
hasDot: boolean;
|
|
18
19
|
maxControlsOnLevel: number;
|
|
19
|
-
renderItemForDesktop?: RenderItem
|
|
20
|
+
renderItemForDesktop?: RenderItem<A>;
|
|
20
21
|
isSearch: boolean;
|
|
21
22
|
}
|
|
22
|
-
export declare const ItemContent:
|
|
23
|
+
export declare const ItemContent: <A extends AdditionalDefault>(props: ItemContent<A>) => ReactElement;
|
|
23
24
|
export {};
|
package/ItemContent.js
CHANGED
|
@@ -2,11 +2,12 @@ import './index.css';
|
|
|
2
2
|
import 'react/jsx-runtime';
|
|
3
3
|
import 'react';
|
|
4
4
|
import 'classnames';
|
|
5
|
+
import '@hh.ru/magritte-common-keyboard';
|
|
5
6
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
6
7
|
import './Action.js';
|
|
7
8
|
import './TreeSelectorItemBase.js';
|
|
8
9
|
import '@hh.ru/magritte-ui-typography';
|
|
9
|
-
export { I as ItemContent } from './ItemContent-
|
|
10
|
+
export { I as ItemContent } from './ItemContent-B8bmjnfm.js';
|
|
10
11
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
11
12
|
import '@hh.ru/magritte-ui-cell';
|
|
12
13
|
//# sourceMappingURL=ItemContent.js.map
|
package/ItemContent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemContent.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ItemContent.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/ItemsList.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import TreeCollection from '
|
|
3
|
-
import { AdditionalDefault, IdCollectionPredicate, TreeModel } from '
|
|
4
|
-
import { RenderItem } from '
|
|
2
|
+
import TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';
|
|
3
|
+
import { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
4
|
+
import { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
5
5
|
interface ItemsListProps<A extends AdditionalDefault> {
|
|
6
6
|
items: TreeModel<A>[];
|
|
7
7
|
collection: TreeCollection<A>;
|
|
@@ -16,7 +16,7 @@ interface ItemsListProps<A extends AdditionalDefault> {
|
|
|
16
16
|
indeterminate: string[];
|
|
17
17
|
singleChoice?: boolean;
|
|
18
18
|
isSearch: boolean;
|
|
19
|
-
renderItemForDesktop?: RenderItem
|
|
19
|
+
renderItemForDesktop?: RenderItem<A>;
|
|
20
20
|
animationTimeout: number;
|
|
21
21
|
}
|
|
22
22
|
export declare const ItemsList: <A extends AdditionalDefault>(props: ItemsListProps<A>) => ReactElement;
|
package/ItemsList.js
CHANGED
|
@@ -4,7 +4,8 @@ import { Item } from './Item.js';
|
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'react-transition-group';
|
|
6
6
|
import 'classnames';
|
|
7
|
-
import './ItemContent-
|
|
7
|
+
import './ItemContent-B8bmjnfm.js';
|
|
8
|
+
import '@hh.ru/magritte-common-keyboard';
|
|
8
9
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
9
10
|
import './Action.js';
|
|
10
11
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
package/ItemsList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ItemsList.js","sources":["../src/ItemsList.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { Item } from '@hh.ru/magritte-ui-tree-selector/Item';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface ItemsListProps<A extends AdditionalDefault> {\n items: TreeModel<A>[];\n collection: TreeCollection<A>;\n leavesOnly?: boolean;\n checkSelectable?: IdCollectionPredicate;\n parentId?: TreeModel<A>['id'];\n onExpansion: (id: string) => void;\n expanded: string[];\n selected: string[];\n disabled: string[];\n onChange: (id: string, isSelected: boolean) => void;\n indeterminate: string[];\n singleChoice?: boolean;\n isSearch: boolean;\n renderItemForDesktop?: RenderItem
|
|
1
|
+
{"version":3,"file":"ItemsList.js","sources":["../src/ItemsList.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { Item } from '@hh.ru/magritte-ui-tree-selector/Item';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface ItemsListProps<A extends AdditionalDefault> {\n items: TreeModel<A>[];\n collection: TreeCollection<A>;\n leavesOnly?: boolean;\n checkSelectable?: IdCollectionPredicate;\n parentId?: TreeModel<A>['id'];\n onExpansion: (id: string) => void;\n expanded: string[];\n selected: string[];\n disabled: string[];\n onChange: (id: string, isSelected: boolean) => void;\n indeterminate: string[];\n singleChoice?: boolean;\n isSearch: boolean;\n renderItemForDesktop?: RenderItem<A>;\n animationTimeout: number;\n}\n\nexport const ItemsList = <A extends AdditionalDefault>(props: ItemsListProps<A>): ReactElement => {\n const {\n items,\n collection,\n leavesOnly,\n checkSelectable,\n selected,\n parentId,\n expanded,\n disabled,\n onExpansion,\n indeterminate,\n onChange,\n isSearch,\n singleChoice,\n renderItemForDesktop,\n animationTimeout,\n } = props;\n return (\n <>\n {items.map((item) => {\n const isExpanded = expanded.includes(item.id);\n const hasChildren = collection.hasChildren(item.id);\n\n return (\n <Item\n key={item.id}\n collection={collection}\n checkSelectable={checkSelectable}\n isSelected={selected.includes(item.id)}\n isExpanded={isExpanded}\n isIndeterminate={indeterminate.includes(item.id)}\n isDisabled={disabled.includes(item.id)}\n parentId={parentId}\n item={item}\n leavesOnly={leavesOnly}\n singleChoice={singleChoice}\n onExpansion={onExpansion}\n onChange={onChange}\n isSearch={isSearch}\n renderItemForDesktop={renderItemForDesktop}\n animationTimeout={animationTimeout}\n >\n {hasChildren && isExpanded && (\n <ItemsList {...props} items={collection.getChildren(item.id)} parentId={item.id} />\n )}\n </Item>\n );\n })}\n </>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;AAyBa,MAAA,SAAS,GAAG,CAA8B,KAAwB,KAAkB;AAC7F,IAAA,MAAM,EACF,KAAK,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,aAAa,EACb,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GACnB,GAAG,KAAK,CAAC;IACV,QACIA,0BACK,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAI;YAChB,MAAM,UAAU,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC9C,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAEpD,QACIA,GAAC,CAAA,IAAI,EAED,EAAA,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EACtC,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EAChD,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EACtC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,oBAAoB,EAAE,oBAAoB,EAC1C,gBAAgB,EAAE,gBAAgB,EAEjC,QAAA,EAAA,WAAW,IAAI,UAAU,KACtBA,IAAC,SAAS,EAAA,EAAA,GAAK,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAI,CAAA,CACtF,EAnBI,EAAA,IAAI,CAAC,EAAE,CAoBT,EACT;SACL,CAAC,EACH,CAAA,EACL;AACN;;;;"}
|
package/MobileItem.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { AdditionalDefault, TreeModel } from '
|
|
3
|
-
import { RenderItem } from '
|
|
2
|
+
import { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
3
|
+
import { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
4
4
|
interface MobileItemProps<A extends AdditionalDefault> {
|
|
5
5
|
item: TreeModel<A>;
|
|
6
6
|
singleChoice?: boolean;
|
|
@@ -8,7 +8,7 @@ interface MobileItemProps<A extends AdditionalDefault> {
|
|
|
8
8
|
isSelected: boolean;
|
|
9
9
|
isDisabled: boolean;
|
|
10
10
|
onChange: (id: string, isSelected: boolean) => void;
|
|
11
|
-
renderItem?: RenderItem
|
|
11
|
+
renderItem?: RenderItem<A>;
|
|
12
12
|
isSearch: boolean;
|
|
13
13
|
}
|
|
14
14
|
export declare const MobileItem: <A extends AdditionalDefault>({ item, isSelected, singleChoice, isSelectable, isDisabled, onChange, isSearch, renderItem, }: MobileItemProps<A>) => ReactElement;
|
package/MobileItem.js
CHANGED
|
@@ -9,7 +9,7 @@ import '@hh.ru/magritte-ui-cell';
|
|
|
9
9
|
|
|
10
10
|
const MobileItem = ({ item, isSelected, singleChoice, isSelectable, isDisabled, onChange, isSearch, renderItem = TreeSelectorItemBase, }) => {
|
|
11
11
|
const input = isSelectable ? (jsx(Action, { selected: isSelected, onChange: onChange, id: item.id, singleChoice: singleChoice })) : undefined;
|
|
12
|
-
return (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: isSelected, children: renderItem({ input, item, isSearch, isXS: true, disabled: isDisabled }) }));
|
|
12
|
+
return (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: isSelected, "data-qa": `tree-selector-item-${item.id}`, children: renderItem({ input, item, isSearch, isXS: true, disabled: isDisabled }) }));
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export { MobileItem };
|
package/MobileItem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileItem.js","sources":["../src/MobileItem.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileItemProps<A extends AdditionalDefault> {\n item: TreeModel<A>;\n singleChoice?: boolean;\n isSelectable?: boolean;\n isSelected: boolean;\n isDisabled: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n renderItem?: RenderItem
|
|
1
|
+
{"version":3,"file":"MobileItem.js","sources":["../src/MobileItem.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileItemProps<A extends AdditionalDefault> {\n item: TreeModel<A>;\n singleChoice?: boolean;\n isSelectable?: boolean;\n isSelected: boolean;\n isDisabled: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n renderItem?: RenderItem<A>;\n isSearch: boolean;\n}\n\nexport const MobileItem = <A extends AdditionalDefault>({\n item,\n isSelected,\n singleChoice,\n isSelectable,\n isDisabled,\n onChange,\n isSearch,\n renderItem = TreeSelectorItemBase,\n}: MobileItemProps<A>): ReactElement => {\n const input = isSelectable ? (\n <Action selected={isSelected} onChange={onChange} id={item.id} singleChoice={singleChoice} />\n ) : undefined;\n return (\n <CheckableCardElement\n padding={16}\n borderRadius={12}\n Element=\"label\"\n checked={isSelected}\n data-qa={`tree-selector-item-${item.id}`}\n >\n {renderItem({ input, item, isSearch, isXS: true, disabled: isDisabled })}\n </CheckableCardElement>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;;AAmBa,MAAA,UAAU,GAAG,CAA8B,EACpD,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,GAAG,oBAAoB,GAChB,KAAkB;AACnC,IAAA,MAAM,KAAK,GAAG,YAAY,IACtBA,GAAC,CAAA,MAAM,EAAC,EAAA,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,YAAY,GAAI,IAC7F,SAAS,CAAC;IACd,QACIA,IAAC,oBAAoB,EAAA,EACjB,OAAO,EAAE,EAAE,EACX,YAAY,EAAE,EAAE,EAChB,OAAO,EAAC,OAAO,EACf,OAAO,EAAE,UAAU,EACV,SAAA,EAAA,CAAA,mBAAA,EAAsB,IAAI,CAAC,EAAE,CAAE,CAAA,EAAA,QAAA,EAEvC,UAAU,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,EACrD,CAAA,EACzB;AACN;;;;"}
|
package/MobileItemsList.d.ts
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { AdditionalDefault, TreeModel } from '
|
|
3
|
-
import { ListControls, TreeSelectorDummyProps } from '
|
|
4
|
-
|
|
1
|
+
import { ReactElement, ForwardedRef, ReactNode } from 'react';
|
|
2
|
+
import { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
3
|
+
import { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
4
|
+
type MobileItemsListProps<A extends AdditionalDefault> = {
|
|
5
5
|
selected: string[];
|
|
6
6
|
disabled: string[];
|
|
7
|
-
getSearchItemOrder: (model: TreeModel<
|
|
7
|
+
getSearchItemOrder: (model: TreeModel<A>) => number;
|
|
8
8
|
setInputValue: (newValue: string) => void;
|
|
9
9
|
handleChangeInput: (newValue: string) => void;
|
|
10
10
|
contentFilterQuery: string;
|
|
11
11
|
trlSelectParent: ReactNode;
|
|
12
|
-
} & Pick<TreeSelectorDummyProps<
|
|
12
|
+
} & Pick<TreeSelectorDummyProps<A>, 'collection' | 'leavesOnly' | 'singleChoice' | 'checkSelectable' | 'onChange' | 'renderItem' | 'renderMobileDelimiter' | 'onMobileNavigationChange'>;
|
|
13
|
+
export declare const MobileItemsList: <A extends AdditionalDefault>(props: {
|
|
14
|
+
selected: string[];
|
|
15
|
+
disabled: string[];
|
|
16
|
+
getSearchItemOrder: (model: TreeModel<A>) => number;
|
|
17
|
+
setInputValue: (newValue: string) => void;
|
|
18
|
+
handleChangeInput: (newValue: string) => void;
|
|
19
|
+
contentFilterQuery: string;
|
|
20
|
+
trlSelectParent: ReactNode;
|
|
21
|
+
} & Pick<TreeSelectorDummyProps<A>, "singleChoice" | "onChange" | "collection" | "leavesOnly" | "checkSelectable" | "renderItem" | "renderMobileDelimiter" | "onMobileNavigationChange"> & {
|
|
22
|
+
ref?: ForwardedRef<ListControls> | undefined;
|
|
23
|
+
}) => ReactElement;
|
|
24
|
+
export {};
|
package/MobileItemsList.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { forwardRef, useRef, useState, useMemo, useEffect, useImperativeHandle } from 'react';
|
|
3
|
+
import { forwardRef, useRef, useState, useMemo, useEffect, useImperativeHandle, Fragment as Fragment$1 } from 'react';
|
|
4
4
|
import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
|
|
5
5
|
import { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
6
6
|
import { Action } from './Action.js';
|
|
@@ -51,7 +51,7 @@ const MobileItemsListComponent = (props, ref) => {
|
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
53
|
}), [handleChangeInput, onMobileNavigationChange, setInputValue]);
|
|
54
|
-
return (jsxs(Fragment, { children: [isSelectable && (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: selected.includes(currentParentId), children: jsx(Cell, { Element: 'div', disabled: disabled.includes(currentParentId), right: jsx(Action, { selected: selected.includes(currentParentId), onChange: onChange, id: currentParentId, singleChoice: singleChoice }), children: jsx(CellText, { children: trlSelectParent }) }) })), sortedOrders.map((order) => {
|
|
54
|
+
return (jsxs(Fragment, { children: [isSelectable && (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: selected.includes(currentParentId), "data-qa": `tree-selector-select-all-${currentParentId}`, children: jsx(Cell, { Element: 'div', disabled: disabled.includes(currentParentId), right: jsx(Action, { selected: selected.includes(currentParentId), onChange: onChange, id: currentParentId, singleChoice: singleChoice }), children: jsx(CellText, { children: trlSelectParent }) }) })), sortedOrders.map((order) => {
|
|
55
55
|
return itemsByOrder[order].map((item, index) => {
|
|
56
56
|
const hasChildren = collection.hasChildren(item.id);
|
|
57
57
|
const hasLetter = item.additional?.char && !isSearch;
|
|
@@ -63,14 +63,14 @@ const MobileItemsListComponent = (props, ref) => {
|
|
|
63
63
|
isFirstInOrder: index === 0,
|
|
64
64
|
isTopLevel: !currentParentId,
|
|
65
65
|
});
|
|
66
|
-
return (jsxs(Fragment, { children: [hasLetter && jsx(MobileDelimiter, { children: item.additional?.char }), delimiterContent && jsx(MobileDelimiter, { children: delimiterContent }), hasChildren ? (jsx(MobileParentItem, { collection: collection, item: item, selected: selected, onClick: () => {
|
|
66
|
+
return (jsxs(Fragment$1, { children: [hasLetter && jsx(MobileDelimiter, { children: item.additional?.char }), delimiterContent && jsx(MobileDelimiter, { children: delimiterContent }), hasChildren ? (jsx(MobileParentItem, { collection: collection, item: item, selected: selected, onClick: () => {
|
|
67
67
|
prevParentIds.current.push(currentParentId);
|
|
68
68
|
prevQueries.current.push(currentQuery.current);
|
|
69
69
|
setCurrentParentId(item.id);
|
|
70
70
|
setInputValue('');
|
|
71
71
|
currentQuery.current = '';
|
|
72
72
|
onMobileNavigationChange?.(item.id);
|
|
73
|
-
}, isSearch: isSearch, renderItem: renderItem }
|
|
73
|
+
}, isSearch: isSearch, renderItem: renderItem })) : (jsx(MobileItem, { item: item, singleChoice: singleChoice, isSelectable: checkSelectable?.(item.id, collection), isSelected: selected.includes(item.id), isDisabled: disabled.includes(item.id), onChange: onChange, isSearch: isSearch, renderItem: renderItem }, item.id))] }, item.id));
|
|
74
74
|
});
|
|
75
75
|
})] }));
|
|
76
76
|
};
|
package/MobileItemsList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileItemsList.js","sources":["../src/MobileItemsList.tsx"],"sourcesContent":["import {\n ReactElement,\n useMemo,\n useState,\n useImperativeHandle,\n forwardRef,\n ForwardedRef,\n useRef,\n useEffect,\n ReactNode,\n} from 'react';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { MobileDelimiter } from '@hh.ru/magritte-ui-tree-selector/MobileDelimiter';\nimport { MobileItem } from '@hh.ru/magritte-ui-tree-selector/MobileItem';\nimport { MobileParentItem } from '@hh.ru/magritte-ui-tree-selector/MobileParentItem';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\ntype MobileItemsListProps<A extends AdditionalDefault> = {\n selected: string[];\n disabled: string[];\n getSearchItemOrder: (model: TreeModel<A>) => number;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n contentFilterQuery: string;\n trlSelectParent: ReactNode;\n} & Pick<\n TreeSelectorDummyProps<A>,\n | 'collection'\n | 'leavesOnly'\n | 'singleChoice'\n | 'checkSelectable'\n | 'onChange'\n | 'renderItem'\n | 'renderMobileDelimiter'\n | 'onMobileNavigationChange'\n>;\n\nconst MobileItemsListComponent = <A extends AdditionalDefault>(\n props: MobileItemsListProps<A>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n collection,\n selected,\n disabled,\n leavesOnly,\n singleChoice,\n onChange,\n checkSelectable,\n getSearchItemOrder,\n setInputValue,\n handleChangeInput,\n renderMobileDelimiter,\n renderItem,\n contentFilterQuery,\n trlSelectParent,\n onMobileNavigationChange,\n } = props;\n const prevParentIds = useRef<(string | undefined)[]>([]);\n const prevQueries = useRef<string[]>([]);\n const currentQuery = useRef(contentFilterQuery);\n const [currentParentId, setCurrentParentId] = useState<string | undefined>();\n const isSearch = !!contentFilterQuery;\n const items = useMemo(\n () => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()),\n [currentParentId, collection]\n );\n const { itemsByOrder, sortedOrders } = useMemo(() => {\n const orders = new Set<number>();\n const itemsByOrder = items.reduce<Record<number, TreeModel<A>[]>>((acc, item) => {\n const modelOrder = isSearch && !currentParentId ? getSearchItemOrder(item) : 0;\n orders.add(modelOrder);\n acc[modelOrder] = acc[modelOrder] || [];\n acc[modelOrder].push(item);\n return acc;\n }, {});\n return { itemsByOrder, sortedOrders: [...orders].sort((a, b) => a - b) };\n }, [items, isSearch, currentParentId, getSearchItemOrder]);\n\n const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);\n\n useEffect(() => {\n setCurrentParentId(undefined);\n prevParentIds.current = [];\n prevQueries.current = [];\n currentQuery.current = contentFilterQuery;\n }, [contentFilterQuery]);\n\n useImperativeHandle(\n ref,\n () => ({\n back: () => {\n const prevParentId = prevParentIds.current.pop();\n setCurrentParentId(prevParentId);\n onMobileNavigationChange?.(prevParentId);\n if (prevQueries.current.length) {\n setInputValue(prevQueries.current.pop() as string);\n } else {\n handleChangeInput('');\n }\n },\n }),\n [handleChangeInput, onMobileNavigationChange, setInputValue]\n );\n return (\n <>\n {isSelectable && (\n <CheckableCardElement\n padding={16}\n borderRadius={12}\n Element=\"label\"\n checked={selected.includes(currentParentId)}\n >\n <Cell\n Element={'div'}\n disabled={disabled.includes(currentParentId)}\n right={\n <Action\n selected={selected.includes(currentParentId)}\n onChange={onChange}\n id={currentParentId}\n singleChoice={singleChoice}\n />\n }\n >\n <CellText>{trlSelectParent}</CellText>\n </Cell>\n </CheckableCardElement>\n )}\n {sortedOrders.map((order) => {\n return itemsByOrder[order].map((item, index) => {\n const hasChildren = collection.hasChildren(item.id);\n const hasLetter = item.additional?.char && !isSearch;\n const delimiterContent = renderMobileDelimiter?.({\n item,\n order,\n isSearch,\n index,\n isFirstInOrder: index === 0,\n isTopLevel: !currentParentId,\n });\n return (\n <>\n {hasLetter && <MobileDelimiter>{item.additional?.char}</MobileDelimiter>}\n {delimiterContent && <MobileDelimiter>{delimiterContent}</MobileDelimiter>}\n {hasChildren ? (\n <MobileParentItem\n key={item.id}\n collection={collection}\n item={item}\n selected={selected}\n onClick={() => {\n prevParentIds.current.push(currentParentId);\n prevQueries.current.push(currentQuery.current);\n setCurrentParentId(item.id);\n setInputValue('');\n currentQuery.current = '';\n onMobileNavigationChange?.(item.id);\n }}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n ) : (\n <MobileItem\n key={item.id}\n item={item}\n singleChoice={singleChoice}\n isSelectable={checkSelectable?.(item.id, collection)}\n isSelected={selected.includes(item.id)}\n isDisabled={disabled.includes(item.id)}\n onChange={onChange}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n )}\n </>\n );\n });\n })}\n </>\n );\n};\n\nexport const MobileItemsList = forwardRef(MobileItemsListComponent);\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;;AAyCA,MAAM,wBAAwB,GAAG,CAC7B,KAA8B,EAC9B,GAA+B,KACjB;AACd,IAAA,MAAM,EACF,UAAU,EACV,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,wBAAwB,GAC3B,GAAG,KAAK,CAAC;AACV,IAAA,MAAM,aAAa,GAAG,MAAM,CAAyB,EAAE,CAAC,CAAC;AACzD,IAAA,MAAM,WAAW,GAAG,MAAM,CAAW,EAAE,CAAC,CAAC;AACzC,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAChD,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,EAAsB,CAAC;AAC7E,IAAA,MAAM,QAAQ,GAAG,CAAC,CAAC,kBAAkB,CAAC;AACtC,IAAA,MAAM,KAAK,GAAG,OAAO,CACjB,OAAO,eAAe,GAAG,UAAU,CAAC,WAAW,CAAC,eAAe,CAAC,GAAG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AI,EACV,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,eAAe,GAAG,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,EACpD,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EACtC,UAAU,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,EACtC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EAAA,EARjB,IAAI,CAAC,EAAE,CASd,CACL,CAAA,EAAA,CACF,EACL;AACN,iBAAC,CAAC,CAAC;aACN,CAAC,CACH,EAAA,CAAA,EACL;AACN,CAAC,CAAC;MAEW,eAAe,GAAG,UAAU,CAAC,wBAAwB;;;;"}
|
|
1
|
+
{"version":3,"file":"MobileItemsList.js","sources":["../src/MobileItemsList.tsx"],"sourcesContent":["import {\n ReactElement,\n Fragment,\n useMemo,\n useState,\n useImperativeHandle,\n forwardRef,\n ForwardedRef,\n useRef,\n useEffect,\n ReactNode,\n} from 'react';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { MobileDelimiter } from '@hh.ru/magritte-ui-tree-selector/MobileDelimiter';\nimport { MobileItem } from '@hh.ru/magritte-ui-tree-selector/MobileItem';\nimport { MobileParentItem } from '@hh.ru/magritte-ui-tree-selector/MobileParentItem';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\ntype MobileItemsListProps<A extends AdditionalDefault> = {\n selected: string[];\n disabled: string[];\n getSearchItemOrder: (model: TreeModel<A>) => number;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n contentFilterQuery: string;\n trlSelectParent: ReactNode;\n} & Pick<\n TreeSelectorDummyProps<A>,\n | 'collection'\n | 'leavesOnly'\n | 'singleChoice'\n | 'checkSelectable'\n | 'onChange'\n | 'renderItem'\n | 'renderMobileDelimiter'\n | 'onMobileNavigationChange'\n>;\n\nconst MobileItemsListComponent = <A extends AdditionalDefault>(\n props: MobileItemsListProps<A>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n collection,\n selected,\n disabled,\n leavesOnly,\n singleChoice,\n onChange,\n checkSelectable,\n getSearchItemOrder,\n setInputValue,\n handleChangeInput,\n renderMobileDelimiter,\n renderItem,\n contentFilterQuery,\n trlSelectParent,\n onMobileNavigationChange,\n } = props;\n const prevParentIds = useRef<(string | undefined)[]>([]);\n const prevQueries = useRef<string[]>([]);\n const currentQuery = useRef(contentFilterQuery);\n const [currentParentId, setCurrentParentId] = useState<string | undefined>();\n const isSearch = !!contentFilterQuery;\n const items = useMemo(\n () => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()),\n [currentParentId, collection]\n );\n const { itemsByOrder, sortedOrders } = useMemo(() => {\n const orders = new Set<number>();\n const itemsByOrder = items.reduce<Record<number, TreeModel<A>[]>>((acc, item) => {\n const modelOrder = isSearch && !currentParentId ? getSearchItemOrder(item) : 0;\n orders.add(modelOrder);\n acc[modelOrder] = acc[modelOrder] || [];\n acc[modelOrder].push(item);\n return acc;\n }, {});\n return { itemsByOrder, sortedOrders: [...orders].sort((a, b) => a - b) };\n }, [items, isSearch, currentParentId, getSearchItemOrder]);\n\n const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);\n\n useEffect(() => {\n setCurrentParentId(undefined);\n prevParentIds.current = [];\n prevQueries.current = [];\n currentQuery.current = contentFilterQuery;\n }, [contentFilterQuery]);\n\n useImperativeHandle(\n ref,\n () => ({\n back: () => {\n const prevParentId = prevParentIds.current.pop();\n setCurrentParentId(prevParentId);\n onMobileNavigationChange?.(prevParentId);\n if (prevQueries.current.length) {\n setInputValue(prevQueries.current.pop() as string);\n } else {\n handleChangeInput('');\n }\n },\n }),\n [handleChangeInput, onMobileNavigationChange, setInputValue]\n );\n return (\n <>\n {isSelectable && (\n <CheckableCardElement\n padding={16}\n borderRadius={12}\n Element=\"label\"\n checked={selected.includes(currentParentId)}\n data-qa={`tree-selector-select-all-${currentParentId}`}\n >\n <Cell\n Element={'div'}\n disabled={disabled.includes(currentParentId)}\n right={\n <Action\n selected={selected.includes(currentParentId)}\n onChange={onChange}\n id={currentParentId}\n singleChoice={singleChoice}\n />\n }\n >\n <CellText>{trlSelectParent}</CellText>\n </Cell>\n </CheckableCardElement>\n )}\n {sortedOrders.map((order) => {\n return itemsByOrder[order].map((item, index) => {\n const hasChildren = collection.hasChildren(item.id);\n const hasLetter = item.additional?.char && !isSearch;\n const delimiterContent = renderMobileDelimiter?.({\n item,\n order,\n isSearch,\n index,\n isFirstInOrder: index === 0,\n isTopLevel: !currentParentId,\n });\n return (\n <Fragment key={item.id}>\n {hasLetter && <MobileDelimiter>{item.additional?.char}</MobileDelimiter>}\n {delimiterContent && <MobileDelimiter>{delimiterContent}</MobileDelimiter>}\n {hasChildren ? (\n <MobileParentItem\n collection={collection}\n item={item}\n selected={selected}\n onClick={() => {\n prevParentIds.current.push(currentParentId);\n prevQueries.current.push(currentQuery.current);\n setCurrentParentId(item.id);\n setInputValue('');\n currentQuery.current = '';\n onMobileNavigationChange?.(item.id);\n }}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n ) : (\n <MobileItem\n key={item.id}\n item={item}\n singleChoice={singleChoice}\n isSelectable={checkSelectable?.(item.id, collection)}\n isSelected={selected.includes(item.id)}\n isDisabled={disabled.includes(item.id)}\n onChange={onChange}\n isSearch={isSearch}\n renderItem={renderItem}\n />\n )}\n </Fragment>\n );\n });\n })}\n </>\n );\n};\n\nexport const MobileItemsList = forwardRef(MobileItemsListComponent) as <A extends AdditionalDefault>(\n props: MobileItemsListProps<A> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":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,UAAU,CAAC,wBAAwB;;;;"}
|
package/MobileParentItem.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import TreeCollection from '
|
|
3
|
-
import { AdditionalDefault, TreeModel } from '
|
|
4
|
-
import { RenderItem } from '
|
|
2
|
+
import TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';
|
|
3
|
+
import { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
4
|
+
import { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
5
5
|
interface MobileParentItemProps<A extends AdditionalDefault> {
|
|
6
6
|
collection: TreeCollection<A>;
|
|
7
7
|
item: TreeModel<A>;
|
|
8
8
|
selected: string[];
|
|
9
9
|
onClick: () => void;
|
|
10
|
-
renderItem?: RenderItem
|
|
10
|
+
renderItem?: RenderItem<A>;
|
|
11
11
|
isSearch: boolean;
|
|
12
12
|
}
|
|
13
13
|
export declare const MobileParentItem: <A extends AdditionalDefault>({ collection, item, selected, onClick, isSearch, renderItem, }: MobileParentItemProps<A>) => ReactElement;
|
package/MobileParentItem.js
CHANGED
|
@@ -16,7 +16,7 @@ const MobileParentItem = ({ collection, item, selected, onClick, isSearch, rende
|
|
|
16
16
|
return count;
|
|
17
17
|
}, [collection, selected, item.id]);
|
|
18
18
|
const labelRight = jsx(LabelRight, { badge: childrenSelectedCount ? childrenSelectedCount.toString() : undefined });
|
|
19
|
-
return (jsx(Card, { padding: 16, borderRadius: 12, showBorder: true, actionCard: true, onClick: onClick, children: renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true }) }));
|
|
19
|
+
return (jsx(Card, { padding: 16, borderRadius: 12, showBorder: true, actionCard: true, onClick: onClick, "data-qa": `tree-selector-item-${item.id}`, children: renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true }) }));
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export { MobileParentItem };
|
package/MobileParentItem.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MobileParentItem.js","sources":["../src/MobileParentItem.tsx"],"sourcesContent":["import { ReactElement, useMemo } from 'react';\n\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { LabelRight } from '@hh.ru/magritte-ui-cell';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileParentItemProps<A extends AdditionalDefault> {\n collection: TreeCollection<A>;\n item: TreeModel<A>;\n selected: string[];\n onClick: () => void;\n renderItem?: RenderItem
|
|
1
|
+
{"version":3,"file":"MobileParentItem.js","sources":["../src/MobileParentItem.tsx"],"sourcesContent":["import { ReactElement, useMemo } from 'react';\n\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { LabelRight } from '@hh.ru/magritte-ui-cell';\nimport { TreeSelectorItemBase } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorItemBase';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItem } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileParentItemProps<A extends AdditionalDefault> {\n collection: TreeCollection<A>;\n item: TreeModel<A>;\n selected: string[];\n onClick: () => void;\n renderItem?: RenderItem<A>;\n isSearch: boolean;\n}\n\nexport const MobileParentItem = <A extends AdditionalDefault>({\n collection,\n item,\n selected,\n onClick,\n isSearch,\n renderItem = TreeSelectorItemBase,\n}: MobileParentItemProps<A>): ReactElement => {\n const childrenSelectedCount = useMemo(() => {\n let count = 0;\n collection.walkChildren(item.id, (model) => {\n if (selected.includes(model.id)) {\n count += 1;\n }\n });\n\n return count;\n }, [collection, selected, item.id]);\n\n const labelRight = <LabelRight badge={childrenSelectedCount ? childrenSelectedCount.toString() : undefined} />;\n\n return (\n <Card\n padding={16}\n borderRadius={12}\n showBorder\n actionCard\n onClick={onClick}\n data-qa={`tree-selector-item-${item.id}`}\n >\n {renderItem({ item, labelRight, childrenSelectedCount, isSearch, isXS: true, isParent: true })}\n </Card>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;MAkBa,gBAAgB,GAAG,CAA8B,EAC1D,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,UAAU,GAAG,oBAAoB,GACV,KAAkB;AACzC,IAAA,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAK;QACvC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,KAAI;YACvC,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;gBAC7B,KAAK,IAAI,CAAC,CAAC;AACd,aAAA;AACL,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,KAAK,CAAC;KAChB,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAGA,GAAC,CAAA,UAAU,IAAC,KAAK,EAAE,qBAAqB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,GAAG,SAAS,GAAI,CAAC;IAE/G,QACIA,IAAC,IAAI,EAAA,EACD,OAAO,EAAE,EAAE,EACX,YAAY,EAAE,EAAE,EAChB,UAAU,EAAA,IAAA,EACV,UAAU,EACV,IAAA,EAAA,OAAO,EAAE,OAAO,EAAA,SAAA,EACP,CAAsB,mBAAA,EAAA,IAAI,CAAC,EAAE,EAAE,EAEvC,QAAA,EAAA,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,qBAAqB,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAC3F,CAAA,EACT;AACN;;;;"}
|
package/TreeSelector.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import { AdditionalDefault } from '
|
|
3
|
-
import { ListControls } from '
|
|
4
|
-
export declare const TreeSelector: import("
|
|
1
|
+
import { ForwardedRef, ReactElement } from 'react';
|
|
2
|
+
import { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';
|
|
3
|
+
import { TreeSelectorProps, ListControls } from '@hh.ru/magritte-ui-tree-selector/types';
|
|
4
|
+
export declare const TreeSelector: <A extends AdditionalDefault>(props: import("@hh.ru/magritte-ui-tree-selector/types").BaseTreeSelectorProps<A> & {
|
|
5
5
|
onChange: (allSelected: string[], id: string, isSelected: boolean) => void;
|
|
6
6
|
collapseToParentId?: boolean | undefined;
|
|
7
7
|
maxSelected?: number | undefined;
|
|
8
|
-
} &
|
|
8
|
+
} & {
|
|
9
|
+
ref?: ForwardedRef<ListControls> | undefined;
|
|
10
|
+
}) => ReactElement;
|
package/TreeSelector.js
CHANGED
|
@@ -12,7 +12,8 @@ import './ItemsList.js';
|
|
|
12
12
|
import './Item.js';
|
|
13
13
|
import 'react-transition-group';
|
|
14
14
|
import 'classnames';
|
|
15
|
-
import './ItemContent-
|
|
15
|
+
import './ItemContent-B8bmjnfm.js';
|
|
16
|
+
import '@hh.ru/magritte-common-keyboard';
|
|
16
17
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
17
18
|
import './Action.js';
|
|
18
19
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
package/TreeSelector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeSelector.js","sources":["../src/TreeSelector.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, ReactElement, useMemo } from 'react';\n\nimport { TreeSelectorDummy } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorDummy';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { TreeSelectorProps, ListControls } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useDisabled } from '@hh.ru/magritte-ui-tree-selector/useDisabled';\nimport { useSelected } from '@hh.ru/magritte-ui-tree-selector/useSelected';\n\nconst TreeSelectorComponent = <A extends AdditionalDefault>(\n props: TreeSelectorProps<A>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n value,\n collection,\n singleChoice,\n leavesOnly,\n collapseToParentId,\n checkSelectable,\n onChange,\n disabled,\n maxSelected,\n ...rest\n } = props;\n const strategy = useMemo(\n () =>\n new ImmutableSelectionStrategy(collection, {\n singleChoice,\n leavesOnly,\n checkSelectable,\n }),\n [collection, singleChoice, leavesOnly, checkSelectable]\n );\n\n if (maxSelected && !collapseToParentId && !leavesOnly) {\n throw new Error(\n `Magritte component TreeSelector: maxSelected can be used only with collapseToParentId or leavesOnly`\n );\n }\n\n const { selected, setSelected } = useSelected({\n value,\n strategy,\n collection,\n onChange,\n maxSelected,\n collapseToParentId,\n });\n\n const currentDisabled = useDisabled({ selected, disabled, collection, maxSelected });\n\n return (\n <TreeSelectorDummy\n {...rest}\n value={selected}\n disabled={currentDisabled}\n collection={collection}\n singleChoice={singleChoice}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n onChange={setSelected}\n ref={ref}\n />\n );\n};\n\nexport const TreeSelector = forwardRef(TreeSelectorComponent);\n"],"names":["_jsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"TreeSelector.js","sources":["../src/TreeSelector.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, ReactElement, useMemo } from 'react';\n\nimport { TreeSelectorDummy } from '@hh.ru/magritte-ui-tree-selector/TreeSelectorDummy';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { TreeSelectorProps, ListControls } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useDisabled } from '@hh.ru/magritte-ui-tree-selector/useDisabled';\nimport { useSelected } from '@hh.ru/magritte-ui-tree-selector/useSelected';\n\nconst TreeSelectorComponent = <A extends AdditionalDefault>(\n props: TreeSelectorProps<A>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const {\n value,\n collection,\n singleChoice,\n leavesOnly,\n collapseToParentId,\n checkSelectable,\n onChange,\n disabled,\n maxSelected,\n ...rest\n } = props;\n const strategy = useMemo(\n () =>\n new ImmutableSelectionStrategy(collection, {\n singleChoice,\n leavesOnly,\n checkSelectable,\n }),\n [collection, singleChoice, leavesOnly, checkSelectable]\n );\n\n if (maxSelected && !collapseToParentId && !leavesOnly) {\n throw new Error(\n `Magritte component TreeSelector: maxSelected can be used only with collapseToParentId or leavesOnly`\n );\n }\n\n const { selected, setSelected } = useSelected({\n value,\n strategy,\n collection,\n onChange,\n maxSelected,\n collapseToParentId,\n });\n\n const currentDisabled = useDisabled({ selected, disabled, collection, maxSelected });\n\n return (\n <TreeSelectorDummy\n {...rest}\n value={selected}\n disabled={currentDisabled}\n collection={collection}\n singleChoice={singleChoice}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n onChange={setSelected}\n ref={ref}\n />\n );\n};\n\nexport const TreeSelector = forwardRef(TreeSelectorComponent) as <A extends AdditionalDefault>(\n props: TreeSelectorProps<A> & { ref?: ForwardedRef<ListControls> }\n) => ReactElement;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,qBAAqB,GAAG,CAC1B,KAA2B,EAC3B,GAA+B,KACjB;IACd,MAAM,EACF,KAAK,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,QAA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