Skip to content

Commit a9119d1

Browse files
fix(Cell): fix component style errors (#568)
* fix(Cell): fix component style errors * chore: update docs * chore: update common * chore: update snapshot * chore: fix doc --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d2583ed commit a9119d1

File tree

12 files changed

+559
-492
lines changed

12 files changed

+559
-492
lines changed

script/generate-css-vars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function resolveCwd(...args) {
55
args.unshift(process.cwd());
66
return path.join(...args);
77
}
8-
8+
// node script/generate-css-vars.js --NAME Cell
99
const COMPONENT_NAME = process.argv[process.argv.indexOf('--NAME') + 1]; // 在 --NAME 后面
1010

1111
// 组件名作为参数传入

src/cell/Cell.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import classnames from 'classnames';
33
import isString from 'lodash/isString';
44
import { ChevronRightIcon } from 'tdesign-icons-react';
55

6+
import parseTNode from '../_util/parseTNode';
67
import { TdCellProps } from './type';
78
import { cellDefaultProps } from './defaultProps';
89
import withNativeProps, { NativeProps } from '../_util/withNativeProps';
@@ -37,12 +38,11 @@ const Cell: React.FC<CellProps> = (originProps) => {
3738
const classNames = useMemo(
3839
() => [
3940
`${name}`,
40-
`${name}--${align}`,
4141
{
4242
[`${name}--borderless`]: !bordered,
4343
},
4444
],
45-
[align, bordered, name],
45+
[bordered, name],
4646
);
4747

4848
const hoverDisabled = useMemo(() => !hover, [hover]);
@@ -55,41 +55,41 @@ const Cell: React.FC<CellProps> = (originProps) => {
5555
[onClick],
5656
);
5757

58-
const readerImage = () => {
58+
const renderImage = () => {
5959
if (isString(image)) {
6060
return <img src={image} className={`${name}__left-image`} />;
6161
}
62-
return image;
62+
return parseTNode(image);
6363
};
6464

65-
const readerLeft = () => (
65+
const renderLeft = () => (
6666
<div className={`${name}__left`}>
67-
{leftIcon && <div className={`${name}__left-icon`}>{leftIcon}</div>}
68-
{readerImage()}
67+
{leftIcon && <div className={`${name}__left-icon`}>{parseTNode(leftIcon)}</div>}
68+
{renderImage()}
6969
</div>
7070
);
7171

72-
const readerTitle = () => {
72+
const renderTitle = () => {
7373
if (!title) {
7474
return null;
7575
}
7676
return (
7777
<div className={`${name}__title`}>
7878
<div className={`${name}__title-text`}>
79-
{title}
79+
{parseTNode(title)}
8080
{required && <span className={`${name}--required`}>&nbsp;*</span>}
8181
</div>
82-
{description && <div className={`${name}__description`}>{description}</div>}
82+
{description && <div className={`${name}__description`}>{parseTNode(description)}</div>}
8383
</div>
8484
);
8585
};
86-
const readerRight = () => {
87-
const Icon = arrow ? <ChevronRightIcon /> : rightIcon;
86+
const renderRight = () => {
87+
const Icon = arrow ? <ChevronRightIcon /> : parseTNode(rightIcon);
8888
if (!Icon) {
8989
return null;
9090
}
9191
return (
92-
<div className={`${name}__right`}>
92+
<div className={classnames(`${name}__right`, `${name}__right--${align}`)}>
9393
<div className={`${name}__right-icon`}>{Icon}</div>
9494
</div>
9595
);
@@ -98,10 +98,10 @@ const Cell: React.FC<CellProps> = (originProps) => {
9898
return withNativeProps(
9999
props,
100100
<div ref={ref} className={classnames(classNames)} onClick={handleClick}>
101-
{readerLeft()}
102-
{readerTitle()}
103-
{note ? <div className={`${name}__note`}>{note}</div> : children}
104-
{readerRight()}
101+
{renderLeft()}
102+
{renderTitle()}
103+
{note ? <div className={`${name}__note`}>{parseTNode(note)}</div> : parseTNode(children)}
104+
{renderRight()}
105105
</div>,
106106
);
107107
};

src/cell/CellGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TdCellGroupProps } from './type';
55
import { cellGroupDefaultProps } from './defaultProps';
66
import withNativeProps, { NativeProps } from '../_util/withNativeProps';
77
import useDefaultProps from '../hooks/useDefaultProps';
8+
import parseTNode from '../_util/parseTNode';
89

910
export type CellGroupProps = TdCellGroupProps & NativeProps;
1011

@@ -29,7 +30,7 @@ const CellGroup: React.FC<CellGroupProps> = (originProps) => {
2930
props,
3031
<div>
3132
{title && <div className={`${name}__title`}>{title}</div>}
32-
<div className={classnames(classNames)}>{children}</div>
33+
<div className={classnames(classNames)}>{parseTNode(children)}</div>
3334
</div>,
3435
);
3536
};

src/cell/_example/group.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { CellGroup, Cell } from 'tdesign-mobile-react';
3-
import { LockOnIcon, ServiceIcon, InternetIcon } from 'tdesign-icons-react';
3+
import { AppIcon, ServiceIcon, InternetIcon } from 'tdesign-icons-react';
44

55
export default function Group() {
66
return (
77
<CellGroup theme="card">
8-
<Cell leftIcon={<LockOnIcon />} title="单行标题" arrow />
8+
<Cell leftIcon={<AppIcon />} title="单行标题" arrow />
99
<Cell leftIcon={<ServiceIcon />} title="单行标题" arrow />
1010
<Cell leftIcon={<InternetIcon />} title="单行标题" arrow />
1111
</CellGroup>

src/cell/_example/multiple.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { CellGroup, Cell, Badge, Switch, Avatar } from 'tdesign-mobile-react';
3-
import { ChevronRightIcon, LockOnIcon } from 'tdesign-icons-react';
3+
import { ChevronRightIcon, AppIcon } from 'tdesign-icons-react';
44

55
export default function Multiple() {
66
const chevronRightIcon = <ChevronRightIcon />;
@@ -14,19 +14,19 @@ export default function Multiple() {
1414
<Cell title="单行标题" description="一段很长很长的内容文字" arrow note={<Badge count={16} />} />
1515
<Cell title="单行标题" description="一段很长很长的内容文字" note={<Switch defaultValue={true} />} />
1616
<Cell title="单行标题" description="一段很长很长的内容文字" note="辅助信息" arrow />
17-
<Cell title="单行标题" description="一段很长很长的内容文字" arrow leftIcon={<LockOnIcon />} />
17+
<Cell title="单行标题" description="一段很长很长的内容文字" arrow leftIcon={<AppIcon />} />
1818
<Cell title="单行标题" description="一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容" />
1919
<Cell
2020
title="多行高度不定,长文本自动换行,该选项的描述是一段很长的内容"
2121
description="一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容"
2222
/>
2323
<Cell
24-
title="多行带头像"
24+
title="单行标题"
2525
description="一段很长很长的内容文字"
2626
leftIcon={<Avatar shape="circle" image={avatarUrl} />}
2727
rightIcon={chevronRightIcon}
2828
/>
29-
<Cell title="多行带图片" description="一段很长很长的内容文字" image={imgUrl} />
29+
<Cell title="单行标题" description="一段很长很长的内容文字" image={imgUrl} />
3030
</CellGroup>
3131
);
3232
}

src/cell/_example/single.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { Cell, CellGroup, Badge, Switch } from 'tdesign-mobile-react';
3-
import { LockOnIcon } from 'tdesign-icons-react';
3+
import { AppIcon } from 'tdesign-icons-react';
44

55
export default function Single() {
66
return (
@@ -13,7 +13,7 @@ export default function Single() {
1313
<Cell title="单行标题" hover note={<Switch default-value={true} />} />
1414
<Cell title="单行标题" arrow hover note="辅助信息" />
1515

16-
<Cell title="单行标题" arrow hover leftIcon={<LockOnIcon />} />
16+
<Cell title="单行标题" arrow hover leftIcon={<AppIcon />} />
1717
</CellGroup>
1818
</div>
1919
);

src/cell/cell.en-US.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,39 @@ style | Object | - | CSS(Cascading Style Sheets),Typescript:`React.CSSProper
3131
bordered | Boolean | false | \- | N
3232
theme | String | default | options: default/card | N
3333
title | String | - | \- | N
34+
35+
### CSS Variables
36+
37+
The component provides the following CSS variables, which can be used to customize styles.
38+
Name | Default Value | Description
39+
-- | -- | --
40+
--td-border-left-space | @cell-horizontal-padding | -
41+
--td-cell-bg-color | @bg-color-container | -
42+
--td-cell-border-color | @component-stroke | -
43+
--td-cell-border-right-space | 0 | -
44+
--td-cell-description-color | @text-color-secondary | -
45+
--td-cell-description-font-size | @font-size-base | -
46+
--td-cell-description-line-height | 22px | -
47+
--td-cell-group-border-color | @border-color | -
48+
--td-cell-group-title-bg-color | @bg-color-secondarycontainer | -
49+
--td-cell-group-title-color | @text-color-placeholder | -
50+
--td-cell-group-title-font-size | 14px | -
51+
--td-cell-group-title-line-height | 45px | -
52+
--td-cell-group-title-padding-left | 16px | -
53+
--td-cell-height | auto | -
54+
--td-cell-horizontal-padding | 16px | -
55+
--td-cell-hover-color | @bg-color-secondarycontainer | -
56+
--td-cell-image-height | 48px | -
57+
--td-cell-image-width | 48px | -
58+
--td-cell-left-icon-color | @brand-color | -
59+
--td-cell-left-icon-font-size | 24px | -
60+
--td-cell-line-height | 24px | -
61+
--td-cell-note-color | @text-color-placeholder | -
62+
--td-cell-note-font-size | @font-size-m | -
63+
--td-cell-required-color | @error-color-6 | -
64+
--td-cell-required-font-size | @font-size-m | -
65+
--td-cell-right-icon-color | @text-color-placeholder | -
66+
--td-cell-right-icon-font-size | 24px | -
67+
--td-cell-title-color | @text-color-primary | -
68+
--td-cell-title-font-size | @font-size-m | -
69+
--td-cell-vertical-padding | 16px | -

src/cell/cell.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
---
2-
title: Cell 宫格
3-
description: 用于各个类别行的信息展示。
4-
spline: base
5-
isComponent: true
6-
toc: false
7-
---
1+
:: BASE_DOC ::
82

93
## API
104

@@ -14,7 +8,7 @@ toc: false
148
-- | -- | -- | -- | --
159
className | String | - | 类名 | N
1610
style | Object | - | 样式,TS 类型:`React.CSSProperties` | N
17-
align | String | middle | 内容的对齐方式,默认居中对齐。可选项:top/middle/bottom | N
11+
align | String | middle | 右侧内容的对齐方式,默认居中对齐。可选项:top/middle/bottom | N
1812
arrow | Boolean | false | 是否显示右侧箭头 | N
1913
bordered | Boolean | true | 是否显示下边框 | N
2014
description | TNode | - | 下方内容描述。TS 类型:`string \| TNode`[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N
@@ -37,3 +31,39 @@ style | Object | - | 样式,TS 类型:`React.CSSProperties` | N
3731
bordered | Boolean | false | 是否显示组边框 | N
3832
theme | String | default | 单元格组风格。可选项:default/card | N
3933
title | String | - | 单元格组标题 | N
34+
35+
### CSS Variables
36+
37+
组件提供了下列 CSS 变量,可用于自定义样式。
38+
名称 | 默认值 | 描述
39+
-- | -- | --
40+
--td-border-left-space | @cell-horizontal-padding | -
41+
--td-cell-bg-color | @bg-color-container | -
42+
--td-cell-border-color | @component-stroke | -
43+
--td-cell-border-right-space | 0 | -
44+
--td-cell-description-color | @text-color-secondary | -
45+
--td-cell-description-font-size | @font-size-base | -
46+
--td-cell-description-line-height | 22px | -
47+
--td-cell-group-border-color | @border-color | -
48+
--td-cell-group-title-bg-color | @bg-color-secondarycontainer | -
49+
--td-cell-group-title-color | @text-color-placeholder | -
50+
--td-cell-group-title-font-size | 14px | -
51+
--td-cell-group-title-line-height | 45px | -
52+
--td-cell-group-title-padding-left | 16px | -
53+
--td-cell-height | auto | -
54+
--td-cell-horizontal-padding | 16px | -
55+
--td-cell-hover-color | @bg-color-secondarycontainer | -
56+
--td-cell-image-height | 48px | -
57+
--td-cell-image-width | 48px | -
58+
--td-cell-left-icon-color | @brand-color | -
59+
--td-cell-left-icon-font-size | 24px | -
60+
--td-cell-line-height | 24px | -
61+
--td-cell-note-color | @text-color-placeholder | -
62+
--td-cell-note-font-size | @font-size-m | -
63+
--td-cell-required-color | @error-color-6 | -
64+
--td-cell-required-font-size | @font-size-m | -
65+
--td-cell-right-icon-color | @text-color-placeholder | -
66+
--td-cell-right-icon-font-size | 24px | -
67+
--td-cell-title-color | @text-color-primary | -
68+
--td-cell-title-font-size | @font-size-m | -
69+
--td-cell-vertical-padding | 16px | -

src/cell/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MouseEvent } from 'react';
99

1010
export interface TdCellProps {
1111
/**
12-
* 内容的对齐方式,默认居中对齐
12+
* 右侧内容的对齐方式,默认居中对齐
1313
* @default middle
1414
*/
1515
align?: 'top' | 'middle' | 'bottom';

0 commit comments

Comments
 (0)