Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed Error when specifying 100% to height. #47
- Loading branch information
1 parent
158c9c3
commit 1c92266
Showing
3 changed files
with
32 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,44 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import { IProps } from '../../utils'; | ||
import { ICommand } from '../../commands'; | ||
import './index.less'; | ||
|
||
export interface IToolbarProps extends IProps { | ||
onCommand?: (command: ICommand) => void; | ||
commands: ICommand[]; | ||
commands?: ICommand[]; | ||
active?: { | ||
[key: string]: any, | ||
}, | ||
} | ||
|
||
export default class Toolbar extends Component<IToolbarProps> { | ||
public static defaultProps: IToolbarProps = { | ||
commands: [], | ||
} | ||
handleClick = (command: ICommand) => { | ||
const { onCommand } = this.props; | ||
export default function Toolbar(props: IToolbarProps = {}) { | ||
const { prefixCls, commands = [], active } = props; | ||
function handleClick(command: ICommand) { | ||
const { onCommand } = props; | ||
onCommand && onCommand(command); | ||
} | ||
render() { | ||
const { prefixCls, commands, active } = this.props; | ||
return ( | ||
<div className={`${prefixCls}-toolbar`}> | ||
<ul> | ||
{commands.map((item, idx) => { | ||
if (item.keyCommand === 'divider') { | ||
return <li key={idx} {...item.liProps} className={`${prefixCls}-toolbar-divider`} /> | ||
} | ||
const activeBtn = active && (item.value ? active[item.keyCommand] && active[item.keyCommand] === item.value : active[item.keyCommand]); | ||
return ( | ||
<li key={idx} {...item.liProps} className={classnames({ active: activeBtn })}> | ||
{!item.buttonProps && item.icon} | ||
{item.buttonProps && React.createElement('button', { | ||
type: 'button', | ||
disabled: active && active.preview && active.preview === 'preview' && !/(preview|fullscreen)/.test(item.keyCommand), | ||
"data-name": item.name, ...item.buttonProps, | ||
onClick: this.handleClick.bind(this, item) | ||
}, item.icon)} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
} | ||
} | ||
return ( | ||
<div className={`${prefixCls}-toolbar`}> | ||
<ul> | ||
{commands.map((item, idx) => { | ||
if (item.keyCommand === 'divider') { | ||
return <li key={idx} {...item.liProps} className={`${prefixCls}-toolbar-divider`} /> | ||
} | ||
const activeBtn = active && (item.value ? active[item.keyCommand] && active[item.keyCommand] === item.value : active[item.keyCommand]); | ||
return ( | ||
<li key={idx} {...item.liProps} className={classnames({ active: activeBtn })}> | ||
{!item.buttonProps && item.icon} | ||
{item.buttonProps && React.createElement('button', { | ||
type: 'button', | ||
disabled: active && active.preview && active.preview === 'preview' && !/(preview|fullscreen)/.test(item.keyCommand), | ||
"data-name": item.name, ...item.buttonProps, | ||
onClick: handleClick.bind(item) | ||
}, item.icon)} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters