Skip to content

Commit

Permalink
feat(menu): menu组件添加offset控制子项偏移量
Browse files Browse the repository at this point in the history
  • Loading branch information
ShanaMaid committed Jun 15, 2018
1 parent 15fbf79 commit 4bb5b6f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
7 changes: 7 additions & 0 deletions components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface IMenuProps extends IBaseComponent {
* 展开回调
*/
onOpenChange?: (openKeys: string[]) => void;
/**
* 偏移量
*/
offset?: number;
}

export interface IMenuState {
Expand All @@ -49,6 +53,7 @@ export class Menu extends Component<IMenuProps, IMenuState> {
static defaultProps = {
defaultActiveKey: '',
defaultOpenKeys: [],
offset: 24,
};

state = {
Expand Down Expand Up @@ -105,6 +110,7 @@ export class Menu extends Component<IMenuProps, IMenuState> {
className, style, children,
onSelect, defaultActiveKey,
onOpenChange, defaultOpenKeys,
offset,
...otherProps} = this.props;
const preCls = 'yoshino-menu';
const clsName = classNames(
Expand All @@ -128,6 +134,7 @@ export class Menu extends Component<IMenuProps, IMenuState> {
openKeys,
onSelect: this.onSelect,
onOpenChange: this.onOpenChange,
offset,
});
})
}
Expand Down
8 changes: 6 additions & 2 deletions components/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export interface IMenuItemProps extends IBaseComponent {
* 禁用
*/
disabled?: boolean;
/**
* 偏移量
*/
offset?: number;
}

export interface IMenuItemState {
Expand Down Expand Up @@ -54,7 +58,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
render() {
const {
className, style, children, deep,
activeKey, keyId, disabled,
activeKey, keyId, disabled, offset,
} = this.props;
const preCls = 'yoshino-menu-item';
const clsName = classNames(
Expand All @@ -64,7 +68,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {
[`${preCls}-disabled`]: disabled,
},
);
const paddingLeft = `${deep as number * 24}px`;
const paddingLeft = `${deep as number * (offset as number)}px`;
return (
<li
className={clsName}
Expand Down
9 changes: 7 additions & 2 deletions components/Menu/MenuItemGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export interface IMenuItemGroupProps extends IBaseComponent {
* 展开回调
*/
onOpenChange?: (openKeys: string[]) => void;
/**
* 偏移量
*/
offset?: number;
}

export interface IMenuItemGroupState {
Expand All @@ -45,14 +49,14 @@ export class MenuItemGroup extends Component<IMenuItemGroupProps, IMenuItemGroup
render() {
const {
className, style, children, deep, title,
activeKey, onSelect,
activeKey, onSelect, offset,
} = this.props;
const preCls = 'yoshino-menu-item-group';
const clsName = classNames(
preCls, className,
);
const childrens = React.Children.toArray(children);
const paddingLeft = `${deep as number * 24}px`;
const paddingLeft = `${deep as number * (offset as number)}px`;
return (
<div
className={clsName}
Expand All @@ -72,6 +76,7 @@ export class MenuItemGroup extends Component<IMenuItemGroupProps, IMenuItemGroup
deep: deep as number + 1,
activeKey,
onSelect,
offset,
});
})
}
Expand Down
9 changes: 7 additions & 2 deletions components/Menu/SubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export interface ISubMenuProps extends IBaseComponent {
* 禁用
*/
disabled?: boolean;
/**
* 偏移量
*/
offset?: number;
}

export interface ISubMenuState {
Expand Down Expand Up @@ -72,7 +76,7 @@ export class SubMenu extends Component<ISubMenuProps, ISubMenuState> {
const {
className, style, children, title, deep,
activeKey, onSelect, onOpenChange, openKeys = [],
keyId, disabled,
keyId, disabled, offset,
...otherProps,
} = this.props;
const preCls = 'yoshino-sub-menu';
Expand All @@ -85,7 +89,7 @@ export class SubMenu extends Component<ISubMenuProps, ISubMenuState> {
},
);
const childrens = React.Children.toArray(children);
const paddingLeft = `${deep as number * 24}px`;
const paddingLeft = `${deep as number * (offset as number)}px`;
return (
<React.Fragment>
<li
Expand Down Expand Up @@ -147,6 +151,7 @@ export class SubMenu extends Component<ISubMenuProps, ISubMenuState> {
openKeys,
onSelect,
onOpenChange,
offset,
});
})
}
Expand Down
6 changes: 6 additions & 0 deletions docs/pages/Menu/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export default [
type: "(openKeys: string[]) => void",
defaultValue: "-",
},
{
props: "offset",
intro: "菜单子项偏移量",
type: "number",
defaultValue: "24",
},
]
},
{
Expand Down

0 comments on commit 4bb5b6f

Please sign in to comment.