Skip to content

Commit

Permalink
feat: 为Card组件的HeaderContent和HeaderExtra添加Wrap style,便于定制 fixes #395
Browse files Browse the repository at this point in the history
* 为Card组件的HeaderContent和HeaderExtra添加Wrap style,便于定制

* 添加测试代码,并通过测试
  • Loading branch information
christtrc authored and BANG88 committed Mar 15, 2019
1 parent a809844 commit 29754a8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions components/card/CardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export interface CardHeaderPropsType
extends WithThemeStyles<
Pick<
CardStyle,
| 'headerContentWrap'
| 'headerContent'
| 'headerExtraWrap'
| 'headerExtra'
| 'headerImage'
| 'headerTitle'
Expand Down Expand Up @@ -46,14 +48,14 @@ export default class CardHeader extends React.Component<CardHeaderProps, any> {
{s => {
const titleDom =
title === undefined ? null : React.isValidElement(title) ? (
<View style={{ flex: 1 }}>{title}</View>
<View style={s.headerContentWrap}>{title}</View>
) : (
<Text style={s.headerContent}>{title}</Text>
);

const extraDom =
extra === undefined ? null : React.isValidElement(extra) ? (
<View style={{ flex: 1 }}>{extra}</View>
<View style={s.headerExtraWrap}>{extra}</View>
) : (
<Text style={[s.headerExtra]}>{extra}</Text>
);
Expand Down
36 changes: 36 additions & 0 deletions components/card/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,18 @@ exports[`renders ./components/card/demo/basic.tsx correctly 1`] = `
"flex": 1,
"fontSize": 17,
},
"headerContentWrap": Object {
"flex": 1,
},
"headerExtra": Object {
"color": "#888888",
"flex": 1,
"fontSize": 17,
"textAlign": "right",
},
"headerExtraWrap": Object {
"flex": 1,
},
"headerImage": Object {
"marginRight": 5,
},
Expand Down Expand Up @@ -211,12 +217,18 @@ exports[`renders ./components/card/demo/basic.tsx correctly 1`] = `
"flex": 1,
"fontSize": 17,
},
"headerContentWrap": Object {
"flex": 1,
},
"headerExtra": Object {
"color": "#888888",
"flex": 1,
"fontSize": 17,
"textAlign": "right",
},
"headerExtraWrap": Object {
"flex": 1,
},
"headerImage": Object {
"marginRight": 5,
},
Expand Down Expand Up @@ -307,12 +319,18 @@ exports[`renders ./components/card/demo/basic.tsx correctly 1`] = `
"flex": 1,
"fontSize": 17,
},
"headerContentWrap": Object {
"flex": 1,
},
"headerExtra": Object {
"color": "#888888",
"flex": 1,
"fontSize": 17,
"textAlign": "right",
},
"headerExtraWrap": Object {
"flex": 1,
},
"headerImage": Object {
"marginRight": 5,
},
Expand Down Expand Up @@ -439,12 +457,18 @@ exports[`renders ./components/card/demo/basic.tsx correctly 1`] = `
"flex": 1,
"fontSize": 17,
},
"headerContentWrap": Object {
"flex": 1,
},
"headerExtra": Object {
"color": "#888888",
"flex": 1,
"fontSize": 17,
"textAlign": "right",
},
"headerExtraWrap": Object {
"flex": 1,
},
"headerImage": Object {
"marginRight": 5,
},
Expand Down Expand Up @@ -573,12 +597,18 @@ exports[`renders ./components/card/demo/basic.tsx correctly 1`] = `
"flex": 1,
"fontSize": 17,
},
"headerContentWrap": Object {
"flex": 1,
},
"headerExtra": Object {
"color": "#888888",
"flex": 1,
"fontSize": 17,
"textAlign": "right",
},
"headerExtraWrap": Object {
"flex": 1,
},
"headerImage": Object {
"marginRight": 5,
},
Expand Down Expand Up @@ -669,12 +699,18 @@ exports[`renders ./components/card/demo/basic.tsx correctly 1`] = `
"flex": 1,
"fontSize": 17,
},
"headerContentWrap": Object {
"flex": 1,
},
"headerExtra": Object {
"color": "#888888",
"flex": 1,
"fontSize": 17,
"textAlign": "right",
},
"headerExtraWrap": Object {
"flex": 1,
},
"headerImage": Object {
"marginRight": 5,
},
Expand Down
8 changes: 8 additions & 0 deletions components/card/style/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export interface CardStyle {
headerWrap: ViewStyle;
headerTitle: ViewStyle;
headerImage: ImageStyle;
headerContentWrap: ViewStyle;
headerContent: TextStyle;
headerExtraWrap: ViewStyle;
headerExtra: TextStyle;
body: ViewStyle;
footerWrap: ViewStyle;
Expand Down Expand Up @@ -45,11 +47,17 @@ export default (theme: Theme) =>
headerImage: {
marginRight: theme.h_spacing_sm,
},
headerContentWrap: {
flex: 1,
},
headerContent: {
color: theme.color_text_base,
fontSize: theme.font_size_heading,
flex: 1,
},
headerExtraWrap: {
flex: 1,
},
headerExtra: {
flex: 1,
fontSize: theme.font_size_heading,
Expand Down

0 comments on commit 29754a8

Please sign in to comment.