Skip to content

feat(tags): improve extensibility of TagHero #4198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 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,8 @@ 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';
import Mithril from 'mithril';

export default class TagHero extends Component {
view() {
Expand All @@ -13,15 +15,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<Mithril.Children>}
*/
viewItems() {
const items = new ItemList();

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

return items;
}

/**
* @returns {ItemList<Mithril.Children>}
*/
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;
}
}
Loading