refactor(client): convert toggle-button to TypeScript
This commit is contained in:
@ -1,5 +1,4 @@
|
|||||||
import React, { Fragment } from 'react';
|
import React, { Fragment } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import {
|
import {
|
||||||
ToggleButtonGroup as BSBG,
|
ToggleButtonGroup as BSBG,
|
||||||
ToggleButton as TB
|
ToggleButton as TB
|
||||||
@ -9,15 +8,18 @@ import './toggle-button.css';
|
|||||||
import ToggleCheck from '../../assets/icons/ToggleCheck';
|
import ToggleCheck from '../../assets/icons/ToggleCheck';
|
||||||
import Spacer from '../../assets/icons/Spacer';
|
import Spacer from '../../assets/icons/Spacer';
|
||||||
|
|
||||||
const propTypes = {
|
interface ButtonProps {
|
||||||
name: PropTypes.string.isRequired,
|
name: string;
|
||||||
offLabel: PropTypes.string,
|
offLabel: string;
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: (value: string) => void;
|
||||||
onLabel: PropTypes.string,
|
onLabel: string;
|
||||||
value: PropTypes.bool.isRequired
|
value: boolean;
|
||||||
};
|
condition: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
function getActiveClass(condition) {
|
type ActiveClass = Pick<ButtonProps, 'condition'>;
|
||||||
|
|
||||||
|
function getActiveClass(condition: ActiveClass | unknown) {
|
||||||
return condition ? 'active' : 'not-active';
|
return condition ? 'active' : 'not-active';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ export default function ToggleButton({
|
|||||||
value,
|
value,
|
||||||
onLabel = 'On',
|
onLabel = 'On',
|
||||||
offLabel = 'Off'
|
offLabel = 'Off'
|
||||||
}) {
|
}: ButtonProps): React.ReactNode {
|
||||||
const checkIconStyle = {
|
const checkIconStyle = {
|
||||||
height: '15px',
|
height: '15px',
|
||||||
width: '20px'
|
width: '20px'
|
||||||
@ -71,4 +73,3 @@ export default function ToggleButton({
|
|||||||
}
|
}
|
||||||
|
|
||||||
ToggleButton.displayName = 'ToggleButton';
|
ToggleButton.displayName = 'ToggleButton';
|
||||||
ToggleButton.propTypes = propTypes;
|
|
Reference in New Issue
Block a user