樣式設定

用於配置熱門樣式工具的基本附加元件

在 Github 上檢視

⚠️ 此附加元件已正式棄用 ⚠️

自發布以來,addon-styling 一直是在 Storybook 中設定樣式的絕佳方式。然而,隨著附加元件迅速發展,很明顯它試圖做太多事情。它試圖成為一個配置工具、一個主題工具,並且還包含笨重的程式碼修改。這使得它難以維護,並添加了大多數用戶不需要的大量依賴項。

為了處理這個問題,我將附加元件拆分為兩個獨立的附加元件,@storybook/addon-styling-webpack@storybook/addon-themes。這些附加元件更加專注,並允許我們更快地迭代它們。

@storybook/addon-styling-webpack 將專門用於使用熱門工具(如 Tailwind、Post CSS、SCSS、Less 和 Vanilla-extract)配置您基於 Webpack 的 Storybook

@storybook/addon-themes 將專注於在 Storybook 中提供和切換多個主題,無論您使用什麼構建工具。

我也已將程式碼修改移至一個單獨的套件中,以便它們可以通過 npx/ yarn dlx / pnpm dlx 使用,而無需在您的 node_modules 中保留笨重的程式碼修改。

我添加了一個遷移指南,以幫助您遷移到新的附加元件。如果您有任何問題,請隨時在 TwitterStorybook Discord 中的支援頻道上與我聯繫。

一切順利,Shaun Evening


@storybook/addon-styling

使用熱門的樣式工具,更快地開始使用 Storybook 7。

使用 Storybook 6?請查看 release-0-3 分支

Toggling between themes

✨ 功能

  • 🤖 通過程式碼修改為熱門工具提供零配置。閱讀更多
  • 🧩 熱門工具的配置範本
  • ⚡️ css 模組、postCss、Sass 和 Less 的選項
  • 🎨 提供主題
  • 🔄 當提供多個主題時,在多個主題之間切換
  • ❗️ 通過參數在元件和 story 層級覆寫主題

🏁 開始使用

要開始使用,請將套件安裝為開發依賴項

yarn

yarn add -D @storybook/addon-styling

npm

npm install -D @storybook/addon-styling

pnpm

pnpm add -D @storybook/addon-styling

然後,將附加元件包含在您的 .storybook/main.js 檔案中

module.exports = {
  stories: [
    "../stories/**/*.stories.mdx",
    "../stories/**/*.stories.@(js|jsx|ts|tsx)",
  ],
  addons: [
    "@storybook/addon-essentials",
+   "@storybook/addon-styling"
  ],
};

👇 特定工具配置

有關特定工具的設定,請查看下面的配方

沒有看到您最喜歡的工具列出?別擔心!這並不表示此附加元件不適合您。請查看 API 參考「編寫自訂裝飾器」部分。

❗️ 覆寫主題

如果您想要覆寫特定元件或 story 的主題,可以使用 theming.themeOverride 參數。

import React from "react";
import { Button } from "./Button";

export default {
  title: "Example/Button",
  component: Button,
  parameters: {
    theming: {
      themeOverride: "light", // component level override
    },
  },
};

const Template = (args) => <Button {...args} />;

export const Primary = Template.bind({});
Primary.args = {
  primary: true,
  label: "Button",
};

export const PrimaryDark = Template.bind({});
PrimaryDark.args = {
  primary: true,
  label: "Button",
};
PrimaryDark.parameters = {
  theming: {
    themeOverride: "dark", // Story level override
  },
};

🤝 貢獻

如果您想為此附加元件貢獻,非常感謝,我很樂意獲得您的幫助 🙏

📝 開發腳本

  • yarn start 在監看模式下執行 babel 並啟動 Storybook
  • yarn build 建構並封裝您的附加元件程式碼

🌲 分支結構

  • next - npm 上的 next 版本,以及大多數工作發生的開發分支
  • main - npm 上的 latest 版本,以及大多數用戶使用的穩定版本

🚀 發布流程

  1. 所有 PR 都應針對 next 分支,該分支依賴於 Storybook 的 next 版本。
  2. 合併後,此套件的新版本將在 next NPM 標籤上發布。
  3. 如果變更包含需要修補回穩定版本的錯誤修復,請在 PR 說明中註明。
  4. 標記為 pick 的 PR 將會被 cherry-picked 回 main 分支,並會在 latest npm 標籤上生成發布。
  • thafryer
    thafryer
  • shaunlloyd
    shaunlloyd
  • kylegach
    kylegach
  • tooppaaa
    tooppaaa
  • ndelangen
    ndelangen
  • shilman
    shilman
適用於
    Angular
    Ember
    HTML
    Preact
    React
    React native
    Svelte
    Vue
    Web Components
標籤