-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from metonym/Avatar
feat: complete Avatar
- Loading branch information
Showing
8 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script> | ||
export let small = false; | ||
export let alt = undefined; | ||
export let src = undefined; | ||
export let parent = false; | ||
export let child = false; | ||
export let width = 72; | ||
export let height = 72; | ||
import { getContext, onMount } from "svelte"; | ||
const id = Math.random().toString(36); | ||
const ctx = getContext("AvatarStack"); | ||
onMount(() => { | ||
if (ctx) { | ||
ctx.add({ id }); | ||
} | ||
return () => { | ||
if (ctx) { | ||
ctx.remove({ id }); | ||
} | ||
}; | ||
}); | ||
$: if (small) { | ||
width = 32; | ||
height = 32; | ||
} | ||
$: if (parent) { | ||
width = 48; | ||
height = 48; | ||
} | ||
$: if (child) { | ||
width = 20; | ||
height = 20; | ||
} | ||
</script> | ||
|
||
<img | ||
{...$$restProps} | ||
class:avatar={true} | ||
class:avatar-small={small} | ||
class:avatar-child={child} | ||
{alt} | ||
{src} | ||
{width} | ||
{height} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
import Avatar from "./Avatar.svelte"; | ||
</script> | ||
|
||
<div | ||
{...$$restProps} | ||
class:avatar-parent-child={true} | ||
class:d-inline-flex={true}> | ||
<slot /> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script> | ||
export let title = "Avatar stack title"; | ||
export let align = "left"; // 'left' | 'right' | ||
import { setContext } from "svelte"; | ||
import { writable } from "svelte/store"; | ||
const avatars = writable([]); | ||
setContext("AvatarStack", { | ||
add: item => { | ||
avatars.update(_ => [..._, item]); | ||
}, | ||
remove: item => { | ||
avatars.update(_ => _.filter(avatar => avatar.id !== item.id)); | ||
} | ||
}); | ||
</script> | ||
|
||
<div | ||
class:AvatarStack={true} | ||
class:AvatarStack--two={$avatars.length === 2} | ||
class:AvatarStack--three-plus={$avatars.length > 2} | ||
class:AvatarStack--right={align === 'right'}> | ||
<div | ||
class="AvatarStack-body tooltipped" | ||
class:tooltipped-se={align === 'left'} | ||
class:tooltipped-align-left-1={align === 'left'} | ||
class:tooltipped-sw={align === 'right'} | ||
class:tooltipped-align-right-1={align === 'right'} | ||
aria-label={title}> | ||
<slot /> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<script> | ||
export let size = "small"; // 'small' | 'medium' | 'large' | ||
export let href = undefined; | ||
</script> | ||
|
||
{#if href} | ||
<a | ||
{...$$restProps} | ||
class:CircleBadge={true} | ||
class:CircleBadge--small={size === 'small'} | ||
class:CircleBadge--medium={size === 'medium'} | ||
class:CircleBadge--large={size === 'large'} | ||
{href} | ||
on:click> | ||
<slot props={{ class: 'CircleBadge-icon' }} /> | ||
</a> | ||
{:else} | ||
<div | ||
{...$$restProps} | ||
class:CircleBadge={true} | ||
class:CircleBadge--small={size === 'small'} | ||
class:CircleBadge--medium={size === 'medium'} | ||
class:CircleBadge--large={size === 'large'} | ||
on:click> | ||
<slot props={{ class: 'CircleBadge-icon' }} /> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
export let title = "Title"; | ||
</script> | ||
|
||
<div {...$$restProps} class:DashedConnection={true}> | ||
<ul class="d-flex list-style-none flex-justify-between" aria-label={title}> | ||
<slot /> | ||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters