@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.
Files changed (81) hide show
  1. package/jsx/build/FlowModeller/FlowModeller.mocks.d.ts.map +1 -1
  2. package/jsx/build/FlowModeller/FlowModeller.mocks.jsx +2 -17
  3. package/jsx/build/FlowModeller/FlowModeller.mocks.jsx.map +1 -1
  4. package/jsx/build/ObjectSelect/ObjectSelect.mocks.d.ts +3 -2
  5. package/jsx/build/ObjectSelect/ObjectSelect.mocks.d.ts.map +1 -1
  6. package/jsx/build/ObjectSelect/ObjectSelect.mocks.jsx.map +1 -1
  7. package/jsx/build/PageTemplates/PageTemplates.stories.jsx.map +1 -1
  8. package/jsx/core/Backdrop/Backdrop.stories.d.ts.map +1 -1
  9. package/jsx/core/Backdrop/Backdrop.stories.jsx +12 -12
  10. package/jsx/core/Backdrop/Backdrop.stories.jsx.map +1 -1
  11. package/jsx/core/Badges/Count.stories.jsx +1 -1
  12. package/jsx/core/Badges/Count.stories.jsx.map +1 -1
  13. package/jsx/core/Dialog/Dialog.mocks.d.ts +26 -0
  14. package/jsx/core/Dialog/Dialog.mocks.d.ts.map +1 -0
  15. package/jsx/core/Dialog/Dialog.mocks.jsx +136 -0
  16. package/jsx/core/Dialog/Dialog.mocks.jsx.map +1 -0
  17. package/jsx/core/Dialog/Dialog.stories.d.ts +1 -1
  18. package/jsx/core/Dialog/Dialog.stories.d.ts.map +1 -1
  19. package/jsx/core/Dialog/Dialog.stories.jsx +78 -69
  20. package/jsx/core/Dialog/Dialog.stories.jsx.map +1 -1
  21. package/jsx/cs/CSAppShell/CSAppShell.mocks.d.ts +16 -0
  22. package/jsx/cs/CSAppShell/CSAppShell.mocks.d.ts.map +1 -1
  23. package/jsx/cs/CSAppShell/CSAppShell.mocks.jsx +92 -2
  24. package/jsx/cs/CSAppShell/CSAppShell.mocks.jsx.map +1 -1
  25. package/jsx/cs/CSAppShell/CSAppShell.stories.d.ts.map +1 -1
  26. package/jsx/cs/CSAppShell/CSAppShell.stories.jsx +3 -33
  27. package/jsx/cs/CSAppShell/CSAppShell.stories.jsx.map +1 -1
  28. package/jsx/cs/InteractionNotification/InteractionNotification.stories.d.ts +3 -1
  29. package/jsx/cs/InteractionNotification/InteractionNotification.stories.d.ts.map +1 -1
  30. package/jsx/cs/InteractionNotification/InteractionNotification.stories.jsx +18 -4
  31. package/jsx/cs/InteractionNotification/InteractionNotification.stories.jsx.map +1 -1
  32. package/jsx/work/CaseView/CaseView.mocks.d.ts +2 -14
  33. package/jsx/work/CaseView/CaseView.mocks.d.ts.map +1 -1
  34. package/jsx/work/CaseView/CaseView.mocks.jsx +23 -11
  35. package/jsx/work/CaseView/CaseView.mocks.jsx.map +1 -1
  36. package/jsx/work/SearchResults/SearchResults.stories.d.ts.map +1 -1
  37. package/jsx/work/SearchResults/SearchResults.stories.jsx +21 -2
  38. package/jsx/work/SearchResults/SearchResults.stories.jsx.map +1 -1
  39. package/jsx/wss/CaseView/CaseView.stories.jsx +1 -1
  40. package/jsx/wss/CaseView/CaseView.stories.jsx.map +1 -1
  41. package/lib/build/FlowModeller/FlowModeller.mocks.d.ts.map +1 -1
  42. package/lib/build/FlowModeller/FlowModeller.mocks.js +2 -17
  43. package/lib/build/FlowModeller/FlowModeller.mocks.js.map +1 -1
  44. package/lib/build/ObjectSelect/ObjectSelect.mocks.d.ts +3 -2
  45. package/lib/build/ObjectSelect/ObjectSelect.mocks.d.ts.map +1 -1
  46. package/lib/build/ObjectSelect/ObjectSelect.mocks.js.map +1 -1
  47. package/lib/build/PageTemplates/PageTemplates.stories.js.map +1 -1
  48. package/lib/core/Backdrop/Backdrop.stories.d.ts.map +1 -1
  49. package/lib/core/Backdrop/Backdrop.stories.js +2 -2
  50. package/lib/core/Backdrop/Backdrop.stories.js.map +1 -1
  51. package/lib/core/Badges/Count.stories.js +1 -1
  52. package/lib/core/Badges/Count.stories.js.map +1 -1
  53. package/lib/core/Dialog/Dialog.mocks.d.ts +26 -0
  54. package/lib/core/Dialog/Dialog.mocks.d.ts.map +1 -0
  55. package/lib/core/Dialog/Dialog.mocks.js +132 -0
  56. package/lib/core/Dialog/Dialog.mocks.js.map +1 -0
  57. package/lib/core/Dialog/Dialog.stories.d.ts +1 -1
  58. package/lib/core/Dialog/Dialog.stories.d.ts.map +1 -1
  59. package/lib/core/Dialog/Dialog.stories.js +65 -41
  60. package/lib/core/Dialog/Dialog.stories.js.map +1 -1
  61. package/lib/cs/CSAppShell/CSAppShell.mocks.d.ts +16 -0
  62. package/lib/cs/CSAppShell/CSAppShell.mocks.d.ts.map +1 -1
  63. package/lib/cs/CSAppShell/CSAppShell.mocks.js +71 -2
  64. package/lib/cs/CSAppShell/CSAppShell.mocks.js.map +1 -1
  65. package/lib/cs/CSAppShell/CSAppShell.stories.d.ts.map +1 -1
  66. package/lib/cs/CSAppShell/CSAppShell.stories.js +4 -17
  67. package/lib/cs/CSAppShell/CSAppShell.stories.js.map +1 -1
  68. package/lib/cs/InteractionNotification/InteractionNotification.stories.d.ts +3 -1
  69. package/lib/cs/InteractionNotification/InteractionNotification.stories.d.ts.map +1 -1
  70. package/lib/cs/InteractionNotification/InteractionNotification.stories.js +18 -4
  71. package/lib/cs/InteractionNotification/InteractionNotification.stories.js.map +1 -1
  72. package/lib/work/CaseView/CaseView.mocks.d.ts +2 -14
  73. package/lib/work/CaseView/CaseView.mocks.d.ts.map +1 -1
  74. package/lib/work/CaseView/CaseView.mocks.js +23 -11
  75. package/lib/work/CaseView/CaseView.mocks.js.map +1 -1
  76. package/lib/work/SearchResults/SearchResults.stories.d.ts.map +1 -1
  77. package/lib/work/SearchResults/SearchResults.stories.js +21 -2
  78. package/lib/work/SearchResults/SearchResults.stories.js.map +1 -1
  79. package/lib/wss/CaseView/CaseView.stories.js +1 -1
  80. package/lib/wss/CaseView/CaseView.stories.js.map +1 -1
  81. 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
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AAC,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 DialogDemo: Story;
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;;AAsB/C,wBAGU;AAEV,eAAO,MAAM,UAAU,EAAE,KAYxB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAuH5B,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 { useRef } from 'react';
2
- import { useState } from '@storybook/addons';
3
- import { Button, Card, CardContent, CardHeader, Dialog, Flex, Input, Option, Select, Status, SummaryItem, Text, useDialog } from '@pega/cosmos-react-core';
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 DialogDemo = () => {
9
- const { target, events } = useDialog();
8
+ export const InfoDialogDemo = () => {
9
+ const [target, setTarget] = useElement(null);
10
10
  return (<>
11
- <Button variant='secondary' {...events}>
11
+ <Button variant='secondary' onClick={(e) => {
12
+ setTarget(e.currentTarget);
13
+ }}>
12
14
  Open dialog
13
15
  </Button>
14
- <Dialog heading='My dialog' target={target}>
15
- Hello Dialog
16
- </Dialog>
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 editBadgeButton = useRef(null);
21
- const editNameButton = useRef(null);
22
- const timeoutRef = useRef();
23
- const [info, setInfo] = useState({ name: 'James Gregory', badgeType: 'info', badgeText: 'info' });
24
- const [name, setName] = useState(() => info.name);
25
- const [badgeType, setBadgeType] = useState(() => info.badgeType);
26
- const [badgeText, setBadgeText] = useState(() => info.badgeText);
27
- const [dialogType, setDialogType] = useState('badge');
28
- const { target, events, loading, setLoading } = useDialog();
29
- const badgeTypes = ['info', 'pending', 'success', 'urgent', 'warn'];
30
- const onOpen = (type) => {
31
- setDialogType(type);
32
- };
33
- const onDialogSubmit = ({ close }) => {
34
- setLoading(true);
35
- timeoutRef.current = setTimeout(() => {
36
- setInfo({ name, badgeText, badgeType });
37
- setLoading(false);
38
- close();
39
- timeoutRef.current = undefined;
40
- }, 1000);
41
- };
42
- const onDialogClose = () => {
43
- if (timeoutRef.current) {
44
- clearTimeout(timeoutRef.current);
45
- setLoading(false);
46
- }
47
- setName(info.name);
48
- setBadgeText(info.badgeText);
49
- setBadgeType(info.badgeType);
50
- };
51
- return (<Card>
52
- <CardHeader>
53
- <Text variant='h1'>Edit these fields</Text>
54
- </CardHeader>
55
- <CardContent>
56
- <Flex container={{ direction: 'column', gap: 1 }}>
57
- <SummaryItem primary={<Text variant='h6'>Badge</Text>} secondary={<Status variant={info.badgeType}>{info.badgeText}</Status>} actions={<Button variant='simple' ref={editBadgeButton} onClick={() => onOpen('badge')} {...events}>
58
- Edit
59
- </Button>}/>
60
- <SummaryItem primary={<Text variant='h6'>Name</Text>} secondary={<Text variant='primary'>{info.name}</Text>} actions={<Button variant='simple' ref={editNameButton} onClick={() => onOpen('name')} {...events}>
61
- Edit
62
- </Button>}/>
63
- </Flex>
64
- <Dialog target={target} heading={`Edit ${dialogType}`} placement='bottom-end' onSubmit={onDialogSubmit} onClose={onDialogClose} loading={loading}>
65
- <Flex container={{ gap: 1, direction: 'column' }}>
66
- {dialogType === 'badge' ? (<>
67
- <Select label='Select a badge type' value={badgeType} onChange={e => setBadgeType(e.target.value)}>
68
- {badgeTypes.map(type => (<Option key={type}>{type}</Option>))}
69
- </Select>
70
- <Input type='text' label='Badge text' value={badgeText} onChange={(e) => setBadgeText(e.target.value)}/>
71
- </>) : (<>
72
- <Input type='text' label='Text value' value={name} onChange={(e) => setName(e.target.value)}/>
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,EAAe,MAAM,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EACL,MAAM,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AAC,EAE5E;cAAA,GAAG,CACJ,CACH;UAAA,EAAE,IAAI,CACR;QAAA,EAAE,MAAM,CACV;MAAA,EAAE,WAAW,CACf;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Meta, Story } from '@storybook/react';\nimport { ChangeEvent, useRef } from 'react';\nimport { useState } from '@storybook/addons';\n\nimport {\n Button,\n Card,\n CardContent,\n CardHeader,\n Dialog,\n Flex,\n Input,\n Option,\n Select,\n StatusProps,\n Status,\n SummaryItem,\n Text,\n useDialog,\n DialogProps\n} from '@pega/cosmos-react-core';\n\nexport default {\n title: 'Core/Dialog',\n component: Dialog\n} as Meta;\n\nexport const DialogDemo: Story = () => {\n const { target, events } = useDialog();\n return (\n <>\n <Button variant='secondary' {...events}>\n Open dialog\n </Button>\n <Dialog heading='My dialog' target={target}>\n Hello Dialog\n </Dialog>\n </>\n );\n};\n\nexport const FormDialogDemo: Story = () => {\n const editBadgeButton = useRef(null);\n const editNameButton = useRef(null);\n const timeoutRef = useRef<number>();\n const [info, setInfo] = useState<{\n name: string;\n badgeType: StatusProps['variant'];\n badgeText: string;\n }>({ name: 'James Gregory', badgeType: 'info', badgeText: 'info' });\n const [name, setName] = useState(() => info.name);\n const [badgeType, setBadgeType] = useState<StatusProps['variant']>(() => info.badgeType);\n const [badgeText, setBadgeText] = useState(() => info.badgeText);\n const [dialogType, setDialogType] = useState<'badge' | 'name'>('badge');\n const { target, events, loading, setLoading } = useDialog();\n\n const badgeTypes: StatusProps['variant'][] = ['info', 'pending', 'success', 'urgent', 'warn'];\n\n const onOpen = (type: 'badge' | 'name') => {\n setDialogType(type);\n };\n\n const onDialogSubmit: DialogProps['onSubmit'] = ({ close }) => {\n setLoading(true);\n timeoutRef.current = setTimeout(() => {\n setInfo({ name, badgeText, badgeType });\n setLoading(false);\n close();\n timeoutRef.current = undefined;\n }, 1000) as unknown as number;\n };\n\n const onDialogClose: DialogProps['onClose'] = () => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n setLoading(false);\n }\n setName(info.name);\n setBadgeText(info.badgeText);\n setBadgeType(info.badgeType);\n };\n\n return (\n <Card>\n <CardHeader>\n <Text variant='h1'>Edit these fields</Text>\n </CardHeader>\n <CardContent>\n <Flex container={{ direction: 'column', gap: 1 }}>\n <SummaryItem\n primary={<Text variant='h6'>Badge</Text>}\n secondary={<Status variant={info.badgeType}>{info.badgeText}</Status>}\n actions={\n <Button\n variant='simple'\n ref={editBadgeButton}\n onClick={() => onOpen('badge')}\n {...events}\n >\n Edit\n </Button>\n }\n />\n <SummaryItem\n primary={<Text variant='h6'>Name</Text>}\n secondary={<Text variant='primary'>{info.name}</Text>}\n actions={\n <Button\n variant='simple'\n ref={editNameButton}\n onClick={() => onOpen('name')}\n {...events}\n >\n Edit\n </Button>\n }\n />\n </Flex>\n <Dialog\n target={target}\n heading={`Edit ${dialogType}`}\n placement='bottom-end'\n onSubmit={onDialogSubmit}\n onClose={onDialogClose}\n loading={loading}\n >\n <Flex container={{ gap: 1, direction: 'column' }}>\n {dialogType === 'badge' ? (\n <>\n <Select\n label='Select a badge type'\n value={badgeType}\n onChange={e => setBadgeType(e.target.value as StatusProps['variant'])}\n >\n {badgeTypes.map(type => (\n <Option key={type}>{type}</Option>\n ))}\n </Select>\n <Input\n type='text'\n label='Badge text'\n value={badgeText}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setBadgeText(e.target.value)}\n />\n </>\n ) : (\n <>\n <Input\n type='text'\n label='Text value'\n value={name}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setName(e.target.value)}\n />\n </>\n )}\n </Flex>\n </Dialog>\n </CardContent>\n </Card>\n );\n};\n"]}
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,IA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,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;wBAC7C,CAAC;qBACF;iBACF;aACF,CAAC;QACJ,CAAC,CAAC,CAAC,EAGL;;MAAA,CAAC,YAAY,IAAI,CACf,CAAC,UAAU,CACT,MAAM,CAAC,CAAC,YAAY,CAAC,CACrB,IAAI,CAAC,CAAC,QAAQ,CAAC,CAEf,QAAQ,CAAC,CAAC,MAAM,CAAC,EAAE;gBACjB,QAAQ,CACN,QAAQ;oBACN,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE;oBACxD,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,CACzC,CAAC;YACJ,CAAC,CAAC,CACF,UAAU,CAAC,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,EAA8B,iBAAiB,EAAwB,MAAM,OAAO,CAAC;AAoB5F,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"}
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