@synerise/ds-confirmation 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 1.1.0 (2025-05-19)
7
+
8
+
9
+ ### Features
10
+
11
+ * **confirmation:** new component ([5ed5b96](https://github.com/Synerise/synerise-design/commit/5ed5b96540e82576951221fdf5f26695c02171e7))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Synerise
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ ---
2
+ id: confirmation
3
+ title: Confirmation
4
+ ---
5
+
6
+ Confirmation UI Component
7
+
8
+ ## Installation
9
+
10
+ ```
11
+ npm i @synerise/ds-confirmation
12
+ or
13
+ yarn add @synerise/ds-confirmation
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ import Confirmation from '@synerise/ds-confirmation'
20
+
21
+ <Confirmation />
22
+
23
+ ```
24
+
25
+ ## Demo
26
+
27
+ <iframe src="/storybook-static/iframe.html?id=components-confirmation--default"></iframe>
28
+
29
+ ## API
30
+
31
+ | Property | Description | Type | Default |
32
+ | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ------- |
33
+ | icon | icon to display above title | Preferably Xl size icon from ds-icons ReactNode | - |
34
+ | title | confirmation title | ReactNode | - |
35
+ | description | confirmation details | ReactNode | - |
36
+ | texts | custom translations | ReactNode | - |
37
+ | type | action type - this defines the button (and icon if negative) color | `success` / `warning` / `negative` / `informative` | - |
38
+ | mainButtonProps | additional button customisation props | subset of ButtonProps see ds-button | - |
39
+ | secondaryButtonProps | additional button customisation props | subset of ButtonProps see ds-button | - |
40
+ | relatedObjects | display objects that have relations to the object, renders a button in the footer that will switch confirmation modal content to this ReactNode | ReactNode | - |
41
+ | batchActionItems | renders a list of items that are affected | ListItemProps[] | - |
42
+ | decisionOptions | renders a group of radio buttons to choose from | RadioProps[] | - |
43
+ | additionalInfo | extra description to render within a bordered frame | ReactNode | - |
44
+
45
+ ### Prompt
46
+
47
+ | Property | Description | Type | Default |
48
+ | -------------------- | ------------------------------------------- | -------------------------------------------------- | ------- |
49
+ | title | prompt title | ReactNode | - |
50
+ | content | prompt content | ReactNode | - |
51
+ | texts | custom translations | ReactNode | - |
52
+ | type | action type - this defines the button color | `success` / `warning` / `negative` / `informative` | - |
53
+ | mainButtonProps | additional button customisation props | subset of ButtonProps see ds-button | - |
54
+ | secondaryButtonProps | additional button customisation props | subset of ButtonProps see ds-button | - |
55
+
56
+ ### ConfirmationTexts
57
+
58
+ | Property | Description | Type | Default |
59
+ | ------------------------- | ----------- | --------- | ------------------------- |
60
+ | mainButtonLabel | | ReactNode | `Ok` |
61
+ | secondaryButtonLabel | | ReactNode | `Cancel` |
62
+ | relatedObjectsButtonLabel | | ReactNode | `Show related objects` |
63
+ | relatedObjectsTitle | | ReactNode | `Objects to delete` |
64
+ | batchActionItemsTitle | | ReactNode | `What do you want to do?` |
65
+ | decisionTitle | | ReactNode | `Related objects` |
@@ -0,0 +1,4 @@
1
+ import type { ConfirmationType } from './Confirmation.types';
2
+ export declare const BUTTON_COLOR_MAPPING: Record<ConfirmationType, string>;
3
+ export declare const ITEM_SIZE = 32;
4
+ export declare const MAX_ITEMS = 6;
@@ -0,0 +1,8 @@
1
+ export var BUTTON_COLOR_MAPPING = {
2
+ negative: 'red',
3
+ success: 'green',
4
+ warning: 'yellow',
5
+ informative: 'blue'
6
+ };
7
+ export var ITEM_SIZE = 32;
8
+ export var MAX_ITEMS = 6;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import type { ListItemProps } from '@synerise/ds-list-item';
3
+ import type { ConfirmationProps } from './Confirmation.types';
4
+ declare const Confirmation: <ItemType extends ListItemProps>({ type, texts, title, description, onCancel, onOk, icon, batchActionItems, decisionOptions, relatedObjects, additionalInfo, secondaryButtonProps, mainButtonProps, ...modalProps }: ConfirmationProps<ItemType>) => React.JSX.Element;
5
+ export default Confirmation;
@@ -0,0 +1,92 @@
1
+ var _excluded = ["type", "texts", "title", "description", "onCancel", "onOk", "icon", "batchActionItems", "decisionOptions", "relatedObjects", "additionalInfo", "secondaryButtonProps", "mainButtonProps"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React, { useMemo, useState } from 'react';
5
+ import Modal from '@synerise/ds-modal';
6
+ import { Paragraph } from '@synerise/ds-typography';
7
+ import Icon, { ShowM, ArrowLeftM } from '@synerise/ds-icon';
8
+ import Button from '@synerise/ds-button';
9
+ import { useTheme } from '@synerise/ds-core';
10
+ import * as S from './Confirmation.styles';
11
+ import { useDefaultTexts } from './hooks/useDefaultTexts';
12
+ import { BUTTON_COLOR_MAPPING } from './Confirmation.const';
13
+ import { BatchItemsList } from './components/BatchItemsList';
14
+ import { DecisionSection } from './components/DecisionSection';
15
+ var Confirmation = function Confirmation(_ref) {
16
+ var type = _ref.type,
17
+ texts = _ref.texts,
18
+ title = _ref.title,
19
+ description = _ref.description,
20
+ onCancel = _ref.onCancel,
21
+ onOk = _ref.onOk,
22
+ icon = _ref.icon,
23
+ batchActionItems = _ref.batchActionItems,
24
+ decisionOptions = _ref.decisionOptions,
25
+ relatedObjects = _ref.relatedObjects,
26
+ additionalInfo = _ref.additionalInfo,
27
+ secondaryButtonProps = _ref.secondaryButtonProps,
28
+ mainButtonProps = _ref.mainButtonProps,
29
+ modalProps = _objectWithoutPropertiesLoose(_ref, _excluded);
30
+ var _useState = useState('default'),
31
+ mode = _useState[0],
32
+ setMode = _useState[1];
33
+ var theme = useTheme();
34
+ var allTexts = useDefaultTexts(texts);
35
+ var buttonColor = BUTTON_COLOR_MAPPING[type];
36
+ var iconColor = type === 'negative' ? theme.palette['red-600'] : theme.palette['grey-800'];
37
+ var modalContent = useMemo(function () {
38
+ if (mode === 'default') {
39
+ return /*#__PURE__*/React.createElement(S.ConfirmationModalContent, null, /*#__PURE__*/React.createElement(S.ConfirmationModalContentMain, null, /*#__PURE__*/React.createElement(Icon, {
40
+ component: icon,
41
+ size: 96,
42
+ color: iconColor
43
+ }), /*#__PURE__*/React.createElement(S.Title, {
44
+ level: 3
45
+ }, title), /*#__PURE__*/React.createElement(Paragraph, {
46
+ size: "small"
47
+ }, description)), additionalInfo && /*#__PURE__*/React.createElement(S.AdditionalInfo, null, additionalInfo), (batchActionItems == null ? void 0 : batchActionItems.length) && /*#__PURE__*/React.createElement(BatchItemsList, {
48
+ items: batchActionItems,
49
+ title: allTexts.batchActionItemsTitle
50
+ }), (decisionOptions == null ? void 0 : decisionOptions.length) && /*#__PURE__*/React.createElement(DecisionSection, {
51
+ options: decisionOptions,
52
+ title: allTexts.decisionTitle
53
+ }));
54
+ }
55
+ return relatedObjects;
56
+ }, [relatedObjects, mode, icon, iconColor, additionalInfo, title, description, batchActionItems, decisionOptions, allTexts.batchActionItemsTitle, allTexts.decisionTitle]);
57
+ var modalFooter = useMemo(function () {
58
+ return mode === 'default' ? /*#__PURE__*/React.createElement(S.Footer, null, relatedObjects && /*#__PURE__*/React.createElement(S.FooterLeft, null, /*#__PURE__*/React.createElement(Button, {
59
+ onClick: function onClick() {
60
+ return setMode('related-objects');
61
+ },
62
+ type: "ghost",
63
+ mode: "icon-label"
64
+ }, /*#__PURE__*/React.createElement(Icon, {
65
+ component: /*#__PURE__*/React.createElement(ShowM, null)
66
+ }), " ", allTexts.relatedObjectsButtonLabel)), /*#__PURE__*/React.createElement(S.FooterRight, null, /*#__PURE__*/React.createElement(Button, _extends({
67
+ type: "secondary",
68
+ onClick: onCancel
69
+ }, secondaryButtonProps), allTexts.secondaryButtonLabel), /*#__PURE__*/React.createElement(Button, _extends({
70
+ type: "custom-color",
71
+ onClick: onOk,
72
+ color: buttonColor
73
+ }, mainButtonProps), allTexts.mainButtonLabel))) : null;
74
+ }, [mode, onOk, onCancel, buttonColor, mainButtonProps, relatedObjects, secondaryButtonProps, allTexts.secondaryButtonLabel, allTexts.mainButtonLabel, allTexts.relatedObjectsButtonLabel]);
75
+ var modalTitle = mode === 'related-objects' ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
76
+ onClick: function onClick() {
77
+ return setMode('default');
78
+ },
79
+ component: /*#__PURE__*/React.createElement(ArrowLeftM, null)
80
+ }), " ", allTexts.relatedObjectsTitle) : undefined;
81
+ return /*#__PURE__*/React.createElement(Modal, _extends({}, modalProps, {
82
+ onCancel: onCancel,
83
+ size: "small",
84
+ blank: mode === 'default',
85
+ footer: modalFooter,
86
+ bodyStyle: {
87
+ padding: 0
88
+ },
89
+ title: modalTitle
90
+ }), modalContent);
91
+ };
92
+ export default Confirmation;
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ export declare const ConfirmationModalContent: import("styled-components").StyledComponent<"div", any, {}, never>;
3
+ export declare const PromptContent: import("styled-components").StyledComponent<"div", any, {}, never>;
4
+ export declare const ConfirmationModalContentMain: import("styled-components").StyledComponent<"div", any, {}, never>;
5
+ export declare const Title: import("styled-components").StyledComponent<({ level, withoutMargin, children, className, ellipsis, ...antdProps }: import("@synerise/ds-typography/dist/Title.types").Props) => import("react").JSX.Element, any, {}, never>;
6
+ export declare const FooterRight: import("styled-components").StyledComponent<"div", any, {}, never>;
7
+ export declare const FooterLeft: import("styled-components").StyledComponent<"div", any, {}, never>;
8
+ export declare const Footer: import("styled-components").StyledComponent<"div", any, {}, never>;
9
+ export declare const ConfirmationExtra: import("styled-components").StyledComponent<"div", any, {}, never>;
10
+ export declare const ConfirmationExtraTitle: import("styled-components").StyledComponent<({ level, withoutMargin, children, className, ellipsis, ...antdProps }: import("@synerise/ds-typography/dist/Title.types").Props) => import("react").JSX.Element, any, {}, never>;
11
+ export declare const BatchItemsList: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<(import("@synerise/ds-scrollbar").ScrollbarProps | import("@synerise/ds-scrollbar").VirtualScrollbarProps) & import("react").RefAttributes<HTMLElement>>, any, {}, never>;
12
+ export declare const AdditionalInfo: import("styled-components").StyledComponent<"div", any, {}, never>;
13
+ export declare const DecisionOptions: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -0,0 +1,57 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { Title as TypographyTitle } from '@synerise/ds-typography';
3
+ import Scrollbar from '@synerise/ds-scrollbar';
4
+ import { RadioWrapper, AdditionalData } from '@synerise/ds-radio/dist/Radio.styles';
5
+ var roundedWrapperCSS = css(["border:solid ", " 1px;border-radius:8px;padding:8px;"], function (props) {
6
+ return props.theme.palette['grey-200'];
7
+ });
8
+ var sectionTitleCSS = css(["margin-bottom:8px;"]);
9
+ var modalContentCSS = css(["padding:36px 48px 48px;"]);
10
+ export var ConfirmationModalContent = styled.div.withConfig({
11
+ displayName: "Confirmationstyles__ConfirmationModalContent",
12
+ componentId: "sc-17izghl-0"
13
+ })(["display:flex;flex-direction:column;align-items:stretch;", " gap:24px;"], modalContentCSS);
14
+ export var PromptContent = styled.div.withConfig({
15
+ displayName: "Confirmationstyles__PromptContent",
16
+ componentId: "sc-17izghl-1"
17
+ })(["", ""], modalContentCSS);
18
+ export var ConfirmationModalContentMain = styled.div.withConfig({
19
+ displayName: "Confirmationstyles__ConfirmationModalContentMain",
20
+ componentId: "sc-17izghl-2"
21
+ })(["display:flex;flex-direction:column;align-items:center;gap:12px;"]);
22
+ export var Title = styled(TypographyTitle).withConfig({
23
+ displayName: "Confirmationstyles__Title",
24
+ componentId: "sc-17izghl-3"
25
+ })(["margin:0;"]);
26
+ export var FooterRight = styled.div.withConfig({
27
+ displayName: "Confirmationstyles__FooterRight",
28
+ componentId: "sc-17izghl-4"
29
+ })(["flex:1 1 auto;"]);
30
+ export var FooterLeft = styled.div.withConfig({
31
+ displayName: "Confirmationstyles__FooterLeft",
32
+ componentId: "sc-17izghl-5"
33
+ })(["flex:1 1 auto;text-align:left;"]);
34
+ export var Footer = styled.div.withConfig({
35
+ displayName: "Confirmationstyles__Footer",
36
+ componentId: "sc-17izghl-6"
37
+ })(["display:flex;justify-content:space-between;"]);
38
+ export var ConfirmationExtra = styled.div.withConfig({
39
+ displayName: "Confirmationstyles__ConfirmationExtra",
40
+ componentId: "sc-17izghl-7"
41
+ })([""]);
42
+ export var ConfirmationExtraTitle = styled(TypographyTitle).withConfig({
43
+ displayName: "Confirmationstyles__ConfirmationExtraTitle",
44
+ componentId: "sc-17izghl-8"
45
+ })(["", ""], sectionTitleCSS);
46
+ export var BatchItemsList = styled(Scrollbar).withConfig({
47
+ displayName: "Confirmationstyles__BatchItemsList",
48
+ componentId: "sc-17izghl-9"
49
+ })(["", ""], roundedWrapperCSS);
50
+ export var AdditionalInfo = styled.div.withConfig({
51
+ displayName: "Confirmationstyles__AdditionalInfo",
52
+ componentId: "sc-17izghl-10"
53
+ })(["", ""], roundedWrapperCSS);
54
+ export var DecisionOptions = styled.div.withConfig({
55
+ displayName: "Confirmationstyles__DecisionOptions",
56
+ componentId: "sc-17izghl-11"
57
+ })(["", ":last-of-type{margin-bottom:0;}", ":empty{display:none;}", ""], RadioWrapper, AdditionalData, roundedWrapperCSS);
@@ -0,0 +1,64 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ButtonProps } from '@synerise/ds-button';
3
+ import type { ListItemProps } from '@synerise/ds-list-item';
4
+ import type { RadioProps } from '@synerise/ds-radio';
5
+ import type { ModalProps } from '@synerise/ds-modal';
6
+ import type { DataAttributes } from '@synerise/ds-utils';
7
+ export type ConfirmationType = 'success' | 'warning' | 'negative' | 'informative';
8
+ export type ConfirmationButtonProps = Pick<ButtonProps, 'mode' | 'loading' | 'readOnly' | 'disabled' | 'tagProps'> & DataAttributes;
9
+ export type ConfirmationTexts = {
10
+ mainButtonLabel: ReactNode;
11
+ secondaryButtonLabel: ReactNode;
12
+ relatedObjectsButtonLabel: ReactNode;
13
+ relatedObjectsTitle: ReactNode;
14
+ batchActionItemsTitle: ReactNode;
15
+ decisionTitle: ReactNode;
16
+ };
17
+ export type RelatedObjectsModalProps = {
18
+ goBack: () => void;
19
+ content: ReactNode;
20
+ title: ReactNode;
21
+ };
22
+ export type BatchItemsListProps<ItemType extends ListItemProps> = {
23
+ items: ItemType[];
24
+ title: ReactNode;
25
+ };
26
+ export type DecisionSectionProps = {
27
+ options: RadioProps[];
28
+ title: ReactNode;
29
+ };
30
+ export type DisplayMode = 'default' | 'related-objects';
31
+ type SharedProps = Pick<ModalProps, 'open' | 'title' | 'zIndex' | 'onCancel' | 'onOk'> & {
32
+ title: ReactNode;
33
+ texts?: Partial<ConfirmationTexts>;
34
+ /**
35
+ * Defines button & icon colors
36
+ */
37
+ type: ConfirmationType;
38
+ mainButtonProps?: ConfirmationButtonProps;
39
+ secondaryButtonProps?: ConfirmationButtonProps;
40
+ };
41
+ export type ConfirmationProps<ItemType extends ListItemProps> = SharedProps & {
42
+ description?: ReactNode;
43
+ icon: ReactNode;
44
+ /**
45
+ * Renders a link in footer to show table with related objects affected by the action
46
+ */
47
+ relatedObjects?: ReactNode;
48
+ /**
49
+ * Renders list of items that are affected by the action (batch actions confirmation)
50
+ */
51
+ batchActionItems?: BatchItemsListProps<ItemType>['items'];
52
+ /**
53
+ * Renders list of action options as a radio selection
54
+ */
55
+ decisionOptions?: DecisionSectionProps['options'];
56
+ /**
57
+ * Additional info displayed below description in a rounded frame
58
+ */
59
+ additionalInfo?: ReactNode;
60
+ };
61
+ export type PromptProps = SharedProps & {
62
+ content?: ReactNode;
63
+ };
64
+ export {};
@@ -0,0 +1 @@
1
+ export {};
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { ListItemProps } from '@synerise/ds-list-item';
3
+ import type { BatchItemsListProps } from '../Confirmation.types';
4
+ export declare const BatchItemsList: <ItemType extends ListItemProps>({ items, title }: BatchItemsListProps<ItemType>) => React.JSX.Element;
@@ -0,0 +1,19 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React from 'react';
3
+ import ListItem from '@synerise/ds-list-item';
4
+ import * as S from '../Confirmation.styles';
5
+ import { ITEM_SIZE, MAX_ITEMS } from '../Confirmation.const';
6
+ export var BatchItemsList = function BatchItemsList(_ref) {
7
+ var items = _ref.items,
8
+ title = _ref.title;
9
+ return /*#__PURE__*/React.createElement(S.ConfirmationExtra, null, /*#__PURE__*/React.createElement(S.ConfirmationExtraTitle, {
10
+ level: 6
11
+ }, title), /*#__PURE__*/React.createElement(S.BatchItemsList, {
12
+ maxHeight: ITEM_SIZE * MAX_ITEMS,
13
+ absolute: true
14
+ }, items.map(function (item) {
15
+ return /*#__PURE__*/React.createElement(ListItem, _extends({
16
+ key: item.id
17
+ }, item));
18
+ })));
19
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { DecisionSectionProps } from '../Confirmation.types';
3
+ export declare const DecisionSection: ({ options, title }: DecisionSectionProps) => React.JSX.Element;
@@ -0,0 +1,15 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React from 'react';
3
+ import Radio from '@synerise/ds-radio';
4
+ import * as S from '../Confirmation.styles';
5
+ export var DecisionSection = function DecisionSection(_ref) {
6
+ var options = _ref.options,
7
+ title = _ref.title;
8
+ return /*#__PURE__*/React.createElement(S.ConfirmationExtra, null, /*#__PURE__*/React.createElement(S.ConfirmationExtraTitle, {
9
+ level: 6
10
+ }, title), /*#__PURE__*/React.createElement(S.DecisionOptions, null, /*#__PURE__*/React.createElement(Radio.Group, null, options.map(function (option) {
11
+ return /*#__PURE__*/React.createElement(Radio, _extends({
12
+ key: option.id
13
+ }, option));
14
+ }))));
15
+ };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { PromptProps } from '../Confirmation.types';
3
+ export declare const Prompt: ({ type, texts, onCancel, onOk, mainButtonProps, secondaryButtonProps, content, ...modalProps }: PromptProps) => React.JSX.Element;
@@ -0,0 +1,39 @@
1
+ var _excluded = ["type", "texts", "onCancel", "onOk", "mainButtonProps", "secondaryButtonProps", "content"];
2
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
4
+ import React, { useMemo } from 'react';
5
+ import Button from '@synerise/ds-button';
6
+ import Modal from '@synerise/ds-modal';
7
+ import * as S from '../Confirmation.styles';
8
+ import { BUTTON_COLOR_MAPPING } from '../Confirmation.const';
9
+ import { useDefaultTexts } from '../hooks/useDefaultTexts';
10
+ export var Prompt = function Prompt(_ref) {
11
+ var type = _ref.type,
12
+ texts = _ref.texts,
13
+ onCancel = _ref.onCancel,
14
+ onOk = _ref.onOk,
15
+ mainButtonProps = _ref.mainButtonProps,
16
+ secondaryButtonProps = _ref.secondaryButtonProps,
17
+ content = _ref.content,
18
+ modalProps = _objectWithoutPropertiesLoose(_ref, _excluded);
19
+ var allTexts = useDefaultTexts(texts);
20
+ var buttonColor = BUTTON_COLOR_MAPPING[type];
21
+ var modalFooter = useMemo(function () {
22
+ return /*#__PURE__*/React.createElement(S.Footer, null, /*#__PURE__*/React.createElement(S.FooterRight, null, /*#__PURE__*/React.createElement(Button, _extends({
23
+ type: "secondary",
24
+ onClick: onCancel
25
+ }, secondaryButtonProps), allTexts.secondaryButtonLabel), /*#__PURE__*/React.createElement(Button, _extends({
26
+ type: "custom-color",
27
+ onClick: onOk,
28
+ color: buttonColor
29
+ }, mainButtonProps), allTexts.mainButtonLabel)));
30
+ }, [buttonColor, onCancel, onOk, mainButtonProps, allTexts.mainButtonLabel, allTexts.secondaryButtonLabel, secondaryButtonProps]);
31
+ return /*#__PURE__*/React.createElement(Modal, _extends({}, modalProps, {
32
+ onCancel: onCancel,
33
+ size: "small",
34
+ footer: modalFooter,
35
+ bodyStyle: {
36
+ padding: 0
37
+ }
38
+ }), /*#__PURE__*/React.createElement(S.PromptContent, null, content));
39
+ };
@@ -0,0 +1,2 @@
1
+ import { ConfirmationTexts } from '../Confirmation.types';
2
+ export declare const useDefaultTexts: (defaultTexts?: Partial<ConfirmationTexts>) => ConfirmationTexts;
@@ -0,0 +1,31 @@
1
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
+ import React from 'react';
3
+ import { FormattedMessage } from 'react-intl';
4
+ export var useDefaultTexts = function useDefaultTexts(defaultTexts) {
5
+ return _extends({
6
+ mainButtonLabel: /*#__PURE__*/React.createElement(FormattedMessage, {
7
+ id: "DS.CONFIRMATION.MAIN-BUTTON-LABEL",
8
+ defaultMessage: "Ok"
9
+ }),
10
+ secondaryButtonLabel: /*#__PURE__*/React.createElement(FormattedMessage, {
11
+ id: "DS.CONFIRMATION.SECONDARY-BUTTON-LABEL",
12
+ defaultMessage: "Cancel"
13
+ }),
14
+ relatedObjectsButtonLabel: /*#__PURE__*/React.createElement(FormattedMessage, {
15
+ id: "DS.CONFIRMATION.RELATED-OBJECT-BUTTON-LABEL",
16
+ defaultMessage: "Show related objects"
17
+ }),
18
+ batchActionItemsTitle: /*#__PURE__*/React.createElement(FormattedMessage, {
19
+ id: "DS.CONFIRMATION.BATCH-ACTIONS-ITEMS-TITLE",
20
+ defaultMessage: "Objects to delete"
21
+ }),
22
+ decisionTitle: /*#__PURE__*/React.createElement(FormattedMessage, {
23
+ id: "DS.CONFIRMATION.DECISION-TITLE",
24
+ defaultMessage: "What do you want to do?"
25
+ }),
26
+ relatedObjectsTitle: /*#__PURE__*/React.createElement(FormattedMessage, {
27
+ id: "DS.CONFIRMATION.RELATED-OBJECTS-TITLE",
28
+ defaultMessage: "Related objects"
29
+ })
30
+ }, defaultTexts || {});
31
+ };
@@ -0,0 +1,3 @@
1
+ export { default } from './Confirmation';
2
+ export type { ConfirmationProps, PromptProps, ConfirmationTexts } from './Confirmation.types';
3
+ export { Prompt } from './components/Prompt';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default } from './Confirmation';
2
+ export { Prompt } from './components/Prompt';
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom';
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@synerise/ds-confirmation",
3
+ "version": "1.1.0",
4
+ "description": "Confirmation UI Component for the Synerise Design System",
5
+ "license": "ISC",
6
+ "repository": "Synerise/synerise-design",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist",
10
+ "CHANGELOG.md",
11
+ "README.md",
12
+ "package.json",
13
+ "LICENSE.md"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "scripts": {
19
+ "build": "npm run build:js && npm run build:css && npm run defs",
20
+ "build:css": "node ../../../scripts/style/less.js",
21
+ "build:js": "babel --delete-dir-on-start --root-mode upward src --out-dir dist --extensions '.js,.ts,.tsx'",
22
+ "build:watch": "npm run build:js -- --watch",
23
+ "defs": "tsc --declaration --outDir dist/ --emitDeclarationOnly",
24
+ "pack:ci": "npm pack --pack-destination ../../storybook/storybook-static/static",
25
+ "prepublish": "npm run build",
26
+ "test": "jest",
27
+ "test:watch": "npm run test -- --watchAll",
28
+ "types": "tsc --noEmit",
29
+ "upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
30
+ },
31
+ "sideEffects": [
32
+ "dist/style/*",
33
+ "*.less"
34
+ ],
35
+ "types": "dist/index.d.ts",
36
+ "dependencies": {
37
+ "@synerise/ds-button": "^1.3.0",
38
+ "@synerise/ds-icon": "^1.5.0",
39
+ "@synerise/ds-list-item": "^1.0.8",
40
+ "@synerise/ds-modal": "^1.1.0",
41
+ "@synerise/ds-radio": "^1.0.8",
42
+ "@synerise/ds-scrollbar": "^1.0.8",
43
+ "@synerise/ds-typography": "^1.0.8",
44
+ "@synerise/ds-utils": "^1.1.0"
45
+ },
46
+ "peerDependencies": {
47
+ "@synerise/ds-core": "*",
48
+ "react": ">=16.9.0 <= 18.3.1",
49
+ "react-intl": "^6.8.7",
50
+ "styled-components": "^5.3.3"
51
+ },
52
+ "gitHead": "8aa16b27c86c97e3ac774d92561ab0a03176c439"
53
+ }