Skip to content

Commit

Permalink
site: turn fancybutton into custombutton (#4476)
Browse files Browse the repository at this point in the history
  • Loading branch information
antony authored Feb 27, 2020
1 parent dc3e9c4 commit 7831766
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import FancyButton from './FancyButton.svelte';
import CustomButton from './CustomButton.svelte';
function handleClick() {
alert('clicked');
}
</script>

<FancyButton on:click={handleClick}/>
<CustomButton on:click={handleClick}/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<style>
button {
height: 4rem;
width: 8rem;
background-color: #aaa;
border-color: #f1c40f;
color: #f1c40f;
font-size: 1.25rem;
background-image: linear-gradient(45deg, #f1c40f 50%, transparent 50%);
background-position: 100%;
background-size: 400%;
transition: background 300ms ease-in-out;
}
button:hover {
background-position: 0;
color: #aaa;
}
</style>

<button on:click>
Click me
</button>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import FancyButton from './FancyButton.svelte';
import CustomButton from './CustomButton.svelte';
function handleClick() {
alert('clicked');
}
</script>

<FancyButton on:click={handleClick}/>
<CustomButton on:click={handleClick}/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<style>
button {
height: 4rem;
width: 8rem;
background-color: #aaa;
border-color: #f1c40f;
color: #f1c40f;
font-size: 1.25rem;
background-image: linear-gradient(45deg, #f1c40f 50%, transparent 50%);
background-position: 100%;
background-size: 400%;
transition: background 300ms ease-in-out;
}
button:hover {
background-position: 0;
color: #aaa;
}
</style>

<button>
Click me
</button>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script>
import FancyButton from './FancyButton.svelte';
import CustomButton from './CustomButton.svelte';
function handleClick() {
alert('clicked');
}
</script>

<FancyButton on:click={handleClick}/>
<CustomButton on:click={handleClick}/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<style>
button {
height: 4rem;
width: 8rem;
background-color: #aaa;
border-color: #f1c40f;
color: #f1c40f;
font-size: 1.25rem;
background-image: linear-gradient(45deg, #f1c40f 50%, transparent 50%);
background-position: 100%;
background-size: 400%;
transition: background 300ms ease-in-out;
}
button:hover {
background-position: 0;
color: #aaa;
}
</style>

<button on:click>
Click me
</button>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: DOM event forwarding

Event forwarding works for DOM events too.

We want to get notified of clicks on our `<FancyButton>` — to do that, we just need to forward `click` events on the `<button>` element in `FancyButton.svelte`:
We want to get notified of clicks on our `<CustomButton>` — to do that, we just need to forward `click` events on the `<button>` element in `CustomButton.svelte`:

```html
<button on:click>
Expand Down
Binary file modified site/static/examples/thumbnails/dom-event-forwarding.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/custom-elements/samples/extended-builtin/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ export default {
warnings: [{
code: "avoid-is",
message: "The 'is' attribute is not supported cross-browser and should be avoided",
pos: 97,
pos: 98,
start: {
character: 97,
character: 98,
column: 8,
line: 7
},
end: {
character: 114,
column: 25,
character: 116,
column: 26,
line: 7
}
}]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class CustomButton extends HTMLButtonElement {}
customElements.define('custom-button', CustomButton, { extends: 'button' });
2 changes: 0 additions & 2 deletions test/custom-elements/samples/extended-builtin/fancy-button.js

This file was deleted.

4 changes: 2 additions & 2 deletions test/custom-elements/samples/extended-builtin/main.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<svelte:options tag="custom-element"/>

<script>
import './fancy-button.js';
import './custom-button.js';
</script>

<button is="fancy-button">click me</button>
<button is="custom-button">click me</button>
2 changes: 1 addition & 1 deletion test/custom-elements/samples/extended-builtin/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export default function (target) {
const el = target.querySelector('custom-element');
const button = el.shadowRoot.querySelector('button');

assert.ok(button instanceof customElements.get('fancy-button'));
assert.ok(button instanceof customElements.get('custom-button'));
}

0 comments on commit 7831766

Please sign in to comment.