Skip to content

Commit

Permalink
feat: add routing
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Oct 13, 2024
1 parent 1cc8ef9 commit 679b594
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 31 deletions.
1 change: 1 addition & 0 deletions packages/settings-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@glzr/components": "1.0.0",
"@solidjs/router": "0.14.8",
"smorf": "1.0.0",
"solid-js": "1.9.2",
"tailwindcss": "3.4.13 ",
Expand Down
4 changes: 4 additions & 0 deletions packages/settings-ui/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ body,
height: 100%;
}

.tabler-icon {
stroke-width: 1;
}

@layer base {
:root {
--background: 0 0% 100%;
Expand Down
12 changes: 10 additions & 2 deletions packages/settings-ui/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/* @refresh reload */
import './index.css';
import { Route, Router } from '@solidjs/router';
import { render } from 'solid-js/web';
import { App } from './App';
import { WidgetSettings } from './settings/WidgetSettings';

render(() => <App />, document.getElementById('root')!);
render(
() => (
<Router>
<Route path="/" component={WidgetSettings} />
</Router>
),
document.getElementById('root')!,
);
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export interface FileItem {
children?: FileItem[];
}

export interface FileTreeProps {
export interface WidgetConfigTreeProps {
files: FileItem[];
onSelect: (file: FileItem) => void;
}

export function FileTree({ files, onSelect }: FileTreeProps) {
export function WidgetConfigTree({
files,
onSelect,
}: WidgetConfigTreeProps) {
const [expanded, setExpanded] = createSignal<Record<string, boolean>>(
{},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileItem, FileTree } from './FileTree';
import { WidgetSettings } from './WidgetSettings';
import { FileItem, WidgetConfigTree } from './WidgetConfigTree';
import { WidgetSettingsForm } from './WidgetSettingsForm';

const initialFiles: FileItem[] = [
{
Expand All @@ -26,37 +26,37 @@ const initialFiles: FileItem[] = [
children: [
{
name: 'Vacation.jpg',
type: 'image',
type: 'file',
size: '3.2 MB',
modified: '2023-09-28',
},
{
name: 'Family.png',
type: 'image',
type: 'file',
size: '2.9 MB',
modified: '2023-09-29',
},
],
},
{
name: 'Music.mp3',
type: 'audio',
type: 'file',
size: '5.4 MB',
modified: '2023-10-01',
},
{
name: 'Video.mp4',
type: 'video',
type: 'file',
size: '15.7 MB',
modified: '2023-10-02',
},
];

export function App() {
export function WidgetSettings() {
return (
<div class="app">
<FileTree files={initialFiles} onSelect={() => {}} />
<WidgetSettings />
<WidgetConfigTree files={initialFiles} onSelect={() => {}} />
<WidgetSettingsForm />
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type WidgetPreset = {
};
};

export function WidgetSettings() {
const widgetForm = createForm<WidgetSettings>({
export function WidgetSettingsForm() {
const settingsForm = createForm<WidgetSettings>({
htmlPath: '',
zOrder: 'normal',
shownInTaskbar: false,
Expand All @@ -59,15 +59,15 @@ export function WidgetSettings() {
});

const presetNames = createMemo(() =>
widgetForm.value.presets.map(preset => preset.name),
settingsForm.value.presets.map(preset => preset.name),
);

const [selectedPreset, setSelectedPreset] = createSignal<string | null>(
null,
);

function addNewPreset() {
widgetForm.setValue('presets', presets => [
settingsForm.setValue('presets', presets => [
...presets,
{
name: presets.length ? `default${presets.length + 1}` : 'default',
Expand All @@ -83,7 +83,7 @@ export function WidgetSettings() {
]);

if (!selectedPreset()) {
setSelectedPreset(widgetForm.value.presets[0].name);
setSelectedPreset(settingsForm.value.presets[0].name);
}
}

Expand All @@ -97,11 +97,11 @@ export function WidgetSettings() {

<Card>
<CardHeader>
<CardTitle>Widget Settings</CardTitle>
<CardTitle>Widget settings</CardTitle>
</CardHeader>

<CardContent class="space-y-4">
<Field of={widgetForm} path="htmlPath">
<Field of={settingsForm} path="htmlPath">
{inputProps => (
<TextField
id="html-path"
Expand All @@ -112,7 +112,7 @@ export function WidgetSettings() {
)}
</Field>

<Field of={widgetForm} path="zOrder">
<Field of={settingsForm} path="zOrder">
{inputProps => (
<SelectField
id="z-order"
Expand All @@ -137,7 +137,7 @@ export function WidgetSettings() {
)}
</Field>

<Field of={widgetForm} path="shownInTaskbar">
<Field of={settingsForm} path="shownInTaskbar">
{inputProps => (
<SwitchField
id="shown-in-taskbar"
Expand All @@ -147,7 +147,7 @@ export function WidgetSettings() {
)}
</Field>

<Field of={widgetForm} path="focused">
<Field of={settingsForm} path="focused">
{inputProps => (
<SwitchField
id="focused"
Expand All @@ -157,7 +157,7 @@ export function WidgetSettings() {
)}
</Field>

<Field of={widgetForm} path="resizable">
<Field of={settingsForm} path="resizable">
{inputProps => (
<SwitchField
id="resizable"
Expand All @@ -167,7 +167,7 @@ export function WidgetSettings() {
)}
</Field>

<Field of={widgetForm} path="transparent">
<Field of={settingsForm} path="transparent">
{inputProps => (
<SwitchField
id="transparent"
Expand All @@ -185,9 +185,9 @@ export function WidgetSettings() {
</CardHeader>

<CardContent class="space-y-4">
{widgetForm.value.presets.map((_, index) => (
{settingsForm.value.presets.map((_, index) => (
<div class="border p-4 rounded-md space-y-2">
<Field of={widgetForm} path={`presets.${index}.name`}>
<Field of={settingsForm} path={`presets.${index}.name`}>
{inputProps => (
<TextField
id={`name-${index}`}
Expand All @@ -198,7 +198,7 @@ export function WidgetSettings() {
</Field>

<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
<Field of={widgetForm} path={`presets.${index}.anchor`}>
<Field of={settingsForm} path={`presets.${index}.anchor`}>
{inputProps => (
<SelectField
id={`anchor-${index}`}
Expand All @@ -223,7 +223,7 @@ export function WidgetSettings() {
</Field>

<Field
of={widgetForm}
of={settingsForm}
path={`presets.${index}.monitorSelection.type`}
>
{inputProps => (
Expand All @@ -245,7 +245,7 @@ export function WidgetSettings() {

<div class="grid grid-cols-1 md:grid-cols-2 gap-2">
{/* TODO: Change to px/percent input. */}
<Field of={widgetForm} path={`presets.${index}.offsetX`}>
<Field of={settingsForm} path={`presets.${index}.offsetX`}>
{inputProps => (
<TextField
id={`offset-x-${index}`}
Expand All @@ -256,7 +256,7 @@ export function WidgetSettings() {
</Field>

{/* TODO: Change to px/percent input. */}
<Field of={widgetForm} path={`presets.${index}.offsetY`}>
<Field of={settingsForm} path={`presets.${index}.offsetY`}>
{inputProps => (
<TextField
id={`offset-y-${index}`}
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 679b594

Please sign in to comment.