Pink Design is an open-source system from Appwrite used to build consistent and reusable user interfaces. It enhances collaboration, development experience, and accessibility. This tutorial demonstrates how to use Appwrite’s Pink Design to create a Dashboard with Next.js.
GitHub
Check out the complete source code here.
Prerequisites
To follow along with this tutorial, you should have a working knowledge of the following:
- React, Next.js, and CSS
- An IDE of your choice
Creating a Next.js project
To create a Next.js project, perform the following steps:
- Open a terminal and run this command line to scaffold a Next.js app: ```powershell
npx create-next-app sample-dashboard
- Go to the project directory and start the development server on `localhost:3000` with this command:
```powershell
cd sample-dashboard && npm run dev
Getting started with Pink Design
You can integrate Pink Design into a project via a content delivery network (CDN) or Node Package Manager (NPM). In this tutorial, we’ll use NPM.
To install Pink Design, open a terminal in the project directory and run the following command:
npm install @appwrite.io/pink
The package should be found in your package.json
file.
To use Pink Design in your project, import it into your project’s JavaScript files.
Creating the dashboard
For the purpose of this tutorial, you will create a simple dashboard that shows some dummy contract data using Pink Design.
- Create a
src/components
folder at the root of your project. In the folder, create aContractStatus.js
component and paste the code below into it.
import "@appwrite.io/pink";
import "@appwrite.io/pink-icons";
const ContractStatus = () => {
return (
<div class="u-flex u-main-center">
<div class="u-margin-32">
<div class="status is-complete">
<span class="status-icon"></span>
<span class="text">Accepted</span>
</div>
<h4 class="heading-level-4 u-text-center">2,340</h4>
</div>
<div class="u-margin-32">
<div class="status is-pending">
<span class="status-icon"></span>
<span class="text">In Contract</span>
</div>
<h4 class="heading-level-4 u-text-center">1,782</h4>
</div>
<div class="u-margin-32">
<div class="status is-processing">
<span class="status-icon"></span>
<span class="text">In Approval</span>
</div>
<h4 class="heading-level-4 u-text-center">1,596</h4>
</div>
</div>
)
}
export default ContractStatus;
The code above does the following:
- Lines 1 and 2 import Appwrite’s Pink Design package and its icons.
- In the main container, the u-flex class from Pink Design styles the container as flex, and u-main- center justifies the container’s content to the center.
- status is-complete, is-pending, is-processing specify the status of a process.
- The status-icon class uses the icon that matches the specified status class.
- heading-level-4 is a typographic functionality that specifies the heading size.
- u-margin-32 defines the margin of the container or item.
You can see from the code above how Pink Design makes it easy to style elements.
- Import the
src/components/ContractStatus.js
component into thepages/index.js
file. The file should look like this at this point:
import Head from 'next/head'
import ContractStatus from '@/src/components/ContractStatus';
import "@appwrite.io/pink";
export default function Home() {
return (
<>
<Head>
<title>Contract Dashboard</title>
</Head>
<div class="box u-margin-32 u-padding-block-12">
<h1 class="heading-level-1 u-text-center">Contract Dashboard</h1>
<ContractStatus />
</div>
</>
)
}
In the code above, the box class styles the container as a box, u-margin-32 applies a margin of 32px, and u-padding-block-12 applies a padding of 0.75rem.
At this point, your UI should look like this:
- Create a
src/components/CycleTime.js
component and paste the code below into it. ```javaScript
const CycleTime = () => {
return (
Average Cycle Time
25 days
NDA
class="avatar"
width="32"
height="32"
src="https://unsplash.it/41"
alt="image"
/>
12 days
Insurance
class="avatar"
width="32"
height="32"
src="https://unsplash.it/41"
alt="image"
/>
45 days
Lease
class="avatar"
width="32"
height="32"
src="https://unsplash.it/41"
alt="image"
/>
18 days
Purchase
class="avatar"
width="32"
height="32"
src="https://unsplash.it/41"
alt="image"
/>
</div>
)
}
export default CycleTime;
The code above creates a series of **alert-grids** for displaying some data. Alerts indicate task-generated and system-generated messages. In this case, it is static, but the purpose is to show how easy Pink Design aids in creating alerts. The type of alert must be set by the user: for example, **is-success,** **is-warning**, and **is-info**.
- Import the `src/components/CycleTime.js` component into the `pages/index.js` file. The file should look like this at this point:
```javaScript
import Head from 'next/head'
import ContractStatus from '@/src/components/ContractStatus';
import CycleTime from '@/src/components/CycleTime';
import "@appwrite.io/pink";
export default function Home() {
return (
<>
<Head>
<title>Contract Dashboard</title>
</Head>
<div class="box u-margin-32 u-padding-block-12">
<h1 class="heading-level-1 u-text-center">Contract Dashboard</h1>
<ContractStatus />
<CycleTime/>
</div>
</>
)
}
At this point, the UI should look like this:
- Create a
src/components/ContractTable.js
component and paste the code below into it. ```javaScript
import "@appwrite.io/pink";
import "@appwrite.io/pink-icons";
const ContractTable = () => {
return (
My Contracts
Serial No. |
Name |
Value |
Status |
Deadline |
---|---|---|---|---|
1001 |
Horizon Tech |
$48,292 |
Active |
01.01.2024 |
1002 |
Flowtech Labs |
$20,500 |
Draft |
- |
1003 |
ServerTech |
$15,800 |
Active |
01.03.2024 |
1004 |
DoveTech |
$20,500 |
Active |
01.01.2024 |
</div>
)
}
export default ContractTable;
The code above creates a table using Appwrite’s Pink Design. Tables consist of five components:
| Class | Type |
| ------------------- | ----------- |
| **table-thead** | Head |
| **table-thead-col** | Head Column |
| **table-tbody** | Body |
| **table-row** | Row |
| **table-col** | Column |
- Import the `src/components/ContractTable.js` into the `pages/index.js` file. The file should look like this:
```javaScript
import Head from 'next/head'
import ContractStatus from '@/src/components/ContractStatus';
import ContractTable from '@/src/components/ContractTable';
import CycleTime from '@/src/components/CycleTime';
import "@appwrite.io/pink";
export default function Home() {
return (
<>
<Head>
<title>Contract Dashboard</title>
</Head>
<div class="box u-margin-32 u-padding-block-12">
<h1 class="heading-level-1 u-text-center">Contract Dashboard</h1>
<ContractStatus />
<CycleTime/>
<ContractTable/>
</div>
</>
)
}
Finally, the UI should look like this at this point.
Conclusion
This tutorial described how to use Appwrite’s Pink Design to create a Dashboard. It showed the ease of use of Pink Design and its accessibility.
The resources below will be helpful: