Skip to content

Commit

Permalink
umputun#299 add bold toolbar for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Apr 12, 2019
1 parent e182d34 commit 7f7b3a2
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 32 deletions.
6 changes: 6 additions & 0 deletions web/app/@types/markdown-toolbar-element/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare namespace JSX {
interface IntrinsicElements {
'markdown-toolbar': any;
'md-bold': any;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
markdown-toolbar {
display: block;
font-size: 16px;
line-height: 1.2;
border: 1px dashed;
border-radius: 2px;
}

md-bold {
display: block;
}
12 changes: 10 additions & 2 deletions web/app/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/* styles imports */
import '@app/components/raw-content';
import '@github/markdown-toolbar-element';
import './styles';

import { h, Component, RenderableProps } from 'preact';
Expand All @@ -19,6 +20,8 @@ const RSS_THREAD_URL = `${BASE_URL}${API_BASE}/rss/post?site=${siteId}&url=${url
const RSS_SITE_URL = `${BASE_URL}${API_BASE}/rss/site?site=${siteId}`;
const RSS_REPLIES_URL = `${BASE_URL}${API_BASE}/rss/reply?site=${siteId}&user=`;

let textareaId = 0;

interface Props {
/** user id for rss link generation */
userId?: User['id'];
Expand Down Expand Up @@ -52,10 +55,11 @@ const Labels = {

export class Input extends Component<Props, State> {
textAreaRef?: TextareaAutosize;

textareaId: string;
constructor(props: Props) {
super(props);

textareaId = textareaId + 1;
this.textareaId = `textarea_${textareaId}`;
this.state = {
preview: null,
isErrorShown: false,
Expand Down Expand Up @@ -166,7 +170,11 @@ export class Input extends Component<Props, State> {
aria-label="New comment"
>
<div className="input__field-wrapper">
<markdown-toolbar for={this.textareaId}>
<md-bold>bold</md-bold>
</markdown-toolbar>
<TextareaAutosize
id={this.textareaId}
ref={ref => (this.textAreaRef = ref)}
className="input__field"
placeholder="Your comment here"
Expand Down
1 change: 1 addition & 0 deletions web/app/components/input/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require('./__rss/input__rss.scss');
require('./__rss-link/input__rss-link.scss');
require('./__markdown/input__markdown.scss');
require('./__markdown-link/input__markdown-link.scss');
require('./__markdown-toolbar/input__markdown-toolbar.scss');

require('./_theme/_dark/input_theme_dark.scss');
require('./_theme/_light/input_theme_light.scss');
1 change: 1 addition & 0 deletions web/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports = {
'\\.scss$': '<rootDir>/app/testUtils/mockStyles.js',
'@app/(.*)': '<rootDir>/app/$1',
},
setupFilesAfterEnv: ['<rootDir>/setup-jest-env.js'],
};
59 changes: 29 additions & 30 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@
"whatwg-fetch": "^3.0.0"
},
"dependencies": {
"@github/markdown-toolbar-element": "^0.2.0",
"bem-react-helper": "^1.1.2",
"core-js": "^3.0.1",
"document-register-element": "^1.13.1",
"focus-visible": "^4.1.5",
"preact": "^8.4.2",
"preact-redux": "^2.0.3",
Expand Down
1 change: 1 addition & 0 deletions web/setup-jest-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('document-register-element/pony')(window);

0 comments on commit 7f7b3a2

Please sign in to comment.