@openzeppelin/ui-components
v2.3.1
Published
Shared React UI components for the OpenZeppelin UI ecosystem.
Downloads
1,537
Readme
@openzeppelin/ui-components
Shared React UI components for the OpenZeppelin UI ecosystem.
Installation
# Using npm
npm install @openzeppelin/ui-components
# Using yarn
yarn add @openzeppelin/ui-components
# Using pnpm
pnpm add @openzeppelin/ui-componentsPeer Dependencies
This package requires React 19:
pnpm add react react-domOverview
This package provides a comprehensive set of shared React UI components. It serves as the central library for all common UI elements, including basic primitives, form field components, and their associated utilities.
All components are built with React, TypeScript, and styled with Tailwind CSS, following the shadcn/ui patterns and design principles.
Key Component Categories
Basic UI Primitives
Button,LoadingButton- Action buttons with variantsInput,Textarea- Text input componentsLabel- Form labelsCard(and its parts) - Container componentsDialog(and its parts) - Modal dialogsAlert(and its parts) - Alert messagesCheckbox,RadioGroup- Selection inputsSelect(and its parts) - Dropdown selectsProgress- Progress indicatorsTabs- Tab navigationTooltip- Hover tooltips
Field Components
Specialized components designed for use within react-hook-form:
AddressField- Blockchain address input with validationAmountField- Token amount inputBaseField- Foundational component for creating new field typesBooleanField- Checkbox/toggle inputsNumberField- Numeric inputsRadioField- Radio button groupsSelectField- Dropdown selectionsSelectGroupedField- Grouped dropdown selectionsTextAreaField- Multi-line text inputsTextField- Single-line text inputs
Field Utilities
Helper functions for validation, accessibility, and layout within field components.
Address Label & Suggestion Contexts
Context providers for automatic address label resolution and autocomplete suggestions:
AddressLabelProvider/AddressLabelContext— When mounted, allAddressDisplayinstances in the subtree auto-resolve human-readable labels via aresolveLabelfunctionAddressSuggestionProvider/AddressSuggestionContext— When mounted, allAddressFieldinstances in the subtree show autocomplete suggestions via aresolveSuggestionsfunctionuseAddressLabel(address, networkId?)— Convenience hook to resolve a label from the nearestAddressLabelProvider
Additional UI Components
OverflowMenu— Compact "..." dropdown for secondary actions with support for icons, destructive styling, and disabled stateNetworkSelector— Searchable network dropdown with optional multi-select mode (multiple={true})AddressDisplay— Enhanced with optionallabel,onLabelEdit, anddisableLabelprops for context-driven alias display
Styling Utilities
Such as buttonVariants for class-variance-authority.
Usage
Components and utilities can be imported directly from this package:
import { Control, useForm } from 'react-hook-form';
import { Button, TextField, type TextFieldProps } from '@openzeppelin/ui-components';
interface MyFormData {
name: string;
}
function MyCustomForm() {
const { control } = useForm<MyFormData>();
return (
<form className="space-y-4">
<TextField
id="name"
name="name"
label="Full Name"
control={control as Control<FieldValues>}
placeholder="Enter your full name"
/>
<Button type="submit">Submit</Button>
</form>
);
}Package Structure
components/
├── src/
│ ├── components/
│ │ ├── ui/ # Basic UI primitives
│ │ └── fields/ # Specialized form field components
│ ├── hooks/ # Shared UI hooks
│ ├── lib/ # Utility functions and configurations
│ └── index.ts # Main package exports
├── package.json
├── tsconfig.json
├── tsdown.config.ts
├── vitest.config.ts
└── README.mdStyling
Components are styled using Tailwind CSS. The necessary Tailwind configuration is expected to be present in the consuming application. The UI package itself does not bundle CSS but provides the class names and structure.
Important: a bare Tailwind import is not enough for OpenZeppelin packages. Tailwind v4 must be told to scan the relevant @openzeppelin/* sources, or some component classes will be omitted from the final CSS.
For consumer apps that use @openzeppelin/ui-dev-cli, the recommended workflow is:
pnpm exec oz-ui-dev tailwind doctor --project "$PWD"
pnpm exec oz-ui-dev tailwind fix --project "$PWD"That creates a managed oz-tailwind.generated.css file and keeps the @source wiring in sync with your installed dependencies.
If you need to configure Tailwind manually, import the shared styles and register the OpenZeppelin package sources explicitly:
@layer base, components, utilities;
@import 'tailwindcss' source(none);
@source "../node_modules/@openzeppelin/ui-components";
@source "../node_modules/@openzeppelin/ui-react";
@source "../node_modules/@openzeppelin/ui-renderer";
@source "../node_modules/@openzeppelin/ui-styles";
@source "../node_modules/@openzeppelin/ui-utils";
@import '@openzeppelin/ui-styles/global.css';Development
# Build the package
pnpm build
# Run tests
pnpm test
# Lint
pnpm lint