-
Notifications
You must be signed in to change notification settings - Fork 70
Configure Storybook and Document Design System Primitives (#361) #433
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
Open
JoyLight00
wants to merge
3
commits into
LightForgeHub:main
Choose a base branch
from
JoyLight00:feat/storybook-primitives-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
281b406
feat(storybook): configure storybook with vite and add primitive comp…
JoyLight00 091fd9d
fix(contracts): resolve custom attribute panic LengthExceedsMax by sp…
JoyLight00 b7f1039
fix(ci): silence clippy warnings in contracts and sync package-lock.json
JoyLight00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { StorybookConfig } from "@storybook/react-vite"; | ||
|
|
||
| const config: StorybookConfig = { | ||
| stories: [ | ||
| "../src/**/*.mdx", | ||
| "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)", | ||
| ], | ||
| addons: [ | ||
| "@storybook/addon-links", | ||
| "@storybook/addon-essentials", | ||
| "@storybook/addon-onboarding", | ||
| "@storybook/addon-interactions", | ||
| ], | ||
| framework: { | ||
| name: "@storybook/react-vite", | ||
| options: {}, | ||
| }, | ||
| docs: { | ||
| autodocs: "tag", | ||
| }, | ||
| }; | ||
| export default config; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import type { Preview } from "@storybook/react"; | ||
| import "../src/app/globals.css"; | ||
|
|
||
| const preview: Preview = { | ||
| parameters: { | ||
| controls: { | ||
| matchers: { | ||
| color: /(background|color)$/i, | ||
| date: /Date$/i, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default preview; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": "../tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": false | ||
| }, | ||
| "include": ["../src/**/*"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: LightForgeHub/SkillSphere-Dapp
Length of output: 196
🏁 Script executed:
Repository: LightForgeHub/SkillSphere-Dapp
Length of output: 2942
🏁 Script executed:
Repository: LightForgeHub/SkillSphere-Dapp
Length of output: 24191
🌐 Web query:
Storybook 8 react-vite tsconfig paths viteFinal alias automatic support documentation💡 Result:
In Storybook 8 with the Vite builder, the approach for handling TypeScript path aliases (defined in tsconfig.json) depends on your version of Vite [1][2]. For projects using Vite 8 or higher, Storybook supports native resolution of TypeScript paths [1][2]. You do not need to use external plugins like vite-tsconfig-paths [1]. Instead, you should enable native support in your Vite configuration file (vite.config.ts) [1]: // vite.config.ts export default defineConfig({ resolve: { tsconfigPaths: true, }, }); If you are using an older version of Vite or need to manually configure aliases in Storybook regardless of your global Vite setup, you can use the viteFinal function in your.storybook/main.ts file [3][4]. This allows you to merge custom Vite configurations into the Storybook build process [5][4]. To manually configure paths using vite-tsconfig-paths (for older Vite versions): //.storybook/main.ts import { mergeConfig } from 'vite'; import tsconfigPaths from 'vite-tsconfig-paths'; export default { //... other config async viteFinal(config) { return mergeConfig(config, { plugins: [tsconfigPaths], }); }, }; Alternatively, to manually define specific aliases without a plugin: //.storybook/main.ts import { mergeConfig } from 'vite'; import path from 'path'; export default { //... other config async viteFinal(config) { return mergeConfig(config, { resolve: { alias: { '@': path.resolve(dirname, '../src'), }, }, }); }, }; Important Considerations: 1. Vite Configuration File: By default, Storybook's Vite builder attempts to read your project's vite.config.ts file [6][4]. However, it may sometimes override or ignore parts of it to ensure compatibility with Storybook’s internal build requirements [7][3]. 2. viteFinal: This function is the recommended way to override or extend the Vite configuration specifically for Storybook [8][4]. It receives the existing config and must return the modified version [5][4]. 3. Native Support: Always check if your project is running Vite 8+, as the native
resolve.tsconfigPaths: trueoption is the preferred, modern approach [1][2].Citations:
vite-tsconfig-pathsused on Vite 8 storybookjs/vite-plugin-storybook-nextjs#108🏁 Script executed:
Repository: LightForgeHub/SkillSphere-Dapp
Length of output: 487
🏁 Script executed:
Repository: LightForgeHub/SkillSphere-Dapp
Length of output: 474
🏁 Script executed:
Repository: LightForgeHub/SkillSphere-Dapp
Length of output: 12057
🌐 Web query:
Storybook 8 builder-vite tsconfig paths automatically resolved vite 6 viteFinal alias docs💡 Result:
Storybook 8 does not automatically resolve tsconfig paths for the Vite builder [1][2]. While Storybook's Vite builder attempts to merge your root
vite.config.tsinto its own configuration, it does not inherently applytsconfig.jsonpath mappings [3][4][2]. To resolve these aliases, you must explicitly configure them in your.storybook/main.tsfile using theviteFinalhook [3][1][4]. The most common and effective way to achieve this is by using thevite-tsconfig-pathsplugin withinviteFinal[1][2][5]. Implementation Example: In your.storybook/main.ts(or.js), you can modify the Vite configuration as follows: import type { StorybookConfig } from '@storybook/your-framework'; import { mergeConfig } from 'vite'; import tsconfigPaths from 'vite-tsconfig-paths'; const config: StorybookConfig = { //... rest of your config async viteFinal(config) { return mergeConfig(config, { plugins: [tsconfigPaths], }); }, }; export default config; Alternatively, you can define aliases manually withinviteFinalif you prefer not to use a plugin: async viteFinal(config) { config.resolve = config.resolve || {}; config.resolve.alias = {...(config.resolve.alias || {}), '@/src': path.resolve(dirname, '../src'), }; return config; }, Important Notes: 1. Vite Configuration: While Storybook looks for avite.config.tsin your project root, it may not pick up all settings (like path plugins) automatically due to the specific way Storybook needs to wrap and manage the configuration [4][2]. 2. Custom Config Paths: If your Storybook configuration folder is not at the project root, you may need to explicitly specify theviteConfigPathin yourmain.tsto ensure your base Vite configuration is loaded correctly [3][1][4]. 3. Vite 6 Compatibility: The approach of usingviteFinalto inject plugins or aliases remains the standard method for Vite 6 compatibility in Storybook 8 [3][6]. Ensure your dependencies, includingvite-tsconfig-paths, are updated to versions compatible with Vite 6.Citations:
Add Storybook Vite alias wiring
.storybook/main.tsdoesn’t inherit the repo’s@/*path mapping, and Storybook 8 with Vite 6 won’t resolvetsconfig.jsonpaths on its own. Add aviteFinalhook (or equivalentresolve.alias) here so stories can import@/...modules without build failures.🤖 Prompt for AI Agents