Skip to content

Commit

Permalink
feat: style radio tile
Browse files Browse the repository at this point in the history
  • Loading branch information
njblore committed Sep 17, 2024
1 parent f4c0465 commit dee34a9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
OakLabelProps,
} from "@/styles/oakThemeApp";

const RadioButtonLabel = styled(OakLabel)<OakLabelProps>`
// TODO: extract to components lib
const RadioTileLabel = styled(OakLabel)<OakLabelProps>`
cursor: pointer;
display: flex;
gap: 8px; // TODO: replace with spacing token
gap: 8px;
`;

const HiddenRadioButtonInput = styled.input.attrs({
Expand All @@ -22,9 +23,14 @@ const HiddenRadioButtonInput = styled.input.attrs({
cursor: pointer;
`;

const RadioButtonFocus = styled(OakBox)<OakBoxProps>`
box-shadow: ${`inset 0 0 0 0.13rem #ffe555`}; // TODO: replace with colour token
const RadioTileFocus = styled(OakBox)<OakBoxProps>`
box-shadow: ${`inset 0 0 0 0.15rem #ffe555`};
width: calc(100% + 12px);
height: calc(100% + 12px);
top: -6px;
left: -6px;
`;

export type RadioTheme = { slug: string; label: string };

export const isRadioTheme = (u: unknown): u is RadioTheme => {
Expand All @@ -36,7 +42,7 @@ export const isRadioTheme = (u: unknown): u is RadioTheme => {
);
};

export const ThemeRadioButton = ({
export const RadioTile = ({
theme,
isChecked,
isFocussed,
Expand All @@ -53,13 +59,26 @@ export const ThemeRadioButton = ({
}) => {
return (
<OakBox
$borderColor="border-neutral-lighter"
$borderStyle="solid"
$borderColor="border-neutral"
$ba="border-solid-m"
$borderRadius="border-radius-s"
$pa="inner-padding-s"
key={theme.slug}
$position={"relative"}
$background={isFocussed || isChecked ? "black" : "transparent"}
$color={isFocussed || isChecked ? "white" : "black"}
>
<RadioButtonLabel htmlFor={id}>
{isFocussed && (
<RadioTileFocus
$background="transparent"
$position="absolute"
$ba="border-solid-l"
$borderColor="grey60"
$borderRadius="border-radius-s"
/>
)}

<RadioTileLabel htmlFor={id}>
<HiddenRadioButtonInput
value={theme.slug}
id={id}
Expand All @@ -72,12 +91,12 @@ export const ThemeRadioButton = ({
<OakFlex
$height={"all-spacing-6"}
$width="all-spacing-6"
$borderColor={"black"}
$borderColor="border-neutral"
$flexGrow={0}
$flexShrink={0}
$alignItems={"center"}
$justifyContent={"center"}
$background="bg-primary"
$background={"bg-primary"}
$ba="border-solid-m"
$borderRadius="border-radius-circle"
>
Expand All @@ -90,20 +109,9 @@ export const ThemeRadioButton = ({
$borderRadius="border-radius-circle"
/>
)}
{isFocussed && (
<RadioButtonFocus
$height={"all-spacing-7"}
$width="all-spacing-7"
$background="transparent"
$position="absolute"
$ba="border-solid-m"
$borderColor="grey60"
$borderRadius="border-radius-circle"
/>
)}
</OakFlex>
{theme.label}
</RadioButtonLabel>
</RadioTileLabel>
</OakBox>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { useState } from "react";
import { useRouter } from "next/router";

import { RadioTheme, ThemeRadioButton, isRadioTheme } from "./ThemeRadioButton";
import { RadioTheme, RadioTile, isRadioTheme } from "./RadioTile";

import {
SpecialistUnitListingLinkProps,
Expand Down Expand Up @@ -123,7 +123,7 @@ const UnitsLearningThemeFilters = ({
const isChecked = activeThemeSlug === theme.slug;
const isFocussed = focussedThemeSlug === theme.slug;
return (
<ThemeRadioButton
<RadioTile
theme={theme}
isChecked={isChecked}
isFocussed={isFocussed}
Expand Down

0 comments on commit dee34a9

Please sign in to comment.