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

Improve the component-binding example #519

Open
Pacheco95 opened this issue Jul 6, 2023 · 2 comments
Open

Improve the component-binding example #519

Pacheco95 opened this issue Jul 6, 2023 · 2 comments

Comments

@Pacheco95
Copy link

I searched the repo for the example file to make a PR but found nothing.

Example: https://svelte.dev/examples/component-bindings

Keypad.svelte

<script>
	import { createEventDispatcher } from 'svelte';

	export let value = '';

	const dispatch = createEventDispatcher();

	const select = (num) => () => (value += num);
	const clear = () => (value = '');
	const submit = () => dispatch('submit');
</script>

<div class="keypad">

	{#each Array(9) as _, i}
		<button on:click={select(i + 1)}>{i + 1}</button>
	{/each}

	<button disabled={!value} on:click={clear}>clear</button>
	<button on:click={select(0)}>0</button>
	<button disabled={!value} on:click={submit}>submit</button>
</div>

<style>
	.keypad {
		display: grid;
		grid-template-columns: repeat(3, 5em);
		grid-template-rows: repeat(4, 3em);
		grid-gap: 0.5em;
	}

	button {
		margin: 0;
	}
</style>
@geoffrich
Copy link
Member

The code is in the svelte repo: https://github.com/sveltejs/svelte/blob/master/documentation/examples/05-bindings/12-component-bindings/Keypad.svelte

@Pacheco95
Copy link
Author

Thanks @geoffrich
Here's the PR
sveltejs/svelte#8931

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

No branches or pull requests

2 participants