@pega/cosmos-react-condition-builder 3.0.0-dev.16.1 → 3.0.0-dev.17.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.
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAwB,MAAM,yBAAyB,CAAC;AAE1F,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;CAClB;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CAwBtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"NumericInput.d.ts","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,MAAM,OAAO,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,cAAc,EAIf,MAAM,yBAAyB,CAAC;AAEjC,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;CAClB;AAED,4IAA4I;AAC5I,QAAA,MAAM,YAAY,EAAE,iBAAiB,CAAC,iBAAiB,CA4BtD,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useState } from 'react';
3
- import { NumberInput, useI18n } from '@pega/cosmos-react-core';
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
6
  const { rhs, onChange, status } = props;
@@ -9,6 +9,9 @@ const NumericInput = (props) => {
9
9
  // if we parse values like `12.`, `12.0`, etc., the decimals will be lost leading to bad UX
10
10
  // Using a local state to avoid that
11
11
  const [localValue, setLocalValue] = useState(rhs.value.toString());
12
+ useAfterInitialEffect(() => {
13
+ setLocalValue(rhs.value.toString());
14
+ }, [rhs]);
12
15
  const handleInputChange = (newValue) => {
13
16
  setLocalValue(newValue);
14
17
  onChange({ value: newValue.trim() ? Number(newValue) : '' }); // Save as a number unless the input is empty
@@ -1 +1 @@
1
- {"version":3,"file":"NumericInput.js","sourceRoot":"","sources":["../../../../src/components/ConditionBuilder/RhsControls/NumericInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAA6B,WAAW,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAa1F,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACxC,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,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,8CAA8C,CAAC,EACxD,WAAW,SACX,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { FunctionComponent, useState } from 'react';\n\nimport { BaseProps, NoChildrenProp, NumberInput, useI18n } 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\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 } = 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 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_compare_with_numeric_value')}\n labelHidden\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,EAAqB,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAGL,WAAW,EACX,qBAAqB,EACrB,OAAO,EACR,MAAM,yBAAyB,CAAC;AAajC,4IAA4I;AAC5I,MAAM,YAAY,GAAyC,CAAC,KAAwB,EAAE,EAAE;IACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;IACxC,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,CAAC,CAAC;IAEV,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,8CAA8C,CAAC,EACxD,WAAW,SACX,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC","sourcesContent":["import { FunctionComponent, useState } from 'react';\n\nimport {\n BaseProps,\n NoChildrenProp,\n NumberInput,\n useAfterInitialEffect,\n useI18n\n} 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\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 } = 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]);\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_compare_with_numeric_value')}\n labelHidden\n />\n );\n};\n\nexport default NumericInput;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAIL,YAAY,EAQb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAsB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAkCjF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CA6KzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"ConditionInput.d.ts","sourceRoot":"","sources":["../../../src/components/ConditionInput/ConditionInput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EAKlB,MAAM,OAAO,CAAC;AAGf,OAAO,EAIL,YAAY,EAWb,MAAM,yBAAyB,CAAC;AAUjC,OAAO,EAAsB,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AA0DjF,QAAA,MAAM,cAAc,EAAE,iBAAiB,CAAC,mBAAmB,GAAG,YAAY,CAqMzE,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -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 } 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 = {
@@ -32,7 +32,23 @@ const StyledConditionRadioGroup = styled(RadioButtonGroup) `
32
32
  } ;
33
33
  `;
34
34
  StyledConditionRadioGroup.defaultProps = defaultThemeProp;
35
- const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange }, ref) => {
35
+ const StyledFieldGroup = styled(FieldGroup)(({ theme: { base: { palette } } }) => {
36
+ return css `
37
+ margin-block-start: 0;
38
+
39
+ ${StyledFieldGroupLegend} {
40
+ border-block-start: 0.0625rem solid ${palette['border-line']};
41
+ padding-block-start: 0.625rem;
42
+
43
+ ${StyledButton} {
44
+ border-color: transparent;
45
+ font-weight: initial;
46
+ }
47
+ }
48
+ `;
49
+ });
50
+ StyledFieldGroup.defaultProps = defaultThemeProp;
51
+ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionProp, fieldLabel, mode, onChange, flat = false }, ref) => {
36
52
  const t = useI18n();
37
53
  const basicType = basicFieldMap[fieldType] ?? fieldType;
38
54
  const fields = [
@@ -118,7 +134,14 @@ const ConditionInput = forwardRef(({ fieldName, fieldType, condition: conditionP
118
134
  onChange(undefined);
119
135
  setNewCondition(condition);
120
136
  };
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) }));
137
+ if (flat) {
138
+ return (_jsx(StyledFieldGroup, { name: fieldLabel, collapsible: true, actions: [{ id: 'clear', text: t('clear'), onClick: onClear }], children: showAdvanced ? (_jsx(AtomicCondition, { condition: newCondition ??
139
+ getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL'])), onChange: onChange, fields: fields, itemDirection: 'column', showLhsAsLabel: true, validRhsTypes: new Set(['LITERAL']), indicateErrors: false })) : (defaultControl) }));
140
+ }
141
+ if (showAdvanced) {
142
+ return (_jsx(CompositeInput, { dialog: dialog, label: fieldLabel, onClear: onClear, value: conditionProp ? formatCondition({ condition: conditionProp }, fields, t) : undefined, placeholder: t('all'), ref: ref }));
143
+ }
144
+ return defaultControl;
122
145
  });
123
146
  export default ConditionInput;
124
147
  //# 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;IACX,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,QAAQ;IACjB,UAAU,EAAE,QAAQ;IACpB,QAAQ,EAAE,QAAQ;IAClB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;CACV,CAAC;AAEX,MAAM,yBAAyB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAA;IACtD,UAAU;;;CAGb,CAAC;AAEF,yBAAyB,CAAC,YAAY,GAAG,gBAAgB,CAAC;AAE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Y;gBACZ,sBAAsB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC5E,MAAM;YACN,QAAQ,EAAE,eAAe;YACzB,aAAa,EAAE,QAAQ;YACvB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;YACnC,cAAc,EAAE,KAAK;SACtB;QACD,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;YACtB,eAAe,CAAC,SAAS,CAAC,CAAC;YAC3B,KAAK,EAAE,CAAC;QACV,CAAC;QACD,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE;YACrB,QAAQ,CAAC,YAAY,CAAC,CAAC;YACvB,KAAK,EAAE,CAAC;QACV,CAAC;KACF,CAAC;IAEF,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpB,eAAe,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,OAAO,CACL,4BACG,YAAY,CAAC,CAAC,CAAC,CACd,KAAC,cAAc,IACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,EAChB,KAAK,EACH,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,MAAM,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.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,UAAU,EAGV,QAAQ,EAER,SAAS,EACV,MAAM,OAAO,CAAC;AACf,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,cAAc,EAEd,gBAAgB,EAEhB,OAAO,EACP,KAAK,EACL,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,OAAO,EACP,UAAU,EACV,sBAAsB,EACtB,YAAY,EACb,MAAM,y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ACL,KAAC,cAAc,IACb,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,OAAO,EAChB,KAAK,EACH,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,EAEtF,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,EACrB,GAAG,EAAE,GAAG,GACR,CACH,CAAC;KACH;IACD,OAAO,cAAc,CAAC;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 } 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} 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 StyledFieldGroup = styled(FieldGroup)(\n ({\n theme: {\n base: { palette }\n }\n }) => {\n return css`\n margin-block-start: 0;\n\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);\n\nStyledFieldGroup.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\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 if (flat) {\n return (\n <StyledFieldGroup\n name={fieldLabel}\n collapsible\n actions={[{ id: 'clear', text: t('clear'), onClick: onClear }]}\n >\n {showAdvanced ? (\n <AtomicCondition\n condition={\n newCondition ??\n getInitConditionForLhs({ field: fieldName }, fields, new Set(['LITERAL']))\n }\n onChange={onChange}\n fields={fields}\n itemDirection='column'\n showLhsAsLabel\n validRhsTypes={new Set(['LITERAL'])}\n indicateErrors={false}\n />\n ) : (\n defaultControl\n )}\n </StyledFieldGroup>\n );\n }\n if (showAdvanced) {\n return (\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 }\n return defaultControl;\n }\n);\n\nexport default ConditionInput;\n"]}
@@ -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,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;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\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,EAMb,MAAM,yBAAyB,CAAC;AAMjC,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;AA+GD,eAAO,MAAM,eAAe,EAAE,iBAAiB,CAAC,oBAAoB,GAAG,YAAY,CAkHlF,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,23 +1,13 @@
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, useBreakpoint, useI18n } from '@pega/cosmos-react-core';
4
+ import { ModalContext, ModalManagerContext } from '@pega/cosmos-react-core/lib/components/Modal/Contexts';
5
5
  import { splitConditionForBuilder } from '../ConditionBuilder/core/utils';
6
6
  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();
7
+ import { StyledPromotedFilters, StyledClearAllButton, StyledTextWithEllipsis } from './PromotedFilters.styles';
8
+ const PromotedFiltersContent = forwardRef(({ filters, condition, onChange, orientation: orientationProp = 'horizontal' }, ref) => {
9
+ const isSmallOrAbove = useBreakpoint('sm');
10
+ const orientation = isSmallOrAbove && orientationProp === 'horizontal' ? 'horizontal' : 'vertical';
21
11
  // map of Conditions indexed by field name
22
12
  const conditionsMap = condition
23
13
  ? splitConditionForBuilder(condition).rows.reduce((result, item) => {
@@ -38,13 +28,66 @@ const PromotedFilters = forwardRef(({ filters, condition, onChange }, ref) => {
38
28
  })
39
29
  };
40
30
  };
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: () => {
31
+ return (_jsx(Flex, { container: {
32
+ gap: 2,
33
+ direction: orientation === 'vertical' ? 'column' : 'row',
34
+ wrap: 'wrap'
35
+ }, ref: ref, children: filters.map(({ fieldName, fieldType, mode, fieldLabel }) => {
36
+ return (_jsx(ConditionInput, { fieldName: fieldName, fieldType: fieldType, mode: mode, fieldLabel: fieldLabel ?? fieldName, condition: conditionsMap[fieldName], flat: orientation === 'vertical', onChange: (newCondition) => {
37
+ onChange(createUpdatedCondition(fieldName, newCondition));
38
+ } }, fieldName));
39
+ }) }));
40
+ });
41
+ const FilterModal = ({ filters, condition, onApply }) => {
42
+ const t = useI18n();
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,GAA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KAAC,cAAc,IAEb,SAAS,EAAE,MAAM,CAAC,SAAS,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,aAAa,EACb,OAAO,EACR,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,Y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CAC/B,wBACE,KAAC,oBAAoB,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 useBreakpoint,\n useI18n\n} from '@pega/cosmos-react-core';\nimport {\n ModalContext,\n ModalManagerContext\n} from '@pega/cosmos-react-core/lib/components/Modal/Contexts';\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 { 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.17.0",
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.17.0",
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",