@darraghmckay/tailwind-react-ui

中文文档
0.9.8发布于 2022/11/25MITESM + CJS近 30 天下载 3043

React component library & UI framework for use with Tailwind CSS

原始使用文档
文档目录10 节
  1. Features
  2. No Built in Styles
  3. Utility Class Props
  4. Configurable Theme
  5. Composable Components
  6. PurgeCSS Support
  7. Example
  8. Using Utility Components
  9. Using UI Components
  10. Useful Links

Tailwind React UI

CircleCI


NB: As the 0.#.# version number suggests this is still very much work in progress, so semantic versioning will not be followed until a v1 release is solidified. Expect breaking changes to occur on minor version jumps.


Tailwind React UI provides ready built components that make use of Tailwind CSS utility framework.

If you're unfamiliar with the concepts behind Tailwind you can get an overview at https://tailwindcss.com/docs/what-is-tailwind:

Creating a framework for building custom UIs means you can't provide abstractions at the usual level of buttons, forms, cards, navbars, etc. Instead, Tailwind provides highly composable, low-level utility classes that make it easy to build complex user interfaces.

Tailwind React UI leverages these utility classes to provide base level components that are common across various projects, whilst still offering the ability to customise the output to match your project's style.

Features

No Built in Styles

Tailwind React UI's components have no inline/encapsulated styles (barring some use for CSS transitions), so there's no specificity issues, no new CSS in JS tool chain to apply. The library simply uses classes made available by Tailwind CSS that your whole app will make use of with hooks available to specify which classes are applied.

Utility Class Props

Introduces a props API for Tailwind's uitlity classes that allows for extensive customisation & quick prototyping

  • Bring this functionality to your own components through the withTailind higher order component or by using the component primitives to have that handled down wind

Configurable Theme

Has a configurable theme to apply a design system approach for the base styling of components

  • Uses React context in order to allow for customising which color / space / etc classes get applied by default

  • Can still leverage the utility props in all components to override the default styling in whatever way you wish with sensible defaults applied in relevent components, e.g. <FillButton bg="purple-dark" text="white" /> will also apply interactive styling to the resulting element <button className="bg-purple text-white hover:bg-purple-darker focus:bg-purple-darker" />

Composable Components

Tailwind React UI's suite of components are highly composable allowing for a large degree of flexibility.

  • Components are largely functional, but where applicable offer wrappers to control UI state for opening/closing/etc.

  • Components have accessibility best practices built in; inputs will read out related help/error text, toggleable components correctly call out their open state, etc

PurgeCSS Support

PurgeCSS is a key tool when using TailwindCSS to strip out any of the unused utilities and to avoid any complications with this the library provides a whitelist of classes your theme will generate from components as well as a custom extractor that parses the utility class props API used by the components.

Example

Using Utility Components

<Box maxW="md" m={{ x: 'auto' }}>
  <Box border shadow bg="white">
    <Box p={4}>
      <Text is="h1" text={['blue', 'xxl']} m={{ b: 4 }}>
        Hello World
      </Text>
    </Box>
    <Flex items="end" wrap reverse>
      <Touchable
        p={{ x: 4, y: 2 }}
        border={[true, 'transparent']}
        bg="blue"
        bg-hocus="blue-dark"
        text="white"
        w="full"
        w-sm="1/5"
      >
        Foo
      </Touchable>
      <Touchable
        p={{ x: 4, y: 2 }}
        border={[true, 'blue']}
        text="blue"
        text-hocus="white"
        bg-hocus="blue"
        w="full"
        w-sm="1/5"
      >
        Bar
      </Touchable>
    </Flex>
  </Box>
</Box>

Using UI Components

<Container maxW="md">
  <Card border shadow>
    <CardBody>
      <Title size={6} text="blue">
        Hello World
      </Title>
    </CardBody>
    <CardFooter wrap>
      <FillButton brand="primary" w="full" w-sm="1/5">
        Foo
      </FillButton>
      <OutlineButton brand="primary" w="full" w-sm="1/5">
        Bar
      </OutlineButton>
    </CardFooter>
  </Card>
</Container>

版本与发布记录

@darraghmckay/tailwind-react-ui 共发布 13 个版本,首次发布于 2020/10/15;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.9.8latest2022/11/253 年前
0.9.72021/11/244 年前
0.9.62021/07/155 年前
0.9.52021/03/265 年前
0.9.42021/03/235 年前
0.9.32021/02/125 年前

关于 @darraghmckay/tailwind-react-ui 的常见问题

@darraghmckay/tailwind-react-ui 是什么?

React component library & UI framework for use with Tailwind CSS

如何安装 @darraghmckay/tailwind-react-ui?

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

@darraghmckay/tailwind-react-ui 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/darraghmckay__tailwind-react-ui 是否存在。

@darraghmckay/tailwind-react-ui 支持 ESM 还是 CommonJS?

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

@darraghmckay/tailwind-react-ui 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=8.11.3。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@darraghmckay/tailwind-react-ui 可以商用吗?

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

@darraghmckay/tailwind-react-ui 的下载量有多少?

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

@darraghmckay/tailwind-react-ui 还在维护吗?

最新版本 0.9.8 发布于 2022/11/25(3 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/10/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。