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

docs: notifications addon PoC #2598

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion packages/core/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const getAddons = () => {
},
"storybook-addon-playground",
"@chromatic-com/storybook",
"@storybook/addon-storysource"
"@storybook/addon-storysource",
"./notifications-addon"
];

if (process.env.NODE_ENV !== "production") {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

const NotificationLink = ({ href, children }) => {
return (
<a href={href} style={{ color: "inherit" }}>
{children}
</a>
);
};

export default NotificationLink;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const NotificationText = ({ href, children }) => {
return <span style={{ color: "inherit" }}>{children}</span>;
};

export default NotificationText;
2 changes: 2 additions & 0 deletions packages/core/.storybook/notifications-addon/consts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const ADDON_ID = "@vibe/storybook-addon-notifications";
export const STORAGE_KEY = `${ADDON_ID}-dismissed`;
7 changes: 7 additions & 0 deletions packages/core/.storybook/notifications-addon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function managerEntries(entry = []) {
return [...entry, require.resolve("./manager.js")];
}

module.exports = {
managerEntries
};
47 changes: 47 additions & 0 deletions packages/core/.storybook/notifications-addon/manager.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import { addons } from "@storybook/manager-api";
import { ADDON_ID, STORAGE_KEY } from "./consts";
import NotificationLink from "./NotificationLink";
import NotificationText from "./NotificationText";

addons.register(ADDON_ID, api => {
const notifications = [
{
id: "welcome-v3",
content: {
headline: "Welcome to Vibe 3!",
subHeadline: (
<NotificationText>
This is our new major. If you're looking for Vibe v2 docs, please{" "}
<NotificationLink href="/v2">click here</NotificationLink>
</NotificationText>
)
}
},
{
id: "new-modal",
content: {
headline: "Did you got to check our new Modal?",
subHeadline: "Click here to go to the documentation"
},
link: "/docs/feedback-modal-new"
}
];

const dismissedNotifications = JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]");

notifications
.filter(({ id }) => !dismissedNotifications.includes(id))
.reverse()
.forEach(({ id, content, link }) => {
api.addNotification({
id,
content,
link,
onClear: options => {
if (!options.dismissed) return;
localStorage.setItem(STORAGE_KEY, JSON.stringify([...dismissedNotifications, id]));
}
});
});
});