33import { Label , Listbox , ListboxButton , ListboxOption , ListboxOptions } from '@headlessui/react' ;
44import { CheckIcon , ChevronUpDownIcon } from '@heroicons/react/16/solid' ;
55import { Array as EffectArray , String as EffectString , Schema , pipe } from 'effect' ;
6- import type { UseFormSetValue } from 'react-hook-form' ;
76
8- import type { InsertAppSchema } from '../../../schema .js' ;
9- import { classnames } from '../../../utils/classnames.js' ;
7+ import { useFieldContext } from '../../../../context/form .js' ;
8+ import { classnames } from '../../../../ utils/classnames.js' ;
109
1110class TypeOption extends Schema . Class < TypeOption > ( '/hypergraph/typesync/models/TypeOption' ) ( {
1211 id : Schema . NonEmptyTrimmedString ,
@@ -27,20 +26,12 @@ const typeOptions: Array<TypeOption> = [
2726] ;
2827
2928export function TypeCombobox ( {
30- typePropertyIdx,
31- typeIdx,
32- value,
33- onTypeSelected,
29+ id,
30+ name,
3431 schemaTypes = [ ] ,
3532} : Readonly < {
36- /** the index of this type selection field in the properties array. Types.AppSchemaForm.types[idx].properties[typeInputIdx] */
37- typePropertyIdx : number ;
38- /** the index of the type within the schema array Types.AppSchemaForm.types[typeIdx] */
39- typeIdx : number ;
40- /** the current value */
41- value : string ;
42- /** set the value in the form when the user selects a value */
43- onTypeSelected : UseFormSetValue < InsertAppSchema > ;
33+ id : string ;
34+ name : string ;
4435 /**
4536 * A list of types within the defined schema that the user can use as a relation
4637 * This allows the user to specify the property as a relationship to a type in the schema
@@ -49,6 +40,8 @@ export function TypeCombobox({
4940 */
5041 schemaTypes ?: Array < string > | undefined ;
5142} > ) {
43+ const field = useFieldContext < string > ( ) ;
44+
5245 const relationTypeOptions = pipe (
5346 schemaTypes ,
5447 EffectArray . filter ( ( _type ) => EffectString . isNonEmpty ( _type ) ) ,
@@ -60,38 +53,37 @@ export function TypeCombobox({
6053 return (
6154 < Listbox
6255 as = "div"
63- id = { `types.${ typeIdx } .properties.${ typePropertyIdx } .type_name` }
64- name = { `types.${ typeIdx } .properties.${ typePropertyIdx } .type_name` }
65- value = { value }
56+ id = { id }
57+ name = { name }
58+ value = { field . state . value }
59+ onBlur = { field . handleBlur }
6660 onChange = { ( value ) => {
6761 if ( value ) {
68- onTypeSelected ( `types.${ typeIdx } .properties.${ typePropertyIdx } .type_name` , value , {
69- shouldDirty : true ,
70- shouldTouch : true ,
71- shouldValidate : true ,
72- } ) ;
62+ field . handleChange ( value ) ;
7363 }
7464 } }
7565 >
7666 < Label className = "sr-only" > Prop type</ Label >
7767 < div className = "relative" >
78- < ListboxButton className = "grid w-full cursor-default grid-cols-1 rounded-md bg-slate-900 py-1.5 pr-2 pl-3 text-left text-white outline-1 -outline-offset-1 outline-gray-500 focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6" >
79- < span className = "col-start-1 row-start-1 truncate pr-6" > { value } </ span >
68+ < ListboxButton className = "grid w-full cursor-default grid-cols-1 rounded-md bg-white dakr:bg-slate-900 py-1.5 pr-2 pl-3 text-left text-white outline-1 -outline-offset-1 outline-gray-500 focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6" >
69+ < span className = "col-start-1 row-start-1 truncate pr-6 text-gray-950 dark:text-white" >
70+ { field . state . value }
71+ </ span >
8072 < ChevronUpDownIcon
8173 aria-hidden = "true"
82- className = "col-start-1 row-start-1 size-5 self-center justify-self-end text-gray-300 sm:size-4"
74+ className = "col-start-1 row-start-1 size-5 self-center justify-self-end text-gray-300 dark:text-gray-50 sm:size-4"
8375 />
8476 </ ListboxButton >
8577
8678 < ListboxOptions
8779 transition
88- className = "absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-slate-800 py-1 text-base shadow-lg ring-1 ring-black/5 focus:outline-hidden data-leave:transition data-leave:duration-100 data-leave:ease-in data-closed:data-leave:opacity-0 sm:text-sm"
80+ className = "absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-gray-50 dark:bg- slate-800 py-1 text-base shadow-lg ring-1 ring-gray-200 dark: ring-black/5 focus:outline-hidden data-leave:transition data-leave:duration-100 data-leave:ease-in data-closed:data-leave:opacity-0 sm:text-sm"
8981 >
9082 { typeOptions . map ( ( type ) => (
9183 < ListboxOption
9284 key = { type . id }
9385 value = { type . name }
94- className = "group relative cursor-default py-2 pr-9 pl-3 text-white select-none data-focus:bg-indigo-600 data-focus:text-white data-focus:outline-hidden"
86+ className = "group relative cursor-default py-2 pr-9 pl-3 text-gray-800 dark:text- white select-none data-focus:bg-indigo-600 data-focus:text-white data-focus:outline-hidden"
9587 >
9688 < span className = "block truncate font-normal group-data-selected:font-semibold" > { type . name } </ span >
9789
@@ -105,7 +97,7 @@ export function TypeCombobox({
10597 key = { type . id }
10698 value = { type . name }
10799 className = { classnames (
108- 'group relative cursor-default py-2 pr-9 pl-3 text-white select-none data-focus:bg-indigo-600 data-focus:text-white data-focus:outline-hidden' ,
100+ 'group relative cursor-default py-2 pr-9 pl-3 text-gray-800 dark:text- white select-none data-focus:bg-indigo-600 data-focus:text-white data-focus:outline-hidden' ,
109101 idx === 0 ? 'border-t border-gray-400 dark:border-white/10' : '' ,
110102 ) }
111103 >
0 commit comments