-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from CivicDataLab/dev
Dev
- Loading branch information
Showing
6 changed files
with
207 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,96 @@ | ||
# Develop | ||
|
||
Welcome to the development section of the documentation. Here you will find information on seting up OPub UI, tools that helps, and how to contribute. | ||
|
||
## First Steps | ||
|
||
OPub UI is built on top of [React](https://reactjs.org/) and [Radix UI](https://www.radix-ui.com/primitives). If you are not familiar with these, we recommend you read up on them before continuing. | ||
|
||
### Add OPub UI to your project | ||
|
||
OPub UI is available as an npm package. You can install it using your favorite package manager. | ||
|
||
```bash | ||
npm install @opub/ui | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add @opub/ui | ||
``` | ||
|
||
### Add base styles | ||
|
||
OPub UI comes with a set of base styles that you need to import into your project. The base styles are required for OPub UI to work correctly. Add them in the base css file of your project. | ||
|
||
```css | ||
@import url('~opub-ui/dist/assets/styles.css'); | ||
``` | ||
|
||
### Usage | ||
|
||
Once you complete the initial setup, you can import components into your project as needed: | ||
|
||
```js | ||
import { Badge, Button, Menu } from 'opub-cdl/ui'; | ||
``` | ||
|
||
## Working with Next.js | ||
|
||
If you are using [Next.js](https://nextjs.org/), you will need to [transpile the packages](https://nextjs.org/docs/advanced-features/compiler#module-transpilation). Add this inside `next.config.js`: | ||
|
||
```js | ||
module.exports = { | ||
transpilePackages: ['opub-ui', 'react-aria'], | ||
}; | ||
``` | ||
|
||
## Tools | ||
|
||
- [Storybook](https://main--64004009fa0a900a3197549c.chromatic.com/) - View the complete list of available components. | ||
- [Color Contrast Checker](https://marijohannessen.github.io/color-contrast-checker/) - Check the contrast of your colors. | ||
|
||
## Contributing | ||
|
||
We welcome contributions to OPub UI. Please read our [contributing guidelines](https://github.com/CivicDataLab/opub-mono/blob/main/CONTRIBUTING.md) to get started. | ||
|
||
### New Component | ||
|
||
This repo includes a `yarn run new-component` module to help create boilerplate for component creation. | ||
|
||
``` | ||
yarn run new-component Button | ||
``` | ||
|
||
This will create a new component directory in `packages/opub-ui/src` with required files and also export the component in the index.ts | ||
|
||
``` | ||
components/ | ||
┣ Button/ | ||
┃ ┣ Button.module.scss/ | ||
┃ ┣ Button.stories.tsx/ | ||
┃ ┣ Button.test.tsx/ | ||
┃ ┣ Button.tsx/ | ||
┃ ┣ index.ts/ | ||
``` | ||
|
||
## Publishing to NPM | ||
|
||
OPub UI is available as an npm package. To publish a new version, follow these steps: | ||
|
||
### Bundling | ||
|
||
To bundle the package, run: | ||
|
||
```bash | ||
yarn build | ||
``` | ||
|
||
This will create a `dist` folder with the bundled files. Then from the root of the project, run: | ||
|
||
```bash | ||
yarn changeset publish | ||
``` | ||
|
||
Make sure to update the version number in the `package.json` file before publishing. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# Workflows | ||
|
||
## Overview | ||
|
||
For OPub, we have a few different workflows that we use to manage our projects. These workflows are designed to help us manage our projects in a way that is consistent and efficient. | ||
|
||
## Figma -> Code | ||
|
||
### Idea | ||
|
||
Since OPub is supposed to be used to create multiple applications, we need to make sure that the design system is consistent across all the applications, while also being flexible enough to allow for customisation. To achieve this, we use Figma to design the components and then use the design tokens to generate the code. | ||
|
||
### Design Tokens | ||
|
||
We use Figma variables to generate our CSS variables and tokens for Tailwind CSS . This allows us to have a single source of truth for our design tokens. | ||
|
||
In future, the process will be fully automated but for now, we have to follow few steps. | ||
|
||
> This process is only required when we make changes to the design tokens. | ||
> This requires the figma file to have OPub UI variables. | ||
- Install the [variables2json](https://www.figma.com/community/plugin/1253571037276959291) plugin from Figma community. | ||
- Open the Figma file and go to `Plugins > variables2json > Download (bottom right)`. | ||
- Open the downloaded `JSON` and remove the following from start: | ||
|
||
```json | ||
"version": "1.0.4", | ||
"metadata": {}, | ||
``` | ||
|
||
- Copy the remaining JSON and paste it in `/config/tokens/tokens.json`. | ||
|
||
- Run the following command to generate the CSS variables and tokens: | ||
|
||
```bash | ||
yarn run build:tokens | ||
``` | ||
|
||
### Style Dictionary | ||
|
||
Following the previous steps will generate styling variables in `/styles/tokens` folder. This process is handled by [Style Dictionary](https://amzn.github.io/style-dictionary/). You can find the configuration file in `/config/tokens/geneate.mjs`. | ||
|
||
Style Dictrionary is also used to generate the Tailwind CSS config file. You can find the configuration file in `/config/tokens/helpers/tailwind-formattor.js`. The generated tokens are used in `tailwind.config.js`. | ||
|
||
## Code -> Storybook | ||
|
||
### Idea | ||
|
||
Storybook is a tool for UI development. It makes development faster and easier by isolating components. This allows you to work on one component at a time in isolation. You can view the Storybook [here](https://main--64004009fa0a900a3197549c.chromatic.com/). | ||
|
||
### Github Actions | ||
|
||
We use Github Actions to automatically deploy the Storybook to Chromatic. This allows us to view the changes in the components and also allows us to test the components in different browsers. You can find the configuration file in `.github/workflows/chromatic.yml`. | ||
|
||
## Backend -> Frontend | ||
|
||
> This is a work in progress and in experimental phase. | ||
In order to sync the backend and frontend, we use [@graphql-codegen/cli](https://the-guild.dev/graphql/codegen) to generate the types. This allows us to have a single source of truth for the backend and frontend. | ||
|
||
The configuration file for GraphQL Codegen is in `/config/codegen.ts`. The generated types are in `/gql/generated`. | ||
|
||
You can check out the [example](https://github.com/CivicDataLab/opub-mono/blob/main/apps/www/app/%5Blocale%5D/dashboard/dataset/page.tsx) on how to use the generated types. | ||
|
||
To sum up, | ||
|
||
- In Server Component (`page.tsx`), we use the generated types to pre-fetch the data from the backend. | ||
- We use `react-query` to dehydrate the data. | ||
- In Client Components, we use the `useQuery` hook to fetch the data from the cache. |
1650c6b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
opub-www – ./apps/www
opub-www.vercel.app
opub-www-civicdatalab.vercel.app
opub-www-git-main-civicdatalab.vercel.app