Toggle button toolbar in React
A group of icon buttons with a single active choice, like text alignment.
Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.
This component also comes in
The code in React
import { useRef, useState, type KeyboardEvent, type ReactNode } from "react";
export type ToggleOption<T extends string> = { value: T; label: string; icon: ReactNode };
type ToggleToolbarProps<T extends string> = {
label: string;
options: ToggleOption<T>[];
value: T;
onChange: (value: T) => void;
};
export function ToggleToolbar<T extends string>({import { useState } from "react";
import { ToggleToolbar, type ToggleOption } from "./ToggleToolbar";
type Alignment = "left" | "center" | "right" | "justify";
const icon = (path: string) => (
<svg
className="size-5"
viewBox="0 0 20 20"
fill="none"
stroke="currentColor"
strokeWidth="1.8"Free component: copy it freely, including for commercial projects.
Other buttons components in React
Buttons components in React
A row of buttons to share the page on Facebook, LinkedIn, WhatsApp or by email, with a copy-link button and no third-party script.
- Tailwind
- React
- CSS
- WordPress

Toggle heart buttons that count favourites, remember them between visits and announce them to screen readers.
- Tailwind
- React
- CSS
- WordPress

A button that adds an event to Google Calendar, Outlook or any calendar through an .ics file, with no third-party service.
- Tailwind
- React
- CSS
- WordPress

A button that copies an IBAN, a reference, an address or a promo code and confirms "Copied", on screen and to screen readers.
- Tailwind
- React
- CSS
- WordPress

A WhatsApp button pinned to the bottom of the screen that opens a welcome bubble with common topics and a pre-filled message, with no third-party widget.
- Tailwind
- React
- CSS
- WordPress

A bar pinned to the bottom of mobile screens with Call and Directions buttons and a live open-now status, built for trades and local shops.
- Tailwind
- React
- CSS
- WordPress