* Set default font in examle * prettify file * add ui elements * Use UIButton at AuthPanel * sort deps * remove unsed getUserTitle method * move UserId inside AuthPanel * tests * use UIButton and UInput in Anonymous login * Use UIButton and UIInput in email login * Replace Button to UIButton * fix context for onTitleClick in dropdown * rearrage class props in dropdown * TODO: change finding over DOM to using ref * Use UIButton in input * rearrage deps * Use UIButton in comment * test * Focus and Input buttons * custom focus style for inputs and buttons * the same focus style for comment input * align buttons by top line in input * Token dropdown & hover fix * disable hover when button disabled * make token dropdown markup in new style * Fix trailing comma * update prettier * move prettier config to json format because it is more hendy for settings (for example vscode can suggest rules) * prettier fixed trailing comman in ejs * Remove unnecessary conditions * Files was formatted by Prettier * fix cursor pointer on collapse button * Move components and right naming * ui-button -> button * ui-input -> input * input -> comment-form * Change cursor behavior on disabled state * Change button style * font-weight: normal by default * add small border-radius * Change another one button to component * Fix autofocus on username in email login form * use preact inbuild autoFocus * fix autofocus on back from token step * sleep for 0s enough to wait next render before focus * use more specific name for username input * fix line-height at auth line on mobile * fix className
102 lines
3.9 KiB
TypeScript
102 lines
3.9 KiB
TypeScript
/** @jsx createElement */
|
|
import { createElement, Component } from 'preact';
|
|
import '@github/markdown-toolbar-element';
|
|
import BoldIcon from './markdown-toolbar-icons/bold-icon';
|
|
import HeaderIcon from './markdown-toolbar-icons/header-icon';
|
|
import ItalicIcon from './markdown-toolbar-icons/italic-icon';
|
|
import QuoteIcon from './markdown-toolbar-icons/quote-icon';
|
|
import CodeIcon from './markdown-toolbar-icons/code-icon';
|
|
import LinkIcon from './markdown-toolbar-icons/link-icon';
|
|
import ImageIcon from './markdown-toolbar-icons/image-icon';
|
|
import UnorderedListIcon from './markdown-toolbar-icons/unordered-list-icon';
|
|
import OrderedListIcon from './markdown-toolbar-icons/ordered-list-icon';
|
|
|
|
interface Props {
|
|
textareaId: string;
|
|
uploadImages: (files: File[]) => Promise<void>;
|
|
allowUpload: boolean;
|
|
}
|
|
|
|
interface FileEventTarget extends EventTarget {
|
|
readonly files: FileList | null;
|
|
value: string | null;
|
|
}
|
|
|
|
interface FileInputEvent extends Event {
|
|
readonly currentTarget: FileEventTarget | null;
|
|
}
|
|
|
|
const boldLabel = 'Add bold text <cmd-b>';
|
|
const headerLabel = 'Add header text';
|
|
const italicLabel = 'Add italic text <cmd-i>';
|
|
const quoteLabel = 'Insert a quote';
|
|
const codeLabel = 'Insert a code';
|
|
const linkLabel = 'Add a link <cmd-k>';
|
|
const unorderedListLabel = 'Add a bulleted list';
|
|
const orderedListLabel = 'Add a numbered list';
|
|
const attachImageLabel = 'Attach the image, drag & drop or paste from clipboard';
|
|
|
|
export default class MarkdownToolbar extends Component<Props> {
|
|
constructor(props: Props) {
|
|
super(props);
|
|
this.uploadImages = this.uploadImages.bind(this);
|
|
}
|
|
async uploadImages(e: Event) {
|
|
const currentTarget = (e as FileInputEvent).currentTarget;
|
|
if (!(this.props.allowUpload && currentTarget && currentTarget.files && currentTarget.files.length !== 0)) return;
|
|
const files = Array.from(currentTarget.files);
|
|
await this.props.uploadImages(files);
|
|
currentTarget.value = null;
|
|
}
|
|
render(props: Props) {
|
|
return (
|
|
<markdown-toolbar className="comment-form__toolbar" for={props.textareaId}>
|
|
<div className="comment-form__toolbar-group">
|
|
<md-header className="comment-form__toolbar-item" title={headerLabel} aria-label={headerLabel}>
|
|
<HeaderIcon />
|
|
</md-header>
|
|
<md-bold className="comment-form__toolbar-item" title={boldLabel} aria-label={boldLabel}>
|
|
<BoldIcon />
|
|
</md-bold>
|
|
<md-italic className="comment-form__toolbar-item" title={italicLabel} aria-label={italicLabel}>
|
|
<ItalicIcon />
|
|
</md-italic>
|
|
</div>
|
|
<div className="comment-form__toolbar-group">
|
|
<md-quote className="comment-form__toolbar-item" title={quoteLabel} aria-label={quoteLabel}>
|
|
<QuoteIcon />
|
|
</md-quote>
|
|
<md-code className="comment-form__toolbar-item" title={codeLabel} aria-label={codeLabel}>
|
|
<CodeIcon />
|
|
</md-code>
|
|
<md-link className="comment-form__toolbar-item" title={linkLabel} aria-label={linkLabel}>
|
|
<LinkIcon />
|
|
</md-link>
|
|
{this.props.allowUpload ? (
|
|
<label className="comment-form__toolbar-item" title={attachImageLabel} aria-label={attachImageLabel}>
|
|
<input multiple className="comment-form__toolbar-file-input" type="file" onChange={this.uploadImages} />
|
|
<ImageIcon />
|
|
</label>
|
|
) : null}
|
|
</div>
|
|
<div className="comment-form__toolbar-group">
|
|
<md-unordered-list
|
|
className="comment-form__toolbar-item"
|
|
title={unorderedListLabel}
|
|
aria-label={unorderedListLabel}
|
|
>
|
|
<UnorderedListIcon />
|
|
</md-unordered-list>
|
|
<md-ordered-list
|
|
className="comment-form__toolbar-item"
|
|
title={orderedListLabel}
|
|
aria-label={orderedListLabel}
|
|
>
|
|
<OrderedListIcon />
|
|
</md-ordered-list>
|
|
</div>
|
|
</markdown-toolbar>
|
|
);
|
|
}
|
|
}
|