Skip to content

Commit d9bf8c2

Browse files
committed
✨ Wrap context in effect
1 parent 0bddfc4 commit d9bf8c2

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/components/ContextMenu/ContextMenu.svelte

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@
6767
}
6868
})
6969
70-
if (!context) {
71-
// eslint-disable-next-line no-console, max-len
72-
console.error('Missing "context" slot. Attach slot="context" to one of the children of your <ContextMenu> component.')
73-
}
70+
$effect(() => {
71+
if (!context) {
72+
// eslint-disable-next-line no-console, max-len
73+
console.error('Missing "context" slot. Attach slot="context" to one of the children of your <ContextMenu> component.')
74+
}
75+
})
7476
</script>
7577

7678
<svelte:element {...rest} this={element} class={classes} bind:this={ctx}>

src/pages/components/context-menu.astro

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { listWithGroups } from '@data'
1212
<Layout>
1313
<h1>ContextMenu</h1>
1414
<div class="grid md-2 lg-3">
15-
<ComponentWrapper type="Astro">
15+
<ComponentWrapper type="Astro" className="card">
1616
<AstroContextMenu className="ctx">
1717
<span class="muted">Right-click here</span>
1818
<span class="muted">Click "Sign out" to close context.</span>
@@ -29,7 +29,7 @@ import { listWithGroups } from '@data'
2929
</AstroContextMenu>
3030
</ComponentWrapper>
3131

32-
<ComponentWrapper type="Svelte">
32+
<ComponentWrapper type="Svelte" className="card">
3333
<!-- @ts-ignore -->
3434
<SvelteContextMenu className="ctx s" client:visible>
3535
<span class="muted">Right-click here</span>
@@ -47,14 +47,22 @@ import { listWithGroups } from '@data'
4747
</SvelteContextMenu>
4848
</ComponentWrapper>
4949

50-
<ComponentWrapper type="React">
50+
<ComponentWrapper type="React" className="card">
5151
<div class="ctx">
5252
<a href="/react" class="muted">See in React playground {'->'}</a>
5353
</div>
5454
</ComponentWrapper>
5555
</div>
5656
</Layout>
5757

58+
<style is:global lang="scss">
59+
@use '../../scss/config.scss' as *;
60+
61+
.card {
62+
@include visibility(visible);
63+
}
64+
</style>
65+
5866
<script>
5967
import { closeContext } from '@utils/context'
6068
import { on } from '@utils/DOMUtils'

src/static/ComponentWrapper.astro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const {
88
secondary,
99
compact,
1010
type,
11+
className,
1112
bodyClassName
1213
} = Astro.props
1314
---
@@ -20,6 +21,7 @@ const {
2021
bodyClassName={bodyClassName}
2122
className={classNames([
2223
type && type.slice(0, 1).toLocaleLowerCase(),
24+
className,
2325
'default'
2426
])}
2527
>

0 commit comments

Comments
 (0)