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.
Files changed (191) hide show
  1. package/colors/colors.module.scss +277 -0
  2. package/copy-styles.js +8 -1
  3. package/dist/cjs/action-card/action-card.d.js +5 -0
  4. package/dist/cjs/action-card/index.js +282 -187
  5. package/dist/cjs/action-card/style.scss +142 -44
  6. package/dist/cjs/autocomplete-tokenfield/index.js +6 -2
  7. package/dist/cjs/box-contrast/index.js +49 -0
  8. package/dist/cjs/button/index.js +1 -1
  9. package/dist/cjs/button-props/button-props.js +41 -0
  10. package/dist/cjs/button-props/index.js +13 -0
  11. package/dist/cjs/color-picker/index.js +11 -0
  12. package/dist/cjs/custom-select-control/style.scss +7 -12
  13. package/dist/cjs/footer/index.js +17 -24
  14. package/dist/cjs/footer/style.scss +0 -36
  15. package/dist/cjs/handoff-message/index.js +0 -3
  16. package/dist/cjs/hooks/useObjectState.js +9 -0
  17. package/dist/cjs/hooks/useObjectState.test.js +5 -5
  18. package/dist/cjs/index.js +7 -21
  19. package/dist/cjs/modal/index.js +4 -1
  20. package/dist/cjs/modal/style.scss +18 -7
  21. package/dist/cjs/newspack-icon/index.js +2 -2
  22. package/dist/cjs/newspack-icon/style.scss +3 -5
  23. package/dist/cjs/notice/index.js +1 -2
  24. package/dist/cjs/notice/style.scss +11 -9
  25. package/dist/cjs/plugin-installer/index.js +3 -3
  26. package/dist/cjs/plugin-settings/SettingsSection.js +2 -0
  27. package/dist/cjs/plugin-settings/index.js +4 -1
  28. package/dist/cjs/plugin-toggle/index.js +2 -0
  29. package/dist/cjs/popover/style.scss +5 -6
  30. package/dist/cjs/progress-bar/index.test.js +1 -2
  31. package/dist/cjs/progress-bar/style.scss +1 -2
  32. package/dist/cjs/proxied-imports/router.js +1 -2
  33. package/dist/cjs/radio-control/style.scss +4 -10
  34. package/dist/cjs/section-header/index.js +21 -1
  35. package/dist/cjs/select-control/ButtonGroupControl.js +2 -0
  36. package/dist/cjs/settings/SettingsCard.js +2 -6
  37. package/dist/cjs/sortable-newsletter-list-control/index.js +7 -5
  38. package/dist/cjs/sortable-newsletter-list-control/style.scss +11 -1
  39. package/dist/cjs/steps-list/style.scss +0 -3
  40. package/dist/cjs/steps-list-item/style.scss +1 -2
  41. package/dist/cjs/style-card/index.js +1 -0
  42. package/dist/cjs/style-card/style.scss +4 -5
  43. package/dist/cjs/style.scss +15 -0
  44. package/dist/cjs/tabbed-navigation/index.js +17 -7
  45. package/dist/cjs/tabbed-navigation/style.scss +2 -6
  46. package/dist/cjs/utils/color.js +35 -0
  47. package/dist/cjs/web-preview/style.scss +11 -11
  48. package/dist/cjs/with-wizard/index.js +80 -3
  49. package/dist/cjs/with-wizard/style.scss +34 -13
  50. package/dist/cjs/with-wizard-screen/index.js +3 -3
  51. package/dist/cjs/with-wizard-screen/style.scss +9 -9
  52. package/dist/cjs/wizard/index.js +38 -13
  53. package/dist/cjs/wizard/store/index.js +13 -5
  54. package/dist/cjs/wizard/store/utils.js +3 -1
  55. package/dist/esm/action-card/action-card.d.js +1 -0
  56. package/dist/esm/action-card/index.js +286 -189
  57. package/dist/esm/action-card/style.scss +142 -44
  58. package/dist/esm/autocomplete-tokenfield/index.js +6 -2
  59. package/dist/esm/box-contrast/index.js +44 -0
  60. package/dist/esm/button/index.js +1 -1
  61. package/dist/esm/button-props/button-props.js +34 -0
  62. package/dist/esm/button-props/index.js +1 -0
  63. package/dist/esm/color-picker/index.js +11 -0
  64. package/dist/esm/custom-select-control/style.scss +7 -12
  65. package/dist/esm/footer/index.js +18 -25
  66. package/dist/esm/footer/style.scss +0 -36
  67. package/dist/esm/handoff-message/index.js +0 -3
  68. package/dist/esm/hooks/useObjectState.js +10 -0
  69. package/dist/esm/hooks/useObjectState.test.js +6 -6
  70. package/dist/esm/index.js +1 -3
  71. package/dist/esm/modal/index.js +4 -1
  72. package/dist/esm/modal/style.scss +18 -7
  73. package/dist/esm/newspack-icon/index.js +2 -2
  74. package/dist/esm/newspack-icon/style.scss +3 -5
  75. package/dist/esm/notice/index.js +1 -2
  76. package/dist/esm/notice/style.scss +11 -9
  77. package/dist/esm/plugin-installer/index.js +3 -3
  78. package/dist/esm/plugin-settings/SettingsSection.js +2 -0
  79. package/dist/esm/plugin-settings/index.js +4 -1
  80. package/dist/esm/plugin-toggle/index.js +2 -0
  81. package/dist/esm/popover/style.scss +5 -6
  82. package/dist/esm/progress-bar/style.scss +1 -2
  83. package/dist/esm/radio-control/style.scss +4 -10
  84. package/dist/esm/section-header/index.js +22 -0
  85. package/dist/esm/select-control/ButtonGroupControl.js +2 -0
  86. package/dist/esm/settings/SettingsCard.js +2 -6
  87. package/dist/esm/sortable-newsletter-list-control/index.js +8 -6
  88. package/dist/esm/sortable-newsletter-list-control/style.scss +11 -1
  89. package/dist/esm/steps-list/style.scss +0 -3
  90. package/dist/esm/steps-list-item/style.scss +1 -2
  91. package/dist/esm/style-card/index.js +1 -0
  92. package/dist/esm/style-card/style.scss +4 -5
  93. package/dist/esm/style.scss +15 -0
  94. package/dist/esm/tabbed-navigation/index.js +17 -7
  95. package/dist/esm/tabbed-navigation/style.scss +2 -6
  96. package/dist/esm/utils/color.js +29 -0
  97. package/dist/esm/web-preview/style.scss +11 -11
  98. package/dist/esm/with-wizard/index.js +81 -4
  99. package/dist/esm/with-wizard/style.scss +34 -13
  100. package/dist/esm/with-wizard-screen/index.js +1 -1
  101. package/dist/esm/with-wizard-screen/style.scss +9 -9
  102. package/dist/esm/wizard/index.js +39 -13
  103. package/dist/esm/wizard/store/index.js +13 -5
  104. package/dist/esm/wizard/store/utils.js +3 -1
  105. package/package.json +1 -1
  106. package/src/accordion/index.js +1 -3
  107. package/src/action-card/action-card.d.ts +40 -0
  108. package/src/action-card/index.js +284 -202
  109. package/src/action-card/style.scss +142 -44
  110. package/src/autocomplete-tokenfield/index.js +3 -2
  111. package/src/autocomplete-with-suggestions/index.js +52 -63
  112. package/src/box-contrast/index.tsx +44 -0
  113. package/src/button/index.tsx +1 -1
  114. package/src/button-card/index.js +1 -12
  115. package/src/card/index.js +1 -11
  116. package/src/category-autocomplete/index.js +4 -19
  117. package/src/color-picker/index.js +11 -7
  118. package/src/custom-select-control/style.scss +7 -12
  119. package/src/footer/index.js +6 -18
  120. package/src/footer/style.scss +0 -36
  121. package/src/form-token-field/index.js +1 -2
  122. package/src/grid/index.tsx +1 -8
  123. package/src/handoff/index.js +4 -11
  124. package/src/handoff-message/index.js +0 -3
  125. package/src/hooks/useObjectState.js +10 -2
  126. package/src/hooks/useObjectState.test.js +14 -14
  127. package/src/image-upload/index.js +3 -23
  128. package/src/index.js +1 -3
  129. package/src/modal/index.js +2 -2
  130. package/src/modal/style.scss +18 -7
  131. package/src/newspack-icon/index.js +3 -14
  132. package/src/newspack-icon/style.scss +3 -5
  133. package/src/notice/index.js +0 -2
  134. package/src/notice/style.scss +11 -9
  135. package/src/plugin-installer/index.js +8 -17
  136. package/src/plugin-settings/SettingsSection.js +3 -7
  137. package/src/plugin-settings/index.js +7 -14
  138. package/src/plugin-toggle/README.md +3 -3
  139. package/src/plugin-toggle/index.js +10 -13
  140. package/src/popover/index.js +1 -5
  141. package/src/popover/style.scss +5 -6
  142. package/src/position-control/index.js +65 -75
  143. package/src/progress-bar/index.js +2 -9
  144. package/src/progress-bar/index.test.js +4 -13
  145. package/src/progress-bar/style.scss +1 -2
  146. package/src/radio-control/style.scss +4 -10
  147. package/src/section-header/index.js +20 -0
  148. package/src/select-control/ButtonGroupControl.js +2 -9
  149. package/src/select-control/GroupedSelectControl.js +1 -9
  150. package/src/select-control/index.js +1 -5
  151. package/src/settings/MinMaxSetting.js +2 -14
  152. package/src/settings/SettingsCard.js +2 -11
  153. package/src/sortable-newsletter-list-control/index.js +10 -26
  154. package/src/sortable-newsletter-list-control/style.scss +11 -1
  155. package/src/steps-list/style.scss +0 -3
  156. package/src/steps-list-item/index.js +1 -4
  157. package/src/steps-list-item/style.scss +1 -2
  158. package/src/style-card/index.js +6 -21
  159. package/src/style-card/style.scss +4 -5
  160. package/src/style.scss +15 -0
  161. package/src/tabbed-navigation/index.js +19 -7
  162. package/src/tabbed-navigation/style.scss +2 -6
  163. package/src/text-control/index.tsx +2 -12
  164. package/src/utils/color.ts +32 -0
  165. package/src/web-preview/style.scss +11 -11
  166. package/src/with-wizard/index.js +67 -16
  167. package/src/with-wizard/style.scss +34 -13
  168. package/src/with-wizard-screen/index.js +1 -1
  169. package/src/with-wizard-screen/style.scss +9 -9
  170. package/src/wizard/components/WizardError.js +2 -7
  171. package/src/wizard/index.js +64 -62
  172. package/src/wizard/store/index.js +8 -10
  173. package/src/wizard/store/utils.js +3 -4
  174. package/dist/cjs/date-range-picker/index.js +0 -39
  175. package/dist/cjs/date-range-picker/style.scss +0 -148
  176. package/dist/cjs/newspack-logo/index.js +0 -54
  177. package/dist/cjs/newspack-logo/style.scss +0 -30
  178. package/dist/cjs/patrons-logo/index.js +0 -77
  179. package/dist/esm/date-range-picker/index.js +0 -31
  180. package/dist/esm/date-range-picker/style.scss +0 -148
  181. package/dist/esm/newspack-logo/index.js +0 -46
  182. package/dist/esm/newspack-logo/style.scss +0 -30
  183. package/dist/esm/patrons-logo/index.js +0 -70
  184. package/shared/scss/_colors.scss +0 -27
  185. package/src/date-range-picker/index.js +0 -31
  186. package/src/date-range-picker/style.scss +0 -148
  187. package/src/newspack-logo/index.js +0 -45
  188. package/src/newspack-logo/style.scss +0 -30
  189. package/src/patrons-logo/index.js +0 -76
  190. /package/{shared/js → src/button-props}/button-props.js +0 -0
  191. /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: true,
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(action.payload.isQuietFetch)
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 = {}) => (0, _data.useSelect)(select => select(_.WIZARD_STORE_NAMESPACE).getWizardAPIData(`newspack-${wizardName}-wizard`)) || 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 { Component } from '@wordpress/element';
9
- import { ExternalLink, ToggleControl } from '@wordpress/components';
10
- import { Icon, check, chevronDown, chevronUp } from '@wordpress/icons';
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
- * When the collapse prop is updated to true, collapse the card if already expanded.
30
- */
31
- componentDidUpdate(prevProps) {
32
- if (!prevProps.collapse && this.props.collapse && this.state.expanded) {
33
- this.setState({
34
- expanded: false
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
- * Render.
41
- */
42
- render() {
43
- const {
44
- badge,
45
- className,
46
- checkbox,
47
- children,
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
- const hasInternalLink = href && href.indexOf('http') !== 0;
94
- const isDisplayingSecondaryAction = secondaryActionText && onSecondaryActionClick;
95
- const badges = !Array.isArray(badge) && badge ? [badge] : badge;
96
- return /*#__PURE__*/_jsxs(Card, {
97
- className: classes,
98
- onClick: simple && onClick,
99
- children: [/*#__PURE__*/_jsxs("div", {
100
- className: "newspack-action-card__region newspack-action-card__region-top",
101
- children: [toggleOnChange && /*#__PURE__*/_jsx(ToggleControl, {
102
- checked: toggleChecked,
103
- onChange: toggleOnChange,
104
- disabled: disabled
105
- }), image && !toggleOnChange && /*#__PURE__*/_jsx("div", {
106
- className: "newspack-action-card__region newspack-action-card__region-left",
107
- children: /*#__PURE__*/_jsx("a", {
108
- href: imageLink,
109
- children: /*#__PURE__*/_jsx("div", {
110
- className: "newspack-action-card__image",
111
- style: backgroundImageStyles(image)
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
- }), checkbox && !toggleOnChange && /*#__PURE__*/_jsx("div", {
115
- className: "newspack-action-card__region newspack-action-card__region-left",
116
- children: /*#__PURE__*/_jsx("span", {
117
- className: classnames('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked', isPending && 'newspack-checkbox-icon--pending'),
118
- children: 'checked' === checkbox && /*#__PURE__*/_jsx(Icon, {
119
- icon: check
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
- }), /*#__PURE__*/_jsx("div", {
123
- className: "newspack-action-card__region newspack-action-card__region-center",
124
- children: /*#__PURE__*/_jsxs(Grid, {
125
- columns: 1,
126
- gutter: 8,
127
- noMargin: true,
128
- children: [/*#__PURE__*/_jsxs("h2", {
129
- children: [/*#__PURE__*/_jsxs("span", {
130
- className: "newspack-action-card__title",
131
- ...titleProps,
132
- children: [titleLink && /*#__PURE__*/_jsx("a", {
133
- href: titleLink,
134
- children: title
135
- }), !titleLink && expandable && /*#__PURE__*/_jsx(Button, {
136
- isLink: true,
137
- onClick: () => this.setState({
138
- expanded: !expanded
139
- }),
140
- children: title
141
- }), !titleLink && !expandable && title]
142
- }), badges?.length && badges.map((badgeText, i) => /*#__PURE__*/_jsx("span", {
143
- className: "newspack-action-card__badge",
144
- children: badgeText
145
- }, `badge-${i}`))]
146
- }), description && /*#__PURE__*/_jsxs("p", {
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
- }), expandable && /*#__PURE__*/_jsx(Button, {
182
- onClick: () => this.setState({
183
- expanded: !expanded
184
- }),
185
- children: /*#__PURE__*/_jsx(Icon, {
186
- icon: expanded ? chevronUp : chevronDown,
187
- height: 24,
188
- width: 24
189
- })
190
- })]
191
- }), notification && /*#__PURE__*/_jsxs("div", {
192
- className: "newspack-action-card__notification newspack-action-card__region-children",
193
- children: ['error' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
194
- noticeText: notification,
195
- isError: true,
196
- rawHTML: notificationHTML
197
- }), 'info' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
198
- noticeText: notification,
199
- rawHTML: notificationHTML
200
- }), 'success' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
201
- noticeText: notification,
202
- isSuccess: true,
203
- rawHTML: notificationHTML
204
- }), 'warning' === notificationLevel && /*#__PURE__*/_jsx(Notice, {
205
- noticeText: notification,
206
- isWarning: true,
207
- rawHTML: notificationHTML
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
- }), children && (expandable && expanded || !expandable) && /*#__PURE__*/_jsx("div", {
210
- className: "newspack-action-card__region-children",
211
- children: 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
- ActionCard.defaultProps = {
217
- toggleChecked: false
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;