Skip to content

Commit

Permalink
fix: Fixed Error when specifying 100% to height. #47
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 30, 2020
1 parent 158c9c3 commit 1c92266
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/MDEditor.tsx
Expand Up @@ -162,7 +162,7 @@ export default class MDEditor extends React.PureComponent<MDEditorProps, MDEdito
/>
<div
className={`${prefixCls}-content`}
style={{ height: this.state.fullscreen ? 'calc(100% - 29px)' : (this.state.height as number) - 29 }}
style={{ height: this.state.fullscreen ? 'calc(100% - 29px)' : `calc(${this.state.height} - 29px` }}
>
{/(edit|live)/.test(this.state.preview as string) && (
<TextArea
Expand Down
65 changes: 30 additions & 35 deletions src/components/Toolbar/index.tsx
@@ -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>
);
};
2 changes: 1 addition & 1 deletion website/App.tsx
Expand Up @@ -121,7 +121,7 @@ export default function App() {
}
return children;
},
code: ({ children, language, value }) => {
code: ({ language, value }) => {
if (language && language.toLocaleLowerCase() === 'katex') {
const html = katex.renderToString(value, {
throwOnError: false
Expand Down

0 comments on commit 1c92266

Please sign in to comment.