From 44e1493db6cf448f59be7eb2b740c3baae76a993 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E7=88=B1=E5=90=83=E7=99=BD=E8=90=9D?= =?UTF-8?q?=E5=8D=9C?= Date: Fri, 13 Oct 2023 15:16:08 +0800 Subject: [PATCH] feat: Watermark support inherit to disable passing (#45319) * docs: init * feat: support inherit * test: update snapshot --- .../__snapshots__/demo-extend.test.ts.snap | 24 +++++++++++++++++-- .../__tests__/__snapshots__/demo.test.ts.snap | 20 ++++++++++++++-- components/watermark/__tests__/index.test.tsx | 13 ++++++++++ components/watermark/demo/portal.tsx | 14 ++++++++--- components/watermark/index.en-US.md | 1 + components/watermark/index.tsx | 10 +++++++- components/watermark/index.zh-CN.md | 1 + 7 files changed, 75 insertions(+), 8 deletions(-) diff --git a/components/watermark/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/watermark/__tests__/__snapshots__/demo-extend.test.ts.snap index 1f5817f06896..22639b1aacb4 100644 --- a/components/watermark/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/watermark/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -1249,7 +1249,7 @@ Array [ type="button" > - Show Modal + Show in Modal @@ -1261,10 +1261,30 @@ Array [ type="button" > - Show Drawer + Show in Drawer +
+ +
+ , +
+
,
- Show Modal + Show in Modal
@@ -822,7 +822,19 @@ Array [ type="button" > - Show Drawer + Show in Drawer + + +
+
+
@@ -831,5 +843,9 @@ Array [ class="" style="position:relative" />, +
, ] `; diff --git a/components/watermark/__tests__/index.test.tsx b/components/watermark/__tests__/index.test.tsx index 5517533de1a1..dcf21ca7cda5 100644 --- a/components/watermark/__tests__/index.test.tsx +++ b/components/watermark/__tests__/index.test.tsx @@ -134,6 +134,19 @@ describe('Watermark', () => { , () => document.body.querySelector('.ant-drawer-content')!.lastChild!, ); + + it('inherit = false', async () => { + render( + + + , + ); + await waitFakeTimer(); + + expect(document.body.querySelector('.ant-drawer-content')!.lastChild).toHaveClass( + 'ant-drawer-wrapper-body', + ); + }); }); it('should not crash if content is empty string', async () => { diff --git a/components/watermark/demo/portal.tsx b/components/watermark/demo/portal.tsx index cfb1223fa751..64bd52e82ef4 100644 --- a/components/watermark/demo/portal.tsx +++ b/components/watermark/demo/portal.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Watermark, Modal, Drawer, Button, Space } from 'antd'; +import { Button, Drawer, Modal, Space, Watermark } from 'antd'; const placeholder = (
{ 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 ( <> - - + + + @@ -43,6 +46,11 @@ const App: React.FC = () => { {placeholder} + + + {placeholder} + + ); }; diff --git a/components/watermark/index.en-US.md b/components/watermark/index.en-US.md index b982669758d6..cedad2cd0f4f 100644 --- a/components/watermark/index.en-US.md +++ b/components/watermark/index.en-US.md @@ -34,6 +34,7 @@ Common props ref:[Common props](/docs/react/common-props) | --- | --- | --- | --- | --- | | 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 | 9 | | | image | Image source, it is recommended to export 2x or 3x image, high priority (support base64 format) | string | - | | diff --git a/components/watermark/index.tsx b/components/watermark/index.tsx index 53047c37abaa..fe859d6ec535 100644 --- a/components/watermark/index.tsx +++ b/components/watermark/index.tsx @@ -31,6 +31,7 @@ export interface WatermarkProps { gap?: [number, number]; offset?: [number, number]; children?: React.ReactNode; + inherit?: boolean; } /** @@ -60,6 +61,7 @@ const Watermark: React.FC = (props) => { gap = [100, 100], offset, children, + inherit = true, } = props; const [, token] = useToken(); const { @@ -267,13 +269,19 @@ const Watermark: React.FC = (props) => { ); // ============================= Render ============================= + const childNode = inherit ? ( + {children} + ) : ( + children + ); + return (
- {children} + {childNode}
); }; diff --git a/components/watermark/index.zh-CN.md b/components/watermark/index.zh-CN.md index cda9a2d18b32..efeef1145a82 100644 --- a/components/watermark/index.zh-CN.md +++ b/components/watermark/index.zh-CN.md @@ -36,6 +36,7 @@ tag: New | --- | --- | --- | --- | --- | | width | 水印的宽度,`content` 的默认值为自身的宽度 | number | 120 | | | height | 水印的高度,`content` 的默认值为自身的高度 | number | 64 | | +| inherit | 是否将水印传导给弹出组件如 Modal、Drawer | boolean | true | 5.11.0 | | rotate | 水印绘制时,旋转的角度,单位 `°` | number | -22 | | | zIndex | 追加的水印元素的 z-index | number | 9 | | | image | 图片源,建议导出 2 倍或 3 倍图,优先级高 (支持 base64 格式) | string | - | |