Skip to content
88 changes: 88 additions & 0 deletions examples/email-recipients/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<title>&lt;email&gt;</title>

<link rel=stylesheet href=style.css>

<email-recipients>

<template name=recipients>
<address>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is address allowed to be email address, not just physical? TIL

Copy link
Copy Markdown
Member Author

@snuggs snuggs Jul 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<button id={#}
onclick=onremove
title='Remove <{self}> from recipients'>x</button>

<label>
<input name=recipients[] type=checkbox value={self} checked>
{self}
</label>
</address>
</template>

<input
type=search
name=address
list=contacts
onchange=addrecipient
placeholder=email@example.com>

<datalist id=contacts>
<template name=contacts>
<option value={email}>{name} &lt;{email}&gt;
</template>
</datalist>

</email-recipients>

<script src=/snuggsi.es></script>
<script defer>

Element `email-recipients`

(class extends HTMLElement {

initialize () {
this.context.recipients =
['angelo@isawesome.com', 'snuggs@isawesome.com']
}

onconnect () {
this.context
.contacts = [
{ name: 'Tim', email: 'tim@isawesome.com' },
{ name: 'Rob Cole', email: 'robcole@isawesome.com' }
]
}

// use Array.prototype.splice
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
onremove (event, id = event.target.id, address) {
address =
this.context
.recipients.splice
(event.target.id, 1)

this.select
`input[name=address]`.focus()
}

addrecipient (event, input = event.target) {
this.context
.recipients.push
(input.value)

input.value = ''
}

get recipients ()
{ return this.context.recipients }

get contacts ()
{ return this.context.contacts }
})

</script>

<script src=/browser-sync.es></script>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we load this conditionally based on localhost?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, hadn't picked up on that. well played.

<script
name=polyfill
src=//cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.0.0/webcomponents-hi-ce.js>
</script>
70 changes: 70 additions & 0 deletions examples/email-recipients/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
:root {
--email-recipients-corner-radius: 1vw;
}

email-recipients > address:hover,
email-recipients {
box-shadow: 0 0 0.28em rgba(40,40,40,0.8);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no spaces between rgba values?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandondees i'm down with that

Copy link
Copy Markdown
Member Author

@snuggs snuggs Jul 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertoponti @brandondees hit me with "Tsu"! f783911

border-radius: var(--email-recipients-corner-radius)
}

email-recipients {
padding: 1em;
display: flex;
flex-basis: auto;
flex-flow: row wrap;
}

email-recipients > * {
font-size: 90%;
line-height: 1.612em;
}

email-recipients > address {
display: flex;
cursor: pointer;
margin: 0;
font-style: normal;
align-items: center;
flex-flow: row nowrap;
font-family: sans-serif;
}
email-recipients > address::after {
content: ", ";
margin-top: -0.4em;
font-size: 2em;
color: rgba(50,50,50,0.7);
}
email-recipients > address:hover {
background: rgba(220,220,220,0.9)
}
email-recipients > address button {
opacity: 0;
border: none;
background: none;
margin-right: 0.12em;
padding: 0 0.12em 0 0.2em;
border-right: 1px solid red;
}

email-recipients > address:hover button {
opacity: 0.5;
font-size: 80%;
cursor: pointer;
color: rgba(230,0,0,0.9);
}
email-recipients > address button:hover {
opacity: 1.0
}

email-recipients input[name='recipients[]'] {
display: none;
}
email-recipients input[name=address] {
flex: 0;
border: none;
outline: none;
background; yellow;
line-height: 1em;
align-items: flex-start;
}