|
1 | | -import { |
2 | | - Card, |
3 | | - CardBody, |
4 | | - __experimentalVStack as VStack, |
5 | | - __experimentalInputControl as InputControl, |
6 | | - __experimentalInputControlSuffixWrapper as InputControlSuffixWrapper, |
7 | | - Button, |
8 | | -} from '@wordpress/components'; |
| 1 | +import { Card, CardBody, __experimentalVStack as VStack, Button } from '@wordpress/components'; |
9 | 2 | import { DataForm, isItemValid } from '@wordpress/dataviews'; |
10 | 3 | import { useState, useMemo } from '@wordpress/element'; |
11 | 4 | import { __ } from '@wordpress/i18n'; |
12 | 5 | import { ButtonStack } from '../../components/button-stack'; |
13 | | -import { Text } from '../../components/text'; |
| 6 | +import SuffixInputControl from '../../components/input-control/suffix-input-control'; |
14 | 7 | import { isValidIpAddress, isValidNameServerSubdomain } from '../../utils/domain'; |
15 | 8 | import type { DomainGlueRecord } from '@automattic/api-core'; |
16 | 9 | import type { Field } from '@wordpress/dataviews'; |
@@ -61,22 +54,21 @@ export default function DomainGlueRecordsForm( { |
61 | 54 | const { id, getValue } = field; |
62 | 55 | const suffix = `.${ domainName }`; |
63 | 56 | const value = getValue( { item: data } ).replace( suffix, '' ); |
| 57 | + const validationMessage = field.isValid?.custom?.( data, field ); |
64 | 58 |
|
65 | 59 | return ( |
66 | | - // TODO: Show the error via Data Form when the ValidatedInputControl component is ready. |
67 | | - <InputControl |
68 | | - __next40pxDefaultSize |
| 60 | + <SuffixInputControl |
| 61 | + required={ !! field.isValid?.required } |
69 | 62 | label={ field.label } |
70 | 63 | placeholder={ field.placeholder } |
71 | 64 | value={ value } |
72 | | - onChange={ ( value ) => { |
| 65 | + onChange={ ( value: string ) => { |
73 | 66 | return onChange( { [ id ]: value + suffix } ); |
74 | 67 | } } |
75 | | - suffix={ |
76 | | - <InputControlSuffixWrapper> |
77 | | - <Text variant="muted">{ suffix }</Text> |
78 | | - </InputControlSuffixWrapper> |
| 68 | + customValidity={ |
| 69 | + validationMessage ? { type: 'invalid', message: validationMessage } : undefined |
79 | 70 | } |
| 71 | + suffix={ suffix } |
80 | 72 | /> |
81 | 73 | ); |
82 | 74 | }, |
|
0 commit comments