-
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.
First attempt for toast that shows on SW update
Housekeeping And other stuff
- Loading branch information
Marvin Heilemann
committed
Feb 3, 2020
1 parent
a582121
commit 6201756
Showing
28 changed files
with
225 additions
and
121 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -1,10 +1,13 @@ | ||
const React = require('react') | ||
|
||
const { ThemeProvider } = require('../src/store/theme') | ||
const { HistoryProvider } = require('../src/store/history') | ||
const { ThemeProvider } = require('../src/provider/theme') | ||
const { HistoryProvider } = require('../src/provider/history') | ||
const { ToastProvider } = require('../src/provider/toast') | ||
|
||
module.exports = ({ element }) => ( | ||
<ThemeProvider> | ||
<HistoryProvider>{element}</HistoryProvider> | ||
<HistoryProvider> | ||
<ToastProvider>{element}</ToastProvider> | ||
</HistoryProvider> | ||
</ThemeProvider> | ||
) |
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 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
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
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,40 @@ | ||
import React, { useEffect } from 'react' | ||
|
||
import Icon from './Icon' | ||
|
||
function Toast({ children, type, labelClose, labelAccept, onClose, onAccept }) { | ||
useEffect(() => { | ||
if (type === 'toast') { | ||
// TODO: add progress bar | ||
const id = setTimeout(() => onClose(), 3000) | ||
return () => clearTimeout(id) | ||
} | ||
}) | ||
|
||
return type === 'prompt' ? ( | ||
<div className="toast"> | ||
<div className="toast__text">{children}</div> | ||
<div className="toast__actions"> | ||
<button onClick={() => onClose()} className="btn btn--small"> | ||
{labelClose} | ||
</button> | ||
<button onClick={() => onAccept()} className="btn btn--small"> | ||
{labelAccept} | ||
</button> | ||
</div> | ||
</div> | ||
) : ( | ||
<div className="toast"> | ||
<div className="toast__text">{children}</div> | ||
<button | ||
onClick={() => onClose()} | ||
className="toast__btn-close reset" | ||
title={labelClose} | ||
> | ||
<Icon name="close" /> | ||
</button> | ||
</div> | ||
) | ||
} | ||
|
||
export default Toast |
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,11 @@ | ||
import { useContext } from 'react' | ||
|
||
import { ToastContext } from '../provider/toast' | ||
|
||
function useToast() { | ||
const { add, remove } = useContext(ToastContext) | ||
|
||
return { add, remove } | ||
} | ||
|
||
export default useToast |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
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 @@ | ||
import React, { createContext, useState } from 'react' | ||
import uniqueString from 'unique-string' | ||
import Toast from '../components/Toast' | ||
|
||
const ToastContext = createContext([]) | ||
const ToastConsumer = ToastContext.Consumer | ||
|
||
function ToastProvider({ children }) { | ||
const [toasts, setToasts] = useState([]) | ||
|
||
const toastOptions = { | ||
type: 'toast', // toast/prompt | ||
labelClose: 'Close', | ||
labelAccept: 'Accept', | ||
onClose: () => {}, | ||
onAccept: () => {}, | ||
} | ||
|
||
const add = (content, options) => { | ||
const id = uniqueString() | ||
options = { ...toastOptions, ...options } | ||
setToasts([...toasts, { id, content, options }]) | ||
return id // toast id | ||
} | ||
const remove = (id) => { | ||
setToasts(toasts.filter((t) => t.id !== id)) | ||
} | ||
|
||
return ( | ||
<ToastContext.Provider value={{ add, remove, toasts }}> | ||
{children} | ||
|
||
<div className="toasts-wrapper"> | ||
{toasts.map((t) => ( | ||
<Toast | ||
key={t.id} | ||
type={t.options.type} | ||
labelClose={t.options.labelClose} | ||
labelAccept={t.options.labelAccept} | ||
onClose={() => t.options.onClose(() => remove(t.id))} | ||
onAccept={() => t.options.onAccept(() => remove(t.id))} | ||
> | ||
{t.content} | ||
</Toast> | ||
))} | ||
</div> | ||
</ToastContext.Provider> | ||
) | ||
} | ||
|
||
export { ToastProvider, ToastConsumer, ToastContext } |
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
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,4 @@ | ||
#gatsby-noscript { | ||
position: fixed; | ||
font-size: var(--text-xxl); | ||
} |
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,44 @@ | ||
.toasts-wrapper { | ||
display: flex; | ||
position: fixed; | ||
bottom: 0; | ||
left: 0px; | ||
flex-direction: column; | ||
margin: var(--spacing-sm); | ||
} | ||
|
||
.toast { | ||
position: relative; | ||
width: 300px; | ||
max-width: 100%; | ||
margin-top: var(--spacing-sm); | ||
padding: var(--spacing-sm); | ||
background: var(--color-primary); | ||
color: var(--color-dark); | ||
|
||
&__text { | ||
font-size: var(--text-md); | ||
} | ||
|
||
&__actions { | ||
display: flex; | ||
margin-top: var(--spacing-sm); | ||
column-gap: var(--spacing-xs); | ||
|
||
button { | ||
flex: 1; | ||
color: var(--text-color-dark); | ||
} | ||
} | ||
|
||
&__btn-close { | ||
display: flex; | ||
position: absolute; | ||
top: var(--spacing-xs); | ||
right: var(--spacing-xs); | ||
|
||
.icon { | ||
--icon-size: 12px; | ||
} | ||
} | ||
} |
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,2 @@ | ||
/* globals workbox */ | ||
/* eslint-disable no-restricted-globals */ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.