newspack-components 4.2.0 → 4.3.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 (131) hide show
  1. package/dist/cjs/action-card/index.js +21 -12
  2. package/dist/cjs/action-card/style.scss +25 -2
  3. package/dist/cjs/autocomplete-tokenfield/index.js +2 -2
  4. package/dist/cjs/autocomplete-with-latest-posts/index.js +289 -0
  5. package/dist/cjs/autocomplete-with-latest-posts/style.scss +150 -0
  6. package/dist/cjs/badge/index.js +32 -0
  7. package/dist/cjs/badge/style.scss +36 -0
  8. package/dist/cjs/button/index.js +2 -0
  9. package/dist/cjs/card/core-card.js +141 -0
  10. package/dist/cjs/card/index.js +33 -0
  11. package/dist/cjs/card/style-core.scss +227 -0
  12. package/dist/cjs/card/style.scss +2 -2
  13. package/dist/cjs/card-settings-group/index.js +49 -0
  14. package/dist/cjs/card-settings-group/style.scss +33 -0
  15. package/dist/cjs/card-sortable-list/index.js +390 -0
  16. package/dist/cjs/card-sortable-list/style.scss +48 -0
  17. package/dist/cjs/confirm-dialog/index.js +59 -0
  18. package/dist/cjs/divider/index.js +42 -0
  19. package/dist/cjs/divider/style.scss +51 -0
  20. package/dist/cjs/form-token-field/style.scss +0 -5
  21. package/dist/cjs/grid/index.js +2 -1
  22. package/dist/cjs/grid/style.scss +63 -9
  23. package/dist/cjs/index.js +42 -0
  24. package/dist/cjs/modal/index.js +11 -4
  25. package/dist/cjs/modal/style.scss +43 -13
  26. package/dist/cjs/newspack-icon/style.scss +5 -3
  27. package/dist/cjs/section-header/index.js +76 -17
  28. package/dist/cjs/section-header/style.scss +109 -4
  29. package/dist/cjs/style.scss +2 -0
  30. package/dist/cjs/waiting/index.js +3 -1
  31. package/dist/cjs/waiting/style.scss +4 -0
  32. package/dist/cjs/web-preview/index.js +98 -39
  33. package/dist/cjs/web-preview/style.scss +20 -53
  34. package/dist/cjs/with-wizard/index.js +1 -1
  35. package/dist/cjs/with-wizard/style.scss +24 -6
  36. package/dist/cjs/with-wizard-screen/style.scss +39 -10
  37. package/dist/cjs/wizard/components/WizardSnackbar.js +70 -0
  38. package/dist/cjs/wizard/components/style.scss +48 -0
  39. package/dist/cjs/wizard/index.js +97 -16
  40. package/dist/cjs/wizard/store/index.js +46 -0
  41. package/dist/esm/action-card/index.js +21 -12
  42. package/dist/esm/action-card/style.scss +25 -2
  43. package/dist/esm/autocomplete-tokenfield/index.js +2 -2
  44. package/dist/esm/autocomplete-with-latest-posts/index.js +281 -0
  45. package/dist/esm/autocomplete-with-latest-posts/style.scss +150 -0
  46. package/dist/esm/badge/index.js +24 -0
  47. package/dist/esm/badge/style.scss +36 -0
  48. package/dist/esm/button/index.js +2 -0
  49. package/dist/esm/card/core-card.js +133 -0
  50. package/dist/esm/card/index.js +33 -0
  51. package/dist/esm/card/style-core.scss +227 -0
  52. package/dist/esm/card/style.scss +2 -2
  53. package/dist/esm/card-settings-group/index.js +42 -0
  54. package/dist/esm/card-settings-group/style.scss +33 -0
  55. package/dist/esm/card-sortable-list/index.js +381 -0
  56. package/dist/esm/card-sortable-list/style.scss +48 -0
  57. package/dist/esm/confirm-dialog/index.js +49 -0
  58. package/dist/esm/divider/index.js +34 -0
  59. package/dist/esm/divider/style.scss +51 -0
  60. package/dist/esm/form-token-field/style.scss +0 -5
  61. package/dist/esm/grid/index.js +2 -1
  62. package/dist/esm/grid/style.scss +63 -9
  63. package/dist/esm/index.js +6 -0
  64. package/dist/esm/modal/index.js +11 -4
  65. package/dist/esm/modal/style.scss +43 -13
  66. package/dist/esm/newspack-icon/style.scss +5 -3
  67. package/dist/esm/section-header/index.js +75 -18
  68. package/dist/esm/section-header/style.scss +109 -4
  69. package/dist/esm/style.scss +2 -0
  70. package/dist/esm/waiting/index.js +3 -1
  71. package/dist/esm/waiting/style.scss +4 -0
  72. package/dist/esm/web-preview/index.js +101 -42
  73. package/dist/esm/web-preview/style.scss +20 -53
  74. package/dist/esm/with-wizard/index.js +1 -1
  75. package/dist/esm/with-wizard/style.scss +24 -6
  76. package/dist/esm/with-wizard-screen/style.scss +39 -10
  77. package/dist/esm/wizard/components/WizardSnackbar.js +64 -0
  78. package/dist/esm/wizard/components/style.scss +48 -0
  79. package/dist/esm/wizard/index.js +101 -20
  80. package/dist/esm/wizard/store/index.js +46 -0
  81. package/package.json +5 -6
  82. package/shared/author-context.js +26 -0
  83. package/shared/hooks/use-coauthors.js +220 -0
  84. package/shared/hooks/use-coauthors.test.js +624 -0
  85. package/shared/hooks/use-custom-byline.js +47 -0
  86. package/shared/hooks/use-custom-byline.test.js +133 -0
  87. package/shared/scss/_mixins.scss +46 -0
  88. package/src/action-card/action-card.d.ts +7 -3
  89. package/src/action-card/index.js +24 -11
  90. package/src/action-card/style.scss +25 -2
  91. package/src/autocomplete-tokenfield/index.js +2 -2
  92. package/src/autocomplete-with-latest-posts/index.js +290 -0
  93. package/src/autocomplete-with-latest-posts/style.scss +150 -0
  94. package/src/badge/index.tsx +24 -0
  95. package/src/badge/style.scss +36 -0
  96. package/src/button/index.tsx +3 -2
  97. package/src/card/core-card.js +147 -0
  98. package/src/card/index.js +39 -1
  99. package/src/card/style-core.scss +227 -0
  100. package/src/card/style.scss +2 -2
  101. package/src/card-settings-group/README.md +43 -0
  102. package/src/card-settings-group/index.tsx +53 -0
  103. package/src/card-settings-group/style.scss +33 -0
  104. package/src/card-sortable-list/README.md +51 -0
  105. package/src/card-sortable-list/index.tsx +412 -0
  106. package/src/card-sortable-list/style.scss +48 -0
  107. package/src/confirm-dialog/index.tsx +64 -0
  108. package/src/divider/README.md +25 -0
  109. package/src/divider/index.js +31 -0
  110. package/src/divider/style.scss +51 -0
  111. package/src/form-token-field/style.scss +0 -5
  112. package/src/grid/index.tsx +2 -1
  113. package/src/grid/style.scss +63 -9
  114. package/src/index.js +6 -0
  115. package/src/modal/index.js +12 -3
  116. package/src/modal/style.scss +43 -13
  117. package/src/newspack-icon/style.scss +5 -3
  118. package/src/section-header/index.js +72 -13
  119. package/src/section-header/style.scss +109 -4
  120. package/src/style.scss +2 -0
  121. package/src/waiting/index.js +2 -1
  122. package/src/waiting/style.scss +4 -0
  123. package/src/web-preview/index.js +90 -35
  124. package/src/web-preview/style.scss +20 -53
  125. package/src/with-wizard/index.js +1 -1
  126. package/src/with-wizard/style.scss +24 -6
  127. package/src/with-wizard-screen/style.scss +39 -10
  128. package/src/wizard/components/WizardSnackbar.js +58 -0
  129. package/src/wizard/components/style.scss +48 -0
  130. package/src/wizard/index.js +108 -14
  131. package/src/wizard/store/index.js +26 -0
@@ -0,0 +1,48 @@
1
+ $collapse-duration: 200ms;
2
+ $shift-duration: 150ms;
3
+ $drop-duration: 400ms; /* must match DROP_ANIMATION_DURATION in index.tsx */
4
+
5
+ .newspack-card--core--sortable-list {
6
+ &__item {
7
+ cursor: grab;
8
+
9
+ /*
10
+ * Animate items sliding to fill/make space around the dragged item.
11
+ */
12
+ transition: transform $shift-duration ease;
13
+
14
+ /*
15
+ * Collapse the source item's content — the wrapper stays in layout as the
16
+ * anchor point, and the container height is locked via inline style in JS.
17
+ */
18
+ &.is-source {
19
+ cursor: grabbing;
20
+ opacity: 0;
21
+ transition: opacity $collapse-duration ease;
22
+ }
23
+
24
+ /*
25
+ * Drop landing animation: brief fade-in and scale on the newly placed item.
26
+ */
27
+ &.is-dropped {
28
+ animation: newspack-sortable-drop $drop-duration ease forwards;
29
+ opacity: 0;
30
+ }
31
+
32
+ }
33
+ }
34
+
35
+ @keyframes newspack-sortable-drop {
36
+ 0% {
37
+ opacity: 0;
38
+ transform: scale(0.98);
39
+ }
40
+ 60% {
41
+ opacity: 1;
42
+ transform: scale(1.01);
43
+ }
44
+ 100% {
45
+ opacity: 1;
46
+ transform: scale(1);
47
+ }
48
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Modal
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies.
7
+ */
8
+ import { forwardRef } from '@wordpress/element';
9
+ import { __experimentalConfirmDialog as BaseComponent } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
10
+
11
+ /**
12
+ * External dependencies.
13
+ */
14
+ import classnames from 'classnames';
15
+
16
+ /*
17
+ * See both https://wordpress.github.io/gutenberg/?path=/docs/components-confirmdialog--docs and
18
+ * https://wordpress.github.io/gutenberg/?path=/docs/components-modal--docs for all supported props.
19
+ */
20
+ import { jsx as _jsx } from "react/jsx-runtime";
21
+ const sizeClassMap = {
22
+ small: 'newspack-modal--size-small',
23
+ medium: 'newspack-modal--size-medium',
24
+ large: 'newspack-modal--size-large',
25
+ 'x-large': 'newspack-modal--size-x-large',
26
+ full: 'newspack-modal--size-full'
27
+ };
28
+ function ConfirmDialog({
29
+ className,
30
+ size = 'small',
31
+ hideTitle,
32
+ isDestructive,
33
+ onConfirm,
34
+ onCancel,
35
+ ...otherProps
36
+ }, ref) {
37
+ const classes = classnames('newspack-modal', sizeClassMap[size], hideTitle && 'newspack-modal--hide-title',
38
+ // Note: also hides the X close button.
39
+ isDestructive && 'newspack-modal--destructive', className);
40
+ return /*#__PURE__*/_jsx(BaseComponent, {
41
+ className: classes,
42
+ ...otherProps,
43
+ ref: ref,
44
+ onConfirm: onConfirm,
45
+ onCancel: onCancel,
46
+ __experimentalHideHeader: false
47
+ });
48
+ }
49
+ export default forwardRef(ConfirmDialog);
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Divider
3
+ */
4
+
5
+ /**
6
+ * Internal dependencies
7
+ */
8
+ import './style.scss';
9
+
10
+ /**
11
+ * External dependencies
12
+ */
13
+ import classNames from 'classnames';
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ const Divider = ({
16
+ alignment = 'none',
17
+ className = undefined,
18
+ marginBottom = 64,
19
+ marginTop = 64,
20
+ variant = 'default',
21
+ ...otherProps
22
+ }) => {
23
+ const classes = classNames('newspack-divider', className, alignment && `newspack-divider--alignment-${alignment}`, variant && `newspack-divider--variant-${variant}`);
24
+ const style = {
25
+ '--divider-margin-bottom': typeof marginBottom === 'number' ? `${marginBottom}px` : marginBottom,
26
+ '--divider-margin-top': typeof marginTop === 'number' ? `${marginTop}px` : marginTop
27
+ };
28
+ return /*#__PURE__*/_jsx("hr", {
29
+ className: classes,
30
+ style: style,
31
+ ...otherProps
32
+ });
33
+ };
34
+ export default Divider;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Divider
3
+ */
4
+
5
+ @use "~@wordpress/base-styles/colors" as wp-colors;
6
+
7
+ .newspack-divider {
8
+ background: transparent;
9
+ border: 0;
10
+ display: block;
11
+ height: 1px;
12
+ margin-bottom: min(32px, var(--divider-margin-bottom, 64px));
13
+ margin-left: 0;
14
+ margin-right: 0;
15
+ margin-top: min(32px, var(--divider-margin-top, 64px));
16
+ padding: 0;
17
+
18
+ @media screen and (min-width: 783px) {
19
+ margin-bottom: var(--divider-margin-bottom, 64px);
20
+ margin-top: var(--divider-margin-top, 64px);
21
+ }
22
+
23
+ // Alignment
24
+
25
+ &--alignment-full-width {
26
+ margin-left: calc(-50vw + 50%);
27
+ width: 100vw;
28
+ }
29
+
30
+ &--alignment-none {
31
+ width: 100%;
32
+ }
33
+
34
+ // Variant
35
+
36
+ &--variant-default {
37
+ background-color: wp-colors.$gray-300;
38
+ }
39
+
40
+ &--variant-primary {
41
+ background-color: var(--wp-admin-theme-color);
42
+ }
43
+
44
+ &--variant-secondary {
45
+ background-color: wp-colors.$gray-900;
46
+ }
47
+
48
+ &--variant-tertiary {
49
+ background-color: wp-colors.$gray-100;
50
+ }
51
+ }
@@ -7,11 +7,6 @@
7
7
  .newspack-form-token-field {
8
8
  width: 100%;
9
9
 
10
- .components-form-token-field__input-container {
11
- padding-bottom: 1px;
12
- padding-top: 1px;
13
- }
14
-
15
10
  // Help
16
11
 
17
12
  &__help {
@@ -14,13 +14,14 @@ import classnames from 'classnames';
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
15
  const Grid = ({
16
16
  className = '',
17
+ borders = false,
17
18
  columns = 2,
18
19
  gutter = 32,
19
20
  noMargin = false,
20
21
  rowGap = 0,
21
22
  ...otherProps
22
23
  }) => {
23
- const classes = classnames('newspack-grid', noMargin && 'newspack-grid--no-margin', columns && 'newspack-grid__columns-' + columns, gutter && 'newspack-grid__gutter-' + gutter, rowGap && 'newspack-grid__row-gap-' + rowGap, className);
24
+ const classes = classnames('newspack-grid', borders && 'newspack-grid__borders', noMargin && 'newspack-grid--no-margin', columns && 'newspack-grid__columns-' + columns, gutter && 'newspack-grid__gutter-' + gutter, rowGap && 'newspack-grid__row-gap-' + rowGap, className);
24
25
  return /*#__PURE__*/_jsx("div", {
25
26
  className: classes,
26
27
  ...otherProps
@@ -13,7 +13,7 @@
13
13
 
14
14
  // No Margin
15
15
  &--no-margin {
16
- margin: 0;
16
+ margin: 0 !important;
17
17
  }
18
18
 
19
19
  // Gutter 0
@@ -41,6 +41,11 @@
41
41
  grid-gap: 32px;
42
42
  }
43
43
 
44
+ // Gutter 64
45
+ &__gutter-64 {
46
+ grid-gap: 64px;
47
+ }
48
+
44
49
  // Row Gap 0
45
50
  &__row-gap-0 {
46
51
  grid-row-gap: 0;
@@ -61,11 +66,6 @@
61
66
  grid-row-gap: 32px;
62
67
  }
63
68
 
64
- // Gutter 64
65
- &__gutter-64 {
66
- grid-gap: 64px;
67
- }
68
-
69
69
  // Columns 6
70
70
  &__columns-6 {
71
71
  grid-template-columns: repeat(2, 1fr);
@@ -77,6 +77,14 @@
77
77
  &__columns-3,
78
78
  &__columns-4 {
79
79
  grid-template-columns: repeat(2, 1fr);
80
+
81
+ > [start] {
82
+ grid-column-start: 1;
83
+ }
84
+
85
+ > [end] {
86
+ grid-column-end: -1;
87
+ }
80
88
  }
81
89
 
82
90
  &__columns-6 {
@@ -84,8 +92,8 @@
84
92
  }
85
93
  }
86
94
 
87
- // Media Queries - 1128px
88
- @media screen and ( min-width: 1128px ) {
95
+ // Media Queries - 1054px
96
+ @media screen and ( min-width: 1054px ) {
89
97
  // Columns 3
90
98
  &__columns-3 {
91
99
  grid-template-columns: repeat(3, 1fr);
@@ -94,6 +102,14 @@
94
102
  // Columns 4
95
103
  &__columns-4 {
96
104
  grid-template-columns: repeat(4, 1fr);
105
+
106
+ > [start="2"] {
107
+ grid-column-start: 2;
108
+ }
109
+
110
+ > [end="4"] {
111
+ grid-column-end: 4;
112
+ }
97
113
  }
98
114
 
99
115
  // Columns 6
@@ -116,6 +132,44 @@
116
132
  > * {
117
133
  margin-bottom: 0 !important;
118
134
  margin-top: 0 !important;
135
+ > h1:first-child,
136
+ > h2:first-child,
137
+ > h3:first-child,
138
+ > h4:first-child,
139
+ > h5:first-child,
140
+ > h6:first-child {
141
+ margin-top: 0;
142
+ }
143
+ }
144
+
145
+ // Borders
146
+ &__borders {
147
+ grid-gap: 0 !important;
148
+ > * {
149
+ border-bottom: 1px solid wp-colors.$gray-300;
150
+ &:last-child {
151
+ border-bottom: none;
152
+ }
153
+ @media screen and ( min-width: 744px ) {
154
+ border-bottom: none;
155
+ border-right: 1px solid wp-colors.$gray-300;
156
+ &:last-child {
157
+ border-right: none;
158
+ }
159
+ }
160
+ }
161
+ &.newspack-grid__gutter-8 > * {
162
+ padding: 8px;
163
+ }
164
+ &.newspack-grid__gutter-16 > * {
165
+ padding: 16px;
166
+ }
167
+ &.newspack-grid__gutter-32 > * {
168
+ padding: 32px;
169
+ }
170
+ &.newspack-grid__gutter-64 > * {
171
+ padding: 64px;
172
+ }
119
173
  }
120
174
 
121
175
  .components-base-control {
@@ -163,4 +217,4 @@
163
217
  &__tbody + &__tbody {
164
218
  margin-top: -32px;
165
219
  }
166
- }
220
+ }
package/dist/esm/index.js CHANGED
@@ -2,13 +2,19 @@ export { default as Accordion } from './accordion';
2
2
  export { default as ActionCard } from './action-card';
3
3
  export { default as AutocompleteTokenField } from './autocomplete-tokenfield';
4
4
  export { default as AutocompleteWithSuggestions } from './autocomplete-with-suggestions';
5
+ export { default as AutocompleteWithLatestPosts } from './autocomplete-with-latest-posts';
6
+ export { default as Badge } from './badge';
5
7
  export { default as Button } from './button';
6
8
  export { default as ButtonCard } from './button-card';
7
9
  export { default as BoxContrast } from './box-contrast';
8
10
  export { default as Card } from './card';
11
+ export { default as CardSettingsGroup } from './card-settings-group';
12
+ export { default as CardSortableList } from './card-sortable-list';
9
13
  export { default as CategoryAutocomplete } from './category-autocomplete';
10
14
  export { default as ColorPicker } from './color-picker';
15
+ export { default as ConfirmDialog } from './confirm-dialog';
11
16
  export { default as CustomSelectControl } from './custom-select-control';
17
+ export { default as Divider } from './divider';
12
18
  export { default as FormTokenField } from './form-token-field';
13
19
  export { default as Footer } from './footer';
14
20
  export { default as Handoff } from './handoff';
@@ -18,16 +18,23 @@ import './style.scss';
18
18
  */
19
19
  import classnames from 'classnames';
20
20
  import { jsx as _jsx } from "react/jsx-runtime";
21
+ const sizeClassMap = {
22
+ small: 'newspack-modal--size-small',
23
+ medium: 'newspack-modal--size-medium',
24
+ large: 'newspack-modal--size-large',
25
+ 'x-large': 'newspack-modal--size-x-large',
26
+ full: 'newspack-modal--size-full'
27
+ };
28
+ const getSizeClassName = size => sizeClassMap[size] || sizeClassMap.medium;
21
29
  function Modal({
22
30
  className,
23
- isWide,
24
- isNarrow,
31
+ size = 'medium',
25
32
  hideTitle,
26
33
  ...otherProps
27
34
  }, ref) {
28
- const classes = classnames('newspack-modal', isWide && 'newspack-modal--wide', isNarrow && 'newspack-modal--narrow', hideTitle && 'newspack-modal--hide-title',
35
+ const classes = classnames('newspack-modal', hideTitle && 'newspack-modal--hide-title',
29
36
  // Note: also hides the X close button.
30
- className);
37
+ getSizeClassName(size), className);
31
38
  return /*#__PURE__*/_jsx(BaseComponent, {
32
39
  className: classes,
33
40
  ...otherProps,
@@ -12,20 +12,37 @@
12
12
  --wp-admin-theme-color-darker-10--rgb: #{colors.$primary-700--rgb};
13
13
  --wp-admin-theme-color-darker-20: #{colors.$primary-800};
14
14
  --wp-admin-theme-color-darker-20--rgb: #{colors.$primary-800--rgb};
15
+ --wp-admin-theme-color-lighter-10: #{colors.$primary-000};
16
+ --wp-admin-theme-color-lighter-10--rgb: #{colors.$primary-000--rgb};
15
17
 
16
- @media screen and ( min-width: 744px ) {
17
- max-width: 680px;
18
- width: 680px;
18
+ border-radius: 8px;
19
+ margin: auto;
20
+ max-height: calc(100% - 64px);
21
+ max-width: 512px;
22
+ width: calc(100% - 64px);
19
23
 
20
- &--wide {
21
- max-width: 1168px;
22
- width: 1168px;
24
+ &--size-small {
25
+ max-width: 384px;
26
+
27
+ &.newspack-modal--hide-title {
28
+ max-width: 350px;
23
29
  }
24
30
  }
25
31
 
26
- &--narrow {
27
- max-width: 360px;
28
- width: 360px;
32
+ &--size-medium {
33
+ max-width: 512px;
34
+ }
35
+
36
+ &--size-large {
37
+ max-width: 840px;
38
+ }
39
+
40
+ &--size-x-large {
41
+ max-width: calc(var(--newspack-wizard-section-width) + 64px)
42
+ }
43
+
44
+ &--size-full {
45
+ max-width: 100%;
29
46
  }
30
47
 
31
48
  &--hide-title {
@@ -39,8 +56,15 @@
39
56
  }
40
57
  }
41
58
 
42
- @media screen and ( min-width: 960px ) {
43
- max-height: calc(100% - 128px);
59
+ &--destructive {
60
+ .components-button.is-primary {
61
+ background-color: colors.$error-500;
62
+ color: colors.$neutral-000;
63
+ &:hover,
64
+ &:focus {
65
+ background-color: colors.$error-600;
66
+ }
67
+ }
44
68
  }
45
69
 
46
70
  // Links
@@ -60,8 +84,14 @@
60
84
  }
61
85
 
62
86
  .components-modal__content {
63
- > *:last-child {
64
- margin-bottom: 0;
87
+ > * {
88
+ &:first-child {
89
+ margin-top: 0;
90
+ }
91
+
92
+ &:last-child {
93
+ margin-bottom: 0;
94
+ }
65
95
  }
66
96
  }
67
97
  }
@@ -1,20 +1,22 @@
1
+ @use '../../../colors/colors.module.scss' as colors;
2
+
1
3
  /**
2
4
  * Newspack Icon
3
5
  */
4
6
 
5
7
  .newspack-icon {
6
- background: var(--wp-admin-theme-color);
8
+ background: colors.$primary-600;
7
9
  fill: white;
8
10
  padding: 12px;
9
11
 
10
12
  &--white {
11
13
  background: white;
12
- fill: var(--wp-admin-theme-color);
14
+ fill: colors.$primary-600;
13
15
  }
14
16
 
15
17
  &--simple {
16
18
  background: none;
17
- fill: var(--wp-admin-theme-color);
19
+ fill: colors.$primary-600;
18
20
  padding: 0;
19
21
  }
20
22
 
@@ -5,12 +5,15 @@
5
5
  /**
6
6
  * WordPress dependencies
7
7
  */
8
+ import { __ } from '@wordpress/i18n';
8
9
  import { useEffect, useRef } from '@wordpress/element';
10
+ import { Tooltip } from '@wordpress/components'; // eslint-disable-line @wordpress/no-unsafe-wp-apis
11
+ import { Icon, chevronLeft } from '@wordpress/icons';
9
12
 
10
13
  /**
11
14
  * Internal dependencies
12
15
  */
13
- import { Grid } from '..';
16
+ import { Badge, Button, Grid } from '..';
14
17
  import './style.scss';
15
18
 
16
19
  /**
@@ -22,14 +25,20 @@ import classnames from 'classnames';
22
25
  * Represents a section header component.
23
26
  *
24
27
  * @typedef {Object} SectionHeaderProps
25
- * @property {boolean} [centered=false] - Indicates if the header is centered.
26
- * @property {?string} [className=null] - Additional CSS class name.
27
- * @property {string|Function|*} [description] - Description of the section.
28
- * @property {number} [heading=2] - HTML heading level, e.g., 1 for h1, 2 for h2, etc.
29
- * @property {boolean} [isWhite=false] - Indicates if the header should use a white theme.
30
- * @property {boolean} [noMargin=false] - Indicates if the header should have no margin.
31
- * @property {string} title - The title of the section.
32
- * @property {?string} [id=null] - Optional ID for the header element.
28
+ * @property {string} [backNav=''] - URL to navigate back to.
29
+ * @property {string|string[]} [badge] - Badge to display in the header.
30
+ * @property {string} [badgeLevel] - Badge level, e.g., 'success', 'info', 'warning', 'error'.
31
+ * @property {boolean} [centered=false] - Indicates if the header is centered.
32
+ * @property {?string} [className=null] - Additional CSS class name.
33
+ * @property {string|Function|*} [description] - Description of the section.
34
+ * @property {number} [heading=2] - HTML heading level, e.g., 1 for h1, 2 for h2, etc.
35
+ * @property {string|Function|*} [icon] - Icon to display in the header.
36
+ * @property {boolean} [isWhite=false] - Indicates if the header should use a white theme.
37
+ * @property {boolean} [noMargin=false] - Indicates if the header should have no margin.
38
+ * @property {boolean} [pageHeader=false] - Indicates if the header is used as a page header.
39
+ * @property {string} title - The title of the section.
40
+ * @property {?string} [id=null] - Optional ID for the header element.
41
+ * @property {?string|Function|*} [children=null] - Optional children to display in the header.
33
42
  */
34
43
 
35
44
  /**
@@ -39,14 +48,21 @@ import classnames from 'classnames';
39
48
  */
40
49
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
41
50
  const SectionHeader = ({
51
+ backNav = '',
52
+ badges,
42
53
  centered = false,
43
54
  className = null,
44
55
  description = '',
45
56
  heading = 2,
57
+ icon = null,
46
58
  isWhite = false,
47
59
  noMargin = false,
60
+ pageHeader = false,
48
61
  title,
49
- id = null
62
+ id = null,
63
+ primaryAction,
64
+ secondaryAction,
65
+ children = null
50
66
  }) => {
51
67
  // If id is in the URL as a scrollTo param, scroll to it on render.
52
68
  const ref = useRef();
@@ -62,18 +78,48 @@ const SectionHeader = ({
62
78
  }), 250);
63
79
  }
64
80
  }, []);
65
- const classes = classnames('newspack-section-header', centered && 'newspack-section-header--is-centered', isWhite && 'newspack-section-header--is-white', noMargin && 'newspack-section-header--no-margin', className);
66
- const HeadingTag = `h${heading}`;
67
- return /*#__PURE__*/_jsx("div", {
81
+ const classes = classnames('newspack-section-header', centered && 'newspack-section-header--is-centered', isWhite && 'newspack-section-header--is-white', noMargin && 'newspack-section-header--no-margin', pageHeader && 'newspack-section-header--page-header');
82
+ const HeadingTag = pageHeader ? 'h1' : `h${heading}`;
83
+ return /*#__PURE__*/_jsxs("div", {
68
84
  id: id,
69
- className: "newspack-section-header__container",
85
+ className: classnames('newspack-section-header__container', backNav && 'newspack-section-header--has-back-nav', primaryAction && 'newspack-section-header--has-primary-action', className),
70
86
  ref: ref,
71
- children: /*#__PURE__*/_jsxs(Grid, {
87
+ children: [/*#__PURE__*/_jsxs(Grid, {
72
88
  columns: 1,
73
89
  gutter: 8,
74
90
  className: classes,
75
- children: [typeof title === 'string' && /*#__PURE__*/_jsx(HeadingTag, {
76
- children: title
91
+ children: [icon && /*#__PURE__*/_jsx("div", {
92
+ className: "newspack-section-header__icon",
93
+ children: /*#__PURE__*/_jsx(Icon, {
94
+ icon: icon,
95
+ size: 48
96
+ })
97
+ }), backNav && /*#__PURE__*/_jsx("div", {
98
+ className: "newspack-section-header__back-nav",
99
+ children: /*#__PURE__*/_jsx(Tooltip, {
100
+ text: __('Go back', 'newspack-plugin'),
101
+ children: /*#__PURE__*/_jsx(Button, {
102
+ href: backNav,
103
+ icon: chevronLeft,
104
+ variant: "tertiary"
105
+ })
106
+ })
107
+ }), typeof title === 'string' && /*#__PURE__*/_jsxs("div", {
108
+ className: "newspack-section-header__title-container",
109
+ children: [/*#__PURE__*/_jsx(HeadingTag, {
110
+ children: title
111
+ }), badges?.length ? badges.map((badge, i) => /*#__PURE__*/_jsx(Badge, {
112
+ text: badge.label,
113
+ level: badge.level || 'default'
114
+ }, i)) : null, secondaryAction && /*#__PURE__*/_jsx("div", {
115
+ className: "newspack-section-header__secondary-action",
116
+ children: /*#__PURE__*/_jsx(Button, {
117
+ variant: "link",
118
+ href: secondaryAction.href,
119
+ onClick: secondaryAction.action,
120
+ children: secondaryAction.label
121
+ })
122
+ })]
77
123
  }), typeof title === 'function' && /*#__PURE__*/_jsx(HeadingTag, {
78
124
  children: title()
79
125
  }), description && typeof description === 'string' && /*#__PURE__*/_jsx("p", {
@@ -82,8 +128,19 @@ const SectionHeader = ({
82
128
  children: description()
83
129
  }), description && typeof description !== 'string' && typeof description !== 'function' && /*#__PURE__*/_jsx("p", {
84
130
  children: description
131
+ }), children && /*#__PURE__*/_jsx("div", {
132
+ className: "newspack-section-header__children",
133
+ children: children
85
134
  })]
86
- })
135
+ }), primaryAction && /*#__PURE__*/_jsx("div", {
136
+ className: "newspack-section-header__primary-action",
137
+ children: /*#__PURE__*/_jsx(Button, {
138
+ href: primaryAction.href,
139
+ variant: "primary",
140
+ onClick: primaryAction.action,
141
+ children: primaryAction.label
142
+ })
143
+ })]
87
144
  });
88
145
  };
89
146
  export default SectionHeader;