Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
fix: build misc
Browse files Browse the repository at this point in the history
Signed-off-by: kaiguo <kaiguo@xsky.com>
  • Loading branch information
kaiguo committed Dec 21, 2022
1 parent f62a5f5 commit f3ebf1c
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 90 deletions.
23 changes: 15 additions & 8 deletions src/components/Button/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { mount } from 'enzyme';
describe('Button-Tooltip', () => {
it('Button is not disabled and show toolTip', () => {
const button = mount(
<Button toolTip={{ placement: 'top', children: 'tooltip showed and able to click' }} onClick={() => document.title = 'clicked'}>
<Button
toolTip={{ placement: 'top', children: 'tooltip showed and able to click' }}
onClick={() => (document.title = 'clicked')}
>
click
</Button>
)
</Button>,
);
const tooltip = document.getElementsByTagName('#Tooltip');
button.simulate('mouseenter');
expect(tooltip.length === 1);
Expand All @@ -19,16 +22,20 @@ describe('Button-Tooltip', () => {
});
it('Button is disabled and show toolTip', () => {
const button = mount(
<Button disabled toolTip={{ placement: 'top', children: 'tooltip showed and not allowed to click' }} onClick={() => document.title = 'clicked'}>
<Button
disabled
toolTip={{ placement: 'top', children: 'tooltip showed and not allowed to click' }}
onClick={() => (document.title = 'clicked')}
>
click
</Button>
)
</Button>,
);
const tooltip = document.getElementsByTagName('#Tooltip');
button.simulate('mouseenter');
expect(tooltip.length === 1);
button.simulate('mouseleave');
expect(tooltip.length === 0);
button.simulate('click');
expect(document.title !== 'clicked');
})
})
});
});
44 changes: 22 additions & 22 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import React from 'react';
import { Button as BSButton } from 'react-bootstrap';
import Tooltip from '../Tooltip'
import Tooltip from '../Tooltip';
import { ButtonProps } from '../../interface';
import './style.scss';

interface Button extends ButtonProps {};
interface Button extends ButtonProps {}

const Button:React.FC<ButtonProps> = props => {
const Button: React.FC<ButtonProps> = props => {
const { toolTip, children, ...restProps } = props;
const { disabled, className } = restProps;
return (
toolTip ? (
<Tooltip
label={
<div className="Button_Tooltip-Div">
<BSButton
{...(restProps as any)}
className={disabled ? `Button_Tooltip-Div-Button ${className}` : `${className}` }
>
{children}
</BSButton>
</div>
}
{...toolTip}
/>
) : <BSButton {...(restProps as any)}>{children}</BSButton>
)
}
return toolTip ? (
<Tooltip
label={
<div className="Button_Tooltip-Div">
<BSButton
{...(restProps as any)}
className={disabled ? `Button_Tooltip-Div-Button ${className}` : `${className}`}
>
{children}
</BSButton>
</div>
}
{...toolTip}
/>
) : (
<BSButton {...(restProps as any)}>{children}</BSButton>
);
};

export default Button;
export default Button;
3 changes: 3 additions & 0 deletions src/components/DatePicker/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`DatePicker get time 1`] = `
readOnly={true}
value=""
/>
<div />
</span>
`;

Expand All @@ -26,6 +27,7 @@ exports[`DatePicker render disable 1`] = `
readOnly={true}
value=""
/>
<div />
</span>
`;

Expand All @@ -42,5 +44,6 @@ exports[`DatePicker render show en lang 1`] = `
readOnly={true}
value=""
/>
<div />
</span>
`;
46 changes: 36 additions & 10 deletions src/components/DropdownButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { DropdownButton as BootstrapDropdownButton, MenuItem, ButtonGroup } from 'react-bootstrap';

Expand All @@ -19,7 +19,12 @@ function randomId() {
.substring(2);
}

function renderContent(menu: DropdownButtonMenuItem[] = [], setButtonOpen: Function, isDifferentMenu: boolean, open?: boolean) {
function renderContent(
menu: DropdownButtonMenuItem[] = [],
setButtonOpen: Function,
isDifferentMenu: boolean,
open?: boolean,
) {
if (menu instanceof Array) {
return menu.map(m => renderMenu(m, setButtonOpen, isDifferentMenu, open));
}
Expand All @@ -34,15 +39,29 @@ function usePrevious(value: any) {
return ref.current;
}

function renderMenu(menu: DropdownButtonMenuItem, setButtonOpen: Function, isDifferentMenu: boolean, open?: boolean) {
function renderMenu(
menu: DropdownButtonMenuItem,
setButtonOpen: Function,
isDifferentMenu: boolean,
open?: boolean,
) {
const item = cloneDeep(menu);
if (!item) {
return null;
}
if (typeof item === 'string') {
return <MenuItem key={item} onSelect={() => { setButtonOpen(!!open) }} >{item}</MenuItem>;
return (
<MenuItem
key={item}
onSelect={() => {
setButtonOpen(!!open);
}}
>
{item}
</MenuItem>
);
}
if (!item.key && isDifferentMenu) {
if (!item.key && isDifferentMenu) {
item.key = randomId();
}
if (item.children && item.children.length) {
Expand All @@ -57,12 +76,19 @@ function renderMenu(menu: DropdownButtonMenuItem, setButtonOpen: Function, isDif
setButtonOpen(!!open);
// 如果有传入 onSelect 回调函数,会继续执行传入的回调函数
if (onSelect) onSelect(eventKey);
}
};
const menuProps = omit(item, 'toolTip');
return <MenuItem {...menuProps} onSelect={handleItemSelect} >
{ item.toolTip ? (<Tooltip {...item.toolTip} placement={item.toolTip.placement || 'right'}>{item.toolTip.children}</Tooltip>)
: item.title }
</MenuItem>;
return (
<MenuItem {...menuProps} onSelect={handleItemSelect}>
{item.toolTip ? (
<Tooltip {...item.toolTip} placement={item.toolTip.placement || 'right'}>
{item.toolTip.children}
</Tooltip>
) : (
item.title
)}
</MenuItem>
);
}

const DropdownButton = (props: DropdownButtonProps) => {
Expand Down
108 changes: 102 additions & 6 deletions src/components/Icon/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,122 @@ initialize {
"attribs": Object {
"aria-hidden": "true",
"height": "1em",
"viewBox": "0 0 34 32",
"viewBox": "0 0 20 21",
"width": "1em",
},
"children": Array [
Object {
"attribs": Object {},
"children": Array [
Object {
"attribs": Object {
"d": "M15.61 11.22c2.4107 0 4.39 1.951 4.39 4.3717a4.4127 4.4127 0 0 1-1.2844 3.1186A4.3759 4.3759 0 0 1 15.61 20c-2.4464 0-4.39-1.951-4.39-4.3717 0-2.4207 1.9428-4.4083 4.39-4.4083zM2.6224 13.6858l6.086 3.2011c.1979.1086.4617.1628.7916.1628.2114 0 .3957-.0223.5529-.0668a5.6276 5.6276 0 0 0 1.1821 2.3322l-.9433.5017c-.198.1085-.4618.1628-.7917.1628-.3299 0-.5937-.0543-.7917-.1628l-8.362-4.449C.1156 15.2591 0 15.1235 0 14.9607c0-.1627.1155-.2984.3464-.4069.8906-.5064 1.4348-.8139 1.6328-.9224.1649-.1085.3793-.0904.6432.0543zm12.388-.4599c-.9994 0-1.7987.8001-1.7987 1.8004a1.794 1.794 0 0 0 .5245 1.2754 1.79 1.79 0 0 0 1.2742.525c.333 0 .633-.1.8993-.2665l1.3324 1.3006c.1.067.2.1333.3331.1333a.4418.4418 0 0 0 .4331-.4336.5124.5124 0 0 0-.1331-.3334l-1.3324-1.3006c.1662-.2665.2662-.5667.2662-.9002 0-1.0003-.7993-1.8004-1.7986-1.8004zm0 .8664c.5 0 .8993.4004.8993.9002 0 .4999-.4.9002-.8993.9002a.896.896 0 0 1-.8994-.9002c0-.4998.4-.9002.8994-.9002zM2.6224 9.3645l6.086 3.2358c.1979.1079.4617.1618.7916.1618.3299 0 .5937-.054.7917-.1618l.7202-.3828c-.7057.957-1.12 2.1404-1.12 3.4163v-.0122a1.4989 1.4989 0 0 1-.3919.0528c-.2639 0-.5278-.072-.7917-.2157l-8.362-4.3684C.1156 10.9824 0 10.8386 0 10.6588c0-.1798.1155-.3236.3464-.4314.8906-.4674 1.4348-.755 1.6328-.863.1979-.1437.4123-.1437.6432 0zM9.5 1.9295c.3299 0 .5937.051.7917.1531l8.362 4.1841c.2308.102.3463.2296.3463.3827 0 .153-.1155.2806-.3464.3827l-8.362 4.184c-.1979.1021-.4617.1531-.7916.1531-.3299 0-.5937-.051-.7917-.153L.3463 7.032C.1156 6.93 0 6.8025 0 6.6494c0-.153.1155-.2806.3464-.3827l8.362-4.184c.1979-.1021.4617-.1531.7916-.1531zm7.4219 7.381l1.7317.9169c.231.1078.3464.2516.3464.4314 0 .1003-.0359.1893-.1077.2672A5.7082 5.7082 0 0 0 15.61 9.8919c-.0782 0-.156.0015-.2334.0046.6804-.3617 1.0468-.557 1.1-.586.1649-.0719.3133-.0719.4453 0z",
"id": "os-search-role_svg__a",
},
"children": Array [],
"name": "path",
"namespace": "http://www.w3.org/2000/svg",
"next": null,
"parent": [Circular],
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"d": undefined,
"id": undefined,
},
"x-attribsPrefix": Object {
"d": undefined,
"id": undefined,
},
},
],
"name": "defs",
"namespace": "http://www.w3.org/2000/svg",
"next": Object {
"attribs": Object {
"fill-rule": "evenodd",
"href": "#os-search-role_svg__a",
"transform": "translate(0 .3276)",
},
"children": Array [],
"name": "use",
"namespace": "http://www.w3.org/2000/svg",
"next": null,
"parent": [Circular],
"prev": [Circular],
"type": "tag",
"x-attribsNamespace": Object {
"fill-rule": undefined,
"href": "http://www.w3.org/1999/xlink",
"transform": undefined,
},
"x-attribsPrefix": Object {
"fill-rule": undefined,
"href": "xlink",
"transform": undefined,
},
},
"parent": [Circular],
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {},
"x-attribsPrefix": Object {},
},
Object {
"attribs": Object {
"d": "M27.337 15.763c-.794-.287-1.65-.443-2.542-.443-4.13 0-7.451 3.34-7.451 7.451 0 3.433 2.318 6.301 5.495 7.148h-18.9c-.854 0-1.547-.692-1.547-1.547V4.465c0-.854.692-1.547 1.547-1.547h21.852c.854 0 1.547.692 1.547 1.547v11.297zm-2.542 1.181c3.2 0 5.827 2.579 5.827 5.779 0 3.248-2.627 5.827-5.827 5.827-3.248 0-5.827-2.579-5.827-5.779s2.579-5.827 5.827-5.827zM5.61 23.679v1.701h8.12v-1.701H5.61zm0-5.413v1.701h11.367v-1.701H5.61zm0-5.413v1.701h14.615v-1.701H5.61zm0-5.413v1.701h16.239V7.44H5.61zm22.003 18.722c.334 0 .621-.287.621-.621 0-.191-.096-.382-.191-.478L26.132 23.2c.239-.382.382-.812.382-1.29 0-1.433-1.146-2.579-2.579-2.579s-2.579 1.146-2.579 2.579a2.568 2.568 0 0 0 2.579 2.579c.478 0 .907-.143 1.29-.382l1.911 1.863c.143.096.287.191.478.191zm-3.677-5.588c.716 0 1.29.573 1.29 1.29s-.573 1.29-1.29 1.29c-.716 0-1.29-.573-1.29-1.29s.573-1.29 1.29-1.29z",
"fill-rule": "evenodd",
"href": "#os-search-role_svg__a",
"transform": "translate(0 .3276)",
},
"children": Array [],
"name": "path",
"name": "use",
"namespace": "http://www.w3.org/2000/svg",
"next": null,
"parent": [Circular],
"prev": null,
"prev": Object {
"attribs": Object {},
"children": Array [
Object {
"attribs": Object {
"d": "M15.61 11.22c2.4107 0 4.39 1.951 4.39 4.3717a4.4127 4.4127 0 0 1-1.2844 3.1186A4.3759 4.3759 0 0 1 15.61 20c-2.4464 0-4.39-1.951-4.39-4.3717 0-2.4207 1.9428-4.4083 4.39-4.4083zM2.6224 13.6858l6.086 3.2011c.1979.1086.4617.1628.7916.1628.2114 0 .3957-.0223.5529-.0668a5.6276 5.6276 0 0 0 1.1821 2.3322l-.9433.5017c-.198.1085-.4618.1628-.7917.1628-.3299 0-.5937-.0543-.7917-.1628l-8.362-4.449C.1156 15.2591 0 15.1235 0 14.9607c0-.1627.1155-.2984.3464-.4069.8906-.5064 1.4348-.8139 1.6328-.9224.1649-.1085.3793-.0904.6432.0543zm12.388-.4599c-.9994 0-1.7987.8001-1.7987 1.8004a1.794 1.794 0 0 0 .5245 1.2754 1.79 1.79 0 0 0 1.2742.525c.333 0 .633-.1.8993-.2665l1.3324 1.3006c.1.067.2.1333.3331.1333a.4418.4418 0 0 0 .4331-.4336.5124.5124 0 0 0-.1331-.3334l-1.3324-1.3006c.1662-.2665.2662-.5667.2662-.9002 0-1.0003-.7993-1.8004-1.7986-1.8004zm0 .8664c.5 0 .8993.4004.8993.9002 0 .4999-.4.9002-.8993.9002a.896.896 0 0 1-.8994-.9002c0-.4998.4-.9002.8994-.9002zM2.6224 9.3645l6.086 3.2358c.1979.1079.4617.1618.7916.1618.3299 0 .5937-.054.7917-.1618l.7202-.3828c-.7057.957-1.12 2.1404-1.12 3.4163v-.0122a1.4989 1.4989 0 0 1-.3919.0528c-.2639 0-.5278-.072-.7917-.2157l-8.362-4.3684C.1156 10.9824 0 10.8386 0 10.6588c0-.1798.1155-.3236.3464-.4314.8906-.4674 1.4348-.755 1.6328-.863.1979-.1437.4123-.1437.6432 0zM9.5 1.9295c.3299 0 .5937.051.7917.1531l8.362 4.1841c.2308.102.3463.2296.3463.3827 0 .153-.1155.2806-.3464.3827l-8.362 4.184c-.1979.1021-.4617.1531-.7916.1531-.3299 0-.5937-.051-.7917-.153L.3463 7.032C.1156 6.93 0 6.8025 0 6.6494c0-.153.1155-.2806.3464-.3827l8.362-4.184c.1979-.1021.4617-.1531.7916-.1531zm7.4219 7.381l1.7317.9169c.231.1078.3464.2516.3464.4314 0 .1003-.0359.1893-.1077.2672A5.7082 5.7082 0 0 0 15.61 9.8919c-.0782 0-.156.0015-.2334.0046.6804-.3617 1.0468-.557 1.1-.586.1649-.0719.3133-.0719.4453 0z",
"id": "os-search-role_svg__a",
},
"children": Array [],
"name": "path",
"namespace": "http://www.w3.org/2000/svg",
"next": null,
"parent": [Circular],
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {
"d": undefined,
"id": undefined,
},
"x-attribsPrefix": Object {
"d": undefined,
"id": undefined,
},
},
],
"name": "defs",
"namespace": "http://www.w3.org/2000/svg",
"next": [Circular],
"parent": [Circular],
"prev": null,
"type": "tag",
"x-attribsNamespace": Object {},
"x-attribsPrefix": Object {},
},
"type": "tag",
"x-attribsNamespace": Object {
"d": undefined,
"fill-rule": undefined,
"href": "http://www.w3.org/1999/xlink",
"transform": undefined,
},
"x-attribsPrefix": Object {
"d": undefined,
"fill-rule": undefined,
"href": "xlink",
"transform": undefined,
},
},
],
Expand Down
5 changes: 3 additions & 2 deletions src/components/Modal/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ describe('Modal', () => {
<strong>Modal Content</strong>
</Modal>,
);
expect(draggableNode.find('.drag-handle').length).toBe(1);
setTimeout(() => {
expect(draggableNode.find('.drag-handle').length).toBe(1);
}, 0);

const disDraggableNode = mount(
<Modal title="Modal Title" onHide={noOp} draggable={false}>
Expand All @@ -88,5 +90,4 @@ describe('Modal', () => {
);
expect(disDraggableNode.find('.drag-handle').length).toBe(0);
});

});
13 changes: 10 additions & 3 deletions src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { Modal as BaseModal, ModalHeader, ModalTitle, ModalBody, ModalFooter, Button } from 'react-bootstrap';
import {
Modal as BaseModal,
ModalHeader,
ModalTitle,
ModalBody,
ModalFooter,
Button,
} from 'react-bootstrap';
import Draggable, { DraggableEvent, DraggableData } from 'react-draggable';
import { ModalProps } from '../../interface';
import Loader from '../Loader';
Expand Down Expand Up @@ -38,7 +45,7 @@ const draggableHiddenTitleStyle: React.CSSProperties = {
visibility: 'hidden',
};

const Modal: React.FC<ModalProps> = (props) => {
const Modal: React.FC<ModalProps> = props => {
const { onStart, bounds, draggleRef } = useDrag();

const {
Expand Down Expand Up @@ -125,7 +132,7 @@ Modal.propTypes = {
/** 对话框附加行内样式 */
style: PropTypes.object,
/** 对话框大小 */
bsSize: PropTypes.oneOf(['sm', 'lg']),
bsSize: PropTypes.oneOf(['sm', 'lg', 'medium', 'xlarge', undefined, null]),
/** 确定、提交按钮文案 */
confirmText: PropTypes.string,
/** 确定、提交按钮样式 */
Expand Down
9 changes: 4 additions & 5 deletions src/components/Tabs/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ describe('Tabs width Dropdown', () => {
const [key, setKey] = useState(newTABS[0].key);
const handleSelect = (key: any) => setKey(key);
return (
<Tabs tabs={newTABS}
<Tabs
tabs={newTABS}
activeKey={key}
onSelect={
(key: any) => handleSelect(key)
}
onSelect={(key: any) => handleSelect(key)}
limitNum={5}
direction="right"
/>
);
}
};
const tabs = mount(<Xtab />);
//title 默认值
expect(tabs.find('NavDropdown').props().title).toBe('更多');
Expand Down
Loading

0 comments on commit f3ebf1c

Please sign in to comment.