@pega/cosmos-react-condition-builder 9.0.0-build.9.8 → 9.0.0

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 (80) hide show
  1. package/lib/components/ConditionBuilder/AtomicCondition.d.ts +4 -0
  2. package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
  3. package/lib/components/ConditionBuilder/AtomicCondition.js +10 -11
  4. package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
  5. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts +2 -3
  6. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -1
  7. package/lib/components/ConditionBuilder/ConditionBuilder.js +79 -40
  8. package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
  9. package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts +604 -6
  10. package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts.map +1 -1
  11. package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +90 -36
  12. package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +1 -1
  13. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +42 -2
  14. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
  15. package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
  16. package/lib/components/ConditionBuilder/RhsControls/CSVInput.d.ts +18 -0
  17. package/lib/components/ConditionBuilder/RhsControls/CSVInput.d.ts.map +1 -0
  18. package/lib/components/ConditionBuilder/RhsControls/CSVInput.js +59 -0
  19. package/lib/components/ConditionBuilder/RhsControls/CSVInput.js.map +1 -0
  20. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts +2 -0
  21. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
  22. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +21 -5
  23. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
  24. package/lib/components/ConditionBuilder/RhsControls/NumericRangeInput.d.ts +31 -0
  25. package/lib/components/ConditionBuilder/RhsControls/NumericRangeInput.d.ts.map +1 -0
  26. package/lib/components/ConditionBuilder/RhsControls/NumericRangeInput.js +52 -0
  27. package/lib/components/ConditionBuilder/RhsControls/NumericRangeInput.js.map +1 -0
  28. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +5 -3
  29. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
  30. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +28 -22
  31. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
  32. package/lib/components/ConditionBuilder/RhsControls/index.d.ts +5 -5
  33. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
  34. package/lib/components/ConditionBuilder/RhsControls/index.js +35 -43
  35. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
  36. package/lib/components/ConditionBuilder/core/comparators.d.ts.map +1 -1
  37. package/lib/components/ConditionBuilder/core/comparators.js +6 -1
  38. package/lib/components/ConditionBuilder/core/comparators.js.map +1 -1
  39. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
  40. package/lib/components/ConditionBuilder/core/formatter.js +51 -4
  41. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
  42. package/lib/components/ConditionBuilder/core/time-utils.d.ts +1 -1
  43. package/lib/components/ConditionBuilder/core/time-utils.d.ts.map +1 -1
  44. package/lib/components/ConditionBuilder/core/time-utils.js +4 -3
  45. package/lib/components/ConditionBuilder/core/time-utils.js.map +1 -1
  46. package/lib/components/ConditionBuilder/core/transformer.d.ts +6 -1
  47. package/lib/components/ConditionBuilder/core/transformer.d.ts.map +1 -1
  48. package/lib/components/ConditionBuilder/core/transformer.js +99 -81
  49. package/lib/components/ConditionBuilder/core/transformer.js.map +1 -1
  50. package/lib/components/ConditionBuilder/core/types.d.ts +4 -1
  51. package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
  52. package/lib/components/ConditionBuilder/core/types.js.map +1 -1
  53. package/lib/components/ConditionBuilder/index.d.ts +2 -1
  54. package/lib/components/ConditionBuilder/index.d.ts.map +1 -1
  55. package/lib/components/ConditionBuilder/index.js.map +1 -1
  56. package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -1
  57. package/lib/components/ConditionInput/ConditionInput.js +110 -32
  58. package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
  59. package/lib/components/ConditionInput/ConditionInput.styles.d.ts +52 -4
  60. package/lib/components/ConditionInput/ConditionInput.styles.d.ts.map +1 -1
  61. package/lib/components/ConditionInput/ConditionInput.styles.js +4 -3
  62. package/lib/components/ConditionInput/ConditionInput.styles.js.map +1 -1
  63. package/lib/components/ConditionInput/ConditionInput.types.d.ts +4 -0
  64. package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -1
  65. package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -1
  66. package/lib/components/PromotedFilters/ConditionSelector.d.ts +2 -0
  67. package/lib/components/PromotedFilters/ConditionSelector.d.ts.map +1 -1
  68. package/lib/components/PromotedFilters/ConditionSelector.js +13 -20
  69. package/lib/components/PromotedFilters/ConditionSelector.js.map +1 -1
  70. package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
  71. package/lib/components/PromotedFilters/PromotedFilters.js +36 -25
  72. package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
  73. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +191 -3
  74. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -1
  75. package/lib/components/PromotedFilters/PromotedFilters.styles.js +13 -5
  76. package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +1 -1
  77. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +4 -0
  78. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -1
  79. package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -1
  80. package/package.json +4 -5
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.styles.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,sBAAsB,kNAWjC,CAAC;AAKH,eAAO,MAAM,SAAS,kNAOrB,CAAC;AAIF,eAAO,MAAM,yBAAyB,yGAIpC,CAAC;AAKH,eAAO,MAAM,sBAAsB,kNAgBlC,CAAC;AAKF,eAAO,MAAM,WAAW,yGASvB,CAAC;AAIF,eAAO,MAAM,qBAAqB,wNAkBhC,CAAC"}
1
+ {"version":3,"file":"ConditionBuilder.styles.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAGA,OAAO,EAKL,IAAI,EAGL,MAAM,yBAAyB,CAAC;AAIjC,eAAO,MAAM,sBAAsB,EAAE,OAAO,IAW1C,CAAC;AAKH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA4B,OAAO;mBAAiB,OAAO;kLA0B/E,CAAC;AAIH,eAAO,MAAM,yBAAyB,6NAIpC,CAAC;AAKH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAA4B,OAAO;kLAyCpE,CAAC;AAKH,eAAO,MAAM,WAAW,6NAkBvB,CAAC;AAIF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;eA7FG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;4OAmHpC,CAAC;AAIH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAAyB,OAAO;cAAY,OAAO;kLAsBnF,CAAC"}
@@ -1,5 +1,7 @@
1
1
  import styled, { css } from 'styled-components';
2
- import { calculateFontSize, defaultThemeProp, FieldGroup, Flex, StyledFieldGroupLegend, StyledPopover } from '@pega/cosmos-react-core';
2
+ import { transparentize } from 'polished';
3
+ import { readableColor, calculateFontSize, defaultThemeProp, FieldGroup, Flex, StyledFieldGroupLegend, StyledPopover } from '@pega/cosmos-react-core';
4
+ import { StyledMenuButton } from '@pega/cosmos-react-core/lib/components/MenuButton/MenuButton';
3
5
  export const StyledConditionBuilder = styled(Flex)(({ theme: { base: { 'content-width': contentWidth, spacing } } }) => {
4
6
  return css `
5
7
  ${StyledPopover}:has(&) {
@@ -10,14 +12,24 @@ export const StyledConditionBuilder = styled(Flex)(({ theme: { base: { 'content-
10
12
  });
11
13
  StyledConditionBuilder.defaultProps = defaultThemeProp;
12
14
  // Styled wrapper for each Condition row
13
- export const StyledRow = styled(Flex) `
14
- padding: 0.25rem;
15
- background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};
15
+ export const StyledRow = styled(Flex)(({ theme: { base: { spacing, palette: { 'border-line': borderLine, 'primary-background': background } } }, $nested, $isBasicMode }) => {
16
+ return css `
17
+ ${!!$nested &&
18
+ css `
19
+ padding: ${spacing};
20
+ background: ${transparentize(0.9, readableColor(background))};
21
+ `}
16
22
 
17
- &:first-of-type {
18
- padding-top: 0;
19
- }
20
- `;
23
+ ${!$isBasicMode &&
24
+ css `
25
+ & {
26
+ border-bottom: 0.0625rem solid ${borderLine};
27
+ padding-block-end: ${spacing};
28
+ margin-block-end: ${spacing};
29
+ }
30
+ `}
31
+ `;
32
+ });
21
33
  StyledRow.defaultProps = defaultThemeProp;
22
34
  export const StyledTimePeriodContainer = styled.div(({ theme }) => {
23
35
  return css `
@@ -26,46 +38,88 @@ export const StyledTimePeriodContainer = styled.div(({ theme }) => {
26
38
  });
27
39
  StyledTimePeriodContainer.defaultProps = defaultThemeProp;
28
40
  // Styled row-separators for Basic-mode
29
- export const StyledRowWithSeparator = styled(StyledRow) `
30
- padding: 0 0.25rem;
31
- &::after,
32
- &::before {
33
- content: '';
34
- flex-grow: 1;
35
- background-image: linear-gradient(to right, rgba(0, 0, 0, 0.4) 60%, rgba(0, 0, 0, 0) 0%);
36
- background-position: left center;
37
- background-size: 0.5rem 0.0625rem;
38
- background-repeat: repeat-x;
39
- }
41
+ export const StyledRowWithSeparator = styled(Flex)(({ $nested, theme: { base: { spacing, palette: { 'primary-background': background } } } }) => {
42
+ const readable = readableColor(background);
43
+ return css `
44
+ ${!!$nested &&
45
+ css `
46
+ padding: ${spacing};
47
+ background: ${transparentize(0.9, readable)};
48
+ `}
40
49
 
41
- &::before {
42
- width: 1rem;
43
- flex-grow: 0;
44
- }
45
- `;
50
+ &::after,
51
+ &::before {
52
+ content: '';
53
+ flex-grow: 1;
54
+ background-image: linear-gradient(
55
+ to right,
56
+ ${transparentize(0.8, readable)} 60%,
57
+ ${transparentize(1, readable)} 0%
58
+ );
59
+ background-position: left center;
60
+ background-size: 0.5rem 0.0625rem;
61
+ background-repeat: repeat-x;
62
+ }
63
+
64
+ &::before {
65
+ width: 1rem;
66
+ flex-grow: 0;
67
+ }
68
+
69
+ ${StyledMenuButton} {
70
+ background: none;
71
+ padding: 0;
72
+ }
73
+ `;
74
+ });
46
75
  StyledRowWithSeparator.defaultProps = defaultThemeProp;
47
76
  // Styled label for the rows in Advanced-mode
48
- export const StyledLabel = styled.div `
49
- font-weight: bold;
50
- line-height: 2rem;
51
- height: 2rem;
52
- width: 2rem;
53
- min-width: 2rem;
54
- margin-bottom: calc(0.125rem);
55
- text-align: center;
56
- background: rgba(0, 0, 0, 0.04);
57
- `;
77
+ export const StyledLabel = styled.div(({ theme: { base: { palette: { 'primary-background': background } } } }) => {
78
+ return css `
79
+ font-weight: bold;
80
+ line-height: 2rem;
81
+ height: 2rem;
82
+ width: 2rem;
83
+ min-width: 2rem;
84
+ text-align: center;
85
+ background: ${transparentize(0.9, readableColor(background))};
86
+ `;
87
+ });
58
88
  StyledLabel.defaultProps = defaultThemeProp;
59
89
  export const StyledAtomicCondition = styled(FieldGroup)(({ theme: { base: { 'font-size': fontSize, 'font-scale': fontScale, spacing }, components: { text } }, collapsed }) => {
60
90
  const fontSizes = calculateFontSize(fontSize, fontScale);
61
- return (!collapsed &&
91
+ return css `
92
+ ${!collapsed &&
62
93
  css `
63
94
  ${StyledFieldGroupLegend} {
64
95
  font-size: ${fontSizes[text.secondary['font-size']]};
65
96
  font-weight: ${text.secondary['font-weight']};
66
97
  margin-block-end: calc(0.5 * ${spacing});
67
98
  }
68
- `);
99
+ `}
100
+
101
+ fieldset {
102
+ min-width: unset;
103
+ }
104
+ `;
69
105
  });
70
106
  StyledAtomicCondition.defaultProps = defaultThemeProp;
107
+ /**
108
+ * Flex wrapper for items that should visually align with the input controls inside AtomicCondition
109
+ * - $row: applies the top-offset when in row layout (aligns with the top input)
110
+ * - $bottom: instead of aligning to the top input, sinks the item to the bottom of the row
111
+ */
112
+ export const StyledInputLevelItem = styled(Flex)(({ theme: { base: { 'hit-area': { 'compact-min': compactMin }, spacing } }, $row, $bottom }) => css `
113
+ ${$row &&
114
+ !$bottom &&
115
+ css `
116
+ padding-block-start: calc(${compactMin} + 0.25 * ${spacing});
117
+ `}
118
+ ${$row &&
119
+ $bottom &&
120
+ css `
121
+ margin-block-start: auto;
122
+ `}
123
+ `);
124
+ StyledInputLevelItem.defaultProps = defaultThemeProp;
71
125
  //# sourceMappingURL=ConditionBuilder.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.styles.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,sBAAsB,EACtB,aAAa,EACd,MAAM,yBAAyB,CAAC;AAGjC,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAClD,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,eAAe,EAAE,YAAY,EAAE,OAAO,EAAE,EACjD,EACF,EAAE,EAAE;IACH,OAAO,GAAG,CAAA;MACN,aAAa;6BACU,YAAY,CAAC,EAAE,sBAAsB,OAAO;0CAC/B,OAAO;;GAE9C,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEvD,wCAAwC;AACxC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;gBAErB,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,aAAa,CAAC;;;;;CAK9E,CAAC;AAEF,SAAS,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE1C,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAChE,OAAO,GAAG,CAAA;aACC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE;GACxC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,yBAAyB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE1D,uCAAuC;AACvC,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;;;;;;;;;;;;;;;;CAgBtD,CAAC;AAEF,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEvD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;CASpC,CAAC;AAEF,WAAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EACvD,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,EACjE,UAAU,EAAE,EAAE,IAAI,EAAE,EACrB,EACD,SAAS,EACV,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACzD,OAAO,CACL,CAAC,SAAS;QACV,GAAG,CAAA;QACC,sBAAsB;qBACT,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAa,CAAC;uBAChD,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;uCACb,OAAO;;KAEzC,CACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport {\n calculateFontSize,\n defaultThemeProp,\n FieldGroup,\n Flex,\n StyledFieldGroupLegend,\n StyledPopover\n} from '@pega/cosmos-react-core';\nimport type { FontSize } from '@pega/cosmos-react-core';\n\nexport const StyledConditionBuilder = styled(Flex)(({\n theme: {\n base: { 'content-width': contentWidth, spacing }\n }\n}) => {\n return css`\n ${StyledPopover}:has(&) {\n min-inline-size: min(${contentWidth.lg}, calc(100vw - 4 * ${spacing}));\n max-inline-size: calc(100vw - 4 * ${spacing});\n }\n `;\n});\n\nStyledConditionBuilder.defaultProps = defaultThemeProp;\n\n// Styled wrapper for each Condition row\nexport const StyledRow = styled(Flex)`\n padding: 0.25rem;\n background: ${props => (props.shaded ? 'rgba(0, 0, 0, 0.05)' : 'transparent')};\n\n &:first-of-type {\n padding-top: 0;\n }\n`;\n\nStyledRow.defaultProps = defaultThemeProp;\n\nexport const StyledTimePeriodContainer = styled.div(({ theme }) => {\n return css`\n width: ${theme.base['content-width'].sm};\n `;\n});\n\nStyledTimePeriodContainer.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nexport const StyledRowWithSeparator = styled(StyledRow)`\n padding: 0 0.25rem;\n &::after,\n &::before {\n content: '';\n flex-grow: 1;\n background-image: linear-gradient(to right, rgba(0, 0, 0, 0.4) 60%, rgba(0, 0, 0, 0) 0%);\n background-position: left center;\n background-size: 0.5rem 0.0625rem;\n background-repeat: repeat-x;\n }\n\n &::before {\n width: 1rem;\n flex-grow: 0;\n }\n`;\n\nStyledRowWithSeparator.defaultProps = defaultThemeProp;\n\n// Styled label for the rows in Advanced-mode\nexport const StyledLabel = styled.div`\n font-weight: bold;\n line-height: 2rem;\n height: 2rem;\n width: 2rem;\n min-width: 2rem;\n margin-bottom: calc(0.125rem);\n text-align: center;\n background: rgba(0, 0, 0, 0.04);\n`;\n\nStyledLabel.defaultProps = defaultThemeProp;\n\nexport const StyledAtomicCondition = styled(FieldGroup)(({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale, spacing },\n components: { text }\n },\n collapsed\n}) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n return (\n !collapsed &&\n css`\n ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.secondary['font-size'] as FontSize]};\n font-weight: ${text.secondary['font-weight']};\n margin-block-end: calc(0.5 * ${spacing});\n }\n `\n );\n});\n\nStyledAtomicCondition.defaultProps = defaultThemeProp;\n"]}
1
+ {"version":3,"file":"ConditionBuilder.styles.js","sourceRoot":"","sources":["../../../src/components/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AAW,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE5C,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EACvD,KAAK,EAAE,EACL,IAAI,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,EACjE,UAAU,EAAE,EAAE,IAAI,EAAE,EACrB,EACD,SAAS,EACV,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IACzD,OAAO,GAAG,CAAA;MACN,CAAC,SAAS;QACZ,GAAG,CAAA;QACC,sBAAsB;qBACT,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAa,CAAC;uBAChD,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC;uCACb,OAAO;;KAEzC;;;;;GAKF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,CAC9C,CAAC,EACC,KAAK,EAAE,EACL,IAAI,EAAE,EACJ,UAAU,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,EACzC,OAAO,EACR,EACF,EACD,IAAI,EACJ,OAAO,EACR,EAAE,EAAE,CAAC,GAAG,CAAA;MACL,IAAI;IACN,CAAC,OAAO;IACR,GAAG,CAAA;kCAC2B,UAAU,aAAa,OAAO;KAC3D;MACC,IAAI;IACN,OAAO;IACP,GAAG,CAAA;;KAEF;GACF,CACF,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\nimport { transparentize } from 'polished';\n\nimport {\n readableColor,\n calculateFontSize,\n defaultThemeProp,\n FieldGroup,\n Flex,\n StyledFieldGroupLegend,\n StyledPopover\n} from '@pega/cosmos-react-core';\nimport type { FontSize } from '@pega/cosmos-react-core';\nimport { StyledMenuButton } from '@pega/cosmos-react-core/lib/components/MenuButton/MenuButton';\n\nexport const StyledConditionBuilder: typeof Flex = styled(Flex)(({\n theme: {\n base: { 'content-width': contentWidth, spacing }\n }\n}) => {\n return css`\n ${StyledPopover}:has(&) {\n min-inline-size: min(${contentWidth.lg}, calc(100vw - 4 * ${spacing}));\n max-inline-size: calc(100vw - 4 * ${spacing});\n }\n `;\n});\n\nStyledConditionBuilder.defaultProps = defaultThemeProp;\n\n// Styled wrapper for each Condition row\nexport const StyledRow = styled(Flex)<{ $nested?: boolean; $isBasicMode?: boolean }>(({\n theme: {\n base: {\n spacing,\n palette: { 'border-line': borderLine, 'primary-background': background }\n }\n },\n $nested,\n $isBasicMode\n}) => {\n return css`\n ${!!$nested &&\n css`\n padding: ${spacing};\n background: ${transparentize(0.9, readableColor(background))};\n `}\n\n ${!$isBasicMode &&\n css`\n & {\n border-bottom: 0.0625rem solid ${borderLine};\n padding-block-end: ${spacing};\n margin-block-end: ${spacing};\n }\n `}\n `;\n});\n\nStyledRow.defaultProps = defaultThemeProp;\n\nexport const StyledTimePeriodContainer = styled.div(({ theme }) => {\n return css`\n width: ${theme.base['content-width'].sm};\n `;\n});\n\nStyledTimePeriodContainer.defaultProps = defaultThemeProp;\n\n// Styled row-separators for Basic-mode\nexport const StyledRowWithSeparator = styled(Flex)<{ $nested?: boolean }>(({\n $nested,\n theme: {\n base: {\n spacing,\n palette: { 'primary-background': background }\n }\n }\n}) => {\n const readable = readableColor(background);\n return css`\n ${!!$nested &&\n css`\n padding: ${spacing};\n background: ${transparentize(0.9, readable)};\n `}\n\n &::after,\n &::before {\n content: '';\n flex-grow: 1;\n background-image: linear-gradient(\n to right,\n ${transparentize(0.8, readable)} 60%,\n ${transparentize(1, readable)} 0%\n );\n background-position: left center;\n background-size: 0.5rem 0.0625rem;\n background-repeat: repeat-x;\n }\n\n &::before {\n width: 1rem;\n flex-grow: 0;\n }\n\n ${StyledMenuButton} {\n background: none;\n padding: 0;\n }\n `;\n});\n\nStyledRowWithSeparator.defaultProps = defaultThemeProp;\n\n// Styled label for the rows in Advanced-mode\nexport const StyledLabel = styled.div(\n ({\n theme: {\n base: {\n palette: { 'primary-background': background }\n }\n }\n }) => {\n return css`\n font-weight: bold;\n line-height: 2rem;\n height: 2rem;\n width: 2rem;\n min-width: 2rem;\n text-align: center;\n background: ${transparentize(0.9, readableColor(background))};\n `;\n }\n);\n\nStyledLabel.defaultProps = defaultThemeProp;\n\nexport const StyledAtomicCondition = styled(FieldGroup)(({\n theme: {\n base: { 'font-size': fontSize, 'font-scale': fontScale, spacing },\n components: { text }\n },\n collapsed\n}) => {\n const fontSizes = calculateFontSize(fontSize, fontScale);\n return css`\n ${!collapsed &&\n css`\n ${StyledFieldGroupLegend} {\n font-size: ${fontSizes[text.secondary['font-size'] as FontSize]};\n font-weight: ${text.secondary['font-weight']};\n margin-block-end: calc(0.5 * ${spacing});\n }\n `}\n\n fieldset {\n min-width: unset;\n }\n `;\n});\n\nStyledAtomicCondition.defaultProps = defaultThemeProp;\n\n/**\n * Flex wrapper for items that should visually align with the input controls inside AtomicCondition\n * - $row: applies the top-offset when in row layout (aligns with the top input)\n * - $bottom: instead of aligning to the top input, sinks the item to the bottom of the row\n */\nexport const StyledInputLevelItem = styled(Flex)<{ $row?: boolean; $bottom?: boolean }>(\n ({\n theme: {\n base: {\n 'hit-area': { 'compact-min': compactMin },\n spacing\n }\n },\n $row,\n $bottom\n }) => css`\n ${$row &&\n !$bottom &&\n css`\n padding-block-start: calc(${compactMin} + 0.25 * ${spacing});\n `}\n ${$row &&\n $bottom &&\n css`\n margin-block-start: auto;\n `}\n `\n);\n\nStyledInputLevelItem.defaultProps = defaultThemeProp;\n"]}
@@ -1,6 +1,7 @@
1
- import type { Ref } from 'react';
1
+ import type { ReactNode, Ref } from 'react';
2
2
  import type { BaseProps, MenuItemProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
3
  import type { Comparator, ComparatorsByType, DateFunction, DatePart, FieldType, RHSType, TimePeriod } from './core/types';
4
+ import type { AtomicConditionProps } from './AtomicCondition';
4
5
  /** RHS object with a Date function */
5
6
  export interface RhsWithDateFunction {
6
7
  /**
@@ -49,6 +50,7 @@ export interface LeafCondition {
49
50
  start: string | number;
50
51
  end: string | number;
51
52
  } | RhsWithDateFunction | RhsWithRelativeDate | RhsWithParameter;
53
+ lhsType?: string;
52
54
  }
53
55
  /** Type definition for objects representing condition-rows in the builder UI */
54
56
  export interface ConditionRow extends LeafCondition {
@@ -99,6 +101,11 @@ export type Field = BasicField & ({
99
101
  * e.g. Text(single value)/Picklist/... should be used as `TEXT`
100
102
  */
101
103
  type: FieldType;
104
+ /**
105
+ * Used to handle percentages are stored in the database,
106
+ * determine whether value is stored in the range of 0 to 1 or 0 to 100
107
+ */
108
+ unit?: 'percent_1' | 'percent_100';
102
109
  } | {
103
110
  /** An array of type Field to represent the child items. */
104
111
  items: Field[];
@@ -110,17 +117,28 @@ export interface DateFunctionsByType {
110
117
  /** Date functions to enable for DATE_ONLY fields */
111
118
  DATE_ONLY: DateFunction[];
112
119
  }
120
+ export type ValidationOptions = {
121
+ /**
122
+ * Whether to validate individual condition rows for completeness.
123
+ *
124
+ * When `true` (default): Validates each row's LHS, comparator, and RHS fields
125
+ * When `false`: Only validates the overall logic string structure
126
+ */
127
+ performRowValidation?: boolean;
128
+ };
113
129
  export interface HandleValue {
114
130
  /**
115
131
  * Returns condition validity and condition or undefined if valid.
116
132
  * Undefined indicates no condition.
117
133
  */
118
- getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];
134
+ getCondition: (options?: ValidationOptions) => [valid: false] | [valid: true, condition: Condition | undefined];
135
+ getLogicError: () => string | null;
119
136
  }
120
137
  /** Type definition for the input props of ConditionBuilder */
121
138
  export default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {
122
139
  /** Metadata (data-model) for the Fields to use in the builder */
123
140
  fields: Field[];
141
+ conditionRenderer?: (props: AtomicConditionProps) => ReactNode;
124
142
  /** (Optional) A seed condition for the builder. To use when editing an existing condition */
125
143
  condition?: Condition;
126
144
  /** (Optional) Used to limit the Comparators allowed in the builder. */
@@ -133,10 +151,32 @@ export default interface ConditionBuilderProps extends BaseProps, NoChildrenProp
133
151
  validRhsTypes?: Set<RHSType>;
134
152
  /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */
135
153
  dateFunctions?: DateFunctionsByType;
154
+ /** (Optional) IANA timezone string used to initialize date/time pickers with the operator's timezone */
155
+ timeZone?: string;
136
156
  /** (Optional) Pass this if the `NOT` operator should be considered as invalid */
137
157
  disallowNOT?: boolean;
138
158
  /** Imperative handle for the component. */
139
159
  handle?: Ref<HandleValue>;
160
+ /** Callback fired when a row is added */
161
+ onAddRow?: (rowIndex: number) => void;
162
+ /** Callback fired when a row is deleted */
163
+ onDeleteRow?: (rowIndex: number) => void;
164
+ /**
165
+ * Callback fired when logic string validation error occurs or clears.
166
+ */
167
+ onLogicError?: (error: string | null) => void;
168
+ /**
169
+ * Callback fired when condition data changes.
170
+ */
171
+ onConditionChange?: () => void;
172
+ /** Makes the input non editable and non clickable. The browser defaults to false. */
173
+ readOnly?: boolean;
174
+ /** Disable the control. The browser defaults to false. */
175
+ disabled?: boolean;
176
+ /**
177
+ * Ref to access the root HTMLDivElement of the ConditionBuilder.
178
+ */
179
+ ref?: Ref<HTMLDivElement>;
140
180
  }
141
181
  export {};
142
182
  //# sourceMappingURL=ConditionBuilder.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAExF,OAAO,KAAK,EACV,UAA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SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC;CACtF;AAED,8DAA8D;AAC9D,MAAM,CAAC,OAAO,WAAW,qBAAsB,SAAQ,SAAS,EAAE,cAAc;IAC9E,iEAAiE;IACjE,MAAM,EAAE,KAAK,EAAE,CAAC;IAEhB,6FAA6F;IAC7F,SAAS,CAAC,EAAE,SAAS,CAAC;IAEtB,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAE7B,iJAAiJ;IACjJ,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,iFAAiF;IACjF,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;CAC3B"}
1
+ {"version":3,"file":"ConditionBuilder.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAExF,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,OAAO,EACP,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,sCAAsC;AACtC,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;;;;;OAcG;IACH,KAAK,EAA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AM,IAAI,CAAC;IAE/B,qFAAqF;IACrF,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;OAEG;IACH,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:words DDTHH\nimport type { Ref } from 'react';\n\nimport type { BaseProps, MenuItemProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport type {\n Comparator,\n ComparatorsByType,\n DateFunction,\n DatePart,\n FieldType,\n RHSType,\n TimePeriod\n} from './core/types';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MINUTES: YYYY-MM-DDTHH:mm:ss\n * SECONDS: YYYY-MM-DDTHH:mm:ss\n * HOURS_OF_DAY: 0-23\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | { start: string | number; end: string | number } // When comparing numeric or date field with two values that determine range\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelectionFunction<F> = (\n args:\n | { lhs?: F; ids: string[] }\n | {\n lhs?: F;\n searchString?: string; // If missing, assume empty string\n comparator?: string; // If missing, assume EQ\n\n // If the below are missing, fetch maximum possible results\n pageNumber?: number;\n pageSize?: number;\n }\n) => Promise<string[] | ReferenceValue[]>;\n\nexport type ValueSelection<F> = string[] | ReferenceValue[] | ValueSelectionFunction<F>;\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Currency/Percentage... should be used as `DECIMAL`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n }\n | {\n /** An array of type Field to represent the child items. */\n items: Field[];\n }\n );\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition or undefined if valid.\n * Undefined indicates no condition.\n */\n getCondition: () => [valid: false] | [valid: true, condition: Condition | undefined];\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n}\n"]}
1
+ {"version":3,"file":"ConditionBuilder.types.js","sourceRoot":"","sources":["../../../src/components/ConditionBuilder/ConditionBuilder.types.ts"],"names":[],"mappings":"","sourcesContent":["// cspell:words DDTHH\nimport type { ReactNode, Ref } from 'react';\n\nimport type { BaseProps, MenuItemProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport type {\n Comparator,\n ComparatorsByType,\n DateFunction,\n DatePart,\n FieldType,\n RHSType,\n TimePeriod\n} from './core/types';\nimport type { AtomicConditionProps } from './AtomicCondition';\n\n/** RHS object with a Date function */\nexport interface RhsWithDateFunction {\n /**\n * Output format for the value varies based on the dateFunction:\n * YEARS: First day of year as YYYY-MM-DD\n * QUARTERS: First day of quarter as YYYY-MM-DD\n * MONTHS: First day of month as YYYY-MM-DD\n * WEEKS: First day of week as YYYY-MM-DD\n * DAYS: Date as YYYY-MM-DD\n * HOURS: YYYY-MM-DDTHH:mm:ss\n * MINUTES: YYYY-MM-DDTHH:mm:ss\n * SECONDS: YYYY-MM-DDTHH:mm:ss\n * HOURS_OF_DAY: 0-23\n * MONTHS_OF_YEAR: 1-12\n * DAYS_OF_MONTH: 1-31\n * DAYS_OF_WEEK: 1-7\n */\n value: string | number;\n dateFunction: DateFunction;\n}\n\n/** RHS object with a Relative Date */\nexport interface RhsWithRelativeDate {\n relativeDate: {\n timePeriod: TimePeriod;\n interval?: number;\n datePart: DatePart;\n };\n}\n\n/** RHS object with PARAMETER type */\nexport interface RhsWithParameter {\n parameterId: string;\n}\n\n/** Type definition for the leaf-level nodes in nested conditions */\nexport interface LeafCondition {\n comparator: Comparator;\n\n lhs: {\n field: string;\n };\n\n // Optional for some of the comparators like IS_TRUE, IS_NULL, etc.\n rhs?:\n | { field: string } // When comparing the LHS with another field\n | { value: string | number } // When comparing the LHS with a single literal value (for comparators like EQ, GTE etc.)\n | { values: string[] | number[] } // When comparing the LHS with a list of literal values (for comparators like IN, NOT_IN etc.)\n | { start: string | number; end: string | number } // When comparing numeric or date field with two values that determine range\n | RhsWithDateFunction // When comparing a date field with a date function on RHS\n | RhsWithRelativeDate // When comparing a date field with a symbolic date on RHS\n | RhsWithParameter; // When comparing the LHS with PARAMETER type\n lhsType?: string;\n}\n\n/** Type definition for objects representing condition-rows in the builder UI */\nexport interface ConditionRow extends LeafCondition {\n id: string; // To use as `key` prop when rendering a list of rows\n label: string; // Used to refer the row from a logic-string\n}\n\n/**\n * Type definition for simple/complex conditions\n * At a given node in the condition tree, it can have exactly one of the keys AND/OR/NOT/condition\n */\nexport type Condition =\n | { AND: Condition[] }\n | { OR: Condition[] }\n | { NOT: Condition }\n | { condition: LeafCondition };\n\n/** Type definition for the input Field objects for the ConditionBuilder */\n\nexport type ParameterValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ReferenceValue = Pick<MenuItemProps, 'id' | 'primary'>;\n\nexport type ValueSelectionFunction<F> = (\n args:\n | { lhs?: F; ids: string[] }\n | {\n lhs?: F;\n searchString?: string; // If missing, assume empty string\n comparator?: string; // If missing, assume EQ\n\n // If the below are missing, fetch maximum possible results\n pageNumber?: number;\n pageSize?: number;\n }\n) => Promise<string[] | ReferenceValue[]>;\n\nexport type ValueSelection<F> = string[] | ReferenceValue[] | ValueSelectionFunction<F>;\n\ninterface BasicField extends Pick<MenuItemProps, 'id' | 'primary'> {}\n\nexport type Field = BasicField &\n (\n | {\n parameters?: ParameterValue[];\n\n /**\n * For TEXT fields, if a list of possible values is known ahead of time, they can be passed.\n * Otherwise we fetch data from api and pass a promise which returns list of values\n * This enables users to select from those values instead of manually typing them\n */\n possibleValues?: ValueSelection<Field>;\n\n /**\n * Data-type for the field.\n * Has to be one of these values. Convert where necessary\n * e.g. Currency/Percentage... should be used as `DECIMAL`\n * e.g. Text(single value)/Picklist/... should be used as `TEXT`\n */\n type: FieldType;\n\n /**\n * Used to handle percentages are stored in the database,\n * determine whether value is stored in the range of 0 to 1 or 0 to 100\n */\n unit?: 'percent_1' | 'percent_100';\n }\n | {\n /** An array of type Field to represent the child items. */\n items: Field[];\n }\n );\n\n/** Valid date functions by field type */\nexport interface DateFunctionsByType {\n /** Date functions to enable for DATE_TIME fields */\n DATE_TIME: DateFunction[];\n /** Date functions to enable for DATE_ONLY fields */\n DATE_ONLY: DateFunction[];\n}\n\nexport type ValidationOptions = {\n /**\n * Whether to validate individual condition rows for completeness.\n *\n * When `true` (default): Validates each row's LHS, comparator, and RHS fields\n * When `false`: Only validates the overall logic string structure\n */\n performRowValidation?: boolean;\n};\n\nexport interface HandleValue {\n /**\n * Returns condition validity and condition or undefined if valid.\n * Undefined indicates no condition.\n */\n getCondition: (\n options?: ValidationOptions\n ) => [valid: false] | [valid: true, condition: Condition | undefined];\n getLogicError: () => string | null;\n}\n\n/** Type definition for the input props of ConditionBuilder */\nexport default interface ConditionBuilderProps extends BaseProps, NoChildrenProp {\n /** Metadata (data-model) for the Fields to use in the builder */\n fields: Field[];\n\n conditionRenderer?: (props: AtomicConditionProps) => ReactNode;\n\n /** (Optional) A seed condition for the builder. To use when editing an existing condition */\n condition?: Condition;\n\n /** (Optional) Used to limit the Comparators allowed in the builder. */\n validComparators?: ComparatorsByType[];\n\n /**\n * (Optional) Pass this to control which all types of RHS are enabled in the component\n * DEFAULT: Set(['LITERAL', 'FIELD'])\n * NOTE: If enabling `DATE_FUNCTION`s, additionally pass a `dateFunctions` prop to specify which functions are enabled\n */\n validRhsTypes?: Set<RHSType>;\n\n /** (Optional) When enabling 'DATE_FUNCTION's via `validRhsTypes`, pass this to specify which all date functions are applicable per field type */\n dateFunctions?: DateFunctionsByType;\n\n /** (Optional) IANA timezone string used to initialize date/time pickers with the operator's timezone */\n timeZone?: string;\n\n /** (Optional) Pass this if the `NOT` operator should be considered as invalid */\n disallowNOT?: boolean;\n\n /** Imperative handle for the component. */\n handle?: Ref<HandleValue>;\n\n /** Callback fired when a row is added */\n onAddRow?: (rowIndex: number) => void;\n\n /** Callback fired when a row is deleted */\n onDeleteRow?: (rowIndex: number) => void;\n\n /**\n * Callback fired when logic string validation error occurs or clears.\n */\n onLogicError?: (error: string | null) => void;\n\n /**\n * Callback fired when condition data changes.\n */\n onConditionChange?: () => void;\n\n /** Makes the input non editable and non clickable. The browser defaults to false. */\n readOnly?: boolean;\n\n /** Disable the control. The browser defaults to false. */\n disabled?: boolean;\n\n /**\n * Ref to access the root HTMLDivElement of the ConditionBuilder.\n */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { type FormControlProps } from '@pega/cosmos-react-core';
2
+ import type { Field, LeafCondition } from '../ConditionBuilder.types';
3
+ import type { FieldType } from '../core/types';
4
+ type CSVField = Field & {
5
+ type: FieldType;
6
+ unit?: 'percent_1' | 'percent_100';
7
+ };
8
+ export interface CSVInputProps extends FormControlProps {
9
+ /** Rhs for the condition */
10
+ rhs?: LeafCondition['rhs'];
11
+ /** Field associated with the condition */
12
+ field: CSVField;
13
+ /** Callback for any modifications to the Rhs */
14
+ onChange: (rhs: LeafCondition['rhs']) => void;
15
+ }
16
+ export declare const CSVInput: ({ rhs, field, onChange, ...restProps }: CSVInputProps) => import("react/jsx-runtime").JSX.Element;
17
+ export {};
18
+ //# sourceMappingURL=CSVInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CSVInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/CSVInput.tsx"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C,KAAK,QAAQ,GAAG,KAAK,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,CAAA;CAAE,CAAC;AAEhF,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,4BAA4B;IAC5B,GAAG,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3B,0CAA0C;IAC1C,KAAK,EAAE,QAAQ,CAAC;IAChB,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE,aAAa,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;CAC/C;AAED,eAAO,MAAM,QAAQ,GAAI,wCAAwC,aAAa,4CA6D7E,CAAC"}
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useState } from 'react';
3
+ import { hasProp, Input, useAfterInitialEffect } from '@pega/cosmos-react-core';
4
+ export const CSVInput = ({ rhs, field, onChange, ...restProps }) => {
5
+ const fieldType = field.type;
6
+ const fieldUnit = field.unit;
7
+ // Set up a CSV input for IN/NOT_IN comparators
8
+ const [csvInput, setCsvInput] = useState(() => {
9
+ if (rhs && hasProp(rhs, 'values')) {
10
+ if ((fieldType === 'DECIMAL' || fieldType === 'INTEGER') && fieldUnit === 'percent_1') {
11
+ return rhs.values
12
+ .map(v => (typeof v === 'number' ? parseFloat((v * 100).toFixed(2)) : v))
13
+ .join(', ');
14
+ }
15
+ return rhs.values.join(', ');
16
+ }
17
+ return '';
18
+ });
19
+ useEffect(() => {
20
+ // If moving away from the CSV-mode, clear the CSV Input.
21
+ // This ensures that if a different `rhs.values` is passed (a new empty array can be passed when an applicable comparator is selected), the local state matches the new input.
22
+ if (csvInput && (!rhs || !hasProp(rhs, 'values'))) {
23
+ setCsvInput('');
24
+ }
25
+ }, [rhs]);
26
+ useAfterInitialEffect(() => {
27
+ if (rhs && hasProp(rhs, 'values')) {
28
+ if ((fieldType === 'DECIMAL' || fieldType === 'INTEGER') && fieldUnit === 'percent_1') {
29
+ setCsvInput(rhs.values
30
+ .map(v => (typeof v === 'number' ? parseFloat((v * 100).toFixed(2)) : v))
31
+ .join(', '));
32
+ }
33
+ else {
34
+ setCsvInput(rhs.values.join(', '));
35
+ }
36
+ }
37
+ }, [rhs]);
38
+ const handleChange = (e) => {
39
+ setCsvInput(e.target.value);
40
+ };
41
+ const handleBlur = () => {
42
+ // Submit a new RHS
43
+ let newValues = csvInput
44
+ .split(',')
45
+ .map(v => v.trim())
46
+ .filter(v => v.length > 0); // Ignore empty strings
47
+ if (fieldType === 'DECIMAL' || fieldType === 'INTEGER') {
48
+ newValues = newValues.map(v => {
49
+ if (fieldUnit === 'percent_1' && !Number.isNaN(Number(v))) {
50
+ return Number(v) / 100;
51
+ }
52
+ return Number(v);
53
+ }); // This can set up some NaN values. Those are used to show an appropriate feedback when the submit button is hit
54
+ }
55
+ onChange({ values: newValues });
56
+ };
57
+ return _jsx(Input, { ...restProps, value: csvInput, onChange: handleChange, onBlur: handleBlur });
58
+ };
59
+ //# sourceMappingURL=CSVInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CSVInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/CSVInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAoB,MAAM,OAAO,CAAC;AAE9D,OAAO,EACL,OAAO,EACP,KAAK,EACL,qBAAqB,EAEtB,MAAM,yBAAyB,CAAC;AAgBjC,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAiB,EAAE,EAAE;IAChF,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;IAC7B,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;IAE7B,+CAA+C;IAC/C,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC5C,IAAI,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,CAAC,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;gBACtF,OAAO,GAAG,CAAC,MAAM;qBACd,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBACxE,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,CAAC;YACD,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAA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AK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aAClB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,uBAAuB;QACrD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;YACvD,SAAS,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBAC5B,IAAI,SAAS,KAAK,WAAW,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC1D,OAAO,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;gBACzB,CAAC;gBACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC,CAAC,CAAC,CAAC,gHAAgH;QACtH,CAAC;QACD,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;IAClC,CAAC,CAAC;IAEF,OAAO,KAAC,KAAK,OAAK,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,GAAI,CAAC;AAC/F,CAAC,CAAC","sourcesContent":["import { useEffect, useState, type ChangeEvent } from 'react';\n\nimport {\n hasProp,\n Input,\n useAfterInitialEffect,\n type FormControlProps\n} from '@pega/cosmos-react-core';\n\nimport type { Field, LeafCondition } from '../ConditionBuilder.types';\nimport type { FieldType } from '../core/types';\n\ntype CSVField = Field & { type: FieldType; unit?: 'percent_1' | 'percent_100' };\n\nexport interface CSVInputProps extends FormControlProps {\n /** Rhs for the condition */\n rhs?: LeafCondition['rhs'];\n /** Field associated with the condition */\n field: CSVField;\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: LeafCondition['rhs']) => void;\n}\n\nexport const CSVInput = ({ rhs, field, onChange, ...restProps }: CSVInputProps) => {\n const fieldType = field.type;\n const fieldUnit = field.unit;\n\n // Set up a CSV input for IN/NOT_IN comparators\n const [csvInput, setCsvInput] = useState(() => {\n if (rhs && hasProp(rhs, 'values')) {\n if ((fieldType === 'DECIMAL' || fieldType === 'INTEGER') && fieldUnit === 'percent_1') {\n return rhs.values\n .map(v => (typeof v === 'number' ? parseFloat((v * 100).toFixed(2)) : v))\n .join(', ');\n }\n return rhs.values.join(', ');\n }\n return '';\n });\n\n useEffect(() => {\n // If moving away from the CSV-mode, clear the CSV Input.\n // This ensures that if a different `rhs.values` is passed (a new empty array can be passed when an applicable comparator is selected), the local state matches the new input.\n if (csvInput && (!rhs || !hasProp(rhs, 'values'))) {\n setCsvInput('');\n }\n }, [rhs]);\n\n useAfterInitialEffect(() => {\n if (rhs && hasProp(rhs, 'values')) {\n if ((fieldType === 'DECIMAL' || fieldType === 'INTEGER') && fieldUnit === 'percent_1') {\n setCsvInput(\n rhs.values\n .map(v => (typeof v === 'number' ? parseFloat((v * 100).toFixed(2)) : v))\n .join(', ')\n );\n } else {\n setCsvInput(rhs.values.join(', '));\n }\n }\n }, [rhs]);\n\n const handleChange = (e: ChangeEvent<HTMLInputElement>) => {\n setCsvInput(e.target.value);\n };\n\n const handleBlur = () => {\n // Submit a new RHS\n let newValues: string[] | number[] = csvInput\n .split(',')\n .map(v => v.trim())\n .filter(v => v.length > 0); // Ignore empty strings\n if (fieldType === 'DECIMAL' || fieldType === 'INTEGER') {\n newValues = newValues.map(v => {\n if (fieldUnit === 'percent_1' && !Number.isNaN(Number(v))) {\n return Number(v) / 100;\n }\n return Number(v);\n }); // This can set up some NaN values. Those are used to show an appropriate feedback when the submit button is hit\n }\n onChange({ values: newValues });\n };\n\n return <Input {...restProps} value={csvInput} onChange={handleChange} onBlur={handleBlur} />;\n};\n"]}
@@ -13,6 +13,8 @@ interface NumericInputProps extends BaseProps, NoChildrenProp {
13
13
  status?: 'error';
14
14
  /** Determines whether decimals can be entered */
15
15
  allowDecimal?: boolean;
16
+ /** Determines whether value is stored in the database in the range of 0 to 1 or 0 to 100 */
17
+ unit?: 'percent_1' | 'percent_100';
16
18
  }
17
19
  /** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */
18
20
  declare const NumericInput: FunctionComponent<NumericInputProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,UAAU,iBAAkB,SAAQ,SAAS,EAAE,cAAc;IAC3D,4BAA4B;IAC5B,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAEhC,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAEpD,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IAEjB,iDAAiD;IACjD,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA4BtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzE,UAAU,iBAAkB,SAAQ,SAAS,EAAE,cAAc;IAC3D,4BAA4B;IAC5B,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAChC,gDAAgD;IAChD,QAAQ,EAAE,CAAC,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACpD,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,4FAA4F;IAC5F,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC;CACpC;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAgDtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -3,20 +3,36 @@ import { useState } from 'react';
3
3
  import { NumberInput, useAfterInitialEffect, useI18n } from '@pega/cosmos-react-core';
4
4
  /** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */
5
5
  const NumericInput = (props) => {
6
- const { rhs, onChange, status, allowDecimal = true } = props;
6
+ const { rhs, onChange, status, allowDecimal = true, unit } = props;
7
7
  const t = useI18n();
8
+ // Formats a value as a percentage and fixes floating point rounding errors in input box
9
+ const convertPercentToDisplayValue = (value) => {
10
+ if (unit === 'percent_1' && typeof value === 'number') {
11
+ return parseFloat((value * 100).toFixed(2));
12
+ }
13
+ return value;
14
+ };
8
15
  // Since we want to always call onChange with parsed Numbers,
9
16
  // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX
10
17
  // Using a local state to avoid that
11
- const [localValue, setLocalValue] = useState(rhs.value.toString());
18
+ const [localValue, setLocalValue] = useState(convertPercentToDisplayValue(rhs.value).toString());
12
19
  useAfterInitialEffect(() => {
13
- setLocalValue(rhs.value.toString());
20
+ setLocalValue(convertPercentToDisplayValue(rhs.value).toString());
14
21
  }, [rhs.value]);
15
22
  const handleInputChange = (newValue) => {
16
23
  setLocalValue(newValue);
17
- onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty
18
24
  };
19
- return (_jsx(NumberInput, { value: localValue, onChange: handleInputChange, status: status, info: status === 'error' ? t('condition_builder_invalid_number') : undefined, label: t('condition_builder_value_label'), numberOfDecimals: allowDecimal ? undefined : 0 }));
25
+ const handleBlur = (newValue) => {
26
+ let outValue = '';
27
+ if (newValue) {
28
+ const valueAsNumber = Number(newValue);
29
+ if (!Number.isNaN(valueAsNumber)) {
30
+ outValue = unit === 'percent_1' ? valueAsNumber / 100 : valueAsNumber;
31
+ }
32
+ }
33
+ onChange({ value: outValue });
34
+ };
35
+ return (_jsx(NumberInput, { value: localValue, onChange: handleInputChange, onBlur: handleBlur, status: status, info: status === 'error' ? t('condition_builder_invalid_number') : undefined, label: t('condition_builder_value_label'), numberOfDecimals: allowDecimal ? undefined : 0, unit: unit === 'percent_1' || unit === 'percent_100' ? 'percent' : undefined }));
20
36
  };
21
37
  export default NumericInput;
22
38
  //# sourceMappingURL=NumericInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAiBtF,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAC7D,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,6DAA6D;IAC7D,2FAA2F;IAC3F,oCAAoC;IACpC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAEnE,qBAAqB,CAAC,GAAG,EAAE;QACzB,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IACtC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;IAEhB,MAAM,iBAAiB,GAAG,CAAC,QAAgB,EAAE,EAAE;QAC7C,aAAa,CAAC,QAAQ,CAAC,CAAC;QACxB,QAAQ,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,6CAA6C;IAC7G,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,WAAW,IACV,KAAK,EAAE,UAAU,EACjB,QAAQ,EAAE,iBAAiB,EAC3B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,kCAAkC,CAAC,CAAC,CAAC,CAAC,SAAS,EAC5E,KAAK,EAAE,CAAC,CAAC,+BAA+B,CAAC,EACzC,gBAAgB,EAAE,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAC9C,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useState } from 'react';\nimport type { FunctionComponent } from 'react';\n\nimport { NumberInput, useAfterInitialEffect, useI18n } from '@pega/cosmos-react-core';\nimport type { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\ninterface NumericInputProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: { value: string | number };\n\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: { value: string | number }) => void;\n\n /** Used to indicate any errors on the control */\n status?: 'error';\n\n /** Determines whether decimals can be entered */\n allowDecimal?: boolean;\n}\n\n/** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */\nconst NumericInput: FunctionComponent<NumericInputProps> = (props: NumericInputProps) => {\n const { rhs, onChange, status, allowDecimal = true } = props;\n const t = useI18n();\n\n // Since we want to always call onChange with parsed Numbers,\n // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX\n // Using a local state to avoid that\n const [localValue, setLocalValue] = useState(rhs.value.toString());\n\n useAfterInitialEffect(() => {\n setLocalValue(rhs.value.toString());\n }, [rhs.value]);\n\n const handleInputChange = (newValue: string) => {\n setLocalValue(newValue);\n onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty\n };\n\n return (\n <NumberInput\n value={localValue}\n onChange={handleInputChange}\n status={status}\n info={status === 'error' ? t('condition_builder_invalid_number') : undefined}\n label={t('condition_builder_value_label')}\n numberOfDecimals={allowDecimal ? undefined : 0}\n />\n );\n};\n\nexport default NumericInput;\n"]}
1
+ {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAgBtF,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,GAAG,IAAI,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;IACnE,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,wFAAwF;IACxF,MAAM,4BAA4B,GAAG,CAAC,KAAsB,EAAE,EAAE;QAC9D,IAAI,IAAI,KAAK,WAAW,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACtD,OAAO,UAAU,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CA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AC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAC9C,IAAI,EAAE,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,GAC5E,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { useState } from 'react';\nimport type { FunctionComponent } from 'react';\n\nimport { NumberInput, useAfterInitialEffect, useI18n } from '@pega/cosmos-react-core';\nimport type { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\ninterface NumericInputProps extends BaseProps, NoChildrenProp {\n /** Rhs for the condition */\n rhs: { value: string | number };\n /** Callback for any modifications to the Rhs */\n onChange: (rhs: { value: string | number }) => void;\n /** Used to indicate any errors on the control */\n status?: 'error';\n /** Determines whether decimals can be entered */\n allowDecimal?: boolean;\n /** Determines whether value is stored in the database in the range of 0 to 1 or 0 to 100 */\n unit?: 'percent_1' | 'percent_100';\n}\n\n/** Wrapper over the NumberInput to parse values as Numbers, while still allowing the user to type partial values like `12.`, `12.0`, ... */\nconst NumericInput: FunctionComponent<NumericInputProps> = (props: NumericInputProps) => {\n const { rhs, onChange, status, allowDecimal = true, unit } = props;\n const t = useI18n();\n\n // Formats a value as a percentage and fixes floating point rounding errors in input box\n const convertPercentToDisplayValue = (value: string | number) => {\n if (unit === 'percent_1' && typeof value === 'number') {\n return parseFloat((value * 100).toFixed(2));\n }\n return value;\n };\n\n // Since we want to always call onChange with parsed Numbers,\n // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX\n // Using a local state to avoid that\n const [localValue, setLocalValue] = useState(convertPercentToDisplayValue(rhs.value).toString());\n\n useAfterInitialEffect(() => {\n setLocalValue(convertPercentToDisplayValue(rhs.value).toString());\n }, [rhs.value]);\n\n const handleInputChange = (newValue: string) => {\n setLocalValue(newValue);\n };\n\n const handleBlur = (newValue: string) => {\n let outValue: string | number = '';\n if (newValue) {\n const valueAsNumber = Number(newValue);\n if (!Number.isNaN(valueAsNumber)) {\n outValue = unit === 'percent_1' ? valueAsNumber / 100 : valueAsNumber;\n }\n }\n onChange({ value: outValue });\n };\n\n return (\n <NumberInput\n value={localValue}\n onChange={handleInputChange}\n onBlur={handleBlur}\n status={status}\n info={status === 'error' ? t('condition_builder_invalid_number') : undefined}\n label={t('condition_builder_value_label')}\n numberOfDecimals={allowDecimal ? undefined : 0}\n unit={unit === 'percent_1' || unit === 'percent_100' ? 'percent' : undefined}\n />\n );\n};\n\nexport default NumericInput;\n"]}
@@ -0,0 +1,31 @@
1
+ import type { Ref } from 'react';
2
+ import type { BaseProps, FormControlProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
+ export interface NumericRangeInputProps extends BaseProps, NoChildrenProp {
4
+ /** Label for the range input. */
5
+ label: FormControlProps['label'];
6
+ /** Determines whether the label is hidden. */
7
+ labelHidden?: FormControlProps['labelHidden'];
8
+ /** Rhs for the condition. */
9
+ rhs?: {
10
+ start: string | number;
11
+ end: string | number;
12
+ };
13
+ /** Callback for any modifications to the Rhs. */
14
+ onChange: (rhs: {
15
+ start: number | undefined;
16
+ end: number | undefined;
17
+ }) => void;
18
+ /** Used to indicate any errors on the control. */
19
+ status?: 'error';
20
+ /**
21
+ * Determines whether decimals can be entered.
22
+ * @default true
23
+ */
24
+ allowDecimal?: boolean;
25
+ /** Determines whether value is stored in the database in the range of 0 to 1 or 0 to 100. */
26
+ unit?: 'percent_1' | 'percent_100';
27
+ /** Ref to the component. */
28
+ ref?: Ref<HTMLFieldSetElement>;
29
+ }
30
+ export declare const NumericRangeInput: import("react").ForwardRefExoticComponent<Omit<NumericRangeInputProps, "ref"> & import("react").RefAttributes<HTMLFieldSetElement>>;
31
+ //# sourceMappingURL=NumericRangeInput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NumericRangeInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericRangeInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE3F,MAAM,WAAW,sBAAuB,SAAQ,SAAS,EAAE,cAAc;IACvE,iCAAiC;IACjC,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACjC,8CAA8C;IAC9C,WAAW,CAAC,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC;IAC9C,6BAA6B;IAC7B,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACvD,iDAAiD;IACjD,QAAQ,EAAE,CAAC,GAAG,EAAE;QAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,KAAK,IAAI,CAAC;IAChF,kDAAkD;IAClD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,6FAA6F;IAC7F,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC;IACnC,4BAA4B;IAC5B,GAAG,CAAC,EAAE,GAAG,CAAC,mBAAmB,CAAC,CAAC;CAChC;AAED,eAAO,MAAM,iBAAiB,qIAuE7B,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useState } from 'react';
3
+ import { NumberRangeInput, useAfterInitialEffect, useI18n } from '@pega/cosmos-react-core';
4
+ export const NumericRangeInput = forwardRef(({ rhs, onChange, status, allowDecimal = true, unit, ...props }, ref) => {
5
+ const t = useI18n();
6
+ // Formats a value as a percentage and fixes floating point rounding errors in input box
7
+ const convertPercentToDisplayValue = (value) => {
8
+ if (unit === 'percent_1') {
9
+ const num = typeof value === 'number' ? value : Number(value);
10
+ // Number value of empty string is 0, which we don't want, so we return just value instead
11
+ if (!Number.isNaN(num) && value !== '') {
12
+ return parseFloat((num * 100).toFixed(2));
13
+ }
14
+ }
15
+ return value;
16
+ };
17
+ const [internalValue, setInternalValue] = useState({
18
+ start: convertPercentToDisplayValue(rhs?.start)?.toString(),
19
+ end: convertPercentToDisplayValue(rhs?.end)?.toString()
20
+ });
21
+ useAfterInitialEffect(() => {
22
+ setInternalValue({
23
+ start: convertPercentToDisplayValue(rhs?.start)?.toString(),
24
+ end: convertPercentToDisplayValue(rhs?.end)?.toString()
25
+ });
26
+ }, [rhs?.start, rhs?.end]);
27
+ const handleChange = (newValue) => {
28
+ setInternalValue(newValue);
29
+ };
30
+ const handleBlur = (newValue) => {
31
+ let outStartValue;
32
+ let outEndValue;
33
+ if (newValue.start) {
34
+ const valueAsNumber = Number(newValue.start);
35
+ if (!Number.isNaN(valueAsNumber)) {
36
+ outStartValue = unit === 'percent_1' ? valueAsNumber / 100 : valueAsNumber;
37
+ }
38
+ }
39
+ if (newValue.end) {
40
+ const valueAsNumber = Number(newValue.end);
41
+ if (!Number.isNaN(valueAsNumber)) {
42
+ outEndValue = unit === 'percent_1' ? valueAsNumber / 100 : valueAsNumber;
43
+ }
44
+ }
45
+ onChange({
46
+ start: outStartValue,
47
+ end: outEndValue
48
+ });
49
+ };
50
+ return (_jsx(NumberRangeInput, { ...props, ref: ref, value: internalValue, onChange: handleChange, onBlur: handleBlur, status: status, info: status === 'error' ? t('condition_builder_invalid_number_range') : undefined, numberOfDecimals: allowDecimal ? undefined : 0, unit: unit === 'percent_1' || unit === 'percent_100' ? 'percent' : undefined, fromPlaceholder: t('range_from_numeric'), toPlaceholder: t('range_to_numeric') }));
51
+ });
52
+ //# sourceMappingURL=NumericRangeInput.js.map