11import { NamedIndex } from '../api/embeddingsApi'
22import { Dispatch , FormEvent , SetStateAction , useCallback , useId } from 'react'
3- import { Label , Stack , TextArea , TextInput } from '@sanity/ui'
3+ import { Box , Label , Stack , TextArea , TextInput , Text } from '@sanity/ui'
44
55export interface IndexFormInputProps {
66 index : Partial < NamedIndex >
77 prop : keyof NamedIndex
88 label : string
9+ description ?: string
910 onChange : Dispatch < SetStateAction < Partial < NamedIndex > > >
1011 readOnly : boolean
1112 placeholder ?: string
1213 type ?: 'text' | 'textarea'
1314}
1415
1516export function IndexFormInput ( props : IndexFormInputProps ) {
16- const { label, index, prop, onChange, readOnly, placeholder, type} = props
17+ const { label, description , index, prop, onChange, readOnly, placeholder, type} = props
1718 const handleChange = useCallback (
1819 ( propValue : string ) => onChange ( ( current ) => ( { ...current , [ prop ] : propValue } ) ) ,
1920 [ onChange , prop ] ,
2021 )
2122 return (
2223 < FormInput
2324 label = { label }
25+ description = { description }
2426 onChange = { handleChange }
2527 value = { index [ prop ] ?? '' }
2628 readOnly = { readOnly }
@@ -32,6 +34,7 @@ export function IndexFormInput(props: IndexFormInputProps) {
3234
3335interface FormInputProps {
3436 label : string
37+ description ?: string
3538 onChange : ( value : string ) => void
3639 value : string
3740 readOnly : boolean
@@ -40,7 +43,7 @@ interface FormInputProps {
4043}
4144
4245function FormInput ( props : FormInputProps ) {
43- const { label, onChange, value, readOnly, placeholder, type = 'text' } = props
46+ const { label, description , onChange, value, readOnly, placeholder, type = 'text' } = props
4447 const id = useId ( )
4548 const handleChange = useCallback (
4649 ( e : FormEvent < HTMLInputElement | HTMLTextAreaElement > ) => onChange ( e . currentTarget . value ) ,
@@ -51,6 +54,13 @@ function FormInput(props: FormInputProps) {
5154 < Label muted htmlFor = { id } >
5255 < label htmlFor = { id } > { label } </ label >
5356 </ Label >
57+ { description && (
58+ < Box >
59+ < Text size = { 1 } muted >
60+ { description }
61+ </ Text >
62+ </ Box >
63+ ) }
5464 { type === 'text' ? (
5565 < TextInput
5666 id = { id }
0 commit comments