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
@@ -5,10 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
- var _element = require("@wordpress/element");
9
8
  var _components = require("@wordpress/components");
9
+ var _element = require("@wordpress/element");
10
+ var _i18n = require("@wordpress/i18n");
10
11
  var _icons = require("@wordpress/icons");
11
12
  var _ = require("../");
13
+ var _actionCardD = require("./action-card.d.ts");
12
14
  require("./style.scss");
13
15
  var _classnames = _interopRequireDefault(require("classnames"));
14
16
  var _jsxRuntime = require("react/jsx-runtime");
@@ -28,200 +30,293 @@ var _jsxRuntime = require("react/jsx-runtime");
28
30
  * External dependencies
29
31
  */
30
32
 
31
- class ActionCard extends _element.Component {
32
- state = {
33
- expanded: false
34
- };
35
-
36
- /**
37
- * When the collapse prop is updated to true, collapse the card if already expanded.
38
- */
39
- componentDidUpdate(prevProps) {
40
- if (!prevProps.collapse && this.props.collapse && this.state.expanded) {
41
- this.setState({
42
- expanded: false
43
- });
33
+ /**
34
+ * ActionCard component
35
+ * @param {ActionCardProps} props Component props.
36
+ * @return {JSX.Element} ActionCard component.
37
+ */const ActionCard = ({
38
+ badge,
39
+ badgeLevel = 'info',
40
+ className,
41
+ checkbox,
42
+ children,
43
+ collapse,
44
+ disabled,
45
+ title,
46
+ description,
47
+ handoff,
48
+ editLink,
49
+ href,
50
+ notification,
51
+ notificationLevel,
52
+ notificationHTML,
53
+ actionContent,
54
+ actionText,
55
+ secondaryActionText,
56
+ secondaryDestructive,
57
+ id,
58
+ image,
59
+ imageLink,
60
+ indent,
61
+ isSmall,
62
+ isMedium,
63
+ simple,
64
+ onClick,
65
+ onSecondaryActionClick,
66
+ isWaiting,
67
+ titleLink,
68
+ toggleChecked = false,
69
+ toggleOnChange,
70
+ hasGreyHeader,
71
+ hasWhiteHeader,
72
+ noBorder,
73
+ isPending,
74
+ expandable = false,
75
+ isButtonEnabled = false,
76
+ // Draggable props. All are required to enable drag sorting.
77
+ draggable = false,
78
+ dragIndex,
79
+ dragWrapperRef,
80
+ onDragCallback
81
+ }) => {
82
+ const [expanded, setExpanded] = (0, _element.useState)(false);
83
+ const [dragging, setDragging] = (0, _element.useState)(false);
84
+ const [targetIndex, setTargetIndex] = (0, _element.useState)(null);
85
+ const [dragRef, setDragRef] = (0, _element.useState)(null);
86
+ (0, _element.useEffect)(() => {
87
+ if (dragWrapperRef && !dragRef) {
88
+ setDragRef(dragWrapperRef);
44
89
  }
45
- }
46
-
47
- /**
48
- * Render.
49
- */
50
- render() {
51
- const {
52
- badge,
53
- className,
54
- checkbox,
55
- children,
56
- disabled,
57
- title,
58
- description,
59
- handoff,
60
- editLink,
61
- href,
62
- notification,
63
- notificationLevel,
64
- notificationHTML,
65
- actionContent,
66
- actionText,
67
- secondaryActionText,
68
- secondaryDestructive,
69
- image,
70
- imageLink,
71
- indent,
72
- isSmall,
73
- isMedium,
74
- simple,
75
- onClick,
76
- onSecondaryActionClick,
77
- isWaiting,
78
- titleLink,
79
- toggleChecked,
80
- toggleOnChange,
81
- hasGreyHeader,
82
- hasWhiteHeader,
83
- isPending,
84
- expandable = false,
85
- isButtonEnabled = false
86
- } = this.props;
87
- const {
88
- expanded
89
- } = this.state;
90
- const hasChildren = notification || children;
91
- const classes = (0, _classnames.default)('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);
92
- const backgroundImageStyles = url => {
93
- return url ? {
94
- backgroundImage: `url(${url})`
95
- } : {};
96
- };
97
- const titleProps = toggleOnChange && !titleLink && !disabled ? {
98
- onClick: () => toggleOnChange(!toggleChecked),
99
- tabIndex: '0'
90
+ }, [dragWrapperRef?.current]);
91
+ (0, _element.useEffect)(() => {
92
+ if (collapse && expanded) {
93
+ setExpanded(false);
94
+ }
95
+ }, [collapse]);
96
+ const hasChildren = notification || children;
97
+ const classes = (0, _classnames.default)('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);
98
+ const backgroundImageStyles = url => {
99
+ return url ? {
100
+ backgroundImage: `url(${url})`
100
101
  } : {};
101
- const hasInternalLink = href && href.indexOf('http') !== 0;
102
- const isDisplayingSecondaryAction = secondaryActionText && onSecondaryActionClick;
103
- const badges = !Array.isArray(badge) && badge ? [badge] : badge;
104
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Card, {
105
- className: classes,
106
- onClick: simple && onClick,
107
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
108
- className: "newspack-action-card__region newspack-action-card__region-top",
109
- children: [toggleOnChange && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, {
110
- checked: toggleChecked,
111
- onChange: toggleOnChange,
112
- disabled: disabled
113
- }), image && !toggleOnChange && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
114
- className: "newspack-action-card__region newspack-action-card__region-left",
115
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
116
- href: imageLink,
117
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
118
- className: "newspack-action-card__image",
119
- style: backgroundImageStyles(image)
120
- })
121
- })
122
- }), checkbox && !toggleOnChange && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
123
- className: "newspack-action-card__region newspack-action-card__region-left",
124
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
125
- className: (0, _classnames.default)('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked', isPending && 'newspack-checkbox-icon--pending'),
126
- children: 'checked' === checkbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
127
- icon: _icons.check
128
- })
102
+ };
103
+ const titleProps = toggleOnChange && !titleLink && !disabled ? {
104
+ onClick: () => toggleOnChange(!toggleChecked),
105
+ tabIndex: '0'
106
+ } : {};
107
+ const hasInternalLink = href && href.indexOf('http') !== 0;
108
+ const isDisplayingSecondaryAction = secondaryActionText && onSecondaryActionClick;
109
+ const badges = !Array.isArray(badge) && badge ? [badge] : badge;
110
+ const Component = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
111
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
112
+ className: "newspack-action-card__region newspack-action-card__region-top",
113
+ children: [toggleOnChange && /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ToggleControl, {
114
+ checked: toggleChecked,
115
+ onChange: toggleOnChange,
116
+ disabled: disabled
117
+ }), image && !toggleOnChange && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
118
+ className: "newspack-action-card__region newspack-action-card__region-left",
119
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
120
+ href: imageLink,
121
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
122
+ className: "newspack-action-card__image",
123
+ style: backgroundImageStyles(image)
129
124
  })
130
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
131
- className: "newspack-action-card__region newspack-action-card__region-center",
132
- children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Grid, {
133
- columns: 1,
134
- gutter: 8,
135
- noMargin: true,
136
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h2", {
137
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
138
- className: "newspack-action-card__title",
139
- ...titleProps,
140
- children: [titleLink && /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
141
- href: titleLink,
142
- children: title
143
- }), !titleLink && expandable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
144
- isLink: true,
145
- onClick: () => this.setState({
146
- expanded: !expanded
147
- }),
148
- children: title
149
- }), !titleLink && !expandable && title]
150
- }), badges?.length && badges.map((badgeText, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
151
- className: "newspack-action-card__badge",
152
- children: badgeText
153
- }, `badge-${i}`))]
154
- }), description && /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
155
- children: [typeof description === 'string' && description, typeof description === 'function' && description()]
156
- })]
125
+ })
126
+ }), checkbox && !toggleOnChange && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
127
+ className: "newspack-action-card__region newspack-action-card__region-left",
128
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
129
+ className: (0, _classnames.default)('newspack-checkbox-icon', 'is-primary', 'checked' === checkbox && 'newspack-checkbox-icon--checked', isPending && 'newspack-checkbox-icon--pending'),
130
+ children: 'checked' === checkbox && /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
131
+ icon: _icons.check
157
132
  })
158
- }), !expandable && (actionText || isDisplayingSecondaryAction || actionContent) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
159
- className: "newspack-action-card__region newspack-action-card__region-right",
160
- children: [actionContent && actionContent, actionText && (handoff ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Handoff, {
161
- plugin: handoff,
162
- editLink: editLink,
163
- compact: true,
164
- isLink: true,
165
- children: actionText
166
- }) : onClick || hasInternalLink ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
167
- disabled: disabled && !isButtonEnabled,
168
- isLink: true,
169
- href: href,
170
- onClick: onClick,
171
- className: "newspack-action-card__primary_button",
172
- children: actionText
173
- }) : href ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ExternalLink, {
174
- href: href,
175
- className: "newspack-action-card__primary_button",
176
- children: actionText
177
- }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
178
- className: "newspack-action-card__container",
179
- children: [actionText, isWaiting && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Waiting, {
180
- isRight: true
181
- })]
182
- })), isDisplayingSecondaryAction && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
183
- isLink: true,
184
- onClick: onSecondaryActionClick,
185
- className: "newspack-action-card__secondary_button",
186
- isDestructive: secondaryDestructive,
187
- children: secondaryActionText
133
+ })
134
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
135
+ className: "newspack-action-card__region newspack-action-card__region-center",
136
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Grid, {
137
+ columns: 1,
138
+ gutter: 8,
139
+ noMargin: true,
140
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("h2", {
141
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
142
+ className: "newspack-action-card__title",
143
+ ...titleProps,
144
+ children: [titleLink && /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
145
+ href: titleLink,
146
+ children: title
147
+ }), !titleLink && expandable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
148
+ isLink: true,
149
+ onClick: () => setExpanded(!expanded),
150
+ children: title
151
+ }), !titleLink && !expandable && title]
152
+ }), badges?.length && badges.map((badgeText, i) => /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
153
+ className: `newspack-action-card__badge newspack-action-card__badge-level-${badgeLevel}`,
154
+ children: badgeText
155
+ }, `badge-${i}`))]
156
+ }), description && /*#__PURE__*/(0, _jsxRuntime.jsxs)("p", {
157
+ children: [typeof description === 'string' && description, typeof description === 'function' && description()]
188
158
  })]
189
- }), expandable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
190
- onClick: () => this.setState({
191
- expanded: !expanded
192
- }),
193
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
194
- icon: expanded ? _icons.chevronUp : _icons.chevronDown,
195
- height: 24,
196
- width: 24
197
- })
198
- })]
199
- }), notification && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
200
- className: "newspack-action-card__notification newspack-action-card__region-children",
201
- children: ['error' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
202
- noticeText: notification,
203
- isError: true,
204
- rawHTML: notificationHTML
205
- }), 'info' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
206
- noticeText: notification,
207
- rawHTML: notificationHTML
208
- }), 'success' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
209
- noticeText: notification,
210
- isSuccess: true,
211
- rawHTML: notificationHTML
212
- }), 'warning' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
213
- noticeText: notification,
214
- isWarning: true,
215
- rawHTML: notificationHTML
159
+ })
160
+ }), !expandable && (actionText || isDisplayingSecondaryAction || actionContent) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
161
+ className: "newspack-action-card__region newspack-action-card__region-right",
162
+ children: [actionContent && actionContent, actionText && (handoff ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Handoff, {
163
+ plugin: handoff,
164
+ editLink: editLink,
165
+ compact: true,
166
+ isLink: true,
167
+ children: actionText
168
+ }) : onClick || hasInternalLink ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
169
+ disabled: disabled && !isButtonEnabled,
170
+ isLink: true,
171
+ href: href,
172
+ onClick: onClick,
173
+ className: "newspack-action-card__primary_button",
174
+ children: actionText
175
+ }) : href ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.ExternalLink, {
176
+ href: href,
177
+ className: "newspack-action-card__primary_button",
178
+ children: actionText
179
+ }) : /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
180
+ className: "newspack-action-card__container",
181
+ children: [actionText, isWaiting && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Waiting, {
182
+ isRight: true
183
+ })]
184
+ })), isDisplayingSecondaryAction && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
185
+ isLink: true,
186
+ onClick: onSecondaryActionClick,
187
+ className: "newspack-action-card__secondary_button",
188
+ isDestructive: secondaryDestructive,
189
+ children: secondaryActionText
216
190
  })]
217
- }), children && (expandable && expanded || !expandable) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
218
- className: "newspack-action-card__region-children",
219
- children: children
191
+ }), expandable && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
192
+ onClick: () => setExpanded(!expanded),
193
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
194
+ icon: expanded ? _icons.chevronUp : _icons.chevronDown,
195
+ height: 24,
196
+ width: 24
197
+ })
198
+ })]
199
+ }), notification && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
200
+ className: "newspack-action-card__notification newspack-action-card__region-children",
201
+ children: ['error' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
202
+ noticeText: notification,
203
+ isError: true,
204
+ rawHTML: notificationHTML
205
+ }), 'info' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
206
+ noticeText: notification,
207
+ rawHTML: notificationHTML
208
+ }), 'success' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
209
+ noticeText: notification,
210
+ isSuccess: true,
211
+ rawHTML: notificationHTML
212
+ }), 'warning' === notificationLevel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Notice, {
213
+ noticeText: notification,
214
+ isWarning: true,
215
+ rawHTML: notificationHTML
220
216
  })]
217
+ }), children && (expandable && expanded || !expandable) && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
218
+ className: "newspack-action-card__region-children",
219
+ children: children
220
+ })]
221
+ });
222
+ if (draggable && dragRef?.current && typeof dragIndex === 'number' && onDragCallback && id) {
223
+ let wrapperRect = dragRef.current.getBoundingClientRect();
224
+ let draggableCards = Array.prototype.slice.call(dragRef.current.querySelectorAll('.newspack-action-card__draggable-wrapper'));
225
+ const isFirstTarget = dragIndex === 0;
226
+ const isLastTarget = dragIndex === draggableCards.length - 1;
227
+ const handleDragStart = () => {
228
+ draggableCards = Array.prototype.slice.call(dragRef.current.querySelectorAll('.newspack-action-card__draggable-wrapper'));
229
+ wrapperRect = dragRef.current.getBoundingClientRect();
230
+ if (dragging) {
231
+ return;
232
+ }
233
+ setTargetIndex(dragIndex);
234
+ setDragging(true);
235
+ };
236
+ const handleDragEnd = () => {
237
+ if (targetIndex !== null && targetIndex !== dragIndex) {
238
+ onDragCallback(targetIndex);
239
+ }
240
+ setTargetIndex(null);
241
+ setDragging(false);
242
+ };
243
+ const handleDragOver = e => {
244
+ const isDraggingToTop = e.pageY <= wrapperRect.top + window.scrollY;
245
+ const isDraggingToBottom = e.pageY >= wrapperRect.bottom + window.scrollY;
246
+ const target = e.target.closest('.newspack-action-card__draggable-wrapper');
247
+ if (isDraggingToTop || isDraggingToBottom || target) {
248
+ setTargetIndex(draggableCards.indexOf(target));
249
+
250
+ // If dragging the element over itself or over an invalid target, cancel the drop.
251
+ if (0 > targetIndex || targetIndex === dragIndex + 1) {
252
+ setTargetIndex(dragIndex);
253
+ }
254
+
255
+ // Handle dropping before the first item.
256
+ if (isDraggingToTop) {
257
+ setTargetIndex(0);
258
+ }
259
+
260
+ // Handle dropping after the last item.
261
+ if (isDraggingToBottom) {
262
+ setTargetIndex(draggableCards.length);
263
+ }
264
+ }
265
+ };
266
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
267
+ className: 'newspack-action-card__draggable-wrapper' + (dragging ? ' is-dragging' : ''),
268
+ id: `draggable-card-${id}`,
269
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Draggable, {
270
+ elementId: `draggable-card-${id}`,
271
+ transferData: {},
272
+ onDragStart: handleDragStart,
273
+ onDragEnd: handleDragEnd,
274
+ onDragOver: handleDragOver,
275
+ children: ({
276
+ onDraggableStart,
277
+ onDraggableEnd
278
+ }) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_.Card, {
279
+ className: classes,
280
+ onClick: simple && onClick,
281
+ id: id !== null && id !== void 0 ? id : null,
282
+ noBorder: noBorder,
283
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
284
+ className: "newspack-action-card__draggable-controls",
285
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
286
+ className: "drag-handle",
287
+ draggable: true,
288
+ onDragStart: onDraggableStart,
289
+ onDragEnd: onDraggableEnd,
290
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_icons.Icon, {
291
+ icon: _icons.dragHandle,
292
+ height: 18,
293
+ width: 18
294
+ })
295
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
296
+ className: "movers",
297
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
298
+ icon: _icons.chevronUp,
299
+ onClick: () => onDragCallback(dragIndex - 1),
300
+ disabled: isFirstTarget,
301
+ label: (0, _i18n.__)('Move one position up', 'newspack-plugin')
302
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Button, {
303
+ icon: _icons.chevronDown,
304
+ onClick: () => onDragCallback(dragIndex + 1),
305
+ disabled: isLastTarget,
306
+ label: (0, _i18n.__)('Move one position down', 'newspack-plugin')
307
+ })]
308
+ })]
309
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})]
310
+ })
311
+ })
221
312
  });
222
313
  }
223
- }
224
- ActionCard.defaultProps = {
225
- toggleChecked: false
314
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_.Card, {
315
+ className: classes,
316
+ onClick: simple && onClick,
317
+ id: id !== null && id !== void 0 ? id : null,
318
+ noBorder: noBorder,
319
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {})
320
+ });
226
321
  };
227
322
  var _default = exports.default = ActionCard;