Skip to content

Commit d29ad3e

Browse files
Add VisualCardToggle component for showcase experiments
Create a custom DataForm Edit component that renders visual-card experiments as cards with image, title, description, enable/disable button, and a green enabled-state badge. The component reads the global AI toggle from the data to handle the disabled state.
1 parent 9926bcf commit d29ad3e

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

routes/ai-home/stage.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* WordPress dependencies
33
*/
44
import { Page } from '@wordpress/admin-ui';
5-
import { Button, Notice, Spinner, ToggleControl } from '@wordpress/components';
5+
import { Button, Icon, Notice, Spinner, ToggleControl } from '@wordpress/components';
6+
import { check } from '@wordpress/icons';
67
import { store as coreStore } from '@wordpress/core-data';
78
import { useSelect, useDispatch, useRegistry } from '@wordpress/data';
89
import { DataForm } from '@wordpress/dataviews';
@@ -411,6 +412,60 @@ function FeatureToggleWithSettings( {
411412
);
412413
}
413414

415+
const VISUAL_CARD_FEATURES = new Map(
416+
PAGE_DATA.features
417+
.filter( ( f ) => f.presentation === 'visual-card' )
418+
.map( ( f ) => [ f.settingName, f ] as const )
419+
);
420+
421+
const VISUAL_CARD_SETTING_NAMES = new Set( VISUAL_CARD_FEATURES.keys() );
422+
423+
function VisualCardToggle( {
424+
field,
425+
data,
426+
onChange,
427+
}: DataFormControlProps< AISettings > ) {
428+
const feature = VISUAL_CARD_FEATURES.get( field.id );
429+
const globalEnabled = !! data[ GLOBAL_FIELD_ID ];
430+
const checked = !! field.getValue( { item: data } );
431+
432+
return (
433+
<div className={ `ai-showcase-card${ ! globalEnabled ? ' ai-showcase-card--disabled' : '' }` }>
434+
{ feature?.image && (
435+
<div className="ai-showcase-card__image">
436+
<img src={ feature.image } alt="" loading="lazy" />
437+
</div>
438+
) }
439+
<div className="ai-showcase-card__content">
440+
<h3 className="ai-showcase-card__title">
441+
{ field.label }
442+
</h3>
443+
<p className="ai-showcase-card__description">
444+
{ field.description }
445+
</p>
446+
<div className="ai-showcase-card__actions">
447+
<Button
448+
variant={ checked ? 'secondary' : 'primary' }
449+
onClick={ () => onChange( { [ field.id ]: ! checked } ) }
450+
disabled={ ! globalEnabled }
451+
size="compact"
452+
>
453+
{ checked
454+
? __( 'Disable', 'ai' )
455+
: __( 'Enable', 'ai' ) }
456+
</Button>
457+
{ checked && (
458+
<span className="ai-showcase-card__enabled-badge">
459+
<Icon icon={ check } size={ 16 } />
460+
{ __( 'Enabled', 'ai' ) }
461+
</span>
462+
) }
463+
</div>
464+
</div>
465+
</div>
466+
);
467+
}
468+
414469
function AISettingsPage() {
415470
const { editedRecord, isLoading } = useSelect( ( select ) => {
416471
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- core-data store selectors aren't fully typed for 'root'/'site' entity args.

0 commit comments

Comments
 (0)