|
@@ -0,0 +1,36 @@
|
|
|
+import cx from 'classnames';
|
|
|
+
|
|
|
+function addClassNameToNode (node, addedClassName) {
|
|
|
+ const {attributes} = node;
|
|
|
+ const {className} = attributes;
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...node,
|
|
|
+ attributes: {
|
|
|
+ ...attributes,
|
|
|
+ className: cx(className, addedClassName)
|
|
|
+ }
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+function appendClassName (component) {
|
|
|
+ return function ({className, ...props}, children) {
|
|
|
+ const rendered = component(props, children);
|
|
|
+
|
|
|
+ // handle lazy component
|
|
|
+ if (typeof rendered === 'function') {
|
|
|
+ return function (state, actions) {
|
|
|
+ return addClassNameToNode(
|
|
|
+ rendered(state, actions),
|
|
|
+ className
|
|
|
+ );
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return addClassNameToNode(rendered, className);
|
|
|
+ };
|
|
|
+}
|
|
|
+
|
|
|
+export {
|
|
|
+ appendClassName
|
|
|
+};
|