Skip to content

Commit

Permalink
component: Checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jeannemas committed Jun 5, 2024
1 parent ee8ae4d commit 5e2a784
Show file tree
Hide file tree
Showing 38 changed files with 277 additions and 82 deletions.
1 change: 1 addition & 0 deletions src/lib/components/accordion/AccordionHeader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
$: headerCtx.update(($ctx) => ({
...$ctx,
...$itemCtx,
}));
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/lib/components/accordion/AccordionItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@
$: itemCtx.update(($ctx) => ({
...$ctx,
disabled,
...$rootCtx,
itemDisabled: disabled,
}));
$: ({ disabled: itemDisabled } = $itemCtx!);
$: ({ disabled: rootDisabled } = $rootCtx!);
$: ({ itemDisabled, rootDisabled } = $itemCtx);
$: isDisabled = rootDisabled || itemDisabled;
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/accordion/AccordionRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$: rootCtx.update(($ctx) => ({
...$ctx,
disabled,
rootDisabled: disabled,
}));
</script>

Expand Down
7 changes: 2 additions & 5 deletions src/lib/components/accordion/AccordionTrigger.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccordionPrimitive.Trigger>;
Expand Down Expand Up @@ -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;
</script>

Expand Down
19 changes: 16 additions & 3 deletions src/lib/components/accordion/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import { Context } from '$lib/utils/context.js';

import type { HeaderProps, ItemProps, RootProps } from './index.js';

export const headerContext = new Context<Writable<Pick<HeaderProps, never>>>();
export const itemContext = new Context<Writable<Pick<ItemProps, 'disabled'>>>();
export const rootContext = new Context<Writable<Pick<RootProps<boolean>, 'disabled'>>>();
type HeaderContext = ItemContext & {
[K in keyof Pick<HeaderProps, never> as `header${Capitalize<K>}`]: HeaderProps[K];
};
type ItemContext = RootContext & {
[K in keyof Pick<ItemProps, 'disabled'> as `item${Capitalize<K>}`]: ItemProps[K];
};
type RootContext = {
[K in keyof Pick<
RootProps<boolean>,
'disabled'
> as `root${Capitalize<K>}`]: RootProps<boolean>[K];
};

export const headerContext = new Context<Writable<HeaderContext>>();
export const itemContext = new Context<Writable<ItemContext>>();
export const rootContext = new Context<Writable<RootContext>>();
13 changes: 6 additions & 7 deletions src/lib/components/alert-dialog/AlertDialogContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
</script>

<!-- <style lang="postcss">
Expand Down Expand Up @@ -152,9 +151,9 @@ Accepts the attributes of a `div` element.
{...attributes}
asChild="{asChild}"
class="{contentStyles({
breakpoint,
breakpoint: rootBreakpoint,
class: attributes.class,
variant,
variant: rootVariant,
})}"
el="{el}"
inTransition="{inTransition}"
Expand Down
8 changes: 3 additions & 5 deletions src/lib/components/alert-dialog/AlertDialogDescription.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { ComponentInfo } from '$lib/utils/types.js';
import { contentContext, rootContext } from './context.js';
import { contentContext } from './context.js';
type Primitive = ComponentInfo<AlertDialogPrimitive.Description>;
Expand Down Expand Up @@ -52,9 +52,7 @@
throw new Error('AlertDialog.Title must be used within an AlertDialog.Content component.');
}
const rootCtx = rootContext.get();
$: ({ variant } = $rootCtx!);
$: ({ rootVariant } = $contentCtx!);
</script>

<!-- <style lang="postcss">
Expand Down Expand Up @@ -91,7 +89,7 @@ None.
asChild="{asChild}"
class="{descriptionStyles({
class: attributes.class,
variant,
variant: rootVariant,
})}"
el="{el}"
let:builder
Expand Down
1 change: 1 addition & 0 deletions src/lib/components/alert-dialog/AlertDialogPortal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$: portalCtx.update(($ctx) => ({
...$ctx,
...$rootCtx,
}));
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/alert-dialog/AlertDialogRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
$: rootCtx.update(($ctx) => ({
...$ctx,
breakpoint,
variant,
rootBreakpoint: breakpoint,
rootVariant: variant,
}));
</script>

Expand Down
8 changes: 3 additions & 5 deletions src/lib/components/alert-dialog/AlertDialogTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import type { ComponentInfo, HeadingLevel } from '$lib/utils/types.js';
import { contentContext, rootContext } from './context.js';
import { contentContext } from './context.js';
type Primitive = ComponentInfo<AlertDialogPrimitive.Title>;
Expand Down Expand Up @@ -59,9 +59,7 @@
throw new Error('AlertDialog.Title must be used within an AlertDialog.Content component.');
}
const rootCtx = rootContext.get();
$: ({ variant } = $rootCtx!);
$: ({ rootVariant } = $contentCtx!);
</script>

<!-- <style lang="postcss">
Expand Down Expand Up @@ -99,7 +97,7 @@ None.
asChild="{asChild}"
class="{titleStyles({
class: attributes.class,
variant,
variant: rootVariant,
})}"
el="{el}"
level="{level}"
Expand Down
16 changes: 13 additions & 3 deletions src/lib/components/alert-dialog/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { Context } from '$lib/utils/context.js';

import type { ContentProps, PortalProps, RootProps } from './index.js';

export const contentContext = new Context<Writable<Pick<ContentProps, never>>>();
export const portalContext = new Context<Writable<Pick<PortalProps, never>>>();
export const rootContext = new Context<Writable<Pick<RootProps, 'breakpoint' | 'variant'>>>();
type ContentContext = PortalContext & {
[K in keyof Pick<ContentProps, never> as `content${Capitalize<K>}`]: ContentProps[K];
};
type PortalContext = RootContext & {
[K in keyof Pick<PortalProps, never> as `portal${Capitalize<K>}`]: PortalProps[K];
};
type RootContext = {
[K in keyof Pick<RootProps, 'breakpoint' | 'variant'> as `root${Capitalize<K>}`]: RootProps[K];
};

export const contentContext = new Context<Writable<ContentContext>>();
export const portalContext = new Context<Writable<PortalContext>>();
export const rootContext = new Context<Writable<RootContext>>();
4 changes: 2 additions & 2 deletions src/lib/components/alert/AlertDescription.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
throw new Error('Alert.Description must be used within an Alert.Root component.');
}
$: ({ variant } = $rootCtx!);
$: ({ rootVariant } = $rootCtx!);
</script>

<!-- <style lang="postcss">
Expand Down Expand Up @@ -82,7 +82,7 @@ None.
{...attributes}
class="{descriptionStyles({
class: attributes.class,
variant,
variant: rootVariant,
})}"
>
<slot />
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/alert/AlertRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$: rootCtx.update(($ctx) => ({
...$ctx,
variant,
rootVariant: variant,
}));
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/lib/components/alert/AlertTitle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
throw new Error('Alert.Title must be used within an Alert.Root component.');
}
$: ({ variant } = $rootCtx!);
$: ({ rootVariant } = $rootCtx!);
</script>

<!-- <style lang="postcss">
Expand Down Expand Up @@ -91,7 +91,7 @@ None.
{...attributes}
class="{titleStyles({
class: attributes.class,
variant,
variant: rootVariant,
})}"
>
<slot />
Expand Down
6 changes: 5 additions & 1 deletion src/lib/components/alert/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ import { Context } from '$lib/utils/context.js';

import type { RootProps } from './index.js';

export const rootContext = new Context<Writable<Pick<RootProps, 'variant'>>>();
type RootContext = {
[K in keyof Pick<RootProps, 'variant'> as `root${Capitalize<K>}`]: RootProps[K];
};

export const rootContext = new Context<Writable<RootContext>>();
1 change: 1 addition & 0 deletions src/lib/components/breadcrumb/BreadcrumbItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
itemCtx.update(($ctx) => ({
...$ctx,
...$listCtx,
}));
</script>

Expand Down
7 changes: 4 additions & 3 deletions src/lib/components/breadcrumb/BreadcrumbList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@
throw new Error('Breadcrumb.List must be used within a Breadcrumb.Root component.');
}
$: ({ breakpoint } = $rootCtx!);
const listCtx = listContext.set(writable());
$: listCtx.update(($ctx) => ({
...$ctx,
...$rootCtx,
}));
$: ({ rootBreakpoint } = $listCtx);
</script>

<!-- <style lang="postcss">
Expand Down Expand Up @@ -112,7 +113,7 @@ None.
{...attributes}
{...builder}
class="{listStyles({
breakpoint,
breakpoint: rootBreakpoint,
class: attributes.class,
})}"
bind:this="{el}"
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/breadcrumb/BreadcrumbRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
$: rootCtx.update(($ctx) => ({
...$ctx,
breakpoint,
rootBreakpoint: breakpoint,
}));
</script>

Expand Down
16 changes: 13 additions & 3 deletions src/lib/components/breadcrumb/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ import { Context } from '$lib/utils/context.js';

import type { ItemProps, ListProps, RootProps } from './index.js';

export const itemContext = new Context<Writable<Pick<ItemProps, never>>>();
export const listContext = new Context<Writable<Pick<ListProps, never>>>();
export const rootContext = new Context<Writable<Pick<RootProps, 'breakpoint'>>>();
type ItemContext = ListContext & {
[K in keyof Pick<ItemProps, never> as `item${Capitalize<K>}`]: ItemProps[K];
};
type ListContext = RootContext & {
[K in keyof Pick<ListProps, never> as `list${Capitalize<K>}`]: ListProps[K];
};
type RootContext = {
[K in keyof Pick<RootProps, 'breakpoint'> as `root${Capitalize<K>}`]: RootProps[K];
};

export const itemContext = new Context<Writable<ItemContext>>();
export const listContext = new Context<Writable<ListContext>>();
export const rootContext = new Context<Writable<RootContext>>();
4 changes: 2 additions & 2 deletions src/lib/components/button/ButtonRoot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
$: rootCtx.update(($ctx) => ({
...$ctx,
size,
variant,
rootSize: size,
rootVariant: variant,
}));
</script>

Expand Down
6 changes: 5 additions & 1 deletion src/lib/components/button/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ import { Context } from '$lib/utils/context.js';

import type { RootProps } from './index.js';

export const rootContext = new Context<Writable<Pick<RootProps, 'size' | 'variant'>>>();
type RootContext = {
[K in keyof Pick<RootProps, 'size' | 'variant'> as `root${Capitalize<K>}`]: RootProps[K];
};

export const rootContext = new Context<Writable<RootContext>>();
1 change: 1 addition & 0 deletions src/lib/components/calendar/CalendarCell.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
$: cellCtx.update(($ctx) => ({
...$ctx,
...$gridRowCtx,
}));
</script>

Expand Down
1 change: 1 addition & 0 deletions src/lib/components/calendar/CalendarGrid.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$: gridCtx.update(($ctx) => ({
...$ctx,
...$monthsCtx,
}));
</script>

Expand Down
1 change: 1 addition & 0 deletions src/lib/components/calendar/CalendarGridBody.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$: gridBodyCtx.update(($ctx) => ({
...$ctx,
...$gridCtx,
}));
</script>

Expand Down
1 change: 1 addition & 0 deletions src/lib/components/calendar/CalendarGridHead.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$: gridHeadCtx.update(($ctx) => ({
...$ctx,
...$gridCtx,
}));
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/calendar/CalendarGridRow.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
$: gridRowCtx.update(($ctx) => ({
...$ctx,
...$gridHeadCtx,
...$gridBodyCtx,
}));
</script>

Expand Down
Loading

0 comments on commit 5e2a784

Please sign in to comment.