mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
feat(components): add Tile
Supports #34 TODO: - remove exported props - compose TileGroup, SelectableTile, RadioTile components
This commit is contained in:
parent
f048e9ea4a
commit
46cb9aa44b
12 changed files with 472 additions and 2 deletions
42
src/components/Tile/ClickableTile.svelte
Normal file
42
src/components/Tile/ClickableTile.svelte
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue