/** * The frame every Funnelforms admin page shares (plugin/src/Admin/Ui.php, assets/admin/admin.css): * a top bar with the brand, the page's name and its actions, then the page with its title and * one-line lead. The lists of forms and entries render it with the same markup and classes, so * they look like the pages the plugin prints; the parts below (key figures, badges, icons) do * the same. */ import React from 'react'; import type { ReactNode } from 'react'; import { __ } from './i18n'; /** Address of the overview, relative to wp-admin (every admin page sits there). */ const OVERVIEW = 'admin.php?page=funnelforms'; export function Frame( { title, lead, actions, children }: { title: string; lead?: string; actions?: ReactNode; children: ReactNode } ) { return (
Funnelforms

{ title }

{ lead ?

{ lead }

: null }
{ children }
); } /** Line icons (Lucide, ISC licence), the set of the plugin's pages and a few more. */ const PATHS = { search: '', filter: '', close: '', table: '', board: '', mail: '', phone: '', inbox: '', unread: '', calendar: '', trend: '', trophy: '', user: '', clock: '', down: '', left: '', right: '', archive: '', shield: '', trash: '', tag: '', check: '', download: '', upload: '', plus: '', stats: '', chart: '', copy: '', edit: '', form: '', file: '', eye: '', activity: '', external: '', undo: '', sparkles: '', } as const; export type IconName = keyof typeof PATHS; export function Icon( { name, size }: { name: IconName; size?: number } ) { return ( ); } /** A key figure as on the overview and the statistics: icon and label, value, a line below. */ export function Kpi( props: { icon: IconName; label: string; value: string | null; hint?: ReactNode; tone?: 'up' | 'down' | ''; pressed?: boolean; onClick?: () => void; title?: string } ) { const body = ( <> { props.label } { null === props.value ? : { props.value } } { props.hint ?? ' ' } ); return props.onClick ? ( ) : (
{ body }
); } export type PillTone = 'neutral' | 'success' | 'warning' | 'danger' | 'info'; /** A status as the plugin's pages show it (Ui::badge()). */ export function Pill( { tone = 'neutral', children }: { tone?: PillTone; children: ReactNode } ) { return { children }; } /** A link or button in the look of the plugin's pages (Ui::button()). */ export function FrameButton( { icon, variant = 'secondary', size, children, ...rest }: React.ButtonHTMLAttributes & { icon?: IconName; variant?: 'primary' | 'secondary' | 'ghost' | 'danger'; size?: 'sm' } ) { const className = 'ffx-btn' + ( 'secondary' === variant ? '' : ' ffx-btn--' + variant ) + ( size ? ' ffx-btn--' + size : '' ) + ( rest.className ? ' ' + rest.className : '' ); return ( ); } /** An empty state as on the overview: the brand mark with an icon, a heading, a line, an action. */ export function EmptyState( { icon, title, children, action }: { icon: IconName; title: string; children?: ReactNode; action?: ReactNode } ) { return (

{ title }

{ children ?

{ children }

: null } { action ?
{ action }
: null }
); } /** Entries per day as small bars (the forms table of the statistics page draws the same). */ export function Spark( { series, label }: { series: number[]; label: string } ) { const max = Math.max( 1, ...series ); const width = 4; const gap = 2; return ( { series.map( ( n, i ) => { const h = n > 0 ? Math.max( 2, Math.round( ( 22 * n ) / max ) ) : 2; return 0 ? undefined : 'is-zero' } />; } ) } ); }