-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Got Snackbars and colors mostly working
- Loading branch information
Showing
9 changed files
with
349 additions
and
10 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 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,56 @@ | ||
<script context="module"> | ||
export async function preload() { | ||
const res = await this.fetch(`components/snackbar.json`); | ||
const jsdoc = await res.json(); | ||
|
||
return { jsdoc }; | ||
} | ||
</script> | ||
|
||
<script> | ||
import { Button, Snackbar } from 'svelma' | ||
import DocHeader from '../../components/DocHeader.svelte' | ||
import Example from '../../components/Example.svelte' | ||
import JSDoc from '../../components/JSDoc.svelte' | ||
|
||
export let jsdoc | ||
|
||
function open(props) { | ||
Snackbar.create({ message: 'I am a snackbar message', ...props }) | ||
} | ||
</script> | ||
|
||
<style> | ||
.buttons { | ||
display: flex; | ||
justify-content: flex-start; | ||
flex-wrap: wrap; | ||
} | ||
</style> | ||
|
||
<DocHeader title="Snackbar" subtitle="Bigger than a toast, smaller than a dialog" /> | ||
|
||
<Example code={`<script> | ||
import { Button, Toast } from 'svelma' | ||
|
||
function open(type, position) { | ||
Toast.create({ message: 'I am a toast', type, position }) | ||
} | ||
</script> | ||
|
||
<Button on:click={() => open()}>Toast</Button> | ||
<Button type="is-success" on:click={() => open('is-success')}>Success</Button> | ||
<Button type="is-danger" on:click={() => open('is-danger', 'is-bottom-right')}>Bottom Right</Button> | ||
<Button type="is-primary" on:click={() => open('is-primary', 'is-top', 'has-background-grey-lighter')}>Custom Background</Button>`}> | ||
<div slot="preview"> | ||
<div class="buttons"> | ||
<Button on:click={() => open()}>Default Snackbar</Button> | ||
<Button type="is-success" on:click={() => open({ type: 'is-success' })}>Success</Button> | ||
<Button type="is-danger" on:click={() => open({ type: 'is-danger', actionText: 'retry', position: 'is-top-right' })}>Top Right</Button> | ||
<Button type="is-primary" on:click={() => open({ background: 'has-background-grey-lighter' })}>Custom Background</Button> | ||
</div> | ||
</div> | ||
</Example> | ||
|
||
|
||
<JSDoc {jsdoc} /> |
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 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 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 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,107 @@ | ||
<script> | ||
import { createEventDispatcher, onDestroy, onMount } from 'svelte' | ||
import { fly, fade } from 'svelte/transition' | ||
import Notice, { fitlerProps } from '../Notice.svelte' | ||
|
||
/** Text or html message for snackbar | ||
* @svelte-prop {String} message | ||
* */ | ||
export let message | ||
|
||
/** Duration snackbar will remain on screen | ||
* @svelte-prop {Number} [duration=3500] | ||
* */ | ||
export let duration = 3500 | ||
|
||
/** Where the snackbar will show on the screen | ||
* @svelte-prop {String} [position=is-bottom-right] | ||
* @values <code>is-top</code>, <code>is-bottom</code>, <code>is-top-left</code>, <code>is-top-right</code>, <code>is-bottom-left</code>, <code>is-bottom-right</code> | ||
* */ | ||
export let position = 'is-bottom-right' | ||
|
||
/** Type (color) | ||
* @svelte-prop {String} [type=is-dark] | ||
* @values $$colors$$ | ||
* */ | ||
export let type = 'is-primary' | ||
|
||
/** Background type (any of the Bulma <code>has-background-</code> classes will work) | ||
* @svelte-prop {String} [background] | ||
* @values <code>has-background-*</code> | ||
* */ | ||
export let background = '' | ||
|
||
export let actionText = 'OK' | ||
|
||
export let onAction = () => {} | ||
|
||
let notice | ||
|
||
function action() { | ||
Promise.resolve(onAction()) | ||
.then(() => notice.close()) | ||
} | ||
|
||
onMount(() => { | ||
if (typeof onAction !== 'function') throw new Error(`onAction ${onAction} is not a function`) | ||
}) | ||
|
||
// $: newBackground = background | ||
$: newType = type && type.replace(/^is-(.*)/, 'has-text-$1') | ||
$: props = { ...fitlerProps($$props), position, duration } | ||
</script> | ||
|
||
<style lang="sass"> | ||
.snackbar { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: space-around; | ||
border-radius: 4px; | ||
margin: 0.5em 0; | ||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04); /* super subtle... */ | ||
pointer-events: auto; | ||
min-height: 3em; | ||
|
||
.text { | ||
margin: .5em 1em; | ||
} | ||
|
||
.action { | ||
margin-left: auto; | ||
padding: 0.5em; | ||
padding-left: 0; | ||
|
||
.button { | ||
font-weight: 600; | ||
text-transform: uppercase; | ||
background: transparent; | ||
border: transparent; | ||
position: relative; | ||
|
||
&:hover::after { | ||
content: ''; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
background: rgba(0, 0, 0, 0.1); | ||
} | ||
} | ||
} | ||
} | ||
</style> | ||
|
||
<Notice {...props} bind:this={notice} transitionOut={false}> | ||
<div class="snackbar {background}" class:has-background-dark={!background} role="alert"> | ||
<div class="text"> <!-- NOTE: this extra div is for dynamic text styling with background-clip --> | ||
{@html message} | ||
</div> | ||
|
||
{#if actionText} | ||
<div class="action" on:click={action}> | ||
<button class="button {newType}">{ actionText }</button> | ||
</div> | ||
{/if} | ||
</div> | ||
</Notice> |
Oops, something went wrong.