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: controlProps() and labelProps() #206

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

huntabyte
Copy link
Member

@huntabyte huntabyte commented Dec 16, 2024

This PR introduces two new functions to Formsnap, controlProps and labelProps, which will retrieve a reactive reference to the control/label props from the context provided by the closest <Control> component in the tree.

These functions reduce the amount of boilerplate required for the Control with Formsnap v2.

Before:

This is still an acceptable way of handling this in Formsnap v2 if you prefer.

<Control>
	{#snippet children({ props })}
		<Label>Name</Label>
		<input {...props} bind:value={$formData.name} />
	{/snippet}
</Control>

After:

<Control>
	<Label>Name</Label>
	<input {...controlProps()} bind:value={$formData.name} />
</Control>

or

<Control>
	<label {...labelProps()}>Name</label>
	<input {...controlProps()} bind:value={$formData.name} />
</Control>

Copy link

changeset-bot bot commented Dec 16, 2024

🦋 Changeset detected

Latest commit: f455af4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
formsnap Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Dec 16, 2024

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
formsnap ✅ Ready (View Log) Visit Preview f455af4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant