Skip to content

Commit

Permalink
Merge pull request #209 from murat-encord/add-toggle-additional-optio…
Browse files Browse the repository at this point in the history
…ns-action

add toggleAdditionalOptions action
  • Loading branch information
nomcopter authored Sep 18, 2023
2 parents 2621eb6 + d4b56ad commit f3acc78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ export interface MosaicWindowProps<T extends MosaicKey> {
* A callback that triggers when a user toggles the additional controls
*/
onAdditionalControlsToggle?: (toggle: boolean) => void;
/**
* Disables the overlay that blocks interaction with the window when additional controls are open
*/
disableAdditionalControlsOverlay?: boolean;
/**
* Whether or not a user should be able to drag windows around
*/
Expand Down Expand Up @@ -367,9 +371,10 @@ export interface MosaicWindowActions {
*/
replaceWithNew: () => Promise<void>;
/**
* Sets the open state for the tray that holds additional controls
* Sets the open state for the tray that holds additional controls.
* Pass 'toggle' to invert the current state.
*/
setAdditionalControlsOpen: (open: boolean) => void;
setAdditionalControlsOpen: (open: boolean | 'toggle') => void;
/**
* Returns the path to this window
*/
Expand Down
15 changes: 13 additions & 2 deletions src/MosaicWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface MosaicWindowProps<T extends MosaicKey> {
additionalControls?: React.ReactNode;
additionalControlButtonText?: string;
onAdditionalControlsToggle?: (toggle: boolean) => void;
disableAdditionalControlsOverlay?: boolean;
draggable?: boolean;
createNode?: CreateNode<T>;
renderPreview?: (props: MosaicWindowProps<T>) => JSX.Element;
Expand Down Expand Up @@ -98,6 +99,7 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
connectDropTarget,
connectDragPreview,
draggedMosaicId,
disableAdditionalControlsOverlay,
} = this.props;

return (
Expand All @@ -112,7 +114,14 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
>
{this.renderToolbar()}
<div className="mosaic-window-body">{this.props.children}</div>
<div className="mosaic-window-body-overlay" onClick={() => this.setAdditionalControlsOpen(false)} />
{!disableAdditionalControlsOverlay && (
<div
className="mosaic-window-body-overlay"
onClick={() => {
this.setAdditionalControlsOpen(false);
}}
/>
)}
<div className="mosaic-window-additional-actions-bar">{additionalControls}</div>
{connectDragPreview(renderPreview!(this.props))}
<div className="drop-target-container">
Expand Down Expand Up @@ -221,7 +230,9 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
return Promise.resolve(createNode!(...args)).then((node) => mosaicActions.replaceWith(path, node));
};

private setAdditionalControlsOpen = (additionalControlsOpen: boolean) => {
private setAdditionalControlsOpen = (additionalControlsOpenOption: boolean | 'toggle') => {
const additionalControlsOpen =
additionalControlsOpenOption === 'toggle' ? !this.state.additionalControlsOpen : additionalControlsOpenOption;
this.setState({ additionalControlsOpen });
this.props.onAdditionalControlsToggle?.(additionalControlsOpen);
};
Expand Down
5 changes: 3 additions & 2 deletions src/contextTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ export interface MosaicWindowActions {
*/
replaceWithNew: (...args: any[]) => Promise<void>;
/**
* Sets the open state for the tray that holds additional controls
* Sets the open state for the tray that holds additional controls.
* Pass 'toggle' to invert the current state.
*/
setAdditionalControlsOpen: (open: boolean) => void;
setAdditionalControlsOpen: (open: boolean | 'toggle') => void;
/**
* Returns the path to this window
*/
Expand Down

0 comments on commit f3acc78

Please sign in to comment.