diff --git a/src/lib/components/accordion/AccordionHeader.svelte b/src/lib/components/accordion/AccordionHeader.svelte index 67221f3..3625525 100644 --- a/src/lib/components/accordion/AccordionHeader.svelte +++ b/src/lib/components/accordion/AccordionHeader.svelte @@ -52,6 +52,7 @@ $: headerCtx.update(($ctx) => ({ ...$ctx, + ...$itemCtx, })); diff --git a/src/lib/components/accordion/AccordionItem.svelte b/src/lib/components/accordion/AccordionItem.svelte index 8ef4f51..5886689 100644 --- a/src/lib/components/accordion/AccordionItem.svelte +++ b/src/lib/components/accordion/AccordionItem.svelte @@ -61,11 +61,11 @@ $: itemCtx.update(($ctx) => ({ ...$ctx, - disabled, + ...$rootCtx, + itemDisabled: disabled, })); - $: ({ disabled: itemDisabled } = $itemCtx!); - $: ({ disabled: rootDisabled } = $rootCtx!); + $: ({ itemDisabled, rootDisabled } = $itemCtx); $: isDisabled = rootDisabled || itemDisabled; diff --git a/src/lib/components/accordion/AccordionRoot.svelte b/src/lib/components/accordion/AccordionRoot.svelte index a8a5126..3e60dbc 100644 --- a/src/lib/components/accordion/AccordionRoot.svelte +++ b/src/lib/components/accordion/AccordionRoot.svelte @@ -63,7 +63,7 @@ $: rootCtx.update(($ctx) => ({ ...$ctx, - disabled, + rootDisabled: disabled, })); diff --git a/src/lib/components/accordion/AccordionTrigger.svelte b/src/lib/components/accordion/AccordionTrigger.svelte index a1fe0e0..a0de69d 100644 --- a/src/lib/components/accordion/AccordionTrigger.svelte +++ b/src/lib/components/accordion/AccordionTrigger.svelte @@ -7,7 +7,7 @@ import { cn } from '$lib/utils/cn.js'; import type { ComponentInfo } from '$lib/utils/types.js'; - import { headerContext, itemContext, rootContext } from './context.js'; + import { headerContext } from './context.js'; type Primitive = ComponentInfo; @@ -66,15 +66,12 @@ $: attributes = $$restProps as Attributes; const headerCtx = headerContext.get(); - const itemCtx = itemContext.get(); - const rootCtx = rootContext.get(); if (!headerCtx) { throw new Error('Accordion.Trigger must be used within an Accordion.Header component.'); } - $: ({ disabled: itemDisabled } = $itemCtx!); - $: ({ disabled: rootDisabled } = $rootCtx!); + $: ({ itemDisabled, rootDisabled } = $headerCtx!); $: isDisabled = (rootDisabled || itemDisabled) ?? false; diff --git a/src/lib/components/accordion/context.ts b/src/lib/components/accordion/context.ts index fd6a9e7..293b22b 100644 --- a/src/lib/components/accordion/context.ts +++ b/src/lib/components/accordion/context.ts @@ -4,6 +4,19 @@ import { Context } from '$lib/utils/context.js'; import type { HeaderProps, ItemProps, RootProps } from './index.js'; -export const headerContext = new Context>>(); -export const itemContext = new Context>>(); -export const rootContext = new Context, 'disabled'>>>(); +type HeaderContext = ItemContext & { + [K in keyof Pick as `header${Capitalize}`]: HeaderProps[K]; +}; +type ItemContext = RootContext & { + [K in keyof Pick as `item${Capitalize}`]: ItemProps[K]; +}; +type RootContext = { + [K in keyof Pick< + RootProps, + 'disabled' + > as `root${Capitalize}`]: RootProps[K]; +}; + +export const headerContext = new Context>(); +export const itemContext = new Context>(); +export const rootContext = new Context>(); diff --git a/src/lib/components/alert-dialog/AlertDialogContent.svelte b/src/lib/components/alert-dialog/AlertDialogContent.svelte index eb09b23..4df2e52 100644 --- a/src/lib/components/alert-dialog/AlertDialogContent.svelte +++ b/src/lib/components/alert-dialog/AlertDialogContent.svelte @@ -7,7 +7,7 @@ import { flyAndScale } from '$lib/transition/flyAndScale.js'; import type { ComponentInfo, Transition } from '$lib/utils/types.js'; - import { contentContext, portalContext, rootContext } from './context.js'; + import { contentContext, portalContext } from './context.js'; type Primitive< TContentTransition extends Transition = Transition, @@ -98,13 +98,12 @@ const contentCtx = contentContext.set(writable()); - contentCtx.update(($ctx) => ({ + $: contentCtx.update(($ctx) => ({ ...$ctx, + ...$portalCtx, })); - const rootCtx = rootContext.get(); - - $: ({ breakpoint, variant } = $rootCtx!); + $: ({ rootBreakpoint, rootVariant } = $contentCtx); + + --> + + import { Checkbox as CheckboxPrimitive } from 'bits-ui'; - import CheckIcon from 'lucide-svelte/icons/check'; - import MinusIcon from 'lucide-svelte/icons/minus'; import type { SvelteHTMLElements } from 'svelte/elements'; + import { writable } from 'svelte/store'; import { tv } from 'tailwind-variants'; import type { ComponentInfo } from '$lib/utils/types.js'; import CheckboxHiddenInput from './CheckboxHiddenInput.svelte'; import CheckboxIndicator from './CheckboxIndicator.svelte'; + import { rootContext } from './context.js'; type Primitive = ComponentInfo; @@ -35,7 +35,9 @@ 'data-[disabled=true]:cursor-not-allowed data-[disabled=true]:opacity-50', 'data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground', ], - defaultVariants: {}, + defaultVariants: { + disabled: false, + }, variants: { disabled: { true: ['cursor-not-allowed opacity-50'], @@ -51,7 +53,7 @@ export let asChild: Props['asChild'] = undefined; export let checked: Props['checked'] = undefined; - export let disabled: Props['disabled'] = undefined; + export let disabled: Props['disabled'] = rootStyles.defaultVariants.disabled; export let el: Props['el'] = undefined; export let name: Props['name'] = undefined; export let onCheckedChange: Props['onCheckedChange'] = undefined; @@ -59,11 +61,58 @@ export let value: Props['value'] = undefined; $: attributes = $$restProps as Attributes; + + const rootCtx = rootContext.set(writable()); + + $: rootCtx.update(($ctx) => ({ + ...$ctx, + })); + + - - - - {#if isChecked} - - {:else if isIndeterminate} - - {/if} - + + + diff --git a/src/lib/components/checkbox/context.ts b/src/lib/components/checkbox/context.ts new file mode 100644 index 0000000..8e0f705 --- /dev/null +++ b/src/lib/components/checkbox/context.ts @@ -0,0 +1,11 @@ +import type { Writable } from 'svelte/store'; + +import { Context } from '$lib/utils/context.js'; + +import type { RootProps } from './index.js'; + +type RootContext = { + [K in keyof Pick as `root${Capitalize}`]: RootProps[K]; +}; + +export const rootContext = new Context>();