Skip to content

Commit 3b182ef

Browse files
committed
refactor: refactor Selection and input
1 parent 1debd8e commit 3b182ef

File tree

14 files changed

+202
-233
lines changed

14 files changed

+202
-233
lines changed

GUI/ETVR/src/app.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { handleAppBoot, handleTitlebar } from '@src/utils/hooks/app'
33
import { AppProvider } from '@store/context/app'
44

55
const AppRoutes = lazy(() => import('@routes/Routes'))
6-
const NewWindow = lazy(() => import('@components/NewWindow'))
7-
const ExampleMenu = lazy(() => import('@components/NewWindow/Example'))
6+
const NewContextMenu = lazy(() => import('@components/NewMenu'))
7+
const ExampleMenu = lazy(() => import('@components/NewMenu/Example'))
88
const ToastNotificationWindow = lazy(() => import('@components/Notifications'))
99

1010
const App = () => {
@@ -19,9 +19,9 @@ const App = () => {
1919
<Suspense>
2020
<AppProvider>
2121
<AppRoutes />
22-
<NewWindow ref={ref} name="test">
22+
<NewContextMenu ref={ref} name="test">
2323
<ExampleMenu />
24-
</NewWindow>
24+
</NewContextMenu>
2525
<ToastNotificationWindow />
2626
</AppProvider>
2727
</Suspense>

GUI/ETVR/src/components/AppSettings/OscSettings/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Input } from '@components/Input'
1+
import Input from '@components/Input'
22

33
export interface IProps {
44
onChangeAddress: (value: string) => void
+12-49
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import { Select } from '@kobalte/core'
2-
import { FaSolidCheck } from 'solid-icons/fa'
3-
import { HiSolidSelector } from 'solid-icons/hi'
4-
import { createSignal } from 'solid-js'
1+
import { type Component, createSignal } from 'solid-js'
2+
import Selection from '@components/Selection'
53
import { useAppAPIContext } from '@src/store/context/api'
6-
import './styles.css'
74

8-
export const FirmwareList = () => {
5+
const FirmwareList: Component = () => {
96
const [firmwareVersion, setFirmwareVersion] = createSignal('')
107

118
const { getFirmwareAssets, getFirmwareVersion } = useAppAPIContext()
@@ -21,49 +18,15 @@ export const FirmwareList = () => {
2118

2219
if (getFirmwareVersion) setFirmwareVersion(getFirmwareVersion())
2320

24-
const [value, setValue] = createSignal(defaultValue)
25-
26-
// TODO: call api to download firmware assets
27-
const handleSubmit = (e: SubmitEvent) => {
28-
e.preventDefault()
29-
console.log('[Firmware Select]: ', value())
30-
}
31-
3221
return (
33-
<form onSubmit={handleSubmit}>
34-
<Select.Root
35-
name="board-select"
36-
value={value()}
37-
onValueChange={setValue}
38-
defaultValue={defaultValue}
39-
options={boardNames}
40-
placeholder="Select a board..."
41-
valueComponent={(props) => props.item.rawValue}
42-
itemComponent={(props) => (
43-
<Select.Item item={props.item} class="select__item">
44-
<Select.ItemLabel>{props.item.rawValue}</Select.ItemLabel>
45-
<Select.ItemIndicator class="select__item-indicator">
46-
<FaSolidCheck />
47-
</Select.ItemIndicator>
48-
</Select.Item>
49-
)}>
50-
<Select.Trigger class="select__trigger" aria-label="ESP_Boards">
51-
<Select.Value class="select__value" />
52-
<Select.Icon class="select__icon">
53-
<HiSolidSelector />
54-
</Select.Icon>
55-
</Select.Trigger>
56-
<Select.Description>Firmware - {firmwareVersion()}</Select.Description>
57-
<Select.Portal>
58-
<Select.Content class="select__content">
59-
<Select.Listbox class="select__listbox" />
60-
</Select.Content>
61-
</Select.Portal>
62-
</Select.Root>
63-
<div>
64-
<button type="reset">Reset</button>
65-
<button>Submit</button>
66-
</div>
67-
</form>
22+
<Selection
23+
name="firmware"
24+
options={boardNames}
25+
placeholder="Select a board"
26+
defaultValue={defaultValue}
27+
description={`Firmware version: ${firmwareVersion()}`}
28+
/>
6829
)
6930
}
31+
32+
export default FirmwareList

GUI/ETVR/src/components/FirmwareList/styles.css

-145
This file was deleted.

GUI/ETVR/src/components/Form/index.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import { Input } from '@components/Input'
1+
import Input from '@components/Input'
22

3-
export const Form = () => {
3+
const Form = () => {
44
const handleChange = (value: string) => {
55
console.log(value)
66
}
77

8+
/* // TODO: call api to download firmware assets
9+
const handleSubmit = (e: SubmitEvent) => {
10+
e.preventDefault()
11+
console.log(`${props.name} [Select]: `, value())
12+
} */
13+
814
return (
915
<div>
1016
<form action="#">
@@ -56,3 +62,5 @@ export const Form = () => {
5662
</div>
5763
)
5864
}
65+
66+
export default Form

GUI/ETVR/src/components/Input/index.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export interface IProps {
1+
import type { Component } from 'solid-js'
2+
3+
interface Props {
24
onChange: (value: string) => void
35
placeholder: string
46
header: string
@@ -7,7 +9,7 @@ export interface IProps {
79
required?: boolean
810
}
911

10-
export const Input = (props: IProps) => {
12+
const Input: Component<Props> = (props) => {
1113
return (
1214
<div class="flex grow rounded-xl flex-col pl-3 pr-3 pb-3 pt-3 bg-[#333742] text-white">
1315
<div>
@@ -35,3 +37,5 @@ export const Input = (props: IProps) => {
3537
</div>
3638
)
3739
}
40+
41+
export default Input

GUI/ETVR/src/components/NewWindow/Example/index.tsx GUI/ETVR/src/components/NewMenu/Example/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import { Button } from '@kobalte/core'
1+
import { Button, Switch } from '@kobalte/core'
2+
23

34
const ExampleMenu = () => {
45
return (
56
<div>
6-
<h1 class="text-lg">Sub Menu</h1>
7+
<h1 class="text-lg">Dev Menu</h1>
78
<hr class="divider" />
89
<label class="context-menu-labels" for="test-button">
9-
Test Button
10+
Enable Dev Tools
1011
</label>
1112
<Button.Root
1213
id="test-button"
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
import { children, createSignal, createEffect, Show, onMount, onCleanup } from 'solid-js'
1+
import { createSignal, createEffect, Show, onMount, onCleanup, type Component } from 'solid-js'
22
import { Portal } from 'solid-js/web'
33
import { onClickOutside, useEventListener } from 'solidjs-use'
44
import type { NewMenu } from '@static/types/interfaces'
55
import { useAppUIContext } from '@src/store/context/ui'
66
import './styles.css'
77

8-
const NewMenu = (props: NewMenu) => {
8+
const NewContextMenu: Component<NewMenu> = (props) => {
99
const [ref, setRef] = createSignal<HTMLElement>()
10-
const Children = children(() => props.children)
11-
1210
const { menuOpenStatus, setMenu } = useAppUIContext()
1311

1412
onMount(() => {
@@ -36,23 +34,21 @@ const NewMenu = (props: NewMenu) => {
3634
})
3735
})
3836
return (
39-
<div>
40-
<Show when={menuOpenStatus() ?? false}>
41-
<Portal mount={props?.ref as HTMLElement}>
42-
<div
43-
ref={setRef}
44-
id={props.name}
45-
class="context-menu"
46-
style={{
47-
top: `${menuOpenStatus()?.y ?? 0}px`,
48-
left: `${menuOpenStatus()?.x ?? 0}px`,
49-
}}>
50-
<Children />
51-
</div>
52-
</Portal>
53-
</Show>
54-
</div>
37+
<Show when={menuOpenStatus() ?? false}>
38+
<Portal mount={props?.ref as HTMLElement}>
39+
<div
40+
ref={setRef}
41+
id={props.name}
42+
class="context-menu shadow-lg bg-[#21232d] dark:bg-gray-800 dark:text-white dark:border-gray-700 border border-gray-200 z-50 absolute"
43+
style={{
44+
top: `${menuOpenStatus()?.y ?? 0}px`,
45+
left: `${menuOpenStatus()?.x ?? 0}px`,
46+
}}>
47+
{props.children}
48+
</div>
49+
</Portal>
50+
</Show>
5551
)
5652
}
5753

58-
export default NewMenu
54+
export default NewContextMenu

GUI/ETVR/src/components/NewWindow/styles.css GUI/ETVR/src/components/NewMenu/styles.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.context-menu {
2-
@apply text-white fixed flex flex-col bg-[#313131] p-3 gap-3 w-fit rounded-sm z-[999];
2+
@apply text-white fixed flex flex-col bg-[#313131] p-3 gap-3 w-fit rounded-lg z-[999];
33
}
44

55
.context-menu button {

0 commit comments

Comments
 (0)