@openzeppelin/ui-components
v1.0.2
Published
Shared React UI components for the OpenZeppelin UI ecosystem.
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.
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.
Import the shared styles from @openzeppelin/ui-styles:
@import '@openzeppelin/ui-styles/global.css';
@import 'tailwindcss';Development
# Build the package
pnpm build
# Run tests
pnpm test
# Lint
pnpm lint