@shopgate/pwa-ui-shared 7.30.4-beta.1 → 7.31.0-alpha.2
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/ActionButton/index.js +66 -67
- package/AddToCartButton/index.js +217 -185
- package/AddToCartButton/style.js +8 -0
- package/Availability/index.js +24 -6
- package/Button/index.js +105 -82
- package/Button/spec.js +3 -4
- package/Card/index.js +26 -7
- package/CardList/components/Item/index.js +15 -3
- package/CartTotalLine/components/Amount/index.js +13 -4
- package/CartTotalLine/components/Hint/index.js +13 -4
- package/CartTotalLine/components/Label/index.js +23 -10
- package/CartTotalLine/index.js +41 -7
- package/Checkbox/index.js +41 -17
- package/Chip/index.js +82 -7
- package/ContextMenu/components/Item/index.js +38 -20
- package/ContextMenu/components/Position/index.js +38 -56
- package/ContextMenu/index.js +64 -28
- package/Dialog/components/BasicDialog/index.js +1 -0
- package/Dialog/components/HtmlContentDialog/spec.js +39 -0
- package/Dialog/components/PipelineErrorDialog/index.js +108 -157
- package/Dialog/components/PipelineErrorDialog/spec.js +12 -18
- package/Dialog/components/TextMessageDialog/index.js +1 -1
- package/Dialog/components/VariantSelectModal/index.js +1 -1
- package/Dialog/index.js +1 -1
- package/DiscountBadge/index.js +48 -15
- package/FavoritesButton/index.js +95 -100
- package/FavoritesButton/spec.js +5 -2
- package/Form/Builder/classes/ActionListener/index.js +1 -0
- package/Form/Checkbox/index.js +64 -56
- package/Form/InfoField/index.js +18 -6
- package/Form/Password/index.js +39 -52
- package/Form/RadioGroup/components/Item/index.js +72 -56
- package/Form/RadioGroup/index.js +79 -90
- package/Form/Select/index.js +108 -130
- package/Form/SelectContextChoices/index.js +30 -8
- package/Form/TextField/index.js +106 -82
- package/Form/TextField/spec.js +4 -3
- package/FormElement/components/ErrorText/index.js +32 -14
- package/FormElement/components/Label/index.js +56 -6
- package/FormElement/components/Placeholder/index.js +44 -11
- package/FormElement/components/Underline/index.js +63 -12
- package/FormElement/index.js +62 -85
- package/Glow/index.js +73 -83
- package/IndicatorCircle/index.js +73 -17
- package/IndicatorCircle/spec.js +2 -5
- package/LoadingIndicator/index.js +34 -12
- package/Manufacturer/index.js +21 -10
- package/MessageBar/index.js +12 -38
- package/NoResults/components/Icon/index.js +30 -14
- package/NoResults/index.js +35 -7
- package/Placeholder/index.js +34 -23
- package/PlaceholderLabel/index.js +17 -3
- package/Price/index.js +34 -21
- package/PriceInfo/index.js +23 -9
- package/PriceStriked/index.js +67 -77
- package/ProgressBar/index.js +112 -77
- package/RadioButton/index.js +29 -11
- package/RatingStars/index.js +122 -137
- package/Ripple/components/RippleAnimation/index.js +13 -3
- package/Ripple/index.js +158 -212
- package/RippleButton/index.js +63 -60
- package/RippleButton/spec.js +15 -9
- package/ScannerOverlay/components/CameraOverlay/index.js +54 -10
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/index.js +53 -27
- package/ScannerOverlay/components/ScannerBar/index.js +50 -26
- package/Sheet/components/Header/components/SearchBar/index.js +54 -10
- package/Sheet/components/Header/index.js +96 -76
- package/Sheet/index.js +295 -157
- package/Sheet/spec.js +8 -6
- package/TaxDisclaimer/index.js +17 -4
- package/TaxDisclaimer/spec.js +16 -5
- package/TextField/components/ErrorText/index.js +35 -14
- package/TextField/components/FormElement/index.js +29 -4
- package/TextField/components/Hint/index.js +39 -10
- package/TextField/components/Label/index.js +43 -6
- package/TextField/components/Underline/index.js +64 -13
- package/TextField/index.js +157 -171
- package/TextField/spec.js +5 -3
- package/icons/AccountBoxIcon.d.ts +7 -0
- package/icons/AccountBoxIcon.d.ts.map +1 -0
- package/icons/AccountBoxIcon.js +1 -4
- package/icons/AddMoreIcon.d.ts +7 -0
- package/icons/AddMoreIcon.d.ts.map +1 -0
- package/icons/AddMoreIcon.js +0 -3
- package/icons/ArrowDropIcon.d.ts +7 -0
- package/icons/ArrowDropIcon.d.ts.map +1 -0
- package/icons/ArrowDropIcon.js +0 -3
- package/icons/ArrowIcon.d.ts +10 -0
- package/icons/ArrowIcon.d.ts.map +1 -0
- package/icons/ArrowIcon.js +2 -11
- package/icons/BarcodeScannerIcon.d.ts +7 -0
- package/icons/BarcodeScannerIcon.d.ts.map +1 -0
- package/icons/BarcodeScannerIcon.js +0 -3
- package/icons/BoxIcon.d.ts +7 -0
- package/icons/BoxIcon.d.ts.map +1 -0
- package/icons/BoxIcon.js +0 -3
- package/icons/BrowseIcon.d.ts +7 -0
- package/icons/BrowseIcon.d.ts.map +1 -0
- package/icons/BrowseIcon.js +1 -3
- package/icons/BurgerIcon.d.ts +7 -0
- package/icons/BurgerIcon.d.ts.map +1 -0
- package/icons/BurgerIcon.js +0 -3
- package/icons/CalendarIcon.d.ts +7 -0
- package/icons/CalendarIcon.d.ts.map +1 -0
- package/icons/CalendarIcon.js +0 -2
- package/icons/CartCouponIcon.d.ts +7 -0
- package/icons/CartCouponIcon.d.ts.map +1 -0
- package/icons/CartCouponIcon.js +0 -2
- package/icons/CartIcon.d.ts +7 -0
- package/icons/CartIcon.d.ts.map +1 -0
- package/icons/CartIcon.js +0 -2
- package/icons/CartPlusIcon.d.ts +7 -0
- package/icons/CartPlusIcon.d.ts.map +1 -0
- package/icons/CartPlusIcon.js +0 -2
- package/icons/CheckIcon.d.ts +7 -0
- package/icons/CheckIcon.d.ts.map +1 -0
- package/icons/CheckIcon.js +0 -2
- package/icons/CheckedIcon.d.ts +7 -0
- package/icons/CheckedIcon.d.ts.map +1 -0
- package/icons/CheckedIcon.js +0 -3
- package/icons/ChevronIcon.d.ts +7 -0
- package/icons/ChevronIcon.d.ts.map +1 -0
- package/icons/ChevronIcon.js +0 -2
- package/icons/CreditCardIcon.d.ts +7 -0
- package/icons/CreditCardIcon.d.ts.map +1 -0
- package/icons/CreditCardIcon.js +0 -2
- package/icons/CrossIcon.d.ts +7 -0
- package/icons/CrossIcon.d.ts.map +1 -0
- package/icons/CrossIcon.js +0 -2
- package/icons/DescriptionIcon.d.ts +7 -0
- package/icons/DescriptionIcon.d.ts.map +1 -0
- package/icons/DescriptionIcon.js +0 -2
- package/icons/FilterIcon.d.ts +7 -0
- package/icons/FilterIcon.d.ts.map +1 -0
- package/icons/FilterIcon.js +0 -2
- package/icons/FlashDisabledIcon.d.ts +7 -0
- package/icons/FlashDisabledIcon.d.ts.map +1 -0
- package/icons/FlashDisabledIcon.js +0 -2
- package/icons/FlashEnabledIcon.d.ts +7 -0
- package/icons/FlashEnabledIcon.d.ts.map +1 -0
- package/icons/FlashEnabledIcon.js +0 -2
- package/icons/GridIcon.d.ts +7 -0
- package/icons/GridIcon.d.ts.map +1 -0
- package/icons/GridIcon.js +1 -3
- package/icons/HeartIcon.d.ts +7 -0
- package/icons/HeartIcon.d.ts.map +1 -0
- package/icons/HeartIcon.js +0 -2
- package/icons/HeartOutlineIcon.d.ts +7 -0
- package/icons/HeartOutlineIcon.d.ts.map +1 -0
- package/icons/HeartOutlineIcon.js +1 -3
- package/icons/HeartPlusIcon.d.ts +7 -0
- package/icons/HeartPlusIcon.d.ts.map +1 -0
- package/icons/HeartPlusIcon.js +1 -3
- package/icons/HeartPlusOutlineIcon.d.ts +7 -0
- package/icons/HeartPlusOutlineIcon.d.ts.map +1 -0
- package/icons/HeartPlusOutlineIcon.js +1 -3
- package/icons/HomeIcon.d.ts +7 -0
- package/icons/HomeIcon.d.ts.map +1 -0
- package/icons/HomeIcon.js +0 -2
- package/icons/InfoIcon.d.ts +7 -0
- package/icons/InfoIcon.d.ts.map +1 -0
- package/icons/InfoIcon.js +0 -2
- package/icons/InfoOutlineIcon.d.ts +7 -0
- package/icons/InfoOutlineIcon.d.ts.map +1 -0
- package/icons/InfoOutlineIcon.js +0 -2
- package/icons/ListIcon.d.ts +7 -0
- package/icons/ListIcon.d.ts.map +1 -0
- package/icons/ListIcon.js +0 -2
- package/icons/LocalShippingIcon.d.ts +7 -0
- package/icons/LocalShippingIcon.d.ts.map +1 -0
- package/icons/LocalShippingIcon.js +0 -2
- package/icons/LocationIcon.d.ts +7 -0
- package/icons/LocationIcon.d.ts.map +1 -0
- package/icons/LocationIcon.js +1 -4
- package/icons/LocatorIcon.d.ts +7 -0
- package/icons/LocatorIcon.d.ts.map +1 -0
- package/icons/LocatorIcon.js +1 -3
- package/icons/LockIcon.d.ts +9 -0
- package/icons/LockIcon.d.ts.map +1 -0
- package/icons/LockIcon.js +1 -2
- package/icons/LogoutIcon.d.ts +7 -0
- package/icons/LogoutIcon.d.ts.map +1 -0
- package/icons/LogoutIcon.js +0 -2
- package/icons/MagnifierIcon.d.ts +7 -0
- package/icons/MagnifierIcon.d.ts.map +1 -0
- package/icons/MagnifierIcon.js +0 -2
- package/icons/MapMarkerIcon.d.ts +7 -0
- package/icons/MapMarkerIcon.d.ts.map +1 -0
- package/icons/MapMarkerIcon.js +1 -3
- package/icons/MoreIcon.d.ts +7 -0
- package/icons/MoreIcon.d.ts.map +1 -0
- package/icons/MoreIcon.js +1 -3
- package/icons/MoreVertIcon.d.ts +7 -0
- package/icons/MoreVertIcon.d.ts.map +1 -0
- package/icons/MoreVertIcon.js +1 -3
- package/icons/NotificationIcon.d.ts +7 -0
- package/icons/NotificationIcon.d.ts.map +1 -0
- package/icons/NotificationIcon.js +1 -3
- package/icons/PersonIcon.d.ts +9 -0
- package/icons/PersonIcon.d.ts.map +1 -0
- package/icons/PersonIcon.js +0 -3
- package/icons/PhoneIcon.d.ts +7 -0
- package/icons/PhoneIcon.d.ts.map +1 -0
- package/icons/PhoneIcon.js +1 -4
- package/icons/PlaceholderIcon.d.ts +7 -0
- package/icons/PlaceholderIcon.d.ts.map +1 -0
- package/icons/PlaceholderIcon.js +0 -2
- package/icons/RadioCheckedIcon.d.ts +10 -0
- package/icons/RadioCheckedIcon.d.ts.map +1 -0
- package/icons/RadioCheckedIcon.js +0 -2
- package/icons/RadioUncheckedIcon.d.ts +10 -0
- package/icons/RadioUncheckedIcon.d.ts.map +1 -0
- package/icons/RadioUncheckedIcon.js +0 -2
- package/icons/SecurityIcon.d.ts +7 -0
- package/icons/SecurityIcon.d.ts.map +1 -0
- package/icons/SecurityIcon.js +0 -2
- package/icons/ShippingMethodIcon.d.ts +7 -0
- package/icons/ShippingMethodIcon.d.ts.map +1 -0
- package/icons/ShippingMethodIcon.js +0 -2
- package/icons/ShoppingCartIcon.d.ts +7 -0
- package/icons/ShoppingCartIcon.d.ts.map +1 -0
- package/icons/ShoppingCartIcon.js +0 -2
- package/icons/SortIcon.d.ts +7 -0
- package/icons/SortIcon.d.ts.map +1 -0
- package/icons/SortIcon.js +0 -2
- package/icons/StarHalfIcon.d.ts +7 -0
- package/icons/StarHalfIcon.d.ts.map +1 -0
- package/icons/StarHalfIcon.js +0 -9
- package/icons/StarIcon.d.ts +7 -0
- package/icons/StarIcon.d.ts.map +1 -0
- package/icons/StarIcon.js +0 -9
- package/icons/StarOutlineIcon.d.ts +7 -0
- package/icons/StarOutlineIcon.d.ts.map +1 -0
- package/icons/StarOutlineIcon.js +0 -2
- package/icons/StopIcon.d.ts +7 -0
- package/icons/StopIcon.d.ts.map +1 -0
- package/icons/StopIcon.js +0 -2
- package/icons/TickIcon.d.ts +7 -0
- package/icons/TickIcon.d.ts.map +1 -0
- package/icons/TickIcon.js +0 -2
- package/icons/TimeIcon.d.ts +7 -0
- package/icons/TimeIcon.d.ts.map +1 -0
- package/icons/TimeIcon.js +0 -2
- package/icons/TrashIcon.d.ts +7 -0
- package/icons/TrashIcon.d.ts.map +1 -0
- package/icons/TrashIcon.js +0 -3
- package/icons/TrashOutlineIcon.d.ts +8 -0
- package/icons/TrashOutlineIcon.d.ts.map +1 -0
- package/icons/TrashOutlineIcon.js +0 -2
- package/icons/UncheckedIcon.d.ts +7 -0
- package/icons/UncheckedIcon.d.ts.map +1 -0
- package/icons/UncheckedIcon.js +0 -2
- package/icons/ViewListIcon.d.ts +7 -0
- package/icons/ViewListIcon.d.ts.map +1 -0
- package/icons/ViewListIcon.js +0 -2
- package/icons/VisibilityIcon.d.ts +8 -0
- package/icons/VisibilityIcon.d.ts.map +1 -0
- package/icons/VisibilityIcon.js +2 -4
- package/icons/VisibilityOffIcon.d.ts +8 -0
- package/icons/VisibilityOffIcon.d.ts.map +1 -0
- package/icons/VisibilityOffIcon.js +2 -4
- package/icons/WarningIcon.d.ts +7 -0
- package/icons/WarningIcon.d.ts.map +1 -0
- package/icons/WarningIcon.js +1 -3
- package/package.json +5 -5
- package/tsconfig.build.json +16 -0
- package/tsconfig.json +3 -0
- package/ActionButton/style.js +0 -22
- package/Availability/style.js +0 -19
- package/Button/style.js +0 -155
- package/Card/style.js +0 -11
- package/CardList/components/Item/style.js +0 -7
- package/CartTotalLine/components/Amount/style.js +0 -8
- package/CartTotalLine/components/Hint/style.js +0 -12
- package/CartTotalLine/components/Label/style.js +0 -17
- package/CartTotalLine/style.js +0 -31
- package/Checkbox/style.js +0 -18
- package/Chip/style.js +0 -78
- package/ContextMenu/components/Item/style.js +0 -34
- package/ContextMenu/components/Position/style.js +0 -11
- package/ContextMenu/style.js +0 -45
- package/DiscountBadge/style.js +0 -36
- package/FavoritesButton/style.js +0 -26
- package/Form/Checkbox/style.js +0 -25
- package/Form/InfoField/style.js +0 -11
- package/Form/Password/style.js +0 -11
- package/Form/RadioGroup/components/Item/style.js +0 -32
- package/Form/RadioGroup/style.js +0 -20
- package/Form/Select/style.js +0 -27
- package/Form/SelectContextChoices/style.js +0 -23
- package/Form/TextField/style.js +0 -70
- package/FormElement/components/ErrorText/style.js +0 -13
- package/FormElement/components/Label/style.js +0 -89
- package/FormElement/components/Placeholder/style.js +0 -56
- package/FormElement/components/Underline/style.js +0 -60
- package/FormElement/style.js +0 -14
- package/Glow/style.js +0 -18
- package/IndicatorCircle/style.js +0 -65
- package/LoadingIndicator/style.js +0 -20
- package/Manufacturer/style.js +0 -5
- package/MessageBar/spec.js +0 -80
- package/MessageBar/style.js +0 -38
- package/NoResults/components/Icon/style.js +0 -17
- package/NoResults/style.js +0 -31
- package/Placeholder/style.js +0 -11
- package/PlaceholderLabel/style.js +0 -12
- package/Price/style.js +0 -22
- package/PriceInfo/style.js +0 -5
- package/PriceStriked/style.js +0 -36
- package/ProgressBar/style.js +0 -85
- package/RadioButton/style.js +0 -21
- package/RatingStars/style.js +0 -53
- package/Ripple/style.js +0 -18
- package/ScannerOverlay/components/CameraOverlay/style.js +0 -40
- package/ScannerOverlay/components/ScannerBar/components/FlashlightButton/style.js +0 -28
- package/ScannerOverlay/components/ScannerBar/style.js +0 -20
- package/Sheet/components/Header/components/SearchBar/style.js +0 -47
- package/Sheet/components/Header/style.js +0 -50
- package/Sheet/style.js +0 -143
- package/TaxDisclaimer/style.js +0 -9
- package/TextField/components/ErrorText/style.js +0 -27
- package/TextField/components/FormElement/style.js +0 -34
- package/TextField/components/Hint/style.js +0 -46
- package/TextField/components/Label/style.js +0 -80
- package/TextField/components/Underline/style.js +0 -60
- package/TextField/style.js +0 -35
package/Chip/index.js
CHANGED
|
@@ -2,16 +2,84 @@ import React, { useRef, useCallback, useEffect } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import Button from '@shopgate/pwa-common/components/Button';
|
|
4
4
|
import ResponsiveContainer from '@shopgate/engage/components/ResponsiveContainer';
|
|
5
|
+
import { hasNewServices } from '@shopgate/engage/core/helpers';
|
|
6
|
+
import { makeStyles, responsiveMediaQuery } from '@shopgate/engage/styles';
|
|
5
7
|
import CrossIcon from "../icons/CrossIcon";
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {boolean} hasRemoveButton Whether this chip has a remove button.
|
|
11
|
+
* @param {Object} theme Theme with spacing().
|
|
12
|
+
* @returns {Object} Shared layout fields for the chip root.
|
|
13
|
+
*/
|
|
14
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
+
const chipBase = (hasRemoveButton, theme) => ({
|
|
16
|
+
display: 'flex',
|
|
17
|
+
alignItems: 'center',
|
|
18
|
+
borderRadius: 26,
|
|
19
|
+
outline: 0,
|
|
20
|
+
height: 26,
|
|
21
|
+
paddingRight: theme.spacing(1),
|
|
22
|
+
paddingLeft: hasRemoveButton ? theme.spacing(0.5) : theme.spacing(1),
|
|
23
|
+
marginRight: 5,
|
|
24
|
+
marginTop: 4,
|
|
25
|
+
marginBottom: 4,
|
|
26
|
+
minWidth: 0
|
|
27
|
+
});
|
|
28
|
+
const useStyles = makeStyles()((theme, {
|
|
29
|
+
removable,
|
|
30
|
+
invert
|
|
31
|
+
}) => ({
|
|
32
|
+
chip: {
|
|
33
|
+
...chipBase(removable, theme),
|
|
34
|
+
...(hasNewServices() ? {
|
|
35
|
+
backgroundColor: invert ? 'var(--color-primary)' : 'var(--color-primary-contrast)',
|
|
36
|
+
color: invert ? 'var(--color-primary-contrast)' : 'var(--color-primary)'
|
|
37
|
+
} : {
|
|
38
|
+
backgroundColor: invert ? 'var(--color-secondary)' : 'var(--color-secondary-contrast)',
|
|
39
|
+
color: invert ? 'var(--color-secondary-contrast)' : 'var(--color-secondary)',
|
|
40
|
+
'--color-text-high-emphasis': invert ? 'var(--color-secondary-contrast)' : 'var(--color-secondary)'
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
removeButton: {
|
|
44
|
+
flexShrink: 0,
|
|
45
|
+
padding: 0,
|
|
46
|
+
[responsiveMediaQuery('>xs', {
|
|
47
|
+
webOnly: true
|
|
48
|
+
})]: {
|
|
49
|
+
padding: '0 5px',
|
|
50
|
+
fontSize: '1.125rem'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
name: {
|
|
54
|
+
paddingLeft: theme.spacing(0.5),
|
|
55
|
+
paddingRight: theme.spacing(0.5),
|
|
56
|
+
paddingTop: 3,
|
|
57
|
+
paddingBottom: 3,
|
|
58
|
+
fontSize: 12,
|
|
59
|
+
fontWeight: 500,
|
|
60
|
+
textOverflow: 'ellipsis',
|
|
61
|
+
maxWidth: '100%',
|
|
62
|
+
whiteSpace: 'nowrap',
|
|
63
|
+
overflow: 'hidden',
|
|
64
|
+
display: 'block',
|
|
65
|
+
lineHeight: '1',
|
|
66
|
+
color: 'inherit',
|
|
67
|
+
[responsiveMediaQuery('>xs', {
|
|
68
|
+
webOnly: true
|
|
69
|
+
})]: {
|
|
70
|
+
fontSize: '0.875rem',
|
|
71
|
+
lineHeight: '1.25rem',
|
|
72
|
+
padding: '6px 8px 6px 0'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}));
|
|
7
76
|
|
|
8
77
|
/**
|
|
9
78
|
* The chip component.
|
|
10
79
|
* @param {Object} props The component props.
|
|
11
80
|
* @returns {JSX}
|
|
12
81
|
*/
|
|
13
|
-
|
|
14
|
-
function Chip(props) {
|
|
82
|
+
const Chip = props => {
|
|
15
83
|
const {
|
|
16
84
|
removable,
|
|
17
85
|
children,
|
|
@@ -22,6 +90,13 @@ function Chip(props) {
|
|
|
22
90
|
removeLabel,
|
|
23
91
|
editLabel
|
|
24
92
|
} = props;
|
|
93
|
+
const {
|
|
94
|
+
classes,
|
|
95
|
+
cx
|
|
96
|
+
} = useStyles({
|
|
97
|
+
removable,
|
|
98
|
+
invert
|
|
99
|
+
});
|
|
25
100
|
const ref = useRef(null);
|
|
26
101
|
const handleRemove = useCallback(() => {
|
|
27
102
|
onRemove(id);
|
|
@@ -31,10 +106,10 @@ function Chip(props) {
|
|
|
31
106
|
});
|
|
32
107
|
return /*#__PURE__*/_jsxs("div", {
|
|
33
108
|
ref: ref,
|
|
34
|
-
className:
|
|
109
|
+
className: cx('ui-shared__chip', classes.chip),
|
|
35
110
|
"data-test-id": id,
|
|
36
111
|
children: [removable && /*#__PURE__*/_jsxs(Button, {
|
|
37
|
-
className:
|
|
112
|
+
className: classes.removeButton,
|
|
38
113
|
onClick: handleRemove,
|
|
39
114
|
testId: "removeFilter",
|
|
40
115
|
"aria-label": removeLabel,
|
|
@@ -52,13 +127,13 @@ function Chip(props) {
|
|
|
52
127
|
})
|
|
53
128
|
})]
|
|
54
129
|
}), /*#__PURE__*/_jsx(Button, {
|
|
55
|
-
className:
|
|
130
|
+
className: classes.name,
|
|
56
131
|
onClick: onClick,
|
|
57
132
|
"aria-label": editLabel,
|
|
58
133
|
children: children
|
|
59
134
|
})]
|
|
60
135
|
});
|
|
61
|
-
}
|
|
136
|
+
};
|
|
62
137
|
Chip.defaultProps = {
|
|
63
138
|
invert: false,
|
|
64
139
|
onClick: () => {},
|
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
import React, { useCallback } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import noop from 'lodash/noop';
|
|
4
|
-
import
|
|
4
|
+
import Color from 'color';
|
|
5
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
6
|
+
import { getCSSCustomProp, makeStyles } from '@shopgate/engage/styles';
|
|
5
7
|
import Glow from "../../../Glow";
|
|
6
|
-
import { getItemClass } from "./style";
|
|
7
8
|
import { useContextMenu } from "../../ContextMenu.hooks";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A delay in ms after that the closeMenu callback gets triggered.
|
|
11
|
-
* @type {number}
|
|
12
|
-
*/
|
|
13
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
10
|
const CLOSE_DELAY = 250;
|
|
11
|
+
const useStyles = makeStyles()((theme, {
|
|
12
|
+
disabled
|
|
13
|
+
}) => {
|
|
14
|
+
let background = themeConfig.colors.shade8;
|
|
15
|
+
const customPropColor = getCSSCustomProp('--color-primary');
|
|
16
|
+
if (customPropColor) {
|
|
17
|
+
background = Color(customPropColor).alpha(0.04).toString();
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
root: {
|
|
21
|
+
position: 'relative',
|
|
22
|
+
whiteSpace: 'nowrap',
|
|
23
|
+
marginBottom: 2,
|
|
24
|
+
padding: theme.spacing(1.75, 2.75),
|
|
25
|
+
lineHeight: 1,
|
|
26
|
+
zIndex: 1,
|
|
27
|
+
color: disabled ? theme.palette.text.secondary : 'inherits',
|
|
28
|
+
...(!disabled ? {
|
|
29
|
+
cursor: 'pointer',
|
|
30
|
+
'&:hover': {
|
|
31
|
+
background
|
|
32
|
+
}
|
|
33
|
+
} : {
|
|
34
|
+
cursor: 'default'
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
});
|
|
15
39
|
|
|
16
40
|
/**
|
|
17
41
|
* The Context Menu Item component.
|
|
@@ -25,15 +49,15 @@ const Item = ({
|
|
|
25
49
|
autoClose,
|
|
26
50
|
className
|
|
27
51
|
}) => {
|
|
52
|
+
const {
|
|
53
|
+
classes,
|
|
54
|
+
cx
|
|
55
|
+
} = useStyles({
|
|
56
|
+
disabled
|
|
57
|
+
});
|
|
28
58
|
const {
|
|
29
59
|
handleMenuToggle
|
|
30
60
|
} = useContextMenu();
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Handles the click event.
|
|
34
|
-
* @param {Event} event The click event.
|
|
35
|
-
* @returns {void}
|
|
36
|
-
*/
|
|
37
61
|
const handleClick = useCallback(event => {
|
|
38
62
|
event.persist();
|
|
39
63
|
setTimeout(() => {
|
|
@@ -45,12 +69,6 @@ const Item = ({
|
|
|
45
69
|
}, 0);
|
|
46
70
|
}, autoClose ? CLOSE_DELAY : 0);
|
|
47
71
|
}, [autoClose, handleMenuToggle, onClick]);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Handles the keypress event for screen readers.
|
|
51
|
-
* @param {Event} event The click event.
|
|
52
|
-
* @returns {void}
|
|
53
|
-
*/
|
|
54
72
|
const handleKeyPress = useCallback(event => {
|
|
55
73
|
if (event.key === 'Enter' || event.key === ' ') {
|
|
56
74
|
event.preventDefault();
|
|
@@ -60,7 +78,7 @@ const Item = ({
|
|
|
60
78
|
return /*#__PURE__*/_jsx(Glow, {
|
|
61
79
|
disabled: disabled,
|
|
62
80
|
children: /*#__PURE__*/_jsx("div", {
|
|
63
|
-
className:
|
|
81
|
+
className: cx(classes.root, className),
|
|
64
82
|
onClick: disabled ? noop : handleClick,
|
|
65
83
|
"data-test-id": "contextMenuButton",
|
|
66
84
|
"aria-disabled": disabled,
|
|
@@ -1,70 +1,52 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { Component } from 'react';
|
|
1
|
+
import React, { useRef, useLayoutEffect } from 'react';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
3
|
import clamp from 'lodash/clamp';
|
|
5
|
-
import
|
|
4
|
+
import { makeStyles, useTheme } from '@shopgate/engage/styles';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
const useStyles = makeStyles()(theme => ({
|
|
7
|
+
container: {
|
|
8
|
+
position: 'absolute',
|
|
9
|
+
margin: theme.spacing(1)
|
|
10
|
+
}
|
|
11
|
+
}));
|
|
6
12
|
|
|
7
13
|
/**
|
|
8
14
|
* The Context Menu Position component.
|
|
15
|
+
* @param {Object} props Props.
|
|
16
|
+
* @returns {JSX.Element}
|
|
9
17
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
29
|
-
const {
|
|
30
|
-
offset
|
|
31
|
-
} = this.props;
|
|
32
|
-
|
|
33
|
-
// Get ref to the actual child DOM element and calculate bounding rect.
|
|
34
|
-
const [child] = this.elementRef.childNodes;
|
|
18
|
+
const Position = ({
|
|
19
|
+
children,
|
|
20
|
+
offset
|
|
21
|
+
}) => {
|
|
22
|
+
const theme = useTheme();
|
|
23
|
+
const gap = theme.spacing(1);
|
|
24
|
+
const {
|
|
25
|
+
classes
|
|
26
|
+
} = useStyles();
|
|
27
|
+
const elementRef = useRef(null);
|
|
28
|
+
useLayoutEffect(() => {
|
|
29
|
+
if (!elementRef.current) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const [child] = elementRef.current.childNodes;
|
|
33
|
+
if (!child) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
35
36
|
const bounds = child.getBoundingClientRect();
|
|
36
|
-
|
|
37
|
-
// Get window dimensions
|
|
38
37
|
const width = window.innerWidth;
|
|
39
38
|
const height = window.innerHeight;
|
|
40
|
-
|
|
41
|
-
// Get the outer gap from styles
|
|
42
|
-
const gap = styles.outerGap;
|
|
43
|
-
|
|
44
|
-
// Calculate clamped menu position
|
|
45
39
|
const left = clamp(offset.left, 0, width - bounds.width - gap * 2);
|
|
46
40
|
const top = clamp(offset.top - gap, 0, height - bounds.height - gap * 2);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
*/;
|
|
57
|
-
_proto.render = function render() {
|
|
58
|
-
return /*#__PURE__*/_jsx("div", {
|
|
59
|
-
ref: ref => {
|
|
60
|
-
this.elementRef = ref;
|
|
61
|
-
},
|
|
62
|
-
className: styles.container,
|
|
63
|
-
children: this.props.children
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
return Position;
|
|
67
|
-
}(Component);
|
|
41
|
+
elementRef.current.style.left = `${left}px`;
|
|
42
|
+
elementRef.current.style.top = `${top}px`;
|
|
43
|
+
}, [offset, gap]);
|
|
44
|
+
return /*#__PURE__*/_jsx("div", {
|
|
45
|
+
ref: elementRef,
|
|
46
|
+
className: classes.container,
|
|
47
|
+
children: children
|
|
48
|
+
});
|
|
49
|
+
};
|
|
68
50
|
Position.defaultProps = {
|
|
69
51
|
children: null,
|
|
70
52
|
offset: {
|
package/ContextMenu/index.js
CHANGED
|
@@ -1,41 +1,82 @@
|
|
|
1
1
|
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { ConnectedReactPortal } from '@shopgate/engage/components';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
4
|
import Backdrop from '@shopgate/pwa-common/components/Backdrop';
|
|
6
5
|
import { FocusTrap } from '@shopgate/engage/a11y/components';
|
|
7
|
-
import { i18n } from '@shopgate/engage/core';
|
|
6
|
+
import { i18n } from '@shopgate/engage/core/helpers';
|
|
7
|
+
import { themeConfig } from '@shopgate/pwa-common/helpers/config';
|
|
8
|
+
import { makeStyles } from '@shopgate/engage/styles';
|
|
8
9
|
import MoreVertIcon from "../icons/MoreVertIcon";
|
|
9
10
|
import Position from "./components/Position";
|
|
10
11
|
import Item from "./components/Item";
|
|
11
|
-
import styles from "./style";
|
|
12
12
|
import ContextMenuProvider from "./ContextMenuProvider";
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
const useStyles = makeStyles()(theme => ({
|
|
15
|
+
container: {
|
|
16
|
+
position: 'relative'
|
|
17
|
+
},
|
|
18
|
+
button: {
|
|
19
|
+
display: 'block',
|
|
20
|
+
fontSize: '1.5rem',
|
|
21
|
+
outline: 0,
|
|
22
|
+
padding: 0,
|
|
23
|
+
color: 'inherit'
|
|
24
|
+
},
|
|
25
|
+
disabled: {
|
|
26
|
+
cursor: 'not-allowed'
|
|
27
|
+
},
|
|
28
|
+
overlay: {
|
|
29
|
+
position: 'fixed',
|
|
30
|
+
top: 0,
|
|
31
|
+
right: 0,
|
|
32
|
+
bottom: 0,
|
|
33
|
+
left: 0,
|
|
34
|
+
zIndex: 10
|
|
35
|
+
},
|
|
36
|
+
menu: {
|
|
37
|
+
position: 'absolute',
|
|
38
|
+
top: 0,
|
|
39
|
+
left: 0,
|
|
40
|
+
padding: theme.spacing(1, 0),
|
|
41
|
+
minWidth: 130,
|
|
42
|
+
background: themeConfig.colors.light,
|
|
43
|
+
borderRadius: 2,
|
|
44
|
+
boxShadow: themeConfig.shadows.contextMenu
|
|
45
|
+
},
|
|
46
|
+
scrollable: {
|
|
47
|
+
maxHeight: '30vh',
|
|
48
|
+
overflowY: 'auto'
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
13
51
|
|
|
14
52
|
/**
|
|
15
53
|
* The Context Menu component.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
54
|
+
* @param {Object} props The component props.
|
|
55
|
+
* @param {Object} props.children The menu items.
|
|
56
|
+
* @param {Object} props.classes The classes for the container and button.
|
|
57
|
+
* @param {string} props.classes.container The class name for the container.
|
|
58
|
+
* @param {string} props.classes.button The class name for the button.
|
|
59
|
+
* @param {boolean} props.disabled Whether the menu is disabled.
|
|
60
|
+
* @param {boolean} props.isOpened Whether the menu is opened.
|
|
61
|
+
* @param {Function} props.onStateChange A callback that is called when the menu state changes.
|
|
62
|
+
* @param {boolean} props.scroll Whether the menu should be scrollable.
|
|
63
|
+
* @param {boolean} props.showToggle Whether the toggle button should be shown.
|
|
64
|
+
* @returns {JSX.Element}
|
|
65
|
+
*/
|
|
29
66
|
const ContextMenu = props => {
|
|
30
67
|
const {
|
|
31
68
|
children,
|
|
32
|
-
classes,
|
|
69
|
+
classes: parentClasses,
|
|
33
70
|
disabled,
|
|
34
71
|
showToggle,
|
|
35
72
|
scroll,
|
|
36
73
|
isOpened,
|
|
37
74
|
onStateChange
|
|
38
75
|
} = props;
|
|
76
|
+
const {
|
|
77
|
+
classes,
|
|
78
|
+
cx
|
|
79
|
+
} = useStyles();
|
|
39
80
|
const [active, setActive] = useState(isOpened);
|
|
40
81
|
const elementRef = useRef(null);
|
|
41
82
|
const menuRef = useRef(null);
|
|
@@ -49,11 +90,6 @@ const ContextMenu = props => {
|
|
|
49
90
|
menuRef.current.focus();
|
|
50
91
|
}
|
|
51
92
|
}, [active]);
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Handles the menu toggle.
|
|
55
|
-
* @param {Object} e The event object.
|
|
56
|
-
*/
|
|
57
93
|
const handleMenuToggle = useCallback(e => {
|
|
58
94
|
if (e) {
|
|
59
95
|
e.preventDefault();
|
|
@@ -79,10 +115,10 @@ const ContextMenu = props => {
|
|
|
79
115
|
return /*#__PURE__*/_jsxs("div", {
|
|
80
116
|
"data-test-id": "contextMenu",
|
|
81
117
|
ref: elementRef,
|
|
82
|
-
className:
|
|
118
|
+
className: cx(classes.container, parentClasses.container, 'ui-shared__context-menu'),
|
|
83
119
|
children: [showToggle && /*#__PURE__*/_jsx("button", {
|
|
84
|
-
className:
|
|
85
|
-
[
|
|
120
|
+
className: cx(classes.button, parentClasses.button, {
|
|
121
|
+
[classes.disabled]: disabled
|
|
86
122
|
}),
|
|
87
123
|
onClick: handleMenuToggle,
|
|
88
124
|
disabled: disabled,
|
|
@@ -99,7 +135,7 @@ const ContextMenu = props => {
|
|
|
99
135
|
children: /*#__PURE__*/_jsx(FocusTrap, {
|
|
100
136
|
active: active,
|
|
101
137
|
children: /*#__PURE__*/_jsxs("div", {
|
|
102
|
-
className:
|
|
138
|
+
className: classes.overlay,
|
|
103
139
|
children: [/*#__PURE__*/_jsx(Backdrop, {
|
|
104
140
|
isVisible: true,
|
|
105
141
|
level: 0,
|
|
@@ -110,8 +146,8 @@ const ContextMenu = props => {
|
|
|
110
146
|
children: /*#__PURE__*/_jsx(ContextMenuProvider, {
|
|
111
147
|
handleMenuToggle: handleMenuToggle,
|
|
112
148
|
children: /*#__PURE__*/_jsxs("div", {
|
|
113
|
-
className:
|
|
114
|
-
[
|
|
149
|
+
className: cx(classes.menu, {
|
|
150
|
+
[classes.scrollable]: useScroll
|
|
115
151
|
}),
|
|
116
152
|
ref: menuRef,
|
|
117
153
|
tabIndex: "-1",
|
|
@@ -5,6 +5,45 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
const message = '<p><i>This is a html message.</i></p>';
|
|
6
6
|
const title = 'This is the title.';
|
|
7
7
|
jest.mock('@shopgate/engage/a11y/components');
|
|
8
|
+
jest.mock('@shopgate/engage/components', () => {
|
|
9
|
+
const mockReact = jest.requireActual('react');
|
|
10
|
+
function Text({
|
|
11
|
+
string
|
|
12
|
+
}) {
|
|
13
|
+
return mockReact.createElement('span', null, string);
|
|
14
|
+
}
|
|
15
|
+
Text.propTypes = {
|
|
16
|
+
params: () => null
|
|
17
|
+
};
|
|
18
|
+
Text.defaultProps = {
|
|
19
|
+
params: {}
|
|
20
|
+
};
|
|
21
|
+
const I18n = {
|
|
22
|
+
Text
|
|
23
|
+
};
|
|
24
|
+
function Ellipsis({
|
|
25
|
+
children
|
|
26
|
+
}) {
|
|
27
|
+
return mockReact.createElement('span', null, children);
|
|
28
|
+
}
|
|
29
|
+
function Button({
|
|
30
|
+
children,
|
|
31
|
+
onClick,
|
|
32
|
+
disabled,
|
|
33
|
+
className
|
|
34
|
+
}) {
|
|
35
|
+
return mockReact.createElement('button', {
|
|
36
|
+
onClick,
|
|
37
|
+
disabled,
|
|
38
|
+
className
|
|
39
|
+
}, children);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
I18n,
|
|
43
|
+
Ellipsis,
|
|
44
|
+
Button
|
|
45
|
+
};
|
|
46
|
+
});
|
|
8
47
|
describe('<HtmlContentDialog />', () => {
|
|
9
48
|
it('should render with minimal props', () => {
|
|
10
49
|
const wrapper = shallow(/*#__PURE__*/_jsx(HtmlContentDialog, {
|