@snack-uikit/notification 0.6.10 → 0.6.11-preview-357970fd.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/README.md +3 -14
- package/dist/components/NotificationPanel/NotificationPanel.d.ts +10 -7
- package/dist/components/NotificationPanel/NotificationPanel.js +7 -4
- package/dist/components/NotificationPanel/styles.module.css +6 -0
- package/package.json +3 -3
- package/src/components/NotificationPanel/NotificationPanel.tsx +62 -59
- package/src/components/NotificationPanel/styles.module.scss +6 -0
package/README.md
CHANGED
|
@@ -98,28 +98,17 @@ const cards = [
|
|
|
98
98
|
### Props
|
|
99
99
|
| name | type | default value | description |
|
|
100
100
|
|------|------|---------------|-------------|
|
|
101
|
-
| triggerElement* | `ReactNode \| ChildrenFunction` | - | Элемент для открытия панели |
|
|
102
101
|
| title* | `string` | - | Заголовок панели |
|
|
103
102
|
| settings | `NotificationPanelSettingsProps` | - | Кнопка настроек и выпадающий список |
|
|
104
103
|
| chips | `Omit<ChipToggleProps, "data-test-id" \| "size">[]` | - | Чипы для фильтрации |
|
|
105
104
|
| readAllButton | `Omit<ButtonFunctionProps, "data-test-id"> & { onClick: MouseEventHandler<HTMLElement>; }` | - | Кнопка в "шапке" панели |
|
|
106
105
|
| footerButton | `{ label: string; onClick: MouseEventHandler<HTMLButtonElement>; }` | - | Кнопка внизу панели |
|
|
106
|
+
| className | `string` | - | CSS-класс |
|
|
107
107
|
| loading | `boolean` | - | Состояние загрузки |
|
|
108
108
|
| content | `ReactNode` | - | Контент для отрисовки (e.g NotificationCard \| NotificationPanel.Blank) |
|
|
109
109
|
| skeletonsAmount | `number` | 2 | Количество скелетонов карточек для отображения при загрузке |
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
| open | `boolean` | - | Управляет состоянием показан/не показан. |
|
|
113
|
-
| onOpenChange | `(isOpen: boolean) => void` | - | Колбек отображения компонента. Срабатывает при изменении состояния open. |
|
|
114
|
-
| hoverDelayOpen | `number` | - | Задержка открытия по ховеру |
|
|
115
|
-
| hoverDelayClose | `number` | - | Задержка закрытия по ховеру |
|
|
116
|
-
| offset | `number` | 0 | Отступ поповера от его триггер-элемента (в пикселях). |
|
|
117
|
-
| closeOnEscapeKey | `boolean` | true | Закрывать ли по нажатию на кнопку `Esc` |
|
|
118
|
-
| triggerClickByKeys | `boolean` | true | Вызывается ли попоповер по нажатию клавиш Enter/Space (при trigger = `click`) |
|
|
119
|
-
| triggerRef | `ForwardedRef<HTMLElement \| ReferenceType>` | - | Ref ссылка на триггер |
|
|
120
|
-
| trigger | enum Trigger: `"click"`, `"hover"`, `"focusVisible"`, `"focus"`, `"hoverAndFocusVisible"`, `"hoverAndFocus"`, `"clickAndFocusVisible"` | - | Условие отображения поповера: <br> - `click` - открывать по клику <br> - `hover` - открывать по ховеру <br> - `focusVisible` - открывать по focus-visible <br> - `focus` - открывать по фокусу <br> - `hoverAndFocusVisible` - открывать по ховеру и focus-visible <br> - `hoverAndFocus` - открывать по ховеру и фокусу <br> - `clickAndFocusVisible` - открывать по клику и focus-visible |
|
|
121
|
-
| placement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Положение поповера относительно своего триггера (children). |
|
|
122
|
-
| contentClassName | `string` | - | CSS-класс для элемента содержащего контент |
|
|
110
|
+
| scrollRef | `RefObject<HTMLElement>` | - | Ссылка на элемент, обозначающий самый конец прокручиваемого списка |
|
|
111
|
+
| scrollContainerRef | `RefObject<HTMLElement>` | - | Ссылка на контейнер, который скроллится |
|
|
123
112
|
## NotificationPanel.Blank
|
|
124
113
|
### Props
|
|
125
114
|
| name | type | default value | description |
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { MouseEventHandler, ReactNode } from 'react';
|
|
1
|
+
import { MouseEventHandler, ReactNode, RefObject } from 'react';
|
|
2
2
|
import { ButtonFunctionProps } from '@snack-uikit/button';
|
|
3
3
|
import { ChipToggleProps } from '@snack-uikit/chips';
|
|
4
|
-
import {
|
|
4
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
5
5
|
import { NotificationPanelBlank, NotificationPanelBlankProps, NotificationPanelSettingsProps } from './components';
|
|
6
6
|
export type { NotificationPanelBlankProps };
|
|
7
|
-
export type NotificationPanelProps = {
|
|
7
|
+
export type NotificationPanelProps = WithSupportProps<{
|
|
8
8
|
/** Заголовок панели */
|
|
9
9
|
title: string;
|
|
10
10
|
/** Кнопка настроек и выпадающий список */
|
|
@@ -15,22 +15,25 @@ export type NotificationPanelProps = {
|
|
|
15
15
|
readAllButton?: Omit<ButtonFunctionProps, 'data-test-id'> & {
|
|
16
16
|
onClick: ButtonFunctionProps['onClick'];
|
|
17
17
|
};
|
|
18
|
-
/** Элемент для открытия панели */
|
|
19
|
-
triggerElement: NotificationPanelPopoverProps['children'];
|
|
20
18
|
/** Кнопка внизу панели */
|
|
21
19
|
footerButton?: {
|
|
22
20
|
label: string;
|
|
23
21
|
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
24
22
|
};
|
|
23
|
+
className?: string;
|
|
25
24
|
/** Состояние загрузки */
|
|
26
25
|
loading?: boolean;
|
|
27
26
|
/** Контент для отрисовки (e.g NotificationCard | NotificationPanel.Blank) */
|
|
28
27
|
content?: ReactNode;
|
|
29
28
|
/** Количество скелетонов карточек для отображения при загрузке */
|
|
30
29
|
skeletonsAmount?: number;
|
|
31
|
-
|
|
30
|
+
/** Ссылка на элемент, обозначающий самый конец прокручиваемого списка */
|
|
31
|
+
scrollRef?: RefObject<HTMLElement>;
|
|
32
|
+
/** Ссылка на контейнер, который скроллится */
|
|
33
|
+
scrollContainerRef?: RefObject<HTMLElement>;
|
|
34
|
+
}>;
|
|
32
35
|
/** Компонент панели для уведомлений */
|
|
33
|
-
export declare function NotificationPanel({ title,
|
|
36
|
+
export declare function NotificationPanel({ title, settings, chips, readAllButton, footerButton, content, loading, skeletonsAmount, scrollRef, scrollContainerRef, className, ...rest }: NotificationPanelProps): import("react/jsx-runtime").JSX.Element;
|
|
34
37
|
export declare namespace NotificationPanel {
|
|
35
38
|
const Blank: typeof NotificationPanelBlank;
|
|
36
39
|
type BlankProps = NotificationPanelBlankProps;
|
|
@@ -10,7 +10,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { createElement as _createElement } from "react";
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import cn from 'classnames';
|
|
14
15
|
import { useMemo } from 'react';
|
|
15
16
|
import { ButtonFunction } from '@snack-uikit/button';
|
|
16
17
|
import { ChipToggle } from '@snack-uikit/chips';
|
|
@@ -18,16 +19,18 @@ import { Scroll } from '@snack-uikit/scroll';
|
|
|
18
19
|
import { SkeletonContextProvider, WithSkeleton } from '@snack-uikit/skeleton';
|
|
19
20
|
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
20
21
|
import { Typography } from '@snack-uikit/typography';
|
|
21
|
-
import {
|
|
22
|
+
import { extractSupportProps } from '@snack-uikit/utils';
|
|
22
23
|
import { NotificationCardSkeleton } from '../NotificationCard/components';
|
|
23
24
|
import { NotificationPanelBlank, NotificationPanelSettings, } from './components';
|
|
24
25
|
import { TEST_IDS } from './constants';
|
|
25
26
|
import styles from './styles.module.css';
|
|
26
27
|
/** Компонент панели для уведомлений */
|
|
27
28
|
export function NotificationPanel(_a) {
|
|
28
|
-
var { title,
|
|
29
|
+
var { title, settings, chips, readAllButton, footerButton, content, loading, skeletonsAmount = 2, scrollRef, scrollContainerRef, className } = _a, rest = __rest(_a, ["title", "settings", "chips", "readAllButton", "footerButton", "content", "loading", "skeletonsAmount", "scrollRef", "scrollContainerRef", "className"]);
|
|
29
30
|
const skeletons = useMemo(() => Array.from({ length: skeletonsAmount }, (_, i) => i), [skeletonsAmount]);
|
|
30
|
-
return (
|
|
31
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className) }, extractSupportProps(rest), { children: [_jsxs("div", { className: styles.notificationPanelHeader, children: [_jsxs("div", { className: styles.notificationPanelHeadline, children: [_jsx(Typography.SansHeadlineS, { className: styles.notificationPanelTitle, children: _jsx(TruncateString, { text: title, "data-test-id": TEST_IDS.title }) }), settings && _jsx(NotificationPanelSettings, Object.assign({}, settings))] }), _jsxs("div", { className: styles.notificationPanelHeaderFunctions, children: [_jsx("div", { className: styles.notificationPanelChips, children: chips === null || chips === void 0 ? void 0 : chips.map(chip => (_createElement(ChipToggle, Object.assign({}, chip, { key: chip.label, "data-test-id": `${TEST_IDS.chip}-${chip.label}`, size: 'xs', disabled: chip.disabled || loading })))) }), readAllButton && (_jsx(ButtonFunction, Object.assign({}, readAllButton, { disabled: readAllButton.disabled || loading, "data-test-id": TEST_IDS.readAll })))] })] }), _jsxs(Scroll, { size: 'm', className: styles.notificationPanelBody, ref: scrollContainerRef, children: [content, loading && (_jsx(SkeletonContextProvider, { loading: loading || false, children: skeletons.map(skeleton => (_jsx(WithSkeleton, { skeleton: _jsx(NotificationCardSkeleton, {}) }, skeleton))) })), _jsx("div", { className: styles.scrollStub, ref: scrollRef })] }),
|
|
32
|
+
// !loading &&
|
|
33
|
+
footerButton && (_jsx("button", { className: styles.notificationPanelFooterButton, "data-test-id": TEST_IDS.footerButton, children: _jsx(Typography.SansLabelS, { children: footerButton.label }) }))] })));
|
|
31
34
|
}
|
|
32
35
|
(function (NotificationPanel) {
|
|
33
36
|
NotificationPanel.Blank = NotificationPanelBlank;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Notification",
|
|
7
|
-
"version": "0.6.
|
|
7
|
+
"version": "0.6.11-preview-357970fd.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@snack-uikit/icon-predefined": "0.4.1",
|
|
38
38
|
"@snack-uikit/icons": "0.20.1",
|
|
39
39
|
"@snack-uikit/link": "0.11.1",
|
|
40
|
-
"@snack-uikit/list": "0.3.0",
|
|
40
|
+
"@snack-uikit/list": "0.3.1-preview-357970fd.0",
|
|
41
41
|
"@snack-uikit/popover-private": "0.13.0",
|
|
42
42
|
"@snack-uikit/scroll": "0.5.0",
|
|
43
43
|
"@snack-uikit/skeleton": "0.3.2",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"@snack-uikit/utils": "3.2.0",
|
|
48
48
|
"classnames": "2.3.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "2a29639b6595426f8870afc293553dd9ee12f188"
|
|
51
51
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
import { MouseEventHandler, ReactNode, RefObject, useMemo } from 'react';
|
|
2
3
|
|
|
3
4
|
import { ButtonFunction, ButtonFunctionProps } from '@snack-uikit/button';
|
|
4
5
|
import { ChipToggle, ChipToggleProps } from '@snack-uikit/chips';
|
|
@@ -6,8 +7,8 @@ import { Scroll } from '@snack-uikit/scroll';
|
|
|
6
7
|
import { SkeletonContextProvider, WithSkeleton } from '@snack-uikit/skeleton';
|
|
7
8
|
import { TruncateString } from '@snack-uikit/truncate-string';
|
|
8
9
|
import { Typography } from '@snack-uikit/typography';
|
|
10
|
+
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
9
11
|
|
|
10
|
-
import { NotificationPanelPopover, NotificationPanelPopoverProps } from '../../helperComponents';
|
|
11
12
|
import { NotificationCardSkeleton } from '../NotificationCard/components';
|
|
12
13
|
import {
|
|
13
14
|
NotificationPanelBlank,
|
|
@@ -20,7 +21,7 @@ import styles from './styles.module.scss';
|
|
|
20
21
|
|
|
21
22
|
export type { NotificationPanelBlankProps };
|
|
22
23
|
|
|
23
|
-
export type NotificationPanelProps = {
|
|
24
|
+
export type NotificationPanelProps = WithSupportProps<{
|
|
24
25
|
/** Заголовок панели */
|
|
25
26
|
title: string;
|
|
26
27
|
/** Кнопка настроек и выпадающий список */
|
|
@@ -31,25 +32,27 @@ export type NotificationPanelProps = {
|
|
|
31
32
|
readAllButton?: Omit<ButtonFunctionProps, 'data-test-id'> & {
|
|
32
33
|
onClick: ButtonFunctionProps['onClick'];
|
|
33
34
|
};
|
|
34
|
-
/** Элемент для открытия панели */
|
|
35
|
-
triggerElement: NotificationPanelPopoverProps['children'];
|
|
36
35
|
/** Кнопка внизу панели */
|
|
37
36
|
footerButton?: {
|
|
38
37
|
label: string;
|
|
39
38
|
onClick: MouseEventHandler<HTMLButtonElement>;
|
|
40
39
|
};
|
|
40
|
+
className?: string;
|
|
41
41
|
/** Состояние загрузки */
|
|
42
42
|
loading?: boolean;
|
|
43
43
|
/** Контент для отрисовки (e.g NotificationCard | NotificationPanel.Blank) */
|
|
44
44
|
content?: ReactNode;
|
|
45
45
|
/** Количество скелетонов карточек для отображения при загрузке */
|
|
46
46
|
skeletonsAmount?: number;
|
|
47
|
-
|
|
47
|
+
/** Ссылка на элемент, обозначающий самый конец прокручиваемого списка */
|
|
48
|
+
scrollRef?: RefObject<HTMLElement>;
|
|
49
|
+
/** Ссылка на контейнер, который скроллится */
|
|
50
|
+
scrollContainerRef?: RefObject<HTMLElement>;
|
|
51
|
+
}>;
|
|
48
52
|
|
|
49
53
|
/** Компонент панели для уведомлений */
|
|
50
54
|
export function NotificationPanel({
|
|
51
55
|
title,
|
|
52
|
-
triggerElement,
|
|
53
56
|
settings,
|
|
54
57
|
chips,
|
|
55
58
|
readAllButton,
|
|
@@ -57,69 +60,69 @@ export function NotificationPanel({
|
|
|
57
60
|
content,
|
|
58
61
|
loading,
|
|
59
62
|
skeletonsAmount = 2,
|
|
63
|
+
scrollRef,
|
|
64
|
+
scrollContainerRef,
|
|
65
|
+
className,
|
|
60
66
|
...rest
|
|
61
67
|
}: NotificationPanelProps) {
|
|
62
68
|
const skeletons = useMemo(() => Array.from({ length: skeletonsAmount }, (_, i) => i), [skeletonsAmount]);
|
|
63
69
|
|
|
64
70
|
return (
|
|
65
|
-
<
|
|
66
|
-
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<Typography.SansHeadlineS className={styles.notificationPanelTitle}>
|
|
72
|
-
<TruncateString text={title} data-test-id={TEST_IDS.title} />
|
|
73
|
-
</Typography.SansHeadlineS>
|
|
71
|
+
<div className={cn(styles.wrapper, className)} {...extractSupportProps(rest)}>
|
|
72
|
+
<div className={styles.notificationPanelHeader}>
|
|
73
|
+
<div className={styles.notificationPanelHeadline}>
|
|
74
|
+
<Typography.SansHeadlineS className={styles.notificationPanelTitle}>
|
|
75
|
+
<TruncateString text={title} data-test-id={TEST_IDS.title} />
|
|
76
|
+
</Typography.SansHeadlineS>
|
|
74
77
|
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
{settings && <NotificationPanelSettings {...settings} />}
|
|
79
|
+
</div>
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
</div>
|
|
90
|
-
|
|
91
|
-
{readAllButton && (
|
|
92
|
-
<ButtonFunction
|
|
93
|
-
{...readAllButton}
|
|
94
|
-
disabled={readAllButton.disabled || loading}
|
|
95
|
-
data-test-id={TEST_IDS.readAll}
|
|
96
|
-
/>
|
|
97
|
-
)}
|
|
98
|
-
</div>
|
|
81
|
+
<div className={styles.notificationPanelHeaderFunctions}>
|
|
82
|
+
<div className={styles.notificationPanelChips}>
|
|
83
|
+
{chips?.map(chip => (
|
|
84
|
+
<ChipToggle
|
|
85
|
+
{...chip}
|
|
86
|
+
key={chip.label}
|
|
87
|
+
data-test-id={`${TEST_IDS.chip}-${chip.label}`}
|
|
88
|
+
size='xs'
|
|
89
|
+
disabled={chip.disabled || loading}
|
|
90
|
+
/>
|
|
91
|
+
))}
|
|
99
92
|
</div>
|
|
100
93
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
</SkeletonContextProvider>
|
|
108
|
-
) : (
|
|
109
|
-
content
|
|
110
|
-
)}
|
|
111
|
-
</Scroll>
|
|
112
|
-
|
|
113
|
-
{!loading && footerButton && (
|
|
114
|
-
<button className={styles.notificationPanelFooterButton} data-test-id={TEST_IDS.footerButton}>
|
|
115
|
-
<Typography.SansLabelS>{footerButton.label}</Typography.SansLabelS>
|
|
116
|
-
</button>
|
|
94
|
+
{readAllButton && (
|
|
95
|
+
<ButtonFunction
|
|
96
|
+
{...readAllButton}
|
|
97
|
+
disabled={readAllButton.disabled || loading}
|
|
98
|
+
data-test-id={TEST_IDS.readAll}
|
|
99
|
+
/>
|
|
117
100
|
)}
|
|
118
|
-
|
|
101
|
+
</div>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<Scroll size='m' className={styles.notificationPanelBody} ref={scrollContainerRef}>
|
|
105
|
+
{content}
|
|
106
|
+
{loading && (
|
|
107
|
+
<SkeletonContextProvider loading={loading || false}>
|
|
108
|
+
{skeletons.map(skeleton => (
|
|
109
|
+
<WithSkeleton key={skeleton} skeleton={<NotificationCardSkeleton />} />
|
|
110
|
+
))}
|
|
111
|
+
</SkeletonContextProvider>
|
|
112
|
+
)}
|
|
113
|
+
|
|
114
|
+
<div className={styles.scrollStub} ref={scrollRef as RefObject<HTMLDivElement>} />
|
|
115
|
+
</Scroll>
|
|
116
|
+
|
|
117
|
+
{
|
|
118
|
+
// !loading &&
|
|
119
|
+
footerButton && (
|
|
120
|
+
<button className={styles.notificationPanelFooterButton} data-test-id={TEST_IDS.footerButton}>
|
|
121
|
+
<Typography.SansLabelS>{footerButton.label}</Typography.SansLabelS>
|
|
122
|
+
</button>
|
|
123
|
+
)
|
|
119
124
|
}
|
|
120
|
-
>
|
|
121
|
-
{triggerElement}
|
|
122
|
-
</NotificationPanelPopover>
|
|
125
|
+
</div>
|
|
123
126
|
);
|
|
124
127
|
}
|
|
125
128
|
|