mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-05-06 11:43:03 +03:00
More elements migrated to typescript
This commit is contained in:
parent
62df46d648
commit
2eba607874
9 changed files with 47 additions and 45 deletions
src/utils
34
src/utils/BooleanControl.tsx
Normal file
34
src/utils/BooleanControl.tsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
import React, { ChangeEvent, FC } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { identity } from 'ramda';
|
||||
|
||||
export interface BooleanControlProps {
|
||||
checked?: boolean;
|
||||
onChange?: (checked: boolean, e: ChangeEvent<HTMLInputElement>) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
interface BooleanControlWithTypeProps extends BooleanControlProps {
|
||||
type: 'switch' | 'checkbox';
|
||||
}
|
||||
|
||||
const BooleanControl: FC<BooleanControlWithTypeProps> = (
|
||||
{ checked = false, onChange = identity, className, children, type },
|
||||
) => {
|
||||
const id = uuid();
|
||||
const onChecked = (e: ChangeEvent<HTMLInputElement>) => onChange(e.target.checked, e);
|
||||
const typeClasses = {
|
||||
'custom-switch': type === 'switch',
|
||||
'custom-checkbox': type === 'checkbox',
|
||||
};
|
||||
|
||||
return (
|
||||
<span className={classNames('custom-control', typeClasses, className)} style={{ display: 'inline' }}>
|
||||
<input type="checkbox" className="custom-control-input" id={id} checked={checked} onChange={onChecked} />
|
||||
<label className="custom-control-label" htmlFor={id}>{children}</label>
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export default BooleanControl;
|
Loading…
Add table
Add a link
Reference in a new issue