forked from deephaven/deephaven-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: contextual_help uses heading, content, footer props (deephaven#945)
- Fixes deephaven#926 - Auto-wraps `heading`, `content`, and `footer` props in their respective component BREAKING CHANGE: `ui.contextual_help`'s signature replaces the `*children` prop with `heading`, `content`, and `footer` props, in that order. In parity with [React Spectrum docs](https://react-spectrum.adobe.com/react-spectrum/ContextualHelp.html#:~:text=Each%20of%20these%20components%20are%20required%20in%20a%20Spectrum%20compliant%20ContextualHelp%20except%20for%20Footer%20since%20including%20a%20link%20is%20optional.), the `heading` and `content` props are required and `footer` is optional. Here are some examples of usages and how they might change: ```python # This is still valid old = ui.contextual_help( ui.heading("My Heading"), ui.content("My content"), ui.footer("My footer") ) ``` ```python # This is invalid old = ui.contextual_help(ui.content("My content")) # You must explicitly set heading to None new = ui.contextual_help(None, ui.content("My content")) ```
- Loading branch information
1 parent
7f03d95
commit d7bcc22
Showing
5 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
ContextualHelp as DHCContextualHelp, | ||
ContextualHelpProps as DHCContextualHelpProps, | ||
Heading, | ||
Content, | ||
Footer, | ||
} from '@deephaven/components'; | ||
import { isElementOfType } from '@deephaven/react-hooks'; | ||
import { ReactNode } from 'react'; | ||
|
||
export type SerializedContextualHelpProps = Omit< | ||
DHCContextualHelpProps, | ||
'children' | ||
> & { | ||
heading: ReactNode; | ||
content: ReactNode; | ||
footer?: ReactNode; | ||
}; | ||
|
||
export function ContextualHelp( | ||
props: SerializedContextualHelpProps | ||
): JSX.Element { | ||
const { heading, content, footer, ...otherProps } = props; | ||
|
||
return ( | ||
/* eslint-disable-next-line react/jsx-props-no-spreading */ | ||
<DHCContextualHelp {...otherProps}> | ||
{heading != null && | ||
(isElementOfType(heading, Heading) ? ( | ||
heading | ||
) : ( | ||
<Heading>{heading}</Heading> | ||
))} | ||
{content != null && | ||
(isElementOfType(content, Content) ? ( | ||
content | ||
) : ( | ||
<Content>{content}</Content> | ||
))} | ||
{footer != null && | ||
(isElementOfType(footer, Footer) ? footer : <Footer>{footer}</Footer>)} | ||
</DHCContextualHelp> | ||
); | ||
} | ||
|
||
export default ContextualHelp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters