From 70bb016ff225dd20e46d9fa79ed388d01b387dbc Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Mon, 16 Dec 2024 17:55:18 +0100 Subject: [PATCH] CreateTemplatePartModalContents: use native radio inputs (#67702) * Refactor to vanilla radio inputs, rewrite styles * Remove unnecessary classname * Apply instance ID to all ids and radio names * Use darker shade of gray for description --- Co-authored-by: ciampo Co-authored-by: mirka <0mirka00@git.wordpress.org> Co-authored-by: jameskoster Co-authored-by: jsnajdr Co-authored-by: tyxla --- .../create-template-part-modal/index.tsx | 106 ++++++++------ .../create-template-part-modal/style.scss | 133 +++++++++++------- 2 files changed, 140 insertions(+), 99 deletions(-) diff --git a/packages/fields/src/components/create-template-part-modal/index.tsx b/packages/fields/src/components/create-template-part-modal/index.tsx index 4043a7824fac4..8728f2681a493 100644 --- a/packages/fields/src/components/create-template-part-modal/index.tsx +++ b/packages/fields/src/components/create-template-part-modal/index.tsx @@ -5,13 +5,8 @@ import { Icon, BaseControl, TextControl, - Flex, - FlexItem, - FlexBlock, Button, Modal, - __experimentalRadioGroup as RadioGroup, - __experimentalRadio as Radio, __experimentalHStack as HStack, __experimentalVStack as VStack, } from '@wordpress/components'; @@ -40,6 +35,13 @@ import { useExistingTemplateParts, } from './utils'; +function getAreaRadioId( value: string, instanceId: number ) { + return `fields-create-template-part-modal__area-option-${ value }-${ instanceId }`; +} +function getAreaRadioDescriptionId( value: string, instanceId: number ) { + return `fields-create-template-part-modal__area-option-description-${ value }-${ instanceId }`; +} + type CreateTemplatePartModalContentsProps = { defaultArea?: string; blocks: any[]; @@ -201,52 +203,66 @@ export function CreateTemplatePartModalContents( { onChange={ setTitle } required /> - - - value && typeof value === 'string' - ? setArea( value ) - : () => void 0 - } - checked={ area } - > +
+ + { __( 'Area' ) } + +
{ ( defaultTemplatePartAreas ?? [] ).map( ( item ) => { const icon = getTemplatePartIcon( item.icon ); return ( - - - - - - - { item.label } -
{ item.description }
-
- - - { area === item.area && ( - - ) } - -
-
+ { + setArea( item.area ); + } } + aria-describedby={ getAreaRadioDescriptionId( + item.area, + instanceId + ) } + /> + + + +

+ { item.description } +

+
); } ) } - - + +