Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import {
__experimentalInputControl as InputControl,
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
privateApis,
} from '@wordpress/components';
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
import { Text } from '../../components/text';
import type React from 'react';

const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/components'
);
const { ValidatedInputControl } = unlock( privateApis );

export default function SuffixInputControl( {
suffix,
...props
}: React.ComponentProps< typeof InputControl > ) {
}: React.ComponentProps< typeof ValidatedInputControl > ) {
return (
<InputControl
<ValidatedInputControl
{ ...props }
suffix={ <InputControlSuffixWrapper variant="control">{ suffix }</InputControlSuffixWrapper> }
suffix={
<InputControlSuffixWrapper>
<Text variant="muted" style={ { whiteSpace: 'nowrap' } }>
{ suffix }
</Text>
</InputControlSuffixWrapper>
}
/>
);
}
26 changes: 9 additions & 17 deletions client/dashboard/domains/domain-glue-records/form.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import {
Card,
CardBody,
__experimentalVStack as VStack,
__experimentalInputControl as InputControl,
__experimentalInputControlSuffixWrapper as InputControlSuffixWrapper,
Button,
} from '@wordpress/components';
import { Card, CardBody, __experimentalVStack as VStack, Button } from '@wordpress/components';
import { DataForm, isItemValid } from '@wordpress/dataviews';
import { useState, useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { ButtonStack } from '../../components/button-stack';
import { Text } from '../../components/text';
import SuffixInputControl from '../../components/input-control/suffix-input-control';
import { isValidIpAddress, isValidNameServerSubdomain } from '../../utils/domain';
import type { DomainGlueRecord } from '@automattic/api-core';
import type { Field } from '@wordpress/dataviews';
Expand Down Expand Up @@ -61,22 +54,21 @@ export default function DomainGlueRecordsForm( {
const { id, getValue } = field;
const suffix = `.${ domainName }`;
const value = getValue( { item: data } ).replace( suffix, '' );
const validationMessage = field.isValid?.custom?.( data, field );

return (
// TODO: Show the error via Data Form when the ValidatedInputControl component is ready.
<InputControl
__next40pxDefaultSize
<SuffixInputControl
required={ !! field.isValid?.required }
label={ field.label }
placeholder={ field.placeholder }
value={ value }
onChange={ ( value ) => {
onChange={ ( value: string ) => {
return onChange( { [ id ]: value + suffix } );
} }
suffix={
<InputControlSuffixWrapper>
<Text variant="muted">{ suffix }</Text>
</InputControlSuffixWrapper>
customValidity={
validationMessage ? { type: 'invalid', message: validationMessage } : undefined
}
suffix={ suffix }
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ const SubdomainInputControlEdit = < Item, >( {
<SuffixInputControl
label={ field.label }
value={ getValue( { item: data } ) }
__next40pxDefaultSize
suffix={ <Text variant="muted">{ DOMAIN_SUFFIX }</Text> }
onChange={ ( newValue ) => {
suffix={ DOMAIN_SUFFIX }
onChange={ ( newValue: string ) => {
onChange( { [ id ]: newValue } as Partial< Item > );
} }
/>
Expand Down