UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

66 lines 2.8 kB
/* tslint:disable:no-unused-variable */ import * as React from 'react'; /* tslint:enable:no-unused-variable */ import * as ReactDOM from 'react-dom'; import { App, AppDefinition } from './AppDefinition'; import { Router, Route } from 'office-ui-fabric-react/lib/utilities/router/index'; import { GettingStartedPage } from './GettingStartedPage'; import { setBaseUrl } from 'office-ui-fabric-react/lib/Utilities'; import { Fabric } from 'office-ui-fabric-react/lib/Fabric'; import { ComponentPage } from '@uifabric/example-app-base'; import './index.scss'; import './ColorStyles.scss'; import { initializeIcons } from '@uifabric/icons/lib/index'; initializeIcons(); setBaseUrl('./dist/'); ComponentPage.defaultProps.areBadgesVisible = true; var rootElement; // Return the anchor link from the URL without the hash function _extractAnchorLink(path) { var index = path.lastIndexOf('#'); if (index >= 0) { path = path.substr(index + 1, path.length - index); } return path; } function _scrollAnchorLink() { if ((window.location.hash.match(/#/g) || []).length > 1) { var anchor = _extractAnchorLink(window.location.hash); document.getElementById(anchor).scrollIntoView(); } } function _onLoad() { rootElement = rootElement || document.getElementById('content'); ReactDOM.render(React.createElement(Fabric, null, React.createElement(Router, { onNewRouteLoaded: _scrollAnchorLink }, _getRoutes())), rootElement); } function _getRoutes() { var routes = AppDefinition.testPages.map(function (page) { return React.createElement(Route, { key: page.key, path: page.url, component: page.component }); }); var appRoutes = []; AppDefinition.examplePages.forEach(function (group) { group.links .filter(function (link) { return link.hasOwnProperty('component') || link.hasOwnProperty('getComponent'); }) .forEach(function (link, linkIndex) { var component = link.component, getComponent = link.getComponent; appRoutes.push(React.createElement(Route, { key: link.key, path: link.url, component: component, getComponent: getComponent })); }); }); // Default route. appRoutes.push(React.createElement(Route, { key: 'gettingstarted', component: GettingStartedPage })); routes.push(React.createElement(Route, { key: 'app', component: App }, appRoutes)); return routes; } function _onUnload() { if (rootElement) { ReactDOM.unmountComponentAtNode(rootElement); } } var isReady = document.readyState === 'interactive' || document.readyState === 'complete'; if (isReady) { _onLoad(); } else { window.onload = _onLoad; } window.onunload = _onUnload; //# sourceMappingURL=index.js.map