Skip to content
FreeForms

Payment Method Selector

Use this component in checkout pages, billing settings, subscription flows, and invoice payment screens.

ReactTailwind CSSFormsCheckout

Choose payment method

Overview

A segmented payment selector for checkout and billing interfaces.

Framework

React

Styling

Tailwind CSS

Animation

Motion

Create a Vite React project

bash
npm create vite@latest my-ui-app -- --template react-ts
cd my-ui-app
npm install

Create a Next.js project

bash
npx create-next-app@latest my-ui-app --typescript --tailwind --eslint
cd my-ui-app

Add Tailwind CSS to Vite

bash
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

Install dependencies

bash
No additional packages required after Tailwind CSS setup.

Usage

tsx
<PaymentMethodSelector />

Payment Method Selector.tsx

tsx
"use client";

import { useState } from "react";

const options = ["Card", "UPI", "Wire"];

export function PaymentMethodSelector() {
  const [active, setActive] = useState("Card");

  return (
    <div className="w-full max-w-sm rounded-xl border border-white/10 bg-zinc-950 p-4 text-white">
      <p className="mb-4 text-sm font-bold">Choose payment method</p>
      <div className="grid grid-cols-3 gap-2">
        {options.map((option) => (
          <button
            key={option}
            type="button"
            onClick={() => setActive(option)}
            className={"rounded-lg border px-3 py-3 text-xs font-semibold " + (active === option ? "border-lime-300 bg-lime-300 text-zinc-950" : "border-white/10 text-zinc-400")}
          >
            {option}
          </button>
        ))}
      </div>
    </div>
  );
}