跳到主要内容

Watermark

Watermark: the unit tile is rendered offscreen to a canvas dataURL and tiled as a background over the protected content (pointer-events: none, not selectable). Text and image modes; H5 carries a MutationObserver self-healing guard. The tile computation and render predicates are all pure functions consumed from @lh-ui/share/core/watermark.

Basic usage​

Text watermark (multi-line via \n)

受保护的内容:水印叠加在本区域之上,不阻断交互。

disabled:不渲染水印层。

import { LhWatermark } from '@lh-ui/react'

export default function Demo() {
return (
<LhWatermark content="lh-ui 家族" fontSize={16} gapX={120}>
<div>Protected content</div>
</LhWatermark>
)
}

Image watermark & fullscreen​

image takes precedence over content; fullscreen covers the viewport (fixed position):

<LhWatermark image="/logo.png" opacity={0.2} fullscreen />

Watermark API​

PropDescriptionTypeDefault
contentWatermark text (multi-line via \n; used when image is absent)string—
imageWatermark image URL; takes precedence over contentstring—
opacityLayer opacity (0-1)number0.15
rotateUnit tile rotation (deg)number-22
gapXHorizontal gap pxnumber100
gapYVertical gap px (falls back to gapX)number—
fontSizeText size px (falls back to watermark.fontSize token)number14
fontColorText color (falls back to color.text.primary token)string—
zIndexLayer z-index (falls back to zIndex.normal)number100
fullscreenCover the viewport instead of the positioned parentbooleanfalse
disabledTurn the watermark off (no layer rendered)booleanfalse
sxQuick layout propsLhSxProps—
childrenProtected content (plus default slot)ReactNode—

Accessibility​

  • The layer is aria-hidden="true"; the root carries aria-label="Watermark".