Skip to content

Commit f3acc78

Browse files
authored
Merge pull request #209 from murat-encord/add-toggle-additional-options-action
add toggleAdditionalOptions action
2 parents 2621eb6 + d4b56ad commit f3acc78

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ export interface MosaicWindowProps<T extends MosaicKey> {
258258
* A callback that triggers when a user toggles the additional controls
259259
*/
260260
onAdditionalControlsToggle?: (toggle: boolean) => void;
261+
/**
262+
* Disables the overlay that blocks interaction with the window when additional controls are open
263+
*/
264+
disableAdditionalControlsOverlay?: boolean;
261265
/**
262266
* Whether or not a user should be able to drag windows around
263267
*/
@@ -367,9 +371,10 @@ export interface MosaicWindowActions {
367371
*/
368372
replaceWithNew: () => Promise<void>;
369373
/**
370-
* Sets the open state for the tray that holds additional controls
374+
* Sets the open state for the tray that holds additional controls.
375+
* Pass 'toggle' to invert the current state.
371376
*/
372-
setAdditionalControlsOpen: (open: boolean) => void;
377+
setAdditionalControlsOpen: (open: boolean | 'toggle') => void;
373378
/**
374379
* Returns the path to this window
375380
*/

src/MosaicWindow.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface MosaicWindowProps<T extends MosaicKey> {
3333
additionalControls?: React.ReactNode;
3434
additionalControlButtonText?: string;
3535
onAdditionalControlsToggle?: (toggle: boolean) => void;
36+
disableAdditionalControlsOverlay?: boolean;
3637
draggable?: boolean;
3738
createNode?: CreateNode<T>;
3839
renderPreview?: (props: MosaicWindowProps<T>) => JSX.Element;
@@ -98,6 +99,7 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
9899
connectDropTarget,
99100
connectDragPreview,
100101
draggedMosaicId,
102+
disableAdditionalControlsOverlay,
101103
} = this.props;
102104

103105
return (
@@ -112,7 +114,14 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
112114
>
113115
{this.renderToolbar()}
114116
<div className="mosaic-window-body">{this.props.children}</div>
115-
<div className="mosaic-window-body-overlay" onClick={() => this.setAdditionalControlsOpen(false)} />
117+
{!disableAdditionalControlsOverlay && (
118+
<div
119+
className="mosaic-window-body-overlay"
120+
onClick={() => {
121+
this.setAdditionalControlsOpen(false);
122+
}}
123+
/>
124+
)}
116125
<div className="mosaic-window-additional-actions-bar">{additionalControls}</div>
117126
{connectDragPreview(renderPreview!(this.props))}
118127
<div className="drop-target-container">
@@ -221,7 +230,9 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
221230
return Promise.resolve(createNode!(...args)).then((node) => mosaicActions.replaceWith(path, node));
222231
};
223232

224-
private setAdditionalControlsOpen = (additionalControlsOpen: boolean) => {
233+
private setAdditionalControlsOpen = (additionalControlsOpenOption: boolean | 'toggle') => {
234+
const additionalControlsOpen =
235+
additionalControlsOpenOption === 'toggle' ? !this.state.additionalControlsOpen : additionalControlsOpenOption;
225236
this.setState({ additionalControlsOpen });
226237
this.props.onAdditionalControlsToggle?.(additionalControlsOpen);
227238
};

src/contextTypes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ export interface MosaicWindowActions {
7676
*/
7777
replaceWithNew: (...args: any[]) => Promise<void>;
7878
/**
79-
* Sets the open state for the tray that holds additional controls
79+
* Sets the open state for the tray that holds additional controls.
80+
* Pass 'toggle' to invert the current state.
8081
*/
81-
setAdditionalControlsOpen: (open: boolean) => void;
82+
setAdditionalControlsOpen: (open: boolean | 'toggle') => void;
8283
/**
8384
* Returns the path to this window
8485
*/

0 commit comments

Comments
 (0)