rmwc
Version:
A thin React wrapper for Material Design (Web) Components
114 lines (84 loc) • 5.55 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Ripple = undefined;
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; }; }();
var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _react = require('react');
var React = _interopRequireWildcard(_react);
var _reactDom = require('react-dom');
var ReactDOM = _interopRequireWildcard(_reactDom);
var _classnames = require('classnames');
var _classnames2 = _interopRequireDefault(_classnames);
var _mdc = require('@material/ripple/dist/mdc.ripple');
var _withFoundation2 = require('../Base/withFoundation');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
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 Ripple = exports.Ripple = function (_withFoundation) {
_inherits(Ripple, _withFoundation);
function Ripple() {
_classCallCheck(this, Ripple);
return _possibleConstructorReturn(this, (Ripple.__proto__ || Object.getPrototypeOf(Ripple)).apply(this, arguments));
}
_createClass(Ripple, [{
key: 'componentDidMount',
value: function componentDidMount() {
// Ripples can be used with many types of components
// we need to use ReactDOM as an escape hatch to just find the DOMNode
this.root_ = ReactDOM.findDOMNode(this);
_get(Ripple.prototype.__proto__ || Object.getPrototypeOf(Ripple.prototype), 'componentDidMount', this).call(this);
}
}, {
key: 'syncWithProps',
value: function syncWithProps(nextProps) {
var _this2 = this;
// We dont know how React might have changed our dom node, re-grab it.
this.root_ = ReactDOM.findDOMNode(this);
// unbounded
(0, _withFoundation2.syncFoundationProp)(nextProps.unbounded, this.unbounded, function () {
return _this2.unbounded = !!nextProps.unbounded;
});
//disabled
(0, _withFoundation2.syncFoundationProp)(nextProps.disabled, this.disabled, function () {
return _this2.disabled = !!nextProps.disabled;
});
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
children = _props.children,
className = _props.className,
primary = _props.primary,
accent = _props.accent,
unbounded = _props.unbounded,
surface = _props.surface,
apiRef = _props.apiRef,
rest = _objectWithoutProperties(_props, ['children', 'className', 'primary', 'accent', 'unbounded', 'surface', 'apiRef']);
var child = React.Children.only(children);
var unboundedProp = unbounded ? { 'data-mdc-ripple-is-unbounded': true } : {};
return React.cloneElement(child, Object.assign({}, child.props, rest, unboundedProp, {
className: (0, _classnames2.default)(child.props.className, {
'mdc-ripple-surface': surface !== undefined ? surface : true,
'mdc-ripple-surface--primary': primary,
'mdc-ripple-surface--accent': accent
})
}));
}
}]);
return Ripple;
}((0, _withFoundation2.withFoundation)({
constructor: _mdc.MDCRipple,
adapter: {}
}));
Object.defineProperty(Ripple, 'displayName', {
enumerable: true,
writable: true,
value: 'Ripple'
});
exports.default = Ripple;
;