-
Notifications
You must be signed in to change notification settings - Fork 34
feat(evo-react): Add EvoIcon component #563
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
HenriqueLimas
wants to merge
3
commits into
main
Choose a base branch
from
feat/evo-react-icons
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
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
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,5 @@ | ||
| --- | ||
| "@evo-web/react": patch | ||
| --- | ||
|
|
||
| feat(evo-react): add icon components |
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,66 @@ | ||
| # 4. Evo React Import Paths | ||
|
|
||
| **Date:** 2026-03-12 | ||
|
|
||
| ## Status | ||
|
|
||
| Accepted | ||
|
|
||
| ## Context | ||
|
|
||
| The `@ebay/ebayui-core-react` package uses individual subpath exports for every component, requiring imports like: | ||
|
|
||
| ```tsx | ||
| import { EbayButton } from "@ebay/ebayui-core-react/ebay-button"; | ||
| import { EbayIconCart16 } from "@ebay/ebayui-core-react/icons/ebay-icon-cart-16"; | ||
| ``` | ||
|
|
||
| This approach optimizes tree-shaking at the cost of more verbose imports and increased cognitive overhead. | ||
|
|
||
| For `@evo-web/react`, we need to decide on an import strategy that balances bundle size optimization, developer experience, and build performance. The core issue with importing all 1,036+ icons from a single entry point is that bundlers must parse and tree-shake them on every build, significantly impacting build performance and risking bundle bloat if tree-shaking fails. | ||
|
|
||
| ## Decision | ||
|
|
||
| Use a **hybrid import strategy** for `@evo-web/react`: | ||
|
|
||
| ### Components (Unified Entry Point) | ||
|
|
||
| All non-icon components export from the main package entry: | ||
|
|
||
| ```tsx | ||
| import { EvoButton, EvoTextbox, EvoIconProvider } from "@evo-web/react"; | ||
| ``` | ||
|
|
||
| **Rationale:** Small number of components (~20-30 total expected), minimal tree-shaking overhead, simpler imports, better developer experience. | ||
|
|
||
| ### Icons (Individual Subpath Exports) | ||
|
|
||
| Each icon has its own subpath export: | ||
|
|
||
| ```tsx | ||
| import { EvoIconCart16 } from "@evo-web/react/evo-icon-cart-16"; | ||
| import { EvoIconChevronDown24 } from "@evo-web/react/evo-icon-chevron-down-24"; | ||
| ``` | ||
|
|
||
| **Rationale:** | ||
|
|
||
| - **Bundle size**: Bundlers resolve exact files without parsing 1,000+ unused icons | ||
| - **Build performance**: Skip tree-shaking analysis for unused icons entirely | ||
| - **No bloat risk**: Direct imports prevent accidental bundling of unused icons | ||
| - **Type safety**: TypeScript resolves icon types without loading all 1,036 definitions | ||
|
|
||
| ## Consequences | ||
|
|
||
| ### Positive | ||
|
|
||
| - Faster builds: Bundlers only process icons actually imported | ||
| - Smaller bundles: Zero risk of accidentally including unused icons | ||
| - Better DX for components: Single import for most use cases | ||
| - Type performance: IDEs don't auto-complete 1,036 icon names from main export | ||
| - Explicit icon usage: Clear dependency on which icons are used | ||
|
|
||
| ### Negative | ||
|
|
||
| - Verbose icon imports: Each icon requires its own import statement | ||
| - Mixed patterns: Developers must remember two import styles | ||
| - Autocomplete fragmentation: Icons don't appear in main package autocomplete |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| /** | ||
| * Loads icons from @ebay/skin and generates individual React icon components | ||
| */ | ||
|
|
||
| import * as fs from "fs"; | ||
| import * as path from "path"; | ||
| import { createRequire } from "module"; | ||
| import { fileURLToPath } from "url"; | ||
| import { parseSync, stringify } from "svgson"; | ||
| import { deleteSync } from "del"; | ||
|
|
||
| const require = createRequire(import.meta.url); | ||
|
|
||
| const skinDir = path.dirname(require.resolve("@ebay/skin/package.json")); | ||
| const svgDir = path.join(skinDir, "dist/svg"); | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = path.dirname(__filename); | ||
|
|
||
| const fileHeader = `// AUTO-GENERATED by \`importSVG\` script (\`scripts/import-svg.ts\`)`; | ||
|
|
||
| function parseSVG(skinIconsFile: string): any[] { | ||
| const icons = fs.readFileSync(skinIconsFile).toString(); | ||
| return ( | ||
| ((icons && parseSync(icons, { camelcase: false })) || {}).children || [] | ||
| ); | ||
| } | ||
|
|
||
| function parseSVGSymbols(skinIconsFile: string): any[] { | ||
| const icons = parseSVG(skinIconsFile); | ||
| return icons.filter(({ name }) => name === "symbol"); | ||
| } | ||
|
|
||
| function camelCased(str: string): string { | ||
| return str | ||
| .replace(/^icon-/, "") | ||
| .replace(/-(\d+)/g, (_, num) => num) | ||
| .replace(/-([a-z])/g, (_, char) => char.toUpperCase()); | ||
| } | ||
|
|
||
| function saveIconComponents(svgFile: string): void { | ||
| const svgSymbols = parseSVG(svgFile); | ||
| const symbolsData = svgSymbols | ||
| .filter(({ name }) => name === "symbol") | ||
| .map((symbol) => ({ | ||
| id: symbol.attributes.id.replace(/^icon-/, ""), | ||
| content: stringify(symbol), | ||
| type: "icon", | ||
| })); | ||
|
|
||
| // Clean up old icons | ||
| const iconsDir = path.resolve(__dirname, "../src/evo-icon/icons"); | ||
| if (fs.existsSync(iconsDir)) { | ||
| deleteSync([`${iconsDir}/*`]); | ||
| } else { | ||
| fs.mkdirSync(iconsDir, { recursive: true }); | ||
| } | ||
|
|
||
| // Create types file for icon components | ||
| fs.writeFileSync( | ||
| path.resolve(__dirname, "../src/evo-icon/icons/types.ts"), | ||
| `${fileHeader}\n | ||
| import type { ComponentProps } from 'react'; | ||
| import type { EvoIcon } from '../icon'; | ||
|
|
||
| export type EvoIconComponentProps = Omit<ComponentProps<typeof EvoIcon>, 'name' | '__symbol'>; | ||
| export type EvoIconComponent = (props: EvoIconComponentProps) => React.JSX.Element; | ||
| `, | ||
| ); | ||
|
|
||
| const icons: Array<{ componentName: string; filePath: string }> = []; | ||
|
|
||
| symbolsData.forEach((data) => { | ||
| const iconNameCamelCase = camelCased(data.id); | ||
| const filename = path.resolve( | ||
| __dirname, | ||
| `../src/evo-icon/icons/evo-icon-${data.id}.tsx`, | ||
| ); | ||
| const iconComponentName = `EvoIcon${iconNameCamelCase[0].toUpperCase()}${iconNameCamelCase.slice(1)}`; | ||
| icons.push({ | ||
| componentName: iconComponentName, | ||
| filePath: `evo-icon-${data.id}`, | ||
| }); | ||
|
|
||
| const content = `${fileHeader}\n | ||
| import { EvoIcon } from "../icon"; | ||
| import type { EvoIconComponent } from "./types"; | ||
|
|
||
| const SYMBOL = \`${data.content}\`; | ||
|
|
||
| export const ${iconComponentName}: EvoIconComponent = props => ( | ||
| <EvoIcon {...props} name="${iconNameCamelCase}" __symbol={SYMBOL} /> | ||
| ); | ||
| `; | ||
|
|
||
| fs.writeFileSync(filename, content); | ||
| }); | ||
|
|
||
| console.log(`Created ${icons.length} icon components.`); | ||
|
|
||
| // Create Storybook stories file | ||
| const storiesFile = path.resolve(__dirname, "../src/evo-icon/icon.stories.tsx"); | ||
|
|
||
| const storiesContent = `${fileHeader}\n | ||
| import type { Meta } from "@storybook/react-vite"; | ||
| import { EvoIconProvider } from "./context"; | ||
| ${icons.map(({ componentName, filePath }) => `import { ${componentName} } from "./icons/${filePath}";`).join("\n")} | ||
|
|
||
| const meta: Meta = { | ||
| title: "Graphics & Icons/EvoIcon", | ||
| tags: ["autodocs"], | ||
| parameters: { | ||
| docs: { | ||
| description: { | ||
| component: \` | ||
| Icon components from the eBay Skin icon set. Each icon is available as an individual component for optimal tree-shaking. | ||
|
|
||
| ## Usage | ||
|
|
||
| \\\`\\\`\\\`tsx | ||
| import { EvoIconProvider } from "@evo-web/react"; | ||
| import { EvoIconCart16 } from "@evo-web/react/evo-icon-cart-16"; | ||
|
|
||
| function App() { | ||
| return ( | ||
| <EvoIconProvider> | ||
| <EvoIconCart16 a11yText="Shopping cart" /> | ||
| </EvoIconProvider> | ||
| ); | ||
| } | ||
| \\\`\\\`\\\` | ||
|
|
||
| ## Icons | ||
|
|
||
| Icons are imported individually via subpath exports: | ||
| - \\\`@evo-web/react/evo-icon-<name>\\\` - Import specific icon component | ||
| - Wrap your app with \\\`<EvoIconProvider>\\\` for better SSR performance | ||
| - Use \\\`a11yText\\\` prop for accessible labels | ||
| - Use \\\`a11yVariant="label"\\\` to use aria-label instead of title element | ||
|
|
||
| ## Available Icons | ||
|
|
||
| Over 1,000 icons available in multiple sizes (12, 16, 20, 24, 32, 48, 64). | ||
| \`, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| export const AllIcons = () => ( | ||
| <EvoIconProvider> | ||
| <table> | ||
| <tbody> | ||
| ${icons | ||
| .map( | ||
| ({ componentName, filePath }) => ` | ||
| <tr> | ||
| <td>{${componentName}.name || "${filePath}"}</td> | ||
| <td> | ||
| <${componentName} /> | ||
| </td> | ||
| </tr> | ||
| `, | ||
| ) | ||
| .join("\n")} | ||
| </tbody> | ||
| </table> | ||
| </EvoIconProvider> | ||
| ); | ||
| `; | ||
|
|
||
| fs.writeFileSync(storiesFile, storiesContent); | ||
| console.log(`Created Storybook stories at ${storiesFile}`); | ||
| } | ||
|
|
||
| // Main execution | ||
| const skinIconsFile = path.join(svgDir, "icons.svg"); | ||
| const skinSVGSymbols = parseSVGSymbols(skinIconsFile); | ||
| console.log(`Found ${skinSVGSymbols.length} icons in Skin.`); | ||
|
|
||
| // Generate individual icon components | ||
| saveIconComponents(skinIconsFile); | ||
|
|
||
| console.log("✅ Icon generation complete!"); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { createContext, useRef, type ReactNode } from "react"; | ||
|
|
||
| export const IconContext = createContext<Set<string> | null>(null); | ||
|
|
||
| export const ROOT_ID = "evo-web-svg-symbols"; | ||
|
|
||
| export function EvoIconProvider({ children }: { children: ReactNode }) { | ||
| const lookupRef = useRef<Set<string>>(new Set()); | ||
|
|
||
| return ( | ||
| <IconContext.Provider value={lookupRef.current}> | ||
| <svg | ||
| id={ROOT_ID} | ||
| style={{ position: "absolute", height: "0px", width: "0px" }} | ||
| focusable={false} | ||
| aria-hidden="true" | ||
| /> | ||
| {children} | ||
| </IconContext.Provider> | ||
| ); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.