워터마크

워터마크 (Watermark)

페이지에 워터마크를 입혀 저작권을 표시하거나 정보 유출을 방지하기 위해 사용하는 컴포넌트입니다.

출처: 문서

본문

언제 사용하나요 (When To Use)

  • 페이지에 워터마크를 입혀 저작권을 식별해야 할 때
  • 정보 도난을 방지하기에 적합할 때

예제 (Examples)

기본 (Basic)

가장 기본적인 사용법입니다.

import React from 'react';
import { Watermark } from 'antd';

const App: React.FC = () => (
  <Watermark content="Ant Design">
    <div style={{ height: 500 }} />
  </Watermark>
);

export default App;

여러 줄 워터마크 (Multi-line watermark)

content로 문자열 배열을 설정하고, WatermarkText로 줄마다 커스텀 글꼴 스타일의 여러 줄 텍스트 워터마크를 지정합니다.

import React from 'react';
import { Watermark } from 'antd';

const App: React.FC = () => (
  <Watermark content={['Ant Design', { text: 'Happy Working', font: { fontSize: 12 } }]}>
    <div style={{ height: 500 }} />
  </Watermark>
);

export default App;

이미지 워터마크 (Image watermark)

image로 이미지 주소를 지정합니다. 이미지가 고해상도이고 늘어나지 않도록 하려면 너비와 높이를 설정하고, 로고 이미지 주소의 너비·높이보다 최소 2배 크게 업로드하세요.

import React from 'react';
import { Watermark } from 'antd';

const App: React.FC = () => (
  <Watermark
    height={30}
    width={130}
    image="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*lkAoRbywo0oAAAAAAAAAAAAADrJ8AQ/original"
  >
    <div style={{ height: 500 }} />
  </Watermark>
);

export default App;

커스텀 구성 (Custom configuration)

커스텀 매개변수를 구성해 워터마크 효과를 미리 봅니다.

import React, { useState } from 'react';
import { ColorPicker, Flex, Form, Input, InputNumber, Slider, Typography, Watermark } from 'antd';
import type { ColorPickerProps, GetProp, WatermarkProps } from 'antd';

type Color = Extract<GetProp<ColorPickerProps, 'value'>, string | { cleared: any }>;

const { Paragraph } = Typography;

interface WatermarkConfig {
  content: string;
  color: string | Color;
  fontSize: number;
  zIndex: number;
  rotate: number;
  gap: [number, number];
  offset?: [number, number];
}

const App: React.FC = () => {
  const [form] = Form.useForm();
  const [config, setConfig] = useState<WatermarkConfig>({
    content: 'Ant Design',
    color: 'rgba(0, 0, 0, 0.15)',
    fontSize: 16,
    zIndex: 11,
    rotate: -22,
    gap: [100, 100],
    offset: undefined,
  });
  const { content, color, fontSize, zIndex, rotate, gap, offset } = config;

  const watermarkProps: WatermarkProps = {
    content,
    zIndex,
    rotate,
    gap,
    offset,
    font: { color: typeof color === 'string' ? color : color.toRgbString(), fontSize },
  };

  return (
    <Flex gap="medium">
      <Watermark {...watermarkProps}>
        <Typography>
          <Paragraph>
            The light-speed iteration of the digital world makes products more complex. However,
            human consciousness and attention resources are limited. Facing this design
            contradiction, the pursuit of natural interaction will be the consistent direction of
            Ant Design.
          </Paragraph>
          <Paragraph>
            Natural user cognition: According to cognitive psychology, about 80% of external
            information is obtained through visual channels. The most important visual elements in
            the interface design, including layout, colors, illustrations, icons, etc., should fully
            absorb the laws of nature, thereby reducing the user&apos;s cognitive cost and bringing
            authentic and smooth feelings. In some scenarios, opportunely adding other sensory
            channels such as hearing, touch can create a richer and more natural product experience.
          </Paragraph>
          <Paragraph>
            Natural user behavior: In the interaction with the system, the designer should fully
            understand the relationship between users, system roles, and task objectives, and also
            contextually organize system functions and services. At the same time, a series of
            methods such as behavior analysis, artificial intelligence and sensors could be applied
            to assist users to make effective decisions and reduce extra operations of users, to
            save users&apos; mental and physical resources and make human-computer interaction more
            natural.
          </Paragraph>
        </Typography>
        <img
          draggable={false}
          style={{ zIndex: 10, width: '100%', maxWidth: 800, position: 'relative' }}
          src="https://gw.alipayobjects.com/mdn/rms_08e378/afts/img/A*zx7LTI_ECSAAAAAAAAAAAABkARQnAQ"
          alt="img"
        />
      </Watermark>
      <Form
        style={{
          width: 280,
          flexShrink: 0,
          borderInlineStart: '1px solid #eee',
          paddingInlineStart: 16,
        }}
        form={form}
        layout="vertical"
        initialValues={config}
        onValuesChange={(_, values) => {
          setConfig(values);
        }}
      >
        <Form.Item name="content" label="Content">
          <Input placeholder="Please enter" />
        </Form.Item>
        <Form.Item name="color" label="Color">
          <ColorPicker />
        </Form.Item>
        <Form.Item name="fontSize" label="FontSize">
          <Slider step={1} min={1} max={100} />
        </Form.Item>
        <Form.Item name="zIndex" label="zIndex">
          <Slider step={1} min={0} max={100} />
        </Form.Item>
        <Form.Item name="rotate" label="Rotate">
          <Slider step={1} min={-180} max={180} />
        </Form.Item>
        <Form.Item label="Gap" style={{ marginBottom: 0 }}>
          <Flex gap="small">
            <Form.Item name={['gap', 0]}>
              <InputNumber placeholder="gapX" style={{ width: '100%' }} />
            </Form.Item>
            <Form.Item name={['gap', 1]}>
              <InputNumber placeholder="gapY" style={{ width: '100%' }} />
            </Form.Item>
          </Flex>
        </Form.Item>
        <Form.Item label="Offset" style={{ marginBottom: 0 }}>
          <Flex gap="small">
            <Form.Item name={['offset', 0]}>
              <InputNumber placeholder="offsetLeft" style={{ width: '100%' }} />
            </Form.Item>
            <Form.Item name={['offset', 1]}>
              <InputNumber placeholder="offsetTop" style={{ width: '100%' }} />
            </Form.Item>
          </Flex>
        </Form.Item>
      </Form>
    </Flex>
  );
};

export default App;

Modal과 Drawer에서 사용합니다.

import React from 'react';
import { Button, Drawer, Flex, Modal, Watermark } from 'antd';

const style: React.CSSProperties = {
  height: 300,
  display: 'flex',
  justifyContent: 'center',
  alignItems: 'center',
  backgroundColor: 'rgba(150, 150, 150, 0.2)',
};

const placeholder = <div style={style}>A mock height</div>;

const App: React.FC = () => {
  const [showModal, setShowModal] = React.useState(false);
  const [showDrawer, setShowDrawer] = React.useState(false);
  const [showDrawer2, setShowDrawer2] = React.useState(false);

  const closeModal = () => setShowModal(false);
  const closeDrawer = () => setShowDrawer(false);
  const closeDrawer2 = () => setShowDrawer2(false);

  return (
    <>
      <Flex gap="medium">
        <Button type="primary" onClick={() => setShowModal(true)}>
          Show in Modal
        </Button>
        <Button type="primary" onClick={() => setShowDrawer(true)}>
          Show in Drawer
        </Button>
        <Button type="primary" onClick={() => setShowDrawer2(true)}>
          Not Show in Drawer
        </Button>
      </Flex>
      <Watermark content="Ant Design">
        <Modal
          destroyOnHidden
          open={showModal}
          title="Modal"
          onCancel={closeModal}
          onOk={closeModal}
        >
          {placeholder}
        </Modal>
        <Drawer destroyOnHidden open={showDrawer} title="Drawer" onClose={closeDrawer}>
          {placeholder}
        </Drawer>
      </Watermark>
      <Watermark content="Ant Design" inherit={false}>
        <Drawer destroyOnHidden open={showDrawer2} title="Drawer" onClose={closeDrawer2}>
          {placeholder}
        </Drawer>
      </Watermark>
    </>
  );
};

export default App;

API

Common props ref:Common props

이 컴포넌트는 [email protected]부터 사용할 수 있습니다.

Watermark

Property Description Type Default Version Global Config
width The width of the watermark, the default value of content is its own width number 120 ×
height The height of the watermark, the default value of content is its own height number 64 ×
inherit Pass the watermark to the pop-up component such as Modal, Drawer boolean true 5.11.0 ×
rotate When the watermark is drawn, the rotation Angle, unit ° number -22 ×
zIndex The z-index of the appended watermark element number 999 ×
image Image source, it is recommended to export 2x or 3x image, high priority (support base64 format) string - ×
content Watermark text content string | WatermarkText | (string | WatermarkText)[] - WatermarkText: 6.5.0 ×
font Text style Font Font ×
gap The spacing between watermarks [number, number] [100, 100] ×
offset The offset of the watermark from the upper left corner of the container. The default is gap/2 [number, number] [gap[0]/2, gap[1]/2] ×
onRemove Callback when the watermark is removed by DOM mutation () => void - 6.0.0 ×

WatermarkText

Property Description Type Default Version
font Custom line text style Font - 6.5.0
text Line text string - 6.5.0

Font

Property Description Type Default Version
color font color CanvasFillStrokeStyles.fillStyle rgba(0,0,0,.15)
fontSize font size number 16
fontWeight font weight normal | lighter | bold | bolder | number normal
fontFamily font family string sans-serif
fontStyle font style none | normal | italic | oblique normal
textAlign specify the text alignment direction CanvasTextAlign center 5.10.0

디자인 토큰 (Design Token)

FAQ

비정상적인 이미지 워터마크 처리 {#faq-invalid-image}

이미지 워터마크를 사용할 때 이미지가 비정상적으로 로딩되면, 워터마크가 무효화되는 것을 막기 위해 동시에 content를 추가할 수 있습니다(5.2.3부터).

<Watermark
  height={30}
  width={130}
  content="Ant Design"
  image="https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*lkAoRbywo0oAAAAAAAAAAAAADrJ8AQ/original"
>
  <div style={{ height: 500 }} />
</Watermark>

5.18.0부터 overflow: hidden 스타일이 추가된 이유는 무엇인가요? {#faq-overflow-hidden}

이전 버전에서는 사용자가 개발자 도구로 컨테이너 높이를 0으로 설정해 워터마크를 숨길 수 있었습니다. 이런 상황을 막기 위해 컨테이너에 overflow: hidden 스타일을 추가했습니다. 컨테이너 높이가 바뀌면 콘텐츠도 숨겨집니다. 스타일을 덮어써 이 동작을 수정할 수 있습니다:

<Watermark style={{ overflow: 'visible' }} />

더 알아보기 (Learn more)