Skip to content
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

Added a new optional callback when the panel has completed transitioning and is fully opened #1368

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export class AppbarButtons {
panel: new PanelApi(panel, buttonId, this.mapId),
button,
groupName: group,
handlePanelOpened: panelProps.handlePanelOpened,
};

// add the new button panel to the correct group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,12 @@ export function Appbar({ activeTrap, activeTrapSet }: AppbarProps): JSX.Element
{Object.keys(buttonPanels).map((buttonPanelsKey) => {
const buttonPanel = buttonPanels[buttonPanelsKey];
return buttonPanel?.panel ? (
<Panel key={buttonPanel.panel.panelId} panel={buttonPanel.panel} button={buttonPanel.button} />
<Panel
key={buttonPanel.panel.panelId}
panel={buttonPanel.panel}
button={buttonPanel.button}
handlePanelOpened={buttonPanel.handlePanelOpened}
/>
) : null;
})}
</Fragment>
Expand Down
4 changes: 4 additions & 0 deletions packages/geoview-core/src/ui/panel/panel-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export type TypePanelProps = {
content?: ReactNode;
/** Custom panel styles */
panelStyles?: PanelStyles;
/** Handler callback triggered when a panel is fully opened */
handlePanelOpened?: () => void;
};

export interface PanelStyles {
Expand Down Expand Up @@ -103,6 +105,8 @@ export type TypeButtonPanel = {
button: TypeIconButtonProps;
/** Group name. */
groupName?: string;
/** Handler callback triggered when a panel is fully opened */
handlePanelOpened?: () => void;
};

/** ******************************************************************************************************************************
Expand Down
25 changes: 23 additions & 2 deletions packages/geoview-core/src/ui/panel/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import makeStyles from '@mui/styles/makeStyles';
import Card from '@mui/material/Card';
import CardHeader from '@mui/material/CardHeader';
import CardContent from '@mui/material/CardContent';
import { useTheme } from '@mui/styles';

import { Cast } from '@/core/types/global-types';
import { HtmlToReact } from '@/core/containers/html-to-react';
Expand All @@ -37,6 +38,9 @@ type TypePanelAppProps = {
panel: PanelApi;
// panelOpen: boolean;
button: TypeIconButtonProps;

// Callback when the panel has completed opened (and transitioned in)
handlePanelOpened?: () => void;
};

const useStyles = makeStyles((theme) => ({
Expand Down Expand Up @@ -102,16 +106,19 @@ const useStyles = makeStyles((theme) => ({
* @returns {JSX.Element} the created Panel element
*/
export function Panel(props: TypePanelAppProps): JSX.Element {
const { panel, button } = props;
const { panel, button, handlePanelOpened } = props;
const { panelStyles } = panel;
// set the active trap value for FocusTrap
const [panelStatus, setPanelStatus] = useState(false);

// Get the theme
const theme = useTheme();

const panelWidth = panel?.width ?? 350;
const panelContainerStyles = {
...(panelStyles?.panelContainer && { ...panelStyles.panelContainer }),
width: panelStatus ? panelWidth : 0,
transition: 'width 300ms ease',
transition: `width ${theme.transitions.duration.standard}ms ease`,
};

const [actionButtons, setActionButtons] = useState<JSX.Element[] & ReactNode[]>([]);
Expand Down Expand Up @@ -181,6 +188,13 @@ export function Panel(props: TypePanelAppProps): JSX.Element {
// set focus on close button on panel open
setPanelStatus(true);

if (handlePanelOpened) {
// Wait the transition period (+50 ms just to be sure of shenanigans)
setTimeout(() => {
handlePanelOpened!();
}, theme.transitions.duration.standard + 50);
}

if (closeBtnRef && closeBtnRef.current) {
(closeBtnRef.current as HTMLElement).focus();
}
Expand Down Expand Up @@ -339,3 +353,10 @@ export function Panel(props: TypePanelAppProps): JSX.Element {
</Box>
);
}

/**
* React's default properties for the Panel
*/
Panel.defaultProps = {
handlePanelOpened: null,
};
Loading