添加颜色预览控件

This commit is contained in:
liaoxuezhi 2019-11-05 18:04:27 +08:00
parent d56448a0d3
commit 6e5e246f55
6 changed files with 61 additions and 1 deletions

View File

@ -0,0 +1,18 @@
.#{$ns}ColorField {
display: inline-block;
&-previewIcon {
display: inline-block;
vertical-align: middle;
width: px2rem(16px);
height: px2rem(16px);
box-shadow: $boxShadowSm;
background-color: #ccc;
}
&-value {
display: inline-block;
margin-left: 10px;
vertical-align: middle;
}
}

View File

@ -502,6 +502,7 @@ $Card-actions-onChecked-onHover-bg: $white;
@import "../components/button-group";
@import "../components/dropdown";
@import "../components/collapse";
@import "../components/color";
@import "../components/wizard";
@import "../components/crud";
@import "../components/table";

View File

@ -184,6 +184,7 @@ pre {
@import '../components/button-group';
@import '../components/dropdown';
@import '../components/collapse';
@import "../components/color";
@import '../components/wizard';
@import '../components/crud';
@import '../components/table';

View File

@ -49,6 +49,7 @@ $Form-input-borderColor: #cfdadd;
@import "../components/button-group";
@import "../components/dropdown";
@import "../components/collapse";
@import "../components/color";
@import "../components/wizard";
@import "../components/crud";
@import "../components/table";
@ -99,4 +100,4 @@ $Form-input-borderColor: #cfdadd;
@import "../components/form/nested-select";
@import "../components/form/icon-picker";
@import "../utilities";
@import "../utilities";

View File

@ -64,6 +64,7 @@ import './renderers/ButtonGroup';
import './renderers/ButtonToolbar';
import './renderers/DropDownButton';
import './renderers/Collapse';
import './renderers/Color';
import './renderers/CRUD';
import './renderers/Pagination';
import './renderers/Cards';

38
src/renderers/Color.tsx Normal file
View File

@ -0,0 +1,38 @@
/**
* @file
*/
import React from 'react';
import {Renderer, RendererProps} from '../factory';
import {resolveVariableAndFilter} from '../utils/tpl-builtin';
export interface ColorProps extends RendererProps {
className: string;
defaultColor: string;
showValue: boolean;
}
export class ColorField extends React.Component<ColorProps, object> {
static defaultProps = {
className: '',
defaultColor: '#ccc',
showValue: true
};
render() {
const {className, data, classnames: cx, name, value, defaultColor, showValue} = this.props;
const color = value || (name ? resolveVariableAndFilter(name, data, '| raw') : null);
return (
<div className={cx('ColorField', className)}>
<i className={cx('ColorField-previewIcon')} style={{backgroundColor: color || defaultColor}} />
{showValue ? <span className={cx('ColorField-value')}>{color}</span> : null}
</div>
);
}
}
@Renderer({
test: /(^|\/)color$/,
name: 'color'
})
export class ColorFieldRenderer extends ColorField {}