-
Notifications
You must be signed in to change notification settings - Fork 10
Add dialog component #76
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dabc124
feat: enhance Select component with additional stories and features
Aunshon 377d091
feat: update ComboboxDropdownMenuDemo to improve dropdown menu struct…
Aunshon 44af396
feat: enhance Combobox component with dropdown menu and dialog for la…
Aunshon 2245416
feat: enhance ComboboxInput component with aria-invalid styles and tr…
Aunshon f2bc6b1
feat: enhance AsyncCombobox component with improved search functional…
Aunshon 29dc014
feat: add AsyncMultiCombobox component with various demo stories
Aunshon c793a5a
feat: update AsyncMultiCombobox badge styles for improved appearance
Aunshon 0c8f593
feat: improve AsyncMultiCombobox accessibility and interaction for di…
Aunshon 725f193
feat: add static options demos for AsyncCombobox and AsyncMultiCombob…
Aunshon c171100
feat: add SmartMultiSelect and SmartSelect components with comprehens…
Aunshon cd7e13f
feat: enhance SmartSelect and SmartMultiSelect components with create…
Aunshon d426bb0
feat: optimize option handling in SmartSelect create functionality
Aunshon 0bf9d64
feat: refactor addOption function to update filteredOptions in a sing…
Aunshon 2a83360
feat: add create functionality and custom forms to SmartMultiSelect c…
Aunshon a76b96f
feat: replace ChevronsUpDownIcon with ChevronDownIcon in SmartMultiSe…
Aunshon 6399e0a
feat: add Babel plugin to inject source code of wrapper functions int…
Aunshon e43b9af
feat: add Claude theme and dark theme to theme options
Aunshon 7ca9cf5
Refactor code structure for improved readability and maintainability
Aunshon 362de4c
Implement feature X to enhance user experience and optimize performance
Aunshon 4560196
Implement feature X to enhance user experience and fix bug Y in module Z
Aunshon 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /** | ||
| * Babel plugin that extracts wrapper/demo function source code and injects it | ||
| * as `parameters.docs.source.code` into Storybook story exports. | ||
| * | ||
| * Problem: Stories that use `render: () => <DemoWrapper />` cause Storybook's | ||
| * "Show code" panel to display `<DemoWrapper />` instead of the actual | ||
| * component usage inside the wrapper. | ||
| * | ||
| * Solution: At compile time, this plugin: | ||
| * 1. Collects all top-level non-exported function declarations (the wrappers). | ||
| * 2. For each story export whose render body is `<WrapperName />`, it copies | ||
| * the wrapper function's original source into | ||
| * `parameters.docs.source.code` so Storybook displays it verbatim. | ||
| */ | ||
| module.exports = function storySourcePlugin({ types: t }) { | ||
| return { | ||
| name: 'story-source-injector', | ||
| visitor: { | ||
| Program: { | ||
| enter(programPath, state) { | ||
| const fileSource = state.file.code; | ||
| if (!fileSource) return; | ||
|
|
||
| // ── Step 1: collect wrapper functions ──────────────────────── | ||
| const wrapperFunctions = new Map(); | ||
|
|
||
| for (const stmt of programPath.get('body')) { | ||
| // Skip any exported declaration | ||
| if ( | ||
| stmt.isExportNamedDeclaration() || | ||
| stmt.isExportDefaultDeclaration() | ||
| ) { | ||
| continue; | ||
| } | ||
|
|
||
| if (stmt.isFunctionDeclaration()) { | ||
| const name = stmt.node.id?.name; | ||
| if (!name) continue; | ||
|
|
||
| const { start, end } = stmt.node; | ||
| if (start == null || end == null) continue; | ||
|
|
||
| wrapperFunctions.set(name, fileSource.slice(start, end)); | ||
| } | ||
| } | ||
|
|
||
| if (wrapperFunctions.size === 0) return; | ||
|
|
||
| // ── Step 2: inject source into matching story exports ──────── | ||
| for (const stmt of programPath.get('body')) { | ||
| if (!stmt.isExportNamedDeclaration()) continue; | ||
|
|
||
| const decl = stmt.get('declaration'); | ||
| if (!decl.isVariableDeclaration()) continue; | ||
|
|
||
| for (const declarator of decl.get('declarations')) { | ||
| let init = declarator.get('init'); | ||
|
|
||
| // Unwrap `{ ... } satisfies Type` or `{ ... } as Type` | ||
| if ( | ||
| init.isTSSatisfiesExpression?.() || | ||
| init.isTSAsExpression?.() | ||
| ) { | ||
| init = init.get('expression'); | ||
| } | ||
|
|
||
| if (!init.isObjectExpression()) continue; | ||
|
|
||
| const properties = init.get('properties'); | ||
|
|
||
| // Find `render` property | ||
| const renderProp = properties.find( | ||
| (p) => | ||
| p.isObjectProperty() && | ||
| p.get('key').isIdentifier({ name: 'render' }) | ||
| ); | ||
| if (!renderProp) continue; | ||
|
|
||
| const renderVal = renderProp.get('value'); | ||
| if (!renderVal.isArrowFunctionExpression()) continue; | ||
|
|
||
| const renderBody = renderVal.get('body'); | ||
| if (!renderBody.isJSXElement()) continue; | ||
|
|
||
| // Must be a self-closing element: <WrapperName /> | ||
| const opening = renderBody.get('openingElement'); | ||
| const nameNode = opening.get('name'); | ||
| if (!nameNode.isJSXIdentifier()) continue; | ||
|
|
||
| const wrapperName = nameNode.node.name; | ||
| if (!wrapperFunctions.has(wrapperName)) continue; | ||
|
|
||
| // Skip stories that already define their own `parameters` | ||
| const hasParams = properties.some( | ||
| (p) => | ||
| p.isObjectProperty() && | ||
| p.get('key').isIdentifier({ name: 'parameters' }) | ||
| ); | ||
| if (hasParams) continue; | ||
|
|
||
| // Build: parameters: { docs: { source: { code, language } } } | ||
| const sourceCode = wrapperFunctions.get(wrapperName); | ||
|
|
||
| const sourceObj = t.objectExpression([ | ||
| t.objectProperty( | ||
| t.identifier('code'), | ||
| t.stringLiteral(sourceCode) | ||
| ), | ||
| t.objectProperty( | ||
| t.identifier('language'), | ||
| t.stringLiteral('tsx') | ||
| ), | ||
| ]); | ||
|
|
||
| const docsObj = t.objectExpression([ | ||
| t.objectProperty(t.identifier('source'), sourceObj), | ||
| ]); | ||
|
|
||
| const paramsObj = t.objectExpression([ | ||
| t.objectProperty(t.identifier('docs'), docsObj), | ||
| ]); | ||
|
|
||
| init.node.properties.push( | ||
| t.objectProperty(t.identifier('parameters'), paramsObj) | ||
| ); | ||
| } | ||
| } | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
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.
Don’t bail out when
parametersalready exists; mergedocs.sourceinstead.At Line 99, the plugin exits if
parametersexists, so many valid stories won’t get injected source at all. This undermines the plugin’s core behavior.Suggested diff
🤖 Prompt for AI Agents