From 3e645db3245cac5ce015c23a8564898a519360c2 Mon Sep 17 00:00:00 2001 From: HarlanLuo Date: Thu, 27 Dec 2018 21:36:20 +0800 Subject: [PATCH 1/7] add feature: colored tags --- browser/components/ColorPicker.js | 63 +++++++++++++ browser/components/ColorPicker.styl | 25 ++++++ browser/components/NoteItem.js | 14 +-- browser/components/TagListItem.js | 8 +- browser/main/Detail/MarkdownNoteDetail.js | 1 + browser/main/Detail/SnippetNoteDetail.js | 1 + browser/main/Detail/TagSelect.js | 6 +- browser/main/NoteList/index.js | 1 + browser/main/SideNav/index.js | 88 +++++++++++++++++++ browser/main/lib/ConfigManager.js | 3 +- package.json | 1 + tests/components/TagListItem.snapshot.test.js | 2 +- .../TagListItem.snapshot.test.js.snap | 5 ++ 13 files changed, 205 insertions(+), 13 deletions(-) create mode 100644 browser/components/ColorPicker.js create mode 100644 browser/components/ColorPicker.styl diff --git a/browser/components/ColorPicker.js b/browser/components/ColorPicker.js new file mode 100644 index 00000000..f68aa8ec --- /dev/null +++ b/browser/components/ColorPicker.js @@ -0,0 +1,63 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { SketchPicker } from 'react-color' +import CSSModules from 'browser/lib/CSSModules' +import styles from './ColorPicker.styl' + +const componentHeight = 333 + +class ColorPicker extends React.Component { + constructor (props) { + super(props) + + this.state = { + color: this.props.color || '#888888' + } + + this.onColorChange = this.onColorChange.bind(this) + this.handleConfirm = this.handleConfirm.bind(this) + } + + onColorChange (color) { + this.setState({ + color + }) + } + + handleConfirm () { + this.props.onConfirm(this.state.color) + } + + render () { + const { onReset, onCancel, targetRect } = this.props + const { color } = this.state + + const clientHeight = document.body.clientHeight + const alignX = targetRect.right + 4 + let alignY = targetRect.top + if (targetRect.top + componentHeight > clientHeight) { + alignY = targetRect.bottom - componentHeight + } + + return ( +
+ +
+ + + +
+
+ ) + } +} + +ColorPicker.propTypes = { + color: PropTypes.string, + targetRect: PropTypes.object, + onConfirm: PropTypes.func.isRequired, + onCancel: PropTypes.func.isRequired, + onReset: PropTypes.func.isRequired +} + +export default CSSModules(ColorPicker, styles) diff --git a/browser/components/ColorPicker.styl b/browser/components/ColorPicker.styl new file mode 100644 index 00000000..4c5a269c --- /dev/null +++ b/browser/components/ColorPicker.styl @@ -0,0 +1,25 @@ +.colorPicker + position fixed + z-index 10000 + display flex + flex-direction column +.footer + display flex + justify-content center + align-items center + padding 5px + & > button + button + margin-left 10px + +.btn-cancel, +.btn-confirm, +.btn-reset + height 1.6em + border 1px solid #888888 + background-color #fff + font-size 16px + border-radius 4px +.btn-confirm + background-color $ui-button-default--active-backgroundColor + + diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index 2fc70a39..cd97527c 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -15,8 +15,8 @@ import i18n from 'browser/lib/i18n' * @param {string} tagName * @return {React.Component} */ -const TagElement = ({ tagName }) => ( - +const TagElement = ({ tagName, color }) => ( + #{tagName} ) @@ -27,7 +27,7 @@ const TagElement = ({ tagName }) => ( * @param {boolean} showTagsAlphabetically * @return {React.Component} */ -const TagElementList = (tags, showTagsAlphabetically) => { +const TagElementList = (tags, showTagsAlphabetically, tagConfig) => { if (!isArray(tags)) { return [] } @@ -35,7 +35,7 @@ const TagElementList = (tags, showTagsAlphabetically) => { if (showTagsAlphabetically) { return _.sortBy(tags).map(tag => TagElement({ tagName: tag })) } else { - return tags.map(tag => TagElement({ tagName: tag })) + return tags.map(tag => TagElement({ tagName: tag, color: tagConfig[tag] })) } } @@ -59,7 +59,8 @@ const NoteItem = ({ storageName, folderName, viewType, - showTagsAlphabetically + showTagsAlphabetically, + tagConfig }) => (
{note.tags.length > 0 - ? TagElementList(note.tags, showTagsAlphabetically) + ? TagElementList(note.tags, showTagsAlphabetically, tagConfig) : ( +const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, handleContextMenu, isActive, isRelated, count, color}) => (
handleContextMenu(e, name)}> {isRelated ?
diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index d8b5798d..96ea0941 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -788,6 +788,7 @@ class SnippetNoteDetail extends React.Component { showTagsAlphabetically={config.ui.showTagsAlphabetically} data={data} onChange={(e) => this.handleChange(e)} + tagConfig={config.tag} />
diff --git a/browser/main/Detail/TagSelect.js b/browser/main/Detail/TagSelect.js index 6ced475b..d4411af9 100644 --- a/browser/main/Detail/TagSelect.js +++ b/browser/main/Detail/TagSelect.js @@ -179,13 +179,14 @@ class TagSelect extends React.Component { } render () { - const { value, className, showTagsAlphabetically } = this.props + const { value, className, showTagsAlphabetically, tagConfig } = this.props const tagList = _.isArray(value) ? (showTagsAlphabetically ? _.sortBy(value) : value).map((tag) => { return ( this.handleTagLabelClick(tag)}>#{tag}
{this.SideNavComponent(isFolded, storageList)} + {colorPicker} ) } diff --git a/browser/main/lib/ConfigManager.js b/browser/main/lib/ConfigManager.js index 81165777..c70978f7 100644 --- a/browser/main/lib/ConfigManager.js +++ b/browser/main/lib/ConfigManager.js @@ -86,7 +86,8 @@ export const DEFAULT_CONFIG = { token: '', username: '', password: '' - } + }, + tag: {} } function validate (config) { diff --git a/package.json b/package.json index f12360a0..9b0c1d31 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "react": "^15.5.4", "react-autosuggest": "^9.4.0", "react-codemirror": "^0.3.0", + "react-color": "^2.17.0", "react-debounce-render": "^4.0.1", "react-dom": "^15.0.2", "react-image-carousel": "^2.0.18", diff --git a/tests/components/TagListItem.snapshot.test.js b/tests/components/TagListItem.snapshot.test.js index 8bea2ccb..637844e6 100644 --- a/tests/components/TagListItem.snapshot.test.js +++ b/tests/components/TagListItem.snapshot.test.js @@ -3,7 +3,7 @@ import renderer from 'react-test-renderer' import TagListItem from 'browser/components/TagListItem' it('TagListItem renders correctly', () => { - const tagListItem = renderer.create() + const tagListItem = renderer.create() expect(tagListItem.toJSON()).toMatchSnapshot() }) diff --git a/tests/components/__snapshots__/TagListItem.snapshot.test.js.snap b/tests/components/__snapshots__/TagListItem.snapshot.test.js.snap index ad883222..d6939ec2 100644 --- a/tests/components/__snapshots__/TagListItem.snapshot.test.js.snap +++ b/tests/components/__snapshots__/TagListItem.snapshot.test.js.snap @@ -14,6 +14,11 @@ exports[`TagListItem renders correctly 1`] = ` > # Test Date: Fri, 28 Dec 2018 11:13:05 +0800 Subject: [PATCH 2/7] rename config.tag to config.coloredTags --- browser/components/ColorPicker.styl | 6 ++-- browser/components/NoteItem.js | 13 +++++---- browser/main/Detail/MarkdownNoteDetail.js | 2 +- browser/main/Detail/SnippetNoteDetail.js | 2 +- browser/main/Detail/TagSelect.js | 6 ++-- browser/main/NoteList/index.js | 2 +- browser/main/SideNav/index.js | 34 ++++++++++++----------- browser/main/lib/ConfigManager.js | 2 +- package.json | 3 +- 9 files changed, 37 insertions(+), 33 deletions(-) diff --git a/browser/components/ColorPicker.styl b/browser/components/ColorPicker.styl index 4c5a269c..927a0da2 100644 --- a/browser/components/ColorPicker.styl +++ b/browser/components/ColorPicker.styl @@ -17,9 +17,9 @@ height 1.6em border 1px solid #888888 background-color #fff - font-size 16px - border-radius 4px + font-size 15px + border-radius 2px .btn-confirm - background-color $ui-button-default--active-backgroundColor + background-color #1EC38B diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index cd97527c..70708223 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -13,6 +13,7 @@ import i18n from 'browser/lib/i18n' /** * @description Tag element component. * @param {string} tagName + * @param {string} color * @return {React.Component} */ const TagElement = ({ tagName, color }) => ( @@ -25,9 +26,10 @@ const TagElement = ({ tagName, color }) => ( * @description Tag element list component. * @param {Array|null} tags * @param {boolean} showTagsAlphabetically + * @param {Object} coloredTags * @return {React.Component} */ -const TagElementList = (tags, showTagsAlphabetically, tagConfig) => { +const TagElementList = (tags, showTagsAlphabetically, coloredTags) => { if (!isArray(tags)) { return [] } @@ -35,7 +37,7 @@ const TagElementList = (tags, showTagsAlphabetically, tagConfig) => { if (showTagsAlphabetically) { return _.sortBy(tags).map(tag => TagElement({ tagName: tag })) } else { - return tags.map(tag => TagElement({ tagName: tag, color: tagConfig[tag] })) + return tags.map(tag => TagElement({ tagName: tag, color: coloredTags[tag] })) } } @@ -46,6 +48,7 @@ const TagElementList = (tags, showTagsAlphabetically, tagConfig) => { * @param {Function} handleNoteClick * @param {Function} handleNoteContextMenu * @param {Function} handleDragStart + * @param {Object} coloredTags * @param {string} dateDisplay */ const NoteItem = ({ @@ -60,7 +63,7 @@ const NoteItem = ({ folderName, viewType, showTagsAlphabetically, - tagConfig + coloredTags }) => (
{note.tags.length > 0 - ? TagElementList(note.tags, showTagsAlphabetically, tagConfig) + ? TagElementList(note.tags, showTagsAlphabetically, coloredTags) : this.handleClearTodo(e)} percentageOfTodo={getTodoPercentageOfCompleted(note.content)} />
diff --git a/browser/main/Detail/SnippetNoteDetail.js b/browser/main/Detail/SnippetNoteDetail.js index 96ea0941..237efb3c 100644 --- a/browser/main/Detail/SnippetNoteDetail.js +++ b/browser/main/Detail/SnippetNoteDetail.js @@ -788,7 +788,7 @@ class SnippetNoteDetail extends React.Component { showTagsAlphabetically={config.ui.showTagsAlphabetically} data={data} onChange={(e) => this.handleChange(e)} - tagConfig={config.tag} + coloredTags={config.coloredTags} />
diff --git a/browser/main/Detail/TagSelect.js b/browser/main/Detail/TagSelect.js index d4411af9..caf0cf39 100644 --- a/browser/main/Detail/TagSelect.js +++ b/browser/main/Detail/TagSelect.js @@ -179,14 +179,14 @@ class TagSelect extends React.Component { } render () { - const { value, className, showTagsAlphabetically, tagConfig } = this.props + const { value, className, showTagsAlphabetically, coloredTags } = this.props const tagList = _.isArray(value) ? (showTagsAlphabetically ? _.sortBy(value) : value).map((tag) => { return ( this.handleTagLabelClick(tag)}>#{tag} diff --git a/browser/components/ColorPicker.styl b/browser/components/ColorPicker.styl index 927a0da2..6e4aceb8 100644 --- a/browser/components/ColorPicker.styl +++ b/browser/components/ColorPicker.styl @@ -1,25 +1,37 @@ .colorPicker position fixed - z-index 10000 + z-index 2 display flex flex-direction column + +.cover + position fixed + top 0 + right 0 + bottom 0 + left 0 + .footer display flex justify-content center + z-index 2 align-items center - padding 5px & > button + button margin-left 10px .btn-cancel, .btn-confirm, .btn-reset - height 1.6em - border 1px solid #888888 - background-color #fff - font-size 15px + vertical-align middle + height 25px + margin-top 2.5px + colorDefaultButton() border-radius 2px + border $ui-border + padding 0 5px .btn-confirm background-color #1EC38B + &:hover + background-color darken(#1EC38B, 25%) diff --git a/browser/components/TagListItem.js b/browser/components/TagListItem.js index 64a74d63..9aa00a1d 100644 --- a/browser/components/TagListItem.js +++ b/browser/components/TagListItem.js @@ -10,8 +10,8 @@ import CSSModules from 'browser/lib/CSSModules' * @param {string} name * @param {Function} handleClickTagListItem * @param {Function} handleClickNarrowToTag -* @param {bool} isActive -* @param {bool} isRelated +* @param {boolean} isActive +* @param {boolean} isRelated * @param {string} bgColor tab backgroundColor */ @@ -24,7 +24,8 @@ const TagListItem = ({name, handleClickTagListItem, handleClickNarrowToTag, hand :
} ) diff --git a/resources/icon/icon-x-light.svg b/resources/icon/icon-x-light.svg new file mode 100644 index 00000000..39828f0b --- /dev/null +++ b/resources/icon/icon-x-light.svg @@ -0,0 +1,17 @@ + + + + x + Created with Sketch. + + + + + + + + + + + + \ No newline at end of file From a9feddf6f69fdde9b0f5eb450678b5e4a017354c Mon Sep 17 00:00:00 2001 From: HarlanLuo Date: Sun, 30 Dec 2018 19:23:43 +0800 Subject: [PATCH 6/7] fix bug missing param colored tags in sorted list --- browser/components/NoteItem.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index 5e8d009f..625bb38d 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -43,7 +43,7 @@ const TagElementList = (tags, showTagsAlphabetically, coloredTags) => { } if (showTagsAlphabetically) { - return _.sortBy(tags).map(tag => TagElement({ tagName: tag })) + return _.sortBy(tags).map(tag => TagElement({ tagName: tag, color: coloredTags[tag] })) } else { return tags.map(tag => TagElement({ tagName: tag, color: coloredTags[tag] })) } From b4e4d7055fbefe44c0321220144013fdd6d54419 Mon Sep 17 00:00:00 2001 From: HarlanLuo Date: Sun, 30 Dec 2018 20:49:26 +0800 Subject: [PATCH 7/7] improve style of color-picker --- browser/components/ColorPicker.styl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/browser/components/ColorPicker.styl b/browser/components/ColorPicker.styl index 6e4aceb8..fbc1212a 100644 --- a/browser/components/ColorPicker.styl +++ b/browser/components/ColorPicker.styl @@ -25,10 +25,12 @@ vertical-align middle height 25px margin-top 2.5px - colorDefaultButton() border-radius 2px - border $ui-border + border none padding 0 5px + background-color $default-button-background + &:hover + background-color $default-button-background--hover .btn-confirm background-color #1EC38B &:hover