| 1 |
import { __ } from '@wordpress/i18n'; |
| 2 |
|
| 3 |
/** |
| 4 |
* Top navigation bar — styled after Fluent Forms' builder header. |
| 5 |
* |
| 6 |
* Layout (left → right): |
| 7 |
* Back | Name | [Editor] [Settings] | Shortcode Preview Publish Draft Fullscreen |
| 8 |
*/ |
| 9 |
export default function Toolbar( { |
| 10 |
meta, |
| 11 |
isDirty, |
| 12 |
isSaving, |
| 13 |
savingAs, |
| 14 |
activeTab, |
| 15 |
isFullscreen, |
| 16 |
templateChosen, |
| 17 |
onTabChange, |
| 18 |
onMetaChange, |
| 19 |
onOpenNameModal, |
| 20 |
onPreview, |
| 21 |
onSave, |
| 22 |
onFullscreen, |
| 23 |
onExit, |
| 24 |
campaignId, |
| 25 |
postStatus, |
| 26 |
viewUrl, |
| 27 |
} ) { |
| 28 |
return ( |
| 29 |
<div className="bp-cb-topnav"> |
| 30 |
|
| 31 |
{/* Left: Back + Name */} |
| 32 |
<div className="bp-cb-topnav__left"> |
| 33 |
<button className="bp-cb-topnav__back" onClick={ onExit } title={ __( 'Back to Campaigns', 'better-payment' ) }> |
| 34 |
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"> |
| 35 |
<path d="M10 12L6 8l4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/> |
| 36 |
</svg> |
| 37 |
</button> |
| 38 |
|
| 39 |
<button className="bp-cb-topnav__name" onClick={ onOpenNameModal } title={ __( 'Edit campaign name', 'better-payment' ) }> |
| 40 |
<svg width="13" height="13" viewBox="0 0 13 13" fill="none" style={ { flexShrink: 0 } }> |
| 41 |
<path d="M9.5 1.5l2 2-7 7H2.5v-2l7-7z" stroke="currentColor" strokeWidth="1.2" strokeLinecap="round" strokeLinejoin="round"/> |
| 42 |
</svg> |
| 43 |
{ meta.title |
| 44 |
? <span>{ meta.title }</span> |
| 45 |
: <span className="bp-cb-topnav__name-placeholder">{ __( 'Campaign Name', 'better-payment' ) }</span> |
| 46 |
} |
| 47 |
</button> |
| 48 |
</div> |
| 49 |
|
| 50 |
{/* Center: Tabs */} |
| 51 |
<div className="bp-cb-topnav__tabs"> |
| 52 |
<button |
| 53 |
className={ `bp-cb-tab-btn${ activeTab === 'templates' ? ' is-active' : '' }` } |
| 54 |
onClick={ () => onTabChange( 'templates' ) } |
| 55 |
> |
| 56 |
{ __( 'Templates', 'better-payment' ) } |
| 57 |
</button> |
| 58 |
<button |
| 59 |
className={ `bp-cb-tab-btn${ activeTab === 'editor' ? ' is-active' : '' }${ ! templateChosen ? ' is-disabled' : '' }` } |
| 60 |
onClick={ () => templateChosen && onTabChange( 'editor' ) } |
| 61 |
disabled={ ! templateChosen } |
| 62 |
title={ ! templateChosen ? __( 'Choose a template first', 'better-payment' ) : '' } |
| 63 |
> |
| 64 |
{ __( 'Editor', 'better-payment' ) } |
| 65 |
</button> |
| 66 |
<button |
| 67 |
className={ `bp-cb-tab-btn${ activeTab === 'settings' ? ' is-active' : '' }${ ! templateChosen ? ' is-disabled' : '' }` } |
| 68 |
onClick={ () => templateChosen && onTabChange( 'settings' ) } |
| 69 |
disabled={ ! templateChosen } |
| 70 |
title={ ! templateChosen ? __( 'Choose a template first', 'better-payment' ) : '' } |
| 71 |
> |
| 72 |
{ __( 'Settings', 'better-payment' ) } |
| 73 |
</button> |
| 74 |
</div> |
| 75 |
|
| 76 |
{/* Right: Actions */} |
| 77 |
<div className="bp-cb-topnav__right"> |
| 78 |
{ postStatus === 'publish' && viewUrl ? ( |
| 79 |
<a |
| 80 |
className="bp-cb-topnav__btn bp-cb-topnav__btn--outline" |
| 81 |
href={ viewUrl } |
| 82 |
target="_blank" |
| 83 |
rel="noreferrer" |
| 84 |
title={ __( 'View published campaign', 'better-payment' ) } |
| 85 |
> |
| 86 |
<svg width="14" height="14" viewBox="0 0 14 14" fill="none"> |
| 87 |
<path d="M6 2H2.5A1.5 1.5 0 001 3.5v8A1.5 1.5 0 002.5 13h8A1.5 1.5 0 0012 11.5V8" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round"/> |
| 88 |
<path d="M8 1h5v5M13 1L6.5 7.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round"/> |
| 89 |
</svg> |
| 90 |
{ __( 'View Live', 'better-payment' ) } |
| 91 |
</a> |
| 92 |
) : ( |
| 93 |
<button |
| 94 |
className="bp-cb-topnav__btn bp-cb-topnav__btn--outline bp-cb-topnav__btn--disabled" |
| 95 |
disabled |
| 96 |
title={ __( 'Publish the campaign to view it live', 'better-payment' ) } |
| 97 |
> |
| 98 |
<svg width="14" height="14" viewBox="0 0 14 14" fill="none"> |
| 99 |
<path d="M6 2H2.5A1.5 1.5 0 001 3.5v8A1.5 1.5 0 002.5 13h8A1.5 1.5 0 0012 11.5V8" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round"/> |
| 100 |
<path d="M8 1h5v5M13 1L6.5 7.5" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round" strokeLinejoin="round"/> |
| 101 |
</svg> |
| 102 |
{ __( 'View Live', 'better-payment' ) } |
| 103 |
</button> |
| 104 |
) } |
| 105 |
|
| 106 |
<button |
| 107 |
className={ `bp-cb-topnav__btn bp-cb-topnav__btn--outline${ ! templateChosen ? ' bp-cb-topnav__btn--disabled' : '' }` } |
| 108 |
onClick={ onPreview } |
| 109 |
disabled={ ! templateChosen } |
| 110 |
title={ ! templateChosen ? __( 'Choose a template first', 'better-payment' ) : '' } |
| 111 |
> |
| 112 |
<svg width="14" height="14" viewBox="0 0 14 14" fill="none"> |
| 113 |
<ellipse cx="7" cy="7" rx="6" ry="4" stroke="currentColor" strokeWidth="1.3"/> |
| 114 |
<circle cx="7" cy="7" r="1.5" fill="currentColor"/> |
| 115 |
</svg> |
| 116 |
{ __( 'Preview', 'better-payment' ) } |
| 117 |
</button> |
| 118 |
|
| 119 |
<button |
| 120 |
className={ `bp-cb-topnav__btn bp-cb-topnav__btn--primary${ ! templateChosen ? ' bp-cb-topnav__btn--disabled' : '' }` } |
| 121 |
onClick={ () => onSave( 'publish' ) } |
| 122 |
disabled={ isSaving || ! templateChosen } |
| 123 |
title={ ! templateChosen ? __( 'Choose a template first', 'better-payment' ) : '' } |
| 124 |
> |
| 125 |
{ savingAs === 'publish' ? ( |
| 126 |
__( 'Saving…', 'better-payment' ) |
| 127 |
) : ( |
| 128 |
<> |
| 129 |
<svg width="14" height="14" viewBox="0 0 14 14" fill="none"> |
| 130 |
<path d="M2.5 7l3 3 6-6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/> |
| 131 |
</svg> |
| 132 |
{ __( 'Publish', 'better-payment' ) } |
| 133 |
</> |
| 134 |
) } |
| 135 |
</button> |
| 136 |
|
| 137 |
<button |
| 138 |
className="bp-cb-topnav__btn bp-cb-topnav__btn--outline" |
| 139 |
onClick={ () => onSave( 'draft' ) } |
| 140 |
disabled={ isSaving } |
| 141 |
> |
| 142 |
{ savingAs === 'draft' ? __( 'Saving…', 'better-payment' ) : __( 'Draft', 'better-payment' ) } |
| 143 |
</button> |
| 144 |
|
| 145 |
<button |
| 146 |
className={ `bp-cb-topnav__icon-btn${ isFullscreen ? ' is-active' : '' }` } |
| 147 |
onClick={ onFullscreen } |
| 148 |
title={ isFullscreen ? __( 'Exit fullscreen', 'better-payment' ) : __( 'Fullscreen', 'better-payment' ) } |
| 149 |
> |
| 150 |
{ isFullscreen ? ( |
| 151 |
<svg width="15" height="15" viewBox="0 0 15 15" fill="none"> |
| 152 |
<path d="M10 5h3V2M5 10H2v3M10 10l3 3M5 5L2 2" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round"/> |
| 153 |
</svg> |
| 154 |
) : ( |
| 155 |
<svg width="15" height="15" viewBox="0 0 15 15" fill="none"> |
| 156 |
<path d="M10 2h3v3M2 10v3h3M10 13h3v-3M2 5V2h3" stroke="currentColor" strokeWidth="1.3" strokeLinecap="round"/> |
| 157 |
</svg> |
| 158 |
) } |
| 159 |
</button> |
| 160 |
</div> |
| 161 |
</div> |
| 162 |
); |
| 163 |
} |
| 164 |
|