feat(components): add Tile

Supports #34

TODO:

- remove exported props
- compose TileGroup, SelectableTile, RadioTile components
This commit is contained in:
Eric Liu 2019-12-19 04:20:20 -08:00
commit 46cb9aa44b
12 changed files with 472 additions and 2 deletions

View file

@ -0,0 +1,42 @@
<script>
let className = undefined;
export { className as class };
export let href = undefined;
export let rel = undefined;
export let light = false;
export let clicked = false;
export let props = {};
import { createEventDispatcher, tick } from 'svelte';
import { cx } from '../../lib';
const dispatch = createEventDispatcher();
async function handleClick(event) {
clicked = !clicked;
await tick();
dispatch('click', event);
}
async function handleKeyDown(event) {
if (event.key === ' ' || event.key === 'Enter') {
clicked = !clicked;
await tick();
}
dispatch('keydown', event);
}
$: _class = cx(
'--link',
'--tile',
'--tile--clickable',
clicked && '--tile--is-clicked',
light && '--tile--light',
className
);
</script>
<a {...props} class={_class} on:click={handleClick} on:keydown={handleKeyDown} {href} {rel}>
<slot />
</a>