@onesy/style-react
Version:
Onesy CSS in JS styling solution for React
30 lines (28 loc) • 1.08 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
const _excluded = ["children", "className"];
import React from 'react';
import { classNames } from '@onesy/style';
import { style } from '.';
const styled = Element => function (value) {
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
// Name
options.name = options.name !== undefined ? options.name : `${Element?.displayName || Element?.type?.displayName || ''}Styled`;
// Use styles
const useStyle = style(value, options);
// Element
const element = /*#__PURE__*/React.forwardRef((props, ref) => {
const {
children,
className: classNameProp
} = props,
other = _objectWithoutProperties(props, _excluded);
const styles = useStyle(props);
return /*#__PURE__*/React.createElement(Element, _extends({
ref: ref,
className: classNames([classNameProp, styles.class])
}, other), children);
});
return element;
};
export default styled;