Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround for a11y, add icons, small Toast fixes #7

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 56 additions & 43 deletions components/Toast/Toast.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
.toast {
font-size: 14px;
font-family: "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Hiragino Kaku Gothic Pro", Meiryo, "Malgun Gothic", sans-serif;
background: hsla(192, 55%, 42%, 1);
/* border: .1rem solid #ededed; */
border-radius: .3rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
display: flex;
align-items: center;
min-width: 320px;
width: 33vw;
color: #fff;
display: block;
padding: 1.4rem;
width: 100%;
font-size: 14px;
font-family: "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Hiragino Kaku Gothic Pro", Meiryo, "Malgun Gothic", sans-serif;
margin-bottom: 20px;
border-radius: .3rem;
animation: toast-in-anim 0.3s;
}

.toast-success {
Expand All @@ -25,65 +29,74 @@
color: #fff;
}

.toast .btn-clear {
color: #fff;
float: right;
.toast-icon {
fill: white;
height: 24px;
width: 24px;
border-radius: 48px;
padding: 0;
}

.toast .btn:not(.btn-clear) {
float: right;
padding: 5px 10px;
background: rgba(255,255,255,0.75)
padding: 3px;
flex-shrink: 0;
}

.app-toast-center .toast .btn-clear{
height: 24px;
width: 24px;
border-radius: 48px;
}

.show-outline .toast .btn:focus {
outline: none;
box-shadow: 0 0 0 2px #fff;
.toast p {
margin: 0;
padding: 0;
}

.btn {
.toast-btn {
position: relative;
-webkit-appearance: none;
background: white;
border: none;
border-radius: .3rem;
cursor: pointer;
display: inline-block;
outline: 0;
text-align: center;
text-decoration: none;
user-select: none;
vertical-align: middle;
white-space: nowrap;
transition-duration: .2s;
margin-left: auto;
flex-shrink: 0;
}

.btn-clear {
.toast-btn:focus {
outline: none;
box-shadow: 0 0 0 2px #fff;
}

.toast-btn.dismiss-btn {
fill: #fff;
padding: 0;
height: 24px;
width: 24px;
border-radius: 48px;
background: transparent;
border: 0;
color: #666;
margin-left: .3rem;
opacity: .45;
padding: 0;
}
.btn-clear:hover {
opacity: .85;
}
.btn-clear::before {
content: '\00d7';
font-size: 2rem;

.toast-btn.dismiss-btn:hover,
.toast-btn.dismiss-btn:focus {
opacity: .85;
}

button:active {
transform: translateY(1px)
.toast-btn.dismiss-btn .dismiss-btn-icon {
outline: 0;
}

.toast-btn.action-btn {
padding: 8px 16px;
background: white;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
}

.toast-btn:active {
transform: translateY(1px);
}

@keyframes toast-in-anim {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
1 change: 0 additions & 1 deletion components/Toast/Toast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as React from 'react'
export interface IToast {
id: string
type: string
icon: string
message: string
}

Expand Down
38 changes: 18 additions & 20 deletions components/Toast/Toast.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import React, { Component } from 'react'

import Icon from '@mdi/react'
import { mdiCheck, mdiAlert, mdiAlertOctagon, mdiInformationOutline, mdiClose } from '@mdi/js'

import './Toast.css'

const IconMap = {
success: mdiCheck,
warning: mdiAlert,
danger: mdiAlertOctagon,
}

class Toast extends Component {
componentDidMount() {
if (!this.props.toast.callback && this.props.toast.type !== 'danger') {
Expand All @@ -22,30 +31,19 @@ class Toast extends Component {
className={`toast toast-${toast.type}`}
role="alert"
>
{toast.icon && (
<i className={`icon fa ${toast.icon}`} />
)}
<span>{toast.message}</span>
<Icon className="toast-icon" path={IconMap[toast.type] ? IconMap[toast.type] : mdiInformationOutline} />
<p>{toast.message}</p>
{toast.callback
? <button className="btn btn-primary action" onClick={() => this.callback(toast.id)}>{toast.callback.label || 'Fix this'}</button>
: <button className="btn btn-clear" onClick={() => this.props.dismissToast(toast.id)} /> }
? <button className="toast-btn action-btn" onClick={() => this.callback(toast.id)}>{toast.callback.label || 'Fix this'}</button>
: (
<button className="toast-btn dismiss-btn" aria-label="close" onClick={() => this.props.dismissToast(toast.id)}>
<Icon className="dismiss-btn-icon" path={mdiClose} tabIndex="-1" />
</button>
)
}
</div>
)
}
}

// const types = {
// toast: {
// id: string
// type: string,
// icon: string,
// message: string,
// callback: {
// fn: fn,
// label: string
// },
// },
// dismissToast: fn (required)
// }

export default Toast
24 changes: 1 addition & 23 deletions components/ToastCenter/ToastCenter.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,4 @@
max-height: 100vh;
padding-top: 32px;
overflow: auto;
}
.toast {
min-width: 320px;
width: 33vw;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
margin-bottom: 20px;
animation: toast-in-anim 0.3s;
}
.icon.fa {
margin-right: 10px;
}
.action {
margin-left: 32px;
}

@keyframes toast-in-anim {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
}
15 changes: 0 additions & 15 deletions components/ToastCenter/ToastCenter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,4 @@ class ToastCenter extends Component {
}
}

// const types = {
// id: string,
// toast: {
// id: string,
// type: string,
// icon: string,
// message: string,
// callback: {
// fn: function,
// label: string
// },
// },
// dismissToast: fn (required)
// }

export default ToastCenter
Loading