@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,60 @@
|
|
|
1
|
+
@use '@sbercloud/figma-tokens-cloud-platform/build/scss/styles-theme-variables';
|
|
2
|
+
|
|
3
|
+
.widget {
|
|
4
|
+
box-sizing: border-box;
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
gap: calc(styles-theme-variables.$dimension-1m + styles-theme-variables.$dimension-050m);
|
|
8
|
+
background-color: styles-theme-variables.$sys-neutral-background1-level;
|
|
9
|
+
border-radius: calc(styles-theme-variables.$dimension-1m + styles-theme-variables.$dimension-050m);
|
|
10
|
+
padding: styles-theme-variables.$dimension-2m;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.widgetHeader {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
justify-content: space-between;
|
|
17
|
+
gap: styles-theme-variables.$dimension-1m;
|
|
18
|
+
min-width: 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.titleClickable {
|
|
22
|
+
flex: 1;
|
|
23
|
+
min-width: 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.widgetContent {
|
|
27
|
+
color: styles-theme-variables.$sys-neutral-text-main;
|
|
28
|
+
min-height: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.actionsWrapper {
|
|
32
|
+
flex-shrink: 0;
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: styles-theme-variables.$dimension-050m;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.actionsWide {
|
|
39
|
+
justify-content: flex-end;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.skeletonContent {
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
gap: styles-theme-variables.$dimension-050m;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.skeletonHeader {
|
|
49
|
+
flex: 1;
|
|
50
|
+
min-width: 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.skeletonActions {
|
|
54
|
+
display: flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
gap: styles-theme-variables.$dimension-1m;
|
|
57
|
+
width: 100%;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { TitleClickableProps } from '@cloud-ru/uikit-product-title-clickable';
|
|
4
|
+
import { WithLayoutType } from '@cloud-ru/uikit-product-utils';
|
|
5
|
+
import type { InfoBlockProps } from '@snack-uikit/info-block';
|
|
6
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
7
|
+
|
|
8
|
+
import { Action } from '../../helperComponents/Actions/types';
|
|
9
|
+
|
|
10
|
+
export type WidgetState = 'default' | 'loading' | 'error';
|
|
11
|
+
|
|
12
|
+
export type WidgetHeaderProps = Pick<
|
|
13
|
+
TitleClickableProps,
|
|
14
|
+
'title' | 'icon' | 'avatar' | 'href' | 'target' | 'onClick' | 'titleTag' | 'fullWidth' | 'children' | 'className'
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export type WidgetLoadingStateProps = {
|
|
18
|
+
loadingContent?: ReactNode;
|
|
19
|
+
showSkeleton?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type WidgetErrorStateProps = {
|
|
23
|
+
errorTitle?: string;
|
|
24
|
+
errorDescription?: string;
|
|
25
|
+
errorIcon?: InfoBlockProps['icon'];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type WidgetProps = WithLayoutType<
|
|
29
|
+
WithSupportProps<{
|
|
30
|
+
header: WidgetHeaderProps;
|
|
31
|
+
children: ReactNode;
|
|
32
|
+
actions?: Action[];
|
|
33
|
+
wide?: boolean;
|
|
34
|
+
state?: WidgetState;
|
|
35
|
+
loadingState?: WidgetLoadingStateProps;
|
|
36
|
+
errorState?: WidgetErrorStateProps;
|
|
37
|
+
className?: string;
|
|
38
|
+
}>
|
|
39
|
+
>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { AdaptiveTooltip } from '@cloud-ru/uikit-product-mobile-tooltip';
|
|
4
|
+
import { WithLayoutType } from '@cloud-ru/uikit-product-utils';
|
|
5
|
+
import {
|
|
6
|
+
ButtonFilled,
|
|
7
|
+
ButtonFilledProps,
|
|
8
|
+
ButtonFunction,
|
|
9
|
+
ButtonFunctionProps,
|
|
10
|
+
ButtonOutline,
|
|
11
|
+
ButtonOutlineProps,
|
|
12
|
+
ButtonSimple,
|
|
13
|
+
ButtonSimpleProps,
|
|
14
|
+
ButtonTonal,
|
|
15
|
+
ButtonTonalProps,
|
|
16
|
+
} from '@snack-uikit/button';
|
|
17
|
+
|
|
18
|
+
import { ButtonDroplist, ButtonDroplistProps } from '../ButtonDroplist';
|
|
19
|
+
import { ButtonKebab, ButtonKebabProps } from '../ButtonKebab';
|
|
20
|
+
import { BUTTON_TYPE } from './constants';
|
|
21
|
+
import { Action } from './types';
|
|
22
|
+
|
|
23
|
+
export function ActionView({
|
|
24
|
+
variant,
|
|
25
|
+
tooltip,
|
|
26
|
+
hidden = false,
|
|
27
|
+
layoutType,
|
|
28
|
+
commonProps,
|
|
29
|
+
...buttonProps
|
|
30
|
+
}: WithLayoutType<Action & { commonProps: { className?: string; size?: 's' | 'm' | 'l'; fullWidth?: boolean } }>) {
|
|
31
|
+
if (hidden) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const addTooltip = (component: ReactNode) =>
|
|
36
|
+
tooltip ? (
|
|
37
|
+
<AdaptiveTooltip layoutType={layoutType} {...tooltip}>
|
|
38
|
+
{component}
|
|
39
|
+
</AdaptiveTooltip>
|
|
40
|
+
) : (
|
|
41
|
+
component
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
switch (variant) {
|
|
45
|
+
case BUTTON_TYPE.Filled:
|
|
46
|
+
return addTooltip(<ButtonFilled {...(buttonProps as ButtonFilledProps)} {...commonProps} />);
|
|
47
|
+
case BUTTON_TYPE.Outline:
|
|
48
|
+
return addTooltip(<ButtonOutline {...(buttonProps as ButtonOutlineProps)} {...commonProps} />);
|
|
49
|
+
case BUTTON_TYPE.Tonal:
|
|
50
|
+
return addTooltip(<ButtonTonal {...(buttonProps as ButtonTonalProps)} {...commonProps} />);
|
|
51
|
+
case BUTTON_TYPE.Function:
|
|
52
|
+
return addTooltip(<ButtonFunction {...(buttonProps as ButtonFunctionProps)} {...commonProps} />);
|
|
53
|
+
case BUTTON_TYPE.Simple:
|
|
54
|
+
return addTooltip(<ButtonSimple {...(buttonProps as ButtonSimpleProps)} {...commonProps} />);
|
|
55
|
+
case BUTTON_TYPE.Kebab: {
|
|
56
|
+
const { button, list } = buttonProps as ButtonKebabProps;
|
|
57
|
+
return addTooltip(<ButtonKebab button={{ ...button, ...commonProps }} list={list} layoutType={layoutType} />);
|
|
58
|
+
}
|
|
59
|
+
case BUTTON_TYPE.Droplist: {
|
|
60
|
+
const { button, list } = buttonProps as ButtonDroplistProps;
|
|
61
|
+
return addTooltip(<ButtonDroplist button={{ ...button, ...commonProps }} list={list} layoutType={layoutType} />);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
default:
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ActionView } from './ActionView';
|
|
2
|
+
import { hasVisibleActions } from './helpers';
|
|
3
|
+
import styles from './styles.module.scss';
|
|
4
|
+
import { ActionsProps } from './types';
|
|
5
|
+
|
|
6
|
+
export function DesktopActions({ items }: Pick<ActionsProps, 'items'>) {
|
|
7
|
+
if (!hasVisibleActions(items)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return (
|
|
12
|
+
<div className={styles.desktopActionsWrapper}>
|
|
13
|
+
{items.map((action, index) => (
|
|
14
|
+
<ActionView
|
|
15
|
+
{...action}
|
|
16
|
+
key={index}
|
|
17
|
+
layoutType='desktop'
|
|
18
|
+
commonProps={{
|
|
19
|
+
className: styles.button,
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
))}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { KebabSVG } from '@cloud-ru/uikit-product-icons';
|
|
4
|
+
import { MobileDroplist, MobileDroplistProps } from '@cloud-ru/uikit-product-mobile-dropdown';
|
|
5
|
+
import { MobileTooltip } from '@cloud-ru/uikit-product-mobile-tooltip';
|
|
6
|
+
import { ButtonOutline } from '@snack-uikit/button';
|
|
7
|
+
import { useDynamicList } from '@snack-uikit/utils';
|
|
8
|
+
|
|
9
|
+
import { ActionView } from './ActionView';
|
|
10
|
+
import { BUTTON_TYPE } from './constants';
|
|
11
|
+
import { hasVisibleActions } from './helpers';
|
|
12
|
+
import styles from './styles.module.scss';
|
|
13
|
+
import { ActionsProps } from './types';
|
|
14
|
+
|
|
15
|
+
export function MobileActions({ items }: ActionsProps) {
|
|
16
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
17
|
+
|
|
18
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
19
|
+
const { visibleItems, hiddenItems } = useDynamicList({ parentContainerRef: containerRef, items, maxVisibleItems: 2 });
|
|
20
|
+
|
|
21
|
+
if (!hasVisibleActions(items)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const hiddenItemsWithKebab = hiddenItems.concat(visibleItems.filter(item => item.variant === 'kebab'));
|
|
26
|
+
const visibleItemsWithoutKebab = visibleItems.filter(item => item.variant !== 'kebab');
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className={styles.mobileActionsWrapper} ref={containerRef}>
|
|
30
|
+
{hiddenItemsWithKebab.length > 0 && (
|
|
31
|
+
<MobileDroplist
|
|
32
|
+
open={isOpen}
|
|
33
|
+
onOpenChange={setIsOpen}
|
|
34
|
+
items={hiddenItemsWithKebab.reduce(
|
|
35
|
+
(acc, action) => {
|
|
36
|
+
switch (action.variant) {
|
|
37
|
+
case BUTTON_TYPE.Tonal:
|
|
38
|
+
case BUTTON_TYPE.Simple:
|
|
39
|
+
case BUTTON_TYPE.Outline:
|
|
40
|
+
case BUTTON_TYPE.Function:
|
|
41
|
+
case BUTTON_TYPE.Filled: {
|
|
42
|
+
acc.push({
|
|
43
|
+
...action,
|
|
44
|
+
content: { option: action.label ?? '' },
|
|
45
|
+
onClick: event => {
|
|
46
|
+
setIsOpen(false);
|
|
47
|
+
action.onClick?.(event);
|
|
48
|
+
},
|
|
49
|
+
beforeContent: action?.icon,
|
|
50
|
+
itemWrapRender: action.tooltip
|
|
51
|
+
? item => (
|
|
52
|
+
<MobileTooltip tip={action.tooltip?.tip ?? ''} {...action.tooltip}>
|
|
53
|
+
{item}
|
|
54
|
+
</MobileTooltip>
|
|
55
|
+
)
|
|
56
|
+
: undefined,
|
|
57
|
+
});
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
case BUTTON_TYPE.Droplist:
|
|
62
|
+
case BUTTON_TYPE.Kebab: {
|
|
63
|
+
const needDivider = Boolean(action.variant === 'droplist' && action?.button.label) || acc.length > 0;
|
|
64
|
+
|
|
65
|
+
acc.push({
|
|
66
|
+
...action,
|
|
67
|
+
type: 'group',
|
|
68
|
+
label: action.variant === 'droplist' ? action?.button.label : undefined,
|
|
69
|
+
divider: needDivider,
|
|
70
|
+
items: action.list.items.map(item => ({
|
|
71
|
+
...item,
|
|
72
|
+
onClick: event => {
|
|
73
|
+
setIsOpen(false);
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
75
|
+
// @ts-expect-error
|
|
76
|
+
item.onClick?.(event);
|
|
77
|
+
},
|
|
78
|
+
})),
|
|
79
|
+
});
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
default: {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return acc;
|
|
89
|
+
},
|
|
90
|
+
[] as MobileDroplistProps['items'],
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
<ButtonOutline appearance='neutral' icon={<KebabSVG />} size='s' />
|
|
94
|
+
</MobileDroplist>
|
|
95
|
+
)}
|
|
96
|
+
|
|
97
|
+
{visibleItemsWithoutKebab.map((action, index) => (
|
|
98
|
+
<ActionView
|
|
99
|
+
{...action}
|
|
100
|
+
key={index}
|
|
101
|
+
layoutType='mobile'
|
|
102
|
+
commonProps={{
|
|
103
|
+
className: styles.button,
|
|
104
|
+
size: 's',
|
|
105
|
+
fullWidth: true,
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
))}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
@use '@sbercloud/figma-tokens-cloud-platform/build/scss/styles-theme-variables';
|
|
2
|
+
|
|
3
|
+
.desktopActionsWrapper {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: row-reverse;
|
|
6
|
+
align-items: center;
|
|
7
|
+
flex-shrink: 0;
|
|
8
|
+
gap: styles-theme-variables.$dimension-1m;
|
|
9
|
+
height: 100%;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.mobileActionsWrapper {
|
|
13
|
+
display: flex;
|
|
14
|
+
gap: 8px;
|
|
15
|
+
flex-shrink: 0;
|
|
16
|
+
width: 100%;
|
|
17
|
+
justify-content: stretch;
|
|
18
|
+
overflow-y: auto;
|
|
19
|
+
flex-direction: row-reverse;
|
|
20
|
+
|
|
21
|
+
/* Hide scrollbar */
|
|
22
|
+
-ms-overflow-style: none; /* IE and Edge */
|
|
23
|
+
scrollbar-width: none; /* Firefox */
|
|
24
|
+
|
|
25
|
+
&::-webkit-scrollbar {
|
|
26
|
+
display: none; /* Chrome, Safari and Opera */
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.button {
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
|
|
33
|
+
&[data-full-width]:not([data-variant='icon-only']) {
|
|
34
|
+
flex-shrink: 0;
|
|
35
|
+
width: auto;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&[data-variant='icon-only'] {
|
|
39
|
+
flex-grow: 0;
|
|
40
|
+
flex-shrink: 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { TooltipProps } from '@cloud-ru/uikit-product-mobile-tooltip';
|
|
2
|
+
import {
|
|
3
|
+
ButtonFilledProps,
|
|
4
|
+
ButtonFunctionProps,
|
|
5
|
+
ButtonOutlineProps,
|
|
6
|
+
ButtonSimpleProps,
|
|
7
|
+
ButtonTonalProps,
|
|
8
|
+
} from '@snack-uikit/button';
|
|
9
|
+
|
|
10
|
+
import { ButtonDroplistProps } from '../ButtonDroplist';
|
|
11
|
+
import { ButtonKebabProps } from '../ButtonKebab';
|
|
12
|
+
import { BUTTON_TYPE } from './constants';
|
|
13
|
+
|
|
14
|
+
type ButtonKebabPropsWithoutLayout = Omit<ButtonKebabProps, 'layoutType'>;
|
|
15
|
+
type ButtonDroplistWithoutLayout = Omit<ButtonDroplistProps, 'layoutType'>;
|
|
16
|
+
|
|
17
|
+
export type Action = {
|
|
18
|
+
tooltip?: TooltipProps;
|
|
19
|
+
hidden?: boolean;
|
|
20
|
+
} & (
|
|
21
|
+
| ({ variant?: typeof BUTTON_TYPE.Filled } & ButtonFilledProps)
|
|
22
|
+
| ({ variant: typeof BUTTON_TYPE.Outline } & ButtonOutlineProps)
|
|
23
|
+
| ({ variant: typeof BUTTON_TYPE.Tonal } & ButtonTonalProps)
|
|
24
|
+
| ({ variant: typeof BUTTON_TYPE.Function } & ButtonFunctionProps)
|
|
25
|
+
| ({ variant: typeof BUTTON_TYPE.Simple } & ButtonSimpleProps)
|
|
26
|
+
| ({ variant: typeof BUTTON_TYPE.Kebab } & ButtonKebabPropsWithoutLayout)
|
|
27
|
+
| ({ variant: typeof BUTTON_TYPE.Droplist } & ButtonDroplistWithoutLayout)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
export type ActionsProps = {
|
|
31
|
+
items: Action[];
|
|
32
|
+
maxVisibleItems?: number;
|
|
33
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ChevronDownSVG, ChevronUpSVG } from '@cloud-ru/uikit-product-icons';
|
|
2
|
+
import { AdaptiveDropdown, AdaptiveDropdownProps } from '@cloud-ru/uikit-product-mobile-dropdown';
|
|
3
|
+
import { WithLayoutType } from '@cloud-ru/uikit-product-utils';
|
|
4
|
+
import { ButtonFunction, ButtonFunctionProps } from '@snack-uikit/button';
|
|
5
|
+
import { useValueControl } from '@snack-uikit/utils';
|
|
6
|
+
|
|
7
|
+
export type ButtonDropdownProps = WithLayoutType<{
|
|
8
|
+
button: Omit<ButtonFunctionProps, 'icon' | 'iconPosition' | 'appearance'>;
|
|
9
|
+
dropdown: Omit<AdaptiveDropdownProps, 'children' | 'layoutType' | 'placement'>;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export function ButtonDropdown({ layoutType, button, dropdown }: ButtonDropdownProps) {
|
|
13
|
+
const [open, onOpenChange] = useValueControl<boolean>({ onChange: dropdown.onOpenChange, value: dropdown.open });
|
|
14
|
+
|
|
15
|
+
const Icon = open ? ChevronUpSVG : ChevronDownSVG;
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<AdaptiveDropdown {...dropdown} open={open} onOpenChange={onOpenChange} layoutType={layoutType}>
|
|
19
|
+
<ButtonFunction {...button} icon={<Icon />} iconPosition='after' appearance='neutral' />
|
|
20
|
+
</AdaptiveDropdown>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ButtonDropdown';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ChevronDownSVG, ChevronUpSVG } from '@cloud-ru/uikit-product-icons';
|
|
4
|
+
import { AdaptiveDroplist, AdaptiveDroplistProps } from '@cloud-ru/uikit-product-mobile-dropdown';
|
|
5
|
+
import { WithLayoutType } from '@cloud-ru/uikit-product-utils';
|
|
6
|
+
import { ButtonFilled, ButtonFilledProps, ButtonFunction, ButtonFunctionProps } from '@snack-uikit/button';
|
|
7
|
+
import { useValueControl } from '@snack-uikit/utils';
|
|
8
|
+
|
|
9
|
+
export type ButtonDroplistProps = WithLayoutType<{
|
|
10
|
+
button:
|
|
11
|
+
| (Omit<ButtonFilledProps, 'appearance'> & { buttonType?: 'filled' })
|
|
12
|
+
| (Omit<ButtonFunctionProps, 'icon' | 'iconPosition' | 'appearance'> & { buttonType?: 'function' });
|
|
13
|
+
list: Pick<AdaptiveDroplistProps, 'items' | 'closeDroplistOnItemClick' | 'className' | 'open' | 'onOpenChange'>;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export function ButtonDroplist({ layoutType, button, list }: ButtonDroplistProps) {
|
|
17
|
+
const [open, onOpenChange] = useValueControl<boolean>({ onChange: list.onOpenChange, value: list.open });
|
|
18
|
+
|
|
19
|
+
const Icon = open ? ChevronUpSVG : ChevronDownSVG;
|
|
20
|
+
|
|
21
|
+
const buttonType = button.buttonType ?? 'function';
|
|
22
|
+
|
|
23
|
+
const Button = buttonType === 'filled' ? ButtonFilled : ButtonFunction;
|
|
24
|
+
|
|
25
|
+
const buttonProps: ButtonDroplistProps['button'] = useMemo(
|
|
26
|
+
() =>
|
|
27
|
+
buttonType === 'filled' ? button : { ...button, appearance: 'neutral', icon: <Icon />, iconPosition: 'after' },
|
|
28
|
+
[buttonType, button, Icon],
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<AdaptiveDroplist
|
|
33
|
+
{...list}
|
|
34
|
+
open={open}
|
|
35
|
+
onOpenChange={onOpenChange}
|
|
36
|
+
layoutType={layoutType}
|
|
37
|
+
selection={{
|
|
38
|
+
mode: 'single',
|
|
39
|
+
value: 'null',
|
|
40
|
+
}}
|
|
41
|
+
size='s'
|
|
42
|
+
>
|
|
43
|
+
<Button {...buttonProps} />
|
|
44
|
+
</AdaptiveDroplist>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ButtonDroplist';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { KebabSVG } from '@cloud-ru/uikit-product-icons';
|
|
2
|
+
import { AdaptiveDroplist, AdaptiveDroplistProps } from '@cloud-ru/uikit-product-mobile-dropdown';
|
|
3
|
+
import { WithLayoutType } from '@cloud-ru/uikit-product-utils';
|
|
4
|
+
import { ButtonOutline, ButtonOutlineProps } from '@snack-uikit/button';
|
|
5
|
+
import { useValueControl } from '@snack-uikit/utils';
|
|
6
|
+
|
|
7
|
+
export type ButtonKebabProps = WithLayoutType<{
|
|
8
|
+
button?: Omit<ButtonOutlineProps, 'label' | 'icon'>;
|
|
9
|
+
list: Pick<AdaptiveDroplistProps, 'items' | 'closeDroplistOnItemClick' | 'open' | 'onOpenChange' | 'className'>;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export function ButtonKebab({ layoutType, button, list }: ButtonKebabProps) {
|
|
13
|
+
const [open, onOpenChange] = useValueControl<boolean>({ onChange: list.onOpenChange, value: list.open });
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<AdaptiveDroplist
|
|
17
|
+
{...list}
|
|
18
|
+
open={open}
|
|
19
|
+
onOpenChange={onOpenChange}
|
|
20
|
+
layoutType={layoutType}
|
|
21
|
+
selection={{
|
|
22
|
+
mode: 'single',
|
|
23
|
+
value: 'null',
|
|
24
|
+
}}
|
|
25
|
+
placement='bottom-end'
|
|
26
|
+
size='s'
|
|
27
|
+
>
|
|
28
|
+
<ButtonOutline {...button} icon={<KebabSVG />} appearance='neutral' />
|
|
29
|
+
</AdaptiveDroplist>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ButtonKebab';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Actions';
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|