1 |
|
2 | import React from 'react';
|
3 | import PropTypes from 'prop-types';
|
4 | import styled from 'styled-components';
|
5 |
|
6 | const RadioStyled = styled.div`
|
7 | height: ${props => props.theme.bahFormInputDefaultHeight};
|
8 | padding: ${props => props.theme.bahFormInputRadioCheckDefaultPadding};
|
9 | vertical-align: middle;
|
10 | width: 100%;
|
11 | margin-bottom: ${props => props.theme.bahFormFieldsDefaultMarginBottom};
|
12 |
|
13 | /* Hide base elements */
|
14 | input[type="radio"] {
|
15 | position: absolute;
|
16 | left: -9999px;
|
17 | }
|
18 |
|
19 | /* Position the <label> */
|
20 | input[type="radio"] + label {
|
21 | position: relative;
|
22 | display: inline-block;
|
23 | height: 17px;
|
24 | line-height: 17px;
|
25 | padding-left: 30px;
|
26 | cursor: pointer;
|
27 | }
|
28 |
|
29 | /* SHARED STYLES - Radio & Checkbox - Unchecked */
|
30 | input[type="radio"] + label:before {
|
31 | content: '';
|
32 | position: absolute;
|
33 | left: 0;
|
34 | top: 50%;
|
35 | transform: translateY(-50%);
|
36 | width: 18px;
|
37 | height: 18px;
|
38 | border: 2px solid ${props => props.theme.bahFormInputBorderColor};
|
39 | background-color: ${props => props.theme.bahFormInputBackgroundColor};
|
40 | }
|
41 |
|
42 | /* RADIO - Unchecked */
|
43 | input[type="radio"]:checked + label:before,
|
44 | input[type="radio"]:not(:checked) + label:before {
|
45 | border-radius: 50%;
|
46 | }
|
47 |
|
48 | /* RADIO - Checked */
|
49 | input[type="radio"]:checked + label:after {
|
50 | position: absolute;
|
51 | content: '';
|
52 | top: 50%;
|
53 | transform: translateY(-50%);
|
54 | left: 6px;
|
55 | width: 10px;
|
56 | height: 10px;
|
57 | border-radius: 50%;
|
58 | background-color: ${props => props.theme.bahFormInputBorderColor};
|
59 | }
|
60 |
|
61 | /* SHARED STYLES - Radio & Checkbox - Disabled */
|
62 | input[type="radio"]:disabled + label:before {
|
63 | border-color: #bbb;
|
64 | background-color: #ddd;
|
65 | }
|
66 |
|
67 | input[type="radio"]:disabled + label {
|
68 | color: #999;
|
69 | }
|
70 | `;
|
71 |
|
72 | const Radio = ({ children, id, disabled, name }) =>
|
73 | (<RadioStyled>
|
74 | <input type={'radio'} disabled={disabled} name={name} id={id} />
|
75 | <label htmlFor={id}>
|
76 | {children}
|
77 | </label>
|
78 | </RadioStyled>);
|
79 |
|
80 | Radio.defaultProps = {
|
81 | children: '',
|
82 | id: '',
|
83 | disabled: false,
|
84 | name: '',
|
85 | };
|
86 |
|
87 | Radio.propTypes = {
|
88 | children: PropTypes.string,
|
89 | id: PropTypes.string,
|
90 | disabled: PropTypes.bool,
|
91 | name: PropTypes.string,
|
92 | };
|
93 |
|
94 | export default Radio;
|
95 |
|
\ | No newline at end of file |