-
Notifications
You must be signed in to change notification settings - Fork 12
feat(PageLayout): support function type for topAlert prop #491
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
feat(PageLayout): support function type for topAlert prop #491
Conversation
|
Preview is ready. |
|
Playwright Test Component is ready. |
| {typeof topAlert === 'function' ? ( | ||
| topAlert() | ||
| ) : ( | ||
| <TopAlert className={b('top-alert')} alert={topAlert} /> |
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.
The base TopAlert component uses the useTopAlertHeight hook to send up information about its height, but this does not happen for the function (the --gn-top-alert-height variable remains equal to 0). Consistency of logic is violated. What can we do about it?
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.
Absolutely. I'll figure something out. Thank you for noticing.
| await expectScreenshot(); | ||
| }); | ||
|
|
||
| test('render story: <CustomTopAlert>', async ({mount, expectScreenshot}) => { |
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.
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.
Sure. I'll rename the story.
src/components/types.ts
Outdated
| onCloseTopAlert?: () => void; | ||
| } | ||
|
|
||
| export interface TopAlertProps extends TopAlertBaseProps { |
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.
The updated TopAlertProps interface still requires message, yet the component explicitly supports a render function that can render arbitrary content. Making message mandatory in the type system forces callers who only want a custom renderer to pass meaningless placeholder text to satisfy the compiler. This should be modeled as a union or by making message optional when render is provided.
| }, [opened, updateTopSize]); | ||
|
|
||
| if (!alert || !alert.message) { | ||
| return null; |
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.
It seems better to make message optional if the render is set.


No description provided.