Skip to content

Commit f4f9fc1

Browse files
NeloopMartin Kruliš
authored andcommitted
Style standalone radio inputs with unified radio appearance
1 parent dc5fd32 commit f4f9fc1

File tree

9 files changed

+140
-84
lines changed

9 files changed

+140
-84
lines changed

src/components/Users/EffectiveRoleSwitching/EffectiveRoleSwitching.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Table } from 'react-bootstrap';
44
import classnames from 'classnames';
55

66
import { knownRoles, roleLabels, UserRoleIcon } from '../../helpers/usersRoles';
7+
import StandaloneRadioInput from '../../forms/StandaloneRadioInput/StandaloneRadioInput';
78

89
const EffectiveRoleSwitching = ({ effectiveRole, setEffectiveRole, updating = null }) => (
910
<Table hover className="no-margin">
@@ -19,8 +20,7 @@ const EffectiveRoleSwitching = ({ effectiveRole, setEffectiveRole, updating = nu
1920
setEffectiveRole(role);
2021
}}>
2122
<td className="shrink-col">
22-
<input
23-
type="radio"
23+
<StandaloneRadioInput
2424
name="effectiveRole"
2525
value={role}
2626
checked={role === (updating || effectiveRole)}

src/components/forms/EditUserRoleForm/EditUserRoleForm.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { FormattedMessage, injectIntl } from 'react-intl';
4-
import { reduxForm, Field } from 'redux-form';
4+
import { reduxForm } from 'redux-form';
55
import { Alert, Table } from 'react-bootstrap';
66
import classnames from 'classnames';
77

88
import { knownRoles, roleLabels, roleDescriptions, UserRoleIcon } from '../../helpers/usersRoles';
99
import FormBox from '../../widgets/FormBox';
1010
import SubmitButton from '../SubmitButton';
11+
import StandaloneRadioField from '../Fields/StandaloneRadioField';
1112

1213
const EditUserRoleForm = ({
1314
currentRole = null,
@@ -55,7 +56,7 @@ const EditUserRoleForm = ({
5556
})}
5657
onClick={() => change('role', role)}>
5758
<td className="shrink-col text-nowrap text-center">
58-
<Field name="role" component="input" type="radio" value={role} />
59+
<StandaloneRadioField name="role" value={role} />
5960
</td>
6061
<td className="shrink-col text-nowrap text-center">
6162
<UserRoleIcon role={role} />

src/components/forms/Fields/RadioField.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@ import PropTypes from 'prop-types';
33

44
import { FormGroup, HelpBlock, Radio } from 'react-bootstrap';
55

6-
import styles from './RadioField.less';
7-
86
const RadioField = ({ input, meta: { error, warning }, options }) => {
97
return (
108
<FormGroup validationState={error ? 'error' : warning ? 'warning' : undefined} controlId={input.name}>
119
{options.map(({ key, name }, idx) => (
1210
<Radio
13-
className={styles.radioContainer}
11+
className={'radio-container'}
1412
key={`radio${idx}-${key}`}
1513
name={input.name}
1614
value={key}
1715
checked={input.value === key}
1816
onChange={input.onChange}>
1917
{name}
20-
<span className={styles.radiomark}></span>
18+
<span className={'radiomark'}></span>
2119
</Radio>
2220
))}
2321

src/components/forms/Fields/RadioField.less

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { Field } from 'redux-form';
4+
5+
const StandaloneRadioField = ({ name, value }) => {
6+
return (
7+
<div className={'radio-container'}>
8+
<label>
9+
<Field name={name} component="input" type="radio" value={value} />
10+
<span className={'radiomark'}></span>
11+
</label>
12+
</div>
13+
);
14+
};
15+
16+
StandaloneRadioField.propTypes = {
17+
name: PropTypes.string.isRequired,
18+
value: PropTypes.string.isRequired,
19+
};
20+
21+
export default StandaloneRadioField;

src/components/forms/Fields/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export { default as ExpandingTextField } from './ExpandingTextField';
2323
export { default as ExpandingSelectField } from './ExpandingSelectField';
2424
export { default as ExpandingInputFilesField } from './ExpandingInputFilesField';
2525
export { default as TagsSelectorField } from './TagsSelectorField';
26+
export { default as StandaloneRadioField } from './StandaloneRadioField';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
const StandaloneRadioInput = ({ name, value, checked, disabled, readOnly }) => {
5+
return (
6+
<div className={'radio-container'}>
7+
<label>
8+
<input
9+
type="radio"
10+
name={name}
11+
value={value}
12+
checked={checked}
13+
disabled={disabled}
14+
readOnly={readOnly}
15+
/>
16+
<span className={'radiomark'}></span>
17+
</label>
18+
</div>
19+
);
20+
};
21+
22+
StandaloneRadioInput.propTypes = {
23+
name: PropTypes.string.isRequired,
24+
value: PropTypes.string.isRequired,
25+
checked: PropTypes.bool,
26+
disabled: PropTypes.bool,
27+
readOnly: PropTypes.bool,
28+
};
29+
30+
export default StandaloneRadioInput;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import StandaloneRadioInput from './StandaloneRadioInput';
2+
export default StandaloneRadioInput;

src/containers/App/recodex.css

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,82 @@ table.table-hover td.clickable:hover, table.table-hover th.clickable:hover {
226226
.noselection .ace_cursor {
227227
color: transparent !important;
228228
}
229+
230+
/******************************************************************************/
231+
/* Radio Input Styling */
232+
/* Taken from W3Schools and adapted for our use case... */
233+
/* https://www.w3schools.com/howto/howto_css_custom_checkbox.asp */
234+
/******************************************************************************/
235+
236+
/* Customize the container of the radio input */
237+
.radio-container {
238+
display: block;
239+
position: relative;
240+
padding-left: 35px;
241+
}
242+
243+
/* Remove default label margin and paddings */
244+
.radio-container label {
245+
padding: 0;
246+
margin: 0;
247+
cursor: pointer;
248+
}
249+
250+
/* Hide the browser's default radio button */
251+
.radio-container input {
252+
position: absolute;
253+
opacity: 0;
254+
cursor: pointer;
255+
height: 0;
256+
width: 0;
257+
}
258+
259+
/* Create a custom radio button */
260+
.radiomark {
261+
position: absolute;
262+
top: 0;
263+
left: 0;
264+
height: 20px;
265+
width: 20px;
266+
background-color: #eee;
267+
border-radius: 50%;
268+
}
269+
270+
/* On mouse-over, add a grey background color */
271+
.radio-container label:hover input ~ .radiomark {
272+
background-color: #ccc;
273+
}
274+
275+
/* When the radio button is checked, add a green background */
276+
.radio-container label input:checked ~ .radiomark {
277+
background-color: #00a65a;
278+
}
279+
280+
/* On mouse-over, when the radio button is checked, add a darker green background */
281+
.radio-container label:hover input:checked ~ .radiomark {
282+
background-color: #008d4c;
283+
}
284+
285+
/* Create the indicator (the dot/circle - hidden when not checked) */
286+
.radiomark:after {
287+
content: "";
288+
position: absolute;
289+
display: none;
290+
}
291+
292+
/* Show the indicator (dot/circle) when checked */
293+
.radio-container input:checked ~ .radiomark:after {
294+
display: block;
295+
}
296+
297+
/* Style the indicator (dot/circle) */
298+
.radio-container .radiomark:after {
299+
top: 4px;
300+
left: 4px;
301+
width: 12px;
302+
height: 12px;
303+
border-radius: 50%;
304+
background: #eee;
305+
}
306+
307+
/******************************************************************************/

0 commit comments

Comments
 (0)