From 23b4cd538053df91ee5a9b54b1b44ebd63752a95 Mon Sep 17 00:00:00 2001 From: Artem Tarasov Date: Thu, 11 Mar 2021 19:03:17 +0300 Subject: [PATCH] Web: Components: added story for Toast --- .../asc-web-components/.storybook/main.js | 1 + .../theme-provider/theme-provider.stories.js | 92 -------- .../toast/all.toast.stories.js | 139 ------------ packages/asc-web-components/toast/index.js | 5 + .../asc-web-components/toast/toast.stories.js | 206 +++++++++++++----- .../toast/toast.stories.mdx | 81 +++++++ 6 files changed, 243 insertions(+), 281 deletions(-) delete mode 100644 packages/asc-web-components/toast/all.toast.stories.js create mode 100644 packages/asc-web-components/toast/toast.stories.mdx diff --git a/packages/asc-web-components/.storybook/main.js b/packages/asc-web-components/.storybook/main.js index a00dc4e1a0..406508e015 100644 --- a/packages/asc-web-components/.storybook/main.js +++ b/packages/asc-web-components/.storybook/main.js @@ -53,6 +53,7 @@ module.exports = { "../text-input/*.stories.@(js|mdx)", "../textarea/*.stories.@(js|mdx)", "../theme-provider/*.stories.@(js|mdx)", + "../toast/*.stories.@(js|mdx)", ], addons: [ "@storybook/addon-links", diff --git a/packages/asc-web-components/theme-provider/theme-provider.stories.js b/packages/asc-web-components/theme-provider/theme-provider.stories.js index 28b56b3a86..d69a9e77ae 100644 --- a/packages/asc-web-components/theme-provider/theme-provider.stories.js +++ b/packages/asc-web-components/theme-provider/theme-provider.stories.js @@ -92,95 +92,3 @@ const DarkTemplate = (args) => { ); }; export const DarkTheme = DarkTemplate.bind({}); - -/* -import { storiesOf } from "@storybook/react"; -import ThemeProvider from "."; -import withReadme from "storybook-readme/with-readme"; -import Readme from "./README.md"; -import { BooleanValue } from "react-values"; -import Box from "../Box"; -import Text from "../Text"; -import JSONPretty from "react-json-pretty"; -import Base from "../themes/base"; -import Heading from "../Heading"; -import Checkbox from "../Checkbox"; - -const LightTheme = { - backgroundColor: "#FFF", - fontFamily: "sans-serif", - text: { color: "#333" }, -}; - -const DarkTheme = { - backgroundColor: "#1F2933", - fontFamily: "Open Sans", - text: { color: "#E4E7EB" }, -}; - -storiesOf("Components|ThemeProvider", module) - .addDecorator(withReadme(Readme)) - .add("Default", () => ( - - {({ value, toggle }) => ( - - - toggle(e.target.value)} - label={value ? "Dark" : "Light"} - /> - - - )} - - )); -storiesOf("Components|ThemeProvider", module) - .addParameters({ options: { showAddonPanel: false } }) - .add("Base theme", () => { - const jsonTheme = { - main: "line-height:1.5;background:#FFF;overflow:auto;", - error: "line-height:1.5;background:#FFF;overflow:auto;", - key: "color:#444;", - string: "color:#00873D;", - }; - return ( - - - Base theme: - - - - - - ); - }); -storiesOf("Components|ThemeProvider", module) - .addParameters({ options: { showAddonPanel: false } }) - .add("Dark theme", () => { - const jsonTheme = { - main: "line-height:1.5;background:#1F2933;overflow:auto;", - error: "line-height:1.5;background:#1F2933;overflow:auto;", - key: "color:#1F97CA;", - string: "color:#00873D;", - }; - return ( - - - Dark theme: - - - - - - ); - }); -*/ diff --git a/packages/asc-web-components/toast/all.toast.stories.js b/packages/asc-web-components/toast/all.toast.stories.js deleted file mode 100644 index 91cd8ac54e..0000000000 --- a/packages/asc-web-components/toast/all.toast.stories.js +++ /dev/null @@ -1,139 +0,0 @@ -import React from "react"; -import ReactDOM from "react-dom"; -import { storiesOf } from "@storybook/react"; -import Toast from "."; -import toastr from "./toastr"; -import Link from "../link"; - -class TostWrapper extends React.Component { - componentDidMount() { - this.toastContainer = document.createElement("div"); - this.toastContainer.setAttribute("id", "toast-container"); - document.body.appendChild(this.toastContainer); - - ReactDOM.render( - , - document.getElementById("toast-container"), - () => { - toastr.success( - "Demo text for success Toast closes in 30 seconds or on click", - null, - 30000 - ); - toastr.error( - "Demo text for error Toast closes in 28 seconds or on click", - null, - 28000 - ); - toastr.warning( - "Demo text for warning Toast closes in 25 seconds or on click", - null, - 25000 - ); - toastr.info( - "Demo text for info Toast closes in 15 seconds or on click", - null, - 15000 - ); - toastr.success( - "Demo text for success Toast with title closes in 12 seconds or on click", - "Demo title", - 12000 - ); - toastr.error( - "Demo text for error Toast with title closes in 10 seconds or on click", - "Demo title", - 10000 - ); - toastr.warning( - "Demo text for warning Toast with title closes in 8 seconds or on click", - "Demo title", - 8000 - ); - toastr.info( - "Demo text for info Toast with title closes in 6 seconds or on click", - "Demo title", - 6000 - ); - toastr.success( - "Demo text for success manual closed Toast", - null, - 0, - true, - true - ); - toastr.error( - "Demo text for error manual closed Toast", - null, - 0, - true, - true - ); - toastr.warning( - "Demo text for warning manual closed Toast", - null, - 0, - true, - true - ); - toastr.info( - "Demo text for info manual closed Toast", - null, - 0, - true, - true - ); - toastr.success( - <> - Demo text for success manual closed Toast with title and contains{" "} - - , - "Demo title", - 0, - true, - true - ); - toastr.error( - "Demo text for error manual closed Toast with title", - "Demo title", - 0, - true, - true - ); - toastr.warning( - "Demo text for warning manual closed Toast with title", - "Demo title", - 0, - true, - true - ); - toastr.info( - "Demo text for info manual closed Toast with title", - "Demo title", - 0, - true, - true - ); - } - ); - } - - componentWillUnmount() { - toastr.clear(); - ReactDOM.unmountComponentAtNode(this.toastContainer); - document.body.removeChild(this.toastContainer); - } - - render() { - return <>; - } -} - -storiesOf("Components|Toast", module) - .addParameters({ options: { showAddonPanel: false } }) - .add("all", () => ); diff --git a/packages/asc-web-components/toast/index.js b/packages/asc-web-components/toast/index.js index 0cec0fa0e9..50f5b7e9ee 100644 --- a/packages/asc-web-components/toast/index.js +++ b/packages/asc-web-components/toast/index.js @@ -37,11 +37,16 @@ const Toast = (props) => { Toast.propTypes = { autoClosed: PropTypes.bool, + /** Accepts class */ className: PropTypes.string, + /** Accepts id */ id: PropTypes.string, + /** Accepts css style */ style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]), text: PropTypes.string, + /** Title inside a toast */ title: PropTypes.string, + /** Define color and icon of toast */ type: PropTypes.oneOf(["success", "error", "warning", "info"]).isRequired, }; diff --git a/packages/asc-web-components/toast/toast.stories.js b/packages/asc-web-components/toast/toast.stories.js index 498d458255..a4be4d33a4 100644 --- a/packages/asc-web-components/toast/toast.stories.js +++ b/packages/asc-web-components/toast/toast.stories.js @@ -1,54 +1,160 @@ -import React from "react"; -import { storiesOf } from "@storybook/react"; -import Toast from "."; +import React, { useEffect } from "react"; +import ReactDOM from "react-dom"; +import Toast from "./"; import toastr from "./toastr"; -import Readme from "./README.md"; -import { - text, - boolean, - withKnobs, - select, - number, -} from "@storybook/addon-knobs/react"; -import withReadme from "storybook-readme/with-readme"; -import Section from "../../../.storybook/decorators/section"; +import Button from "../button"; +import Link from "../link"; -const typeToast = ["success", "error", "warning", "info"]; +const BaseTemplate = ({ type, data, title, timeout, withCross, ...args }) => { + return ( + <> + + - - +export const basic = BaseTemplate.bind({}); +basic.args = { + type: "success", + data: "Demo text for Toast", + title: "Demo title", + withCross: false, + timeout: 5000, +}; + +const AllTemplate = (args) => { + const renderAllToast = () => { + toastr.success( + "Demo text for success Toast closes in 30 seconds or on click", + null, + 30000 ); - }); + toastr.error( + "Demo text for error Toast closes in 28 seconds or on click", + null, + 28000 + ); + toastr.warning( + "Demo text for warning Toast closes in 25 seconds or on click", + null, + 25000 + ); + toastr.info( + "Demo text for info Toast closes in 15 seconds or on click", + null, + 15000 + ); + toastr.success( + "Demo text for success Toast with title closes in 12 seconds or on click", + "Demo title", + 12000 + ); + toastr.error( + "Demo text for error Toast with title closes in 10 seconds or on click", + "Demo title", + 10000 + ); + toastr.warning( + "Demo text for warning Toast with title closes in 8 seconds or on click", + "Demo title", + 8000 + ); + toastr.info( + "Demo text for info Toast with title closes in 6 seconds or on click", + "Demo title", + 6000 + ); + toastr.success( + "Demo text for success manual closed Toast", + null, + 0, + true, + true + ); + toastr.error( + "Demo text for error manual closed Toast", + null, + 0, + true, + true + ); + toastr.warning( + "Demo text for warning manual closed Toast", + null, + 0, + true, + true + ); + toastr.info("Demo text for info manual closed Toast", null, 0, true, true); + toastr.success( + <> + Demo text for success manual closed Toast with title and contains{" "} + + , + "Demo title", + 0, + true, + true + ); + toastr.error( + "Demo text for error manual closed Toast with title", + "Demo title", + 0, + true, + true + ); + toastr.warning( + "Demo text for warning manual closed Toast with title", + "Demo title", + 0, + true, + true + ); + toastr.info( + "Demo text for info manual closed Toast with title", + "Demo title", + 0, + true, + true + ); + }; + return ( + <> + + +``` + +or + +```jsx +{toastr.success("Some text for toast")} +``` + +You can use simple html tags. For this action you should wrap your message by empty tags: + +```jsx + + +``` + +If your notification include only text in html tags or data in JSX tags, you can omit empty tags: + +```jsx + + +``` + +#### Other Options + +```js + + // Remove all toasts in your page programmatically + +```