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): add size api #2591

Merged
merged 1 commit into from
Sep 19, 2023
Merged
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/flat-insects-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/descriptions": minor
---

feat: add size api
5 changes: 5 additions & 0 deletions .changeset/selfish-islands-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hi-ui/hiui": patch
---

Descriptions feat: add size api
6 changes: 6 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,
size = 'md',
...rest
},
ref
Expand All @@ -46,6 +47,7 @@ export const Descriptions = forwardRef<HTMLDivElement | null, DescriptionsProps>
appearance && `${prefixCls}--appearance-${appearance}`,
placement && `${prefixCls}--placement-${placement}`,
labelPlacement && `${prefixCls}--label-placement-${labelPlacement}`,
`${prefixCls}--size-${size}`,
className
)

Expand Down Expand Up @@ -98,6 +100,10 @@ export interface DescriptionsProps extends HiBaseHTMLProps<'div'> {
* label宽度
*/
labelWidth?: React.ReactText
/**
* 设置大小
*/
size?: 'md' | 'sm'
}

if (__DEV__) {
Expand Down
16 changes: 13 additions & 3 deletions packages/ui/descriptions/src/styles/descriptions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ $prefix: '#{$component-prefix}-descriptions' !default;
> th,
> td {
box-sizing: border-box;
padding: 0;
font-weight: use-text-weight('normal');
}

Expand Down Expand Up @@ -59,9 +60,18 @@ $prefix: '#{$component-prefix}-descriptions' !default;

&--placement {
&-horizontal {
.#{$prefix}-row > th,
.#{$prefix}-row > td {
padding-bottom: use-spacing(6);
&.#{$prefix}--size-md {
.#{$prefix}-row > th,
.#{$prefix}-row > td {
padding-bottom: use-spacing(6);
}
}

&.#{$prefix}--size-sm {
.#{$prefix}-row > th,
.#{$prefix}-row > td {
padding-bottom: use-spacing(2);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/ui/descriptions/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export * from './col.stories'
export * from './vertical.stories'
export * from './vertical-border.stories'
export * from './label-width.stories'
export * from './size.stories'

export default {
title: 'Data Display/Descriptions',
Expand Down
146 changes: 146 additions & 0 deletions packages/ui/descriptions/stories/size.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import React from 'react'
import Descriptions from '../src'
import Preview from '@hi-ui/preview'
import { JpgColorful } from '@hi-ui/icons'

/**
* @title 设置大小
*/
export const Size = () => {
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 (
<>
<h1>Size</h1>
<div className="descriptions-size__wrap">
<h2>md</h2>
<Descriptions size="md">
<Descriptions.Item label="机构类型" labelWidth={84}>
第三方网点
</Descriptions.Item>
<Descriptions.Item label="主子站类型" labelWidth={84}>
主站
</Descriptions.Item>
<Descriptions.Item label="机构状态" labelWidth={84}>
有效
</Descriptions.Item>
<Descriptions.Item label="机构名称" labelWidth={84}>
某某有限公司
</Descriptions.Item>
<Descriptions.Item label="是否自营" labelWidth={84}>
</Descriptions.Item>
<Descriptions.Item label="实体门店招牌" labelWidth={84}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<JpgColorful style={{ fontSize: 16 }} />
<a href="#" style={{ textDecoration: 'none', color: '#4a9eff' }}>
主站.jpg
</a>
</div>
</Descriptions.Item>
<Descriptions.Item label="备注信息" labelWidth={84} colSpan={2}>
备注内容可能会非常长备注内容可能会非常长备注内容可能会非常长
</Descriptions.Item>
<Descriptions.Item label="维度名称常规" labelWidth={84}>
<img
src={images[0]}
style={{ width: 40, height: 40, borderRadius: 2, cursor: 'pointer', marginRight: 6 }}
onClick={() => {
setCurrent(0)
setVisible(true)
}}
/>
<img
src={images[1]}
style={{ width: 40, height: 40, borderRadius: 2, cursor: 'pointer', marginRight: 6 }}
onClick={() => {
setCurrent(1)
setVisible(true)
}}
/>
<img
src={images[2]}
style={{ width: 40, height: 40, borderRadius: 2, cursor: 'pointer' }}
onClick={() => {
setCurrent(2)
setVisible(true)
}}
/>
</Descriptions.Item>
</Descriptions>
<h2>sm</h2>
<Descriptions size="sm">
<Descriptions.Item label="机构类型" labelWidth={84}>
第三方网点
</Descriptions.Item>
<Descriptions.Item label="主子站类型" labelWidth={84}>
主站
</Descriptions.Item>
<Descriptions.Item label="机构状态" labelWidth={84}>
有效
</Descriptions.Item>
<Descriptions.Item label="机构名称" labelWidth={84}>
某某有限公司
</Descriptions.Item>
<Descriptions.Item label="是否自营" labelWidth={84}>
</Descriptions.Item>
<Descriptions.Item label="实体门店招牌" labelWidth={84}>
<div style={{ display: 'flex', alignItems: 'center' }}>
<JpgColorful style={{ fontSize: 16 }} />
<a href="#" style={{ textDecoration: 'none', color: '#4a9eff' }}>
主站.jpg
</a>
</div>
</Descriptions.Item>
<Descriptions.Item label="备注信息" labelWidth={84} colSpan={2}>
备注内容可能会非常长备注内容可能会非常长备注内容可能会非常长
</Descriptions.Item>
<Descriptions.Item label="维度名称常规" labelWidth={84}>
<img
src={images[0]}
style={{ width: 40, height: 40, borderRadius: 2, cursor: 'pointer', marginRight: 6 }}
onClick={() => {
setCurrent(0)
setVisible(true)
}}
/>
<img
src={images[1]}
style={{ width: 40, height: 40, borderRadius: 2, cursor: 'pointer', marginRight: 6 }}
onClick={() => {
setCurrent(1)
setVisible(true)
}}
/>
<img
src={images[2]}
style={{ width: 40, height: 40, borderRadius: 2, cursor: 'pointer' }}
onClick={() => {
setCurrent(2)
setVisible(true)
}}
/>
</Descriptions.Item>
</Descriptions>

<Preview
title={`${current + 1}/${images.length}`}
src={images}
current={current}
onPreviewChange={setCurrent}
visible={visible}
onClose={() => {
setVisible(false)
}}
/>
</div>
</>
)
}