Skip to content

Instantly share code, notes, and snippets.

@Guria
Last active March 14, 2016 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Guria/da4f1fabacf8ffcc71e3 to your computer and use it in GitHub Desktop.
Save Guria/da4f1fabacf8ffcc71e3 to your computer and use it in GitHub Desktop.
import { createElement, DOMElement, ReactNode } from 'react';
import { stringify, BEMEntity } from 'rebem-classname';
export interface BEMFactory {
(props: BEMEntity, ...children: ReactNode[]): DOMElement<BEMEntity>
}
function BEM (props: BEMEntity, ...children: ReactNode[]) {
const tag = props.tag || 'div';
const className = stringify(props);
props.className = className
return createElement(tag, props, ...children);
}
function blockFactory(block: string) : BEMFactory {
return function (props: BEMEntity, ...children: ReactNode[]) {
props.block = block
return BEM(props, ...children);
};
}
export { BEM, blockFactory };
"use strict";
// result of typescript compilation
var react_1 = require('react');
var rebem_classname_1 = require('rebem-classname');
function BEM(props) {
var children = [];
for (var _i = 1; _i < arguments.length; _i++) {
children[_i - 1] = arguments[_i];
}
var tag = props.tag || 'div';
var className = rebem_classname_1.stringify(props);
props.className = className;
return react_1.createElement.apply(void 0, [tag, props].concat(children));
}
exports.BEM = BEM;
function blockFactory(block) {
return function (props) {
var children = [];
for (var _i = 1; _i < arguments.length; _i++) {
children[_i - 1] = arguments[_i];
}
props.block = block;
return BEM.apply(void 0, [props].concat(children));
};
}
exports.blockFactory = blockFactory;
import React from 'react';
import { stringify } from 'rebem-classname';
function BEM(props, ...children) {
const tag = props.tag || 'div';
const className = stringify(props);
const newProps = className ? { ...props, className } : props;
return React.createElement(tag, newProps, ...children);
}
function blockFactory(block) {
return function (props, ...children) {
return BEM({ ...props, block }, ...children);
};
}
export { BEM, blockFactory };
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.blockFactory = exports.BEM = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _rebemClassname = require('rebem-classname');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function BEM(props) {
var tag = props.tag || 'div';
var className = (0, _rebemClassname.stringify)(props);
var newProps = className ? _extends({}, props, { className: className }) : props;
for (var _len = arguments.length, children = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
children[_key - 1] = arguments[_key];
}
return _react2.default.createElement.apply(_react2.default, [tag, newProps].concat(children));
}
function blockFactory(block) {
return function (props) {
for (var _len2 = arguments.length, children = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
children[_key2 - 1] = arguments[_key2];
}
return BEM.apply(undefined, [_extends({}, props, { block: block })].concat(children));
};
}
exports.BEM = BEM;
exports.blockFactory = blockFactory;
@Guria
Copy link
Author

Guria commented Mar 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment