@shopgate/engage 7.32.0-beta.14 → 7.32.0-beta.16
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.
- package/cart/components/CartItem/CartItemQuantityPicker.js +1 -1
- package/components/Badge/Badge.d.ts.map +1 -1
- package/components/Badge/Badge.js +1 -0
- package/components/index.d.ts +1 -0
- package/components/index.d.ts.map +1 -1
- package/components/index.js +3 -1
- package/components/v2/IconButton/IconButton.d.ts +72 -0
- package/components/v2/IconButton/IconButton.d.ts.map +1 -0
- package/components/v2/IconButton/IconButton.js +169 -0
- package/components/v2/IconButton/index.d.ts +3 -0
- package/components/v2/IconButton/index.d.ts.map +1 -0
- package/components/v2/IconButton/index.js +1 -0
- package/components/v2/index.d.ts +1 -0
- package/components/v2/index.d.ts.map +1 -1
- package/components/v2/index.js +1 -0
- package/filter/components/FilterItem/index.js +9 -2
- package/filter/components/FilterPageContent/components/ApplyButton/index.d.ts +21 -0
- package/filter/components/FilterPageContent/components/ApplyButton/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/ApplyButton/index.js +25 -52
- package/filter/components/FilterPageContent/components/FilterButtonBar/index.d.ts +8 -0
- package/filter/components/FilterPageContent/components/FilterButtonBar/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/FilterButtonBar/index.js +63 -0
- package/filter/components/FilterPageContent/components/ResetButton/index.d.ts +17 -0
- package/filter/components/FilterPageContent/components/ResetButton/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/ResetButton/index.js +24 -46
- package/filter/components/FilterPageContent/components/Selector/components/Selected/index.d.ts +19 -0
- package/filter/components/FilterPageContent/components/Selector/components/Selected/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/Selector/components/Selected/index.js +25 -46
- package/filter/components/FilterPageContent/components/Selector/components/Toggle/index.d.ts +14 -0
- package/filter/components/FilterPageContent/components/Selector/components/Toggle/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/Selector/components/Toggle/index.js +13 -46
- package/filter/components/FilterPageContent/components/Selector/components/ValueCheckbox/index.d.ts +25 -0
- package/filter/components/FilterPageContent/components/Selector/components/ValueCheckbox/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/Selector/components/ValueCheckbox/index.js +77 -0
- package/filter/components/FilterPageContent/components/Selector/index.d.ts +43 -0
- package/filter/components/FilterPageContent/components/Selector/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/components/Selector/index.js +52 -40
- package/filter/components/FilterPageContent/index.d.ts +16 -0
- package/filter/components/FilterPageContent/index.d.ts.map +1 -0
- package/filter/components/FilterPageContent/index.js +51 -57
- package/filter/components/PriceSlider/components/Label/index.js +69 -94
- package/filter/components/PriceSlider/index.js +43 -33
- package/filter/helpers/buildFilterParamsForFetchFiltersRequest.d.ts +8 -0
- package/filter/helpers/buildFilterParamsForFetchFiltersRequest.d.ts.map +1 -0
- package/filter/helpers/buildInitialFilters.d.ts +7 -0
- package/filter/helpers/buildInitialFilters.d.ts.map +1 -0
- package/filter/helpers/buildUpdatedFilters.d.ts +7 -0
- package/filter/helpers/buildUpdatedFilters.d.ts.map +1 -0
- package/filter/helpers/index.d.ts +5 -0
- package/filter/helpers/index.d.ts.map +1 -0
- package/filter/helpers/translateFilterLabel.d.ts +8 -0
- package/filter/helpers/translateFilterLabel.d.ts.map +1 -0
- package/filter/providers/FilterPageProvider.context.d.ts +157 -0
- package/filter/providers/FilterPageProvider.context.d.ts.map +1 -0
- package/filter/providers/FilterPageProvider.d.ts +24 -0
- package/filter/providers/FilterPageProvider.d.ts.map +1 -0
- package/filter/providers/FilterPageProvider.js +77 -132
- package/locations/components/GlobalLocationSwitcher/GlobalLocationSwitcherBar.js +4 -2
- package/package.json +7 -7
- package/page/widgets/CategoryList/CategoryList.js +2 -1
- package/product/components/FilterBar/components/Content/components/FilterButton/index.js +38 -46
- package/product/components/FilterBar/components/Content/components/FilterChips/components/FilterChip/index.d.ts +38 -0
- package/product/components/FilterBar/components/Content/components/FilterChips/components/FilterChip/index.d.ts.map +1 -0
- package/product/components/FilterBar/components/Content/components/FilterChips/components/FilterChip/index.js +88 -0
- package/product/components/FilterBar/components/Content/components/FilterChips/index.js +54 -35
- package/product/components/FilterBar/components/Content/components/Sort/index.js +1 -1
- package/product/components/FilterBar/components/Content/index.js +7 -3
- package/product/components/FilterBar/index.js +11 -22
- package/product/components/ProductFilters/index.js +2 -6
- package/product/components/ProductGrid/components/Item/components/ItemFavoritesButton/index.js +0 -1
- package/product/components/ProductGridPrice/index.js +1 -1
- package/settings/reducers/appSettings.js +1 -1
- package/styles/theme/createDefaultThemeOptions/index.d.ts +11 -1
- package/styles/theme/createDefaultThemeOptions/index.d.ts.map +1 -1
- package/styles/theme/createDefaultThemeOptions/index.js +17 -5
- package/styles/theme/createTheme/createComponents.types.d.ts +27 -0
- package/styles/theme/createTheme/createComponents.types.d.ts.map +1 -1
- package/styles/theme/createTheme/createComponents.types.js +31 -4
- package/filter/components/FilterPageContent/components/Selector/components/ValueButton/index.js +0 -69
- package/product/components/FilterBar/components/Content/components/FilterChips/connector.js +0 -22
|
@@ -1,55 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import { memo } from 'react';
|
|
3
2
|
import { I18n, SurroundPortals } from '@shopgate/engage/components';
|
|
4
3
|
import { Button } from '@shopgate/engage/components/v2';
|
|
5
|
-
import { makeStyles } from '@shopgate/engage/styles';
|
|
6
4
|
import { PORTAL_FILTER_RESET_BUTTON } from '@shopgate/engage/filter/constants';
|
|
7
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
const useStyles = makeStyles()(theme => ({
|
|
9
|
-
buttonContainer: {
|
|
10
|
-
marginTop: theme.spacing(0.5),
|
|
11
|
-
marginRight: theme.spacing(2),
|
|
12
|
-
marginBottom: 40,
|
|
13
|
-
textAlign: 'right'
|
|
14
|
-
}
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
6
|
/**
|
|
18
|
-
* The filter reset button
|
|
19
|
-
* @
|
|
20
|
-
* @param {boolean} props.disabled Whether the button is disabled
|
|
21
|
-
* @param {Function} props.onClick Click handler for the button
|
|
22
|
-
* @returns {JSX.Element}
|
|
7
|
+
* The filter reset button, rendered as "Clear all" in the filter button bar.
|
|
8
|
+
* @returns The rendered component.
|
|
23
9
|
*/
|
|
24
10
|
const FilterResetButton = ({
|
|
25
|
-
disabled,
|
|
26
|
-
onClick
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
testId: "clearAllButton",
|
|
45
|
-
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
46
|
-
string: "filter.reset"
|
|
47
|
-
})
|
|
48
|
-
})
|
|
11
|
+
disabled = false,
|
|
12
|
+
onClick,
|
|
13
|
+
className
|
|
14
|
+
}) => /*#__PURE__*/_jsx(SurroundPortals, {
|
|
15
|
+
portalName: PORTAL_FILTER_RESET_BUTTON,
|
|
16
|
+
portalProps: {
|
|
17
|
+
disabled,
|
|
18
|
+
onClick
|
|
19
|
+
},
|
|
20
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
21
|
+
className: className,
|
|
22
|
+
variant: "outlined",
|
|
23
|
+
onClick: onClick,
|
|
24
|
+
disabled: disabled,
|
|
25
|
+
fullWidth: true,
|
|
26
|
+
size: "small",
|
|
27
|
+
testId: "clearAllButton",
|
|
28
|
+
children: /*#__PURE__*/_jsx(I18n.Text, {
|
|
29
|
+
string: "filter.clear_all"
|
|
49
30
|
})
|
|
50
|
-
})
|
|
51
|
-
};
|
|
52
|
-
FilterResetButton.defaultProps = {
|
|
53
|
-
disabled: false
|
|
54
|
-
};
|
|
31
|
+
})
|
|
32
|
+
});
|
|
55
33
|
export default /*#__PURE__*/memo(FilterResetButton);
|
package/filter/components/FilterPageContent/components/Selector/components/Selected/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface SelectedValue {
|
|
2
|
+
/**
|
|
3
|
+
* Id of the filter value.
|
|
4
|
+
*/
|
|
5
|
+
id: string;
|
|
6
|
+
/**
|
|
7
|
+
* Display label of the filter value.
|
|
8
|
+
*/
|
|
9
|
+
label: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SelectedProps {
|
|
12
|
+
/**
|
|
13
|
+
* The selected filter values, already ordered for display.
|
|
14
|
+
*/
|
|
15
|
+
values: SelectedValue[];
|
|
16
|
+
}
|
|
17
|
+
declare const _default: import("react").MemoExoticComponent<({ values }: SelectedProps) => import("react").JSX.Element | null>;
|
|
18
|
+
export default _default;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
package/filter/components/FilterPageContent/components/Selector/components/Selected/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../filter/components/FilterPageContent/components/Selector/components/Selected/index.tsx"],"names":[],"mappings":"AAkBA,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;yEAM6B,aAAa;AAgB3C,wBAA8B"}
|
package/filter/components/FilterPageContent/components/Selector/components/Selected/index.js
CHANGED
|
@@ -1,63 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "core-js/modules/es.array.reduce.js";
|
|
3
|
-
import React, { Fragment, memo, useMemo } from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import { memo } from 'react';
|
|
5
2
|
import { makeStyles } from '@shopgate/engage/styles';
|
|
6
|
-
import { jsx as _jsx
|
|
7
|
-
const useStyles = makeStyles()(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
textOverflow: 'ellipsis',
|
|
13
|
-
whiteSpace: 'nowrap'
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
const useStyles = makeStyles()(theme => ({
|
|
5
|
+
chips: {
|
|
6
|
+
display: 'flex',
|
|
7
|
+
flexWrap: 'wrap',
|
|
8
|
+
gap: theme.spacing(0.5)
|
|
14
9
|
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
chip: {
|
|
11
|
+
...theme.typography.body2,
|
|
12
|
+
padding: theme.spacing(0.25, 1.25),
|
|
13
|
+
borderRadius: theme.shape.borderRadius,
|
|
14
|
+
border: `1px solid ${theme.palette.secondary.main}`,
|
|
15
|
+
overflowWrap: 'anywhere'
|
|
19
16
|
}
|
|
20
17
|
}));
|
|
21
|
-
|
|
22
18
|
/**
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
* @returns {JSX.Element|null}
|
|
19
|
+
* Renders the selected filter values as chips in the accordion header.
|
|
20
|
+
* @returns The rendered component.
|
|
26
21
|
*/
|
|
27
22
|
const Selected = ({
|
|
28
|
-
selected,
|
|
29
23
|
values
|
|
30
24
|
}) => {
|
|
31
25
|
const {
|
|
32
26
|
classes
|
|
33
27
|
} = useStyles();
|
|
34
|
-
|
|
35
|
-
if (!selected || selected.length === 0) {
|
|
36
|
-
return [];
|
|
37
|
-
}
|
|
38
|
-
return values.reduce((prevValues, value) => {
|
|
39
|
-
if (selected.includes(value.id)) {
|
|
40
|
-
prevValues.push(value.label);
|
|
41
|
-
}
|
|
42
|
-
return prevValues;
|
|
43
|
-
}, []);
|
|
44
|
-
}, [selected, values]);
|
|
45
|
-
if (!selected || selected.length === 0) {
|
|
28
|
+
if (values.length === 0) {
|
|
46
29
|
return null;
|
|
47
30
|
}
|
|
48
|
-
return /*#__PURE__*/_jsx(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, item))
|
|
31
|
+
return /*#__PURE__*/_jsx("div", {
|
|
32
|
+
className: classes.chips,
|
|
33
|
+
children: values.map(({
|
|
34
|
+
id,
|
|
35
|
+
label
|
|
36
|
+
}) => /*#__PURE__*/_jsx("span", {
|
|
37
|
+
className: classes.chip,
|
|
38
|
+
children: label
|
|
39
|
+
}, id))
|
|
58
40
|
});
|
|
59
41
|
};
|
|
60
|
-
Selected.defaultProps = {
|
|
61
|
-
selected: null
|
|
62
|
-
};
|
|
63
42
|
export default /*#__PURE__*/memo(Selected);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface ToggleProps {
|
|
3
|
+
/**
|
|
4
|
+
* The filter label.
|
|
5
|
+
*/
|
|
6
|
+
label: ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* The selected values element rendered below the label.
|
|
9
|
+
*/
|
|
10
|
+
selected?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import("react").MemoExoticComponent<({ label, selected }: ToggleProps) => import("react").JSX.Element>;
|
|
13
|
+
export default _default;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
package/filter/components/FilterPageContent/components/Selector/components/Toggle/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../filter/components/FilterPageContent/components/Selector/components/Toggle/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAkBvC,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;kFAM2C,WAAW;AAavD,wBAA4B"}
|
|
@@ -1,71 +1,38 @@
|
|
|
1
|
-
import
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
1
|
+
import { memo } from 'react';
|
|
3
2
|
import { makeStyles } from '@shopgate/engage/styles';
|
|
4
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
4
|
const useStyles = makeStyles()(theme => ({
|
|
6
5
|
toggle: {
|
|
7
6
|
display: 'flex',
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
flexDirection: 'column',
|
|
8
|
+
alignItems: 'flex-start',
|
|
9
|
+
gap: theme.spacing(1),
|
|
10
|
+
flex: 1,
|
|
11
|
+
minWidth: 0
|
|
11
12
|
},
|
|
12
13
|
label: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
flexGrow: 1,
|
|
16
|
-
textAlign: 'left',
|
|
17
|
-
maxWidth: '50%',
|
|
18
|
-
minWidth: '35%',
|
|
19
|
-
paddingRight: '16px'
|
|
20
|
-
},
|
|
21
|
-
selected: {
|
|
22
|
-
display: 'flex',
|
|
23
|
-
flexFlow: 'row wrap',
|
|
24
|
-
flexGrow: 1,
|
|
25
|
-
justifyContent: 'flex-end',
|
|
26
|
-
minWidth: '50%',
|
|
27
|
-
maxWidth: '65%'
|
|
28
|
-
},
|
|
29
|
-
closed: {
|
|
30
|
-
fontWeight: theme.typography.fontWeightRegular
|
|
31
|
-
},
|
|
32
|
-
open: {
|
|
33
|
-
fontWeight: theme.typography.fontWeightBold
|
|
14
|
+
...theme.typography.body1,
|
|
15
|
+
textAlign: 'left'
|
|
34
16
|
}
|
|
35
17
|
}));
|
|
36
|
-
|
|
37
18
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
40
|
-
* @returns {JSX.Element}
|
|
19
|
+
* Renders the filter label and its selected values in the accordion header.
|
|
20
|
+
* @returns The rendered component.
|
|
41
21
|
*/
|
|
42
22
|
const Toggle = ({
|
|
43
23
|
label,
|
|
44
|
-
|
|
45
|
-
selected
|
|
24
|
+
selected = null
|
|
46
25
|
}) => {
|
|
47
26
|
const {
|
|
48
27
|
classes,
|
|
49
28
|
cx
|
|
50
29
|
} = useStyles();
|
|
51
|
-
const labelClassName = useMemo(() => cx({
|
|
52
|
-
[classes.label]: true,
|
|
53
|
-
[classes.open]: open,
|
|
54
|
-
[classes.closed]: !open
|
|
55
|
-
}), [classes.closed, classes.label, classes.open, open, cx]);
|
|
56
30
|
return /*#__PURE__*/_jsxs("div", {
|
|
57
31
|
className: classes.toggle,
|
|
58
32
|
children: [/*#__PURE__*/_jsx("span", {
|
|
59
|
-
className:
|
|
33
|
+
className: cx(classes.label, 'filter-selector-toggle-label'),
|
|
60
34
|
children: label
|
|
61
|
-
}), selected
|
|
62
|
-
className: classes.selected,
|
|
63
|
-
children: selected
|
|
64
|
-
})]
|
|
35
|
+
}), selected]
|
|
65
36
|
});
|
|
66
37
|
};
|
|
67
|
-
Toggle.defaultProps = {
|
|
68
|
-
open: false,
|
|
69
|
-
selected: null
|
|
70
|
-
};
|
|
71
38
|
export default /*#__PURE__*/memo(Toggle);
|
package/filter/components/FilterPageContent/components/Selector/components/ValueCheckbox/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ValueCheckboxProps {
|
|
2
|
+
/**
|
|
3
|
+
* Id of the filter value. Also used as the form element name and test id.
|
|
4
|
+
*/
|
|
5
|
+
id: string;
|
|
6
|
+
/**
|
|
7
|
+
* Display label of the filter value. Rendered as is — never translated.
|
|
8
|
+
*/
|
|
9
|
+
label: string;
|
|
10
|
+
/**
|
|
11
|
+
* Number of products that are available for the filter value.
|
|
12
|
+
*/
|
|
13
|
+
hits?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the value is currently selected.
|
|
16
|
+
*/
|
|
17
|
+
isActive?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Invoked with the value id whenever the checkbox is toggled.
|
|
20
|
+
*/
|
|
21
|
+
onToggle?: (id: string) => void;
|
|
22
|
+
}
|
|
23
|
+
declare const _default: import("react").MemoExoticComponent<({ id, label, hits, isActive, onToggle, }: ValueCheckboxProps) => import("react").JSX.Element>;
|
|
24
|
+
export default _default;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../filter/components/FilterPageContent/components/Selector/components/ValueCheckbox/index.tsx"],"names":[],"mappings":"AA6CA,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;uGAYE,kBAAkB;AAkCrB,wBAAmC"}
|
package/filter/components/FilterPageContent/components/Selector/components/ValueCheckbox/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { memo, useCallback } from 'react';
|
|
2
|
+
import noop from 'lodash/noop';
|
|
3
|
+
import { Checkbox } from '@shopgate/engage/components';
|
|
4
|
+
import { i18n } from '@shopgate/engage/core/helpers';
|
|
5
|
+
import { makeStyles } from '@shopgate/engage/styles';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `Checkbox` is untyped JavaScript whose optional props read as required from TypeScript.
|
|
9
|
+
*/
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const CheckboxField = Checkbox;
|
|
12
|
+
const useStyles = makeStyles()(theme => ({
|
|
13
|
+
root: {
|
|
14
|
+
paddingBottom: 0,
|
|
15
|
+
marginLeft: 0
|
|
16
|
+
},
|
|
17
|
+
checkbox: {
|
|
18
|
+
display: 'flex',
|
|
19
|
+
alignItems: 'flex-start',
|
|
20
|
+
padding: theme.spacing(0.75, 0),
|
|
21
|
+
'& .checkedIcon': {
|
|
22
|
+
color: theme.palette.secondary.main
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
label: {
|
|
26
|
+
width: '100%',
|
|
27
|
+
display: 'flex',
|
|
28
|
+
justifyContent: 'space-between',
|
|
29
|
+
gap: theme.spacing(1),
|
|
30
|
+
paddingLeft: theme.spacing(1),
|
|
31
|
+
[theme.breakpoints.up('md')]: {
|
|
32
|
+
width: 'max-content',
|
|
33
|
+
maxWidth: '100%'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
/**
|
|
38
|
+
* A single selectable value of a filter on the filter page.
|
|
39
|
+
* @returns The rendered component.
|
|
40
|
+
*/
|
|
41
|
+
const ValueCheckbox = ({
|
|
42
|
+
id,
|
|
43
|
+
label,
|
|
44
|
+
hits,
|
|
45
|
+
isActive = false,
|
|
46
|
+
onToggle = noop
|
|
47
|
+
}) => {
|
|
48
|
+
const {
|
|
49
|
+
classes
|
|
50
|
+
} = useStyles();
|
|
51
|
+
const handleChange = useCallback(() => {
|
|
52
|
+
onToggle(id);
|
|
53
|
+
}, [id, onToggle]);
|
|
54
|
+
return /*#__PURE__*/_jsx("div", {
|
|
55
|
+
"data-test-id": id,
|
|
56
|
+
children: /*#__PURE__*/_jsx(CheckboxField, {
|
|
57
|
+
className: classes.root,
|
|
58
|
+
checkboxClassName: classes.checkbox,
|
|
59
|
+
name: id,
|
|
60
|
+
checked: isActive,
|
|
61
|
+
onChange: handleChange,
|
|
62
|
+
label: /*#__PURE__*/_jsxs("div", {
|
|
63
|
+
className: classes.label,
|
|
64
|
+
"aria-label": hits === undefined ? label : i18n.text('filter.hits', {
|
|
65
|
+
label,
|
|
66
|
+
count: hits
|
|
67
|
+
}),
|
|
68
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
69
|
+
children: label
|
|
70
|
+
}), hits !== undefined && /*#__PURE__*/_jsx("span", {
|
|
71
|
+
children: `(${hits})`
|
|
72
|
+
})]
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export default /*#__PURE__*/memo(ValueCheckbox);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface FilterValue {
|
|
2
|
+
/**
|
|
3
|
+
* Id of the filter value.
|
|
4
|
+
*/
|
|
5
|
+
id: string;
|
|
6
|
+
/**
|
|
7
|
+
* Display label of the filter value.
|
|
8
|
+
*/
|
|
9
|
+
label: string;
|
|
10
|
+
/**
|
|
11
|
+
* Number of products available for the filter value.
|
|
12
|
+
*/
|
|
13
|
+
hits?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface SelectorProps {
|
|
16
|
+
/**
|
|
17
|
+
* Id of the filter.
|
|
18
|
+
*/
|
|
19
|
+
id: string;
|
|
20
|
+
/**
|
|
21
|
+
* Display label of the filter.
|
|
22
|
+
*/
|
|
23
|
+
label: string;
|
|
24
|
+
/**
|
|
25
|
+
* The selectable values of the filter.
|
|
26
|
+
*/
|
|
27
|
+
values: FilterValue[];
|
|
28
|
+
/**
|
|
29
|
+
* Whether multiple values can be selected at once.
|
|
30
|
+
*/
|
|
31
|
+
multi?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Invoked with the filter id and the updated selection whenever a value is toggled.
|
|
34
|
+
*/
|
|
35
|
+
onChange?: (id: string, selected: string[]) => void;
|
|
36
|
+
/**
|
|
37
|
+
* The currently selected value ids.
|
|
38
|
+
*/
|
|
39
|
+
selected?: string[] | null;
|
|
40
|
+
}
|
|
41
|
+
declare const _default: import("react").MemoExoticComponent<({ id, label, values, multi, onChange, selected: selectedFromProps, }: SelectorProps) => import("react").JSX.Element>;
|
|
42
|
+
export default _default;
|
|
43
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../filter/components/FilterPageContent/components/Selector/index.tsx"],"names":[],"mappings":"AA4CA,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;IACX;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACpD;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC5B;mIAaE,aAAa;AAwFhB,wBAA8B"}
|
|
@@ -1,37 +1,54 @@
|
|
|
1
1
|
import "core-js/modules/es.array.includes.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import { useState, useEffect, useCallback, useMemo, memo } from 'react';
|
|
3
|
+
import noop from 'lodash/noop';
|
|
4
4
|
import { Accordion, SurroundPortals } from '@shopgate/engage/components';
|
|
5
5
|
import { i18n } from '@shopgate/engage/core/helpers';
|
|
6
6
|
import { makeStyles } from '@shopgate/engage/styles';
|
|
7
7
|
import { FilterItem } from '@shopgate/engage/filter';
|
|
8
8
|
import { PORTAL_FILTER_SELECTOR } from '@shopgate/engage/filter/constants';
|
|
9
|
-
import
|
|
9
|
+
import ValueCheckbox from "./components/ValueCheckbox";
|
|
10
10
|
import Toggle from "./components/Toggle";
|
|
11
11
|
import Selected from "./components/Selected";
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
const useStyles = makeStyles()(
|
|
13
|
+
const useStyles = makeStyles()(theme => ({
|
|
14
14
|
accordion: {
|
|
15
15
|
overflow: 'hidden'
|
|
16
16
|
},
|
|
17
|
+
chevron: {
|
|
18
|
+
alignSelf: 'flex-start'
|
|
19
|
+
},
|
|
17
20
|
content: {
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
paddingBottom: theme.spacing(1),
|
|
22
|
+
display: 'flex',
|
|
23
|
+
flexDirection: 'column'
|
|
20
24
|
}
|
|
21
25
|
}));
|
|
22
26
|
|
|
23
27
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @param
|
|
26
|
-
* @returns
|
|
28
|
+
* Formats selected filter value labels into a readable enumeration.
|
|
29
|
+
* @param labels Labels of the selected values.
|
|
30
|
+
* @returns The formatted enumeration.
|
|
31
|
+
*/
|
|
32
|
+
const formatSelectedLabels = labels => {
|
|
33
|
+
const {
|
|
34
|
+
ListFormat
|
|
35
|
+
} = Intl;
|
|
36
|
+
if (typeof ListFormat !== 'function') {
|
|
37
|
+
return labels.join(', ');
|
|
38
|
+
}
|
|
39
|
+
return new ListFormat(i18n.getLang()).format(labels);
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The selector component renders a single filter as an accordion with selectable values.
|
|
43
|
+
* @returns The rendered component.
|
|
27
44
|
*/
|
|
28
45
|
const Selector = ({
|
|
29
46
|
id,
|
|
30
47
|
label,
|
|
31
48
|
values,
|
|
32
|
-
multi,
|
|
33
|
-
onChange,
|
|
34
|
-
selected: selectedFromProps
|
|
49
|
+
multi = false,
|
|
50
|
+
onChange = noop,
|
|
51
|
+
selected: selectedFromProps = null
|
|
35
52
|
}) => {
|
|
36
53
|
const {
|
|
37
54
|
classes
|
|
@@ -40,10 +57,7 @@ const Selector = ({
|
|
|
40
57
|
useEffect(() => {
|
|
41
58
|
setSelected(selectedFromProps || []);
|
|
42
59
|
}, [selectedFromProps]);
|
|
43
|
-
const
|
|
44
|
-
const {
|
|
45
|
-
value
|
|
46
|
-
} = event.target;
|
|
60
|
+
const handleToggle = useCallback(value => {
|
|
47
61
|
setSelected(prev => {
|
|
48
62
|
let newSelected = [].concat(prev, [value]);
|
|
49
63
|
if (!multi && prev.length === 1) {
|
|
@@ -56,21 +70,24 @@ const Selector = ({
|
|
|
56
70
|
return newSelected;
|
|
57
71
|
});
|
|
58
72
|
}, [id, multi, onChange]);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
target: {
|
|
62
|
-
value: updatedId
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}, [handleClick]);
|
|
66
|
-
const renderLabel = useCallback(props => /*#__PURE__*/_jsx(Toggle, {
|
|
67
|
-
...props,
|
|
73
|
+
const selectedValues = useMemo(() => values.filter(value => selected.includes(value.id)), [selected, values]);
|
|
74
|
+
const renderLabel = useCallback(() => /*#__PURE__*/_jsx(Toggle, {
|
|
68
75
|
label: label,
|
|
69
76
|
selected: /*#__PURE__*/_jsx(Selected, {
|
|
70
|
-
values:
|
|
71
|
-
selected: selected
|
|
77
|
+
values: selectedValues
|
|
72
78
|
})
|
|
73
|
-
}), [label,
|
|
79
|
+
}), [label, selectedValues]);
|
|
80
|
+
const handleLabel = useMemo(() => {
|
|
81
|
+
if (selectedValues.length === 0) {
|
|
82
|
+
return i18n.text('filter.filter_by', {
|
|
83
|
+
label
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return i18n.text('filter.filter_by_with_selected', {
|
|
87
|
+
label,
|
|
88
|
+
selected: formatSelectedLabels(selectedValues.map(value => value.label))
|
|
89
|
+
});
|
|
90
|
+
}, [label, selectedValues]);
|
|
74
91
|
return /*#__PURE__*/_jsx(SurroundPortals, {
|
|
75
92
|
portalName: PORTAL_FILTER_SELECTOR,
|
|
76
93
|
portalProps: {
|
|
@@ -81,32 +98,27 @@ const Selector = ({
|
|
|
81
98
|
isMultiSelect: multi
|
|
82
99
|
},
|
|
83
100
|
selectedValueIds: selected,
|
|
84
|
-
onChange:
|
|
101
|
+
onChange: handleToggle
|
|
85
102
|
},
|
|
86
103
|
children: /*#__PURE__*/_jsx(FilterItem, {
|
|
87
104
|
children: /*#__PURE__*/_jsx(Accordion, {
|
|
88
105
|
renderLabel: renderLabel,
|
|
89
106
|
testId: id,
|
|
90
|
-
handleLabel:
|
|
91
|
-
label
|
|
92
|
-
}),
|
|
107
|
+
handleLabel: handleLabel,
|
|
93
108
|
className: classes.accordion,
|
|
109
|
+
chevronClassName: classes.chevron,
|
|
94
110
|
children: /*#__PURE__*/_jsx("div", {
|
|
95
111
|
className: classes.content,
|
|
96
|
-
children: values.map(value => /*#__PURE__*/_jsx(
|
|
112
|
+
children: values.map(value => /*#__PURE__*/_jsx(ValueCheckbox, {
|
|
97
113
|
id: value.id,
|
|
98
114
|
label: value.label,
|
|
99
|
-
|
|
100
|
-
|
|
115
|
+
hits: value.hits,
|
|
116
|
+
isActive: selected.includes(value.id),
|
|
117
|
+
onToggle: handleToggle
|
|
101
118
|
}, value.id))
|
|
102
119
|
})
|
|
103
120
|
})
|
|
104
121
|
})
|
|
105
122
|
});
|
|
106
123
|
};
|
|
107
|
-
Selector.defaultProps = {
|
|
108
|
-
multi: false,
|
|
109
|
-
onChange() {},
|
|
110
|
-
selected: null
|
|
111
|
-
};
|
|
112
124
|
export default /*#__PURE__*/memo(Selector);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
export interface FilterPageContentProps {
|
|
3
|
+
/**
|
|
4
|
+
* The component to be rendered as the app bar.
|
|
5
|
+
*/
|
|
6
|
+
AppBarComponent?: ComponentType<{
|
|
7
|
+
title?: string;
|
|
8
|
+
}> | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The FilterPageContent component renders all filters for the filter page.
|
|
12
|
+
* @returns The rendered component.
|
|
13
|
+
*/
|
|
14
|
+
declare const FilterPageContent: ({ AppBarComponent }: FilterPageContentProps) => import("react").JSX.Element;
|
|
15
|
+
export default FilterPageContent;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../filter/components/FilterPageContent/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAyB3C,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,eAAe,CAAC,EAAE,aAAa,CAAC;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI,CAAC;CAC5D;AAED;;;GAGG;AACH,QAAA,MAAM,iBAAiB,GAAI,qBAA4B,sBAAsB,gCAmD5E,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|