@pega/custom-dx-components 2.0.14 → 2.0.16

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 (118) hide show
  1. package/README.md +3 -3
  2. package/package.json +2 -2
  3. package/src/cli.js +0 -18
  4. package/src/tasks/authenticate/index.js +1 -3
  5. package/src/tasks/create/index.js +3 -6
  6. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +1 -1
  7. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +18 -29
  8. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +2 -1
  9. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +67 -179
  10. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +16 -39
  11. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +1 -3
  12. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +1 -0
  13. package/src/tasks/create/templates/Constellation/Field/DateTime/{date-utils.js.mustache → date-utils.js} +0 -1
  14. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +0 -1
  15. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +15 -39
  16. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +0 -2
  17. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +17 -22
  18. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +1 -2
  19. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +17 -25
  20. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +4 -3
  21. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +17 -22
  22. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +2 -8
  23. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +17 -22
  24. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +1 -2
  25. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +14 -42
  26. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +1 -44
  27. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +43 -0
  28. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +16 -21
  29. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +16 -20
  30. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +2 -44
  31. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +43 -0
  32. package/src/tasks/create/templates/Constellation/{Template/DETAILS/StatusWork.jsx.mustache → Field/Text-Input/StatusWork.js} +1 -0
  33. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +17 -21
  34. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +3 -46
  35. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +43 -0
  36. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +17 -21
  37. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +2 -44
  38. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +43 -0
  39. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +17 -19
  40. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +2 -46
  41. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +43 -0
  42. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +17 -19
  43. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +3 -174
  44. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +172 -0
  45. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +16 -24
  46. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +0 -1
  47. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +29 -14
  48. package/src/tasks/create/templates/Constellation/Template/DETAILS/utils.js.mustache +77 -3
  49. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +29 -14
  50. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/utils.js.mustache +74 -3
  51. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +10 -6
  52. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +8 -10
  53. package/src/tasks/create/templates/Constellation/Template/PAGE/{GetNextWork.jsx.mustache → GetNextWork.js.mustache} +0 -6
  54. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +7 -9
  55. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +1 -4
  56. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +0 -1
  57. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +8 -8
  58. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Avatar.jsx.mustache → Avatar.js.mustache} +0 -2
  59. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/{Operator.jsx.mustache → Operator.js.mustache} +1 -2
  60. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +9 -9
  61. package/src/tasks/delete/helper.js +0 -4
  62. package/src/tasks/delete/index.js +0 -4
  63. package/src/tasks/index.js +0 -3
  64. package/src/tasks/init/index.js +1 -1
  65. package/src/tasks/init/template/.eslintrc.json +5 -186
  66. package/src/tasks/init/template/package.json.mustache +4 -19
  67. package/src/tasks/init/template/tasks.config.json +0 -1
  68. package/src/tasks/list/index.js +0 -4
  69. package/src/tasks/{bundle → publish/bundle}/builder/index.js +0 -0
  70. package/src/tasks/{bundle → publish/bundle}/builder/modules.js +0 -0
  71. package/src/tasks/{bundle → publish/bundle}/builder/paths.js +0 -0
  72. package/src/tasks/{bundle → publish/bundle}/builder/webpack.config.js +2 -0
  73. package/src/tasks/{bundle → publish/bundle}/index.js +2 -2
  74. package/src/tasks/publish/index.js +1 -14
  75. package/src/util.js +0 -10
  76. package/src/tasks/build/helper.js +0 -123
  77. package/src/tasks/build/index.js +0 -54
  78. package/src/tasks/create/templates/Constellation/Field/Boolean/mock.stories.js.mustache +0 -21
  79. package/src/tasks/create/templates/Constellation/Field/Date/DateFormatter.js.mustache +0 -61
  80. package/src/tasks/create/templates/Constellation/Field/Date/FormattedText.jsx.mustache +0 -41
  81. package/src/tasks/create/templates/Constellation/Field/Date/mock.stories.js.mustache +0 -23
  82. package/src/tasks/create/templates/Constellation/Field/DateTime/mock.stories.js.mustache +0 -23
  83. package/src/tasks/create/templates/Constellation/Field/Decimal/mock.stories.js.mustache +0 -21
  84. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/mock.stories.js.mustache +0 -23
  85. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/mock.stories.js.mustache +0 -21
  86. package/src/tasks/create/templates/Constellation/Field/Integer/mock.stories.js.mustache +0 -21
  87. package/src/tasks/create/templates/Constellation/Field/Picklist/mock.stories.js.mustache +0 -67
  88. package/src/tasks/create/templates/Constellation/Field/Text/mock.stories.js.mustache +0 -13
  89. package/src/tasks/create/templates/Constellation/Field/Text-Email/mock.stories.js.mustache +0 -22
  90. package/src/tasks/create/templates/Constellation/Field/Text-Input/StatusWork.jsx +0 -26
  91. package/src/tasks/create/templates/Constellation/Field/Text-Input/mock.stories.js.mustache +0 -21
  92. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/mock.stories.js.mustache +0 -20
  93. package/src/tasks/create/templates/Constellation/Field/Text-Phone/mock.stories.js.mustache +0 -37
  94. package/src/tasks/create/templates/Constellation/Field/Text-URL/mock.stories.js.mustache +0 -22
  95. package/src/tasks/create/templates/Constellation/Field/TimeofDay/mock.stories.js.mustache +0 -20
  96. package/src/tasks/create/templates/Constellation/Template/DETAILS/demo.stories.jsx.mustache +0 -110
  97. package/src/tasks/create/templates/Constellation/Template/DETAILS/mock.stories.js.mustache +0 -179
  98. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/StatusWork.jsx.mustache +0 -26
  99. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/demo.stories.jsx.mustache +0 -118
  100. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/mock.stories.js.mustache +0 -215
  101. package/src/tasks/create/templates/Constellation/Template/FORM/demo.stories.jsx.mustache +0 -89
  102. package/src/tasks/create/templates/Constellation/Template/FORM/mock.stories.js.mustache +0 -125
  103. package/src/tasks/create/templates/Constellation/Template/FORM-region/demo.stories.jsx.mustache +0 -92
  104. package/src/tasks/create/templates/Constellation/Template/FORM-region/mock.stories.js.mustache +0 -125
  105. package/src/tasks/create/templates/Constellation/Template/PAGE/demo.stories.jsx.mustache +0 -102
  106. package/src/tasks/create/templates/Constellation/Template/PAGE/mock.stories.js.mustache +0 -94
  107. package/src/tasks/create/templates/Constellation/Widget/CASE/demo.stories.jsx.mustache +0 -78
  108. package/src/tasks/create/templates/Constellation/Widget/CASE/mock.stories.js.mustache +0 -389
  109. package/src/tasks/create/templates/Constellation/Widget/PAGE/demo.stories.jsx.mustache +0 -30
  110. package/src/tasks/create/templates/Constellation/Widget/PAGE/mock.stories.js.mustache +0 -22
  111. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/demo.stories.jsx.mustache +0 -68
  112. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/mock.stories.js.mustache +0 -51
  113. package/src/tasks/delete-all/helper.js +0 -175
  114. package/src/tasks/delete-all/index.js +0 -49
  115. package/src/tasks/init/template/.eslintignore +0 -8
  116. package/src/tasks/linter/index.js +0 -46
  117. package/src/tasks/publish-all/helper.js +0 -139
  118. package/src/tasks/publish-all/index.js +0 -84
@@ -4,60 +4,16 @@ import {
4
4
  getPhoneNumberParts,
5
5
  PhoneDisplay,
6
6
  FieldValueList,
7
- Text,
8
- EmailDisplay, URLDisplay
7
+ Text
9
8
  } from '@pega/cosmos-react-core';
10
9
  import PropTypes from 'prop-types';
11
10
 
12
11
  // includes in bundle
12
+ import {formatExists,textFormatter} from "./text-phone";
13
13
  import handleEvent from "./event-utils";
14
14
  import { suggestionsHandler } from './suggestions-handler';
15
15
 
16
16
  import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
17
- import { } from "@pega/cosmos-react-core";
18
-
19
- export const formatExists = (formatterVal) => {
20
- const formatterValues = [
21
- "TextInput",
22
- "WorkStatus",
23
- "RichText",
24
- "Email",
25
- "Phone",
26
- "URL",
27
- "Operator"
28
- ];
29
- let isformatter = false;
30
- if (formatterValues.includes(formatterVal)) {
31
- isformatter = true;
32
- }
33
- return isformatter;
34
- };
35
-
36
-
37
- export const textFormatter = (formatter,value) => {
38
- let displayComponent = null;
39
- switch(formatter){
40
- case "TextInput" : {
41
- displayComponent = value;
42
- break;
43
- }
44
- case "Email" : {
45
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
46
- break;
47
- }
48
- case "Phone" : {
49
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
50
- break;
51
- }
52
- case "URL" : {
53
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
54
- break;
55
- }
56
- // no default
57
- }
58
- return displayComponent;
59
- };
60
-
61
17
 
62
18
 
63
19
  // Duplicated runtime code from Constellation Design System Component
@@ -0,0 +1,43 @@
1
+ import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
+
3
+ export const formatExists = (formatterVal) => {
4
+ const formatterValues = [
5
+ "TextInput",
6
+ "WorkStatus",
7
+ "RichText",
8
+ "Email",
9
+ "Phone",
10
+ "URL",
11
+ "Operator"
12
+ ];
13
+ let isformatter = false;
14
+ if (formatterValues.includes(formatterVal)) {
15
+ isformatter = true;
16
+ }
17
+ return isformatter;
18
+ };
19
+
20
+
21
+ export const textFormatter = (formatter,value) => {
22
+ let displayComponent = null;
23
+ switch(formatter){
24
+ case "TextInput" : {
25
+ displayComponent = value;
26
+ break;
27
+ }
28
+ case "Email" : {
29
+ displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
30
+ break;
31
+ }
32
+ case "Phone" : {
33
+ displayComponent = (<PhoneDisplay value={value} variant="link" />);
34
+ break;
35
+ }
36
+ case "URL" : {
37
+ displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
38
+ break;
39
+ }
40
+ // no default
41
+ }
42
+ return displayComponent;
43
+ };
@@ -1,7 +1,7 @@
1
- import { withKnobs } from '@storybook/addon-knobs';
1
+ import { useState } from 'react';
2
+ import { withKnobs, text, boolean } from '@storybook/addon-knobs';
2
3
 
3
4
  import {{COMPONENT_CLASS_NAME}} from './index.jsx';
4
- import { stateProps, configProps } from './mock.stories';
5
5
 
6
6
  export default {
7
7
  title: '{{COMPONENT_CLASS_NAME}}',
@@ -10,32 +10,30 @@ export default {
10
10
  };
11
11
 
12
12
  export const base{{COMPONENT_CLASS_NAME}} = () => {
13
+ const [value, setValue] = useState('test value');
13
14
 
14
15
  const props = {
15
- value: configProps.value,
16
- placeholder: configProps.placeholder,
17
- label: configProps.label,
18
- helperText: configProps.helperText,
19
- testId: configProps.testId,
20
- hasSuggestions: configProps.hasSuggestions,
21
-
22
16
  getPConnect: () => {
23
17
  return {
24
- getStateProps: () => {
25
- return stateProps;
26
- },
27
18
  getActionsApi: () => {
28
19
  return {
29
- updateFieldValue: () => {},
30
- triggerFieldChange: () => {}
20
+ updateFieldValue: (propName, value) => {
21
+ setValue(value);
22
+ }
31
23
  };
32
24
  },
33
- ignoreSuggestion: () => {},
34
- acceptSuggestion: () => {},
35
- setInheritedProps: () => {},
36
- resolveConfigProps: () => {}
25
+ getStateProps: () => {
26
+ return { value: '.name' };
27
+ }
37
28
  };
38
- }
29
+ },
30
+ value,
31
+ placeholder: text('Placeholder', 'Test placeholder'),
32
+ disabled: boolean('Disabled', false),
33
+ readOnly: boolean('Disabled', false),
34
+ required: boolean('Disabled', false),
35
+ label: text('Label', 'Sample Label'),
36
+ testId: text('Test id', 'text-12344566')
39
37
  };
40
38
 
41
39
  return (
@@ -1,185 +1,14 @@
1
- import { useState, useEffect, useRef, React} from "react";
2
- import { Input, FieldValueList, Text, EmailDisplay, PhoneDisplay, URLDisplay, Button, Lightbox, Image } from "@pega/cosmos-react-core";
1
+ import { useState, useEffect, useRef} from "react";
2
+ import { Input, FieldValueList, Text } from "@pega/cosmos-react-core";
3
3
  import PropTypes from "prop-types";
4
4
 
5
5
  // includes in bundle
6
+ import {formatExists,textFormatter, urlFormatter, suggestionHandler} from "./text-url";
6
7
  import handleEvent from "./event-utils";
7
8
  import { suggestionsHandler } from './suggestions-handler';
8
9
 
9
10
  import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
10
11
 
11
- export const formatExists = (formatterVal) => {
12
- const formatterValues = [
13
- "TextInput",
14
- "WorkStatus",
15
- "RichText",
16
- "Email",
17
- "Phone",
18
- "URL",
19
- "Operator"
20
- ];
21
- let isformatter = false;
22
- if (formatterValues.includes(formatterVal)) {
23
- isformatter = true;
24
- }
25
- return isformatter;
26
- };
27
-
28
- const urlLabelVal = (urlLabelSelection, btnVal, urlLabel, propUrlLabel) => {
29
- if ((urlLabel !== '' || propUrlLabel !== '') && btnVal !== null) {
30
- switch (urlLabelSelection) {
31
- case 'constant': {
32
- btnVal = urlLabel;
33
- break;
34
- }
35
- case 'propertyRef': {
36
- btnVal = propUrlLabel;
37
- break;
38
- }
39
- // no default
40
- }
41
- }
42
- return btnVal;
43
- };
44
-
45
- const isImage = (url) => /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(url);
46
-
47
- const TableImage = (imageProps) => {
48
- const { value, altText, altTextOfImage, propaltTextOfImage, urlLabelSelection, urlLabel, propUrlLabel } = imageProps;
49
- const demoButtonRef = useRef(null);
50
- let imageDisplayComp = null;
51
- const [images, setImages] = useState(null);
52
- const imgDescription = {
53
- id: 'url',
54
- name: urlLabelSelection === 'constant' ? urlLabel : propUrlLabel,
55
- description: altText === 'constant' ? altTextOfImage : propaltTextOfImage,
56
- src: value
57
- };
58
- const onClick = () => {
59
- setImages([imgDescription]);
60
- };
61
- const onItemDownload = async (id) => {
62
- const a = document.createElement('a');
63
- a.href = await fetch(images[0].src)
64
- .then((response) => {
65
- return response.blob();
66
- })
67
- .then((blob) => {
68
- return URL.createObjectURL(blob);
69
- });
70
- a.download = images?.find((image) => image.id === id)?.name ?? id;
71
- document.body.appendChild(a);
72
- a.click();
73
- document.body.removeChild(a);
74
- };
75
- let btnVal = value;
76
- btnVal = urlLabelVal(urlLabelSelection, btnVal, urlLabel, propUrlLabel);
77
- imageDisplayComp = (
78
- <React.Fragment>
79
- {btnVal !== null && (
80
- <Button ref={demoButtonRef} variant='link' compact={false} onClick={onClick} autoFocus>
81
- {btnVal}
82
- </Button>
83
- )}
84
- {images && (
85
- <Lightbox
86
- items={images}
87
- cycle={false}
88
- onAfterClose={() => {
89
- setImages(null);
90
- demoButtonRef.current?.focus();
91
- }}
92
- onItemDownload={isImage(images[0].src) ? onItemDownload : undefined}
93
- />
94
- )}
95
- </React.Fragment>
96
- );
97
- return imageDisplayComp;
98
- };
99
-
100
- export const textFormatter = (formatter,value) => {
101
- let displayComponent = null;
102
- switch(formatter){
103
- case "TextInput" : {
104
- displayComponent = value;
105
- break;
106
- }
107
- case "Email" : {
108
- displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
109
- break;
110
- }
111
- case "Phone" : {
112
- displayComponent = (<PhoneDisplay value={value} variant="link" />);
113
- break;
114
- }
115
- case "URL" : {
116
- displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
117
- break;
118
- }
119
- // no default
120
- }
121
- return displayComponent;
122
- };
123
-
124
- /**
125
- * Returns a URL display component based on the options
126
- * @function urlFormatter
127
- * @param {string} value value
128
- * @param {object} options options for formatting
129
- * { displayAs,tableDisplayAs,isTableFormatter,altText,altTextOfImage,propaltTextOfImage,urlLabelSelection, urlLabel,propUrlLabel, widthSel, customWidth}
130
- */
131
- export const urlFormatter = (value, options) => {
132
- const {
133
- displayAs,
134
- tableDisplayAs,
135
- isTableFormatter,
136
- altText,
137
- altTextOfImage,
138
- propaltTextOfImage,
139
- urlLabelSelection,
140
- urlLabel,
141
- propUrlLabel,
142
- widthSel,
143
- customWidth
144
- } = options;
145
-
146
- let urlFormatComp = null;
147
- if (
148
- (displayAs === 'labelText' || (isTableFormatter && tableDisplayAs === 'link')) &&
149
- (urlLabel !== '' || propUrlLabel !== '')
150
- ) {
151
- urlFormatComp = (
152
- <URLDisplay
153
- target='_blank'
154
- value={value}
155
- displayText={urlLabelSelection === 'constant' ? urlLabel : propUrlLabel}
156
- variant='link'
157
- />
158
- );
159
- } else if ((displayAs === 'Image' || tableDisplayAs === 'Image') && !!value) {
160
- if (isTableFormatter) {
161
- urlFormatComp = TableImage({
162
- value,
163
- altText,
164
- altTextOfImage,
165
- propaltTextOfImage,
166
- urlLabelSelection,
167
- urlLabel,
168
- propUrlLabel
169
- });
170
- } else {
171
- const width = widthSel === 'widthpx' ? customWidth : null;
172
- urlFormatComp = (
173
- <Image src={value} width={width} alt={altText === 'constant' ? altTextOfImage : propaltTextOfImage} />
174
- );
175
- }
176
- } else {
177
- urlFormatComp = <URLDisplay target='_blank' value={value} displayText={value} variant='link' />;
178
- }
179
- return urlFormatComp;
180
- };
181
-
182
-
183
12
 
184
13
  // Duplicated runtime code from Constellation Design System Component
185
14
 
@@ -0,0 +1,172 @@
1
+ import {EmailDisplay, PhoneDisplay, URLDisplay } from "@pega/cosmos-react-core";
2
+
3
+ export const formatExists = (formatterVal) => {
4
+ const formatterValues = [
5
+ "TextInput",
6
+ "WorkStatus",
7
+ "RichText",
8
+ "Email",
9
+ "Phone",
10
+ "URL",
11
+ "Operator"
12
+ ];
13
+ let isformatter = false;
14
+ if (formatterValues.includes(formatterVal)) {
15
+ isformatter = true;
16
+ }
17
+ return isformatter;
18
+ };
19
+
20
+ const urlLabelVal = (urlLabelSelection, btnVal, urlLabel, propUrlLabel) => {
21
+ if ((urlLabel !== '' || propUrlLabel !== '') && btnVal !== null) {
22
+ switch (urlLabelSelection) {
23
+ case 'constant': {
24
+ btnVal = urlLabel;
25
+ break;
26
+ }
27
+ case 'propertyRef': {
28
+ btnVal = propUrlLabel;
29
+ break;
30
+ }
31
+ // no default
32
+ }
33
+ }
34
+ return btnVal;
35
+ };
36
+
37
+ const isImage = (url) => /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(url);
38
+
39
+ const TableImage = (imageProps) => {
40
+ const { value, altText, altTextOfImage, propaltTextOfImage, urlLabelSelection, urlLabel, propUrlLabel } = imageProps;
41
+ const demoButtonRef = useRef(null);
42
+ let imageDisplayComp = null;
43
+ const [images, setImages] = useState(null);
44
+ const imgDescription = {
45
+ id: 'url',
46
+ name: urlLabelSelection === 'constant' ? urlLabel : propUrlLabel,
47
+ description: altText === 'constant' ? altTextOfImage : propaltTextOfImage,
48
+ src: value
49
+ };
50
+ const onClick = () => {
51
+ setImages([imgDescription]);
52
+ };
53
+ const onItemDownload = async (id) => {
54
+ const a = document.createElement('a');
55
+ a.href = await fetch(images[0].src)
56
+ .then((response) => {
57
+ return response.blob();
58
+ })
59
+ .then((blob) => {
60
+ return URL.createObjectURL(blob);
61
+ });
62
+ a.download = images?.find((image) => image.id === id)?.name ?? id;
63
+ document.body.appendChild(a);
64
+ a.click();
65
+ document.body.removeChild(a);
66
+ };
67
+ let btnVal = value;
68
+ btnVal = urlLabelVal(urlLabelSelection, btnVal, urlLabel, propUrlLabel);
69
+ imageDisplayComp = (
70
+ <React.Fragment>
71
+ {btnVal !== null && (
72
+ <Button ref={demoButtonRef} variant='link' compact={false} onClick={onClick} autoFocus>
73
+ {btnVal}
74
+ </Button>
75
+ )}
76
+ {images && (
77
+ <Lightbox
78
+ items={images}
79
+ cycle={false}
80
+ onAfterClose={() => {
81
+ setImages(null);
82
+ demoButtonRef.current?.focus();
83
+ }}
84
+ onItemDownload={isImage(images[0].src) ? onItemDownload : undefined}
85
+ />
86
+ )}
87
+ </React.Fragment>
88
+ );
89
+ return imageDisplayComp;
90
+ };
91
+
92
+ export const textFormatter = (formatter,value) => {
93
+ let displayComponent = null;
94
+ switch(formatter){
95
+ case "TextInput" : {
96
+ displayComponent = value;
97
+ break;
98
+ }
99
+ case "Email" : {
100
+ displayComponent = (<EmailDisplay value={value} displayText={value} variant="link" />);
101
+ break;
102
+ }
103
+ case "Phone" : {
104
+ displayComponent = (<PhoneDisplay value={value} variant="link" />);
105
+ break;
106
+ }
107
+ case "URL" : {
108
+ displayComponent = (<URLDisplay target="_blank" value={value} displayText={value} variant="link" />);
109
+ break;
110
+ }
111
+ // no default
112
+ }
113
+ return displayComponent;
114
+ };
115
+
116
+ /**
117
+ * Returns a URL display component based on the options
118
+ * @function urlFormatter
119
+ * @param {string} value value
120
+ * @param {object} options options for formatting
121
+ * { displayAs,tableDisplayAs,isTableFormatter,altText,altTextOfImage,propaltTextOfImage,urlLabelSelection, urlLabel,propUrlLabel, widthSel, customWidth}
122
+ */
123
+ export const urlFormatter = (value, options) => {
124
+ const {
125
+ displayAs,
126
+ tableDisplayAs,
127
+ isTableFormatter,
128
+ altText,
129
+ altTextOfImage,
130
+ propaltTextOfImage,
131
+ urlLabelSelection,
132
+ urlLabel,
133
+ propUrlLabel,
134
+ widthSel,
135
+ customWidth
136
+ } = options;
137
+
138
+ let urlFormatComp = null;
139
+ if (
140
+ (displayAs === 'labelText' || (isTableFormatter && tableDisplayAs === 'link')) &&
141
+ (urlLabel !== '' || propUrlLabel !== '')
142
+ ) {
143
+ urlFormatComp = (
144
+ <URLDisplay
145
+ target='_blank'
146
+ value={value}
147
+ displayText={urlLabelSelection === 'constant' ? urlLabel : propUrlLabel}
148
+ variant='link'
149
+ />
150
+ );
151
+ } else if ((displayAs === 'Image' || tableDisplayAs === 'Image') && !!value) {
152
+ if (isTableFormatter) {
153
+ urlFormatComp = TableImage({
154
+ value,
155
+ altText,
156
+ altTextOfImage,
157
+ propaltTextOfImage,
158
+ urlLabelSelection,
159
+ urlLabel,
160
+ propUrlLabel
161
+ });
162
+ } else {
163
+ const width = widthSel === 'widthpx' ? customWidth : null;
164
+ urlFormatComp = (
165
+ <Image src={value} width={width} alt={altText === 'constant' ? altTextOfImage : propaltTextOfImage} />
166
+ );
167
+ }
168
+ } else {
169
+ urlFormatComp = <URLDisplay target='_blank' value={value} displayText={value} variant='link' />;
170
+ }
171
+ return urlFormatComp;
172
+ };
@@ -1,5 +1,6 @@
1
+ import { useState } from 'react';
1
2
  import { withKnobs, text, boolean } from '@storybook/addon-knobs';
2
- import { configProps, stateProps } from './mock.stories';
3
+
3
4
  import {{COMPONENT_CLASS_NAME}} from './index.jsx';
4
5
 
5
6
  export default {
@@ -9,39 +10,30 @@ export default {
9
10
  };
10
11
 
11
12
  export const base{{COMPONENT_CLASS_NAME}} = () => {
13
+ const [value, setValue] = useState('test value');
14
+
12
15
  const props = {
13
16
  getPConnect: () => {
14
17
  return {
15
18
  getActionsApi: () => {
16
19
  return {
17
- updateFieldValue: () => {},
18
- triggerFieldChange: () => {}
20
+ updateFieldValue: (propName, value) => {
21
+ setValue(value);
22
+ }
19
23
  };
20
24
  },
21
25
  getStateProps: () => {
22
- return stateProps;
23
- },
24
- getConfigProps: () => {
25
- return configProps;
26
- },
27
- ignoreSuggestion: () => {},
28
- clearErrorMessages: () => {}
26
+ return { value: '.name' };
27
+ }
29
28
  };
30
29
  },
31
- value: configProps.value,
32
- validatemessage: configProps.validatemessage,
33
- label: configProps.label,
34
- hideLabel: configProps.hideLabel,
35
- helperText: configProps.helperText,
36
- withSeconds: configProps.withSeconds,
37
- testId: configProps.testId,
38
- additionalProps: configProps.additionalProps,
39
- displayMode: configProps.displayMode,
40
- variant: configProps.variant,
41
- hasSuggestions: configProps.hasSuggestions,
42
- disabled: configProps.disabled,
43
- readOnly: configProps.readOnly,
44
- required: configProps.required
30
+ value,
31
+ placeholder: text('Placeholder', 'Test placeholder'),
32
+ disabled: boolean('Disabled', false),
33
+ readOnly: boolean('Disabled', false),
34
+ required: boolean('Disabled', false),
35
+ label: text('Label', 'Sample Label'),
36
+ testId: text('Test id', 'text-12344566')
45
37
  };
46
38
 
47
39
  return (
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-undef */
2
1
  import dayjs from "dayjs";
3
2
 
4
3
  const relativeTime = require("dayjs/plugin/relativeTime");
@@ -1,5 +1,5 @@
1
- import { Fragment } from 'react';
2
- import { Grid, Flex, FieldGroup } from '@pega/cosmos-react-core';
1
+ import { useContext, Fragment } from 'react';
2
+ import { Grid , Flex, FieldGroup } from '@pega/cosmos-react-core';
3
3
  import PropTypes from 'prop-types';
4
4
 
5
5
  import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
@@ -13,19 +13,13 @@ import { getAllFields } from './utils';
13
13
  // any default values in config.pros should be set in defaultProps at bottom of this file
14
14
  export default function {{COMPONENT_CLASS_NAME}}(props) {
15
15
 
16
- const { getPConnect, children, label, showLabel, showHighlightedData } = props;
16
+
17
+ const { getPConnect, children, template, regionsMetadata = [], label, showLabel, showHighlightedData } = props;
18
+
17
19
  const propsToUse = { label, showLabel, ...getPConnect().getInheritedProps() };
18
20
 
19
- const numRegions = getAllFields(getPConnect)?.length;
20
- const gridRepeat = "repeat(".concat(numRegions).concat(", 1fr)");
21
- const gridContainer = { "colGap": 1};
22
- gridContainer.cols = gridRepeat;
23
- gridContainer.alignItems = 'start';
24
21
 
25
- const gridHighlightContainer = { "gap": 2};
26
- gridHighlightContainer.cols = gridRepeat;
27
- gridHighlightContainer.alignItems = 'start';
28
- gridHighlightContainer.pad = [0, 0, 2, 0];
22
+ const numRegions = regionsMetadata.length;
29
23
 
30
24
  // Set up highlighted data to pass in return if is set to show, need raw metadata to pass to createComponent
31
25
  let highlightedDataArr = [];
@@ -50,14 +44,14 @@ export default function {{COMPONENT_CLASS_NAME}}(props) {
50
44
  {{=<% %>=}}
51
45
  <FieldGroup name={propsToUse.showLabel ? propsToUse.label : ''}>
52
46
  {showHighlightedData && highlightedDataArr.length > 0 && (
53
- <Grid container={gridHighlightContainer}
47
+ <Grid container={{ cols:'repeat(${numRegions}, 1fr)', gap: 2, alignItems: 'start', pad: [0, 0, 2, 0] }}
54
48
  data-testid={`highlighted-column-count-${numRegions}`}>
55
49
  {highlightedDataArr.map((child, i) => (
56
50
  <Fragment key={`hf-${i + 1}`}>{child}</Fragment>
57
51
  ))}
58
52
  </Grid>
59
53
  )}
60
- <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
54
+ <Grid container={{ cols:'repeat(${numRegions}, 1fr)', alignItems: 'start', colGap: 1 }} data-testid={`column-count-${numRegions}`} >
61
55
  {children.map((child, i) => (
62
56
  <Flex container={{ direction: 'column'}} key={`r-${i + 1}`}>
63
57
  {child}
@@ -77,10 +71,31 @@ export default function {{COMPONENT_CLASS_NAME}}(props) {
77
71
  showHighlightedData: false
78
72
  };
79
73
 
74
+ // Since the fields are not part of the 'config' in Details template metadata, they need to be subscribed with additionalprops
75
+ const mapStateToProps = (_, ownProps) => {
76
+ const { getPConnect, showLabel, label } = ownProps;
77
+ const Allfields = getAllFields(getPConnect);
78
+
79
+ return {
80
+ regionsMetadata: Allfields,
81
+ label,
82
+ showLabel,
83
+ getPConnect
84
+ };
85
+ };
80
86
 
81
87
  {{COMPONENT_CLASS_NAME}}.propTypes = {
88
+ regionsMetadata: PropTypes.arrayOf(
89
+ PropTypes.arrayOf(
90
+ PropTypes.shape({
91
+ value: PropTypes.oneOfType([PropTypes.bool, PropTypes.string, PropTypes.number]),
92
+ label: PropTypes.string
93
+ })
94
+ )
95
+ ).isRequired,
82
96
  showLabel: PropTypes.bool,
83
97
  label: PropTypes.string,
84
98
  getPConnect: PropTypes.func.isRequired,
99
+ template: PropTypes.string.isRequired,
85
100
  showHighlightedData: PropTypes.bool
86
101
  };