@cloud-ru/uikit-product-widget 0.9.4
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 +998 -0
- package/LICENSE +201 -0
- package/README.md +8 -0
- package/dist/cjs/components/ProductsWidget/ProductsWidget.d.ts +10 -0
- package/dist/cjs/components/ProductsWidget/ProductsWidget.js +36 -0
- package/dist/cjs/components/ProductsWidget/constants.d.ts +4 -0
- package/dist/cjs/components/ProductsWidget/constants.js +7 -0
- package/dist/cjs/components/ProductsWidget/index.d.ts +1 -0
- package/dist/cjs/components/ProductsWidget/index.js +17 -0
- package/dist/cjs/components/ProductsWidget/styles.module.css +45 -0
- package/dist/cjs/components/ProductsWidget/utils/getLoadingCards.d.ts +6 -0
- package/dist/cjs/components/ProductsWidget/utils/getLoadingCards.js +17 -0
- package/dist/cjs/components/ProductsWidget/utils/getProductColumns.d.ts +8 -0
- package/dist/cjs/components/ProductsWidget/utils/getProductColumns.js +19 -0
- package/dist/cjs/components/SolutionsWidget/SolutionsWidget.d.ts +8 -0
- package/dist/cjs/components/SolutionsWidget/SolutionsWidget.js +30 -0
- package/dist/cjs/components/SolutionsWidget/index.d.ts +1 -0
- package/dist/cjs/components/SolutionsWidget/index.js +17 -0
- package/dist/cjs/components/SolutionsWidget/styles.module.css +28 -0
- package/dist/cjs/components/Widget/Widget.d.ts +2 -0
- package/dist/cjs/components/Widget/Widget.js +101 -0
- package/dist/cjs/components/Widget/index.d.ts +2 -0
- package/dist/cjs/components/Widget/index.js +18 -0
- package/dist/cjs/components/Widget/styles.module.css +56 -0
- package/dist/cjs/components/Widget/types.d.ts +27 -0
- package/dist/cjs/components/Widget/types.js +2 -0
- package/dist/cjs/components/index.d.ts +3 -0
- package/dist/cjs/components/index.js +19 -0
- package/dist/cjs/helperComponents/Actions/ActionView.d.ts +10 -0
- package/dist/cjs/helperComponents/Actions/ActionView.js +49 -0
- package/dist/cjs/helperComponents/Actions/DesktopActions.d.ts +2 -0
- package/dist/cjs/helperComponents/Actions/DesktopActions.js +19 -0
- package/dist/cjs/helperComponents/Actions/MobileActions.d.ts +2 -0
- package/dist/cjs/helperComponents/Actions/MobileActions.js +70 -0
- package/dist/cjs/helperComponents/Actions/constants.d.ts +9 -0
- package/dist/cjs/helperComponents/Actions/constants.js +12 -0
- package/dist/cjs/helperComponents/Actions/helpers.d.ts +2 -0
- package/dist/cjs/helperComponents/Actions/helpers.js +6 -0
- package/dist/cjs/helperComponents/Actions/index.d.ts +3 -0
- package/dist/cjs/helperComponents/Actions/index.js +19 -0
- package/dist/cjs/helperComponents/Actions/styles.module.css +35 -0
- package/dist/cjs/helperComponents/Actions/types.d.ts +30 -0
- package/dist/cjs/helperComponents/Actions/types.js +2 -0
- package/dist/cjs/helperComponents/ButtonDropdown/ButtonDropdown.d.ts +8 -0
- package/dist/cjs/helperComponents/ButtonDropdown/ButtonDropdown.js +13 -0
- package/dist/cjs/helperComponents/ButtonDropdown/index.d.ts +1 -0
- package/dist/cjs/helperComponents/ButtonDropdown/index.js +17 -0
- package/dist/cjs/helperComponents/ButtonDroplist/ButtonDroplist.d.ts +12 -0
- package/dist/cjs/helperComponents/ButtonDroplist/ButtonDroplist.js +21 -0
- package/dist/cjs/helperComponents/ButtonDroplist/index.d.ts +1 -0
- package/dist/cjs/helperComponents/ButtonDroplist/index.js +17 -0
- package/dist/cjs/helperComponents/ButtonKebab/ButtonKebab.d.ts +8 -0
- package/dist/cjs/helperComponents/ButtonKebab/ButtonKebab.js +15 -0
- package/dist/cjs/helperComponents/ButtonKebab/index.d.ts +1 -0
- package/dist/cjs/helperComponents/ButtonKebab/index.js +17 -0
- package/dist/cjs/helperComponents/index.d.ts +1 -0
- package/dist/cjs/helperComponents/index.js +17 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +17 -0
- package/dist/esm/components/ProductsWidget/ProductsWidget.d.ts +10 -0
- package/dist/esm/components/ProductsWidget/ProductsWidget.js +30 -0
- package/dist/esm/components/ProductsWidget/constants.d.ts +4 -0
- package/dist/esm/components/ProductsWidget/constants.js +4 -0
- package/dist/esm/components/ProductsWidget/index.d.ts +1 -0
- package/dist/esm/components/ProductsWidget/index.js +1 -0
- package/dist/esm/components/ProductsWidget/styles.module.css +45 -0
- package/dist/esm/components/ProductsWidget/utils/getLoadingCards.d.ts +6 -0
- package/dist/esm/components/ProductsWidget/utils/getLoadingCards.js +14 -0
- package/dist/esm/components/ProductsWidget/utils/getProductColumns.d.ts +8 -0
- package/dist/esm/components/ProductsWidget/utils/getProductColumns.js +16 -0
- package/dist/esm/components/SolutionsWidget/SolutionsWidget.d.ts +8 -0
- package/dist/esm/components/SolutionsWidget/SolutionsWidget.js +24 -0
- package/dist/esm/components/SolutionsWidget/index.d.ts +1 -0
- package/dist/esm/components/SolutionsWidget/index.js +1 -0
- package/dist/esm/components/SolutionsWidget/styles.module.css +28 -0
- package/dist/esm/components/Widget/Widget.d.ts +2 -0
- package/dist/esm/components/Widget/Widget.js +95 -0
- package/dist/esm/components/Widget/index.d.ts +2 -0
- package/dist/esm/components/Widget/index.js +2 -0
- package/dist/esm/components/Widget/styles.module.css +56 -0
- package/dist/esm/components/Widget/types.d.ts +27 -0
- package/dist/esm/components/Widget/types.js +1 -0
- package/dist/esm/components/index.d.ts +3 -0
- package/dist/esm/components/index.js +3 -0
- package/dist/esm/helperComponents/Actions/ActionView.d.ts +10 -0
- package/dist/esm/helperComponents/Actions/ActionView.js +46 -0
- package/dist/esm/helperComponents/Actions/DesktopActions.d.ts +2 -0
- package/dist/esm/helperComponents/Actions/DesktopActions.js +13 -0
- package/dist/esm/helperComponents/Actions/MobileActions.d.ts +2 -0
- package/dist/esm/helperComponents/Actions/MobileActions.js +64 -0
- package/dist/esm/helperComponents/Actions/constants.d.ts +9 -0
- package/dist/esm/helperComponents/Actions/constants.js +9 -0
- package/dist/esm/helperComponents/Actions/helpers.d.ts +2 -0
- package/dist/esm/helperComponents/Actions/helpers.js +3 -0
- package/dist/esm/helperComponents/Actions/index.d.ts +3 -0
- package/dist/esm/helperComponents/Actions/index.js +3 -0
- package/dist/esm/helperComponents/Actions/styles.module.css +35 -0
- package/dist/esm/helperComponents/Actions/types.d.ts +30 -0
- package/dist/esm/helperComponents/Actions/types.js +1 -0
- package/dist/esm/helperComponents/ButtonDropdown/ButtonDropdown.d.ts +8 -0
- package/dist/esm/helperComponents/ButtonDropdown/ButtonDropdown.js +10 -0
- package/dist/esm/helperComponents/ButtonDropdown/index.d.ts +1 -0
- package/dist/esm/helperComponents/ButtonDropdown/index.js +1 -0
- package/dist/esm/helperComponents/ButtonDroplist/ButtonDroplist.d.ts +12 -0
- package/dist/esm/helperComponents/ButtonDroplist/ButtonDroplist.js +18 -0
- package/dist/esm/helperComponents/ButtonDroplist/index.d.ts +1 -0
- package/dist/esm/helperComponents/ButtonDroplist/index.js +1 -0
- package/dist/esm/helperComponents/ButtonKebab/ButtonKebab.d.ts +8 -0
- package/dist/esm/helperComponents/ButtonKebab/ButtonKebab.js +12 -0
- package/dist/esm/helperComponents/ButtonKebab/index.d.ts +1 -0
- package/dist/esm/helperComponents/ButtonKebab/index.js +1 -0
- package/dist/esm/helperComponents/index.d.ts +1 -0
- package/dist/esm/helperComponents/index.js +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/package.json +58 -0
- package/src/components/ProductsWidget/ProductsWidget.tsx +66 -0
- package/src/components/ProductsWidget/constants.ts +7 -0
- package/src/components/ProductsWidget/index.ts +1 -0
- package/src/components/ProductsWidget/styles.module.scss +40 -0
- package/src/components/ProductsWidget/utils/getLoadingCards.tsx +23 -0
- package/src/components/ProductsWidget/utils/getProductColumns.tsx +30 -0
- package/src/components/SolutionsWidget/SolutionsWidget.tsx +43 -0
- package/src/components/SolutionsWidget/index.ts +1 -0
- package/src/components/SolutionsWidget/styles.module.scss +31 -0
- package/src/components/Widget/Widget.tsx +173 -0
- package/src/components/Widget/index.ts +2 -0
- package/src/components/Widget/styles.module.scss +60 -0
- package/src/components/Widget/types.ts +39 -0
- package/src/components/index.ts +3 -0
- package/src/helperComponents/Actions/ActionView.tsx +67 -0
- package/src/helperComponents/Actions/DesktopActions.tsx +25 -0
- package/src/helperComponents/Actions/MobileActions.tsx +111 -0
- package/src/helperComponents/Actions/constants.ts +9 -0
- package/src/helperComponents/Actions/helpers.ts +5 -0
- package/src/helperComponents/Actions/index.ts +3 -0
- package/src/helperComponents/Actions/styles.module.scss +42 -0
- package/src/helperComponents/Actions/types.ts +33 -0
- package/src/helperComponents/ButtonDropdown/ButtonDropdown.tsx +22 -0
- package/src/helperComponents/ButtonDropdown/index.ts +1 -0
- package/src/helperComponents/ButtonDroplist/ButtonDroplist.tsx +46 -0
- package/src/helperComponents/ButtonDroplist/index.ts +1 -0
- package/src/helperComponents/ButtonKebab/ButtonKebab.tsx +31 -0
- package/src/helperComponents/ButtonKebab/index.ts +1 -0
- package/src/helperComponents/index.ts +1 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,30 @@
|
|
|
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 { useMemo } from 'react';
|
|
14
|
+
import { useLocale } from '@sbercloud/uikit-product-locale';
|
|
15
|
+
import { AdaptiveCarousel } from '@sbercloud/uikit-product-mobile-carousel';
|
|
16
|
+
import { extractSupportProps } from '@sbercloud/uikit-product-utils';
|
|
17
|
+
import { Typography } from '@snack-uikit/typography';
|
|
18
|
+
import { COLUMN_SIZE, MOBILE_COLUMN_SIZE, MOBILE_ROW_SIZE, ROW_SIZE } from './constants';
|
|
19
|
+
import styles from './styles.module.css';
|
|
20
|
+
import { getLoadingCards } from './utils/getLoadingCards';
|
|
21
|
+
import { getProductColumns } from './utils/getProductColumns';
|
|
22
|
+
export function ProductsWidget(_a) {
|
|
23
|
+
var { layoutType, cards = [], loading = false, columnSize: columnSizeProp = COLUMN_SIZE, rowSize: rowSizeProp = ROW_SIZE, arrows = true, pagination = true } = _a, rest = __rest(_a, ["layoutType", "cards", "loading", "columnSize", "rowSize", "arrows", "pagination"]);
|
|
24
|
+
const { t } = useLocale('Widget');
|
|
25
|
+
const isMobile = layoutType === 'mobile';
|
|
26
|
+
const columnSize = isMobile ? MOBILE_COLUMN_SIZE : columnSizeProp;
|
|
27
|
+
const rowSize = isMobile ? MOBILE_ROW_SIZE : rowSizeProp;
|
|
28
|
+
const productsCards = useMemo(() => (loading ? getLoadingCards({ columnSize, rowSize }) : getProductColumns({ cards, columnSize, rowSize })), [columnSize, loading, cards, rowSize]);
|
|
29
|
+
return (_jsxs("div", Object.assign({ className: styles.wrapper }, extractSupportProps(rest), { children: [_jsx("div", { className: styles.headerWrapper, children: _jsx(Typography.SansTitleL, { tag: 'h5', children: t('Products.title') }) }), _jsx(AdaptiveCarousel, { layoutType: layoutType, gap: '8px', infiniteScroll: !isMobile, swipe: false, showItems: rowSize, arrows: arrows, pagination: pagination, children: productsCards.map((d, index) => (_jsx("div", { className: styles.column, children: d }, index))) })] })));
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ProductsWidget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ProductsWidget';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
.wrapper{
|
|
2
|
+
display:flex;
|
|
3
|
+
flex-direction:column;
|
|
4
|
+
gap:16px;
|
|
5
|
+
grid-column:span 12;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.column{
|
|
9
|
+
display:flex;
|
|
10
|
+
flex-direction:column;
|
|
11
|
+
gap:var(--dimension-1m, 8px);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.headerWrapper{
|
|
15
|
+
display:flex;
|
|
16
|
+
align-items:center;
|
|
17
|
+
justify-content:space-between;
|
|
18
|
+
gap:var(--dimension-050m, 4px);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.arrowWrapper{
|
|
22
|
+
display:flex;
|
|
23
|
+
align-items:center;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.pageNumber{
|
|
27
|
+
font-family:var(--sans-label-l-font-family, SB Sans Interface);
|
|
28
|
+
font-weight:var(--sans-label-l-font-weight, Semibold);
|
|
29
|
+
line-height:var(--sans-label-l-line-height, 20px);
|
|
30
|
+
font-size:var(--sans-label-l-font-size, 14px);
|
|
31
|
+
letter-spacing:var(--sans-label-l-letter-spacing, 0px);
|
|
32
|
+
paragraph-spacing:var(--sans-label-l-paragraph-spacing, 7.7px);
|
|
33
|
+
color:var(--sys-neutral-text-main, #41424e);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.pageTotal{
|
|
37
|
+
font-family:var(--sans-body-m-font-family, SB Sans Interface);
|
|
38
|
+
font-weight:var(--sans-body-m-font-weight, Regular);
|
|
39
|
+
line-height:var(--sans-body-m-line-height, 20px);
|
|
40
|
+
font-size:var(--sans-body-m-font-size, 14px);
|
|
41
|
+
letter-spacing:var(--sans-body-m-letter-spacing, 0.1px);
|
|
42
|
+
paragraph-spacing:var(--sans-body-m-paragraph-spacing, 7.7px);
|
|
43
|
+
margin-right:var(--dimension-050m, 4px);
|
|
44
|
+
color:var(--sys-neutral-text-support, #6d707f);
|
|
45
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Skeleton } from '@snack-uikit/skeleton';
|
|
3
|
+
import { COLUMN_SIZE, ROW_SIZE } from '../constants';
|
|
4
|
+
export function getLoadingCards({ columnSize = COLUMN_SIZE, rowSize = ROW_SIZE }) {
|
|
5
|
+
const result = [];
|
|
6
|
+
for (let i = 0; i < rowSize; i++) {
|
|
7
|
+
const columnSkeletons = [];
|
|
8
|
+
for (let j = 0; j < columnSize; j++) {
|
|
9
|
+
columnSkeletons.push(_jsx(Skeleton, { loading: true, borderRadius: 8, height: 48 }));
|
|
10
|
+
}
|
|
11
|
+
result.push(columnSkeletons);
|
|
12
|
+
}
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type GetProductColumnsParams = {
|
|
3
|
+
cards: ReactNode[];
|
|
4
|
+
columnSize: number;
|
|
5
|
+
rowSize: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function getProductColumns({ cards, columnSize }: GetProductColumnsParams): (string | number | boolean | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined)[][];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function getProductColumns({ cards, columnSize }) {
|
|
2
|
+
const result = [];
|
|
3
|
+
for (let i = 0; i < cards.length; i += columnSize) {
|
|
4
|
+
const innerCards = [];
|
|
5
|
+
for (let j = 0; j < columnSize; j++) {
|
|
6
|
+
const index = i + j;
|
|
7
|
+
if (index >= cards.length) {
|
|
8
|
+
break;
|
|
9
|
+
}
|
|
10
|
+
const card = cards[index];
|
|
11
|
+
innerCards.push(card);
|
|
12
|
+
}
|
|
13
|
+
result.push(innerCards);
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CardSuggestProps } from '@sbercloud/uikit-product-card-predefined';
|
|
2
|
+
import { WithLayoutType, WithSupportProps } from '@sbercloud/uikit-product-utils';
|
|
3
|
+
import { LinkProps } from '@snack-uikit/link';
|
|
4
|
+
export type SolutionsWidgetProps = WithLayoutType<WithSupportProps<{
|
|
5
|
+
moreLink?: Pick<LinkProps, 'onClick' | 'href'>;
|
|
6
|
+
cards: Pick<CardSuggestProps, 'description' | 'title' | 'onClick'>[];
|
|
7
|
+
}>>;
|
|
8
|
+
export declare function SolutionsWidget({ layoutType, moreLink, cards, ...rest }: SolutionsWidgetProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { CardSuggest } from '@sbercloud/uikit-product-card-predefined';
|
|
14
|
+
import { useLocale } from '@sbercloud/uikit-product-locale';
|
|
15
|
+
import { extractSupportProps } from '@sbercloud/uikit-product-utils';
|
|
16
|
+
import { Link } from '@snack-uikit/link';
|
|
17
|
+
import { Typography } from '@snack-uikit/typography';
|
|
18
|
+
import styles from './styles.module.css';
|
|
19
|
+
export function SolutionsWidget(_a) {
|
|
20
|
+
var { layoutType, moreLink, cards } = _a, rest = __rest(_a, ["layoutType", "moreLink", "cards"]);
|
|
21
|
+
const { t } = useLocale('Widget');
|
|
22
|
+
const isMobile = layoutType === 'mobile';
|
|
23
|
+
return (_jsxs("div", Object.assign({ className: styles.wrapper }, extractSupportProps(rest), { children: [_jsxs("div", { className: styles.header, children: [_jsx(Typography.SansTitleL, { tag: 'h5', children: t('Solutions.title') }), moreLink && (_jsx(Link, { text: t('Solutions.link'), size: 'm', appearance: 'neutral', onClick: moreLink === null || moreLink === void 0 ? void 0 : moreLink.onClick, href: moreLink === null || moreLink === void 0 ? void 0 : moreLink.href }))] }), _jsx("div", { className: styles.cards, "data-mobile": isMobile || undefined, children: cards.map(({ description, title, onClick }) => (_jsx(CardSuggest, { className: styles.card, description: description, title: title, onClick: onClick }, title))) })] })));
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SolutionsWidget';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SolutionsWidget';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
.wrapper{
|
|
2
|
+
display:flex;
|
|
3
|
+
flex-direction:column;
|
|
4
|
+
gap:var(--dimension-2m, 16px);
|
|
5
|
+
grid-column:span 12;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.header{
|
|
9
|
+
display:flex;
|
|
10
|
+
flex-direction:row;
|
|
11
|
+
justify-content:space-between;
|
|
12
|
+
align-items:center;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.cards{
|
|
16
|
+
display:grid;
|
|
17
|
+
grid-template-columns:repeat(4, 1fr);
|
|
18
|
+
gap:var(--dimension-1m, 8px);
|
|
19
|
+
}
|
|
20
|
+
.cards[data-mobile]{
|
|
21
|
+
display:flex;
|
|
22
|
+
flex-direction:column;
|
|
23
|
+
gap:10px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.card{
|
|
27
|
+
flex-grow:0;
|
|
28
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
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, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import cn from 'classnames';
|
|
14
|
+
import { CrossSVG } from '@sbercloud/uikit-product-icons';
|
|
15
|
+
import { useLocale } from '@sbercloud/uikit-product-locale';
|
|
16
|
+
import { TitleClickable } from '@sbercloud/uikit-product-title-clickable';
|
|
17
|
+
import { InfoBlock } from '@snack-uikit/info-block';
|
|
18
|
+
import { Skeleton } from '@snack-uikit/skeleton';
|
|
19
|
+
import { extractSupportProps } from '@snack-uikit/utils';
|
|
20
|
+
import { ActionView } from '../../helperComponents/Actions/ActionView';
|
|
21
|
+
import { BUTTON_TYPE } from '../../helperComponents/Actions/constants';
|
|
22
|
+
import { DesktopActions } from '../../helperComponents/Actions/DesktopActions';
|
|
23
|
+
import { MobileActions } from '../../helperComponents/Actions/MobileActions';
|
|
24
|
+
import { ButtonKebab } from '../../helperComponents/ButtonKebab';
|
|
25
|
+
import styles from './styles.module.css';
|
|
26
|
+
export function Widget(_a) {
|
|
27
|
+
var { header, children, actions = [], wide = false, state = 'default', loadingState, errorState, className, layoutType } = _a, rest = __rest(_a, ["header", "children", "actions", "wide", "state", "loadingState", "errorState", "className", "layoutType"]);
|
|
28
|
+
const { t } = useLocale('Widget');
|
|
29
|
+
const renderContent = () => {
|
|
30
|
+
var _a;
|
|
31
|
+
switch (state) {
|
|
32
|
+
case 'loading': {
|
|
33
|
+
if (loadingState === null || loadingState === void 0 ? void 0 : loadingState.loadingContent) {
|
|
34
|
+
return loadingState.loadingContent;
|
|
35
|
+
}
|
|
36
|
+
if (loadingState === null || loadingState === void 0 ? void 0 : loadingState.showSkeleton) {
|
|
37
|
+
return (_jsx("div", { className: styles.skeletonContent, children: _jsx(Skeleton, { loading: true, width: '100%', height: 80, borderRadius: 8 }) }));
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
case 'error': {
|
|
42
|
+
return (_jsx(InfoBlock, { size: 'm', icon: (_a = errorState === null || errorState === void 0 ? void 0 : errorState.errorIcon) !== null && _a !== void 0 ? _a : { icon: CrossSVG, appearance: 'neutral', decor: true }, title: (errorState === null || errorState === void 0 ? void 0 : errorState.errorTitle) || t('dataErrorTitle'), description: (errorState === null || errorState === void 0 ? void 0 : errorState.errorDescription) || t('dataErrorDescription') }));
|
|
43
|
+
}
|
|
44
|
+
case 'default':
|
|
45
|
+
default: {
|
|
46
|
+
return children;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const renderActionsSkeleton = () => (_jsx("div", { className: cn(styles.actionsWrapper, { [styles.actionsWide]: wide }), children: _jsx("div", { className: styles.skeletonActions, children: wide ? (_jsxs(_Fragment, { children: [_jsx(Skeleton, { loading: true, width: 96, height: 32, borderRadius: 8 }), _jsx(Skeleton, { loading: true, width: 32, height: 32, borderRadius: 8 })] })) : (_jsxs(_Fragment, { children: [_jsx("div", { style: { flex: 1, minWidth: 0 }, children: _jsx(Skeleton, { loading: true, width: '100%', height: 32, borderRadius: 8 }) }), _jsx(Skeleton, { loading: true, width: 32, height: 32, borderRadius: 8 })] })) }) }));
|
|
51
|
+
const getPrimaryAction = (items) => {
|
|
52
|
+
const index = items.findIndex(a => a.variant !== BUTTON_TYPE.Droplist && a.variant !== BUTTON_TYPE.Kebab);
|
|
53
|
+
return index >= 0 ? items[index] : undefined;
|
|
54
|
+
};
|
|
55
|
+
const buildKebabItems = (items) => items.reduce((acc, action) => {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
if (action.variant === BUTTON_TYPE.Droplist || action.variant === BUTTON_TYPE.Kebab) {
|
|
58
|
+
acc.push({
|
|
59
|
+
type: 'group',
|
|
60
|
+
label: action.variant === BUTTON_TYPE.Droplist ? (_a = action.button) === null || _a === void 0 ? void 0 : _a.label : undefined,
|
|
61
|
+
items: action.list.items,
|
|
62
|
+
divider: acc.length > 0,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
acc.push({
|
|
67
|
+
content: { option: (_b = action.label) !== null && _b !== void 0 ? _b : '' },
|
|
68
|
+
beforeContent: action.icon,
|
|
69
|
+
onClick: (event) => {
|
|
70
|
+
var _a;
|
|
71
|
+
(_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action, event);
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return acc;
|
|
76
|
+
}, []);
|
|
77
|
+
const renderActions = () => {
|
|
78
|
+
if (state === 'loading') {
|
|
79
|
+
return renderActionsSkeleton();
|
|
80
|
+
}
|
|
81
|
+
if (!actions.length)
|
|
82
|
+
return null;
|
|
83
|
+
if (wide) {
|
|
84
|
+
const isMobile = layoutType === 'mobile';
|
|
85
|
+
return (_jsx("div", { className: cn(styles.actionsWrapper, { [styles.actionsWide]: wide }), children: isMobile ? _jsx(MobileActions, { items: actions }) : _jsx(DesktopActions, { items: actions }) }));
|
|
86
|
+
}
|
|
87
|
+
const primaryAction = getPrimaryAction(actions);
|
|
88
|
+
const kebabItemsMobile = buildKebabItems(actions);
|
|
89
|
+
return (_jsxs("div", { className: cn(styles.actionsWrapper), children: [primaryAction && (_jsx(ActionView, Object.assign({}, primaryAction, { layoutType: layoutType, commonProps: { size: 's', fullWidth: true } }))), _jsx(ButtonKebab, { layoutType: layoutType, list: {
|
|
90
|
+
items: kebabItemsMobile,
|
|
91
|
+
closeDroplistOnItemClick: true,
|
|
92
|
+
} })] }));
|
|
93
|
+
};
|
|
94
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.widget, className) }, extractSupportProps(rest), { children: [_jsxs("div", { className: styles.widgetHeader, children: [state === 'loading' ? (_jsx("div", { className: styles.skeletonHeader, children: _jsx(Skeleton, { loading: true, width: wide ? 120 : '100%', height: 32, borderRadius: 8 }) })) : (_jsx(TitleClickable, Object.assign({}, header, { className: cn(styles.titleClickable, header.className) }))), wide && renderActions()] }), _jsx("div", { className: styles.widgetContent, children: renderContent() }), !wide && renderActions()] })));
|
|
95
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.widget{
|
|
2
|
+
box-sizing:border-box;
|
|
3
|
+
display:flex;
|
|
4
|
+
flex-direction:column;
|
|
5
|
+
gap:calc(var(--dimension-1m, 8px) + var(--dimension-050m, 4px));
|
|
6
|
+
background-color:var(--sys-neutral-background1-level, #fdfdfd);
|
|
7
|
+
border-radius:calc(var(--dimension-1m, 8px) + var(--dimension-050m, 4px));
|
|
8
|
+
padding:var(--dimension-2m, 16px);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.widgetHeader{
|
|
12
|
+
display:flex;
|
|
13
|
+
align-items:center;
|
|
14
|
+
justify-content:space-between;
|
|
15
|
+
gap:var(--dimension-1m, 8px);
|
|
16
|
+
min-width:0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.titleClickable{
|
|
20
|
+
flex:1;
|
|
21
|
+
min-width:0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.widgetContent{
|
|
25
|
+
color:var(--sys-neutral-text-main, #41424e);
|
|
26
|
+
min-height:0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.actionsWrapper{
|
|
30
|
+
flex-shrink:0;
|
|
31
|
+
display:flex;
|
|
32
|
+
align-items:center;
|
|
33
|
+
gap:var(--dimension-050m, 4px);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.actionsWide{
|
|
37
|
+
justify-content:flex-end;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.skeletonContent{
|
|
41
|
+
display:flex;
|
|
42
|
+
flex-direction:column;
|
|
43
|
+
gap:var(--dimension-050m, 4px);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.skeletonHeader{
|
|
47
|
+
flex:1;
|
|
48
|
+
min-width:0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.skeletonActions{
|
|
52
|
+
display:flex;
|
|
53
|
+
align-items:center;
|
|
54
|
+
gap:var(--dimension-1m, 8px);
|
|
55
|
+
width:100%;
|
|
56
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { TitleClickableProps } from '@sbercloud/uikit-product-title-clickable';
|
|
3
|
+
import { WithLayoutType } from '@sbercloud/uikit-product-utils';
|
|
4
|
+
import type { InfoBlockProps } from '@snack-uikit/info-block';
|
|
5
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
6
|
+
import { Action } from '../../helperComponents/Actions/types';
|
|
7
|
+
export type WidgetState = 'default' | 'loading' | 'error';
|
|
8
|
+
export type WidgetHeaderProps = Pick<TitleClickableProps, 'title' | 'icon' | 'avatar' | 'href' | 'target' | 'onClick' | 'titleTag' | 'fullWidth' | 'children' | 'className'>;
|
|
9
|
+
export type WidgetLoadingStateProps = {
|
|
10
|
+
loadingContent?: ReactNode;
|
|
11
|
+
showSkeleton?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type WidgetErrorStateProps = {
|
|
14
|
+
errorTitle?: string;
|
|
15
|
+
errorDescription?: string;
|
|
16
|
+
errorIcon?: InfoBlockProps['icon'];
|
|
17
|
+
};
|
|
18
|
+
export type WidgetProps = WithLayoutType<WithSupportProps<{
|
|
19
|
+
header: WidgetHeaderProps;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
actions?: Action[];
|
|
22
|
+
wide?: boolean;
|
|
23
|
+
state?: WidgetState;
|
|
24
|
+
loadingState?: WidgetLoadingStateProps;
|
|
25
|
+
errorState?: WidgetErrorStateProps;
|
|
26
|
+
className?: string;
|
|
27
|
+
}>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { WithLayoutType } from '@sbercloud/uikit-product-utils';
|
|
3
|
+
import { Action } from './types';
|
|
4
|
+
export declare function ActionView({ variant, tooltip, hidden, layoutType, commonProps, ...buttonProps }: WithLayoutType<Action & {
|
|
5
|
+
commonProps: {
|
|
6
|
+
className?: string;
|
|
7
|
+
size?: 's' | 'm' | 'l';
|
|
8
|
+
fullWidth?: boolean;
|
|
9
|
+
};
|
|
10
|
+
}>): string | number | boolean | import("react/jsx-runtime").JSX.Element | Iterable<ReactNode> | null | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
13
|
+
import { AdaptiveTooltip } from '@sbercloud/uikit-product-mobile-tooltip';
|
|
14
|
+
import { ButtonFilled, ButtonFunction, ButtonOutline, ButtonSimple, ButtonTonal, } from '@snack-uikit/button';
|
|
15
|
+
import { ButtonDroplist } from '../ButtonDroplist';
|
|
16
|
+
import { ButtonKebab } from '../ButtonKebab';
|
|
17
|
+
import { BUTTON_TYPE } from './constants';
|
|
18
|
+
export function ActionView(_a) {
|
|
19
|
+
var { variant, tooltip, hidden = false, layoutType, commonProps } = _a, buttonProps = __rest(_a, ["variant", "tooltip", "hidden", "layoutType", "commonProps"]);
|
|
20
|
+
if (hidden) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const addTooltip = (component) => tooltip ? (_jsx(AdaptiveTooltip, Object.assign({ layoutType: layoutType }, tooltip, { children: component }))) : (component);
|
|
24
|
+
switch (variant) {
|
|
25
|
+
case BUTTON_TYPE.Filled:
|
|
26
|
+
return addTooltip(_jsx(ButtonFilled, Object.assign({}, buttonProps, commonProps)));
|
|
27
|
+
case BUTTON_TYPE.Outline:
|
|
28
|
+
return addTooltip(_jsx(ButtonOutline, Object.assign({}, buttonProps, commonProps)));
|
|
29
|
+
case BUTTON_TYPE.Tonal:
|
|
30
|
+
return addTooltip(_jsx(ButtonTonal, Object.assign({}, buttonProps, commonProps)));
|
|
31
|
+
case BUTTON_TYPE.Function:
|
|
32
|
+
return addTooltip(_jsx(ButtonFunction, Object.assign({}, buttonProps, commonProps)));
|
|
33
|
+
case BUTTON_TYPE.Simple:
|
|
34
|
+
return addTooltip(_jsx(ButtonSimple, Object.assign({}, buttonProps, commonProps)));
|
|
35
|
+
case BUTTON_TYPE.Kebab: {
|
|
36
|
+
const { button, list } = buttonProps;
|
|
37
|
+
return addTooltip(_jsx(ButtonKebab, { button: Object.assign(Object.assign({}, button), commonProps), list: list, layoutType: layoutType }));
|
|
38
|
+
}
|
|
39
|
+
case BUTTON_TYPE.Droplist: {
|
|
40
|
+
const { button, list } = buttonProps;
|
|
41
|
+
return addTooltip(_jsx(ButtonDroplist, { button: Object.assign(Object.assign({}, button), commonProps), list: list, layoutType: layoutType }));
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { ActionView } from './ActionView';
|
|
4
|
+
import { hasVisibleActions } from './helpers';
|
|
5
|
+
import styles from './styles.module.css';
|
|
6
|
+
export function DesktopActions({ items }) {
|
|
7
|
+
if (!hasVisibleActions(items)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return (_jsx("div", { className: styles.desktopActionsWrapper, children: items.map((action, index) => (_createElement(ActionView, Object.assign({}, action, { key: index, layoutType: 'desktop', commonProps: {
|
|
11
|
+
className: styles.button,
|
|
12
|
+
} })))) }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef, useState } from 'react';
|
|
4
|
+
import { KebabSVG } from '@sbercloud/uikit-product-icons';
|
|
5
|
+
import { MobileDroplist } from '@sbercloud/uikit-product-mobile-dropdown';
|
|
6
|
+
import { MobileTooltip } from '@sbercloud/uikit-product-mobile-tooltip';
|
|
7
|
+
import { ButtonOutline } from '@snack-uikit/button';
|
|
8
|
+
import { useDynamicList } from '@snack-uikit/utils';
|
|
9
|
+
import { ActionView } from './ActionView';
|
|
10
|
+
import { BUTTON_TYPE } from './constants';
|
|
11
|
+
import { hasVisibleActions } from './helpers';
|
|
12
|
+
import styles from './styles.module.css';
|
|
13
|
+
export function MobileActions({ items }) {
|
|
14
|
+
const containerRef = useRef(null);
|
|
15
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
16
|
+
const { visibleItems, hiddenItems } = useDynamicList({ parentContainerRef: containerRef, items, maxVisibleItems: 2 });
|
|
17
|
+
if (!hasVisibleActions(items)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const hiddenItemsWithKebab = hiddenItems.concat(visibleItems.filter(item => item.variant === 'kebab'));
|
|
21
|
+
const visibleItemsWithoutKebab = visibleItems.filter(item => item.variant !== 'kebab');
|
|
22
|
+
return (_jsxs("div", { className: styles.mobileActionsWrapper, ref: containerRef, children: [hiddenItemsWithKebab.length > 0 && (_jsx(MobileDroplist, { open: isOpen, onOpenChange: setIsOpen, items: hiddenItemsWithKebab.reduce((acc, action) => {
|
|
23
|
+
var _a;
|
|
24
|
+
switch (action.variant) {
|
|
25
|
+
case BUTTON_TYPE.Tonal:
|
|
26
|
+
case BUTTON_TYPE.Simple:
|
|
27
|
+
case BUTTON_TYPE.Outline:
|
|
28
|
+
case BUTTON_TYPE.Function:
|
|
29
|
+
case BUTTON_TYPE.Filled: {
|
|
30
|
+
acc.push(Object.assign(Object.assign({}, action), { content: { option: (_a = action.label) !== null && _a !== void 0 ? _a : '' }, onClick: event => {
|
|
31
|
+
var _a;
|
|
32
|
+
setIsOpen(false);
|
|
33
|
+
(_a = action.onClick) === null || _a === void 0 ? void 0 : _a.call(action, event);
|
|
34
|
+
}, beforeContent: action === null || action === void 0 ? void 0 : action.icon, itemWrapRender: action.tooltip
|
|
35
|
+
? item => {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
return (_jsx(MobileTooltip, Object.assign({ tip: (_b = (_a = action.tooltip) === null || _a === void 0 ? void 0 : _a.tip) !== null && _b !== void 0 ? _b : '' }, action.tooltip, { children: item })));
|
|
38
|
+
}
|
|
39
|
+
: undefined }));
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case BUTTON_TYPE.Droplist:
|
|
43
|
+
case BUTTON_TYPE.Kebab: {
|
|
44
|
+
const needDivider = Boolean(action.variant === 'droplist' && (action === null || action === void 0 ? void 0 : action.button.label)) || acc.length > 0;
|
|
45
|
+
acc.push(Object.assign(Object.assign({}, action), { type: 'group', label: action.variant === 'droplist' ? action === null || action === void 0 ? void 0 : action.button.label : undefined, divider: needDivider, items: action.list.items.map(item => (Object.assign(Object.assign({}, item), { onClick: event => {
|
|
46
|
+
var _a;
|
|
47
|
+
setIsOpen(false);
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
49
|
+
// @ts-expect-error
|
|
50
|
+
(_a = item.onClick) === null || _a === void 0 ? void 0 : _a.call(item, event);
|
|
51
|
+
} }))) }));
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
default: {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return acc;
|
|
59
|
+
}, []), children: _jsx(ButtonOutline, { appearance: 'neutral', icon: _jsx(KebabSVG, {}), size: 's' }) })), visibleItemsWithoutKebab.map((action, index) => (_createElement(ActionView, Object.assign({}, action, { key: index, layoutType: 'mobile', commonProps: {
|
|
60
|
+
className: styles.button,
|
|
61
|
+
size: 's',
|
|
62
|
+
fullWidth: true,
|
|
63
|
+
} }))))] }));
|
|
64
|
+
}
|