mirror of
https://github.com/flarum/core.git
synced 2025-08-26 01:34:16 +02:00
refactor: use isDark rather than getContrast
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import extract from 'flarum/common/utils/extract';
|
||||
import getContrast from 'flarum/common/utils/getContrast';
|
||||
import isDark from 'flarum/common/utils/isDark';
|
||||
import Link from 'flarum/common/components/Link';
|
||||
import tagIcon from './tagIcon';
|
||||
|
||||
@@ -12,16 +12,15 @@ export default function tagLabel(tag, attrs = {}) {
|
||||
|
||||
if (tag) {
|
||||
const color = tag.color();
|
||||
const contrast = getContrast(color);
|
||||
if (color) {
|
||||
attrs.style['--tag-bg'] = color;
|
||||
attrs.className += ' colored';
|
||||
|
||||
if (contrast >= 128) {
|
||||
attrs.className += ' tag-light';
|
||||
if (isDark(color)) {
|
||||
attrs.className += ' tag-dark';
|
||||
}
|
||||
else {
|
||||
attrs.className += ' tag-dark';
|
||||
attrs.className += ' tag-light';
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ import Link from 'flarum/common/components/Link';
|
||||
import LoadingIndicator from 'flarum/common/components/LoadingIndicator';
|
||||
import listItems from 'flarum/common/helpers/listItems';
|
||||
import humanTime from 'flarum/common/helpers/humanTime';
|
||||
import getContrast from 'flarum/common/utils/getContrast';
|
||||
import isDark from 'flarum/common/utils/isDark';
|
||||
|
||||
import tagIcon from '../../common/helpers/tagIcon';
|
||||
import tagLabel from '../../common/helpers/tagLabel';
|
||||
@@ -59,7 +59,7 @@ export default class TagsPage extends Page {
|
||||
const children = sortTags(tag.children() || []);
|
||||
|
||||
return (
|
||||
<li className={'TagTile ' + (tag.color() ? 'colored ' : '') + (getContrast(tag.color()) >= 128 ? 'tag-light' : 'tag-dark')} style={{ '--tag-bg': tag.color() }}>
|
||||
<li className={'TagTile ' + (tag.color() ? 'colored ' : '') + (isDark(tag.color()) ? 'tag-dark' : 'tag-light')} style={{ '--tag-bg': tag.color() }}>
|
||||
<Link className="TagTile-info" href={app.route.tag(tag)}>
|
||||
{tag.icon() && tagIcon(tag, {}, { useColor: false })}
|
||||
<h3 className="TagTile-name">{tag.name()}</h3>
|
||||
|
Reference in New Issue
Block a user