@pega/cosmos-react-demos 4.0.0-dev.5.0 → 4.0.0-dev.6.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/jsx/build/FlowModeller/FlowModeller.mocks.d.ts.map +1 -1
- package/jsx/build/FlowModeller/FlowModeller.mocks.jsx +2 -17
- package/jsx/build/FlowModeller/FlowModeller.mocks.jsx.map +1 -1
- package/jsx/build/ObjectSelect/ObjectSelect.mocks.d.ts +3 -2
- package/jsx/build/ObjectSelect/ObjectSelect.mocks.d.ts.map +1 -1
- package/jsx/build/ObjectSelect/ObjectSelect.mocks.jsx.map +1 -1
- package/jsx/build/PageTemplates/PageTemplates.stories.jsx.map +1 -1
- package/jsx/core/Backdrop/Backdrop.stories.d.ts.map +1 -1
- package/jsx/core/Backdrop/Backdrop.stories.jsx +12 -12
- package/jsx/core/Backdrop/Backdrop.stories.jsx.map +1 -1
- package/jsx/core/Badges/Count.stories.jsx +1 -1
- package/jsx/core/Badges/Count.stories.jsx.map +1 -1
- package/jsx/core/Dialog/Dialog.mocks.d.ts +26 -0
- package/jsx/core/Dialog/Dialog.mocks.d.ts.map +1 -0
- package/jsx/core/Dialog/Dialog.mocks.jsx +136 -0
- package/jsx/core/Dialog/Dialog.mocks.jsx.map +1 -0
- package/jsx/core/Dialog/Dialog.stories.d.ts +1 -1
- package/jsx/core/Dialog/Dialog.stories.d.ts.map +1 -1
- package/jsx/core/Dialog/Dialog.stories.jsx +78 -69
- package/jsx/core/Dialog/Dialog.stories.jsx.map +1 -1
- package/jsx/cs/CSAppShell/CSAppShell.mocks.d.ts +16 -0
- package/jsx/cs/CSAppShell/CSAppShell.mocks.d.ts.map +1 -1
- package/jsx/cs/CSAppShell/CSAppShell.mocks.jsx +92 -2
- package/jsx/cs/CSAppShell/CSAppShell.mocks.jsx.map +1 -1
- package/jsx/cs/CSAppShell/CSAppShell.stories.d.ts.map +1 -1
- package/jsx/cs/CSAppShell/CSAppShell.stories.jsx +3 -33
- package/jsx/cs/CSAppShell/CSAppShell.stories.jsx.map +1 -1
- package/jsx/cs/InteractionNotification/InteractionNotification.stories.d.ts +3 -1
- package/jsx/cs/InteractionNotification/InteractionNotification.stories.d.ts.map +1 -1
- package/jsx/cs/InteractionNotification/InteractionNotification.stories.jsx +18 -4
- package/jsx/cs/InteractionNotification/InteractionNotification.stories.jsx.map +1 -1
- package/jsx/work/CaseView/CaseView.mocks.d.ts +2 -14
- package/jsx/work/CaseView/CaseView.mocks.d.ts.map +1 -1
- package/jsx/work/CaseView/CaseView.mocks.jsx +23 -11
- package/jsx/work/CaseView/CaseView.mocks.jsx.map +1 -1
- package/jsx/work/SearchResults/SearchResults.stories.d.ts.map +1 -1
- package/jsx/work/SearchResults/SearchResults.stories.jsx +21 -2
- package/jsx/work/SearchResults/SearchResults.stories.jsx.map +1 -1
- package/jsx/wss/CaseView/CaseView.stories.jsx +1 -1
- package/jsx/wss/CaseView/CaseView.stories.jsx.map +1 -1
- package/lib/build/FlowModeller/FlowModeller.mocks.d.ts.map +1 -1
- package/lib/build/FlowModeller/FlowModeller.mocks.js +2 -17
- package/lib/build/FlowModeller/FlowModeller.mocks.js.map +1 -1
- package/lib/build/ObjectSelect/ObjectSelect.mocks.d.ts +3 -2
- package/lib/build/ObjectSelect/ObjectSelect.mocks.d.ts.map +1 -1
- package/lib/build/ObjectSelect/ObjectSelect.mocks.js.map +1 -1
- package/lib/build/PageTemplates/PageTemplates.stories.js.map +1 -1
- package/lib/core/Backdrop/Backdrop.stories.d.ts.map +1 -1
- package/lib/core/Backdrop/Backdrop.stories.js +2 -2
- package/lib/core/Backdrop/Backdrop.stories.js.map +1 -1
- package/lib/core/Badges/Count.stories.js +1 -1
- package/lib/core/Badges/Count.stories.js.map +1 -1
- package/lib/core/Dialog/Dialog.mocks.d.ts +26 -0
- package/lib/core/Dialog/Dialog.mocks.d.ts.map +1 -0
- package/lib/core/Dialog/Dialog.mocks.js +132 -0
- package/lib/core/Dialog/Dialog.mocks.js.map +1 -0
- package/lib/core/Dialog/Dialog.stories.d.ts +1 -1
- package/lib/core/Dialog/Dialog.stories.d.ts.map +1 -1
- package/lib/core/Dialog/Dialog.stories.js +65 -41
- package/lib/core/Dialog/Dialog.stories.js.map +1 -1
- package/lib/cs/CSAppShell/CSAppShell.mocks.d.ts +16 -0
- package/lib/cs/CSAppShell/CSAppShell.mocks.d.ts.map +1 -1
- package/lib/cs/CSAppShell/CSAppShell.mocks.js +71 -2
- package/lib/cs/CSAppShell/CSAppShell.mocks.js.map +1 -1
- package/lib/cs/CSAppShell/CSAppShell.stories.d.ts.map +1 -1
- package/lib/cs/CSAppShell/CSAppShell.stories.js +4 -17
- package/lib/cs/CSAppShell/CSAppShell.stories.js.map +1 -1
- package/lib/cs/InteractionNotification/InteractionNotification.stories.d.ts +3 -1
- package/lib/cs/InteractionNotification/InteractionNotification.stories.d.ts.map +1 -1
- package/lib/cs/InteractionNotification/InteractionNotification.stories.js +18 -4
- package/lib/cs/InteractionNotification/InteractionNotification.stories.js.map +1 -1
- package/lib/work/CaseView/CaseView.mocks.d.ts +2 -14
- package/lib/work/CaseView/CaseView.mocks.d.ts.map +1 -1
- package/lib/work/CaseView/CaseView.mocks.js +23 -11
- package/lib/work/CaseView/CaseView.mocks.js.map +1 -1
- package/lib/work/SearchResults/SearchResults.stories.d.ts.map +1 -1
- package/lib/work/SearchResults/SearchResults.stories.js +21 -2
- package/lib/work/SearchResults/SearchResults.stories.js.map +1 -1
- package/lib/wss/CaseView/CaseView.stories.js +1 -1
- package/lib/wss/CaseView/CaseView.stories.js.map +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { useEffect, useReducer, useState } from 'react';
|
|
2
|
+
import { ComboBox, createUID, Flex, FormDialog, Input } from '@pega/cosmos-react-core';
|
|
3
|
+
const errorText = 'Cannot be blank';
|
|
4
|
+
const categories = Array.from({ length: 5 }, (_, i) => `Category ${i + 1}`);
|
|
5
|
+
const initialItems = Array.from({ length: 3 }, (_, i) => {
|
|
6
|
+
return {
|
|
7
|
+
id: createUID(),
|
|
8
|
+
name: `Editable item ${i + 1}`,
|
|
9
|
+
category: categories[i]
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
const itemReducer = (items, payload) => {
|
|
13
|
+
switch (payload.type) {
|
|
14
|
+
case 'add': {
|
|
15
|
+
return [...items, { ...payload.item, id: createUID() }];
|
|
16
|
+
}
|
|
17
|
+
case 'edit': {
|
|
18
|
+
return items.map(item => {
|
|
19
|
+
return item.id === payload.item.id
|
|
20
|
+
? { ...item, name: payload.item.name, category: payload.item.category }
|
|
21
|
+
: item;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
case 'remove': {
|
|
25
|
+
const itemIndex = items.findIndex(item => item.id === payload.item.id);
|
|
26
|
+
if (itemIndex === -1)
|
|
27
|
+
return items;
|
|
28
|
+
items.splice(itemIndex, 1);
|
|
29
|
+
return [...items];
|
|
30
|
+
}
|
|
31
|
+
default: {
|
|
32
|
+
return items;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const progressStates = {
|
|
37
|
+
loading: 'Loading...',
|
|
38
|
+
submitting: 'Submitting...'
|
|
39
|
+
};
|
|
40
|
+
export const useMockItems = () => {
|
|
41
|
+
return useReducer(itemReducer, undefined, () => initialItems);
|
|
42
|
+
};
|
|
43
|
+
export const ItemDialog = ({ target, item: itemProp, dispatch, onComplete }) => {
|
|
44
|
+
const [nameField, setNameField] = useState(() => {
|
|
45
|
+
return {
|
|
46
|
+
value: itemProp?.name ?? null,
|
|
47
|
+
error: null,
|
|
48
|
+
errorOnPriorBlur: false
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
const [categoryField, setCategoryField] = useState(() => {
|
|
52
|
+
return {
|
|
53
|
+
value: itemProp?.category ?? null,
|
|
54
|
+
error: null
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
const [progress, setProgress] = useState(progressStates.loading);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
let timerId;
|
|
60
|
+
if (progress === progressStates.loading) {
|
|
61
|
+
timerId = window.setTimeout(() => {
|
|
62
|
+
setProgress(false);
|
|
63
|
+
}, 1000);
|
|
64
|
+
}
|
|
65
|
+
else if (progress === progressStates.submitting) {
|
|
66
|
+
timerId = window.setTimeout(() => {
|
|
67
|
+
setProgress(false);
|
|
68
|
+
dispatch({ name: nameField.value, category: categoryField.value });
|
|
69
|
+
onComplete();
|
|
70
|
+
}, 2000);
|
|
71
|
+
}
|
|
72
|
+
return () => {
|
|
73
|
+
window.clearTimeout(timerId);
|
|
74
|
+
};
|
|
75
|
+
}, [progress]);
|
|
76
|
+
return (<FormDialog target={target} heading={`${itemProp ? 'Edit' : 'Add'} item`} progress={progress} onCancel={{
|
|
77
|
+
handler: () => {
|
|
78
|
+
setProgress(false);
|
|
79
|
+
onComplete();
|
|
80
|
+
}
|
|
81
|
+
}} onSubmit={{
|
|
82
|
+
disabled: !!progress || [nameField, categoryField].some(field => !field.value || field.error),
|
|
83
|
+
handler: () => {
|
|
84
|
+
setProgress(progressStates.submitting);
|
|
85
|
+
}
|
|
86
|
+
}}>
|
|
87
|
+
{(!progress || progress !== progressStates.loading) && (<Flex container={{ direction: 'column', gap: 2 }}>
|
|
88
|
+
<Input required label='Name' value={nameField.value ?? ''} onChange={(e) => {
|
|
89
|
+
setNameField(cur => ({
|
|
90
|
+
...cur,
|
|
91
|
+
value: e.target.value,
|
|
92
|
+
error: !e.target.value && cur.errorOnPriorBlur ? errorText : null
|
|
93
|
+
}));
|
|
94
|
+
}} onBlur={(e) => {
|
|
95
|
+
if (!e.target.value) {
|
|
96
|
+
setNameField(cur => ({
|
|
97
|
+
...cur,
|
|
98
|
+
error: errorText,
|
|
99
|
+
errorOnPriorBlur: true
|
|
100
|
+
}));
|
|
101
|
+
}
|
|
102
|
+
else if (nameField.errorOnPriorBlur) {
|
|
103
|
+
setNameField(cur => ({ ...cur, errorOnPriorBlur: false }));
|
|
104
|
+
}
|
|
105
|
+
}} status={nameField.error ? 'error' : undefined} info={nameField.error}/>
|
|
106
|
+
<ComboBox required label='Category' selected={categoryField.value
|
|
107
|
+
? {
|
|
108
|
+
items: {
|
|
109
|
+
id: categoryField.value,
|
|
110
|
+
text: categoryField.value
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
: undefined} menu={{
|
|
114
|
+
mode: 'single-select',
|
|
115
|
+
onItemClick: category => {
|
|
116
|
+
setCategoryField({
|
|
117
|
+
value: category,
|
|
118
|
+
error: null
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
items: categories.map(category => {
|
|
122
|
+
return {
|
|
123
|
+
id: category,
|
|
124
|
+
primary: category,
|
|
125
|
+
selected: category === categoryField.value
|
|
126
|
+
};
|
|
127
|
+
})
|
|
128
|
+
}} onBlur={selected => {
|
|
129
|
+
if (!selected) {
|
|
130
|
+
setCategoryField(cur => ({ ...cur, error: errorText }));
|
|
131
|
+
}
|
|
132
|
+
}} status={categoryField.error ? 'error' : undefined} info={categoryField.error}/>
|
|
133
|
+
</Flex>)}
|
|
134
|
+
</FormDialog>);
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=Dialog.mocks.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dialog.mocks.jsx","sourceRoot":"","sources":["../../../src/core/Dialog/Dialog.mocks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA2B,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjF,OAAO,EACL,QAAQ,EACR,SAAS,EACT,IAAI,EACJ,UAAU,EAEV,KAAK,EACN,MAAM,yBAAyB,CAAC;AA8BjC,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAEpC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAgB,EAAE,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AAE,EAAE,aAAa,CAAC,KAAK;wBACvB,IAAI,EAAE,aAAa,CAAC,KAAK;qBAC1B;iBACF;gBACH,CAAC,CAAC,SAAS,CACd,CACD,IAAI,CAAC,CAAC;gBACJ,IAAI,EAAE,eAAe;gBACrB,WAAW,EAAE,QAAQ,CAAC,EAAE;oBACtB,gBAAgB,CAAC;wBACf,KAAK,EAAE,QAAwB;wBAC/B,KAAK,EAAE,IAAI;qBACZ,CAAC,CAAC;gBACL,CAAC;gBACD,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE;oBAC/B,OAAO;wBACL,EAAE,EAAE,QAAQ;wBACZ,OAAO,EAAE,QAAQ;wBACjB,QAAQ,EAAE,QAAQ,KAAK,aAAa,CAAC,KAAK;qBAC3C,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC,CACF,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE;gBACjB,IAAI,CAAC,QAAQ,EAAE;oBACb,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;iBACzD;YACH,CAAC,CAAC,CACF,MAAM,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAClD,IAAI,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,EAE9B;QAAA,EAAE,IAAI,CAAC,CACR,CACH;IAAA,EAAE,UAAU,CAAC,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { ChangeEvent, FocusEvent, useEffect, useReducer, useState } from 'react';\n\nimport {\n ComboBox,\n createUID,\n Flex,\n FormDialog,\n FormDialogProps,\n Input\n} from '@pega/cosmos-react-core';\n\nexport type MockCategory = `Category ${number}`;\n\nexport interface MockItem {\n readonly id: string;\n name: string;\n category: MockCategory;\n}\n\nexport type MockReducerPayload =\n | {\n type: 'add';\n item: Pick<MockItem, 'name' | 'category'>;\n }\n | {\n type: 'edit';\n item: MockItem;\n }\n | {\n type: 'remove';\n item: Pick<MockItem, 'id'>;\n };\n\nexport interface MockItemDialogProps extends Pick<FormDialogProps, 'target'> {\n item: MockItem | null;\n dispatch: (fieldValues: Pick<MockItem, 'name' | 'category'>) => void;\n onComplete: () => void;\n}\n\nconst errorText = 'Cannot be blank';\n\nconst categories = Array.from({ length: 5 }, (_, i): MockCategory => `Category ${i + 1}`);\n\nconst initialItems: MockItem[] = Array.from({ length: 3 }, (_, i) => {\n return {\n id: createUID(),\n name: `Editable item ${i + 1}`,\n category: categories[i]\n };\n});\n\nconst itemReducer = (items: MockItem[], payload: MockReducerPayload) => {\n switch (payload.type) {\n case 'add': {\n return [...items, { ...payload.item, id: createUID() }];\n }\n\n case 'edit': {\n return items.map(item => {\n return item.id === payload.item.id\n ? { ...item, name: payload.item.name, category: payload.item.category }\n : item;\n });\n }\n\n case 'remove': {\n const itemIndex = items.findIndex(item => item.id === payload.item.id);\n if (itemIndex === -1) return items;\n items.splice(itemIndex, 1);\n return [...items];\n }\n\n default: {\n return items;\n }\n }\n};\n\nconst progressStates = {\n loading: 'Loading...',\n submitting: 'Submitting...'\n} as const;\n\nexport const useMockItems = () => {\n return useReducer(itemReducer, undefined, () => initialItems);\n};\n\nexport const ItemDialog = ({\n target,\n item: itemProp,\n dispatch,\n onComplete\n}: MockItemDialogProps) => {\n const [nameField, setNameField] = useState<{\n value: string | null;\n error: typeof errorText | null;\n errorOnPriorBlur: boolean;\n }>(() => {\n return {\n value: itemProp?.name ?? null,\n error: null,\n errorOnPriorBlur: false\n };\n });\n\n const [categoryField, setCategoryField] = useState<{\n value: MockCategory | null;\n error: typeof errorText | null;\n }>(() => {\n return {\n value: itemProp?.category ?? null,\n error: null\n };\n });\n\n const [progress, setProgress] = useState<\n typeof progressStates[keyof typeof progressStates] | false\n >(progressStates.loading);\n\n useEffect(() => {\n let timerId: number;\n\n if (progress === progressStates.loading) {\n timerId = window.setTimeout(() => {\n setProgress(false);\n }, 1000);\n } else if (progress === progressStates.submitting) {\n timerId = window.setTimeout(() => {\n setProgress(false);\n dispatch({ name: nameField.value!, category: categoryField.value! });\n onComplete();\n }, 2000);\n }\n\n return () => {\n window.clearTimeout(timerId);\n };\n }, [progress]);\n\n return (\n <FormDialog\n target={target}\n heading={`${itemProp ? 'Edit' : 'Add'} item`}\n progress={progress}\n onCancel={{\n handler: () => {\n setProgress(false);\n onComplete();\n }\n }}\n onSubmit={{\n disabled:\n !!progress || [nameField, categoryField].some(field => !field.value || field.error),\n handler: () => {\n setProgress(progressStates.submitting);\n }\n }}\n >\n {(!progress || progress !== progressStates.loading) && (\n <Flex container={{ direction: 'column', gap: 2 }}>\n <Input\n required\n label='Name'\n value={nameField.value ?? ''}\n onChange={(e: ChangeEvent<HTMLInputElement>) => {\n setNameField(cur => ({\n ...cur,\n value: e.target.value,\n error: !e.target.value && cur.errorOnPriorBlur ? errorText : null\n }));\n }}\n onBlur={(e: FocusEvent<HTMLInputElement>) => {\n if (!e.target.value) {\n setNameField(cur => ({\n ...cur,\n error: errorText,\n errorOnPriorBlur: true\n }));\n } else if (nameField.errorOnPriorBlur) {\n setNameField(cur => ({ ...cur, errorOnPriorBlur: false }));\n }\n }}\n status={nameField.error ? 'error' : undefined}\n info={nameField.error}\n />\n <ComboBox\n required\n label='Category'\n selected={\n categoryField.value\n ? {\n items: {\n id: categoryField.value,\n text: categoryField.value\n }\n }\n : undefined\n }\n menu={{\n mode: 'single-select',\n onItemClick: category => {\n setCategoryField({\n value: category as MockCategory,\n error: null\n });\n },\n items: categories.map(category => {\n return {\n id: category,\n primary: category,\n selected: category === categoryField.value\n };\n })\n }}\n onBlur={selected => {\n if (!selected) {\n setCategoryField(cur => ({ ...cur, error: errorText }));\n }\n }}\n status={categoryField.error ? 'error' : undefined}\n info={categoryField.error}\n />\n </Flex>\n )}\n </FormDialog>\n );\n};\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Meta, Story } from '@storybook/react';
|
|
2
2
|
declare const _default: Meta<import("@storybook/react").Args>;
|
|
3
3
|
export default _default;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const InfoDialogDemo: Story;
|
|
5
5
|
export declare const FormDialogDemo: Story;
|
|
6
6
|
//# sourceMappingURL=Dialog.stories.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.stories.d.ts","sourceRoot":"","sources":["../../../src/core/Dialog/Dialog.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;;
|
|
1
|
+
{"version":3,"file":"Dialog.stories.d.ts","sourceRoot":"","sources":["../../../src/core/Dialog/Dialog.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;;AAiB/C,wBAEU;AAGV,eAAO,MAAM,cAAc,EAAE,KA+B5B,CAAC;AAGF,eAAO,MAAM,cAAc,EAAE,KA0E5B,CAAC"}
|
|
@@ -1,79 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Button, Flex, Text, useElement, InfoDialog, SummaryList } from '@pega/cosmos-react-core';
|
|
3
|
+
import { FieldValueListDemo } from '../FieldValueList/FieldValueList.stories';
|
|
4
|
+
import { ItemDialog, useMockItems } from './Dialog.mocks';
|
|
4
5
|
export default {
|
|
5
|
-
title: 'Core/Dialog'
|
|
6
|
-
component: Dialog
|
|
6
|
+
title: 'Core/Dialog'
|
|
7
7
|
};
|
|
8
|
-
export const
|
|
9
|
-
const
|
|
8
|
+
export const InfoDialogDemo = () => {
|
|
9
|
+
const [target, setTarget] = useElement(null);
|
|
10
10
|
return (<>
|
|
11
|
-
<Button variant='secondary' {
|
|
11
|
+
<Button variant='secondary' onClick={(e) => {
|
|
12
|
+
setTarget(e.currentTarget);
|
|
13
|
+
}}>
|
|
12
14
|
Open dialog
|
|
13
15
|
</Button>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
{target && (<InfoDialog heading='General information' target={target} onDismiss={() => setTarget(null)}>
|
|
18
|
+
<Flex container={{ direction: 'column', gap: 2 }}>
|
|
19
|
+
<Text as='p'>
|
|
20
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
|
|
21
|
+
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
|
|
22
|
+
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
|
|
23
|
+
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
|
|
24
|
+
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
|
|
25
|
+
mollit anim id est laborum.
|
|
26
|
+
</Text>
|
|
27
|
+
<FieldValueListDemo name='Demo field' value='demo value'/>
|
|
28
|
+
</Flex>
|
|
29
|
+
</InfoDialog>)}
|
|
17
30
|
</>);
|
|
18
31
|
};
|
|
19
32
|
export const FormDialogDemo = () => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
</Flex>
|
|
75
|
-
</Dialog>
|
|
76
|
-
</CardContent>
|
|
77
|
-
</Card>);
|
|
33
|
+
const [dialogTarget, setDialogTarget] = useState(null);
|
|
34
|
+
const [editItem, setEditItem] = useState(null);
|
|
35
|
+
const [items, dispatch] = useMockItems();
|
|
36
|
+
return (<>
|
|
37
|
+
<SummaryList name='Editable items' icon='list' count={items.length} actions={[
|
|
38
|
+
{
|
|
39
|
+
id: 'Add',
|
|
40
|
+
text: 'Add',
|
|
41
|
+
icon: 'plus',
|
|
42
|
+
onClick: (_, e) => {
|
|
43
|
+
setDialogTarget(e.currentTarget);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]} items={items.map(({ id, name, category }) => {
|
|
47
|
+
return {
|
|
48
|
+
id,
|
|
49
|
+
primary: name,
|
|
50
|
+
secondary: <Text variant='secondary'>{category}</Text>,
|
|
51
|
+
actions: [
|
|
52
|
+
{
|
|
53
|
+
id: 'Edit',
|
|
54
|
+
text: 'Edit',
|
|
55
|
+
icon: 'pencil',
|
|
56
|
+
onClick: (_, e, menuButton) => {
|
|
57
|
+
if (menuButton)
|
|
58
|
+
setDialogTarget(menuButton);
|
|
59
|
+
setEditItem({
|
|
60
|
+
id,
|
|
61
|
+
name,
|
|
62
|
+
category
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'Remove',
|
|
68
|
+
text: 'Remove',
|
|
69
|
+
icon: 'trash',
|
|
70
|
+
onClick: () => {
|
|
71
|
+
dispatch({ type: 'remove', item: { id } });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
};
|
|
76
|
+
})}/>
|
|
77
|
+
|
|
78
|
+
{dialogTarget && (<ItemDialog target={dialogTarget} item={editItem} dispatch={fields => {
|
|
79
|
+
dispatch(editItem
|
|
80
|
+
? { type: 'edit', item: { id: editItem.id, ...fields } }
|
|
81
|
+
: { type: 'add', item: { ...fields } });
|
|
82
|
+
}} onComplete={() => {
|
|
83
|
+
setDialogTarget(null);
|
|
84
|
+
setEditItem(null);
|
|
85
|
+
}}/>)}
|
|
86
|
+
</>);
|
|
78
87
|
};
|
|
79
88
|
//# sourceMappingURL=Dialog.stories.jsx.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.stories.jsx","sourceRoot":"","sources":["../../../src/core/Dialog/Dialog.stories.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"Dialog.stories.jsx","sourceRoot":"","sources":["../../../src/core/Dialog/Dialog.stories.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EACL,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,UAAU,EACV,WAAW,EAEZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAE9E,OAAO,EAAE,UAAU,EAAiC,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEzF,eAAe;IACb,KAAK,EAAE,aAAa;CACb,CAAC;AAGV,MAAM,CAAC,MAAM,cAAc,GAAU,GAAG,EAAE;IACxC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,UAAU,CAAoB,IAAI,CAAC,CAAC;IAEhE,OAAO,CACL,EACE;MAAA,CAAC,MAAM,CACL,OAAO,CAAC,WAAW,CACnB,OAAO,CAAC,CAAC,CAAC,CAAgC,EAAE,EAAE;YAC5C,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;QAC7B,CAAC,CAAC,CAEF;;MACF,EAAE,MAAM,CAER;;MAAA,CAAC,MAAM,IAAI,CACT,CAA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C,CAAC,GAAG,EAAE;gBACf,eAAe,CAAC,IAAI,CAAC,CAAC;gBACtB,WAAW,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC,CAAC,EACF,CACH,CACH;IAAA,GAAG,CACJ,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Meta, Story } from '@storybook/react';\nimport { MouseEvent, useState } from 'react';\n\nimport {\n Button,\n Flex,\n Text,\n useElement,\n InfoDialog,\n SummaryList,\n SummaryListItem\n} from '@pega/cosmos-react-core';\n\nimport { FieldValueListDemo } from '../FieldValueList/FieldValueList.stories';\n\nimport { ItemDialog, MockItem, MockItemDialogProps, useMockItems } from './Dialog.mocks';\n\nexport default {\n title: 'Core/Dialog'\n} as Meta;\n\n// InfoDialogDemo\nexport const InfoDialogDemo: Story = () => {\n const [target, setTarget] = useElement<HTMLButtonElement>(null);\n\n return (\n <>\n <Button\n variant='secondary'\n onClick={(e: MouseEvent<HTMLButtonElement>) => {\n setTarget(e.currentTarget);\n }}\n >\n Open dialog\n </Button>\n\n {target && (\n <InfoDialog heading='General information' target={target} onDismiss={() => setTarget(null)}>\n <Flex container={{ direction: 'column', gap: 2 }}>\n <Text as='p'>\n Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor\n incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud\n exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure\n dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt\n mollit anim id est laborum.\n </Text>\n <FieldValueListDemo name='Demo field' value='demo value' />\n </Flex>\n </InfoDialog>\n )}\n </>\n );\n};\n\n// FormDialogDemo\nexport const FormDialogDemo: Story = () => {\n const [dialogTarget, setDialogTarget] = useState<MockItemDialogProps['target'] | null>(null);\n const [editItem, setEditItem] = useState<MockItem | null>(null);\n const [items, dispatch] = useMockItems();\n\n return (\n <>\n <SummaryList\n name='Editable items'\n icon='list'\n count={items.length}\n actions={[\n {\n id: 'Add',\n text: 'Add',\n icon: 'plus',\n onClick: (_, e) => {\n setDialogTarget(e.currentTarget);\n }\n }\n ]}\n items={items.map<SummaryListItem>(({ id, name, category }) => {\n return {\n id,\n primary: name,\n secondary: <Text variant='secondary'>{category}</Text>,\n actions: [\n {\n id: 'Edit',\n text: 'Edit',\n icon: 'pencil',\n onClick: (_, e, menuButton) => {\n if (menuButton) setDialogTarget(menuButton);\n\n setEditItem({\n id,\n name,\n category\n });\n }\n },\n {\n id: 'Remove',\n text: 'Remove',\n icon: 'trash',\n onClick: () => {\n dispatch({ type: 'remove', item: { id } });\n }\n }\n ]\n };\n })}\n />\n\n {dialogTarget && (\n <ItemDialog\n target={dialogTarget}\n item={editItem}\n // Wrap dispatch so the dialog can only affect the item it creates or updates.\n dispatch={fields => {\n dispatch(\n editItem\n ? { type: 'edit', item: { id: editItem.id, ...fields } }\n : { type: 'add', item: { ...fields } }\n );\n }}\n onComplete={() => {\n setDialogTarget(null);\n setEditItem(null);\n }}\n />\n )}\n </>\n );\n};\n"]}
|
|
@@ -70,4 +70,20 @@ export declare const AppShellMockData: {
|
|
|
70
70
|
}[];
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
+
export declare const statuses: ({
|
|
74
|
+
id: string;
|
|
75
|
+
primary: string;
|
|
76
|
+
selected: boolean;
|
|
77
|
+
items?: undefined;
|
|
78
|
+
} | {
|
|
79
|
+
id: string;
|
|
80
|
+
primary: string;
|
|
81
|
+
items: {
|
|
82
|
+
id: string;
|
|
83
|
+
primary: string;
|
|
84
|
+
selected: boolean;
|
|
85
|
+
}[];
|
|
86
|
+
selected?: undefined;
|
|
87
|
+
})[];
|
|
88
|
+
export declare const ChatSettingsPanelMock: FunctionComponent;
|
|
73
89
|
//# sourceMappingURL=CSAppShell.mocks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CSAppShell.mocks.d.ts","sourceRoot":"","sources":["../../../src/cs/CSAppShell/CSAppShell.mocks.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"CSAppShell.mocks.d.ts","sourceRoot":"","sources":["../../../src/cs/CSAppShell/CSAppShell.mocks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AA4Bf,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC1C,OAAO,EAAE,CACP,SAAS,EAAE,MAAM,cAAc,CAAC,gBAAgB,CAAC,EACjD,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,KACb,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;IACrC,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,cAAc,CAiE3D,CAAC;AAEF,eAAO,MAAM,sBAAsB;UAC3B,UAAU,GAAG,UAAU;;qBAEZ,OAAO;EAKxB,CAAC;AAEH,eAAO,MAAM,eAAe,EAAE,iBAmE7B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmO5B,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;IAYpB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,iBA2HnC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createContext, useContext, useState } from 'react';
|
|
2
|
-
import { AppShellDrawerContext, Banner, Button, Flex, Form, Input, Option, Select } from '@pega/cosmos-react-core';
|
|
1
|
+
import { createContext, useCallback, useContext, useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import { AppShellDrawerContext, Banner, Button, Flex, Form, Input, Option, Select, menuHelpers, CheckboxGroup, Checkbox, ComboBox } from '@pega/cosmos-react-core';
|
|
3
3
|
import { CTIPanel } from '@pega/cosmos-react-cs';
|
|
4
|
+
import ChatSettingsPanel from '@pega/cosmos-react-social/lib/components/Chat/ChatSettingsPanel';
|
|
4
5
|
import { userStatusOptions } from '../CallControlPanel/CallControlPanel.mocks';
|
|
5
6
|
import { CallControlPanelDemo, ExternalCTIDemo } from '../CallControlPanel/CallControlPanel.stories';
|
|
6
7
|
export const CallLoginForm = ({ ctiLinkOptions, onLogin, onCancel }) => {
|
|
@@ -296,4 +297,93 @@ export const AppShellMockData = {
|
|
|
296
297
|
]
|
|
297
298
|
}
|
|
298
299
|
};
|
|
300
|
+
export const statuses = [
|
|
301
|
+
{ id: 'available', primary: 'Available', selected: false },
|
|
302
|
+
{
|
|
303
|
+
id: 'temporarilyUnavailable',
|
|
304
|
+
primary: 'Temporarily unavailable',
|
|
305
|
+
items: [
|
|
306
|
+
{ id: 'quick_break', primary: 'Quick break', selected: false },
|
|
307
|
+
{ id: 'personal_work', primary: 'Personal work', selected: false },
|
|
308
|
+
{ id: 'in_a_meeting', primary: 'In a meeting', selected: false }
|
|
309
|
+
]
|
|
310
|
+
},
|
|
311
|
+
{ id: 'unavailable', primary: 'Unavailable', selected: false }
|
|
312
|
+
];
|
|
313
|
+
export const ChatSettingsPanelMock = () => {
|
|
314
|
+
const { openDrawer, closeDrawer } = useContext(AppShellDrawerContext);
|
|
315
|
+
const [chatAlias, setChatAlias] = useState('');
|
|
316
|
+
const [queues, setQueues] = useState([
|
|
317
|
+
{ id: 'Billing', checked: false },
|
|
318
|
+
{ id: 'General', checked: false },
|
|
319
|
+
{ id: 'Technical', checked: false }
|
|
320
|
+
]);
|
|
321
|
+
const [items, setItems] = useState(() => {
|
|
322
|
+
return menuHelpers.mapTree(statuses, item => ({
|
|
323
|
+
...item,
|
|
324
|
+
selected: item.items ? undefined : !!item.selected
|
|
325
|
+
}));
|
|
326
|
+
});
|
|
327
|
+
const selected = useMemo(() => menuHelpers.getSelected(items)[0], [items]);
|
|
328
|
+
const selectItem = useCallback((id) => {
|
|
329
|
+
setItems(cur => menuHelpers.selectItem(cur, id, 'single-select'));
|
|
330
|
+
}, []);
|
|
331
|
+
const formActions = (<>
|
|
332
|
+
<Button name='Cancel' variant='secondary' onClick={closeDrawer}>
|
|
333
|
+
Cancel
|
|
334
|
+
</Button>
|
|
335
|
+
<Button name='Submit' variant='primary' onClick={closeDrawer}>
|
|
336
|
+
Submit
|
|
337
|
+
</Button>
|
|
338
|
+
</>);
|
|
339
|
+
const chatSettings = useMemo(() => (<Flex container={{ direction: 'column', gap: 2, pad: 2 }} item={{ grow: 1 }}>
|
|
340
|
+
<Form actions={formActions}>
|
|
341
|
+
<Flex container={{ direction: 'column', pad: 0.5 }}>
|
|
342
|
+
<Input label='Chat alias' value={chatAlias} onChange={(e) => {
|
|
343
|
+
setChatAlias(e.target.value);
|
|
344
|
+
}}/>
|
|
345
|
+
</Flex>
|
|
346
|
+
<Flex container={{ direction: 'column', pad: 1 }}>
|
|
347
|
+
<CheckboxGroup label='Joined queues' name='queueslist' labelHidden={false}>
|
|
348
|
+
{queues.map(({ id, checked }) => (<Checkbox label={id} id={id} name={id} checked={checked} onChange={e => setQueues(queues.map(queue => {
|
|
349
|
+
if (queue.id === id) {
|
|
350
|
+
return {
|
|
351
|
+
...queue,
|
|
352
|
+
checked: e.target.checked
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
return queue;
|
|
356
|
+
}))}/>))}
|
|
357
|
+
</CheckboxGroup>
|
|
358
|
+
</Flex>
|
|
359
|
+
<Flex container={{ direction: 'column', pad: 0.5 }}>
|
|
360
|
+
<ComboBox label='Status' mode='single-select' required selected={selected
|
|
361
|
+
? {
|
|
362
|
+
items: {
|
|
363
|
+
id: selected?.id,
|
|
364
|
+
text: selected?.primary
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
: undefined} menu={{
|
|
368
|
+
items,
|
|
369
|
+
variant: 'drill-down',
|
|
370
|
+
onItemClick: selectItem
|
|
371
|
+
}}/>
|
|
372
|
+
</Flex>
|
|
373
|
+
</Form>
|
|
374
|
+
</Flex>), [items]);
|
|
375
|
+
const drawerHeader = 'Chat settings';
|
|
376
|
+
const drawerContent = {
|
|
377
|
+
drawerHeader,
|
|
378
|
+
drawerView: chatSettings,
|
|
379
|
+
name: drawerHeader
|
|
380
|
+
};
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
if (selected)
|
|
383
|
+
openDrawer(drawerContent);
|
|
384
|
+
}, [selected]);
|
|
385
|
+
return (<ChatSettingsPanel label={drawerHeader} status={menuHelpers.getParentItem(items, selected?.id)?.id === 'temporarilyUnavailable'
|
|
386
|
+
? menuHelpers.getParentItem(items, selected?.id)?.id
|
|
387
|
+
: selected?.id} onClick={() => openDrawer(drawerContent)}/>);
|
|
388
|
+
};
|
|
299
389
|
//# sourceMappingURL=CSAppShell.mocks.jsx.map
|