feat: create reusable Hero component#4215
feat: create reusable Hero component#4215DavideIadeluca wants to merge 11 commits intoflarum:2.xfrom
Hero component#4215Conversation
Hero componentHero component
Hero componentHero component
Hero componentHero component
|
FYI @imorland I just made a minor change I've had in mind. This PR is now good to go from my side |
imorland
left a comment
There was a problem hiding this comment.
Thanks for this — the design is solid and consistent with the existing Modal pattern. This PR has been open for a while but I checked: the Laravel upgrade, LESS 5.x upgrade, and webpack changes that landed since opening do not affect any of this, so it is not stale. A few things to address before merge.
Summary of required changes:
- Add
import './components/Hero'toforum.ts— explicit registration is the established convention and important for discoverability as a first-class extension point - Add JSDoc to
viewItems()— it is the primary structural extension point but has no documentation - Remove
?? undefinedfromstyle={}inHero.view()— redundant sincestyle()already returnsundefined, notnull - Fix
Hero.view()return type fromMithril.Vnode | nulltoJSX.Element— the base never returnsnull - Document the
viewItems()→bodyItems()rename as a breaking change in the PR description and upgrade guide - Add a note about
UserPage'sUserHero(viaUserCard) being intentionally excluded
Also worth considering:
- The
TagHero.className()approach of returning a space-separated string passed toclassList()works with clsx 1.x but would silently break on a future upgrade to clsx 2.x, which does not split strings. See inline comment. - Tests: the checklist item is unchecked. Snapshot/render tests confirming HTML structure is preserved would be valuable given the inheritance chain changes.
|
|
||
| export interface IWelcomeHeroAttrs {} | ||
| export interface IWelcomeHeroAttrs extends IHeroAttrs {} | ||
|
|
There was a problem hiding this comment.
Breaking change notice needed. The current published dist-typings/forum/components/WelcomeHero.d.ts exposes viewItems() as a public method. Any third-party extension using extend(WelcomeHero.prototype, 'viewItems', ...) will silently stop firing after this rename.
Same applies to TagHero — its dist-typings also expose viewItems().
For a 2.x pre-release this is acceptable, but please:
- Add an explicit note to the PR description calling this out
- Ensure it is captured in the upgrade guide
There was a problem hiding this comment.
viewItems() is moved to the abstract class and can technically continue to be consumed the same way. In the grand scheme of things, this is a minuscule, non breaking change. Created a documentation PR for this anyways at flarum/docs#500
|
|
||
| import type Mithril from 'mithril'; | ||
|
|
||
| export interface IMessagesPageHeroAttrs extends IHeroAttrs {} |
There was a problem hiding this comment.
Empty interface extending another is fine for extensibility, but a brief comment would help clarify the intent to readers:
// Intentionally empty — extend this interface to add attrs for extensions.
export interface IMessagesPageHeroAttrs extends IHeroAttrs {}There was a problem hiding this comment.
It's pretty common across the codebase to have empty interfaces like this — none of which have comments like this. If you would like we can follow up in a separate PR to streamline & create JSDoc's for interfaces
Fixes #4202
Changes proposed in this pull request:
Reviewers should focus on:
Screenshot
DOM / UI should stay the same
Necessity
Confirmed
composer test).Required changes: