Skip to content

Commit

Permalink
chore: extensible TagHero (#4041)
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland authored Sep 29, 2024
1 parent e9c8890 commit 54fbcde
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions extensions/tags/js/src/forum/components/TagHero.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Component from 'flarum/common/Component';
import textContrastClass from 'flarum/common/helpers/textContrastClass';
import tagIcon from '../../common/helpers/tagIcon';
import classList from 'flarum/common/utils/classList';
import ItemList from 'flarum/common/utils/ItemList';

export default class TagHero extends Component {
view() {
Expand All @@ -13,15 +14,39 @@ export default class TagHero extends Component {
className={classList('Hero', 'TagHero', { 'TagHero--colored': color, [textContrastClass(color)]: color })}
style={color ? { '--hero-bg': color } : undefined}
>
<div className="container">
<div className="containerNarrow">
<h1 className="Hero-title">
{tag.icon() && tagIcon(tag, {}, { useColor: false })} {tag.name()}
</h1>
<div className="Hero-subtitle">{tag.description()}</div>
</div>
</div>
<div className="container">{this.viewItems().toArray()}</div>
</header>
);
}

/**
* @returns {ItemList}
*/
viewItems() {
const items = new ItemList();

items.add('content', <div className="containerNarrow">{this.contentItems().toArray()}</div>, 80);

return items;
}

/**
* @returns {ItemList}
*/
contentItems() {
const items = new ItemList();
const tag = this.attrs.model;

items.add(
'tag-title',
<h1 className="Hero-title">
{tag.icon() && tagIcon(tag, {}, { useColor: false })} {tag.name()}
</h1>,
100
);

items.add('tag-subtitle', <div className="Hero-subtitle">{tag.description()}</div>, 90);

return items;
}
}

0 comments on commit 54fbcde

Please sign in to comment.