@flipdish/ui-library

中文文档
0.52.0发布于 2026/11/16TypeScriptESM + CJS近 30 天下载 9276

Flipdish Design System — atomic-design component library (Tailwind v4 + UntitledUI + React Aria).

原始使用文档
文档目录13 节
  1. Installation
  2. Peer dependencies
  3. Component-specific peer dependencies
  4. Tailwind setup
  5. React Native
  6. Tailwind setup (NativeWind)
  7. TypeScript setup
  8. Importing a component that isn't available yet
  9. Scoping Tailwind CSS to a subtree
  10. Options
  11. Documentation
  12. Changelog
  13. Contributing

@flipdish/ui-library

Atomic-design React component library for Flipdish products, built on Tailwind CSS v4, Untitled UI primitives, and React Aria Components. Web-first today, with React Native (via NativeWind) support rolling out per component.

Internal design system, published publicly. This package is built for and tuned to Flipdish's brand and tooling. It's on the public npm registry so it can be shared across Flipdish micro-frontends and apps — it isn't intended as a general-purpose UI kit.

Part of the Flipdish Design System:

PackagePurpose
@flipdish/ui-tokensDesign tokens — colours, type scale, spacing
@flipdish/ui-iconsIcon set
@flipdish/ui-libraryComponents (this package)
@flipdish/ui-connectedAPI-connected components

Installation

pnpm add @flipdish/ui-library @flipdish/ui-tokens @flipdish/ui-icons

For the full setup walkthrough (Vite config, CSS entry, providers, first component), see Getting Started → Installation.

Peer dependencies

Shared — required on every platform:

PackageVersion
react^19.0.0
tailwind-merge^3.6.0

Web:

PackageVersion
react-dom^19.0.0
react-aria3.50.0
react-aria-components1.19.0
react-router^7.0.0

React Native:

PackageVersion
react-native>=0.81.0
nativewind^5.0.0-preview.4
react-native-css^3.0.7
lightningcss>=1.27.0 <1.30.2
@expo/metro-config>=54.0.0
@react-native-aria/interactions>=0.2.7
@react-native-aria/focus>=0.2.7

lightningcss must be pinned to 1.30.1. NativeWind v5 + react-native-css can hit a failed to deserialize error on versions >=1.30.2 (see the NativeWind installation guide). This only affects your app's install — a library's own version pin can't propagate to consumers — so add this to your app's package.json:

{ "overrides": { "lightningcss": "1.30.1" } }

(pnpm projects: nest this under a top-level "pnpm" key instead — { "pnpm": { "overrides": { "lightningcss": "1.30.1" } } }.)

Component-specific peer dependencies

A handful of components are backed by larger third-party libraries declared as optional peers — importing Button never pulls in the charting or rich-text stack. Install only the peer(s) for the components you actually use; a missing peer causes a build/runtime error.

ComponentRequired peer(s)
Chartsrecharts
CodeSnippetshiki, hast-util-to-jsx-runtime
TextEditor@tiptap/core, @tiptap/pm, @tiptap/react, @tiptap/starter-kit, @tiptap/extension-image, @tiptap/extension-placeholder, @tiptap/extension-text-align, @tiptap/extension-text-style
Carouselembla-carousel-react
QRCodeqr-code-styling
VerificationCodeInputinput-otp
CommandMenureact-hotkeys-hook
FileUpload, SidebarNavigationmotion
forms/* (except FormSection)react-hook-form; forms/validation needs zod and @hookform/resolvers as well

Tailwind setup

Import the library's shared runtime from your CSS entry in this exact layer order:

@layer theme, base, components, utilities;

@import 'tailwindcss/theme.css' layer(theme);
@import '@flipdish/ui-tokens/css' layer(theme);
@import 'tailwindcss/preflight.css' layer(base);
@import '@flipdish/ui-library/styles';
@import 'tailwindcss/utilities.css' layer(utilities);

React Native

Components are web-first and opt in per component. A component is available on React Native only once it has a .native.tsx implementation; the rest are web-only and are deliberately not resolvable from an RN app.

For the full Expo walkthrough (Metro config, NativeWind CSS entry, TypeScript, first component), see Getting Started → Installation (React Native). The summary below covers the essentials.

Available on React Native today: Avatar, Button, plus the cx, testIdUtils and isReactComponent utilities. Storybook is the live reference: each component's docs page carries a React Native section listing exactly which props that platform supports, and the Platform switch in the toolbar re-renders its stories with the React Native implementation.

Import paths are identical across platforms — Metro picks the native build via the react-native export condition:

// Resolves to the web build under Vite/webpack, the native build under Metro.
import { Avatar } from '@flipdish/ui-library/components/atoms/Avatar';

react-native >= 0.81 is load-bearing, not just a version floor. Every public subpath of this package is exposed through a wildcard exports map, and Metro only consults exports with Package Exports enabled — the default from Metro 0.82 / RN 0.79 onward. On anything older, no subpath of this package resolves at all.

Tailwind setup (NativeWind)

Use the styles.native entry, not styles. The web runtime declares Tailwind plugins, ::-webkit-scrollbar utilities and html/input resets that don't apply under NativeWind, and its @source scans the web build output for classes.

In your app's global.css — the file you import from your root component and point withNativewind at in metro.config.js:

@import 'tailwindcss/theme.css' layer(theme);
@import '@flipdish/ui-tokens/css' layer(theme);
@import 'tailwindcss/preflight.css' layer(base);

/* NativeWind's own theme variables — required by its Metro transformer. */
@import 'nativewind/theme';

@import '@flipdish/ui-library/styles.native';
@import 'tailwindcss/utilities.css';

styles.native contributes exactly one thing: @source "./native", which tells Tailwind to scan this package's React Native build output so the class strings inside Avatar, Button (and every component that follows) generate utilities. Without it those components render unstyled — Tailwind ignores node_modules unless a source is declared explicitly.

Dark mode follows the device colour scheme via NativeWind's useColorScheme. (The web runtime instead remaps dark: onto [data-theme="dark"], which has no RN equivalent.)

The @source mechanism mirrors what ./styles already does on web, where it's proven in production. The exact import order above is modelled on NativeWind v5's documented install and has not yet been executed against a real Expo app — confirm it during the pre-publish verification described below.

TypeScript setup

Add the react-native condition to your app's tsconfig.json so TypeScript resolves the same files Metro does:

{
  "compilerOptions": {
    "moduleResolution": "bundler", // or "node16" / "nodenext"
    "customConditions": ["react-native"],
  },
}

Without it you get the web type definitions — Avatar would appear to accept src and badge, neither of which the native implementation supports (initials IS supported natively).

Importing a component that isn't available yet

Both TypeScript and Metro reject it, so the mistake can't reach a device:

error TS2305: Module '"@flipdish/ui-library/components/atoms/Button"'
              has no exported member 'Button'.
Unable to resolve module .../dist/native/components/atoms/Button/index.js

Scoping Tailwind CSS to a subtree

When your app doesn't own the whole page — a widget, an embed, a Storybook preview, a multi-tenant host, or a micro-frontend — its Tailwind v4 output (utilities and Preflight resets) can leak into or clash with the surrounding CSS. The fix is to scope every emitted selector under a single element the app renders itself: UIProvider's scopeId stamps data-mfe-scope on the themed root for this. Never scope to a host container id (#flipdish-micro-frontend) or a union of ids; several apps share those containers, so the rules leak across them.

@flipdish/ui-library/utilities/cssScopeUtils ships createScopedPrefixTransform, a small factory for postcss-prefix-selector that consolidates the scoping rules (scope :root/html so @theme tokens and base typography cascade only within the subtree, leave :host and @keyframes steps alone, never double-prefix, etc.) so you write one line instead of copy-pasting a bespoke transform.

Install the companion plugin (an optional peer):

pnpm add -D postcss-prefix-selector

Then add it to your PostCSS config:

// postcss.config.mjs
import prefixSelector from 'postcss-prefix-selector';
import { createScopedPrefixTransform } from '@flipdish/ui-library/utilities/cssScopeUtils';

// Your Portal microFrontendWindowName; must match <UIProvider scopeId="sale-service">.
const SCOPE = '[data-mfe-scope="sale-service"]';

export default {
  plugins: [
    prefixSelector({
      prefix: SCOPE,
      transform: createScopedPrefixTransform(SCOPE),
    }),
  ],
};

Tailwind's output becomes plain [data-mfe-scope="sale-service"] .px-4 { … }, which every downstream tool (Vite, lightningcss) understands.

Options

createScopedPrefixTransform(scopeSelector, options?):

OptionTypeDefaultDescription
shouldScope(filePath: string | undefined) => boolean() => trueReturn false to leave a file's selectors untouched (e.g. third-party CSS you don't want prefixed).
scopeBodybooleanfalseScope Preflight body resets to the mount selector instead of leaving body global. Enable when the host page must not inherit the reset.
matchRootElementbooleantrueAlso emit a compound selector so the scope root itself matches class and attribute selectors; [data-theme="dark"] on the themed root needs it.
createScopedPrefixTransform('[data-tailwind]', {
  shouldScope: (file) => !file || !file.includes('node_modules'),
  scopeBody: true,
});

Why PostCSS and not Tailwind's important(#selector)? Tailwind v4's important(...) syntax emits non-standard @media important(...) blocks that lightningcss can't parse during minification, so scoping is done as a PostCSS pass over Tailwind's output instead.

Micro-frontends are one use case; the same transform applies to widgets, embeds, Storybook, and multi-tenant UIs.

Documentation

Full component docs, interactive examples, and design guidance live in the Storybook.

Changelog

See CHANGELOG.md for release history.

Contributing

This package lives in the flipdish-design-system monorepo. Contributor documentation — folder conventions, how Untitled UI components are adapted, the web/native file split, and dependency rules — lives alongside the source there.

版本与发布记录

@flipdish/ui-library 共发布 122 个版本,首次发布于 2026/06/22;过去 12 个月发布了 122 个版本。

版本发布日期距今
0.52.0latest2026/11/16今天
0.51.02026/11/141 天前
0.50.02026/11/142 天前
0.49.02026/11/105 天前
0.48.32026/11/096 天前
0.48.22026/11/079 天前

关于 @flipdish/ui-library 的常见问题

@flipdish/ui-library 是什么?

Flipdish Design System — atomic-design component library (Tailwind v4 + UntitledUI + React Aria).

如何安装 @flipdish/ui-library?

在项目目录运行 npm install @flipdish/ui-library,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、tailwind-merge(^3.6.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flipdish/ui-library 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@flipdish/ui-library 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flipdish/ui-library 可以商用吗?

@flipdish/ui-library 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@flipdish/ui-library 的下载量有多少?

根据 npm 官方下载统计,@flipdish/ui-library 在 2026/10/15 – 2026/11/13 这 30 天内被下载 9,276 次,日均约 309 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flipdish/ui-library 还在维护吗?

最新版本 0.52.0 发布于 2026/11/16(今天);至今共发布 122 个版本,其中过去 12 个月发布了 122 个;首次发布于 2026/06/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。