Skip to content

Commit

Permalink
v1.4.0 - support for noMargins-flag, disabling top and bottom margins
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Wendel committed Jun 6, 2016
1 parent 659bdce commit aa66418
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ffe-checkbox-react

React implementation of the checkbox found in FFE.
React implementation of the checkbox found in FFE

## Install

Expand All @@ -20,17 +20,15 @@ import Checkbox from 'ffe-checkbox-react';
onChange={ function }
checked={ boolean }
name={ string }
label={ string }
label={ string }
noMargins={ boolean} // disables top- and bottom margins, useful for use in tables etc
/>
```

If you need a description thats more complex than just a string, use `children`:
If you need a more complex description, use `children`:

```
<Checkbox
onChange={ function }
checked={ boolean }
name={ string } >
<Checkbox>
<Icon />
Some text
<AnotherIcon />
Expand Down
3 changes: 2 additions & 1 deletion docs/example-component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Checkbox from '../lib/checkbox';
import Checkbox from '../src/checkbox';
import React from 'react';

export const MainExample = (
Expand All @@ -15,4 +15,5 @@ export default props => <Checkbox
checked={props.checked}
name={props.name}
label={props.label}
noMargins={props.noMargins}
/>;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffe-checkbox-react",
"version": "1.3.0",
"version": "1.4.0",
"main": "lib/checkbox.js",
"scripts": {
"build": "babel -d lib/. --ignore=*.test.js src/. && npm run example",
Expand All @@ -18,6 +18,7 @@
"ffe-core": "^6.0.0"
},
"dependencies": {
"classnames": "2.2.5",
"nfe-hash": "^1.1.0"
},
"devDependencies": {
Expand Down
11 changes: 9 additions & 2 deletions src/checkbox.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React, { PropTypes } from 'react';
import hash from 'nfe-hash';
import classNames from 'classnames';

export default function CheckBox({ name, label, onChange, checked, children }) {
export default function CheckBox({ name, label, onChange, checked, children, noMargins }) {
const id = `checkbox-${hash(name)}`;
const classes = classNames({
'ffe-checkbox': true,
'ffe-checkbox--inline': true,
'ffe-checkbox--no-margins': noMargins
});

return <span>
<input
Expand All @@ -13,7 +19,7 @@ export default function CheckBox({ name, label, onChange, checked, children }) {
name={name}
id={id}
/>
<label className="ffe-checkbox ffe-checkbox--inline" htmlFor={id}>
<label className={ classes } htmlFor={id}>
{label || children}
</label>
</span>;
Expand All @@ -24,5 +30,6 @@ CheckBox.propTypes = {
label: PropTypes.string.isRequired,
onChange: PropTypes.func,
checked: PropTypes.bool,
noMargins: PropTypes.bool,
children: PropTypes.array
};
10 changes: 10 additions & 0 deletions src/checkbox.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ describe('<Checkbox />', () => {
wrapper.find('input').prop('id')
);
});

it('should support noMargins', () => {
assert.equal(
shallow(CreateCheckbox({ noMargins: false })).find('.ffe-checkbox--no-margins').length,
0);

assert.equal(
shallow(CreateCheckbox({ noMargins: true })).find('.ffe-checkbox--no-margins').length,
1);
});

});

0 comments on commit aa66418

Please sign in to comment.