| 1 |
import { __ } from "@wordpress/i18n"; |
| 2 |
import { InspectorControls, PanelColorSettings } from "@wordpress/block-editor"; |
| 3 |
import { |
| 4 |
PanelBody, |
| 5 |
SelectControl, |
| 6 |
ToggleControl, |
| 7 |
TextControl, |
| 8 |
TextareaControl, |
| 9 |
RangeControl, |
| 10 |
BaseControl, |
| 11 |
ButtonGroup, |
| 12 |
Button, |
| 13 |
TabPanel, |
| 14 |
} from "@wordpress/components"; |
| 15 |
|
| 16 |
import { |
| 17 |
BOX_PADDING, |
| 18 |
BOX_BORDER, |
| 19 |
DIGITS_PADDING, |
| 20 |
DIGITS_BORDER, |
| 21 |
UNITS, |
| 22 |
COUNTDOWN_TYPES, |
| 23 |
LAYOUT_OPTIONS, |
| 24 |
LABEL_VIEW_OPTIONS, |
| 25 |
SEPARATOR_OPTIONS, |
| 26 |
ALIGN_OPTIONS, |
| 27 |
EXPIRE_TYPES, |
| 28 |
} from "./constants"; |
| 29 |
import { |
| 30 |
DIGITS_TYPO, |
| 31 |
LABEL_TYPO, |
| 32 |
EXPIRE_TITLE_TYPO, |
| 33 |
EXPIRE_TEXT_TYPO, |
| 34 |
} from "./typographyConstants"; |
| 35 |
import objAttributes from "./attributes"; |
| 36 |
|
| 37 |
const { TypographyDropdown, ResponsiveDimensionsControl, BorderShadowControl } = |
| 38 |
window.EBControls; |
| 39 |
|
| 40 |
const UNIT_LABELS = { |
| 41 |
days: __("Days", "notificationx"), |
| 42 |
hours: __("Hours", "notificationx"), |
| 43 |
minutes: __("Minutes", "notificationx"), |
| 44 |
seconds: __("Seconds", "notificationx"), |
| 45 |
}; |
| 46 |
|
| 47 |
export default function Inspector({ attributes, setAttributes }) { |
| 48 |
const { |
| 49 |
resOption, |
| 50 |
countdownType, |
| 51 |
dueTime, |
| 52 |
evergreenHours, |
| 53 |
evergreenMinutes, |
| 54 |
evergreenRecurring, |
| 55 |
recurringRestartAfter, |
| 56 |
recurringStopTime, |
| 57 |
layout, |
| 58 |
labelView, |
| 59 |
alignment, |
| 60 |
showDays, |
| 61 |
daysLabel, |
| 62 |
showHours, |
| 63 |
hoursLabel, |
| 64 |
showMinutes, |
| 65 |
minutesLabel, |
| 66 |
showSeconds, |
| 67 |
secondsLabel, |
| 68 |
showSeparator, |
| 69 |
separatorStyle, |
| 70 |
separatorColor, |
| 71 |
expireType, |
| 72 |
expiryTitle, |
| 73 |
expiryText, |
| 74 |
redirectUrl, |
| 75 |
boxBgColor, |
| 76 |
boxBgGradient, |
| 77 |
boxSpacing, |
| 78 |
digitsColor, |
| 79 |
digitsBgColor, |
| 80 |
labelColor, |
| 81 |
expireAlignment, |
| 82 |
expireTitleColor, |
| 83 |
expireTextColor, |
| 84 |
} = attributes; |
| 85 |
|
| 86 |
const resRequiredProps = { setAttributes, resOption, attributes, objAttributes }; |
| 87 |
|
| 88 |
const AlignButtons = ({ value, onChange }) => ( |
| 89 |
<BaseControl> |
| 90 |
<ButtonGroup> |
| 91 |
{ALIGN_OPTIONS.map((item) => ( |
| 92 |
<Button |
| 93 |
key={item.value} |
| 94 |
isPrimary={value === item.value} |
| 95 |
isSecondary={value !== item.value} |
| 96 |
onClick={() => onChange(item.value)} |
| 97 |
> |
| 98 |
{item.label} |
| 99 |
</Button> |
| 100 |
))} |
| 101 |
</ButtonGroup> |
| 102 |
</BaseControl> |
| 103 |
); |
| 104 |
|
| 105 |
return ( |
| 106 |
<InspectorControls key="controls"> |
| 107 |
<div className="eb-panel-control"> |
| 108 |
<TabPanel |
| 109 |
className="eb-parent-tab-panel" |
| 110 |
activeClass="active-tab" |
| 111 |
tabs={[ |
| 112 |
{ name: "general", title: __("General", "notificationx"), className: "eb-tab general" }, |
| 113 |
{ name: "styles", title: __("Style", "notificationx"), className: "eb-tab styles" }, |
| 114 |
]} |
| 115 |
> |
| 116 |
{(tab) => |
| 117 |
tab.name === "general" ? ( |
| 118 |
<div className="eb-panel-control"> |
| 119 |
{/* ── Timer Settings ── */} |
| 120 |
<PanelBody title={__("Timer Settings", "notificationx")} initialOpen={true}> |
| 121 |
<SelectControl |
| 122 |
label={__("Type", "notificationx")} |
| 123 |
value={countdownType} |
| 124 |
options={COUNTDOWN_TYPES} |
| 125 |
onChange={(v) => setAttributes({ countdownType: v })} |
| 126 |
/> |
| 127 |
{countdownType === "due_date" && ( |
| 128 |
<TextControl |
| 129 |
label={__("Countdown Due Date", "notificationx")} |
| 130 |
type="datetime-local" |
| 131 |
value={dueTime} |
| 132 |
onChange={(v) => setAttributes({ dueTime: v })} |
| 133 |
/> |
| 134 |
)} |
| 135 |
{countdownType === "evergreen" && ( |
| 136 |
<> |
| 137 |
<TextControl |
| 138 |
label={__("Hours", "notificationx")} |
| 139 |
type="number" |
| 140 |
value={evergreenHours} |
| 141 |
onChange={(v) => setAttributes({ evergreenHours: parseInt(v || 0, 10) })} |
| 142 |
/> |
| 143 |
<TextControl |
| 144 |
label={__("Minutes", "notificationx")} |
| 145 |
type="number" |
| 146 |
value={evergreenMinutes} |
| 147 |
onChange={(v) => setAttributes({ evergreenMinutes: parseInt(v || 0, 10) })} |
| 148 |
/> |
| 149 |
<ToggleControl |
| 150 |
label={__("Recurring Countdown", "notificationx")} |
| 151 |
checked={!!evergreenRecurring} |
| 152 |
onChange={(v) => setAttributes({ evergreenRecurring: v })} |
| 153 |
/> |
| 154 |
{evergreenRecurring && ( |
| 155 |
<> |
| 156 |
<TextControl |
| 157 |
label={__("Restart After (Hours)", "notificationx")} |
| 158 |
type="number" |
| 159 |
help={__("0 = restart immediately.", "notificationx")} |
| 160 |
value={recurringRestartAfter} |
| 161 |
onChange={(v) => setAttributes({ recurringRestartAfter: parseInt(v || 0, 10) })} |
| 162 |
/> |
| 163 |
<TextControl |
| 164 |
label={__("Recurring End Date", "notificationx")} |
| 165 |
type="datetime-local" |
| 166 |
value={recurringStopTime} |
| 167 |
onChange={(v) => setAttributes({ recurringStopTime: v })} |
| 168 |
/> |
| 169 |
</> |
| 170 |
)} |
| 171 |
</> |
| 172 |
)} |
| 173 |
</PanelBody> |
| 174 |
|
| 175 |
{/* ── Content Settings ── */} |
| 176 |
<PanelBody title={__("Content Settings", "notificationx")} initialOpen={false}> |
| 177 |
<SelectControl |
| 178 |
label={__("View", "notificationx")} |
| 179 |
value={layout} |
| 180 |
options={LAYOUT_OPTIONS} |
| 181 |
onChange={(v) => setAttributes({ layout: v })} |
| 182 |
/> |
| 183 |
<SelectControl |
| 184 |
label={__("Label Position", "notificationx")} |
| 185 |
value={labelView} |
| 186 |
options={LABEL_VIEW_OPTIONS} |
| 187 |
onChange={(v) => setAttributes({ labelView: v })} |
| 188 |
/> |
| 189 |
<BaseControl label={__("Alignment", "notificationx")}> |
| 190 |
<AlignButtons value={alignment} onChange={(v) => setAttributes({ alignment: v })} /> |
| 191 |
</BaseControl> |
| 192 |
|
| 193 |
<ToggleControl |
| 194 |
label={__("Display Days", "notificationx")} |
| 195 |
checked={!!showDays} |
| 196 |
onChange={(v) => setAttributes({ showDays: v })} |
| 197 |
/> |
| 198 |
{showDays && ( |
| 199 |
<TextControl |
| 200 |
label={__("Days Label", "notificationx")} |
| 201 |
value={daysLabel} |
| 202 |
onChange={(v) => setAttributes({ daysLabel: v })} |
| 203 |
/> |
| 204 |
)} |
| 205 |
<ToggleControl |
| 206 |
label={__("Display Hours", "notificationx")} |
| 207 |
checked={!!showHours} |
| 208 |
onChange={(v) => setAttributes({ showHours: v })} |
| 209 |
/> |
| 210 |
{showHours && ( |
| 211 |
<TextControl |
| 212 |
label={__("Hours Label", "notificationx")} |
| 213 |
value={hoursLabel} |
| 214 |
onChange={(v) => setAttributes({ hoursLabel: v })} |
| 215 |
/> |
| 216 |
)} |
| 217 |
<ToggleControl |
| 218 |
label={__("Display Minutes", "notificationx")} |
| 219 |
checked={!!showMinutes} |
| 220 |
onChange={(v) => setAttributes({ showMinutes: v })} |
| 221 |
/> |
| 222 |
{showMinutes && ( |
| 223 |
<TextControl |
| 224 |
label={__("Minutes Label", "notificationx")} |
| 225 |
value={minutesLabel} |
| 226 |
onChange={(v) => setAttributes({ minutesLabel: v })} |
| 227 |
/> |
| 228 |
)} |
| 229 |
<ToggleControl |
| 230 |
label={__("Display Seconds", "notificationx")} |
| 231 |
checked={!!showSeconds} |
| 232 |
onChange={(v) => setAttributes({ showSeconds: v })} |
| 233 |
/> |
| 234 |
{showSeconds && ( |
| 235 |
<TextControl |
| 236 |
label={__("Seconds Label", "notificationx")} |
| 237 |
value={secondsLabel} |
| 238 |
onChange={(v) => setAttributes({ secondsLabel: v })} |
| 239 |
/> |
| 240 |
)} |
| 241 |
|
| 242 |
<ToggleControl |
| 243 |
label={__("Display Separator", "notificationx")} |
| 244 |
checked={!!showSeparator} |
| 245 |
onChange={(v) => setAttributes({ showSeparator: v })} |
| 246 |
/> |
| 247 |
{showSeparator && ( |
| 248 |
<SelectControl |
| 249 |
label={__("Separator Style", "notificationx")} |
| 250 |
value={separatorStyle} |
| 251 |
options={SEPARATOR_OPTIONS} |
| 252 |
onChange={(v) => setAttributes({ separatorStyle: v })} |
| 253 |
/> |
| 254 |
)} |
| 255 |
</PanelBody> |
| 256 |
|
| 257 |
{/* ── Expire Action ── */} |
| 258 |
<PanelBody title={__("Expire Action", "notificationx")} initialOpen={false}> |
| 259 |
<SelectControl |
| 260 |
label={__("On Expire", "notificationx")} |
| 261 |
value={expireType} |
| 262 |
options={EXPIRE_TYPES} |
| 263 |
onChange={(v) => setAttributes({ expireType: v })} |
| 264 |
/> |
| 265 |
{expireType === "text" && ( |
| 266 |
<> |
| 267 |
<TextareaControl |
| 268 |
label={__("Expiry Title", "notificationx")} |
| 269 |
value={expiryTitle} |
| 270 |
onChange={(v) => setAttributes({ expiryTitle: v })} |
| 271 |
/> |
| 272 |
<TextareaControl |
| 273 |
label={__("Expiry Content", "notificationx")} |
| 274 |
value={expiryText} |
| 275 |
onChange={(v) => setAttributes({ expiryText: v })} |
| 276 |
/> |
| 277 |
</> |
| 278 |
)} |
| 279 |
{expireType === "url" && ( |
| 280 |
<TextControl |
| 281 |
label={__("Redirect URL", "notificationx")} |
| 282 |
type="url" |
| 283 |
value={redirectUrl} |
| 284 |
onChange={(v) => setAttributes({ redirectUrl: v })} |
| 285 |
/> |
| 286 |
)} |
| 287 |
</PanelBody> |
| 288 |
</div> |
| 289 |
) : ( |
| 290 |
<div className="eb-panel-control"> |
| 291 |
{/* ── Countdown Box ── */} |
| 292 |
<PanelBody title={__("Countdown Box", "notificationx")} initialOpen={true}> |
| 293 |
<PanelColorSettings |
| 294 |
title={__("Background", "notificationx")} |
| 295 |
className="nx-color-control" |
| 296 |
initialOpen={false} |
| 297 |
colorSettings={[ |
| 298 |
{ |
| 299 |
value: boxBgColor, |
| 300 |
onChange: (v) => setAttributes({ boxBgColor: v }), |
| 301 |
label: __("Box Background Color", "notificationx"), |
| 302 |
}, |
| 303 |
]} |
| 304 |
/> |
| 305 |
<TextControl |
| 306 |
label={__("Background Gradient (CSS)", "notificationx")} |
| 307 |
help={__("Optional. e.g. linear-gradient(90deg, #f00, #00f). Overrides the background color.", "notificationx")} |
| 308 |
value={boxBgGradient} |
| 309 |
onChange={(v) => setAttributes({ boxBgGradient: v })} |
| 310 |
/> |
| 311 |
<RangeControl |
| 312 |
label={__("Space Between Boxes", "notificationx")} |
| 313 |
value={boxSpacing} |
| 314 |
onChange={(v) => setAttributes({ boxSpacing: v })} |
| 315 |
min={0} |
| 316 |
max={100} |
| 317 |
/> |
| 318 |
<ResponsiveDimensionsControl |
| 319 |
resRequiredProps={resRequiredProps} |
| 320 |
controlName={BOX_PADDING} |
| 321 |
baseLabel={__("Padding", "notificationx")} |
| 322 |
/> |
| 323 |
<PanelBody title={__("Border & Shadow", "notificationx")} initialOpen={false} className="nx-color-control"> |
| 324 |
<BorderShadowControl |
| 325 |
controlName={BOX_BORDER} |
| 326 |
resRequiredProps={resRequiredProps} |
| 327 |
noBdrHover |
| 328 |
noShdowHover |
| 329 |
/> |
| 330 |
</PanelBody> |
| 331 |
</PanelBody> |
| 332 |
|
| 333 |
{/* ── Color & Typography ── */} |
| 334 |
<PanelBody title={__("Color & Typography", "notificationx")} initialOpen={false}> |
| 335 |
<PanelColorSettings |
| 336 |
title={__("Digits", "notificationx")} |
| 337 |
className="nx-color-control" |
| 338 |
initialOpen={false} |
| 339 |
colorSettings={[ |
| 340 |
{ value: digitsColor, onChange: (v) => setAttributes({ digitsColor: v }), label: __("Digits Color", "notificationx") }, |
| 341 |
{ value: digitsBgColor, onChange: (v) => setAttributes({ digitsBgColor: v }), label: __("Background Color", "notificationx") }, |
| 342 |
]} |
| 343 |
/> |
| 344 |
<TypographyDropdown |
| 345 |
baseLabel={__("Digits Typography", "notificationx")} |
| 346 |
typographyPrefixConstant={DIGITS_TYPO} |
| 347 |
resRequiredProps={resRequiredProps} |
| 348 |
/> |
| 349 |
<ResponsiveDimensionsControl |
| 350 |
resRequiredProps={resRequiredProps} |
| 351 |
controlName={DIGITS_PADDING} |
| 352 |
baseLabel={__("Digits Padding", "notificationx")} |
| 353 |
/> |
| 354 |
<PanelBody title={__("Digits Border & Shadow", "notificationx")} initialOpen={false} className="nx-color-control"> |
| 355 |
<BorderShadowControl |
| 356 |
controlName={DIGITS_BORDER} |
| 357 |
resRequiredProps={resRequiredProps} |
| 358 |
noBdrHover |
| 359 |
noShdowHover |
| 360 |
/> |
| 361 |
</PanelBody> |
| 362 |
<PanelColorSettings |
| 363 |
title={__("Labels", "notificationx")} |
| 364 |
className="nx-color-control" |
| 365 |
initialOpen={false} |
| 366 |
colorSettings={[ |
| 367 |
{ value: labelColor, onChange: (v) => setAttributes({ labelColor: v }), label: __("Label Color", "notificationx") }, |
| 368 |
]} |
| 369 |
/> |
| 370 |
<TypographyDropdown |
| 371 |
baseLabel={__("Label Typography", "notificationx")} |
| 372 |
typographyPrefixConstant={LABEL_TYPO} |
| 373 |
resRequiredProps={resRequiredProps} |
| 374 |
/> |
| 375 |
{showSeparator && ( |
| 376 |
<PanelColorSettings |
| 377 |
title={__("Separator", "notificationx")} |
| 378 |
className="nx-color-control" |
| 379 |
initialOpen={false} |
| 380 |
colorSettings={[ |
| 381 |
{ value: separatorColor, onChange: (v) => setAttributes({ separatorColor: v }), label: __("Separator Color", "notificationx") }, |
| 382 |
]} |
| 383 |
/> |
| 384 |
)} |
| 385 |
</PanelBody> |
| 386 |
|
| 387 |
{/* ── Individual Box Styling ── */} |
| 388 |
<PanelBody title={__("Individual Box Styling", "notificationx")} initialOpen={false}> |
| 389 |
{UNITS.map((unit) => ( |
| 390 |
<PanelColorSettings |
| 391 |
key={unit} |
| 392 |
title={UNIT_LABELS[unit]} |
| 393 |
className="nx-color-control" |
| 394 |
initialOpen={false} |
| 395 |
colorSettings={[ |
| 396 |
{ value: attributes[`${unit}BgColor`], onChange: (v) => setAttributes({ [`${unit}BgColor`]: v }), label: __("Background Color", "notificationx") }, |
| 397 |
{ value: attributes[`${unit}DigitColor`], onChange: (v) => setAttributes({ [`${unit}DigitColor`]: v }), label: __("Digit Color", "notificationx") }, |
| 398 |
{ value: attributes[`${unit}LabelColor`], onChange: (v) => setAttributes({ [`${unit}LabelColor`]: v }), label: __("Label Color", "notificationx") }, |
| 399 |
{ value: attributes[`${unit}BorderColor`], onChange: (v) => setAttributes({ [`${unit}BorderColor`]: v }), label: __("Border Color", "notificationx") }, |
| 400 |
]} |
| 401 |
/> |
| 402 |
))} |
| 403 |
</PanelBody> |
| 404 |
|
| 405 |
{/* ── Expire Message ── */} |
| 406 |
{expireType === "text" && ( |
| 407 |
<PanelBody title={__("Expire Message", "notificationx")} initialOpen={false}> |
| 408 |
<BaseControl label={__("Alignment", "notificationx")}> |
| 409 |
<AlignButtons value={expireAlignment} onChange={(v) => setAttributes({ expireAlignment: v })} /> |
| 410 |
</BaseControl> |
| 411 |
<PanelColorSettings |
| 412 |
title={__("Colors", "notificationx")} |
| 413 |
className="nx-color-control" |
| 414 |
initialOpen={false} |
| 415 |
colorSettings={[ |
| 416 |
{ value: expireTitleColor, onChange: (v) => setAttributes({ expireTitleColor: v }), label: __("Title Color", "notificationx") }, |
| 417 |
{ value: expireTextColor, onChange: (v) => setAttributes({ expireTextColor: v }), label: __("Text Color", "notificationx") }, |
| 418 |
]} |
| 419 |
/> |
| 420 |
<TypographyDropdown |
| 421 |
baseLabel={__("Title Typography", "notificationx")} |
| 422 |
typographyPrefixConstant={EXPIRE_TITLE_TYPO} |
| 423 |
resRequiredProps={resRequiredProps} |
| 424 |
/> |
| 425 |
<TypographyDropdown |
| 426 |
baseLabel={__("Text Typography", "notificationx")} |
| 427 |
typographyPrefixConstant={EXPIRE_TEXT_TYPO} |
| 428 |
resRequiredProps={resRequiredProps} |
| 429 |
/> |
| 430 |
</PanelBody> |
| 431 |
)} |
| 432 |
</div> |
| 433 |
) |
| 434 |
} |
| 435 |
</TabPanel> |
| 436 |
</div> |
| 437 |
</InspectorControls> |
| 438 |
); |
| 439 |
} |
| 440 |
|