Reablocks React Component Library

repository·master·Indexed 41 days ago

https://github.com/reaviz/reablocks

A React-based UI component library featuring over 50 components styled with Tailwind CSS. Designed with a dark-first approach, Reablocks provides a comprehensive design system including semantic color tokens, a typography scale using Inter and Fira Code, and specific layout guidelines for rapid interface development. Version 10.3.1.

Tokens
29.4K
Snippets
72
Records
177
Agent score
51%

What's inside Reablocks

  1. Introduction to reablocks

    master
    reablocks is a collection of UI components for React built on top of Tailwind CSS. It provides a set of reusable blocks designed to accelerate UI development within the React ecosystem using Tailwind's utility-first styling approach.
  2. Understand the reablocks color system and semantic tokens

    master

    reablocks uses a semantic token API for styling. Instead of using raw color values, you should use semantic tokens which adapt automatically between dark and light modes.

    Core Semantic Tokens

    • primary: The brand accent (electric blue #105eff). Used for primary actions, selected states, and links. Hover state brightens to primary-hover in dark mode.
    • secondary: Charcoal (#242433) for secondary button fills. In light mode, this resolves to a pale blue (#c3d7ff).
    • panel: The base background (#02020f in dark).
    • panel-accent: The hairline border color used for cards, inputs, and dialogs.
    • surface: Raised interactive surfaces like toggle tracks and dividers.
    • text-primary: Main text color (#f7f7fa in dark).
    • text-secondary: Muted text/labels (#77778c in dark).
    • on-primary: The color for labels/icons sitting on top of primary/success/error/warning surfaces. Note: This is always near-white in both dark and light modes.

    State Colors

    • success, error, warning, info: Used for state-specific feedback. Each has a -hover variant and a dark -background tint for callouts in dark mode.

    Theme Mapping Reference

    TokenDark (Default)Light
    primary#105eff#105eff
    secondary#242433#c3d7ff
    panel#02020f#ffffff
    panel-accent#242433#e6e6f0
    surface#242433#c9c9d6
    text-primary#f7f7fa#11111f
    text-secondary#77778c#242433
  3. Understand the reablocks design system principles

    master

    reablocks is a Tailwind CSS-powered React component library designed with a dark-first approach.

    Key design characteristics:

    • Theme Strategy: The semantic tokens are defined by their default dark theme values.
    • Light Mode Support: Light mode is achieved through <token>-light variants (e.g., primary-light). The underlying palette primitives remain unchanged.
    • Typography: Primarily driven by the Inter font family, with Fira Code used for monospace elements.
    • Compactness: The system is designed to be compact and highly structured using semantic tokens.
  4. Visual Design Specifications for Reablocks Components

    master

    Reablocks components follow a strict design system based on semantic tokens and shared scales.

    Buttons

    • Variants: Filled, outline, and text.
    • Filled Buttons: Use semantic tokens for fill (e.g., primary, success). Labels use {colors.on-primary} (white in both modes) except for button-secondary which uses {colors.text-primary}.
    • Outline Buttons: Transparent with a 1px border and variant-colored text.
    • Text Buttons: Borderless with colored text that brightens on hover.
    • Sizes: small (12px label), medium (14px label, default), large (20px label).
    • Disabled: Filled buttons use {colors.gray-600} with {colors.gray-400} text.

    Inputs

    • Appearance: Flex wrapper on {colors.panel} with a 1px {colors.panel-accent} border and {rounded.xs} corners.
    • Focus/Hover: No focus ring; instead, a 1px radial-gradient underline is painted at the bottom edge.
    • Error State: Border swaps to {colors.error}.
    • Disabled: Text is pinned to waterloo #77778c in both modes; background is a muted tint; underline is removed.

    Selection Controls (Checkbox, Radio, Toggle)

    • Checkbox: 1rem SVG box. Unchecked is transparent with {colors.gray-400} stroke; checked is {colors.blue-500} with a white check.
    • Radio: 1rem circle with a 1px {colors.surface} border. Selected state uses {colors.primary-active} border and a {colors.primary} dot.
    • Toggle: Pill track (3rem × 1.5rem medium) in {colors.surface}. Turns {colors.primary} when 'on'.

    Chips & Badges

    • Chips: Compact pills with {rounded.xs} corners. Default is {colors.panel} with primary text. Color variants fill with semantic tokens and flip text to {colors.panel} for contrast.
    • Badges: 18×18px fully-round dots used for counts/alerts.

    Containers (Cards, Tooltips, Dialogs)

    • Card: {colors.panel} with a 1px {colors.panel-accent} border and {rounded.xs} corners.
    • Tooltip: {colors.panel-accent} background, {rounded.sm} corners, and 0.375rem padding.
    • Dialog: {colors.panel} sheet with {colors.panel-accent} border, {rounded.sm} corners, and shadow-2xl.
  5. Best Practices for Reablocks Development

    master

    To maintain visual consistency and ensure theme compatibility, follow these rules:

    Do's

    • Use Semantic Tokens: Always use primary, panel, surface, and text-primary for surfaces and text. These resolve correctly in both light and dark modes.
    • Use Shared Scales: Stick to the established scales for radius (xs–4xl), typography (10–16px), and spacing (0.25rem grid).
    • Mode Switching: Keep dark mode as the default. Switch modes using theme-light/theme-dark classes or data-theme attributes on the root element.
    • Accents: Reserve raw palette steps (e.g., teal-500, violet-400) for non-semantic accents like charts or category colors.
    • Customization: Use the theme system (extendTheme, extendComponentTheme, or the theme prop) instead of external CSS or !important to ensure deep-merging works correctly.

    Don'ts

    • Hardcode Hex Values: Never use hex codes where a semantic token exists; this breaks light-mode support and theme overrides.
    • Use Raw Grays for Surfaces: Avoid gray-700 or gray-950 for surfaces/text; use surface or panel instead.
    • Add Heavy Elevation: Do not use large corner radii or heavy drop shadows on buttons, cards, or inputs. Reablocks uses hairline borders and layered darkness for separation.
    • Modify Typography: Do not introduce new font families or increase body text above 14px by default.
  6. Run Reablocks locally with Storybook

    master

    To run the Reablocks development environment locally and explore components in Storybook, follow these steps:

    1. Clone the repository.
    2. Install dependencies using npm i.
    3. Start the development server with npm start.

    This will automatically open your browser to the Storybook page where you can interact with the components.

    npm i
    npm start
  7. Apply layout, spacing, and shape guidelines

    master

    To maintain the 'engineered' reablocks aesthetic, follow these layout and shape constraints:

    Spacing and Density

    • Use a 4px grid based on spacing.unit (0.25rem).
    • Prefer tight, even rhythm over generous whitespace.
    • Standard component padding:
      • Medium buttons: 0.5rem x 1rem
      • Inputs: 0.375rem x 0.625rem
      • Cards: 1.75rem all around

    Shapes and Radii

    Avoid medium-rounded corners (8–12px) as they break the visual identity. Use the following:

    • rounded.xs (2px): For structural elements like buttons, cards, inputs, and chips.
    • rounded.sm (4px): For tooltips and dialogs.
    • rounded.full: For small controls like toggles, radios, and badges.

    Elevation

    Avoid heavy shadows. Hierarchy is achieved through layered darkness and hairline borders:

    • Base: colors.panel (#02020f)
    • Raised: colors.surface (#242433)
    • Separation: 1px colors.panel-accent border.
    • Shadows: Use sparingly. Only dialogs should use the strongest shadow (shadow-2xl).
  8. Run visual regression tests

    master

    Reablocks uses Playwright to perform visual regression testing by taking screenshots of every Storybook story to detect unintended visual changes.

    Prerequisites: Storybook must be running on localhost:9009. If it is not running, Playwright will attempt to start it automatically.

    Use the following commands to manage visual tests:

    • To run tests against the existing baseline screenshots: npm run test:visual
    • To update the baseline screenshots (use this after making intentional visual changes): npm run test:visual:update

    Note: test:visual:extract runs automatically during these commands to fetch the story list from Storybook.

    # Run visual tests against existing baseline screenshots
    npm run test:visual
    
    # Update baseline screenshots (after intentional visual changes)
    npm run test:visual:update
  9. Activate the light theme in reablocks

    master

    By default, reablocks uses a dark-first theme. To switch to the complete light theme, add the theme-light class or the data-theme="light" attribute to a root element in your application.

    All component styling is driven by a centralized theme system. To ensure correct rendering in both modes, always reference semantic tokens (e.g., primary, panel) rather than hardcoding hex values. The theme system automatically resolves semantic tokens to their -light counterparts when the light theme is active.

    <!-- Using class -->
    <div class="theme-light">
      <!-- components here -->
    </div>
    
    <!-- Using data attribute -->
    <div data-theme="light">
      <!-- components here -->
    </div>
  10. Explore Reablocks Theme API entrypoints

    master

    The src/utils/Theme/index.ts file serves as the central export point for the Reablocks theming system. It aggregates all necessary components, types, and utilities required to manage and apply themes across your application.

    To implement theming, you will primarily interact with the following modules:

    • ThemeProvider: The component used to inject theme context into your component tree.
    • themes: Pre-defined theme objects or definitions.
    • hooks: React hooks for consuming theme data (e.g., accessing current colors or spacing) within functional components.
    • types: TypeScript definitions for theme structures and configuration.
    • blocks: Theme-aware block configurations.
    • helpers: Utility functions for theme manipulation and calculation.