Skip to content

Commit

Permalink
feat(descriptions): 新增支持自定义列间距功能(XiaoMi#2796)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiamiao committed Apr 18, 2024
1 parent 234687e commit 4046a04
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/ui/descriptions/src/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const Cell: React.FC<CellProps> = ({
label,
content,
labelWidth,
cellColumnGap,
}) => {
const Component: any = component

if (bordered) {
const compareStyle =
!isNullish(labelWidth) && !isNullish(label)
Expand All @@ -42,7 +42,7 @@ export const Cell: React.FC<CellProps> = ({

return (
<Component className={cx(`${itemPrefixCls}-item`, className)} style={style} colSpan={colSpan}>
<div className={`${itemPrefixCls}-item__container`}>
<div className={`${itemPrefixCls}-item__container`} style={{ paddingRight: cellColumnGap }}>
{!isNullish(label) && (
<span className={cx(`${itemPrefixCls}-item__label`)} style={{ width: labelWidth }}>
{label}
Expand All @@ -67,4 +67,5 @@ export interface CellProps {
label?: React.ReactNode
content?: React.ReactNode
labelWidth?: React.ReactText
cellColumnGap?: React.ReactText
}
7 changes: 7 additions & 0 deletions packages/ui/descriptions/src/Descriptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const Descriptions = forwardRef<HTMLDivElement | null, DescriptionsProps>
appearance = 'unset',
labelPlacement = 'left',
labelWidth,
columnGap,
size = 'md',
...rest
},
Expand Down Expand Up @@ -66,6 +67,7 @@ export const Descriptions = forwardRef<HTMLDivElement | null, DescriptionsProps>
noBackground={noBackground}
labelPlacement={labelPlacement}
rootLabelWidth={labelWidth}
cellColumnGap={columnGap}
/>
))}
</tbody>
Expand Down Expand Up @@ -100,6 +102,11 @@ export interface DescriptionsProps extends HiBaseHTMLProps<'div'> {
* label宽度
*/
labelWidth?: React.ReactText
/**
* 单元格列间距
* 注:在无边框场景下生效
*/
columnGap?: React.ReactText
/**
* 设置大小
*/
Expand Down
10 changes: 9 additions & 1 deletion packages/ui/descriptions/src/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface RowProps {
noBackground?: boolean
labelPlacement?: 'left' | 'center' | 'right'
rootLabelWidth?: React.ReactText
cellColumnGap?: React.ReactText
}

interface CellConfig {
Expand All @@ -60,7 +61,13 @@ interface CellConfig {

function renderCols(
items: React.ReactElement<DescriptionsItemProps>[],
{ prefixCls, bordered, labelPlacement: labelPlacementContext, rootLabelWidth }: RowProps,
{
prefixCls,
bordered,
labelPlacement: labelPlacementContext,
rootLabelWidth,
cellColumnGap,
}: RowProps,
{ component, type, showLabel, showContent }: CellConfig
) {
return items.map(
Expand Down Expand Up @@ -95,6 +102,7 @@ function renderCols(
label={showLabel ? label : null}
content={showContent ? children : null}
labelWidth={labelWidth ?? rootLabelWidth}
cellColumnGap={index === items.length - 1 ? 0 : cellColumnGap}
/>
)
}
Expand Down

0 comments on commit 4046a04

Please sign in to comment.