diff --git a/.changeset/hungry-shirts-laugh.md b/.changeset/hungry-shirts-laugh.md new file mode 100644 index 0000000000..8221e807e3 --- /dev/null +++ b/.changeset/hungry-shirts-laugh.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/descriptions": minor +--- + +feat: Add contentPosition api diff --git a/.changeset/shaggy-vans-drive.md b/.changeset/shaggy-vans-drive.md new file mode 100644 index 0000000000..d3348da5ed --- /dev/null +++ b/.changeset/shaggy-vans-drive.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +feat(descriptions): Add contentPosition api diff --git a/packages/ui/descriptions/src/Cell.tsx b/packages/ui/descriptions/src/Cell.tsx index fc1a23582d..1f13a7c9f7 100644 --- a/packages/ui/descriptions/src/Cell.tsx +++ b/packages/ui/descriptions/src/Cell.tsx @@ -1,6 +1,7 @@ import * as React from 'react' import { cx, getPrefixStyleVar } from '@hi-ui/classname' import { isNullish } from '@hi-ui/type-assertion' +import { ContentPosition } from './types' export const Cell: React.FC = ({ itemPrefixCls, @@ -14,6 +15,7 @@ export const Cell: React.FC = ({ content, labelWidth, cellColumnGap, + contentPosition: contentPositionProp = 'top', }) => { const Component: any = component @@ -41,6 +43,13 @@ export const Cell: React.FC = ({ ) } + const contentPosition = { + top: 'start', + center: 'center', + bottom: 'end', + }[contentPositionProp] + console.log('contentPosition', contentPosition) + return (
= ({ style={{ [`${getPrefixStyleVar('container-padding-right')}`]: typeof cellColumnGap === 'number' ? cellColumnGap + 'px' : cellColumnGap, + [`${getPrefixStyleVar('container-align-items')}`]: contentPosition, }} > {!isNullish(label) && ( @@ -75,4 +85,5 @@ export interface CellProps { content?: React.ReactNode labelWidth?: React.ReactText cellColumnGap?: React.ReactText + contentPosition?: ContentPosition } diff --git a/packages/ui/descriptions/src/Descriptions.tsx b/packages/ui/descriptions/src/Descriptions.tsx index 9220da7686..ef4dce5941 100644 --- a/packages/ui/descriptions/src/Descriptions.tsx +++ b/packages/ui/descriptions/src/Descriptions.tsx @@ -5,6 +5,7 @@ import { HiBaseHTMLProps } from '@hi-ui/core' import { cloneElement, toArray } from './util' import { Row } from './Row' import { + ContentPosition, DescriptionsAppearanceEnum, DescriptionsLabelPlacementEnum, DescriptionsPlacementEnum, @@ -31,6 +32,7 @@ export const Descriptions = forwardRef labelWidth, columnGap, size = 'md', + contentPosition = 'top', ...rest }, ref @@ -68,6 +70,7 @@ export const Descriptions = forwardRef labelPlacement={labelPlacement} rootLabelWidth={labelWidth} cellColumnGap={columnGap} + contentPosition={contentPosition} /> ))} @@ -111,6 +114,10 @@ export interface DescriptionsProps extends HiBaseHTMLProps<'div'> { * 设置大小 */ size?: 'md' | 'sm' + /** + * 在 horizontal 放置时,标签相对内容垂直对齐的方式 + */ + contentPosition?: ContentPosition } if (__DEV__) { diff --git a/packages/ui/descriptions/src/Row.tsx b/packages/ui/descriptions/src/Row.tsx index c5117cb42a..d448b5ad71 100644 --- a/packages/ui/descriptions/src/Row.tsx +++ b/packages/ui/descriptions/src/Row.tsx @@ -1,6 +1,7 @@ import * as React from 'react' import { DescriptionsItemProps } from './DescriptionsItem' import { Cell } from './Cell' +import { ContentPosition } from './types' export const Row: React.FC = (props) => { const { prefixCls, vertical, row, index, bordered, noBackground } = props @@ -50,6 +51,7 @@ export interface RowProps { labelPlacement?: 'left' | 'center' | 'right' rootLabelWidth?: React.ReactText cellColumnGap?: React.ReactText + contentPosition?: ContentPosition } interface CellConfig { @@ -67,6 +69,7 @@ function renderCols( labelPlacement: labelPlacementContext, rootLabelWidth, cellColumnGap, + contentPosition, }: RowProps, { component, type, showLabel, showContent }: CellConfig ) { @@ -103,6 +106,7 @@ function renderCols( content={showContent ? children : null} labelWidth={labelWidth ?? rootLabelWidth} cellColumnGap={index === items.length - 1 ? 0 : cellColumnGap} + contentPosition={contentPosition} /> ) } @@ -119,6 +123,7 @@ function renderCols( bordered={bordered} label={label} labelWidth={labelWidth ?? rootLabelWidth} + contentPosition={contentPosition} />, , ] } diff --git a/packages/ui/descriptions/src/styles/descriptions.scss b/packages/ui/descriptions/src/styles/descriptions.scss index d0d9a7ecb0..16607883a3 100644 --- a/packages/ui/descriptions/src/styles/descriptions.scss +++ b/packages/ui/descriptions/src/styles/descriptions.scss @@ -36,6 +36,7 @@ $prefix: '#{$component-prefix}-descriptions' !default; &__container { box-sizing: border-box; display: flex; + align-items: var(--hi-v4-container-align-items, normal); padding-right: var(--hi-v4-container-padding-right, 0); } diff --git a/packages/ui/descriptions/src/types.ts b/packages/ui/descriptions/src/types.ts index d42d7fb5e3..1767ea76d6 100644 --- a/packages/ui/descriptions/src/types.ts +++ b/packages/ui/descriptions/src/types.ts @@ -3,3 +3,5 @@ export type DescriptionsPlacementEnum = 'horizontal' | 'vertical' | undefined export type DescriptionsAppearanceEnum = 'table' | 'unset' | undefined export type DescriptionsLabelPlacementEnum = 'left' | 'right' | undefined + +export type ContentPosition = 'top' | 'center' | 'bottom' diff --git a/packages/ui/descriptions/stories/content-position.stories.tsx b/packages/ui/descriptions/stories/content-position.stories.tsx new file mode 100644 index 0000000000..93d99c5cbf --- /dev/null +++ b/packages/ui/descriptions/stories/content-position.stories.tsx @@ -0,0 +1,91 @@ +import React from 'react' +import Descriptions from '../src' +import Preview from '@hi-ui/preview' +import { JpgColorful } from '@hi-ui/icons' + +/** + * @title 设置标签和内容对齐方式 + */ +export const ContentPosition = () => { + const [images] = React.useState([ + 'http://i1.mifile.cn/f/i/hiui/docs/card/pic_1.png', + 'http://i1.mifile.cn/f/i/hiui/docs/card/pic_2.png', + 'http://i1.mifile.cn/f/i/hiui/docs/card/pic_3.png', + ]) + const [visible, setVisible] = React.useState(false) + const [current, setCurrent] = React.useState(0) + + return ( + <> +

ContentPosition

+
+

md

+ + + 第三方网点 + + + 主站 + + + 有效 + + + 某某有限公司 + + + 是 + + + + + + 备注内容可能会非常长备注内容可能会非常长备注内容可能会非常长 + + + { + setCurrent(0) + setVisible(true) + }} + /> + { + setCurrent(1) + setVisible(true) + }} + /> + { + setCurrent(2) + setVisible(true) + }} + /> + + + + { + setVisible(false) + }} + /> +
+ + ) +} diff --git a/packages/ui/descriptions/stories/index.stories.tsx b/packages/ui/descriptions/stories/index.stories.tsx index 1cd29d4676..dbcc362ac3 100644 --- a/packages/ui/descriptions/stories/index.stories.tsx +++ b/packages/ui/descriptions/stories/index.stories.tsx @@ -5,6 +5,7 @@ export * from './config.stories' export * from './ellipsis.stories' export * from './bordered.stories' export * from './label-placement.stories' +export * from './content-position.stories' export * from './col.stories' export * from './vertical.stories' export * from './vertical-border.stories'