Skip to content

Commit

Permalink
Moved RadioButton component to RadioButtonGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Aug 26, 2024
1 parent 5a29dc4 commit aa2531c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 101 deletions.
46 changes: 45 additions & 1 deletion src/components/forms/radioButtonGroup/RadioButtonGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import styles from "src/components/forms/radioButtonGroup/radioButtonGroup.module.css";
import { RadioButton } from "./components/RadioButton";
import textStyles from "src/components/text/text.module.css";

export interface IOption {
Expand All @@ -9,6 +8,17 @@ export interface IOption {
disabled?: boolean;
}

interface RadioButtonProps {
id: string;
name: string;
label: string;
value?: string;
checked?: boolean;
disabled?: boolean;
defaultChecked?: boolean;
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
}

interface RadioButtonGroupProps {
id: string;
label: string;
Expand Down Expand Up @@ -53,3 +63,37 @@ export const RadioButtonGroup = ({
</fieldset>
);
};

const RadioButton = ({
id,
name,
value,
label,
checked,
disabled,
defaultChecked,
onChange,
}: RadioButtonProps) => {
return (
<label
htmlFor={id}
className={`${styles.container} ${textStyles.caption} ${disabled ? styles.disabledLabel : styles.label}`}
>
<input
className={styles.input}
type="radio"
name={name}
id={id}
value={value}
checked={checked}
disabled={disabled}
aria-disabled={disabled ? "true" : "false"}
defaultChecked={defaultChecked}
onChange={onChange}
aria-label={label}
/>

{label}
</label>
);
};
48 changes: 0 additions & 48 deletions src/components/forms/radioButtonGroup/components/RadioButton.tsx

This file was deleted.

This file was deleted.

53 changes: 53 additions & 0 deletions src/components/forms/radioButtonGroup/radioButtonGroup.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,56 @@
flex-direction: column;
gap: 0.5rem;
}

.container {
display: flex;
gap: 1rem;
align-items: center;
}

.label {
font-size: 1rem;
color: var(--dark-purple);
}

.disabledLabel {
color: gray;
cursor: not-allowed;
}

.input {
appearance: none;
width: 24px;
height: 24px;
border: 2px solid black;
border-radius: 50%;
transition: all 0.1s ease-in-out;
box-sizing: border-box;
background-color: white;
position: relative;
}

.input:checked::after {
content: "";
position: absolute;
top: 4px;
left: 4px;
width: 12px;
height: 12px;
border-radius: 50%;
background-color: var(--primary-green-dark);
}

.input:hover {
background-color: var(--primary-green-light);
outline: 2px solid var(--primary-green-light);
}

.input:focus {
outline: 2px solid var(--primary-green-light);
}

.input[disabled] {
cursor: not-allowed;
border-color: grey;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default function SalaryCalculator({

return (
<form
//TODO: replace aria-label with static translation from Sanity
aria-label="salary calculator"
className={styles.calculator}
onSubmit={onSubmit}
Expand Down

0 comments on commit aa2531c

Please sign in to comment.