@pega/cosmos-react-condition-builder 3.0.0-dev.16.1 → 3.0.0-dev.18.1

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 (61) hide show
  1. package/lib/components/ConditionBuilder/AtomicCondition.d.ts +2 -2
  2. package/lib/components/ConditionBuilder/AtomicCondition.d.ts.map +1 -1
  3. package/lib/components/ConditionBuilder/AtomicCondition.js +22 -14
  4. package/lib/components/ConditionBuilder/AtomicCondition.js.map +1 -1
  5. package/lib/components/ConditionBuilder/ConditionBuilder.d.ts.map +1 -1
  6. package/lib/components/ConditionBuilder/ConditionBuilder.js +2 -30
  7. package/lib/components/ConditionBuilder/ConditionBuilder.js.map +1 -1
  8. package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts +5 -0
  9. package/lib/components/ConditionBuilder/ConditionBuilder.styles.d.ts.map +1 -0
  10. package/lib/components/ConditionBuilder/ConditionBuilder.styles.js +44 -0
  11. package/lib/components/ConditionBuilder/ConditionBuilder.styles.js.map +1 -0
  12. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts +10 -3
  13. package/lib/components/ConditionBuilder/ConditionBuilder.types.d.ts.map +1 -1
  14. package/lib/components/ConditionBuilder/ConditionBuilder.types.js.map +1 -1
  15. package/lib/components/ConditionBuilder/FieldCondition.js +1 -1
  16. package/lib/components/ConditionBuilder/FieldCondition.js.map +1 -1
  17. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.d.ts.map +1 -1
  18. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js +3 -2
  19. package/lib/components/ConditionBuilder/RhsControls/FieldSelector.js.map +1 -1
  20. package/lib/components/ConditionBuilder/RhsControls/NumericInput.d.ts.map +1 -1
  21. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js +4 -1
  22. package/lib/components/ConditionBuilder/RhsControls/NumericInput.js.map +1 -1
  23. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts +5 -3
  24. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.d.ts.map +1 -1
  25. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js +33 -8
  26. package/lib/components/ConditionBuilder/RhsControls/RhsModeSwitch.js.map +1 -1
  27. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts +5 -1
  28. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.d.ts.map +1 -1
  29. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js +47 -22
  30. package/lib/components/ConditionBuilder/RhsControls/ValueSelector.js.map +1 -1
  31. package/lib/components/ConditionBuilder/RhsControls/index.d.ts.map +1 -1
  32. package/lib/components/ConditionBuilder/RhsControls/index.js +23 -15
  33. package/lib/components/ConditionBuilder/RhsControls/index.js.map +1 -1
  34. package/lib/components/ConditionBuilder/core/evaluator.d.ts.map +1 -1
  35. package/lib/components/ConditionBuilder/core/evaluator.js +3 -0
  36. package/lib/components/ConditionBuilder/core/evaluator.js.map +1 -1
  37. package/lib/components/ConditionBuilder/core/formatter.d.ts +1 -0
  38. package/lib/components/ConditionBuilder/core/formatter.d.ts.map +1 -1
  39. package/lib/components/ConditionBuilder/core/formatter.js +59 -25
  40. package/lib/components/ConditionBuilder/core/formatter.js.map +1 -1
  41. package/lib/components/ConditionBuilder/core/types.d.ts +1 -1
  42. package/lib/components/ConditionBuilder/core/types.d.ts.map +1 -1
  43. package/lib/components/ConditionBuilder/core/types.js.map +1 -1
  44. package/lib/components/ConditionInput/ConditionInput.d.ts.map +1 -1
  45. package/lib/components/ConditionInput/ConditionInput.js +62 -11
  46. package/lib/components/ConditionInput/ConditionInput.js.map +1 -1
  47. package/lib/components/ConditionInput/ConditionInput.types.d.ts +3 -1
  48. package/lib/components/ConditionInput/ConditionInput.types.d.ts.map +1 -1
  49. package/lib/components/ConditionInput/ConditionInput.types.js.map +1 -1
  50. package/lib/components/PromotedFilters/PromotedFilters.d.ts +6 -1
  51. package/lib/components/PromotedFilters/PromotedFilters.d.ts.map +1 -1
  52. package/lib/components/PromotedFilters/PromotedFilters.js +67 -24
  53. package/lib/components/PromotedFilters/PromotedFilters.js.map +1 -1
  54. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts +4 -0
  55. package/lib/components/PromotedFilters/PromotedFilters.styles.d.ts.map +1 -0
  56. package/lib/components/PromotedFilters/PromotedFilters.styles.js +26 -0
  57. package/lib/components/PromotedFilters/PromotedFilters.styles.js.map +1 -0
  58. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts +4 -2
  59. package/lib/components/PromotedFilters/PromotedFilters.types.d.ts.map +1 -1
  60. package/lib/components/PromotedFilters/PromotedFilters.types.js.map +1 -1
  61. package/package.json +2 -2
@@ -1,7 +1,7 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useEffect } from 'react';
3
- import styled from 'styled-components';
4
- import { CompositeInput, defaultThemeProp, hasProp, Input, NumberInput, RadioButton, RadioButtonGroup, StyledGrid, useI18n } from '@pega/cosmos-react-core';
3
+ import styled, { css } from 'styled-components';
4
+ import { CompositeInput, defaultThemeProp, hasProp, Input, NumberInput, RadioButton, RadioButtonGroup, StyledGrid, useI18n, FieldGroup, StyledFieldGroupLegend, StyledButton, DateInput, TimeInput, DateTimeInput, useConfiguration } from '@pega/cosmos-react-core';
5
5
  import AtomicCondition, { getInitConditionForLhs } from '../ConditionBuilder/AtomicCondition';
6
6
  import formatCondition from '../ConditionBuilder/core/formatter';
7
7
  const defaultComparators = {
@@ -13,7 +13,10 @@ const defaultComparators = {
13
13
  DECIMAL: 'EQ',
14
14
  PERCENTAGE: 'EQ',
15
15
  CURRENCY: 'EQ',
16
- BOOLEAN: 'IS_TRUE'
16
+ BOOLEAN: 'IS_TRUE',
17
+ DATE_ONLY: 'LT',
18
+ TIME_ONLY: 'LT',
19
+ DATE_TIME: 'LT'
17
20
  };
18
21
  const basicFieldMap = {
19
22
  EMAIL: 'TEXT',
@@ -24,7 +27,10 @@ const basicFieldMap = {
24
27
  PERCENTAGE: 'NUMBER',
25
28
  CURRENCY: 'NUMBER',
26
29
  TEXT: 'TEXT',
27
- BOOLEAN: 'BOOLEAN'
30
+ BOOLEAN: 'BOOLEAN',
31
+ DATE_ONLY: 'DATE_ONLY',
32
+ TIME_ONLY: 'TIME_ONLY',
33
+ DATE_TIME: 'DATE_TIME'
28
34
  };
29
35
  const StyledConditionRadioGroup = styled(RadioButtonGroup) `
30
36
  ${StyledGrid} {
@@ -32,8 +38,26 @@ const StyledConditionRadioGroup = styled(RadioButtonGroup) `
32
38
  } ;
33
39
  `;
34
40
  StyledConditionRadioGroup.defaultProps = defaultThemeProp;
35
- const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange }, ref) => {
41
+ const StyledFieldGroupLegendFn = ({ theme: { base: { palette } } }) => {
42
+ return css `
43
+ ${StyledFieldGroupLegend} {
44
+ border-block-start: 0.0625rem solid ${palette['border-line']};
45
+ padding-block-start: 0.625rem;
46
+
47
+ ${StyledButton} {
48
+ border-color: transparent;
49
+ font-weight: initial;
50
+ }
51
+ }
52
+ `;
53
+ };
54
+ const StyledFieldGroup = styled(FieldGroup)(StyledFieldGroupLegendFn);
55
+ StyledFieldGroup.defaultProps = defaultThemeProp;
56
+ const StyledAtomicCondition = styled(AtomicCondition)(StyledFieldGroupLegendFn);
57
+ StyledAtomicCondition.defaultProps = defaultThemeProp;
58
+ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange, flat = false }, ref) => {
36
59
  const t = useI18n();
60
+ const { locale } = useConfiguration();
37
61
  const basicType = basicFieldMap[fieldType] ?? fieldType;
38
62
  const fields = [
39
63
  { id: fieldName, type: basicType, primary: fieldLabel || fieldName }
@@ -73,19 +97,34 @@ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionP
73
97
  case 'DECIMAL':
74
98
  case 'PERCENTAGE':
75
99
  case 'CURRENCY':
76
- defaultControl = (_jsx(NumberInput, { label: fieldLabel, ref: ref, value: inputValue, onChange: setInputValue, onBlur: value => {
100
+ defaultControl = (_jsx(NumberInput, { label: fieldLabel, labelHidden: flat, ref: ref, value: inputValue, onChange: setInputValue, onBlur: value => {
77
101
  onChange(createConditionForDefaultMode(value));
78
102
  }, numberOfDecimals: fieldType === 'INTEGER' ? 0 : undefined }));
79
103
  break;
80
104
  case 'BOOLEAN':
81
- defaultControl = (_jsxs(StyledConditionRadioGroup, { ref: ref, label: fieldLabel, name: fieldName, inline: true, children: [_jsx(RadioButton, { label: t('show_all'), checked: condition === undefined, onChange: () => onRadioButtonChange() }), _jsx(RadioButton, { label: t('boolean_display_true_label'), checked: condition?.comparator === 'IS_TRUE', onChange: () => onRadioButtonChange(true) }), _jsx(RadioButton, { label: t('boolean_display_false_label'), checked: condition?.comparator === 'IS_FALSE', onChange: () => onRadioButtonChange(false) })] }));
105
+ defaultControl = (_jsxs(StyledConditionRadioGroup, { ref: ref, label: fieldLabel, labelHidden: flat, name: fieldName, inline: true, children: [_jsx(RadioButton, { label: t('show_all'), checked: condition === undefined, onChange: () => onRadioButtonChange() }), _jsx(RadioButton, { label: t('boolean_display_true_label'), checked: condition?.comparator === 'IS_TRUE', onChange: () => onRadioButtonChange(true) }), _jsx(RadioButton, { label: t('boolean_display_false_label'), checked: condition?.comparator === 'IS_FALSE', onChange: () => onRadioButtonChange(false) })] }));
106
+ break;
107
+ case 'DATE_ONLY':
108
+ defaultControl = (_jsx(DateInput, { label: fieldLabel, ref: ref, value: inputValue, onChange: ({ valueAsISOString }) => setInputValue(valueAsISOString), onBlur: ({ valueAsISOString }) => {
109
+ onChange(createConditionForDefaultMode(valueAsISOString));
110
+ } }));
111
+ break;
112
+ case 'TIME_ONLY':
113
+ defaultControl = (_jsx(TimeInput, { label: fieldLabel, ref: ref, value: inputValue || undefined, onChange: ({ valueAsISOString }) => setInputValue(valueAsISOString), onBlur: ({ valueAsISOString }) => {
114
+ onChange(createConditionForDefaultMode(valueAsISOString));
115
+ } }));
116
+ break;
117
+ case 'DATE_TIME':
118
+ defaultControl = (_jsx(DateTimeInput, { label: fieldLabel, ref: ref, value: inputValue, onChange: ({ valueAsISOString }) => setInputValue(valueAsISOString), onBlur: ({ valueAsISOString }) => {
119
+ onChange(createConditionForDefaultMode(valueAsISOString));
120
+ } }));
82
121
  break;
83
122
  case 'TEXT':
84
123
  case 'EMAIL':
85
124
  case 'URL':
86
125
  case 'PHONE':
87
126
  default:
88
- defaultControl = (_jsx(Input, { label: fieldLabel, ref: ref, value: inputValue, onChange: (e) => setInputValue(e.target.value), onBlur: (e) => onChange(createConditionForDefaultMode(e.target.value)) }));
127
+ defaultControl = (_jsx(Input, { label: fieldLabel, labelHidden: flat, ref: ref, value: inputValue, onChange: (e) => setInputValue(e.target.value), onBlur: (e) => onChange(createConditionForDefaultMode(e.target.value)) }));
89
128
  break;
90
129
  }
91
130
  }
@@ -101,7 +140,7 @@ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionP
101
140
  fields,
102
141
  onChange: setNewCondition,
103
142
  itemDirection: 'column',
104
- showLhsAsLabel: true,
143
+ lhsMode: 'hidden',
105
144
  validRhsTypes: new Set(['LITERAL']),
106
145
  indicateErrors: false
107
146
  },
@@ -118,7 +157,19 @@ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionP
118
157
  onChange(undefined);
119
158
  setNewCondition(condition);
120
159
  };
121
- return (_jsx(_Fragment, { children: showAdvanced ? (_jsx(CompositeInput, { dialog: dialog, label: fieldLabel, onClear: onClear, value: conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined, placeholder: t('all'), ref: ref })) : (defaultControl) }));
160
+ if (flat) {
161
+ return showAdvanced ? (_jsx(StyledAtomicCondition, { collapsible: true, actions: [{ id: 'clear', text: t('clear'), onClick: onClear }], condition: newCondition ??
162
+ getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])), onChange: onChange, fields: fields, itemDirection: 'column', lhsMode: 'label', validRhsTypes: new Set(['LITERAL']), indicateErrors: false })) : (_jsx(StyledFieldGroup, { name: fieldLabel, collapsible: true, actions: [{ id: 'clear', text: t('clear'), onClick: onClear }], children: defaultControl }));
163
+ }
164
+ if (showAdvanced) {
165
+ return (_jsx(CompositeInput, { dialog: dialog, label: fieldLabel, onClear: onClear, value: conditionProp
166
+ ? formatCondition({ condition: conditionProp }, fields, t, {
167
+ locale,
168
+ omitLhs: true
169
+ })
170
+ : undefined, placeholder: t('all'), ref: ref }));
171
+ }
172
+ return defaultControl;
122
173
  });
123
174
  export default ConditionInput;
124
175
  //# sourceMappingURL=ConditionInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,cAAc,EAEd,gBAAgB,EAEhB,OAAO,EACP,KAAK,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,OAAO,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,eAAe,EAAE,EAEtB,sBAAsB,EACvB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,eAAe,MAAM,oCAAoC,CAAC;AAKjE,MAAM,kBAAkB,GAA2C;IACjE,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,GAAG,EAAE,UAAU;IACf,KAAK,EAAE,UAAU;IACjB,OAAO,EAAE,IAAI;IACb,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,IAAI;IAChB,QAAQ,EAAE,IAAI;IACd,OAAO,EAAE,SAAS;CACV,CAAC;AAEX,MAAM,aAAa,GAA0C;IAC3D,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM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AAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAEtF,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,EACrB,GAAG,EAAE,GAAG,GACR,CACH,CAAC,CAAC,CAAC,CACF,cAAc,CACf,GACA,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useState,\n ChangeEvent,\n useEffect\n} from 'react';\nimport styled from 'styled-components';\n\nimport {\n CompositeInput,\n CompositeInputProps,\n defaultThemeProp,\n ForwardProps,\n hasProp,\n Input,\n NumberInput,\n RadioButton,\n RadioButtonGroup,\n StyledGrid,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\nimport AtomicCondition, {\n AtomicConditionProps,\n getInitConditionForLhs\n} from '../ConditionBuilder/AtomicCondition';\nimport formatCondition from '../ConditionBuilder/core/formatter';\nimport type { LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\n\nimport { ConditionFieldType, ConditionInputProps } from './ConditionInput.types';\n\nconst defaultComparators: Record<ConditionFieldType, Comparator> = {\n TEXT: 'CONTAINS',\n EMAIL: 'CONTAINS',\n URL: 'CONTAINS',\n PHONE: 'CONTAINS',\n INTEGER: 'EQ',\n DECIMAL: 'EQ',\n PERCENTAGE: 'EQ',\n CURRENCY: 'EQ',\n BOOLEAN: 'IS_TRUE'\n} as const;\n\nconst basicFieldMap: Record<ConditionFieldType, FieldType> = {\n EMAIL: 'TEXT',\n URL: 'TEXT',\n PHONE: 'TEXT',\n INTEGER: 'NUMBER',\n DECIMAL: 'NUMBER',\n PERCENTAGE: 'NUMBER',\n CURRENCY: 'NUMBER',\n TEXT: 'TEXT',\n BOOLEAN: 'BOOLEAN'\n} as const;\n\nconst StyledConditionRadioGroup = styled(RadioButtonGroup)`\n ${StyledGrid} {\n display: inline-flex;\n } ;\n`;\n\nStyledConditionRadioGroup.defaultProps = defaultThemeProp;\n\nconst ConditionInput: FunctionComponent<ConditionInputProps & ForwardProps> = forwardRef(\n (\n {\n fieldName,\n fieldType,\n condition: conditionProp,\n fieldLabel,\n mode,\n onChange\n }: PropsWithoutRef<ConditionInputProps>,\n ref: ConditionInputProps['ref']\n ) => {\n const t = useI18n();\n\n const basicType = basicFieldMap[fieldType] ?? fieldType;\n\n const fields: AtomicConditionProps['fields'] = [\n { id: fieldName, type: basicType, primary: fieldLabel || fieldName }\n ];\n\n const condition =\n conditionProp ??\n (fieldType === 'BOOLEAN'\n ? undefined\n : getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])));\n\n const onRadioButtonChange = (value?: boolean) => {\n const updatedCondition: LeafCondition | undefined =\n value === undefined\n ? undefined\n : {\n lhs: { field: fieldName },\n comparator: value ? 'IS_TRUE' : 'IS_FALSE'\n };\n onChange(updatedCondition);\n };\n\n const createConditionForDefaultMode = (value: string) => {\n return {\n lhs: { field: fieldName },\n comparator: defaultComparators[fieldType],\n rhs: { value: basicType === 'NUMBER' ? Number(value) : value }\n };\n };\n\n const rhsValue =\n condition?.rhs && hasProp(condition.rhs, 'value')\n ? condition.rhs.value.toString()\n : undefined;\n\n const [inputValue, setInputValue] = useState(rhsValue);\n\n useEffect(() => {\n setInputValue(rhsValue);\n }, [conditionProp]);\n\n const showAdvanced = mode === 'advanced' && fieldType !== 'BOOLEAN';\n\n let defaultControl: JSX.Element | null = null;\n\n if (!showAdvanced) {\n switch (fieldType) {\n case 'INTEGER':\n case 'DECIMAL':\n case 'PERCENTAGE':\n case 'CURRENCY':\n defaultControl = (\n <NumberInput\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={setInputValue}\n onBlur={value => {\n onChange(createConditionForDefaultMode(value));\n }}\n numberOfDecimals={fieldType === 'INTEGER' ? 0 : undefined}\n />\n );\n break;\n case 'BOOLEAN':\n defaultControl = (\n <StyledConditionRadioGroup ref={ref} label={fieldLabel} name={fieldName} inline>\n <RadioButton\n label={t('show_all')}\n checked={condition === undefined}\n onChange={() => onRadioButtonChange()}\n />\n <RadioButton\n label={t('boolean_display_true_label')}\n checked={condition?.comparator === 'IS_TRUE'}\n onChange={() => onRadioButtonChange(true)}\n />\n <RadioButton\n label={t('boolean_display_false_label')}\n checked={condition?.comparator === 'IS_FALSE'}\n onChange={() => onRadioButtonChange(false)}\n />\n </StyledConditionRadioGroup>\n );\n break;\n case 'TEXT':\n case 'EMAIL':\n case 'URL':\n case 'PHONE':\n default:\n defaultControl = (\n <Input\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setInputValue(e.target.value)}\n onBlur={(e: ChangeEvent<HTMLInputElement>) =>\n onChange(createConditionForDefaultMode(e.target.value))\n }\n />\n );\n break;\n }\n }\n\n const [newCondition, setNewCondition] = useState<LeafCondition | undefined>(condition);\n\n useEffect(() => {\n setNewCondition(condition);\n }, [conditionProp]);\n\n const dialog: CompositeInputProps<AtomicConditionProps & ForwardProps>['dialog'] = {\n renderer: AtomicCondition,\n rendererProps: {\n condition:\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),\n fields,\n onChange: setNewCondition,\n itemDirection: 'column',\n showLhsAsLabel: true,\n validRhsTypes: new Set(['LITERAL']),\n indicateErrors: false\n },\n onCancel: ({ close }) => {\n setNewCondition(condition);\n close();\n },\n onApply: ({ close }) => {\n onChange(newCondition);\n close();\n }\n };\n\n const onClear = () => {\n onChange(undefined);\n setNewCondition(condition);\n };\n\n return (\n <>\n {showAdvanced ? (\n <CompositeInput\n dialog={dialog}\n label={fieldLabel}\n onClear={onClear}\n value={\n conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined\n }\n placeholder={t('all')}\n ref={ref}\n />\n ) : (\n defaultControl\n )}\n </>\n );\n }\n);\n\nexport default ConditionInput;\n"]}
1
+ {"version":3,"file":"ConditionInput.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput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AAC;AACxB,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useState,\n ChangeEvent,\n useEffect\n} from 'react';\nimport styled, { css, DefaultTheme, ThemeProps } from 'styled-components';\n\nimport {\n CompositeInput,\n CompositeInputProps,\n defaultThemeProp,\n ForwardProps,\n hasProp,\n Input,\n NumberInput,\n RadioButton,\n RadioButtonGroup,\n StyledGrid,\n useI18n,\n FieldGroup,\n StyledFieldGroupLegend,\n StyledButton,\n DateInput,\n TimeInput,\n DateTimeInput,\n useConfiguration\n} from '@pega/cosmos-react-core';\n\nimport type { Comparator, FieldType } from '../ConditionBuilder/core/types';\nimport AtomicCondition, {\n AtomicConditionProps,\n getInitConditionForLhs\n} from '../ConditionBuilder/AtomicCondition';\nimport formatCondition from '../ConditionBuilder/core/formatter';\nimport type { LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\n\nimport { ConditionFieldType, ConditionInputProps } from './ConditionInput.types';\n\nconst defaultComparators: Record<ConditionFieldType, Comparator> = {\n TEXT: 'CONTAINS',\n EMAIL: 'CONTAINS',\n URL: 'CONTAINS',\n PHONE: 'CONTAINS',\n INTEGER: 'EQ',\n DECIMAL: 'EQ',\n PERCENTAGE: 'EQ',\n CURRENCY: 'EQ',\n BOOLEAN: 'IS_TRUE',\n DATE_ONLY: 'LT',\n TIME_ONLY: 'LT',\n DATE_TIME: 'LT'\n} as const;\n\nconst basicFieldMap: Record<ConditionFieldType, FieldType> = {\n EMAIL: 'TEXT',\n URL: 'TEXT',\n PHONE: 'TEXT',\n INTEGER: 'NUMBER',\n DECIMAL: 'NUMBER',\n PERCENTAGE: 'NUMBER',\n CURRENCY: 'NUMBER',\n TEXT: 'TEXT',\n BOOLEAN: 'BOOLEAN',\n DATE_ONLY: 'DATE_ONLY',\n TIME_ONLY: 'TIME_ONLY',\n DATE_TIME: 'DATE_TIME'\n} as const;\n\nconst StyledConditionRadioGroup = styled(RadioButtonGroup)`\n ${StyledGrid} {\n display: inline-flex;\n } ;\n`;\n\nStyledConditionRadioGroup.defaultProps = defaultThemeProp;\n\nconst StyledFieldGroupLegendFn = ({\n theme: {\n base: { palette }\n }\n}: ThemeProps<DefaultTheme>) => {\n return css`\n ${StyledFieldGroupLegend} {\n border-block-start: 0.0625rem solid ${palette['border-line']};\n padding-block-start: 0.625rem;\n\n ${StyledButton} {\n border-color: transparent;\n font-weight: initial;\n }\n }\n `;\n};\n\nconst StyledFieldGroup = styled(FieldGroup)(StyledFieldGroupLegendFn);\n\nStyledFieldGroup.defaultProps = defaultThemeProp;\n\nconst StyledAtomicCondition = styled(AtomicCondition)(StyledFieldGroupLegendFn);\n\nStyledAtomicCondition.defaultProps = defaultThemeProp;\n\nconst ConditionInput: FunctionComponent<ConditionInputProps & ForwardProps> = forwardRef(\n (\n {\n fieldName,\n fieldType,\n condition: conditionProp,\n fieldLabel,\n mode,\n onChange,\n flat = false\n }: PropsWithoutRef<ConditionInputProps>,\n ref: ConditionInputProps['ref']\n ) => {\n const t = useI18n();\n const { locale } = useConfiguration();\n\n const basicType = basicFieldMap[fieldType] ?? fieldType;\n\n const fields: AtomicConditionProps['fields'] = [\n { id: fieldName, type: basicType, primary: fieldLabel || fieldName }\n ];\n\n const condition =\n conditionProp ??\n (fieldType === 'BOOLEAN'\n ? undefined\n : getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])));\n\n const onRadioButtonChange = (value?: boolean) => {\n const updatedCondition: LeafCondition | undefined =\n value === undefined\n ? undefined\n : {\n lhs: { field: fieldName },\n comparator: value ? 'IS_TRUE' : 'IS_FALSE'\n };\n onChange(updatedCondition);\n };\n\n const createConditionForDefaultMode = (value: string) => {\n return {\n lhs: { field: fieldName },\n comparator: defaultComparators[fieldType],\n rhs: { value: basicType === 'NUMBER' ? Number(value) : value }\n };\n };\n\n const rhsValue =\n condition?.rhs && hasProp(condition.rhs, 'value')\n ? condition.rhs.value.toString()\n : undefined;\n\n const [inputValue, setInputValue] = useState(rhsValue);\n\n useEffect(() => {\n setInputValue(rhsValue);\n }, [conditionProp]);\n\n const showAdvanced = mode === 'advanced' && fieldType !== 'BOOLEAN';\n\n let defaultControl: JSX.Element | null = null;\n\n if (!showAdvanced) {\n switch (fieldType) {\n case 'INTEGER':\n case 'DECIMAL':\n case 'PERCENTAGE':\n case 'CURRENCY':\n defaultControl = (\n <NumberInput\n label={fieldLabel}\n labelHidden={flat}\n ref={ref}\n value={inputValue}\n onChange={setInputValue}\n onBlur={value => {\n onChange(createConditionForDefaultMode(value));\n }}\n numberOfDecimals={fieldType === 'INTEGER' ? 0 : undefined}\n />\n );\n break;\n case 'BOOLEAN':\n defaultControl = (\n <StyledConditionRadioGroup\n ref={ref}\n label={fieldLabel}\n labelHidden={flat}\n name={fieldName}\n inline\n >\n <RadioButton\n label={t('show_all')}\n checked={condition === undefined}\n onChange={() => onRadioButtonChange()}\n />\n <RadioButton\n label={t('boolean_display_true_label')}\n checked={condition?.comparator === 'IS_TRUE'}\n onChange={() => onRadioButtonChange(true)}\n />\n <RadioButton\n label={t('boolean_display_false_label')}\n checked={condition?.comparator === 'IS_FALSE'}\n onChange={() => onRadioButtonChange(false)}\n />\n </StyledConditionRadioGroup>\n );\n break;\n case 'DATE_ONLY':\n defaultControl = (\n <DateInput\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={({ valueAsISOString }) => setInputValue(valueAsISOString)}\n onBlur={({ valueAsISOString }) => {\n onChange(createConditionForDefaultMode(valueAsISOString));\n }}\n />\n );\n break;\n case 'TIME_ONLY':\n defaultControl = (\n <TimeInput\n label={fieldLabel}\n ref={ref}\n value={inputValue || undefined}\n onChange={({ valueAsISOString }) => setInputValue(valueAsISOString)}\n onBlur={({ valueAsISOString }) => {\n onChange(createConditionForDefaultMode(valueAsISOString));\n }}\n />\n );\n break;\n case 'DATE_TIME':\n defaultControl = (\n <DateTimeInput\n label={fieldLabel}\n ref={ref}\n value={inputValue}\n onChange={({ valueAsISOString }) => setInputValue(valueAsISOString)}\n onBlur={({ valueAsISOString }) => {\n onChange(createConditionForDefaultMode(valueAsISOString));\n }}\n />\n );\n break;\n case 'TEXT':\n case 'EMAIL':\n case 'URL':\n case 'PHONE':\n default:\n defaultControl = (\n <Input\n label={fieldLabel}\n labelHidden={flat}\n ref={ref}\n value={inputValue}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setInputValue(e.target.value)}\n onBlur={(e: ChangeEvent<HTMLInputElement>) =>\n onChange(createConditionForDefaultMode(e.target.value))\n }\n />\n );\n break;\n }\n }\n\n const [newCondition, setNewCondition] = useState<LeafCondition | undefined>(condition);\n\n useEffect(() => {\n setNewCondition(condition);\n }, [conditionProp]);\n\n const dialog: CompositeInputProps<AtomicConditionProps & ForwardProps>['dialog'] = {\n renderer: AtomicCondition,\n rendererProps: {\n condition:\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])),\n fields,\n onChange: setNewCondition,\n itemDirection: 'column',\n lhsMode: 'hidden',\n validRhsTypes: new Set(['LITERAL']),\n indicateErrors: false\n },\n onCancel: ({ close }) => {\n setNewCondition(condition);\n close();\n },\n onApply: ({ close }) => {\n onChange(newCondition);\n close();\n }\n };\n\n const onClear = () => {\n onChange(undefined);\n setNewCondition(condition);\n };\n\n if (flat) {\n return showAdvanced ? (\n <StyledAtomicCondition\n collapsible\n actions={[{ id: 'clear', text: t('clear'), onClick: onClear }]}\n condition={\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL']))\n }\n onChange={onChange}\n fields={fields}\n itemDirection='column'\n lhsMode='label'\n validRhsTypes={new Set(['LITERAL'])}\n indicateErrors={false}\n />\n ) : (\n <StyledFieldGroup\n name={fieldLabel}\n collapsible\n actions={[{ id: 'clear', text: t('clear'), onClick: onClear }]}\n >\n {defaultControl}\n </StyledFieldGroup>\n );\n }\n if (showAdvanced) {\n return (\n <CompositeInput\n dialog={dialog}\n label={fieldLabel}\n onClear={onClear}\n value={\n conditionProp\n ? formatCondition({ condition: conditionProp }, fields, t, {\n locale,\n omitLhs: true\n })\n : undefined\n }\n placeholder={t('all')}\n ref={ref}\n />\n );\n }\n return defaultControl;\n }\n);\n\nexport default ConditionInput;\n"]}
@@ -1,6 +1,6 @@
1
1
  import { Ref } from 'react';
2
2
  import { LeafCondition } from '../ConditionBuilder';
3
- export declare type ConditionFieldType = 'TEXT' | 'EMAIL' | 'URL' | 'PHONE' | 'INTEGER' | 'DECIMAL' | 'PERCENTAGE' | 'BOOLEAN' | 'CURRENCY';
3
+ export declare type ConditionFieldType = 'TEXT' | 'EMAIL' | 'URL' | 'PHONE' | 'INTEGER' | 'DECIMAL' | 'PERCENTAGE' | 'BOOLEAN' | 'CURRENCY' | 'DATE_ONLY' | 'TIME_ONLY' | 'DATE_TIME';
4
4
  export declare type ConditionInputMode = 'default' | 'advanced';
5
5
  export interface ConditionInputProps {
6
6
  /** Name of the field the condition is created for. */
@@ -17,5 +17,7 @@ export interface ConditionInputProps {
17
17
  onChange: (condition?: LeafCondition) => void;
18
18
  /** Reference to the input element. */
19
19
  ref?: Ref<HTMLInputElement>;
20
+ /** Whether advanced view should be wrapped in popup or just flat. */
21
+ flat?: boolean;
20
22
  }
21
23
  //# sourceMappingURL=ConditionInput.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oBAAY,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,oBAAY,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,kBAAkB,CAAC;IAC9B,wEAAwE;IACxE,IAAI,EAAE,kBAAkB,CAAC;IACzB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,sCAAsC;IACtC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;CAC7B"}
1
+ {"version":3,"file":"ConditionInput.types.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,oBAAY,kBAAkB,GAC1B,MAAM,GACN,OAAO,GACP,KAAK,GACL,OAAO,GACP,SAAS,GACT,SAAS,GACT,YAAY,GACZ,SAAS,GACT,UAAU,GACV,WAAW,GACX,WAAW,GACX,WAAW,CAAC;AAEhB,oBAAY,kBAAkB,GAAG,SAAS,GAAG,UAAU,CAAC;AAExD,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,sDAAsD;IACtD,SAAS,EAAE,kBAAkB,CAAC;IAC9B,wEAAwE;IACxE,IAAI,EAAE,kBAAkB,CAAC;IACzB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uBAAuB;IACvB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,wDAAwD;IACxD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC9C,sCAAsC;IACtC,GAAG,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAC5B,qEAAqE;IACrE,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB"}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.types.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { LeafCondition } from '../ConditionBuilder';\n\nexport type ConditionFieldType =\n | 'TEXT'\n | 'EMAIL'\n | 'URL'\n | 'PHONE'\n | 'INTEGER'\n | 'DECIMAL'\n | 'PERCENTAGE'\n | 'BOOLEAN'\n | 'CURRENCY';\n\nexport type ConditionInputMode = 'default' | 'advanced';\n\nexport interface ConditionInputProps {\n /** Name of the field the condition is created for. */\n fieldName: string;\n /** Type of the field the condition is created for. */\n fieldType: ConditionFieldType;\n /** Display mode. Either with default comparator or the full-fledged. */\n mode: ConditionInputMode;\n /** Label for the input. */\n fieldLabel?: string;\n /** Condition value. */\n condition?: LeafCondition;\n /** Callback invoked when user changes the condition. */\n onChange: (condition?: LeafCondition) => void;\n /** Reference to the input element. */\n ref?: Ref<HTMLInputElement>;\n}\n"]}
1
+ {"version":3,"file":"ConditionInput.types.js","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { LeafCondition } from '../ConditionBuilder';\n\nexport type ConditionFieldType =\n | 'TEXT'\n | 'EMAIL'\n | 'URL'\n | 'PHONE'\n | 'INTEGER'\n | 'DECIMAL'\n | 'PERCENTAGE'\n | 'BOOLEAN'\n | 'CURRENCY'\n | 'DATE_ONLY'\n | 'TIME_ONLY'\n | 'DATE_TIME';\n\nexport type ConditionInputMode = 'default' | 'advanced';\n\nexport interface ConditionInputProps {\n /** Name of the field the condition is created for. */\n fieldName: string;\n /** Type of the field the condition is created for. */\n fieldType: ConditionFieldType;\n /** Display mode. Either with default comparator or the full-fledged. */\n mode: ConditionInputMode;\n /** Label for the input. */\n fieldLabel?: string;\n /** Condition value. */\n condition?: LeafCondition;\n /** Callback invoked when user changes the condition. */\n onChange: (condition?: LeafCondition) => void;\n /** Reference to the input element. */\n ref?: Ref<HTMLInputElement>;\n /** Whether advanced view should be wrapped in popup or just flat. */\n flat?: boolean;\n}\n"]}
@@ -1,6 +1,11 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import { ForwardProps } from '@pega/cosmos-react-core';
3
+ import { Condition } from '../ConditionBuilder/ConditionBuilder.types';
3
4
  import { PromotedFiltersProps } from './PromotedFilters.types';
4
- declare const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps>;
5
+ export interface FilterModalProps extends Pick<PromotedFiltersProps, 'filters' | 'condition'> {
6
+ /** Callback fired on apply of any of the filters */
7
+ onApply?: (condition: Condition | undefined) => void;
8
+ }
9
+ export declare const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps>;
5
10
  export default PromotedFilters;
6
11
  //# sourceMappingURL=PromotedFilters.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAc,iBAAiB,EAAmB,MAAM,OAAO,CAAC;AAGvE,OAAO,EAAkC,YAAY,EAAW,MAAM,yBAAyB,CAAC;AAMhG,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAkB/D,QAAA,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAqE3E,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"PromotedFilters.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAOlB,MAAM,OAAO,CAAC;AAEf,OAAO,EAGL,YAAY,EAOb,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAiB,MAAM,4CAA4C,CAAC;AAItF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAO/D,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,oBAAoB,EAAE,SAAS,GAAG,WAAW,CAAC;IAC3F,oDAAoD;IACpD,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC;CACtD;AAgHD,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAkHlF,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,23 +1,12 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef } from 'react';
3
- import styled, { css } from 'styled-components';
4
- import { Button, defaultThemeProp, Flex, useI18n } from '@pega/cosmos-react-core';
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { forwardRef, useCallback, useContext, useEffect, useRef, useState } from 'react';
3
+ import { Button, Flex, Icon, Modal, ModalManagerContext, useBreakpoint, useI18n } from '@pega/cosmos-react-core';
5
4
  import { splitConditionForBuilder } from '../ConditionBuilder/core/utils';
6
5
  import ConditionInput from '../ConditionInput';
7
- const StyledPromotedFilters = styled.div(({ theme }) => {
8
- return css `
9
- border-radius: ${theme.components.card['border-radius']};
10
- background-color: ${theme.base.palette['secondary-background']};
11
- `;
12
- });
13
- StyledPromotedFilters.defaultProps = defaultThemeProp;
14
- const StyledClearAllButton = styled(Button) `
15
- margin-top: 0.625rem;
16
- white-space: nowrap;
17
- `;
18
- StyledClearAllButton.defaultProps = defaultThemeProp;
19
- const PromotedFilters = forwardRef(({ filters, condition, onChange }, ref) => {
20
- const t = useI18n();
6
+ import { StyledPromotedFilters, StyledClearAllButton, StyledTextWithEllipsis } from './PromotedFilters.styles';
7
+ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orientation: orientationProp = 'horizontal' }, ref) => {
8
+ const isSmallOrAbove = useBreakpoint('sm');
9
+ const orientation = isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';
21
10
  // map of Conditions indexed by field name
22
11
  const conditionsMap = condition
23
12
  ? splitConditionForBuilder(condition).rows.reduce((result, item) => {
@@ -38,13 +27,67 @@ const PromotedFilters = forwardRef(({ filters, condition, onChange }, ref) => {
38
27
  })
39
28
  };
40
29
  };
41
- return (_jsxs(Flex, { as: StyledPromotedFilters, container: { alignItems: 'start', justify: 'between', pad: 2, gap: 2 }, ref: ref, children: [_jsx(Flex, { container: { wrap: 'wrap', gap: 2 }, children: filters.map(filter => {
42
- return (_jsx(ConditionInput, { fieldName: filter.fieldName, fieldType: filter.fieldType, mode: filter.mode, fieldLabel: filter.fieldLabel ?? filter.fieldName, condition: conditionsMap[filter.fieldName], onChange: (newCondition) => {
43
- onChange(createUpdatedCondition(filter.fieldName, newCondition));
44
- } }, filter.fieldName));
45
- }) }), _jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
30
+ return (_jsx(Flex, { container: {
31
+ gap: 2,
32
+ direction: orientation === 'vertical' ? 'column' : 'row',
33
+ wrap: 'wrap'
34
+ }, ref: ref, children: filters.map(({ fieldName, fieldType, mode, fieldLabel }) => {
35
+ return (_jsx(ConditionInput, { fieldName: fieldName, fieldType: fieldType, mode: mode, fieldLabel: fieldLabel ?? fieldName, condition: conditionsMap[fieldName], flat: orientation === 'vertical', onChange: (newCondition) => {
36
+ onChange(createUpdatedCondition(fieldName, newCondition));
37
+ } }, fieldName));
38
+ }) }));
39
+ });
40
+ const FilterModal = ({ filters, condition, onApply }) => {
41
+ const t = useI18n();
42
+ const { ModalContext } = useContext(ModalManagerContext);
43
+ const { dismiss } = useContext(ModalContext);
44
+ const [newCondition, setNewCondition] = useState(condition);
45
+ const onApplyClick = useCallback(() => {
46
+ onApply?.(newCondition);
47
+ dismiss();
48
+ }, [newCondition, onApply]);
49
+ const actions = (_jsx(Button, { variant: 'primary', onClick: onApplyClick, children: t('apply') }));
50
+ return (_jsxs(Modal, { heading: t('filters'), actions: actions, stretch: true, children: [_jsx(Flex, { container: { justify: 'end' }, children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
51
+ setNewCondition(undefined);
52
+ }, children: t('clear_all') }) }), _jsx(PromotedFiltersContent, { filters: filters, condition: newCondition, onChange: setNewCondition, orientation: 'vertical' })] }));
53
+ };
54
+ export const PromotedFilters = forwardRef(({ filters, condition, onChange, orientation = 'horizontal' }, ref) => {
55
+ const t = useI18n();
56
+ const isSmallOrAbove = useBreakpoint('sm');
57
+ const { create } = useContext(ModalManagerContext);
58
+ const modalMethods = useRef();
59
+ // map of Conditions indexed by field name
60
+ const conditionsCount = condition ? splitConditionForBuilder(condition).rows.length : undefined;
61
+ useEffect(() => {
62
+ modalMethods.current?.update({
63
+ filters,
64
+ condition
65
+ });
66
+ }, [filters, condition]);
67
+ const openFiltersModal = () => {
68
+ modalMethods.current = create(FilterModal, {
69
+ filters,
70
+ condition,
71
+ onApply: onChange
72
+ });
73
+ };
74
+ return (_jsx(Flex, { as: StyledPromotedFilters, container: {
75
+ alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,
76
+ justify: 'between',
77
+ direction: !isSmallOrAbove || orientation === 'horizontal' ? 'row' : 'column',
78
+ pad: 2,
79
+ gap: 2
80
+ }, ref: ref, children: isSmallOrAbove ? (_jsxs(_Fragment, { children: [orientation === 'vertical' && (_jsxs(Flex, { container: {
81
+ justify: 'between',
82
+ alignItems: 'center',
83
+ pad: [0, 0, 1, 0]
84
+ }, children: [_jsx(StyledTextWithEllipsis, { variant: 'h3', children: t('filters') }), _jsx(Button, { variant: 'simple', onClick: () => {
85
+ onChange();
86
+ }, children: t('clear_all') })] })), _jsx(PromotedFiltersContent, { filters: filters, onChange: onChange, condition: condition, orientation: orientation, ref: ref }), orientation === 'horizontal' && (_jsx("div", { children: _jsx(StyledClearAllButton, { variant: 'simple', onClick: () => {
87
+ onChange();
88
+ }, children: t('promoted_filters_clear_all_button_label') }) }))] })) : (_jsxs(_Fragment, { children: [_jsx(Button, { type: 'button', variant: 'text', onClick: openFiltersModal, children: _jsxs(Flex, { container: { alignItems: 'center', gap: 0.5 }, forwardedAs: 'span', children: [_jsx(Icon, { name: 'filter' }), _jsxs("span", { children: [t('filters'), conditionsCount && `\u00a0(${conditionsCount})`] })] }) }), _jsx(Button, { variant: 'simple', onClick: () => {
46
89
  onChange();
47
- }, children: t('promoted_filters_clear_all_button_label') }) })] }));
90
+ }, children: t('clear_all') })] })) }));
48
91
  });
49
92
  export default PromotedFilters;
50
93
  //# sourceMappingURL=PromotedFilters.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAsC,MAAM,OAAO,CAAC;AACvE,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,IAAI,EAAgB,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGhG,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,cAAc,MAAM,mBAAmB,CAAC;AAI/C,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IACrD,OAAO,GAAG,CAAA;qBACS,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC;wBACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC;GAC/D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;CAG1C,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,eAAe,GAA2D,UAA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S,EAC3B,SAAS,EAAE,MAAM,CAAC,SAAS,EAC3B,IAAI,EAAE,MAAM,CAAC,IAAI,EACjB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,SAAS,EACjD,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,EAC1C,QAAQ,EAAE,CAAC,YAA4B,EAAE,EAAE;4BACzC,QAAQ,CAAC,sBAAsB,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC;wBACnE,CAAC,IARI,MAAM,CAAC,SAAS,CASrB,CACH,CAAC;gBACJ,CAAC,CAAC,GACG,EAEP,wBACE,KAAC,oBAAoB,IACnB,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAC;oBACb,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,IACD,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { forwardRef, FunctionComponent, PropsWithoutRef } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport { Button, defaultThemeProp, Flex, ForwardProps, useI18n } from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport { splitConditionForBuilder } from '../ConditionBuilder/core/utils';\nimport ConditionInput from '../ConditionInput';\n\nimport { PromotedFiltersProps } from './PromotedFilters.types';\n\nconst StyledPromotedFilters = styled.div(({ theme }) => {\n return css`\n border-radius: ${theme.components.card['border-radius']};\n background-color: ${theme.base.palette['secondary-background']};\n `;\n});\n\nStyledPromotedFilters.defaultProps = defaultThemeProp;\n\nconst StyledClearAllButton = styled(Button)`\n margin-top: 0.625rem;\n white-space: nowrap;\n`;\n\nStyledClearAllButton.defaultProps = defaultThemeProp;\n\nconst PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n { filters, condition, onChange }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n\n // map of Conditions indexed by field name\n const conditionsMap = condition\n ? splitConditionForBuilder(condition).rows.reduce(\n (result: { [key: string]: LeafCondition }, item) => {\n result[item.lhs.field] = item;\n return result;\n },\n {}\n )\n : {};\n\n const createUpdatedCondition = (key: string, newCondition?: LeafCondition) => {\n if (newCondition) {\n conditionsMap[key] = newCondition;\n } else {\n delete conditionsMap[key];\n }\n\n return {\n AND: Object.values(conditionsMap).map(c => {\n return { condition: c } as Condition;\n })\n };\n };\n\n return (\n <Flex\n as={StyledPromotedFilters}\n container={{ alignItems: 'start', justify: 'between', pad: 2, gap: 2 }}\n ref={ref}\n >\n <Flex container={{ wrap: 'wrap', gap: 2 }}>\n {filters.map(filter => {\n return (\n <ConditionInput\n key={filter.fieldName}\n fieldName={filter.fieldName}\n fieldType={filter.fieldType}\n mode={filter.mode}\n fieldLabel={filter.fieldLabel ?? filter.fieldName}\n condition={conditionsMap[filter.fieldName]}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(filter.fieldName, newCondition));\n }}\n />\n );\n })}\n </Flex>\n\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('promoted_filters_clear_all_button_label')}\n </StyledClearAllButton>\n </div>\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
1
+ {"version":3,"file":"PromotedFilters.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,WAAW,EACX,UAAU,EACV,SAAS,EACT,MAAM,EACN,QAAQ,EACT,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,MAAM,EACN,IAAI,EAEJ,IAAI,EACJ,KAAK,EAEL,mBAAmB,EACnB,aAAa,EACb,OAAO,EACR,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,C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,IACnB,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;4BACZ,QAAQ,EAAE,CAAC;wBACb,CAAC,YAEA,CAAC,CAAC,yCAAyC,CAAC,GACxB,GACnB,CACP,IACA,CACJ,CAAC,CAAC,CAAC,CACF,8BACE,KAAC,MAAM,IAAC,IAAI,EAAC,QAAQ,EAAC,OAAO,EAAC,MAAM,EAAC,OAAO,EAAE,gBAAgB,YAC5D,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,WAAW,EAAC,MAAM,aACrE,KAAC,IAAI,IAAC,IAAI,EAAC,QAAQ,GAAG,EACtB,2BACG,CAAC,CAAC,SAAS,CAAC,EACZ,eAAe,IAAI,UAAU,eAAe,GAAG,IAC3C,IACF,GACA,EACT,KAAC,MAAM,IACL,OAAO,EAAC,QAAQ,EAChB,OAAO,EAAE,GAAG,EAAE;wBACZ,QAAQ,EAAE,CAAC;oBACb,CAAC,YAEA,CAAC,CAAC,WAAW,CAAC,GACR,IACR,CACJ,GACI,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import {\n forwardRef,\n FunctionComponent,\n PropsWithoutRef,\n useCallback,\n useContext,\n useEffect,\n useRef,\n useState\n} from 'react';\n\nimport {\n Button,\n Flex,\n ForwardProps,\n Icon,\n Modal,\n ModalMethods,\n ModalManagerContext,\n useBreakpoint,\n useI18n\n} from '@pega/cosmos-react-core';\n\nimport { Condition, LeafCondition } from '../ConditionBuilder/ConditionBuilder.types';\nimport { splitConditionForBuilder } from '../ConditionBuilder/core/utils';\nimport ConditionInput from '../ConditionInput';\n\nimport { PromotedFiltersProps } from './PromotedFilters.types';\nimport {\n StyledPromotedFilters,\n StyledClearAllButton,\n StyledTextWithEllipsis\n} from './PromotedFilters.styles';\n\nexport interface FilterModalProps extends Pick<PromotedFiltersProps, 'filters' | 'condition'> {\n /** Callback fired on apply of any of the filters */\n onApply?: (condition: Condition | undefined) => void;\n}\n\nconst PromotedFiltersContent: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n {\n filters,\n condition,\n onChange,\n orientation: orientationProp = 'horizontal'\n }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const isSmallOrAbove = useBreakpoint('sm');\n const orientation =\n isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';\n\n // map of Conditions indexed by field name\n const conditionsMap = condition\n ? splitConditionForBuilder(condition).rows.reduce(\n (result: { [key: string]: LeafCondition }, item) => {\n result[item.lhs.field] = item;\n return result;\n },\n {}\n )\n : {};\n\n const createUpdatedCondition = (key: string, newCondition?: LeafCondition) => {\n if (newCondition) {\n conditionsMap[key] = newCondition;\n } else {\n delete conditionsMap[key];\n }\n\n return {\n AND: Object.values(conditionsMap).map(c => {\n return { condition: c } as Condition;\n })\n };\n };\n\n return (\n <Flex\n container={{\n gap: 2,\n direction: orientation === 'vertical' ? 'column' : 'row',\n wrap: 'wrap'\n }}\n ref={ref}\n >\n {filters.map(({ fieldName, fieldType, mode, fieldLabel }) => {\n return (\n <ConditionInput\n key={fieldName}\n fieldName={fieldName}\n fieldType={fieldType}\n mode={mode}\n fieldLabel={fieldLabel ?? fieldName}\n condition={conditionsMap[fieldName]}\n flat={orientation === 'vertical'}\n onChange={(newCondition?: LeafCondition) => {\n onChange(createUpdatedCondition(fieldName, newCondition));\n }}\n />\n );\n })}\n </Flex>\n );\n }\n);\n\nconst FilterModal = ({ filters, condition, onApply }: FilterModalProps) => {\n const t = useI18n();\n\n const { ModalContext } = useContext(ModalManagerContext);\n const { dismiss } = useContext(ModalContext);\n const [newCondition, setNewCondition] = useState<Condition | undefined>(condition);\n\n const onApplyClick = useCallback(() => {\n onApply?.(newCondition);\n dismiss();\n }, [newCondition, onApply]);\n\n const actions = (\n <Button variant='primary' onClick={onApplyClick}>\n {t('apply')}\n </Button>\n );\n\n return (\n <Modal heading={t('filters')} actions={actions} stretch>\n <Flex container={{ justify: 'end' }}>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n setNewCondition(undefined);\n }}\n >\n {t('clear_all')}\n </StyledClearAllButton>\n </Flex>\n\n <PromotedFiltersContent\n filters={filters}\n condition={newCondition}\n onChange={setNewCondition}\n orientation='vertical'\n />\n </Modal>\n );\n};\n\nexport const PromotedFilters: FunctionComponent<PromotedFiltersProps & ForwardProps> = forwardRef(\n (\n {\n filters,\n condition,\n onChange,\n orientation = 'horizontal'\n }: PropsWithoutRef<PromotedFiltersProps>,\n ref: PromotedFiltersProps['ref']\n ) => {\n const t = useI18n();\n\n const isSmallOrAbove = useBreakpoint('sm');\n\n const { create } = useContext(ModalManagerContext);\n const modalMethods = useRef<ModalMethods<FilterModalProps>>();\n\n // map of Conditions indexed by field name\n const conditionsCount = condition ? splitConditionForBuilder(condition).rows.length : undefined;\n\n useEffect(() => {\n modalMethods.current?.update({\n filters,\n condition\n });\n }, [filters, condition]);\n\n const openFiltersModal = () => {\n modalMethods.current = create(FilterModal, {\n filters,\n condition,\n onApply: onChange\n });\n };\n\n return (\n <Flex\n as={StyledPromotedFilters}\n container={{\n alignItems: orientation === 'horizontal' && isSmallOrAbove ? 'start' : undefined,\n justify: 'between',\n direction: !isSmallOrAbove || orientation === 'horizontal' ? 'row' : 'column',\n pad: 2,\n gap: 2\n }}\n ref={ref}\n >\n {isSmallOrAbove ? (\n <>\n {orientation === 'vertical' && (\n <Flex\n container={{\n justify: 'between',\n alignItems: 'center',\n pad: [0, 0, 1, 0]\n }}\n >\n <StyledTextWithEllipsis variant='h3'>{t('filters')}</StyledTextWithEllipsis>\n <Button\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('clear_all')}\n </Button>\n </Flex>\n )}\n\n <PromotedFiltersContent\n filters={filters}\n onChange={onChange}\n condition={condition}\n orientation={orientation}\n ref={ref}\n />\n\n {orientation === 'horizontal' && (\n <div>\n <StyledClearAllButton\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('promoted_filters_clear_all_button_label')}\n </StyledClearAllButton>\n </div>\n )}\n </>\n ) : (\n <>\n <Button type='button' variant='text' onClick={openFiltersModal}>\n <Flex container={{ alignItems: 'center', gap: 0.5 }} forwardedAs='span'>\n <Icon name='filter' />\n <span>\n {t('filters')}\n {conditionsCount && `\\u00a0(${conditionsCount})`}\n </span>\n </Flex>\n </Button>\n <Button\n variant='simple'\n onClick={() => {\n onChange();\n }}\n >\n {t('clear_all')}\n </Button>\n </>\n )}\n </Flex>\n );\n }\n);\n\nexport default PromotedFilters;\n"]}
@@ -0,0 +1,4 @@
1
+ export declare const StyledPromotedFilters: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
2
+ export declare const StyledClearAllButton: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").ButtonProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
3
+ export declare const StyledTextWithEllipsis: import("styled-components").StyledComponent<import("react").FunctionComponent<import("@pega/cosmos-react-core").TextProps & import("@pega/cosmos-react-core").ForwardProps>, import("styled-components").DefaultTheme, {}, never>;
4
+ //# sourceMappingURL=PromotedFilters.styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromotedFilters.styles.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,yGAKhC,CAAC;AAIH,eAAO,MAAM,oBAAoB,qOAOhC,CAAC;AAIF,eAAO,MAAM,sBAAsB,mOAIlC,CAAC"}
@@ -0,0 +1,26 @@
1
+ import styled, { css } from 'styled-components';
2
+ import { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';
3
+ import { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';
4
+ export const StyledPromotedFilters = styled.div(({ theme }) => {
5
+ return css `
6
+ border-radius: ${theme.components.card['border-radius']};
7
+ background-color: ${theme.base.palette['secondary-background']};
8
+ `;
9
+ });
10
+ StyledPromotedFilters.defaultProps = defaultThemeProp;
11
+ export const StyledClearAllButton = styled(Button) `
12
+ margin: 1.125rem 0 0.625rem;
13
+ white-space: nowrap;
14
+
15
+ ${StyledModalChildrenWrap} & {
16
+ margin-top: 0;
17
+ }
18
+ `;
19
+ StyledClearAllButton.defaultProps = defaultThemeProp;
20
+ export const StyledTextWithEllipsis = styled(Text) `
21
+ overflow: hidden;
22
+ white-space: nowrap;
23
+ text-overflow: ellipsis;
24
+ `;
25
+ StyledTextWithEllipsis.defaultProps = defaultThemeProp;
26
+ //# sourceMappingURL=PromotedFilters.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromotedFilters.styles.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.styles.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2DAA2D,CAAC;AAEpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;IAC5D,OAAO,GAAG,CAAA;qBACS,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC;wBACnC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC;GAC/D,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,qBAAqB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;;;;IAI9C,uBAAuB;;;CAG1B,CAAC;AAEF,oBAAoB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;;;;CAIjD,CAAC;AAEF,sBAAsB,CAAC,YAAY,GAAG,gBAAgB,CAAC","sourcesContent":["import styled, { css } from 'styled-components';\n\nimport { defaultThemeProp, Button, Text } from '@pega/cosmos-react-core';\nimport { StyledModalChildrenWrap } from '@pega/cosmos-react-core/lib/components/Modal/Modal.styles';\n\nexport const StyledPromotedFilters = styled.div(({ theme }) => {\n return css`\n border-radius: ${theme.components.card['border-radius']};\n background-color: ${theme.base.palette['secondary-background']};\n `;\n});\n\nStyledPromotedFilters.defaultProps = defaultThemeProp;\n\nexport const StyledClearAllButton = styled(Button)`\n margin: 1.125rem 0 0.625rem;\n white-space: nowrap;\n\n ${StyledModalChildrenWrap} & {\n margin-top: 0;\n }\n`;\n\nStyledClearAllButton.defaultProps = defaultThemeProp;\n\nexport const StyledTextWithEllipsis = styled(Text)`\n overflow: hidden;\n white-space: nowrap;\n text-overflow: ellipsis;\n`;\n\nStyledTextWithEllipsis.defaultProps = defaultThemeProp;\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Ref } from 'react';
2
- import { BaseProps } from '@pega/cosmos-react-core';
2
+ import { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';
3
3
  import type { Condition } from '../ConditionBuilder/ConditionBuilder.types';
4
4
  import type { ConditionInputMode, ConditionFieldType } from '../ConditionInput/ConditionInput.types';
5
5
  export interface PromotedFilter {
@@ -12,11 +12,13 @@ export interface PromotedFilter {
12
12
  /** Label for the filter. */
13
13
  fieldLabel?: string;
14
14
  }
15
- export interface PromotedFiltersProps extends BaseProps {
15
+ export interface PromotedFiltersProps extends BaseProps, NoChildrenProp {
16
16
  /** Configuration of filters for every field that has been defined as promoted. */
17
17
  filters: PromotedFilter[];
18
18
  /** A value representing the current condition state. */
19
19
  condition?: Condition;
20
+ /** Orientation mode. The default is horizontal. */
21
+ orientation?: 'vertical' | 'horizontal';
20
22
  /** Callback fired on change of any of the filters. */
21
23
  onChange: (condition?: Condition) => void;
22
24
  /** Ref for the wrapping element. */
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.types.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,oBAAoB;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS;IACrD,kFAAkF;IAClF,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,sDAAsD;IACtD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
1
+ {"version":3,"file":"PromotedFilters.types.d.ts","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,wCAAwC,CAAC;AAEhD,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,yBAAyB;IACzB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,oBAAoB;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS,EAAE,cAAc;IACrE,kFAAkF;IAClF,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,wDAAwD;IACxD,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,mDAAmD;IACnD,WAAW,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC;IACxC,sDAAsD;IACtD,QAAQ,EAAE,CAAC,SAAS,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,oCAAoC;IACpC,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CAC3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"PromotedFilters.types.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps } from '@pega/cosmos-react-core';\n\nimport type { Condition } from '../ConditionBuilder/ConditionBuilder.types';\nimport type {\n ConditionInputMode,\n ConditionFieldType\n} from '../ConditionInput/ConditionInput.types';\n\nexport interface PromotedFilter {\n /** Unique field identifier. */\n fieldName: string;\n /** Type of the field. */\n fieldType: ConditionFieldType;\n /** Display mode. */\n mode: ConditionInputMode;\n /** Label for the filter. */\n fieldLabel?: string;\n}\n\nexport interface PromotedFiltersProps extends BaseProps {\n /** Configuration of filters for every field that has been defined as promoted. */\n filters: PromotedFilter[];\n /** A value representing the current condition state. */\n condition?: Condition;\n /** Callback fired on change of any of the filters. */\n onChange: (condition?: Condition) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
1
+ {"version":3,"file":"PromotedFilters.types.js","sourceRoot":"","sources":["../../../src/components/PromotedFilters/PromotedFilters.types.ts"],"names":[],"mappings":"","sourcesContent":["import { Ref } from 'react';\n\nimport { BaseProps, NoChildrenProp } from '@pega/cosmos-react-core';\n\nimport type { Condition } from '../ConditionBuilder/ConditionBuilder.types';\nimport type {\n ConditionInputMode,\n ConditionFieldType\n} from '../ConditionInput/ConditionInput.types';\n\nexport interface PromotedFilter {\n /** Unique field identifier. */\n fieldName: string;\n /** Type of the field. */\n fieldType: ConditionFieldType;\n /** Display mode. */\n mode: ConditionInputMode;\n /** Label for the filter. */\n fieldLabel?: string;\n}\n\nexport interface PromotedFiltersProps extends BaseProps, NoChildrenProp {\n /** Configuration of filters for every field that has been defined as promoted. */\n filters: PromotedFilter[];\n /** A value representing the current condition state. */\n condition?: Condition;\n /** Orientation mode. The default is horizontal. */\n orientation?: 'vertical' | 'horizontal';\n /** Callback fired on change of any of the filters. */\n onChange: (condition?: Condition) => void;\n /** Ref for the wrapping element. */\n ref?: Ref<HTMLDivElement>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pega/cosmos-react-condition-builder",
3
- "version": "3.0.0-dev.16.1",
3
+ "version": "3.0.0-dev.18.1",
4
4
  "author": "Pegasystems",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "build": "tsc -b"
24
24
  },
25
25
  "dependencies": {
26
- "@pega/cosmos-react-core": "3.0.0-dev.16.1",
26
+ "@pega/cosmos-react-core": "3.0.0-dev.18.1",
27
27
  "@types/react": "^16.14.24 || ^17.0.38",
28
28
  "@types/react-dom": "^16.9.14 || ^17.0.11",
29
29
  "@types/styled-components": "^5.1.7",