@snack-uikit/list 0.1.1-preview-57c837e3.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/CHANGELOG.md +21 -0
- package/LICENSE +201 -0
- package/README.md +73 -0
- package/dist/components/Items/AccordionItem/AccordionItem.d.ts +2 -0
- package/dist/components/Items/AccordionItem/AccordionItem.js +41 -0
- package/dist/components/Items/AccordionItem/index.d.ts +1 -0
- package/dist/components/Items/AccordionItem/index.js +1 -0
- package/dist/components/Items/BaseItem/BaseItem.d.ts +8 -0
- package/dist/components/Items/BaseItem/BaseItem.js +67 -0
- package/dist/components/Items/BaseItem/constants.d.ts +2 -0
- package/dist/components/Items/BaseItem/constants.js +5 -0
- package/dist/components/Items/BaseItem/index.d.ts +1 -0
- package/dist/components/Items/BaseItem/index.js +1 -0
- package/dist/components/Items/BaseItem/styles.module.css +205 -0
- package/dist/components/Items/GroupItem/GroupItem.d.ts +2 -0
- package/dist/components/Items/GroupItem/GroupItem.js +9 -0
- package/dist/components/Items/GroupItem/index.d.ts +1 -0
- package/dist/components/Items/GroupItem/index.js +1 -0
- package/dist/components/Items/NextListItem/NextListItem.d.ts +2 -0
- package/dist/components/Items/NextListItem/NextListItem.js +66 -0
- package/dist/components/Items/NextListItem/hooks.d.ts +19 -0
- package/dist/components/Items/NextListItem/hooks.js +80 -0
- package/dist/components/Items/NextListItem/index.d.ts +1 -0
- package/dist/components/Items/NextListItem/index.js +1 -0
- package/dist/components/Items/PinGroupItem/PinGroupItem.d.ts +7 -0
- package/dist/components/Items/PinGroupItem/PinGroupItem.js +15 -0
- package/dist/components/Items/PinGroupItem/index.d.ts +1 -0
- package/dist/components/Items/PinGroupItem/index.js +1 -0
- package/dist/components/Items/PinGroupItem/styles.module.css +31 -0
- package/dist/components/Items/SearchItem/SearchItem.d.ts +5 -0
- package/dist/components/Items/SearchItem/SearchItem.js +28 -0
- package/dist/components/Items/SearchItem/index.d.ts +1 -0
- package/dist/components/Items/SearchItem/index.js +1 -0
- package/dist/components/Items/SearchItem/styles.module.css +11 -0
- package/dist/components/Items/hooks.d.ts +22 -0
- package/dist/components/Items/hooks.js +61 -0
- package/dist/components/Items/index.d.ts +9 -0
- package/dist/components/Items/index.js +9 -0
- package/dist/components/Items/styles.module.css +74 -0
- package/dist/components/Items/types.d.ts +43 -0
- package/dist/components/Items/types.js +1 -0
- package/dist/components/Items/utils.d.ts +17 -0
- package/dist/components/Items/utils.js +42 -0
- package/dist/components/Lists/Droplist/DropList.d.ts +2 -0
- package/dist/components/Lists/Droplist/DropList.js +97 -0
- package/dist/components/Lists/Droplist/index.d.ts +1 -0
- package/dist/components/Lists/Droplist/index.js +1 -0
- package/dist/components/Lists/List/List.d.ts +14 -0
- package/dist/components/Lists/List/List.js +77 -0
- package/dist/components/Lists/List/index.d.ts +1 -0
- package/dist/components/Lists/List/index.js +1 -0
- package/dist/components/Lists/ListPrivate/ListPrivate.d.ts +22 -0
- package/dist/components/Lists/ListPrivate/ListPrivate.js +41 -0
- package/dist/components/Lists/ListPrivate/index.d.ts +1 -0
- package/dist/components/Lists/ListPrivate/index.js +1 -0
- package/dist/components/Lists/ListPrivate/styles.module.css +46 -0
- package/dist/components/Lists/contexts/CollapseProvider.d.ts +6 -0
- package/dist/components/Lists/contexts/CollapseProvider.js +3 -0
- package/dist/components/Lists/contexts/ListProvider.d.ts +12 -0
- package/dist/components/Lists/contexts/ListProvider.js +22 -0
- package/dist/components/Lists/contexts/ParentListProvider.d.ts +18 -0
- package/dist/components/Lists/contexts/ParentListProvider.js +12 -0
- package/dist/components/Lists/contexts/SelectionProvider.d.ts +53 -0
- package/dist/components/Lists/contexts/SelectionProvider.js +61 -0
- package/dist/components/Lists/contexts/index.d.ts +4 -0
- package/dist/components/Lists/contexts/index.js +4 -0
- package/dist/components/Lists/hooks.d.ts +16 -0
- package/dist/components/Lists/hooks.js +73 -0
- package/dist/components/Lists/index.d.ts +4 -0
- package/dist/components/Lists/index.js +2 -0
- package/dist/components/Lists/styles.module.css +70 -0
- package/dist/components/Lists/types.d.ts +35 -0
- package/dist/components/Lists/types.js +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -0
- package/dist/helperComponents/CollapseBlockPrivate/CollapseBlockPrivate.d.ts +9 -0
- package/dist/helperComponents/CollapseBlockPrivate/CollapseBlockPrivate.js +20 -0
- package/dist/helperComponents/CollapseBlockPrivate/index.d.ts +1 -0
- package/dist/helperComponents/CollapseBlockPrivate/index.js +1 -0
- package/dist/helperComponents/CollapseBlockPrivate/styles.module.css +38 -0
- package/dist/helperComponents/HiddenTabButton/HiddenTabButton.d.ts +6 -0
- package/dist/helperComponents/HiddenTabButton/HiddenTabButton.js +17 -0
- package/dist/helperComponents/HiddenTabButton/index.d.ts +1 -0
- package/dist/helperComponents/HiddenTabButton/index.js +1 -0
- package/dist/helperComponents/HiddenTabButton/styles.module.css +9 -0
- package/dist/helperComponents/Separator/Separator.d.ts +7 -0
- package/dist/helperComponents/Separator/Separator.js +12 -0
- package/dist/helperComponents/Separator/index.d.ts +1 -0
- package/dist/helperComponents/Separator/index.js +1 -0
- package/dist/helperComponents/Separator/styles.module.css +112 -0
- package/dist/helperComponents/index.d.ts +3 -0
- package/dist/helperComponents/index.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +18 -0
- package/dist/utils.js +69 -0
- package/package.json +48 -0
- package/src/components/Items/AccordionItem/AccordionItem.tsx +60 -0
- package/src/components/Items/AccordionItem/index.ts +1 -0
- package/src/components/Items/BaseItem/BaseItem.tsx +150 -0
- package/src/components/Items/BaseItem/constants.ts +7 -0
- package/src/components/Items/BaseItem/index.ts +1 -0
- package/src/components/Items/BaseItem/styles.module.scss +190 -0
- package/src/components/Items/GroupItem/GroupItem.tsx +17 -0
- package/src/components/Items/GroupItem/index.ts +1 -0
- package/src/components/Items/NextListItem/NextListItem.tsx +131 -0
- package/src/components/Items/NextListItem/hooks.ts +105 -0
- package/src/components/Items/NextListItem/index.ts +1 -0
- package/src/components/Items/PinGroupItem/PinGroupItem.tsx +28 -0
- package/src/components/Items/PinGroupItem/index.ts +1 -0
- package/src/components/Items/PinGroupItem/styles.module.scss +38 -0
- package/src/components/Items/SearchItem/SearchItem.tsx +52 -0
- package/src/components/Items/SearchItem/index.ts +1 -0
- package/src/components/Items/SearchItem/styles.module.scss +13 -0
- package/src/components/Items/hooks.tsx +101 -0
- package/src/components/Items/index.ts +9 -0
- package/src/components/Items/styles.module.scss +78 -0
- package/src/components/Items/types.ts +61 -0
- package/src/components/Items/utils.ts +69 -0
- package/src/components/Lists/Droplist/DropList.tsx +166 -0
- package/src/components/Lists/Droplist/index.ts +1 -0
- package/src/components/Lists/List/List.tsx +120 -0
- package/src/components/Lists/List/index.ts +1 -0
- package/src/components/Lists/ListPrivate/ListPrivate.tsx +149 -0
- package/src/components/Lists/ListPrivate/index.ts +1 -0
- package/src/components/Lists/ListPrivate/styles.module.scss +48 -0
- package/src/components/Lists/contexts/CollapseProvider.ts +9 -0
- package/src/components/Lists/contexts/ListProvider.tsx +24 -0
- package/src/components/Lists/contexts/ParentListProvider.tsx +35 -0
- package/src/components/Lists/contexts/SelectionProvider.tsx +171 -0
- package/src/components/Lists/contexts/index.ts +4 -0
- package/src/components/Lists/hooks.ts +99 -0
- package/src/components/Lists/index.ts +10 -0
- package/src/components/Lists/styles.module.scss +73 -0
- package/src/components/Lists/types.ts +47 -0
- package/src/components/index.ts +3 -0
- package/src/helperComponents/CollapseBlockPrivate/CollapseBlockPrivate.tsx +34 -0
- package/src/helperComponents/CollapseBlockPrivate/index.ts +1 -0
- package/src/helperComponents/CollapseBlockPrivate/styles.module.scss +51 -0
- package/src/helperComponents/HiddenTabButton/HiddenTabButton.tsx +27 -0
- package/src/helperComponents/HiddenTabButton/index.ts +1 -0
- package/src/helperComponents/HiddenTabButton/styles.module.scss +11 -0
- package/src/helperComponents/Separator/Separator.tsx +33 -0
- package/src/helperComponents/Separator/index.ts +1 -0
- package/src/helperComponents/Separator/styles.module.scss +63 -0
- package/src/helperComponents/index.ts +3 -0
- package/src/index.ts +1 -0
- package/src/types.ts +14 -0
- package/src/utils.ts +106 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
.listContainer{
|
|
2
|
+
margin:0;
|
|
3
|
+
padding:0;
|
|
4
|
+
}
|
|
5
|
+
.listContainer:focus-visible{
|
|
6
|
+
border:none;
|
|
7
|
+
outline:none;
|
|
8
|
+
}
|
|
9
|
+
.listContainer:focus-visible[data-active]{
|
|
10
|
+
outline-width:var(--border-state-focus-s-border-width, 2px);
|
|
11
|
+
outline-style:var(--border-state-focus-s-border-style, solid);
|
|
12
|
+
outline-color:var(--border-state-focus-s-border-color, );
|
|
13
|
+
outline-offset:calc(var(--border-state-focus-s-border-width, 2px) * -1);
|
|
14
|
+
outline-color:var(--sys-available-complementary, #131313);
|
|
15
|
+
}
|
|
16
|
+
.listContainer:focus-visible[data-active] *{
|
|
17
|
+
cursor:inherit;
|
|
18
|
+
}
|
|
19
|
+
.listContainer li,
|
|
20
|
+
.listContainer ul{
|
|
21
|
+
list-style-type:none;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.wrapper{
|
|
25
|
+
position:relative;
|
|
26
|
+
overflow:hidden;
|
|
27
|
+
display:block;
|
|
28
|
+
box-sizing:border-box;
|
|
29
|
+
padding:var(--dimension-025m, 2px);
|
|
30
|
+
}
|
|
31
|
+
.wrapper:has(.listContainer:focus-visible){
|
|
32
|
+
outline-width:var(--border-state-focus-s-border-width, 2px);
|
|
33
|
+
outline-style:var(--border-state-focus-s-border-style, solid);
|
|
34
|
+
outline-color:var(--border-state-focus-s-border-color, );
|
|
35
|
+
outline-offset:calc(var(--border-state-focus-s-border-width, 2px) * -1);
|
|
36
|
+
outline-color:var(--sys-available-complementary, #131313);
|
|
37
|
+
}
|
|
38
|
+
.wrapper li,
|
|
39
|
+
.wrapper ul{
|
|
40
|
+
list-style-type:none;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.scrollContainerS{
|
|
44
|
+
height:auto;
|
|
45
|
+
max-height:calc(var(--dimension-1m, 8px) * 32);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.scrollContainerM{
|
|
49
|
+
height:auto;
|
|
50
|
+
max-height:calc(var(--dimension-1m, 8px) * 40);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.scrollContainerL{
|
|
54
|
+
height:auto;
|
|
55
|
+
max-height:calc(var(--dimension-1m, 8px) * 48);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.infoBlock{
|
|
59
|
+
font-family:var(--sans-body-s-font-family, SB Sans Interface);
|
|
60
|
+
font-weight:var(--sans-body-s-font-weight, Regular);
|
|
61
|
+
line-height:var(--sans-body-s-line-height, 16px);
|
|
62
|
+
font-size:var(--sans-body-s-font-size, 12px);
|
|
63
|
+
letter-spacing:var(--sans-body-s-letter-spacing, 0.1px);
|
|
64
|
+
paragraph-spacing:var(--sans-body-s-paragraph-spacing, 6.6px);
|
|
65
|
+
display:flex;
|
|
66
|
+
align-items:center;
|
|
67
|
+
justify-content:center;
|
|
68
|
+
padding:var(--dimension-1m, 8px);
|
|
69
|
+
color:var(--sys-neutral-text-support, #565656);
|
|
70
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { FocusEvent, KeyboardEvent, ReactNode, RefObject } from 'react';
|
|
2
|
+
import { DropdownProps } from '@snack-uikit/dropdown';
|
|
3
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
|
+
import { ScrollProps, SearchState } from '../../types';
|
|
5
|
+
import { ItemProps } from '../Items';
|
|
6
|
+
import { ListContextType, SelectionProviderProps } from './contexts';
|
|
7
|
+
export type ListProps = WithSupportProps<{
|
|
8
|
+
items: ItemProps[];
|
|
9
|
+
pinTop?: ItemProps[];
|
|
10
|
+
pinBottom?: ItemProps[];
|
|
11
|
+
footer?: ReactNode;
|
|
12
|
+
search?: SearchState;
|
|
13
|
+
loading?: boolean;
|
|
14
|
+
noData?: string;
|
|
15
|
+
noResults?: string;
|
|
16
|
+
footerActiveElementsRefs?: RefObject<HTMLElement>[];
|
|
17
|
+
} & Pick<SelectionProviderProps, 'value' | 'defaultValue' | 'onChange' | 'selection'> & ListContextType & ScrollProps>;
|
|
18
|
+
export type DroplistProps = {
|
|
19
|
+
triggerElemRef?: RefObject<HTMLElement>;
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
open?: boolean;
|
|
22
|
+
onOpenChange?(open: boolean): void;
|
|
23
|
+
trigger?: DropdownProps['trigger'];
|
|
24
|
+
placement?: DropdownProps['placement'];
|
|
25
|
+
widthStrategy?: DropdownProps['widthStrategy'];
|
|
26
|
+
} & ListProps;
|
|
27
|
+
export type ListPrivateProps = ListProps & {
|
|
28
|
+
nested?: boolean;
|
|
29
|
+
active?: boolean;
|
|
30
|
+
tabIndex?: number;
|
|
31
|
+
onFocus?(e: FocusEvent<HTMLElement>): void;
|
|
32
|
+
onBlur?(e: FocusEvent<HTMLElement>): void;
|
|
33
|
+
onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
|
|
34
|
+
collapse?: 'single' | 'multiple';
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Lists';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
export type CollapseBlockPrivateProps = WithSupportProps<{
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
header: ReactNode;
|
|
6
|
+
expanded: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function CollapseBlockPrivate({ children, expanded, className, header, ...rest }: CollapseBlockPrivateProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import cn from 'classnames';
|
|
14
|
+
import { extractSupportProps } from '@snack-uikit/utils';
|
|
15
|
+
import styles from './styles.module.css';
|
|
16
|
+
// TODO: Add animation. Solution like in Accordion/Tree does not work with Scroll =(
|
|
17
|
+
export function CollapseBlockPrivate(_a) {
|
|
18
|
+
var { children, expanded, className, header } = _a, rest = __rest(_a, ["children", "expanded", "className", "header"]);
|
|
19
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.accordion, className), role: 'menuitem', "aria-haspopup": true, "aria-expanded": expanded }, extractSupportProps(rest), { children: [header, _jsx("div", { className: styles.contentWrapper, "aria-hidden": !expanded, children: _jsx("div", { className: styles.content, "data-content": true, children: children }) })] })));
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CollapseBlockPrivate';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './CollapseBlockPrivate';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
.accordion{
|
|
2
|
+
display:flex;
|
|
3
|
+
flex-direction:column;
|
|
4
|
+
box-sizing:border-box;
|
|
5
|
+
transition:gap 300ms;
|
|
6
|
+
}
|
|
7
|
+
.accordion::-webkit-scrollbar{
|
|
8
|
+
width:0;
|
|
9
|
+
}
|
|
10
|
+
.accordion[aria-expanded=false]{
|
|
11
|
+
gap:0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.contentWrapper{
|
|
15
|
+
box-sizing:border-box;
|
|
16
|
+
width:100%;
|
|
17
|
+
}
|
|
18
|
+
.contentWrapper[aria-hidden=false] > div[data-content]{
|
|
19
|
+
display:block;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.content{
|
|
23
|
+
position:relative;
|
|
24
|
+
display:none;
|
|
25
|
+
box-sizing:border-box;
|
|
26
|
+
width:100%;
|
|
27
|
+
}
|
|
28
|
+
.content::before{
|
|
29
|
+
pointer-events:none;
|
|
30
|
+
content:"";
|
|
31
|
+
position:absolute;
|
|
32
|
+
top:0;
|
|
33
|
+
left:0;
|
|
34
|
+
width:100%;
|
|
35
|
+
height:100%;
|
|
36
|
+
opacity:var(--opacity-a004, 0.04);
|
|
37
|
+
background-color:var(--sys-neutral-accent-default, #757575);
|
|
38
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
type HiddenTabButtonProps = {
|
|
3
|
+
listRef: RefObject<HTMLElement>;
|
|
4
|
+
};
|
|
5
|
+
export declare const HiddenTabButton: import("react").ForwardRefExoticComponent<HiddenTabButtonProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useCallback } from 'react';
|
|
3
|
+
import styles from './styles.module.css';
|
|
4
|
+
export const HiddenTabButton = forwardRef(({ listRef }, ref) => {
|
|
5
|
+
const handleFocus = useCallback((e) => {
|
|
6
|
+
var _a;
|
|
7
|
+
if (e.relatedTarget !== listRef.current) {
|
|
8
|
+
(_a = listRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
9
|
+
}
|
|
10
|
+
e.preventDefault();
|
|
11
|
+
e.stopPropagation();
|
|
12
|
+
}, [listRef]);
|
|
13
|
+
const handleKeyDown = useCallback((e) => {
|
|
14
|
+
e.stopPropagation();
|
|
15
|
+
}, []);
|
|
16
|
+
return _jsx("button", { "aria-hidden": true, ref: ref, onKeyDown: handleKeyDown, onFocus: handleFocus, className: styles.hiddenBtn });
|
|
17
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './HiddenTabButton';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './HiddenTabButton';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Divider } from '@snack-uikit/divider';
|
|
3
|
+
import styles from './styles.module.css';
|
|
4
|
+
export function Separator({ label, divider, mode = 'secondary', size = 's' }) {
|
|
5
|
+
if (label) {
|
|
6
|
+
return (_jsxs("div", { className: styles.separatorWithLabel, "data-size": size, children: [_jsx("span", { className: styles.label, "data-mode": mode, children: label }), divider && _jsx(Divider, { weight: mode === 'primary' ? 'regular' : 'light' })] }));
|
|
7
|
+
}
|
|
8
|
+
if (divider) {
|
|
9
|
+
return (_jsx("div", { className: styles.separatorWithoutLabel, "data-size": size, children: _jsx(Divider, { weight: 'regular' }) }));
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Separator';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Separator';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
.separatorWithLabel{
|
|
2
|
+
display:flex;
|
|
3
|
+
gap:var(--dimension-1m, 8px);
|
|
4
|
+
align-items:flex-end;
|
|
5
|
+
box-sizing:border-box;
|
|
6
|
+
}
|
|
7
|
+
.separatorWithLabel[data-size=s]{
|
|
8
|
+
padding-top:var(--space-drop-list-item-s-container-separator-subheader-vertical-padding, 4px);
|
|
9
|
+
padding-bottom:var(--space-drop-list-item-s-container-separator-subheader-vertical-padding, 4px);
|
|
10
|
+
padding-left:var(--space-drop-list-item-s-container-horizontal-padding, 8px);
|
|
11
|
+
padding-right:var(--space-drop-list-item-s-container-horizontal-padding, 8px);
|
|
12
|
+
gap:var(--space-drop-list-item-s-container-gap, 8px);
|
|
13
|
+
height:var(--size-drop-list-item-s-container-separator-subheader-height, 32px);
|
|
14
|
+
}
|
|
15
|
+
.separatorWithLabel[data-size=s] .label[data-mode=primary]{
|
|
16
|
+
font-family:var(--sans-label-m-font-family, SB Sans Interface);
|
|
17
|
+
font-weight:var(--sans-label-m-font-weight, Semibold);
|
|
18
|
+
line-height:var(--sans-label-m-line-height, 16px);
|
|
19
|
+
font-size:var(--sans-label-m-font-size, 12px);
|
|
20
|
+
letter-spacing:var(--sans-label-m-letter-spacing, -0.1px);
|
|
21
|
+
paragraph-spacing:var(--sans-label-m-paragraph-spacing, 6.6px);
|
|
22
|
+
}
|
|
23
|
+
.separatorWithLabel[data-size=s] .label[data-mode=secondary]{
|
|
24
|
+
font-family:var(--light-label-m-font-family, SB Sans Interface);
|
|
25
|
+
font-weight:var(--light-label-m-font-weight, Regular);
|
|
26
|
+
line-height:var(--light-label-m-line-height, 16px);
|
|
27
|
+
font-size:var(--light-label-m-font-size, 12px);
|
|
28
|
+
letter-spacing:var(--light-label-m-letter-spacing, -0.1px);
|
|
29
|
+
paragraph-spacing:var(--light-label-m-paragraph-spacing, 6.6px);
|
|
30
|
+
}
|
|
31
|
+
.separatorWithLabel[data-size=m]{
|
|
32
|
+
padding-top:var(--space-drop-list-item-m-container-separator-subheader-vertical-padding, 5px);
|
|
33
|
+
padding-bottom:var(--space-drop-list-item-m-container-separator-subheader-vertical-padding, 5px);
|
|
34
|
+
padding-left:var(--space-drop-list-item-m-container-horizontal-padding, 10px);
|
|
35
|
+
padding-right:var(--space-drop-list-item-m-container-horizontal-padding, 10px);
|
|
36
|
+
gap:var(--space-drop-list-item-m-container-gap, 8px);
|
|
37
|
+
height:var(--size-drop-list-item-m-container-separator-subheader-height, 40px);
|
|
38
|
+
}
|
|
39
|
+
.separatorWithLabel[data-size=m] .label[data-mode=primary]{
|
|
40
|
+
font-family:var(--sans-label-l-font-family, SB Sans Interface);
|
|
41
|
+
font-weight:var(--sans-label-l-font-weight, Semibold);
|
|
42
|
+
line-height:var(--sans-label-l-line-height, 20px);
|
|
43
|
+
font-size:var(--sans-label-l-font-size, 14px);
|
|
44
|
+
letter-spacing:var(--sans-label-l-letter-spacing, -0.1px);
|
|
45
|
+
paragraph-spacing:var(--sans-label-l-paragraph-spacing, 7.7px);
|
|
46
|
+
}
|
|
47
|
+
.separatorWithLabel[data-size=m] .label[data-mode=secondary]{
|
|
48
|
+
font-family:var(--light-label-l-font-family, SB Sans Interface);
|
|
49
|
+
font-weight:var(--light-label-l-font-weight, Regular);
|
|
50
|
+
line-height:var(--light-label-l-line-height, 20px);
|
|
51
|
+
font-size:var(--light-label-l-font-size, 14px);
|
|
52
|
+
letter-spacing:var(--light-label-l-letter-spacing, -0.1px);
|
|
53
|
+
paragraph-spacing:var(--light-label-l-paragraph-spacing, 7.7px);
|
|
54
|
+
}
|
|
55
|
+
.separatorWithLabel[data-size=l]{
|
|
56
|
+
padding-top:var(--space-drop-list-item-l-container-separator-subheader-vertical-padding, 6px);
|
|
57
|
+
padding-bottom:var(--space-drop-list-item-l-container-separator-subheader-vertical-padding, 6px);
|
|
58
|
+
padding-left:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
|
|
59
|
+
padding-right:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
|
|
60
|
+
gap:var(--space-drop-list-item-l-container-gap, 8px);
|
|
61
|
+
height:var(--size-drop-list-item-l-container-separator-subheader-height, 48px);
|
|
62
|
+
}
|
|
63
|
+
.separatorWithLabel[data-size=l] .label[data-mode=primary]{
|
|
64
|
+
font-family:var(--sans-title-m-font-family, SB Sans Interface);
|
|
65
|
+
font-weight:var(--sans-title-m-font-weight, Semibold);
|
|
66
|
+
line-height:var(--sans-title-m-line-height, 24px);
|
|
67
|
+
font-size:var(--sans-title-m-font-size, 16px);
|
|
68
|
+
letter-spacing:var(--sans-title-m-letter-spacing, 0.15px);
|
|
69
|
+
paragraph-spacing:var(--sans-title-m-paragraph-spacing, 8.8px);
|
|
70
|
+
}
|
|
71
|
+
.separatorWithLabel[data-size=l] .label[data-mode=secondary]{
|
|
72
|
+
font-family:var(--light-title-m-font-family, SB Sans Interface);
|
|
73
|
+
font-weight:var(--light-title-m-font-weight, Regular);
|
|
74
|
+
line-height:var(--light-title-m-line-height, 24px);
|
|
75
|
+
font-size:var(--light-title-m-font-size, 16px);
|
|
76
|
+
letter-spacing:var(--light-title-m-letter-spacing, 0.15px);
|
|
77
|
+
paragraph-spacing:var(--light-title-m-paragraph-spacing, 8.8px);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.separatorWithoutLabel{
|
|
81
|
+
display:flex;
|
|
82
|
+
align-items:flex-end;
|
|
83
|
+
box-sizing:border-box;
|
|
84
|
+
}
|
|
85
|
+
.separatorWithoutLabel[data-size=s]{
|
|
86
|
+
padding-top:var(--space-drop-list-item-s-container-separator-subheader-vertical-padding, 4px);
|
|
87
|
+
padding-bottom:var(--space-drop-list-item-s-container-separator-subheader-vertical-padding, 4px);
|
|
88
|
+
padding-left:var(--space-drop-list-item-s-container-horizontal-padding, 8px);
|
|
89
|
+
padding-right:var(--space-drop-list-item-s-container-horizontal-padding, 8px);
|
|
90
|
+
}
|
|
91
|
+
.separatorWithoutLabel[data-size=m]{
|
|
92
|
+
padding-top:var(--space-drop-list-item-m-container-separator-subheader-vertical-padding, 5px);
|
|
93
|
+
padding-bottom:var(--space-drop-list-item-m-container-separator-subheader-vertical-padding, 5px);
|
|
94
|
+
padding-left:var(--space-drop-list-item-m-container-horizontal-padding, 10px);
|
|
95
|
+
padding-right:var(--space-drop-list-item-m-container-horizontal-padding, 10px);
|
|
96
|
+
}
|
|
97
|
+
.separatorWithoutLabel[data-size=l]{
|
|
98
|
+
padding-top:var(--space-drop-list-item-l-container-separator-subheader-vertical-padding, 6px);
|
|
99
|
+
padding-bottom:var(--space-drop-list-item-l-container-separator-subheader-vertical-padding, 6px);
|
|
100
|
+
padding-left:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
|
|
101
|
+
padding-right:var(--space-drop-list-item-l-container-horizontal-padding, 12px);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.label{
|
|
105
|
+
flex-shrink:0;
|
|
106
|
+
}
|
|
107
|
+
.label[data-mode=primary]{
|
|
108
|
+
color:var(--sys-neutral-text-main, #333333);
|
|
109
|
+
}
|
|
110
|
+
.label[data-mode=secondary]{
|
|
111
|
+
color:var(--sys-neutral-text-light, #898989);
|
|
112
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
export type SearchState = {
|
|
3
|
+
placeholder?: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
onChange(value: string): void;
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type ScrollProps = {
|
|
9
|
+
scroll?: boolean;
|
|
10
|
+
scrollRef?: RefObject<HTMLElement>;
|
|
11
|
+
scrollContainerRef?: RefObject<HTMLElement>;
|
|
12
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { ItemProps } from './components/Items';
|
|
3
|
+
type WithCollapsedItemsProps = {
|
|
4
|
+
items: ItemProps[];
|
|
5
|
+
openCollapsedItems: Array<number | string>;
|
|
6
|
+
};
|
|
7
|
+
export declare function withCollapsedItems({ items, openCollapsedItems }: WithCollapsedItemsProps): {
|
|
8
|
+
items: ItemProps[];
|
|
9
|
+
itemRefs: RefObject<HTMLButtonElement>[];
|
|
10
|
+
ids: (string | number)[];
|
|
11
|
+
expandedIds: (string | number)[];
|
|
12
|
+
};
|
|
13
|
+
export declare function extractItemRefs(items: ItemProps[]): RefObject<HTMLButtonElement>[];
|
|
14
|
+
export declare function extractItemIds(items: ItemProps[]): Array<string | number>;
|
|
15
|
+
export declare function extractChildIds({ items }: {
|
|
16
|
+
items: ItemProps[];
|
|
17
|
+
}): Array<string | number>;
|
|
18
|
+
export {};
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps, } from './components/Items';
|
|
2
|
+
export function withCollapsedItems({ items, openCollapsedItems }) {
|
|
3
|
+
let itemRefs = [];
|
|
4
|
+
let newItems = [];
|
|
5
|
+
let ids = [];
|
|
6
|
+
let expandedIds = [];
|
|
7
|
+
items.forEach(item => {
|
|
8
|
+
var _a;
|
|
9
|
+
if ((isBaseItemProps(item) || isNextListItemProps(item) || isAccordionItemProps(item)) && !item.disabled) {
|
|
10
|
+
newItems = newItems.concat([item]);
|
|
11
|
+
ids = ids.concat([(_a = item.id) !== null && _a !== void 0 ? _a : '']);
|
|
12
|
+
if (item.itemRef) {
|
|
13
|
+
itemRefs = itemRefs.concat([item.itemRef]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (isNextListItemProps(item) && item.id && !item.disabled) {
|
|
17
|
+
expandedIds = expandedIds.concat(item.id);
|
|
18
|
+
}
|
|
19
|
+
if (isGroupItemProps(item)) {
|
|
20
|
+
const { itemRefs: nestedItemsRefs, ids: nestedIds } = withCollapsedItems({
|
|
21
|
+
items: item.items,
|
|
22
|
+
openCollapsedItems,
|
|
23
|
+
});
|
|
24
|
+
ids = ids.concat(nestedIds);
|
|
25
|
+
itemRefs = itemRefs.concat(nestedItemsRefs);
|
|
26
|
+
}
|
|
27
|
+
if (isAccordionItemProps(item) && item.id && openCollapsedItems.includes(item.id)) {
|
|
28
|
+
const { itemRefs: nestedItemsRefs, ids: nestedIds, items: nestedItems, expandedIds: nestedExpandedIds, } = withCollapsedItems({
|
|
29
|
+
items: item.items,
|
|
30
|
+
openCollapsedItems,
|
|
31
|
+
});
|
|
32
|
+
ids = ids.concat(nestedIds);
|
|
33
|
+
newItems = newItems.concat(nestedItems);
|
|
34
|
+
itemRefs = itemRefs.concat(nestedItemsRefs);
|
|
35
|
+
expandedIds = expandedIds.concat(nestedExpandedIds);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return { items, itemRefs, ids, expandedIds };
|
|
39
|
+
}
|
|
40
|
+
export function extractItemRefs(items) {
|
|
41
|
+
return items.reduce((prev, item) => {
|
|
42
|
+
if (isGroupItemProps(item)) {
|
|
43
|
+
return prev.concat(extractItemRefs(item.items));
|
|
44
|
+
}
|
|
45
|
+
return item.itemRef ? prev.concat([item.itemRef]) : prev;
|
|
46
|
+
}, []);
|
|
47
|
+
}
|
|
48
|
+
export function extractItemIds(items) {
|
|
49
|
+
return items.reduce((prev, item) => {
|
|
50
|
+
if (isGroupItemProps(item)) {
|
|
51
|
+
return prev.concat(extractItemIds(item.items));
|
|
52
|
+
}
|
|
53
|
+
return item.id ? prev.concat([item.id]) : prev;
|
|
54
|
+
}, []);
|
|
55
|
+
}
|
|
56
|
+
export function extractChildIds({ items }) {
|
|
57
|
+
return items
|
|
58
|
+
.filter(item => isAccordionItemProps(item) || isNextListItemProps(item) || isGroupItemProps(item) || !item.disabled)
|
|
59
|
+
.reduce((prev, item) => {
|
|
60
|
+
var _a;
|
|
61
|
+
if (isAccordionItemProps(item) || isNextListItemProps(item)) {
|
|
62
|
+
return prev.concat([(_a = item.id) !== null && _a !== void 0 ? _a : '']).concat(extractChildIds({ items: item.items }));
|
|
63
|
+
}
|
|
64
|
+
if (isGroupItemProps(item)) {
|
|
65
|
+
return prev.concat(extractChildIds({ items: item.items }));
|
|
66
|
+
}
|
|
67
|
+
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
68
|
+
}, []);
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snack-uikit/list",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"title": "List",
|
|
7
|
+
"version": "0.1.1-preview-57c837e3.0",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"*.css",
|
|
10
|
+
"*.woff",
|
|
11
|
+
"*.woff2"
|
|
12
|
+
],
|
|
13
|
+
"description": "",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"module": "./dist/index.js",
|
|
16
|
+
"homepage": "https://cloud-ru-tech.github.io/snack-uikit/packages/list",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/cloud-ru-tech/snack-uikit/tree/master",
|
|
20
|
+
"directory": "packages/list"
|
|
21
|
+
},
|
|
22
|
+
"author": "Nikita Ershov <niershov@cloud.ru>",
|
|
23
|
+
"contributors": [
|
|
24
|
+
"Nikita Ershov <niershov@cloud.ru>"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src",
|
|
29
|
+
"./CHANGELOG.md",
|
|
30
|
+
"./LICENSE"
|
|
31
|
+
],
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"scripts": {},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@snack-uikit/divider": "3.0.1",
|
|
36
|
+
"@snack-uikit/dropdown": "0.1.0",
|
|
37
|
+
"@snack-uikit/icons": "0.20.0",
|
|
38
|
+
"@snack-uikit/loaders": "0.5.0",
|
|
39
|
+
"@snack-uikit/scroll": "0.5.0",
|
|
40
|
+
"@snack-uikit/search-private": "0.1.2",
|
|
41
|
+
"@snack-uikit/toggles": "0.9.4",
|
|
42
|
+
"@snack-uikit/truncate-string": "0.4.5",
|
|
43
|
+
"@snack-uikit/utils": "3.2.0",
|
|
44
|
+
"classnames": "2.5.1",
|
|
45
|
+
"uncontrollable": "8.0.4"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "0539acbacf5bc065cdb55739e06f63366ac9178b"
|
|
48
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { KeyboardEvent, MouseEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
|
|
4
|
+
import { useToggleGroup } from '@snack-uikit/toggles';
|
|
5
|
+
|
|
6
|
+
import { CollapseBlockPrivate } from '../../../helperComponents';
|
|
7
|
+
import { CollapseContext, useCollapseContext, useParentListContext } from '../../Lists/contexts';
|
|
8
|
+
import { BaseItem } from '../BaseItem';
|
|
9
|
+
import { useGroupItemSelection, useRenderItems } from '../hooks';
|
|
10
|
+
import { AccordionItemProps } from '../types';
|
|
11
|
+
|
|
12
|
+
export function AccordionItem({ items: itemsProp, id, disabled, ...option }: AccordionItemProps) {
|
|
13
|
+
const { level = 1 } = useCollapseContext();
|
|
14
|
+
const { toggleOpenCollapsedItems } = useParentListContext();
|
|
15
|
+
const { isIndeterminate, checked, handleOnSelect } = useGroupItemSelection({ items: itemsProp, id, disabled });
|
|
16
|
+
|
|
17
|
+
const { isChecked: open, handleClick: handleChange } = useToggleGroup({ value: String(id) });
|
|
18
|
+
|
|
19
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLButtonElement>) => {
|
|
20
|
+
if (e.key === 'ArrowRight') {
|
|
21
|
+
handleChange();
|
|
22
|
+
toggleOpenCollapsedItems?.(id ?? '');
|
|
23
|
+
|
|
24
|
+
e.preventDefault();
|
|
25
|
+
e.stopPropagation();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const itemsJSX = useRenderItems(itemsProp);
|
|
30
|
+
|
|
31
|
+
const handleItemClick = (e: MouseEvent<HTMLButtonElement>) => {
|
|
32
|
+
handleChange();
|
|
33
|
+
toggleOpenCollapsedItems?.(id ?? '');
|
|
34
|
+
option.onClick?.(e);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<li style={{ listStyleType: 'none' }}>
|
|
39
|
+
<CollapseBlockPrivate
|
|
40
|
+
header={
|
|
41
|
+
<BaseItem
|
|
42
|
+
{...option}
|
|
43
|
+
id={id}
|
|
44
|
+
disabled={disabled}
|
|
45
|
+
expandIcon={open ? <ChevronUpSVG /> : <ChevronDownSVG />}
|
|
46
|
+
onClick={handleItemClick}
|
|
47
|
+
isParentNode
|
|
48
|
+
onKeyDown={handleKeyDown}
|
|
49
|
+
indeterminate={isIndeterminate && !checked}
|
|
50
|
+
onSelect={!disabled ? handleOnSelect : undefined}
|
|
51
|
+
/>
|
|
52
|
+
}
|
|
53
|
+
expanded={open}
|
|
54
|
+
data-test-id={`list__accordion-item-${id}`}
|
|
55
|
+
>
|
|
56
|
+
<CollapseContext.Provider value={{ level: level + 1 }}>{itemsJSX}</CollapseContext.Provider>
|
|
57
|
+
</CollapseBlockPrivate>
|
|
58
|
+
</li>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './AccordionItem';
|