New Nx project

In this guide, we will cover how quick and easy it is to create your first Generic UI List in the Nx project. We will build a simple list example, it will look like that:



Eat healthy breakfast7:30 AM
Clean the house10:00 AM
Have Lunch with Mark1:30 PM
Go to the movie theatre9:00 PM

Nx Setup

First, you need to make sure you have installed the nx cli. You can find the official installation guide here: Nx setup.

Creating an Nx Angular project

We start off by generating a new Nx project with a preset for the Angular. Navigate to the folder you wish to place your project and type this in your terminal:

npx create-nx-workspace --preset=angular

You can select a name for the workspace e.g. nx-list

After the process is complete navigate to your project directory with:

cd nx-list

and install Generic UI List by typing this in your project directory:

npm i @generic-ui/ngx-list @generic-ui/fabric @generic-ui/hermes

Creating a Generic UI List component

This section covers some of the key steps in building a Generic UI List.

Most importantly, you need to add GuiListModule to the app.module.ts file. Also, don't forget to import GuiListModule from @generic-ui/ngx-list.

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { GuiListModule } from '@generic-ui/ngx-list';

import { AppComponent } from './app.component';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    GuiListModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Now that we have added GuiListModule to our project, we can move to the next step.

Creating simple source and columns variables

In order to build list you need to have source and template specified. In app.component.ts create variable named as source and paste the code below:

source = [{
	time: '7:30 AM',
	title: 'Eat healthy breakfast',
	status: 'green'
}, {
	time: '10:00 AM',
	title: 'Clean the house',
	status: 'green'
}, {
	time: '1:30 PM',
	title: 'Have Lunch with Mark',
	status: 'red'
}, {
	time: '9:00 PM',
	title: 'Go to the movie theatre',
	status: 'yellow'
}];

With our source defined, we can now create template.

<gui-list-item>
	<ng-template let-item="item">
		<span class="gui-list-item-color"></span>
		<span class="gui-list-item-title">{{item.title}}</span>
		<span class="gui-list-item-time">{{item.time}}</span>
	</ng-template>
</gui-list-item>

Creating gui-list component

Open up the app.component.html and create the <gui-list></gui-list> tag. With columns and source specified all we need to do now is to pass them in the <gui-list> selector as inputs:

<gui-list class="todo-list" [source]="source">
	<gui-list-item>
		<ng-template let-item="item">
			<span class="gui-list-item-color"></span>
			<span class="gui-list-item-title">{{item.title}}</span>
			<span class="gui-list-item-time">{{item.time}}</span>
		</ng-template>
	</gui-list-item>
</gui-list>
Eat healthy breakfast7:30 AM
Clean the house10:00 AM
Have Lunch with Mark1:30 PM
Go to the movie theatre9:00 PM

Final code

app.component.ts
app.component.scss
data.ts
@Component({
	template: `
		<gui-list class="todo-list" [source]="source">
			<gui-list-item>
				<ng-template let-item="item">
					<span class="gui-list-item-color"></span>
					<span class="gui-list-item-title">{{item.title}}</span>
					<span class="gui-list-item-time">{{item.time}}</span>
				</ng-template>
			</gui-list-item>
		</gui-list>
	`,
	styleUrls: [`./app.component.css`]
})
export class AppComponent {

	source = data;

}
.todo-list .gui-list-item-color {
	border-radius: 50%;
	background: green;
	display: inline-block;
	margin-right: 8px;
	height: 8px;
	width: 8px;
}

.todo-list .gui-list-item-title {
	font-size: 16px;
	display: inline-block;
}

.todo-list .gui-list-item-time {
	margin-left: auto;
	color: #666;
	font-size: 14px;
	display: inline-block;
}

.todo-list .gui-list-item div {
	display: flex;
	align-items: center;
}

.todo-list .gui-list-item {
	margin-bottom: 12px;
}
[
    {
        "time": "7:30 AM",
        "title": "Eat healthy breakfast",
        "status": "green"
    },
    {
        "time": "10:00 AM",
        "title": "Clean the house",
        "status": "green"
    },
    {
        "time": "1:30 PM",
        "title": "Have Lunch with Mark",
        "status": "red"
    },
    {
        "time": "9:00 PM",
        "title": "Go to the movie theatre",
        "status": "yellow"
    }
]

Related articles:






We use cookies to improve your experience. If you continue browsing, we assume that you consent to our use of cookies.