Skip to content

Commit

Permalink
refactor(storybook): add Badges and fix storybook styles
Browse files Browse the repository at this point in the history
  • Loading branch information
masoudmanson committed Feb 13, 2024
1 parent f510e62 commit c8af49a
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .storybook/components/SidebarItem/SidebarItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";
import { StyledSidebarItem } from "./style";
import StatusTag from "../StatusTag/StatusTag";

export type StatusType = "beta" | "deprecated" | "wip";

interface SidebarItemProps {
children: React.ReactNode;
status: StatusType;
}

const SidebarItem = (props: SidebarItemProps) => {
return (
<StyledSidebarItem>
<div>{props.children}</div>
<StatusTag type={props.status}>{props.status}</StatusTag>
</StyledSidebarItem>
);
};

export default SidebarItem;
8 changes: 8 additions & 0 deletions .storybook/components/SidebarItem/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { styled } from "@mui/material";

export const StyledSidebarItem = styled("div")`
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
`;
22 changes: 22 additions & 0 deletions .storybook/components/StatusTag/StatusTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { FC } from "react";
import { StyledLabel } from "./style";
import { StatusType } from "../SidebarItem/SidebarItem";

interface StatusTagProps {
children: React.ReactNode;
type: StatusType;
}

const TypeToLabel: Record<StatusType, string> = {
beta: "Beta",
deprecated: "Deprecated",
wip: "Work in Progress",
};

const StatusTag: FC<StatusTagProps> = ({ type }) => {
const label = TypeToLabel[type];

return <StyledLabel type={type}>{label}</StyledLabel>;
};

export default StatusTag;
36 changes: 36 additions & 0 deletions .storybook/components/StatusTag/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { styled } from "@mui/material";
import { StatusType } from "../SidebarItem/SidebarItem";

interface StyledLabelProps {
type: StatusType;
}

const TypeToColor: Record<StatusType, string> = {
beta: "#703CBE",
deprecated: "#C61128",
wip: "#D8921F",
};

const TypeToBackGroundColor: Record<StatusType, string> = {
beta: "#F4F0F9",
deprecated: "#FEF2F2",
wip: "#FCF6EC",
};

export const StyledLabel = styled("label")`
${(props: StyledLabelProps) => {
const { type } = props;
const color = TypeToColor[type];
return `
margin: 0 16px 0 8px;
padding: 1px 4px;
font-size: 10px;
font-weight: 600;
color: ${color};
border: solid 1px transparent;
background-color: ${TypeToBackGroundColor[type]};
border-radius: 2px;
`;
}}
`;
17 changes: 4 additions & 13 deletions .storybook/manager-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#storybook-explorer-menu svg {
color: #555;
margin-top: 4px;
}

#storybook-explorer-menu button:focus,
Expand Down Expand Up @@ -69,7 +68,7 @@
padding-bottom: 5px;
}

#storybook-explorer-menu .sidebar-item > span {
#storybook-explorer-menu .sidebar-item > div > span {
display: inline-block;
position: relative;
border-style: solid;
Expand All @@ -87,15 +86,7 @@
margin-right: 6px;
}

#storybook-explorer-menu .sidebar-item > span {
margin-top: 7px;
}

#storybook-explorer-menu .sidebar-item > div > span {
margin-top: 3px;
}

#storybook-explorer-menu .sidebar-item[aria-expanded="true"] > span,
#storybook-explorer-menu .sidebar-item[aria-expanded="true"] > div > span,
#storybook-explorer-menu
.sidebar-subheading[aria-expanded="true"]
> button
Expand All @@ -106,7 +97,7 @@
<script>
//workaround to increase the left panel width just enough to show even the longer story names
//based on https://github.com/storybookjs/storybook/issues/9682#issuecomment-983356523
const DEFAULT_MINIMUM_LEFT_PANEL_WIDTH = 260; // original default is 230
const DEFAULT_MINIMUM_LEFT_PANEL_WIDTH = 280; // original default is 230
let storybookConfig = JSON.parse(localStorage.getItem("storybook-layout"));

// we only resize the left panel if it is set to a value lower than DEFAULT_MINIMUM_LEFT_PANEL_WIDTH
Expand All @@ -133,7 +124,7 @@
).firstChild;
bookmarkHollowIcon.setAttribute(
"d",
"M 13.762 6.202 C 13.87 6.452 13.927 6.724 13.927 7.001 C 13.927 7.275 13.87 7.548 13.762 7.799 C 13.656 8.049 13.498 8.272 13.303 8.451 L 8.873 12.502 C 8.711 12.65 8.504 12.731 8.29 12.731 L 0.968 12.731 C 0.731 12.731 0.503 12.631 0.336 12.452 C 0.168 12.273 0.073 12.03 0.073 11.775 L 0.073 2.224 C 0.073 1.971 0.168 1.727 0.336 1.548 C 0.503 1.369 0.731 1.269 0.968 1.269 L 8.29 1.269 C 8.504 1.269 8.711 1.35 8.873 1.499 L 13.303 5.55 C 13.498 5.729 13.656 5.952 13.762 6.202 Z M 11.862 7.553 C 11.929 7.492 11.988 7.412 12.029 7.315 C 12.071 7.219 12.093 7.11 12.093 7.001 C 12.093 6.889 12.071 6.782 12.029 6.684 C 11.988 6.589 11.929 6.508 11.862 6.447 L 7.885 2.809 L 1.594 2.809 L 1.594 11.191 L 7.885 11.191 L 11.862 7.553 Z"
"M 13.762 6.202 C 13.87 6.452 13.927 6.724 13.927 7.001 C 13.927 7.275 13.87 7.548 13.762 7.799 C 13.656 8.049 13.498 8.272 13.303 8.451 L 8.873 12.502 C 8.711 12.65 8.504 12.731 8.29 12.731 L 0.968 12.731 C 0.731 12.731 0.503 12.631 0.336 12.452 C 0.168 12.273 0.073 12.03 0.073 11.775 L 0.073 2.224 C 0.073 1.971 0.168 1.727 0.336 1.548 C 0.503 1.369 0.731 1.269 0.968 1.269 L 8.29 1.269 C 8.504 1.269 8.711 1.35 8.873 1.499 L 13.303 5.55 C 13.498 5.729 13.656 5.952 13.762 6.202 Z M 12.508 7.538 C 12.575 7.477 12.634 7.397 12.675 7.3 C 12.717 7.204 12.739 7.095 12.739 6.986 C 12.739 6.874 12.717 6.767 12.675 6.669 C 12.634 6.574 12.575 6.493 12.508 6.432 L 8.161 2.346 L 1.085 2.34 L 1.106 11.659 L 8.28 11.628 L 12.508 7.538 Z"
);
bookmarkHollowIcon.setAttribute("fill-rule", "evenodd");
});
Expand Down
19 changes: 18 additions & 1 deletion .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
// .storybook/manager.js

import React from "react";
import { addons } from "@storybook/addons";
import sdsTheme from "./sds-theme";
import SidebarItem from "./components/SidebarItem/SidebarItem";

addons.setConfig({
theme: sdsTheme,
sidebar: {
renderLabel: ({ name }) => {
const statusRegex = /\[([^)]+)]/gi;
const [statusMatch, statusType] = statusRegex.exec(name) || [];

if (statusMatch) {
return (
<SidebarItem status={statusType}>
{name.replace(statusMatch, "").trim()}
</SidebarItem>
);
}

return name;
},
},
});
48 changes: 48 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { defaultTheme } from "../packages/components/src/core/styles";
import { ThemeProvider } from "@mui/material/styles";
import { BADGE } from "../packages/components/src/common/SDSBadges";

export const decorators = [
(Story) => (
Expand All @@ -19,6 +20,53 @@ const preview = {
pseudo: {},
},
parameters: {
badgesConfig: {
[BADGE.BETA]: {
styles: {
backgroundColor: "#F4F0F9",
borderColor: "#7A41CE",
borderRadius: 2,
color: "#703CBE",
},
title: "Beta",
},
[BADGE.DEPRECATED]: {
styles: {
backgroundColor: "#FEF2F2",
borderColor: "#DC132C",
borderRadius: 2,
color: "#C61128",
},
title: "Deprecated",
},
[BADGE.NEEDS_REVISION]: {
styles: {
backgroundColor: "#F8F8F8",
borderColor: "#999999",
borderRadius: 2,
color: "#767676",
},
title: "Needs Revision",
},
[BADGE.STABLE]: {
styles: {
backgroundColor: "#ECF5F0",
borderColor: "#3CB371",
borderRadius: 2,
color: "#349A61",
},
title: "Stable",
},
[BADGE.WIP]: {
styles: {
backgroundColor: "#FCF6EC",
borderColor: "#F5A623",
borderRadius: 2,
color: "#D8921F",
},
title: "Work in progress",
},
},
options: {
storySort: {
method: "alphabetical",
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/common/SDSBadges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { BADGE as addonBadge } from "@geometricpanda/storybook-addon-badges";

export const BADGE = {
BETA: addonBadge.BETA,
DEPRECATED: addonBadge.DEPRECATED,
NEEDS_REVISION: addonBadge.NEEDS_REVISION,
STABLE: addonBadge.STABLE,
WIP: "wip",
};
6 changes: 3 additions & 3 deletions packages/components/src/core/Alert/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from "react";
import Button from "../Button";
import { defaultTheme } from "../styles/common/defaultTheme";
import Alert from "./index";
import { BADGE } from "@geometricpanda/storybook-addon-badges";
import { BADGE } from "../../common/SDSBadges";

const DismissButton = styled(Button)`
margin-left: -${defaultTheme.spacing(3)}px;
Expand Down Expand Up @@ -38,9 +38,9 @@ export default {
},
component: Demo,
parameters: {
badges: [BADGE.DEPRECATED, BADGE.OBSOLETE],
badges: [BADGE.DEPRECATED],
},
title: "Deprecated/Alert",
title: "Deprecated/Alert [deprecated]",
} as Meta;

export const Default = {
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/core/Chip/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Args, Meta } from "@storybook/react";
import React from "react";
import Button from "../Button";
import Chip from "./index";
import { BADGE } from "@geometricpanda/storybook-addon-badges";
import { BADGE } from "../../common/SDSBadges";

const Demo = (props: Args): JSX.Element => {
const { size, isRounded } = props;
Expand All @@ -27,9 +27,9 @@ const Demo = (props: Args): JSX.Element => {
export default {
component: Demo,
parameters: {
badges: [BADGE.DEPRECATED, BADGE.OBSOLETE],
badges: [BADGE.DEPRECATED],
},
title: "Deprecated/Chip",
title: "Deprecated/Chip [deprecated]",
} as Meta;

export const MediumSquareChip = {
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/core/DesignTokens/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Args, Meta } from "@storybook/react";
import { BADGE } from "@geometricpanda/storybook-addon-badges";
import { BADGE } from "../../common/SDSBadges";

const DesignTokens = (props: Args): JSX.Element => {
return <p {...props}>Design Tokens go here</p>;
Expand All @@ -14,9 +14,9 @@ export default {
},
component: DesignTokens,
parameters: {
badges: [BADGE.EXPERIMENTAL],
badges: [BADGE.WIP],
},
title: "Foundations/Colors",
title: "Foundations/Colors [wip]",
} as Meta;

// Default
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/core/MenuSelect/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AUTOCOMPLETE_SINGLE_COLUMN_OPTIONS } from "../../common/AUTOCOMPLETE_SI
import TagFilter from "../TagFilter";
import { getColors, getCorners, getShadows } from "../styles";
import RawMenuSelect, { DefaultMenuSelectOption } from "./index";
import { BADGE } from "@geometricpanda/storybook-addon-badges";
import { BADGE } from "../../common/SDSBadges";

const StyledPopper = styled(Popper)`
${(props) => {
Expand Down Expand Up @@ -260,9 +260,9 @@ export default {
},
component: MenuSelect,
parameters: {
badges: [BADGE.DEPRECATED, BADGE.OBSOLETE],
badges: [BADGE.DEPRECATED],
},
title: "Deprecated/MenuSelect",
title: "Deprecated/MenuSelect [deprecated]",
} as Meta;

// Default
Expand Down
4 changes: 2 additions & 2 deletions packages/data-viz/src/core/HeatmapChart/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const HeatmapChart = (props: Args): JSX.Element => {
export default {
component: HeatmapChart,
parameters: {
badges: [BADGE.STABLE],
badges: [BADGE.BETA],
},
title: "Data Viz/HeatmapChart",
title: "Data Viz/HeatmapChart [beta]",
} as Meta;

// Default
Expand Down

0 comments on commit c8af49a

Please sign in to comment.