1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

invert text color in colored tags

This commit is contained in:
HarlanLuo
2018-12-28 22:12:51 +08:00
parent 699006a3e9
commit 0cf6487cad
3 changed files with 24 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
import PropTypes from 'prop-types'
import React from 'react'
import invertColor from 'invert-color'
import CSSModules from 'browser/lib/CSSModules'
import styles from './TagSelect.styl'
import _ from 'lodash'
@@ -183,12 +184,19 @@ class TagSelect extends React.Component {
const tagList = _.isArray(value)
? (showTagsAlphabetically ? _.sortBy(value) : value).map((tag) => {
const wrapperStyle = {}
const textStyle = {}
const color = coloredTags[tag]
if (color) {
wrapperStyle.backgroundColor = color
textStyle.color = invertColor(color, { black: '#222', white: '#f1f1f1' })
}
return (
<span styleName='tag'
key={tag}
style={{backgroundColor: coloredTags[tag]}}
style={wrapperStyle}
>
<span styleName='tag-label' onClick={(e) => this.handleTagLabelClick(tag)}>#{tag}</span>
<span styleName='tag-label' style={textStyle} onClick={(e) => this.handleTagLabelClick(tag)}>#{tag}</span>
<button styleName='tag-removeButton'
onClick={(e) => this.handleTagRemoveButtonClick(tag)}
>