@ovine/core
Version:
Build flexible admin system with json.
44 lines (43 loc) • 1.64 kB
JavaScript
/**
* lib-css 样式渲染器
* 可为组件 传入自定义 css
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Renderer } from 'amis/lib/factory';
import React from 'react';
import styled, { css } from 'styled-components';
let LibCss = class LibCss extends React.Component {
componentDidMount() {
const { htmlClassName } = this.props;
if (htmlClassName) {
$('html').addClass(htmlClassName);
}
}
componentWillUnmount() {
const { htmlClassName } = this.props;
if (htmlClassName) {
$('html').removeClass(htmlClassName);
}
}
render() {
const { css: getCss, tag, render, className = '', body } = this.props;
return (React.createElement(StyledCss, { as: tag, className: className, css: getCss }, render('body', body)));
}
};
LibCss = __decorate([
Renderer({
test: /(^|\/)lib-css$/,
name: 'lib-css',
})
], LibCss);
export { LibCss };
const StyledCss = styled.div `
${(p) => css `
${!p.css ? undefined : typeof p.css === 'string' ? p.css : p.css(p.theme)};
`};
`;