Skip to content

Commit

Permalink
copy component from skeleton to fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cmintey committed Nov 8, 2024
1 parent 887f6be commit ca2fe8e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
73 changes: 73 additions & 0 deletions src/lib/components/Tab/TabGroup.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<!-- Custom TabGroup component from Skeleton which fixes a type issue with svelte 5 -->
<script lang="ts">
import type { CssClasses } from "@skeletonlabs/skeleton";
// Slots
/**
* @slot panel - An optional region to house tab content.
*/
import { setContext } from "svelte";
// Props (Group)
/** Provide classes to set the tab list flex justification. */
export let justify: CssClasses = "justify-start";
/** Provide classes to set the tab group border styles. */
export let border: CssClasses = "border-b border-surface-400-500-token";
// Props (Tab)
/** Provide classes to style each tab's active styles. */
export let active: CssClasses = "border-b-2 border-surface-900-50-token";
/** Provide classes to style each tab's hover styles. */
export let hover: CssClasses = "hover:variant-soft";
/** Provide classes to style each tab's flex styles. */
export let flex: CssClasses = "flex-none";
/** Provide classes to style each tab's padding styles. */
export let padding: CssClasses = "px-4 py-2";
/** Provide classes to style each tab's box radius styles. */
export let rounded: CssClasses = "rounded-tl-container-token rounded-tr-container-token";
/** Provide classes to set the vertical spacing between items. */
export let spacing: CssClasses = "space-y-1";
// Props (regions)
/** Provide arbitrary classes to style the tab list region. */
export let regionList: CssClasses = "";
/** Provide arbitrary classes to style the tab panel region. */
export let regionPanel: CssClasses = "";
// Props (a11y)
/** Provide the ID of the element that labels the tab list. */
export let labelledby = "";
/** Matches the tab aria-control value, pairs with the panel. */
export let panellabelledby = "";
// Context
setContext("active", active);
setContext("hover", hover);
setContext("flex", flex);
setContext("padding", padding);
setContext("rounded", rounded);
setContext("spacing", spacing);
// Classes
const cBase = "space-y-4";
const cList = "flex overflow-x-auto hide-scrollbar";
const cPanel = "";
// Reactive
$: classesBase = `${cBase} ${$$props.class ?? ""}`;
$: classesList = `${cList} ${justify} ${border} ${regionList}`;
$: classesPanel = `${cPanel} ${regionPanel}`;
</script>

<div class="tab-group {classesBase}" data-testid="tab-group">
<!-- Tab List -->
<div class="tab-list {classesList}" aria-labelledby={labelledby} role="tablist">
<slot />
</div>
<!-- Tab Panel -->
{#if $$slots.panel}
<div class="tab-panel {classesPanel}" aria-labelledby={panellabelledby} role="tabpanel" tabindex="0">
<slot name="panel" />
</div>
{/if}
</div>
3 changes: 2 additions & 1 deletion src/routes/account/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import ChangePassword from "$lib/components/account/ChangePassword.svelte";
import EditProfile from "$lib/components/account/EditProfile.svelte";
import Avatar from "$lib/components/Avatar.svelte";
import { FileButton, Tab, TabGroup } from "@skeletonlabs/skeleton";
import { FileButton, Tab } from "@skeletonlabs/skeleton";
import type { PageServerData } from "./$types";
import TabGroup from "$lib/components/Tab/TabGroup.svelte";
interface Props {
data: PageServerData;
Expand Down
3 changes: 2 additions & 1 deletion src/routes/admin/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { Tab, TabGroup } from "@skeletonlabs/skeleton";
import { Tab } from "@skeletonlabs/skeleton";
import type { Snapshot } from "./$types";
import TabGroup from "$lib/components/Tab/TabGroup.svelte";
interface Props {
children?: import("svelte").Snippet;
Expand Down
3 changes: 2 additions & 1 deletion src/routes/admin/groups/[groupId]/+layout@.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import { goto, invalidateAll } from "$app/navigation";
import { Tab, TabGroup } from "@skeletonlabs/skeleton";
import { Tab } from "@skeletonlabs/skeleton";
import type { LayoutData, Snapshot } from "./$types";
import { page } from "$app/stores";
import { GroupAPI } from "$lib/api/groups";
import TabGroup from "$lib/components/Tab/TabGroup.svelte";
interface Props {
data: LayoutData;
Expand Down

0 comments on commit ca2fe8e

Please sign in to comment.