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