Skip to content

Commit

Permalink
split input-types array to a separate utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Oct 4, 2022
1 parent cf959dc commit c2dcd04
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 40 deletions.
46 changes: 6 additions & 40 deletions packages/block-library/src/input-field/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,10 @@ import {
} from '@wordpress/components';
import { useRef } from '@wordpress/element';

const inputTypeOptions = [
{
key: 'text',
name: __( 'Text' ),
},
{
key: 'textarea',
name: __( 'Textarea' ),
},
{
key: 'checkbox',
name: __( 'Checkbox' ),
},
{
key: 'email',
name: __( 'Email' ),
},
{
key: 'url',
name: __( 'URL' ),
},
{
key: 'tel',
name: __( 'Telephone' ),
},
{
key: 'number',
name: __( 'Number' ),
},
{
key: 'datetime-local',
name: __( 'Date and time' ),
},
{
key: 'submit',
name: __( 'Submit' ),
},
];
/**
* Internal dependencies
*/
import { INPUT_TYPES } from './utils';

function InputFieldBlock( { attributes, setAttributes } ) {
const { type, name, label, inlineLabel } = attributes;
Expand All @@ -69,10 +35,10 @@ function InputFieldBlock( { attributes, setAttributes } ) {
<PanelBody title={ __( 'Input settings' ) }>
<CustomSelectControl
label={ __( 'Type' ) }
value={ inputTypeOptions.find(
value={ INPUT_TYPES.find(
( option ) => option.key === type
) }
options={ inputTypeOptions }
options={ INPUT_TYPES }
onChange={ ( newVal ) => {
setAttributes( {
type: newVal?.selectedItem?.key,
Expand Down
43 changes: 43 additions & 0 deletions packages/block-library/src/input-field/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

export const INPUT_TYPES = [
{
key: 'text',
name: __( 'Text' ),
},
{
key: 'textarea',
name: __( 'Textarea' ),
},
{
key: 'checkbox',
name: __( 'Checkbox' ),
},
{
key: 'email',
name: __( 'Email' ),
},
{
key: 'url',
name: __( 'URL' ),
},
{
key: 'tel',
name: __( 'Telephone' ),
},
{
key: 'number',
name: __( 'Number' ),
},
{
key: 'datetime-local',
name: __( 'Date and time' ),
},
{
key: 'submit',
name: __( 'Submit' ),
},
];

0 comments on commit c2dcd04

Please sign in to comment.