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

Commit

Permalink
fix: change dropdownbutton divider
Browse files Browse the repository at this point in the history
Signed-off-by: fan-mengwen <fan.mengwen@xsky.com>
  • Loading branch information
fan-mengwen committed May 19, 2023
1 parent ea084cc commit 8419ea0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
19 changes: 14 additions & 5 deletions src/components/Dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const defaultProps: DropdownDefaultProps = {
};

const Dropdown = (props: DropdownProps) => {
const { customToggle, align, className, id, title, children } = props;
const { customToggle, className, id, title, children, align } = props;
return (
<BootstrapDropdown id={id} className={className} align={align}>
{customToggle && title}
{customToggle && title && (
<BootstrapDropdown.Toggle variant="default" as={title as React.ElementType} />
)}
{!customToggle && title && (
<BootstrapDropdown.Toggle variant="default">{title}</BootstrapDropdown.Toggle>
)}
Expand All @@ -27,9 +29,9 @@ Dropdown.propTypes = {
**/
className: PropTypes.string,
/**
* 下拉框收起时展示内容 string
* 下拉框收起时展示内容 node
**/
title: PropTypes.string,
title: PropTypes.node,
/**
* 元素 id,默认为 CustomDropdown string
**/
Expand All @@ -42,4 +44,11 @@ Dropdown.propTypes = {

Dropdown.defaultProps = defaultProps;

export default Dropdown;
export default Object.assign(Dropdown, {
Toggle: BootstrapDropdown.Toggle,
Menu: BootstrapDropdown.Menu,
Item: BootstrapDropdown.Item,
ItemText: BootstrapDropdown.ItemText,
Divider: BootstrapDropdown.Divider,
Header: BootstrapDropdown.Header,
});
6 changes: 5 additions & 1 deletion src/components/DropdownButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,17 @@ function renderMenu(
</SubMenu>
);
}
if (item.divider) {
return <Dropdown.Divider key={item.key} />;
}
const handleItemSelect = (eventKey: any) => {
const { onSelect } = item;
setButtonShow(!!show);
// 如果有传入 onSelect 回调函数,会继续执行传入的回调函数
if (onSelect) onSelect(eventKey);
};
const menuProps = omit(item, 'toolTip');
const menuProps = omit(item, ['toolTip', 'divider']);

return (
<Dropdown.Item {...menuProps} onSelect={handleItemSelect}>
{item.toolTip ? (
Expand Down
4 changes: 2 additions & 2 deletions src/components/SubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const SubMenu = (props: SubMenuProps) => {
const { title, children, name } = props;
return (
<div className="SubMenu" data-name={`SubMenu-${name}`}>
<Dropdown.Item bsPrefix="dropdown-header dropdown-submenu dropdown-submenu-header">
<Dropdown.Header bsPrefix="dropdown-submenu dropdown-submenu-header">
<span>{title}</span>
<ul className="dropdown-menu">{children}</ul>
</Dropdown.Item>
</Dropdown.Header>
</div>
);
};
Expand Down
3 changes: 2 additions & 1 deletion src/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export type DropdownButtonMenuItem =
onSelect?: Function;
disabled?: boolean;
toolTip?: TooltipProps;
divider?: boolean;
}
| string;

Expand Down Expand Up @@ -306,7 +307,7 @@ export interface DropdownAlignProps {
}
export interface DropdownProps extends DropdownDefaultProps, DropdownAlignProps {
className?: string;
title?: string;
title?: React.ReactNode;
children?: React.ReactNode;
customToggle?: boolean;
pullRight?: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/style/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ $progress-height: 8px;
$progress-legend-height: 8px;

/* PingFang font */
$pingfang-font: "-apple-system", "BlinkMacSystemFont", "Helvetica Neue", "Helvetica", "Arial", "PingFangSC-Regular", "San Francisco", "Noto Sans", "Roboto", "Microsoft Yahei", "微软雅黑", "Segoe UI", "sans-serif";
$pingfang-font: '-apple-system', 'BlinkMacSystemFont', 'Helvetica Neue', 'Helvetica', 'Arial', 'PingFang SC',
'San Francisco', 'Noto Sans', 'Roboto', 'Microsoft Yahei', '微软雅黑', 'Segoe UI', 'sans-serif';

/* Font weight */
$font-weight-regular: 400;
Expand Down

0 comments on commit 8419ea0

Please sign in to comment.