|
1 |
| -<svelte:options runes={false} /> |
| 1 | +<svelte:options runes={true} /> |
2 | 2 |
|
3 | 3 | <aside
|
4 | 4 | bind:this={element}
|
|
11 | 11 | 'smui-drawer__absolute': variant === 'modal' && !fixed,
|
12 | 12 | ...internalClasses,
|
13 | 13 | })}
|
14 |
| - {...$$restProps} |
| 14 | + {...restProps} |
15 | 15 | onkeydown={(e) => {
|
16 | 16 | if (instance) {
|
17 | 17 | instance.handleKeydown(e);
|
18 | 18 | }
|
19 |
| - $$restProps.onkeydown?.(e); |
| 19 | + restProps.onkeydown?.(e); |
20 | 20 | }}
|
21 | 21 | ontransitionend={(e) => {
|
22 | 22 | if (instance) {
|
23 | 23 | instance.handleTransitionEnd(e);
|
24 | 24 | }
|
25 |
| - $$restProps.ontransitionend?.(e); |
| 25 | + restProps.ontransitionend?.(e); |
26 | 26 | }}
|
27 | 27 | >
|
28 |
| - <slot /> |
| 28 | + {#if children}{@render children()}{/if} |
29 | 29 | </aside>
|
30 | 30 |
|
31 | 31 | <script lang="ts">
|
|
34 | 34 | MDCModalDrawerFoundation,
|
35 | 35 | } from '@material/drawer';
|
36 | 36 | import { focusTrap as domFocusTrap } from '@material/dom';
|
| 37 | + import type { Snippet } from 'svelte'; |
37 | 38 | import { onMount, onDestroy, setContext } from 'svelte';
|
38 | 39 | import type { SmuiAttrs } from '@smui/common';
|
39 | 40 | import type { ActionArray } from '@smui/common/internal';
|
|
42 | 43 | const { FocusTrap } = domFocusTrap;
|
43 | 44 |
|
44 | 45 | type OwnProps = {
|
| 46 | + /** |
| 47 | + * An array of Action or [Action, ActionProps] to be applied to the element. |
| 48 | + */ |
45 | 49 | use?: ActionArray;
|
| 50 | + /** |
| 51 | + * A space separated list of CSS classes. |
| 52 | + */ |
46 | 53 | class?: string;
|
| 54 | + /** |
| 55 | + * How the drawer opens. |
| 56 | + * |
| 57 | + * Undefined means it's always open. |
| 58 | + * |
| 59 | + * Dismissible means it pushes the content over when it opens. |
| 60 | + * |
| 61 | + * Modal means it uses a scrim to open over the content. |
| 62 | + */ |
47 | 63 | variant?: 'dismissible' | 'modal' | undefined;
|
| 64 | + /** |
| 65 | + * When using a dismissible or modal drawer, controls whether it's open. |
| 66 | + */ |
48 | 67 | open?: boolean;
|
| 68 | + /** |
| 69 | + * Turn this off for non-page-wide drawers. |
| 70 | + * |
| 71 | + * This controls whether the drawer uses fixed or absolute positioning. |
| 72 | + */ |
49 | 73 | fixed?: boolean;
|
50 |
| - }; |
51 |
| - type $$Props = OwnProps & SmuiAttrs<'aside', keyof OwnProps>; |
52 | 74 |
|
53 |
| - // Remember to update $$Props if you add/remove/rename props. |
54 |
| - export let use: ActionArray = []; |
55 |
| - let className = ''; |
56 |
| - export { className as class }; |
57 |
| - export let variant: 'dismissible' | 'modal' | undefined = undefined; |
58 |
| - export let open = false; |
59 |
| - export let fixed = true; |
| 75 | + children?: Snippet; |
| 76 | + }; |
| 77 | + let { |
| 78 | + use = $bindable([]), |
| 79 | + class: className = $bindable(''), |
| 80 | + variant = $bindable(undefined), |
| 81 | + open = $bindable(false), |
| 82 | + fixed = $bindable(true), |
| 83 | + children, |
| 84 | + ...restProps |
| 85 | + }: OwnProps & SmuiAttrs<'aside', keyof OwnProps> = $props(); |
60 | 86 |
|
61 | 87 | let element: HTMLElement;
|
62 | 88 | let instance:
|
63 | 89 | | MDCDismissibleDrawerFoundation
|
64 | 90 | | MDCModalDrawerFoundation
|
65 |
| - | undefined = undefined; |
66 |
| - let internalClasses: { [k: string]: boolean } = {}; |
67 |
| - let previousFocus: Element | null = null; |
| 91 | + | undefined = $state(undefined); |
| 92 | + let internalClasses: { [k: string]: boolean } = $state({}); |
| 93 | + let previousFocus: Element | null = $state(null); |
68 | 94 | let focusTrap: domFocusTrap.FocusTrap;
|
69 |
| - let scrim: Element | false = false; |
| 95 | + let scrim: Element | false = $state(false); |
70 | 96 |
|
71 | 97 | setContext('SMUI:list:nav', true);
|
72 | 98 | setContext('SMUI:list:item:nav', true);
|
73 | 99 | setContext('SMUI:list:wrapFocus', true);
|
74 | 100 |
|
75 |
| - $: if (instance && instance.isOpen() !== open) { |
76 |
| - if (open) { |
77 |
| - instance.open(); |
78 |
| - } else { |
79 |
| - instance.close(); |
| 101 | + $effect(() => { |
| 102 | + if (instance && instance.isOpen() !== open) { |
| 103 | + if (open) { |
| 104 | + instance.open(); |
| 105 | + } else { |
| 106 | + instance.close(); |
| 107 | + } |
80 | 108 | }
|
81 |
| - } |
| 109 | + }); |
82 | 110 |
|
83 | 111 | let oldVariant = variant;
|
84 |
| - $: if (oldVariant !== variant) { |
85 |
| - oldVariant = variant; |
86 |
| - instance && instance.destroy(); |
87 |
| - internalClasses = {}; |
88 |
| - instance = getInstance(); |
89 |
| - instance && instance.init(); |
90 |
| - } |
| 112 | + $effect(() => { |
| 113 | + if (oldVariant !== variant) { |
| 114 | + oldVariant = variant; |
| 115 | + instance && instance.destroy(); |
| 116 | + internalClasses = {}; |
| 117 | + instance = getInstance(); |
| 118 | + instance && instance.init(); |
| 119 | + } |
| 120 | + }); |
91 | 121 |
|
92 | 122 | onMount(() => {
|
93 | 123 | focusTrap = new FocusTrap(element, {
|
|
0 commit comments