fix(amis-editor): 弹性布局设置配置项优化

This commit is contained in:
wibetter 2023-04-04 11:21:05 +08:00
parent c27f246929
commit 0813818626
4 changed files with 43 additions and 21 deletions

View File

@ -18,11 +18,18 @@
> button { > button {
flex: 1 1 auto; flex: 1 1 auto;
display: flex;
justify-content: center;
align-items: center;
} }
} }
svg { svg.scaleX-180 {
vertical-align: middle; transform: rotate(180deg);
}
svg.scaleX-90 {
transform: rotate(90deg);
} }
} }
} }

View File

@ -1 +1 @@
<svg fill="currentColor" preserveAspectRatio="xMidYMid meet" width="20" height="20" viewBox="0 0 9 18"><g fillRule="evenodd"><path d="M0 6h9v5H0zm5 9v-3H4v3H2l2.5 3L7 15H5z"></path><path opacity=".4" d="M1 1h7v3H1z"></path><path d="M1 1v3h7V1H1zM0 0h9v5H0V0z"></path></g></svg> <svg fill="currentColor" preserveAspectRatio="xMidYMid meet" width="20" height="20" viewBox="0 0 9 18" class="ve-svgicon vs-style-reverse-v" style="vertical-align: middle;"><g fill-rule="evenodd"><path d="M0 6h9v5H0zm5 9v-3H4v3H2l2.5 3L7 15H5z"></path><path opacity=".4" d="M1 1h7v3H1z" data-spm-anchor-id="a2q5o.26736379.0.i51.35962a19sy6kFy"></path><path d="M1 1v3h7V1H1zM0 0h9v5H0V0z"></path></g></svg>

Before

Width:  |  Height:  |  Size: 277 B

After

Width:  |  Height:  |  Size: 405 B

View File

@ -2,17 +2,18 @@
* @file icon按钮组 * @file icon按钮组
*/ */
import React from 'react'; import React from 'react';
import {FormItem, Button, Icon, ClassNamesFn} from 'amis'; import {FormItem, Button, Icon, FormControlProps} from 'amis';
import cx from 'classnames';
export interface ButtonGroupControlProps { export interface ButtonGroupControlProps extends FormControlProps {
options?: Array<{ options?: Array<{
label: string; label: string;
icon: string; icon: string;
value: string; value: string;
iconClassName?: string;
}>; }>;
onChange: (value: string | number) => void; onChange: (value: string | number) => void;
value?: string | number; value?: string | number;
classnames?: ClassNamesFn;
} }
export default class ButtonGroupControl extends React.Component<ButtonGroupControlProps> { export default class ButtonGroupControl extends React.Component<ButtonGroupControlProps> {
@ -21,9 +22,10 @@ export default class ButtonGroupControl extends React.Component<ButtonGroupContr
} }
render() { render() {
const {options, value, onChange, classnames: cx} = this.props; const {options, value, onChange, classnames} = this.props;
const cls = classnames || cx;
return ( return (
<div className={cx('ButtonGroup', 'icon-ButtonList')}> <div className={cls('ButtonGroup', 'icon-ButtonList')}>
{options && {options &&
options.map(item => ( options.map(item => (
<Button <Button
@ -34,7 +36,10 @@ export default class ButtonGroupControl extends React.Component<ButtonGroupContr
active={value === item.value} active={value === item.value}
> >
{item.icon ? ( {item.icon ? (
<Icon icon={item.icon} className="icon" /> <Icon
icon={item.icon}
className={cx('icon', item.iconClassName)}
/>
) : ( ) : (
item.label item.label
)} )}

View File

@ -17,6 +17,9 @@ interface FlexSettingControlProps extends FormControlProps {
const getFlexItem = (props: FlexSettingControlProps) => { const getFlexItem = (props: FlexSettingControlProps) => {
const {value, direction, justify, alignItems} = props; const {value, direction, justify, alignItems} = props;
const curDirection = value?.flexDirection || direction; const curDirection = value?.flexDirection || direction;
const isColumn =
curDirection === 'column' || curDirection === 'column-reverse';
// 主轴排列方向 // 主轴排列方向
const directionItemOptions = [ const directionItemOptions = [
{ {
@ -32,31 +35,35 @@ const getFlexItem = (props: FlexSettingControlProps) => {
{ {
label: '水平反向', label: '水平反向',
value: 'row-reverse', value: 'row-reverse',
icon: 'drowReverse' icon: 'drowReverse',
iconClassName: 'scaleX-180'
}, },
{ {
label: '垂直反向', label: '垂直反向',
value: 'column-reverse', value: 'column-reverse',
icon: 'dcolumnReverse' icon: 'dcolumnReverse',
iconClassName: 'scaleX-180'
} }
]; ];
// 交叉轴排列方式 // 交叉轴排列方式
const alignItemsOptions = [ const alignItemsOptions = [
{ {
label: '起点对齐', label: isColumn ? '左对齐' : '顶部对齐',
value: 'flex-start', value: 'flex-start',
icon: 'aFlexStart' icon: 'aFlexStart'
// iconClassName: isColumn ? 'scaleX-90' : '',
}, },
{ {
label: '垂直居中', label: isColumn ? '水平居中' : '垂直居中',
value: 'center', value: 'center',
icon: 'aCenter' icon: 'aCenter'
}, },
{ {
label: '终点对齐', label: isColumn ? '右对齐' : '底部对齐',
value: 'flex-end', value: 'flex-end',
icon: 'aFlexEnd' icon: 'aFlexEnd'
// iconClassName: isColumn ? 'scaleX-90' : '',
}, },
{ {
label: '基线对齐', label: '基线对齐',
@ -64,28 +71,31 @@ const getFlexItem = (props: FlexSettingControlProps) => {
icon: 'aBaseline' icon: 'aBaseline'
}, },
{ {
label: '高度撑满', label: isColumn ? '水平铺开' : '高度撑满',
value: 'stretch', value: 'stretch',
icon: 'aStretch' icon: 'aStretch',
iconClassName: isColumn ? 'scaleX-90' : ''
} }
]; ];
// 主轴排列方式 // 主轴排列方式
const justifyItemsOptions = [ const justifyItemsOptions = [
{ {
label: '左对齐', label: isColumn ? '顶部对齐' : '左对齐',
value: 'flex-start', value: 'flex-start',
icon: 'jFlexStart' icon: 'jFlexStart'
// iconClassName: isColumn ? 'scaleX-90' : '',
}, },
{ {
label: '水平居中', label: isColumn ? '垂直居中' : '水平居中',
value: 'center', value: 'center',
icon: 'jCenter' icon: 'jCenter'
}, },
{ {
label: '右对齐', label: isColumn ? '底部对齐' : '右对齐',
value: 'flex-end', value: 'flex-end',
icon: 'jFlexEnd' icon: 'jFlexEnd'
// iconClassName: isColumn ? 'scaleX-90' : '',
}, },
{ {
label: '两端对齐', label: '两端对齐',
@ -136,7 +146,7 @@ export default class FlexSettingControl extends React.Component<FlexSettingContr
} }
render() { render() {
const {value, label, classnames} = this.props; const {value, label, ...rest} = this.props;
const flexItems = getFlexItem(this.props); const flexItems = getFlexItem(this.props);
return ( return (
@ -148,10 +158,10 @@ export default class FlexSettingControl extends React.Component<FlexSettingContr
key={item.field} key={item.field}
> >
<ButtonGroup <ButtonGroup
{...rest}
options={item.options} options={item.options}
value={value?.[item.field] || item.default} value={value?.[item.field] || item.default}
onChange={this.setField(item.field)} onChange={this.setField(item.field)}
classnames={classnames}
/> />
</div> </div>
))} ))}