Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
174 changes: 140 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,171 @@
# NL Design Skeleton Application
# Skeleton Application

The NL Design Skeleton application is design for rapid application testing and prototype development on the NL Design System. It does so by providing a basic skeleton application with full NL Design system functionality that an developer can easily extend view locally and deploy to an online environment for demonstration purposes. the main benefits of this are.
This skeleton application is designed for rapid application testing and prototype development on the NL Design System. It provides a basic skeleton application with full NL Design system functionality that any developer can easily extend, view locally, and deploy to an online environment for demonstration purposes. The main benefits are:
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

Development and (online) demonstration of prototypes without the need of an servers
An ready out of the box basic application that doesn't require configuration or setup and can be extended immediately.

The application is available in two versions, a next.js version and an gatsby version. If you want to put your prototype online without setting up a server we recommend the gatsby version, since that can be deployed through github pages.
- Development and (online) demonstration of prototypes without needing a server.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more accurate to say that when implementing, you do not need to create or maintain your own server; since a server is always needed when hosting something.

- An out-of-the-box basic application that doesn't require configuration or setup and can be extended immediately.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

## Getting started

In order to set up your own project you will need an github account and be logged in, the simply click on “use this template” button. Tell github where you want to save your prototype and click “create repository from template”.

Click on the green "code" button and choose to clone the repo to contribute to this project or fork this project. Forking will be needed when deploying your version.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

## Spinning up your local environment

For this part of the tutorial you will need a git client, node.js, and either yarn or npm on your local machine.
The Skeleton application is a end-to-end application and consists of a Gatsby-based front-end and the back-end from [Conduction](https://github.com/ConductionNL/commonground-gateway).

You will need two things installed for this application to work.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

- [Node.js](https://nodejs.org/en/)
- [Docker](https://www.docker.com/)
Comment on lines +18 to +19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should have version numbers included I think.


With both installed, first spin up the front-end of the application.

In order to start developing locally you need to clone your new repository to your local machine. Then open your favorite CLI and simply navigate to the folder containing your repository then go into /pwa and start up gatsby or next.js in development mode with the following commands.
Clone your new repository to your local machine to start developing. Open the terminal, and navigate to the folder containing your repository.

**NextJS**
Use the following command to spin up the front-end:

```cli
$ yarn install
$ yarn dev
cd /pwa
npm install
npm run develop
```

**Gatsby**
With the front-end running in `port:8000`, change directory out of the folder to the root of your repo. With Docker running:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docker has to be running to run these commands. I feel as if, if you're unfamiliar with Docker, this might not be clear at this point.

It might be good to add some info boxes to our documentation every now and then. To add some more context to why things might not yet be working. In this case, we could just add all the commands as already stated, but add an information box with e.g. "Make sure your docker is running on your local machine".

Example of how React does this in their documentation (yellow box):

image


```cli
$ npm install
$ npm run develop
docker-compose pull
docker-compose up
Comment on lines +36 to +37

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commands for development and production differ, might be good to add the development ones here and add a production section of documentation in which we document the production commands.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docker-compose -f docker-compose-dev.yml pull 
docker-compose -f docker-compose-dev.yml up 

```

After yarn is ready with setting up your dev environment you should be able to navigate to [http://localhost:3000/](http://localhost:3000/) on Next or to [http://localhost:8000/](http://localhost:8000/) for gatsby and see the same application as on
[https://conductionnl.github.io/nl-design-skeleton-gatsby/](https://conductionnl.github.io/nl-design-skeleton-gatsby/). Feel free to open up your project code and make some changes you should see the changes in your development environment after an automatic hot reload.
Allow Docker the time to pull all the images required and spin up the back-end. After a few minutes, a "ready to handle connections" message will be displayed in the terminal. Navigate to [http://localhost:8000/](http://localhost:8000/) to view the app in your browser.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be nice to be inside of one of those info boxes.


## Common Ground Gateway
To help with authentication and connecting to API's we integrated another open source project called [Common Ground api gateway](https://github.com/ConductionNL/commonground-gateway).
This allows us to define how to authenticate to external API's and help with user authentication.
To use the gateway docker desktop is required on your machine.
When in the root folder you can run the following command to start the common ground gateway and its admin dashboard:
We integrated another open source project called Common Gateway to authenticate and connect to APIs. This gateway allows us to define how to authenticate to external APIs and help with user authentication. To use the gateway docker desktop is required on your machine. When in the root folder, you can run the following command to start the Common Gateway and its admin dashboard. Navigate to [http://localhost:83/](http://localhost:83/) to view the app in your browser.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this regarding the previous commands docker-compose pull & up? Or is the command missing here?

"you can run the following command", but no command follows.


```cli
$ docker-compose -f "docker-compose-dev.yml" up
## Development of the Skeleton Application

The following examples assumes understanding of `HTML/CSS/JavaScript`. Basic understanding of how [React](https://reactjs.org/docs/getting-started.html) and [TypeScript](https://www.typescriptlang.org/) work is highly recommended for developing and customizing the skeleton application.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

## Adding Design Tokens and importing component from a NL Design Library

As you may have noticed, the `className` of the example above is from the municipality of Utrecht. This is called a `NL Design Token`. Whereas using classnames to store `CSS` rules is a classic method, exporting a bundle classnames as tokens to be used in other applications is a clever way to endorse a modular ecosystem. Design tokens are all the values needed to construct and maintain a design system — spacing, color, typography, object styles, animation, etc. — represented as data. Replacing one design token for another will quickly change the look of an application, without the need of specifying many rules you normally would.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

In the NL Design System there are multiple participants and for this example we will use both [Den Haag's](https://nl-design-system.github.io/denhaag/?path=/story/den-haag-introduction--page) and [Utrecht's](https://github.com/nl-design-system/utrecht) library.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has it been decided that we're going to use Den Haag's components? Last time I heard, we weren't.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the hackathon they was a mention of using them and it that it would've been nice to add them. If not, I can replace that part


## _Importing a component from a library_

Below is a `<Button/>` implemented in the top-level `<App />` component. There are three steps to do this.

- `$ npm install @gemeente-denhaag/components-react`
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

This installs the library and provides access to the components. Then in the second step, import the `<Button />` in `<App />` or any other component you like.

```JavaScript
import { Button, StylesProvider } from "@gemeente-denhaag/components-react"; // This is step 2
// Import your design tokens here as well! Otherwise your components will be unstyled (below is documented how to do this)

function App() {
return (
<StylesProvider>
<Button variant={"primary-action"}>Click here!</Button>
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved
</StylesProvider>
);
} // The <Button> component is implemented here

export default App;
```

After it's finished loading the gateway will be available from [localhost](localhost) and its admin ui from [localhost:83](localhost:83).
## _Adding design tokens_

Mixing components from one library and the design tokens from another library is where things get interesting. To do this,

- `$ npm i @utrecht/design-tokens` and import the tokens in the file of the component.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

to add the design tokens itself. Now you can import the tokens and add them (for instance) to the `<Button />` component by adding `--utrecht-color-blue-35`. This changes the button color to a light blue.

The code would look like:

```JavaScript
import { Button, StylesProvider } from "@gemeente-denhaag/components-react";
import * from @utrecht/design-tokens; // here the tokens are add from the Utrecht library

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if this is the way we want to implement this. Right now, we're just implementing the entire package like it's a javascript import (which might be the way to go, but I'm unsure).

We've done this in a different way in the skeleton-gatsby repository (the new skeleton application repository). You could check the /styling/index.css file to see how we did it.

I think that in both cases we're including all the design tokens right now, which we will have to refactor at some point in the future. Because right now (in this example) we're importing literally every design-token, to only make use of --utrecht-color-blue-35.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are the lead, man ;)

Will implement all suggestions/


function App() {
return (
<StylesProvider>
<Button className={--utrecht-color-blue-35} variant={"primary-action"}>Click here!</Button>
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved
</StylesProvider>
);
}

export default App;
```

## _Adding a component directly_

Below is an example of how a `TopNav` component is added in TypeScript.

To add a `TopNav` component:

```javascript
cd /src/components
mkdir topNav
touch TopNav.tsx
touch TopNav.css
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved
```

Add the following code in `TopNav.tsx`

```TypeScript
import * as React from "react"; // Import everything you need from React
import { Link } from "gatsby"; // Gatsby's way of local linking.

// interfaces are required values for the component.
interface ITopNavItem {
href: string; // hyperlink
title: string | JSX.Element; // displayed name of link
current?: boolean; // optional
}

interface TopNavProps {
items: ITopNavItem[];
}

export const Menu: React.FC<TopNavProps> = ({ items }) => {
return (
<div className="utrecht-navhtml">
<nav className="topnav">
<ul className="utrecht-topnav__list">
{/*example of a item */}
<Link className={"utrecht-topnav__link"} to={"/"}>
Home
</Link>
</ul>
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved
</nav>
</div>
);
};

```

This component now is ready to be imported by a component higher up in the application, like the `<Layout />`.
MWest2020 marked this conversation as resolved.
Show resolved Hide resolved

That's it. The imported component is written in JSX.

## API calls (to be added)

In the `/src/apiService` folder.

## Environment variables
In the pwa folder there are 2 .env files used for local development and the static files.

These are called [.env.development](pwa/.env.development) and [.env.production](pwa/.env.production).
You can edit these to define your own environment variables.
In the `pwa` folder there are 2 `.env` files used for local development and the static files.

These are called `.env.development` and `.env.production`. You can edit these to define your own environment variables.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we have to update.

If we're going to add .env.development and .env.production into the repository (and therefore into git), Github will be able to see the changes. This can cause many issues (e.g. production keys being committed by accident).

A simple way to solve this is as followed:

Add .env.development and .env.production to the .gitignore and add two new files to the repository: .env.development.example and .env.production.example.

In these example files, we add all the KEYS (NOT the VALUES of these KEYS), like so (e.g.):

API_KEY_X=
OTHER_KEY=
YOU_GET_THE_IDEA=

In this documentation, we could explain that you have to copy these files, to the respective variants without .example and add they values to the required keys.

This way, when cloning a repository, you always know what keys you need to fill, but you can never push those keys to the repository.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: if we have values to keys that are publicly available, we could add these to the .example files I think.


When adding new variables make sure to also add them to the [urlContext](pwa/src/context/urlContext.tsx) file.
When adding new variables make sure to also add them to the `urlContext` file.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to keep doing this.


## Publishing your prototype to the internet (gatsby only)
## Publishing your prototype to the internet (Gatsby only)

The gatsby version of the skeleton application has build in support for github pages, meaning that you can build your application into a static website and publish it as a github page. The skeleton repository comes with a build in github action for publishing itself as a github page, meaning that you can have your prototype automatically published to the internet on a code push.
The Gatsby version of the skeleton application has built support for GitHub pages. You can turn your application into a static website and publish it as a GitHub page. The skeleton repository comes with a build GitHub action for publishing itself as a GitHub page. You can have your prototype automatically published to the internet on a code push.

For this to work you will need to do active github-pages on your repository, go to your repository settings and click on pages select gh-pages as a source and press on save (if you do not see a gh-pages branch yet you can create one by pushing to master).
For this to work, you will need to do activate GitHub-pages on your repository, go to your repository settings, click on pages, select `gh-pages` as a source, and press on save (if you do not see a `gh-pages` branch yet you can create one by pushing to main).

After clicking on save you can wait for github to publish your project and provide you with a link you can share for your demo. Keep in mind that from this point on all pushes to master and development will result in updates to your online demo environment.
After clicking on save, you can wait for GitHub to publish your project and provide you with a link you can share for your demo. Keep in mind that all pushes to main and development will result in updates to your online demo environment from this point on.