shru-design-system
v0.5.4
Published
A React component library with atoms and molecules built on Radix UI and Tailwind CSS
Maintainers
Readme
shru-design-system
A React component library with atoms and molecules built on Radix UI and Tailwind CSS, featuring a dynamic theme system.
Project Structure
Root Files
package.json- Package configuration, dependencies, and scriptstsconfig.json- TypeScript configurationtsup.config.ts- Build configuration for bundling (ESM/CJS)tailwind.config.js- Tailwind CSS configuration (for library development)postcss.config.js- PostCSS configuration (for library development).gitignore- Git ignore rules
Source Code (src/)
src/index.ts- Main entry point, exports all components and utilitiessrc/utils.ts- Utility functions (cn helper for class merging)
Atoms (src/atoms/)
Basic UI building blocks:
Alert.tsx- Alert component for notificationsAvatar.tsx- Avatar component with image and fallbackBadge.tsx- Badge component for labels and tagsButton.tsx- Button component with variants and sizesCheckbox.tsx- Checkbox input componentEmpty.tsx- Empty state componentErrorBoundary.tsx- Error boundary componentImage.tsx- Image component with loading statesInputOTP.tsx- OTP input componentKbd.tsx- Keyboard key display componentLabel.tsx- Form label componentProgress.tsx- Progress bar componentRadio.tsx- Radio button group componentSeparator.tsx- Horizontal/vertical divider componentSkeleton.tsx- Skeleton loading componentSkeletonGrid.tsx- Grid layout skeleton componentSkeletonText.tsx- Text lines skeleton componentSlider.tsx- Slider input componentSpinner.tsx- Loading spinner componentSwitch.tsx- Toggle switch componentText.tsx- Typography text componentTextInput.tsx- Text input field componentTextarea.tsx- Multi-line text input componentToggle.tsx- Toggle button componentUpload.tsx- File upload component
Molecules (src/molecules/)
Composite components:
Accordion.tsx- Collapsible accordion componentAlertDialog.tsx- Alert dialog componentBreadcrumb.tsx- Breadcrumb navigation componentCalendar.tsx- Calendar date picker componentCarousel.tsx- Image/content carousel componentChart.tsx- Chart component (Recharts wrapper)Collapsible.tsx- Collapsible content componentCommand.tsx- Command palette componentConfirmModal.tsx- Confirmation modal componentContextMenu.tsx- Right-click context menuCopyButton.tsx- Copy to clipboard buttonDrawer.tsx- Drawer/side panel componentDropdownMenu.tsx- Dropdown menu componentField.tsx- Form field wrapper componentForm.tsx- Form component (react-hook-form)FormInput.tsx- Form input with label and errorFormModal.tsx- Modal with form integrationHistoryControlButtons.tsx- Browser history controlsHoverCard.tsx- Hover card componentInfoBanner.tsx- Information banner componentInlineEdit.tsx- Inline editing componentInputGroup.tsx- Input with addons/buttonsSearchInput.tsx- Search input with debounce and clearableMenubar.tsx- Menu bar componentModal.tsx- Modal dialog componentNavigationMenu.tsx- Navigation menu componentPagination.tsx- Pagination componentPopover.tsx- Popover componentSelect.tsx- Dropdown select componentSheet.tsx- Sheet/side panel componentSnackbar.tsx- Snackbar notification componentStatusText.tsx- Status text with iconsStepper.tsx- Step indicator componentTabs.tsx- Tabs componentToast.tsx- Toast notification componentToaster.tsx- Toast provider componentToggleGroup.tsx- Toggle group componentTooltip.tsx- Tooltip componentTriggerModal.tsx- Modal with trigger component
Layout (src/layout/)
Layout and container components:
AspectRatio.tsx- Aspect ratio containerBox.tsx- Generic box containerCard.tsx- Card container componentCollapsiblePanel.tsx- Collapsible panel componentContainer.tsx- Responsive container componentEmptyScreen.tsx- Empty screen componentFooter.tsx- Footer componentGrid.tsx- Grid layout componentHeader.tsx- Header componentList.tsx- Enhanced list component with search, grid/list views, empty/loading statesResizable.tsx- Resizable panels componentResizeContainer.tsx- Resizable container wrapperScrollArea.tsx- Scrollable area componentSidebar.tsx- Sidebar navigation componentStack.tsx- Stack layout componentTable.tsx- Table component
Theme System (src/themes/)
themeConfig.ts- Theme configuration and category definitionsthemeUtils.ts- Theme utility functions (loading, merging, flattening)applyThemeSync.ts- Synchronous theme application (prevents FOUC)useTheme.tsx- React hook for theme managementui/ThemeToggle/- Theme toggle UI component and related filesThemeToggle.tsx- Main theme toggle componentuseThemeToggle.ts- Hook for theme toggle UI statethemeToggleConfig.ts- Theme toggle configurationthemeToggleUtils.ts- Theme toggle utility functionsindex.ts- Theme toggle exports
Build Output (dist/)
index.js- CommonJS bundleindex.mjs- ESM bundleindex.d.ts- TypeScript declarations (CJS)index.d.mts- TypeScript declarations (ESM)
Scripts (scripts/)
Setup and runtime scripts:
init.js- Postinstall script that sets up Tailwind, PostCSS, and token files in consuming appsapply-theme-sync.js- Standalone synchronous theme script (injected into HTML)applyThemeSync.js- Synchronous theme application modulethemeConfig.js- Theme configuration (JavaScript version)themeUtils.js- Theme utilities (JavaScript version)tokens/- Default token files (copied to consuming apps)base.json- Base design tokenspalettes.json- Color palette definitionsthemes/- Theme category filescolor/- Color theme variants (white, dark)typography/- Typography themes (sans, serif)shape/- Shape themes (smooth, sharp)density/- Density themes (comfortable, compact)animation/- Animation themes (gentle, brisk)custom/- Custom theme examples (brand, minimal)
Test Application (test/)
Local test environment for developing and testing the library:
package.json- Test app dependenciesvite.config.ts- Vite configuration for test appindex.html- Test app HTML entry pointsrc/App.tsx- Test app component showcasing all library componentssrc/main.tsx- Test app entry pointsrc/index.css- Test app global stylestailwind.config.js- Tailwind config for test apppostcss.config.js- PostCSS config for test apppublic/tokens/- Token files for testing (generated by init script)dist/- Vite build output (ignored in git)
Usage
Install:
npm install shru-design-systemTheme setup (new flow)
- Tokens are embedded in the bundle, so the theme system works out-of-the-box (no
/public/tokensrequired). - If you want to self-host tokens (for custom themes or CDN):
- Set
window.__THEME_TOKENS_BASE__ = "/tokens"(or your URL) before the app renders, or setDESIGN_SYSTEM_TOKENS_BASEenv at build/runtime. - Serve token JSONs at
<base>/base.json,<base>/palettes.json,<base>/themes/<category>/<theme>.json.
- Set
- Blocking HTML injection is removed; the runtime/applyThemeSync appends
#dynamic-themeat the end of<head>so its CSS vars override compiled CSS.
Optional token copy:
npx shru-design-system-init # copies tokens into public/tokens if you want static hostingImport components:
import {
Button,
Modal,
ThemeToggle,
Alert,
Avatar,
Accordion,
Calendar,
Carousel,
Form,
Field,
// ... and many more
registerThemeFromFile
} from 'shru-design-system'Available Components
The library includes 67+ components organized into:
- Atoms (23): Basic UI elements like Button, Input, Badge, etc.
- Molecules (35): Composite components like Modal, Form, Calendar, etc.
- Layout (16): Layout components like Grid, Stack, Sidebar, etc.
Registering themes:
- Add a custom theme file at your token base, e.g.
/tokens/themes/custom/my-brand.json. - Call at runtime (after page load):
registerThemeFromFile('custom', 'my-brand', '/tokens/themes/custom/my-brand.json')The theme toggle will pick it up automatically.
Development
Build the library:
npm run buildTest locally:
cd test && npm run dev