Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions common/changes/modal-remove-core-dep_2017-04-20-21-53.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Modal: Updated animation to use local transition and removed Fabric Core dependency",
"type": "patch"
}
],
"email": "micahgodbolt@gmail.com"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
// --------------------------------------------------
// Modal styles


.root {
@include ms-baseFont;
background-color: transparent;
position: fixed;
height: 100%;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
display: none; // Hidden by default

opacity: 0;
pointer-events: none;
transition: opacity $ms-duration2;
:global(.ms-Button.ms-Button--compound) {
display: block;
@include margin-left(0);
Expand All @@ -30,9 +31,9 @@
}
}

// State: The dialog is open
.root.isOpen {
display: flex;
.rootIsVisible {
opacity: 1;
pointer-events: auto;
}

// The actual dialog element
Expand Down
98 changes: 43 additions & 55 deletions packages/office-ui-fabric-react/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import styles = require('./Modal.scss');

export interface IDialogState {
isOpen?: boolean;
isAnimatingOpen?: boolean;
isAnimatingClose?: boolean;
isVisible?: boolean;
isVisibleClose?: boolean;
id?: string;
}

Expand All @@ -32,34 +32,48 @@ export class Modal extends BaseComponent<IModalProps, IDialogState> {
containerClassName: '',
};

private _onModalCloseTimer: number;

constructor(props: IModalProps) {
super(props);

this._onDialogRef = this._onDialogRef.bind(this);

this.state = {
id: getId('Modal'),
isOpen: props.isOpen,
isAnimatingOpen: props.isOpen,
isAnimatingClose: false
isVisible: props.isOpen,
};
}

public componentWillReceiveProps(newProps: IModalProps) {
clearTimeout(this._onModalCloseTimer);

// Opening the dialog
if (newProps.isOpen && !this.state.isOpen) {
this.setState({
isOpen: true,
isAnimatingOpen: true,
isAnimatingClose: false
});
if (newProps.isOpen) {
if (!this.state.isOpen) {
// First Open
this.setState({
isOpen: true
});
} else {
// Reopen during closing
this.setState({
isVisible: true
});
}
}

// Closing the dialog
if (!newProps.isOpen && this.state.isOpen) {
this._onModalCloseTimer = this._async.setTimeout(this._onModalClose, 1000);
this.setState({
isAnimatingOpen: false,
isAnimatingClose: true
isVisible: false
});
}
}

public componentDidUpdate(prevState: IDialogState, prevProps: IModalProps) {
if (!prevProps.isOpen && !prevState.isVisible) {
this.setState({
isVisible: true
});
}
}
Expand All @@ -79,20 +93,17 @@ export class Modal extends BaseComponent<IModalProps, IDialogState> {
titleAriaId,
subtitleAriaId,
} = this.props;
let { id, isOpen, isAnimatingOpen, isAnimatingClose } = this.state;
let { id, isOpen, isVisible } = this.state;

const modalClassName = css('ms-Dialog', styles.root, this.props.className, {
['is-open ']: isOpen,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, remove space now that you don't concatenate

[styles.rootIsVisible]: isVisible,
});

// @TODO - the discussion on whether the Modal contain a property for rendering itself is still being discussed
if (!isOpen) {
return null;
}

let subTextContent;
const modalClassName = css('ms-Dialog', styles.root, this.props.className, {
['is-open ' + styles.isOpen]: isOpen,
'ms-u-fadeIn200': isAnimatingOpen,
'ms-u-fadeOut200': isAnimatingClose
});

// @temp tuatology - Will adjust this to be a panel at certain breakpoints
if (responsiveMode >= ResponsiveMode.small) {
return (
Expand All @@ -103,9 +114,7 @@ export class Modal extends BaseComponent<IModalProps, IDialogState> {
ariaDescribedBy={ subtitleAriaId }
onDismiss={ onDismiss }
>
<div
className={ modalClassName }
ref={ this._onDialogRef }>
<div className={ modalClassName }>
<Overlay isDarkThemed={ isDarkOverlay } onClick={ isBlocking ? null : onDismiss } />
<FocusTrapZone
className={ css('ms-Dialog-main', styles.main, this.props.containerClassName) }
Expand All @@ -123,36 +132,15 @@ export class Modal extends BaseComponent<IModalProps, IDialogState> {
}
}

private _onDialogRef(ref: HTMLDivElement) {
if (ref) {
this._events.on(ref, 'animationend', this._onAnimationEnd);
} else {
this._events.off();
}
}

// Watch for completed animations and set the state
private _onAnimationEnd(ev: AnimationEvent) {

// The dialog has just opened (faded in)
if (ev.animationName.indexOf('fadeIn') > -1) {
this.setState({
isOpen: true,
isAnimatingOpen: false
});
}

// The dialog has just closed (faded out)
if (ev.animationName.indexOf('fadeOut') > -1) {
this.setState({
isOpen: false,
isAnimatingClose: false
});
private _onModalClose() {
this.setState({
isOpen: false
});

// Call the onDismiss callback
if (this.props.onDismissed) {
this.props.onDismissed();
}
// Call the onDismiss callback
if (this.props.onDismissed) {
this.props.onDismissed();
}
}
}