This is a Next.js implementation of the A2UI library, using ShadCN components. A2UI is a declarative UI library that allows you to define your UI using a JSON schema, which can be dynamically generated and updated.
- Install the required dependencies:
npm install- Run the development server:
npm run dev- Open http://localhost:3000 to see the demo.
The A2UI library includes the following components:
- Row: Horizontal layout container
- Column: Vertical layout container
- List: Scrollable list of items
- Card: Container with elevation and padding
- Text: Display text content with optional styling
- Image: Display images from URLs
- Icon: Display icons (using emoji as fallback)
- Divider: Visual separator line
- Table: Data table with headers and rows (additional component)
- Button: Clickable button with action support
- TextField: Text input field
- Checkbox: Boolean toggle
- Slider: Range slider input
- MultipleChoice: Dropdown or radio button selection
- DateTimeInput: Date and time picker
- Modal: Overlay dialog
- Tabs: Tabbed interface
- Video: Video player
- AudioPlayer: Audio player
To use the A2UI library, you first need to define your UI using a JSON schema. This schema is typically generated by an AI system or created manually.
Here's an example of how to use the A2UI library:
import { Renderer } from '@/components/a2ui/renderer';
import { MessageProcessor } from '@/components/a2ui/processor';
import type { AnyComponentNode } from '@/components/a2ui/types';
const processor = new MessageProcessor();
const myComponents: AnyComponentNode[] = [
{
id: 'root',
type: 'Card',
properties: {
child: {
id: 'content',
type: 'Column',
properties: {
children: [
{
id: 'title',
type: 'Text',
properties: {
text: { literalString: 'Hello, World!' },
usageHint: 'h1',
},
},
{
id: 'subtitle',
type: 'Text',
properties: {
text: { literalString: 'This is a demo of the A2UI library.' },
},
},
],
},
},
},
},
];
function MyComponent() {
return (
<Renderer
processor={processor}
surfaceId="my-surface"
component={myComponents.find(c => c.id === 'root')!}
/>
);
}The demo page includes two examples:
- Chat Interface: A simple chat interface with messages and input field
- Streams UI: A real-time streams UI with temperature, humidity, and fan speed controls
The A2UI library is built around the following core concepts:
- Message Processor: Handles data binding and message dispatch
- Components: React components that render A2UI nodes
- Renderer: Dynamically renders components from the A2UI schema
- Theme: Defines the styling for all components
You can customize the appearance of A2UI components by modifying the theme in theme.ts. This allows you to override the default styles with your own brand colors and fonts.
This implementation is based on the A2UI library from Google, which is licensed under the Apache 2.0 License.