Skip to content

Commit

Permalink
Got Snackbars and colors mostly working
Browse files Browse the repository at this point in the history
  • Loading branch information
c0bra committed Jun 6, 2019
1 parent f25d3ce commit 39ebe08
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 10 deletions.
154 changes: 154 additions & 0 deletions docs/src/routes/components/jsdocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,160 @@
"Modal": [],
"Notice": [],
"Notices": [],
"Snackbar": [
{
"meta": {
"filename": "Snackbar.svelte",
"lineno": 7,
"columnno": 2,
"path": "src/components/Snackbar"
},
"description": "Text or html message for snackbar",
"type": [
"String"
],
"name": "message",
"_isSvelteDoc": true,
"_svelteProps": {
"type": {
"names": [
"String"
]
},
"name": "message"
},
"kind": "prop",
"longname": "module:Snackbar~message",
"scope": "inner",
"memberof": "module:Snackbar",
"___s": true
},
{
"meta": {
"filename": "Snackbar.svelte",
"lineno": 12,
"columnno": 2,
"path": "src/components/Snackbar"
},
"description": "Duration snackbar will remain on screen",
"type": [
"Number"
],
"optional": true,
"defaultvalue": 3500,
"name": "duration",
"_isSvelteDoc": true,
"_svelteProps": {
"type": {
"names": [
"Number"
]
},
"optional": true,
"defaultvalue": 3500,
"name": "duration"
},
"kind": "prop",
"longname": "module:Snackbar~duration",
"scope": "inner",
"memberof": "module:Snackbar",
"___s": true
},
{
"meta": {
"filename": "Snackbar.svelte",
"lineno": 17,
"columnno": 2,
"path": "src/components/Snackbar"
},
"description": "Where the snackbar will show on the screen",
"type": [
"String"
],
"optional": true,
"defaultvalue": "is-bottom-right",
"name": "position",
"_isSvelteDoc": true,
"_svelteProps": {
"type": {
"names": [
"String"
]
},
"optional": true,
"defaultvalue": "is-bottom-right",
"name": "position"
},
"kind": "prop",
"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>",
"longname": "module:Snackbar~position",
"scope": "inner",
"memberof": "module:Snackbar",
"___s": true
},
{
"meta": {
"filename": "Snackbar.svelte",
"lineno": 23,
"columnno": 2,
"path": "src/components/Snackbar"
},
"description": "Type (color)",
"type": [
"String"
],
"optional": true,
"defaultvalue": "is-dark",
"name": "type",
"_isSvelteDoc": true,
"_svelteProps": {
"type": {
"names": [
"String"
]
},
"optional": true,
"defaultvalue": "is-dark",
"name": "type"
},
"kind": "prop",
"values": "<code>is-white</code>, <code>is-black</code>, <code>is-light</code>, <code>is-dark</code>, <code>is-primary</code>, <code>is-info</code>, <code>is-success</code>, <code>is-warning</code>, <code>is-danger</code>",
"longname": "module:Snackbar~type",
"scope": "inner",
"memberof": "module:Snackbar",
"___s": true
},
{
"meta": {
"filename": "Snackbar.svelte",
"lineno": 29,
"columnno": 2,
"path": "src/components/Snackbar"
},
"description": "Background type (any of the Bulma <code>has-background-</code> classes will work)",
"type": [
"String"
],
"optional": true,
"name": "background",
"_isSvelteDoc": true,
"_svelteProps": {
"type": {
"names": [
"String"
]
},
"optional": true,
"name": "background"
},
"kind": "prop",
"values": "<code>has-background-*</code>",
"longname": "module:Snackbar~background",
"scope": "inner",
"memberof": "module:Snackbar",
"___s": true
}
],
"Toast": [
{
"meta": {
Expand Down
56 changes: 56 additions & 0 deletions docs/src/routes/components/snackbar.svelte
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} />
4 changes: 2 additions & 2 deletions docs/static/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"background_color": "#ffffff",
"theme_color": "#333333",
"name": "TODO",
"short_name": "TODO",
"name": "Svelma",
"short_name": "Svelma",
"display": "minimal-ui",
"start_url": "/",
"icons": [
Expand Down
7 changes: 4 additions & 3 deletions src/components/Notice.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
export let type = 'is-dark'
export let position = 'is-top'
export let duration = 2000
export let transitionOut = true

let el
let parent
Expand All @@ -24,7 +25,7 @@

$: transitionY = ~position.indexOf('is-top') ? -200 : 200

function close() {
export function close() {
active = false
}

Expand Down Expand Up @@ -63,7 +64,7 @@
chooseParent()

timer = setTimeout(() => {
close()
// close()
}, duration)
})
</script>
Expand Down Expand Up @@ -95,7 +96,7 @@
class="notice {position}"
aria-hidden={!active}
in:fly={{ y: transitionY }}
out:fade
out:fade={{ duration: transitionOut ? 400 : 0 }}
on:outroend={remove}
bind:this={el}>

Expand Down
2 changes: 1 addition & 1 deletion src/components/Notices.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
flex-direction: column-reverse;
}

[class*='has-background-'] * {
[class*='has-background-'] .text {
color: transparent !important;
filter: invert(1) brightness(2.5) grayscale(1) contrast(9);
background: inherit;
Expand Down
107 changes: 107 additions & 0 deletions src/components/Snackbar/Snackbar.svelte
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>
Loading

0 comments on commit 39ebe08

Please sign in to comment.