1- import { Select } from "@cloudflare/kumo/primitives/select " ;
1+ import { DropdownMenu } from "@cloudflare/kumo" ;
22import {
33 CaretUpDownIcon ,
44 CheckIcon ,
55 PlusIcon ,
66 TableIcon ,
77} from "@phosphor-icons/react" ;
88import { useNavigate } from "@tanstack/react-router" ;
9- import { useCallback , useState } from "react" ;
9+ import { useCallback } from "react" ;
1010import type { StudioRef } from "./studio" ;
1111import type { RefObject } from "react" ;
1212
@@ -22,14 +22,9 @@ export function TableSelect({
2222 selectedTable,
2323} : TableSelectProps ) : JSX . Element {
2424 const navigate = useNavigate ( ) ;
25- const [ open , setOpen ] = useState ( false ) ;
2625
2726 const handleTableChange = useCallback (
28- ( tableName : string | null ) => {
29- if ( tableName === null ) {
30- return ;
31- }
32-
27+ ( tableName : string ) => {
3328 void navigate ( {
3429 search : ( prev ) => ( { ...prev , table : tableName } ) ,
3530 to : "." ,
@@ -39,77 +34,49 @@ export function TableSelect({
3934 ) ;
4035
4136 const handleCreateTable = useCallback ( ( ) : void => {
42- setOpen ( false ) ;
4337 studioRef . current ?. openCreateTableTab ( ) ;
4438 } , [ studioRef ] ) ;
4539
4640 return (
47- < Select . Root
48- key = "table-select"
49- onOpenChange = { setOpen }
50- onValueChange = { handleTableChange }
51- open = { open }
52- value = { selectedTable }
53- >
54- < Select . Trigger className = "-mx-1.5 inline-flex cursor-pointer items-center gap-1 rounded-md border-none bg-transparent p-2 text-sm text-kumo-default transition-colors hover:bg-kumo-fill data-popup-open:bg-kumo-fill" >
55- { selectedTable ? < Select . Value /> : "Select table" }
56- < Select . Icon >
57- < CaretUpDownIcon className = "h-3.5 w-3.5 text-kumo-subtle" />
58- </ Select . Icon >
59- </ Select . Trigger >
60-
61- < Select . Portal >
62- < Select . Positioner
63- align = "start"
64- alignItemWithTrigger = { false }
65- className = "z-100"
66- side = "bottom"
67- sideOffset = { 4 }
68- >
69- < Select . Popup className = "max-h-72 min-w-36 overflow-hidden rounded-lg border border-kumo-fill bg-kumo-base shadow-[0_4px_12px_rgba(0,0,0,0.15)] transition-[opacity,transform] duration-150 data-ending-style:-translate-y-1 data-ending-style:opacity-0 data-starting-style:-translate-y-1 data-starting-style:opacity-0" >
70- < div className = "p-1" >
71- < button
72- className = "flex w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm text-kumo-default transition-colors outline-none select-none hover:bg-kumo-elevated"
73- onClick = { handleCreateTable }
74- type = "button"
75- >
76- < span className = "flex w-4 items-center" >
77- < PlusIcon className = "h-3.5 w-3.5" />
78- </ span >
79- Create table
80- </ button >
81- </ div >
41+ < DropdownMenu >
42+ < DropdownMenu . Trigger
43+ render = {
44+ < button
45+ className = "-mx-1.5 inline-flex cursor-pointer items-center gap-1 rounded-md border-none bg-transparent p-2 text-sm text-kumo-default transition-colors hover:bg-kumo-fill data-[popup-open]:bg-kumo-fill"
46+ type = "button"
47+ />
48+ }
49+ >
50+ { selectedTable ?? "Select table" }
51+ < CaretUpDownIcon className = "h-3.5 w-3.5 text-kumo-subtle" />
52+ </ DropdownMenu . Trigger >
8253
83- < div className = "mx-1 border-t border-kumo-fill" />
54+ < DropdownMenu . Content
55+ className = "max-h-72 overflow-y-auto"
56+ style = { { zIndex : 50 } }
57+ >
58+ < DropdownMenu . Item icon = { PlusIcon } onClick = { handleCreateTable } >
59+ Create table
60+ </ DropdownMenu . Item >
8461
85- < Select . List className = "p-1" >
86- { tables . length > 0 ? (
87- tables . map ( ( table ) => {
88- const Icon =
89- selectedTable === table . value ? CheckIcon : TableIcon ;
62+ < DropdownMenu . Separator />
9063
91- return (
92- < Select . Item
93- className = "flex w-full cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm text-kumo-default transition-colors outline-none select-none data-highlighted:bg-kumo-elevated"
94- key = { table . value }
95- value = { table . value }
96- >
97- < span className = "flex w-4 items-center" >
98- < Icon className = "h-3.5 w-3.5" />
99- </ span >
100- < Select . ItemText > { table . label } </ Select . ItemText >
101- </ Select . Item >
102- ) ;
103- } )
104- ) : (
105- < span className = "flex w-full items-center justify-center gap-2 px-2 py-1.5 text-sm text-kumo-subtle" >
106- No tables
107- </ span >
108- ) }
109- </ Select . List >
110- </ Select . Popup >
111- </ Select . Positioner >
112- </ Select . Portal >
113- </ Select . Root >
64+ { tables . length > 0 ? (
65+ tables . map ( ( table ) => (
66+ < DropdownMenu . Item
67+ icon = { selectedTable === table . value ? CheckIcon : TableIcon }
68+ key = { table . value }
69+ onClick = { ( ) => handleTableChange ( table . value ) }
70+ >
71+ { table . label }
72+ </ DropdownMenu . Item >
73+ ) )
74+ ) : (
75+ < span className = "flex w-full items-center justify-center gap-2 px-2 py-1.5 text-sm text-kumo-subtle" >
76+ No tables
77+ </ span >
78+ ) }
79+ </ DropdownMenu . Content >
80+ </ DropdownMenu >
11481 ) ;
11582}
0 commit comments