import React, { useState } from "react";
const styles = {
container: {
display: "flex",
justifyContent: "center",
alignItems: "center",
},
heading: {
color: "green",
textAlign: "center",
},
radioButton: {
padding: "12px 16px",
borderRadius: "8px",
margin: "8px",
border: "2px solid #007BFF",
background: "#fff",
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "280px",
cursor: "pointer",
transition:
"background-color 0.3s, color 0.3s",
},
selected: {
background: "#007BFF",
color: "#fff",
borderColor: "#007BFF",
},
list: {
listStyleType: "none",
padding: 0,
textAlign: "center",
},
};
const CustomRadioButton = ({
label,
selected,
onSelect,
}) => (
<li>
<button
style={{
...styles.radioButton,
...(selected
? styles.selected
: {}),
}}
onClick={onSelect}
>
{label}
</button>
</li>
);
function App() {
const [
selectedValue,
setSelectedValue,
] = useState(null);
return (
<div>
<h1 style={styles.heading}>
Geeksforgeeks
</h1>
<div
style={styles.container}
>
<ul style={styles.list}>
<CustomRadioButton
label="ReactJS"
selected={
selectedValue ===
"option1"
}
onSelect={() =>
setSelectedValue(
"option1"
)
}
/>
<CustomRadioButton
label="NextJs"
selected={
selectedValue ===
"option2"
}
onSelect={() =>
setSelectedValue(
"option2"
)
}
/>
<CustomRadioButton
label="React Native"
selected={
selectedValue ===
"option3"
}
onSelect={() =>
setSelectedValue(
"option3"
)
}
/>
</ul>
</div>
</div>
);
}
export default App;