UNPKG

jss-react-material

Version:

Google Material Components for React

70 lines (59 loc) 1.92 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.getClassesStatic = undefined; var _lodash = require('lodash'); var _lodash2 = _interopRequireDefault(_lodash); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var gridClasses = { smPush: 'push-sm', smdPush: 'push-smd', mdPush: 'push-md', lgPush: 'push-lg', xlgPush: 'push-xlg', xxlgPush: 'push-xxlg', xxxlgPush: 'push-xxxlg', sm: 'col-sm', smd: 'col-smd', md: 'col-md', lg: 'col-lg', xlg: 'col-xlg', xxlg: 'col-xxlg', xxxlg: 'col-xxxlg' }; var getClassesStatic = exports.getClassesStatic = function getClassesStatic(prefix, props) { var classes = []; _lodash2.default.forIn(props, function (value, key) { if (value === true) { return classes.push(prefix + '-' + key.toLowerCase()); } if (Object.keys(gridClasses).indexOf(key) !== -1) { return classes.push(gridClasses[key] + '-' + value); } if (typeof value === 'number' && value >= 1) { return classes.push(prefix + '-' + key + '-' + value); } if (['color', 'background', 'hoverColor'].indexOf(key) !== -1) { return classes.push(key.toLowerCase() + '-' + value); } if (['size'].indexOf(key) !== -1) { return classes.push(prefix + '-' + key.toLowerCase() + '-' + value); } if (key === 'className' && typeof value === 'string') { classes = classes.concat(value.split(' ')); } }); classes.push(prefix); classes.reverse(); return classes.join(' '); }; /** * Makes the given component "getClasses". * * @param object component Component. */ function getClassesDecorator(component) { component.prototype.getClasses = getClassesStatic; } exports.default = getClassesDecorator;