Skip to content

Commit 0beda70

Browse files
layershifterharel
authored andcommitted
style(Card): update typings and propTypes usage (Semantic-Org#1284)
1 parent 2fd93f0 commit 0beda70

File tree

13 files changed

+100
-63
lines changed

13 files changed

+100
-63
lines changed

src/views/Card/Card.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,14 @@ import {
1111
useKeyOnly,
1212
} from '../../lib'
1313
import Image from '../../elements/Image'
14-
1514
import CardContent from './CardContent'
1615
import CardDescription from './CardDescription'
1716
import CardGroup from './CardGroup'
1817
import CardHeader from './CardHeader'
1918
import CardMeta from './CardMeta'
2019

21-
const _meta = {
22-
name: 'Card',
23-
type: META.TYPES.VIEW,
24-
props: {
25-
color: SUI.COLORS,
26-
},
27-
}
28-
2920
/**
30-
* A card displays site content in a manner similar to a playing card
21+
* A card displays site content in a manner similar to a playing card.
3122
*/
3223
export default class Card extends Component {
3324
static propTypes = {
@@ -44,7 +35,7 @@ export default class Card extends Component {
4435
className: PropTypes.string,
4536

4637
/** A Card can be formatted to display different colors. */
47-
color: PropTypes.oneOf(_meta.props.color),
38+
color: PropTypes.oneOf(SUI.COLORS),
4839

4940
/** Shorthand for CardDescription. */
5041
description: customPropTypes.itemShorthand,
@@ -80,7 +71,10 @@ export default class Card extends Component {
8071
raised: PropTypes.bool,
8172
}
8273

83-
static _meta = _meta
74+
static _meta = {
75+
name: 'Card',
76+
type: META.TYPES.VIEW,
77+
}
8478

8579
static Content = CardContent
8680
static Description = CardDescription

src/views/Card/CardContent.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { PropTypes } from 'react'
44

55
import {
@@ -15,10 +15,18 @@ import CardHeader from './CardHeader'
1515
import CardMeta from './CardMeta'
1616

1717
/**
18-
* A card can contain blocks of content or extra content meant to be formatted separately from the main content
18+
* A card can contain blocks of content or extra content meant to be formatted separately from the main content.
1919
*/
2020
function CardContent(props) {
21-
const { children, className, description, extra, header, meta } = props
21+
const {
22+
children,
23+
className,
24+
description,
25+
extra,
26+
header,
27+
meta,
28+
} = props
29+
2230
const classes = cx(
2331
className,
2432
useKeyOnly(extra, 'extra'),
@@ -59,7 +67,7 @@ CardContent.propTypes = {
5967
/** Shorthand for CardDescription. */
6068
description: customPropTypes.itemShorthand,
6169

62-
/** A card can contain extra content meant to be formatted separately from the main content */
70+
/** A card can contain extra content meant to be formatted separately from the main content. */
6371
extra: PropTypes.bool,
6472

6573
/** Shorthand for CardHeader. */

src/views/Card/CardDescription.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { PropTypes } from 'react'
44

55
import {
@@ -10,15 +10,19 @@ import {
1010
} from '../../lib'
1111

1212
/**
13-
* A card can contain a description with one or more paragraphs
13+
* A card can contain a description with one or more paragraphs.
1414
*/
1515
function CardDescription(props) {
1616
const { children, className, content } = props
1717
const classes = cx(className, 'description')
1818
const rest = getUnhandledProps(CardDescription, props)
1919
const ElementType = getElementType(CardDescription, props)
2020

21-
return <ElementType {...rest} className={classes}>{_.isNil(children) ? content : children}</ElementType>
21+
return (
22+
<ElementType {...rest} className={classes}>
23+
{_.isNil(children) ? content : children}
24+
</ElementType>
25+
)
2226
}
2327

2428
CardDescription._meta = {

src/views/Card/CardGroup.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { PropTypes } from 'react'
44

55
import {
@@ -17,11 +17,19 @@ import Card from './Card'
1717
* A group of cards.
1818
*/
1919
function CardGroup(props) {
20-
const { children, className, doubling, items, itemsPerRow, stackable } = props
20+
const {
21+
children,
22+
className,
23+
doubling,
24+
items,
25+
itemsPerRow,
26+
stackable,
27+
} = props
28+
2129
const classes = cx('ui',
22-
useWidthProp(itemsPerRow),
2330
useKeyOnly(doubling, 'doubling'),
2431
useKeyOnly(stackable, 'stackable'),
32+
useWidthProp(itemsPerRow),
2533
className,
2634
'cards',
2735
)
@@ -43,9 +51,6 @@ function CardGroup(props) {
4351
CardGroup._meta = {
4452
name: 'CardGroup',
4553
parent: 'Card',
46-
props: {
47-
itemsPerRow: SUI.WIDTHS,
48-
},
4954
type: META.TYPES.VIEW,
5055
}
5156

@@ -59,16 +64,16 @@ CardGroup.propTypes = {
5964
/** Additional classes. */
6065
className: PropTypes.string,
6166

62-
/** A group of cards can double its column width for mobile */
67+
/** A group of cards can double its column width for mobile. */
6368
doubling: PropTypes.bool,
6469

6570
/** Shorthand array of props for Card. */
6671
items: customPropTypes.collectionShorthand,
6772

68-
/** A group of cards can set how many cards should exist in a row */
69-
itemsPerRow: PropTypes.oneOf(CardGroup._meta.props.itemsPerRow),
73+
/** A group of cards can set how many cards should exist in a row. */
74+
itemsPerRow: PropTypes.oneOf(SUI.WIDTHS),
7075

71-
/** A group of cards can automatically stack rows to a single columns on mobile devices */
76+
/** A group of cards can automatically stack rows to a single columns on mobile devices. */
7277
stackable: PropTypes.bool,
7378
}
7479

src/views/Card/CardHeader.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { PropTypes } from 'react'
44

55
import {
@@ -10,15 +10,19 @@ import {
1010
} from '../../lib'
1111

1212
/**
13-
* A card can contain a header
13+
* A card can contain a header.
1414
*/
1515
function CardHeader(props) {
1616
const { children, className, content } = props
1717
const classes = cx(className, 'header')
1818
const rest = getUnhandledProps(CardHeader, props)
1919
const ElementType = getElementType(CardHeader, props)
2020

21-
return <ElementType {...rest} className={classes}>{_.isNil(children) ? content : children}</ElementType>
21+
return (
22+
<ElementType {...rest} className={classes}>
23+
{_.isNil(children) ? content : children}
24+
</ElementType>
25+
)
2226
}
2327

2428
CardHeader._meta = {

src/views/Card/CardMeta.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import _ from 'lodash'
21
import cx from 'classnames'
2+
import _ from 'lodash'
33
import React, { PropTypes } from 'react'
44

55
import {
@@ -10,15 +10,19 @@ import {
1010
} from '../../lib'
1111

1212
/**
13-
* A card can contain content metadata
13+
* A card can contain content metadata.
1414
*/
1515
function CardMeta(props) {
1616
const { children, className, content } = props
1717
const classes = cx(className, 'meta')
1818
const rest = getUnhandledProps(CardMeta, props)
1919
const ElementType = getElementType(CardMeta, props)
2020

21-
return <ElementType {...rest} className={classes}>{_.isNil(children) ? content : children}</ElementType>
21+
return (
22+
<ElementType {...rest} className={classes}>
23+
{_.isNil(children) ? content : children}
24+
</ElementType>
25+
)
2226
}
2327

2428
CardMeta._meta = {

src/views/Card/index.d.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ReactMouseEvents, SemanticCOLORS, SemanticWIDTHS } from '../..';
21
import * as React from 'react';
2+
import { SemanticCOLORS, SemanticWIDTHS } from '../..';
33

4-
interface CardProps extends ReactMouseEvents<HTMLElement> {
4+
interface CardProps {
5+
[key: string]: any;
56

67
/** An element type to render as (string or function). */
78
as?: any;
@@ -46,23 +47,25 @@ interface CardProps extends ReactMouseEvents<HTMLElement> {
4647
* @param {SyntheticEvent} event - React's original SyntheticEvent.
4748
* @param {object} data - All props.
4849
*/
49-
onClick?: React.MouseEventHandler<any>;
50+
onClick?: (event: React.MouseEvent<HTMLAnchorElement>, data: CardProps) => void;
5051

5152
/** A Card can be formatted to raise above the page. */
5253
raised?: boolean;
5354
}
5455

55-
interface CardClass extends React.ComponentClass<CardProps> {
56+
interface CardComponent extends React.ComponentClass<CardProps> {
5657
Content: typeof CardContent;
5758
Description: typeof CardDescription;
5859
Group: typeof CardGroup;
5960
Header: typeof CardHeader;
6061
Meta: typeof CardMeta;
6162
}
6263

63-
export const Card: CardClass;
64+
export const Card: CardComponent;
6465

6566
interface CardContentProps {
67+
[key: string]: any;
68+
6669
/** An element type to render as (string or function). */
6770
as?: any;
6871

@@ -75,7 +78,7 @@ interface CardContentProps {
7578
/** Shorthand for CardDescription. */
7679
description?: string;
7780

78-
/** A card can contain extra content meant to be formatted separately from the main content */
81+
/** A card can contain extra content meant to be formatted separately from the main content. */
7982
extra?: boolean;
8083

8184
/** Shorthand for CardHeader. */
@@ -85,9 +88,11 @@ interface CardContentProps {
8588
meta?: any;
8689
}
8790

88-
export const CardContent: React.ComponentClass<CardContentProps>;
91+
export const CardContent: React.StatelessComponent<CardContentProps>;
8992

9093
interface CardDescriptionProps {
94+
[key: string]: any;
95+
9196
/** An element type to render as (string or function). */
9297
as?: any;
9398

@@ -98,12 +103,14 @@ interface CardDescriptionProps {
98103
className?: string;
99104

100105
/** Shorthand for primary content. */
101-
content?: any;
106+
content?: React.ReactNode;
102107
}
103108

104-
export const CardDescription: React.ComponentClass<CardDescriptionProps>;
109+
export const CardDescription: React.StatelessComponent<CardDescriptionProps>;
105110

106111
interface CardGroupProps {
112+
[key: string]: any;
113+
107114
/** An element type to render as (string or function). */
108115
as?: any;
109116

@@ -113,22 +120,24 @@ interface CardGroupProps {
113120
/** Additional classes. */
114121
className?: string;
115122

116-
/** A group of cards can double its column width for mobile */
123+
/** A group of cards can double its column width for mobile. */
117124
doubling?: boolean;
118125

119126
/** Shorthand array of props for Card. */
120127
items?: Array<any>;
121128

122-
/** A group of cards can set how many cards should exist in a row */
129+
/** A group of cards can set how many cards should exist in a row. */
123130
itemsPerRow?: SemanticWIDTHS;
124131

125-
/** A group of cards can automatically stack rows to a single columns on mobile devices */
132+
/** A group of cards can automatically stack rows to a single columns on mobile devices. */
126133
stackable?: boolean;
127134
}
128135

129-
export const CardGroup: React.ComponentClass<CardGroupProps>;
136+
export const CardGroup: React.StatelessComponent<CardGroupProps>;
130137

131138
interface CardHeaderProps {
139+
[key: string]: any;
140+
132141
/** An element type to render as (string or function). */
133142
as?: any;
134143

@@ -139,12 +148,14 @@ interface CardHeaderProps {
139148
className?: string;
140149

141150
/** Shorthand for primary content. */
142-
content?: any;
151+
content?: React.ReactNode;
143152
}
144153

145-
export const CardHeader: React.ComponentClass<CardHeaderProps>;
154+
export const CardHeader: React.StatelessComponent<CardHeaderProps>;
146155

147156
interface CardMetaProps {
157+
[key: string]: any;
158+
148159
/** An element type to render as (string or function). */
149160
as?: any;
150161

@@ -155,7 +166,7 @@ interface CardMetaProps {
155166
className?: string;
156167

157168
/** Shorthand for primary content. */
158-
content?: any;
169+
content?: React.ReactNode;
159170
}
160171

161-
export const CardMeta: React.ComponentClass<CardMetaProps>;
172+
export const CardMeta: React.StatelessComponent<CardMetaProps>;

test/specs/views/Card/Card-test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
import faker from 'faker'
22
import React from 'react'
33

4-
import * as common from 'test/specs/commonTests'
5-
import { sandbox } from 'test/utils'
4+
import { SUI } from 'src/lib'
65
import Card from 'src/views/Card/Card'
76
import CardContent from 'src/views/Card/CardContent'
87
import CardDescription from 'src/views/Card/CardDescription'
98
import CardGroup from 'src/views/Card/CardGroup'
109
import CardHeader from 'src/views/Card/CardHeader'
1110
import CardMeta from 'src/views/Card/CardMeta'
11+
import * as common from 'test/specs/commonTests'
12+
import { sandbox } from 'test/utils'
1213

1314
describe('Card', () => {
1415
common.isConformant(Card)
15-
common.hasUIClassName(Card)
1616
common.hasSubComponents(Card, [CardContent, CardDescription, CardGroup, CardHeader, CardMeta])
17+
common.hasUIClassName(Card)
18+
common.rendersChildren(Card)
19+
1720
common.propKeyOnlyToClassName(Card, 'centered')
1821
common.propKeyOnlyToClassName(Card, 'fluid')
1922
common.propKeyOnlyToClassName(Card, 'raised')
20-
common.rendersChildren(Card)
23+
24+
common.propValueOnlyToClassName(Card, 'color', SUI.COLORS)
2125

2226
it('renders a <div> by default', () => {
2327
shallow(<Card />).should.have.tagName('div')

0 commit comments

Comments
 (0)