newspack-components 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/colors/colors.module.scss +277 -0
- package/copy-styles.js +8 -1
- package/dist/cjs/action-card/action-card.d.js +5 -0
- package/dist/cjs/action-card/index.js +282 -187
- package/dist/cjs/action-card/style.scss +142 -44
- package/dist/cjs/autocomplete-tokenfield/index.js +6 -2
- package/dist/cjs/box-contrast/index.js +49 -0
- package/dist/cjs/button/index.js +1 -1
- package/dist/cjs/button-props/button-props.js +41 -0
- package/dist/cjs/button-props/index.js +13 -0
- package/dist/cjs/color-picker/index.js +11 -0
- package/dist/cjs/custom-select-control/style.scss +7 -12
- package/dist/cjs/footer/index.js +17 -24
- package/dist/cjs/footer/style.scss +0 -36
- package/dist/cjs/handoff-message/index.js +0 -3
- package/dist/cjs/hooks/useObjectState.js +9 -0
- package/dist/cjs/hooks/useObjectState.test.js +5 -5
- package/dist/cjs/index.js +7 -21
- package/dist/cjs/modal/index.js +4 -1
- package/dist/cjs/modal/style.scss +18 -7
- package/dist/cjs/newspack-icon/index.js +2 -2
- package/dist/cjs/newspack-icon/style.scss +3 -5
- package/dist/cjs/notice/index.js +1 -2
- package/dist/cjs/notice/style.scss +11 -9
- package/dist/cjs/plugin-installer/index.js +3 -3
- package/dist/cjs/plugin-settings/SettingsSection.js +2 -0
- package/dist/cjs/plugin-settings/index.js +4 -1
- package/dist/cjs/plugin-toggle/index.js +2 -0
- package/dist/cjs/popover/style.scss +5 -6
- package/dist/cjs/progress-bar/index.test.js +1 -2
- package/dist/cjs/progress-bar/style.scss +1 -2
- package/dist/cjs/proxied-imports/router.js +1 -2
- package/dist/cjs/radio-control/style.scss +4 -10
- package/dist/cjs/section-header/index.js +21 -1
- package/dist/cjs/select-control/ButtonGroupControl.js +2 -0
- package/dist/cjs/settings/SettingsCard.js +2 -6
- package/dist/cjs/sortable-newsletter-list-control/index.js +7 -5
- package/dist/cjs/sortable-newsletter-list-control/style.scss +11 -1
- package/dist/cjs/steps-list/style.scss +0 -3
- package/dist/cjs/steps-list-item/style.scss +1 -2
- package/dist/cjs/style-card/index.js +1 -0
- package/dist/cjs/style-card/style.scss +4 -5
- package/dist/cjs/style.scss +15 -0
- package/dist/cjs/tabbed-navigation/index.js +17 -7
- package/dist/cjs/tabbed-navigation/style.scss +2 -6
- package/dist/cjs/utils/color.js +35 -0
- package/dist/cjs/web-preview/style.scss +11 -11
- package/dist/cjs/with-wizard/index.js +80 -3
- package/dist/cjs/with-wizard/style.scss +34 -13
- package/dist/cjs/with-wizard-screen/index.js +3 -3
- package/dist/cjs/with-wizard-screen/style.scss +9 -9
- package/dist/cjs/wizard/index.js +38 -13
- package/dist/cjs/wizard/store/index.js +13 -5
- package/dist/cjs/wizard/store/utils.js +3 -1
- package/dist/esm/action-card/action-card.d.js +1 -0
- package/dist/esm/action-card/index.js +286 -189
- package/dist/esm/action-card/style.scss +142 -44
- package/dist/esm/autocomplete-tokenfield/index.js +6 -2
- package/dist/esm/box-contrast/index.js +44 -0
- package/dist/esm/button/index.js +1 -1
- package/dist/esm/button-props/button-props.js +34 -0
- package/dist/esm/button-props/index.js +1 -0
- package/dist/esm/color-picker/index.js +11 -0
- package/dist/esm/custom-select-control/style.scss +7 -12
- package/dist/esm/footer/index.js +18 -25
- package/dist/esm/footer/style.scss +0 -36
- package/dist/esm/handoff-message/index.js +0 -3
- package/dist/esm/hooks/useObjectState.js +10 -0
- package/dist/esm/hooks/useObjectState.test.js +6 -6
- package/dist/esm/index.js +1 -3
- package/dist/esm/modal/index.js +4 -1
- package/dist/esm/modal/style.scss +18 -7
- package/dist/esm/newspack-icon/index.js +2 -2
- package/dist/esm/newspack-icon/style.scss +3 -5
- package/dist/esm/notice/index.js +1 -2
- package/dist/esm/notice/style.scss +11 -9
- package/dist/esm/plugin-installer/index.js +3 -3
- package/dist/esm/plugin-settings/SettingsSection.js +2 -0
- package/dist/esm/plugin-settings/index.js +4 -1
- package/dist/esm/plugin-toggle/index.js +2 -0
- package/dist/esm/popover/style.scss +5 -6
- package/dist/esm/progress-bar/style.scss +1 -2
- package/dist/esm/radio-control/style.scss +4 -10
- package/dist/esm/section-header/index.js +22 -0
- package/dist/esm/select-control/ButtonGroupControl.js +2 -0
- package/dist/esm/settings/SettingsCard.js +2 -6
- package/dist/esm/sortable-newsletter-list-control/index.js +8 -6
- package/dist/esm/sortable-newsletter-list-control/style.scss +11 -1
- package/dist/esm/steps-list/style.scss +0 -3
- package/dist/esm/steps-list-item/style.scss +1 -2
- package/dist/esm/style-card/index.js +1 -0
- package/dist/esm/style-card/style.scss +4 -5
- package/dist/esm/style.scss +15 -0
- package/dist/esm/tabbed-navigation/index.js +17 -7
- package/dist/esm/tabbed-navigation/style.scss +2 -6
- package/dist/esm/utils/color.js +29 -0
- package/dist/esm/web-preview/style.scss +11 -11
- package/dist/esm/with-wizard/index.js +81 -4
- package/dist/esm/with-wizard/style.scss +34 -13
- package/dist/esm/with-wizard-screen/index.js +1 -1
- package/dist/esm/with-wizard-screen/style.scss +9 -9
- package/dist/esm/wizard/index.js +39 -13
- package/dist/esm/wizard/store/index.js +13 -5
- package/dist/esm/wizard/store/utils.js +3 -1
- package/package.json +1 -1
- package/src/accordion/index.js +1 -3
- package/src/action-card/action-card.d.ts +40 -0
- package/src/action-card/index.js +284 -202
- package/src/action-card/style.scss +142 -44
- package/src/autocomplete-tokenfield/index.js +3 -2
- package/src/autocomplete-with-suggestions/index.js +52 -63
- package/src/box-contrast/index.tsx +44 -0
- package/src/button/index.tsx +1 -1
- package/src/button-card/index.js +1 -12
- package/src/card/index.js +1 -11
- package/src/category-autocomplete/index.js +4 -19
- package/src/color-picker/index.js +11 -7
- package/src/custom-select-control/style.scss +7 -12
- package/src/footer/index.js +6 -18
- package/src/footer/style.scss +0 -36
- package/src/form-token-field/index.js +1 -2
- package/src/grid/index.tsx +1 -8
- package/src/handoff/index.js +4 -11
- package/src/handoff-message/index.js +0 -3
- package/src/hooks/useObjectState.js +10 -2
- package/src/hooks/useObjectState.test.js +14 -14
- package/src/image-upload/index.js +3 -23
- package/src/index.js +1 -3
- package/src/modal/index.js +2 -2
- package/src/modal/style.scss +18 -7
- package/src/newspack-icon/index.js +3 -14
- package/src/newspack-icon/style.scss +3 -5
- package/src/notice/index.js +0 -2
- package/src/notice/style.scss +11 -9
- package/src/plugin-installer/index.js +8 -17
- package/src/plugin-settings/SettingsSection.js +3 -7
- package/src/plugin-settings/index.js +7 -14
- package/src/plugin-toggle/README.md +3 -3
- package/src/plugin-toggle/index.js +10 -13
- package/src/popover/index.js +1 -5
- package/src/popover/style.scss +5 -6
- package/src/position-control/index.js +65 -75
- package/src/progress-bar/index.js +2 -9
- package/src/progress-bar/index.test.js +4 -13
- package/src/progress-bar/style.scss +1 -2
- package/src/radio-control/style.scss +4 -10
- package/src/section-header/index.js +20 -0
- package/src/select-control/ButtonGroupControl.js +2 -9
- package/src/select-control/GroupedSelectControl.js +1 -9
- package/src/select-control/index.js +1 -5
- package/src/settings/MinMaxSetting.js +2 -14
- package/src/settings/SettingsCard.js +2 -11
- package/src/sortable-newsletter-list-control/index.js +10 -26
- package/src/sortable-newsletter-list-control/style.scss +11 -1
- package/src/steps-list/style.scss +0 -3
- package/src/steps-list-item/index.js +1 -4
- package/src/steps-list-item/style.scss +1 -2
- package/src/style-card/index.js +6 -21
- package/src/style-card/style.scss +4 -5
- package/src/style.scss +15 -0
- package/src/tabbed-navigation/index.js +19 -7
- package/src/tabbed-navigation/style.scss +2 -6
- package/src/text-control/index.tsx +2 -12
- package/src/utils/color.ts +32 -0
- package/src/web-preview/style.scss +11 -11
- package/src/with-wizard/index.js +67 -16
- package/src/with-wizard/style.scss +34 -13
- package/src/with-wizard-screen/index.js +1 -1
- package/src/with-wizard-screen/style.scss +9 -9
- package/src/wizard/components/WizardError.js +2 -7
- package/src/wizard/index.js +64 -62
- package/src/wizard/store/index.js +8 -10
- package/src/wizard/store/utils.js +3 -4
- package/dist/cjs/date-range-picker/index.js +0 -39
- package/dist/cjs/date-range-picker/style.scss +0 -148
- package/dist/cjs/newspack-logo/index.js +0 -54
- package/dist/cjs/newspack-logo/style.scss +0 -30
- package/dist/cjs/patrons-logo/index.js +0 -77
- package/dist/esm/date-range-picker/index.js +0 -31
- package/dist/esm/date-range-picker/style.scss +0 -148
- package/dist/esm/newspack-logo/index.js +0 -46
- package/dist/esm/newspack-logo/style.scss +0 -30
- package/dist/esm/patrons-logo/index.js +0 -70
- package/shared/scss/_colors.scss +0 -27
- package/src/date-range-picker/index.js +0 -31
- package/src/date-range-picker/style.scss +0 -148
- package/src/newspack-logo/index.js +0 -45
- package/src/newspack-logo/style.scss +0 -30
- package/src/patrons-logo/index.js +0 -76
- /package/{shared/js → src/button-props}/button-props.js +0 -0
- /package/{shared/js → src/button-props}/index.js +0 -0
|
@@ -21,7 +21,7 @@ var _utils = require("./utils.js");
|
|
|
21
21
|
|
|
22
22
|
const WIZARD_STORE_NAMESPACE = exports.WIZARD_STORE_NAMESPACE = 'newspack/wizards';
|
|
23
23
|
const DEFAULT_STATE = {
|
|
24
|
-
isLoading:
|
|
24
|
+
isLoading: false,
|
|
25
25
|
isQuietLoading: false,
|
|
26
26
|
apiData: {},
|
|
27
27
|
error: null
|
|
@@ -120,6 +120,10 @@ const selectors = {
|
|
|
120
120
|
isLoading: state => state.isLoading,
|
|
121
121
|
isQuietLoading: state => state.isQuietLoading,
|
|
122
122
|
getWizardAPIData: (state, slug) => state.apiData[slug] || {},
|
|
123
|
+
getWizardData: (state, slug) => {
|
|
124
|
+
var _state$apiData$slug;
|
|
125
|
+
return (_state$apiData$slug = state.apiData[slug]) !== null && _state$apiData$slug !== void 0 ? _state$apiData$slug : {};
|
|
126
|
+
},
|
|
123
127
|
getError: state => state.error
|
|
124
128
|
};
|
|
125
129
|
const store = (0, _data.createReduxStore)(WIZARD_STORE_NAMESPACE, {
|
|
@@ -128,17 +132,21 @@ const store = (0, _data.createReduxStore)(WIZARD_STORE_NAMESPACE, {
|
|
|
128
132
|
selectors,
|
|
129
133
|
controls: {
|
|
130
134
|
FETCH_FROM_API: action => {
|
|
135
|
+
const {
|
|
136
|
+
isLocalError = false,
|
|
137
|
+
isQuietFetch = false
|
|
138
|
+
} = action.payload;
|
|
131
139
|
(0, _data.dispatch)(WIZARD_STORE_NAMESPACE).startLoadingData({
|
|
132
|
-
isQuietLoading: Boolean(
|
|
140
|
+
isQuietLoading: Boolean(isQuietFetch)
|
|
133
141
|
});
|
|
134
142
|
return (0, _apiFetch.default)(action.payload).then(data => {
|
|
135
143
|
(0, _data.dispatch)(WIZARD_STORE_NAMESPACE).setError(null);
|
|
136
144
|
return data;
|
|
137
145
|
}).catch(error => {
|
|
146
|
+
if (isLocalError) {
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
138
149
|
(0, _data.dispatch)(WIZARD_STORE_NAMESPACE).setError(error);
|
|
139
|
-
return {
|
|
140
|
-
error
|
|
141
|
-
};
|
|
142
150
|
}).finally(result => {
|
|
143
151
|
(0, _data.dispatch)(WIZARD_STORE_NAMESPACE).finishLoadingData();
|
|
144
152
|
return result;
|
|
@@ -19,5 +19,7 @@ const createAction = type => payload => ({
|
|
|
19
19
|
payload
|
|
20
20
|
});
|
|
21
21
|
exports.createAction = createAction;
|
|
22
|
-
const useWizardData = (wizardName, defaultValue = {}) =>
|
|
22
|
+
const useWizardData = (wizardName, defaultValue = {}) => {
|
|
23
|
+
return (0, _data.useSelect)(select => select(_.WIZARD_STORE_NAMESPACE).getWizardAPIData(wizardName)) || defaultValue;
|
|
24
|
+
};
|
|
23
25
|
exports.useWizardData = useWizardData;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -5,215 +5,312 @@
|
|
|
5
5
|
/**
|
|
6
6
|
* WordPress dependencies
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { Draggable, ExternalLink, ToggleControl } from '@wordpress/components';
|
|
9
|
+
import { useEffect, useState } from '@wordpress/element';
|
|
10
|
+
import { __ } from '@wordpress/i18n';
|
|
11
|
+
import { Icon, check, chevronDown, chevronUp, dragHandle } from '@wordpress/icons';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Internal dependencies
|
|
14
15
|
*/
|
|
15
16
|
import { Button, Card, Grid, Handoff, Notice, Waiting } from '../';
|
|
17
|
+
import { ActionCardProps } from './action-card.d.ts';
|
|
16
18
|
import './style.scss';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* External dependencies
|
|
20
22
|
*/
|
|
21
23
|
import classnames from 'classnames';
|
|
22
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
-
class ActionCard extends Component {
|
|
24
|
-
state = {
|
|
25
|
-
expanded: false
|
|
26
|
-
};
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
25
|
+
/**
|
|
26
|
+
* ActionCard component
|
|
27
|
+
* @param {ActionCardProps} props Component props.
|
|
28
|
+
* @return {JSX.Element} ActionCard component.
|
|
29
|
+
*/
|
|
30
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
31
|
+
const ActionCard = ({
|
|
32
|
+
badge,
|
|
33
|
+
badgeLevel = 'info',
|
|
34
|
+
className,
|
|
35
|
+
checkbox,
|
|
36
|
+
children,
|
|
37
|
+
collapse,
|
|
38
|
+
disabled,
|
|
39
|
+
title,
|
|
40
|
+
description,
|
|
41
|
+
handoff,
|
|
42
|
+
editLink,
|
|
43
|
+
href,
|
|
44
|
+
notification,
|
|
45
|
+
notificationLevel,
|
|
46
|
+
notificationHTML,
|
|
47
|
+
actionContent,
|
|
48
|
+
actionText,
|
|
49
|
+
secondaryActionText,
|
|
50
|
+
secondaryDestructive,
|
|
51
|
+
id,
|
|
52
|
+
image,
|
|
53
|
+
imageLink,
|
|
54
|
+
indent,
|
|
55
|
+
isSmall,
|
|
56
|
+
isMedium,
|
|
57
|
+
simple,
|
|
58
|
+
onClick,
|
|
59
|
+
onSecondaryActionClick,
|
|
60
|
+
isWaiting,
|
|
61
|
+
titleLink,
|
|
62
|
+
toggleChecked = false,
|
|
63
|
+
toggleOnChange,
|
|
64
|
+
hasGreyHeader,
|
|
65
|
+
hasWhiteHeader,
|
|
66
|
+
noBorder,
|
|
67
|
+
isPending,
|
|
68
|
+
expandable = false,
|
|
69
|
+
isButtonEnabled = false,
|
|
70
|
+
// Draggable props. All are required to enable drag sorting.
|
|
71
|
+
draggable = false,
|
|
72
|
+
dragIndex,
|
|
73
|
+
dragWrapperRef,
|
|
74
|
+
onDragCallback
|
|
75
|
+
}) => {
|
|
76
|
+
const [expanded, setExpanded] = useState(false);
|
|
77
|
+
const [dragging, setDragging] = useState(false);
|
|
78
|
+
const [targetIndex, setTargetIndex] = useState(null);
|
|
79
|
+
const [dragRef, setDragRef] = useState(null);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (dragWrapperRef && !dragRef) {
|
|
82
|
+
setDragRef(dragWrapperRef);
|
|
36
83
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
disabled,
|
|
49
|
-
title,
|
|
50
|
-
description,
|
|
51
|
-
handoff,
|
|
52
|
-
editLink,
|
|
53
|
-
href,
|
|
54
|
-
notification,
|
|
55
|
-
notificationLevel,
|
|
56
|
-
notificationHTML,
|
|
57
|
-
actionContent,
|
|
58
|
-
actionText,
|
|
59
|
-
secondaryActionText,
|
|
60
|
-
secondaryDestructive,
|
|
61
|
-
image,
|
|
62
|
-
imageLink,
|
|
63
|
-
indent,
|
|
64
|
-
isSmall,
|
|
65
|
-
isMedium,
|
|
66
|
-
simple,
|
|
67
|
-
onClick,
|
|
68
|
-
onSecondaryActionClick,
|
|
69
|
-
isWaiting,
|
|
70
|
-
titleLink,
|
|
71
|
-
toggleChecked,
|
|
72
|
-
toggleOnChange,
|
|
73
|
-
hasGreyHeader,
|
|
74
|
-
hasWhiteHeader,
|
|
75
|
-
isPending,
|
|
76
|
-
expandable = false,
|
|
77
|
-
isButtonEnabled = false
|
|
78
|
-
} = this.props;
|
|
79
|
-
const {
|
|
80
|
-
expanded
|
|
81
|
-
} = this.state;
|
|
82
|
-
const hasChildren = notification || children;
|
|
83
|
-
const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasWhiteHeader && 'newspack-card--has-white-header', hasChildren && 'newspack-card--has-children', indent && 'newspack-card--indent', isSmall && 'is-small', isMedium && 'is-medium', checkbox && 'has-checkbox', expandable && 'is-expandable', actionContent && 'has-action-content', className);
|
|
84
|
-
const backgroundImageStyles = url => {
|
|
85
|
-
return url ? {
|
|
86
|
-
backgroundImage: `url(${url})`
|
|
87
|
-
} : {};
|
|
88
|
-
};
|
|
89
|
-
const titleProps = toggleOnChange && !titleLink && !disabled ? {
|
|
90
|
-
onClick: () => toggleOnChange(!toggleChecked),
|
|
91
|
-
tabIndex: '0'
|
|
84
|
+
}, [dragWrapperRef?.current]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (collapse && expanded) {
|
|
87
|
+
setExpanded(false);
|
|
88
|
+
}
|
|
89
|
+
}, [collapse]);
|
|
90
|
+
const hasChildren = notification || children;
|
|
91
|
+
const classes = classnames('newspack-action-card', simple && 'newspack-card--is-clickable', hasGreyHeader && 'newspack-card--has-grey-header', hasWhiteHeader && 'newspack-card--has-white-header', hasChildren && 'newspack-card--has-children', indent && 'newspack-card--indent', isSmall && 'is-small', isMedium && 'is-medium', checkbox && 'has-checkbox', expandable && 'is-expandable', draggable && 'is-draggable', actionContent && 'has-action-content', className);
|
|
92
|
+
const backgroundImageStyles = url => {
|
|
93
|
+
return url ? {
|
|
94
|
+
backgroundImage: `url(${url})`
|
|
92
95
|
} : {};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
};
|
|
97
|
+
const titleProps = toggleOnChange && !titleLink && !disabled ? {
|
|
98
|
+
onClick: () => toggleOnChange(!toggleChecked),
|
|
99
|
+
tabIndex: '0'
|
|
100
|
+
} : {};
|
|
101
|
+
const hasInternalLink = href && href.indexOf('http') !== 0;
|
|
102
|
+
const isDisplayingSecondaryAction = secondaryActionText && onSecondaryActionClick;
|
|
103
|
+
const badges = !Array.isArray(badge) && badge ? [badge] : badge;
|
|
104
|
+
const Component = () => /*#__PURE__*/_jsxs(_Fragment, {
|
|
105
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
106
|
+
className: "newspack-action-card__region newspack-action-card__region-top",
|
|
107
|
+
children: [toggleOnChange && /*#__PURE__*/_jsx(ToggleControl, {
|
|
108
|
+
checked: toggleChecked,
|
|
109
|
+
onChange: toggleOnChange,
|
|
110
|
+
disabled: disabled
|
|
111
|
+
}), image && !toggleOnChange && /*#__PURE__*/_jsx("div", {
|
|
112
|
+
className: "newspack-action-card__region newspack-action-card__region-left",
|
|
113
|
+
children: /*#__PURE__*/_jsx("a", {
|
|
114
|
+
href: imageLink,
|
|
115
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
116
|
+
className: "newspack-action-card__image",
|
|
117
|
+
style: backgroundImageStyles(image)
|
|
113
118
|
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
})
|
|
120
|
+
}), checkbox && !toggleOnChange && /*#__PURE__*/_jsx("div", {
|
|
121
|
+
className: "newspack-action-card__region newspack-action-card__region-left",
|
|
122
|
+
children: /*#__PURE__*/_jsx("span", {
|
|
123
|
+
className: classnames('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked', isPending && 'newspack-checkbox-icon--pending'),
|
|
124
|
+
children: 'checked' === checkbox && /*#__PURE__*/_jsx(Icon, {
|
|
125
|
+
icon: check
|
|
121
126
|
})
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
children: [typeof description === 'string' && description, typeof description === 'function' && description()]
|
|
148
|
-
})]
|
|
149
|
-
})
|
|
150
|
-
}), !expandable && (actionText || isDisplayingSecondaryAction || actionContent) && /*#__PURE__*/_jsxs("div", {
|
|
151
|
-
className: "newspack-action-card__region newspack-action-card__region-right",
|
|
152
|
-
children: [actionContent && actionContent, actionText && (handoff ? /*#__PURE__*/_jsx(Handoff, {
|
|
153
|
-
plugin: handoff,
|
|
154
|
-
editLink: editLink,
|
|
155
|
-
compact: true,
|
|
156
|
-
isLink: true,
|
|
157
|
-
children: actionText
|
|
158
|
-
}) : onClick || hasInternalLink ? /*#__PURE__*/_jsx(Button, {
|
|
159
|
-
disabled: disabled && !isButtonEnabled,
|
|
160
|
-
isLink: true,
|
|
161
|
-
href: href,
|
|
162
|
-
onClick: onClick,
|
|
163
|
-
className: "newspack-action-card__primary_button",
|
|
164
|
-
children: actionText
|
|
165
|
-
}) : href ? /*#__PURE__*/_jsx(ExternalLink, {
|
|
166
|
-
href: href,
|
|
167
|
-
className: "newspack-action-card__primary_button",
|
|
168
|
-
children: actionText
|
|
169
|
-
}) : /*#__PURE__*/_jsxs("div", {
|
|
170
|
-
className: "newspack-action-card__container",
|
|
171
|
-
children: [actionText, isWaiting && /*#__PURE__*/_jsx(Waiting, {
|
|
172
|
-
isRight: true
|
|
173
|
-
})]
|
|
174
|
-
})), isDisplayingSecondaryAction && /*#__PURE__*/_jsx(Button, {
|
|
175
|
-
isLink: true,
|
|
176
|
-
onClick: onSecondaryActionClick,
|
|
177
|
-
className: "newspack-action-card__secondary_button",
|
|
178
|
-
isDestructive: secondaryDestructive,
|
|
179
|
-
children: secondaryActionText
|
|
127
|
+
})
|
|
128
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
129
|
+
className: "newspack-action-card__region newspack-action-card__region-center",
|
|
130
|
+
children: /*#__PURE__*/_jsxs(Grid, {
|
|
131
|
+
columns: 1,
|
|
132
|
+
gutter: 8,
|
|
133
|
+
noMargin: true,
|
|
134
|
+
children: [/*#__PURE__*/_jsxs("h2", {
|
|
135
|
+
children: [/*#__PURE__*/_jsxs("span", {
|
|
136
|
+
className: "newspack-action-card__title",
|
|
137
|
+
...titleProps,
|
|
138
|
+
children: [titleLink && /*#__PURE__*/_jsx("a", {
|
|
139
|
+
href: titleLink,
|
|
140
|
+
children: title
|
|
141
|
+
}), !titleLink && expandable && /*#__PURE__*/_jsx(Button, {
|
|
142
|
+
isLink: true,
|
|
143
|
+
onClick: () => setExpanded(!expanded),
|
|
144
|
+
children: title
|
|
145
|
+
}), !titleLink && !expandable && title]
|
|
146
|
+
}), badges?.length && badges.map((badgeText, i) => /*#__PURE__*/_jsx("span", {
|
|
147
|
+
className: `newspack-action-card__badge newspack-action-card__badge-level-${badgeLevel}`,
|
|
148
|
+
children: badgeText
|
|
149
|
+
}, `badge-${i}`))]
|
|
150
|
+
}), description && /*#__PURE__*/_jsxs("p", {
|
|
151
|
+
children: [typeof description === 'string' && description, typeof description === 'function' && description()]
|
|
180
152
|
})]
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
})
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
153
|
+
})
|
|
154
|
+
}), !expandable && (actionText || isDisplayingSecondaryAction || actionContent) && /*#__PURE__*/_jsxs("div", {
|
|
155
|
+
className: "newspack-action-card__region newspack-action-card__region-right",
|
|
156
|
+
children: [actionContent && actionContent, actionText && (handoff ? /*#__PURE__*/_jsx(Handoff, {
|
|
157
|
+
plugin: handoff,
|
|
158
|
+
editLink: editLink,
|
|
159
|
+
compact: true,
|
|
160
|
+
isLink: true,
|
|
161
|
+
children: actionText
|
|
162
|
+
}) : onClick || hasInternalLink ? /*#__PURE__*/_jsx(Button, {
|
|
163
|
+
disabled: disabled && !isButtonEnabled,
|
|
164
|
+
isLink: true,
|
|
165
|
+
href: href,
|
|
166
|
+
onClick: onClick,
|
|
167
|
+
className: "newspack-action-card__primary_button",
|
|
168
|
+
children: actionText
|
|
169
|
+
}) : href ? /*#__PURE__*/_jsx(ExternalLink, {
|
|
170
|
+
href: href,
|
|
171
|
+
className: "newspack-action-card__primary_button",
|
|
172
|
+
children: actionText
|
|
173
|
+
}) : /*#__PURE__*/_jsxs("div", {
|
|
174
|
+
className: "newspack-action-card__container",
|
|
175
|
+
children: [actionText, isWaiting && /*#__PURE__*/_jsx(Waiting, {
|
|
176
|
+
isRight: true
|
|
177
|
+
})]
|
|
178
|
+
})), isDisplayingSecondaryAction && /*#__PURE__*/_jsx(Button, {
|
|
179
|
+
isLink: true,
|
|
180
|
+
onClick: onSecondaryActionClick,
|
|
181
|
+
className: "newspack-action-card__secondary_button",
|
|
182
|
+
isDestructive: secondaryDestructive,
|
|
183
|
+
children: secondaryActionText
|
|
208
184
|
})]
|
|
209
|
-
}),
|
|
210
|
-
|
|
211
|
-
children:
|
|
185
|
+
}), expandable && /*#__PURE__*/_jsx(Button, {
|
|
186
|
+
onClick: () => setExpanded(!expanded),
|
|
187
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
188
|
+
icon: expanded ? chevronUp : chevronDown,
|
|
189
|
+
height: 24,
|
|
190
|
+
width: 24
|
|
191
|
+
})
|
|
212
192
|
})]
|
|
193
|
+
}), notification && /*#__PURE__*/_jsxs("div", {
|
|
194
|
+
className: "newspack-action-card__notification newspack-action-card__region-children",
|
|
195
|
+
children: ['error' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
|
|
196
|
+
noticeText: notification,
|
|
197
|
+
isError: true,
|
|
198
|
+
rawHTML: notificationHTML
|
|
199
|
+
}), 'info' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
|
|
200
|
+
noticeText: notification,
|
|
201
|
+
rawHTML: notificationHTML
|
|
202
|
+
}), 'success' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
|
|
203
|
+
noticeText: notification,
|
|
204
|
+
isSuccess: true,
|
|
205
|
+
rawHTML: notificationHTML
|
|
206
|
+
}), 'warning' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
|
|
207
|
+
noticeText: notification,
|
|
208
|
+
isWarning: true,
|
|
209
|
+
rawHTML: notificationHTML
|
|
210
|
+
})]
|
|
211
|
+
}), children && (expandable && expanded || !expandable) && /*#__PURE__*/_jsx("div", {
|
|
212
|
+
className: "newspack-action-card__region-children",
|
|
213
|
+
children: children
|
|
214
|
+
})]
|
|
215
|
+
});
|
|
216
|
+
if (draggable && dragRef?.current && typeof dragIndex === 'number' && onDragCallback && id) {
|
|
217
|
+
let wrapperRect = dragRef.current.getBoundingClientRect();
|
|
218
|
+
let draggableCards = Array.prototype.slice.call(dragRef.current.querySelectorAll('.newspack-action-card__draggable-wrapper'));
|
|
219
|
+
const isFirstTarget = dragIndex === 0;
|
|
220
|
+
const isLastTarget = dragIndex === draggableCards.length - 1;
|
|
221
|
+
const handleDragStart = () => {
|
|
222
|
+
draggableCards = Array.prototype.slice.call(dragRef.current.querySelectorAll('.newspack-action-card__draggable-wrapper'));
|
|
223
|
+
wrapperRect = dragRef.current.getBoundingClientRect();
|
|
224
|
+
if (dragging) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
setTargetIndex(dragIndex);
|
|
228
|
+
setDragging(true);
|
|
229
|
+
};
|
|
230
|
+
const handleDragEnd = () => {
|
|
231
|
+
if (targetIndex !== null && targetIndex !== dragIndex) {
|
|
232
|
+
onDragCallback(targetIndex);
|
|
233
|
+
}
|
|
234
|
+
setTargetIndex(null);
|
|
235
|
+
setDragging(false);
|
|
236
|
+
};
|
|
237
|
+
const handleDragOver = e => {
|
|
238
|
+
const isDraggingToTop = e.pageY <= wrapperRect.top + window.scrollY;
|
|
239
|
+
const isDraggingToBottom = e.pageY >= wrapperRect.bottom + window.scrollY;
|
|
240
|
+
const target = e.target.closest('.newspack-action-card__draggable-wrapper');
|
|
241
|
+
if (isDraggingToTop || isDraggingToBottom || target) {
|
|
242
|
+
setTargetIndex(draggableCards.indexOf(target));
|
|
243
|
+
|
|
244
|
+
// If dragging the element over itself or over an invalid target, cancel the drop.
|
|
245
|
+
if (0 > targetIndex || targetIndex === dragIndex + 1) {
|
|
246
|
+
setTargetIndex(dragIndex);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Handle dropping before the first item.
|
|
250
|
+
if (isDraggingToTop) {
|
|
251
|
+
setTargetIndex(0);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Handle dropping after the last item.
|
|
255
|
+
if (isDraggingToBottom) {
|
|
256
|
+
setTargetIndex(draggableCards.length);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
return /*#__PURE__*/_jsx("div", {
|
|
261
|
+
className: 'newspack-action-card__draggable-wrapper' + (dragging ? ' is-dragging' : ''),
|
|
262
|
+
id: `draggable-card-${id}`,
|
|
263
|
+
children: /*#__PURE__*/_jsx(Draggable, {
|
|
264
|
+
elementId: `draggable-card-${id}`,
|
|
265
|
+
transferData: {},
|
|
266
|
+
onDragStart: handleDragStart,
|
|
267
|
+
onDragEnd: handleDragEnd,
|
|
268
|
+
onDragOver: handleDragOver,
|
|
269
|
+
children: ({
|
|
270
|
+
onDraggableStart,
|
|
271
|
+
onDraggableEnd
|
|
272
|
+
}) => /*#__PURE__*/_jsxs(Card, {
|
|
273
|
+
className: classes,
|
|
274
|
+
onClick: simple && onClick,
|
|
275
|
+
id: id !== null && id !== void 0 ? id : null,
|
|
276
|
+
noBorder: noBorder,
|
|
277
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
278
|
+
className: "newspack-action-card__draggable-controls",
|
|
279
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
280
|
+
className: "drag-handle",
|
|
281
|
+
draggable: true,
|
|
282
|
+
onDragStart: onDraggableStart,
|
|
283
|
+
onDragEnd: onDraggableEnd,
|
|
284
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
285
|
+
icon: dragHandle,
|
|
286
|
+
height: 18,
|
|
287
|
+
width: 18
|
|
288
|
+
})
|
|
289
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
290
|
+
className: "movers",
|
|
291
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
292
|
+
icon: chevronUp,
|
|
293
|
+
onClick: () => onDragCallback(dragIndex - 1),
|
|
294
|
+
disabled: isFirstTarget,
|
|
295
|
+
label: __('Move one position up', 'newspack-plugin')
|
|
296
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
297
|
+
icon: chevronDown,
|
|
298
|
+
onClick: () => onDragCallback(dragIndex + 1),
|
|
299
|
+
disabled: isLastTarget,
|
|
300
|
+
label: __('Move one position down', 'newspack-plugin')
|
|
301
|
+
})]
|
|
302
|
+
})]
|
|
303
|
+
}), /*#__PURE__*/_jsx(Component, {})]
|
|
304
|
+
})
|
|
305
|
+
})
|
|
213
306
|
});
|
|
214
307
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
308
|
+
return /*#__PURE__*/_jsx(Card, {
|
|
309
|
+
className: classes,
|
|
310
|
+
onClick: simple && onClick,
|
|
311
|
+
id: id !== null && id !== void 0 ? id : null,
|
|
312
|
+
noBorder: noBorder,
|
|
313
|
+
children: /*#__PURE__*/_jsx(Component, {})
|
|
314
|
+
});
|
|
218
315
|
};
|
|
219
316
|
export default ActionCard;
|