Skip to content

Commit 5652ee5

Browse files
author
Alexander Fedyashov
committed
style(Checkbox|Flag|Image|Radio): propTypes cleanups
1 parent b7ffa6a commit 5652ee5

File tree

11 files changed

+79
-91
lines changed

11 files changed

+79
-91
lines changed

src/addons/Radio/Radio.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { PropTypes } from 'react'
1+
import React from 'react'
22

33
import { getUnhandledProps, META } from '../../lib'
44
import Checkbox from '../../modules/Checkbox'
@@ -23,20 +23,17 @@ function Radio(props) {
2323
Radio._meta = {
2424
name: 'Radio',
2525
type: META.TYPES.ADDON,
26-
props: {
27-
type: Checkbox._meta.props.type,
28-
},
2926
}
3027

3128
Radio.propTypes = {
32-
/** Format to emphasize the current selection state */
29+
/** Format to emphasize the current selection state. */
3330
slider: Checkbox.propTypes.slider,
3431

35-
/** Format to show an on or off choice */
32+
/** Format to show an on or off choice. */
3633
toggle: Checkbox.propTypes.toggle,
3734

3835
/** HTML input type, either checkbox or radio. */
39-
type: PropTypes.oneOf(Radio._meta.props.type),
36+
type: Checkbox.propTypes.type,
4037
}
4138

4239
Radio.defaultProps = {

src/addons/Radio/index.d.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
import { CheckboxProps } from '../../modules/Checkbox/index';
21
import * as React from 'react';
32

4-
export const Radio: React.ComponentClass<CheckboxProps>;
3+
interface RadioProps {
4+
[key: string]: any;
5+
6+
/** Format to emphasize the current selection state. */
7+
slider?: boolean;
8+
9+
/** Format to show an on or off choice. */
10+
toggle?: boolean;
11+
12+
/** HTML input type, either checkbox or radio. */
13+
type?: 'checkbox' | 'radio';
14+
}
15+
16+
export const Radio: React.StatelessComponent<RadioProps>;

src/elements/Flag/Flag.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ const names = [
5353
'ye', 'yemen', 'yt', 'mayotte', 'za', 'south africa', 'zm', 'zambia', 'zw', 'zimbabwe',
5454
]
5555

56+
/**
57+
* A flag is is used to represent a political state.
58+
**/
5659
function Flag(props) {
5760
const { className, name } = props
58-
const classes = cx(name, className, 'flag')
61+
const classes = cx(name, 'flag', className)
5962
const rest = getUnhandledProps(Flag, props)
6063
const ElementType = getElementType(Flag, props)
6164

@@ -65,9 +68,6 @@ function Flag(props) {
6568
Flag._meta = {
6669
name: 'Flag',
6770
type: META.TYPES.ELEMENT,
68-
props: {
69-
name: names,
70-
},
7171
}
7272

7373
Flag.propTypes = {
@@ -77,8 +77,8 @@ Flag.propTypes = {
7777
/** Additional classes. */
7878
className: PropTypes.string,
7979

80-
/** Flag name, can use the two digit country code, the full name, or a common alias */
81-
name: customPropTypes.suggest(Flag._meta.props.name),
80+
/** Flag name, can use the two digit country code, the full name, or a common alias. */
81+
name: customPropTypes.suggest(names),
8282
}
8383

8484
Flag.defaultProps = {
@@ -88,4 +88,3 @@ Flag.defaultProps = {
8888
Flag.create = createShorthandFactory(Flag, value => ({ name: value }))
8989

9090
export default Flag
91-

src/elements/Flag/index.d.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
import { ReactMouseEvents, SemanticCOUNTRY } from '../..';
21
import * as React from 'react';
2+
import { SemanticCOUNTRY } from '../..';
33

4-
// Flag
5-
// ----------------------------------
6-
interface FlagProps extends ReactMouseEvents<any> {
4+
interface FlagProps {
5+
[key: string]: any;
76

87
/** An element type to render as (string or function). */
98
as?: any;
109

1110
/** Additional classes. */
1211
className?: string;
1312

14-
/** Flag name, can use the two digit country code, the full name, or a common alias */
13+
/** Flag name, can use the two digit country code, the full name, or a common alias. */
1514
name: SemanticCOUNTRY,
1615
}
1716

18-
export class Flag extends React.Component<FlagProps, void> {
19-
}
17+
export const Flag : React.StatelessComponent<FlagProps>;

src/elements/Image/Image.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,6 @@ Image.Group = ImageGroup
9595
Image._meta = {
9696
name: 'Image',
9797
type: META.TYPES.ELEMENT,
98-
props: {
99-
verticalAlign: SUI.VERTICAL_ALIGNMENTS,
100-
floated: SUI.FLOATS,
101-
shape: ['rounded', 'circular'],
102-
size: SUI.SIZES,
103-
spaced: ['left', 'right'],
104-
},
10598
}
10699

107100
Image.propTypes = {
@@ -133,7 +126,7 @@ Image.propTypes = {
133126
dimmer: customPropTypes.itemShorthand,
134127

135128
/** An image can sit to the left or right of other content. */
136-
floated: PropTypes.oneOf(Image._meta.props.floated),
129+
floated: PropTypes.oneOf(SUI.FLOATS),
137130

138131
/** An image can take up the width of its container. */
139132
fluid: customPropTypes.every([
@@ -160,15 +153,15 @@ Image.propTypes = {
160153
label: customPropTypes.itemShorthand,
161154

162155
/** An image may appear rounded or circular. */
163-
shape: PropTypes.oneOf(Image._meta.props.shape),
156+
shape: PropTypes.oneOf(['rounded', 'circular']),
164157

165158
/** An image may appear at different sizes. */
166-
size: PropTypes.oneOf(Image._meta.props.size),
159+
size: PropTypes.oneOf(SUI.SIZES),
167160

168161
/** An image can specify that it needs an additional spacing to separate it from nearby content. */
169162
spaced: PropTypes.oneOfType([
170163
PropTypes.bool,
171-
PropTypes.oneOf(Image._meta.props.spaced),
164+
PropTypes.oneOf(['left', 'right']),
172165
]),
173166

174167
/** Specifies the URL of the image. */
@@ -177,16 +170,16 @@ Image.propTypes = {
177170
/** Whether or not to add the ui className. */
178171
ui: PropTypes.bool,
179172

180-
/** An image can specify its vertical alignment */
181-
verticalAlign: PropTypes.oneOf(Image._meta.props.verticalAlign),
173+
/** An image can specify its vertical alignment. */
174+
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS),
182175

183-
/** The img element width attribute */
176+
/** The img element width attribute. */
184177
width: PropTypes.oneOfType([
185178
PropTypes.string,
186179
PropTypes.number,
187180
]),
188181

189-
/** An image can render wrapped in a `div.ui.image` as alternative HTML markup */
182+
/** An image can render wrapped in a `div.ui.image` as alternative HTML markup. */
190183
wrapped: customPropTypes.every([
191184
PropTypes.bool,
192185
// these props wrap the image in an a tag already

src/elements/Image/ImageGroup.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../../lib'
1111

1212
/**
13-
* A group of images
13+
* A group of images.
1414
*/
1515
function ImageGroup(props) {
1616
const { children, className, size } = props
@@ -25,9 +25,6 @@ ImageGroup._meta = {
2525
name: 'ImageGroup',
2626
parent: 'Image',
2727
type: META.TYPES.ELEMENT,
28-
props: {
29-
size: SUI.SIZES,
30-
},
3128
}
3229

3330
ImageGroup.propTypes = {
@@ -41,7 +38,7 @@ ImageGroup.propTypes = {
4138
className: PropTypes.string,
4239

4340
/** A group of images can be formatted to have the same size. */
44-
size: PropTypes.oneOf(ImageGroup._meta.props.size),
41+
size: PropTypes.oneOf(SUI.SIZES),
4542
}
4643

4744
export default ImageGroup

src/elements/Image/index.d.ts

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { LabelProps } from '../Label';
22
import {
3-
ReactMouseEvents,
43
SemanticFLOATS,
54
SemanticSIZES,
65
SemanticVERTICALALIGNMENTS,
@@ -9,10 +8,8 @@ import {
98
} from '../..';
109
import * as React from 'react';
1110

12-
13-
// Image
14-
// ----------------------------------
15-
export interface ImageProps extends ReactMouseEvents<any> {
11+
export interface ImageProps {
12+
[key: string]: any;
1613

1714
/** Alternate text for the image specified. */
1815
alt?: string;
@@ -36,7 +33,7 @@ export interface ImageProps extends ReactMouseEvents<any> {
3633
disabled?: boolean;
3734

3835
/** Shorthand for Dimmer. */
39-
dimmer?:any;
36+
dimmer?: any;
4037

4138
/** An image can sit to the left or right of other content. */
4239
floated?: SemanticFLOATS;
@@ -54,10 +51,10 @@ export interface ImageProps extends ReactMouseEvents<any> {
5451
inline?: boolean;
5552

5653
/** Shorthand for Label. */
57-
label?: LabelProps;
54+
label?: any | LabelProps;
5855

5956
/** An image may appear rounded or circular. */
60-
shape?: boolean |'rounded'|'circular';
57+
shape?: 'rounded'|'circular';
6158

6259
/** An image may appear at different sizes. */
6360
size?: SemanticSIZES;
@@ -71,24 +68,25 @@ export interface ImageProps extends ReactMouseEvents<any> {
7168
/** Whether or not to add the ui className. */
7269
ui?: boolean;
7370

74-
/** An image can specify its vertical alignment */
71+
/** An image can specify its vertical alignment. */
7572
verticalAlign?: SemanticVERTICALALIGNMENTS;
7673

77-
/** The img element width attribute */
74+
/** The img element width attribute. */
7875
width?: number|SemanticWIDTHSSTRING| SemanticWIDTHSNUMBER;
7976

80-
/** An image can render wrapped in a `div.ui.image` as alternative HTML markup */
81-
wrapped?: any;
77+
/** An image can render wrapped in a `div.ui.image` as alternative HTML markup. */
78+
wrapped?: boolean;
8279
}
8380

84-
interface ImageClass extends React.ComponentClass<ImageProps> {
81+
interface ImageComponent extends React.StatelessComponent<ImageProps> {
8582
Group: typeof ImageGroup;
8683
}
8784

88-
export const Image: ImageClass;
85+
export const Image: ImageComponent;
8986

9087
interface ImageGroupProps {
91-
88+
[key: string]: any;
89+
9290
/** An element type to render as (string or function). */
9391
as?: any;
9492

@@ -101,4 +99,4 @@ interface ImageGroupProps {
10199
/** A group of images can be formatted to have the same size. */
102100
size?: SemanticSIZES;
103101
}
104-
export const ImageGroup: React.ComponentClass<ImageGroupProps>;
102+
export const ImageGroup: React.StatelessComponent<ImageGroupProps>;

src/modules/Checkbox/Checkbox.js

+10-18
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,8 @@ import {
1414
} from '../../lib'
1515
const debug = makeDebugger('checkbox')
1616

17-
const _meta = {
18-
name: 'Checkbox',
19-
type: META.TYPES.MODULE,
20-
props: {
21-
type: [
22-
'checkbox',
23-
'radio',
24-
],
25-
},
26-
}
27-
2817
/**
29-
* A checkbox allows a user to select a value from a small set of options, often binary
18+
* A checkbox allows a user to select a value from a small set of options, often binary.
3019
* @see Form
3120
* @see Radio
3221
*/
@@ -78,29 +67,29 @@ export default class Checkbox extends Component {
7867
*/
7968
onClick: PropTypes.func,
8069

81-
/** Format as a radio element. This means it is an exclusive option.*/
70+
/** Format as a radio element. This means it is an exclusive option. */
8271
radio: customPropTypes.every([
8372
PropTypes.bool,
8473
customPropTypes.disallow(['slider', 'toggle']),
8574
]),
8675

87-
/** A checkbox can be read-only and unable to change states */
76+
/** A checkbox can be read-only and unable to change states. */
8877
readOnly: PropTypes.bool,
8978

90-
/** Format to emphasize the current selection state */
79+
/** Format to emphasize the current selection state. */
9180
slider: customPropTypes.every([
9281
PropTypes.bool,
9382
customPropTypes.disallow(['radio', 'toggle']),
9483
]),
9584

96-
/** Format to show an on or off choice */
85+
/** Format to show an on or off choice. */
9786
toggle: customPropTypes.every([
9887
PropTypes.bool,
9988
customPropTypes.disallow(['radio', 'slider']),
10089
]),
10190

10291
/** HTML input type, either checkbox or radio. */
103-
type: PropTypes.oneOf(_meta.props.type),
92+
type: PropTypes.oneOf(['checkbox', 'radio']),
10493

10594
/** The HTML input value. */
10695
value: PropTypes.string,
@@ -121,7 +110,10 @@ export default class Checkbox extends Component {
121110
'indeterminate',
122111
]
123112

124-
static _meta = _meta
113+
static _meta = {
114+
name: 'Checkbox',
115+
type: META.TYPES.MODULE,
116+
}
125117

126118
state = {}
127119

0 commit comments

Comments
 (0)