A lightweight, highly optimized vanilla JavaScript component library with powerful theming capabilities. Built with performance, maintainability, and flexibility in mind - all with zero external dependencies.
Svarog UI now offers theme-specific packages for optimal bundle sizes! Install only what you need:
# Option 1: Core only (no themes)
npm install svarog-ui-core
# Option 2: Core + specific theme
npm install svarog-ui-core @svarog-ui/theme-cabalou
# Option 3: Traditional all-in-one (includes default theme)
npm install svarog-ui- 📦 Modular Packages - Install only the themes you need
- 🔍 Zero Dependencies - Pure JavaScript with no external runtime dependencies
- 🎨 Powerful Theming - Comprehensive CSS variable-based theming system
- 🧱 Factory Pattern - Consistent component API using factory functions
- 🚀 Performance Optimized - Event delegation, DOM batching, and CSS injection
- ♿ Accessible - Follows accessibility best practices
- 🧪 Well Tested - Comprehensive test coverage with Vitest
- 📚 Custom Component Explorer - Built-in Storybook-like viewer
- 🎯 Zero Configuration - Components automatically inject their own styles
- 🌐 Universal Compatibility - Works in Node.js, browsers, bundlers without CSS import errors
Install only what you need for the smallest bundle size:
# Core components only
npm install svarog-ui-core
# Add specific themes as needed
npm install @svarog-ui/theme-default
npm install @svarog-ui/theme-cabalou
npm install @svarog-ui/theme-muchandyFor backward compatibility or if you prefer the all-in-one approach:
npm install svarog-uiThis includes the core components and default theme pre-applied.
| Package | Description | Size |
|---|---|---|
svarog-ui-core |
Core components without themes | ~50KB |
@svarog-ui/theme-default |
Material Design inspired theme | ~15KB |
@svarog-ui/theme-cabalou |
Cabalou theme | ~15KB |
@svarog-ui/theme-muchandy |
Muchandy theme | ~15KB |
svarog-ui |
All-in-one (core + default theme) | ~65KB |
// Import only what you need
import { Button, Card } from 'svarog-ui-core';
import cabalouTheme from '@svarog-ui/theme-cabalou';
// Apply theme
cabalouTheme.apply();
// Create components
const button = Button({
text: 'Click Me',
variant: 'primary',
onClick: () => console.log('Clicked!'),
});
document.body.appendChild(button.getElement());import { Button, Card } from 'svarog-ui';
// Default theme is already applied
const button = Button({
text: 'Click Me',
variant: 'primary',
});
document.body.appendChild(button.getElement());Each theme package exports an object with these methods:
import defaultTheme from '@svarog-ui/theme-default';
import cabalouTheme from '@svarog-ui/theme-cabalou';
import muchandyTheme from '@svarog-ui/theme-muchandy';
// Apply a theme
defaultTheme.apply();
// Remove current theme
defaultTheme.remove();
// Get theme CSS string
const css = defaultTheme.getStyles();
// Switch themes
function switchTheme(newTheme) {
// Remove any existing theme
document
.querySelectorAll('[data-svarog*="theme"]')
.forEach((el) => el.remove());
// Apply new theme
newTheme.apply();
}
// Usage
switchTheme(cabalouTheme);Currently, custom themes can be created by following the pattern of existing theme packages. A dedicated theme creation utility is planned for a future release.
// Example custom theme structure
const myCustomTheme = {
name: 'custom',
apply() {
const styles = `.custom-theme {
--color-primary: #FF6B6B;
--color-primary-light: #FF8E8E;
--color-primary-dark: #E55555;
/* ... more variables ... */
}`;
const styleEl = document.createElement('style');
styleEl.id = 'svarog-theme-custom';
styleEl.setAttribute('data-svarog', 'theme-custom');
styleEl.textContent = styles;
document.head.appendChild(styleEl);
document.documentElement.classList.add('custom-theme');
document.body.classList.add('custom-theme');
},
remove() {
document.documentElement.classList.remove('custom-theme');
document.body.classList.remove('custom-theme');
const styleEl = document.getElementById('svarog-theme-custom');
if (styleEl) styleEl.remove();
},
getStyles() {
return '/* theme CSS */';
},
};All components follow a consistent factory pattern:
const component = Component({
// Component props
});
// Get DOM element
const element = component.getElement();
// Update props
component.update({ text: 'New Text' });
// Cleanup
component.destroy();Grid- Flexible grid systemSection- Content sections with variantsCard- Content containers
Form- Form container with validationFormGroup- Form field groupingFormSection- Form sectionsFormActions- Form action buttonsInput- Text inputsSelect- Dropdown selectionsCheckbox- Checkbox inputsRadio&RadioGroup- Radio buttonsConditionSelector- Condition selection UI
Button- Buttons with variantsTypography- Text componentsLink- Enhanced linksImage- Responsive imagesLogo- Logo displayRating- Star ratingsPriceDisplay- Price formattingStepsIndicator- Progress stepsTabs- Tabbed interface
Navigation- Main navigationPagination- Page navigationHeader- Page headerCollapsibleHeader- Collapsing headerFooter- Page footer
Hero- Hero sectionsBlogCard- Blog post cardsBlogList- Blog post listsBlogDetail- Blog post detailProductCard- Product cardsMap- Map integration
MuchandyHero- Custom hero variantPhoneRepairForm- Phone repair formUsedPhonePriceForm- Price calculatorContactInfo- Contact informationStickyContactIcons- Sticky contact buttonsPage- Page wrapperHead- Document head management
Svarog's innovative CSS injection system eliminates CSS import errors:
// No CSS imports needed!
const button = Button({ text: 'Click' });
// Styles are automatically injected on first render
// Works everywhere:
// ✅ Browser
// ✅ Node.js (SSR)
// ✅ Build tools
// ✅ Test environments- Zero Configuration - No webpack/build setup needed
- Automatic Deduplication - Styles injected only once
- Tree Shaking - Only used component styles are loaded
- SSR Compatible - Works with server-side rendering
- Performance Optimized - Efficient style injection
- All component JavaScript files
- Component CSS for style injection
- Utility functions (except theme-specific utilities)
- No themes included
Each theme package (@svarog-ui/theme-*) includes:
- JavaScript module with
apply(),remove(), andgetStyles()methods - Embedded CSS variables and styles
- No external dependencies
- Re-exports all core components
- Includes default theme pre-applied
- Convenience package for quick setup
- Themes are now separate packages for optimal bundle size
- Core can be used without any theme
- Three themes currently available: default, cabalou, muchandy
- Backward compatibility maintained through the main
svarog-uipackage
Before (v3):
import { Button } from 'svarog-ui';
// All themes were bundled (~120KB)After (v4):
import { Button } from 'svarog-ui-core';
import cabalouTheme from '@svarog-ui/theme-cabalou';
cabalouTheme.apply();
// Only what you need (~65KB)No changes needed! The svarog-ui package works the same way:
import { Button } from 'svarog-ui'; // Still works!# Clone the repository
git clone https://github.com/your-username/svarog.git
cd svarog
# Install dependencies
npm install
# Build all packages
npm run build:all
# Start development server
npm start
# Run tests
npm test
# Build for production
npm run buildsvarog/
├── packages/ # Monorepo packages
│ ├── svarog-ui/ # Main package (backward compatible)
│ ├── svarog-ui-core/ # Core components
│ └── @svarog-ui/ # Scoped packages
│ ├── theme-default/ # Default theme
│ ├── theme-cabalou/ # Cabalou theme
│ └── theme-muchandy/ # Muchandy theme
│
├── src/ # Source code
│ ├── components/ # Component implementations
│ ├── styles/ # Theme definitions
│ └── utils/ # Utilities
│
├── .storybook/ # Component explorer
├── scripts/ # Build scripts
└── docs/ # Documentation
Svarog is built for performance:
- Small Bundle Sizes - Modular packages mean you only ship what you use
- Fast Runtime - Optimized algorithms and efficient DOM updates
- Lazy Loading - Components can be dynamically imported
- Memory Efficient - Proper cleanup and memory management
| Setup | Size | Reduction |
|---|---|---|
| v3 (All themes bundled) | ~120KB | - |
| v4 Core + 1 theme | ~65KB | 46% smaller |
| v4 Core only | ~50KB | 58% smaller |
- Chrome/Edge 88+
- Firefox 78+
- Safari 14+
- Opera 74+
- Chrome for Android
- Safari on iOS 14+
We welcome contributions! Please see our Contributing Guide for details.
# Fork and clone
git clone https://github.com/your-username/svarog.git
cd svarog
# Install and bootstrap
npm install
npm run build:all
# Create new component
npm run create-component MyComponent
# Run tests
npm test
# Start dev server
npm startPlanned features and packages for future releases:
@svarog-ui/theme-dark- Dark mode theme@svarog-ui/theme-light- Light mode theme@svarog-ui/theme-red- Red accent theme@svarog-ui/create-theme- Theme creation utilities- TypeScript declarations
- React/Vue adapters
- Additional components based on community feedback
ISC License - see LICENSE file for details.
Made with ❤️ by Sebastian Huber