@hh.ru/magritte-ui-tree-selector 1.5.1 → 1.6.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.js +4 -3
- package/Action.js.map +1 -1
- package/Item.d.ts +2 -1
- package/Item.js +32 -4
- package/Item.js.map +1 -1
- package/ItemContent-36f7db0a.js +24 -0
- package/ItemContent-36f7db0a.js.map +1 -0
- package/ItemContent.d.ts +2 -2
- package/ItemContent.js +1 -1
- package/ItemsList.d.ts +1 -0
- package/ItemsList.js +4 -3
- package/ItemsList.js.map +1 -1
- package/MobileItemsList.d.ts +5 -15
- package/MobileItemsList.js +6 -3
- package/MobileItemsList.js.map +1 -1
- package/TreeSelector.d.ts +6 -2
- package/TreeSelector.js +5 -3
- package/TreeSelector.js.map +1 -1
- package/TreeSelectorDummy.js +15 -7
- package/TreeSelectorDummy.js.map +1 -1
- package/TreeSelectorItemBase.js +1 -1
- package/TreeSelectorItemBase.js.map +1 -1
- package/index.css +71 -11
- package/index.js +4 -1
- package/index.js.map +1 -1
- package/package.json +6 -3
- package/types.d.ts +5 -9
- package/useAnimationTimeout.d.ts +7 -0
- package/useAnimationTimeout.js +23 -0
- package/useAnimationTimeout.js.map +1 -0
- package/useDisabled.d.ts +3 -6
- package/useDisabled.js.map +1 -1
- package/useRenderInput.js +8 -2
- package/useRenderInput.js.map +1 -1
- package/useSelected.d.ts +3 -9
- package/useSelected.js +11 -19
- package/useSelected.js.map +1 -1
- package/ItemContent-cec51c98.js +0 -23
- package/ItemContent-cec51c98.js.map +0 -1
package/Action.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useCallback } from 'react';
|
|
3
|
+
import { memo, useCallback } from 'react';
|
|
4
4
|
import { Radio, Checkbox } from '@hh.ru/magritte-ui-checkbox-radio';
|
|
5
5
|
|
|
6
|
-
const Action = ({ id, singleChoice, indeterminate, selected, onChange }) => {
|
|
6
|
+
const Action = memo(({ id, singleChoice, indeterminate, selected, onChange }) => {
|
|
7
7
|
const handleChange = useCallback((event) => {
|
|
8
8
|
onChange(id, event.target.checked);
|
|
9
9
|
}, [id, onChange]);
|
|
@@ -12,7 +12,8 @@ const Action = ({ id, singleChoice, indeterminate, selected, onChange }) => {
|
|
|
12
12
|
onChange: handleChange,
|
|
13
13
|
};
|
|
14
14
|
return singleChoice ? jsx(Radio, { ...inputProps }) : jsx(Checkbox, { ...inputProps, indeterminate: indeterminate });
|
|
15
|
-
};
|
|
15
|
+
});
|
|
16
|
+
Action.displayName = 'TreeSelectorAction';
|
|
16
17
|
|
|
17
18
|
export { Action };
|
|
18
19
|
//# sourceMappingURL=Action.js.map
|
package/Action.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Action.js","sources":["../src/Action.tsx"],"sourcesContent":["import { ChangeEventHandler, FC, useCallback } 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> = ({ id, singleChoice, indeterminate, selected, onChange }) => {\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 };\n\n return singleChoice ? <Radio {...inputProps} /> : <Checkbox {...inputProps} indeterminate={indeterminate} />;\n};\n"],"names":["_jsx"],"mappings":";;;;AAaa,MAAA,MAAM,GAAoB,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAI;
|
|
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 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 };\n\n return singleChoice ? <Radio {...inputProps} /> : <Checkbox {...inputProps} indeterminate={indeterminate} />;\n});\n\nAction.displayName = 'TreeSelectorAction';\n"],"names":["_jsx"],"mappings":";;;;AAaa,MAAA,MAAM,GAAoB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAI;AACpG,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;KACzB,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,EAAE;AAEH,MAAM,CAAC,WAAW,GAAG,oBAAoB;;;;"}
|
package/Item.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ interface ItemProps<A extends AdditionalDefault> extends PropsWithChildren {
|
|
|
17
17
|
onExpansion: (id: string) => void;
|
|
18
18
|
onChange: (id: string, isSelected: boolean) => void;
|
|
19
19
|
renderItemForDesktop?: RenderItem;
|
|
20
|
+
animationTimeout: number;
|
|
20
21
|
}
|
|
21
|
-
export declare const Item: <A extends AdditionalDefault>({ collection, item, parentId, isExpanded, isSelected, isIndeterminate, isDisabled, leavesOnly, singleChoice, isSearch, checkSelectable, onExpansion, onChange, renderItemForDesktop, children, }: ItemProps<A>) => ReactElement
|
|
22
|
+
export declare const Item: import("react").MemoExoticComponent<(<A extends AdditionalDefault>({ collection, item, parentId, isExpanded, isSelected, isIndeterminate, isDisabled, leavesOnly, singleChoice, isSearch, checkSelectable, onExpansion, onChange, renderItemForDesktop, animationTimeout, children, }: ItemProps<A>) => ReactElement)>;
|
|
22
23
|
export {};
|
package/Item.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useMemo } from 'react';
|
|
3
|
+
import { memo, useMemo, useRef, Children } from 'react';
|
|
4
|
+
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
4
5
|
import classnames from 'classnames';
|
|
5
|
-
import { s as styles, I as ItemContent } from './ItemContent-
|
|
6
|
+
import { s as styles, I as ItemContent } from './ItemContent-36f7db0a.js';
|
|
6
7
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
7
8
|
import './Action.js';
|
|
8
9
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
@@ -10,7 +11,7 @@ import './TreeSelectorItemBase.js';
|
|
|
10
11
|
import '@hh.ru/magritte-ui-cell';
|
|
11
12
|
import '@hh.ru/magritte-ui-typography';
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
+
const ItemComponent = ({ collection, item, parentId, isExpanded, isSelected, isIndeterminate, isDisabled, leavesOnly, singleChoice, isSearch, checkSelectable, onExpansion, onChange, renderItemForDesktop, animationTimeout, children, }) => {
|
|
14
15
|
const modelsOnLevel = useMemo(() => (parentId ? collection.getChildren(parentId) : collection.getTopLevel()), [parentId, collection]);
|
|
15
16
|
const hasLetterOnLevel = useMemo(() => {
|
|
16
17
|
return !isSearch && modelsOnLevel.some((model) => model.additional?.char);
|
|
@@ -34,13 +35,40 @@ const Item = ({ collection, item, parentId, isExpanded, isSelected, isIndetermin
|
|
|
34
35
|
const allBoxesCount = +hasLetterOnLevel + maxControlsOnLevel;
|
|
35
36
|
const hasShift = allBoxesCount > 1 &&
|
|
36
37
|
((hasParentAction && (hasLetterOnLevel || hasChildren || hasDot)) || (!hasParentAction && hasLetterOnLevel));
|
|
38
|
+
const childrenContentRef = useRef(null);
|
|
39
|
+
const handleEnter = () => {
|
|
40
|
+
if (childrenContentRef.current) {
|
|
41
|
+
childrenContentRef.current.style.height = '0';
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const handleEntering = () => {
|
|
45
|
+
if (childrenContentRef.current) {
|
|
46
|
+
childrenContentRef.current.style.height = `${childrenContentRef.current.scrollHeight}px`;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const handleEntered = () => {
|
|
50
|
+
if (childrenContentRef.current) {
|
|
51
|
+
childrenContentRef.current.style.height = `auto`;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const handleExit = () => {
|
|
55
|
+
if (childrenContentRef.current) {
|
|
56
|
+
childrenContentRef.current.style.height = `${childrenContentRef.current.scrollHeight}px`;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const handleExiting = () => {
|
|
60
|
+
if (childrenContentRef.current) {
|
|
61
|
+
childrenContentRef.current.style.height = '0';
|
|
62
|
+
}
|
|
63
|
+
};
|
|
37
64
|
return (jsxs("div", { className: classnames(styles.item, {
|
|
38
65
|
[styles.withTwoBoxes]: allBoxesCount === 2,
|
|
39
66
|
[styles.withThreeBoxes]: allBoxesCount === 3,
|
|
40
67
|
[styles.withShift]: hasShift && parentId,
|
|
41
68
|
[styles.withIndent]: allBoxesCount === 0,
|
|
42
|
-
}), 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 }), children
|
|
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, children: jsx("div", { ref: childrenContentRef, className: styles.children, children: child }) }, index))) })] }));
|
|
43
70
|
};
|
|
71
|
+
const Item = memo(ItemComponent);
|
|
44
72
|
|
|
45
73
|
export { Item };
|
|
46
74
|
//# sourceMappingURL=Item.js.map
|
package/Item.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.js","sources":["../src/Item.tsx"],"sourcesContent":["import { PropsWithChildren, ReactElement, useMemo } from 'react';\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}\n\nexport const Item = <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 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 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 {children && <div className={styles.children}>{children}</div>}\n </div>\n );\n};\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;AA2Ba,MAAA,IAAI,GAAG,CAA8B,EAC9C,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,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,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,EAAA,CAAO,CAC5D,EAAA,CAAA,EACR;AACN;;;;"}
|
|
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,kBAA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,CAAA,EAAA,CAChB,EACR;AACN,CAAC,CAAC;MAEW,IAAI,GAAG,IAAI,CAAC,aAAa;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { DotFilledSize24, ChevronUpOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
6
|
+
import { Action } from './Action.js';
|
|
7
|
+
import { TreeSelectorItemBase } from './TreeSelectorItemBase.js';
|
|
8
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
9
|
+
|
|
10
|
+
var styles = {"item-animation-timeout":"magritte-item-animation-timeout___pbOyZ_1-6-0","itemAnimationTimeout":"magritte-item-animation-timeout___pbOyZ_1-6-0","wrapper":"magritte-wrapper___GHKV6_1-6-0","letter":"magritte-letter___yZOCU_1-6-0","icon":"magritte-icon___kO3Fj_1-6-0","space":"magritte-space___xTO79_1-6-0","iconActive":"magritte-iconActive___4yrG5_1-6-0","iconUp":"magritte-iconUp___mpXV6_1-6-0","content":"magritte-content___ZRc6R_1-6-0","with-shift":"magritte-with-shift___ZErxZ_1-6-0","withShift":"magritte-with-shift___ZErxZ_1-6-0","with-indent":"magritte-with-indent___MH9Vy_1-6-0","withIndent":"magritte-with-indent___MH9Vy_1-6-0","item":"magritte-item___2LtOL_1-6-0","children":"magritte-children___kq-eq_1-6-0","with-two-boxes":"magritte-with-two-boxes___LWOy2_1-6-0","withTwoBoxes":"magritte-with-two-boxes___LWOy2_1-6-0","with-three-boxes":"magritte-with-three-boxes___cyVao_1-6-0","withThreeBoxes":"magritte-with-three-boxes___cyVao_1-6-0"};
|
|
11
|
+
|
|
12
|
+
const ItemContentComponent = ({ item, hasAction, hasChildren, letter, isExpanded, isDisabled, onExpansion, hasLetterOnLevel, isSelected, onChange, isIndeterminate, singleChoice, hasDot, maxControlsOnLevel, isSearch, renderItemForDesktop = TreeSelectorItemBase, }) => {
|
|
13
|
+
const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);
|
|
14
|
+
const currentActionCount = +hasDot + +hasAction + +hasChildren;
|
|
15
|
+
const neededSpacesCount = maxControlsOnLevel - currentActionCount;
|
|
16
|
+
const input = hasAction ? (jsx(Action, { selected: isSelected, onChange: onChange, id: item.id, indeterminate: isIndeterminate, singleChoice: singleChoice })) : undefined;
|
|
17
|
+
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, {
|
|
18
|
+
[styles.iconUp]: isExpanded,
|
|
19
|
+
}), onClick: handleExpandableClick, children: jsx(ChevronUpOutlinedSize24, { initial: "tertiary" }) })), renderItemForDesktop({ disabled: isDisabled, input, item, isSearch, isParent: hasChildren })] }));
|
|
20
|
+
};
|
|
21
|
+
const ItemContent = memo(ItemContentComponent);
|
|
22
|
+
|
|
23
|
+
export { ItemContent as I, styles as s };
|
|
24
|
+
//# sourceMappingURL=ItemContent-36f7db0a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemContent-36f7db0a.js","sources":["../src/ItemContent.tsx"],"sourcesContent":["import { ReactElement, useCallback, memo } from 'react';\nimport classnames from 'classnames';\n\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 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;\n isSearch: boolean;\n}\n\nconst ItemContentComponent = <A extends AdditionalDefault>({\n item,\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 input = hasAction ? (\n <Action\n selected={isSelected}\n onChange={onChange}\n id={item.id}\n indeterminate={isIndeterminate}\n singleChoice={singleChoice}\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 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);\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;AA+BA,MAAM,oBAAoB,GAAG,CAA8B,EACvD,IAAI,EACJ,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,KAAK,GAAG,SAAS,IACnBA,GAAA,CAAC,MAAM,EAAA,EACH,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,IAAI,CAAC,EAAE,EACX,aAAa,EAAE,eAAe,EAC9B,YAAY,EAAE,YAAY,EAC5B,CAAA,IACF,SAAS,CAAC;IAEd,QACIC,IAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,OAAO,EAAA,QAAA,EAAA,CACzB,CAAC,MAAM,IAAI,gBAAgB,MACxBD,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,MAAM,EACxB,QAAA,EAAA,MAAM,KACHA,GAAC,CAAA,IAAI,IAAC,UAAU,EAAC,qBAAqB,EAAC,KAAK,EAAC,WAAW,EAAC,OAAO,EAAC,MAAM,EAAA,QAAA,EAClE,MAAM,EAAA,CACJ,CACV,EACC,CAAA,CACT,EACA,MAAM,KACHA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,IAAI,EACvB,QAAA,EAAAA,GAAA,CAAC,eAAe,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,EACF,OAAO,EAAE,qBAAqB,YAE9BA,GAAC,CAAA,uBAAuB,EAAC,EAAA,OAAO,EAAC,UAAU,EAAA,CAAG,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
|
@@ -19,5 +19,5 @@ interface ItemContent<A extends AdditionalDefault> {
|
|
|
19
19
|
renderItemForDesktop?: RenderItem;
|
|
20
20
|
isSearch: boolean;
|
|
21
21
|
}
|
|
22
|
-
declare const ItemContent: <A extends AdditionalDefault>({ item, hasAction, hasChildren, letter, isExpanded, isDisabled, onExpansion, hasLetterOnLevel, isSelected, onChange, isIndeterminate, singleChoice, hasDot, maxControlsOnLevel, isSearch, renderItemForDesktop, }: ItemContent<A>) => ReactElement
|
|
23
|
-
export {
|
|
22
|
+
export declare const ItemContent: import("react").MemoExoticComponent<(<A extends AdditionalDefault>({ item, hasAction, hasChildren, letter, isExpanded, isDisabled, onExpansion, hasLetterOnLevel, isSelected, onChange, isIndeterminate, singleChoice, hasDot, maxControlsOnLevel, isSearch, renderItemForDesktop, }: ItemContent<A>) => ReactElement)>;
|
|
23
|
+
export {};
|
package/ItemContent.js
CHANGED
|
@@ -6,7 +6,7 @@ import '@hh.ru/magritte-ui-icon/icon';
|
|
|
6
6
|
import './Action.js';
|
|
7
7
|
import './TreeSelectorItemBase.js';
|
|
8
8
|
import '@hh.ru/magritte-ui-typography';
|
|
9
|
-
export { I as ItemContent } from './ItemContent-
|
|
9
|
+
export { I as ItemContent } from './ItemContent-36f7db0a.js';
|
|
10
10
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
11
11
|
import '@hh.ru/magritte-ui-cell';
|
|
12
12
|
//# sourceMappingURL=ItemContent.js.map
|
package/ItemsList.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ interface ItemsListProps<A extends AdditionalDefault> {
|
|
|
17
17
|
singleChoice?: boolean;
|
|
18
18
|
isSearch: boolean;
|
|
19
19
|
renderItemForDesktop?: RenderItem;
|
|
20
|
+
animationTimeout: number;
|
|
20
21
|
}
|
|
21
22
|
export declare const ItemsList: <A extends AdditionalDefault>(props: ItemsListProps<A>) => ReactElement;
|
|
22
23
|
export {};
|
package/ItemsList.js
CHANGED
|
@@ -2,8 +2,9 @@ import './index.css';
|
|
|
2
2
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { Item } from './Item.js';
|
|
4
4
|
import 'react';
|
|
5
|
+
import 'react-transition-group';
|
|
5
6
|
import 'classnames';
|
|
6
|
-
import './ItemContent-
|
|
7
|
+
import './ItemContent-36f7db0a.js';
|
|
7
8
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
8
9
|
import './Action.js';
|
|
9
10
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
@@ -12,11 +13,11 @@ import '@hh.ru/magritte-ui-cell';
|
|
|
12
13
|
import '@hh.ru/magritte-ui-typography';
|
|
13
14
|
|
|
14
15
|
const ItemsList = (props) => {
|
|
15
|
-
const { items, collection, leavesOnly, checkSelectable, selected, parentId, expanded, disabled, onExpansion, indeterminate, onChange, isSearch, singleChoice, renderItemForDesktop, } = props;
|
|
16
|
+
const { items, collection, leavesOnly, checkSelectable, selected, parentId, expanded, disabled, onExpansion, indeterminate, onChange, isSearch, singleChoice, renderItemForDesktop, animationTimeout, } = props;
|
|
16
17
|
return (jsx(Fragment, { children: items.map((item) => {
|
|
17
18
|
const isExpanded = expanded.includes(item.id);
|
|
18
19
|
const hasChildren = collection.hasChildren(item.id);
|
|
19
|
-
return (jsx(Item, { collection: collection, checkSelectable: checkSelectable, isSelected: selected.includes(item.id), isExpanded: isExpanded, isIndeterminate: indeterminate.includes(item.id), isDisabled: disabled.includes(item.id), parentId: parentId, item: item, leavesOnly: leavesOnly, singleChoice: singleChoice, onExpansion: onExpansion, onChange: onChange, isSearch: isSearch, renderItemForDesktop: renderItemForDesktop, children: hasChildren && isExpanded && (jsx(ItemsList, { ...props, items: collection.getChildren(item.id), parentId: item.id })) }, item.id));
|
|
20
|
+
return (jsx(Item, { collection: collection, checkSelectable: checkSelectable, isSelected: selected.includes(item.id), isExpanded: isExpanded, isIndeterminate: indeterminate.includes(item.id), isDisabled: disabled.includes(item.id), parentId: parentId, item: item, leavesOnly: leavesOnly, singleChoice: singleChoice, onExpansion: onExpansion, onChange: onChange, isSearch: isSearch, renderItemForDesktop: renderItemForDesktop, animationTimeout: animationTimeout, children: hasChildren && isExpanded && (jsx(ItemsList, { ...props, items: collection.getChildren(item.id), parentId: item.id })) }, item.id));
|
|
20
21
|
}) }));
|
|
21
22
|
};
|
|
22
23
|
|
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;\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 } = 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 >\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":"
|
|
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;\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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AAU,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/MobileItemsList.d.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
interface MobileItemsListProps<A extends AdditionalDefault> {
|
|
6
|
-
collection: TreeCollection<A>;
|
|
2
|
+
import { AdditionalDefault, TreeModel } from './collection/types';
|
|
3
|
+
import { ListControls, TreeSelectorDummyProps } from './types';
|
|
4
|
+
export declare const MobileItemsList: import("react").ForwardRefExoticComponent<{
|
|
7
5
|
selected: string[];
|
|
8
6
|
disabled: string[];
|
|
9
|
-
|
|
10
|
-
singleChoice?: boolean;
|
|
11
|
-
checkSelectable?: IdCollectionPredicate;
|
|
12
|
-
onChange: (id: string, isSelected: boolean) => void;
|
|
13
|
-
getSearchItemOrder: (model: TreeModel<A>) => number;
|
|
7
|
+
getSearchItemOrder: (model: TreeModel<AdditionalDefault>) => number;
|
|
14
8
|
setInputValue: (newValue: string) => void;
|
|
15
9
|
handleChangeInput: (newValue: string) => void;
|
|
16
10
|
contentFilterQuery: string;
|
|
17
|
-
renderItem?: RenderItem;
|
|
18
|
-
renderMobileDelimiter?: RenderMobileDelimiter;
|
|
19
11
|
trlSelectParent: ReactNode;
|
|
20
|
-
}
|
|
21
|
-
export declare const MobileItemsList: import("react").ForwardRefExoticComponent<MobileItemsListProps<AdditionalDefault> & import("react").RefAttributes<ListControls>>;
|
|
22
|
-
export {};
|
|
12
|
+
} & Pick<TreeSelectorDummyProps<AdditionalDefault>, "singleChoice" | "onChange" | "collection" | "leavesOnly" | "checkSelectable" | "renderItem" | "renderMobileDelimiter" | "onMobileNavigationChange"> & import("react").RefAttributes<ListControls>>;
|
package/MobileItemsList.js
CHANGED
|
@@ -13,7 +13,7 @@ import '@hh.ru/magritte-ui-typography';
|
|
|
13
13
|
import './TreeSelectorItemBase.js';
|
|
14
14
|
|
|
15
15
|
const MobileItemsListComponent = (props, ref) => {
|
|
16
|
-
const { collection, selected, disabled, leavesOnly, singleChoice, onChange, checkSelectable, getSearchItemOrder, setInputValue, handleChangeInput, renderMobileDelimiter, renderItem, contentFilterQuery, trlSelectParent, } = props;
|
|
16
|
+
const { collection, selected, disabled, leavesOnly, singleChoice, onChange, checkSelectable, getSearchItemOrder, setInputValue, handleChangeInput, renderMobileDelimiter, renderItem, contentFilterQuery, trlSelectParent, onMobileNavigationChange, } = props;
|
|
17
17
|
const prevParentIds = useRef([]);
|
|
18
18
|
const prevQueries = useRef([]);
|
|
19
19
|
const currentQuery = useRef(contentFilterQuery);
|
|
@@ -40,7 +40,9 @@ const MobileItemsListComponent = (props, ref) => {
|
|
|
40
40
|
}, [contentFilterQuery]);
|
|
41
41
|
useImperativeHandle(ref, () => ({
|
|
42
42
|
back: () => {
|
|
43
|
-
|
|
43
|
+
const prevParentId = prevParentIds.current.pop();
|
|
44
|
+
setCurrentParentId(prevParentId);
|
|
45
|
+
onMobileNavigationChange?.(prevParentId);
|
|
44
46
|
if (prevQueries.current.length) {
|
|
45
47
|
setInputValue(prevQueries.current.pop());
|
|
46
48
|
}
|
|
@@ -48,7 +50,7 @@ const MobileItemsListComponent = (props, ref) => {
|
|
|
48
50
|
handleChangeInput('');
|
|
49
51
|
}
|
|
50
52
|
},
|
|
51
|
-
}), [handleChangeInput, setInputValue]);
|
|
53
|
+
}), [handleChangeInput, onMobileNavigationChange, setInputValue]);
|
|
52
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) => {
|
|
53
55
|
return itemsByOrder[order].map((item, index) => {
|
|
54
56
|
const hasChildren = collection.hasChildren(item.id);
|
|
@@ -67,6 +69,7 @@ const MobileItemsListComponent = (props, ref) => {
|
|
|
67
69
|
setCurrentParentId(item.id);
|
|
68
70
|
setInputValue('');
|
|
69
71
|
currentQuery.current = '';
|
|
72
|
+
onMobileNavigationChange?.(item.id);
|
|
70
73
|
}, isSearch: isSearch, renderItem: renderItem }, item.id)) : (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))] }));
|
|
71
74
|
});
|
|
72
75
|
})] }));
|
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 TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, IdCollectionPredicate, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, RenderItem, RenderMobileDelimiter } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileItemsListProps<A extends AdditionalDefault> {\n collection: TreeCollection<A>;\n selected: string[];\n disabled: string[];\n leavesOnly?: boolean;\n singleChoice?: boolean;\n checkSelectable?: IdCollectionPredicate;\n onChange: (id: string, isSelected: boolean) => void;\n getSearchItemOrder: (model: TreeModel<A>) => number;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n contentFilterQuery: string;\n renderItem?: RenderItem;\n renderMobileDelimiter?: RenderMobileDelimiter;\n trlSelectParent: ReactNode;\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 } = 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 setCurrentParentId(prevParentIds.current.pop());\n if (prevQueries.current.length) {\n setInputValue(prevQueries.current.pop() as string);\n } else {\n handleChangeInput('');\n }\n },\n }),\n [handleChangeInput, 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 }}\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":";;;;;;;;;;;;;AAuCA,MAAM,wBAAw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,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAK;AACV,oCAAA,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;oCAC5C,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AAC/C,oCAAA,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;oCAC5B,aAAa,CAAC,EAAE,CAAC,CAAC;AAClB,oCAAA,YAAY,CAAC,OAAO,GAAG,EAAE,CAAC;AAC9B,iCAAC,EACD,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EAZjB,EAAA,IAAI,CAAC,EAAE,CAad,KAEFA,GAAA,CAAC,UAAU,EAAA,EAEP,IAAI,EAAE,IAAI,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 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,UAAU,CAAC,WAAW,EAAE,CAAC,EAC5F,CAAC,eAAe,EAAE,UAAU,CAAC,CAChC,CAAC;IACF,M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,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;;;;"}
|
package/TreeSelector.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { AdditionalDefault } from './collection/types';
|
|
3
|
-
import {
|
|
4
|
-
export declare const TreeSelector: import("react").ForwardRefExoticComponent<
|
|
3
|
+
import { ListControls } from './types';
|
|
4
|
+
export declare const TreeSelector: import("react").ForwardRefExoticComponent<import("./types").BaseTreeSelectorProps<AdditionalDefault> & {
|
|
5
|
+
onChange: (allSelected: string[], id: string, isSelected: boolean) => void;
|
|
6
|
+
collapseToParentId?: boolean | undefined;
|
|
7
|
+
maxSelected?: number | undefined;
|
|
8
|
+
} & import("react").RefAttributes<ListControls>>;
|
package/TreeSelector.js
CHANGED
|
@@ -10,8 +10,9 @@ import '@hh.ru/magritte-ui-breakpoint';
|
|
|
10
10
|
import '@hh.ru/magritte-ui-spacing';
|
|
11
11
|
import './ItemsList.js';
|
|
12
12
|
import './Item.js';
|
|
13
|
+
import 'react-transition-group';
|
|
13
14
|
import 'classnames';
|
|
14
|
-
import './ItemContent-
|
|
15
|
+
import './ItemContent-36f7db0a.js';
|
|
15
16
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
16
17
|
import './Action.js';
|
|
17
18
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
@@ -26,9 +27,11 @@ import './MobileItem.js';
|
|
|
26
27
|
import './MobileParentItem.js';
|
|
27
28
|
import './collection/treeCollectionHelper.js';
|
|
28
29
|
import './collection/treeCollection.js';
|
|
30
|
+
import './useAnimationTimeout.js';
|
|
29
31
|
import './useExpanded.js';
|
|
30
32
|
import './useIndeterminate.js';
|
|
31
33
|
import './useRenderInput.js';
|
|
34
|
+
import '@hh.ru/magritte-common-func-utils';
|
|
32
35
|
import '@hh.ru/magritte-ui-input';
|
|
33
36
|
import './strategy/selectionStrategy.js';
|
|
34
37
|
import './strategy/createSingleValueToggler.js';
|
|
@@ -36,7 +39,7 @@ import './strategy/createTreeCollectionToggler.js';
|
|
|
36
39
|
import './strategy/dummyToggle.js';
|
|
37
40
|
|
|
38
41
|
const TreeSelectorComponent = (props, ref) => {
|
|
39
|
-
const { value, collection, singleChoice, leavesOnly, collapseToParentId, checkSelectable, onChange,
|
|
42
|
+
const { value, collection, singleChoice, leavesOnly, collapseToParentId, checkSelectable, onChange, disabled, maxSelected, ...rest } = props;
|
|
40
43
|
const strategy = useMemo(() => new ImmutableSelectionStrategy(collection, {
|
|
41
44
|
singleChoice,
|
|
42
45
|
leavesOnly,
|
|
@@ -47,7 +50,6 @@ const TreeSelectorComponent = (props, ref) => {
|
|
|
47
50
|
}
|
|
48
51
|
const { selected, setSelected } = useSelected({
|
|
49
52
|
value,
|
|
50
|
-
initialValue,
|
|
51
53
|
strategy,
|
|
52
54
|
collection,
|
|
53
55
|
onChange,
|
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
|
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,QAAQ,EACR,WAAW,EACX,GAAG,IAAI,EACV,GAAG,KAAK,CAAC;IACV,MAAM,QAAQ,GAAG,OAAO,CACpB,MACI,IAAI,0BAA0B,CAAC,UAAU,EAAE;QACvC,YAAY;QACZ,UAAU;QACV,eAAe;KAClB,CAAC,EACN,CAAC,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,CAAC,CAC1D,CAAC;AAEF,IAAA,IAAI,WAAW,IAAI,CAAC,kBAAkB,IAAI,CAAC,UAAU,EAAE;AACnD,QAAA,MAAM,IAAI,KAAK,CACX,CAAA,mGAAA,CAAqG,CACxG,CAAC;AACL,KAAA;AAED,IAAA,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC;QAC1C,KAAK;QACL,QAAQ;QACR,UAAU;QACV,QAAQ;QACR,WAAW;QACX,kBAAkB;AACrB,KAAA,CAAC,CAAC;AAEH,IAAA,MAAM,eAAe,GAAG,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC,CAAC;AAErF,IAAA,QACIA,GAAC,CAAA,iBAAiB,EACV,EAAA,GAAA,IAAI,EACR,KAAK,EAAE,QAAQ,EACf,QAAQ,EAAE,eAAe,EACzB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,WAAW,EACrB,GAAG,EAAE,GAAG,EAAA,CACV,EACJ;AACN,CAAC,CAAC;MAEW,YAAY,GAAG,UAAU,CAAC,qBAAqB;;;;"}
|
package/TreeSelectorDummy.js
CHANGED
|
@@ -7,12 +7,14 @@ import { VSpacingContainer } from '@hh.ru/magritte-ui-spacing';
|
|
|
7
7
|
import { ItemsList } from './ItemsList.js';
|
|
8
8
|
import { MobileItemsList } from './MobileItemsList.js';
|
|
9
9
|
import { filterWithParents } from './collection/treeCollectionHelper.js';
|
|
10
|
+
import { useAnimationTimeout } from './useAnimationTimeout.js';
|
|
10
11
|
import { useExpanded } from './useExpanded.js';
|
|
11
12
|
import { useIndeterminate } from './useIndeterminate.js';
|
|
12
13
|
import { useRenderInput } from './useRenderInput.js';
|
|
13
14
|
import './Item.js';
|
|
15
|
+
import 'react-transition-group';
|
|
14
16
|
import 'classnames';
|
|
15
|
-
import './ItemContent-
|
|
17
|
+
import './ItemContent-36f7db0a.js';
|
|
16
18
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
17
19
|
import './Action.js';
|
|
18
20
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
@@ -25,6 +27,7 @@ import '@hh.ru/magritte-ui-card';
|
|
|
25
27
|
import './MobileItem.js';
|
|
26
28
|
import './MobileParentItem.js';
|
|
27
29
|
import './collection/treeCollection.js';
|
|
30
|
+
import '@hh.ru/magritte-common-func-utils';
|
|
28
31
|
import '@hh.ru/magritte-ui-input';
|
|
29
32
|
|
|
30
33
|
const defaultCheckSelectable = () => true;
|
|
@@ -32,11 +35,12 @@ const defaultArray = [];
|
|
|
32
35
|
const needToApply = (query) => {
|
|
33
36
|
return !!(query && query.length);
|
|
34
37
|
};
|
|
35
|
-
const TreeSelectorDummy = forwardRef(({ collection: initialCollection, checkSelectable = defaultCheckSelectable, initialExpanded = defaultArray, value: selected, leavesOnly, singleChoice, expanded, disabled = defaultArray, treeFilter = filterWithParents, suggestedNotFound = defaultArray, constantlySuggested = defaultArray, renderItemForDesktop, renderItem, renderMobileDelimiter, onExpand, onChange, onChangeFilterQuery, trls, children, }, ref) => {
|
|
38
|
+
const TreeSelectorDummy = forwardRef(({ collection: initialCollection, checkSelectable = defaultCheckSelectable, initialExpanded = defaultArray, value: selected, leavesOnly, singleChoice, expanded, disabled = defaultArray, treeFilter = filterWithParents, suggestedNotFound = defaultArray, constantlySuggested = defaultArray, renderItemForDesktop, renderItem, renderMobileDelimiter, onExpand, onChange, onChangeFilterQuery, contentNotFound, onMobileNavigationChange, trls, children, }, ref) => {
|
|
36
39
|
const [collection, setCollection] = useState(initialCollection);
|
|
37
40
|
const currentQuery = useRef('');
|
|
38
41
|
const suggestedNotFoundModels = useRef(initialCollection.getExistModels(suggestedNotFound));
|
|
39
42
|
const constantlySuggestedModels = useRef(initialCollection.getExistModels(constantlySuggested));
|
|
43
|
+
const { animationTimeout } = useAnimationTimeout();
|
|
40
44
|
const { indeterminate } = useIndeterminate({ collection: initialCollection, selected });
|
|
41
45
|
const { expanded: currentExpanded, setExpanded, handleExpansion, } = useExpanded({
|
|
42
46
|
initialValue: expanded ? expanded.slice() : initialExpanded.slice(),
|
|
@@ -104,10 +108,11 @@ const TreeSelectorDummy = forwardRef(({ collection: initialCollection, checkSele
|
|
|
104
108
|
onChangeFilterQuery,
|
|
105
109
|
]);
|
|
106
110
|
const renderTreeSelector = useCallback(() => {
|
|
107
|
-
|
|
111
|
+
const hasModels = collection.getTopLevel().length;
|
|
112
|
+
return hasModels ? (jsx(VSpacingContainer, { default: 12, gteM: 0, children: isMobile ? (jsx(MobileItemsList, { getSearchItemOrder: (model) => initialCollection.getModelLevel(model.id), collection: collection, selected: selected, disabled: disabled, onChange: onChange, leavesOnly: leavesOnly, checkSelectable: checkSelectable, singleChoice: singleChoice, ref: ref, setInputValue: setInputValue, renderItem: renderItem, renderMobileDelimiter: renderMobileDelimiter, handleChangeInput: handleChangeInput, contentFilterQuery: contentFilterQuery.trim(), trlSelectParent: trls.selectAllParent, onMobileNavigationChange: onMobileNavigationChange })) : (jsx(ItemsList, { collection: collection, items: collection.getTopLevel(), leavesOnly: leavesOnly, checkSelectable: checkSelectable, expanded: currentExpanded, onExpansion: handleExpansion, selected: selected, onChange: onChange, disabled: disabled, singleChoice: singleChoice, indeterminate: indeterminate, isSearch: !!contentFilterQuery.trim(), renderItemForDesktop: renderItemForDesktop, animationTimeout: animationTimeout })) })) : (jsx(Fragment, { children: contentNotFound }));
|
|
108
113
|
}, [
|
|
109
|
-
isMobile,
|
|
110
114
|
collection,
|
|
115
|
+
isMobile,
|
|
111
116
|
selected,
|
|
112
117
|
disabled,
|
|
113
118
|
onChange,
|
|
@@ -116,15 +121,18 @@ const TreeSelectorDummy = forwardRef(({ collection: initialCollection, checkSele
|
|
|
116
121
|
singleChoice,
|
|
117
122
|
ref,
|
|
118
123
|
setInputValue,
|
|
124
|
+
renderItem,
|
|
125
|
+
renderMobileDelimiter,
|
|
119
126
|
handleChangeInput,
|
|
120
127
|
contentFilterQuery,
|
|
128
|
+
trls.selectAllParent,
|
|
129
|
+
onMobileNavigationChange,
|
|
121
130
|
currentExpanded,
|
|
122
131
|
handleExpansion,
|
|
123
132
|
indeterminate,
|
|
124
133
|
renderItemForDesktop,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
trls.selectAllParent,
|
|
134
|
+
animationTimeout,
|
|
135
|
+
contentNotFound,
|
|
128
136
|
initialCollection,
|
|
129
137
|
]);
|
|
130
138
|
return jsx(Fragment, { children: children({ renderTreeSelector, renderInput }) });
|
package/TreeSelectorDummy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeSelectorDummy.js","sources":["../src/TreeSelectorDummy.tsx"],"sourcesContent":["import { ReactElement, forwardRef, ForwardedRef, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { match } from '@hh.ru/magritte-common-fuzzy-search';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { VSpacingContainer } from '@hh.ru/magritte-ui-spacing';\nimport { ItemsList } from '@hh.ru/magritte-ui-tree-selector/ItemsList';\nimport { MobileItemsList } from '@hh.ru/magritte-ui-tree-selector/MobileItemsList';\nimport { filterWithParents } from '@hh.ru/magritte-ui-tree-selector/collection/treeCollectionHelper';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useExpanded } from '@hh.ru/magritte-ui-tree-selector/useExpanded';\nimport { useIndeterminate } from '@hh.ru/magritte-ui-tree-selector/useIndeterminate';\nimport { useRenderInput } from '@hh.ru/magritte-ui-tree-selector/useRenderInput';\n\nconst defaultCheckSelectable = () => true;\nconst defaultArray: string[] = [];\n\nconst needToApply = (query: string): boolean => {\n return !!(query && query.length);\n};\n\nexport const TreeSelectorDummy = forwardRef(\n <A extends AdditionalDefault>(\n {\n collection: initialCollection,\n checkSelectable = defaultCheckSelectable,\n initialExpanded = defaultArray,\n value: selected,\n leavesOnly,\n singleChoice,\n expanded,\n disabled = defaultArray,\n treeFilter = filterWithParents,\n suggestedNotFound = defaultArray,\n constantlySuggested = defaultArray,\n renderItemForDesktop,\n renderItem,\n renderMobileDelimiter,\n onExpand,\n onChange,\n onChangeFilterQuery,\n trls,\n children,\n }: TreeSelectorDummyProps<A>,\n ref: ForwardedRef<ListControls>\n ): ReactElement => {\n const [collection, setCollection] = useState(initialCollection);\n const currentQuery = useRef('');\n const suggestedNotFoundModels = useRef(initialCollection.getExistModels(suggestedNotFound));\n const constantlySuggestedModels = useRef(initialCollection.getExistModels(constantlySuggested));\n\n const { indeterminate } = useIndeterminate({ collection: initialCollection, selected });\n const {\n expanded: currentExpanded,\n setExpanded,\n handleExpansion,\n } = useExpanded({\n initialValue: expanded ? expanded.slice() : initialExpanded.slice(),\n controlledExpanded: expanded,\n onExpand,\n });\n const { isMobile } = useBreakpoint();\n\n const { contentFilterQuery, setInputValue, handleChangeInput, renderInput } = useRenderInput();\n\n useEffect(() => {\n const contentFilterQueryTrimmed = contentFilterQuery.trim();\n const queryWasChanged = contentFilterQueryTrimmed !== currentQuery.current.trim();\n\n if (queryWasChanged && needToApply(contentFilterQueryTrimmed)) {\n const newExpanded: string[] = [];\n const newCollection = treeFilter(\n initialCollection,\n (item) => match(contentFilterQueryTrimmed, item.text),\n isMobile\n );\n newCollection.toList().forEach((item) => {\n if (newCollection.hasChildren(item.id)) {\n // Если есть в отфильтрованной коллекции есть дочерние элементы,\n // значит они заматчились, и нужно открыть родителя.\n newExpanded.push(item.id);\n } else {\n // Если заматчился только сам родитель, показываем его\n // схлопнутым => нужно добавить его ветку в коллекцию.\n initialCollection.walkChildren(item.id, (child, parents) => {\n newCollection.addModel({ ...child }, parents[0].id);\n });\n }\n });\n\n const filteredIds = newCollection.toList().map((model) => model.id);\n\n // Если в отфильтрованной коллекции нет моделей, но заданы предложенные,\n // то показываем их\n // Если в отфильтрованной коллекции модели есть, то пробуем добавить к ним\n // всегда показывающиеся модели, если их ещё нет в коллекции\n if (!filteredIds.length && suggestedNotFoundModels.current.length) {\n suggestedNotFoundModels.current.forEach((model) => newCollection.addModel({ ...model }));\n } else {\n constantlySuggestedModels.current.forEach((model) => {\n if (!filteredIds.includes(model.id)) {\n newCollection.addModel({ ...model });\n }\n });\n }\n\n setCollection(newCollection);\n currentQuery.current = contentFilterQuery;\n onChangeFilterQuery?.(filteredIds, contentFilterQueryTrimmed);\n setExpanded(newExpanded);\n } else if (queryWasChanged) {\n // Запрос не годится для поиска.\n const newExpanded = initialExpanded.slice();\n setCollection(initialCollection);\n\n onChangeFilterQuery?.(\n initialCollection.toList().map((model) => model.id),\n contentFilterQueryTrimmed\n );\n currentQuery.current = contentFilterQuery;\n setExpanded(newExpanded);\n }\n }, [\n initialCollection,\n contentFilterQuery,\n treeFilter,\n selected,\n initialExpanded,\n setExpanded,\n isMobile,\n onChangeFilterQuery,\n ]);\n\n const renderTreeSelector = useCallback(() => {\n return (\n <VSpacingContainer default={12} gteM={0}>\n {isMobile ? (\n <MobileItemsList\n getSearchItemOrder={(model) => initialCollection.getModelLevel(model.id)}\n collection={collection}\n selected={selected}\n disabled={disabled}\n onChange={onChange}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n singleChoice={singleChoice}\n ref={ref}\n setInputValue={setInputValue}\n renderItem={renderItem}\n renderMobileDelimiter={renderMobileDelimiter}\n handleChangeInput={handleChangeInput}\n contentFilterQuery={contentFilterQuery.trim()}\n trlSelectParent={trls.selectAllParent}\n />\n ) : (\n <ItemsList\n collection={collection}\n items={collection.getTopLevel()}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n expanded={currentExpanded}\n onExpansion={handleExpansion}\n selected={selected}\n onChange={onChange}\n disabled={disabled}\n singleChoice={singleChoice}\n indeterminate={indeterminate}\n isSearch={!!contentFilterQuery.trim()}\n renderItemForDesktop={renderItemForDesktop}\n />\n )}\n </VSpacingContainer>\n );\n }, [\n isMobile,\n collection,\n selected,\n disabled,\n onChange,\n leavesOnly,\n checkSelectable,\n singleChoice,\n ref,\n setInputValue,\n handleChangeInput,\n contentFilterQuery,\n currentExpanded,\n handleExpansion,\n indeterminate,\n renderItemForDesktop,\n renderItem,\n renderMobileDelimiter,\n trls.selectAllParent,\n initialCollection,\n ]);\n\n return <>{children({ renderTreeSelector, renderInput })}</>;\n }\n);\n\nTreeSelectorDummy.displayName = 'TreeSelectorDummy';\n"],"names":["_jsx","_Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAC1C,MAAM,YAAY,GAAa,EAAE,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,KAAa,KAAa;IAC3C,OAAO,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AAC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A,CAAC,CAAC;IAEH,OAAOA,GAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAG,QAAQ,CAAC,EAAE,kBAAkB,EAAE,WAAW,EAAE,CAAC,EAAA,CAAI,CAAC;AAChE,CAAC,EACH;AAEF,iBAAiB,CAAC,WAAW,GAAG,mBAAmB;;;;"}
|
|
1
|
+
{"version":3,"file":"TreeSelectorDummy.js","sources":["../src/TreeSelectorDummy.tsx"],"sourcesContent":["import { ReactElement, forwardRef, ForwardedRef, useCallback, useEffect, useRef, useState } from 'react';\n\nimport { match } from '@hh.ru/magritte-common-fuzzy-search';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { VSpacingContainer } from '@hh.ru/magritte-ui-spacing';\nimport { ItemsList } from '@hh.ru/magritte-ui-tree-selector/ItemsList';\nimport { MobileItemsList } from '@hh.ru/magritte-ui-tree-selector/MobileItemsList';\nimport { filterWithParents } from '@hh.ru/magritte-ui-tree-selector/collection/treeCollectionHelper';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls, TreeSelectorDummyProps } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useAnimationTimeout } from '@hh.ru/magritte-ui-tree-selector/useAnimationTimeout';\nimport { useExpanded } from '@hh.ru/magritte-ui-tree-selector/useExpanded';\nimport { useIndeterminate } from '@hh.ru/magritte-ui-tree-selector/useIndeterminate';\nimport { useRenderInput } from '@hh.ru/magritte-ui-tree-selector/useRenderInput';\n\nconst defaultCheckSelectable = () => true;\nconst defaultArray: string[] = [];\n\nconst needToApply = (query: string): boolean => {\n return !!(query && query.length);\n};\n\nexport const TreeSelectorDummy = forwardRef(\n <A extends AdditionalDefault>(\n {\n collection: initialCollection,\n checkSelectable = defaultCheckSelectable,\n initialExpanded = defaultArray,\n value: selected,\n leavesOnly,\n singleChoice,\n expanded,\n disabled = defaultArray,\n treeFilter = filterWithParents,\n suggestedNotFound = defaultArray,\n constantlySuggested = defaultArray,\n renderItemForDesktop,\n renderItem,\n renderMobileDelimiter,\n onExpand,\n onChange,\n onChangeFilterQuery,\n contentNotFound,\n onMobileNavigationChange,\n trls,\n children,\n }: TreeSelectorDummyProps<A>,\n ref: ForwardedRef<ListControls>\n ): ReactElement => {\n const [collection, setCollection] = useState(initialCollection);\n const currentQuery = useRef('');\n const suggestedNotFoundModels = useRef(initialCollection.getExistModels(suggestedNotFound));\n const constantlySuggestedModels = useRef(initialCollection.getExistModels(constantlySuggested));\n const { animationTimeout } = useAnimationTimeout();\n\n const { indeterminate } = useIndeterminate({ collection: initialCollection, selected });\n const {\n expanded: currentExpanded,\n setExpanded,\n handleExpansion,\n } = useExpanded({\n initialValue: expanded ? expanded.slice() : initialExpanded.slice(),\n controlledExpanded: expanded,\n onExpand,\n });\n const { isMobile } = useBreakpoint();\n\n const { contentFilterQuery, setInputValue, handleChangeInput, renderInput } = useRenderInput();\n\n useEffect(() => {\n const contentFilterQueryTrimmed = contentFilterQuery.trim();\n const queryWasChanged = contentFilterQueryTrimmed !== currentQuery.current.trim();\n\n if (queryWasChanged && needToApply(contentFilterQueryTrimmed)) {\n const newExpanded: string[] = [];\n const newCollection = treeFilter(\n initialCollection,\n (item) => match(contentFilterQueryTrimmed, item.text),\n isMobile\n );\n newCollection.toList().forEach((item) => {\n if (newCollection.hasChildren(item.id)) {\n // Если есть в отфильтрованной коллекции есть дочерние элементы,\n // значит они заматчились, и нужно открыть родителя.\n newExpanded.push(item.id);\n } else {\n // Если заматчился только сам родитель, показываем его\n // схлопнутым => нужно добавить его ветку в коллекцию.\n initialCollection.walkChildren(item.id, (child, parents) => {\n newCollection.addModel({ ...child }, parents[0].id);\n });\n }\n });\n\n const filteredIds = newCollection.toList().map((model) => model.id);\n\n // Если в отфильтрованной коллекции нет моделей, но заданы предложенные,\n // то показываем их\n // Если в отфильтрованной коллекции модели есть, то пробуем добавить к ним\n // всегда показывающиеся модели, если их ещё нет в коллекции\n if (!filteredIds.length && suggestedNotFoundModels.current.length) {\n suggestedNotFoundModels.current.forEach((model) => newCollection.addModel({ ...model }));\n } else {\n constantlySuggestedModels.current.forEach((model) => {\n if (!filteredIds.includes(model.id)) {\n newCollection.addModel({ ...model });\n }\n });\n }\n\n setCollection(newCollection);\n currentQuery.current = contentFilterQuery;\n onChangeFilterQuery?.(filteredIds, contentFilterQueryTrimmed);\n setExpanded(newExpanded);\n } else if (queryWasChanged) {\n // Запрос не годится для поиска.\n const newExpanded = initialExpanded.slice();\n setCollection(initialCollection);\n\n onChangeFilterQuery?.(\n initialCollection.toList().map((model) => model.id),\n contentFilterQueryTrimmed\n );\n currentQuery.current = contentFilterQuery;\n setExpanded(newExpanded);\n }\n }, [\n initialCollection,\n contentFilterQuery,\n treeFilter,\n selected,\n initialExpanded,\n setExpanded,\n isMobile,\n onChangeFilterQuery,\n ]);\n\n const renderTreeSelector = useCallback(() => {\n const hasModels = collection.getTopLevel().length;\n return hasModels ? (\n <VSpacingContainer default={12} gteM={0}>\n {isMobile ? (\n <MobileItemsList\n getSearchItemOrder={(model) => initialCollection.getModelLevel(model.id)}\n collection={collection}\n selected={selected}\n disabled={disabled}\n onChange={onChange}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n singleChoice={singleChoice}\n ref={ref}\n setInputValue={setInputValue}\n renderItem={renderItem}\n renderMobileDelimiter={renderMobileDelimiter}\n handleChangeInput={handleChangeInput}\n contentFilterQuery={contentFilterQuery.trim()}\n trlSelectParent={trls.selectAllParent}\n onMobileNavigationChange={onMobileNavigationChange}\n />\n ) : (\n <ItemsList\n collection={collection}\n items={collection.getTopLevel()}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n expanded={currentExpanded}\n onExpansion={handleExpansion}\n selected={selected}\n onChange={onChange}\n disabled={disabled}\n singleChoice={singleChoice}\n indeterminate={indeterminate}\n isSearch={!!contentFilterQuery.trim()}\n renderItemForDesktop={renderItemForDesktop}\n animationTimeout={animationTimeout}\n />\n )}\n </VSpacingContainer>\n ) : (\n <>{contentNotFound}</>\n );\n }, [\n collection,\n isMobile,\n selected,\n disabled,\n onChange,\n leavesOnly,\n checkSelectable,\n singleChoice,\n ref,\n setInputValue,\n renderItem,\n renderMobileDelimiter,\n handleChangeInput,\n contentFilterQuery,\n trls.selectAllParent,\n onMobileNavigationChange,\n currentExpanded,\n handleExpansion,\n indeterminate,\n renderItemForDesktop,\n animationTimeout,\n contentNotFound,\n initialCollection,\n ]);\n\n return <>{children({ renderTreeSelector, renderInput })}</>;\n }\n);\n\nTreeSelectorDummy.displayName = 'TreeSelectorDummy';\n"],"names":["_jsx","_Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAC1C,MAAM,YAAY,GAAa,EAAE,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,KAAa,KAAa;IAC3C,OAAO,CAAC,EAAE,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC,CAAC;AAEK,MAAM,iBAAiB,GAAG,UAAU,CACvC,CACI,EACI,UAAU,EAAE,iBAAiB,EAC7B,eAAe,GAAG,sBAAsB,EACxC,eAAe,GAAG,YAAY,EAC9B,KAAK,EAAE,QAAQ,EACf,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,QAAQ,GAAG,YAAY,EACvB,UAAU,GAAG,iBAAiB,EAC9B,iBAAiB,GAAG,YAAY,EAChC,mBAAmB,GAAG,YAAY,EAClC,oBAAoB,EACpB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,wBAAwB,EACxB,IAAI,EACJ,QAAQ,GACgB,EAC5B,GAA+B,KACjB;IACd,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;AAChE,IAAA,MAAM,YAAY,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC;IAChC,MAAM,uBAAuB,GAAG,M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right' : 'left']: input,
|
|
8
8
|
...(isXS && labelRight && { right: labelRight }),
|
|
9
9
|
};
|
|
10
|
-
return (jsx(Cell, { disabled: disabled, ...cellProps, children: jsx(CellText, { children: item.text }) }));
|
|
10
|
+
return (jsx(Cell, { disabled: disabled, ...cellProps, align: "top", children: jsx(CellText, { children: item.text }) }));
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { TreeSelectorItemBase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeSelectorItemBase.js","sources":["../src/TreeSelectorItemBase.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItemProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\nexport const TreeSelectorItemBase = <A extends AdditionalDefault>({\n disabled,\n input,\n item,\n isXS,\n labelRight,\n}: RenderItemProps<A>): ReactElement => {\n const cellProps = {\n [isXS ? 'right' : 'left']: input,\n ...(isXS && labelRight && { right: labelRight }),\n };\n return (\n <Cell disabled={disabled} {...cellProps}>\n <CellText>{item.text}</CellText>\n </Cell>\n );\n};\n"],"names":["_jsx"],"mappings":";;;AAMa,MAAA,oBAAoB,GAAG,CAA8B,EAC9D,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,GACO,KAAkB;AACnC,IAAA,MAAM,SAAS,GAAG;QACd,CAAC,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK;QAChC,IAAI,IAAI,IAAI,UAAU,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;KACnD,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeSelectorItemBase.js","sources":["../src/TreeSelectorItemBase.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { RenderItemProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\nexport const TreeSelectorItemBase = <A extends AdditionalDefault>({\n disabled,\n input,\n item,\n isXS,\n labelRight,\n}: RenderItemProps<A>): ReactElement => {\n const cellProps = {\n [isXS ? 'right' : 'left']: input,\n ...(isXS && labelRight && { right: labelRight }),\n };\n return (\n <Cell disabled={disabled} {...cellProps} align=\"top\">\n <CellText>{item.text}</CellText>\n </Cell>\n );\n};\n"],"names":["_jsx"],"mappings":";;;AAMa,MAAA,oBAAoB,GAAG,CAA8B,EAC9D,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,GACO,KAAkB;AACnC,IAAA,MAAM,SAAS,GAAG;QACd,CAAC,IAAI,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK;QAChC,IAAI,IAAI,IAAI,UAAU,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;KACnD,CAAC;IACF,QACIA,IAAC,IAAI,EAAA,EAAC,QAAQ,EAAE,QAAQ,EAAM,GAAA,SAAS,EAAE,KAAK,EAAC,KAAK,EAAA,QAAA,EAChDA,GAAC,CAAA,QAAQ,EAAE,EAAA,QAAA,EAAA,IAAI,CAAC,IAAI,EAAA,CAAY,EAC7B,CAAA,EACT;AACN;;;;"}
|
package/index.css
CHANGED
|
@@ -1,10 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
:root{
|
|
2
|
+
--magritte-semantic-animation-ease-in-out-200-timing-function-v18-2-0:cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
3
|
+
--magritte-semantic-animation-ease-in-out-200-duration-v18-2-0:200ms;
|
|
4
|
+
}
|
|
5
|
+
.magritte-item-animation-timeout___Pdli9_1-6-0{
|
|
6
|
+
transition:height 500ms ease;
|
|
7
|
+
transition-timing-function:var(--magritte-semantic-animation-ease-in-out-200-timing-function-v18-2-0);
|
|
8
|
+
overflow:hidden;
|
|
9
|
+
--animation-duration:0ms;
|
|
10
|
+
transition-duration:var(--animation-duration);
|
|
11
|
+
}
|
|
12
|
+
@media (prefers-reduced-motion: no-preference){
|
|
13
|
+
.magritte-item-animation-timeout___Pdli9_1-6-0{
|
|
14
|
+
--animation-duration:var(--magritte-semantic-animation-ease-in-out-200-duration-v18-2-0);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
:root{
|
|
19
|
+
--magritte-semantic-animation-ease-in-out-100-timing-function-v18-2-0:cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
20
|
+
--magritte-semantic-animation-ease-in-out-100-duration-v18-2-0:100ms;
|
|
21
|
+
--magritte-semantic-animation-ease-in-out-200-timing-function-v18-2-0:cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
22
|
+
--magritte-semantic-animation-ease-in-out-200-duration-v18-2-0:200ms;
|
|
23
|
+
}
|
|
24
|
+
.magritte-item-animation-timeout___pbOyZ_1-6-0{
|
|
25
|
+
transition:height 500ms ease;
|
|
26
|
+
transition-timing-function:var(--magritte-semantic-animation-ease-in-out-200-timing-function-v18-2-0);
|
|
27
|
+
overflow:hidden;
|
|
28
|
+
--animation-duration:0ms;
|
|
29
|
+
transition-duration:var(--animation-duration);
|
|
30
|
+
}
|
|
31
|
+
@media (prefers-reduced-motion: no-preference){
|
|
32
|
+
.magritte-item-animation-timeout___pbOyZ_1-6-0{
|
|
33
|
+
--animation-duration:var(--magritte-semantic-animation-ease-in-out-200-duration-v18-2-0);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
.magritte-wrapper___GHKV6_1-6-0{
|
|
2
37
|
display:flex;
|
|
3
38
|
padding:12px 0;
|
|
4
39
|
gap:12px;
|
|
5
40
|
align-items:flex-start;
|
|
6
41
|
}
|
|
7
|
-
.magritte-letter___yZOCU_1-
|
|
42
|
+
.magritte-letter___yZOCU_1-6-0{
|
|
8
43
|
width:24px;
|
|
9
44
|
height:24px;
|
|
10
45
|
display:flex;
|
|
@@ -12,30 +47,55 @@
|
|
|
12
47
|
justify-content:center;
|
|
13
48
|
flex-shrink:0;
|
|
14
49
|
}
|
|
15
|
-
.magritte-icon___kO3Fj_1-
|
|
16
|
-
.magritte-space___xTO79_1-
|
|
50
|
+
.magritte-icon___kO3Fj_1-6-0,
|
|
51
|
+
.magritte-space___xTO79_1-6-0{
|
|
17
52
|
flex-shrink:0;
|
|
18
53
|
line-height:0;
|
|
19
54
|
width:24px;
|
|
20
55
|
}
|
|
21
|
-
.magritte-
|
|
56
|
+
.magritte-icon___kO3Fj_1-6-0{
|
|
57
|
+
transform:rotate(0);
|
|
58
|
+
}
|
|
59
|
+
.magritte-iconActive___4yrG5_1-6-0{
|
|
22
60
|
cursor:pointer;
|
|
23
61
|
}
|
|
24
|
-
.magritte-
|
|
62
|
+
.magritte-iconUp___mpXV6_1-6-0{
|
|
63
|
+
transform:rotate(-180deg);
|
|
64
|
+
}
|
|
65
|
+
@media (prefers-reduced-motion: no-preference){
|
|
66
|
+
.magritte-icon___kO3Fj_1-6-0{
|
|
67
|
+
transition-property:transform;
|
|
68
|
+
transition-duration:var(--magritte-semantic-animation-ease-in-out-100-duration-v18-2-0);
|
|
69
|
+
transition-timing-function:var(--magritte-semantic-animation-ease-in-out-100-timing-function-v18-2-0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
.magritte-content___ZRc6R_1-6-0{
|
|
25
73
|
flex-grow:1;
|
|
26
74
|
}
|
|
27
|
-
.magritte-with-shift___ZErxZ_1-
|
|
75
|
+
.magritte-with-shift___ZErxZ_1-6-0{
|
|
28
76
|
margin-left:-36px;
|
|
29
77
|
}
|
|
30
|
-
.magritte-with-indent___MH9Vy_1-
|
|
78
|
+
.magritte-with-indent___MH9Vy_1-6-0{
|
|
31
79
|
margin-left:36px;
|
|
32
80
|
}
|
|
33
|
-
.magritte-item___2LtOL_1-
|
|
81
|
+
.magritte-item___2LtOL_1-6-0 > .magritte-children___kq-eq_1-6-0{
|
|
34
82
|
padding-left:36px;
|
|
35
83
|
}
|
|
36
|
-
.magritte-item___2LtOL_1-
|
|
84
|
+
.magritte-item___2LtOL_1-6-0.magritte-with-two-boxes___LWOy2_1-6-0 > .magritte-children___kq-eq_1-6-0{
|
|
37
85
|
padding-left:72px;
|
|
38
86
|
}
|
|
39
|
-
.magritte-item___2LtOL_1-
|
|
87
|
+
.magritte-item___2LtOL_1-6-0.magritte-with-three-boxes___cyVao_1-6-0 > .magritte-children___kq-eq_1-6-0{
|
|
40
88
|
padding-left:108px;
|
|
41
89
|
}
|
|
90
|
+
.magritte-children___kq-eq_1-6-0{
|
|
91
|
+
transition:height 500ms ease;
|
|
92
|
+
transition-timing-function:var(--magritte-semantic-animation-ease-in-out-200-timing-function-v18-2-0);
|
|
93
|
+
overflow:hidden;
|
|
94
|
+
--animation-duration:0ms;
|
|
95
|
+
transition-duration:var(--animation-duration);
|
|
96
|
+
}
|
|
97
|
+
@media (prefers-reduced-motion: no-preference){
|
|
98
|
+
.magritte-children___kq-eq_1-6-0{
|
|
99
|
+
--animation-duration:var(--magritte-semantic-animation-ease-in-out-200-duration-v18-2-0);
|
|
100
|
+
}
|
|
101
|
+
}
|
package/index.js
CHANGED
|
@@ -18,8 +18,9 @@ import '@hh.ru/magritte-ui-breakpoint';
|
|
|
18
18
|
import '@hh.ru/magritte-ui-spacing';
|
|
19
19
|
import './ItemsList.js';
|
|
20
20
|
import './Item.js';
|
|
21
|
+
import 'react-transition-group';
|
|
21
22
|
import 'classnames';
|
|
22
|
-
import './ItemContent-
|
|
23
|
+
import './ItemContent-36f7db0a.js';
|
|
23
24
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
24
25
|
import './Action.js';
|
|
25
26
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
@@ -31,8 +32,10 @@ import './MobileDelimiter.js';
|
|
|
31
32
|
import '@hh.ru/magritte-ui-card';
|
|
32
33
|
import './MobileItem.js';
|
|
33
34
|
import './MobileParentItem.js';
|
|
35
|
+
import './useAnimationTimeout.js';
|
|
34
36
|
import './useExpanded.js';
|
|
35
37
|
import './useIndeterminate.js';
|
|
36
38
|
import './useRenderInput.js';
|
|
39
|
+
import '@hh.ru/magritte-common-func-utils';
|
|
37
40
|
import '@hh.ru/magritte-ui-input';
|
|
38
41
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hh.ru/magritte-ui-tree-selector",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"sideEffects": [
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"test": "yarn root:test $(pwd)"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@hh.ru/magritte-common-func-utils": "1.3.6",
|
|
22
23
|
"@hh.ru/magritte-common-fuzzy-search": "1.0.4",
|
|
24
|
+
"@hh.ru/magritte-design-tokens": "18.2.0",
|
|
23
25
|
"@hh.ru/magritte-ui-breakpoint": "4.0.2",
|
|
24
26
|
"@hh.ru/magritte-ui-card": "6.0.8",
|
|
25
27
|
"@hh.ru/magritte-ui-cell": "3.0.1",
|
|
@@ -34,10 +36,11 @@
|
|
|
34
36
|
},
|
|
35
37
|
"peerDependencies": {
|
|
36
38
|
"classnames": ">=2.3.2",
|
|
37
|
-
"react": ">=18.2.0"
|
|
39
|
+
"react": ">=18.2.0",
|
|
40
|
+
"react-transition-group": ">=4.4.5"
|
|
38
41
|
},
|
|
39
42
|
"publishConfig": {
|
|
40
43
|
"access": "public"
|
|
41
44
|
},
|
|
42
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "731585449c1e6729e634c99e1b3d9758b8116f58"
|
|
43
46
|
}
|
package/types.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export interface RenderMobileDelimiter {
|
|
|
33
33
|
<A extends AdditionalDefault>(props: RenderMobileDelimiterProps<A>): ReactNode;
|
|
34
34
|
}
|
|
35
35
|
export interface BaseTreeSelectorProps<A extends AdditionalDefault> {
|
|
36
|
+
value: string[];
|
|
36
37
|
collection: TreeCollection<A>;
|
|
37
38
|
singleChoice?: boolean;
|
|
38
39
|
leavesOnly?: boolean;
|
|
@@ -50,27 +51,22 @@ export interface BaseTreeSelectorProps<A extends AdditionalDefault> {
|
|
|
50
51
|
renderItemForDesktop?: RenderItem;
|
|
51
52
|
renderItem?: RenderItem;
|
|
52
53
|
renderMobileDelimiter?: RenderMobileDelimiter;
|
|
54
|
+
contentNotFound?: ReactNode;
|
|
55
|
+
onMobileNavigationChange?: (currentId?: string) => void;
|
|
53
56
|
trls: {
|
|
54
57
|
selectAllParent: ReactNode;
|
|
55
58
|
};
|
|
56
59
|
}
|
|
57
60
|
export interface DummyProps {
|
|
58
|
-
value: string[];
|
|
59
61
|
onChange: (id: string, isSelected: boolean) => void;
|
|
60
62
|
collapseToParentId?: never;
|
|
61
63
|
maxSelected?: never;
|
|
62
64
|
}
|
|
63
65
|
type NonDummyProps = {
|
|
64
|
-
onChange
|
|
66
|
+
onChange: (allSelected: string[], id: string, isSelected: boolean) => void;
|
|
65
67
|
collapseToParentId?: boolean;
|
|
66
68
|
maxSelected?: number;
|
|
67
|
-
}
|
|
68
|
-
value: string[];
|
|
69
|
-
initialValue?: never;
|
|
70
|
-
} | {
|
|
71
|
-
value?: never;
|
|
72
|
-
initialValue: string[];
|
|
73
|
-
});
|
|
69
|
+
};
|
|
74
70
|
export type TreeSelectorDummyProps<A extends AdditionalDefault> = BaseTreeSelectorProps<A> & DummyProps;
|
|
75
71
|
export type TreeSelectorProps<A extends AdditionalDefault> = BaseTreeSelectorProps<A> & NonDummyProps;
|
|
76
72
|
export interface ListControls {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { useState, useLayoutEffect } from 'react';
|
|
3
|
+
|
|
4
|
+
var styles = {"item-animation-timeout":"magritte-item-animation-timeout___Pdli9_1-6-0","itemAnimationTimeout":"magritte-item-animation-timeout___Pdli9_1-6-0"};
|
|
5
|
+
|
|
6
|
+
const useAnimationTimeout = () => {
|
|
7
|
+
const [animationTimeout, setAnimationTimeout] = useState(0);
|
|
8
|
+
useLayoutEffect(() => {
|
|
9
|
+
const animationTimeoutElement = document.createElement('div');
|
|
10
|
+
animationTimeoutElement.classList.add(styles.itemAnimationTimeout);
|
|
11
|
+
document.body.appendChild(animationTimeoutElement);
|
|
12
|
+
const style = window.getComputedStyle(animationTimeoutElement);
|
|
13
|
+
const animationTimeout = parseInt(style.getPropertyValue(`--animation-duration`), 10);
|
|
14
|
+
if (Number.isInteger(animationTimeout)) {
|
|
15
|
+
setAnimationTimeout(animationTimeout);
|
|
16
|
+
}
|
|
17
|
+
document.body.removeChild(animationTimeoutElement);
|
|
18
|
+
}, []);
|
|
19
|
+
return { animationTimeout };
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useAnimationTimeout };
|
|
23
|
+
//# sourceMappingURL=useAnimationTimeout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnimationTimeout.js","sources":["../src/useAnimationTimeout.ts"],"sourcesContent":["import { useLayoutEffect, useState } from 'react';\n\nimport styles from './animation.less';\n\ninterface UseAnimationTimeoutHook {\n (): { animationTimeout: number };\n}\n\nexport const useAnimationTimeout: UseAnimationTimeoutHook = () => {\n const [animationTimeout, setAnimationTimeout] = useState(0);\n\n useLayoutEffect(() => {\n const animationTimeoutElement = document.createElement('div');\n animationTimeoutElement.classList.add(styles.itemAnimationTimeout);\n document.body.appendChild(animationTimeoutElement);\n const style = window.getComputedStyle(animationTimeoutElement);\n const animationTimeout = parseInt(style.getPropertyValue(`--animation-duration`), 10);\n if (Number.isInteger(animationTimeout)) {\n setAnimationTimeout(animationTimeout);\n }\n document.body.removeChild(animationTimeoutElement);\n }, []);\n\n return { animationTimeout };\n};\n"],"names":[],"mappings":";;;;AAQO,MAAM,mBAAmB,GAA4B,MAAK;IAC7D,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5D,eAAe,CAAC,MAAK;QACjB,MAAM,uBAAuB,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9D,uBAAuB,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;AACnE,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC;QACnD,MAAM,KAAK,GAAG,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,CAAC,CAAC;AAC/D,QAAA,MAAM,gBAAgB,GAAG,QAAQ,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAsB,oBAAA,CAAA,CAAC,EAAE,EAAE,CAAC,CAAC;AACtF,QAAA,IAAI,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,EAAE;YACpC,mBAAmB,CAAC,gBAAgB,CAAC,CAAC;AACzC,SAAA;AACD,QAAA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC;KACtD,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAChC;;;;"}
|
package/useDisabled.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import TreeCollection from './collection/treeCollection';
|
|
2
1
|
import { AdditionalDefault } from './collection/types';
|
|
3
|
-
|
|
2
|
+
import { TreeSelectorProps } from './types';
|
|
3
|
+
type UseDisabledHookProps<A extends AdditionalDefault> = {
|
|
4
4
|
selected: string[];
|
|
5
|
-
|
|
6
|
-
collection: TreeCollection<A>;
|
|
7
|
-
maxSelected?: number;
|
|
8
|
-
}
|
|
5
|
+
} & Pick<TreeSelectorProps<A>, 'disabled' | 'collection' | 'maxSelected'>;
|
|
9
6
|
interface UseDisabledHook {
|
|
10
7
|
<A extends AdditionalDefault>(props: UseDisabledHookProps<A>): string[] | undefined;
|
|
11
8
|
}
|
package/useDisabled.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDisabled.js","sources":["../src/useDisabled.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport
|
|
1
|
+
{"version":3,"file":"useDisabled.js","sources":["../src/useDisabled.ts"],"sourcesContent":["import { useMemo } from 'react';\n\nimport { getIdsWithNoParentsInSameList } from '@hh.ru/magritte-ui-tree-selector/collection/treeCollectionHelper';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { TreeSelectorProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\ntype UseDisabledHookProps<A extends AdditionalDefault> = {\n selected: string[];\n} & Pick<TreeSelectorProps<A>, 'disabled' | 'collection' | 'maxSelected'>;\ninterface UseDisabledHook {\n <A extends AdditionalDefault>(props: UseDisabledHookProps<A>): string[] | undefined;\n}\n\nexport const useDisabled: UseDisabledHook = ({ selected, disabled, collection, maxSelected }) => {\n return useMemo(() => {\n const valueIds = getIdsWithNoParentsInSameList(collection, selected);\n if (maxSelected && valueIds.length >= maxSelected) {\n return collection\n .toList()\n .map(({ id }) => id)\n .filter((id) => !selected.includes(id));\n }\n return disabled;\n }, [selected, collection, disabled, maxSelected]);\n};\n"],"names":[],"mappings":";;;;AAaO,MAAM,WAAW,GAAoB,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,KAAI;IAC5F,OAAO,OAAO,CAAC,MAAK;QAChB,MAAM,QAAQ,GAAG,6BAA6B,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AACrE,QAAA,IAAI,WAAW,IAAI,QAAQ,CAAC,MAAM,IAAI,WAAW,EAAE;AAC/C,YAAA,OAAO,UAAU;AACZ,iBAAA,MAAM,EAAE;iBACR,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AACnB,iBAAA,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/C,SAAA;AACD,QAAA,OAAO,QAAQ,CAAC;KACnB,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;AACtD;;;;"}
|
package/useRenderInput.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { useState, useEffect, useCallback } from 'react';
|
|
4
|
+
import { useDebounce } from '@hh.ru/magritte-common-func-utils';
|
|
4
5
|
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
5
6
|
import { SearchInput } from '@hh.ru/magritte-ui-input';
|
|
7
|
+
import { useAnimationTimeout } from './useAnimationTimeout.js';
|
|
6
8
|
|
|
7
9
|
const useRenderInput = () => {
|
|
8
10
|
const [contentFilterQuery, setContentFilterQuery] = useState('');
|
|
11
|
+
const { animationTimeout } = useAnimationTimeout();
|
|
9
12
|
const [value, setValue] = useState('');
|
|
10
13
|
const { isMobile } = useBreakpoint();
|
|
11
14
|
useEffect(() => {
|
|
12
15
|
setValue('');
|
|
13
16
|
setContentFilterQuery('');
|
|
14
17
|
}, [isMobile]);
|
|
15
|
-
const
|
|
18
|
+
const debouncedContentFilterQuery = useDebounce(useCallback((newValue) => {
|
|
16
19
|
setContentFilterQuery(newValue);
|
|
20
|
+
}, []), animationTimeout);
|
|
21
|
+
const handleChangeInput = useCallback((newValue) => {
|
|
22
|
+
debouncedContentFilterQuery(newValue);
|
|
17
23
|
setValue(newValue);
|
|
18
|
-
}, [
|
|
24
|
+
}, [debouncedContentFilterQuery]);
|
|
19
25
|
const setInputValue = useCallback((newValue) => {
|
|
20
26
|
setValue(newValue);
|
|
21
27
|
}, [setValue]);
|
package/useRenderInput.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderInput.js","sources":["../src/useRenderInput.tsx"],"sourcesContent":["import { ReactElement, useCallback, useEffect, useState } from 'react';\n\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { SearchInput } from '@hh.ru/magritte-ui-input';\n\nexport interface UseRenderInputHook {\n (): {\n contentFilterQuery: string;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n renderInput: () => ReactElement;\n };\n}\n\nexport const useRenderInput: UseRenderInputHook = () => {\n const [contentFilterQuery, setContentFilterQuery] = useState('');\n const [value, setValue] = useState('');\n const { isMobile } = useBreakpoint();\n\n useEffect(() => {\n setValue('');\n setContentFilterQuery('');\n }, [isMobile]);\n\n const handleChangeInput = useCallback(\n (newValue: string) => {\n
|
|
1
|
+
{"version":3,"file":"useRenderInput.js","sources":["../src/useRenderInput.tsx"],"sourcesContent":["import { ReactElement, useCallback, useEffect, useState } from 'react';\n\nimport { useDebounce } from '@hh.ru/magritte-common-func-utils';\nimport { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';\nimport { SearchInput } from '@hh.ru/magritte-ui-input';\nimport { useAnimationTimeout } from '@hh.ru/magritte-ui-tree-selector/useAnimationTimeout';\n\nexport interface UseRenderInputHook {\n (): {\n contentFilterQuery: string;\n setInputValue: (newValue: string) => void;\n handleChangeInput: (newValue: string) => void;\n renderInput: () => ReactElement;\n };\n}\n\nexport const useRenderInput: UseRenderInputHook = () => {\n const [contentFilterQuery, setContentFilterQuery] = useState('');\n const { animationTimeout } = useAnimationTimeout();\n const [value, setValue] = useState('');\n const { isMobile } = useBreakpoint();\n\n useEffect(() => {\n setValue('');\n setContentFilterQuery('');\n }, [isMobile]);\n\n const debouncedContentFilterQuery = useDebounce(\n useCallback((newValue: string) => {\n setContentFilterQuery(newValue);\n }, []),\n animationTimeout\n );\n\n const handleChangeInput = useCallback(\n (newValue: string) => {\n debouncedContentFilterQuery(newValue);\n setValue(newValue);\n },\n [debouncedContentFilterQuery]\n );\n\n const setInputValue = useCallback(\n (newValue: string) => {\n setValue(newValue);\n },\n [setValue]\n );\n\n const renderInput = useCallback(() => {\n return <SearchInput value={value} onChange={handleChangeInput} />;\n }, [value, handleChangeInput]);\n\n return { contentFilterQuery, setInputValue, handleChangeInput, renderInput };\n};\n"],"names":["_jsx"],"mappings":";;;;;;;AAgBO,MAAM,cAAc,GAAuB,MAAK;IACnD,MAAM,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;AACjE,IAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,mBAAmB,EAAE,CAAC;IACnD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvC,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IAErC,SAAS,CAAC,MAAK;QACX,QAAQ,CAAC,EAAE,CAAC,CAAC;QACb,qBAAqB,CAAC,EAAE,CAAC,CAAC;AAC9B,KAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,MAAM,2BAA2B,GAAG,WAAW,CAC3C,WAAW,CAAC,CAAC,QAAgB,KAAI;QAC7B,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACpC,KAAC,EAAE,EAAE,CAAC,EACN,gBAAgB,CACnB,CAAC;AAEF,IAAA,MAAM,iBAAiB,GAAG,WAAW,CACjC,CAAC,QAAgB,KAAI;QACjB,2BAA2B,CAAC,QAAQ,CAAC,CAAC;QACtC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvB,KAAC,EACD,CAAC,2BAA2B,CAAC,CAChC,CAAC;AAEF,IAAA,MAAM,aAAa,GAAG,WAAW,CAC7B,CAAC,QAAgB,KAAI;QACjB,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvB,KAAC,EACD,CAAC,QAAQ,CAAC,CACb,CAAC;AAEF,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,MAAK;QACjC,OAAOA,GAAA,CAAC,WAAW,EAAA,EAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAA,CAAI,CAAC;AACtE,KAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAE/B,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,CAAC;AACjF;;;;"}
|
package/useSelected.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
import TreeCollection from './collection/treeCollection';
|
|
2
1
|
import { AdditionalDefault } from './collection/types';
|
|
3
2
|
import ImmutableSelectionStrategy from './strategy/immutableSelectionStrategy';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
initialValue?: string[];
|
|
3
|
+
import { TreeSelectorProps } from './types';
|
|
4
|
+
type UseSelectedHookProps<A extends AdditionalDefault> = {
|
|
7
5
|
strategy: ImmutableSelectionStrategy<A>;
|
|
8
|
-
|
|
9
|
-
onChange?: (id: string, isSelected: boolean, allSelected: string[]) => void;
|
|
10
|
-
collapseToParentId?: boolean;
|
|
11
|
-
maxSelected?: number;
|
|
12
|
-
}
|
|
6
|
+
} & Pick<TreeSelectorProps<A>, 'value' | 'onChange' | 'collapseToParentId' | 'maxSelected' | 'collection'>;
|
|
13
7
|
type UseSelectedHookReturn = {
|
|
14
8
|
selected: string[];
|
|
15
9
|
setSelected: (id: string, isSelected: boolean) => void;
|
package/useSelected.js
CHANGED
|
@@ -3,18 +3,15 @@ import { useCallback, useState, useRef, useEffect } from 'react';
|
|
|
3
3
|
import { getIdsWithNoParentsInSameList } from './collection/treeCollectionHelper.js';
|
|
4
4
|
import './collection/treeCollection.js';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const useSelected = ({ value, initialValue = defaultArray, maxSelected, strategy, collection, collapseToParentId, onChange, }) => {
|
|
6
|
+
const useSelected = ({ value, maxSelected, strategy, collection, collapseToParentId, onChange, }) => {
|
|
8
7
|
const getSelectedFromValue = useCallback(() => {
|
|
9
|
-
let newValue = value
|
|
8
|
+
let newValue = value.slice();
|
|
10
9
|
if (maxSelected && newValue && newValue.length > maxSelected) {
|
|
11
10
|
newValue = newValue.slice(0, maxSelected);
|
|
12
11
|
}
|
|
13
12
|
return strategy.add([], newValue);
|
|
14
13
|
}, [value, maxSelected, strategy]);
|
|
15
|
-
const
|
|
16
|
-
const slicedInitialValue = initialValue && maxSelected ? initialValue.slice(0, maxSelected) : initialValue;
|
|
17
|
-
const [selected, setSelectedState] = useState(isControlled ? getSelectedFromValue : slicedInitialValue);
|
|
14
|
+
const [selected, setSelectedState] = useState(getSelectedFromValue);
|
|
18
15
|
const firstRender = useRef(true);
|
|
19
16
|
const setSelected = useCallback((id, isSelected) => {
|
|
20
17
|
const ids = [id];
|
|
@@ -25,21 +22,16 @@ const useSelected = ({ value, initialValue = defaultArray, maxSelected, strategy
|
|
|
25
22
|
if (maxSelected && filteredUpdatedSelected.length > maxSelected) {
|
|
26
23
|
filteredUpdatedSelected.length = maxSelected;
|
|
27
24
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
onChange?.(id, isSelected, filteredUpdatedSelected);
|
|
32
|
-
}, [strategy, selected, collection, collapseToParentId, onChange, isControlled, maxSelected]);
|
|
25
|
+
onChange(filteredUpdatedSelected, id, isSelected);
|
|
26
|
+
}, [strategy, selected, collection, collapseToParentId, onChange, maxSelected]);
|
|
33
27
|
useEffect(() => {
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const selected = getSelectedFromValue();
|
|
40
|
-
setSelectedState(selected);
|
|
28
|
+
if (firstRender.current) {
|
|
29
|
+
firstRender.current = false;
|
|
30
|
+
return;
|
|
41
31
|
}
|
|
42
|
-
|
|
32
|
+
const selected = getSelectedFromValue();
|
|
33
|
+
setSelectedState(selected);
|
|
34
|
+
}, [getSelectedFromValue, firstRender]);
|
|
43
35
|
return {
|
|
44
36
|
selected,
|
|
45
37
|
setSelected,
|
package/useSelected.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSelected.js","sources":["../src/useSelected.ts"],"sourcesContent":["import { useState, useCallback, useRef, useEffect } from 'react';\n\nimport
|
|
1
|
+
{"version":3,"file":"useSelected.js","sources":["../src/useSelected.ts"],"sourcesContent":["import { useState, useCallback, useRef, useEffect } from 'react';\n\nimport { getIdsWithNoParentsInSameList } from '@hh.ru/magritte-ui-tree-selector/collection/treeCollectionHelper';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { TreeSelectorProps } from '@hh.ru/magritte-ui-tree-selector/types';\n\ntype UseSelectedHookProps<A extends AdditionalDefault> = {\n strategy: ImmutableSelectionStrategy<A>;\n} & Pick<TreeSelectorProps<A>, 'value' | 'onChange' | 'collapseToParentId' | 'maxSelected' | 'collection'>;\n\ntype UseSelectedHookReturn = {\n selected: string[];\n setSelected: (id: string, isSelected: boolean) => void;\n};\n\ninterface UseSelectedHook {\n <A extends AdditionalDefault>(props: UseSelectedHookProps<A>): UseSelectedHookReturn;\n}\n\nexport const useSelected: UseSelectedHook = ({\n value,\n maxSelected,\n strategy,\n collection,\n collapseToParentId,\n onChange,\n}) => {\n const getSelectedFromValue = useCallback((): string[] => {\n let newValue = value.slice();\n if (maxSelected && newValue && newValue.length > maxSelected) {\n newValue = newValue.slice(0, maxSelected);\n }\n return strategy.add([], newValue);\n }, [value, maxSelected, strategy]);\n\n const [selected, setSelectedState] = useState(getSelectedFromValue);\n const firstRender = useRef(true);\n\n const setSelected = useCallback(\n (id: string, isSelected: boolean) => {\n const ids = [id];\n const updatedSelected = isSelected ? strategy.add(selected, ids) : strategy.remove(selected, ids);\n const filteredUpdatedSelected = collapseToParentId\n ? getIdsWithNoParentsInSameList(collection, updatedSelected)\n : updatedSelected;\n if (maxSelected && filteredUpdatedSelected.length > maxSelected) {\n filteredUpdatedSelected.length = maxSelected;\n }\n\n onChange(filteredUpdatedSelected, id, isSelected);\n },\n [strategy, selected, collection, collapseToParentId, onChange, maxSelected]\n );\n\n useEffect(() => {\n if (firstRender.current) {\n firstRender.current = false;\n return;\n }\n\n const selected = getSelectedFromValue();\n\n setSelectedState(selected);\n }, [getSelectedFromValue, firstRender]);\n\n return {\n selected,\n setSelected,\n };\n};\n"],"names":[],"mappings":";;;;AAoBa,MAAA,WAAW,GAAoB,CAAC,EACzC,KAAK,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,QAAQ,GACX,KAAI;AACD,IAAA,MAAM,oBAAoB,GAAG,WAAW,CAAC,MAAe;AACpD,QAAA,IAAI,QAAQ,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,WAAW,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,WAAW,EAAE;YAC1D,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAC7C,SAAA;QACD,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;KACrC,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEnC,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AACpE,IAAA,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAEjC,MAAM,WAAW,GAAG,WAAW,CAC3B,CAAC,EAAU,EAAE,UAAmB,KAAI;AAChC,QAAA,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC;QACjB,MAAM,eAAe,GAAG,UAAU,GAAG,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QAClG,MAAM,uBAAuB,GAAG,kBAAkB;AAC9C,cAAE,6BAA6B,CAAC,UAAU,EAAE,eAAe,CAAC;cAC1D,eAAe,CAAC;AACtB,QAAA,IAAI,WAAW,IAAI,uBAAuB,CAAC,MAAM,GAAG,WAAW,EAAE;AAC7D,YAAA,uBAAuB,CAAC,MAAM,GAAG,WAAW,CAAC;AAChD,SAAA;AAED,QAAA,QAAQ,CAAC,uBAAuB,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;AACtD,KAAC,EACD,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,QAAQ,EAAE,WAAW,CAAC,CAC9E,CAAC;IAEF,SAAS,CAAC,MAAK;QACX,IAAI,WAAW,CAAC,OAAO,EAAE;AACrB,YAAA,WAAW,CAAC,OAAO,GAAG,KAAK,CAAC;YAC5B,OAAO;AACV,SAAA;AAED,QAAA,MAAM,QAAQ,GAAG,oBAAoB,EAAE,CAAC;QAExC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;AAC/B,KAAC,EAAE,CAAC,oBAAoB,EAAE,WAAW,CAAC,CAAC,CAAC;IAExC,OAAO;QACH,QAAQ;QACR,WAAW;KACd,CAAC;AACN;;;;"}
|
package/ItemContent-cec51c98.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import './index.css';
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
import { DotFilledSize24, ChevronDownOutlinedSize24, ChevronUpOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
6
|
-
import { Action } from './Action.js';
|
|
7
|
-
import { TreeSelectorItemBase } from './TreeSelectorItemBase.js';
|
|
8
|
-
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
9
|
-
|
|
10
|
-
var styles = {"wrapper":"magritte-wrapper___GHKV6_1-5-1","letter":"magritte-letter___yZOCU_1-5-1","icon":"magritte-icon___kO3Fj_1-5-1","space":"magritte-space___xTO79_1-5-1","iconActive":"magritte-iconActive___4yrG5_1-5-1","content":"magritte-content___ZRc6R_1-5-1","with-shift":"magritte-with-shift___ZErxZ_1-5-1","withShift":"magritte-with-shift___ZErxZ_1-5-1","with-indent":"magritte-with-indent___MH9Vy_1-5-1","withIndent":"magritte-with-indent___MH9Vy_1-5-1","item":"magritte-item___2LtOL_1-5-1","children":"magritte-children___kq-eq_1-5-1","with-two-boxes":"magritte-with-two-boxes___LWOy2_1-5-1","withTwoBoxes":"magritte-with-two-boxes___LWOy2_1-5-1","with-three-boxes":"magritte-with-three-boxes___cyVao_1-5-1","withThreeBoxes":"magritte-with-three-boxes___cyVao_1-5-1"};
|
|
11
|
-
|
|
12
|
-
const ItemContent = ({ item, hasAction, hasChildren, letter, isExpanded, isDisabled, onExpansion, hasLetterOnLevel, isSelected, onChange, isIndeterminate, singleChoice, hasDot, maxControlsOnLevel, isSearch, renderItemForDesktop = TreeSelectorItemBase, }) => {
|
|
13
|
-
const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);
|
|
14
|
-
const currentActionCount = +hasDot + +hasAction + +hasChildren;
|
|
15
|
-
const neededSpacesCount = maxControlsOnLevel - currentActionCount;
|
|
16
|
-
const input = hasAction ? (jsx(Action, { selected: isSelected, onChange: onChange, id: item.id, indeterminate: isIndeterminate, singleChoice: singleChoice })) : undefined;
|
|
17
|
-
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 && (jsxs("div", { className: classnames(styles.icon, {
|
|
18
|
-
[styles.iconActive]: hasChildren,
|
|
19
|
-
}), onClick: handleExpandableClick, children: [isExpanded && jsx(ChevronDownOutlinedSize24, { initial: "tertiary" }), !isExpanded && jsx(ChevronUpOutlinedSize24, { initial: "tertiary" })] })), renderItemForDesktop({ disabled: isDisabled, input, item, isSearch, isParent: hasChildren })] }));
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export { ItemContent as I, styles as s };
|
|
23
|
-
//# sourceMappingURL=ItemContent-cec51c98.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemContent-cec51c98.js","sources":["../src/ItemContent.tsx"],"sourcesContent":["import { ReactElement, useCallback } from 'react';\nimport classnames from 'classnames';\n\nimport { ChevronDownOutlinedSize24, 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 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;\n isSearch: boolean;\n}\n\nconst ItemContent = <A extends AdditionalDefault>({\n item,\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 input = hasAction ? (\n <Action\n selected={isSelected}\n onChange={onChange}\n id={item.id}\n indeterminate={isIndeterminate}\n singleChoice={singleChoice}\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, {\n [styles.iconActive]: hasChildren,\n })}\n onClick={handleExpandableClick}\n >\n {isExpanded && <ChevronDownOutlinedSize24 initial=\"tertiary\" />}\n {!isExpanded && <ChevronUpOutlinedSize24 initial=\"tertiary\" />}\n </div>\n )}\n {renderItemForDesktop({ disabled: isDisabled, input, item, isSearch, isParent: hasChildren })}\n </div>\n );\n};\n\nexport { ItemContent };\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;;AA+BA,MAAM,WAAW,GAAG,CAA8B,EAC9C,IAAI,EACJ,SAAS,EACT,WAAW,EACX,MAAM,EACN,UAAU,EACV,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,QAAQ,EACR,eAAe,EACf,YAAY,E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