@creativoma/liquid-glass

中文文档
1.5.0发布于 2026/08/27MITTypeScriptESM + CJS零依赖近 30 天下载 4701

A React wrapper component with liquid frosted glass effect using TailwindCSS

原始使用文档
文档目录22 节
  1. Features
  2. Installation
  3. Quick Start
  4. API Reference
  5. Props
  6. SSR / Next.js
  7. Styling
  8. Accessibility
  9. Usage Examples
  10. Card with glass effect
  11. Button with liquid glass effect
  12. Modal with glassmorphism
  13. Navbar with glass effect
  14. Advanced liquid effect customization
  15. Development
  16. Project Structure
  17. Requirements
  18. Technologies
  19. Package Formats
  20. Contributing
  21. License
  22. Changelog

@creativoma/liquid-glass

npm version npm downloads CI License: MIT TypeScript React

A modern React component library featuring liquid frosted glass effect using TailwindCSS and SVG filters. Create elegant glassmorphism interfaces with advanced visual effects.

Live demo →

Features

  • Liquid frosted glass effect with customizable displacement mapping
  • SSR-ready: works out of the box in Next.js (App Router and pages router), Remix, and any server-rendered app
  • Full TypeScript support with comprehensive type definitions
  • TailwindCSS integration for seamless styling
  • Polymorphic component API (render as any HTML element)
  • Cross-browser compatible with Safari/iOS fallback support
  • Respects prefers-reduced-motion by automatically using the lighter filter
  • disabled prop to fully bypass the effect for low-power devices or long lists
  • Customizable blur, tint, and turbulence parameters
  • Zero dependencies (peer dependencies only)
  • ESM and CJS formats for maximum compatibility

Installation

npm install @creativoma/liquid-glass
yarn add @creativoma/liquid-glass
pnpm add @creativoma/liquid-glass

Quick Start

import { LiquidGlass } from '@creativoma/liquid-glass'

function App() {
  return (
    <LiquidGlass backdropBlur={3} tintColor="rgba(255, 255, 255, 0.25)">
      <div className="p-8">
        <h1>Your content here</h1>
        <p>The frosted glass effect is applied to this container</p>
      </div>
    </LiquidGlass>
  )
}

API Reference

Props

PropTypeDefaultDescription
childrenReact.ReactNode-Content to display inside the container
classNamestring''Additional TailwindCSS CSS classes
contentClassNamestring-Classes for the internal content wrapper (layout goes here)
backdropBlurnumber2Blur level for the backdrop filter (in px)
tintColorstring'rgba(255, 255, 255, .2)'Tint overlay color (rgba)
displacementScalenumber150Displacement map scale (liquid effect intensity)
turbulenceBaseFrequencystring'0.008 0.008'Turbulence base frequency (controls noise size)
turbulenceSeednumber1.5Turbulence seed (for different noise patterns)
asElementType'div'HTML component to render (div, button, section, etc.)
styleCSSProperties-Additional inline styles
disabledbooleanfalseFully bypasses the glass effect, rendering plain children

SSR / Next.js

The component is SSR-safe and ships with the "use client" directive baked into every bundle, so it works in Next.js without any wrapper:

// app/page.tsx — App Router, works directly in a Server Component tree
import { LiquidGlass } from '@creativoma/liquid-glass'

export default function Page() {
  return (
    <LiquidGlass backdropBlur={4} className="rounded-2xl p-8">
      <h1>Server-rendered glass</h1>
    </LiquidGlass>
  )
}
  • No window, document, or layout effects during render — renderToString works in plain Node (covered by a regression test).
  • Browser capability detection (Safari/iOS fallback, prefers-reduced-motion) runs after mount, so server and client markup always match and there are no hydration warnings.
  • Both import (ESM) and require (CJS) entry points are published, so it also works with the pages router and older toolchains.

Styling

Rounded corners go on className (or style) of the component itself — the internal backdrop and tint layers use border-radius: inherit, so they follow whatever radius you set:

<LiquidGlass backdropBlur={8} className="rounded-3xl p-6">
  <p className="text-white">The blur is clipped to the same radius</p>
</LiquidGlass>

Layout classes (flex/grid) go on contentClassName instead: children render inside an internal wrapper (it keeps them above the blur and tint layers), so display: flex on className would lay out that wrapper, not your content:

<LiquidGlass
  as="nav"
  className="rounded-full px-6 py-3"
  contentClassName="flex items-center gap-6"
>
  <span>Logo</span>
  <a href="#docs">Docs</a>
</LiquidGlass>

Accessibility

LiquidGlass automatically detects the OS-level prefers-reduced-motion setting (via useBrowserDetection) and falls back to the lighter Safari/iOS filter when it's set, since the full turbulence + displacement pipeline is the most GPU-intensive path. If you need to opt out entirely — for a reduced-motion mode, a low-power device, or a long list of glass cards — pass disabled to render plain children with no filter or backdrop blur:

<LiquidGlass disabled={isLowPowerMode}>
  <div className="p-8">Falls back to plain content</div>
</LiquidGlass>

Usage Examples

Card with glass effect

<LiquidGlass
  backdropBlur={5}
  tintColor="rgba(255, 255, 255, 0.3)"
  className="max-w-md rounded-xl p-6"
>
  <h2 className="mb-4 text-2xl font-bold text-white">Card Title</h2>
  <p className="text-white/90">
    Card content with elegant frosted glass effect.
  </p>
</LiquidGlass>

Button with liquid glass effect

<LiquidGlass
  as="button"
  backdropBlur={3}
  tintColor="rgba(0, 0, 0, 0.2)"
  className="rounded-full px-8 py-4 font-semibold text-white transition-transform hover:scale-110"
>
  Click Me!
</LiquidGlass>

Modal with glassmorphism

<div className="fixed inset-0 flex items-center justify-center bg-black/50">
  <LiquidGlass
    backdropBlur={10}
    tintColor="rgba(255, 255, 255, 0.15)"
    className="max-w-lg rounded-2xl p-8 shadow-2xl"
  >
    <h3 className="mb-4 text-xl font-semibold text-white">
      Modal with Liquid Glass
    </h3>
    <p className="mb-6 text-white/90">
      This is an example of a modal with glassmorphism effect
    </p>
    <button className="rounded-lg bg-blue-500 px-4 py-2 text-white">
      Close
    </button>
  </LiquidGlass>
</div>

Navbar with glass effect

<LiquidGlass
  backdropBlur={4}
  tintColor="rgba(255, 255, 255, 0.1)"
  className="fixed top-0 right-0 left-0 z-50 border-b border-white/20"
>
  <nav className="container mx-auto flex items-center justify-between px-6 py-4">
    <div className="text-xl font-bold text-white">My App</div>
    <div className="flex gap-6 text-white">
      <a href="#home">Home</a>
      <a href="#about">About</a>
      <a href="#contact">Contact</a>
    </div>
  </nav>
</LiquidGlass>

Advanced liquid effect customization

<LiquidGlass
  backdropBlur={3}
  tintColor="rgba(100, 200, 255, 0.2)"
  displacementScale={200}
  turbulenceBaseFrequency="0.01 0.01"
  turbulenceSeed={5}
  className="rounded-3xl p-12"
>
  <p className="text-white">Custom liquid effect</p>
</LiquidGlass>

Development

# Clone the repository
git clone https://github.com/creativoma/liquid-glass.git
cd liquid-glass

# Install dependencies
pnpm install

# Development mode
pnpm run dev

# Linting and formatting
pnpm run lint
pnpm run format

# Build library
pnpm run build:lib

# Build demo
pnpm run build:demo

# Preview
pnpm run preview

# Publish (requires permissions)
npm publish

Project Structure

liquid-glass/
├── src/
│   ├── components/
│   │   ├── LiquidGlass.tsx
│   │   └── types.ts
│   ├── hooks/
│   │   └── useBrowserDetection.ts
│   ├── demo/                  # Demo/landing application
│   ├── main.tsx               # Demo entry point
│   ├── index.ts               # Library entry point
│   └── index.css
├── dist/                      # Compiled library
├── dist-demo/                 # Compiled demo site
├── public/                    # Demo assets
├── README.md
├── package.json
├── tsconfig.json
├── vite.config.ts            # Demo build config
├── vite.config.lib.ts        # Library build config
└── tailwind.config.js

Requirements

  • React >= 18.0.0
  • React DOM >= 18.0.0
  • TailwindCSS (component uses Tailwind classes)

CI verifies compatibility with both React 18 and React 19 on every push (see .github/workflows/ci.yml).

Technologies

  • React - Component library
  • TypeScript - Static typing
  • Vite - Build tool and bundler
  • Tailwind CSS - CSS framework for glassmorphism effect
  • SVG Filters - Advanced visual effects with feTurbulence and feDisplacementMap

Package Formats

This package includes multiple formats for maximum compatibility:

  • ESM (dist/index.js) - For modern applications
  • CJS (dist/index.cjs) - For require() consumers (Next.js pages router, Jest, plain Node)
  • TypeScript (dist/index.d.ts / dist/index.d.cts) - Type definitions for both entry points

All bundles are prefixed with the "use client" directive for React Server Components compatibility.

Contributing

Contributions are welcome! Please:

  1. Fork the project
  2. Create a branch for your feature (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT © Mariano Álvarez

Changelog

See CHANGELOG.md for a detailed list of changes.

版本与发布记录

@creativoma/liquid-glass 共发布 13 个版本,首次发布于 2025/10/23;过去 12 个月发布了 11 个版本。

版本发布日期距今
1.5.0latest2026/08/272 个月前
1.4.02026/08/252 个月前
1.3.12026/08/252 个月前
1.3.02026/08/013 个月前
1.2.02026/03/078 个月前
1.1.32026/03/078 个月前

关于 @creativoma/liquid-glass 的常见问题

@creativoma/liquid-glass 是什么?

A React wrapper component with liquid frosted glass effect using TailwindCSS

如何安装 @creativoma/liquid-glass?

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

@creativoma/liquid-glass 支持 TypeScript 吗?

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

@creativoma/liquid-glass 支持 ESM 还是 CommonJS?

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

@creativoma/liquid-glass 可以商用吗?

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

@creativoma/liquid-glass 的下载量有多少?

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

@creativoma/liquid-glass 还在维护吗?

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