diff --git a/src/Toast/ToastContainer.jsx b/src/Toast/ToastContainer.jsx
index 915a4e8b01..3bd6d82492 100644
--- a/src/Toast/ToastContainer.jsx
+++ b/src/Toast/ToastContainer.jsx
@@ -26,7 +26,7 @@ function ToastContainer({ position, className }) {
const portalDivRef = useRef(null);
const positionStyle = positionStyles[position] || positionStyles['bottom-left'];
- if (!portalDivRef.current) {
+ if (!portalDivRef.current && typeof document !== 'undefined') {
portalDivRef.current = document.createElement('div');
portalDivRef.current.setAttribute('class', 'toast-portal');
portalDivRef.current.setAttribute('role', 'alert');
diff --git a/www/src/components/CodeBlock.tsx b/www/src/components/CodeBlock.tsx
index b63c3e408a..5c28f37891 100644
--- a/www/src/components/CodeBlock.tsx
+++ b/www/src/components/CodeBlock.tsx
@@ -26,7 +26,7 @@ import HipsterIpsum from './exampleComponents/HipsterIpsum';
import ExamplePropsForm from './exampleComponents/ExamplePropsForm';
const {
- Collapsible, Toast, IconButton, Icon,
+ Collapsible, IconButton, Icon, toast, ToastContainer
} = ParagonReact;
export type CollapsibleLiveEditorTypes = {
@@ -117,14 +117,13 @@ function CodeBlock({
}: ICodeBlock) {
const intl = useIntl();
const language: any = className ? className.replace(/language-/, '') : 'jsx';
- const [showToast, setShowToast] = useState(false);
const [codeExample, setCodeExample] = useState(children);
const handleCodeChange = (e) => setCodeExample(e.target.value);
const handleCopyCodeExample = () => {
navigator.clipboard.writeText(codeExample);
- setShowToast(true);
+ toast({message: 'Code example copied to clipboard!', duration: 2000 });
};
if (live) {
@@ -160,13 +159,7 @@ function CodeBlock({
- setShowToast(false)}
- show={showToast}
- delay={2000}
- >
- Code example copied to clipboard!
-
+
);
}
diff --git a/www/src/components/IconsTable.tsx b/www/src/components/IconsTable.tsx
index a3f6a2a8c7..d288044c3f 100644
--- a/www/src/components/IconsTable.tsx
+++ b/www/src/components/IconsTable.tsx
@@ -1,7 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import PropTypes from 'prop-types';
import debounce from 'lodash.debounce';
-import { Icon, SearchField, Toast } from '~paragon-react';
+import { Icon, SearchField, ToastContainer, toast } from '~paragon-react';
import * as IconComponents from '~paragon-icons';
const WINDOW_HEIGHT = 2400;
@@ -66,7 +66,6 @@ function IconsTable({ iconNames }) {
const [tableWidth, setTableWidth] = useState(0);
const [data, setData] = useState({ iconsList: iconNames, rowsCount: ROWS_PER_WINDOW });
const [currentIcon, setCurrentIcon] = useState(iconNames[0]);
- const [showToast, setShowToast] = useState(false);
const currentIconImport = `import { ${currentIcon} } from '@edx/paragon/icons';`;
const { rowsCount, iconsList } = data;
@@ -74,7 +73,7 @@ function IconsTable({ iconNames }) {
const copyToClipboard = (content) => {
navigator.clipboard.writeText(content);
- setShowToast(true);
+ toast({ message: 'Copied to clipboard!', duration: 2000 });
global.analytics.track('openedx.paragon.docs.icons-table.selected-icon.copied', { name: currentIcon });
};
@@ -177,13 +176,7 @@ function IconsTable({ iconNames }) {
- setShowToast(false)}
- show={showToast}
- delay={2000}
- >
- Copied to clipboard!
-
+
>
);
}
diff --git a/www/src/pages/foundations/elevation.jsx b/www/src/pages/foundations/elevation.jsx
index 68d1421c56..77865f6b52 100644
--- a/www/src/pages/foundations/elevation.jsx
+++ b/www/src/pages/foundations/elevation.jsx
@@ -5,7 +5,8 @@ import {
Button,
Form,
Input,
- Toast,
+ ToastContainer,
+ toast,
Icon,
IconButtonWithTooltip,
} from '~paragon-react';
@@ -27,11 +28,9 @@ const controlsProps = [
];
function BoxShadowNode() {
- const [showToast, setShowToast] = useState(false);
-
const isBoxShadowCopied = (level, side) => {
navigator.clipboard.writeText(`@include pgn-box-shadow(${level}, "${side}");`);
- setShowToast(true);
+ toast({ message: 'Box-shadow copied to clipboard!', duration: 2000 });
};
const boxShadowCells = boxShadowLevels.map(level => (
@@ -55,14 +54,7 @@ function BoxShadowNode() {
return (
{ boxShadowCells }
- setShowToast(false)}
- show={showToast}
- delay={2000}
- >
- Box-shadow copied to clipboard!
-
+
);
}