@snack-uikit/modal 0.8.1 → 0.9.1

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 CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.9.1 (2023-12-14)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/icons@0.19.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/icons/CHANGELOG.md)
10
+ * [@snack-uikit/link@0.9.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/link/CHANGELOG.md)
11
+ * [@snack-uikit/tooltip@0.10.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/tooltip/CHANGELOG.md)
12
+ * [@snack-uikit/truncate-string@0.4.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/truncate-string/CHANGELOG.md)
13
+
14
+
15
+
16
+
17
+
18
+ # 0.9.0 (2023-12-14)
19
+
20
+
21
+ ### BREAKING CHANGES
22
+
23
+
24
+ * **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
25
+
26
+
27
+
28
+
6
29
  ## 0.8.1 (2023-12-06)
7
30
 
8
31
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -22,8 +22,8 @@
22
22
  | children* | `ReactNode` | - | Контент |
23
23
  | onClose* | `() => void` | - | Колбек закрытия компонента. |
24
24
  | open* | `boolean` | - | Управляет состоянием показан/не показан. |
25
- | mode | enum Mode: `"regular"`, `"aggressive"`, `"forced"` | Mode.Regular | Режим отображения модального окна: <br> - __`Regular`__ - есть кнопка закрытия, клик на оверлей и нажатие кнопки `Esc` закрывают модалку <br> - __`Aggressive`__ - есть кнопка закрытия, но выключен клик на оверлей и не работает закрытие по клавише `Esc` <br> - __`Forced`__ - закрыть модальное окно можно только по нажатию на кнопку действия в нижней части |
26
- | size | enum Size: `"s"`, `"m"`, `"l"` | Size.S | Размер модального окна |
25
+ | mode | enum Mode: `"regular"`, `"aggressive"`, `"forced"` | regular | Режим отображения модального окна: <br> - __`Regular`__ - есть кнопка закрытия, клик на оверлей и нажатие кнопки `Esc` закрывают модалку <br> - __`Aggressive`__ - есть кнопка закрытия, но выключен клик на оверлей и не работает закрытие по клавише `Esc` <br> - __`Forced`__ - закрыть модальное окно можно только по нажатию на кнопку действия в нижней части |
26
+ | size | enum Size: `"s"`, `"m"`, `"l"` | s | Размер модального окна |
27
27
  | className | `string` | - | CSS-класс |
28
28
  ## ModalCustom.Header
29
29
  ### Props
@@ -48,7 +48,7 @@
48
48
  |------|------|---------------|-------------|
49
49
  | actions* | `ReactNode` | - | Параметр для передачи кнопок |
50
50
  | disclaimer | `ReactNode` | - | Параметр для небольшого текста под кнопками |
51
- | align | enum Align: `"default"`, `"center"`, `"vertical"` | - | Выравнивание контента |
51
+ | align | enum Align: `"vertical"`, `"default"`, `"center"` | - | Выравнивание контента |
52
52
  | className | `string` | - | CSS-класс |
53
53
  ## Modal
54
54
  ### Props
@@ -58,7 +58,7 @@
58
58
  | title* | `string` | - | Заголовок модального окна |
59
59
  | onClose* | `() => void` | - | Колбек закрытия компонента. |
60
60
  | open* | `boolean` | - | Управляет состоянием показан/не показан. |
61
- | mode | enum Mode: `"regular"`, `"aggressive"`, `"forced"` | Mode.Regular | Режим отображения модального окна: <br> - __`Regular`__ - есть кнопка закрытия, клик на оверлей и нажатие кнопки `Esc` закрывают модалку <br> - __`Aggressive`__ - есть кнопка закрытия, но выключен клик на оверлей и не работает закрытие по клавише `Esc` <br> - __`Forced`__ - закрыть модальное окно можно только по нажатию на кнопку действия в нижней части |
61
+ | mode | enum Mode: `"regular"`, `"aggressive"`, `"forced"` | regular | Режим отображения модального окна: <br> - __`Regular`__ - есть кнопка закрытия, клик на оверлей и нажатие кнопки `Esc` закрывают модалку <br> - __`Aggressive`__ - есть кнопка закрытия, но выключен клик на оверлей и не работает закрытие по клавише `Esc` <br> - __`Forced`__ - закрыть модальное окно можно только по нажатию на кнопку действия в нижней части |
62
62
  | className | `string` | - | CSS-класс |
63
63
  | titleTooltip | `ReactNode` | - | Всплывающая подсказка для заголовка |
64
64
  | subtitle | `string` | - | Подзаголовок |
@@ -66,8 +66,8 @@
66
66
  | cancelButton | `Omit<ButtonOutlineProps, "data-test-id" \| "size">` | - | Кнопка отмены |
67
67
  | additionalButton | `Omit<ButtonSimpleProps, "data-test-id" \| "size">` | - | Вторая кнопка действия |
68
68
  | disclaimer | `{ text: string; link?: Pick<LinkProps, "text" \| "href" \| "target">; }` | - | Небольшой текст под кнопками футера с возможностью передать дополнительно ссылку |
69
- | size | enum Size: `"s"`, `"m"`, `"l"` | Size.S | Размер |
70
- | align | enum Align: `"default"`, `"center"`, `"vertical"` | Align.Default | Выравнивание, для разных размеров доступны разные значения <br> для `Size.S` - все <br> для `Size.M` - `Align.Default \| Align.Center` <br> для `Size.L` - `Align.Default` |
69
+ | size | "s" \| "m" \| "l" | s | Размер |
70
+ | align | enum Align: `"vertical"`, `"default"`, `"center"` | default | Выравнивание, для разных размеров доступны разные значения <br> для size=`s` - все <br> для size=`m` - align=`default \| center` <br> для size=`l` - align=`default` |
71
71
  | picture | `JSXElementConstructor<{ size?: number; className?: string; }> \| ModalHeaderImage` | - | Можно передать иконку из пакета `@snack-uikit/icon-predefined`, или путь к картинке и атрибут `alt` |
72
72
 
73
73
 
@@ -1,9 +1,3 @@
1
- import { Align, Mode, Size } from '../../constants';
2
1
  import { ModalLProps, ModalMProps, ModalSProps } from './types';
3
2
  export type ModalProps = ModalSProps | ModalMProps | ModalLProps;
4
3
  export declare function Modal({ open, onClose, size, mode, align, title, titleTooltip, subtitle, picture: pictureProp, content, approveButton, cancelButton, additionalButton, disclaimer, className, ...rest }: ModalProps): import("react/jsx-runtime").JSX.Element;
5
- export declare namespace Modal {
6
- var aligns: typeof Align;
7
- var modes: typeof Mode;
8
- var sizes: typeof Size;
9
- }
@@ -14,17 +14,14 @@ import { ButtonFilled, ButtonOutline, ButtonSimple } from '@snack-uikit/button';
14
14
  import { Link } from '@snack-uikit/link';
15
15
  import { TruncateString } from '@snack-uikit/truncate-string';
16
16
  import { Typography } from '@snack-uikit/typography';
17
- import { Align, Mode, Size, TEST_IDS } from '../../constants';
18
- import { getAlignProps, getButtonsSizes, getPicture } from '../../utils';
17
+ import { ALIGN, MODE, SIZE, TEST_IDS } from '../../constants';
18
+ import { getAlignProps, getButtonsSize, getPicture } from '../../utils';
19
19
  import { ModalCustom } from '../ModalCustom';
20
20
  import styles from './styles.module.css';
21
21
  export function Modal(_a) {
22
- var { open, onClose, size = Size.S, mode = Mode.Regular, align = Align.Default, title, titleTooltip, subtitle, picture: pictureProp, content, approveButton, cancelButton, additionalButton, disclaimer, className } = _a, rest = __rest(_a, ["open", "onClose", "size", "mode", "align", "title", "titleTooltip", "subtitle", "picture", "content", "approveButton", "cancelButton", "additionalButton", "disclaimer", "className"]);
22
+ var { open, onClose, size = SIZE.S, mode = MODE.Regular, align = ALIGN.Default, title, titleTooltip, subtitle, picture: pictureProp, content, approveButton, cancelButton, additionalButton, disclaimer, className } = _a, rest = __rest(_a, ["open", "onClose", "size", "mode", "align", "title", "titleTooltip", "subtitle", "picture", "content", "approveButton", "cancelButton", "additionalButton", "disclaimer", "className"]);
23
23
  const aligns = getAlignProps({ align, size });
24
- const buttonsSizes = getButtonsSizes({ align, size });
24
+ const buttonsSize = getButtonsSize({ align, size });
25
25
  const picture = getPicture({ size, picture: pictureProp });
26
- return (_jsxs(ModalCustom, Object.assign({ open: open, onClose: onClose, size: size, mode: mode, className: className }, rest, { children: [_jsx(ModalCustom.Header, { title: _jsx(TruncateString, { text: title }), titleTooltip: titleTooltip, subtitle: subtitle, picture: picture, align: aligns.header }), Boolean(content) && _jsx(ModalCustom.Body, { content: content, align: aligns.body }), _jsx(ModalCustom.Footer, { actions: _jsxs(_Fragment, { children: [_jsx(ButtonFilled, Object.assign({}, approveButton, { size: buttonsSizes.filled, className: styles.footerButton, "data-test-id": TEST_IDS.approveButton })), cancelButton && (_jsx(ButtonOutline, Object.assign({}, cancelButton, { size: buttonsSizes.outline, className: styles.footerButton, "data-test-id": TEST_IDS.cancelButton }))), additionalButton && (_jsx(ButtonSimple, Object.assign({}, additionalButton, { size: buttonsSizes.light, className: styles.footerButton, "data-test-id": TEST_IDS.additionalButton })))] }), disclaimer: disclaimer && (_jsxs(_Fragment, { children: [_jsx(Typography, Object.assign({ family: Typography.families.Sans, role: Typography.roles.Body, size: Typography.sizes.S, "data-test-id": TEST_IDS.disclaimerText }, { children: disclaimer.text })), disclaimer.link && (_jsx(Link, Object.assign({}, disclaimer.link, { size: Link.sizes.S, external: true, "data-test-id": TEST_IDS.disclaimerLink })))] })), align: aligns.footer, className: styles.modalFooter })] })));
26
+ return (_jsxs(ModalCustom, Object.assign({ open: open, onClose: onClose, size: size, mode: mode, className: className }, rest, { children: [_jsx(ModalCustom.Header, { title: _jsx(TruncateString, { text: title }), titleTooltip: titleTooltip, subtitle: subtitle, picture: picture, align: aligns.header }), Boolean(content) && _jsx(ModalCustom.Body, { content: content, align: aligns.body }), _jsx(ModalCustom.Footer, { actions: _jsxs(_Fragment, { children: [_jsx(ButtonFilled, Object.assign({}, approveButton, { size: buttonsSize, className: styles.footerButton, "data-test-id": TEST_IDS.approveButton })), cancelButton && (_jsx(ButtonOutline, Object.assign({}, cancelButton, { size: buttonsSize, className: styles.footerButton, "data-test-id": TEST_IDS.cancelButton }))), additionalButton && (_jsx(ButtonSimple, Object.assign({}, additionalButton, { size: buttonsSize, className: styles.footerButton, "data-test-id": TEST_IDS.additionalButton })))] }), disclaimer: disclaimer && (_jsxs(_Fragment, { children: [_jsx(Typography.SansBodyS, { "data-test-id": TEST_IDS.disclaimerText, children: disclaimer.text }), disclaimer.link && (_jsx(Link, Object.assign({}, disclaimer.link, { size: 's', external: true, "data-test-id": TEST_IDS.disclaimerLink })))] })), align: aligns.footer, className: styles.modalFooter })] })));
27
27
  }
28
- Modal.aligns = Align;
29
- Modal.modes = Mode;
30
- Modal.sizes = Size;
@@ -1,7 +1,8 @@
1
1
  import { ButtonFilledProps, ButtonOutlineProps, ButtonSimpleProps } from '@snack-uikit/button';
2
2
  import { LinkProps } from '@snack-uikit/link';
3
- import { Align, Size } from '../../constants';
3
+ import { ALIGN, SIZE } from '../../constants';
4
4
  import { ModalBodyProps, ModalHeaderImage, ModalHeaderProps } from '../../helperComponents';
5
+ import { Align } from '../../types';
5
6
  import { ModalCustomProps } from '../ModalCustom';
6
7
  type BaseModalProps = Omit<ModalCustomProps, 'children' | 'size'> & {
7
8
  /** Заголовок модального окна */
@@ -26,25 +27,25 @@ type BaseModalProps = Omit<ModalCustomProps, 'children' | 'size'> & {
26
27
  };
27
28
  export type ModalSProps = BaseModalProps & {
28
29
  /** Размер */
29
- size?: Size.S;
30
+ size?: typeof SIZE.S;
30
31
  /**
31
32
  * Выравнивание, для разных размеров доступны разные значения
32
- * <br> для `Size.S` - все
33
+ * <br> для size=`s` - все
33
34
  */
34
35
  align?: Align;
35
36
  /** Можно передать иконку из пакета `@snack-uikit/icon-predefined`, или путь к картинке и атрибут `alt` */
36
37
  picture?: ModalHeaderProps['picture'];
37
38
  };
38
39
  export type ModalMProps = BaseModalProps & {
39
- size?: Size.M;
40
- /** <br> для `Size.M` - `Align.Default | Align.Center` */
41
- align?: Align.Default | Align.Center;
40
+ size?: typeof SIZE.M;
41
+ /** <br> для size=`m` - align=`default | center` */
42
+ align?: typeof ALIGN.Default | typeof ALIGN.Center;
42
43
  picture?: ModalHeaderImage;
43
44
  };
44
45
  export type ModalLProps = BaseModalProps & {
45
- size?: Size.L;
46
- /** <br> для `Size.L` - `Align.Default` */
47
- align?: Align.Default;
46
+ size?: typeof SIZE.L;
47
+ /** <br> для size=`l` - align=`default` */
48
+ align?: typeof ALIGN.Default;
48
49
  picture?: ModalHeaderImage;
49
50
  };
50
51
  export {};
@@ -1,7 +1,7 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { WithSupportProps } from '@snack-uikit/utils';
3
- import { Mode, Size } from '../../constants';
4
3
  import { ModalBody, ModalBodyProps, ModalFooter, ModalFooterProps, ModalHeader, ModalHeaderProps } from '../../helperComponents';
4
+ import { Mode, Size } from '../../types';
5
5
  export type ModalCustomProps = WithSupportProps<{
6
6
  /** Управляет состоянием показан/не показан. */
7
7
  open: boolean;
@@ -26,10 +26,6 @@ export type ModalCustomProps = WithSupportProps<{
26
26
  children: ReactNode;
27
27
  }>;
28
28
  export declare function ModalCustom({ open, onClose, size, mode, children, className, ...rest }: ModalCustomProps): import("react/jsx-runtime").JSX.Element;
29
- export declare namespace ModalCustom {
30
- var modes: typeof Mode;
31
- var sizes: typeof Size;
32
- }
33
29
  export declare namespace ModalCustom {
34
30
  type HeaderProps = ModalHeaderProps;
35
31
  type BodyProps = ModalBodyProps;
@@ -12,24 +12,22 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import RCModal from 'react-modal';
15
- import { Mode, Size } from '../../constants';
15
+ import { MODE, SIZE } from '../../constants';
16
16
  import { ButtonClose, ModalBody, ModalFooter, ModalHeader, OverlayElement, } from '../../helperComponents';
17
17
  import styles from './styles.module.css';
18
18
  import { getDataTestAttributes } from './utils';
19
19
  export function ModalCustom(_a) {
20
- var { open, onClose, size = Size.S, mode = Mode.Regular, children, className } = _a, rest = __rest(_a, ["open", "onClose", "size", "mode", "children", "className"]);
20
+ var { open, onClose, size = SIZE.S, mode = MODE.Regular, children, className } = _a, rest = __rest(_a, ["open", "onClose", "size", "mode", "children", "className"]);
21
21
  const handleCloseButtonClick = () => {
22
22
  onClose();
23
23
  };
24
24
  const handleClose = () => {
25
- if (mode === Mode.Regular) {
25
+ if (mode === MODE.Regular) {
26
26
  onClose();
27
27
  }
28
28
  };
29
- return (_jsxs(RCModal, Object.assign({ data: Object.assign(Object.assign({}, getDataTestAttributes(rest)), { size }), isOpen: open, onRequestClose: handleClose, appElement: document.body, overlayElement: (_, content) => (_jsx(OverlayElement, { blur: [Mode.Forced, Mode.Aggressive].includes(mode), content: content, onClose: handleClose })), className: cn(styles.modal, className) }, { children: [mode !== Mode.Forced && (_jsx("div", Object.assign({ className: styles.headerElements }, { children: _jsx(ButtonClose, { onClick: handleCloseButtonClick }) }))), children] })));
29
+ return (_jsxs(RCModal, { data: Object.assign(Object.assign({}, getDataTestAttributes(rest)), { size }), isOpen: open, onRequestClose: handleClose, appElement: document.body, overlayElement: (_, content) => (_jsx(OverlayElement, { blur: [MODE.Forced, MODE.Aggressive].includes(mode), content: content, onClose: handleClose })), className: cn(styles.modal, className), children: [mode !== MODE.Forced && (_jsx("div", { className: styles.headerElements, children: _jsx(ButtonClose, { onClick: handleCloseButtonClick }) })), children] }));
30
30
  }
31
- ModalCustom.modes = Mode;
32
- ModalCustom.sizes = Size;
33
31
  (function (ModalCustom) {
34
32
  ModalCustom.Header = ModalHeader;
35
33
  ModalCustom.Body = ModalBody;
@@ -1,22 +1,22 @@
1
- export declare enum Size {
2
- S = "s",
3
- M = "m",
4
- L = "l"
5
- }
6
- export declare enum Mode {
7
- Regular = "regular",
8
- Aggressive = "aggressive",
9
- Forced = "forced"
10
- }
11
- export declare enum Align {
12
- Default = "default",
13
- Center = "center",
14
- Vertical = "vertical"
15
- }
16
- export declare enum ContentAlign {
17
- Default = "default",
18
- Center = "center"
19
- }
1
+ export declare const SIZE: {
2
+ readonly S: "s";
3
+ readonly M: "m";
4
+ readonly L: "l";
5
+ };
6
+ export declare const MODE: {
7
+ readonly Regular: "regular";
8
+ readonly Aggressive: "aggressive";
9
+ readonly Forced: "forced";
10
+ };
11
+ export declare const ALIGN: {
12
+ readonly Default: "default";
13
+ readonly Center: "center";
14
+ readonly Vertical: "vertical";
15
+ };
16
+ export declare const CONTENT_ALIGN: {
17
+ readonly Default: "default";
18
+ readonly Center: "center";
19
+ };
20
20
  export declare const TEST_IDS: {
21
21
  overlay: string;
22
22
  closeButton: string;
package/dist/constants.js CHANGED
@@ -1,26 +1,22 @@
1
- export var Size;
2
- (function (Size) {
3
- Size["S"] = "s";
4
- Size["M"] = "m";
5
- Size["L"] = "l";
6
- })(Size || (Size = {}));
7
- export var Mode;
8
- (function (Mode) {
9
- Mode["Regular"] = "regular";
10
- Mode["Aggressive"] = "aggressive";
11
- Mode["Forced"] = "forced";
12
- })(Mode || (Mode = {}));
13
- export var Align;
14
- (function (Align) {
15
- Align["Default"] = "default";
16
- Align["Center"] = "center";
17
- Align["Vertical"] = "vertical";
18
- })(Align || (Align = {}));
19
- export var ContentAlign;
20
- (function (ContentAlign) {
21
- ContentAlign["Default"] = "default";
22
- ContentAlign["Center"] = "center";
23
- })(ContentAlign || (ContentAlign = {}));
1
+ export const SIZE = {
2
+ S: 's',
3
+ M: 'm',
4
+ L: 'l',
5
+ };
6
+ export const MODE = {
7
+ Regular: 'regular',
8
+ Aggressive: 'aggressive',
9
+ Forced: 'forced',
10
+ };
11
+ export const ALIGN = {
12
+ Default: 'default',
13
+ Center: 'center',
14
+ Vertical: 'vertical',
15
+ };
16
+ export const CONTENT_ALIGN = {
17
+ Default: 'default',
18
+ Center: 'center',
19
+ };
24
20
  export const TEST_IDS = {
25
21
  overlay: 'modal__overlay',
26
22
  closeButton: 'modal__close-button',
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { WithSupportProps } from '@snack-uikit/utils';
3
- import { ContentAlign } from '../../constants';
3
+ import { ContentAlign } from '../../types';
4
4
  export type ModalBodyProps = WithSupportProps<{
5
5
  /** Содержимое модального окна */
6
6
  content: ReactNode;
@@ -9,6 +9,3 @@ export type ModalBodyProps = WithSupportProps<{
9
9
  className?: string;
10
10
  }>;
11
11
  export declare function ModalBody({ content, align, className, ...rest }: ModalBodyProps): import("react/jsx-runtime").JSX.Element;
12
- export declare namespace ModalBody {
13
- var aligns: typeof ContentAlign;
14
- }
@@ -13,10 +13,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { Scroll } from '@snack-uikit/scroll';
15
15
  import { extractSupportProps } from '@snack-uikit/utils';
16
- import { ContentAlign, TEST_IDS } from '../../constants';
16
+ import { CONTENT_ALIGN, TEST_IDS } from '../../constants';
17
17
  import styles from './styles.module.css';
18
18
  export function ModalBody(_a) {
19
- var { content, align = ContentAlign.Default, className } = _a, rest = __rest(_a, ["content", "align", "className"]);
20
- return (_jsx(Scroll, Object.assign({ size: Scroll.sizes.M, className: cn(styles.modalBody, className) }, extractSupportProps(rest), { "data-align": align, "data-test-id": TEST_IDS.content }, { children: content })));
19
+ var { content, align = CONTENT_ALIGN.Default, className } = _a, rest = __rest(_a, ["content", "align", "className"]);
20
+ return (_jsx(Scroll, Object.assign({ size: 'm', className: cn(styles.modalBody, className) }, extractSupportProps(rest), { "data-align": align, "data-test-id": TEST_IDS.content, children: content })));
21
21
  }
22
- ModalBody.aligns = ContentAlign;
@@ -3,5 +3,5 @@ import { CrossSVG } from '@snack-uikit/icons';
3
3
  import { TEST_IDS } from '../../constants';
4
4
  import styles from './styles.module.css';
5
5
  export function ButtonClose({ onClick }) {
6
- return (_jsx("button", Object.assign({ className: styles.buttonClose, onClick: onClick, "aria-label": 'close modal', "data-test-id": TEST_IDS.closeButton }, { children: _jsx(CrossSVG, {}) })));
6
+ return (_jsx("button", { className: styles.buttonClose, onClick: onClick, "aria-label": 'close modal', "data-test-id": TEST_IDS.closeButton, children: _jsx(CrossSVG, {}) }));
7
7
  }
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { WithSupportProps } from '@snack-uikit/utils';
3
- import { Align } from '../../constants';
3
+ import { Align } from '../../types';
4
4
  export type ModalFooterProps = WithSupportProps<{
5
5
  /** Параметр для передачи кнопок */
6
6
  actions: ReactNode;
@@ -11,6 +11,3 @@ export type ModalFooterProps = WithSupportProps<{
11
11
  className?: string;
12
12
  }>;
13
13
  export declare function ModalFooter({ actions, disclaimer, align, className, ...rest }: ModalFooterProps): import("react/jsx-runtime").JSX.Element;
14
- export declare namespace ModalFooter {
15
- var aligns: typeof Align;
16
- }
@@ -12,10 +12,9 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
14
  import { extractSupportProps } from '@snack-uikit/utils';
15
- import { Align, TEST_IDS } from '../../constants';
15
+ import { ALIGN, TEST_IDS } from '../../constants';
16
16
  import styles from './styles.module.css';
17
17
  export function ModalFooter(_a) {
18
- var { actions, disclaimer, align = Align.Default, className } = _a, rest = __rest(_a, ["actions", "disclaimer", "align", "className"]);
19
- return (_jsxs("div", Object.assign({ "data-align": align, className: cn(styles.footer, className) }, extractSupportProps(rest), { "data-test-id": TEST_IDS.footer }, { children: [_jsx("div", Object.assign({ className: styles.footerActions }, { children: actions })), disclaimer && (_jsx("div", Object.assign({ className: styles.footerDisclaimer, "data-test-id": TEST_IDS.disclaimer }, { children: disclaimer })))] })));
18
+ var { actions, disclaimer, align = ALIGN.Default, className } = _a, rest = __rest(_a, ["actions", "disclaimer", "align", "className"]);
19
+ return (_jsxs("div", Object.assign({ "data-align": align, className: cn(styles.footer, className) }, extractSupportProps(rest), { "data-test-id": TEST_IDS.footer, children: [_jsx("div", { className: styles.footerActions, children: actions }), disclaimer && (_jsx("div", { className: styles.footerDisclaimer, "data-test-id": TEST_IDS.disclaimer, children: disclaimer }))] })));
20
20
  }
21
- ModalFooter.aligns = Align;
@@ -2,7 +2,7 @@ import { ReactNode } from 'react';
2
2
  import { IconPredefinedProps } from '@snack-uikit/icon-predefined';
3
3
  import { QuestionTooltipProps } from '@snack-uikit/tooltip';
4
4
  import { WithSupportProps } from '@snack-uikit/utils';
5
- import { ContentAlign } from '../../constants';
5
+ import { ContentAlign } from '../../types';
6
6
  import { ModalHeaderImage } from './types';
7
7
  export type ModalHeaderProps = WithSupportProps<{
8
8
  /** Заголовок модального окна */
@@ -18,6 +18,3 @@ export type ModalHeaderProps = WithSupportProps<{
18
18
  className?: string;
19
19
  }>;
20
20
  export declare function ModalHeader({ title, titleTooltip, subtitle, align, picture, className, ...rest }: ModalHeaderProps): import("react/jsx-runtime").JSX.Element;
21
- export declare namespace ModalHeader {
22
- var aligns: typeof ContentAlign;
23
- }
@@ -15,12 +15,11 @@ import { IconPredefined } from '@snack-uikit/icon-predefined';
15
15
  import { QuestionTooltip } from '@snack-uikit/tooltip';
16
16
  import { Typography } from '@snack-uikit/typography';
17
17
  import { extractSupportProps } from '@snack-uikit/utils';
18
- import { ContentAlign, TEST_IDS } from '../../constants';
18
+ import { CONTENT_ALIGN, TEST_IDS } from '../../constants';
19
19
  import { isPictureImage } from '../../utils';
20
20
  import styles from './styles.module.css';
21
21
  export function ModalHeader(_a) {
22
- var { title, titleTooltip, subtitle, align = ContentAlign.Default, picture, className } = _a, rest = __rest(_a, ["title", "titleTooltip", "subtitle", "align", "picture", "className"]);
23
- return (_jsxs("div", Object.assign({ className: cn(styles.header, className) }, extractSupportProps(rest), { "data-test-id": TEST_IDS.header }, { children: [picture &&
24
- (isPictureImage(picture) ? (_jsx("img", { src: picture.src, alt: picture.alt, className: styles.image, "data-test-id": TEST_IDS.image })) : (_jsx("div", Object.assign({ className: styles.icon, "data-test-id": TEST_IDS.icon }, { children: _jsx(IconPredefined, { icon: picture, size: IconPredefined.sizes.L }) })))), _jsxs("div", Object.assign({ className: styles.headlineLayout, "data-align": align }, { children: [_jsxs("div", Object.assign({ className: styles.headline }, { children: [_jsx(Typography, Object.assign({ family: Typography.families.Sans, role: Typography.roles.Headline, size: Typography.sizes.S, className: styles.title, "data-test-id": TEST_IDS.title }, { children: title })), titleTooltip && (_jsx(QuestionTooltip, { tip: titleTooltip, size: QuestionTooltip.sizes.S, "data-test-id": TEST_IDS.tooltip }))] })), subtitle && (_jsx(Typography, Object.assign({ family: Typography.families.Sans, role: Typography.roles.Body, size: Typography.sizes.M, className: styles.subtitle, "data-test-id": TEST_IDS.subtitle }, { children: subtitle })))] }))] })));
22
+ var { title, titleTooltip, subtitle, align = CONTENT_ALIGN.Default, picture, className } = _a, rest = __rest(_a, ["title", "titleTooltip", "subtitle", "align", "picture", "className"]);
23
+ return (_jsxs("div", Object.assign({ className: cn(styles.header, className) }, extractSupportProps(rest), { "data-test-id": TEST_IDS.header, children: [picture &&
24
+ (isPictureImage(picture) ? (_jsx("img", { src: picture.src, alt: picture.alt, className: styles.image, "data-test-id": TEST_IDS.image })) : (_jsx("div", { className: styles.icon, "data-test-id": TEST_IDS.icon, children: _jsx(IconPredefined, { icon: picture, size: 'l' }) }))), _jsxs("div", { className: styles.headlineLayout, "data-align": align, children: [_jsxs("div", { className: styles.headline, children: [_jsx(Typography.SansHeadlineS, { className: styles.title, "data-test-id": TEST_IDS.title, children: title }), titleTooltip && _jsx(QuestionTooltip, { tip: titleTooltip, size: 's', "data-test-id": TEST_IDS.tooltip })] }), subtitle && (_jsx(Typography.SansBodyM, { className: styles.subtitle, "data-test-id": TEST_IDS.subtitle, children: subtitle }))] })] })));
25
25
  }
26
- ModalHeader.aligns = ContentAlign;
@@ -0,0 +1,6 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+ import { ALIGN, CONTENT_ALIGN, MODE, SIZE } from './constants';
3
+ export type Size = ValueOf<typeof SIZE>;
4
+ export type Mode = ValueOf<typeof MODE>;
5
+ export type Align = ValueOf<typeof ALIGN>;
6
+ export type ContentAlign = ValueOf<typeof CONTENT_ALIGN>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/dist/utils.d.ts CHANGED
@@ -1,28 +1,26 @@
1
1
  /// <reference types="react" />
2
- import { Align, ContentAlign, Size } from './constants';
3
2
  import { ModalHeaderImage, ModalHeaderProps } from './helperComponents';
3
+ import { Align, Size } from './types';
4
4
  export declare function getAlignProps({ align, size }: {
5
5
  align: Align;
6
6
  size: Size;
7
7
  }): {
8
- header: ContentAlign;
9
- body: ContentAlign;
10
- footer: Align;
8
+ header: "default";
9
+ body: "default";
10
+ footer: "default";
11
+ } | {
12
+ header: "center";
13
+ body: "center";
14
+ footer: "center";
15
+ } | {
16
+ header: "center";
17
+ body: "center";
18
+ footer: "vertical";
11
19
  };
12
- export declare function getButtonsSizes({ align, size }: {
20
+ export declare function getButtonsSize({ align, size }: {
13
21
  align: Align;
14
22
  size: Size;
15
- }): {
16
- filled: import("@snack-uikit/button/dist/constants").SizeSL;
17
- outline: import("@snack-uikit/button/dist/constants").SizeSL;
18
- simple: import("@snack-uikit/button/dist/constants").SizeSL;
19
- light?: undefined;
20
- } | {
21
- filled: import("@snack-uikit/button/dist/constants").SizeSL;
22
- outline: import("@snack-uikit/button/dist/constants").SizeSL;
23
- light: import("@snack-uikit/button/dist/constants").SizeSL;
24
- simple?: undefined;
25
- };
23
+ }): "m" | "l";
26
24
  export declare function isPictureImage(picture: ModalHeaderProps['picture']): picture is ModalHeaderImage;
27
25
  export declare function getPicture({ size, picture }: {
28
26
  size: Size;
package/dist/utils.js CHANGED
@@ -1,46 +1,37 @@
1
- import { ButtonFilled, ButtonOutline, ButtonSimple } from '@snack-uikit/button';
2
- import { Align, ContentAlign, Size } from './constants';
1
+ import { ALIGN, CONTENT_ALIGN, SIZE } from './constants';
3
2
  const MAP_ALIGNS = {
4
- [Align.Default]: {
5
- header: ContentAlign.Default,
6
- body: ContentAlign.Default,
7
- footer: Align.Default,
3
+ [ALIGN.Default]: {
4
+ header: CONTENT_ALIGN.Default,
5
+ body: CONTENT_ALIGN.Default,
6
+ footer: ALIGN.Default,
8
7
  },
9
- [Align.Center]: {
10
- header: ContentAlign.Center,
11
- body: ContentAlign.Center,
12
- footer: Align.Center,
8
+ [ALIGN.Center]: {
9
+ header: CONTENT_ALIGN.Center,
10
+ body: CONTENT_ALIGN.Center,
11
+ footer: ALIGN.Center,
13
12
  },
14
- [Align.Vertical]: {
15
- header: ContentAlign.Center,
16
- body: ContentAlign.Center,
17
- footer: Align.Vertical,
13
+ [ALIGN.Vertical]: {
14
+ header: CONTENT_ALIGN.Center,
15
+ body: CONTENT_ALIGN.Center,
16
+ footer: ALIGN.Vertical,
18
17
  },
19
18
  };
20
19
  export function getAlignProps({ align, size }) {
21
- if (size === Size.L) {
22
- return MAP_ALIGNS[Align.Default];
20
+ if (size === SIZE.L) {
21
+ return MAP_ALIGNS[ALIGN.Default];
23
22
  }
24
- if (size === Size.M && align === Align.Vertical) {
25
- return MAP_ALIGNS[Align.Default];
23
+ if (size === SIZE.M && align === ALIGN.Vertical) {
24
+ return MAP_ALIGNS[ALIGN.Default];
26
25
  }
27
26
  return MAP_ALIGNS[align];
28
27
  }
29
- export function getButtonsSizes({ align, size }) {
28
+ export function getButtonsSize({ align, size }) {
30
29
  switch (true) {
31
- case align === Align.Vertical && size === Size.S:
32
- return {
33
- filled: ButtonFilled.sizes.L,
34
- outline: ButtonOutline.sizes.L,
35
- simple: ButtonSimple.sizes.L,
36
- };
37
- case [Align.Default, Align.Center].includes(align):
30
+ case align === ALIGN.Vertical && size === SIZE.S:
31
+ return 'l';
32
+ case [ALIGN.Default, ALIGN.Center].includes(align):
38
33
  default:
39
- return {
40
- filled: ButtonFilled.sizes.M,
41
- outline: ButtonOutline.sizes.M,
42
- light: ButtonSimple.sizes.M,
43
- };
34
+ return 'm';
44
35
  }
45
36
  }
46
37
  export function isPictureImage(picture) {
@@ -50,10 +41,10 @@ export function isPictureImage(picture) {
50
41
  }
51
42
  export function getPicture({ size, picture }) {
52
43
  switch (size) {
53
- case Size.S:
44
+ case SIZE.S:
54
45
  return picture;
55
- case Size.M:
56
- case Size.L:
46
+ case SIZE.M:
47
+ case SIZE.L:
57
48
  default:
58
49
  return isPictureImage(picture) ? picture : undefined;
59
50
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Modal",
7
- "version": "0.8.1",
7
+ "version": "0.9.1",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,20 +32,20 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/button": "0.14.1",
36
- "@snack-uikit/icon-predefined": "0.3.1",
37
- "@snack-uikit/icons": "0.19.0",
38
- "@snack-uikit/link": "0.8.1",
39
- "@snack-uikit/scroll": "0.4.1",
40
- "@snack-uikit/tooltip": "0.9.1",
41
- "@snack-uikit/truncate-string": "0.3.1",
42
- "@snack-uikit/typography": "0.5.1",
43
- "@snack-uikit/utils": "3.1.0",
35
+ "@snack-uikit/button": "0.15.0",
36
+ "@snack-uikit/icon-predefined": "0.4.0",
37
+ "@snack-uikit/icons": "0.19.1",
38
+ "@snack-uikit/link": "0.9.1",
39
+ "@snack-uikit/scroll": "0.5.0",
40
+ "@snack-uikit/tooltip": "0.10.1",
41
+ "@snack-uikit/truncate-string": "0.4.1",
42
+ "@snack-uikit/typography": "0.6.0",
43
+ "@snack-uikit/utils": "3.2.0",
44
44
  "classnames": "2.3.2",
45
45
  "react-modal": "3.16.1"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/react-modal": "3.16.0"
49
49
  },
50
- "gitHead": "76a159dde7baccf49dc7b11e1fd7abc31424b42f"
50
+ "gitHead": "62f43bf0cbfd611d0b746117400f67096b1790f6"
51
51
  }
@@ -3,8 +3,8 @@ import { Link } from '@snack-uikit/link';
3
3
  import { TruncateString } from '@snack-uikit/truncate-string';
4
4
  import { Typography } from '@snack-uikit/typography';
5
5
 
6
- import { Align, Mode, Size, TEST_IDS } from '../../constants';
7
- import { getAlignProps, getButtonsSizes, getPicture } from '../../utils';
6
+ import { ALIGN, MODE, SIZE, TEST_IDS } from '../../constants';
7
+ import { getAlignProps, getButtonsSize, getPicture } from '../../utils';
8
8
  import { ModalCustom } from '../ModalCustom';
9
9
  import styles from './styles.module.scss';
10
10
  import { ModalLProps, ModalMProps, ModalSProps } from './types';
@@ -14,9 +14,9 @@ export type ModalProps = ModalSProps | ModalMProps | ModalLProps;
14
14
  export function Modal({
15
15
  open,
16
16
  onClose,
17
- size = Size.S,
18
- mode = Mode.Regular,
19
- align = Align.Default,
17
+ size = SIZE.S,
18
+ mode = MODE.Regular,
19
+ align = ALIGN.Default,
20
20
  title,
21
21
  titleTooltip,
22
22
  subtitle,
@@ -30,7 +30,7 @@ export function Modal({
30
30
  ...rest
31
31
  }: ModalProps) {
32
32
  const aligns = getAlignProps({ align, size });
33
- const buttonsSizes = getButtonsSizes({ align, size });
33
+ const buttonsSize = getButtonsSize({ align, size });
34
34
  const picture = getPicture({ size, picture: pictureProp });
35
35
 
36
36
  return (
@@ -50,7 +50,7 @@ export function Modal({
50
50
  <>
51
51
  <ButtonFilled
52
52
  {...approveButton}
53
- size={buttonsSizes.filled}
53
+ size={buttonsSize}
54
54
  className={styles.footerButton}
55
55
  data-test-id={TEST_IDS.approveButton}
56
56
  />
@@ -58,7 +58,7 @@ export function Modal({
58
58
  {cancelButton && (
59
59
  <ButtonOutline
60
60
  {...cancelButton}
61
- size={buttonsSizes.outline}
61
+ size={buttonsSize}
62
62
  className={styles.footerButton}
63
63
  data-test-id={TEST_IDS.cancelButton}
64
64
  />
@@ -67,7 +67,7 @@ export function Modal({
67
67
  {additionalButton && (
68
68
  <ButtonSimple
69
69
  {...additionalButton}
70
- size={buttonsSizes.light}
70
+ size={buttonsSize}
71
71
  className={styles.footerButton}
72
72
  data-test-id={TEST_IDS.additionalButton}
73
73
  />
@@ -77,17 +77,10 @@ export function Modal({
77
77
  disclaimer={
78
78
  disclaimer && (
79
79
  <>
80
- <Typography
81
- family={Typography.families.Sans}
82
- role={Typography.roles.Body}
83
- size={Typography.sizes.S}
84
- data-test-id={TEST_IDS.disclaimerText}
85
- >
86
- {disclaimer.text}
87
- </Typography>
80
+ <Typography.SansBodyS data-test-id={TEST_IDS.disclaimerText}>{disclaimer.text}</Typography.SansBodyS>
88
81
 
89
82
  {disclaimer.link && (
90
- <Link {...disclaimer.link} size={Link.sizes.S} external data-test-id={TEST_IDS.disclaimerLink} />
83
+ <Link {...disclaimer.link} size='s' external data-test-id={TEST_IDS.disclaimerLink} />
91
84
  )}
92
85
  </>
93
86
  )
@@ -98,7 +91,3 @@ export function Modal({
98
91
  </ModalCustom>
99
92
  );
100
93
  }
101
-
102
- Modal.aligns = Align;
103
- Modal.modes = Mode;
104
- Modal.sizes = Size;
@@ -1,8 +1,9 @@
1
1
  import { ButtonFilledProps, ButtonOutlineProps, ButtonSimpleProps } from '@snack-uikit/button';
2
2
  import { LinkProps } from '@snack-uikit/link';
3
3
 
4
- import { Align, Size } from '../../constants';
4
+ import { ALIGN, SIZE } from '../../constants';
5
5
  import { ModalBodyProps, ModalHeaderImage, ModalHeaderProps } from '../../helperComponents';
6
+ import { Align } from '../../types';
6
7
  import { ModalCustomProps } from '../ModalCustom';
7
8
 
8
9
  type BaseModalProps = Omit<ModalCustomProps, 'children' | 'size'> & {
@@ -29,10 +30,10 @@ type BaseModalProps = Omit<ModalCustomProps, 'children' | 'size'> & {
29
30
 
30
31
  export type ModalSProps = BaseModalProps & {
31
32
  /** Размер */
32
- size?: Size.S;
33
+ size?: typeof SIZE.S;
33
34
  /**
34
35
  * Выравнивание, для разных размеров доступны разные значения
35
- * <br> для `Size.S` - все
36
+ * <br> для size=`s` - все
36
37
  */
37
38
  align?: Align;
38
39
  /** Можно передать иконку из пакета `@snack-uikit/icon-predefined`, или путь к картинке и атрибут `alt` */
@@ -40,15 +41,15 @@ export type ModalSProps = BaseModalProps & {
40
41
  };
41
42
 
42
43
  export type ModalMProps = BaseModalProps & {
43
- size?: Size.M;
44
- /** <br> для `Size.M` - `Align.Default | Align.Center` */
45
- align?: Align.Default | Align.Center;
44
+ size?: typeof SIZE.M;
45
+ /** <br> для size=`m` - align=`default | center` */
46
+ align?: typeof ALIGN.Default | typeof ALIGN.Center;
46
47
  picture?: ModalHeaderImage;
47
48
  };
48
49
 
49
50
  export type ModalLProps = BaseModalProps & {
50
- size?: Size.L;
51
- /** <br> для `Size.L` - `Align.Default` */
52
- align?: Align.Default;
51
+ size?: typeof SIZE.L;
52
+ /** <br> для size=`l` - align=`default` */
53
+ align?: typeof ALIGN.Default;
53
54
  picture?: ModalHeaderImage;
54
55
  };
@@ -4,7 +4,7 @@ import RCModal from 'react-modal';
4
4
 
5
5
  import { WithSupportProps } from '@snack-uikit/utils';
6
6
 
7
- import { Mode, Size } from '../../constants';
7
+ import { MODE, SIZE } from '../../constants';
8
8
  import {
9
9
  ButtonClose,
10
10
  ModalBody,
@@ -15,6 +15,7 @@ import {
15
15
  ModalHeaderProps,
16
16
  OverlayElement,
17
17
  } from '../../helperComponents';
18
+ import { Mode, Size } from '../../types';
18
19
  import styles from './styles.module.scss';
19
20
  import { getDataTestAttributes } from './utils';
20
21
 
@@ -45,8 +46,8 @@ export type ModalCustomProps = WithSupportProps<{
45
46
  export function ModalCustom({
46
47
  open,
47
48
  onClose,
48
- size = Size.S,
49
- mode = Mode.Regular,
49
+ size = SIZE.S,
50
+ mode = MODE.Regular,
50
51
  children,
51
52
  className,
52
53
  ...rest
@@ -56,7 +57,7 @@ export function ModalCustom({
56
57
  };
57
58
 
58
59
  const handleClose = () => {
59
- if (mode === Mode.Regular) {
60
+ if (mode === MODE.Regular) {
60
61
  onClose();
61
62
  }
62
63
  };
@@ -68,11 +69,15 @@ export function ModalCustom({
68
69
  onRequestClose={handleClose}
69
70
  appElement={document.body}
70
71
  overlayElement={(_, content) => (
71
- <OverlayElement blur={[Mode.Forced, Mode.Aggressive].includes(mode)} content={content} onClose={handleClose} />
72
+ <OverlayElement
73
+ blur={([MODE.Forced, MODE.Aggressive] as Mode[]).includes(mode)}
74
+ content={content}
75
+ onClose={handleClose}
76
+ />
72
77
  )}
73
78
  className={cn(styles.modal, className)}
74
79
  >
75
- {mode !== Mode.Forced && (
80
+ {mode !== MODE.Forced && (
76
81
  <div className={styles.headerElements}>
77
82
  <ButtonClose onClick={handleCloseButtonClick} />
78
83
  </div>
@@ -83,9 +88,6 @@ export function ModalCustom({
83
88
  );
84
89
  }
85
90
 
86
- ModalCustom.modes = Mode;
87
- ModalCustom.sizes = Size;
88
-
89
91
  export namespace ModalCustom {
90
92
  export type HeaderProps = ModalHeaderProps;
91
93
  export type BodyProps = ModalBodyProps;
package/src/constants.ts CHANGED
@@ -1,25 +1,25 @@
1
- export enum Size {
2
- S = 's',
3
- M = 'm',
4
- L = 'l',
5
- }
1
+ export const SIZE = {
2
+ S: 's',
3
+ M: 'm',
4
+ L: 'l',
5
+ } as const;
6
6
 
7
- export enum Mode {
8
- Regular = 'regular',
9
- Aggressive = 'aggressive',
10
- Forced = 'forced',
11
- }
7
+ export const MODE = {
8
+ Regular: 'regular',
9
+ Aggressive: 'aggressive',
10
+ Forced: 'forced',
11
+ } as const;
12
12
 
13
- export enum Align {
14
- Default = 'default',
15
- Center = 'center',
16
- Vertical = 'vertical',
17
- }
13
+ export const ALIGN = {
14
+ Default: 'default',
15
+ Center: 'center',
16
+ Vertical: 'vertical',
17
+ } as const;
18
18
 
19
- export enum ContentAlign {
20
- Default = 'default',
21
- Center = 'center',
22
- }
19
+ export const CONTENT_ALIGN = {
20
+ Default: 'default',
21
+ Center: 'center',
22
+ } as const;
23
23
 
24
24
  export const TEST_IDS = {
25
25
  overlay: 'modal__overlay',
@@ -4,7 +4,8 @@ import { ReactNode } from 'react';
4
4
  import { Scroll } from '@snack-uikit/scroll';
5
5
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
6
6
 
7
- import { ContentAlign, TEST_IDS } from '../../constants';
7
+ import { CONTENT_ALIGN, TEST_IDS } from '../../constants';
8
+ import { ContentAlign } from '../../types';
8
9
  import styles from './styles.module.scss';
9
10
 
10
11
  export type ModalBodyProps = WithSupportProps<{
@@ -15,10 +16,10 @@ export type ModalBodyProps = WithSupportProps<{
15
16
  className?: string;
16
17
  }>;
17
18
 
18
- export function ModalBody({ content, align = ContentAlign.Default, className, ...rest }: ModalBodyProps) {
19
+ export function ModalBody({ content, align = CONTENT_ALIGN.Default, className, ...rest }: ModalBodyProps) {
19
20
  return (
20
21
  <Scroll
21
- size={Scroll.sizes.M}
22
+ size='m'
22
23
  className={cn(styles.modalBody, className)}
23
24
  {...extractSupportProps(rest)}
24
25
  data-align={align}
@@ -28,5 +29,3 @@ export function ModalBody({ content, align = ContentAlign.Default, className, ..
28
29
  </Scroll>
29
30
  );
30
31
  }
31
-
32
- ModalBody.aligns = ContentAlign;
@@ -3,7 +3,8 @@ import { ReactNode } from 'react';
3
3
 
4
4
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
5
5
 
6
- import { Align, TEST_IDS } from '../../constants';
6
+ import { ALIGN, TEST_IDS } from '../../constants';
7
+ import { Align } from '../../types';
7
8
  import styles from './styles.module.scss';
8
9
 
9
10
  export type ModalFooterProps = WithSupportProps<{
@@ -16,7 +17,7 @@ export type ModalFooterProps = WithSupportProps<{
16
17
  className?: string;
17
18
  }>;
18
19
 
19
- export function ModalFooter({ actions, disclaimer, align = Align.Default, className, ...rest }: ModalFooterProps) {
20
+ export function ModalFooter({ actions, disclaimer, align = ALIGN.Default, className, ...rest }: ModalFooterProps) {
20
21
  return (
21
22
  <div
22
23
  data-align={align}
@@ -34,5 +35,3 @@ export function ModalFooter({ actions, disclaimer, align = Align.Default, classN
34
35
  </div>
35
36
  );
36
37
  }
37
-
38
- ModalFooter.aligns = Align;
@@ -6,7 +6,8 @@ import { QuestionTooltip, QuestionTooltipProps } from '@snack-uikit/tooltip';
6
6
  import { Typography } from '@snack-uikit/typography';
7
7
  import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
8
8
 
9
- import { ContentAlign, TEST_IDS } from '../../constants';
9
+ import { CONTENT_ALIGN, TEST_IDS } from '../../constants';
10
+ import { ContentAlign } from '../../types';
10
11
  import { isPictureImage } from '../../utils';
11
12
  import styles from './styles.module.scss';
12
13
  import { ModalHeaderImage } from './types';
@@ -29,7 +30,7 @@ export function ModalHeader({
29
30
  title,
30
31
  titleTooltip,
31
32
  subtitle,
32
- align = ContentAlign.Default,
33
+ align = CONTENT_ALIGN.Default,
33
34
  picture,
34
35
  className,
35
36
  ...rest
@@ -41,41 +42,25 @@ export function ModalHeader({
41
42
  <img src={picture.src} alt={picture.alt} className={styles.image} data-test-id={TEST_IDS.image} />
42
43
  ) : (
43
44
  <div className={styles.icon} data-test-id={TEST_IDS.icon}>
44
- <IconPredefined icon={picture} size={IconPredefined.sizes.L} />
45
+ <IconPredefined icon={picture} size='l' />
45
46
  </div>
46
47
  ))}
47
48
 
48
49
  <div className={styles.headlineLayout} data-align={align}>
49
50
  <div className={styles.headline}>
50
- <Typography
51
- family={Typography.families.Sans}
52
- role={Typography.roles.Headline}
53
- size={Typography.sizes.S}
54
- className={styles.title}
55
- data-test-id={TEST_IDS.title}
56
- >
51
+ <Typography.SansHeadlineS className={styles.title} data-test-id={TEST_IDS.title}>
57
52
  {title}
58
- </Typography>
53
+ </Typography.SansHeadlineS>
59
54
 
60
- {titleTooltip && (
61
- <QuestionTooltip tip={titleTooltip} size={QuestionTooltip.sizes.S} data-test-id={TEST_IDS.tooltip} />
62
- )}
55
+ {titleTooltip && <QuestionTooltip tip={titleTooltip} size='s' data-test-id={TEST_IDS.tooltip} />}
63
56
  </div>
64
57
 
65
58
  {subtitle && (
66
- <Typography
67
- family={Typography.families.Sans}
68
- role={Typography.roles.Body}
69
- size={Typography.sizes.M}
70
- className={styles.subtitle}
71
- data-test-id={TEST_IDS.subtitle}
72
- >
59
+ <Typography.SansBodyM className={styles.subtitle} data-test-id={TEST_IDS.subtitle}>
73
60
  {subtitle}
74
- </Typography>
61
+ </Typography.SansBodyM>
75
62
  )}
76
63
  </div>
77
64
  </div>
78
65
  );
79
66
  }
80
-
81
- ModalHeader.aligns = ContentAlign;
package/src/types.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+
3
+ import { ALIGN, CONTENT_ALIGN, MODE, SIZE } from './constants';
4
+
5
+ export type Size = ValueOf<typeof SIZE>;
6
+
7
+ export type Mode = ValueOf<typeof MODE>;
8
+
9
+ export type Align = ValueOf<typeof ALIGN>;
10
+
11
+ export type ContentAlign = ValueOf<typeof CONTENT_ALIGN>;
package/src/utils.ts CHANGED
@@ -1,53 +1,44 @@
1
- import { ButtonFilled, ButtonOutline, ButtonSimple } from '@snack-uikit/button';
2
-
3
- import { Align, ContentAlign, Size } from './constants';
1
+ import { ALIGN, CONTENT_ALIGN, SIZE } from './constants';
4
2
  import { ModalHeaderImage, ModalHeaderProps } from './helperComponents';
3
+ import { Align, Size } from './types';
5
4
 
6
5
  const MAP_ALIGNS = {
7
- [Align.Default]: {
8
- header: ContentAlign.Default,
9
- body: ContentAlign.Default,
10
- footer: Align.Default,
6
+ [ALIGN.Default]: {
7
+ header: CONTENT_ALIGN.Default,
8
+ body: CONTENT_ALIGN.Default,
9
+ footer: ALIGN.Default,
11
10
  },
12
- [Align.Center]: {
13
- header: ContentAlign.Center,
14
- body: ContentAlign.Center,
15
- footer: Align.Center,
11
+ [ALIGN.Center]: {
12
+ header: CONTENT_ALIGN.Center,
13
+ body: CONTENT_ALIGN.Center,
14
+ footer: ALIGN.Center,
16
15
  },
17
- [Align.Vertical]: {
18
- header: ContentAlign.Center,
19
- body: ContentAlign.Center,
20
- footer: Align.Vertical,
16
+ [ALIGN.Vertical]: {
17
+ header: CONTENT_ALIGN.Center,
18
+ body: CONTENT_ALIGN.Center,
19
+ footer: ALIGN.Vertical,
21
20
  },
22
21
  };
23
22
 
24
23
  export function getAlignProps({ align, size }: { align: Align; size: Size }) {
25
- if (size === Size.L) {
26
- return MAP_ALIGNS[Align.Default];
24
+ if (size === SIZE.L) {
25
+ return MAP_ALIGNS[ALIGN.Default];
27
26
  }
28
27
 
29
- if (size === Size.M && align === Align.Vertical) {
30
- return MAP_ALIGNS[Align.Default];
28
+ if (size === SIZE.M && align === ALIGN.Vertical) {
29
+ return MAP_ALIGNS[ALIGN.Default];
31
30
  }
32
31
 
33
32
  return MAP_ALIGNS[align];
34
33
  }
35
34
 
36
- export function getButtonsSizes({ align, size }: { align: Align; size: Size }) {
35
+ export function getButtonsSize({ align, size }: { align: Align; size: Size }) {
37
36
  switch (true) {
38
- case align === Align.Vertical && size === Size.S:
39
- return {
40
- filled: ButtonFilled.sizes.L,
41
- outline: ButtonOutline.sizes.L,
42
- simple: ButtonSimple.sizes.L,
43
- };
44
- case [Align.Default, Align.Center].includes(align):
37
+ case align === ALIGN.Vertical && size === SIZE.S:
38
+ return 'l';
39
+ case ([ALIGN.Default, ALIGN.Center] as Align[]).includes(align):
45
40
  default:
46
- return {
47
- filled: ButtonFilled.sizes.M,
48
- outline: ButtonOutline.sizes.M,
49
- light: ButtonSimple.sizes.M,
50
- };
41
+ return 'm';
51
42
  }
52
43
  }
53
44
 
@@ -59,10 +50,10 @@ export function isPictureImage(picture: ModalHeaderProps['picture']): picture is
59
50
 
60
51
  export function getPicture({ size, picture }: { size: Size; picture: ModalHeaderProps['picture'] }) {
61
52
  switch (size) {
62
- case Size.S:
53
+ case SIZE.S:
63
54
  return picture;
64
- case Size.M:
65
- case Size.L:
55
+ case SIZE.M:
56
+ case SIZE.L:
66
57
  default:
67
58
  return isPictureImage(picture) ? picture : undefined;
68
59
  }