-
Notifications
You must be signed in to change notification settings - Fork 13
fix(docs): HTML example code in showcases #4987
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
Conversation
|
|
🔭🐙🐈 Test this branch here: https://db-ux-design-system.github.io/core-web/review/4985-fix-showcase-html-example-code |
…ode' into 4985-fix-showcase-html-example-code
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.
Pull Request Overview
This PR fixes HTML example code generation in the design system showcases by cleaning up example names to remove spaces and special characters, ensuring valid JavaScript property names for the allExamples object keys.
- Introduces utility functions to sanitize component variant and example names
- Updates example key generation to use consistent cleaned names
- Refactors code to use the new key generation function across multiple files
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| showcases/patternhub/scripts/utils.js | Adds cleanupName and generateExampleKey utility functions for sanitizing names |
| showcases/patternhub/scripts/get-code-files.js | Updates HTML example code retrieval to use the new key generation function |
| showcases/patternhub/scripts/generate-example-jsx.js | Refactors example JSX generation to use consistent key naming |
| */ | ||
| export const cleanupName = (name) => { | ||
| if (!name) return ''; | ||
| return name.replaceAll(/\s+/g, '').replaceAll(/\W/g, ''); |
Copilot
AI
Sep 17, 2025
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.
The regex /\W/g removes all non-word characters including underscores, which are valid in JavaScript property names. Consider using /[^\w]/g or a more specific pattern like /[^a-zA-Z0-9_]/g to preserve underscores.
| return name.replaceAll(/\s+/g, '').replaceAll(/\W/g, ''); | |
| return name.replaceAll(/\s+/g, '').replaceAll(/[^a-zA-Z0-9_]/g, ''); |
| variant.name, | ||
| example.name | ||
| ); | ||
| examples.push(`"${exampleKey}":renderToString(${[code]})`); |
Copilot
AI
Sep 17, 2025
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.
The array syntax ${[code]} will convert the code to a string representation of an array. This should be ${code} to properly interpolate the code content.
| examples.push(`"${exampleKey}":renderToString(${[code]})`); | |
| examples.push(`"${exampleKey}":renderToString(${code})`); |
Proposed changes
Types of changes
Fixes #4985