Skip to content

Commit

Permalink
component: Breadcrumb
Browse files Browse the repository at this point in the history
  • Loading branch information
jeannemas committed Jun 4, 2024
1 parent f98e747 commit c42d593
Show file tree
Hide file tree
Showing 31 changed files with 383 additions and 85 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/accordion/AccordionHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
const headerCtx = headerContext.set(writable());
$: headerCtx.update(($headerCtx) => ({
...$headerCtx,
$: headerCtx.update(($ctx) => ({
...$ctx,
}));
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/accordion/AccordionItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
const itemCtx = itemContext.set(writable());
$: itemCtx.update(($itemCtx) => ({
...$itemCtx,
$: itemCtx.update(($ctx) => ({
...$ctx,
disabled,
}));
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/accordion/AccordionRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
const rootCtx = rootContext.set(writable());
$: rootCtx.update(($rootCtx) => ({
...$rootCtx,
$: rootCtx.update(($ctx) => ({
...$ctx,
disabled,
}));
</script>
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/alert-dialog/AlertDialogContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
lg: ['lg:max-w-2xl'],
},
variant: {
danger: ['border-red-500 bg-red-50'],
default: ['border-border bg-background'],
destructive: ['border-red-500 bg-red-50'],
},
},
});
Expand Down Expand Up @@ -98,8 +98,8 @@
const contentCtx = contentContext.set(writable());
contentCtx.update(($contentCtx) => ({
...$contentCtx,
contentCtx.update(($ctx) => ({
...$ctx,
}));
const rootCtx = rootContext.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
base: ['text-sm'],
variants: {
variant: {
danger: ['text-red-500'],
default: ['text-muted-foreground'],
destructive: ['text-red-500'],
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/alert-dialog/AlertDialogPortal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
const portalCtx = portalContext.set(writable());
$: portalCtx.update(($portalCtx) => ({
...$portalCtx,
$: portalCtx.update(($ctx) => ({
...$ctx,
}));
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/alert-dialog/AlertDialogRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
lg: [''],
},
variant: {
danger: [''],
default: [''],
destructive: [''],
},
},
});
Expand All @@ -87,8 +87,8 @@
const rootCtx = rootContext.set(writable());
$: rootCtx.update(($rootCtx) => ({
...$rootCtx,
$: rootCtx.update(($ctx) => ({
...$ctx,
breakpoint,
variant,
}));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/alert-dialog/AlertDialogTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
base: ['text-lg font-semibold'],
variants: {
variant: {
danger: ['text-red-500'],
default: ['text-foreground'],
destructive: ['text-red-500'],
},
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/alert/AlertDescription.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
base: ['text-sm'],
variants: {
variant: {
danger: ['text-red-500'],
default: ['text-foreground'],
destructive: ['text-red-500'],
},
},
});
Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/alert/AlertRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
},
variants: {
variant: {
danger: ['border-red-500 bg-red-50'],
default: ['border-border bg-background'],
destructive: ['border-red-500 bg-red-50'],
},
},
});
Expand All @@ -61,8 +61,8 @@
const rootCtx = rootContext.set(writable());
$: rootCtx.update(($rootCtx) => ({
...$rootCtx,
$: rootCtx.update(($ctx) => ({
...$ctx,
variant,
}));
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/alert/AlertTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
base: ['mb-2 font-medium leading-none tracking-tight'],
variants: {
variant: {
danger: ['text-red-500'],
default: ['text-foreground'],
destructive: ['text-red-500'],
},
},
});
Expand Down
52 changes: 46 additions & 6 deletions src/lib/components/breadcrumb/BreadcrumbEllipsis.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import type { SvelteHTMLElements } from 'svelte/elements';
import { tv } from 'tailwind-variants';
import type { EmptyObject } from '$lib/utils/types.js';
import type { AnyObject, EmptyObject } from '$lib/utils/types.js';
import { itemContext } from './context.js';
/**
* The attributes of the ellipsis.
Expand All @@ -25,7 +27,9 @@
* The slots of the ellipsis.
*/
export type Slots = {
default: EmptyObject;
default: {
builder: AnyObject;
};
};
/**
Expand All @@ -45,24 +49,60 @@
export let el: Props['el'] = undefined;
$: attributes = $$restProps as Attributes;
$: builder = {
role: 'presentation',
'aria-hidden': true,
};
const itemCtx = itemContext.get();
if (!itemCtx) {
throw new Error('Breadcrumb.Ellipsis must be used within a Breadcrumb.Item component.');
}
</script>

<!-- <style lang="postcss">
</style> -->

<!--
@component
An ellipsis of a breadcrumb item component.
Must be used within a `Breadcrumb.Item` component.
### Attributes
Accepts the attributes of a `span` element.
### Events
None.
### Props
- `asChild` - Whether to delegate rendering the element to your own custom element.
- `el` - Bind to the underlying DOM element of the component.
### Slots
- `default` - The default slot.
- `builder` - The builder object, provided when `asChild=true`.
-->

{#if asChild}
<slot />
<slot builder="{builder}" />
{:else}
<span
{...attributes}
{...builder}
class="{ellipsisStyles({
class: attributes.class,
})}"
role="presentation"
aria-hidden="true"
bind:this="{el}"
>
<slot>
<slot builder="{builder}">
<EllipsisIcon class="size-4" />

<span class="sr-only">More</span>
Expand Down
54 changes: 50 additions & 4 deletions src/lib/components/breadcrumb/BreadcrumbItem.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<script context="module" lang="ts">
import type { SvelteHTMLElements } from 'svelte/elements';
import { writable } from 'svelte/store';
import { tv } from 'tailwind-variants';
import type { EmptyObject } from '$lib/utils/types.js';
import type { AnyObject, EmptyObject } from '$lib/utils/types.js';
import { itemContext, listContext } from './context.js';
/**
* The attributes of the item.
Expand All @@ -24,7 +27,9 @@
* The slots of the item.
*/
export type Slots = {
default: EmptyObject;
default: {
builder: AnyObject;
};
};
/**
Expand All @@ -44,21 +49,62 @@
export let el: Props['el'] = undefined;
$: attributes = $$restProps as Attributes;
$: builder = {};
const listCtx = listContext.get();
if (!listCtx) {
throw new Error('Breadcrumb.Item must be used within a Breadcrumb.List component.');
}
const itemCtx = itemContext.set(writable());
itemCtx.update(($ctx) => ({
...$ctx,
}));
</script>

<!-- <style lang="postcss">
</style> -->

<!--
@component
An item of the breadcrumb component.
Must be used within a `Breadcrumb.List` component.
### Attributes
Accepts the attributes of a `li` element.
### Events
None.
### Props
- `asChild` - Whether to delegate rendering the element to your own custom element.
- `el` - Bind to the underlying DOM element of the component.
### Slots
- `default` - The default slot.
- `builder` - The builder object, provided when `asChild=true`.
-->

{#if asChild}
<slot />
<slot builder="{builder}" />
{:else}
<li
{...attributes}
{...builder}
class="{itemStyles({
class: attributes.class,
})}"
bind:this="{el}"
>
<slot />
<slot builder="{builder}" />
</li>
{/if}
Loading

0 comments on commit c42d593

Please sign in to comment.