/** * Loader — the single waiting state for the whole plugin. * * Every screen here is Operate-mode UI: the visitor came to finish a task, and * a centred spinner tells them nothing except that the page is not ready yet. * A skeleton tells them what is about to arrive and holds its space, so the * layout settles once instead of twice. * * `text` is no longer painted. It is announced — screen readers hear "Loading * campaigns…", sighted users get the shape of the campaigns. Every existing * `` call site therefore keeps working unchanged. * * Variants describe what is coming, not what it looks like: * cards a grid of records (default — lists, galleries, pickers) * table a ledger with a head row (subscribers, logs, history) * form labelled fields (settings panels, editors) * dashboard stat rail over charts (analytics, overviews) * calendar a month of day cells (content and social calendars) * lines bare text, no chrome (inside an existing panel) * * Card chrome is stripped by CSS when a Loader is rendered inside a card, so a * default-variant Loader never produces a card inside a card. */ import { __ } from '@wordpress/i18n'; // Deterministic, not random: a skeleton that reshuffles its own widths on every // re-render reads as content changing rather than content arriving. const CARD_LINES = [ { height: 14, width: '46%' }, { height: 16, width: '86%' }, { height: 12, width: '96%' }, { height: 12, width: '62%' }, ]; const ROW_WIDTHS = [ '72%', '90%', '55%', '80%', '64%' ]; const Bar = ( { height, width, className = '' } ) => ( ); const Loader = ( { text, variant = 'cards', count, className = '' } ) => { const items = count || ( variant === 'table' ? 5 : 3 ); let body; if ( variant === 'table' ) { body = (
{ ROW_WIDTHS.map( ( w, c ) => ) }
{ Array.from( { length: items } ).map( ( _, r ) => (
{ ROW_WIDTHS.map( ( w, c ) => ( // Shift the width pattern one column per row so the // column edges do not line up into a false grid. ) ) }
) ) }
); } else if ( variant === 'form' ) { body = (
{ Array.from( { length: items } ).map( ( _, i ) => (
) ) }
); } else if ( variant === 'dashboard' ) { // Analytics surfaces open with a stat rail over charts, never with a row // of paragraph cards. Reserving the wrong shape moves the page twice. body = ( <>
{ Array.from( { length: 4 } ).map( ( _, i ) => (
) ) }
{ Array.from( { length: count || 2 } ).map( ( _, i ) => (
) ) }
); } else if ( variant === 'calendar' ) { body = (
{ Array.from( { length: 7 } ).map( ( _, i ) => ( ) ) } { Array.from( { length: ( count || 5 ) * 7 } ).map( ( _, i ) => (
{ /* Only some days carry an entry — an evenly filled month would promise a full schedule that is not there. */ } { i % 4 === 1 && }
) ) }
); } else if ( variant === 'lines' ) { body = (
{ CARD_LINES.slice( 0, count || CARD_LINES.length ).map( ( line, i ) => ( ) ) }
); } else { body = (
{ Array.from( { length: items } ).map( ( _, i ) => (
{ CARD_LINES.map( ( line, l ) => ) }
) ) }
); } return (
{ text || __( 'Loading…', 'ai-marketing-expert' ) } { body }
); }; export default Loader;