Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(descriptions): 新增支持自定义列间距功能(#2796) #2800

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-rats-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/descriptions": minor
---

feat: 新增支持自定义列间距功能
5 changes: 5 additions & 0 deletions .changeset/nice-humans-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/check-select": patch
---

fix: 修复 onClear 设置后没触发问题
5 changes: 5 additions & 0 deletions .changeset/rotten-starfishes-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": minor
---

feat(descriptions): 新增支持自定义列间距功能
5 changes: 5 additions & 0 deletions .changeset/young-donkeys-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

fix(check-select): 修复 onClear 设置后没触发问题
2 changes: 2 additions & 0 deletions packages/ui/check-select/src/CheckSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const CheckSelect = forwardRef<HTMLDivElement | null, CheckSelectProps>(
visible,
onOpen,
onClose,
onClear,
// picker
appearance,
invalid,
Expand Down Expand Up @@ -316,6 +317,7 @@ export const CheckSelect = forwardRef<HTMLDivElement | null, CheckSelectProps>(
value={value}
// @ts-ignore
onChange={tryChangeValue}
onClear={onClear}
data={mergedData}
invalid={invalid}
onClick={(evt) => {
Expand Down
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