Skip to content

Commit dae83f4

Browse files
committed
1.0.4
* Fixing missing className prop from Checkbox * Updating snapshot tests * Minor test enhancements to support bug fix
1 parent 973b63a commit dae83f4

File tree

6 files changed

+27
-16
lines changed

6 files changed

+27
-16
lines changed

docs/src/sections/FAQ.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const scss = `// @import ...
1717

1818
const jsx = `import { Checkbox } from 'pretty-checkbox-react';
1919
20+
// pass a custom className to Checkbox, Radio, or Switch
2021
<Checkbox className="my-icon"
2122
icon={<i className="fas fas-question-circle" />}>
2223
Label
@@ -41,16 +42,14 @@ function FAQ() {
4142
<Title>FAQ</Title>
4243
<div className="content">
4344
<ol>
44-
<QA title={<>Formik overrides <code>p-icon</code> styles</>}>
45-
If you are using Formik and adding a pretty-checkbox or pretty-checkbox-react component, then you might be seeing visual discrepancies.
46-
We can get around this by using the render prop or child render function exposed by <strong>pretty-react-checkbox</strong>.
45+
<QA title={<> Something is overriding <code>pretty-checkbox</code> styles!</>}>
46+
Sometimes things aren't perfect and styles get messed up. Thankfully, we can fix this easily!
4747
The easiest way to get around this is to custom build pretty-checkbox <code>.scss</code> source files.
4848
Once you have that in place we need to make a few tweaks.
4949
<SyntaxHighlighter language="scss" style={darcula}>{scss}</SyntaxHighlighter>
5050
With the magic of using Sass <code>@extends</code> we can essentially "copy" the pretty-checkbox base styles to our own selector.
5151
After this, our usage becomes a bit different as well.
5252
<SyntaxHighlighter language="jsx" style={darcula}>{jsx}</SyntaxHighlighter>
53-
Formik will still apply styles to <code>p-icon</code>, but the styles shouldn't clash anymore.
5453
</QA>
5554
<QA title="How can I customize pretty-checkbox state div?">
5655
Good question! All components offer <code>render</code> prop and <code>children</code> render function support. It's as easy as this:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pretty-checkbox-react",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Quickly integrate pretty checkbox Components (checkbox, switch, radio) with React",
55
"keywords": [
66
"Pretty",

src/components/Checkbox.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export type CheckboxProps = {
1717
};
1818

1919
function Checkbox(props: CheckboxProps) {
20-
const { animation } = props;
20+
const { animation, className, ...rest } = props;
2121

2222
if (animation
2323
&& animation !== 'smooth'
@@ -28,11 +28,16 @@ function Checkbox(props: CheckboxProps) {
2828
throw new Error(`animation '${animation}' is incompatible with default checkbox styles. You must specify an icon, image, or a svg.`);
2929
}
3030

31-
return <Input className={classNames(
32-
// $ExpectError
33-
getBaseClassName(props, PREFIX),
34-
props.indeterminate ? 'p-has-indeterminate' : null
35-
)} type="checkbox" {...props} />;
31+
return (
32+
<Input type="checkbox"
33+
className={classNames(
34+
// $ExpectError
35+
getBaseClassName(props, PREFIX),
36+
props.indeterminate ? 'p-has-indeterminate' : null,
37+
className
38+
)}
39+
{...rest} />
40+
);
3641
}
3742

3843
export default Checkbox;

src/components/Radio.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ function Radio(props: RadioProps) {
2222
return (
2323
<Input
2424
type="radio"
25-
className={classNames(
26-
// $ExpectError
27-
getBaseClassName(props, PREFIX), className)}
25+
className={
26+
classNames(
27+
// $ExpectError
28+
getBaseClassName(props, PREFIX),
29+
className
30+
)
31+
}
2832
inputProps={{ ...inputProps, name: name }}
2933
{...rest}
3034
/>

src/components/__tests__/Checkbox.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ describe('Checkbox tests', function () {
1111
describe('Basic Checkbox usage', function () {
1212
it('should behave as a checkbox', function () {
1313
const handleChange = jest.fn();
14-
const { container } = render(<Checkbox id="foo" onChange={handleChange} />);
14+
const { container, debug } = render(<Checkbox className="dummy-selector" id="foo" onChange={handleChange} />);
15+
16+
debug();
1517

1618
expect(getByTestId(container, 'pcr-input')).toHaveAttribute('type', 'checkbox');
19+
expect(getByTestId(container, 'pcr-wrapper')).toHaveClass('dummy-selector');
1720

1821
fireEvent.click(getByTestId(container, 'pcr-input'));
1922

src/components/__tests__/__snapshots__/Checkbox.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`Checkbox tests Basic Checkbox usage should behave as a checkbox 1`] = `
44
<div>
55
<div
6-
class="pretty p-default"
6+
class="pretty p-default dummy-selector"
77
data-testid="pcr-wrapper"
88
>
99
<input

0 commit comments

Comments
 (0)