Reshaped UI Documentation

repository·canary·Indexed 24 days ago

https://github.com/reshaped-ui/reshaped

A library of professionally crafted React and Figma components for building products or design systems. It includes the core 'reshaped' React design system, '@reshaped/headless' for logic-only components, and '@reshaped/utilities' for framework-agnostic TypeScript utilities such as Flyout positioning, TrapFocus navigation, lockScroll, and RTL detection.

Tokens
23.3K
Snippets
21
Records
220
Agent score
79%

What's inside Reshaped

  1. Overview of Reshaped packages

    canary

    Reshaped provides a suite of packages for building products or design systems using React and Figma-synced components. Depending on your needs, you can choose between styled components, headless logic, or framework-agnostic utilities:

    • reshaped: The core React design system. It includes professionally crafted components, hooks, utilities, and design tokens. The implementation is synchronized with the Reshaped Figma library.
    • @reshaped/headless: Provides headless React components and utilities. Use this if you want to build your own design system or product with custom styles while leveraging Reshaped's logic.
    • @reshaped/utilities: A collection of framework-agnostic UI utilities written in vanilla TypeScript.
  2. How Flyout works for positioning floating elements

    canary

    The Flyout class handles complex positioning logic, collision detection, and automatic adjustments for floating elements like dropdowns, popovers, or tooltips. You provide a content element and a trigger element, and the Flyout ensures the content is visible and properly aligned relative to the trigger.

    Usage

    1. Create a new Flyout instance with content and trigger (or triggerCoordinates).
    2. Call .activate() to position and show the content.
    3. Call .deactivate() to clean up behavior when closing.
    4. Use .update(options) to adjust position based on viewport changes or new options.

    Options

    • content: The HTMLElement to be positioned (must be rendered when instantiated).
    • trigger: The HTMLElement to position against.
    • triggerCoordinates: { x: number; y: number } used if no trigger element exists (e.g., for context menus).
    • container: An HTMLElement to act as the positioning boundary instead of the viewport.
    • position: The default position (e.g., top, bottom-start, end-top).
    • fallbackPositions: An array of Position values to use if the default position causes a collision.
    • fallbackAdjustLayout: If true, tries shifting/resizing content before changing position.
    • onDeactivate: Callback triggered when the flyout deactivates itself (e.g., due to scrolling).
    import { Flyout } from "@reshaped/utilities";
    
    const flyout = new Flyout({
    	content: contentElement,
    	trigger: triggerElement,
    	position: "bottom-start",
    });
    
    // Position the flyout content based on the trigger element
    flyout.activate();
    
    // Clean-up the flyout behavior on closing the content
    flyout.deactivate();
    
    // Update flyout position based on updated options and the current viewport position
    flyout.update(options);
  3. Migrate TextField endSlotPadding from v3 to v4

    canary

    In Reshaped v4, the default endSlotPadding for the TextField component has changed to 2. To preserve the visual behavior of your application if you were using an endSlot in v3, you must explicitly set the padding.

    Migration Logic:

    • If you are not using endSlot, no action is required.
    • If you have already manually set endSlotPadding, no action is required.
    • If you are using endSlot without a defined endSlotPadding, you must add endSlotPadding={1} to maintain the previous v3 layout.
  4. Migrate focus and blur handlers in form components

    canary

    In Reshaped v4, several form components (including Autocomplete, Checkbox, HiddenInput, Radio, Select, Switch, TextArea, and TextField) have dropped the top-level onFocus and onBlur props. These handlers must now be passed via the inputAttributes object to ensure they are correctly applied to the underlying input element.

    To migrate, move any existing onFocus or onBlur props into the inputAttributes configuration object.

    <Autocomplete
    	inputAttributes={{ onFocus: () => console.log("focused"), onBlur: () => console.log("blurred") }}
    />
  5. Migrate Button from faded variant to new variants

    canary

    In Reshaped v4, the faded variant for the Button component has been removed. There is no automated migration path. You must manually replace variant="faded" based on your desired visual outcome:

    • For a bordered style: Use variant="outline" with the same color.
    • For a minimal style: Use variant="ghost" with the same color.
    • For a neutral appearance: Use color="neutral".
  6. Generate a Reshaped v3 -> v4 Migration Report

    canary

    After performing a migration, you must create a report file in the workspace root named reshaped-v3-v4-migration-report.md. This report provides an audit trail of applied changes, manual review requirements, and overall migration status.

    Report Structure

    The report must include:

    • Scope: Target folders/packages and the migration date.
    • Migration Results: A section for every file in changes/*.md containing:
      • Status: completed | partial | not-applicable | blocked
      • Components updated: Count of components modified.
      • Confidence: high | medium | low
      • Medium/low review locations: Exact <path>:<line> for items requiring human review.
      • Notes: Key decisions or caveats.
      • Manual steps: Required human follow-up.
    • Summary: Aggregated totals for processed migrations, completion status, and total components updated.
    # Reshaped v3 -> v4 Migration Report
    
    ## Scope
    
    - Target: <folders/packages migrated>
    - Date: <YYYY-MM-DD>
    
    ## Migration Results
    
    ### <migration name from file>
    
    - Status: `completed` | `partial` | `not-applicable` | `blocked`
    - Components updated: <number>
    - Confidence: `high` | `medium` | `low`
    - Medium/low review locations:
      - `<path>:<line>` - <why review is needed>
    - Notes: <key decisions, caveats>
    - Manual steps (if any):
      - <required human follow-up>
    
    <!-- Repeat for every changes/*.md file -->
    
    ## Summary
    
    - Total migrations processed: <number>
    - Completed: <number>
    - Partial: <number>
    - Not applicable: <number>
    - Blocked: <number>
    - Total components updated: <number>
  7. Migrate Tabs component from v3 to v4

    canary

    In Reshaped v4, the Tabs component no longer automatically detects a defaultValue based on its children. To maintain existing behavior, you must explicitly provide a defaultValue prop to the Tabs component.

    Migration Logic:

    • Controlled Components: If your Tabs component is already controlled via the value prop, no changes are required.
    • Existing Default Values: If you have already explicitly defined a defaultValue, no changes are required.
    • Uncontrolled Components: If neither value nor defaultValue is present, you must manually add the defaultValue prop. The value should match the value prop of the Tabs.Item you want selected by default (typically the first item).
    // Before (v3)
    <Tabs>
    	<Tabs.Item value="overview">Overview</Tabs.Item>
    	<Tabs.Item value="activity">Activity</Tabs.Item>
    </Tabs>
    
    // After (v4)
    <Tabs defaultValue="overview">
    	<Tabs.Item value="overview">Overview</Tabs.Item>
    	<Tabs.Item value="activity">Activity</Tabs.Item>
    </Tabs>
  8. Migrate from Progress to ProgressBar

    canary

    When upgrading to Reshaped v4, the Progress component has been renamed to ProgressBar. To complete the migration, you must update both the component usage and the associated type imports.

    1. Replace the Progress component with ProgressBar in your JSX.
    2. Replace ProgressProps with ProgressBarProps in your type definitions or component props.
    // Before
    import { Progress } from "reshaped";
    import type { ProgressProps } from "reshaped";
    
    <Progress value={40} />;
    
    // After
    import { ProgressBar } from "reshaped";
    import type { ProgressBarProps } from "reshaped";
    
    <ProgressBar value={40} />;