@constructor-io/constructorio-ui-components

中文文档
1.8.0发布于 2026/11/03MITTypeScriptESM + CJS构建来源已验证近 30 天下载 1.4万

Constructor UI Components library for web applications

原始使用文档
文档目录22 节
  1. Introduction
  2. Requirements
  3. Installation
  4. Usage Patterns
  5. Normal Usage
  6. Render Other Components using asChild
  7. Component Overrides
  8. Passing Data Attributes
  9. Compound Components
  10. Tailwind CSS Prefix
  11. Class Categories
  12. Class Naming Convention
  13. Variants and Modifiers
  14. Responsive Breakpoints
  15. Arbitrary Values and Selectors
  16. CSS Variables
  17. Customizing Theme
  18. Local Development
  19. Development Scripts
  20. Build scripts
  21. Contributing
  22. License

Constructor UI Components Library

minzipped size NPM Version MIT licensed

Introduction

UI Components Library is a collection of React components that can be used to build UI for Constructor.io products.

Our Storybook Docs provide a comprehensive overview of each component, including its behavior, variations, and configuration options.

Requirements

  • Node.js v22.18.0 (LTS Jod)
  • React >=16.12.0
  • React DOM >=16.12.0

Installation

npm i @constructor-io/constructorio-ui-components

Usage Patterns

Normal Usage

import { Button } from '@constructor-io/constructorio-ui-components';
import '@constructor-io/constructorio-ui-components/styles.css'

function App() {
  return <Button>Click me</Button>;
}

Render Other Components using asChild

import { Badge } from '@constructor-io/constructorio-ui-components';
import '@constructor-io/constructorio-ui-components/styles.css'

function App() {
  return (
    <Badge asChild variant="outline">
      <a href="#">
        A link that looks like a badge
      </a>
    </Badge>
  );
}

Component Overrides

import { Button } from '@constructor-io/constructorio-ui-components';
import '@constructor-io/constructorio-ui-components/styles.css'

function App() {
  return (
    <Button
      componentOverrides={{
        reactNode: <span>A span rendered in place of a button</span>
      }}
    >
      This will be overridden
    </Button>
  );
}

Passing Data Attributes

import { Button } from '@constructor-io/constructorio-ui-components';
import '@constructor-io/constructorio-ui-components/styles.css'

function App() {
  return <Button data-cnstrc-price={23.25}>Purchase</Button>;
}

Compound Components

import { ProductCard } from '@constructor-io/constructorio-ui-components';
import '@constructor-io/constructorio-ui-components/styles.css'

function App() {
  return (
    <ProductCard
      product={{
        id: 'highland-golf-pants',
        variationId: 'highland-golf-pants--navy',
        name: "Highland Golf Pants",
        imageUrl: 'https://example.com/pants.jpg',
        price: '799',
        rating: 4.8,
        reviewsCount: 203,
        description: 'Premium golf pants designed for comfort and performance on the course',
      }}
      className='overflow-hidden max-w-md'
    >
      <div className='grid grid-cols-2 gap-4 p-4'>
        <ProductCard.ImageSection />
        <div className='space-y-2'>
          <ProductCard.PriceSection />
          <ProductCard.TitleSection />
          <ProductCard.RatingSection />
        </div>
      </div>
      <ProductCard.Footer>
        <ProductCard.AddToCartButton />
      </ProductCard.Footer>
    </ProductCard>
  );
}

Tailwind CSS Prefix

This library uses Tailwind CSS v4 with a cio: prefix to avoid conflicts with your application's Tailwind classes. All utility classes and CSS variables are namespaced to ensure styles don't leak or collide.

Class Categories

The codebase uses two distinct class namespaces. They look similar but serve different purposes:

  • cio-* (no colon) — plain CSS hooks / BEM identifiers attached to component roots and key sub-elements (e.g., cio-components, cio-badge, cio-product-card-image, cio-filter-visual-swatch). These are stable selectors used for styling overrides and tests; they are not Tailwind utilities and are never prefixed with cio:.
  • cio:* (with colon) — Tailwind v4 utility classes scoped by the prefix(cio) import directive (e.g., cio:flex, cio:hover:bg-primary/90). The conventions in the rest of this section apply to these.
// Both kinds appear together on the same element:
<div className="cio-badge cio:inline-flex cio:items-center cio:gap-1.5">

Class Naming Convention

When adding or customizing Tailwind classes in this library, always use the cio: prefix:

// Correct
<div className="cio:flex cio:items-center cio:gap-2">

// Incorrect - will not work
<div className="flex items-center gap-2">

Variants and Modifiers

The prefix must come before any variants (hover, focus, responsive, etc.):

// Correct - prefix first, then variant, then utility
<button className="cio:bg-primary cio:hover:bg-primary/90 cio:disabled:opacity-50">

// Incorrect - variant before prefix
<button className="hover:cio:bg-primary/90 disabled:cio:opacity-50">

Responsive Breakpoints

// Correct
<div className="cio:p-2 cio:sm:p-4 cio:lg:p-6">

// Incorrect
<div className="cio:p-2 sm:cio:p-4 lg:cio:p-6">

Arbitrary Values and Selectors

// Correct
<div className="cio:w-[200px] cio:[&_svg]:size-4">

// Incorrect
<div className="[&_svg]:cio:size-4">

CSS Variables

CSS variables are prefixed with --cio-:

:root {
  --cio-primary: oklch(0.1969 0.0101 276.49);
  --cio-background: oklch(1 0 0);
  --cio-radius: 0.625rem;
}

Customizing Theme

You can override the default theme by setting the CSS variables in your application:

:root {
  --cio-primary: #your-brand-color;
  --cio-radius: 0.5rem;
}

Local Development

Development Scripts

npm ci                         # Install dependencies for local dev
npm run dev                    # Start a local dev server for Storybook
npm run lint                   # Run lint
npm run test                   # Run unit tests

Build scripts

npm run compile                # Compile the library, remove aliases, copy styles
npm run build-storybook        # Build Storybook
npm run serve-built-storybook  # Serve the built Storybook

Contributing

  • Fork the repo & create a new branch.
  • Run npm install to install dependencies.
  • Submit a PR for review.

License

MIT © Constructor.io

版本与发布记录

@constructor-io/constructorio-ui-components 共发布 14 个版本,首次发布于 2026/01/09;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.8.0latest2026/11/037 天前
1.7.02026/09/072 个月前
1.6.22026/09/072 个月前
1.6.12026/08/312 个月前
1.6.02026/06/164 个月前
1.5.02026/05/275 个月前

关于 @constructor-io/constructorio-ui-components 的常见问题

@constructor-io/constructorio-ui-components 是什么?

Constructor UI Components library for web applications

如何安装 @constructor-io/constructorio-ui-components?

在项目目录运行 npm install @constructor-io/constructorio-ui-components,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.12.0)、tslib(^2.4.0)、react-dom(>=16.12.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@constructor-io/constructorio-ui-components 支持 TypeScript 吗?

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

@constructor-io/constructorio-ui-components 支持 ESM 还是 CommonJS?

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

@constructor-io/constructorio-ui-components 可以商用吗?

@constructor-io/constructorio-ui-components 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@constructor-io/constructorio-ui-components 的下载量有多少?

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

@constructor-io/constructorio-ui-components 还在维护吗?

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