Skip to content

Commit 28471af

Browse files
committed
chore: make WelcomeHero extensible
1 parent 9038ff6 commit 28471af

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

framework/core/js/src/forum/components/WelcomeHero.tsx

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import app from '../app';
22
import Component from '../../common/Component';
33
import Button from '../../common/components/Button';
44
import type Mithril from 'mithril';
5+
import ItemList from '../../common/utils/ItemList';
56

67
export interface IWelcomeHeroAttrs {}
78

@@ -24,25 +25,9 @@ export default class WelcomeHero extends Component<IWelcomeHeroAttrs> {
2425
view(vnode: Mithril.Vnode<IWelcomeHeroAttrs, this>) {
2526
if (this.isHidden()) return null;
2627

27-
const slideUp = () => {
28-
this.$().slideUp(this.hide.bind(this));
29-
};
30-
3128
return (
3229
<header className="Hero WelcomeHero">
33-
<div className="container">
34-
<Button
35-
icon="fas fa-times"
36-
onclick={slideUp}
37-
className="Hero-close Button Button--icon Button--link"
38-
aria-label={app.translator.trans('core.forum.welcome_hero.hide')}
39-
/>
40-
41-
<div className="containerNarrow">
42-
<h1 className="Hero-title">{app.forum.attribute('welcomeTitle')}</h1>
43-
<div className="Hero-subtitle">{m.trust(app.forum.attribute('welcomeMessage'))}</div>
44-
</div>
45-
</div>
30+
<div className="container">{this.viewItems().toArray()}</div>
4631
</header>
4732
);
4833
}
@@ -66,4 +51,37 @@ export default class WelcomeHero extends Component<IWelcomeHeroAttrs> {
6651

6752
return false;
6853
}
54+
55+
viewItems(): ItemList<Mithril.Children> {
56+
const items = new ItemList<Mithril.Children>();
57+
58+
const slideUp = () => {
59+
this.$().slideUp(this.hide.bind(this));
60+
};
61+
62+
items.add(
63+
'dismiss-button',
64+
<Button
65+
icon="fas fa-times"
66+
onclick={slideUp}
67+
className="Hero-close Button Button--icon Button--link"
68+
aria-label={app.translator.trans('core.forum.welcome_hero.hide')}
69+
/>,
70+
100
71+
);
72+
73+
items.add('content', <div className="containerNarrow">{this.contentItems().toArray()}</div>, 80);
74+
75+
return items;
76+
}
77+
78+
contentItems(): ItemList<Mithril.Children> {
79+
const items = new ItemList<Mithril.Children>();
80+
81+
items.add('title', <h1 className="Hero-title">{app.forum.attribute('welcomeTitle')}</h1>, 100);
82+
83+
items.add('subtitle', <div className="Hero-subtitle">{m.trust(app.forum.attribute('welcomeMessage'))}</div>);
84+
85+
return items;
86+
}
6987
}

0 commit comments

Comments
 (0)