feat(theme): Add theme settings UI

This commit is contained in:
Bouncey
2018-09-14 13:20:51 +01:00
committed by Stuart Taylor
parent a41ef09932
commit efd8c18f5a
4 changed files with 109 additions and 4 deletions

View File

@@ -0,0 +1,58 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import {
ToggleButtonGroup as BSBG,
ToggleButton as TB
} from '@freecodecamp/react-bootstrap';
import './toggle-button.css';
const propTypes = {
name: PropTypes.string.isRequired,
offLabel: PropTypes.string,
onChange: PropTypes.func.isRequired,
onLabel: PropTypes.string,
value: PropTypes.bool.isRequired
};
function getActiveClass(condition) {
return condition ? 'active' : 'not-active';
}
export default function ToggleButton({
name,
onChange,
value,
onLabel = 'On',
offLabel = 'Off'
}) {
return (
<Fragment>
<BSBG name={name} onChange={onChange} type='radio'>
<TB
bsSize='lg'
bsStyle='primary'
className={`toggle-${getActiveClass(value)}`}
disabled={value}
type='radio'
value={1}
>
{onLabel}
</TB>
<TB
bsSize='lg'
bsStyle='primary'
className={`toggle-${getActiveClass(!value)}`}
disabled={!value}
type='radio'
value={2}
>
{offLabel}
</TB>
</BSBG>
</Fragment>
);
}
ToggleButton.displayName = 'ToggleButton';
ToggleButton.propTypes = propTypes;

View File

@@ -0,0 +1,16 @@
.toggle-active.btn[disabled] {
background-color: #006400;
opacity: 1;
}
.toggle-not-active.btn-primary.active {
background-color: #006400;
}
.toggle-not-active {
background-color: #dedede;
color: rgb(0, 49, 0);
}
.toggle-not-active:hover, .toggle-not-active:focus {
background-color: #006400;
}