diff --git a/site/content/tutorial/06-bindings/01-text-inputs/app-a/App.svelte b/site/content/tutorial/06-bindings/01-text-inputs/app-a/App.svelte new file mode 100644 index 0000000000..d3cf1a44ed --- /dev/null +++ b/site/content/tutorial/06-bindings/01-text-inputs/app-a/App.svelte @@ -0,0 +1,9 @@ + + + + +
{a} + {b} = {a + b}
\ No newline at end of file diff --git a/site/content/tutorial/06-bindings/02-numeric-inputs/app-b/App.svelte b/site/content/tutorial/06-bindings/02-numeric-inputs/app-b/App.svelte new file mode 100644 index 0000000000..798d57e021 --- /dev/null +++ b/site/content/tutorial/06-bindings/02-numeric-inputs/app-b/App.svelte @@ -0,0 +1,16 @@ + + + + + + +{a} + {b} = {a + b}
\ No newline at end of file diff --git a/site/content/tutorial/06-bindings/02-numeric-inputs/text.md b/site/content/tutorial/06-bindings/02-numeric-inputs/text.md new file mode 100644 index 0000000000..1ede244301 --- /dev/null +++ b/site/content/tutorial/06-bindings/02-numeric-inputs/text.md @@ -0,0 +1,12 @@ +--- +title: Numeric inputs +--- + +In the DOM, everything is a string. That's unhelpful when you're dealing with numeric inputs — `type="number"` and `type="range"` — as it means you have to remember to coerce `input.value` before using it. + +With `bind:value`, Svelte takes care of it for you: + +```html + + +``` \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/03-checkbox-inputs/app-a/App.svelte b/site/content/tutorial/06-bindings/03-checkbox-inputs/app-a/App.svelte new file mode 100644 index 0000000000..2847dad485 --- /dev/null +++ b/site/content/tutorial/06-bindings/03-checkbox-inputs/app-a/App.svelte @@ -0,0 +1,18 @@ + + + + +{#if yes} +Thank you. We will bombard your inbox and sell your personal details.
+{:else} +You must opt in to continue. If you're not paying, you're the product.
+{/if} + + \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/03-checkbox-inputs/app-b/App.svelte b/site/content/tutorial/06-bindings/03-checkbox-inputs/app-b/App.svelte new file mode 100644 index 0000000000..b82d31e783 --- /dev/null +++ b/site/content/tutorial/06-bindings/03-checkbox-inputs/app-b/App.svelte @@ -0,0 +1,18 @@ + + + + +{#if yes} +Thank you. We will bombard your inbox and sell your personal details.
+{:else} +You must opt in to continue. If you're not paying, you're the product.
+{/if} + + \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/03-checkbox-inputs/text.md b/site/content/tutorial/06-bindings/03-checkbox-inputs/text.md new file mode 100644 index 0000000000..621d9fbb7b --- /dev/null +++ b/site/content/tutorial/06-bindings/03-checkbox-inputs/text.md @@ -0,0 +1,9 @@ +--- +title: Checkbox inputs +--- + +Checkboxes are used for toggling between states. Instead of binding to `input.value`, we bind to `input.checked`: + +```html + +``` \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte b/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte new file mode 100644 index 0000000000..5ea04f4e95 --- /dev/null +++ b/site/content/tutorial/06-bindings/04-group-inputs/app-a/App.svelte @@ -0,0 +1,54 @@ + + +Please select at least one flavour
+{:else if flavours.length > scoops} +Can't order more flavours than scoops!
+{:else} ++ You ordered {scoops} {scoops === 1 ? 'scoop' : 'scoops'} + of {join(flavours)} +
+{/if} diff --git a/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte b/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte new file mode 100644 index 0000000000..a46c61c7e7 --- /dev/null +++ b/site/content/tutorial/06-bindings/04-group-inputs/app-b/App.svelte @@ -0,0 +1,52 @@ + + +Please select at least one flavour
+{:else if flavours.length > scoops} +Can't order more flavours than scoops!
+{:else} ++ You ordered {scoops} {scoops === 1 ? 'scoop' : 'scoops'} + of {join(flavours)} +
+{/if} diff --git a/site/content/tutorial/06-bindings/04-group-inputs/text.md b/site/content/tutorial/06-bindings/04-group-inputs/text.md new file mode 100644 index 0000000000..97edb8db76 --- /dev/null +++ b/site/content/tutorial/06-bindings/04-group-inputs/text.md @@ -0,0 +1,36 @@ +--- +title: Group inputs +--- + +If you have multiple inputs relating to the same value, you can use `bind:group` along with the `value` attribute. Radio inputs in the same group are mutually exclusive; checkbox inputs in the same group form an array of selected values. + +Add `bind:group` to each input: + +```html + +``` + +In this case, we could make the code simpler by moving the checkbox inputs into an `each` block. First, add a `menu` variable to the ` + + + + + +{@html rendered} \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte b/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte new file mode 100644 index 0000000000..4081569dd1 --- /dev/null +++ b/site/content/tutorial/06-bindings/05-textarea-inputs/app-b/App.svelte @@ -0,0 +1,14 @@ + + + + + + +{@html rendered} \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/05-textarea-inputs/text.md b/site/content/tutorial/06-bindings/05-textarea-inputs/text.md new file mode 100644 index 0000000000..a19d561719 --- /dev/null +++ b/site/content/tutorial/06-bindings/05-textarea-inputs/text.md @@ -0,0 +1,9 @@ +--- +title: Textarea inputs +--- + +The `