Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: expose complete stateStore as a slot prop #38

Merged
merged 7 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-cars-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'cmdk-sv': patch
---

feat: expose state slot prop for Command.Root
4 changes: 2 additions & 2 deletions src/lib/cmdk/components/Command.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@
</script>

{#if asChild}
<slot {root} label={{ attrs: labelAttrs }} />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move these into a reactive slotProps prop, so something like:

<script lang="ts">
	$: slotProps = {
		root,
		label: { attrs: labelAttrs },
		stateStore,
		state: $stateStore,
	}
</script>

If we're going to pass stores as slot props I think they should be suffixed with Store and then we can also pass the value of the store as the state prop.

<slot {root} state={stateStore} label={{ attrs: labelAttrs }} />
{:else}
<div use:rootAction {...rootAttrs} {...$$restProps}>
<!-- svelte-ignore a11y-label-has-associated-control applied in attrs -->
<label {...labelAttrs}>
{label ?? ''}
</label>
<slot {root} label={{ attrs: labelAttrs }} />
<slot {root} state={stateStore} label={{ attrs: labelAttrs }} />
</div>
{/if}
Loading