for consistency
This commit is contained in:
41
src/components/Selectable.tsx
Normal file
41
src/components/Selectable.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { useTheme } from "@/context/ThemeContext";
|
||||||
|
import type { JSXElement } from "solid-js";
|
||||||
|
import type { BoxOptions, TextOptions } from "@opentui/core";
|
||||||
|
|
||||||
|
export function SelectableBox({
|
||||||
|
selected,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: {
|
||||||
|
selected: () => boolean;
|
||||||
|
children: JSXElement;
|
||||||
|
} & BoxOptions) {
|
||||||
|
const { theme } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<box
|
||||||
|
borderColor={selected() ? theme.surface : theme.border}
|
||||||
|
backgroundColor={selected() ? theme.primary : theme.surface}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SelectableText({
|
||||||
|
selected,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: {
|
||||||
|
selected: () => boolean;
|
||||||
|
children: JSXElement;
|
||||||
|
} & TextOptions) {
|
||||||
|
const { theme } = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<text fg={selected() ? theme.surface : theme.text} {...props}>
|
||||||
|
{children}
|
||||||
|
</text>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useTheme } from "@/context/ThemeContext";
|
import { useTheme } from "@/context/ThemeContext";
|
||||||
import { TABS } from "@/utils/navigation";
|
import { TABS } from "@/utils/navigation";
|
||||||
import { For } from "solid-js";
|
import { For } from "solid-js";
|
||||||
|
import { SelectableBox, SelectableText } from "@/components/Selectable";
|
||||||
|
|
||||||
interface TabNavigationProps {
|
interface TabNavigationProps {
|
||||||
activeTab: TABS;
|
activeTab: TABS;
|
||||||
@@ -29,24 +30,18 @@ export function TabNavigation(props: TabNavigationProps) {
|
|||||||
>
|
>
|
||||||
<For each={tabs}>
|
<For each={tabs}>
|
||||||
{(tab) => (
|
{(tab) => (
|
||||||
<box
|
<SelectableBox
|
||||||
border
|
border
|
||||||
borderColor={theme.border}
|
selected={() => tab.id == props.activeTab}
|
||||||
onMouseDown={() => props.onTabSelect(tab.id)}
|
onMouseDown={() => props.onTabSelect(tab.id)}
|
||||||
style={{
|
|
||||||
backgroundColor:
|
|
||||||
tab.id == props.activeTab ? theme.primary : "transparent",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<text
|
<SelectableText
|
||||||
style={{
|
selected={() => tab.id == props.activeTab}
|
||||||
fg: tab.id == props.activeTab ? "white" : theme.text,
|
alignSelf="center"
|
||||||
alignSelf: "center",
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{tab.label}
|
{tab.label}
|
||||||
</text>
|
</SelectableText>
|
||||||
</box>
|
</SelectableBox>
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
</box>
|
</box>
|
||||||
|
|||||||
Reference in New Issue
Block a user