Skip to content

Commit

Permalink
fix(antd/next): fix FormItem inherit priority #1624
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jun 22, 2021
1 parent 1f205b7 commit ee4fc5f
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 64 deletions.
8 changes: 4 additions & 4 deletions designable/antd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"start": "webpack-dev-server --config playground/webpack.dev.ts"
},
"devDependencies": {
"@designable/react-settings-form": "^0.3.14",
"@designable/react-settings-form": "^0.3.15",
"autoprefixer": "^9.0",
"file-loader": "^5.0.2",
"fs-extra": "^8.1.0",
Expand All @@ -56,9 +56,9 @@
"react-is": ">=16.8.0 || >=17.0.0"
},
"dependencies": {
"@designable/core": "^0.3.14",
"@designable/formily": "^0.3.14",
"@designable/react": "^0.3.14",
"@designable/core": "^0.3.15",
"@designable/formily": "^0.3.15",
"@designable/react": "^0.3.15",
"@formily/antd": "2.0.0-beta.69",
"@formily/core": "2.0.0-beta.69",
"@formily/react": "2.0.0-beta.69",
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/Cascader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const Cascader: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/DatePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const CommonDatePickerAPI = {
},
size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
12 changes: 6 additions & 6 deletions designable/antd/src/schemas/FormItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const FormItem: ISchema = {
},
feedbackLayout: {
type: 'string',
enum: ['loose', 'terse', 'popover', 'none', ''],
enum: ['loose', 'terse', 'popover', 'none', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -65,7 +65,7 @@ export const FormItem: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'default', ''],
enum: ['large', 'small', 'default', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -74,7 +74,7 @@ export const FormItem: ISchema = {
},
layout: {
type: 'string',
enum: ['vertical', 'horizontal', 'inline', ''],
enum: ['vertical', 'horizontal', 'inline', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -84,7 +84,7 @@ export const FormItem: ISchema = {

tooltipLayout: {
type: 'string',
enum: ['icon', 'text', ''],
enum: ['icon', 'text', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -93,7 +93,7 @@ export const FormItem: ISchema = {
},
labelAlign: {
type: 'string',
enum: ['left', 'right', ''],
enum: ['left', 'right', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -102,7 +102,7 @@ export const FormItem: ISchema = {
},
wrapperAlign: {
type: 'string',
enum: ['left', 'right', ''],
enum: ['left', 'right', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
12 changes: 6 additions & 6 deletions designable/antd/src/schemas/FormLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const FormLayout: ISchema = {
},
feedbackLayout: {
type: 'string',
enum: ['loose', 'terse', 'popover', 'none', ''],
enum: ['loose', 'terse', 'popover', 'none', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -40,7 +40,7 @@ export const FormLayout: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'default', ''],
enum: ['large', 'small', 'default', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -49,7 +49,7 @@ export const FormLayout: ISchema = {
},
layout: {
type: 'string',
enum: ['vertical', 'horizontal', 'inline', ''],
enum: ['vertical', 'horizontal', 'inline', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -58,7 +58,7 @@ export const FormLayout: ISchema = {
},
tooltipLayout: {
type: 'string',
enum: ['icon', 'text', ''],
enum: ['icon', 'text', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -67,7 +67,7 @@ export const FormLayout: ISchema = {
},
labelAlign: {
type: 'string',
enum: ['left', 'right', ''],
enum: ['left', 'right', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand All @@ -76,7 +76,7 @@ export const FormLayout: ISchema = {
},
wrapperAlign: {
type: 'string',
enum: ['left', 'right', ''],
enum: ['left', 'right', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/FormTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const FormTab: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'default', ''],
enum: ['large', 'small', 'default', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Input: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/NumberPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const NumberPicker: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
6 changes: 3 additions & 3 deletions designable/antd/src/schemas/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export const Select: ISchema = {
properties: {
mode: {
type: 'string',
enum: ['multiple', 'tags', ''],
enum: ['multiple', 'tags', null],
'x-decorator': 'FormItem',
'x-component': 'Radio.Group',
'x-component-props': {
defaultValue: '',
defaultValue: null,
optionType: 'button',
},
},
Expand Down Expand Up @@ -138,7 +138,7 @@ export const Select: ISchema = {

size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/TimePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const CommonTimePickerAPI = {
},
size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
},
Expand Down
2 changes: 1 addition & 1 deletion designable/antd/src/schemas/TreeSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const TreeSelect: ISchema = {
},
size: {
type: 'string',
enum: ['large', 'small', 'middle', ''],
enum: ['large', 'small', 'middle', null],
'x-decorator': 'FormItem',
'x-component': 'Select',
'x-component-props': {
Expand Down
40 changes: 21 additions & 19 deletions packages/antd/src/form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ const useFormItemLayout = (props: IFormItemProps) => {
const layout = useFormLayout()
return {
...props,
layout: props.layout || layout.layout || 'horizontal',
colon: props.colon || layout.colon,
layout: props.layout ?? layout.layout ?? 'horizontal',
colon: props.colon ?? layout.colon,
labelAlign:
layout.layout === 'vertical'
? props.labelAlign || layout.labelAlign || 'left'
: props.labelAlign || layout.labelAlign || 'right',
labelWrap: props.labelWrap || layout.labelWrap,
labelWidth: props.labelWidth || layout.labelWidth,
wrapperWidth: props.wrapperWidth || layout.wrapperWidth,
labelCol: props.labelCol || layout.labelCol,
wrapperCol: props.wrapperCol || layout.wrapperCol,
wrapperAlign: props.wrapperAlign || layout.wrapperAlign,
wrapperWrap: props.wrapperWrap || layout.wrapperWrap,
fullness: props.fullness || layout.fullness,
size: props.size || layout.size,
inset: props.inset || layout.inset,
? props.labelAlign ?? layout.labelAlign ?? 'left'
: props.labelAlign ?? layout.labelAlign ?? 'right',
labelWrap: props.labelWrap ?? layout.labelWrap,
labelWidth: props.labelWidth ?? layout.labelWidth,
wrapperWidth: props.wrapperWidth ?? layout.wrapperWidth,
labelCol: props.labelCol ?? layout.labelCol,
wrapperCol: props.wrapperCol ?? layout.wrapperCol,
wrapperAlign: props.wrapperAlign ?? layout.wrapperAlign,
wrapperWrap: props.wrapperWrap ?? layout.wrapperWrap,
fullness: props.fullness ?? layout.fullness,
size: props.size ?? layout.size,
inset: props.inset ?? layout.inset,
asterisk: props.asterisk,
bordered: props.bordered || layout.bordered,
bordered: props.bordered ?? layout.bordered,
feedbackIcon: props.feedbackIcon,
feedbackLayout: props.feedbackLayout || layout.feedbackLayout || 'loose',
tooltipLayout: props.tooltipLayout || layout.tooltipLayout || 'icon',
feedbackLayout: props.feedbackLayout ?? layout.feedbackLayout ?? 'loose',
tooltipLayout: props.tooltipLayout ?? layout.tooltipLayout ?? 'icon',
}
}

Expand Down Expand Up @@ -248,7 +248,7 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
}

const renderLabel = () => {
if (!label || label === ' ') return null
if (!label) return null
return (
<div
className={cls({
Expand All @@ -261,7 +261,9 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
>
{renderLabelText()}
{renderTooltipIcon()}
<span className={cls(`${prefixCls}-colon`)}>{colon ? ':' : ''}</span>
{label !== ' ' && (
<span className={cls(`${prefixCls}-colon`)}>{colon ? ':' : ''}</span>
)}
</div>
)
}
Expand Down
40 changes: 21 additions & 19 deletions packages/next/src/form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ const useFormItemLayout = (props: IFormItemProps) => {
const layout = useFormLayout()
return {
...props,
layout: props.layout || layout.layout || 'horizontal',
colon: props.colon || layout.colon,
layout: props.layout ?? layout.layout ?? 'horizontal',
colon: props.colon ?? layout.colon,
labelAlign:
layout.layout === 'vertical'
? props.labelAlign || layout.labelAlign || 'left'
: props.labelAlign || layout.labelAlign || 'right',
labelWrap: props.labelWrap || layout.labelWrap,
labelWidth: props.labelWidth || layout.labelWidth,
wrapperWidth: props.wrapperWidth || layout.wrapperWidth,
labelCol: props.labelCol || layout.labelCol,
wrapperCol: props.wrapperCol || layout.wrapperCol,
wrapperAlign: props.wrapperAlign || layout.wrapperAlign,
wrapperWrap: props.wrapperWrap || layout.wrapperWrap,
fullness: props.fullness || layout.fullness,
size: props.size || layout.size,
inset: props.inset || layout.inset,
? props.labelAlign ?? layout.labelAlign ?? 'left'
: props.labelAlign ?? layout.labelAlign ?? 'right',
labelWrap: props.labelWrap ?? layout.labelWrap,
labelWidth: props.labelWidth ?? layout.labelWidth,
wrapperWidth: props.wrapperWidth ?? layout.wrapperWidth,
labelCol: props.labelCol ?? layout.labelCol,
wrapperCol: props.wrapperCol ?? layout.wrapperCol,
wrapperAlign: props.wrapperAlign ?? layout.wrapperAlign,
wrapperWrap: props.wrapperWrap ?? layout.wrapperWrap,
fullness: props.fullness ?? layout.fullness,
size: props.size ?? layout.size,
inset: props.inset ?? layout.inset,
asterisk: props.asterisk,
bordered: props.bordered || layout.bordered,
bordered: props.bordered ?? layout.bordered,
feedbackIcon: props.feedbackIcon,
feedbackLayout: props.feedbackLayout || layout.feedbackLayout || 'loose',
tooltipLayout: props.tooltipLayout || layout.tooltipLayout || 'icon',
feedbackLayout: props.feedbackLayout ?? layout.feedbackLayout ?? 'loose',
tooltipLayout: props.tooltipLayout ?? layout.tooltipLayout ?? 'icon',
}
}

Expand Down Expand Up @@ -243,7 +243,7 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
}

const renderLabel = () => {
if (!label || label === ' ') return null
if (!label) return null
return (
<div
className={cls({
Expand All @@ -256,7 +256,9 @@ export const BaseItem: React.FC<IFormItemProps> = (props) => {
>
{renderLabelText()}
{renderTooltipIcon()}
<span className={cls(`${prefixCls}-colon`)}>{colon ? ':' : ''}</span>
{label !== ' ' && (
<span className={cls(`${prefixCls}-colon`)}>{colon ? ':' : ''}</span>
)}
</div>
)
}
Expand Down

0 comments on commit ee4fc5f

Please sign in to comment.