Skip to content

Commit

Permalink
Add components/Checkbox, Input, Radio
Browse files Browse the repository at this point in the history
  • Loading branch information
heimdallrj authored and thinkholic committed Aug 11, 2020
1 parent 03899d5 commit 764b6f3
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/components/Checkbox/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import PropTypes from 'prop-types';

import Input from '../Input';

export default function Checkbox({
name,
checked,
label,
wrapperStyle,
inputStyle,
labelStyle,
...restProps
}) {
return (
<div style={wrapperStyle}>
<Input
{...restProps}
type="checkbox"
name={name}
checked={checked}
style={inputStyle}
/>
<label style={labelStyle} htmlFor={name}>
{label}
</label>
</div>
);
}

Checkbox.propTypes = {
name: PropTypes.string,
checked: PropTypes.bool,
label: PropTypes.string,
wrapperStyle: PropTypes.object,
inputStyle: PropTypes.object,
labelStyle: PropTypes.object,
};

Checkbox.defaultProps = {
checked: false
};
55 changes: 55 additions & 0 deletions src/components/Input/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import PropTypes from 'prop-types';

export default function Input({
type,
name,
minLength,
maxLength,
size,
...restProps
}) {
return (
<input
{...restProps}
type={type}
id={name}
name={name}
minLength={minLength}
maxLength={maxLength}
size={size}
/>
);
}

Input.propTypes = {
type: PropTypes.oneOf([
'color',
'date',
'datetime-local',
'email',
'file',
'hidden',
'checkbox',
'radio',
'image',
'month',
'number',
'password',
'range',
'search',
'tel',
'text',
'time',
'url',
'week',
]).isRequired,
name: PropTypes.string,
minLength: PropTypes.number,
maxLength: PropTypes.number,
size: PropTypes.number,
};

Input.defaultProps = {
type: 'text',
};
45 changes: 45 additions & 0 deletions src/components/Radio/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import PropTypes from 'prop-types';

import Input from '../Input';

export default function Radio({
name,
value,
checked,
label,
wrapperStyle,
inputStyle,
labelStyle,
...restProps
}) {
return (
<div style={wrapperStyle}>
<Input
{...restProps}
type="radio"
name={name}
checked={checked}
style={inputStyle}
value={value}
/>
<label style={labelStyle} htmlFor={name}>
{label}
</label>
</div>
);
}

Radio.propTypes = {
name: PropTypes.string,
value: PropTypes.string,
checked: PropTypes.bool,
label: PropTypes.string,
wrapperStyle: PropTypes.object,
inputStyle: PropTypes.object,
labelStyle: PropTypes.object,
};

Radio.defaultProps = {
checked: false
};

0 comments on commit 764b6f3

Please sign in to comment.