UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

61 lines 3.73 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { DefaultButton } from 'office-ui-fabric-react/lib/Button'; import { FocusTrapCallout } from 'office-ui-fabric-react/lib/Callout'; import { CommandBar } from 'office-ui-fabric-react/lib/CommandBar'; import { getId } from 'office-ui-fabric-react/lib/Utilities'; import './CalloutExample.scss'; var CalloutFocusTrapExample = /** @class */ (function (_super) { tslib_1.__extends(CalloutFocusTrapExample, _super); function CalloutFocusTrapExample() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { isCalloutVisible: false }; // Use getId() to ensure that the callout title ID is unique on the page. // (It's also okay to use a plain string without getId() and manually ensure its uniqueness.) _this._titleId = getId('callout-label'); _this._onDismiss = function () { _this.setState({ isCalloutVisible: !_this.state.isCalloutVisible }); }; return _this; } CalloutFocusTrapExample.prototype.render = function () { var _this = this; var isCalloutVisible = this.state.isCalloutVisible; return (React.createElement("div", { className: "ms-CalloutExample" }, React.createElement("div", { className: "ms-CalloutBasicExample-buttonArea", ref: function (menuButton) { return (_this._menuButtonElement = menuButton); } }, React.createElement(DefaultButton, { onClick: this._onDismiss, text: isCalloutVisible ? 'Hide callout' : 'Show callout' })), isCalloutVisible ? (React.createElement("div", null, React.createElement(FocusTrapCallout, { role: "alertdialog", ariaLabelledBy: this._titleId, className: "ms-CalloutExample-callout", gapSpace: 0, target: this._menuButtonElement, onDismiss: this._onDismiss, setInitialFocus: true }, React.createElement("div", { className: "ms-CalloutExample-header" }, React.createElement("p", { className: "ms-CalloutExample-title", id: this._titleId }, "Callout title here")), React.createElement("div", { className: "ms-CalloutExample-inner" }, React.createElement("div", { className: "ms-CalloutExample-content" }, React.createElement("p", { className: "ms-CalloutExample-subText" }, "Message body is optional. If help documentation is available, consider adding a link to learn more at the bottom."))), React.createElement(CommandBar, { items: /* tslint:disable-line:no-use-before-declare */ items })))) : null)); }; return CalloutFocusTrapExample; }(React.Component)); export { CalloutFocusTrapExample }; var onCommandClick = function (ev, item) { return console.log(item && item.name); }; var items = [ { key: 'newItem', name: 'New', iconProps: { iconName: 'Add' }, ariaLabel: 'New. Use left and right arrow keys to navigate', subMenuProps: { items: [ { key: 'emailMessage', name: 'Email message', iconProps: { iconName: 'Mail' } }, { key: 'calendarEvent', name: 'Calendar event', iconProps: { iconName: 'Calendar' } } ] } }, { key: 'upload', name: 'Upload', iconProps: { iconName: 'Upload' }, href: 'https://dev.office.com/fabric', target: '_blank' }, { key: 'share', name: 'Share', iconProps: { iconName: 'Share' }, onClick: onCommandClick }, { key: 'download', name: 'Download', iconProps: { iconName: 'Download' }, onClick: onCommandClick } ]; //# sourceMappingURL=Callout.FocusTrap.Example.js.map