|
2 | 2 | * WordPress dependencies |
3 | 3 | */ |
4 | 4 | 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'; |
6 | 7 | import { store as coreStore } from '@wordpress/core-data'; |
7 | 8 | import { useSelect, useDispatch, useRegistry } from '@wordpress/data'; |
8 | 9 | import { DataForm } from '@wordpress/dataviews'; |
@@ -411,6 +412,60 @@ function FeatureToggleWithSettings( { |
411 | 412 | ); |
412 | 413 | } |
413 | 414 |
|
| 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 | + |
414 | 469 | function AISettingsPage() { |
415 | 470 | const { editedRecord, isLoading } = useSelect( ( select ) => { |
416 | 471 | // 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