Forráskód Böngészése

feat: sidesheet support for customized closeIcon (#1965)

LonelySnowman 1 éve
szülő
commit
872a8e8d45

+ 1 - 0
content/show/sidesheet/index-en-US.md

@@ -303,6 +303,7 @@ class Demo extends React.Component {
 | bodyStyle | Content style                                                                                                              | CSSProperties | - | - |
 | bodyStyle | Content style                                                                                                              | CSSProperties | - | - |
 | className | Class name                                                                                                                 | string | - | - |
 | className | Class name                                                                                                                 | string | - | - |
 | closable | Toggle whether to show close button                                                                                        | boolean | true | - |
 | closable | Toggle whether to show close button                                                                                        | boolean | true | - |
+| closeIcon         | Icon for close button                                                                                              | ReactNode | <IconClose /\>    | - |
 | closeOnEsc | oggle whether to allow close modal by keyboard event Esc                                                                   | boolean | false | 1.0.0 |
 | closeOnEsc | oggle whether to allow close modal by keyboard event Esc                                                                   | boolean | false | 1.0.0 |
 | disableScroll | Toggle whether to add `overflow: hidden` to document.body element. Only works when not setting `getPopupContainer`         | boolean | true | - |
 | disableScroll | Toggle whether to add `overflow: hidden` to document.body element. Only works when not setting `getPopupContainer`         | boolean | true | - |
 | footer | Footer                                                                                                                     | ReactNode | null | 1.3.0 |
 | footer | Footer                                                                                                                     | ReactNode | null | 1.3.0 |

+ 1 - 0
content/show/sidesheet/index.md

@@ -308,6 +308,7 @@ class Demo extends React.Component {
 | bodyStyle | 面板内容的样式                                                                       | CSSProperties | - | - |
 | bodyStyle | 面板内容的样式                                                                       | CSSProperties | - | - |
 | className | 类名                                                                            | string | - | - |
 | className | 类名                                                                            | string | - | - |
 | closable | 是否允许通过右上角的关闭按钮关闭                                                              | boolean | true | - |
 | closable | 是否允许通过右上角的关闭按钮关闭                                                              | boolean | true | - |
+| closeIcon | 关闭按钮的 icon                                                                 | ReactNode | <IconClose /\> | - |
 | closeOnEsc | 允许通过键盘事件 Esc 触发关闭                                                             | boolean | false | 1.0.0 |
 | closeOnEsc | 允许通过键盘事件 Esc 触发关闭                                                             | boolean | false | 1.0.0 |
 | disableScroll | 默认渲染在 document.body 层时是否禁止 body 的滚动,即给 body 添加 `overflow: hidden`             | boolean | true | - |
 | disableScroll | 默认渲染在 document.body 层时是否禁止 body 的滚动,即给 body 添加 `overflow: hidden`             | boolean | true | - |
 | footer | 侧边栏底部                                                                         | ReactNode | null | 1.3.0 |
 | footer | 侧边栏底部                                                                         | ReactNode | null | 1.3.0 |

+ 1 - 0
packages/semi-foundation/sideSheet/sideSheetFoundation.ts

@@ -8,6 +8,7 @@ export interface SideSheetProps {
     bodyStyle?: Record<string, any>;
     bodyStyle?: Record<string, any>;
     className?: string;
     className?: string;
     closable?: boolean;
     closable?: boolean;
+    closeIcon?: any;
     closeOnEsc?: boolean;
     closeOnEsc?: boolean;
     disableScroll?: boolean;
     disableScroll?: boolean;
     footer?: any;
     footer?: any;

+ 6 - 2
packages/semi-ui/sideSheet/SideSheetContent.tsx

@@ -1,4 +1,4 @@
-import React, { CSSProperties } from 'react';
+import React, { CSSProperties, ReactNode } from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 import cls from 'classnames';
 import cls from 'classnames';
 import { cssClasses } from '@douyinfe/semi-foundation/sideSheet/constants';
 import { cssClasses } from '@douyinfe/semi-foundation/sideSheet/constants';
@@ -14,6 +14,7 @@ const prefixCls = cssClasses.PREFIX;
 
 
 export interface SideSheetContentProps {
 export interface SideSheetContentProps {
     onClose?: (e: React.MouseEvent) => void;
     onClose?: (e: React.MouseEvent) => void;
+    closeIcon?: ReactNode;
     mask?: boolean;
     mask?: boolean;
     maskStyle?: CSSProperties;
     maskStyle?: CSSProperties;
     maskClosable?: boolean;
     maskClosable?: boolean;
@@ -38,6 +39,7 @@ export interface SideSheetContentProps {
 export default class SideSheetContent extends React.PureComponent<SideSheetContentProps> {
 export default class SideSheetContent extends React.PureComponent<SideSheetContentProps> {
     static propTypes = {
     static propTypes = {
         onClose: PropTypes.func,
         onClose: PropTypes.func,
+        closeIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
     };
     };
 
 
     static defaultProps = {
     static defaultProps = {
@@ -92,6 +94,7 @@ export default class SideSheetContent extends React.PureComponent<SideSheetConte
             title,
             title,
             closable,
             closable,
             headerStyle,
             headerStyle,
+            closeIcon,
         } = this.props;
         } = this.props;
         let header, closer;
         let header, closer;
         if (title) {
         if (title) {
@@ -102,13 +105,14 @@ export default class SideSheetContent extends React.PureComponent<SideSheetConte
             );
             );
         }
         }
         if (closable) {
         if (closable) {
+            const iconType = closeIcon || <IconClose/>;
             closer = (
             closer = (
                 <Button
                 <Button
                     className={`${prefixCls}-close`}
                     className={`${prefixCls}-close`}
                     key="close-btn"
                     key="close-btn"
                     onClick={this.close}
                     onClick={this.close}
                     type="tertiary"
                     type="tertiary"
-                    icon={<IconClose/>}
+                    icon={iconType}
                     theme="borderless"
                     theme="borderless"
                     size="small"
                     size="small"
                 />
                 />

+ 10 - 0
packages/semi-ui/sideSheet/__test__/sideSheet.test.js

@@ -1,5 +1,6 @@
 import { Icon, SideSheet, Modal } from '../../index';
 import { Icon, SideSheet, Modal } from '../../index';
 import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
 import { BASE_CLASS_PREFIX } from '../../../semi-foundation/base/constants';
+import { IconEyeClosed } from '@douyinfe/semi-icons';
 // import toJson from 'enzyme-to-json';
 // import toJson from 'enzyme-to-json';
 
 
 function getSideSheet(SideSheetProps, children) {
 function getSideSheet(SideSheetProps, children) {
@@ -316,4 +317,13 @@ describe('SideSheet', () => {
         sideSheet.unmount();
         sideSheet.unmount();
     });
     });
 
 
+    it('closeIcon', () => {
+        let com = getSideSheet({
+            visible: true,
+            closeIcon: (<IconEyeClosed />)
+        });
+        let sideSheet = mount(com, { attachTo: document.getElementById('container') });
+        expect(sideSheet.find(`.${BASE_CLASS_PREFIX}-icon-eye_closed`).length).toBe(1);
+    });
+
 })
 })