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