Skip to content

Commit

Permalink
feat: Add Toast example and handle ToastManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 3, 2020
1 parent 797d958 commit 7d619d4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/components/ComponentExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CSS_BUNDLE } from '../utils/sdk';
const TRAILING_SEMI = /;\s*$/;

const EXAMPLE_CSS = `
.nr1-Component-Example {
.nr1-ComponentExample {
line-height: 1.36;
font-weight: 400;
background-color: #fff;
Expand All @@ -19,6 +19,20 @@ const EXAMPLE_CSS = `
font-family: Open Sans,Segoe UI,Tahoma,sans-serif;
}
.nr1-ComponentExample-ToastManager > div {
position: fixed;
top: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
padding-top: 16px;
padding-right: 16px;
pointer-events: none;
z-index: 200;
min-height: 9999px;
}
.nr1-Docs-prettify > * {
margin-right: 0.5rem;
}
Expand All @@ -42,8 +56,9 @@ const EXAMPLE_CSS = `
}
`;

const ComponentExample = ({ className, example }) => {
const ComponentExample = ({ className, example, useToastManager }) => {
const [stylesLoaded, setStylesLoaded] = useState(false);
const ToastManager = window.__NR1_SDK__.ToastManager;
let formattedCode;

try {
Expand Down Expand Up @@ -75,8 +90,13 @@ const ComponentExample = ({ className, example }) => {
onLoad={() => setStylesLoaded(true)}
/>
<style type="text/css">{EXAMPLE_CSS}</style>
{useToastManager && (
<div className="nr1-ComponentExample-ToastManager">
<ToastManager />
</div>
)}
{stylesLoaded ? (
<LivePreview className="nr1-Component-Example" />
<LivePreview className="nr1-ComponentExample" />
) : (
'Loading...'
)}
Expand Down
4 changes: 4 additions & 0 deletions src/data/sidenav.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
{
"displayName": "Icon",
"url": "/components/icon"
},
{
"displayName": "Toast",
"url": "/components/toast"
}
]
}
Expand Down
7 changes: 7 additions & 0 deletions src/markdown-pages/toast.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
path: '/components/toast'
title: 'Toast'
description: 'A Toast component!'
component: 'Toast'
template: 'ReferenceTemplate'
---
1 change: 1 addition & 0 deletions src/templates/ReferenceTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const ReferenceTemplate = ({ data }) => {
{examples.map((example, i) => (
<ComponentExample
key={i}
useToastManager={component === 'Toast'}
className={styles.componentExample}
example={example}
/>
Expand Down
14 changes: 14 additions & 0 deletions src/templates/ReferenceTemplate.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,17 @@
.section:not(:last-child) {
margin-bottom: 2rem;
}

.toastManager > div {
position: fixed;
top: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
padding-top: 16px;
padding-right: 16px;
pointer-events: none;
z-index: 200;
min-height: 9999px;
}

0 comments on commit 7d619d4

Please sign in to comment.