Skip to content

Instantly share code, notes, and snippets.

@timelyportfolio
Created November 19, 2017 17:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
office ui fabric react in R
license: mit

Yes, R users can use React as shown in this blog post. This example uses office-ui-fabric-react from Microsoft.

library(htmltools)
library(reactR)

fabric <- htmlDependency(
  name = "office-fabric-ui-react",
  version = "5.23.0",
  src = c(href="https://unpkg.com/office-ui-fabric-react/dist"),
  script = "office-ui-fabric-react.js",
  stylesheet = "css/fabric.min.css"
)

browsable(
  tagList(
    html_dependency_react(offline=FALSE),
    fabric,
    tags$div(id="pivot-example"),
    tags$script(HTML(babel_transform(
"
class PivotBasicExample extends React.Component {
  render() {
    return (
      <div>
        <Fabric.Pivot>
          <Fabric.PivotItem linkText='My Files'>
            <Fabric.Label>Pivot #1</Fabric.Label>
          </Fabric.PivotItem>
          <Fabric.PivotItem linkText='Recent'>
            <Fabric.Label>Pivot #2</Fabric.Label>
          </Fabric.PivotItem>
          <Fabric.PivotItem linkText='Shared with me'>
            <Fabric.Label>Pivot #3</Fabric.Label>
          </Fabric.PivotItem>
        </Fabric.Pivot>
      </div>
    );
  }
}
ReactDOM.render(<PivotBasicExample />, document.querySelector('#pivot-example'));
"
    )))
  )
)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<script src="//unpkg.com/react/umd/react.production.min.js"></script>
<script src="//unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
<link href="https://unpkg.com/office-ui-fabric-react/dist/css/fabric.min.css" rel="stylesheet" />
<script src="https://unpkg.com/office-ui-fabric-react/dist/office-ui-fabric-react.js"></script>
</head>
<body style="background-color:white;">
<div id="pivot-example"></div>
<script>'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var PivotBasicExample = function (_React$Component) {
_inherits(PivotBasicExample, _React$Component);
function PivotBasicExample() {
_classCallCheck(this, PivotBasicExample);
return _possibleConstructorReturn(this, (PivotBasicExample.__proto__ || Object.getPrototypeOf(PivotBasicExample)).apply(this, arguments));
}
_createClass(PivotBasicExample, [{
key: 'render',
value: function render() {
return React.createElement(
'div',
null,
React.createElement(
Fabric.Pivot,
null,
React.createElement(
Fabric.PivotItem,
{ linkText: 'My Files' },
React.createElement(
Fabric.Label,
null,
'Pivot #1'
)
),
React.createElement(
Fabric.PivotItem,
{ linkText: 'Recent' },
React.createElement(
Fabric.Label,
null,
'Pivot #2'
)
),
React.createElement(
Fabric.PivotItem,
{ linkText: 'Shared with me' },
React.createElement(
Fabric.Label,
null,
'Pivot #3'
)
)
)
);
}
}]);
return PivotBasicExample;
}(React.Component);
ReactDOM.render(React.createElement(PivotBasicExample, null), document.querySelector('#pivot-example'));</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment