Option cards

A radio group drawn as cards, each with an icon, a title and a line of description. The cards are labels around real radio inputs, so the arrow keys and forms work as usual.

What do you need?

Pick the one to start with. You can add more later.

Options

Screen
Colour

Code

import { useState } from "react";
import "./option-cards.css";

/* A radio group drawn as cards. Each option has a value, a title, a line of
   description and the path of a 20 by 20 filled icon.

   <OptionCards legend="What do you need?" hint="Pick one." name="service" options={options} value={value} onChange={setValue} /> */
export function OptionCards({ legend, hint, name, options, value, onChange }) {
  return (
    <fieldset className="dh-option">
      <legend>{legend}</legend>
      {hint && <p>{hint}</p>}
      <div>
        {options.map((option) => (
          <label key={option.value}>
            <input
              type="radio"
              name={name}
              value={option.value}
              checked={option.value === value}
              onChange={() => onChange(option.value)}
            />
            <svg viewBox="0 0 20 20" aria-hidden="true">
              <path d={option.icon} />
            </svg>
            <i />
            <b>{option.title}</b>
            <span>{option.text}</span>
          </label>
        ))}
      </div>
    </fieldset>
  );
}

const services = [
  {
    value: "website",
    title: "Website",
    text: "A new site, designed and built from scratch.",
    icon: "M4.500 3A2.500 2.500 0 0 0 2 5.500V7h16V5.500A2.500 2.500 0 0 0 15.500 3h-11ZM18 8.500H2v6A2.500 2.500 0 0 0 4.500 17h11a2.500 2.500 0 0 0 2.500-2.500v-6Z",
  },
  {
    value: "shop",
    title: "Shop",
    text: "Products, payments and orders in one place.",
    icon: "M6 6V5a4 4 0 0 1 8 0v1h1.200a1.500 1.500 0 0 1 1.490 1.330l.900 8A1.500 1.500 0 0 1 16.100 17H3.900a1.500 1.500 0 0 1-1.490-1.670l.900-8A1.500 1.500 0 0 1 4.800 6H6Zm1.500 0h5V5a2.500 2.500 0 0 0-5 0v1Z",
  },
  {
    value: "hosting",
    title: "Hosting",
    text: "We keep it fast, backed up and online.",
    icon: "M4.500 3A2.500 2.500 0 0 0 2 5.500v2A2.500 2.500 0 0 0 4.500 10h11A2.500 2.500 0 0 0 18 7.500v-2A2.500 2.500 0 0 0 15.500 3h-11Zm1 2.500a1 1 0 1 1 0 2 1 1 0 0 1 0-2ZM2 13.500A2.500 2.500 0 0 1 4.500 11h11a2.500 2.500 0 0 1 2.500 2.500v1a2.500 2.500 0 0 1-2.500 2.500h-11A2.500 2.500 0 0 1 2 14.500v-1Zm3.500-.500a1 1 0 1 0 0 2 1 1 0 0 0 0-2Z",
  },
];

export function Example() {
  const [service, setService] = useState("website");
  return (
    <OptionCards
      legend="What do you need?"
      hint="Pick the one to start with. You can add more later."
      name="dh-option-service"
      options={services}
      value={service}
      onChange={setService}
    />
  );
}
What do you need?

Pick the one to start with. You can add more later.