README.md

WrappedKit #

Composable, headless summary stories for React. Components provide semantic structure and behavior; you bring the styles.

Usage #

import { Story, Stat, RankedList, SummaryStory } from "wrappedkit";

export const Summary = () => (
  <SummaryStory.Root aria-label="Your year in music">
    <Story.Image src="/artwork.jpg" alt="Your favourite album artwork" />
    <SummaryStory.Grid>
      <RankedList.Root>
        <RankedList.Title>Top Artists</RankedList.Title>
        <RankedList.Items>
          <RankedList.Item>Zara Larsson</RankedList.Item>
          <RankedList.Item>Ava Max</RankedList.Item>
          <RankedList.Item>Zach Top</RankedList.Item>
        </RankedList.Items>
      </RankedList.Root>
      <Stat.Root>
        <Stat.Label>Minutes Listened</Stat.Label>
        <Stat.Value value={42279} />
      </Stat.Root>
    </SummaryStory.Grid>
  </SummaryStory.Root>
);

All components are headless and exported from wrappedkit. Style them with className, style, or the data-wk-part attributes.

Components #

Namespace Parts
Story Root, Image, Title, Description, ShareButton
Stat Root, Label, Value
RankedList Root, Title, Items, Item
SummaryStory Root, Grid

All parts accept their native element props, className, style, and DOM refs. The elements are sections for story/list roots, h2 for story titles, h3 for list titles, ol/li for ranked items, and native images and buttons. Statistics use div containers/labels and a span value; Stat.Value also works independently.

SummaryStory.Grid chooses columns from available container width, with a 10rem preferred minimum column width that can shrink to fit narrow containers. Set columns={2} to request two columns even on narrow screens. Explicit columns must be positive integers. Visual gaps are supplied by consumer CSS.

Stat.Value requires a number or string value. Numbers use Intl.NumberFormat, with optional locale and formatOptions. The default locale is en-US; strings are unchanged. Use the same explicit locale on the server and client.

Story.ShareButton is disabled unless an explicit onClick is supplied. It defaults to type="button". This release contains standalone components: story playback, image export, and automatic native sharing are not implemented.

Styling #

WrappedKit ships no stylesheet. Artwork, logos, footer content, and decorative backgrounds are consumer-composed markup. The Storybook examples style the headless parts with CSS modules to demonstrate this.

DOM parts expose:

  • data-wk-part: story-root, story-image, story-title, story-description, story-share-button, stat-root, stat-label, stat-value, ranked-list-root, ranked-list-title, ranked-list-items, ranked-list-item, summary-root, or summary-grid.
  • data-columns: auto or the explicit grid column count.
  • data-fitting: present while text fitting is enabled.
  • data-disabled: present on disabled share buttons.
  • data-wk-export-exclude: marks share buttons for future export integration.

Text fitting #

Stat.Value and RankedList.Item accept fitText={true | false | { minFontSize, maxFontSize }}. Sizes are in CSS pixels. Fitting is opt-in. Default bounds are 20–44px for values and 14–22px for ranked items. Set fitText={false} to use ordinary CSS sizing.

Fitting measures the content width after mounting and updates when text, fonts, the element, or its available width changes. It never runs during server rendering. Text wraps and remains visible when it cannot fit at the minimum; long stories can grow vertically. Bounds must be finite and positive, with the maximum at least the minimum.

Development #

Each component lives in src/components/<Name>/index.tsx, which defines and exports its simple parts and their types. Parts with their own logic live in subfolders such as src/components/Stat/StatValue/index.tsx and are re-exported from the component index. Non-public helpers (formatting, text fitting, hooks, shared types) live in src/internal. src/index.ts is the package entry point.

Each component has a colocated <Name>.stories.tsx that styles the headless parts with a <Name>.module.css CSS module for demo purposes. The Overview story (src/index.stories.tsx) renders every variation on one page. Tests are colocated with the files or public entry points they cover.

pnpm build
pnpm typecheck
pnpm test:unit
pnpm test:browser
pnpm test:stories
pnpm test:package
pnpm storybook

Build before checking public package types. Browser tests run in Chromium, Firefox, and WebKit. Install browser binaries with pnpm exec playwright install if needed.

After editing code, run pnpm oxlint --fix, then pnpm oxfmt. Finish with pnpm oxlint --deny-warnings --format=agent.