1- import { QuestionMarkCircleIcon } from '@heroicons /react/24/outline '
1+ import { Field , Label , Select } from '@headlessui /react'
22import {
3- Flex ,
4- Icon ,
5- NumberInput ,
6- Select ,
7- SelectItem ,
8- Text ,
9- TextInput ,
10- } from '@tremor/react'
3+ ChevronDownIcon ,
4+ QuestionMarkCircleIcon ,
5+ } from '@heroicons/react/24/outline'
6+ import { Flex , Icon , NumberInput , Text , TextInput } from '@tremor/react'
117import { JSONSchema7 , JSONSchema7TypeName } from 'json-schema'
12- import { useCallback , useState } from 'react'
8+ import React , { useCallback } from 'react'
139
1410import RangeSlider from './RangeSlider'
15- import React from 'react'
1611
1712interface Props {
1813 schema : JSONSchema7
@@ -91,23 +86,23 @@ const renderers: Record<
9186 )
9287 } ,
9388 select : ( field : FieldDefinition ) => {
94- const [ value , setValue ] = useState < string > ( field . defaultValue || '' )
95-
9689 return (
97- < div >
90+ < div className = "relative" >
9891 < Select
92+ name = { field . name }
9993 defaultValue = { field . defaultValue }
100- onValueChange = { setValue }
101- value = { value }
94+ className = "appearance-none text-sm/6 w-full outline-none text-left whitespace-nowrap truncate rounded-tremor-default focus:ring-2 transition duration-100 border px-3 py-1.5 shadow-tremor-input focus:border-tremor-brand-subtle focus:ring-tremor-brand-muted dark:shadow-dark-tremor-input dark:focus:border-dark-tremor-brand-subtle dark:focus:ring-dark-tremor-brand-muted pl-3 bg-tremor-background dark:bg-dark-tremor-background hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted text-tremor-content dark:text-dark-tremor-content border-tremor-border dark:border-dark-tremor-border"
10295 >
10396 { field . value . enum ! . map ( ( item ) => (
104- < SelectItem key = { item ?. toString ( ) } value = { item ! . toString ( ) } >
97+ < option key = { item ?. toString ( ) } value = { item ! . toString ( ) } >
10598 { item ?. toString ( ) }
106- </ SelectItem >
99+ </ option >
107100 ) ) }
108101 </ Select >
109-
110- < input type = "hidden" name = { field . name } value = { value } />
102+ < ChevronDownIcon
103+ className = "group pointer-events-none absolute top-2.5 right-2.5 size-4"
104+ aria-hidden = "true"
105+ />
111106 </ div >
112107 )
113108 } ,
@@ -216,12 +211,12 @@ const JsonSchemaForm: React.FC<Props> = ({ errors = {}, schema }) => {
216211 } )
217212
218213 return (
219- < div key = { key } >
220- < Flex className = "justify-between" >
221- < Text className = "mb-2 " >
214+ < Field key = { key } >
215+ < Flex className = "mb-2 justify-between" >
216+ < Label className = "text-sm font-medium " >
222217 { label }
223218 { required && ' *' }
224- </ Text >
219+ </ Label >
225220
226221 { value . description && (
227222 < Icon
@@ -238,11 +233,11 @@ const JsonSchemaForm: React.FC<Props> = ({ errors = {}, schema }) => {
238233 { errors [ key ] }
239234 </ Text >
240235 ) }
241- </ div >
236+ </ Field >
242237 )
243238 } )
244239
245- return < Flex className = "gap-4 flex-col items-stretch" > { inputFields } </ Flex >
240+ return < Flex className = "gap-6 flex-col items-stretch" > { inputFields } </ Flex >
246241}
247242
248243export default JsonSchemaForm
0 commit comments