@hh.ru/magritte-ui-tree-selector 1.1.5 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Action.d.ts +1 -1
- package/Action.js.map +1 -1
- package/Item.js +21 -22
- package/Item.js.map +1 -1
- package/ItemContent-59665486.js +22 -0
- package/ItemContent-59665486.js.map +1 -0
- package/ItemContent.d.ts +3 -3
- package/ItemContent.js +1 -1
- package/ItemsList.js +1 -1
- package/MobileItem.d.ts +11 -0
- package/MobileItem.js +14 -0
- package/MobileItem.js.map +1 -0
- package/MobileItemsList.d.ts +14 -0
- package/MobileItemsList.js +34 -0
- package/MobileItemsList.js.map +1 -0
- package/MobileParentItem.d.ts +11 -0
- package/MobileParentItem.js +21 -0
- package/MobileParentItem.js.map +1 -0
- package/TreeSelector.d.ts +3 -3
- package/TreeSelector.js +14 -5
- package/TreeSelector.js.map +1 -1
- package/UncontrolledTreeSelector.d.ts +6 -3
- package/UncontrolledTreeSelector.js +12 -4
- package/UncontrolledTreeSelector.js.map +1 -1
- package/index.css +14 -22
- package/index.d.ts +2 -0
- package/index.js +18 -2
- package/index.js.map +1 -1
- package/package.json +6 -2
- package/types.d.ts +4 -1
- package/ItemContent-ad35f8ca.js +0 -20
- package/ItemContent-ad35f8ca.js.map +0 -1
package/Action.d.ts
CHANGED
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
|
|
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;AAC/F,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;;;;"}
|
package/Item.js
CHANGED
|
@@ -2,7 +2,7 @@ import './index.css';
|
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
import classnames from 'classnames';
|
|
5
|
-
import { s as styles, I as ItemContent } from './ItemContent-
|
|
5
|
+
import { s as styles, I as ItemContent } from './ItemContent-59665486.js';
|
|
6
6
|
import '@hh.ru/magritte-ui-cell';
|
|
7
7
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
8
8
|
import './Action.js';
|
|
@@ -11,35 +11,34 @@ import '@hh.ru/magritte-ui-typography';
|
|
|
11
11
|
|
|
12
12
|
const Item = ({ collection, item, parentId, isExpanded, isSelected, isIndeterminate, leavesOnly, singleChoice, checkSelectable, onExpansion, onChange, children, }) => {
|
|
13
13
|
const modelsOnLevel = useMemo(() => (parentId ? collection.getChildren(parentId) : collection.getTopLevel()), [parentId, collection]);
|
|
14
|
-
const hasChildrenOnLevel = useMemo(() => {
|
|
15
|
-
return modelsOnLevel.some((model) => {
|
|
16
|
-
return collection.hasChildren(model.id);
|
|
17
|
-
});
|
|
18
|
-
}, [modelsOnLevel, collection]);
|
|
19
|
-
const hasActionOnLevel = useMemo(() => {
|
|
20
|
-
return modelsOnLevel.some((model) => {
|
|
21
|
-
const hasChildren = collection.hasChildren(model.id);
|
|
22
|
-
const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(model.id, collection);
|
|
23
|
-
return hasAction;
|
|
24
|
-
});
|
|
25
|
-
}, [modelsOnLevel, collection, leavesOnly, checkSelectable]);
|
|
26
14
|
const hasLetterOnLevel = useMemo(() => {
|
|
27
15
|
return modelsOnLevel.some((model) => model.additional?.char);
|
|
28
16
|
}, [modelsOnLevel]);
|
|
17
|
+
// максимальное кол-во контролов на уровне, максимум может быть 2 - шеврон + чекбокс/радио
|
|
18
|
+
const maxControlsOnLevel = useMemo(() => {
|
|
19
|
+
return modelsOnLevel.reduce((currentMax, model) => {
|
|
20
|
+
const hasChildren = collection.hasChildren(model.id);
|
|
21
|
+
const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(model.id, collection);
|
|
22
|
+
const actionCount = +hasChildren + +!!hasAction;
|
|
23
|
+
return Math.max(currentMax, actionCount);
|
|
24
|
+
}, 0);
|
|
25
|
+
}, [modelsOnLevel, checkSelectable, leavesOnly, collection]);
|
|
29
26
|
const hasChildren = collection.hasChildren(item.id);
|
|
30
27
|
const hasAction = !(leavesOnly && hasChildren) && checkSelectable?.(item.id, collection);
|
|
31
28
|
const hasLetter = item.additional?.char;
|
|
29
|
+
const realControlsCount = +hasChildren + +!!hasAction;
|
|
30
|
+
// точка заменяет недостающий контрол, если их суммарное кол-во на уровне больше суммарного значения на текущем уровне
|
|
31
|
+
const hasDot = realControlsCount < maxControlsOnLevel && (hasAction || hasChildren);
|
|
32
32
|
const hasParentAction = parentId ? !leavesOnly && checkSelectable?.(parentId, collection) : false;
|
|
33
|
-
const
|
|
34
|
-
const hasShift =
|
|
35
|
-
((hasParentAction && (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
[styles.
|
|
39
|
-
[styles.withChevron]: hasChildren || hasChildrenOnLevel,
|
|
40
|
-
[styles.withAction]: hasAction || hasActionOnLevel,
|
|
33
|
+
const allBoxesCount = +hasLetterOnLevel + maxControlsOnLevel;
|
|
34
|
+
const hasShift = allBoxesCount > 1 &&
|
|
35
|
+
((hasParentAction && (hasLetterOnLevel || hasChildren || hasDot)) || (!hasParentAction && hasLetterOnLevel));
|
|
36
|
+
return (jsxs("div", { className: classnames(styles.item, {
|
|
37
|
+
[styles.withTwoBoxes]: allBoxesCount === 2,
|
|
38
|
+
[styles.withThreeBoxes]: allBoxesCount === 3,
|
|
41
39
|
[styles.withShift]: hasShift && parentId,
|
|
42
|
-
|
|
40
|
+
[styles.withIndent]: allBoxesCount === 0,
|
|
41
|
+
}), children: [jsx(ItemContent, { item: item, hasChildren: hasChildren, hasAction: !!hasAction, letter: hasLetter, expanded: isExpanded, onExpansion: onExpansion, selected: isSelected, onChange: onChange, singleChoice: singleChoice, indeterminate: isIndeterminate, hasLetterOnLevel: hasLetterOnLevel, hasDot: hasDot, maxControlsOnLevel: maxControlsOnLevel }), children && jsx("div", { className: styles.children, children: children })] }));
|
|
43
42
|
};
|
|
44
43
|
|
|
45
44
|
export { Item };
|
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';\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 singleChoice?: boolean;\n isIndeterminate: boolean;\n onExpansion: (id: string) => void;\n onChange: (id: string, isSelected: boolean) => void;\n}\n\nexport const Item = <A extends AdditionalDefault>({\n collection,\n item,\n parentId,\n isExpanded,\n isSelected,\n isIndeterminate,\n leavesOnly,\n singleChoice,\n checkSelectable,\n onExpansion,\n onChange,\n children,\n}: ItemProps<A>): ReactElement => {\n const modelsOnLevel = useMemo(\n () => (parentId ? collection.getChildren(parentId) : collection.getTopLevel()),\n [parentId, collection]\n );\n const
|
|
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';\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 singleChoice?: boolean;\n isIndeterminate: boolean;\n onExpansion: (id: string) => void;\n onChange: (id: string, isSelected: boolean) => void;\n}\n\nexport const Item = <A extends AdditionalDefault>({\n collection,\n item,\n parentId,\n isExpanded,\n isSelected,\n isIndeterminate,\n leavesOnly,\n singleChoice,\n checkSelectable,\n onExpansion,\n onChange,\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 modelsOnLevel.some((model) => model.additional?.char);\n }, [modelsOnLevel]);\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;\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}\n expanded={isExpanded}\n onExpansion={onExpansion}\n selected={isSelected}\n onChange={onChange}\n singleChoice={singleChoice}\n indeterminate={isIndeterminate}\n hasLetterOnLevel={hasLetterOnLevel}\n hasDot={hasDot}\n maxControlsOnLevel={maxControlsOnLevel}\n />\n {children && <div className={styles.children}>{children}</div>}\n </div>\n );\n};\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AAuBO,MAAM,IAAI,GAAG,CAA8B,EAC9C,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,YAAY,EACZ,eAAe,EACf,WAAW,EACX,QAAQ,EACR,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,aAAa,CAAC,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACjE,KAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;;AAGpB,IAAA,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAK;QACpC,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,KAAK,KAAI;YAC9C,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACrD,YAAA,MAAM,SAAS,GAAG,EAAE,UAAU,IAAI,WAAW,CAAC,IAAI,eAAe,GAAG,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;YAC1F,MAAM,WAAW,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;YAChD,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;SAC5C,EAAE,CAAC,CAAC,CAAC;KACT,EAAE,CAAC,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;IAE7D,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpD,IAAA,MAAM,SAAS,GAAG,EAAE,UAAU,IAAI,WAAW,CAAC,IAAI,eAAe,GAAG,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC;AACzF,IAAA,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC;IACxC,MAAM,iBAAiB,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;;IAGtD,MAAM,MAAM,GAAG,iBAAiB,GAAG,kBAAkB,KAAK,SAAS,IAAI,WAAW,CAAC,CAAC;IACpF,MAAM,eAAe,GAAG,QAAQ,GAAG,CAAC,UAAU,IAAI,eAAe,GAAG,QAAQ,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;AAElG,IAAA,MAAM,aAAa,GAAG,CAAC,gBAAgB,GAAG,kBAAkB,CAAC;AAE7D,IAAA,MAAM,QAAQ,GACV,aAAa,GAAG,CAAC;AACjB,SAAC,CAAC,eAAe,KAAK,gBAAgB,IAAI,WAAW,IAAI,MAAM,CAAC,MAAM,CAAC,eAAe,IAAI,gBAAgB,CAAC,CAAC,CAAC;IAEjH,QACIA,cACI,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE;AAC/B,YAAA,CAAC,MAAM,CAAC,YAAY,GAAG,aAAa,KAAK,CAAC;AAC1C,YAAA,CAAC,MAAM,CAAC,cAAc,GAAG,aAAa,KAAK,CAAC;AAC5C,YAAA,CAAC,MAAM,CAAC,SAAS,GAAG,QAAQ,IAAI,QAAQ;AACxC,YAAA,CAAC,MAAM,CAAC,UAAU,GAAG,aAAa,KAAK,CAAC;AAC3C,SAAA,CAAC,EAEF,QAAA,EAAA,CAAAC,GAAA,CAAC,WAAW,EAAA,EACR,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,CAAC,CAAC,SAAS,EACtB,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,UAAU,EACpB,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,eAAe,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,MAAM,EAAE,MAAM,EACd,kBAAkB,EAAE,kBAAkB,EACxC,CAAA,EACD,QAAQ,IAAIA,aAAK,SAAS,EAAE,MAAM,CAAC,QAAQ,EAAG,QAAA,EAAA,QAAQ,EAAO,CAAA,CAAA,EAAA,CAC5D,EACR;AACN;;;;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
|
|
6
|
+
import { DotFilledSize24, ChevronDownOutlinedSize24, ChevronUpOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
7
|
+
import { Action } from './Action.js';
|
|
8
|
+
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
9
|
+
|
|
10
|
+
var styles = {"wrapper":"magritte-wrapper___GHKV6_1-2-0","letter":"magritte-letter___yZOCU_1-2-0","icon":"magritte-icon___kO3Fj_1-2-0","space":"magritte-space___xTO79_1-2-0","iconActive":"magritte-iconActive___4yrG5_1-2-0","content":"magritte-content___ZRc6R_1-2-0","with-shift":"magritte-with-shift___ZErxZ_1-2-0","withShift":"magritte-with-shift___ZErxZ_1-2-0","with-indent":"magritte-with-indent___MH9Vy_1-2-0","withIndent":"magritte-with-indent___MH9Vy_1-2-0","item":"magritte-item___2LtOL_1-2-0","children":"magritte-children___kq-eq_1-2-0","with-two-boxes":"magritte-with-two-boxes___LWOy2_1-2-0","withTwoBoxes":"magritte-with-two-boxes___LWOy2_1-2-0","with-three-boxes":"magritte-with-three-boxes___cyVao_1-2-0","withThreeBoxes":"magritte-with-three-boxes___cyVao_1-2-0"};
|
|
11
|
+
|
|
12
|
+
const ItemContent = ({ item, hasAction, hasChildren, letter, expanded, onExpansion, hasLetterOnLevel, selected, onChange, indeterminate, singleChoice, hasDot, maxControlsOnLevel, }) => {
|
|
13
|
+
const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);
|
|
14
|
+
const currentActionCount = +hasDot + +hasAction + +hasChildren;
|
|
15
|
+
const neededSpacesCount = maxControlsOnLevel - currentActionCount;
|
|
16
|
+
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, {
|
|
17
|
+
[styles.iconActive]: hasChildren,
|
|
18
|
+
}), onClick: handleExpandableClick, children: [expanded && jsx(ChevronDownOutlinedSize24, { initial: "tertiary" }), !expanded && jsx(ChevronUpOutlinedSize24, { initial: "tertiary" })] })), jsx(Cell, { left: hasAction ? (jsx(Action, { selected: selected, onChange: onChange, id: item.id, indeterminate: indeterminate, singleChoice: singleChoice })) : undefined, children: jsx(CellText, { children: item.text }) })] }));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export { ItemContent as I, styles as s };
|
|
22
|
+
//# sourceMappingURL=ItemContent-59665486.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ItemContent-59665486.js","sources":["../src/ItemContent.tsx"],"sourcesContent":["import { ReactElement, useCallback } from 'react';\nimport classnames from 'classnames';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { ChevronDownOutlinedSize24, ChevronUpOutlinedSize24, DotFilledSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/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 expanded?: boolean;\n selected: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n indeterminate: boolean;\n singleChoice?: boolean;\n hasLetterOnLevel: boolean;\n hasDot: boolean;\n maxControlsOnLevel: number;\n}\n\nconst ItemContent = <A extends AdditionalDefault>({\n item,\n hasAction,\n hasChildren,\n letter,\n expanded,\n onExpansion,\n hasLetterOnLevel,\n selected,\n onChange,\n indeterminate,\n singleChoice,\n hasDot,\n maxControlsOnLevel,\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 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 {expanded && <ChevronDownOutlinedSize24 initial=\"tertiary\" />}\n {!expanded && <ChevronUpOutlinedSize24 initial=\"tertiary\" />}\n </div>\n )}\n\n <Cell\n left={\n hasAction ? (\n <Action\n selected={selected}\n onChange={onChange}\n id={item.id}\n indeterminate={indeterminate}\n singleChoice={singleChoice}\n />\n ) : undefined\n }\n >\n <CellText>{item.text}</CellText>\n </Cell>\n </div>\n );\n};\n\nexport { ItemContent };\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AA2BA,MAAM,WAAW,GAAG,CAA8B,EAC9C,IAAI,EACJ,SAAS,EACT,WAAW,EACX,MAAM,EACN,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,MAAM,EACN,kBAAkB,GACL,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;IAElE,QACIA,IAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,OAAO,EAAA,QAAA,EAAA,CACzB,CAAC,MAAM,IAAI,gBAAgB,MACxBC,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,MAAM,EAAA,QAAA,EACxB,MAAM,KACHA,GAAA,CAAC,IAAI,EAAC,EAAA,UAAU,EAAC,qBAAqB,EAAC,KAAK,EAAC,WAAW,EAAC,OAAO,EAAC,MAAM,EAAA,QAAA,EAClE,MAAM,EACJ,CAAA,CACV,EACC,CAAA,CACT,EACA,MAAM,KACHA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,IAAI,YACvBA,GAAC,CAAA,eAAe,EAAC,EAAA,OAAO,EAAC,UAAU,GAAG,EACpC,CAAA,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,KACRD,IACI,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE;AAC/B,oBAAA,CAAC,MAAM,CAAC,UAAU,GAAG,WAAW;AACnC,iBAAA,CAAC,EACF,OAAO,EAAE,qBAAqB,EAAA,QAAA,EAAA,CAE7B,QAAQ,IAAIC,GAAA,CAAC,yBAAyB,EAAA,EAAC,OAAO,EAAC,UAAU,EAAG,CAAA,EAC5D,CAAC,QAAQ,IAAIA,GAAC,CAAA,uBAAuB,IAAC,OAAO,EAAC,UAAU,EAAA,CAAG,IAC1D,CACT,EAEDA,GAAC,CAAA,IAAI,IACD,IAAI,EACA,SAAS,IACLA,GAAA,CAAC,MAAM,EAAA,EACH,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,IAAI,CAAC,EAAE,EACX,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,GAC5B,IACF,SAAS,EAGjB,QAAA,EAAAA,GAAA,CAAC,QAAQ,EAAA,EAAA,QAAA,EAAE,IAAI,CAAC,IAAI,GAAY,EAC7B,CAAA,CAAA,EAAA,CACL,EACR;AACN;;;;"}
|
package/ItemContent.d.ts
CHANGED
|
@@ -7,13 +7,13 @@ interface ItemContent<A extends AdditionalDefault> {
|
|
|
7
7
|
letter?: string;
|
|
8
8
|
onExpansion: (id: string) => void;
|
|
9
9
|
expanded?: boolean;
|
|
10
|
-
hasChildrenOnLevel: boolean;
|
|
11
10
|
selected: boolean;
|
|
12
11
|
onChange: (id: string, isSelected: boolean) => void;
|
|
13
12
|
indeterminate: boolean;
|
|
14
13
|
singleChoice?: boolean;
|
|
15
|
-
hasActionOnLevel: boolean;
|
|
16
14
|
hasLetterOnLevel: boolean;
|
|
15
|
+
hasDot: boolean;
|
|
16
|
+
maxControlsOnLevel: number;
|
|
17
17
|
}
|
|
18
|
-
declare const ItemContent: <A extends AdditionalDefault>({ item, hasAction, hasChildren, letter, expanded, onExpansion,
|
|
18
|
+
declare const ItemContent: <A extends AdditionalDefault>({ item, hasAction, hasChildren, letter, expanded, onExpansion, hasLetterOnLevel, selected, onChange, indeterminate, singleChoice, hasDot, maxControlsOnLevel, }: ItemContent<A>) => ReactElement;
|
|
19
19
|
export { ItemContent };
|
package/ItemContent.js
CHANGED
|
@@ -6,6 +6,6 @@ import '@hh.ru/magritte-ui-cell';
|
|
|
6
6
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
7
7
|
import './Action.js';
|
|
8
8
|
import '@hh.ru/magritte-ui-typography';
|
|
9
|
-
export { I as ItemContent } from './ItemContent-
|
|
9
|
+
export { I as ItemContent } from './ItemContent-59665486.js';
|
|
10
10
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
11
11
|
//# sourceMappingURL=ItemContent.js.map
|
package/ItemsList.js
CHANGED
|
@@ -3,7 +3,7 @@ import { jsx, Fragment } from 'react/jsx-runtime';
|
|
|
3
3
|
import { Item } from './Item.js';
|
|
4
4
|
import 'react';
|
|
5
5
|
import 'classnames';
|
|
6
|
-
import './ItemContent-
|
|
6
|
+
import './ItemContent-59665486.js';
|
|
7
7
|
import '@hh.ru/magritte-ui-cell';
|
|
8
8
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
9
9
|
import './Action.js';
|
package/MobileItem.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { AdditionalDefault, TreeModel } from './collection/types';
|
|
3
|
+
interface MobileItemProps<A extends AdditionalDefault> {
|
|
4
|
+
item: TreeModel<A>;
|
|
5
|
+
singleChoice?: boolean;
|
|
6
|
+
isSelectable?: boolean;
|
|
7
|
+
isSelected: boolean;
|
|
8
|
+
onChange: (id: string, isSelected: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const MobileItem: <A extends AdditionalDefault>({ item, isSelected, singleChoice, isSelectable, onChange, }: MobileItemProps<A>) => ReactElement;
|
|
11
|
+
export {};
|
package/MobileItem.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
|
|
4
|
+
import { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
5
|
+
import { Action } from './Action.js';
|
|
6
|
+
import 'react';
|
|
7
|
+
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
8
|
+
|
|
9
|
+
const MobileItem = ({ item, isSelected, singleChoice, isSelectable, onChange, }) => {
|
|
10
|
+
return (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: isSelected, children: jsx(Cell, { Element: 'div', right: isSelectable ? (jsx(Action, { selected: isSelected, onChange: onChange, id: item.id, singleChoice: singleChoice })) : undefined, children: jsx(CellText, { children: item.text }) }) }));
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { MobileItem };
|
|
14
|
+
//# sourceMappingURL=MobileItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileItem.js","sources":["../src/MobileItem.tsx"],"sourcesContent":["import { ReactElement } 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 { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\n\ninterface MobileItemProps<A extends AdditionalDefault> {\n item: TreeModel<A>;\n singleChoice?: boolean;\n isSelectable?: boolean;\n isSelected: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n}\n\nexport const MobileItem = <A extends AdditionalDefault>({\n item,\n isSelected,\n singleChoice,\n isSelectable,\n onChange,\n}: MobileItemProps<A>): ReactElement => {\n return (\n <CheckableCardElement padding={16} borderRadius={12} Element=\"label\" checked={isSelected}>\n <Cell\n Element={'div'}\n right={\n isSelectable ? (\n <Action selected={isSelected} onChange={onChange} id={item.id} singleChoice={singleChoice} />\n ) : undefined\n }\n >\n <CellText>{item.text}</CellText>\n </Cell>\n </CheckableCardElement>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;;;AAea,MAAA,UAAU,GAAG,CAA8B,EACpD,IAAI,EACJ,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,QAAQ,GACS,KAAkB;AACnC,IAAA,QACIA,GAAA,CAAC,oBAAoB,EAAA,EAAC,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,OAAO,EAAC,OAAO,EAAC,OAAO,EAAE,UAAU,EAAA,QAAA,EACpFA,GAAC,CAAA,IAAI,IACD,OAAO,EAAE,KAAK,EACd,KAAK,EACD,YAAY,IACRA,GAAA,CAAC,MAAM,EAAA,EAAC,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,YAAY,EAAE,YAAY,EAAI,CAAA,IAC7F,SAAS,YAGjBA,GAAC,CAAA,QAAQ,EAAE,EAAA,QAAA,EAAA,IAAI,CAAC,IAAI,EAAA,CAAY,EAC7B,CAAA,EAAA,CACY,EACzB;AACN;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import TreeCollection from './collection/treeCollection';
|
|
3
|
+
import { AdditionalDefault, IdCollectionPredicate } from './collection/types';
|
|
4
|
+
import { ListControls } from './types';
|
|
5
|
+
interface MobileItemsListProps<A extends AdditionalDefault> {
|
|
6
|
+
collection: TreeCollection<A>;
|
|
7
|
+
selected: string[];
|
|
8
|
+
leavesOnly?: boolean;
|
|
9
|
+
singleChoice?: boolean;
|
|
10
|
+
checkSelectable?: IdCollectionPredicate;
|
|
11
|
+
onChange: (id: string, isSelected: boolean) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const MobileItemsList: import("react").ForwardRefExoticComponent<MobileItemsListProps<AdditionalDefault> & import("react").RefAttributes<ListControls>>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef, useRef, useState, useMemo, useImperativeHandle } from 'react';
|
|
4
|
+
import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
|
|
5
|
+
import { CheckableCardElement } from '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
6
|
+
import { Action } from './Action.js';
|
|
7
|
+
import { MobileItem } from './MobileItem.js';
|
|
8
|
+
import { MobileParentItem } from './MobileParentItem.js';
|
|
9
|
+
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
10
|
+
import '@hh.ru/magritte-ui-card';
|
|
11
|
+
|
|
12
|
+
const MobileItemsListComponent = (props, ref) => {
|
|
13
|
+
const { collection, selected, leavesOnly, singleChoice, onChange, checkSelectable } = props;
|
|
14
|
+
const prevParentIds = useRef([]);
|
|
15
|
+
const [currentParentId, setCurrentParentId] = useState();
|
|
16
|
+
const items = useMemo(() => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()), [currentParentId, collection]);
|
|
17
|
+
const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);
|
|
18
|
+
useImperativeHandle(ref, () => ({
|
|
19
|
+
back: () => {
|
|
20
|
+
setCurrentParentId(prevParentIds.current.pop());
|
|
21
|
+
},
|
|
22
|
+
}), []);
|
|
23
|
+
return (jsxs(Fragment, { children: [isSelectable && (jsx(CheckableCardElement, { padding: 16, borderRadius: 12, Element: "label", checked: selected.includes(currentParentId), children: jsx(Cell, { Element: 'div', right: jsx(Action, { selected: selected.includes(currentParentId), onChange: onChange, id: currentParentId, singleChoice: singleChoice }), children: jsx(CellText, { children: "\u0412\u044B\u0431\u0440\u0430\u0442\u044C \u0432\u0441\u0435" }) }) })), items.map((item) => {
|
|
24
|
+
const hasChildren = collection.hasChildren(item.id);
|
|
25
|
+
return hasChildren ? (jsx(MobileParentItem, { collection: collection, item: item, selected: selected, onClick: () => {
|
|
26
|
+
prevParentIds.current.push(currentParentId);
|
|
27
|
+
setCurrentParentId(item.id);
|
|
28
|
+
} }, item.id)) : (jsx(MobileItem, { item: item, singleChoice: singleChoice, isSelectable: checkSelectable?.(item.id, collection), isSelected: selected.includes(item.id), onChange: onChange }, item.id));
|
|
29
|
+
})] }));
|
|
30
|
+
};
|
|
31
|
+
const MobileItemsList = forwardRef(MobileItemsListComponent);
|
|
32
|
+
|
|
33
|
+
export { MobileItemsList };
|
|
34
|
+
//# sourceMappingURL=MobileItemsList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileItemsList.js","sources":["../src/MobileItemsList.tsx"],"sourcesContent":["import { ReactElement, useMemo, useState, useImperativeHandle, forwardRef, ForwardedRef, useRef } 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 { 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 } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ListControls } from '@hh.ru/magritte-ui-tree-selector/types';\n\ninterface MobileItemsListProps<A extends AdditionalDefault> {\n collection: TreeCollection<A>;\n selected: string[];\n leavesOnly?: boolean;\n singleChoice?: boolean;\n checkSelectable?: IdCollectionPredicate;\n onChange: (id: string, isSelected: boolean) => void;\n}\n\nconst MobileItemsListComponent = <A extends AdditionalDefault>(\n props: MobileItemsListProps<A>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const { collection, selected, leavesOnly, singleChoice, onChange, checkSelectable } = props;\n const prevParentIds = useRef<(string | undefined)[]>([]);\n const [currentParentId, setCurrentParentId] = useState<string | undefined>();\n const items = useMemo(\n () => (currentParentId ? collection.getChildren(currentParentId) : collection.getTopLevel()),\n [currentParentId, collection]\n );\n const isSelectable = currentParentId && !leavesOnly && checkSelectable?.(currentParentId, collection);\n\n useImperativeHandle(\n ref,\n () => ({\n back: () => {\n setCurrentParentId(prevParentIds.current.pop());\n },\n }),\n []\n );\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 right={\n <Action\n selected={selected.includes(currentParentId)}\n onChange={onChange}\n id={currentParentId}\n singleChoice={singleChoice}\n />\n }\n >\n <CellText>Выбрать все</CellText>\n </Cell>\n </CheckableCardElement>\n )}\n {items.map((item) => {\n const hasChildren = collection.hasChildren(item.id);\n\n return hasChildren ? (\n <MobileParentItem\n key={item.id}\n collection={collection}\n item={item}\n selected={selected}\n onClick={() => {\n prevParentIds.current.push(currentParentId);\n setCurrentParentId(item.id);\n }}\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 onChange={onChange}\n />\n );\n })}\n </>\n );\n};\n\nexport const MobileItemsList = forwardRef(MobileItemsListComponent);\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;AAoBA,MAAM,wBAAwB,GAAG,CAC7B,KAA8B,EAC9B,GAA+B,KACjB;AACd,IAAA,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;AAC5F,IAAA,MAAM,aAAa,GAAG,MAAM,CAAyB,EAAE,CAAC,CAAC;IACzD,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,EAAsB,CAAC;AAC7E,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;AACF,IAAA,MAAM,YAAY,GAAG,eAAe,IAAI,CAAC,UAAU,IAAI,eAAe,GAAG,eAAe,EAAE,UAAU,CAAC,CAAC;AAEtG,IAAA,mBAAmB,CACf,GAAG,EACH,OAAO;QACH,IAAI,EAAE,MAAK;YACP,kBAAkB,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;SACnD;KACJ,CAAC,EACF,EAAE,CACL,CAAC;AAEF,IAAA,QACIA,IACK,CAAAC,QAAA,EAAA,EAAA,QAAA,EAAA,CAAA,YAAY,KACTC,IAAC,oBAAoB,EAAA,EACjB,OAAO,EAAE,EAAE,EACX,YAAY,EAAE,EAAE,EAChB,OAAO,EAAC,OAAO,EACf,OAAO,EAAE,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,EAE3C,QAAA,EAAAA,GAAA,CAAC,IAAI,EACD,EAAA,OAAO,EAAE,KAAK,EACd,KAAK,EACDA,GAAC,CAAA,MAAM,IACH,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,EAC5C,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,eAAe,EACnB,YAAY,EAAE,YAAY,EAC5B,CAAA,EAAA,QAAA,EAGNA,GAAC,CAAA,QAAQ,gFAAuB,EAC7B,CAAA,EAAA,CACY,CAC1B,EACA,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,KAAI;gBAChB,MAAM,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAEpD,OAAO,WAAW,IACdA,GAAC,CAAA,gBAAgB,EAEb,EAAA,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,IAAI,EACV,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAK;AACV,wBAAA,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AAC5C,wBAAA,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;qBAC/B,EAAA,EAPI,IAAI,CAAC,EAAE,CAQd,KAEFA,GAAC,CAAA,UAAU,IAEP,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,QAAQ,EAAE,QAAQ,EALb,EAAA,IAAI,CAAC,EAAE,CAMd,CACL,CAAC;aACL,CAAC,CACH,EAAA,CAAA,EACL;AACN,CAAC,CAAC;MAEW,eAAe,GAAG,UAAU,CAAC,wBAAwB;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import TreeCollection from './collection/treeCollection';
|
|
3
|
+
import { AdditionalDefault, TreeModel } from './collection/types';
|
|
4
|
+
interface MobileParentItemProps<A extends AdditionalDefault> {
|
|
5
|
+
collection: TreeCollection<A>;
|
|
6
|
+
item: TreeModel<A>;
|
|
7
|
+
selected: string[];
|
|
8
|
+
onClick: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const MobileParentItem: <A extends AdditionalDefault>({ collection, item, selected, onClick, }: MobileParentItemProps<A>) => ReactElement;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import './index.css';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { Card } from '@hh.ru/magritte-ui-card';
|
|
5
|
+
import { Cell, LabelRight, CellText } from '@hh.ru/magritte-ui-cell';
|
|
6
|
+
|
|
7
|
+
const MobileParentItem = ({ collection, item, selected, onClick, }) => {
|
|
8
|
+
const childrenSelectedCount = useMemo(() => {
|
|
9
|
+
let count = 0;
|
|
10
|
+
collection.walkChildren(item.id, (model) => {
|
|
11
|
+
if (selected.includes(model.id)) {
|
|
12
|
+
count += 1;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return count;
|
|
16
|
+
}, [collection, selected, item.id]);
|
|
17
|
+
return (jsx(Card, { padding: 16, borderRadius: 12, showBorder: true, actionCard: true, onClick: onClick, children: jsx(Cell, { right: jsx(LabelRight, { counter: childrenSelectedCount ? childrenSelectedCount.toString() : undefined }), children: jsx(CellText, { children: item.text }) }) }));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { MobileParentItem };
|
|
21
|
+
//# sourceMappingURL=MobileParentItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MobileParentItem.js","sources":["../src/MobileParentItem.tsx"],"sourcesContent":["import { ReactElement, useMemo } from 'react';\n\nimport { Card } from '@hh.ru/magritte-ui-card';\nimport { Cell, CellText, LabelRight } from '@hh.ru/magritte-ui-cell';\nimport TreeCollection from '@hh.ru/magritte-ui-tree-selector/collection/treeCollection';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/types';\n\ninterface MobileParentItemProps<A extends AdditionalDefault> {\n collection: TreeCollection<A>;\n item: TreeModel<A>;\n selected: string[];\n onClick: () => void;\n}\n\nexport const MobileParentItem = <A extends AdditionalDefault>({\n collection,\n item,\n selected,\n onClick,\n}: MobileParentItemProps<A>): ReactElement => {\n const childrenSelectedCount = useMemo(() => {\n let count = 0;\n collection.walkChildren(item.id, (model) => {\n if (selected.includes(model.id)) {\n count += 1;\n }\n });\n\n return count;\n }, [collection, selected, item.id]);\n\n return (\n <Card padding={16} borderRadius={12} showBorder actionCard onClick={onClick}>\n <Cell right={<LabelRight counter={childrenSelectedCount ? childrenSelectedCount.toString() : undefined} />}>\n <CellText>{item.text}</CellText>\n </Cell>\n </Card>\n );\n};\n"],"names":["_jsx"],"mappings":";;;;;AAcO,MAAM,gBAAgB,GAAG,CAA8B,EAC1D,UAAU,EACV,IAAI,EACJ,QAAQ,EACR,OAAO,GACgB,KAAkB;AACzC,IAAA,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAK;QACvC,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,KAAK,KAAI;YACvC,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE;gBAC7B,KAAK,IAAI,CAAC,CAAC;AACd,aAAA;AACL,SAAC,CAAC,CAAC;AAEH,QAAA,OAAO,KAAK,CAAC;KAChB,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpC,QACIA,GAAC,CAAA,IAAI,EAAC,EAAA,OAAO,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,UAAU,EAAC,IAAA,EAAA,UAAU,EAAC,IAAA,EAAA,OAAO,EAAE,OAAO,EACvE,QAAA,EAAAA,GAAA,CAAC,IAAI,EAAA,EAAC,KAAK,EAAEA,GAAC,CAAA,UAAU,IAAC,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,GAAG,SAAS,EAAI,CAAA,EAAA,QAAA,EACtGA,GAAC,CAAA,QAAQ,EAAE,EAAA,QAAA,EAAA,IAAI,CAAC,IAAI,EAAY,CAAA,EAAA,CAC7B,EACJ,CAAA,EACT;AACN;;;;"}
|
package/TreeSelector.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { AdditionalDefault } from './collection/types';
|
|
3
|
-
import {
|
|
4
|
-
export declare const TreeSelector: <
|
|
3
|
+
import { ListControls } from './types';
|
|
4
|
+
export declare const TreeSelector: import("react").ForwardRefExoticComponent<import("./types").TreeSelectorProps<AdditionalDefault> & import("@hh.ru/magritte-ui-tree-selector/types").ControlledProps & import("react").RefAttributes<ListControls>>;
|
package/TreeSelector.js
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { forwardRef } from 'react';
|
|
4
|
+
import { useBreakpoint } from '@hh.ru/magritte-ui-breakpoint';
|
|
5
|
+
import { VSpacingContainer } from '@hh.ru/magritte-ui-spacing';
|
|
3
6
|
import { ItemsList } from './ItemsList.js';
|
|
7
|
+
import { MobileItemsList } from './MobileItemsList.js';
|
|
4
8
|
import useExpanded from './useExpanded.js';
|
|
5
9
|
import { useIndeterminate } from './useIndeterminate.js';
|
|
6
10
|
import './Item.js';
|
|
7
|
-
import 'react';
|
|
8
11
|
import 'classnames';
|
|
9
|
-
import './ItemContent-
|
|
12
|
+
import './ItemContent-59665486.js';
|
|
10
13
|
import '@hh.ru/magritte-ui-cell';
|
|
11
14
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
12
15
|
import './Action.js';
|
|
13
16
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
14
17
|
import '@hh.ru/magritte-ui-typography';
|
|
18
|
+
import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
19
|
+
import './MobileItem.js';
|
|
20
|
+
import './MobileParentItem.js';
|
|
21
|
+
import '@hh.ru/magritte-ui-card';
|
|
15
22
|
|
|
16
23
|
const defaultCheckSelectable = () => true;
|
|
17
24
|
const defaultArray = [];
|
|
18
|
-
const TreeSelector = ({ collection, checkSelectable = defaultCheckSelectable, initialExpanded = defaultArray, value: selected, leavesOnly, singleChoice, expanded, onExpand, onChange, }) => {
|
|
25
|
+
const TreeSelector = forwardRef(({ collection, checkSelectable = defaultCheckSelectable, initialExpanded = defaultArray, value: selected, leavesOnly, singleChoice, expanded, onExpand, onChange, }, ref) => {
|
|
19
26
|
const { indeterminate } = useIndeterminate({ collection, selected });
|
|
20
27
|
const { expanded: currentExpanded, handleExpansion } = useExpanded({
|
|
21
28
|
initialValue: expanded ? expanded.slice() : initialExpanded.slice(),
|
|
22
29
|
controlledExpanded: expanded,
|
|
23
30
|
onExpand,
|
|
24
31
|
});
|
|
25
|
-
|
|
26
|
-
};
|
|
32
|
+
const { isMobile } = useBreakpoint();
|
|
33
|
+
return (jsx(VSpacingContainer, { default: 12, gteM: 0, children: isMobile ? (jsx(MobileItemsList, { collection: collection, selected: selected, onChange: onChange, leavesOnly: leavesOnly, checkSelectable: checkSelectable, singleChoice: singleChoice, ref: ref })) : (jsx(ItemsList, { collection: collection, items: collection.getTopLevel(), leavesOnly: leavesOnly, checkSelectable: checkSelectable, expanded: currentExpanded, onExpansion: handleExpansion, selected: selected, onChange: onChange, singleChoice: singleChoice, indeterminate: indeterminate })) }));
|
|
34
|
+
});
|
|
35
|
+
TreeSelector.displayName = 'TreeSelector';
|
|
27
36
|
|
|
28
37
|
export { TreeSelector };
|
|
29
38
|
//# sourceMappingURL=TreeSelector.js.map
|
package/TreeSelector.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeSelector.js","sources":["../src/TreeSelector.tsx"],"sourcesContent":["import { ReactElement } from 'react';\n\nimport { ItemsList } from '@hh.ru/magritte-ui-tree-selector/ItemsList';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ControlledTreeSelectorProps } 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';\n\nconst defaultCheckSelectable = () => true;\nconst defaultArray: string[] = [];\n\nexport const TreeSelector = <A extends AdditionalDefault>({\n
|
|
1
|
+
{"version":3,"file":"TreeSelector.js","sources":["../src/TreeSelector.tsx"],"sourcesContent":["import { ReactElement, forwardRef, ForwardedRef } from 'react';\n\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 { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport { ControlledTreeSelectorProps, ListControls } 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';\n\nconst defaultCheckSelectable = () => true;\nconst defaultArray: string[] = [];\n\nexport const TreeSelector = forwardRef(\n <A extends AdditionalDefault>(\n {\n collection,\n checkSelectable = defaultCheckSelectable,\n initialExpanded = defaultArray,\n value: selected,\n leavesOnly,\n singleChoice,\n expanded,\n onExpand,\n onChange,\n }: ControlledTreeSelectorProps<A>,\n ref: ForwardedRef<ListControls>\n ): ReactElement => {\n const { indeterminate } = useIndeterminate({ collection, selected });\n const { expanded: currentExpanded, handleExpansion } = useExpanded({\n initialValue: expanded ? expanded.slice() : initialExpanded.slice(),\n controlledExpanded: expanded,\n onExpand,\n });\n const { isMobile } = useBreakpoint();\n\n return (\n <VSpacingContainer default={12} gteM={0}>\n {isMobile ? (\n <MobileItemsList\n collection={collection}\n selected={selected}\n onChange={onChange}\n leavesOnly={leavesOnly}\n checkSelectable={checkSelectable}\n singleChoice={singleChoice}\n ref={ref}\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 singleChoice={singleChoice}\n indeterminate={indeterminate}\n />\n )}\n </VSpacingContainer>\n );\n }\n);\n\nTreeSelector.displayName = 'TreeSelector';\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAWA,MAAM,sBAAsB,GAAG,MAAM,IAAI,CAAC;AAC1C,MAAM,YAAY,GAAa,EAAE,CAAC;AAE3B,MAAM,YAAY,GAAG,UAAU,CAClC,CACI,EACI,UAAU,EACV,eAAe,GAAG,sBAAsB,EACxC,eAAe,GAAG,YAAY,EAC9B,KAAK,EAAE,QAAQ,EACf,UAAU,EACV,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,QAAQ,GACqB,EACjC,GAA+B,KACjB;AACd,IAAA,MAAM,EAAE,aAAa,EAAE,GAAG,gBAAgB,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC;IACrE,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,GAAG,WAAW,CAAC;AAC/D,QAAA,YAAY,EAAE,QAAQ,GAAG,QAAQ,CAAC,KAAK,EAAE,GAAG,eAAe,CAAC,KAAK,EAAE;AACnE,QAAA,kBAAkB,EAAE,QAAQ;QAC5B,QAAQ;AACX,KAAA,CAAC,CAAC;AACH,IAAA,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,EAAE,CAAC;IAErC,QACIA,IAAC,iBAAiB,EAAA,EAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,YAClC,QAAQ,IACLA,IAAC,eAAe,EAAA,EACZ,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,GAAG,EAAE,GAAG,EACV,CAAA,KAEFA,GAAA,CAAC,SAAS,EACN,EAAA,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,UAAU,CAAC,WAAW,EAAE,EAC/B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,eAAe,EAC5B,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,EAC9B,CAAA,CACL,EACe,CAAA,EACtB;AACN,CAAC,EACH;AAEF,YAAY,CAAC,WAAW,GAAG,cAAc;;;;"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import { AdditionalDefault } from './collection/types';
|
|
3
|
-
import {
|
|
4
|
-
export declare const UncontrolledTreeSelector: <
|
|
3
|
+
import { ListControls } from './types';
|
|
4
|
+
export declare const UncontrolledTreeSelector: import("react").ForwardRefExoticComponent<import("./types").TreeSelectorProps<AdditionalDefault> & {
|
|
5
|
+
value?: string[] | undefined;
|
|
6
|
+
onChange?: ((id: string, isSelected: boolean, allSelected: string[]) => void) | undefined;
|
|
7
|
+
} & import("react").RefAttributes<ListControls>>;
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useMemo } from 'react';
|
|
3
|
+
import { forwardRef, useMemo } from 'react';
|
|
4
4
|
import { TreeSelector } from './TreeSelector.js';
|
|
5
5
|
import ImmutableSelectionStrategy from './strategy/immutableSelectionStrategy.js';
|
|
6
6
|
import { useSelected } from './useSelected.js';
|
|
7
|
+
import '@hh.ru/magritte-ui-breakpoint';
|
|
8
|
+
import '@hh.ru/magritte-ui-spacing';
|
|
7
9
|
import './ItemsList.js';
|
|
8
10
|
import './Item.js';
|
|
9
11
|
import 'classnames';
|
|
10
|
-
import './ItemContent-
|
|
12
|
+
import './ItemContent-59665486.js';
|
|
11
13
|
import '@hh.ru/magritte-ui-cell';
|
|
12
14
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
13
15
|
import './Action.js';
|
|
14
16
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
15
17
|
import '@hh.ru/magritte-ui-typography';
|
|
18
|
+
import './MobileItemsList.js';
|
|
19
|
+
import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
20
|
+
import './MobileItem.js';
|
|
21
|
+
import './MobileParentItem.js';
|
|
22
|
+
import '@hh.ru/magritte-ui-card';
|
|
16
23
|
import './useExpanded.js';
|
|
17
24
|
import './useIndeterminate.js';
|
|
18
25
|
import './strategy/selectionStrategy.js';
|
|
@@ -23,7 +30,7 @@ import './strategy/createTreeCollectionToggler.js';
|
|
|
23
30
|
import './strategy/dummyToggle.js';
|
|
24
31
|
|
|
25
32
|
const defaultArray = [];
|
|
26
|
-
const
|
|
33
|
+
const UncontrolledTreeSelectorComponent = (props, ref) => {
|
|
27
34
|
const { value = defaultArray, collection, singleChoice, leavesOnly, checkSelectable, onChange } = props;
|
|
28
35
|
const strategy = useMemo(() => new ImmutableSelectionStrategy(collection, {
|
|
29
36
|
singleChoice,
|
|
@@ -31,8 +38,9 @@ const UncontrolledTreeSelector = (props) => {
|
|
|
31
38
|
checkSelectable,
|
|
32
39
|
}), [collection, singleChoice, leavesOnly, checkSelectable]);
|
|
33
40
|
const { selected, setSelected } = useSelected({ value, strategy, onChange });
|
|
34
|
-
return jsx(TreeSelector, { ...props, value: selected, onChange: setSelected });
|
|
41
|
+
return jsx(TreeSelector, { ...props, value: selected, onChange: setSelected, ref: ref });
|
|
35
42
|
};
|
|
43
|
+
const UncontrolledTreeSelector = forwardRef(UncontrolledTreeSelectorComponent);
|
|
36
44
|
|
|
37
45
|
export { UncontrolledTreeSelector };
|
|
38
46
|
//# sourceMappingURL=UncontrolledTreeSelector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UncontrolledTreeSelector.js","sources":["../src/UncontrolledTreeSelector.tsx"],"sourcesContent":["import { ReactElement, useMemo } from 'react';\n\nimport { TreeSelector } from '@hh.ru/magritte-ui-tree-selector/TreeSelector';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { UncontrolledTreeSelectorProps } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useSelected } from '@hh.ru/magritte-ui-tree-selector/useSelected';\n\nconst defaultArray: string[] = [];\
|
|
1
|
+
{"version":3,"file":"UncontrolledTreeSelector.js","sources":["../src/UncontrolledTreeSelector.tsx"],"sourcesContent":["import { ForwardedRef, forwardRef, ReactElement, useMemo } from 'react';\n\nimport { TreeSelector } from '@hh.ru/magritte-ui-tree-selector/TreeSelector';\nimport { AdditionalDefault } from '@hh.ru/magritte-ui-tree-selector/collection/types';\nimport ImmutableSelectionStrategy from '@hh.ru/magritte-ui-tree-selector/strategy/immutableSelectionStrategy';\nimport { UncontrolledTreeSelectorProps, ListControls } from '@hh.ru/magritte-ui-tree-selector/types';\nimport { useSelected } from '@hh.ru/magritte-ui-tree-selector/useSelected';\n\nconst defaultArray: string[] = [];\nconst UncontrolledTreeSelectorComponent = <A extends AdditionalDefault>(\n props: UncontrolledTreeSelectorProps<A>,\n ref: ForwardedRef<ListControls>\n): ReactElement => {\n const { value = defaultArray, collection, singleChoice, leavesOnly, checkSelectable, onChange } = 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 const { selected, setSelected } = useSelected({ value, strategy, onChange });\n return <TreeSelector {...props} value={selected} onChange={setSelected} ref={ref}></TreeSelector>;\n};\n\nexport const UncontrolledTreeSelector = forwardRef(UncontrolledTreeSelectorComponent);\n"],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,YAAY,GAAa,EAAE,CAAC;AAClC,MAAM,iCAAiC,GAAG,CACtC,KAAuC,EACvC,GAA+B,KACjB;AACd,IAAA,MAAM,EAAE,KAAK,GAAG,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxG,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,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC7E,IAAA,OAAOA,IAAC,YAAY,EAAA,EAAA,GAAK,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,GAAG,GAAiB,CAAC;AACtG,CAAC,CAAC;MAEW,wBAAwB,GAAG,UAAU,CAAC,iCAAiC;;;;"}
|
package/index.css
CHANGED
|
@@ -1,46 +1,38 @@
|
|
|
1
|
-
.magritte-wrapper___GHKV6_1-
|
|
1
|
+
.magritte-wrapper___GHKV6_1-2-0{
|
|
2
2
|
display:flex;
|
|
3
3
|
padding:12px 0;
|
|
4
4
|
gap:12px;
|
|
5
5
|
align-items:center;
|
|
6
6
|
}
|
|
7
|
-
.magritte-letter___yZOCU_1-
|
|
7
|
+
.magritte-letter___yZOCU_1-2-0{
|
|
8
8
|
width:24px;
|
|
9
9
|
flex-shrink:0;
|
|
10
10
|
text-align:center;
|
|
11
11
|
}
|
|
12
|
-
.magritte-icon___kO3Fj_1-
|
|
12
|
+
.magritte-icon___kO3Fj_1-2-0,
|
|
13
|
+
.magritte-space___xTO79_1-2-0{
|
|
13
14
|
flex-shrink:0;
|
|
14
15
|
line-height:0;
|
|
15
16
|
width:24px;
|
|
16
17
|
}
|
|
17
|
-
.magritte-iconActive___4yrG5_1-
|
|
18
|
+
.magritte-iconActive___4yrG5_1-2-0{
|
|
18
19
|
cursor:pointer;
|
|
19
20
|
}
|
|
20
|
-
.magritte-content___ZRc6R_1-
|
|
21
|
+
.magritte-content___ZRc6R_1-2-0{
|
|
21
22
|
flex-grow:1;
|
|
22
23
|
}
|
|
23
|
-
.magritte-with-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
.magritte-with-action___-lsFP_1-1-5.magritte-with-letter___skx30_1-1-5 > .magritte-children___kq-eq_1-1-5{
|
|
27
|
-
padding-left:72px;
|
|
24
|
+
.magritte-with-shift___ZErxZ_1-2-0{
|
|
25
|
+
margin-left:-36px;
|
|
28
26
|
}
|
|
29
|
-
.magritte-with-
|
|
30
|
-
|
|
27
|
+
.magritte-with-indent___MH9Vy_1-2-0{
|
|
28
|
+
margin-left:36px;
|
|
31
29
|
}
|
|
32
|
-
.magritte-
|
|
33
|
-
padding-left:108px;
|
|
34
|
-
}
|
|
35
|
-
.magritte-with-letter___skx30_1-1-5 > .magritte-children___kq-eq_1-1-5{
|
|
30
|
+
.magritte-item___2LtOL_1-2-0 > .magritte-children___kq-eq_1-2-0{
|
|
36
31
|
padding-left:36px;
|
|
37
32
|
}
|
|
38
|
-
.magritte-
|
|
33
|
+
.magritte-item___2LtOL_1-2-0.magritte-with-two-boxes___LWOy2_1-2-0 > .magritte-children___kq-eq_1-2-0{
|
|
39
34
|
padding-left:72px;
|
|
40
35
|
}
|
|
41
|
-
.magritte-with-
|
|
42
|
-
padding-left:
|
|
43
|
-
}
|
|
44
|
-
.magritte-with-shift___ZErxZ_1-1-5{
|
|
45
|
-
margin-left:-36px;
|
|
36
|
+
.magritte-item___2LtOL_1-2-0.magritte-with-three-boxes___cyVao_1-2-0 > .magritte-children___kq-eq_1-2-0{
|
|
37
|
+
padding-left:108px;
|
|
46
38
|
}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
import './index.css';
|
|
2
2
|
export { TreeSelector } from './TreeSelector.js';
|
|
3
|
+
export { UncontrolledTreeSelector } from './UncontrolledTreeSelector.js';
|
|
3
4
|
import 'react/jsx-runtime';
|
|
5
|
+
import 'react';
|
|
6
|
+
import '@hh.ru/magritte-ui-breakpoint';
|
|
7
|
+
import '@hh.ru/magritte-ui-spacing';
|
|
4
8
|
import './ItemsList.js';
|
|
5
9
|
import './Item.js';
|
|
6
|
-
import 'react';
|
|
7
10
|
import 'classnames';
|
|
8
|
-
import './ItemContent-
|
|
11
|
+
import './ItemContent-59665486.js';
|
|
9
12
|
import '@hh.ru/magritte-ui-cell';
|
|
10
13
|
import '@hh.ru/magritte-ui-icon/icon';
|
|
11
14
|
import './Action.js';
|
|
12
15
|
import '@hh.ru/magritte-ui-checkbox-radio';
|
|
13
16
|
import '@hh.ru/magritte-ui-typography';
|
|
17
|
+
import './MobileItemsList.js';
|
|
18
|
+
import '@hh.ru/magritte-ui-checkable-card/CheckableCardElement';
|
|
19
|
+
import './MobileItem.js';
|
|
20
|
+
import './MobileParentItem.js';
|
|
21
|
+
import '@hh.ru/magritte-ui-card';
|
|
14
22
|
import './useExpanded.js';
|
|
15
23
|
import './useIndeterminate.js';
|
|
24
|
+
import './strategy/immutableSelectionStrategy.js';
|
|
25
|
+
import './strategy/selectionStrategy.js';
|
|
26
|
+
import './collection/treeCollectionHelper.js';
|
|
27
|
+
import './collection/treeCollection.js';
|
|
28
|
+
import './strategy/createSingleValueToggler.js';
|
|
29
|
+
import './strategy/createTreeCollectionToggler.js';
|
|
30
|
+
import './strategy/dummyToggle.js';
|
|
31
|
+
import './useSelected.js';
|
|
16
32
|
//# 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.2.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"sideEffects": [
|
|
@@ -19,10 +19,14 @@
|
|
|
19
19
|
"test": "yarn root:test $(pwd)"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@hh.ru/magritte-ui-breakpoint": "4.0.1",
|
|
23
|
+
"@hh.ru/magritte-ui-card": "6.0.4",
|
|
22
24
|
"@hh.ru/magritte-ui-cell": "2.2.11",
|
|
25
|
+
"@hh.ru/magritte-ui-checkable-card": "3.0.6",
|
|
23
26
|
"@hh.ru/magritte-ui-checkbox-radio": "3.0.2",
|
|
24
27
|
"@hh.ru/magritte-ui-icon": "7.1.6",
|
|
25
28
|
"@hh.ru/magritte-ui-mock-component": "1.0.10",
|
|
29
|
+
"@hh.ru/magritte-ui-spacing": "2.0.22",
|
|
26
30
|
"@hh.ru/magritte-ui-theme-provider": "1.1.22",
|
|
27
31
|
"@hh.ru/magritte-ui-typography": "3.0.9"
|
|
28
32
|
},
|
|
@@ -33,5 +37,5 @@
|
|
|
33
37
|
"publishConfig": {
|
|
34
38
|
"access": "public"
|
|
35
39
|
},
|
|
36
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "59e0e0164dddefec65be2bba7b1c43237393e25d"
|
|
37
41
|
}
|
package/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface TreeSelectorProps<A extends AdditionalDefault> {
|
|
|
9
9
|
expanded?: string[];
|
|
10
10
|
onExpand?: (expanded: string[]) => void;
|
|
11
11
|
}
|
|
12
|
-
interface ControlledProps {
|
|
12
|
+
export interface ControlledProps {
|
|
13
13
|
value: string[];
|
|
14
14
|
onChange: (id: string, isSelected: boolean) => void;
|
|
15
15
|
}
|
|
@@ -19,4 +19,7 @@ type UncontrolledProps = {
|
|
|
19
19
|
};
|
|
20
20
|
export type ControlledTreeSelectorProps<A extends AdditionalDefault> = TreeSelectorProps<A> & ControlledProps;
|
|
21
21
|
export type UncontrolledTreeSelectorProps<A extends AdditionalDefault> = TreeSelectorProps<A> & UncontrolledProps;
|
|
22
|
+
export interface ListControls {
|
|
23
|
+
back: () => void;
|
|
24
|
+
}
|
|
22
25
|
export {};
|
package/ItemContent-ad35f8ca.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import './index.css';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
import { Cell, CellText } from '@hh.ru/magritte-ui-cell';
|
|
6
|
-
import { DotFilledSize24, ChevronDownOutlinedSize24, ChevronUpOutlinedSize24 } from '@hh.ru/magritte-ui-icon/icon';
|
|
7
|
-
import { Action } from './Action.js';
|
|
8
|
-
import { Text } from '@hh.ru/magritte-ui-typography';
|
|
9
|
-
|
|
10
|
-
var styles = {"wrapper":"magritte-wrapper___GHKV6_1-1-5","letter":"magritte-letter___yZOCU_1-1-5","icon":"magritte-icon___kO3Fj_1-1-5","iconActive":"magritte-iconActive___4yrG5_1-1-5","content":"magritte-content___ZRc6R_1-1-5","with-action":"magritte-with-action___-lsFP_1-1-5","withAction":"magritte-with-action___-lsFP_1-1-5","children":"magritte-children___kq-eq_1-1-5","with-letter":"magritte-with-letter___skx30_1-1-5","withLetter":"magritte-with-letter___skx30_1-1-5","with-chevron":"magritte-with-chevron___VOytc_1-1-5","withChevron":"magritte-with-chevron___VOytc_1-1-5","with-shift":"magritte-with-shift___ZErxZ_1-1-5","withShift":"magritte-with-shift___ZErxZ_1-1-5"};
|
|
11
|
-
|
|
12
|
-
const ItemContent = ({ item, hasAction, hasChildren, letter, expanded, onExpansion, hasChildrenOnLevel, hasLetterOnLevel, selected, onChange, indeterminate, singleChoice, hasActionOnLevel, }) => {
|
|
13
|
-
const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);
|
|
14
|
-
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 })) })), hasActionOnLevel && hasChildren && !hasAction && (jsx("div", { className: styles.icon, children: jsx(DotFilledSize24, { initial: "tertiary" }) })), (hasChildrenOnLevel || hasChildren) && (jsxs("div", { className: classnames(styles.icon, {
|
|
15
|
-
[styles.iconActive]: hasChildren,
|
|
16
|
-
}), onClick: handleExpandableClick, children: [expanded && hasChildren && jsx(ChevronDownOutlinedSize24, { initial: "tertiary" }), !expanded && hasChildren && jsx(ChevronUpOutlinedSize24, { initial: "tertiary" }), hasChildrenOnLevel && !hasChildren && jsx(DotFilledSize24, { initial: "tertiary" })] })), jsx(Cell, { left: hasAction ? (jsx(Action, { selected: selected, onChange: onChange, id: item.id, indeterminate: indeterminate, singleChoice: singleChoice })) : undefined, children: jsx(CellText, { children: item.text }) })] }));
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export { ItemContent as I, styles as s };
|
|
20
|
-
//# sourceMappingURL=ItemContent-ad35f8ca.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ItemContent-ad35f8ca.js","sources":["../src/ItemContent.tsx"],"sourcesContent":["import { ReactElement, useCallback } from 'react';\nimport classnames from 'classnames';\n\nimport { Cell, CellText } from '@hh.ru/magritte-ui-cell';\nimport { ChevronDownOutlinedSize24, ChevronUpOutlinedSize24, DotFilledSize24 } from '@hh.ru/magritte-ui-icon/icon';\nimport { Action } from '@hh.ru/magritte-ui-tree-selector/Action';\nimport { AdditionalDefault, TreeModel } from '@hh.ru/magritte-ui-tree-selector/collection/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 expanded?: boolean;\n hasChildrenOnLevel: boolean;\n selected: boolean;\n onChange: (id: string, isSelected: boolean) => void;\n indeterminate: boolean;\n singleChoice?: boolean;\n hasActionOnLevel: boolean;\n hasLetterOnLevel: boolean;\n}\n\nconst ItemContent = <A extends AdditionalDefault>({\n item,\n hasAction,\n hasChildren,\n letter,\n expanded,\n onExpansion,\n hasChildrenOnLevel,\n hasLetterOnLevel,\n selected,\n onChange,\n indeterminate,\n singleChoice,\n hasActionOnLevel,\n}: ItemContent<A>): ReactElement => {\n const handleExpandableClick = useCallback(() => onExpansion && onExpansion(item.id), [item.id, onExpansion]);\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 {hasActionOnLevel && hasChildren && !hasAction && (\n <div className={styles.icon}>\n <DotFilledSize24 initial=\"tertiary\" />\n </div>\n )}\n\n {(hasChildrenOnLevel || hasChildren) && (\n <div\n className={classnames(styles.icon, {\n [styles.iconActive]: hasChildren,\n })}\n onClick={handleExpandableClick}\n >\n {expanded && hasChildren && <ChevronDownOutlinedSize24 initial=\"tertiary\" />}\n {!expanded && hasChildren && <ChevronUpOutlinedSize24 initial=\"tertiary\" />}\n {hasChildrenOnLevel && !hasChildren && <DotFilledSize24 initial=\"tertiary\" />}\n </div>\n )}\n\n <Cell\n left={\n hasAction ? (\n <Action\n selected={selected}\n onChange={onChange}\n id={item.id}\n indeterminate={indeterminate}\n singleChoice={singleChoice}\n />\n ) : undefined\n }\n >\n <CellText>{item.text}</CellText>\n </Cell>\n </div>\n );\n};\n\nexport { ItemContent };\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;AA2BA,MAAM,WAAW,GAAG,CAA8B,EAC9C,IAAI,EACJ,SAAS,EACT,WAAW,EACX,MAAM,EACN,QAAQ,EACR,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,gBAAgB,GACH,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;AAE7G,IAAA,QACIA,IAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,OAAO,EACzB,QAAA,EAAA,CAAA,CAAC,MAAM,IAAI,gBAAgB,MACxBC,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,MAAM,EAAA,QAAA,EACxB,MAAM,KACHA,IAAC,IAAI,EAAA,EAAC,UAAU,EAAC,qBAAqB,EAAC,KAAK,EAAC,WAAW,EAAC,OAAO,EAAC,MAAM,EAAA,QAAA,EAClE,MAAM,EACJ,CAAA,CACV,EACC,CAAA,CACT,EACA,gBAAgB,IAAI,WAAW,IAAI,CAAC,SAAS,KAC1CA,GAAK,CAAA,KAAA,EAAA,EAAA,SAAS,EAAE,MAAM,CAAC,IAAI,EACvB,QAAA,EAAAA,GAAA,CAAC,eAAe,EAAC,EAAA,OAAO,EAAC,UAAU,GAAG,EACpC,CAAA,CACT,EAEA,CAAC,kBAAkB,IAAI,WAAW,MAC/BD,IAAA,CAAA,KAAA,EAAA,EACI,SAAS,EAAE,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE;AAC/B,oBAAA,CAAC,MAAM,CAAC,UAAU,GAAG,WAAW;iBACnC,CAAC,EACF,OAAO,EAAE,qBAAqB,aAE7B,QAAQ,IAAI,WAAW,IAAIC,GAAA,CAAC,yBAAyB,EAAC,EAAA,OAAO,EAAC,UAAU,EAAA,CAAG,EAC3E,CAAC,QAAQ,IAAI,WAAW,IAAIA,GAAA,CAAC,uBAAuB,EAAC,EAAA,OAAO,EAAC,UAAU,EAAA,CAAG,EAC1E,kBAAkB,IAAI,CAAC,WAAW,IAAIA,IAAC,eAAe,EAAA,EAAC,OAAO,EAAC,UAAU,GAAG,CAC3E,EAAA,CAAA,CACT,EAEDA,GAAA,CAAC,IAAI,EAAA,EACD,IAAI,EACA,SAAS,IACLA,GAAC,CAAA,MAAM,IACH,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,EAAE,EAAE,IAAI,CAAC,EAAE,EACX,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,YAAY,GAC5B,IACF,SAAS,YAGjBA,GAAC,CAAA,QAAQ,cAAE,IAAI,CAAC,IAAI,EAAY,CAAA,EAAA,CAC7B,CACL,EAAA,CAAA,EACR;AACN;;;;"}
|