-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Page] Add ReactNode as an accepted primaryAction prop value #3002
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,7 +43,7 @@ export interface HeaderProps extends TitleProps { | |||||||||||||
| /** Adds a border to the bottom of the page header (stand-alone app use only) */ | ||||||||||||||
| separator?: boolean; | ||||||||||||||
| /** Primary page-level action */ | ||||||||||||||
| primaryAction?: PrimaryAction; | ||||||||||||||
| primaryAction?: PrimaryAction | React.ReactNode; | ||||||||||||||
| /** Page-level pagination (stand-alone app use only) */ | ||||||||||||||
| pagination?: PaginationDescriptor; | ||||||||||||||
| /** Collection of breadcrumbs */ | ||||||||||||||
|
|
@@ -56,6 +56,12 @@ export interface HeaderProps extends TitleProps { | |||||||||||||
| additionalNavigation?: React.ReactNode; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function isPrimaryAction( | ||||||||||||||
| x: PrimaryAction | React.ReactNode, | ||||||||||||||
| ): x is PrimaryAction { | ||||||||||||||
| return !React.isValidElement(x) && x !== undefined; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export function Header({ | ||||||||||||||
| title, | ||||||||||||||
| subtitle, | ||||||||||||||
|
|
@@ -116,28 +122,8 @@ export function Header({ | |||||||||||||
| /> | ||||||||||||||
| ); | ||||||||||||||
|
|
||||||||||||||
| const primary = | ||||||||||||||
| primaryAction && | ||||||||||||||
| (primaryAction.primary === undefined ? true : primaryAction.primary); | ||||||||||||||
|
|
||||||||||||||
| const primaryActionMarkup = primaryAction ? ( | ||||||||||||||
| <ConditionalWrapper | ||||||||||||||
| condition={newDesignLanguage === false} | ||||||||||||||
| wrapper={(children) => ( | ||||||||||||||
| <div className={styles.PrimaryActionWrapper}>{children}</div> | ||||||||||||||
| )} | ||||||||||||||
| > | ||||||||||||||
| {buttonsFrom( | ||||||||||||||
| shouldShowIconOnly( | ||||||||||||||
| newDesignLanguage, | ||||||||||||||
| isNavigationCollapsed, | ||||||||||||||
| primaryAction, | ||||||||||||||
| ), | ||||||||||||||
| { | ||||||||||||||
| primary, | ||||||||||||||
| }, | ||||||||||||||
| )} | ||||||||||||||
| </ConditionalWrapper> | ||||||||||||||
| <PrimaryActionMarkup primaryAction={primaryAction} /> | ||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually create an
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine. |
||||||||||||||
| ) : null; | ||||||||||||||
|
|
||||||||||||||
| const actionMenuMarkup = | ||||||||||||||
|
|
@@ -228,6 +214,42 @@ export function Header({ | |||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function PrimaryActionMarkup({ | ||||||||||||||
| primaryAction, | ||||||||||||||
| }: { | ||||||||||||||
| primaryAction: PrimaryAction | React.ReactNode; | ||||||||||||||
| }) { | ||||||||||||||
| const {isNavigationCollapsed} = useMediaQuery(); | ||||||||||||||
| const {newDesignLanguage} = useFeatures(); | ||||||||||||||
|
Comment on lines
+222
to
+223
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious if anyone thinks we should pass these in as props?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I was curious about this too.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd leave it. It will be easier to clean-up and really doesn't become part of the API 🤷 |
||||||||||||||
| let content = primaryAction; | ||||||||||||||
| if (isPrimaryAction(primaryAction)) { | ||||||||||||||
|
Comment on lines
+224
to
+225
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: With an early return we don't have to wrap the entire component 😄
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I never want to return |
||||||||||||||
| const primary = | ||||||||||||||
| primaryAction.primary === undefined ? true : primaryAction.primary; | ||||||||||||||
|
|
||||||||||||||
| content = buttonsFrom( | ||||||||||||||
| shouldShowIconOnly( | ||||||||||||||
| newDesignLanguage, | ||||||||||||||
| isNavigationCollapsed, | ||||||||||||||
| primaryAction, | ||||||||||||||
| ), | ||||||||||||||
| { | ||||||||||||||
| primary, | ||||||||||||||
| }, | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| return ( | ||||||||||||||
| <ConditionalWrapper | ||||||||||||||
| condition={newDesignLanguage === false} | ||||||||||||||
| wrapper={(children) => ( | ||||||||||||||
| <div className={styles.PrimaryActionWrapper}>{children}</div> | ||||||||||||||
| )} | ||||||||||||||
| > | ||||||||||||||
| {content} | ||||||||||||||
| </ConditionalWrapper> | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| function shouldShowIconOnly( | ||||||||||||||
| newDesignLanguage: boolean, | ||||||||||||||
| isMobile: boolean, | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a little odd to me - this condition is more "this is not a react node" rather than "this is a primary action", which is alright for now but might get confusing if we want to pass more sorts of things into this. Is there a way to check for action's shape rather than not ReactNode's shape?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that it feels a little odd, the reason I did it this way is there are no required properties on
primaryAction