mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-20 07:14:23 +00:00
fix: 🐛 add tip on setter title
This commit is contained in:
parent
791771c5cd
commit
c93c1d0b1e
@ -1,4 +1,5 @@
|
|||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
|
import { isObject } from 'lodash';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { Icon } from '@alifd/next';
|
import { Icon } from '@alifd/next';
|
||||||
import { Title, Tip } from '@ali/lowcode-editor-core';
|
import { Title, Tip } from '@ali/lowcode-editor-core';
|
||||||
@ -7,6 +8,7 @@ import { PopupPipe, PopupContext } from '../popup';
|
|||||||
import { intl, intlNode } from '../../locale';
|
import { intl, intlNode } from '../../locale';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
import { IconClear } from 'editor-skeleton/src/icons/clear';
|
import { IconClear } from 'editor-skeleton/src/icons/clear';
|
||||||
|
import InlineTip from './inlinetip';
|
||||||
|
|
||||||
export interface FieldProps {
|
export interface FieldProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -14,6 +16,8 @@ export interface FieldProps {
|
|||||||
defaultDisplay?: 'accordion' | 'inline' | 'block';
|
defaultDisplay?: 'accordion' | 'inline' | 'block';
|
||||||
collapsed?: boolean;
|
collapsed?: boolean;
|
||||||
valueState?: number;
|
valueState?: number;
|
||||||
|
name?: string;
|
||||||
|
tip?: any;
|
||||||
onExpandChange?: (expandState: boolean) => void;
|
onExpandChange?: (expandState: boolean) => void;
|
||||||
onClear?: () => void;
|
onClear?: () => void;
|
||||||
}
|
}
|
||||||
@ -76,11 +80,36 @@ export class Field extends Component<FieldProps> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTipContent(propName: string, tip?: any): any {
|
||||||
|
let tipContent = (
|
||||||
|
<div>
|
||||||
|
<div>属性:{propName}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isObject(tip)) {
|
||||||
|
tipContent = (
|
||||||
|
<div>
|
||||||
|
<div>属性:{propName}</div>
|
||||||
|
<div>说明:{tip.content}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
} else if (tip) {
|
||||||
|
tipContent = (
|
||||||
|
<div>
|
||||||
|
<div>属性:{propName}</div>
|
||||||
|
<div>说明:{tip}</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return tipContent;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, children, title, valueState, onClear } = this.props;
|
const { className, children, title, valueState, onClear, name: propName, tip } = this.props;
|
||||||
const { display, collapsed } = this.state;
|
const { display, collapsed } = this.state;
|
||||||
const isAccordion = display === 'accordion';
|
const isAccordion = display === 'accordion';
|
||||||
|
const tipContent = this.getTipContent(propName, tip);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classNames(`lc-field lc-${display}-field`, className, {
|
className={classNames(`lc-field lc-${display}-field`, className, {
|
||||||
@ -91,6 +120,7 @@ export class Field extends Component<FieldProps> {
|
|||||||
<div className="lc-field-title">
|
<div className="lc-field-title">
|
||||||
{createValueState(valueState, onClear)}
|
{createValueState(valueState, onClear)}
|
||||||
<Title title={title || ''} />
|
<Title title={title || ''} />
|
||||||
|
<InlineTip position="top">{tipContent}</InlineTip>
|
||||||
</div>
|
</div>
|
||||||
{isAccordion && <Icon className="lc-field-icon" type="arrow-up" size="xs" />}
|
{isAccordion && <Icon className="lc-field-icon" type="arrow-up" size="xs" />}
|
||||||
</div>
|
</div>
|
||||||
@ -115,7 +145,7 @@ export class Field extends Component<FieldProps> {
|
|||||||
*/
|
*/
|
||||||
function createValueState(valueState?: number, onClear?: () => void) {
|
function createValueState(valueState?: number, onClear?: () => void) {
|
||||||
let tip: any = null;
|
let tip: any = null;
|
||||||
let className: string = 'lc-valuestate';
|
let className = 'lc-valuestate';
|
||||||
let icon: any = null;
|
let icon: any = null;
|
||||||
if (valueState) {
|
if (valueState) {
|
||||||
if (valueState < 0) {
|
if (valueState < 0) {
|
||||||
@ -139,10 +169,12 @@ function createValueState(valueState?: number, onClear?: () => void) {
|
|||||||
// unset 占位空间
|
// unset 占位空间
|
||||||
}
|
}
|
||||||
|
|
||||||
return <i className={className} onClick={onClear}>
|
return (
|
||||||
|
<i className={className} onClick={onClear}>
|
||||||
{icon}
|
{icon}
|
||||||
{tip && <Tip>{tip}</Tip>}
|
{tip && <Tip>{tip}</Tip>}
|
||||||
</i>;
|
</i>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PopupFieldProps extends FieldProps {
|
export interface PopupFieldProps extends FieldProps {
|
||||||
|
|||||||
25
packages/editor-skeleton/src/components/field/inlinetip.tsx
Normal file
25
packages/editor-skeleton/src/components/field/inlinetip.tsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
export interface InlineTipProps {
|
||||||
|
position: string;
|
||||||
|
theme?: 'green' | 'black';
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class InlineTip extends React.Component<InlineTipProps> {
|
||||||
|
static displayName = 'InlineTip';
|
||||||
|
|
||||||
|
static defaultProps = {
|
||||||
|
position: 'auto',
|
||||||
|
theme: 'black',
|
||||||
|
};
|
||||||
|
|
||||||
|
render(): React.ReactNode {
|
||||||
|
const { position, theme, children } = this.props;
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'none' }} data-role="tip" data-position={position} data-theme={theme}>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -66,6 +66,7 @@ class SettingFieldView extends Component<{ field: SettingField }> {
|
|||||||
valueState: field.isRequired ? 10 : field.valueState,
|
valueState: field.isRequired ? 10 : field.valueState,
|
||||||
onExpandChange: (expandState) => field.setExpanded(expandState),
|
onExpandChange: (expandState) => field.setExpanded(expandState),
|
||||||
onClear: () => field.clearValue(),
|
onClear: () => field.clearValue(),
|
||||||
|
...extraProps,
|
||||||
},
|
},
|
||||||
createSetterContent(setterType, {
|
createSetterContent(setterType, {
|
||||||
...shallowIntl(setterProps),
|
...shallowIntl(setterProps),
|
||||||
@ -91,7 +92,7 @@ class SettingFieldView extends Component<{ field: SettingField }> {
|
|||||||
value,
|
value,
|
||||||
});
|
});
|
||||||
field.setValue(value);
|
field.setValue(value);
|
||||||
}
|
},
|
||||||
}),
|
}),
|
||||||
extraProps.forceInline ? 'plain' : extraProps.display,
|
extraProps.forceInline ? 'plain' : extraProps.display,
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user