2021-10-28 14:55:51 +00:00
---
order: 2
---
# Client Components
2021-10-31 01:44:52 +00:00
To allow more non-developers to participate, NocoBase provides a companion client - a visual interface without code. The client interface is very flexible and consists of different components, which are divided into three categories.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- Routing components created by createRouteSwitch, such as Layout, Page
- Field components created by createCollectionField, used to extend fields
- JSON Schema components created by createSchemaComponent, which can be anything, such as tables, forms, calendars, kanban, etc.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
[For more on components, see the section on components ](# )
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## Component tree structure
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
The interface is a component tree composed of components with the following structure.
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Layout >
< Page >
< Grid >
2021-10-31 01:44:52 +00:00
// Block, table
2021-10-28 14:55:51 +00:00
< Table >
< Table.DesignableBar / >
< Table.ActionBar >
< Action / >
< Action / >
< / Table.ActionBar >
< Table.Content >
< Table.Column >
2021-10-31 01:44:52 +00:00
// Fields in table columns
2021-10-28 14:55:51 +00:00
< CollectionField / >
< / Table.Column >
< Table.Column >
< CollectionField / >
< / Table.Column >
< / Table.Content >
< / Table >
< / Grid >
< AddNew / >
< / Page >
< / Layout >
< / pre >
2021-10-31 01:44:52 +00:00
Note: The above example is only for expressing the structure of the component tree and the relationship between components, the actual code does not.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Next, let's introduce the concept of each component in detail.
## Layout and pages
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Pages are web pages that can be accessed by address. Different pages may have the same header, footer and navigation between them, and usually we put these common contents in the layout component. For example, the initialized NocoBase provides two layout components, as shown in
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Figure
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- AuthLayout: accessible without login, usually used to embed login, registration, forgot password, etc. pages.
- AdminLayout: requires login and manages all pages of the backend.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Layout and page components are registered through createRouteSwitch, more extensions are available here.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## Page content layout
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
For developers, the writing of page content is free, but to facilitate the layout of page content, two types of layout are provided.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
### Simple top-down structure
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Page >
< BlockItem / >
< BlockItem / >
< BlockItem / >
< / Page >
< / pre >
2021-10-31 01:44:52 +00:00
Example
2021-10-28 14:55:51 +00:00
```js
2021-10-31 01:44:52 +00:00
// coming soon
2021-10-28 14:55:51 +00:00
```
2021-10-31 01:44:52 +00:00
### Drag and drop grid
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Page >
< Grid >
< Grid.Row >
< Grid.Col >
< BlockItem / >
< / Grid.Col >
< Grid.Col >
< BlockItem / >
< / Grid.Col >
< / Grid.Row >
< Grid.Row >
< Grid.Col >
< BlockItem / >
< / Grid.Col >
< Grid.Col >
< BlockItem / >
< / Grid.Col >
< / Grid.Row >
< / Grid >
< / Page >
< / pre >
2021-10-31 01:44:52 +00:00
Grid component defines the outer frame of the block based on rows (Grid.Row) and columns (Grid.Col). Examples are as follows:
2021-10-28 14:55:51 +00:00
```js
2021-10-31 01:44:52 +00:00
// coming soon
2021-10-28 14:55:51 +00:00
```
## AddNew
2021-10-31 01:44:52 +00:00
AddNew is the most important button for visual configuration of the page, more about [AddNew ](# ) here
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## Block
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Blocks are generally placed in pages and can be anything, including text, attachments, tables, forms, calendars, kanban boards, etc. A complete block consists of three parts.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- Content, the body of the block
- ActionBar, where you can place various action buttons to manipulate the block data (optional)
- DesignableBar, buttons for operating the block configuration (optional)
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Take the table block as an example, the component structure is as follows:
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Table >
< Table.DesignableBar / >
< Table.ActionBar / >
< Table.Content / >
< / Table >
< / pre >
2021-10-31 01:44:52 +00:00
Example
2021-10-28 14:55:51 +00:00
```js
2021-10-31 01:44:52 +00:00
// coming soon
2021-10-28 14:55:51 +00:00
```
2021-10-31 01:44:52 +00:00
There are several types of blocks.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- Data types, used to display data from data tables, such as tables, calendars, kanban, forms, details, etc.
- Multimedia, for enriching page content, such as text paragraphs, attachments, etc. For now there is only a simple Markdown.
- Charts, for displaying data statistics.
- Templates, which can directly template certain finished products and apply them directly to the page.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Blocks can be extended at will, see the [createSchemaComponent ](# ) chapter for how to do so.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## ActionBar
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
An action bar is a collection of actions, typically used inside a block. The user issues an action command, the program makes a change, and responds with the result in the block's content area.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Example.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Form, the content area is a table, and the action area will place some action buttons, such as filter, add, delete, export, etc
2021-10-28 14:55:51 +00:00
```js
2021-10-31 01:44:52 +00:00
// coming soon
2021-10-28 14:55:51 +00:00
```
2021-10-31 01:44:52 +00:00
details, the content area is the details of the data, the operation area will be placed on the edit, export and other buttons
2021-10-28 14:55:51 +00:00
```js
2021-10-31 01:44:52 +00:00
// coming soon
2021-10-28 14:55:51 +00:00
```
2021-10-31 01:44:52 +00:00
The buttons of the action bar may be different for different blocks. The action bar buttons are also customizable, check the action chapter for details.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## Action
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
An action is an encapsulated piece of instruction that generally requires user participation.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
For example.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- Delete data, which requires the user to select the data to be deleted, and then trigger the delete command
- Filtering data requires the user to fill in the filter items and then triggers the filter command
- Add data, the user needs to fill in the data and then submit it, triggering the add operation instruction
- View details, the user clicks the operation button, the pop-up window to view the details or the current window to open the details page to view
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
The simplest operation, you only need to bind a paragraph of instructions, simply specify a function, no need to pass parameters. The component structure is as follows.
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Action useAction = {useAction} / >
< / pre >
2021-10-31 01:44:52 +00:00
Most of the action instructions require user-supplied parameters, such as the add data action, which requires the user to fill in the data, which usually requires a pop-up form, and the user fills in the data and clicks submit to trigger the action instruction. The component structure is as follows.
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Action useAction = {useAction} >
2021-10-31 01:44:52 +00:00
{/* This is a popup form with a built-in submit button that triggers an action command when clicked, the specific code is omitted */}
2021-10-28 14:55:51 +00:00
< Action.Modal x-decorator = {'Form'} > < / Action.Modal >
< / Action >
< / pre >
2021-10-31 01:44:52 +00:00
A complete action is roughly divided into two steps.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- Bind a directive to the Action
- If the directive requires user-supplied parameters, it needs to provide an interaction interface, which is currently built in as follows
- Action.Drawer: drawer
- Modal: dialog box
- Popover: bubble
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
Action is a very important concept in NocoBase, more details click here to see
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## DesignableBar
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
All Schema Components can be bound to their own configuration toolbar (DesignableBar) for modifying the Schema of the current component.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
**What is a Schema Component?**
A component written in JSON-like Schema format via the Schema protocol, e.g.
2021-10-28 14:55:51 +00:00
```js
{
type: 'void',
2021-10-31 01:44:52 +00:00
'x-Component': 'Hello',
2021-10-28 14:55:51 +00:00
'x-designable-bar': 'Hello.DesignableBar',
'x-dect': 'CardItem',
}
```
2021-10-31 01:44:52 +00:00
To give a few examples, e.g.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
JSON Schema for form fields
2021-10-28 14:55:51 +00:00
```js
const schema = {
type: 'string',
'x-component': 'Input',
'x-decorator': 'FormItem',
'x-designable-bar': 'Form.Field.DesignableBar',
};
```
2021-10-31 01:44:52 +00:00
The effect of the form item's configuration toolbar `Form.Field.DesignableBar`
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
< img src = "https://nocobase.oss-cn-beijing.aliyuncs.com/1ffba32f9a5625760c3fe11e7eb19974.png" style = "max-width: 350px;" / >
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
JSON Schema for the form
2021-10-28 14:55:51 +00:00
```js
const schema = {
type: 'array',
'x-component': 'Table',
'x-decorator': 'CardItem',
'x-designable-bar': 'Table.DesignableBar',
};
```
2021-10-31 01:44:52 +00:00
The effect of the table configuration toolbar `Table.DesignableBar`
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
< img src = "https://nocobase.oss-cn-beijing.aliyuncs.com/dcd762a0444ef55a8515c53d706f7bc4.png" style = "max-width: 250px;" / >
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
JSON Schema for the menu item.
2021-10-28 14:55:51 +00:00
```js
const schema = {
type: 'array',
'x-component': 'Menu.Item',
'x-designable-bar': 'Menu.Item.DesignableBar',
};
```
2021-10-31 01:44:52 +00:00
Effect of menu item configuration toolbar `Menu.Item.DesignableBar`
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
< img src = "https://nocobase.oss-cn-beijing.aliyuncs.com/984ab6da6a8f72fe790bb9bd18b3eb35.png" style = "max-width: 200px;" / >
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
For more details on the configuration toolbar click here
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
## CollectionField
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
The configuration parameters of field components can be very many, and the same field component can be used in different data blocks. In order to reduce code duplication, NocoBase assigns the configuration of field components to the data table for unified management. One configuration, many uses. The field component is directly referenced in the data block, and then extended if there are other different parameters.
2021-10-28 14:55:51 +00:00
< pre lang = "tsx" >
< Table >
// 原生态的写法
< Table.Column title = {'姓名'} >
< Input { . . . others } name = "name" readPretty = {true}/ >
< / Table.Column >
// 简化之后的字段引用
< Table.Column >
< CollectionField name = "name" / >
< / Table.Column >
< / Table >
< Form >
// 如果在表格里也用到,再写一遍
< FormItem title = {'姓名'} >
< Input { . . . others } name = "name" / >
< / FormItem >
// 字段引用,只需要提供 name 即可
< FormItem >
< CollectionField name = "name" / >
< / FormItem >
< / Form >
< / pre >
2021-10-31 01:44:52 +00:00
The field component has three display states.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- fillable - editable
- unfillable - disabled
- Read mode - read-pretty
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
As an example for a single line of text (Input).
2021-10-28 14:55:51 +00:00
```js
2021-10-31 01:44:52 +00:00
// example (three display states for Input)
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
// example to be added
2021-10-28 14:55:51 +00:00
```
2021-10-31 01:44:52 +00:00
**Why do fields have multiple display states? **
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
- In a form, the field is normally filled in (editable), but if it is for viewing only, the field is set to disabled or read-pretty.
- In forms, fields are generally read-pretty, but if you need to edit them quickly within the form, you can dynamically activate a field as editable.
2021-10-28 14:55:51 +00:00
2021-10-31 01:44:52 +00:00
The field component can be extended in any way, see the createCollectionField section for how to do so.