> For the complete documentation index, see [llms.txt](https://admincode.gitbook.io/admincode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://admincode.gitbook.io/admincode/basics/interactive-blocks.md).

# UI Components

Reusable UI components in an app provide a significant advantage over custom HTML components by streamlining development, ensuring consistency, and improving maintainability. These components, such as buttons, tables, forms, and modals, encapsulate logic and styling, reducing redundant code and making UI updates more efficient. Unlike custom HTML components, which require repetitive implementation and maintenance, reusable components enhance scalability and facilitate a modular approach to UI design, leading to faster development cycles and a more cohesive user experience

**Layout**

At the core of any well-structured admin UI lies the **Layout** component, serving as the foundation that brings all other UI components together seamlessly. It defines the overarching structure, handling key elements like navigation, headers, sidebars, and content areas, ensuring a consistent and responsive user experience.

{% tabs %}
{% tab title="Preview" %}

<figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2F3rfQEuqNBPnyztHkfgMp%2FScreenshot%202025-02-23%20at%202.14.51%E2%80%AFPM.png?alt=media&amp;token=4a194406-d643-4d97-9031-cd09d146f5ad" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Code" %}

```java
public class LayoutForm extends UIComponent {	
	
	private List<Row> rows = new ArrayList<>();
	
	public List<Row> getRows() {
		return rows;
	}

	public void setRows(List<Row> rows) {
		this.rows = rows;
	}
}

public LayoutForm getLayoutForm(Object o) throws Exception {
    	LayoutForm layoutForm = new LayoutForm();
    	
    	ArticleDTO article = (ArticleDTO)o;
		Input articleId = UIInput.draw("Id", article.getId(), UIInputType.Text);
		Input articleTitle = UIInput.draw("title", article.getTitle(), UIInputType.Text);
		Input articleCategory = UIInput.draw("category", article.getCategory(), UIInputType.Text);
		Input articleSummary = UIInput.draw("summary", article.getSummary(), UIInputType.TextArea);	
		
		Table author = Table.Builder.newInstance()
				.setTableDescription("author")
				.setName("authors")
				.oneToOneBuilder()
					.setIsOneToOne(true)	
					.setDisplayValue(article.getAuthor() != null ? article.getAuthor().getName() : "")
					.setValueType("name")
					.done()
				.setIsEditable(true)
				.addEditBehavior()
					.setAddButtonIsSingleSelectTable(true)
					.setAddButtonUILayoutTitle("Select Author")
					.done()
				.setDatalistType(AuthorDTO.class)
				.setTableId("author")
				.build();
		author = UIDataTable.draw(author);
		
		List<DropDownOption> types = new ArrayList<>();
		DropDownOption type = new DropDownOption();
		type.setDescription("Politics");
		type.setValue(ArticleTypeEnum.POLITICS.name());
		types.add(type);
		type = new DropDownOption();
		type.setDescription("Civil");
		type.setValue(ArticleTypeEnum.CIVIL.name());
		types.add(type);
		type = new DropDownOption();
		type.setDescription("Economy");
		type.setValue(ArticleTypeEnum.ECONOMY.name());
		types.add(type);
		DropDown articleType = UIDropDown.draw("type", types, 
				article.getType() != null ? 
				article.getType().name() : "");	
		
		// Multi dropdown with lookup table and DTO
		DropDown articleTypes = UIMultiDropDown.draw("types", 
				article.getTypes() != null ? 
						article.getTypes().stream()
						.map(v -> v.getType().name())
						.collect(Collectors.toList())
						: List.of(), "type", types);
		
		// Multi dropdown with plain List<String>
		List<DropDownOption> typeStringList = new ArrayList<>();
		type = new DropDownOption();
		type.setDescription("Politics");
		type.setValue(ArticleTypeEnum.POLITICS.name());
		typeStringList.add(type);
		type = new DropDownOption();
		type.setDescription("Civil");
		type.setValue(ArticleTypeEnum.CIVIL.name());
		typeStringList.add(type);

		Table citations = Table.Builder.newInstance()
				.setTableDescription("citations")
				.setName("citations")
				.setIsEditable(true)
				.addEditBehavior()
					.setAddButtonIsSingleSelectTable(false)
					.setAddButtonUILayoutTitle("Select Citations")
					.done()
				.setDatalist(article.getCitations())
				.setDatalistType(CitationDTO.class)
				.setTableId("citations")
				.build();
		citations = UIDataTable.draw(citations);

		Table comments = Table.Builder.newInstance()
				.setTableDescription("comments")
				.setName("comments")
				.setIsEditable(true)
				.addEditBehavior()
					.setAddButtonActionUrl("article/confirmAddNewComment")
					.setAddButtonGetUILayoutUrl("article/getAddNewCommentLayout")
					.setAddButtonUILayoutTitle("New Comment")
					.done()
				.setDatalist(article.getComments())
				.setDatalistType(ArticleCommentDTO.class)
				.setTableId("comments")
				.build();
		comments = UIDataTable.draw(comments);

		Map<String, UIComponent> fieldsRow1Col1 = new LinkedHashMap<String, UIComponent>();
		fieldsRow1Col1.put(articleId.getName(), articleId);
		fieldsRow1Col1.put(articleTitle.getName(), articleTitle);
		fieldsRow1Col1.put(articleCategory.getName(), articleCategory);
		fieldsRow1Col1.put(articleSummary.getName(), articleSummary);
		
		Map<String, UIComponent> fieldsRow1Col2 = new LinkedHashMap<String, UIComponent>();
		fieldsRow1Col2.put(articleType.getName(), articleType);
		fieldsRow1Col2.put(articleTypes.getName(), articleTypes);
		fieldsRow1Col2.put("author", author);
	
		Map<String, UIComponent> fieldsRow2Col1 = new LinkedHashMap<String, UIComponent>();
		fieldsRow2Col1.put("citations", citations);
		fieldsRow2Col1.put("comments", comments);
		
		List<Row> rows = layoutForm.getRows();
		Column col1 = new Column(fieldsRow1Col1);
		Column col2 = new Column(fieldsRow1Col2);
		Row row1 = new Row();
		row1.setColumns(List.of(col1, col2));
		rows.add(row1);
		Column col3 = new Column(fieldsRow2Col1);
		Row row2 = new Row();
		row2.setColumns(List.of(col3));
		rows.add(row2);
		layoutForm.setRows(rows);
		
    	return layoutForm;	
	}

```

{% endtab %}
{% endtabs %}

### Textbox

{% tabs %}
{% tab title="Preview" %}

<figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2FfqIfRNJI1Eye7u1tnKQE%2FScreenshot%202025-03-02%20at%202.00.31%E2%80%AFPM.png?alt=media&amp;token=fd053b08-8a70-4254-95cf-f4c47b2e9fff" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Code" %}

```java
Input articleId = UIInput.draw("Id", article.getId(), UIInputType.Text);
```

{% endtab %}
{% endtabs %}

### Textarea

{% tabs %}
{% tab title="Preview" %}

<figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2FT1w3ANWpAinPeZk4a5w7%2FScreenshot%202025-03-02%20at%202.00.20%E2%80%AFPM.png?alt=media&amp;token=42d0ee0f-11c8-430e-a5ad-3c7dc60a9392" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Code" %}

```java
Input articleSummary = UIInput.draw("summary", article.getSummary(), UIInputType.TextArea);
```

{% endtab %}
{% endtabs %}

### Selectable Textbox

{% tabs %}
{% tab title="Preview" %}

<div><figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2Fc67rCRMl72ZJJpgCfs4A%2FScreenshot%202025-03-01%20at%202.29.50%E2%80%AFPM.png?alt=media&amp;token=8deb298a-9de9-4ea3-98ee-67305a20dc27" alt=""><figcaption></figcaption></figure> <figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2FWWaPZ5RrTKYkoVXA9ja4%2FScreenshot%202025-03-01%20at%202.39.03%E2%80%AFPM.png?alt=media&amp;token=e8517b10-ffa7-48fa-a645-99300060b2c6" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Code" %}

```java

Table author = Table.Builder.newInstance()
		.setTableDescription("author")
		.setName("authors")
		.oneToOneBuilder()
			.setIsOneToOne(true)	
			.setDisplayValue(article.getAuthor() != null ? article.getAuthor().getName() : "")
			.setValueType("name")
			.done()
		.setIsEditable(true)
			.addEditBehavior()
			.setAddButtonIsSingleSelectTable(true)
			.setAddButtonUILayoutTitle("Select Author")
			.done()
		.setDatalistType(AuthorDTO.class)
		.setTableId("author") // Must be the field name
		.build();
author = UIDataTable.draw(author);
```

{% endtab %}
{% endtabs %}

### DropDown

{% tabs %}
{% tab title="Preview" %}

<figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2FKHYI3nBWKGhy7WthzfG1%2FScreenshot%202025-03-02%20at%201.52.18%E2%80%AFPM.png?alt=media&amp;token=e1c36f9a-74bf-4b6b-853b-f1725fa716d1" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Code" %}

```java
List<DropDownOption> types = new ArrayList<>();
DropDownOption type = new DropDownOption();
type.setDescription("Politics");
type.setValue(ArticleTypeEnum.POLITICS.name());
types.add(type);
type = new DropDownOption();
type.setDescription("Civil");
type.setValue(ArticleTypeEnum.CIVIL.name());
types.add(type);
type = new DropDownOption();
type.setDescription("Economy");
type.setValue(ArticleTypeEnum.ECONOMY.name());
types.add(type);
DropDown articleType = UIDropDown.draw("type", types, 
				article.getType() != null ? 
				article.getType().name() : "");	
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Preview" %}

<figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2FWc66FosWBkgCGNn9MzXL%2FScreenshot%202025-03-02%20at%201.53.11%E2%80%AFPM.png?alt=media&amp;token=f1a9c592-213f-40ff-aaca-57172d1460b0" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Code" %}

```java
DropDown articleTypes = UIMultiDropDown.draw("types", article.getTypes() != null ? 
						article.getTypes().stream()
						.map(v -> v.getType().name())
						.collect(Collectors.toList())
						: List.of(), "type", types);
		
```

{% endtab %}
{% endtabs %}

### DataTable

{% tabs %}
{% tab title="Preview" %}

<figure><img src="https://2308997185-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8FIBMz5maCg8JQVrVt15%2Fuploads%2FAdgPnkzruuefUC7m4saC%2FScreenshot%202025-03-01%20at%202.30.09%E2%80%AFPM.png?alt=media&amp;token=79e73928-7db9-459d-8676-9b56281cea91" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Code" %}

```java
Table citations = Table.Builder.newInstance()
				.setTableDescription("citations")
				.setName("citations")
				.setIsEditable(true)
				.addEditBehavior()
					.setAddButtonIsSingleSelectTable(false)
					.setAddButtonUILayoutTitle("Select Citations")
					.done()
				.setDatalist(article.getCitations())
				.setDatalistType(CitationDTO.class)
				.setTableId("citations") // Must be the exact name of the field
				.build();
citations = UIDataTable.draw(citations);
```

{% endtab %}
{% endtabs %}
