From 44ef530c148fe2ea996f450c64c3c67977802fbc Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 2 Mar 2019 08:47:58 -0500 Subject: [PATCH] dimension/this bindings --- .../10-dimensions/app-a/App.svelte | 20 +++++++ .../10-dimensions/app-b/App.svelte | 20 +++++++ .../06-bindings/10-dimensions/text.md | 17 ++++++ .../06-bindings/11-this/app-a/App.svelte | 58 ++++++++++++++++++ .../06-bindings/11-this/app-b/App.svelte | 59 +++++++++++++++++++ .../tutorial/06-bindings/11-this/text.md | 15 +++++ site/content/tutorial/99-todo/99-todo/text.md | 6 +- site/static/logo-mask.svg | 6 ++ 8 files changed, 199 insertions(+), 2 deletions(-) create mode 100644 site/content/tutorial/06-bindings/10-dimensions/app-a/App.svelte create mode 100644 site/content/tutorial/06-bindings/10-dimensions/app-b/App.svelte create mode 100644 site/content/tutorial/06-bindings/10-dimensions/text.md create mode 100644 site/content/tutorial/06-bindings/11-this/app-a/App.svelte create mode 100644 site/content/tutorial/06-bindings/11-this/app-b/App.svelte create mode 100644 site/content/tutorial/06-bindings/11-this/text.md create mode 100644 site/static/logo-mask.svg diff --git a/site/content/tutorial/06-bindings/10-dimensions/app-a/App.svelte b/site/content/tutorial/06-bindings/10-dimensions/app-a/App.svelte new file mode 100644 index 0000000000..59e11c79f0 --- /dev/null +++ b/site/content/tutorial/06-bindings/10-dimensions/app-a/App.svelte @@ -0,0 +1,20 @@ + + + + + + + +

size: {w}px x {h}px

+ +
+ {text} +
\ No newline at end of file diff --git a/site/content/tutorial/06-bindings/10-dimensions/app-b/App.svelte b/site/content/tutorial/06-bindings/10-dimensions/app-b/App.svelte new file mode 100644 index 0000000000..ca992599c1 --- /dev/null +++ b/site/content/tutorial/06-bindings/10-dimensions/app-b/App.svelte @@ -0,0 +1,20 @@ + + + + + + + +

size: {w}px x {h}px

+ +
+ {text} +
\ No newline at end of file diff --git a/site/content/tutorial/06-bindings/10-dimensions/text.md b/site/content/tutorial/06-bindings/10-dimensions/text.md new file mode 100644 index 0000000000..3f0a27a7ea --- /dev/null +++ b/site/content/tutorial/06-bindings/10-dimensions/text.md @@ -0,0 +1,17 @@ +--- +title: Dimensions +--- + +Every block-level element has `clientWidth`, `clientHeight`, `offsetWidth` and `offsetHeight` bindings: + +```html +
+ {text} +
+``` + +These bindings are readonly — changing the values of `w` and `h` won't have any effect. + +> Elements are measured using a technique similar to [this one](http://www.backalleycoder.com/2013/03/18/cross-browser-event-based-element-resize-detection/). There is some overhead involved, so it's not recommended to use this for large numbers of elements. +> +> `display: inline` elements cannot be measured with this approach; nor can elements that can't contain other elements (such as ``). In these cases you will need to measure a wrapper element instead. \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/11-this/app-a/App.svelte b/site/content/tutorial/06-bindings/11-this/app-a/App.svelte new file mode 100644 index 0000000000..1dbb904ebc --- /dev/null +++ b/site/content/tutorial/06-bindings/11-this/app-a/App.svelte @@ -0,0 +1,58 @@ + + + + + \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/11-this/app-b/App.svelte b/site/content/tutorial/06-bindings/11-this/app-b/App.svelte new file mode 100644 index 0000000000..5416bbb9cd --- /dev/null +++ b/site/content/tutorial/06-bindings/11-this/app-b/App.svelte @@ -0,0 +1,59 @@ + + + + + \ No newline at end of file diff --git a/site/content/tutorial/06-bindings/11-this/text.md b/site/content/tutorial/06-bindings/11-this/text.md new file mode 100644 index 0000000000..e1aed607b0 --- /dev/null +++ b/site/content/tutorial/06-bindings/11-this/text.md @@ -0,0 +1,15 @@ +--- +title: This +--- + +The readonly `this` binding applies to every element (and component) and allows to you obtain a reference to rendered elements. For example, we can get a reference to a `` element: + +```html + +``` + +Note that the value of `canvas` will be `undefined` until the component has mounted, so we put the logic inside the `onMount` [lifecycle function](tutorials/onmount). \ No newline at end of file diff --git a/site/content/tutorial/99-todo/99-todo/text.md b/site/content/tutorial/99-todo/99-todo/text.md index 2b6f1ce7c7..ba93a02266 100644 --- a/site/content/tutorial/99-todo/99-todo/text.md +++ b/site/content/tutorial/99-todo/99-todo/text.md @@ -69,10 +69,12 @@ Another one should cover how to set up an editor for syntax highlighting. * [x] Form bindings (input, textarea, select, multiple select) * [x] deep/contextual bindings -* [ ] Dimensions -* [ ] `this` +* [x] Dimensions +* [x] `this` * [ ] shorthand +Maybe lifecycle should go first, since we're using `onMount` in the `this` demo? + ## Stores diff --git a/site/static/logo-mask.svg b/site/static/logo-mask.svg new file mode 100644 index 0000000000..d7919a61ab --- /dev/null +++ b/site/static/logo-mask.svg @@ -0,0 +1,6 @@ + + + + \ No newline at end of file