Skip to content

Commit

Permalink
feat: containerStyle configuration add padding prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mengshang918 committed Mar 10, 2022
1 parent fcbbf9d commit 27cefed
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/drip-form/src/render/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Author: jiangxiaowei
* @Date: 2021-07-30 16:35:48
* @Last Modified by: jiangxiaowei
* @Last Modified time: 2022-03-02 16:35:49
* @Last Modified time: 2022-03-10 18:22:15
*/
import React from 'react'
import type { RenderFnProps } from './type'
Expand Down Expand Up @@ -36,7 +36,7 @@ const Render = ({
theme = 'antd',
title: globalTitleUi = {},
formMode = 'edit',
containerStyle: globalContainerStyle = { width: '100%' },
containerStyle: globalContainerStyle,
} = uiSchema
// 当前父级UiSchema
const currentUiSchema = parentUiSchemaKey.reduce((prev, cur) => {
Expand Down Expand Up @@ -160,7 +160,7 @@ const Render = ({
type === 'object' && properties[item]?.mode === 'collapse'
? { marginBottom: 20 }
: {},
isRoot ? globalContainerStyle : {},
isRoot ? { width: '100%', ...globalContainerStyle } : {},
properties[item]?.containerStyle || {}
)
// 当前Field所接收的ui props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const PropertyConfig = () => {
* 监听配置区修改,实时更新到渲染区
*/
const onChangeSchema = useCallback(
({ changeKey, get }) => {
({ changeKey, get, set }) => {
// 当chengKey为空字符串时,认为为ajv校验或初始化执行的操作,不做实时更新
if (changeKey === '') return
// 当前修改的字段处理为为可映射到渲染区schema的路径
Expand Down Expand Up @@ -189,6 +189,10 @@ const PropertyConfig = () => {
key = 'ui.options'
}
if (changeKey === 'containerStyle.width') {
// 更改全局布局宽度时,如果选用多列并且未设置padding,则自动设置
if (type === 'root' && data !== 100 && !get().data.padding) {
set('containerStyle.padding', 'data', '0 10px 0 0')
}
// TODO @jiangxiaowei 后续支持px、vw
data = data + '%'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ const unitedSchema = {
placeholder: '形如0 30px 20px 0 | 0 30px',
},
},
{
fieldKey: 'padding',
type: 'string',
title: '组件内边距',
ui: {
type: 'text',
placeholder: '形如0 10px 0 10px | 0 10px',
},
},
],
}

Expand Down
9 changes: 9 additions & 0 deletions packages/generator/src/fields/container/root.field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ const unitedSchema = [
placeholder: '形如0 30px 20px 0 | 0 30px',
},
},
{
fieldKey: 'padding',
type: 'string',
title: '组件内边距',
ui: {
type: 'text',
placeholder: '形如0 10px 0 10px | 0 10px',
},
},
],
},
{
Expand Down
6 changes: 6 additions & 0 deletions packages/utils/src/schemaHandle/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export type ContainerStyle = Partial<{
marginLeft: number | string
// 容器margin
margin: string
// 容器padding
padding: string
paddingTop: number | string
paddingBottom: number | string
paddingRigth: number | string
paddingLeft: number | string
}> | null
export type Description = {
type: 'icon' | 'text'
Expand Down

0 comments on commit 27cefed

Please sign in to comment.