/** * Blog display controls, split by scope. * * The `blog` settings tree has two halves — `blog.archive` (how posts appear * on listings) and `blog.single` (what shows on an individual post). Each half * belongs to a different Post Types panel, so this renders just one scope at a * time and both content-type panels reuse it, replacing the old standalone * Blog section. * * Renders two cards per scope: the scope's own (Post Cards / Post Content) * and Post Meta, each a collapsible FieldGroup laid out as setting rows. * * Writes go to `blog..*`, read back by the Blog module via * `aureon_blog_settings` — unchanged from the previous Blog section. */ import { __ } from '@wordpress/i18n'; import { TextControl } from '@wordpress/components'; import { useId } from '@wordpress/element'; import { Image, List, WholeWord, Link, MousePointer2, Layers, Calendar, User, Folder, Tag, MessageSquare, Circle, SquareUser, ArrowLeftRight, Newspaper, } from 'lucide-react'; import type { LucideIcon } from 'lucide-react'; import FieldGroup from './field-group'; import InlineField from './inline-field'; import RangeField from './range-field'; import SegmentedControl from './segmented-control'; import SelectField from './select-field'; import SettingRow, { SettingToggle } from './setting-row'; import ToggleRow from './toggle-row'; import type { WorkingSettings, SetPath } from '../types'; interface Option { value: string; label: string; } interface MetaField { key: string; label: string; } export interface BlogSchema { label?: string; layouts?: Option[]; columns?: { min: number; max: number }; content_modes?: Option[]; read_more_styles?: Option[]; meta_fields?: MetaField[]; } interface BlogControlsProps { scope: 'archive' | 'single'; schema?: BlogSchema; working: WorkingSettings; setPath: SetPath; } // Keyed by the schema's meta field keys; a field the theme adds later without // an entry here still renders, just with the neutral fallback. const META_ICONS: Record< string, LucideIcon > = { date: Calendar, author: User, categories: Folder, tags: Tag, comments: MessageSquare, }; export default function BlogControls( { scope, schema, working, setPath, }: BlogControlsProps ) { const readMoreId = `aureon-readmore-${ useId() }`; if ( ! schema ) { return null; } const blog = ( working?.blog ?? {} ) as Record< string, any >; const values = ( blog[ scope ] ?? {} ) as Record< string, any >; const metaFields = schema.meta_fields ?? []; const metaCard = (
{ metaFields.map( ( field ) => ( setPath( `blog.${ scope }.meta.${ field.key }`, checked ) } /> ) ) }
); const featuredImage = ( setPath( `blog.${ scope }.show_featured_image`, checked ) } /> ); if ( 'archive' === scope ) { const columns = schema.columns ?? { min: 1, max: 4 }; const isGrid = 'grid' === ( values.layout ?? 'list' ); // A grid never renders full content (see content-loop.php), so the // control shows what the feed actually does rather than the stored // choice, which still applies once the layout goes back to List. const content = isGrid ? 'excerpt' : values.content ?? 'excerpt'; const readMore = values.read_more_text ?? ''; return ( <> setPath( 'blog.archive.layout', value ) } /> { isGrid && ( setPath( 'blog.archive.columns', value ) } /> ) }
{ featuredImage } setPath( 'blog.archive.content', value ) } /> { 'excerpt' === content && ( setPath( 'blog.archive.excerpt_length', value ) } /> ) } setPath( 'blog.archive.read_more_text', value ) } /> { '' !== readMore.trim() && ( setPath( 'blog.archive.read_more_style', value ) } /> ) }
{ metaCard } ); } return ( <>
{ featuredImage } setPath( 'blog.single.show_author_box', checked ) } /> setPath( 'blog.single.show_post_nav', checked ) } />
{ metaCard } ); }