Radio Component v1.0
This commit is contained in:
parent
a2a47d7f14
commit
2395b1e2d8
46
src/components/Radio.tsx
Normal file
46
src/components/Radio.tsx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import React from "react";
|
||||||
|
/**
|
||||||
|
* [*]This is a Radio component.
|
||||||
|
*
|
||||||
|
* [*]when you click on the label the radio will be selected
|
||||||
|
*
|
||||||
|
* [*] when you call this component pass the following:
|
||||||
|
* [1]. label
|
||||||
|
* [2]. id
|
||||||
|
* [3]. name
|
||||||
|
*
|
||||||
|
* [*] A good example will be:
|
||||||
|
* <Radio label=" Will Smith" id="one" name="radio" />
|
||||||
|
*/
|
||||||
|
type RadioProps = {
|
||||||
|
/**
|
||||||
|
* the text that will be shown besie the radio
|
||||||
|
*/
|
||||||
|
label: string;
|
||||||
|
/**
|
||||||
|
* please provide a unique id
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* The name of radio element
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
} & Omit<React.HTMLProps<HTMLInputElement>, "type">;
|
||||||
|
|
||||||
|
const Radio = ({ label, id, name, ...props }: RadioProps) => {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
className="hover:bg-sky-700 focus:bg-sky-900 active:bg-sky-300 "
|
||||||
|
type="Radio"
|
||||||
|
name={name}
|
||||||
|
value={label}
|
||||||
|
id={id}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
<label htmlFor={id}>{label}</label>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Radio;
|
Loading…
x
Reference in New Issue
Block a user