/** * WordPress dependencies */ import { BaseControl, SelectControl } from '@safe-wordpress/components'; import { useInstanceId } from '@safe-wordpress/compose'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import clsx from 'clsx'; import { toPairs } from 'lodash'; import { ErrorText, NumberControl } from '@nab/components'; import type { SREditProps } from '@nab/types'; /** * Internal dependencies */ import './edit.scss'; import type { Attributes } from './types'; export const Edit = ( { attributes: { condition, value, interval }, errors, setAttributes, }: SREditProps< Attributes > ): JSX.Element => { const instanceId = useInstanceId( Edit ); const valueControlId = `nab-window-width-segmentation-rule__value-${ instanceId }`; return ( <> setAttributes( { condition: newCondition } ) } /> { 'between' !== condition && ( } >
setAttributes( { value: newValue } ) } />
) } { 'between' === condition && ( <> } >
setAttributes( { interval: { min: newValue, max: interval.max, }, } ) } />
} >
setAttributes( { interval: { min: interval.min, max: newValue, }, } ) } />
) } ); }; // ======= // HELPERS // ======= const CONDITION_LABEL_RECORD: Record< Attributes[ 'condition' ], string > = { 'is-greater-than': _x( 'Is greater than', 'text', 'nelio-ab-testing' ), 'is-less-than': _x( 'Is less than', 'text', 'nelio-ab-testing' ), between: _x( 'Between', 'text', 'nelio-ab-testing' ), }; const CONDITIONS = toPairs( CONDITION_LABEL_RECORD ).map( ( [ value, label ] ) => ( { label, value, } ) );