Skip to content

Commit

Permalink
Merge pull request #198 from jacargentina/feature-disable-preview
Browse files Browse the repository at this point in the history
feature #197: added "disablePreview" prop
  • Loading branch information
andrerpena authored Dec 6, 2019
2 parents 26f099e + 790b33c commit d2e8e17
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs-md/5-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ though on the first call, *editorState* is supposed to be something like `{markd
options. It is recommended to [inspect the layouts source code](https://github.com/andrerpena/react-mde/tree/master/src/components-layout) to see what options can be passed to each
while the documentation is not complete.
-- **readOnly?: boolean**: Flag to render the editor in read-only mode.
-- **disablePreview?: boolean**: Flag to disable preview, which also disables the tab selection. Useful when handling preview generation externally.

## Styling

Expand Down
36 changes: 19 additions & 17 deletions src/components/MdeToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface MdeToolbarProps {
onCommand: (command: Command) => void;
onTabChange: (tab: Tab) => void;
readOnly: boolean;
disablePreview: boolean;
tab: Tab,
l18n: L18n
}
Expand All @@ -26,28 +27,29 @@ export class MdeToolbar extends React.Component<MdeToolbarProps> {

render() {
const { l18n } = this.props;
const { getIcon, children, commands, onCommand, readOnly } = this.props;
const { getIcon, children, commands, onCommand, readOnly, disablePreview } = this.props;
if ((!commands || commands.length === 0) && !children) {
return null;
}
return (
<div className="mde-header">
<div className="mde-tabs">
<button
type="button"
className={classNames({ "selected": this.props.tab === "write" })}
onClick={() => this.handleTabChange("write")}
>
{l18n.write}
</button>
<button
type="button"
className={classNames({ "selected": this.props.tab === "preview" })}
onClick={() => this.handleTabChange("preview")}
>
{l18n.preview}
</button>
</div>
{!disablePreview && <div className="mde-tabs">
<button
type="button"
className={classNames({ "selected": this.props.tab === "write" })}
onClick={() => this.handleTabChange("write")}
>
{l18n.write}
</button>
<button
type="button"
className={classNames({ "selected": this.props.tab === "preview" })}
onClick={() => this.handleTabChange("preview")}
>
{l18n.preview}
</button>
</div>
}
{
commands.map((commandGroup: CommandGroup, i: number) => (
<MdeToolbarButtonGroup key={i} hidden={this.props.tab === "preview"}>
Expand Down
6 changes: 5 additions & 1 deletion src/components/ReactMde.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface ReactMdeProps {
emptyPreviewHtml?: string;
loadingPreview?: React.ReactNode;
readOnly?: boolean;
disablePreview?: boolean;
textAreaProps?: Partial<React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>>;
l18n?: L18n;
}
Expand Down Expand Up @@ -61,7 +62,8 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
minEditorHeight: 200,
maxEditorHeight: 500,
minPreviewHeight: 200,
selectedTab: "write"
selectedTab: "write",
disablePreview: false,
};

constructor(props: ReactMdeProps) {
Expand Down Expand Up @@ -130,6 +132,7 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
loadingPreview,
emptyPreviewHtml,
readOnly,
disablePreview,
value,
l18n,
minPreviewHeight,
Expand All @@ -147,6 +150,7 @@ export class ReactMde extends React.Component<ReactMdeProps, ReactMdeState> {
onTabChange={this.handleTabChange}
tab={selectedTab}
readOnly={readOnly}
disablePreview={disablePreview}
l18n={l18n}
/>
{
Expand Down

0 comments on commit d2e8e17

Please sign in to comment.