Skip to content

Commit fff06a2

Browse files
committed
fix errors
1 parent a00e7ef commit fff06a2

File tree

3 files changed

+64
-142
lines changed

3 files changed

+64
-142
lines changed

src/solidbase-theme/mdx-components.tsx

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import {
22
Accessor,
33
For,
4+
Match,
45
type ParentProps,
6+
Show,
7+
Switch,
58
children,
9+
createMemo,
610
createSignal,
711
splitProps,
812
} from "solid-js";
@@ -22,58 +26,68 @@ export { ImageLinks } from "~/ui/image-links";
2226

2327
const EraserLinkImpl = clientOnly(() => import("../ui/eraser-link"));
2428

29+
type CalloutType = "info" | "tip" | "danger" | "caution";
30+
2531
export const DirectiveContainer = (
2632
props: {
27-
type: "info" | "tip" | "danger" | "caution" | "tab-group" | "tab";
33+
type: "tab-group" | "tab" | CalloutType;
2834
title?: string;
2935
codeGroup?: string;
3036
tabNames?: string;
3137
} & ParentProps
3238
) => {
3339
const _children = children(() => props.children).toArray();
3440

35-
if (props.type === "tab") {
36-
return _children;
37-
}
38-
39-
if (props.type === "tab-group") {
40-
const tabNames = props.tabNames?.split("\0") ?? [];
41+
const tabNames = createMemo(() => props.tabNames?.split("\0") ?? []);
4142

42-
const tabs = (value?: Accessor<string>, onChange?: (s: string) => void) => (
43-
<Tabs>
44-
<TabList>
45-
<For each={tabNames}>
46-
{(title) => (
47-
<Tab
48-
value={title}
49-
class="px-5 py-1 relative top-0.5 transition-colors duration-300 aria-selected:font-bold aria-selected:dark:text-slate-300 aria-selected:text-blue-500 aria-selected:border-b-2 aria-selected:border-blue-400"
50-
>
51-
{title}
52-
</Tab>
53-
)}
54-
</For>
55-
</TabList>
56-
<For each={tabNames}>
57-
{(title, idx) => (
58-
<TabPanel value={title} forceMount={true}>
59-
{_children[idx()]}
60-
</TabPanel>
43+
const tabs = (value?: Accessor<string>, onChange?: (s: string) => void) => (
44+
<Tabs value={value?.()} onChange={onChange}>
45+
<TabList>
46+
<For each={tabNames()}>
47+
{(title) => (
48+
<Tab
49+
value={title}
50+
class="px-5 py-1 relative top-0.5 transition-colors duration-300 aria-selected:font-bold aria-selected:dark:text-slate-300 aria-selected:text-blue-500 aria-selected:border-b-2 aria-selected:border-blue-400"
51+
>
52+
{title}
53+
</Tab>
6154
)}
6255
</For>
63-
</Tabs>
64-
);
65-
66-
if (!props.title) return tabs();
56+
</TabList>
57+
<For each={tabNames()}>
58+
{(title, idx) => (
59+
<TabPanel value={title} forceMount={true}>
60+
{_children[idx()]}
61+
</TabPanel>
62+
)}
63+
</For>
64+
</Tabs>
65+
);
6766

68-
const [openTab, setOpenTab] = makePersisted(createSignal(tabNames[0]!), {
67+
const tabsWithPersistence = () => {
68+
// eslint-disable-next-line solid/reactivity
69+
const [openTab, setOpenTab] = makePersisted(createSignal(tabNames()[0]), {
6970
name: `tab-group:${props.title}`,
7071
sync: messageSync(new BroadcastChannel("tab-group")),
7172
});
7273

7374
return tabs(openTab, setOpenTab);
74-
}
75+
};
7576

76-
return <Callout type={props.type} children={props.children} />;
77+
return (
78+
<Switch
79+
fallback={
80+
<Callout type={props.type as CalloutType} children={props.children} />
81+
}
82+
>
83+
<Match when={props.type === "tab"}>{_children}</Match>
84+
<Match when={props.type === "tab-group"}>
85+
<Show when={props.title} fallback={tabs()}>
86+
{tabsWithPersistence()}
87+
</Show>
88+
</Match>
89+
</Switch>
90+
);
7791
};
7892

7993
export const strong = (props: ParentProps) => (

src/ui/package-manager.tsx

Lines changed: 0 additions & 100 deletions
This file was deleted.

src/ui/tabs.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
1+
import { type PolymorphicProps } from "@kobalte/core";
12
import {
23
Tabs as KobalteTabs,
34
type TabsRootProps as KobalteTabsRootProps,
45
type TabsListProps as KobalteTabsListProps,
56
type TabsTriggerProps as KobalteTabsTriggerProps,
67
type TabsContentProps as KobalteTabsContentProps,
78
} from "@kobalte/core/tabs";
8-
import { ComponentProps } from "solid-js";
99

10-
export type TabsProps = ComponentProps<"div"> &
11-
Omit<KobalteTabsRootProps, "as">;
10+
export type TabsProps = PolymorphicProps<
11+
"div",
12+
Omit<KobalteTabsRootProps, "as">
13+
>;
1214

1315
export function Tabs(props: TabsProps) {
1416
return <KobalteTabs {...props} />;
1517
}
1618

17-
export type TabListProps = ComponentProps<"div"> &
18-
Omit<KobalteTabsListProps, "as">;
19+
export type TabListProps = PolymorphicProps<
20+
"div",
21+
Omit<KobalteTabsListProps, "as">
22+
>;
1923

2024
export function TabList(props: TabListProps) {
2125
return (
2226
<KobalteTabs.List {...props} class="mb-2 border-b-2 border-slate-800" />
2327
);
2428
}
2529

26-
export type TabProps = ComponentProps<"button"> &
27-
Omit<KobalteTabsTriggerProps, "as">;
30+
export type TabProps = PolymorphicProps<
31+
"button",
32+
Omit<KobalteTabsTriggerProps, "as">
33+
>;
2834

2935
export function Tab(props: TabProps) {
3036
return (
@@ -35,8 +41,10 @@ export function Tab(props: TabProps) {
3541
);
3642
}
3743

38-
export type TabPanelProps = ComponentProps<"div"> &
39-
Omit<KobalteTabsContentProps, "id">;
44+
export type TabPanelProps = PolymorphicProps<
45+
"div",
46+
Omit<KobalteTabsContentProps, "id">
47+
>;
4048

4149
export function TabPanel(props: TabPanelProps) {
4250
return (

0 commit comments

Comments
 (0)