@pega/custom-dx-components 0.24.10 → 0.24.12

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 (38) hide show
  1. package/package.json +1 -1
  2. package/src/tasks/create/templates/Constellation/Field/Icon-Button-URL/index.tsx.mustache +35 -12
  3. package/src/tasks/create/templates/Constellation/Template/DETAILS/index.tsx.mustache +7 -3
  4. package/src/tasks/create/templates/Constellation/Template/DETAILS-region/index.tsx.mustache +6 -3
  5. package/src/tasks/create/templates/Constellation/Template/FORM/DetailsRender.tsx +2 -1
  6. package/src/tasks/create/templates/Constellation/Template/FORM/index.tsx.mustache +1 -1
  7. package/src/tasks/create/templates/Constellation/Template/FORM-region/DetailsRender.tsx +2 -1
  8. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/PConnProps.d.ts.mustache +46 -0
  9. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/config.json.mustache +32 -0
  10. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/demo.stories.tsx.mustache +98 -0
  11. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/index.tsx.mustache +203 -0
  12. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/mock.ts.mustache +5 -0
  13. package/src/tasks/create/templates/Launchpad/Field/Icon-Button-URL/styles.ts.mustache +8 -0
  14. package/src/tasks/create/templates/Launchpad/Widget/PAGE/OneColumnPage.svg +36 -0
  15. package/src/tasks/create/templates/Launchpad/Widget/PAGE/PConnProps.d.ts.mustache +46 -0
  16. package/src/tasks/create/templates/Launchpad/Widget/PAGE/config.json.mustache +59 -0
  17. package/src/tasks/create/templates/Launchpad/Widget/PAGE/demo.stories.tsx.mustache +112 -0
  18. package/src/tasks/create/templates/Launchpad/Widget/PAGE/index.tsx.mustache +95 -0
  19. package/src/tasks/create/templates/Launchpad/Widget/PAGE/mock.ts.mustache +25 -0
  20. package/src/tasks/create/templates/Launchpad/Widget/PAGE/styles.ts.mustache +8 -0
  21. package/src/tasks/init/template/package.json.mustache +1 -1
  22. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/index.tsx +7 -3
  23. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyForm/DetailsRender.tsx +2 -1
  24. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyForm/index.tsx +1 -1
  25. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/index.tsx +35 -12
  26. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/index.tsx +6 -3
  27. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnForm/DetailsRender.tsx +2 -1
  28. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/index.tsx +7 -3
  29. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyForm/DetailsRender.tsx +2 -1
  30. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyForm/index.tsx +1 -1
  31. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyIconButtonURL/config.json +0 -32
  32. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyIconButtonURL/demo.stories.tsx +9 -10
  33. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyIconButtonURL/index.tsx +42 -23
  34. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyIconButtonURL/mock.ts +1 -1
  35. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyPageWidget/demo.stories.tsx +12 -12
  36. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyPageWidget/index.tsx +5 -5
  37. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/index.tsx +6 -3
  38. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnForm/DetailsRender.tsx +2 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/custom-dx-components",
3
- "version": "0.24.10",
3
+ "version": "0.24.12",
4
4
  "description": "Utility for building custom UI components",
5
5
  "bin": "./bin/index.js",
6
6
  "scripts": {
@@ -6,7 +6,8 @@ import {
6
6
  registerIcon,
7
7
  Table,
8
8
  Label,
9
- Link
9
+ Link,
10
+ URLDisplay
10
11
  } from '@pega/cosmos-react-core';
11
12
  import type { PConnFieldProps } from './PConnProps';
12
13
 
@@ -26,20 +27,32 @@ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
26
27
  countryCode: string;
27
28
  }
28
29
 
30
+ export const textFormatter = (value: string) => {
31
+ const displayComponent = (
32
+ <URLDisplay target='_blank' value={value} displayText={value} variant='link' />
33
+ );
34
+
35
+ return displayComponent;
36
+ };
37
+
29
38
  // *************
30
- // This component is meant to be an example of usage (Icon, Button, etc.) and NOT meant to be
39
+ // This component is meant to be an example of usage (Icon, Button, Link, etc.) and NOT meant to be
31
40
  // used "as is"
32
41
  //
33
42
  // In this example, Icon is shown on its own and inside a Button
34
43
  // Though an Icon can have an "onClick" event is it recommended if you want to click on it,
35
- // to put it in a Button (shown below), so you can have a tooltip and hover style
44
+ // to put it in a Button (shown below), so you can have a tooltip and hover style or put it
45
+ // in a Link (shown below) as a URL.
36
46
  //
37
- // In this example, the click will get a list of states for a given country and display in a
38
- // table below. The table dispaly will toggle with the click of the button icon.
47
+ // For the button, the click will get a list of states for a given country and display in a
48
+ // table below. The table display will toggle with the click of the button icon. Example shows
49
+ // how to handle click, retrieve data from PCore and display it.
39
50
  //
40
- // Globe icon is an icon placed in a LINK element set to use an icon (NOTE: In general
41
- // the LINK element shows the open icon to the left of the link text, but here we are using
42
- // another icon, so with "icon" specified in the link, the open icon doesn't show)
51
+ // Globe icon is an icon placed in a Link element. The Link element to use an icon internally. (NOTE: In general
52
+ // the Link element shows the open icon to the left of the link text, but here we are using
53
+ // another icon, so with "icon" specified in the Link element, the open icon doesn't show)
54
+ // Link elements do not handle bad urls well, so we have a simple validator to prevent the Link element
55
+ // from getting most bad urls.
43
56
  //
44
57
  // NOTE: because icons have to be imported and registered, you can NOT put the icon name
45
58
  // inside the config.json and let the user pick it, if it is not already part of your
@@ -49,10 +62,10 @@ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
49
62
  // props passed in combination of props from property panel (config.json) and run time props from Constellation
50
63
  // any default values in config.pros should be set in defaultProps at bottom of this file
51
64
  function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
52
- const { value, countryCode = 'USA', getPConnect, testId } = props;
65
+ const { value, displayMode, countryCode = 'USA', getPConnect, testId } = props;
53
66
  const [statelist, setStatelist] = useState([]);
54
67
  const [showTable, setShowTable] = useState(false);
55
- const [validUrl, setValidUrl] = useState('');
68
+ const [validUrl, setValidUrl] = useState('about:blank');
56
69
  const PConnect = getPConnect();
57
70
 
58
71
  // IMPORTANT: need to register icons used in camel case
@@ -70,7 +83,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
70
83
  setShowTable(prevShowTable => !prevShowTable);
71
84
  }
72
85
 
73
- // check if url is valid
86
+ // check if url is valid (simple)
74
87
  function validateUrl(href: string) {
75
88
  return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(
76
89
  href
@@ -83,11 +96,13 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
83
96
  // For example: Since the value is the property field,
84
97
  // it could be entered from another component and thus as it is
85
98
  // entered (typed in), it won't be valid until it is all entered.
99
+ // NOTE: can't have a blank value for the url as the Link element will error out
100
+ // in App studio preview
86
101
  useEffect(() => {
87
102
  if (validateUrl(value)) {
88
103
  setValidUrl(value);
89
104
  } else {
90
- setValidUrl('');
105
+ setValidUrl('about:blank');
91
106
  }
92
107
  }, [value]);
93
108
 
@@ -126,6 +141,14 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
126
141
  }
127
142
  }, [PConnect, countryCode, showTable]);
128
143
 
144
+ // when DISPLAY_ONLY, in this example we will just show the URL.
145
+ if (displayMode === 'DISPLAY_ONLY') {
146
+ const displayComp = textFormatter(validUrl);
147
+ return (
148
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper> {displayComp} </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
149
+ );
150
+ }
151
+
129
152
  return (
130
153
  <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
131
154
  {{! pick new delimiters for mustache }}
@@ -34,7 +34,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
34
34
 
35
35
  const numRegions = getAllFields(getPConnect)?.length;
36
36
  const gridRepeat = "repeat(".concat(numRegions).concat(", 1fr)");
37
- const gridContainer = { "colGap": 0};
37
+ const gridContainer = { colGap: 0, 'margin-line-start': 0 };
38
38
  // @ts-ignore
39
39
  gridContainer.cols = gridRepeat;
40
40
  // @ts-ignore
@@ -88,8 +88,12 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
88
88
  )}
89
89
  <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
90
90
  {children.map((child: any, i: number) => (
91
- // @ts-ignore
92
- <Flex container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }} key={`r-${i + 1}`}>
91
+
92
+ <Flex
93
+ // @ts-ignore
94
+ container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }}
95
+ key={`r-${i + 1}`}
96
+ >
93
97
  <DetailsRender child={child} />
94
98
  </Flex>
95
99
  ))}
@@ -34,7 +34,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
34
34
 
35
35
  const numRegions = getAllFields(getPConnect)?.length;
36
36
  const gridRepeat = "repeat(".concat(numRegions).concat(", 1fr)");
37
- const gridContainer = { "colGap": 0};
37
+ const gridContainer = { colGap: 0, 'margin-line-start': 0 };
38
38
  // @ts-ignore
39
39
  gridContainer.cols = gridRepeat;
40
40
  // @ts-ignore
@@ -95,8 +95,11 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
95
95
  )}
96
96
  <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
97
97
  {children.map((child: any, i: number) => (
98
- // @ts-ignore
99
- <Flex container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }} key={`r-${i + 1}`}>
98
+ <Flex
99
+ // @ts-ignore
100
+ container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }}
101
+ key={`r-${i + 1}`}
102
+ >
100
103
  <DetailsRender child={child} />
101
104
  </Flex>
102
105
  ))}
@@ -32,7 +32,8 @@ const DetailsRender = (props: DetailsRenderProps) => {
32
32
 
33
33
  const fvlStyle = {
34
34
  myColGap: {
35
- columnGap: '0'
35
+ columnGap: '0',
36
+ marginLineStart: 0
36
37
  }
37
38
  };
38
39
 
@@ -27,7 +27,7 @@ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
27
27
  if (readOnly && readOnly === true && displayMode && displayMode === 'DISPLAY_ONLY') {
28
28
  const numRegions = '1';
29
29
  const gridRepeat = 'repeat('.concat(numRegions).concat(', 1fr)');
30
- const gridContainer = { colGap: 0 };
30
+ const gridContainer = { colGap: 0, 'margin-line-start': 0 };
31
31
  // @ts-ignore
32
32
  gridContainer.cols = gridRepeat;
33
33
 
@@ -32,7 +32,8 @@ const DetailsRender = (props: DetailsRenderProps) => {
32
32
 
33
33
  const fvlStyle = {
34
34
  myColGap: {
35
- columnGap: '0'
35
+ columnGap: '0',
36
+ marginLineStart: 0
36
37
  }
37
38
  };
38
39
 
@@ -0,0 +1,46 @@
1
+ import {PConnect } from '@pega/pcore-pconnect-typedefs';
2
+
3
+ // PConnProps.d.ts
4
+ // This gives us a place to have each component (which is most DX Components) that is
5
+ // expected to have a getPConnect extend its props (from BaseProps)
6
+ // such that every component will be expected to have a getPConnect() function
7
+ // that returns a PConnect object. (new/better way of doing .propTypes).
8
+ // This PConnProps can be extended to include other props that we know are in every component
9
+ export interface PConnProps {
10
+ // getPConnect should exist for every C11n component. (add @ts-ignore in special cases where it isn't)
11
+ getPConnect: () => typeof PConnect;
12
+
13
+ // Allow any/all other key/value pairs in the BaseProps for now
14
+ // TODO: refine which other props are always expected for various component
15
+ // types and consider further interface "subclassing". For example, we may
16
+ // want to create a "BasePropsForm" that gives guidance on required, readonly, etc.
17
+ // and any other props that every Form component expects.
18
+ // For example, see the PConnFieldProps below.
19
+ // NOTE: if you uncomment the line below, the PConnProps type will allow
20
+ // otherwise undefined types to appear. This can be helpful for debugging
21
+ // or when adding new components whose types aren't yet known.
22
+ // [key: string]: any;
23
+ }
24
+
25
+
26
+ // PConnFieldProps extends PConnProps to bring in the common properties that are
27
+ // associated with most field components (ex: Dropdown, TextInput, etc.) in the
28
+ // components/field directory
29
+ export interface PConnFieldProps extends PConnProps {
30
+ label: string,
31
+ required: boolean,
32
+ disabled: boolean,
33
+ value: any,
34
+ validatemessage: string,
35
+ status?: string,
36
+ onChange?: any,
37
+ onBlur?: any,
38
+ readOnly: boolean,
39
+ testId: string,
40
+ helperText: string,
41
+ displayMode?: string,
42
+ hideLabel: boolean,
43
+ placeholder?: string,
44
+ fieldMetadata?: any,
45
+ additionalProps?: any
46
+ }
@@ -0,0 +1,32 @@
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-url-active.svg",
13
+ "properties": [
14
+ {
15
+ "label": "Advanced",
16
+ "format": "GROUP",
17
+ "collapsible": true,
18
+ "properties": [
19
+ {
20
+ "name": "testId",
21
+ "label": "Test ID",
22
+ "format": "TEXT",
23
+ "ignorePattern": "[^-_\\p{N}\\p{L}]",
24
+ "includeAnnotations": false
25
+ }
26
+ ]
27
+ }
28
+ ],
29
+ "defaultConfig": {
30
+ "label": "@L $this.label"
31
+ }
32
+ }
@@ -0,0 +1,98 @@
1
+
2
+ /* eslint-disable react/jsx-no-useless-fragment */
3
+ // @ts-nocheck
4
+ import type { Meta, StoryObj } from '@storybook/react';
5
+
6
+ import {{COMPONENT_CLASS_NAME}} from './index';
7
+ import { stateProps, configProps } from './mock';
8
+
9
+ const meta: Meta<typeof {{COMPONENT_CLASS_NAME}}> = {
10
+ title: '{{COMPONENT_CLASS_NAME}}',
11
+ component: {{COMPONENT_CLASS_NAME}},
12
+ excludeStories: /.*Data$/
13
+ };
14
+
15
+ export default meta;
16
+ type Story = StoryObj<typeof {{COMPONENT_CLASS_NAME}}>;
17
+
18
+ if (!window.PCore) {
19
+ window.PCore = {};
20
+ }
21
+
22
+ const countrylistData = {
23
+ data: [
24
+ {
25
+ Name: 'United States of America',
26
+ ShortName: 'USA'
27
+ },
28
+ {
29
+ Name: 'Canada',
30
+ ShortName: 'CAN'
31
+ },
32
+ {
33
+ Name: 'Mexico',
34
+ ShortName: 'MEX'
35
+ }
36
+ ]
37
+ };
38
+
39
+ window.PCore.getDataPageUtils = () => {
40
+ return {
41
+ getDataAsync: () => {
42
+ return new Promise(resolve => {
43
+ resolve(countrylistData);
44
+ });
45
+ }
46
+ };
47
+ };
48
+
49
+ export const Base{{COMPONENT_CLASS_NAME}}: Story = args => {
50
+
51
+ const props = {
52
+ getPConnect: () => {
53
+ return {
54
+ getValue: value => {
55
+ return value;
56
+ },
57
+ getContextName: () => {
58
+ return 'app/primary_1';
59
+ },
60
+ getLocalizedValue: value => {
61
+ return value;
62
+ },
63
+ getActionsApi: () => {
64
+ return {
65
+ updateFieldValue: () => {
66
+ /* nothing */
67
+ },
68
+ triggerFieldChange: () => {
69
+ /* nothing */
70
+ }
71
+ };
72
+ },
73
+ ignoreSuggestion: () => {
74
+ /* nothing */
75
+ },
76
+ acceptSuggestion: () => {
77
+ /* nothing */
78
+ },
79
+ setInheritedProps: () => {
80
+ /* nothing */
81
+ },
82
+ resolveConfigProps: () => {
83
+ /* nothing */
84
+ }
85
+ };
86
+ }
87
+ };
88
+
89
+ return (
90
+ <>
91
+ <{{COMPONENT_CLASS_NAME}} {...props} {...args} />
92
+ </>
93
+ );
94
+ };
95
+
96
+ Base{{COMPONENT_CLASS_NAME}}.args = {
97
+
98
+ };
@@ -0,0 +1,203 @@
1
+ import { useEffect, useState } from 'react';
2
+ import {
3
+ Icon,
4
+ Button,
5
+ withConfiguration,
6
+ registerIcon,
7
+ Table,
8
+ Label,
9
+ Link,
10
+ URLDisplay
11
+ } from '@pega/cosmos-react-core';
12
+ import type { PConnFieldProps } from './PConnProps';
13
+
14
+ // IMPORTANT
15
+ // To use Icons, need to individually import the icon file form @pega/cosmos-react-core (see path below)
16
+ // Icons filename is kabab case (file-name), where as the icon you import is camel case (fileName)
17
+ // Icons need to be registered (camel case), and then used (kabab case)
18
+ import * as listNumber from '@pega/cosmos-react-core/lib/components/Icon/icons/list-number.icon';
19
+ import * as arrowRight from '@pega/cosmos-react-core/lib/components/Icon/icons/arrow-right.icon';
20
+ import * as globe from '@pega/cosmos-react-core/lib/components/Icon/icons/globe.icon';
21
+
22
+ import Styled{{COMPONENT_CLASS_NAME}}Wrapper from './styles';
23
+
24
+ // interface for props
25
+ interface {{COMPONENT_CLASS_NAME}}Props extends PConnFieldProps {
26
+ // If any, enter additional props that only exist on TextInput here
27
+ }
28
+
29
+ export const textFormatter = (value: string) => {
30
+ const displayComponent = (
31
+ <URLDisplay target='_blank' value={value} displayText={value} variant='link' />
32
+ );
33
+
34
+ return displayComponent;
35
+ };
36
+
37
+ // *************
38
+ // This component is meant to be an example of usage (Icon, Button, Link, etc.) and NOT meant to be
39
+ // used "as is"
40
+ //
41
+ // In this example, Icon is shown on its own and inside a Button
42
+ // Though an Icon can have an "onClick" event is it recommended if you want to click on it,
43
+ // to put it in a Button (shown below), so you can have a tooltip and hover style or put it
44
+ // in a Link (shown below) as a URL.
45
+ //
46
+ // For the button, the click will get a list of countries and display in a table
47
+ //
48
+ // Globe icon is an icon placed in a Link element. The Link element to use an icon internally. (NOTE: In general
49
+ // the Link element shows the open icon to the left of the link text, but here we are using
50
+ // another icon, so with "icon" specified in the Link element, the open icon doesn't show)
51
+ // Link elements do not handle bad urls well, so we have a simple validator to prevent the Link element
52
+ // from getting most bad urls.
53
+ //
54
+ // NOTE: because icons have to be imported and registered, you can NOT put the icon name
55
+ // inside the config.json and let the user pick it, if it is not already part of your
56
+ // import and registration (can't be done on the fly)
57
+ // **************
58
+
59
+ // props passed in combination of props from property panel (config.json) and run time props from Constellation
60
+ // any default values in config.pros should be set in defaultProps at bottom of this file
61
+ function {{COMPONENT_CLASS_NAME}}(props: {{COMPONENT_CLASS_NAME}}Props) {
62
+ const { value, displayMode, getPConnect, testId } = props;
63
+ const [statelist, setStatelist] = useState([]);
64
+ const [showTable, setShowTable] = useState(false);
65
+ const [validUrl, setValidUrl] = useState('about:blank');
66
+ const PConnect = getPConnect();
67
+
68
+ // IMPORTANT: need to register icons used in camel case
69
+ registerIcon(listNumber, arrowRight, globe);
70
+
71
+
72
+ // setting up columns for the work list table
73
+ const columns = [
74
+ { renderer: 'countryName', label: PConnect.getLocalizedValue('Country Name', '', '') },
75
+ { renderer: 'shortName', label: PConnect.getLocalizedValue('Abbreviation', '', '') }
76
+ ];
77
+
78
+ // toggle showing table and getting table data
79
+ function showHideTable() {
80
+ setShowTable(prevShowTable => !prevShowTable);
81
+ }
82
+
83
+ // check if url is valid (simple)
84
+ function validateUrl(href: string) {
85
+ return /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(
86
+ href
87
+ );
88
+ }
89
+
90
+ // Testing to see if value entered is valid url, if not can't use it.
91
+ // Reason for this code is that you can NOT pass to Link component
92
+ // a bad url, or it will error out.
93
+ // For example: Since the value is the property field,
94
+ // it could be entered from another component and thus as it is
95
+ // entered (typed in), it won't be valid until it is all entered.
96
+ // NOTE: can't have a blank value for the url as the Link element will error out
97
+ // in App studio preview
98
+ useEffect(() => {
99
+ if (validateUrl(value)) {
100
+ setValidUrl(value);
101
+ } else {
102
+ setValidUrl('about:blank');
103
+ }
104
+ }, [value]);
105
+
106
+ // going to get data for worklist to put into a table
107
+ // data comes from calling a PCore function to get
108
+ // get data from a data page and a PConnect function
109
+ // to get getContextName
110
+ useEffect(() => {
111
+ const dataViewName = 'CountryList';
112
+ const context = PConnect.getContextName();
113
+ const params = { };
114
+
115
+ // only retrieve table data if table is shown
116
+ if (showTable) {
117
+ PCore.getDataPageUtils()
118
+ .getDataAsync(dataViewName, context, params, null, null)
119
+ // @ts-ignore
120
+ .then((response: any) => {
121
+ // table requires an index or will get setExtraStackFrame error
122
+ setStatelist(
123
+ response.data.map((entry: any, index: number) => {
124
+ // mapping the data into the column names
125
+ // MUST have an id/index or will get a setExtraStackFrame error
126
+ // put a key in the table
127
+ return {
128
+ countryName: entry.Name,
129
+ shortName: entry.ShortName,
130
+ id: index
131
+ };
132
+ })
133
+ );
134
+ })
135
+ .catch((error: any) => {
136
+ console.log(error);
137
+ });
138
+ }
139
+ }, [PConnect, showTable]);
140
+
141
+ // when DISPLAY_ONLY, in this example we will just show the URL.
142
+ if (displayMode === 'DISPLAY_ONLY') {
143
+ const displayComp = textFormatter(validUrl);
144
+ return (
145
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper> {displayComp} </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
146
+ );
147
+ }
148
+
149
+ return (
150
+ <Styled{{COMPONENT_CLASS_NAME}}Wrapper>
151
+ {{! pick new delimiters for mustache }}
152
+ {{=<% %>=}}
153
+ <div style={{ display: 'flex' }} data-testid={testId}>
154
+ <Icon
155
+ style={{ height: '1.5rem', width: '1.5rem' }}
156
+ // icon name is kabab case
157
+ name='arrow-right'
158
+ role='img'
159
+ aria-label='arrow right'
160
+ />
161
+ <Label style={{ margin: '0.1rem' }}>
162
+ {' '}
163
+ {PConnect.getLocalizedValue('List of countries', '', '')}{' '}
164
+ </Label>
165
+ <Button
166
+ icon
167
+ label={PConnect.getLocalizedValue('Click to show/hide country list', '', '')}
168
+ variant='link'
169
+ compact={false}
170
+ onClick={showHideTable}
171
+ >
172
+ <Icon
173
+ style={{ height: '1.5rem', width: '1.5rem' }}
174
+ // icon name is kabab case
175
+ name='list-number'
176
+ role='img'
177
+ aria-label='numbered list'
178
+ />
179
+ </Button>
180
+ <Link href={validUrl} variant='link' label={validUrl} icon>
181
+ <Icon
182
+ style={{ height: '1.5rem', width: '1.5rem' }}
183
+ // icon name is kabab case
184
+ name='globe'
185
+ role='img'
186
+ aria-label='open link'
187
+ />
188
+ </Link>
189
+ </div>
190
+ {showTable && (
191
+ <Table
192
+ title={PConnect.getLocalizedValue('State list', '', '')}
193
+ columns={columns}
194
+ data={statelist}
195
+ />
196
+ )}
197
+ <%={{ }}=%> {{! revert delimiters for mustache }}
198
+ </Styled{{COMPONENT_CLASS_NAME}}Wrapper>
199
+ );
200
+ }
201
+
202
+
203
+ export default withConfiguration({{COMPONENT_CLASS_NAME}});
@@ -0,0 +1,5 @@
1
+
2
+ // @ts-nocheck
3
+ export const configProps = {
4
+
5
+ };
@@ -0,0 +1,8 @@
1
+ // individual style, comment out above, and uncomment here and add styles
2
+ import styled, { css } from 'styled-components';
3
+
4
+ export default styled.div(() => {
5
+ return css`
6
+ margin: 0px 0;
7
+ `;
8
+ });
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg width="100px" height="70px" viewBox="0 0 100 70" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <title>1 col </title>
4
+ <defs>
5
+ <rect id="path-1" x="0" y="0" width="100" height="70"></rect>
6
+ </defs>
7
+ <g id="Concepts" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
8
+ <g id="Templates" transform="translate(-98.000000, -108.000000)">
9
+ <g id="Change-template" transform="translate(42.000000, 36.000000)">
10
+ <g id="1-col-" transform="translate(56.000000, 72.000000)">
11
+ <mask id="mask-2" fill="white">
12
+ <use xlink:href="#path-1"></use>
13
+ </mask>
14
+ <rect stroke="#A5A8BC" stroke-width="0.5" x="0.25" y="0.25" width="99.5" height="69.5"></rect>
15
+ <g id="white" mask="url(#mask-2)" fill="#FFFFFF">
16
+ <g transform="translate(3.000000, 3.000000)" id="Rectangle">
17
+ <rect x="0" y="0" width="94" height="66.5"></rect>
18
+ </g>
19
+ </g>
20
+ <g id="gray" mask="url(#mask-2)" fill="#8084A7">
21
+ <g transform="translate(6.000000, 6.000000)" id="Rectangle">
22
+ <rect x="0" y="-2.84217094e-14" width="88" height="77.8"></rect>
23
+ </g>
24
+ </g>
25
+ <g id="labels" mask="url(#mask-2)" font-family="OpenSans-Semibold, Open Sans" font-size="11" font-weight="500">
26
+ <g transform="translate(44.000000, 17.000000)" id="A">
27
+ <text>
28
+ <tspan x="0.75" y="12" fill="#FFFFFF">A</tspan>
29
+ </text>
30
+ </g>
31
+ </g>
32
+ </g>
33
+ </g>
34
+ </g>
35
+ </g>
36
+ </svg>
@@ -0,0 +1,46 @@
1
+ import {PConnect } from '@pega/pcore-pconnect-typedefs';
2
+
3
+ // PConnProps.d.ts
4
+ // This gives us a place to have each component (which is most DX Components) that is
5
+ // expected to have a getPConnect extend its props (from BaseProps)
6
+ // such that every component will be expected to have a getPConnect() function
7
+ // that returns a PConnect object. (new/better way of doing .propTypes).
8
+ // This PConnProps can be extended to include other props that we know are in every component
9
+ export interface PConnProps {
10
+ // getPConnect should exist for every C11n component. (add @ts-ignore in special cases where it isn't)
11
+ getPConnect: () => typeof PConnect;
12
+
13
+ // Allow any/all other key/value pairs in the BaseProps for now
14
+ // TODO: refine which other props are always expected for various component
15
+ // types and consider further interface "subclassing". For example, we may
16
+ // want to create a "BasePropsForm" that gives guidance on required, readonly, etc.
17
+ // and any other props that every Form component expects.
18
+ // For example, see the PConnFieldProps below.
19
+ // NOTE: if you uncomment the line below, the PConnProps type will allow
20
+ // otherwise undefined types to appear. This can be helpful for debugging
21
+ // or when adding new components whose types aren't yet known.
22
+ // [key: string]: any;
23
+ }
24
+
25
+
26
+ // PConnFieldProps extends PConnProps to bring in the common properties that are
27
+ // associated with most field components (ex: Dropdown, TextInput, etc.) in the
28
+ // components/field directory
29
+ export interface PConnFieldProps extends PConnProps {
30
+ label: string,
31
+ required: boolean,
32
+ disabled: boolean,
33
+ value: any,
34
+ validatemessage: string,
35
+ status?: string,
36
+ onChange?: any,
37
+ onBlur?: any,
38
+ readOnly: boolean,
39
+ testId: string,
40
+ helperText: string,
41
+ displayMode?: string,
42
+ hideLabel: boolean,
43
+ placeholder?: string,
44
+ fieldMetadata?: any,
45
+ additionalProps?: any
46
+ }