@doubao-dev/template 0.3.0 → 0.4.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,7 +45,7 @@ export default function ProductCard() {
45
45
  - `header` 配置标题栏右侧操作,类型为 `TemplateCardHeaderProps`,包含 `actionText` / `showAction` / `onActionClick`。
46
46
  - `footer` 配置底部操作区,类型为 `TemplateCardFooterProps`,包含 `primaryActionButton` / `secondaryActionButton`。只传一个按钮时占据整行。
47
47
  - `header`、`footer` 和内容区相互独立。footer 不会影响 `items` 展示数量,内容区也不负责渲染 header/footer。
48
- - 优先使用模板公开的结构化 Props;部分模板保留的 `children` 已废弃,只用于兼容旧代码。
48
+ - 优先使用模板公开的结构化 Props;一个业务语义需要组合多个已知模块时使用 `CompositeCard`,不通过 `children` 自定义卡片布局。
49
49
  - `className` / `style` / `onClick` 作用在卡片根节点。
50
50
  - 模板和 primitives 不声明或暴露组件级 CSS 变量;颜色可以直接消费已有的全局主题 token。
51
51
 
@@ -182,6 +182,76 @@ import { Price } from '@doubao-dev/template/primitives';
182
182
  - `loading` 展示最大宽度为 60% 的扫光占位。
183
183
  - `className` 和 `style` 可用于样式定制。
184
184
 
185
+ ## CompositeCard
186
+
187
+ 组合卡模板,用于一个完整业务语义同时需要多个模板已知模块、但不适合新增专用模板的场景。例如车票预订卡可以按顺序组合行程信息和乘车人选择。
188
+
189
+ ```tsx
190
+ import { CompositeCard } from '@doubao-dev/template';
191
+
192
+ <CompositeCard
193
+ sections={[
194
+ {
195
+ type: 'transit',
196
+ props: {
197
+ items: [
198
+ {
199
+ title: 'G1 · 9月16日 · 二等座',
200
+ departureMain: '07:00',
201
+ departureSub: '北京南',
202
+ transferTop: '4小时36分',
203
+ arrivalMain: '11:36',
204
+ arrivalSub: '上海虹桥',
205
+ price: '¥553'
206
+ }
207
+ ]
208
+ }
209
+ },
210
+ {
211
+ type: 'content',
212
+ props: {
213
+ items: [
214
+ {
215
+ key: 'passenger-title',
216
+ subtitle: '选择乘车人(多选)'
217
+ }
218
+ ]
219
+ }
220
+ },
221
+ {
222
+ type: 'option-group',
223
+ props: {
224
+ selectionMode: 'multiple',
225
+ maxSelected: 2,
226
+ items: [
227
+ { value: 'wang', title: '王一山' },
228
+ { value: 'zheng', title: '郑天' },
229
+ { value: 'add', title: '添加', icon: 'add' }
230
+ ],
231
+ value: ['wang'],
232
+ onChange: (nextValues) => console.log(nextValues)
233
+ }
234
+ }
235
+ ]}
236
+ footer={{
237
+ primaryActionButton: {
238
+ text: '确认预订',
239
+ onClick: () => console.log('confirm')
240
+ }
241
+ }}
242
+ />
243
+ ```
244
+
245
+ 说明:
246
+
247
+ - `sections` 是单层有序数组,按配置顺序展示;当前白名单支持 `type: 'transit'`、`type: 'content'` 和 `type: 'option-group'`。
248
+ - `content.props.items` 与 `ContentCard.items` 一致,但只渲染 ContentCard 的内容区域,不会产生嵌套卡片外壳。
249
+ - section 不提供独立标题字段;标题、说明等内容通过 `content` section 表达。组合器不开放 `ReactNode`、`children` 或布局参数。
250
+ - section 的 `props` 与对应模块一致,模块原有回调、`className`、`style` 和具名 `ReactNode` 字段仍然可用。`transit.props.items` 支持多个行程。
251
+ - 卡片统一提供标准 header/footer;模块保留自身原有的内容留白、内部布局和窄屏策略,不需要为组合模式单独适配。`OptionGroup` 在组合卡内由专用容器补充左右 12px、下方 16px 的留白,上方不额外留白。
252
+ - `items` 为空的 section 连同间距一起收起;运行时遇到未知 `type` 时不展示该 section。
253
+ - `sections` 不支持运行中插入、删除或重排,因此不要求业务配置 section key。
254
+
185
255
  ## MapCard
186
256
 
187
257
  地图卡模板,由固定高度地图、可选信息区和操作区组成,适合路线预估、叫车状态、位置详情等场景。
@@ -226,7 +296,7 @@ import { MapCard } from '@doubao-dev/template';
226
296
 
227
297
  ## ContentCard
228
298
 
229
- <img src="https://unpkg.com/@doubao-dev/template@0.3.0/assets/content-card.png" alt="ContentCard 示例" width="400" />
299
+ <img src="https://unpkg.com/@doubao-dev/template@0.4.0-rc.5/assets/content-card.png" alt="ContentCard 示例" width="400" />
230
300
 
231
301
  通用列表卡,由标题栏、列表内容和底部操作区组成,适合商品、服务、内容入口等可重复条目。
232
302
 
@@ -268,7 +338,7 @@ import { ContentCard } from '@doubao-dev/template';
268
338
 
269
339
  ## PriceActionCard
270
340
 
271
- <img src="https://unpkg.com/@doubao-dev/template@0.3.0/assets/price-action-card.png" alt="PriceActionCard 示例" width="400" />
341
+ <img src="https://unpkg.com/@doubao-dev/template@0.4.0-rc.5/assets/price-action-card.png" alt="PriceActionCard 示例" width="400" />
272
342
 
273
343
  价格操作卡,由多条"价格 + 信息 + 右侧按钮"组成,适合报价、权益、服务方案等结果列表。
274
344
 
@@ -301,7 +371,7 @@ import { PriceActionCard } from '@doubao-dev/template';
301
371
 
302
372
  ## CheckoutCard
303
373
 
304
- <img src="https://unpkg.com/@doubao-dev/template@0.3.0/assets/checkout-card.png" alt="CheckoutCard 示例" width="400" />
374
+ <img src="https://unpkg.com/@doubao-dev/template@0.4.0-rc.5/assets/checkout-card.png" alt="CheckoutCard 示例" width="400" />
305
375
 
306
376
  通用提单卡,由商品摘要、提单信息、费用汇总和底部操作区组成,适合下单确认、支付确认等场景。
307
377
 
@@ -352,7 +422,7 @@ import { CheckoutCard } from '@doubao-dev/template';
352
422
 
353
423
  ## TicketOrderCard
354
424
 
355
- <img src="https://unpkg.com/@doubao-dev/template@0.3.0/assets/ticket-checkout-card.png" alt="TicketOrderCard 示例" width="400" />
425
+ <img src="https://unpkg.com/@doubao-dev/template@0.4.0-rc.5/assets/ticket-checkout-card.png" alt="TicketOrderCard 示例" width="400" />
356
426
 
357
427
  > **已废弃:** 请使用 `CheckoutCard`。`TicketOrderCard` 仅为兼容现有代码保留。
358
428
 
@@ -399,7 +469,7 @@ import { TicketOrderCard } from '@doubao-dev/template';
399
469
 
400
470
  ## TransitCard
401
471
 
402
- <img src="https://unpkg.com/@doubao-dev/template@0.3.0/assets/transit-card.png" alt="TransitCard 示例" width="400" />
472
+ <img src="https://unpkg.com/@doubao-dev/template@0.4.0-rc.5/assets/transit-card.png" alt="TransitCard 示例" width="400" />
403
473
 
404
474
  交通票务列表卡,由多条出发、中转、到达和价格信息组成,适合展示机票、火车票、大巴等推荐列表。
405
475
 
@@ -444,10 +514,11 @@ import { TransitCard } from '@doubao-dev/template';
444
514
  - `tag` 传 `{ text, tone? }`,`tone` 仅支持红色 `marketing` 和灰色 `neutral`,默认 `marketing`;不传 `tag` 时保持原来的单价格布局。
445
515
  - `title`、`transfer` 接收 `ReactNode`,适合需要自定义整块区域的场景。
446
516
  - `departureMain`、`departureSub`、`transferTop`、`transferBottom`、`arrivalMain`、`arrivalDayOffset`、`arrivalSub` 接收字符串或数字。
517
+ - 窄屏下模板会先压缩行程与价格之间的空白,再压缩出发、中转和到达列之间的空白;空间仍不足时隐藏价格,内容块本身保持原有宽度。
447
518
 
448
519
  ## AskHumanCard
449
520
 
450
- <img src="https://unpkg.com/@doubao-dev/template@0.3.0/assets/ask-human-card.png" alt="AskHumanCard 示例" width="400" />
521
+ <img src="https://unpkg.com/@doubao-dev/template@0.4.0-rc.5/assets/ask-human-card.png" alt="AskHumanCard 示例" width="400" />
451
522
 
452
523
  人工确认选项卡,由一组选项组成,适合让用户在多个候选项中确认选择。
453
524
 
@@ -1,4 +1,4 @@
1
- import type { ReactElement, ReactNode } from 'react';
1
+ import { type ReactElement, type ReactNode } from 'react';
2
2
  import type { TemplateText } from '../../types.js';
3
3
  import './styles.scss';
4
4
  export interface TemplateTransportSummaryProps {
@@ -96,21 +96,21 @@ function TemplateTransportSummary(props) {
96
96
  isArrival: true
97
97
  });
98
98
  const arrivalDayOffsetNode = null == arrivalPointNode ? null : renderTemplateTransportSummaryArrivalDayOffset(arrivalDayOffset);
99
- const arrivalNode = null == arrivalPointNode ? null : <view className="doubao-template-transport-summary__arrival">{arrivalPointNode}</view>;
99
+ const arrivalNode = null == arrivalPointNode ? null : <view className="doubao-template-transport-summary__arrival">
100
+ {arrivalPointNode}
101
+ {arrivalDayOffsetNode}
102
+ </view>;
100
103
  const titleNode = renderTemplateTransportSummaryNodeField(title, 'doubao-template-transport-summary__title', 'doubao-template-transport-summary__title-text');
101
104
  const priceNode = renderTemplateTransportSummaryPrice(price, tag);
102
105
  const hasRoute = Boolean(departureNode || transferNode || arrivalNode);
103
- const hasRouteRow = Boolean(hasRoute || priceNode);
106
+ const hasRouteRow = hasRoute || null != priceNode;
104
107
  if (null == titleNode && !hasRouteRow) return null;
105
108
  return <view className={clsx('doubao-template-transport-summary', className)}>
106
109
  {titleNode}
107
110
  {hasRouteRow && <view className="doubao-template-transport-summary__route-row">
108
- {hasRoute && <view className="doubao-template-transport-summary__route">
109
- {departureNode}
110
- {transferNode}
111
- {arrivalNode}
112
- {arrivalDayOffsetNode}
113
- </view>}
111
+ {departureNode}
112
+ {transferNode}
113
+ {arrivalNode}
114
114
  {priceNode}
115
115
  </view>}
116
116
  </view>;
@@ -39,8 +39,8 @@
39
39
  }
40
40
 
41
41
  .doubao-template-transport-summary__route-row {
42
- flex-direction: row;
43
- justify-content: space-between;
42
+ flex-flow: wrap;
43
+ place-content: flex-start space-between;
44
44
  align-items: center;
45
45
  width: 100%;
46
46
  min-width: 0;
@@ -48,17 +48,7 @@
48
48
  margin-top: 2px;
49
49
  display: flex;
50
50
  position: relative;
51
- }
52
-
53
- .doubao-template-transport-summary__route {
54
- flex-direction: row;
55
- flex-shrink: 0;
56
- justify-content: space-between;
57
- align-items: center;
58
- width: 200px;
59
- min-width: 0;
60
- height: 46px;
61
- display: flex;
51
+ overflow: hidden;
62
52
  }
63
53
 
64
54
  .doubao-template-transport-summary__route-point {
@@ -127,7 +117,7 @@
127
117
  display: flex;
128
118
  position: absolute;
129
119
  top: 2px;
130
- left: 202px;
120
+ left: 100%;
131
121
  }
132
122
 
133
123
  .doubao-template-transport-summary__arrival-day-offset-text {
@@ -196,11 +186,34 @@
196
186
  .doubao-template-transport-summary__price {
197
187
  box-sizing: border-box;
198
188
  flex-direction: column;
189
+ flex: 0 0 80px;
199
190
  justify-content: center;
200
191
  align-items: flex-end;
201
- width: 88px;
192
+ width: 80px;
202
193
  height: 42px;
203
- padding: 0 4px;
194
+ }
195
+
196
+ .doubao-template-transport-summary__price > .doubao-price {
197
+ justify-content: flex-end;
198
+ width: 100%;
199
+ min-width: 0;
200
+ overflow: hidden;
201
+ }
202
+
203
+ .doubao-template-transport-summary__price .doubao-price__amount, .doubao-template-transport-summary__price .doubao-price__main, .doubao-template-transport-summary__price .doubao-price__integer-group {
204
+ min-width: 0;
205
+ max-width: 100%;
206
+ overflow: hidden;
207
+ }
208
+
209
+ .doubao-template-transport-summary__price .doubao-price__main, .doubao-template-transport-summary__price .doubao-price__integer-group, .doubao-template-transport-summary__price .doubao-price__integer {
210
+ flex-shrink: 1;
211
+ }
212
+
213
+ .doubao-template-transport-summary__price .doubao-price__integer {
214
+ text-overflow: ellipsis;
215
+ min-width: 0;
216
+ overflow: hidden;
204
217
  }
205
218
 
206
219
  .doubao-template-transport-summary__price--with-tag {
@@ -0,0 +1,43 @@
1
+ import type { CSSProperties, TouchEvent } from '@lynx-js/types';
2
+ import type { ReactElement } from 'react';
3
+ import { type TemplateCardFooterProps } from '../components/footer/index.js';
4
+ import { type TemplateCardHeaderProps } from '../components/header/index.js';
5
+ import { type ContentCardProps } from '../content-card/index.js';
6
+ import { type OptionGroupProps } from '../primitives/option-group/index.js';
7
+ import type { TransitCardProps } from '../transit-card/index.js';
8
+ import './styles.scss';
9
+ export interface CompositeCardTransitSection {
10
+ /** 行程模块。 */
11
+ type: 'transit';
12
+ /** 行程模块配置。 */
13
+ props: Pick<TransitCardProps, 'items'>;
14
+ }
15
+ export interface CompositeCardContentSection {
16
+ /** 内容列表模块。 */
17
+ type: 'content';
18
+ /** 内容列表模块配置。 */
19
+ props: Pick<ContentCardProps, 'items'>;
20
+ }
21
+ export interface CompositeCardOptionGroupSection {
22
+ /** 选项组模块。 */
23
+ type: 'option-group';
24
+ /** 选项组模块配置。 */
25
+ props: OptionGroupProps;
26
+ }
27
+ export type CompositeCardSection = CompositeCardTransitSection | CompositeCardContentSection | CompositeCardOptionGroupSection;
28
+ export interface CompositeCardProps {
29
+ /** 标题栏配置。 */
30
+ header?: TemplateCardHeaderProps;
31
+ /** 按顺序展示的卡片模块。 */
32
+ sections: CompositeCardSection[];
33
+ /** 底部操作区配置。 */
34
+ footer?: TemplateCardFooterProps;
35
+ /** 卡片根节点自定义类名。 */
36
+ className?: string;
37
+ /** 卡片根节点自定义样式。 */
38
+ style?: CSSProperties;
39
+ /** 点击卡片根节点时触发。 */
40
+ onClick?: (event: TouchEvent) => void;
41
+ }
42
+ export declare function CompositeCard(props: CompositeCardProps): ReactElement;
43
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { useThemeClassName } from "@byted-doubao-apps/components";
2
+ import { clsx } from "clsx";
3
+ import { TemplateCardFooter } from "../components/footer/index.js";
4
+ import { TemplateCardHeader } from "../components/header/index.js";
5
+ import { ContentCardContent } from "../content-card/index.js";
6
+ import { OptionGroup } from "../primitives/option-group/index.js";
7
+ import { TransitCardContent } from "../transit-card/content.js";
8
+ import "./styles.css";
9
+ function isCompositeCardSectionVisible(section) {
10
+ switch(section.type){
11
+ case 'transit':
12
+ return (section.props.items?.length ?? 0) > 0;
13
+ case 'content':
14
+ return (section.props.items?.length ?? 0) > 0;
15
+ case 'option-group':
16
+ return section.props.items.length > 0;
17
+ default:
18
+ return false;
19
+ }
20
+ }
21
+ function renderCompositeCardSectionContent(section) {
22
+ switch(section.type){
23
+ case 'transit':
24
+ return <TransitCardContent items={section.props.items}/>;
25
+ case 'content':
26
+ return <ContentCardContent items={section.props.items}/>;
27
+ case 'option-group':
28
+ return <view className="doubao-composite-card__option-group">
29
+ <OptionGroup {...section.props}/>
30
+ </view>;
31
+ default:
32
+ return null;
33
+ }
34
+ }
35
+ function renderCompositeCardSection(section, index) {
36
+ if (!isCompositeCardSectionVisible(section)) return null;
37
+ return <view className="doubao-composite-card__section" key={index}>
38
+ {renderCompositeCardSectionContent(section)}
39
+ </view>;
40
+ }
41
+ function CompositeCard(props) {
42
+ const { header, sections, footer, className, style, onClick } = props;
43
+ const visibleSections = sections.filter(isCompositeCardSectionVisible);
44
+ return <view className={useThemeClassName(clsx('doubao-composite-card', className))} style={style} bindtap={onClick}>
45
+ <TemplateCardHeader actionText={header?.actionText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
46
+ {visibleSections.length > 0 && <view className="doubao-composite-card__sections">
47
+ {visibleSections.map(renderCompositeCardSection)}
48
+ </view>}
49
+ <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton}/>
50
+ </view>;
51
+ }
52
+ export { CompositeCard };
@@ -0,0 +1,36 @@
1
+ .doubao-composite-card {
2
+ box-sizing: border-box;
3
+ background-color: var(--bg-base-1);
4
+ border: 1px solid var(--bg-base-2-overlay);
5
+ border-radius: 8px;
6
+ flex-direction: column;
7
+ align-items: stretch;
8
+ width: 100%;
9
+ display: flex;
10
+ overflow: hidden;
11
+ }
12
+
13
+ .doubao-composite-card__sections {
14
+ box-sizing: border-box;
15
+ background-color: var(--bg-base-1);
16
+ flex-direction: column;
17
+ width: 100%;
18
+ min-width: 0;
19
+ display: flex;
20
+ }
21
+
22
+ .doubao-composite-card__section {
23
+ box-sizing: border-box;
24
+ flex-direction: column;
25
+ width: 100%;
26
+ min-width: 0;
27
+ display: flex;
28
+ }
29
+
30
+ .doubao-composite-card__option-group {
31
+ box-sizing: border-box;
32
+ width: 100%;
33
+ min-width: 0;
34
+ padding: 0 12px 16px;
35
+ }
36
+
@@ -51,5 +51,6 @@ export interface ContentCardItem {
51
51
  /** 点击列表项时触发。 */
52
52
  onClick?: (event: TouchEvent) => void;
53
53
  }
54
+ export declare function ContentCardContent({ items }: Pick<ContentCardProps, 'items'>): ReactElement;
54
55
  export declare function ContentCard(props: ContentCardProps): ReactElement;
55
56
  //# sourceMappingURL=index.d.ts.map
@@ -64,15 +64,18 @@ function ContentCardItemView({ item, isLast }) {
64
64
  </view>}
65
65
  </view>;
66
66
  }
67
+ function ContentCardContent({ items }) {
68
+ const contentItems = items ?? [];
69
+ return <view className="doubao-content-card__body">
70
+ {contentItems.map((item, index)=><ContentCardItemView key={item.key ?? index} item={item} isLast={index === contentItems.length - 1}/>)}
71
+ </view>;
72
+ }
67
73
  function ContentCard(props) {
68
74
  const { header, items, footer, children, className, style, onClick } = props;
69
- const contentItems = items ?? [];
70
75
  return <view className={useThemeClassName(clsx('doubao-content-card', className))} style={style} bindtap={onClick} clip-radius="true">
71
76
  <TemplateCardHeader actionText={header?.actionText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
72
- <view className="doubao-content-card__body">
73
- {children ?? contentItems.map((item, index)=><ContentCardItemView key={item.key ?? index} item={item} isLast={index === contentItems.length - 1}/>)}
74
- </view>
77
+ {null == children ? <ContentCardContent items={items}/> : <view className="doubao-content-card__body">{children}</view>}
75
78
  <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton}/>
76
79
  </view>;
77
80
  }
78
- export { ContentCard };
81
+ export { ContentCard, ContentCardContent };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ContentCard, type ContentCardItem, type ContentCardProps } from './content-card/index.js';
2
+ export { CompositeCard, type CompositeCardContentSection, type CompositeCardOptionGroupSection, type CompositeCardProps, type CompositeCardSection, type CompositeCardTransitSection } from './composite-card/index.js';
2
3
  export type { TemplateCardHeaderProps } from './components/header/index.js';
3
4
  export type { TemplateCardFooterActionButton, TemplateCardFooterProps } from './components/footer/index.js';
4
5
  export type { TemplateExtraAction, TemplateExtraActionButton, TemplateExtraActionPlayback, TemplateExtraActionSwitch } from './components/extra-action/index.js';
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ContentCard } from "./content-card/index.js";
2
+ export { CompositeCard } from "./composite-card/index.js";
2
3
  export { AskHumanCard } from "./ask-human-card/index.js";
3
4
  export { CheckoutCard } from "./checkout-card/index.js";
4
5
  export { PriceActionCard } from "./price-action-card/index.js";
@@ -0,0 +1,7 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { TransitCardItem } from './index.js';
3
+ import './styles.scss';
4
+ export declare function TransitCardContent({ items }: {
5
+ items?: TransitCardItem[];
6
+ }): ReactElement;
7
+ //# sourceMappingURL=content.d.ts.map
@@ -0,0 +1,43 @@
1
+ import { clsx } from "clsx";
2
+ import { TemplateTransportSummary } from "../components/transport-summary/index.js";
3
+ import { Price } from "../primitives/price/index.js";
4
+ import { Tag } from "../primitives/tag/index.js";
5
+ import "./styles.css";
6
+ function isTransitCardPriceConfig(price) {
7
+ return null != price && 'object' == typeof price && !Array.isArray(price) && 'value' in price;
8
+ }
9
+ function renderTransitCardTextPrice(price) {
10
+ if ('' === price) return null;
11
+ const matched = price.match(/^(.*?)([¥¥$€£₩₽₹])(.*)$/);
12
+ if (null == matched) return <Price value={price} currency=""/>;
13
+ const [, prefix, currency, value] = matched;
14
+ return <Price value={value} currency={currency} prefix={prefix || void 0}/>;
15
+ }
16
+ function renderTransitCardPrice(price) {
17
+ if ('number' == typeof price) return <Price value={price}/>;
18
+ if ('string' == typeof price) return renderTransitCardTextPrice(price);
19
+ if (isTransitCardPriceConfig(price)) return <Price value={price.value} currency={price.currency} prefix={price.prefix} prefixTone={price.prefixTone} tone={price.tone}/>;
20
+ return price;
21
+ }
22
+ function renderTransitCardTag(tag) {
23
+ if (null == tag || '' === tag.text) return null;
24
+ return <Tag text={tag.text} tone={tag.tone ?? 'marketing'}/>;
25
+ }
26
+ function renderTransitCardItem({ item, index, isLast }) {
27
+ return <view className={clsx('doubao-transit-card__item', isLast && 'doubao-transit-card__item--last', item.className)} style={item.style} key={item.key ?? index} {...null != item.onClick ? {
28
+ catchtap: item.onClick
29
+ } : {}}>
30
+ <TemplateTransportSummary className="doubao-template-transport-summary--list" title={item.title} departureMain={item.departureMain} departureSub={item.departureSub} transfer={item.transfer} transferTop={item.transferTop} transferBottom={item.transferBottom} arrivalMain={item.arrivalMain} arrivalDayOffset={item.arrivalDayOffset} arrivalSub={item.arrivalSub} price={renderTransitCardPrice(item.price)} tag={renderTransitCardTag(item.tag)}/>
31
+ {!isLast && <view className="doubao-transit-card__item--spread"/>}
32
+ </view>;
33
+ }
34
+ function TransitCardContent({ items = [] }) {
35
+ return <view className="doubao-transit-card__body">
36
+ {items.map((item, index)=>renderTransitCardItem({
37
+ item,
38
+ index,
39
+ isLast: index === items.length - 1
40
+ }))}
41
+ </view>;
42
+ }
43
+ export { TransitCardContent };
@@ -2,10 +2,9 @@ import type { CSSProperties, TouchEvent } from '@lynx-js/types';
2
2
  import type { ReactElement, ReactNode } from 'react';
3
3
  import { type TemplateCardFooterProps } from '../components/footer/index.js';
4
4
  import { type TemplateCardHeaderProps } from '../components/header/index.js';
5
- import { type PricePrefixTone, type PriceTone, type PriceValue } from '../primitives/price/index.js';
6
- import { type TagValue } from '../primitives/tag/index.js';
5
+ import type { PricePrefixTone, PriceTone, PriceValue } from '../primitives/price/index.js';
6
+ import type { TagValue } from '../primitives/tag/index.js';
7
7
  import type { TemplateKey, TemplateText } from '../types.js';
8
- import './styles.scss';
9
8
  export interface TransitCardProps {
10
9
  /** 标题栏配置。 */
11
10
  header?: TemplateCardHeaderProps;
@@ -2,49 +2,12 @@ import { useThemeClassName } from "@byted-doubao-apps/components";
2
2
  import { clsx } from "clsx";
3
3
  import { TemplateCardFooter } from "../components/footer/index.js";
4
4
  import { TemplateCardHeader } from "../components/header/index.js";
5
- import { TemplateTransportSummary } from "../components/transport-summary/index.js";
6
- import { Price } from "../primitives/price/index.js";
7
- import { Tag } from "../primitives/tag/index.js";
8
- import "./styles.css";
9
- function isTransitCardPriceConfig(price) {
10
- return null != price && 'object' == typeof price && !Array.isArray(price) && 'value' in price;
11
- }
12
- function renderTransitCardTextPrice(price) {
13
- if ('' === price) return null;
14
- const matched = price.match(/^(.*?)([¥¥$€£₩₽₹])(.*)$/);
15
- if (null == matched) return <Price value={price} currency=""/>;
16
- const [, prefix, currency, value] = matched;
17
- return <Price value={value} currency={currency} prefix={prefix || void 0}/>;
18
- }
19
- function renderTransitCardPrice(price) {
20
- if ('number' == typeof price) return <Price value={price}/>;
21
- if ('string' == typeof price) return renderTransitCardTextPrice(price);
22
- if (isTransitCardPriceConfig(price)) return <Price value={price.value} currency={price.currency} prefix={price.prefix} prefixTone={price.prefixTone} tone={price.tone}/>;
23
- return price;
24
- }
25
- function renderTransitCardTag(tag) {
26
- if (null == tag || '' === tag.text) return null;
27
- return <Tag text={tag.text} tone={tag.tone ?? 'marketing'}/>;
28
- }
29
- function renderTransitCardItem({ item, index, isLast }) {
30
- return <view className={clsx('doubao-transit-card__item', isLast && 'doubao-transit-card__item--last', item.className)} style={item.style} key={item.key ?? index} {...null != item.onClick ? {
31
- catchtap: item.onClick
32
- } : {}}>
33
- <TemplateTransportSummary className="doubao-template-transport-summary--list" title={item.title} departureMain={item.departureMain} departureSub={item.departureSub} transfer={item.transfer} transferTop={item.transferTop} transferBottom={item.transferBottom} arrivalMain={item.arrivalMain} arrivalDayOffset={item.arrivalDayOffset} arrivalSub={item.arrivalSub} price={renderTransitCardPrice(item.price)} tag={renderTransitCardTag(item.tag)}/>
34
- {!isLast && <view className="doubao-transit-card__item--spread"/>}
35
- </view>;
36
- }
5
+ import { TransitCardContent } from "./content.js";
37
6
  function TransitCard(props) {
38
7
  const { header, items = [], footer, className, style, onClick } = props;
39
8
  return <view className={useThemeClassName(clsx('doubao-transit-card', className))} style={style} bindtap={onClick}>
40
9
  <TemplateCardHeader actionText={header?.actionText} showAction={header?.showAction} onActionClick={header?.onActionClick}/>
41
- <view className="doubao-transit-card__body">
42
- {items.map((item, index)=>renderTransitCardItem({
43
- item,
44
- index,
45
- isLast: index === items.length - 1
46
- }))}
47
- </view>
10
+ <TransitCardContent items={items}/>
48
11
  <TemplateCardFooter primaryActionButton={footer?.primaryActionButton} secondaryActionButton={footer?.secondaryActionButton}/>
49
12
  </view>;
50
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doubao-dev/template",
3
- "version": "0.3.0",
3
+ "version": "0.4.0-rc.5",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {