@pega/custom-dx-components 0.24.10 → 0.24.11

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 (20) 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/init/template/package.json.mustache +1 -1
  9. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyDetails/index.tsx +7 -3
  10. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyForm/DetailsRender.tsx +2 -1
  11. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyForm/index.tsx +1 -1
  12. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyIconButtonURL/index.tsx +35 -12
  13. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnDetails/index.tsx +6 -3
  14. package/tests/assets/components/createAll/Constellation/Pega_DXIL_MyTwoColumnForm/DetailsRender.tsx +2 -1
  15. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyDetails/index.tsx +7 -3
  16. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyForm/DetailsRender.tsx +2 -1
  17. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyForm/index.tsx +1 -1
  18. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyIconButtonURL/index.tsx +35 -12
  19. package/tests/assets/components/createAll/Launchpad/Pega_DXIL_MyTwoColumnDetails/index.tsx +6 -3
  20. 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.11",
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
 
@@ -69,7 +69,7 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@pega/configs": "^0.6.0",
72
- "@pega/custom-dx-components": "0.24.10",
72
+ "@pega/custom-dx-components": "0.24.11",
73
73
  "@pega/pcore-pconnect-typedefs": "~3.0.0",
74
74
  "@storybook/addon-actions": "^7.6.7",
75
75
  "@storybook/addon-essentials": "^7.6.7",
@@ -34,7 +34,7 @@ function PegaDxilMyDetails(props: PegaDxilMyDetailsProps) {
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
@@ -86,8 +86,12 @@ function PegaDxilMyDetails(props: PegaDxilMyDetailsProps) {
86
86
  )}
87
87
  <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
88
88
  {children.map((child: any, i: number) => (
89
- // @ts-ignore
90
- <Flex container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }} key={`r-${i + 1}`}>
89
+
90
+ <Flex
91
+ // @ts-ignore
92
+ container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }}
93
+ key={`r-${i + 1}`}
94
+ >
91
95
  <DetailsRender child={child} />
92
96
  </Flex>
93
97
  ))}
@@ -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 PegaDxilMyForm(props: PegaDxilMyFormProps) {
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
 
@@ -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 PegaDxilMyIconButtonUrlProps 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 PegaDxilMyIconButtonUrlProps 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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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
+ <StyledPegaDxilMyIconButtonUrlWrapper> {displayComp} </StyledPegaDxilMyIconButtonUrlWrapper>
149
+ );
150
+ }
151
+
129
152
  return (
130
153
  <StyledPegaDxilMyIconButtonUrlWrapper>
131
154
  <div style={{ display: 'flex' }} data-testid={testId}>
@@ -34,7 +34,7 @@ function PegaDxilMyTwoColumnDetails(props: PegaDxilMyTwoColumnDetailsProps) {
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
@@ -93,8 +93,11 @@ function PegaDxilMyTwoColumnDetails(props: PegaDxilMyTwoColumnDetailsProps) {
93
93
  )}
94
94
  <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
95
95
  {children.map((child: any, i: number) => (
96
- // @ts-ignore
97
- <Flex container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }} key={`r-${i + 1}`}>
96
+ <Flex
97
+ // @ts-ignore
98
+ container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }}
99
+ key={`r-${i + 1}`}
100
+ >
98
101
  <DetailsRender child={child} />
99
102
  </Flex>
100
103
  ))}
@@ -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
 
@@ -34,7 +34,7 @@ function PegaDxilMyDetails(props: PegaDxilMyDetailsProps) {
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
@@ -86,8 +86,12 @@ function PegaDxilMyDetails(props: PegaDxilMyDetailsProps) {
86
86
  )}
87
87
  <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
88
88
  {children.map((child: any, i: number) => (
89
- // @ts-ignore
90
- <Flex container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }} key={`r-${i + 1}`}>
89
+
90
+ <Flex
91
+ // @ts-ignore
92
+ container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }}
93
+ key={`r-${i + 1}`}
94
+ >
91
95
  <DetailsRender child={child} />
92
96
  </Flex>
93
97
  ))}
@@ -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 PegaDxilMyForm(props: PegaDxilMyFormProps) {
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
 
@@ -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 PegaDxilMyIconButtonUrlProps 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 PegaDxilMyIconButtonUrlProps 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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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 PegaDxilMyIconButtonUrl(props: PegaDxilMyIconButtonUrlProps) {
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
+ <StyledPegaDxilMyIconButtonUrlWrapper> {displayComp} </StyledPegaDxilMyIconButtonUrlWrapper>
149
+ );
150
+ }
151
+
129
152
  return (
130
153
  <StyledPegaDxilMyIconButtonUrlWrapper>
131
154
  <div style={{ display: 'flex' }} data-testid={testId}>
@@ -34,7 +34,7 @@ function PegaDxilMyTwoColumnDetails(props: PegaDxilMyTwoColumnDetailsProps) {
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
@@ -93,8 +93,11 @@ function PegaDxilMyTwoColumnDetails(props: PegaDxilMyTwoColumnDetailsProps) {
93
93
  )}
94
94
  <Grid container={gridContainer} data-testid={`column-count-${numRegions}`} >
95
95
  {children.map((child: any, i: number) => (
96
- // @ts-ignore
97
- <Flex container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }} key={`r-${i + 1}`}>
96
+ <Flex
97
+ // @ts-ignore
98
+ container={{ direction: 'column', alignItems: 'normal', colGap: 0, rowGap: 1.5 }}
99
+ key={`r-${i + 1}`}
100
+ >
98
101
  <DetailsRender child={child} />
99
102
  </Flex>
100
103
  ))}
@@ -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