Skip to content

Commit 06a4c12

Browse files
layershifterlevithomason
authored andcommitted
style(Grid): update typings and propTypes usage (#1231)
* style(Grid): update typings and propTypes usage * style(Grid): fix type
1 parent 6319d9a commit 06a4c12

File tree

6 files changed

+58
-75
lines changed

6 files changed

+58
-75
lines changed

src/collections/Grid/Grid.js

+14-22
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ function Grid(props) {
2424
const {
2525
celled,
2626
centered,
27-
container,
2827
children,
2928
className,
3029
columns,
30+
container,
3131
divided,
3232
doubling,
3333
padded,
@@ -69,16 +69,6 @@ Grid.Row = GridRow
6969
Grid._meta = {
7070
name: 'Grid',
7171
type: META.TYPES.COLLECTION,
72-
props: {
73-
celled: ['internally'],
74-
columns: [...SUI.WIDTHS, 'equal'],
75-
divided: ['vertically'],
76-
padded: ['horizontally', 'vertically'],
77-
relaxed: ['very'],
78-
reversed: ['computer', 'computer vertically', 'mobile', 'mobile vertically', 'tablet', 'tablet vertically'],
79-
textAlign: SUI.TEXT_ALIGNMENTS,
80-
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
81-
},
8272
}
8373

8474
Grid.propTypes = {
@@ -88,28 +78,28 @@ Grid.propTypes = {
8878
/** A grid can have rows divided into cells. */
8979
celled: PropTypes.oneOfType([
9080
PropTypes.bool,
91-
PropTypes.oneOf(Grid._meta.props.celled),
81+
PropTypes.oneOf(['internally']),
9282
]),
9383

9484
/** A grid can have its columns centered. */
9585
centered: PropTypes.bool,
9686

97-
/** A grid can be combined with a container to use avaiable layout and alignment */
98-
container: PropTypes.bool,
99-
10087
/** Primary content. */
10188
children: PropTypes.node,
10289

10390
/** Additional classes. */
10491
className: PropTypes.string,
10592

10693
/** Represents column count per row in Grid. */
107-
columns: PropTypes.oneOf(Grid._meta.props.columns),
94+
columns: PropTypes.oneOf([...SUI.WIDTHS, 'equal']),
95+
96+
/** A grid can be combined with a container to use avaiable layout and alignment. */
97+
container: PropTypes.bool,
10898

10999
/** A grid can have dividers between its columns. */
110100
divided: PropTypes.oneOfType([
111101
PropTypes.bool,
112-
PropTypes.oneOf(Grid._meta.props.divided),
102+
PropTypes.oneOf(['vertically']),
113103
]),
114104

115105
/** A grid can double its column width on tablet and mobile sizes. */
@@ -118,17 +108,19 @@ Grid.propTypes = {
118108
/** A grid can preserve its vertical and horizontal gutters on first and last columns. */
119109
padded: PropTypes.oneOfType([
120110
PropTypes.bool,
121-
PropTypes.oneOf(Grid._meta.props.padded),
111+
PropTypes.oneOf(['horizontally', 'vertically']),
122112
]),
123113

124114
/** A grid can increase its gutters to allow for more negative space. */
125115
relaxed: PropTypes.oneOfType([
126116
PropTypes.bool,
127-
PropTypes.oneOf(Grid._meta.props.relaxed),
117+
PropTypes.oneOf(['very']),
128118
]),
129119

130120
/** A grid can specify that its columns should reverse order at different device sizes. */
131-
reversed: PropTypes.oneOf(Grid._meta.props.reversed),
121+
reversed: PropTypes.oneOf([
122+
'computer', 'computer vertically', 'mobile', 'mobile vertically', 'tablet', 'tablet vertically',
123+
]),
132124

133125
/** A grid can have its columns stack on-top of each other after reaching mobile breakpoints. */
134126
stackable: PropTypes.bool,
@@ -137,10 +129,10 @@ Grid.propTypes = {
137129
stretched: PropTypes.bool,
138130

139131
/** A grid can specify its text alignment. */
140-
textAlign: PropTypes.oneOf(Grid._meta.props.textAlign),
132+
textAlign: PropTypes.oneOf(SUI.TEXT_ALIGNMENTS),
141133

142134
/** A grid can specify its vertical alignment to have all its columns vertically centered. */
143-
verticalAlign: PropTypes.oneOf(GridColumn._meta.props.verticalAlign),
135+
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
144136
}
145137

146138
export default Grid

src/collections/Grid/GridColumn.js

+13-26
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ GridColumn._meta = {
6161
name: 'GridColumn',
6262
parent: 'Grid',
6363
type: META.TYPES.COLLECTION,
64-
props: {
65-
color: SUI.COLORS,
66-
computer: SUI.WIDTHS,
67-
floated: SUI.FLOATS,
68-
largeScreen: SUI.WIDTHS,
69-
mobile: SUI.WIDTHS,
70-
only: ['computer', 'large screen', 'mobile', 'tablet mobile', 'tablet', 'widescreen'],
71-
tablet: SUI.WIDTHS,
72-
textAlign: SUI.TEXT_ALIGNMENTS,
73-
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
74-
widescreen: SUI.WIDTHS,
75-
width: SUI.WIDTHS,
76-
},
7764
}
7865

7966
GridColumn.propTypes = {
@@ -86,41 +73,41 @@ GridColumn.propTypes = {
8673
/** Additional classes. */
8774
className: PropTypes.string,
8875

89-
/** A column can specify a width for a computer. */
90-
computer: PropTypes.oneOf(GridColumn._meta.props.width),
91-
9276
/** A grid column can be colored. */
93-
color: PropTypes.oneOf(GridColumn._meta.props.color),
77+
color: PropTypes.oneOf(SUI.COLORS),
78+
79+
/** A column can specify a width for a computer. */
80+
computer: PropTypes.oneOf(SUI.WIDTHS),
9481

9582
/** A column can sit flush against the left or right edge of a row. */
96-
floated: PropTypes.oneOf(GridColumn._meta.props.floated),
83+
floated: PropTypes.oneOf(SUI.FLOATS),
9784

9885
/** A column can specify a width for a large screen device. */
99-
largeScreen: PropTypes.oneOf(GridColumn._meta.props.width),
86+
largeScreen: PropTypes.oneOf(SUI.WIDTHS),
10087

10188
/** A column can specify a width for a mobile device. */
102-
mobile: PropTypes.oneOf(GridColumn._meta.props.width),
89+
mobile: PropTypes.oneOf(SUI.WIDTHS),
10390

10491
/** A column can appear only for a specific device, or screen sizes. */
105-
only: PropTypes.oneOf(GridColumn._meta.props.only),
92+
only: PropTypes.oneOf(['computer', 'large screen', 'mobile', 'tablet mobile', 'tablet', 'widescreen']),
10693

10794
/** An can stretch its contents to take up the entire grid or row height. */
10895
stretched: PropTypes.bool,
10996

11097
/** A column can specify a width for a tablet device. */
111-
tablet: PropTypes.oneOf(GridColumn._meta.props.width),
98+
tablet: PropTypes.oneOf(SUI.WIDTHS),
11299

113100
/** A row can specify its text alignment. */
114-
textAlign: PropTypes.oneOf(GridColumn._meta.props.textAlign),
101+
textAlign: PropTypes.oneOf(SUI.TEXT_ALIGNMENTS),
115102

116103
/** A column can specify its vertical alignment to have all its columns vertically centered. */
117-
verticalAlign: PropTypes.oneOf(GridColumn._meta.props.verticalAlign),
104+
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
118105

119106
/** A column can specify a width for a wide screen device. */
120-
widescreen: PropTypes.oneOf(GridColumn._meta.props.width),
107+
widescreen: PropTypes.oneOf(SUI.WIDTHS),
121108

122109
/** Represents width of column. */
123-
width: PropTypes.oneOf(GridColumn._meta.props.width),
110+
width: PropTypes.oneOf(SUI.WIDTHS),
124111
}
125112

126113
export default GridColumn

src/collections/Grid/GridRow.js

+8-14
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ GridRow._meta = {
5555
name: 'GridRow',
5656
parent: 'Grid',
5757
type: META.TYPES.COLLECTION,
58-
props: {
59-
color: SUI.COLORS,
60-
columns: [...SUI.WIDTHS, 'equal'],
61-
only: ['computer', 'large screen', 'mobile', 'tablet mobile', 'tablet', 'widescreen'],
62-
reversed: ['computer', 'computer vertically', 'mobile', 'mobile vertically', 'tablet', 'tablet vertically'],
63-
textAlign: SUI.TEXT_ALIGNMENTS,
64-
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
65-
},
6658
}
6759

6860
GridRow.propTypes = {
@@ -79,28 +71,30 @@ GridRow.propTypes = {
7971
className: PropTypes.string,
8072

8173
/** A grid row can be colored. */
82-
color: PropTypes.oneOf(GridRow._meta.props.color),
74+
color: PropTypes.oneOf(SUI.COLORS),
8375

8476
/** Represents column count per line in Row. */
85-
columns: PropTypes.oneOf(GridRow._meta.props.columns),
77+
columns: PropTypes.oneOf([...SUI.WIDTHS, 'equal']),
8678

8779
/** A row can have dividers between its columns. */
8880
divided: PropTypes.bool,
8981

9082
/** A row can appear only for a specific device, or screen sizes. */
91-
only: PropTypes.oneOf(GridRow._meta.props.only),
83+
only: PropTypes.oneOf(['computer', 'large screen', 'mobile', 'tablet mobile', 'tablet', 'widescreen']),
9284

9385
/** A row can specify that its columns should reverse order at different device sizes. */
94-
reversed: PropTypes.oneOf(GridRow._meta.props.reversed),
86+
reversed: PropTypes.oneOf([
87+
'computer', 'computer vertically', 'mobile', 'mobile vertically', 'tablet', 'tablet vertically',
88+
]),
9589

9690
/** An can stretch its contents to take up the entire column height. */
9791
stretched: PropTypes.bool,
9892

9993
/** A row can specify its text alignment. */
100-
textAlign: PropTypes.oneOf(GridRow._meta.props.textAlign),
94+
textAlign: PropTypes.oneOf(SUI.TEXT_ALIGNMENTS),
10195

10296
/** A row can specify its vertical alignment to have all its columns vertically centered. */
103-
verticalAlign: PropTypes.oneOf(GridRow._meta.props.verticalAlign),
97+
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
10498
}
10599

106100
export default GridRow

src/collections/Grid/index.d.ts

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1+
import * as React from 'react';
12
import {
23
SemanticCOLORS,
34
SemanticFLOATS,
45
SemanticTEXTALIGNMENTS,
56
SemanticVERTICALALIGNMENTS,
67
SemanticWIDTHS
78
} from '../..';
8-
import * as React from 'react';
99

10-
export type GridPropReversed = 'computer' | 'computer vertically' | 'mobile' | 'mobile vertically' | 'tablet' | 'tablet vertically';
10+
type GridPropOnly = 'computer' | 'large screen' | 'mobile' | 'tablet mobile' | 'tablet' | 'widescreen';
11+
type GridPropReversed = 'computer' | 'computer vertically' | 'mobile' | 'mobile vertically' | 'tablet' | 'tablet vertically';
12+
1113
export interface GridProps {
14+
[key: string]: any;
15+
1216
/** An element type to render as (string or function). */
1317
as?: any;
1418

1519
/** A grid can have rows divided into cells. */
16-
celled?: boolean|'internally';
20+
celled?: boolean | 'internally';
1721

1822
/** A grid can have its columns centered. */
1923
centered?: boolean;
@@ -27,6 +31,9 @@ export interface GridProps {
2731
/** Represents column count per row in Grid. */
2832
columns?: SemanticWIDTHS | 'equal';
2933

34+
/** A grid can be combined with a container to use avaiable layout and alignment. */
35+
container?: boolean;
36+
3037
/** A grid can have dividers between its columns. */
3138
divided?: boolean | 'vertically';
3239

@@ -55,15 +62,16 @@ export interface GridProps {
5562
verticalAlign?: SemanticVERTICALALIGNMENTS;
5663
}
5764

58-
interface GridClass extends React.ComponentClass<GridProps> {
65+
interface GridComponent extends React.StatelessComponent<GridProps> {
5966
Column: typeof GridColumn;
6067
Row: typeof GridRow;
6168
}
6269

63-
export const Grid: GridClass;
70+
export const Grid: GridComponent;
6471

65-
type GridPropOnly = 'computer' | 'large screen' | 'mobile' | 'tablet mobile' | 'tablet' | 'widescreen';
6672
interface GridColumnProps {
73+
[key: string]: any;
74+
6775
/** An element type to render as (string or function). */
6876
as?: any;
6977

@@ -110,9 +118,11 @@ interface GridColumnProps {
110118
width?: SemanticWIDTHS;
111119
}
112120

113-
export const GridColumn: React.ComponentClass<GridColumnProps>;
121+
export const GridColumn: React.StatelessComponent<GridColumnProps>;
114122

115123
interface GridRowProps {
124+
[key: string]: any;
125+
116126
/** An element type to render as (string or function). */
117127
as?: any;
118128

@@ -150,4 +160,4 @@ interface GridRowProps {
150160
verticalAlign?: SemanticVERTICALALIGNMENTS;
151161
}
152162

153-
export const GridRow: React.ComponentClass<GridRowProps>;
163+
export const GridRow: React.StatelessComponent<GridRowProps>;

test/specs/collections/Grid/Grid-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import GridRow from 'src/collections/Grid/GridRow'
66

77
describe('Grid', () => {
88
common.isConformant(Grid)
9-
common.hasUIClassName(Grid)
109
common.hasSubComponents(Grid, [GridRow, GridColumn])
10+
common.hasUIClassName(Grid)
1111
common.rendersChildren(Grid)
1212

1313
common.implementsTextAlignProp(Grid)

test/specs/collections/Grid/GridRow-test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ describe('GridRow', () => {
66
common.isConformant(GridRow)
77
common.rendersChildren(GridRow)
88

9+
common.implementsTextAlignProp(GridRow)
10+
common.implementsVerticalAlignProp(GridRow)
11+
common.implementsWidthProp(GridRow, { propKey: 'columns', widthClass: 'column', canEqual: true })
12+
913
common.propKeyAndValueToClassName(GridRow, 'only')
1014
common.propKeyAndValueToClassName(GridRow, 'reversed')
1115

@@ -14,8 +18,4 @@ describe('GridRow', () => {
1418
common.propKeyOnlyToClassName(GridRow, 'stretched')
1519

1620
common.propValueOnlyToClassName(GridRow, 'color', SUI.COLORS)
17-
18-
common.implementsTextAlignProp(GridRow)
19-
common.implementsVerticalAlignProp(GridRow)
20-
common.implementsWidthProp(GridRow, { propKey: 'columns', widthClass: 'column', canEqual: true })
2121
})

0 commit comments

Comments
 (0)