A comprehensive system for managing SVG assets as React components with module federation support for cloud.redhat.com applications.
This repository automatically converts SVG files into TypeScript React components and exposes them via webpack module federation. It provides a complete workflow for managing icons, logos, and other visual assets across Red Hat's cloud applications.
Looking to use an icon in your application? Check out our Component Mappings for:
- π Complete list of available components
- πΌοΈ Visual previews of all icons
- π» Usage examples with ScalprumComponent
- π Props documentation
Adding or modifying SVG assets:
# 1. Add your SVG file to the appropriate directory under src/
cp my-icon.svg src/icons/
# 2. Generate React components and update module federation config
npm run generate-modules
# 3. Commit your changes (pre-commit hooks will validate everything)
git add .
git commit -m "Add new icon"
src/
βββ partners-icons/ # External images that are not internally given by Red Hat
βββ technology-icons/ # Red Hat technology icons
Each SVG file becomes a TypeScript React component with:
- TypeScript Support: Full type definitions
- PatternFly Integration: Optional PatternFly Icon wrapper
- Flexible Props: Separate props for SVG and Icon wrapper
- Module Federation: Automatic exposure via webpack
- Node.js β₯16.0.0
- npm β₯7.0.0
npm install
Script | Description |
---|---|
npm run generate-modules |
Generate React components and update module federation config |
npm run validate-config |
Validate that module federation config is up-to-date |
npm run build |
Generate components and build the application |
npm run dev |
Start development server with hot reload |
npm run verify |
Validate config and build (used in CI) |
npm run lint |
Run ESLint on source files |
- Add SVG File: Place your SVG in the appropriate
src/
subdirectory - Run Generation: Execute
npm run generate-modules
- Review Output: Check the generated
.tsx
file and updatedfec.config.js
- Test Locally: Use
npm run dev
to test your changes - Commit: Git hooks will automatically validate your changes
Components are consumed via module federation using ScalprumComponent:
import { ScalprumComponent } from '@scalprum/react-core';
// Basic usage
<ScalprumComponent
scope="frontend-assets"
module="./IconsIconAutomation"
/>
// With PatternFly wrapper
<ScalprumComponent
scope="frontend-assets"
module="./IconsIconAutomation"
pfIconWrapper={true}
iconProps={{ size: "md" }}
/>
// With custom SVG props
<ScalprumComponent
scope="frontend-assets"
module="./IconsIconAutomation"
svgProps={{ width: "32", height: "32", fill: "red" }}
/>
The system automatically maintains the module federation configuration in fec.config.js
. Each SVG file is exposed as:
moduleFederation: {
exposes: {
"./IconsIconAutomation": path.resolve(__dirname, 'src', 'icons/icon__automation.tsx'),
// ... more entries
}
}
All generated components support these props:
type ComponentProps = {
pfIconWrapper?: boolean; // Use PatternFly Icon wrapper
iconProps?: IconComponentProps; // Props for PatternFly Icon
svgProps?: React.SVGProps<SVGSVGElement>; // Props for SVG element
};
Husky pre-commit hooks automatically:
- β Validate module federation configuration
- β Run ESLint checks
- β Prevent commits with out-of-sync configurations
The npm run verify
command ensures:
- Configuration is up-to-date
- All components build successfully
- No linting errors
The validation script (scripts/validate-config.js
) checks:
- All SVG files have corresponding module federation entries
- No orphaned entries exist
- Paths are correctly formatted with
path.resolve
The system generates several files automatically:
File | Purpose |
---|---|
src/**/*.tsx |
React components for each SVG |
fec.config.js |
Updated module federation configuration |
COMPONENT_MAPPINGS.md |
Documentation with usage examples |
.tsx
files or the module federation configuration in fec.config.js
. These are automatically maintained by the generation script.
Module federation config out of sync:
npm run generate-modules
git add fec.config.js
git commit -m "Update module federation config"
Pre-commit hook failures:
- Ensure you've run
npm run generate-modules
after adding/removing SVGs - Check that all files are properly committed
- Run
npm run validate-config
to see specific issues
Build failures:
- Verify SVG files are valid XML
- Check for unsupported SVG features (see scripts documentation)
- Ensure file names follow naming conventions
- Check the Component Mappings for usage examples
- Review the Scripts Documentation for technical details
- Run
npm run validate-config
for configuration issues - Check the generated
.tsx
files for component-specific problems
- Fork the repository
- Create a feature branch
- Add your SVG assets to the appropriate directory
- Run
npm run generate-modules
- Test your changes with
npm run dev
- Commit your changes (hooks will validate)
- Submit a pull request
- Use kebab-case for SVG filenames:
my-icon.svg
- Place files in appropriate directories based on usage
- Avoid special characters and spaces in filenames
- Component Mappings - Complete component reference
- Scripts Documentation - Technical implementation details
- PatternFly Icons - Icon design guidelines