@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
@@ -0,0 +1,254 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { DateInput, FieldValueList, DateTimeDisplay, Text } from '@pega/cosmos-react-core';
3
+ import PropTypes from 'prop-types';
4
+
5
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
6
+
7
+ // includes in bundle
8
+ import {
9
+ datetimedisplayformatter,
10
+ formatExists,
11
+ getFullYear,
12
+ getMaxDate,
13
+ getMinDate,
14
+ datetimeFireChangeBlurEvents,
15
+ getDateFormat
16
+ } from "./date.js";
17
+ import { suggestionsHandler } from './suggestions-handler';
18
+
19
+ // Duplicated runtime code from Constellation Design System Component
20
+
21
+ // props passed in combination of props from property panel (config.json) and run time props from Constellation
22
+ // any default values in config.pros should be set in defaultProps at bottom of this file
23
+ const {{COMPONENT_CLASS_NAME}} = props => {
24
+ const {
25
+ getPConnect,
26
+ value,
27
+ validatemessage,
28
+ label,
29
+ hideLabel,
30
+ helperText,
31
+ nextYearRange,
32
+ previousYearRange,
33
+ showWeekNumber,
34
+ testId,
35
+ showAsFormattedText,
36
+ additionalProps,
37
+ displayMode,
38
+ variant,
39
+ hasSuggestions
40
+ } = props;
41
+
42
+ let {formatter} = props;
43
+ const pConn = getPConnect();
44
+ const actions = pConn.getActionsApi();
45
+ const propName = pConn?.getStateProps()?.value;
46
+
47
+ let { readOnly, required, disabled } = props;
48
+ [readOnly, required, disabled] = [readOnly, required, disabled].map(
49
+ (prop) => prop === true || (typeof prop === "string" && prop === "true")
50
+ );
51
+
52
+ const [status, setStatus] = useState(hasSuggestions ? 'pending' : '');
53
+
54
+ useEffect(() => {
55
+ if (validatemessage !== '') {
56
+ setStatus('error');
57
+ }
58
+ if (hasSuggestions) {
59
+ setStatus('pending');
60
+ } else if (!hasSuggestions && status !== 'success') {
61
+ setStatus(validatemessage !== '' ? 'error' : undefined);
62
+ }
63
+ }, [validatemessage, hasSuggestions]);
64
+
65
+ // calculate min and max range of calendar
66
+ const currentYear = getFullYear();
67
+ const yearFromValue = getFullYear(value);
68
+ const maxDate = getMaxDate(
69
+ parseInt(nextYearRange, 10),
70
+ currentYear,
71
+ yearFromValue
72
+ );
73
+ const minDate = getMinDate(
74
+ parseInt(previousYearRange, 10),
75
+ currentYear,
76
+ yearFromValue
77
+ );
78
+
79
+ const onResolveSuggestionHandler = (accepted) => {
80
+ suggestionsHandler(accepted, pConn, setStatus);
81
+ };
82
+
83
+
84
+
85
+ function handleBlur(onBlurValue) {
86
+ const { valueAsISOString: date, state: errorState } = onBlurValue;
87
+ const trimmedDate = date ? date.substring(0, date.indexOf('T')) : date;
88
+ datetimeFireChangeBlurEvents(errorState, value, trimmedDate, actions, propName, pConn);
89
+ const isValueChanged = !(value === undefined && trimmedDate === '') && value !== trimmedDate;
90
+ if (hasSuggestions && isValueChanged) {
91
+ pConn.ignoreSuggestion();
92
+ }
93
+ }
94
+
95
+ function handleChange(onChangeValue) {
96
+ const { valueAsISOString: date } = onChangeValue;
97
+ const trimmedDate = date ? date.substring(0, date.indexOf('T')) : date;
98
+ if (hasSuggestions && value !== trimmedDate) {
99
+ setStatus(undefined);
100
+ }
101
+ pConn.clearErrorMessages({
102
+ property: propName
103
+ })
104
+ }
105
+
106
+ if (displayMode === 'LABELS_LEFT' || displayMode === 'STACKED_LARGE_VAL' || displayMode === 'DISPLAY_ONLY') {
107
+ let variantValue = "date";
108
+ let formatValue = "long";
109
+ if(pConn && pConn.getConfigProps()){
110
+ const runtimeformatter = pConn.getConfigProps()?.formatter;
111
+ if(formatter !== runtimeformatter){
112
+ formatter = runtimeformatter;
113
+ }
114
+ }
115
+ if(formatter !== "" && formatExists(formatter)){
116
+ const {variantVal,formatVal} = datetimedisplayformatter(formatter);
117
+ variantValue = variantVal;
118
+ formatValue = formatVal;
119
+ }
120
+ const displayComp = (
121
+ <DateTimeDisplay
122
+ variant={variantValue}
123
+ format={formatValue}
124
+ value={value}
125
+ />
126
+ );
127
+ switch(displayMode){
128
+ case 'DISPLAY_ONLY': {
129
+ return ( <Styled{{COMPONENT_CLASS_NAME}}Wrapper> displayComp </Styled{{COMPONENT_CLASS_NAME}}Wrapper>);
130
+ }
131
+ case "LABELS_LEFT" : {
132
+ return (
133
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
134
+ <FieldValueList
135
+ variant={hideLabel ? "stacked" : variant}
136
+ data-testid={testId}
137
+ fields={[{ id: '1', name: hideLabel ? "" :label, value: displayComp }]}
138
+ />
139
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
140
+
141
+ );
142
+ }
143
+ case "STACKED_LARGE_VAL" : {
144
+ return (
145
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
146
+ <FieldValueList
147
+ variant='stacked'
148
+ data-testid={testId}
149
+ fields={[{ id: '2', name: hideLabel ? "" :label, value: <Text variant='h1' as='span'>{displayComp}</Text> }]}
150
+ />
151
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
152
+
153
+ );
154
+ }
155
+ // no default
156
+ }
157
+ }
158
+
159
+
160
+ let dateComponent;
161
+
162
+ if (readOnly && showAsFormattedText) {
163
+ const environmentInfo = PCore.getEnvironmentInfo();
164
+ const locale = environmentInfo && environmentInfo.getLocale();
165
+ const textAdditionalProps = {
166
+ format: getDateFormat(locale),
167
+ fieldType: 'Date'
168
+ };
169
+ dateComponent = (
170
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
171
+ <FormattedText
172
+ formatType='date'
173
+ value={value}
174
+ label={label}
175
+ hideLabel={hideLabel}
176
+ testId={testId}
177
+ additionalProps={textAdditionalProps}
178
+ customFormat={getDateFormat(locale)}
179
+ />
180
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
181
+ );
182
+ } else {
183
+ dateComponent = (
184
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
185
+ <DateInput
186
+ {...additionalProps}
187
+ label={label}
188
+ labelHidden={hideLabel}
189
+ info={validatemessage || helperText}
190
+ status={status}
191
+ value={value || undefined}
192
+ disabled={disabled}
193
+ readOnly={readOnly}
194
+ required={required}
195
+ showWeekNumber={showWeekNumber}
196
+ min={minDate}
197
+ max={maxDate}
198
+ data-testid={testId}
199
+ onFocus={actions.onFocus}
200
+ onChange={handleChange}
201
+ onBlur={handleBlur}
202
+ onResolveSuggestion={onResolveSuggestionHandler}
203
+ />
204
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
205
+ );
206
+ }
207
+ return dateComponent;
208
+ }
209
+
210
+
211
+
212
+ {{COMPONENT_CLASS_NAME}}.defaultProps = {
213
+ value: undefined,
214
+ validatemessage: "",
215
+ helperText: "",
216
+ hideLabel: false,
217
+ disabled: false,
218
+ readOnly: false,
219
+ required: false,
220
+ showWeekNumber: false,
221
+ nextYearRange: "",
222
+ previousYearRange: "",
223
+ testId: null,
224
+ showAsFormattedText: false,
225
+ additionalProps: {},
226
+ displayMode: null,
227
+ variant: "inline",
228
+ formatter: "defaultDate",
229
+ hasSuggestions: false
230
+ };
231
+
232
+ {{COMPONENT_CLASS_NAME}}.propTypes = {
233
+ value: PropTypes.string,
234
+ label: PropTypes.string.isRequired,
235
+ hideLabel: PropTypes.bool,
236
+ getPConnect: PropTypes.func.isRequired,
237
+ validatemessage: PropTypes.string,
238
+ helperText: PropTypes.string,
239
+ disabled: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
240
+ readOnly: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
241
+ required: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
242
+ showWeekNumber: PropTypes.bool,
243
+ nextYearRange: PropTypes.string,
244
+ previousYearRange: PropTypes.string,
245
+ testId: PropTypes.string,
246
+ showAsFormattedText: PropTypes.bool,
247
+ additionalProps: PropTypes.objectOf(PropTypes.any),
248
+ displayMode: PropTypes.string,
249
+ variant: PropTypes.string,
250
+ formatter: PropTypes.string,
251
+ hasSuggestions: PropTypes.bool
252
+ };
253
+
254
+ 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
+ });
@@ -0,0 +1,10 @@
1
+ /* eslint-disable import/prefer-default-export */
2
+ export const suggestionsHandler = (accepted, pConn, setStatus) => {
3
+ if (accepted) {
4
+ pConn.acceptSuggestion();
5
+ setStatus('success');
6
+ } else {
7
+ pConn.ignoreSuggestion();
8
+ setStatus(undefined);
9
+ }
10
+ };
@@ -0,0 +1,256 @@
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-text-input-active.svg",
13
+ "properties": [
14
+ {
15
+ "name": "label",
16
+ "label": "Field label",
17
+ "format": "TEXT",
18
+ "required": true
19
+ },
20
+ {
21
+ "name": "readOnly",
22
+ "label": "Edit mode",
23
+ "format": "READONLY"
24
+ },
25
+ {
26
+ "format": "SELECT",
27
+ "name": "clockFormat",
28
+ "label": "Clock",
29
+ "defaultValue": "0",
30
+ "source": [
31
+ {
32
+ "key": "0",
33
+ "value": "use locale"
34
+ },
35
+ {
36
+ "key": "12",
37
+ "value": "12 hours"
38
+ },
39
+ {
40
+ "key": "24",
41
+ "value": "24 hours"
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "name": "withSeconds",
47
+ "label": "Display seconds",
48
+ "format": "BOOLEAN"
49
+ },
50
+ {
51
+ "label": "Column settings",
52
+ "format": "GROUP",
53
+ "visibility": "@VIEWTYPE == 'MultiRecordDisplayAsTable'",
54
+ "properties": [
55
+ {
56
+ "name": "columnWidth",
57
+ "label": "Column width",
58
+ "format": "SELECT",
59
+ "source": [
60
+ {
61
+ "key": "auto",
62
+ "value": "Auto"
63
+ },
64
+ {
65
+ "key": "custom",
66
+ "value": "Custom"
67
+ }
68
+ ]
69
+ },
70
+ {
71
+ "name": "width",
72
+ "label": "Width (px)",
73
+ "format": "NUMBER",
74
+ "visibility": "$this.columnWidth == 'custom'"
75
+ }
76
+ ]
77
+ },
78
+ {
79
+ "label": "Input settings",
80
+ "format": "GROUP",
81
+ "visibility": "(!readOnly = true)",
82
+ "properties": [
83
+ {
84
+ "format": "LABEL",
85
+ "label": "Year range",
86
+ "variant": "secondary"
87
+ },
88
+ {
89
+ "format": "INLINE",
90
+ "elements": [
91
+ {
92
+ "key": "next",
93
+ "format": "LABEL",
94
+ "label": "Next",
95
+ "variant": "secondary"
96
+ },
97
+ {
98
+ "key": "nextYears",
99
+ "format": "NUMBER",
100
+ "label": "",
101
+ "name": "nextYearRange",
102
+ "min": 0
103
+ },
104
+ {
105
+ "key": "year",
106
+ "format": "LABEL",
107
+ "label": "years",
108
+ "variant": "secondary"
109
+ }
110
+ ]
111
+ },
112
+ {
113
+ "format": "INLINE",
114
+ "elements": [
115
+ {
116
+ "key": "previous",
117
+ "format": "LABEL",
118
+ "label": "Previous",
119
+ "variant": "secondary"
120
+ },
121
+ {
122
+ "key": "previousYears",
123
+ "format": "NUMBER",
124
+ "label": "",
125
+ "name": "previousYearRange",
126
+ "min": 0
127
+ },
128
+ {
129
+ "key": "year",
130
+ "format": "LABEL",
131
+ "label": "years",
132
+ "variant": "secondary"
133
+ }
134
+ ]
135
+ },
136
+ {
137
+ "name": "showWeekNumber",
138
+ "label": "Display week numbers on calendar",
139
+ "format": "BOOLEAN"
140
+ },
141
+ {
142
+ "format": "SELECT",
143
+ "name": "pickerInterval",
144
+ "label": "Time picker",
145
+ "defaultValue": "30",
146
+ "source": [
147
+ {
148
+ "key": "5",
149
+ "value": "5 min"
150
+ },
151
+ {
152
+ "key": "10",
153
+ "value": "10 min"
154
+ },
155
+ {
156
+ "key": "15",
157
+ "value": "15 min"
158
+ },
159
+ {
160
+ "key": "20",
161
+ "value": "20 min"
162
+ },
163
+ {
164
+ "key": "30",
165
+ "value": "30 min"
166
+ },
167
+ {
168
+ "key": "60",
169
+ "value": "1 hr"
170
+ }
171
+ ]
172
+ },
173
+ {
174
+ "name": "helperText",
175
+ "label": "Helper text",
176
+ "format": "TEXT"
177
+ }
178
+ ]
179
+ },
180
+ {
181
+ "label": "Read-only settings",
182
+ "format": "GROUP",
183
+ "properties": [
184
+ {
185
+ "name": "showAsFormattedText",
186
+ "label": "Show as formatted text",
187
+ "format": "BOOLEAN"
188
+ },
189
+ {
190
+ "format": "SELECT",
191
+ "name": "formatter",
192
+ "label": "Format",
193
+ "defaultValue": "defaultDateTime",
194
+ "source": [
195
+ {
196
+ "key": "defaultDateTime",
197
+ "value": "Default"
198
+ },
199
+ {
200
+ "key": "DateTime-Short",
201
+ "value": "Date"
202
+ },
203
+ {
204
+ "key": "DateTime-Since",
205
+ "value": "Since"
206
+ },
207
+ {
208
+ "key": "Time-Only",
209
+ "value": "Time only"
210
+ }
211
+ ]
212
+ }
213
+ ]
214
+ },
215
+ {
216
+ "label": "Conditions",
217
+ "format": "GROUP",
218
+ "properties": [
219
+ {
220
+ "name": "required",
221
+ "label": "Required",
222
+ "format": "REQUIRED",
223
+ "visibility": "(!readOnly = true)"
224
+ },
225
+ {
226
+ "name": "disabled",
227
+ "label": "Disabled",
228
+ "format": "DISABLED",
229
+ "visibility": "(!readOnly = true)"
230
+ },
231
+ {
232
+ "name": "visibility",
233
+ "label": "Visibility",
234
+ "format": "VISIBILITY"
235
+ }
236
+ ]
237
+ },
238
+ {
239
+ "label": "Advanced",
240
+ "format": "GROUP",
241
+ "collapsible": true,
242
+ "properties": [
243
+ {
244
+ "name": "testId",
245
+ "label": "Test ID",
246
+ "format": "TEXT",
247
+ "ignorePattern": "[^-_\\p{N}\\p{L}]",
248
+ "includeAnnotations": false
249
+ }
250
+ ]
251
+ }
252
+ ],
253
+ "defaultConfig": {
254
+ "label": "@L $this.label"
255
+ }
256
+ }
@@ -0,0 +1,93 @@
1
+ import dayjs from "dayjs";
2
+ import relativeTime from "dayjs/plugin/relativeTime";
3
+ import localizedFormat from "dayjs/plugin/localizedFormat";
4
+ import utc from "dayjs/plugin/utc";
5
+ import tzone from "dayjs/plugin/timezone";
6
+
7
+ dayjs.extend(relativeTime);
8
+ dayjs.extend(localizedFormat);
9
+ dayjs.extend(utc);
10
+ dayjs.extend(tzone);
11
+
12
+ const types = ["fromNow", "customFormat"];
13
+
14
+ // value should be in ISO 8601 format.
15
+ function DateFormatter(
16
+ value,
17
+ { type = types[1], format = "DD/MM/YYYY", timezone, fieldType } = {}
18
+ ) {
19
+ if (!value) return value;
20
+ switch (type) {
21
+ case types[1]:
22
+ if (timezone && fieldType !== 'Date') return dayjs(value).tz(timezone).format(format); // Date only value should be formatted without timezone
23
+ return dayjs(value).format(format);
24
+ case types[0]:
25
+ return dayjs(value).from(dayjs());
26
+ default:
27
+ return value;
28
+ }
29
+ }
30
+ // value should be in hh:mm:ss format (00:00:00 - 23:59:59).
31
+ function TimeFormatter(value, options) {
32
+ if (!value) return value;
33
+ const { locale = "en-US" } = options;
34
+ const timeOnlyRegex = /^(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)$/;
35
+ if (value.length === 8 && timeOnlyRegex.test(value)) {
36
+ const { timeOptions = {} } = options;
37
+ const tempDate = new Date();
38
+ const hours = parseInt(value.substr(0, 2), 10);
39
+ const minutes = parseInt(value.substr(3, 2), 10);
40
+ const seconds = parseInt(value.substr(6, 2), 10);
41
+ tempDate.setHours(hours);
42
+ tempDate.setMinutes(minutes);
43
+ tempDate.setSeconds(seconds);
44
+ return tempDate.toLocaleTimeString(locale, timeOptions);
45
+ }
46
+ return DateFormatter(value, options);
47
+ }
48
+
49
+ export const DateTimeShortFormatter = (value, options) => {
50
+ //export function DateTimeShortFormatter(value, options) {
51
+ return DateFormatter(value, {
52
+ ...options,
53
+ type: "customFormat",
54
+ format: "MMM DD, YYYY"
55
+ });
56
+ }
57
+
58
+ export default {
59
+ "DateTime-Long": (value, options) =>
60
+ DateFormatter(value, { ...options, type: "customFormat", format: "LLL" }),
61
+ "DateTime-Short": DateTimeShortFormatter,
62
+ "DateTime-Since": (value) => DateFormatter(value, { type: "fromNow" }),
63
+ "Time-Only": (value, options) =>
64
+ TimeFormatter(value, {
65
+ ...options,
66
+ type: "customFormat",
67
+ format: "hh:mm:ss A"
68
+ }),
69
+ convertToTimezone: (value, options) => {
70
+ return value && options && options.timezone
71
+ ? DateFormatter(value, {
72
+ ...options,
73
+ type: "customFormat",
74
+ format: "YYYY-MM-DDTHH:mm:ss"
75
+ })
76
+ : value;
77
+ },
78
+ convertFromTimezone: (value, timezone) =>
79
+ value && timezone
80
+ ? dayjs.tz(value, timezone).utc().format("YYYY-MM-DDTHH:mm:ss[Z]")
81
+ : value,
82
+ Date: (value, options) =>
83
+ DateFormatter(value, { type: "customFormat", ...options }),
84
+ "Date-Default": DateTimeShortFormatter,
85
+ "Date-Time-Default": (value, options) =>
86
+ DateFormatter(value, { ...options, type: "customFormat", format: "lll" }),
87
+ "Time-Default": (value, options) =>
88
+ TimeFormatter(value, {
89
+ ...options,
90
+ type: "customFormat",
91
+ format: "hh:mm A"
92
+ })
93
+ };