misc_pterodactyl-panel/resources/scripts/components/elements/Checkbox.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-10-01 17:07:48 +00:00
import Label from '@/components/elements/Label';
import React from 'react';
import { Field, FieldProps } from 'formik';
2020-07-04 23:26:07 +00:00
import Input from '@/components/elements/Input';
2021-10-01 17:07:48 +00:00
import tw from 'twin.macro';
interface Props {
name: string;
2021-10-01 17:07:48 +00:00
label?: string;
2020-07-11 22:37:59 +00:00
className?: string;
}
2021-10-01 17:07:48 +00:00
type OmitFields = 'ref' | 'name' | 'value' | 'type';
2020-07-04 23:26:07 +00:00
type InputProps = Omit<JSX.IntrinsicElements['input'], OmitFields>;
2021-10-01 17:07:48 +00:00
const Checkbox = ({ name, label, className, ...props }: Props & InputProps) => (
<Field name={name}>
2021-10-01 17:07:48 +00:00
{({ field }: FieldProps) => {
return (
2021-10-01 17:07:48 +00:00
<div css={tw`flex flex-row`} className={className}>
<Input
{...field}
{...props}
css={tw`w-5 h-5 mr-2`}
type={'checkbox'}
/>
{label &&
<div css={tw`flex-1`}>
<Label noBottomSpacing>{label}</Label>
</div>}
</div>
);
}}
</Field>
);
export default Checkbox;