@@ -4,8 +4,7 @@ import { z } from 'zod'
44import { useDeviceParams } from './useDeviceParams'
55import { useRouteParams } from '../../utils/hooks'
66import { IconButton } from '../../components/IconButton'
7- import { DeviceParamType } from '../toggles/settings'
8- import { Fragment } from 'react'
7+ import { DeviceParamType } from '../../utils/params'
98import { useStorage } from '../../utils/storage'
109
1110const BaseAction = z . object ( {
@@ -22,6 +21,7 @@ const ToggleAction = BaseAction.extend({
2221 type : z . literal ( 'toggle' ) ,
2322 toggleKey : z . string ( ) ,
2423 toggleType : z . number ( ) ,
24+ disabled : z . boolean ( ) . optional ( ) ,
2525} )
2626
2727const RedirectAction = BaseAction . extend ( {
@@ -32,22 +32,23 @@ const RedirectAction = BaseAction.extend({
3232export const Action = z . discriminatedUnion ( 'type' , [ NavigationAction , ToggleAction , RedirectAction ] )
3333export type Action = z . infer < typeof Action >
3434
35+ const BUTTON_STYLE = 'h-full w-full rounded-md border border-white/5 text-white bg-background-alt hover:bg-background'
36+ const SELECTED_BUTTON = 'bg-white !text-background-alt hover:!bg-white/80'
37+
3538const RedirectActionComponent = ( { icon, title, href } : z . infer < typeof RedirectAction > ) => {
3639 const { dongleId } = useRouteParams ( )
3740 return (
3841 < IconButton
3942 name = { icon }
4043 href = { href . replaceAll ( '{dongleId}' , dongleId ) }
4144 disabled = { ! href . replaceAll ( '{dongleId}' , dongleId ) }
42- className = { clsx (
43- 'text-xl flex items-center justify-center aspect-square rounded-lg bg-background-alt transition-colors border border-white/5 text-white/80 ' ,
44- ) }
45+ className = { clsx ( BUTTON_STYLE ) }
4546 title = { title }
4647 />
4748 )
4849}
4950
50- const ToggleActionComponent = ( { icon, toggleKey, toggleType, title } : z . infer < typeof ToggleAction > ) => {
51+ const ToggleActionComponent = ( { icon, toggleKey, toggleType, title, disabled } : z . infer < typeof ToggleAction > ) => {
5152 const { get, isLoading, isError, save } = useDeviceParams ( )
5253 if ( toggleType !== DeviceParamType . Boolean ) return null
5354 const value = get ( toggleKey as any )
@@ -58,11 +59,8 @@ const ToggleActionComponent = ({ icon, toggleKey, toggleType, title }: z.infer<t
5859 onClick = { async ( ) => {
5960 await save ( { [ toggleKey ] : isSelected ? '0' : '1' } )
6061 } }
61- disabled = { isLoading || isError || value === undefined }
62- className = { clsx (
63- 'flex items-center justify-center aspect-square rounded-lg transition-colors border border-white/5 text-xl' ,
64- isSelected ? 'bg-white text-background-alt' : 'bg-background-alt text-white/80' ,
65- ) }
62+ disabled = { isLoading || isError || value === undefined || disabled }
63+ className = { clsx ( BUTTON_STYLE , isSelected && SELECTED_BUTTON ) }
6664 title = { title }
6765 />
6866 )
@@ -80,30 +78,36 @@ const NavigationActionComponent = ({ title, icon, location }: z.infer<typeof Nav
8078 await setMapboxRoute ( address )
8179 } }
8280 disabled = { ! address || route === undefined }
83- className = { clsx (
84- 'flex items-center justify-center aspect-square rounded-lg transition-colors border border-white/5 text-xl' ,
85- isSelected ? 'bg-white text-background-alt' : 'bg-background-alt text-white/80' ,
86- ) }
81+ className = { clsx ( BUTTON_STYLE , isSelected && SELECTED_BUTTON ) }
8782 title = { title }
8883 />
8984 )
9085}
9186
9287export const ActionBar = ( { className } : { className ?: string } ) => {
93- const [ actions ] = useStorage ( 'actions' )
88+ const [ actions , setActions ] = useStorage ( 'actions' )
89+
9490 return (
9591 < div
96- className = { clsx ( 'grid gap-2' , className ) }
92+ className = { clsx ( 'flex gap-2 flex-wrap-reverse items-center justify-center ' , className ) }
9793 style = { {
98- gridTemplateColumns : `repeat(${ actions . length } , minmax(0, 1fr ))` ,
94+ gridTemplateColumns : `repeat(${ actions . length } , minmax(2, 2fr ))` ,
9995 } }
10096 >
10197 { actions . map ( ( props , i ) => (
102- < Fragment key = { i } >
98+ < div key = { i } className = "flex text-xl relative group min-w-10 h-10 min-h-10 flex-1" >
10399 { props . type === 'redirect' && < RedirectActionComponent { ...props } /> }
104100 { props . type === 'toggle' && < ToggleActionComponent { ...props } /> }
105101 { props . type === 'navigation' && < NavigationActionComponent { ...props } /> }
106- </ Fragment >
102+ < IconButton
103+ name = "close_small"
104+ title = "Remove"
105+ onClick = { ( ) => {
106+ setActions ( actions . filter ( ( _ , j ) => i !== j ) )
107+ } }
108+ className = "hidden group-hover:flex absolute translate-x-1/2 -translate-y-1/2 top-0 right-0 border border-white/20 z-10 text-white bg-background aspect-square hover:bg-background-alt"
109+ />
110+ </ div >
107111 ) ) }
108112 </ div >
109113 )
0 commit comments