Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions content/docs/03-objectui/actions/api-request.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
---
title: API Request
description: Make HTTP requests
---

# API Request

Make HTTP requests to backend endpoints.

## Protocol

```typescript
{
type: 'api',
api: string, // API endpoint
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE',
data?: object | string, // Request body (template supported)
headers?: object, // Request headers
confirm?: string, // Confirmation message
onSuccess?: Action, // Success handler
onError?: Action, // Error handler
}
```

## Examples

### Basic Request

```json
{
"type": "button",
"label": "Save",
"onClick": {
"type": "api",
"api": "/api/users/${userId}",
"method": "PUT",
"data": "${formData}",
"confirm": "Save changes?",
"onSuccess": {
"type": "toast",
"message": "Saved successfully!"
}
}
}
```

### DELETE with Confirmation

```json
{
"type": "api",
"api": "/api/users/${id}",
"method": "DELETE",
"confirm": "Are you sure you want to delete this user?",
"onSuccess": [
{ "type": "toast", "message": "User deleted" },
{ "type": "reload" }
],
"onError": {
"type": "toast",
"message": "Failed to delete user",
"variant": "error"
}
}
```

### POST with Custom Headers

```json
{
"type": "api",
"api": "/api/upload",
"method": "POST",
"headers": {
"Content-Type": "multipart/form-data"
},
"data": "${fileData}"
}
```

## HTTP Methods

- **GET** - Retrieve data
- **POST** - Create new resources
- **PUT** - Update entire resources
- **PATCH** - Partial updates
- **DELETE** - Remove resources

## Template Variables

Use template syntax in `api`, `data`, and other string fields:

```json
{
"api": "/api/users/${userId}/posts/${postId}",
"data": {
"title": "${formData.title}",
"content": "${formData.content}"
}
}
```

## Action Chaining

Chain multiple actions on success or error:

```json
{
"type": "api",
"api": "/api/submit",
"method": "POST",
"onSuccess": [
{ "type": "toast", "message": "Success!" },
{ "type": "navigate", "url": "/dashboard" }
]
}
```

## Confirmation Dialogs

Add a confirmation prompt before executing:

```json
{
"type": "api",
"api": "/api/delete-all",
"method": "POST",
"confirm": "This will delete all data. Are you sure?"
}
```

## Related

- **[Form](/docs/03-objectui/container-components/form)** - Form submission
- **[Toast](/docs/03-objectui/actions/toast)** - User feedback
- **[Navigate](/docs/03-objectui/actions/navigate)** - Redirect after API calls
122 changes: 122 additions & 0 deletions content/docs/03-objectui/actions/dialog.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
---
title: Dialog
description: Open modal dialogs
---

# Dialog

Open a modal dialog with custom content.

## Protocol

```typescript
{
type: 'dialog',
title?: string,
width?: number | string,
body: Component,
footer?: Component[],
closable?: boolean,
}
```

## Examples

### Form Dialog

```json
{
"type": "button",
"label": "Add User",
"onClick": {
"type": "dialog",
"title": "Create New User",
"width": 600,
"body": {
"type": "form",
"api": "/api/users",
"fields": [
{ "type": "input", "name": "name", "label": "Name", "required": true },
{ "type": "input", "name": "email", "label": "Email", "inputType": "email", "required": true }
]
}
}
}
```

### Confirmation Dialog

```json
{
"type": "dialog",
"title": "Confirm Action",
"body": {
"type": "text",
"value": "Are you sure you want to proceed?"
},
"footer": [
{ "type": "button", "label": "Cancel", "onClick": { "type": "close" } },
{ "type": "button", "label": "Confirm", "onClick": { "type": "api", "api": "/api/confirm" } }
]
}
```

### Content Dialog

```json
{
"type": "button",
"label": "View Details",
"onClick": {
"type": "dialog",
"title": "User Details",
"width": "80%",
"body": {
"type": "card",
"body": [
{ "type": "text", "value": "Name: ${user.name}" },
{ "type": "text", "value": "Email: ${user.email}" },
{ "type": "text", "value": "Role: ${user.role}" }
]
}
}
}
```

## Features

### Width

Control dialog width with:
- Fixed pixel values: `600`
- Percentage: `"80%"`
- Preset sizes: `"sm"`, `"md"`, `"lg"`, `"xl"`

### Closable

Set `closable: false` to prevent users from closing the dialog via the close button or ESC key.

### Body Content

The dialog body can contain any component:
- Forms for data entry
- Cards for content display
- Tables for data selection
- Custom component compositions

### Footer

Add custom footer buttons for actions like Cancel, Confirm, Save, etc.

## Use Cases

- Create/edit forms
- Confirmation prompts
- Detail views
- Multi-step wizards
- Image galleries

## Related

- **[Form](/docs/03-objectui/container-components/form)** - Forms in dialogs
- **[API Request](/docs/03-objectui/actions/api-request)** - Submit from dialog
103 changes: 103 additions & 0 deletions content/docs/03-objectui/actions/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
title: Actions
description: Interactive behaviors and event handlers in ObjectUI
---

# Actions

Actions define interactive behaviors in ObjectUI.

## Action Types

- **[API Request](/docs/03-objectui/actions/api-request)** - Make HTTP requests
- **[Navigate](/docs/03-objectui/actions/navigate)** - Navigate to different pages
- **[Dialog](/docs/03-objectui/actions/dialog)** - Open modal dialogs
- **[Toast](/docs/03-objectui/actions/toast)** - Show notification messages

## Overview

Actions are the interactive layer of ObjectUI, handling user events and triggering responses. They support:

- **Chaining**: Actions can trigger other actions (onSuccess, onError)
- **Template Substitution**: Use `${variable}` syntax for dynamic values
- **Confirmation**: Add confirm prompts before execution
- **Error Handling**: Built-in error handling and user feedback

## Common Patterns

### Form Submission

```json
{
"type": "form",
"fields": [...],
"onSubmit": {
"type": "api",
"api": "/api/users",
"method": "POST",
"onSuccess": {
"type": "toast",
"message": "User created successfully!"
}
}
}
```

### Button Actions

```json
{
"type": "button",
"label": "Save",
"onClick": {
"type": "api",
"api": "/api/save",
"method": "POST",
"data": "${formData}"
}
}
```

### Navigation

```json
{
"type": "button",
"label": "View Details",
"onClick": {
"type": "navigate",
"url": "/users/${userId}"
}
}
```

## Action Chaining

Actions can trigger other actions on success or error:

```json
{
"type": "api",
"api": "/api/users/${id}",
"method": "DELETE",
"confirm": "Delete this user?",
"onSuccess": [
{ "type": "toast", "message": "User deleted" },
{ "type": "reload" }
],
"onError": {
"type": "toast",
"message": "Failed to delete user",
"variant": "error"
}
}
```

## Next Steps

Explore individual action types for detailed protocol definitions and examples:

- **[API Request](/docs/03-objectui/actions/api-request)** - HTTP requests
- **[Navigate](/docs/03-objectui/actions/navigate)** - Page navigation
- **[Dialog](/docs/03-objectui/actions/dialog)** - Modal dialogs
- **[Toast](/docs/03-objectui/actions/toast)** - Notifications
10 changes: 10 additions & 0 deletions content/docs/03-objectui/actions/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"title": "Actions",
"pages": [
"index",
"api-request",
"navigate",
"dialog",
"toast"
]
}
Loading
Loading