@pega/custom-dx-components 2.0.7 → 2.0.9

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 (142) hide show
  1. package/package.json +1 -1
  2. package/src/constants.js +29 -17
  3. package/src/tasks/create/index.js +46 -23
  4. package/src/tasks/create/templates/Constellation/Field/Boolean/Boolean.js.mustache +38 -0
  5. package/src/tasks/create/templates/Constellation/Field/Boolean/boolean-format.js.mustache +26 -0
  6. package/src/tasks/create/templates/Constellation/Field/Boolean/config.json.mustache +145 -0
  7. package/src/tasks/create/templates/Constellation/Field/Boolean/demo.stories.jsx.mustache +44 -0
  8. package/src/tasks/create/templates/Constellation/Field/Boolean/event-utils.js.mustache +18 -0
  9. package/src/tasks/create/templates/Constellation/Field/Boolean/index.jsx.mustache +171 -0
  10. package/src/tasks/create/templates/Constellation/Field/Boolean/styles.js.mustache +7 -0
  11. package/src/tasks/create/templates/Constellation/Field/Date/config.json.mustache +195 -0
  12. package/src/tasks/create/templates/Constellation/Field/Date/date.js.mustache +327 -0
  13. package/src/tasks/create/templates/Constellation/Field/Date/demo.stories.jsx.mustache +44 -0
  14. package/src/tasks/create/templates/Constellation/Field/Date/index.jsx.mustache +254 -0
  15. package/src/tasks/create/templates/Constellation/Field/Date/styles.js.mustache +7 -0
  16. package/src/tasks/create/templates/Constellation/Field/Date/suggestions-handler.js +10 -0
  17. package/src/tasks/create/templates/Constellation/Field/DateTime/config.json.mustache +256 -0
  18. package/src/tasks/create/templates/Constellation/Field/DateTime/date-time.js.mustache +93 -0
  19. package/src/tasks/create/templates/Constellation/Field/DateTime/date-utils.js +286 -0
  20. package/src/tasks/create/templates/Constellation/Field/DateTime/date.js.mustache +327 -0
  21. package/src/tasks/create/templates/Constellation/Field/DateTime/demo.stories.jsx.mustache +44 -0
  22. package/src/tasks/create/templates/Constellation/Field/DateTime/index.jsx.mustache +252 -0
  23. package/src/tasks/create/templates/Constellation/Field/DateTime/styles.js.mustache +7 -0
  24. package/src/tasks/create/templates/Constellation/Field/DateTime/suggestions-handler.js +10 -0
  25. package/src/tasks/create/templates/Constellation/Field/Decimal/config.json.mustache +278 -0
  26. package/src/tasks/create/templates/Constellation/Field/Decimal/demo.stories.jsx.mustache +44 -0
  27. package/src/tasks/create/templates/Constellation/Field/Decimal/event-utils.js.mustache +18 -0
  28. package/src/tasks/create/templates/Constellation/Field/Decimal/index.jsx.mustache +272 -0
  29. package/src/tasks/create/templates/Constellation/Field/Decimal/styles.js.mustache +7 -0
  30. package/src/tasks/create/templates/Constellation/Field/Decimal/suggestions-handler.js +10 -0
  31. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/config.json.mustache +291 -0
  32. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/demo.stories.jsx.mustache +44 -0
  33. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/event-utils.js.mustache +18 -0
  34. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/index.jsx.mustache +300 -0
  35. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/styles.js.mustache +7 -0
  36. package/src/tasks/create/templates/Constellation/Field/Decimal-Currency/suggestions-handler.js +10 -0
  37. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/config.json.mustache +93 -0
  38. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/demo.stories.jsx.mustache +44 -0
  39. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/event-utils.js.mustache +18 -0
  40. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/index.jsx.mustache +275 -0
  41. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/styles.js.mustache +7 -0
  42. package/src/tasks/create/templates/Constellation/Field/Decimal-Percentage/suggestions-handler.js +10 -0
  43. package/src/tasks/create/templates/Constellation/Field/Integer/config.json.mustache +347 -0
  44. package/src/tasks/create/templates/Constellation/Field/Integer/demo.stories.jsx.mustache +44 -0
  45. package/src/tasks/create/templates/Constellation/Field/Integer/event-utils.js.mustache +18 -0
  46. package/src/tasks/create/templates/Constellation/Field/Integer/index.jsx.mustache +335 -0
  47. package/src/tasks/create/templates/Constellation/Field/Integer/styles.js.mustache +7 -0
  48. package/src/tasks/create/templates/Constellation/Field/Integer/suggestions-handler.js +10 -0
  49. package/src/tasks/create/templates/Constellation/Field/Picklist/config.json.mustache +114 -0
  50. package/src/tasks/create/templates/Constellation/Field/Picklist/demo.stories.jsx.mustache +44 -0
  51. package/src/tasks/create/templates/Constellation/Field/Picklist/event-utils.js.mustache +18 -0
  52. package/src/tasks/create/templates/Constellation/Field/Picklist/index.jsx.mustache +308 -0
  53. package/src/tasks/create/templates/Constellation/Field/Picklist/picklist.js.mustache +43 -0
  54. package/src/tasks/create/templates/Constellation/Field/Picklist/styles.js.mustache +7 -0
  55. package/src/tasks/create/templates/Constellation/Field/Picklist/suggestions-handler.js +10 -0
  56. package/src/tasks/create/templates/Constellation/Field/Text/config.json.mustache +62 -0
  57. package/src/tasks/create/templates/Constellation/Field/Text/demo.stories.jsx.mustache +44 -0
  58. package/src/tasks/create/templates/Constellation/Field/Text/index.jsx.mustache +60 -0
  59. package/src/tasks/create/templates/Constellation/Field/Text/styles.js.mustache +7 -0
  60. package/src/tasks/create/templates/Constellation/Field/Text-Email/config.json.mustache +111 -0
  61. package/src/tasks/create/templates/Constellation/Field/Text-Email/demo.stories.jsx.mustache +44 -0
  62. package/src/tasks/create/templates/Constellation/Field/Text-Email/event-utils.js.mustache +18 -0
  63. package/src/tasks/create/templates/Constellation/Field/Text-Email/index.jsx.mustache +189 -0
  64. package/src/tasks/create/templates/Constellation/Field/Text-Email/styles.js.mustache +7 -0
  65. package/src/tasks/create/templates/Constellation/Field/Text-Email/suggestions-handler.js +10 -0
  66. package/src/tasks/create/templates/Constellation/Field/Text-Email/text-email.js.mustache +43 -0
  67. package/src/tasks/create/templates/Constellation/Field/Text-Input/StatusWork.js +27 -0
  68. package/src/tasks/create/templates/Constellation/Field/Text-Input/config.json.mustache +111 -0
  69. package/src/tasks/create/templates/Constellation/Field/Text-Input/demo.stories.jsx.mustache +44 -0
  70. package/src/tasks/create/templates/Constellation/Field/Text-Input/event-utils.js.mustache +18 -0
  71. package/src/tasks/create/templates/Constellation/Field/Text-Input/index.jsx.mustache +196 -0
  72. package/src/tasks/create/templates/Constellation/Field/Text-Input/styles.js.mustache +7 -0
  73. package/src/tasks/create/templates/Constellation/Field/Text-Input/suggestions-handler.js +10 -0
  74. package/src/tasks/create/templates/Constellation/Field/Text-Input/text-input.js.mustache +43 -0
  75. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/config.json.mustache +111 -0
  76. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/demo.stories.jsx.mustache +44 -0
  77. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/event-utils.js.mustache +18 -0
  78. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/index.jsx.mustache +189 -0
  79. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/styles.js.mustache +7 -0
  80. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/suggestions-handler.js +10 -0
  81. package/src/tasks/create/templates/Constellation/Field/Text-Paragraph/text-paragraph.js.mustache +43 -0
  82. package/src/tasks/create/templates/Constellation/Field/Text-Phone/config.json.mustache +123 -0
  83. package/src/tasks/create/templates/Constellation/Field/Text-Phone/demo.stories.jsx.mustache +44 -0
  84. package/src/tasks/create/templates/Constellation/Field/Text-Phone/event-utils.js.mustache +18 -0
  85. package/src/tasks/create/templates/Constellation/Field/Text-Phone/index.jsx.mustache +223 -0
  86. package/src/tasks/create/templates/Constellation/Field/Text-Phone/styles.js.mustache +7 -0
  87. package/src/tasks/create/templates/Constellation/Field/Text-Phone/suggestions-handler.js +10 -0
  88. package/src/tasks/create/templates/Constellation/Field/Text-Phone/text-phone.js.mustache +43 -0
  89. package/src/tasks/create/templates/Constellation/Field/Text-URL/config.json.mustache +237 -0
  90. package/src/tasks/create/templates/Constellation/Field/Text-URL/demo.stories.jsx.mustache +44 -0
  91. package/src/tasks/create/templates/Constellation/Field/Text-URL/event-utils.js.mustache +18 -0
  92. package/src/tasks/create/templates/Constellation/Field/Text-URL/index.jsx.mustache +232 -0
  93. package/src/tasks/create/templates/Constellation/Field/Text-URL/styles.js.mustache +7 -0
  94. package/src/tasks/create/templates/Constellation/Field/Text-URL/suggestions-handler.js +10 -0
  95. package/src/tasks/create/templates/Constellation/Field/Text-URL/text-url.js.mustache +172 -0
  96. package/src/tasks/create/templates/Constellation/Field/TimeofDay/config.json.mustache +185 -0
  97. package/src/tasks/create/templates/Constellation/Field/TimeofDay/demo.stories.jsx.mustache +44 -0
  98. package/src/tasks/create/templates/Constellation/Field/TimeofDay/index.jsx.mustache +213 -0
  99. package/src/tasks/create/templates/Constellation/Field/TimeofDay/styles.js.mustache +7 -0
  100. package/src/tasks/create/templates/Constellation/Field/TimeofDay/suggestions-handler.js +10 -0
  101. package/src/tasks/create/templates/Constellation/Field/TimeofDay/time-of-day.js.mustache +286 -0
  102. package/src/tasks/create/templates/Constellation/Template/DETAILS/OneColumnDetails.svg +22 -0
  103. package/src/tasks/create/templates/Constellation/Template/DETAILS/config.json.mustache +35 -0
  104. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.jsx.mustache +99 -0
  105. package/src/tasks/create/templates/Constellation/Template/DETAILS/styles.js.mustache +7 -0
  106. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/TwoColumnDetails.svg +28 -0
  107. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/config.json.mustache +42 -0
  108. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.jsx.mustache +99 -0
  109. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/styles.js.mustache +7 -0
  110. package/src/tasks/create/templates/Constellation/Template/FORM/DefaultForm.svg +29 -0
  111. package/src/tasks/create/templates/Constellation/Template/FORM/config.json.mustache +45 -0
  112. package/src/tasks/create/templates/Constellation/Template/FORM/index.jsx.mustache +49 -0
  113. package/src/tasks/create/templates/Constellation/Template/FORM/styles.js.mustache +7 -0
  114. package/src/tasks/create/templates/Constellation/Template/FORM-region/TwoColumn.svg +38 -0
  115. package/src/tasks/create/templates/Constellation/Template/FORM-region/config.json.mustache +27 -0
  116. package/src/tasks/create/templates/Constellation/Template/FORM-region/index.jsx.mustache +43 -0
  117. package/src/tasks/create/templates/Constellation/Template/FORM-region/styles.js.mustache +7 -0
  118. package/src/tasks/create/templates/Constellation/Template/PAGE/GetNextWork.js.mustache +29 -0
  119. package/src/tasks/create/templates/Constellation/Template/PAGE/OneColumnPage.svg +36 -0
  120. package/src/tasks/create/templates/Constellation/Template/PAGE/config.json.mustache +32 -0
  121. package/src/tasks/create/templates/Constellation/Template/PAGE/index.jsx.mustache +68 -0
  122. package/src/tasks/create/templates/Constellation/Template/PAGE/localizations.json.mustache +4 -0
  123. package/src/tasks/create/templates/Constellation/Template/PAGE/styles.js.mustache +7 -0
  124. package/src/tasks/create/templates/Constellation/Template/PAGE/utils.js.mustache +226 -0
  125. package/src/tasks/create/templates/Constellation/Widget/CASE/OneColumnPage.svg +36 -0
  126. package/src/tasks/create/templates/Constellation/Widget/CASE/config.json.mustache +23 -0
  127. package/src/tasks/create/templates/Constellation/Widget/CASE/index.jsx.mustache +75 -0
  128. package/src/tasks/create/templates/Constellation/Widget/CASE/styles.js.mustache +7 -0
  129. package/src/tasks/create/templates/Constellation/Widget/PAGE/OneColumnPage.svg +36 -0
  130. package/src/tasks/create/templates/Constellation/Widget/PAGE/config.json.mustache +59 -0
  131. package/src/tasks/create/templates/Constellation/Widget/PAGE/index.jsx.mustache +48 -0
  132. package/src/tasks/create/templates/Constellation/Widget/PAGE/styles.js.mustache +7 -0
  133. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Avatar.js.mustache +73 -0
  134. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/OneColumnPage.svg +36 -0
  135. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/Operator.js.mustache +239 -0
  136. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/config.json.mustache +66 -0
  137. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/index.jsx.mustache +110 -0
  138. package/src/tasks/create/templates/Constellation/Widget/PAGE-CASE/styles.js.mustache +7 -0
  139. package/src/tasks/init/template/package.json.mustache +7 -2
  140. package/src/tasks/publish/bundle/builder/index.js +49 -5
  141. package/src/tasks/publish/bundle/builder/webpack.config.js +7 -3
  142. package/src/tasks/validator/index.js +107 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
package/src/constants.js CHANGED
@@ -13,6 +13,24 @@ export const DELETE_COMPONENT_SERVICE_REST_ENDPOINT = 'PRRestService/dev/v1/dele
13
13
  export const TOKEN_URL_V1 = 'PRRestService/oauth2/v1/token';
14
14
 
15
15
  export const COMPONENT_SCHEMA = {
16
+ framework: [
17
+ {
18
+ name: 'Constellation',
19
+ value: 'Constellation'
20
+ },
21
+ {
22
+ name: 'SDK Angular',
23
+ value: 'SDK-Angular'
24
+ },
25
+ {
26
+ name: 'SDK React',
27
+ value: 'SDK-React'
28
+ },
29
+ {
30
+ name: 'SDK Web Components',
31
+ value: 'SDK-WebComponents'
32
+ }
33
+ ],
16
34
  type: [
17
35
  {
18
36
  name: 'Field',
@@ -25,10 +43,6 @@ export const COMPONENT_SCHEMA = {
25
43
  {
26
44
  name: 'Widget',
27
45
  value: 'Widget'
28
- },
29
- {
30
- name: 'Table',
31
- value: 'Table'
32
46
  }
33
47
  ],
34
48
  subtype: {
@@ -37,6 +51,10 @@ export const COMPONENT_SCHEMA = {
37
51
  name: 'Text',
38
52
  value: 'Text'
39
53
  },
54
+ {
55
+ name: 'Text Input',
56
+ value: 'Text-Input'
57
+ },
40
58
  {
41
59
  name: 'Paragraph',
42
60
  value: 'Text-Paragraph'
@@ -82,34 +100,28 @@ export const COMPONENT_SCHEMA = {
82
100
  value: 'DateTime'
83
101
  },
84
102
  {
85
- name: 'TimeofDay',
86
- value: 'TimeofDay'
103
+ name: 'TimeOfDay',
104
+ value: 'TimeOfDay'
87
105
  },
88
106
  {
89
107
  name: 'Picklist',
90
108
  value: 'Picklist'
91
109
  }
92
110
  ],
93
- template: ['DETAILS', 'FORM', 'PAGE'],
111
+ template: ['DETAILS', 'DETAILS-region', 'FORM', 'FORM-region', 'PAGE' ],
94
112
  widget: [
95
- {
96
- name: 'PAGE',
97
- value: 'PAGE'
98
- },
99
113
  {
100
114
  name: 'CASE',
101
115
  value: 'CASE'
102
116
  },
117
+ {
118
+ name: 'PAGE',
119
+ value: 'PAGE'
120
+ },
103
121
  {
104
122
  name: 'PAGE & CASE',
105
123
  value: ['PAGE', 'CASE']
106
124
  }
107
- ],
108
- table: [
109
- {
110
- name: 'Cell',
111
- value: 'Cell'
112
- }
113
125
  ]
114
126
  }
115
127
  };
@@ -53,6 +53,16 @@ const compileMustacheTemplates = async (
53
53
  subtype = subtype.toString();
54
54
  }
55
55
 
56
+ let mustacheSubType = subtype;
57
+ if (typeof(mustacheSubType) == "string") {
58
+ if (mustacheSubType == "FORM-region") {
59
+ mustacheSubType = "FORM";
60
+ }
61
+ else if (mustacheSubType == "DETAILS-region") {
62
+ mustacheSubType = "DETAILS";
63
+ }
64
+ }
65
+
56
66
  if (allowedApplications.trim() === '') {
57
67
  allowedApplications = [];
58
68
  } else {
@@ -76,7 +86,7 @@ const compileMustacheTemplates = async (
76
86
  LIBRARY: library,
77
87
  ALLOWEDAPPS: JSON.stringify(allowedApplications),
78
88
  TYPE: type,
79
- SUB_TYPE: JSON.stringify(subtype),
89
+ SUB_TYPE: JSON.stringify(mustacheSubType),
80
90
  DESCRIPTION: description,
81
91
  IS_TEMPLATE: isTemplate,
82
92
  IS_PICKLIST: isPicklist,
@@ -94,6 +104,7 @@ const validateCompile = async (
94
104
  componentLabel,
95
105
  library,
96
106
  version,
107
+ framework,
97
108
  type,
98
109
  subtype,
99
110
  description,
@@ -101,8 +112,23 @@ const validateCompile = async (
101
112
  },
102
113
  options
103
114
  ) => {
104
- const templateDirectory = fileURLToPath(new URL('./template', import.meta.url));
105
115
 
116
+ let sSubType = subtype;
117
+ if (Array.isArray(subtype)) {
118
+ sSubType = subtype.join("-");
119
+ }
120
+
121
+ // for now, until add question back in
122
+ if (framework == undefined || framework == "") {
123
+ framework = "Constellation";
124
+ }
125
+
126
+ const templateDir = `./templates/${framework}/${type}/${sSubType}`;
127
+ //const templateDirectory = fileURLToPath(new URL('./template', import.meta.url));
128
+ const templateDirectory = fileURLToPath(new URL(templateDir, import.meta.url));
129
+
130
+
131
+ //console.log("temp dir:" + templateDirectory);
106
132
  const { organization } = JSON.parse(fs.readFileSync(path.resolve('package.json'), 'utf8'));
107
133
 
108
134
  const componentKey = `${organization}_${library}_${componentName}`;
@@ -146,20 +172,23 @@ const validateCompile = async (
146
172
  };
147
173
 
148
174
  export default async options => {
149
- if (options.params[9]) {
175
+ if (options.params[10]) {
150
176
  const componentName = options.params[3];
151
177
  const componentLabel = options.params[4];
152
178
  const library = options.params[5];
153
179
  const version = options.params[6];
154
- const type = options.params[7];
155
- const subtype = options.params[8];
156
- const description = options.params[9];
180
+ const framework = options.params[7];
181
+ const type = options.params[8];
182
+ const subtype = options.params[9];
183
+ const description = options.params[10];
184
+
157
185
  await validateCompile(
158
186
  {
159
187
  componentName,
160
188
  componentLabel,
161
189
  library,
162
190
  version,
191
+ framework,
163
192
  type,
164
193
  subtype,
165
194
  description
@@ -225,6 +254,13 @@ export default async options => {
225
254
  message: 'Please enter the application names to be supported (comma-separated). ',
226
255
  suffix: 'Keep empty for all applications'
227
256
  },
257
+ // {
258
+ // name: 'framework',
259
+ // type: 'rawlist',
260
+ // message: 'Enter framework a',
261
+ // default: 'COSMOS_React',
262
+ // choices: COMPONENT_SCHEMA.framework
263
+ // },
228
264
  {
229
265
  name: 'type',
230
266
  type: 'rawlist',
@@ -269,35 +305,21 @@ export default async options => {
269
305
  return 'Please select subtype';
270
306
  }
271
307
  },
272
- {
273
- name: 'subtype',
274
- type: 'rawlist',
275
- message: 'Enter subtype of component',
276
- default: [componentDefaults.subtype || COMPONENT_SCHEMA.subtype.table[0]],
277
- choices: COMPONENT_SCHEMA.subtype.table,
278
- when(answers) {
279
- return answers.type === 'Table';
280
- },
281
- validate: value => {
282
- /* value should not be empty */
283
- if (Array.isArray(value) && value.length) {
284
- return true;
285
- }
286
- return 'Please select subtype';
287
- }
288
- },
289
308
  {
290
309
  name: 'description',
291
310
  message: 'Enter description for the component',
292
311
  default: componentDefaults.description
293
312
  }
294
313
  ];
314
+
315
+ console.log(chalk.green("DX Component Builder v2.0.9"));
295
316
  await inquirer.prompt(questions).then(async answers => {
296
317
  const {
297
318
  componentName,
298
319
  componentLabel,
299
320
  library,
300
321
  version,
322
+ framework,
301
323
  type,
302
324
  subtype,
303
325
  description,
@@ -309,6 +331,7 @@ export default async options => {
309
331
  componentLabel,
310
332
  library,
311
333
  version,
334
+ framework,
312
335
  type,
313
336
  subtype,
314
337
  description,
@@ -0,0 +1,38 @@
1
+ function Boolean(value, { allowEmpty = true, tick = "", cross = "" } = {}) {
2
+ if (
3
+ (!allowEmpty && !value) ||
4
+ value === false ||
5
+ value?.toString()?.toLowerCase() === "false" ||
6
+ value === 0 ||
7
+ value === "0"
8
+ ) {
9
+ return cross || "";
10
+ }
11
+ if (
12
+ value === true ||
13
+ value?.toString()?.toLowerCase() === "true" ||
14
+ value === 1 ||
15
+ value === "1"
16
+ ) {
17
+ return tick || "";
18
+ }
19
+ if (
20
+ allowEmpty &&
21
+ (value === "null" ||
22
+ value === "" ||
23
+ value === null ||
24
+ typeof value === "undefined")
25
+ ) {
26
+ return "––";
27
+ }
28
+ return value;
29
+ }
30
+
31
+ export default {
32
+ TrueFalse: (value, options) =>
33
+ Boolean(value, {
34
+ ...options,
35
+ tick: "True",
36
+ cross: "False"
37
+ })
38
+ };
@@ -0,0 +1,26 @@
1
+ import Boolean from "./Boolean";
2
+
3
+
4
+ export default {
5
+ ...Boolean
6
+ };
7
+
8
+
9
+
10
+ export function format(value, type, options) {
11
+ let formattedValue;
12
+
13
+ switch (type?.toLowerCase()) {
14
+
15
+
16
+ case "boolean":
17
+ case "checkbox": {
18
+ formattedValue = Boolean.TrueFalse(value, { allowEmpty: false });
19
+ break;
20
+ }
21
+
22
+ default:
23
+ formattedValue = value;
24
+ }
25
+ return formattedValue;
26
+ }
@@ -0,0 +1,145 @@
1
+ {
2
+ "name": "{{COMPONENT_KEY}}",
3
+ "label": "{{COMPONENT_LABEL}}",
4
+ "description": "{{DESCRIPTION}}",
5
+ "organization": "{{ORGANIZATION}}",
6
+ "version": "{{VERSION}}",
7
+ "library": "{{LIBRARY}}",
8
+ "allowedApplications": {{{ALLOWEDAPPS}}},
9
+ "componentKey": "{{COMPONENT_KEY}}",
10
+ "type": "{{TYPE}}",
11
+ "subtype": {{{SUB_TYPE}}},
12
+ "icon": "images/pz-checkbox-active.svg",
13
+ "properties": [
14
+ {
15
+ "name": "label",
16
+ "label": "Field label",
17
+ "format": "TEXT"
18
+ },
19
+ {
20
+ "name": "hideLabel",
21
+ "label": "Hide Label",
22
+ "format": "BOOLEAN"
23
+ },
24
+ {
25
+ "name": "readOnly",
26
+ "label": "Edit mode",
27
+ "format": "READONLY"
28
+ },
29
+ {
30
+ "label": "Column settings",
31
+ "format": "GROUP",
32
+ "visibility": "@VIEWTYPE == 'MultiRecordDisplayAsTable'",
33
+ "properties": [
34
+ {
35
+ "name": "columnWidth",
36
+ "label": "Column width",
37
+ "format": "SELECT",
38
+ "source": [
39
+ {
40
+ "key": "auto",
41
+ "value": "Auto"
42
+ },
43
+ {
44
+ "key": "custom",
45
+ "value": "Custom"
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "name": "width",
51
+ "label": "Width (px)",
52
+ "format": "NUMBER",
53
+ "visibility": "$this.columnWidth == 'custom'"
54
+ }
55
+ ]
56
+ },
57
+ {
58
+ "label": "Input settings",
59
+ "format": "GROUP",
60
+ "visibility": "(!readOnly = true)",
61
+ "properties": [
62
+ {
63
+ "name": "caption",
64
+ "label": "Caption",
65
+ "format": "TEXT",
66
+ "useAsAuthoringLabel": true
67
+ },
68
+ {
69
+ "name": "helperText",
70
+ "label": "Helper text",
71
+ "format": "TEXT"
72
+ }
73
+ ]
74
+ },
75
+ {
76
+ "label": "Read-only settings",
77
+ "format": "GROUP",
78
+ "properties": [
79
+ {
80
+ "format": "SELECT",
81
+ "name": "displayValue",
82
+ "label": "Display Value",
83
+ "defaultValue": "Yes/No",
84
+ "localize": true,
85
+ "splitValues": {
86
+ "token": "/",
87
+ "propertyNames": ["trueLabel", "falseLabel"]
88
+ },
89
+ "source": [
90
+ {
91
+ "key": "Yes/No",
92
+ "value": "Yes/No"
93
+ },
94
+ {
95
+ "key": "True/False",
96
+ "value": "True/False"
97
+ }
98
+ ]
99
+ }
100
+ ]
101
+ },
102
+ {
103
+ "label": "Conditions",
104
+ "format": "GROUP",
105
+ "properties": [
106
+ {
107
+ "name": "required",
108
+ "label": "Required",
109
+ "format": "REQUIRED",
110
+ "visibility": "(!readOnly = true)"
111
+ },
112
+ {
113
+ "name": "disabled",
114
+ "label": "Disabled",
115
+ "format": "DISABLED",
116
+ "visibility": "(!readOnly = true)"
117
+ },
118
+ {
119
+ "name": "visibility",
120
+ "label": "Visibility",
121
+ "format": "VISIBILITY"
122
+ }
123
+ ]
124
+ },
125
+ {
126
+ "label": "Advanced",
127
+ "format": "GROUP",
128
+ "collapsible": true,
129
+ "properties": [
130
+ {
131
+ "name": "testId",
132
+ "label": "Test ID",
133
+ "format": "TEXT",
134
+ "ignorePattern": "[^-_\\p{N}\\p{L}]",
135
+ "includeAnnotations": false
136
+ }
137
+ ]
138
+ }
139
+ ],
140
+ "defaultConfig": {
141
+ "caption": "@L $this.label",
142
+ "trueLabel": "@L Yes",
143
+ "falseLabel": "@L No"
144
+ }
145
+ }
@@ -0,0 +1,44 @@
1
+ import { useState } from 'react';
2
+ import { withKnobs, text, boolean } from '@storybook/addon-knobs';
3
+
4
+ import {{COMPONENT_CLASS_NAME}} from './index.jsx';
5
+
6
+ export default {
7
+ title: '{{COMPONENT_CLASS_NAME}}',
8
+ decorators: [withKnobs],
9
+ component: {{COMPONENT_CLASS_NAME}}
10
+ };
11
+
12
+ export const base{{COMPONENT_CLASS_NAME}} = () => {
13
+ const [value, setValue] = useState('test value');
14
+
15
+ const props = {
16
+ getPConnect: () => {
17
+ return {
18
+ getActionsApi: () => {
19
+ return {
20
+ updateFieldValue: (propName, value) => {
21
+ setValue(value);
22
+ }
23
+ };
24
+ },
25
+ getStateProps: () => {
26
+ return { value: '.name' };
27
+ }
28
+ };
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')
37
+ };
38
+
39
+ return (
40
+ <>
41
+ <{{COMPONENT_CLASS_NAME}} {...props} />
42
+ </>
43
+ );
44
+ };
@@ -0,0 +1,18 @@
1
+ const handleEvent = (actions, eventType, propName, value) => {
2
+ switch (eventType) {
3
+ case "change":
4
+ actions.updateFieldValue(propName, value);
5
+ break;
6
+ case "blur":
7
+ actions.triggerFieldChange(propName, value);
8
+ break;
9
+ case "changeNblur":
10
+ actions.updateFieldValue(propName, value);
11
+ actions.triggerFieldChange(propName, value);
12
+ break;
13
+ default:
14
+ break;
15
+ }
16
+ };
17
+
18
+ export default handleEvent;
@@ -0,0 +1,171 @@
1
+ import {
2
+ Checkbox as CosmosCheckbox,
3
+ CheckboxGroup,
4
+ FieldValueList,
5
+ Text
6
+ } from "@pega/cosmos-react-core";
7
+ import PropTypes from "prop-types";
8
+
9
+ // includes in bundle
10
+ import { format } from "./boolean-format";
11
+ import handleEvent from "./event-utils";
12
+
13
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
14
+
15
+ // Duplicated runtime code from Constellation Design System Component
16
+
17
+ // props passed in combination of props from property panel (config.json) and run time props from Constellation
18
+ // any default values in config.pros should be set in defaultProps at bottom of this file
19
+ const {{COMPONENT_CLASS_NAME}} = props => {
20
+ const {
21
+ getPConnect,
22
+ value,
23
+ label,
24
+ helperText,
25
+ caption,
26
+ validatemessage,
27
+ hideLabel,
28
+ testId,
29
+ additionalProps,
30
+ displayMode,
31
+ variant,
32
+ trueLabel,
33
+ falseLabel
34
+ } = props;
35
+ const pConn = getPConnect();
36
+ const actions = pConn.getActionsApi();
37
+ const propName = pConn.getStateProps().value;
38
+
39
+ let { readOnly, required, disabled } = props;
40
+ [readOnly, required, disabled] = [readOnly, required, disabled].map(
41
+ (prop) => prop === true || (typeof prop === 'string' && prop === 'true')
42
+ );
43
+
44
+ let status = "";
45
+ if (validatemessage !== "") {
46
+ status = "error";
47
+ }
48
+
49
+ const aCosmosCheckbox = (
50
+ <CosmosCheckbox
51
+ {...additionalProps}
52
+ className="standard"
53
+ checked={value}
54
+ label={caption}
55
+ disabled={disabled}
56
+ readOnly={readOnly}
57
+ required={required}
58
+ onClick={actions.onClick}
59
+ onChange={(event) => {
60
+ handleEvent(actions, "changeNblur", propName, event.target.checked);
61
+ }}
62
+ onBlur={(event) => {
63
+ pConn.getValidationApi().validate(event.target.checked);
64
+ }}
65
+ data-testid={testId}
66
+ />
67
+ );
68
+
69
+ const parentTestId = testId ? `${testId}-parent` : testId;
70
+
71
+ let displayComponent;
72
+ if (displayMode) {
73
+ displayComponent = <BooleanDisplay value={value} trueLabel={trueLabel} falseLabel={falseLabel}></BooleanDisplay>;
74
+ }
75
+
76
+ if (displayMode === 'DISPLAY_ONLY') {
77
+ return ( <Styled{{COMPONENT_CLASS_NAME}}Wrapper> displayComponent </Styled{{COMPONENT_CLASS_NAME}}Wrapper>);
78
+ }
79
+
80
+ if (displayMode === "LABELS_LEFT") {
81
+ return (
82
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
83
+ <FieldValueList
84
+ variant={hideLabel ? 'stacked' : variant}
85
+ data-testid={testId}
86
+ fields={[{ id: '1', name: hideLabel ? '' : caption, value: displayComponent }]}
87
+ />
88
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
89
+ );
90
+ }
91
+
92
+ if (displayMode === "STACKED_LARGE_VAL") {
93
+ return (
94
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
95
+ <FieldValueList
96
+ variant='stacked'
97
+ data-testid={testId}
98
+ fields={[
99
+ {
100
+ id: '2',
101
+ name: hideLabel ? '' : caption,
102
+ value: (
103
+ <Text variant='h1' as='span'>
104
+ {displayComponent}
105
+ </Text>
106
+ )
107
+ }
108
+ ]}
109
+ />
110
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
111
+ );
112
+ }
113
+
114
+
115
+ return (
116
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
117
+ <CheckboxGroup
118
+ label={label}
119
+ labelHidden={hideLabel}
120
+ data-testid={parentTestId}
121
+ info={validatemessage || helperText}
122
+ status={status}
123
+ >
124
+ {aCosmosCheckbox}
125
+ </CheckboxGroup>
126
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
127
+ );
128
+
129
+
130
+ };
131
+
132
+
133
+ {{COMPONENT_CLASS_NAME}}.defaultProps = {
134
+ validatemessage: '',
135
+ value: false,
136
+ label: '',
137
+ hideLabel: false,
138
+ helperText: '',
139
+ disabled: false,
140
+ readOnly: false,
141
+ required: false,
142
+ testId: null,
143
+ additionalProps: {},
144
+ displayMode: null,
145
+ variant: 'inline',
146
+ displayValue: 'Yes/No',
147
+ trueLabel: '',
148
+ falseLabel: ''
149
+ };
150
+
151
+ {{COMPONENT_CLASS_NAME}}.propTypes = {
152
+ getPConnect: PropTypes.func.isRequired,
153
+ validatemessage: PropTypes.string,
154
+ label: PropTypes.string,
155
+ hideLabel: PropTypes.bool,
156
+ helperText: PropTypes.string,
157
+ value: PropTypes.bool,
158
+ caption: PropTypes.string.isRequired,
159
+ disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
160
+ readOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
161
+ required: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
162
+ testId: PropTypes.string,
163
+ additionalProps: PropTypes.objectOf(PropTypes.any),
164
+ displayMode: PropTypes.string,
165
+ variant: PropTypes.string,
166
+ displayValue: PropTypes.string,
167
+ trueLabel: PropTypes.string,
168
+ falseLabel: PropTypes.string
169
+ };
170
+
171
+ export default {{COMPONENT_CLASS_NAME}};
@@ -0,0 +1,7 @@
1
+ import styled, { css } from 'styled-components';
2
+
3
+ export default styled.div(() => {
4
+ return css`
5
+ margin: 8px 0;
6
+ `;
7
+ });