Skip to content

Commit 87946a1

Browse files
committed
1.0.0
* Adding disjoint union for flow types * Updating some deps * Exporting flow types * Reflecting type changes in dependent modules * Updating .npmignore to exclude more files * Adding React as an external * Moving 1.0.0
1 parent 9144cff commit 87946a1

File tree

8 files changed

+1819
-232
lines changed

8 files changed

+1819
-232
lines changed

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ coverage/
55
flow-typed/
66
*.gif
77
.travis.yml
8+
.eslintrc.js
9+
.eslintignore
10+
.gitignore
11+
.prettierrc

package-lock.json

+1,720-186
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pretty-checkbox-react",
3-
"version": "0.0.10",
3+
"version": "1.0.0",
44
"description": "Quickly integrate pretty checkbox Components (checkbox, switch, radio) with React",
55
"keywords": [
66
"Pretty",
@@ -20,10 +20,10 @@
2020
"module": "dist/pretty-checkbox-react.es.js",
2121
"browser": "dist/pretty-checkbox-react.umd.min.js",
2222
"scripts": {
23-
"flow": "flow focus-check src/**",
23+
"build:flow": "flow focus-check src/components/** && flow-copy-source src dist",
2424
"lint": "eslint src/**",
2525
"pretest": "eslint src/**",
26-
"build": "rimraf dist/** && rollup -c rollup.config.js",
26+
"build": "rimraf dist/** && rollup -c rollup.config.js && npm run build:flow",
2727
"prepublish": "eslint src/** && jest && rollup -c rollup.config.js",
2828
"test": "jest"
2929
},
@@ -46,33 +46,35 @@
4646
},
4747
"devDependencies": {
4848
"@babel/core": "^7.2.2",
49-
"@babel/plugin-proposal-class-properties": "^7.2.3",
50-
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
51-
"@babel/preset-env": "^7.2.3",
49+
"@babel/plugin-proposal-class-properties": "^7.3.0",
50+
"@babel/plugin-proposal-object-rest-spread": "^7.3.1",
51+
"@babel/preset-env": "^7.3.1",
5252
"@babel/preset-flow": "^7.0.0",
5353
"@babel/preset-react": "^7.0.0",
5454
"babel-core": "^7.0.0-bridge.0",
5555
"babel-eslint": "^9.0.0",
5656
"babel-jest": "^23.6.0",
5757
"coveralls": "^3.0.2",
5858
"eslint": "5.6.0",
59-
"eslint-config-prettier": "^3.4.0",
59+
"eslint-config-prettier": "^3.6.0",
6060
"eslint-plugin-flowtype": "^3.2.1",
6161
"eslint-plugin-prettier": "^3.0.1",
62-
"eslint-plugin-react": "^7.12.3",
62+
"eslint-plugin-react": "^7.12.4",
6363
"flow": "^0.2.3",
64-
"flow-bin": "^0.90.0",
64+
"flow-bin": "^0.91.0",
65+
"flow-copy-source": "^2.0.2",
66+
"flow-coverage-report": "^0.6.1",
6567
"jest": "^23.6.0",
6668
"jest-dom": "^3.0.0",
67-
"prettier": "^1.15.3",
69+
"prettier": "^1.16.1",
6870
"pretty-checkbox": "^3.0.3",
6971
"react": "^16.7.0",
7072
"react-docgen": "^3.0.0-rc.2",
7173
"react-dom": "^16.7.0",
7274
"react-testing-library": "^5.4.4",
7375
"rimraf": "^2.6.3",
74-
"rollup": "^1.1.0",
75-
"rollup-plugin-babel": "^4.3.0",
76+
"rollup": "^1.1.2",
77+
"rollup-plugin-babel": "^4.3.2",
7678
"rollup-plugin-commonjs": "^9.2.0",
7779
"rollup-plugin-json": "^3.1.0",
7880
"rollup-plugin-node-resolve": "^4.0.0",

rollup.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const baseConfig = {
3030
plugins: [
3131
babel(),
3232
...commonPlugins
33-
]
33+
],
34+
external: ['react']
3435
};
3536

3637
const umd_export = {

src/components/Checkbox.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,19 @@ type CheckboxProps = {
1717
};
1818

1919
function Checkbox(props: CheckboxProps) {
20-
const { animation, icon, image, svg } = props;
21-
22-
if (animation && animation !== 'smooth' && animation !== 'pulse' && !icon && !image && !svg) {
20+
const { animation } = props;
21+
22+
if (animation
23+
&& animation !== 'smooth'
24+
&& animation !== 'pulse'
25+
&& !props.icon
26+
&& !props.image
27+
&& !props.svg) {
2328
throw new Error(`animation '${animation}' is incompatible with default checkbox styles. You must specify an icon, image, or a svg.`);
2429
}
2530

2631
return <Input className={classNames(
32+
// $ExpectError
2733
getBaseClassName(props, PREFIX),
2834
props.indeterminate ? 'p-has-indeterminate' : null
2935
)} type="checkbox" {...props} />;

src/components/Input.js

+67-24
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,29 @@ import classNames from 'classnames';
88
*/
99
export const PREFIX: string = 'p-';
1010

11-
export type InputProps = {
11+
type SVG = {|
12+
/**
13+
* Render a custom `.svg` in the checkbox or radio.
14+
*/
15+
svg: React.Element<'svg'>
16+
|};
17+
18+
19+
type Image = {|
20+
/**
21+
* Render a custom `img` in the checkbox or radio.
22+
*/
23+
image: React.Element<'img'>
24+
|};
25+
26+
type Icon = {|
27+
/**
28+
* Render a custom font icon in the checkbox or radio.
29+
*/
30+
icon: React.Element<any>
31+
|};
32+
33+
type BaseProps = {
1234
/**
1335
* Select the type if component: checkbox or radio.
1436
*/
@@ -40,22 +62,7 @@ export type InputProps = {
4062
/**
4163
* The shape of the checkbox or radio component.
4264
*/
43-
shape?: "round" | "curve",
44-
45-
/**
46-
* Render a custom font icon in the checkbox or radio.
47-
*/
48-
icon?: React.Element<any>,
49-
50-
/**
51-
* Render a custom `.svg` in the checkbox or radio.
52-
*/
53-
svg?: React.Element<'svg'>,
54-
55-
/**
56-
* Render a custom `img` in the checkbox or radio.
57-
*/
58-
image?: React.Element<'img'>,
65+
shape?: "round" | "curve" | "outline" | "fill" | "slim",
5966

6067
/**
6168
* Additional class selectors to pass to the `pretty` element.
@@ -125,6 +132,17 @@ export type InputProps = {
125132
plain?: boolean
126133
};
127134

135+
export type InputProps = {
136+
...BaseProps,
137+
...SVG
138+
} | {
139+
...BaseProps,
140+
...Image
141+
} | {
142+
...BaseProps,
143+
...Icon
144+
};
145+
128146
/**
129147
* Automatically append the className for icon component. This will automatically add
130148
* `icon` to icon prop components, `svg` to prop svg components, and `image` to
@@ -146,7 +164,32 @@ const fillClassNameForIcons = (component: React.Element<any> | void, className:
146164
/**
147165
* Handles custom or default rendering of the pretty-checkbox `div.state` class.
148166
*/
149-
const PrettyInputState = ({ children, render, id, color, icon, svg, image }: InputProps): React.Node => {
167+
const PrettyInputState = (props: InputProps): React.Node => {
168+
let node: {|
169+
className: string,
170+
node: any
171+
|} | null = null;
172+
173+
const { children, render, id, color } = props;
174+
175+
// yuck, needed for type refinement :(
176+
if (props.svg) {
177+
node = {
178+
className: 'svg',
179+
node: props.svg
180+
};
181+
} else if (props.icon) {
182+
node = {
183+
className: 'icon',
184+
node: props.icon
185+
};
186+
} else if (props.image) {
187+
node = {
188+
className: 'image',
189+
node: props.image
190+
};
191+
}
192+
150193
if (typeof children === 'function') {
151194
return children();
152195
}
@@ -157,7 +200,7 @@ const PrettyInputState = ({ children, render, id, color, icon, svg, image }: Inp
157200

158201
return (
159202
<div className={classNames('state', color ? PREFIX + color : null)} data-testid="pcr-state">
160-
{fillClassNameForIcons(icon, 'icon') || fillClassNameForIcons(svg, 'svg') || fillClassNameForIcons(image, 'image') || null}
203+
{node ? fillClassNameForIcons(node.node, node.className) : null}
161204
{children ? <label htmlFor={id}>{children}</label> : null}
162205
</div>
163206
);
@@ -178,13 +221,10 @@ function Input(props: InputProps) {
178221
bigger,
179222
shape,
180223
style,
181-
image,
182-
svg,
183-
icon,
184224
plain
185225
} = props;
186226

187-
if ((icon && svg) || (icon && image) || (svg && image)) {
227+
if ((props.icon && props.svg) || (props.icon && props.image) || (props.svg && props.image)) {
188228
throw new Error('icon, svg, and image are mutually exclusive props; choose one');
189229
}
190230

@@ -212,7 +252,10 @@ function Input(props: InputProps) {
212252
data-testid="pcr-input"
213253
{...inputProps}
214254
/>
215-
<PrettyInputState {...props} />
255+
{
256+
// $ExpectError
257+
<PrettyInputState {...props} />
258+
}
216259
</div>
217260
);
218261
}

src/components/Radio.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function Radio(props: RadioProps) {
2222
return (
2323
<Input
2424
type="radio"
25-
className={classNames(getBaseClassName(props, PREFIX), className)}
25+
className={classNames(
26+
// $ExpectError
27+
getBaseClassName(props, PREFIX), className)}
2628
inputProps={{ ...inputProps, name: name }}
2729
{...rest}
2830
/>

src/components/Switch.js

-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ function Switch(props: SwitchProps) {
4040
throw new Error('Switch animations can be one of the following: smooth, jelly, or tada');
4141
}
4242

43-
// if (type === 'radio' && !name) {
44-
// console.warn('Using a radio control without a name specified can lead to unexpected behavior');
45-
// }
46-
47-
// $ExpectError
4843
return (
4944
<Input className={classNames(`${PREFIX}switch`, className)}
5045
type={type}

0 commit comments

Comments
 (0)