├── .nvmrc ├── .prettierrc ├── .prettierignore ├── .yarn └── .gitignore ├── manager.js ├── .storybook ├── preview-head.html ├── local-preset.js ├── main.ts └── preview.tsx ├── .yarnrc.yml ├── media ├── screenshot.png └── icon.svg ├── .gitignore ├── src ├── components │ ├── index.ts │ ├── badge-tooltip-wrapper.component.tsx │ ├── badges.component.tsx │ └── badge.component.tsx ├── index.ts ├── stories │ ├── Button.mdx │ ├── button.css │ ├── Button.tsx │ ├── Button.stories.tsx │ └── assets │ │ ├── direction.svg │ │ ├── flow.svg │ │ ├── code-brackets.svg │ │ ├── comments.svg │ │ ├── repo.svg │ │ ├── plugin.svg │ │ ├── stackalt.svg │ │ └── colors.svg ├── locations │ ├── sidebar │ │ ├── index.tsx │ │ └── sidebar.tsx │ ├── toolbar-extra │ │ └── index.tsx │ └── toolbar │ │ └── index.tsx ├── constants.ts ├── manager.tsx ├── typings.interface.ts └── config.ts ├── vite.config.ts ├── tsup.config.ts ├── tsconfig.json ├── .github └── workflows │ └── release.yml ├── scripts ├── eject-typescript.mjs ├── prepublish-checks.mjs └── welcome.js ├── LICENSE ├── package.json ├── README.md └── CHANGELOG.md /.nvmrc: -------------------------------------------------------------------------------- 1 | v20.10.0 -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | dist 2 | -------------------------------------------------------------------------------- /.yarn/.gitignore: -------------------------------------------------------------------------------- 1 | install-state.gz 2 | -------------------------------------------------------------------------------- /manager.js: -------------------------------------------------------------------------------- 1 | export * from "./dist/manager"; 2 | -------------------------------------------------------------------------------- /.storybook/preview-head.html: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | yarnPath: .yarn/releases/yarn-4.5.0.cjs 2 | 3 | nodeLinker: node-modules 4 | -------------------------------------------------------------------------------- /media/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimdrury/storybook-addon-badges/HEAD/media/screenshot.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/ 2 | node_modules/ 3 | storybook-static/ 4 | build-storybook.log 5 | .DS_Store 6 | .env 7 | .idea 8 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export * from './badges.component'; 2 | export * from './badge.component'; 3 | export * from './badge-tooltip-wrapper.component'; 4 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "vite"; 2 | import react from "@vitejs/plugin-react"; 3 | 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | }); 8 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | // make it work with --isolatedModules 2 | export * from './constants'; 3 | export * from './config'; 4 | 5 | export type { TooltipConfig, BadgeConfig, BadgesConfig } from './typings.interface'; 6 | 7 | export default {}; 8 | -------------------------------------------------------------------------------- /.storybook/local-preset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * to load the built addon in this test Storybook 3 | */ 4 | 5 | function managerEntries(entry = []) { 6 | return [...entry, require.resolve("../dist/manager.mjs")]; 7 | } 8 | 9 | module.exports = { 10 | managerEntries, 11 | }; 12 | -------------------------------------------------------------------------------- /src/stories/Button.mdx: -------------------------------------------------------------------------------- 1 | import {Canvas, Meta} from '@storybook/blocks'; 2 | import * as ButtonStories from "./Button.stories"; 3 | import {BADGE} from "../constants"; 4 | 5 | 6 | 7 | 8 | # Button 9 | 10 | This is an example of a button story 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/locations/sidebar/index.tsx: -------------------------------------------------------------------------------- 1 | import type { API_HashEntry, API_SidebarOptions } from "@storybook/types"; 2 | import React from "react"; 3 | import { Sidebar } from "./sidebar"; 4 | 5 | export const sidebar: API_SidebarOptions = { 6 | renderLabel: (item: API_HashEntry) => { 7 | if (item.type !== "story" && item.type !== "docs") { 8 | return; 9 | } 10 | 11 | return ; 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig } from "tsup"; 2 | 3 | export default defineConfig((options) => ({ 4 | entry: ["src/index.ts", "src/manager.tsx"], 5 | splitting: false, 6 | minify: !options.watch, 7 | format: ["cjs", "esm"], 8 | dts: { 9 | resolve: true, 10 | }, 11 | treeshake: true, 12 | sourcemap: true, 13 | clean: true, 14 | platform: "browser", 15 | esbuildOptions(options) { 16 | options.conditions = ["module"]; 17 | }, 18 | })); 19 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "baseUrl": "../../addon-kit", 5 | "esModuleInterop": true, 6 | "experimentalDecorators": true, 7 | "incremental": false, 8 | "isolatedModules": true, 9 | "jsx": "react", 10 | "lib": ["es2020", "dom"], 11 | "module": "commonjs", 12 | "noImplicitAny": true, 13 | "rootDir": "./src", 14 | "skipLibCheck": true, 15 | "target": "ES2020" 16 | }, 17 | "include": ["src/**/*"] 18 | } 19 | -------------------------------------------------------------------------------- /.storybook/main.ts: -------------------------------------------------------------------------------- 1 | import type {StorybookConfig} from "@storybook/react-vite"; 2 | 3 | const config: StorybookConfig = { 4 | stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], 5 | addons: [ 6 | "@storybook/addon-links", 7 | "@storybook/addon-essentials", 8 | "@storybook/addon-interactions", 9 | "./local-preset.js", 10 | ], 11 | framework: { 12 | name: "@storybook/react-vite", 13 | options: {}, 14 | }, 15 | docs: { 16 | autodocs: "tag", 17 | }, 18 | }; 19 | export default config; 20 | -------------------------------------------------------------------------------- /src/constants.ts: -------------------------------------------------------------------------------- 1 | export const ADDON_ID = '@geometricpanda/storybook-addon-badges'; 2 | export const TOOL_ID = ADDON_ID; 3 | export const TOOL_ID_EXTRA = `${ADDON_ID}/extra`; 4 | 5 | export const ADDON_TITLE = 'Storybook Addon Badges'; 6 | export const PARAM_CONFIG_KEY = 'badgesConfig'; 7 | export const PARAM_BADGES_KEY = 'badges'; 8 | 9 | export enum BADGE_LOCATION { 10 | TOOLBAR = 'toolbar', 11 | TOOLBAR_EXTRA = 'toolbar-extra', 12 | SIDEBAR = 'sidebar', 13 | } 14 | 15 | export enum BADGE { 16 | DEFAULT = 'default', 17 | BETA = 'beta', 18 | STABLE = 'stable', 19 | NEEDS_REVISION = 'needs-revision', 20 | OBSOLETE = 'obsolete', 21 | EXPERIMENTAL = 'experimental', 22 | DEPRECATED = 'deprecated', 23 | } 24 | -------------------------------------------------------------------------------- /src/stories/button.css: -------------------------------------------------------------------------------- 1 | .storybook-button { 2 | font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; 3 | font-weight: 700; 4 | border: 0; 5 | border-radius: 3em; 6 | cursor: pointer; 7 | display: inline-block; 8 | line-height: 1; 9 | } 10 | .storybook-button--primary { 11 | color: white; 12 | background-color: #1ea7fd; 13 | } 14 | .storybook-button--secondary { 15 | color: #333; 16 | background-color: transparent; 17 | box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 0px 1px inset; 18 | } 19 | .storybook-button--small { 20 | font-size: 12px; 21 | padding: 10px 16px; 22 | } 23 | .storybook-button--medium { 24 | font-size: 14px; 25 | padding: 11px 20px; 26 | } 27 | .storybook-button--large { 28 | font-size: 16px; 29 | padding: 12px 24px; 30 | } 31 | -------------------------------------------------------------------------------- /src/components/badge-tooltip-wrapper.component.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {WithTooltip, TooltipMessage} from '@storybook/components'; 3 | 4 | import type {FC, ReactNode} from 'react'; 5 | import type {TooltipConfig} from "../typings.interface"; 6 | 7 | export interface BadgeTooltipWrapperProps { 8 | children: ReactNode; 9 | tooltip: TooltipConfig; 10 | } 11 | 12 | export const BadgeTooltipWrapper: FC = ({tooltip, children}) => { 13 | 14 | const tooltipMessageProps = (typeof tooltip === 'string') 15 | ? {desc: tooltip} 16 | : tooltip; 17 | 18 | const tooltipMessage = ; 19 | 20 | return ( 21 | 22 | {children} 23 | 24 | ) 25 | }; 26 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: [push] 4 | 5 | jobs: 6 | release: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | 11 | - name: Prepare repository 12 | run: git fetch --unshallow --tags 13 | 14 | - name: Install Node Version 15 | uses: actions/setup-node@v4.0.4 16 | with: 17 | node-version-file: ".nvmrc" 18 | 19 | - name: Install Yarn 20 | run: npm install -g yarn@1.22.22 21 | 22 | - name: Run install 23 | uses: borales/actions-yarn@v4 24 | with: 25 | cmd: install --immutable 26 | 27 | - name: Create Release 28 | env: 29 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 31 | run: | 32 | yarn release 33 | -------------------------------------------------------------------------------- /src/components/badges.component.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from "react"; 2 | import { Separator } from "@storybook/components"; 3 | import { styled } from "@storybook/theming"; 4 | import { Badge } from "./badge.component"; 5 | import { BadgeConfig } from "../typings.interface"; 6 | 7 | const BadgesWrapper = styled.div(({ theme }) => ({ 8 | gap: theme.layoutMargin, 9 | paddingInline: theme.layoutMargin / 2, 10 | display: "flex", 11 | alignItems: "center", 12 | })); 13 | 14 | interface BadgesProps { 15 | badges: Array; 16 | } 17 | 18 | export const Badges: FC = ({ badges }) => { 19 | if(!badges.length) { 20 | return null; 21 | } 22 | 23 | return ( 24 | <> 25 | 26 | 27 | {badges.map((badge) => ( 28 | 29 | ))} 30 | 31 | 32 | 33 | ) 34 | } 35 | -------------------------------------------------------------------------------- /src/locations/toolbar-extra/index.tsx: -------------------------------------------------------------------------------- 1 | import { useStorybookApi } from "@storybook/manager-api"; 2 | import React from "react"; 3 | 4 | import { PARAM_BADGES_KEY, PARAM_CONFIG_KEY } from "../../constants"; 5 | import { Badges } from "../../components"; 6 | import { BadgesConfig } from "../../typings.interface"; 7 | import { defaultBadgesConfig } from "../../config"; 8 | 9 | export const ToolbarExtra = () => { 10 | const api = useStorybookApi(); 11 | const storyBadges = api.getCurrentParameter(PARAM_BADGES_KEY) || []; 12 | const customBadgesConfig = 13 | api.getCurrentParameter(PARAM_CONFIG_KEY) || {}; 14 | 15 | const config = { 16 | ...defaultBadgesConfig, 17 | ...customBadgesConfig, 18 | }; 19 | 20 | const badges = storyBadges 21 | .map((badge) => config[badge]) 22 | .filter((badge) => badge.location?.includes("toolbar-extra")); 23 | 24 | return badges.length ? : null; 25 | }; 26 | -------------------------------------------------------------------------------- /src/locations/toolbar/index.tsx: -------------------------------------------------------------------------------- 1 | import { useStorybookApi } from "@storybook/manager-api"; 2 | import React from "react"; 3 | 4 | import { PARAM_BADGES_KEY, PARAM_CONFIG_KEY } from "../../constants"; 5 | import { Badges } from "../../components"; 6 | import { BadgesConfig } from "../../typings.interface"; 7 | import { defaultBadgesConfig } from "../../config"; 8 | 9 | export const Toolbar = () => { 10 | const api = useStorybookApi(); 11 | const storyBadges = api.getCurrentParameter(PARAM_BADGES_KEY) || []; 12 | const customBadgesConfig = 13 | api.getCurrentParameter(PARAM_CONFIG_KEY) || {}; 14 | 15 | const config = { 16 | ...defaultBadgesConfig, 17 | ...customBadgesConfig, 18 | }; 19 | 20 | const badges = storyBadges 21 | .map((badge) => config[badge]) 22 | .filter((badge) => !badge.location || badge.location?.includes("toolbar")); 23 | 24 | return badges.length ? : null; 25 | }; 26 | -------------------------------------------------------------------------------- /src/manager.tsx: -------------------------------------------------------------------------------- 1 | import { addons, types } from "@storybook/manager-api"; 2 | import { 3 | ADDON_ID, 4 | ADDON_TITLE, 5 | PARAM_BADGES_KEY, 6 | TOOL_ID, 7 | TOOL_ID_EXTRA, 8 | } from "./constants"; 9 | import { sidebar } from "./locations/sidebar"; 10 | import { Toolbar } from "./locations/toolbar"; 11 | import { ToolbarExtra } from "./locations/toolbar-extra"; 12 | 13 | // Register the addon 14 | addons.register(ADDON_ID, () => { 15 | 16 | // Register the tool 17 | addons.add(TOOL_ID, { 18 | type: types.TOOL, 19 | paramKey: PARAM_BADGES_KEY, 20 | title: ADDON_TITLE, 21 | match: () => true, 22 | render: Toolbar, 23 | }); 24 | 25 | // Register the tool extra location 26 | addons.add(TOOL_ID_EXTRA, { 27 | type: types.TOOLEXTRA, 28 | paramKey: PARAM_BADGES_KEY, 29 | title: ADDON_TITLE, 30 | match: () => true, 31 | render: ToolbarExtra, 32 | }); 33 | 34 | }); 35 | 36 | addons.setConfig({ 37 | sidebar, 38 | }); 39 | -------------------------------------------------------------------------------- /scripts/eject-typescript.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zx 2 | 3 | // Copy TS files and delete src 4 | await $`cp -r ./src ./srcTS`; 5 | await $`rm -rf ./src`; 6 | await $`mkdir ./src`; 7 | 8 | // Convert TS code to JS 9 | await $`babel --no-babelrc --presets @babel/preset-typescript ./srcTS -d ./src --extensions \".js,.jsx,.ts,.tsx\" --ignore "./srcTS/typings.d.ts"`; 10 | 11 | // Format the newly created .js files 12 | await $`prettier --write ./src`; 13 | 14 | // Add in minimal files required for the TS build setup 15 | await $`touch ./src/dummy.ts`; 16 | await $`printf "export {};" >> ./src/dummy.ts`; 17 | 18 | await $`touch ./src/typings.d.ts`; 19 | await $`printf 'declare module "global";' >> ./src/typings.d.ts`; 20 | 21 | // Clean up 22 | await $`rm -rf ./srcTS`; 23 | 24 | console.log( 25 | chalk.green.bold` 26 | TypeScript Ejection complete!`, 27 | chalk.green` 28 | Addon code converted with JS. The TypeScript build setup is still available in case you want to adopt TypeScript in the future. 29 | ` 30 | ); 31 | -------------------------------------------------------------------------------- /.storybook/preview.tsx: -------------------------------------------------------------------------------- 1 | import type {Preview} from "@storybook/react"; 2 | import {BADGE, defaultBadgesConfig} from "../src"; 3 | 4 | const preview: Preview = { 5 | parameters: { 6 | badgesConfig: { 7 | [BADGE.BETA]: { 8 | ...defaultBadgesConfig[BADGE.BETA], 9 | tooltip: { 10 | title: 'This is Beta', 11 | desc: 'Be ready to receive updates frequently and leave a feedback', 12 | links: [ 13 | {title: 'Read more', href: 'http://path/to/your/docs'}, 14 | { 15 | title: 'Leave feedback', onClick: () => { 16 | alert('thanks for the feedback') 17 | } 18 | }] 19 | } 20 | }, 21 | [BADGE.DEPRECATED]: { 22 | ...defaultBadgesConfig[BADGE.DEPRECATED], 23 | tooltip: 'This component is deprecated, please avoid using it.' 24 | } 25 | } 26 | } 27 | }; 28 | 29 | export default preview; 30 | -------------------------------------------------------------------------------- /src/stories/Button.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './button.css'; 3 | 4 | interface ButtonProps { 5 | /** 6 | * Is this the principal call to action on the page? 7 | */ 8 | primary?: boolean; 9 | /** 10 | * What background color to use 11 | */ 12 | backgroundColor?: string; 13 | /** 14 | * How large should the button be? 15 | */ 16 | size?: 'small' | 'medium' | 'large'; 17 | /** 18 | * Button contents 19 | */ 20 | label: string; 21 | /** 22 | * Optional click handler 23 | */ 24 | onClick?: () => void; 25 | } 26 | 27 | /** 28 | * Primary UI component for user interaction 29 | */ 30 | export const Button = ({ 31 | primary = false, 32 | size = 'medium', 33 | backgroundColor, 34 | label, 35 | ...props 36 | }: ButtonProps) => { 37 | const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary'; 38 | return ( 39 | 47 | ); 48 | }; 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Storybook contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/stories/Button.stories.tsx: -------------------------------------------------------------------------------- 1 | import type { Meta, StoryObj } from "@storybook/react"; 2 | 3 | import { Button } from "./Button"; 4 | import {BADGE} from "../constants"; 5 | 6 | const meta: Meta = { 7 | title: "Example/Button", 8 | component: Button, 9 | parameters: { 10 | badges: [BADGE.BETA] 11 | }, 12 | }; 13 | 14 | export default meta; 15 | type Story = StoryObj; 16 | 17 | export const AllBadges: Story = { 18 | parameters: { 19 | badges: [ 20 | BADGE.DEFAULT, 21 | BADGE.BETA, 22 | BADGE.STABLE, 23 | BADGE.NEEDS_REVISION, 24 | BADGE.OBSOLETE, 25 | BADGE.EXPERIMENTAL, 26 | BADGE.DEPRECATED, 27 | ], 28 | }, 29 | args: { 30 | primary: true, 31 | label: "Button", 32 | }, 33 | }; 34 | 35 | export const Primary: Story = { 36 | args: { 37 | primary: true, 38 | label: "Button", 39 | }, 40 | }; 41 | 42 | export const Secondary: Story = { 43 | args: { 44 | label: "Button", 45 | }, 46 | }; 47 | 48 | export const Large: Story = { 49 | args: { 50 | size: "large", 51 | label: "Button", 52 | }, 53 | }; 54 | 55 | export const Small: Story = { 56 | args: { 57 | size: "small", 58 | label: "Button", 59 | }, 60 | }; 61 | -------------------------------------------------------------------------------- /src/stories/assets/direction.svg: -------------------------------------------------------------------------------- 1 | illustration/direction -------------------------------------------------------------------------------- /src/locations/sidebar/sidebar.tsx: -------------------------------------------------------------------------------- 1 | import { useStorybookApi } from "@storybook/manager-api"; 2 | import React, { FC } from "react"; 3 | import type { API_DocsEntry, API_StoryEntry } from "@storybook/types"; 4 | import { PARAM_BADGES_KEY, PARAM_CONFIG_KEY } from "../../constants"; 5 | import { defaultBadgesConfig } from "../../config"; 6 | import { BadgesConfig } from "../../typings.interface"; 7 | import { Badges } from "../../components"; 8 | 9 | interface SidebarProps { 10 | item: API_DocsEntry | API_StoryEntry; 11 | } 12 | 13 | export const Sidebar: FC = ({ item }) => { 14 | const api = useStorybookApi(); 15 | const params = api.getParameters(item.id); 16 | 17 | if (!params || !params[PARAM_BADGES_KEY] || !params[PARAM_CONFIG_KEY]) { 18 | return item.name; 19 | } 20 | 21 | const storyBadges: Array = params[PARAM_BADGES_KEY]; 22 | const customBadgesConfig: BadgesConfig = params[PARAM_CONFIG_KEY]; 23 | 24 | const config = { 25 | ...defaultBadgesConfig, 26 | ...customBadgesConfig, 27 | }; 28 | 29 | const badges = storyBadges 30 | .map((badge) => config[badge]) 31 | .filter((badge) => badge.location?.includes("sidebar")); 32 | 33 | return ( 34 | <> 35 | {item.name} 36 | 37 | 38 | ); 39 | }; 40 | -------------------------------------------------------------------------------- /src/typings.interface.ts: -------------------------------------------------------------------------------- 1 | import type {ComponentProps} from "react"; 2 | import type {TooltipMessage} from "@storybook/components"; 3 | import type {Property} from 'csstype'; 4 | 5 | export type TooltipConfig = 6 | | Omit, 'children'> 7 | | string; 8 | 9 | export type BadgeConfig = { 10 | styles?: { 11 | backgroundColor?: Property.BackgroundColor, 12 | borderColor?: Property.BorderColor, 13 | borderRadius?: Property.BorderRadius, 14 | borderStyle?: Property.BorderStyle, 15 | borderWidth?: Property.BorderWidth, 16 | color?: Property.Color, 17 | fontFamily?: Property.FontFamily, 18 | fontSize?: Property.FontSize, 19 | fontWeight?: Property.FontWeight, 20 | lineHeight?: Property.LineHeight, 21 | paddingBlock?: Property.PaddingBlock, 22 | paddingInline?: Property.PaddingInline, 23 | textTransform?: Property.TextTransform, 24 | whiteSpace?: Property.WhiteSpace, 25 | overflow?: Property.Overflow, 26 | textOverflow?: Property.TextOverflow, 27 | }; 28 | location?: Array<'toolbar' | 'toolbar-extra' | 'sidebar'>; 29 | title?: string; 30 | tooltip?: TooltipConfig; 31 | }; 32 | 33 | export type BadgesConfig = Record; 34 | 35 | -------------------------------------------------------------------------------- /src/stories/assets/flow.svg: -------------------------------------------------------------------------------- 1 | illustration/flow -------------------------------------------------------------------------------- /src/stories/assets/code-brackets.svg: -------------------------------------------------------------------------------- 1 | illustration/code-brackets -------------------------------------------------------------------------------- /src/stories/assets/comments.svg: -------------------------------------------------------------------------------- 1 | illustration/comments -------------------------------------------------------------------------------- /src/stories/assets/repo.svg: -------------------------------------------------------------------------------- 1 | illustration/repo -------------------------------------------------------------------------------- /src/components/badge.component.tsx: -------------------------------------------------------------------------------- 1 | import React, { FC } from "react"; 2 | import { styled } from "@storybook/theming"; 3 | 4 | import { BadgeTooltipWrapper } from "./badge-tooltip-wrapper.component"; 5 | import type { BadgeConfig } from "../typings.interface"; 6 | 7 | export interface StyledBadgeProps { 8 | config: BadgeConfig; 9 | } 10 | 11 | export const StyledBadge = styled.span( 12 | ({ config: { styles } }) => ({ 13 | borderColor: styles?.borderColor || "#474D66", 14 | borderRadius: styles?.borderRadius || "3px", 15 | borderStyle: styles?.borderStyle || "solid", 16 | borderWidth: styles?.borderWidth || "1px", 17 | color: styles?.color || "#474D66", 18 | backgroundColor: styles?.backgroundColor || "#EDEFF5", 19 | fontSize: styles?.fontSize || "0.625rem", 20 | fontFamily: styles?.fontFamily || "inherit", 21 | fontWeight: styles?.fontWeight || "bold", 22 | lineHeight: styles?.lineHeight || "1", 23 | textTransform: styles?.textTransform || "uppercase", 24 | paddingInline: styles?.paddingInline || "5px", 25 | paddingBlock: styles?.paddingBlock || "2px", 26 | whiteSpace: styles?.whiteSpace || "nowrap", 27 | overflow: styles?.overflow || "hidden", 28 | textOverflow: styles?.textOverflow || "ellipsis", 29 | display: "block", 30 | }), 31 | ); 32 | 33 | export interface BadgeProps { 34 | config: BadgeConfig; 35 | } 36 | 37 | export const Badge: FC = ({ config }) => { 38 | if (config.tooltip) { 39 | return ( 40 | 41 | {config.title} 42 | 43 | ); 44 | } 45 | 46 | return {config.title}; 47 | }; 48 | -------------------------------------------------------------------------------- /src/config.ts: -------------------------------------------------------------------------------- 1 | import {BadgeConfig, BadgesConfig} from "./typings.interface"; 2 | import {BADGE} from "./constants"; 3 | 4 | export const defaultBadgesConfig: BadgesConfig = { 5 | [BADGE.DEFAULT]: { 6 | title: 'Badge', 7 | }, 8 | [BADGE.BETA]: { 9 | title: 'Beta', 10 | styles: { 11 | backgroundColor: '#D6E0FF', 12 | borderColor: '#2952CC', 13 | color: '#2952CC', 14 | }, 15 | }, 16 | [BADGE.STABLE]: { 17 | title: 'Stable', 18 | styles: { 19 | backgroundColor: '#DCF2EA', 20 | borderColor: '#317159', 21 | color: '#317159', 22 | }, 23 | }, 24 | [BADGE.NEEDS_REVISION]: { 25 | title: 'Needs Revision', 26 | location: ['toolbar-extra'], 27 | styles: { 28 | backgroundColor: '#FFEFD2', 29 | borderColor: '#66460D', 30 | color: '#66460D', 31 | }, 32 | }, 33 | [BADGE.OBSOLETE]: { 34 | title: 'Obsolete', 35 | location: ['sidebar'], 36 | styles: { 37 | backgroundColor: '#F9DADA', 38 | borderColor: '#7D2828', 39 | color: '#7D2828', 40 | }, 41 | }, 42 | [BADGE.EXPERIMENTAL]: { 43 | title: 'Experimental', 44 | styles: { 45 | backgroundColor: '#E7E4F9', 46 | borderColor: '#6E62B6', 47 | color: '#6E62B6', 48 | }, 49 | }, 50 | [BADGE.DEPRECATED]: { 51 | title: 'Deprecated', 52 | styles: { 53 | backgroundColor: '#F8E3DA', 54 | borderColor: '#85462B', 55 | color: '#85462B', 56 | }, 57 | }, 58 | }; 59 | 60 | export const defaultBadgeConfig: BadgeConfig = defaultBadgesConfig[BADGE.DEFAULT]; 61 | -------------------------------------------------------------------------------- /scripts/prepublish-checks.mjs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env zx 2 | 3 | import packageJson from "../package.json" assert { type: 'json' }; 4 | import boxen from "boxen"; 5 | import dedent from "dedent"; 6 | 7 | const name = packageJson.name; 8 | const displayName = packageJson.storybook.displayName; 9 | 10 | let exitCode = 0; 11 | $.verbose = false; 12 | 13 | /** 14 | * Check that meta data has been updated 15 | */ 16 | if (name.includes("addon-kit") || displayName.includes("Addon Kit")) { 17 | console.error( 18 | boxen( 19 | dedent` 20 | ${chalk.red.bold("Missing metadata")} 21 | 22 | ${chalk.red(dedent`Your package name and/or displayName includes default values from the Addon Kit. 23 | The addon gallery filters out all such addons. 24 | 25 | Please configure appropriate metadata before publishing your addon. For more info, see: 26 | https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata`)}`, 27 | { padding: 1, borderColor: "red" } 28 | ) 29 | ); 30 | 31 | exitCode = 1; 32 | } 33 | 34 | /** 35 | * Check that README has been updated 36 | */ 37 | const readmeTestStrings = 38 | "# Storybook Addon Kit|Click the \\*\\*Use this template\\*\\* button to get started.|https://user-images.githubusercontent.com/42671/106809879-35b32000-663a-11eb-9cdc-89f178b5273f.gif"; 39 | 40 | if ((await $`cat README.md | grep -E ${readmeTestStrings}`.exitCode) == 0) { 41 | console.error( 42 | boxen( 43 | dedent` 44 | ${chalk.red.bold("README not updated")} 45 | 46 | ${chalk.red(dedent`You are using the default README.md file that comes with the addon kit. 47 | Please update it to provide info on what your addon does and how to use it.`)} 48 | `, 49 | { padding: 1, borderColor: "red" } 50 | ) 51 | ); 52 | 53 | exitCode = 1; 54 | } 55 | 56 | process.exit(exitCode); 57 | -------------------------------------------------------------------------------- /src/stories/assets/plugin.svg: -------------------------------------------------------------------------------- 1 | illustration/plugin -------------------------------------------------------------------------------- /src/stories/assets/stackalt.svg: -------------------------------------------------------------------------------- 1 | illustration/stackalt -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@geometricpanda/storybook-addon-badges", 3 | "version": "2.0.5", 4 | "description": "A Storybook addon which allows you to add badges to your stories", 5 | "keywords": [ 6 | "storybook-addons", 7 | "storybook", 8 | "addon", 9 | "layout", 10 | "organize", 11 | "badges" 12 | ], 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/geometricpanda/storybook-addon-badges" 16 | }, 17 | "author": "Jim Drury ", 18 | "license": "MIT", 19 | "exports": { 20 | ".": { 21 | "require": "./dist/index.js", 22 | "import": "./dist/index.mjs", 23 | "types": "./dist/index.d.ts" 24 | }, 25 | "./manager": { 26 | "require": "./dist/manager.js", 27 | "import": "./dist/manager.mjs", 28 | "types": "./dist/manager.d.ts" 29 | }, 30 | "./package.json": "./package.json" 31 | }, 32 | "main": "dist/index.js", 33 | "module": "dist/index.mjs", 34 | "types": "dist/index.d.ts", 35 | "files": [ 36 | "dist/**/*", 37 | "README.md", 38 | "*.js", 39 | "*.d.ts" 40 | ], 41 | "scripts": { 42 | "clean": "rimraf ./dist", 43 | "prebuild": "yarn clean", 44 | "build": "tsup", 45 | "build:watch": "yarn build --watch", 46 | "test": "echo \"Error: no test specified\" && exit 1", 47 | "start": "concurrently \"yarn build:watch\" \"yarn storybook --quiet\"", 48 | "prerelease": "zx scripts/prepublish-checks.mjs", 49 | "release": "yarn build && auto shipit", 50 | "eject-ts": "zx scripts/eject-typescript.mjs", 51 | "storybook": "storybook dev -p 6006", 52 | "build-storybook": "storybook build" 53 | }, 54 | "devDependencies": { 55 | "@storybook/addon-essentials": "^8.3.0", 56 | "@storybook/addon-interactions": "^8.3.0", 57 | "@storybook/addon-links": "^8.3.0", 58 | "@storybook/blocks": "^8.3.0", 59 | "@storybook/components": "^8.3.0", 60 | "@storybook/core-events": "^8.3.0", 61 | "@storybook/manager-api": "^8.3.0", 62 | "@storybook/preview-api": "^8.3.0", 63 | "@storybook/react": "^8.3.0", 64 | "@storybook/react-vite": "^8.3.0", 65 | "@storybook/testing-library": "^0.2.2", 66 | "@storybook/theming": "^8.3.0", 67 | "@storybook/types": "^8.3.0", 68 | "@types/node": "^18.15.0", 69 | "@vitejs/plugin-react": "^4.2.1", 70 | "auto": "^11.1.4", 71 | "boxen": "^7.1.1", 72 | "concurrently": "^8.2.2", 73 | "dedent": "^1.5.3", 74 | "prettier": "^3.2.5", 75 | "prompts": "^2.4.2", 76 | "prop-types": "^15.8.1", 77 | "react": "^18.2.0", 78 | "react-dom": "^18.2.0", 79 | "rimraf": "^5.0.5", 80 | "storybook": "^8.3.0", 81 | "tsup": "^8.0.2", 82 | "typescript": "^5.4.4", 83 | "vite": "^5.2.8", 84 | "zx": "^7.2.3" 85 | }, 86 | "peerDependencies": { 87 | "@storybook/blocks": "^8.3.0", 88 | "@storybook/components": "^8.3.0", 89 | "@storybook/core-events": "^8.3.0", 90 | "@storybook/manager-api": "^8.3.0", 91 | "@storybook/preview-api": "^8.3.0", 92 | "@storybook/theming": "^8.3.0", 93 | "@storybook/types": "^8.3.0", 94 | "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", 95 | "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" 96 | }, 97 | "peerDependenciesMeta": { 98 | "react": { 99 | "optional": true 100 | }, 101 | "react-dom": { 102 | "optional": true 103 | } 104 | }, 105 | "publishConfig": { 106 | "access": "public" 107 | }, 108 | "storybook": { 109 | "displayName": "Badges", 110 | "supportedFrameworks": [ 111 | "react", 112 | "vue", 113 | "angular", 114 | "web-components", 115 | "ember", 116 | "html", 117 | "svelte", 118 | "preact", 119 | "react-native" 120 | ], 121 | "icon": "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png" 122 | }, 123 | "packageManager": "yarn@4.5.0" 124 | } 125 | -------------------------------------------------------------------------------- /media/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /scripts/welcome.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable eslint-comments/disable-enable-pair */ 2 | /* eslint-disable no-console */ 3 | const prompts = require("prompts"); 4 | const dedent = require("ts-dedent").default; 5 | const path = require("path"); 6 | const fs = require("fs"); 7 | const { execSync } = require("child_process"); 8 | 9 | // CLI questions 10 | const questions = [ 11 | { 12 | type: "text", 13 | name: "authorName", 14 | initial: "", 15 | message: "What is the package author name?*", 16 | validate: (name) => (name === "" ? "Name can't be empty" : true), 17 | }, 18 | { 19 | type: "text", 20 | name: "authorEmail", 21 | initial: "", 22 | message: "What is the package author email?", 23 | }, 24 | { 25 | type: "text", 26 | name: "packageName", 27 | message: "What is the addon package name (eg: storybook-addon-something)?*", 28 | validate: (name) => (name === "" ? "Package name can't be empty" : true), 29 | }, 30 | { 31 | type: "text", 32 | name: "displayName", 33 | message: 34 | "What is the addon display name (this will be used in the addon catalog)?*", 35 | validate: (name) => 36 | name === "" 37 | ? "Display name can't be empty. For more info, see: https://storybook.js.org/docs/react/addons/addon-catalog#addon-metadata" 38 | : true, 39 | }, 40 | { 41 | type: "text", 42 | name: "addonDescription", 43 | initial: "", 44 | message: "Write a short description of the addon*", 45 | validate: (name) => (name === "" ? "Description can't be empty" : true), 46 | }, 47 | { 48 | type: "text", 49 | name: "repoUrl", 50 | message: "Git repo URL for your addon package (https://github.com/...)*", 51 | validate: (url) => (url === "" ? "URL can't be empty" : true), 52 | }, 53 | { 54 | type: "text", 55 | name: "addonIcon", 56 | initial: 57 | "https://user-images.githubusercontent.com/321738/63501763-88dbf600-c4cc-11e9-96cd-94adadc2fd72.png", 58 | message: "URL of your addon icon", 59 | }, 60 | { 61 | type: "list", 62 | name: "keywords", 63 | initial: "storybook-addons", 64 | message: "Enter addon keywords (comma separated)", 65 | separator: ",", 66 | format: (keywords) => 67 | keywords 68 | .concat(["storybook-addons"]) 69 | .map((k) => `"${k}"`) 70 | .join(", "), 71 | }, 72 | { 73 | type: "list", 74 | name: "supportedFrameworks", 75 | initial: 76 | "react, vue, angular, web-components, ember, html, svelte, preact, react-native", 77 | message: "List of frameworks you support (comma separated)?", 78 | separator: ",", 79 | format: (frameworks) => frameworks.map((k) => `"${k}"`).join(", "), 80 | }, 81 | ]; 82 | 83 | const REPLACE_TEMPLATES = { 84 | packageName: "storybook-addon-kit", 85 | addonDescription: "everything you need to build a Storybook addon", 86 | packageAuthor: "package-author", 87 | repoUrl: "https://github.com/storybookjs/storybook-addon-kit", 88 | keywords: `"storybook-addons"`, 89 | displayName: "Addon Kit", 90 | supportedFrameworks: `"supported-frameworks"`, 91 | }; 92 | 93 | const bold = (message) => `\u001b[1m${message}\u001b[22m`; 94 | const magenta = (message) => `\u001b[35m${message}\u001b[39m`; 95 | const blue = (message) => `\u001b[34m${message}\u001b[39m`; 96 | 97 | const main = async () => { 98 | console.log( 99 | bold( 100 | magenta( 101 | dedent` 102 | Welcome to Storybook addon-kit! 103 | Please answer the following questions while we prepare this project for you:\n 104 | ` 105 | ) 106 | ) 107 | ); 108 | 109 | const { 110 | authorName, 111 | authorEmail, 112 | packageName, 113 | addonDescription, 114 | repoUrl, 115 | displayName, 116 | keywords, 117 | supportedFrameworks, 118 | } = await prompts(questions); 119 | 120 | if (!authorName || !packageName) { 121 | console.log( 122 | `\nProcess canceled by the user. Feel free to run ${bold( 123 | "yarn postinstall" 124 | )} to execute the installation steps again!` 125 | ); 126 | process.exit(0); 127 | } 128 | 129 | const authorField = authorName + (authorEmail ? ` <${authorEmail}>` : ""); 130 | 131 | const packageJson = path.resolve(__dirname, `../package.json`); 132 | 133 | console.log(`\n👷 Updating package.json...`); 134 | let packageJsonContents = fs.readFileSync(packageJson, "utf-8"); 135 | 136 | packageJsonContents = packageJsonContents 137 | .replace(REPLACE_TEMPLATES.packageName, packageName) 138 | .replace(REPLACE_TEMPLATES.addonDescription, addonDescription) 139 | .replace(REPLACE_TEMPLATES.packageAuthor, authorField) 140 | .replace(REPLACE_TEMPLATES.keywords, keywords) 141 | .replace(REPLACE_TEMPLATES.repoUrl, repoUrl) 142 | .replace(REPLACE_TEMPLATES.displayName, displayName) 143 | .replace(REPLACE_TEMPLATES.supportedFrameworks, supportedFrameworks) 144 | .replace(/\s*"postinstall".*node.*scripts\/welcome.js.*",/, ''); 145 | 146 | fs.writeFileSync(packageJson, packageJsonContents); 147 | 148 | console.log("📝 Updating the README..."); 149 | const readme = path.resolve(__dirname, `../README.md`); 150 | let readmeContents = fs.readFileSync(readme, "utf-8"); 151 | 152 | const regex = /<\!-- README START -->([\s\S]*)<\!-- README END -->/g; 153 | 154 | readmeContents = readmeContents.replace( 155 | regex, 156 | dedent` 157 | # Storybook Addon ${displayName} 158 | ${addonDescription} 159 | ` 160 | ); 161 | 162 | fs.writeFileSync(readme, readmeContents); 163 | 164 | console.log(`📦 Creating a commit...`); 165 | execSync('git add . && git commit -m "project setup" --no-verify'); 166 | 167 | console.log( 168 | dedent`\n 169 | 🚀 All done! Run \`yarn start\` to get started. 170 | 171 | Thanks for using this template, ${authorName.split(" ")[0]}! ❤️ 172 | 173 | Feel free to open issues in case there are bugs/feature requests at: 174 | 175 | ${bold(blue("https://github.com/storybookjs/addon-kit"))}\n 176 | ` 177 | ); 178 | }; 179 | 180 | main().catch((e) => console.log(`Something went wrong: ${e}`)); 181 | -------------------------------------------------------------------------------- /src/stories/assets/colors.svg: -------------------------------------------------------------------------------- 1 | illustration/colors -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![npm version](https://badge.fury.io/js/%40geometricpanda%2Fstorybook-addon-badges.svg)](https://www.npmjs.com/package/@geometricpanda/storybook-addon-badges) 2 | 3 | # Storybook Addon Badges 4 | 5 | Using `@geometricpanda/storybook-addon-badges` you're able to add badges to 6 | your [Storybook](https://storybook.js.org) app. 7 | 8 | ![Screenshot of Storybook](https://raw.githubusercontent.com/geometricpanda/storybook-addon-badges/main/media/screenshot.png) 9 | 10 | ## Installation 11 | 12 | NPM: 13 | 14 | ```shell 15 | npm install @geometricpanda/storybook-addon-badges --save 16 | ``` 17 | 18 | Yarn: 19 | 20 | ```shell 21 | yarn add @geometricpanda/storybook-addon-badges 22 | ``` 23 | 24 | ## Configuration 25 | 26 | In your `.storybook/main.ts` you'll need to load `@geometricpanda/storybook-addon-badges` into Storybook: 27 | 28 | ```typescript 29 | // .storybook/main.ts 30 | module.exports = { 31 | stories: [], 32 | addons: ['@geometricpanda/storybook-addon-badges'], 33 | }; 34 | ``` 35 | 36 | Optionally, you can define custom badge styles in `.storybook/preview.ts`. 37 | 38 | ```typescript 39 | // .storybook/preview.ts 40 | import type { Preview } from "@storybook/react"; 41 | import { BADGE, BadgesConfig, BADGE_LOCATION } from "@geometricpanda/storybook-addon-badges"; 42 | 43 | const preview: Preview = { 44 | parameters: { 45 | badgesConfig: { 46 | beta: { 47 | styles: { 48 | backgroundColor: '#FFF', 49 | borderColor: '#018786', 50 | color: '#018786', 51 | }, 52 | location: [BADGE_LOCATION.TOOLBAR, BADGE_LOCATION.SIDEBAR], 53 | title: 'Beta', 54 | }, 55 | deprecated: { 56 | styles: { 57 | backgroundColor: '#FFF', 58 | borderColor: '#6200EE', 59 | color: '#6200EE', 60 | }, 61 | location: [BADGE_LOCATION.TOOLBAR_EXTRA], 62 | title: 'Deprecated', 63 | }, 64 | }, 65 | } 66 | } 67 | 68 | export default preview; 69 | ``` 70 | 71 | ## New features 72 | 73 | - You can now define the location of each badge in the config 74 | 75 | ### Badge Locations 76 | 77 | You can import a list of locations for badges using the following import: 78 | 79 | ```typescript 80 | import { BADGE_LOCATION } from "@geometricpanda/storybook-addon-badges"; 81 | ``` 82 | 83 | You can then set the badge location via the config object: 84 | 85 | ```typescript 86 | badgesConfig: { 87 | beta: { 88 | styles: { 89 | backgroundColor: "#FFF", 90 | borderColor: "#018786", 91 | color: "#018786" 92 | }, 93 | location: [BADGE_LOCATION.TOOLBAR, BADGE_LOCATION.SIDEBAR], 94 | title: "Beta" 95 | } 96 | }; 97 | ``` 98 | 99 | If the location is not set, or the location array is empty, the badge will be displayed in the toolbar. 100 | 101 | **Please note that there is a known quirk of the `sidebar` location, which means that it only renders for the currently 102 | active story.** 103 | 104 | ## Upgrade to Storybook 7 105 | 106 | As Storybook 7 has removed the `addParameters` method, we need to migrate to exporting a `preview` object. 107 | Thankfully it's not too dissimilar to what we had before. 108 | 109 | ### Before 110 | 111 | ```typescript 112 | // .storybook/preview.ts 113 | import { addParameters } from '@storybook/react'; 114 | import { BadgesConfig } from "@geometricpanda/storybook-addon-badges"; 115 | 116 | addParameters({ 117 | badgesConfig: { 118 | ... 119 | } 120 | }); 121 | ``` 122 | 123 | ### After 124 | 125 | ```typescript 126 | // .storybook/preview.ts 127 | import type { Preview } from "@storybook/react"; 128 | import { BadgesConfig } from "@geometricpanda/storybook-addon-badges"; 129 | 130 | const preview: Preview = { 131 | parameters: { 132 | badgesConfig: { 133 | ... 134 | }, 135 | } 136 | }; 137 | 138 | export default preview; 139 | ``` 140 | 141 | Please be aware that it's now advised that stories use CSF format with external MDX files just for the docs page. 142 | As such, this addon won't officially support MDX story format, but it'll probably work just fine. 143 | 144 | ## Tooltips 145 | 146 | Optionally, you can define more complex tooltips for any of your badges. 147 | 148 | ```ts 149 | // .storybook/preview.ts 150 | import type { Preview } from "@storybook/react"; 151 | import { BADGE, BadgesConfig } from "@geometricpanda/storybook-addon-badges"; 152 | 153 | const preview: Preview = { 154 | parameters: { 155 | badgesConfig: { 156 | beta: { 157 | tooltip: { 158 | title: 'This is Beta', 159 | desc: 'Be ready to receive updates frequently and leave a feedback', 160 | links: [ 161 | { title: 'Read more', href: 'http://path/to/your/docs' }, 162 | { 163 | title: 'Leave feedback', 164 | onClick: () => { 165 | alert('thanks for the feedback'); 166 | }, 167 | }, 168 | ], 169 | }, 170 | }, 171 | deprecated: { 172 | title: "Deprecated", 173 | tooltip: 'This component is deprecated, please avoid using it.', 174 | }, 175 | }, 176 | } 177 | }; 178 | 179 | export default preview; 180 | ``` 181 | 182 | The key for each badge will be what's used throughout storybook to invoke that badge. 183 | 184 | I tend to define each key as an `enum` when using TypeScript, or even an `Object` in plain JavaScript 185 | to avoid using magic strings. 186 | 187 | Don't worry if you haven't defined a badge which you use later, any badges which aren't recognised fall 188 | back to the default preconfigured grey. 189 | 190 | _Tip: If you prefer, instead of using the `addParameters` function, you can also 191 | export `const parameters` containing a full parameters object._ 192 | 193 | ```typescript 194 | // .storybook/constants.ts 195 | export enum BADGES { 196 | STATUS = 'status', 197 | } 198 | ``` 199 | 200 | ```typescript 201 | // .storybook/preview.ts 202 | import type { Preview } from "@storybook/react"; 203 | import { BADGE, BadgesConfig } from "@geometricpanda/storybook-addon-badges"; 204 | 205 | const preview: Preview = { 206 | parameters: { 207 | badgesConfig: { 208 | [BADGE.STATUS]: { 209 | styles: { 210 | backgroundColor: '#FFF', 211 | borderColor: '#018786', 212 | color: '#018786', 213 | }, 214 | title: 'Status', 215 | }, 216 | }, 217 | } 218 | }; 219 | 220 | export default preview; 221 | ``` 222 | 223 | ## Preconfigured badges 224 | 225 | You can import a collection of preconfigured badges using the following import: 226 | 227 | ```js 228 | import { BADGE } from '@geometricpanda/storybook-addon-badges'; 229 | ``` 230 | 231 | You can then use these badges by passing in the following enum values: 232 | 233 | - `BADGE.DEFAULT` 234 | - `BADGE.BETA` 235 | - `BADGE.STABLE` 236 | - `BADGE.DEPRECATED` 237 | - `BADGE.EXPERIMENTAL` 238 | - `BADGE.NEEDS_REVISION` 239 | - `BADGE.OBSOLETE` 240 | 241 | Should you wish to override these styles you can do by configuring a badge with the same key: 242 | 243 | ```typescript 244 | // .storybook/preview.ts 245 | import type { Preview } from "@storybook/react"; 246 | import { BADGE, BadgesConfig } from "@geometricpanda/storybook-addon-badges"; 247 | 248 | const preview: Preview = { 249 | parameters: { 250 | badgesConfig: { 251 | [BADGE.STATUS]: { 252 | styles: { 253 | backgroundColor: '#FFF', 254 | borderColor: '#018786', 255 | color: '#018786', 256 | }, 257 | title: 'Status', 258 | }, 259 | }, 260 | } 261 | } 262 | 263 | export default preview; 264 | ``` 265 | 266 | Valid options for the `styles` configuration are: 267 | 268 | - `backgroundColor` 269 | - `borderColor` 270 | - `borderRadius` 271 | - `borderStyle` 272 | - `borderWidth` 273 | - `color` 274 | - `fontSize` 275 | - `fontFamily` 276 | - `fontWeight` 277 | - `lineHeight` 278 | - `textTransform` 279 | - `paddingInline` 280 | - `paddingBlock` 281 | 282 | ### Breaking Changes 283 | 284 | The previous `color` and `contrast` properties have been deprecated and have now been removed. 285 | Please migrate to the `styles` property. 286 | 287 | ## Component Story Format (CSF) 288 | 289 | ### All Stories 290 | 291 | The following will apply the badges to all components within your Story: 292 | 293 | ```jsx 294 | import { BADGE } from '@geometricpanda/storybook-addon-badges'; 295 | 296 | export default { 297 | title: 'Path/To/MyComponent', 298 | parameters: { 299 | badges: [ 300 | BADGE.DEPRECATED, 301 | BADGE.OBSOLETE 302 | ], 303 | }, 304 | }; 305 | 306 | const Template = () =>

Hello World

; 307 | 308 | export const FirstComponent = Template.bind({}); 309 | export const SecondComponent = Template.bind({}); 310 | export const ThirdComponent = Template.bind({}); 311 | ``` 312 | 313 | ### Individual Stories 314 | 315 | You can also selectively add badges to each Story: 316 | 317 | ```jsx 318 | import { BADGE } from '@geometricpanda/storybook-addon-badges'; 319 | 320 | export default { 321 | title: 'Path/To/MyComponent', 322 | }; 323 | 324 | const Template = () =>

Hello World

; 325 | 326 | export const FirstComponent = Template.bind({}); 327 | FirstComponent.parameters = { 328 | badges: [BADGE.DEPRECATED], 329 | }; 330 | 331 | export const SecondComponent = Template.bind({}); 332 | SecondComponent.parameters = { 333 | badges: [BADGE.STABLE], 334 | }; 335 | 336 | export const ThirdComponent = Template.bind({}); 337 | ThirdComponent.parameters = { 338 | badges: [BADGE.OBSOLETE], 339 | }; 340 | ``` 341 | 342 | ### Removing Badges from Stories 343 | 344 | When applying Badges to all Stories you can selectively remove them too: 345 | 346 | ```jsx 347 | import { BADGE } from '@geometricpanda/storybook-addon-badges'; 348 | 349 | export default { 350 | title: 'Path/To/MyComponent', 351 | parameters: { 352 | badges: [BADGE.BETA], 353 | }, 354 | }; 355 | 356 | const Template = () =>

Hello World

; 357 | 358 | export const FirstComponent = Template.bind({}); 359 | export const SecondComponent = Template.bind({}); 360 | 361 | export const ThirdComponent = Template.bind({}); 362 | ThirdComponent.parameters = { 363 | badges: [], 364 | }; 365 | ``` 366 | 367 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # v2.0.5 (Fri Oct 11 2024) 2 | 3 | #### 🐛 Bug Fix 4 | 5 | - fix: use the item's name as the name of the leaf node [#27](https://github.com/geometricpanda/storybook-addon-badges/pull/27) ([@DanielRose](https://github.com/DanielRose)) 6 | 7 | #### Authors: 1 8 | 9 | - Daniel Rose ([@DanielRose](https://github.com/DanielRose)) 10 | 11 | --- 12 | 13 | # v2.0.4 (Sun Sep 29 2024) 14 | 15 | #### ⚠️ Pushed to `main` 16 | 17 | - chore: remove install state ([@geometricpanda](https://github.com/geometricpanda)) 18 | - chore: ignore install-state.gz ([@geometricpanda](https://github.com/geometricpanda)) 19 | - chore: updates action to use differnet yarn command ([@geometricpanda](https://github.com/geometricpanda)) 20 | - chore: fix lockfile ([@geometricpanda](https://github.com/geometricpanda)) 21 | - Merge branch 'main' of https://github.com/geometricpanda/storybook-addon-badges ([@geometricpanda](https://github.com/geometricpanda)) 22 | - feat: add ability to control location ([@geometricpanda](https://github.com/geometricpanda)) 23 | 24 | #### Authors: 1 25 | 26 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 27 | 28 | --- 29 | 30 | # v2.0.3 (Sun Sep 29 2024) 31 | 32 | #### 🐛 Bug Fix 33 | 34 | - fix: 🐛 Resolves yarn version mismatch in release workflow [#23](https://github.com/geometricpanda/storybook-addon-badges/pull/23) ([@JamesIves](https://github.com/JamesIves)) 35 | - Storybook 8 compatibility [#22](https://github.com/geometricpanda/storybook-addon-badges/pull/22) ([@evg4b](https://github.com/evg4b)) 36 | 37 | #### ⚠️ Pushed to `main` 38 | 39 | - chore: updating setup-node action ([@geometricpanda](https://github.com/geometricpanda)) 40 | 41 | #### Authors: 3 42 | 43 | - Evgeny Abramovich ([@evg4b](https://github.com/evg4b)) 44 | - James Ives ([@JamesIves](https://github.com/JamesIves)) 45 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 46 | 47 | --- 48 | 49 | # v2.0.2 (Fri Feb 09 2024) 50 | 51 | #### 🐛 Bug Fix 52 | 53 | - Export types from index. [#19](https://github.com/geometricpanda/storybook-addon-badges/pull/19) ([@DrJKL](https://github.com/DrJKL)) 54 | 55 | #### Authors: 1 56 | 57 | - Alexander Brown ([@DrJKL](https://github.com/DrJKL)) 58 | 59 | --- 60 | 61 | # v2.0.1 (Fri Jan 12 2024) 62 | 63 | #### 🐛 Bug Fix 64 | 65 | - fix: do not render separators if no badges [#16](https://github.com/geometricpanda/storybook-addon-badges/pull/16) ([@kzimins-arvatosystems](https://github.com/kzimins-arvatosystems)) 66 | 67 | #### Authors: 1 68 | 69 | - Konstantīns Zimins ([@kzimins-arvatosystems](https://github.com/kzimins-arvatosystems)) 70 | 71 | --- 72 | 73 | # v2.0.0 (Tue Apr 11 2023) 74 | 75 | #### 💥 Breaking Change 76 | 77 | - chore(storybook-7): upgrades to support storybook 7 [#12](https://github.com/geometricpanda/storybook-addon-badges/pull/12) ([@geometricpanda](https://github.com/geometricpanda)) 78 | 79 | #### Authors: 1 80 | 81 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 82 | 83 | --- 84 | 85 | # v1.1.1 (Wed Mar 01 2023) 86 | 87 | #### ⚠️ Pushed to `main` 88 | 89 | - feat: updates icon and storybook metadata ([@geometricpanda](https://github.com/geometricpanda)) 90 | 91 | #### Authors: 1 92 | 93 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 94 | 95 | --- 96 | 97 | # v1.1.0 (Wed Mar 01 2023) 98 | 99 | #### 🚀 Enhancement 100 | 101 | - Refactor/simplify badge [#10](https://github.com/geometricpanda/storybook-addon-badges/pull/10) ([@geometricpanda](https://github.com/geometricpanda)) 102 | 103 | #### ⚠️ Pushed to `main` 104 | 105 | - Merge branch 'main' of https://github.com/geometricpanda/storybook-addon-badges (jim.drury@virginmediao2.co.uk) 106 | 107 | #### Authors: 2 108 | 109 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 110 | - Jim Drury (jim.drury@virginmediao2.co.uk) 111 | 112 | --- 113 | 114 | # v1.0.2 (Mon Feb 27 2023) 115 | 116 | #### 🐛 Bug Fix 117 | 118 | - fix: exports badges in default export [#6](https://github.com/geometricpanda/storybook-addon-badges/pull/6) (jim.drury@virginmediao2.co.uk [@geometricpanda](https://github.com/geometricpanda)) 119 | 120 | #### Authors: 2 121 | 122 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 123 | - Jim Drury (jim.drury@virginmediao2.co.uk) 124 | 125 | --- 126 | 127 | # v1.0.1 (Mon Feb 27 2023) 128 | 129 | #### 🐛 Bug Fix 130 | 131 | - fix: resolves issue with preview preset [#3](https://github.com/geometricpanda/storybook-addon-badges/pull/3) (jim.drury@virginmediao2.co.uk [@geometricpanda](https://github.com/geometricpanda)) 132 | 133 | #### Authors: 2 134 | 135 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 136 | - Jim Drury (jim.drury@virginmediao2.co.uk) 137 | 138 | --- 139 | 140 | # v1.0.0 (Mon Feb 27 2023) 141 | 142 | #### 💥 Breaking Change 143 | 144 | - docs: updates docs to new repo path [#2](https://github.com/geometricpanda/storybook-addon-badges/pull/2) (jim@jimdrury.co.uk [@geometricpanda](https://github.com/geometricpanda)) 145 | 146 | #### 🚀 Enhancement 147 | 148 | - refactor: migrates badges into storybook addon kit format [#1](https://github.com/geometricpanda/storybook-addon-badges/pull/1) (jim@jimdrury.co.uk [@geometricpanda](https://github.com/geometricpanda)) 149 | 150 | #### ⚠️ Pushed to `main` 151 | 152 | - project setup (jim@jimdrury.co.uk) 153 | - fix: `postinstall` script removal ([@sheriffMoose](https://github.com/sheriffMoose)) 154 | - fix: welcome message grammar ([@eddiemonge](https://github.com/eddiemonge)) 155 | - FIxes broken links ([@jonniebigodes](https://github.com/jonniebigodes)) 156 | - Add addon-generated toolbar example ([@shilman](https://github.com/shilman)) 157 | - fix initial type ([@makotot](https://github.com/makotot)) 158 | - Add React 18 support ([@winkerVSbecks](https://github.com/winkerVSbecks)) 159 | - upgrade to SB 6.5 ([@winkerVSbecks](https://github.com/winkerVSbecks)) 160 | - fix: decorator types ([@italoteix](https://github.com/italoteix)) 161 | - remove posinstall script after the first run ([@winkerVSbecks](https://github.com/winkerVSbecks)) 162 | - copy edits ([@winkerVSbecks](https://github.com/winkerVSbecks)) 163 | - add a welcome script ([@winkerVSbecks](https://github.com/winkerVSbecks)) 164 | - perf: Modify the corresponding ID ([@SCWR](https://github.com/SCWR)) 165 | - upgrade to storybook 6.4 ([@winkerVSbecks](https://github.com/winkerVSbecks)) 166 | - Update README.md ([@literalpie](https://github.com/literalpie)) 167 | - Update Storybook from 6.2.9 to 6.3.6 ([@chantastic](https://github.com/chantastic)) 168 | - Fix issue with global persistently showing in URL ([@ghengeveld](https://github.com/ghengeveld)) 169 | - Update README.md ([@ghengeveld](https://github.com/ghengeveld)) 170 | - Add a prepublish check for README, use zx for all the scripts and fix deps ([@winkerVSbecks](https://github.com/winkerVSbecks)) 171 | - Add essentials and fix selector for docs tab ([@winkerVSbecks](https://github.com/winkerVSbecks)) 172 | - Use interface instead of type and React.FC ([@winkerVSbecks](https://github.com/winkerVSbecks)) 173 | - update README ([@winkerVSbecks](https://github.com/winkerVSbecks)) 174 | - Add script to eject TS mode ([@winkerVSbecks](https://github.com/winkerVSbecks)) 175 | - migrate code to typescript ([@winkerVSbecks](https://github.com/winkerVSbecks)) 176 | - Update withGlobals.js ([@kjenkins19](https://github.com/kjenkins19)) 177 | - upgrade deps ([@winkerVSbecks](https://github.com/winkerVSbecks)) 178 | - Add both esm as a build target ([@winkerVSbecks](https://github.com/winkerVSbecks)) 179 | - switch to yarn ([@winkerVSbecks](https://github.com/winkerVSbecks)) 180 | - Add dummy.ts to make tsc happy ([@shilman](https://github.com/shilman)) 181 | - Add out-of-the-box typescript support ([@shilman](https://github.com/shilman)) 182 | - Add a prerelease check for metadata ([@winkerVSbecks](https://github.com/winkerVSbecks)) 183 | - use dist/preset as main ([@winkerVSbecks](https://github.com/winkerVSbecks)) 184 | - start versioning at 0.0.0 ([@hipstersmoothie](https://github.com/hipstersmoothie)) 185 | - add automated release setup ([@hipstersmoothie](https://github.com/hipstersmoothie)) 186 | - Add publishConfig for scoped packages ([@shilman](https://github.com/shilman)) 187 | - add lockfile ([@winkerVSbecks](https://github.com/winkerVSbecks)) 188 | - Remove chromatic ([@winkerVSbecks](https://github.com/winkerVSbecks)) 189 | - Add header and page stories ([@winkerVSbecks](https://github.com/winkerVSbecks)) 190 | - Update README.md ([@winkerVSbecks](https://github.com/winkerVSbecks)) 191 | - Panel expandable item and clear data when switching stories ([@winkerVSbecks](https://github.com/winkerVSbecks)) 192 | - Add documentation ([@winkerVSbecks](https://github.com/winkerVSbecks)) 193 | - Add more contextual info to the UI patterns ([@winkerVSbecks](https://github.com/winkerVSbecks)) 194 | - set up chromatic ([@winkerVSbecks](https://github.com/winkerVSbecks)) 195 | - extract presentational components ([@winkerVSbecks](https://github.com/winkerVSbecks)) 196 | - use a more realistic example of supportedFrameworks ([@winkerVSbecks](https://github.com/winkerVSbecks)) 197 | - use {} in template.bind ([@winkerVSbecks](https://github.com/winkerVSbecks)) 198 | - First commit ([@winkerVSbecks](https://github.com/winkerVSbecks)) 199 | - Create LICENSE ([@winkerVSbecks](https://github.com/winkerVSbecks)) 200 | 201 | #### Authors: 15 202 | 203 | - [@jonniebigodes](https://github.com/jonniebigodes) 204 | - Andrew Lisowski ([@hipstersmoothie](https://github.com/hipstersmoothie)) 205 | - Benjamin Kindle ([@literalpie](https://github.com/literalpie)) 206 | - Eddie Monge Jr ([@eddiemonge](https://github.com/eddiemonge)) 207 | - Gert Hengeveld ([@ghengeveld](https://github.com/ghengeveld)) 208 | - Ítalo Teixeira ([@italoteix](https://github.com/italoteix)) 209 | - Jim Drury (he/him) ([@geometricpanda](https://github.com/geometricpanda)) 210 | - Jim Drury (jim@jimdrury.co.uk) 211 | - Kyle Jenkins ([@kjenkins19](https://github.com/kjenkins19)) 212 | - Makoto Tateno ([@makotot](https://github.com/makotot)) 213 | - Michael Chan ([@chantastic](https://github.com/chantastic)) 214 | - Michael Shilman ([@shilman](https://github.com/shilman)) 215 | - Mostafa Sherif ([@sheriffMoose](https://github.com/sheriffMoose)) 216 | - SCWR ([@SCWR](https://github.com/SCWR)) 217 | - Varun Vachhar ([@winkerVSbecks](https://github.com/winkerVSbecks)) 218 | --------------------------------------------------------------------------------