Skip to content

Commit 63341b6

Browse files
authored
Merge pull request #277 from bcgov/feature/components
React components package
2 parents 7e27c92 + 4f71b41 commit 63341b6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+20140
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
"eslint:recommended",
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:react-hooks/recommended",
8+
"plugin:storybook/recommended",
9+
],
10+
ignorePatterns: ["dist", ".eslintrc.cjs"],
11+
parser: "@typescript-eslint/parser",
12+
plugins: ["react-refresh"],
13+
rules: {
14+
"react-refresh/only-export-components": [
15+
"warn",
16+
{ allowConstantExport: true },
17+
],
18+
},
19+
};

packages/react-components/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
storybook-static
14+
vite-dist
15+
*.local
16+
17+
# Editor directories and files
18+
.vscode/*
19+
!.vscode/extensions.json
20+
.idea
21+
.DS_Store
22+
*.suo
23+
*.ntvs*
24+
*.njsproj
25+
*.sln
26+
*.sw?

packages/react-components/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { StorybookConfig } from "@storybook/react-vite";
2+
3+
const config: StorybookConfig = {
4+
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
5+
addons: [
6+
"@storybook/addon-links",
7+
"@storybook/addon-essentials",
8+
"@storybook/addon-interactions",
9+
],
10+
framework: {
11+
name: "@storybook/react-vite",
12+
options: {},
13+
},
14+
};
15+
export default config;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { Preview } from "@storybook/react";
2+
3+
import "@bcgov/bc-sans/css/BC_Sans.css";
4+
import "@bcgov/design-tokens/css/variables.css";
5+
6+
const preview: Preview = {
7+
parameters: {
8+
actions: { argTypesRegex: "^on[A-Z].*" },
9+
controls: {
10+
matchers: {
11+
color: /(background|color)$/i,
12+
date: /Date$/i,
13+
},
14+
},
15+
options: {
16+
storySort: {
17+
order: ["Introduction"],
18+
},
19+
},
20+
},
21+
};
22+
23+
export default preview;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
## 0.0.2
4+
5+
### Changed
6+
7+
- Moved `@bcgov/bc-sans` to peer dependencies and included import guidance in README, rather than bundling copies of the font in the rollup process.
8+
- Moved design tokens CSS import out of Tag component and into common index export file.
9+
10+
### Added
11+
12+
- Added Button component.
13+
14+
## 0.0.1
15+
16+
### Added
17+
18+
- Added TagGroup/TagList/Tag components.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Dockerfile.storybook
2+
3+
# -----------
4+
# Build stage
5+
# -----------
6+
FROM node:lts-alpine as build-stage
7+
8+
# Copy package.json and package-lock.json
9+
WORKDIR /app
10+
COPY package*.json .
11+
12+
# Print npm config
13+
RUN npm config list
14+
15+
# Install dependencies
16+
RUN npm install
17+
18+
# Copy required files
19+
COPY src ./src
20+
COPY .storybook ./.storybook
21+
22+
# Run Storybook build script, which places built files in /app/storybook-static
23+
RUN npm run storybook-build
24+
25+
# -----------
26+
# Serve stage
27+
# -----------
28+
FROM nginxinc/nginx-unprivileged:alpine as serve-stage
29+
30+
# Copy nginx configuration
31+
COPY ./nginx.storybook.conf /etc/nginx/nginx.conf
32+
33+
# Copy built Storybook files to nginx public web root folder
34+
COPY --from=build-stage /app/storybook-static /usr/share/nginx/html
35+
36+
EXPOSE 8080
37+
CMD ["nginx", "-g", "daemon off;"]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Dockerfile.vite
2+
3+
# -----------
4+
# Build stage
5+
# -----------
6+
FROM node:lts-alpine as build-stage
7+
8+
# Copy package.json and package-lock.json
9+
WORKDIR /app
10+
COPY package*.json .
11+
12+
# Print npm config
13+
RUN npm config list
14+
15+
# Install dependencies
16+
RUN npm install
17+
18+
# Copy required files
19+
COPY index.html ./
20+
COPY tsconfig.json ./
21+
COPY tsconfig.vite.json ./
22+
COPY vite.config.ts ./
23+
COPY src ./src
24+
25+
# Run Vite build script, which places built files in /app/vite-dist
26+
RUN npm run vite-build
27+
28+
# -----------
29+
# Serve stage
30+
# -----------
31+
FROM nginxinc/nginx-unprivileged:alpine as serve-stage
32+
33+
# Copy nginx configuration
34+
COPY ./nginx.vite.conf /etc/nginx/nginx.conf
35+
36+
# Copy built Vite files to nginx public web root folder
37+
COPY --from=build-stage /app/vite-dist /usr/share/nginx/html
38+
39+
EXPOSE 5555
40+
CMD ["nginx", "-g", "daemon off;"]

packages/react-components/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# @bcgov/design-system-react-components
2+
3+
[![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://github.com/bcgov/repomountie/blob/master/doc/lifecycle-badges.md)
4+
5+
This package contains a library of React components built using [React Aria Components](https://react-spectrum.adobe.com/react-aria/react-aria-components.html) to implement the BC Design System.
6+
7+
Questions? Please email the <a href="mailto:DesignSystem@gov.bc.ca">GDX OSS Design Team</a>.
8+
9+
See repository: https://github.com/bcgov/design-system
10+
11+
To use, install this package and import the components into your application.
12+
13+
## Install
14+
15+
`npm install @bcgov/design-system-react-components`
16+
17+
## BC Sans font dependency
18+
19+
This package installs [@bcgov/bc-sans](https://www.npmjs.com/package/@bcgov/bc-sans) as a peer dependency. You must import the font-face declarations from @bcgov/bc-sans and ensure the font is reachable for your end user. The React components require that the `BC Sans` font-face is available to display correctly. The components do not ship their own copies of the font to minimize your bundle size.
20+
21+
**Important!** If you are on a BC Government-provisioned laptop, you already have the BC Sans font installed on your machine. This package uses `BC Sans` (with a space) for its font styles. If you are using this component library but not supplying the font, it's possible that your machine will still display the font correctly for you, **but not your end user**. Make sure to check this by disabling the font on your machine or by testing with another machine.
22+
23+
### Use
24+
25+
```jsx
26+
// App.jsx
27+
28+
// If you're already importing the BC Sans font-face somewhere else in your
29+
// project, there is no need to import it again. Just make sure the `BC Sans`
30+
// declaration and font files are available.
31+
import "@bcgov/bc-sans/css/BC_Sans.css";
32+
33+
// Import the individual components you need
34+
import { TagGroup, TagList } from "@bcgov/design-system-react-components";
35+
36+
export default function App() {
37+
return (
38+
<TagGroup aria-label="Tag group with two items">
39+
<TagList
40+
items={[
41+
{ id: "one", textValue: "One" },
42+
{ id: "two", textValue: "Two" },
43+
]}
44+
/>
45+
</TagGroup>
46+
);
47+
}
48+
```
49+
50+
## Component list
51+
52+
| Component | React Aria Components docs link |
53+
| ---------------------- | --------------------------------------------------------- |
54+
| Button | https://react-spectrum.adobe.com/react-aria/Button.html |
55+
| TagGroup, TagList, Tag | https://react-spectrum.adobe.com/react-aria/TagGroup.html |
56+
57+
## Supported React versions
58+
59+
This package has a peer dependency on `react` and `react-dom` at these versions: `"^16.14.0 || ^17.0.0-rc.1 || ^18.0.0"`
60+
61+
By targeting v16.4.0 as a minimum, we get to use [React's modern JSX transformation](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) in `tsconfig.json`:
62+
63+
```json
64+
"jsx": "react-jsx",
65+
```
66+
67+
This means there's no need for unused `import React from "react"` statements in your JSX files.
68+
69+
## Development
70+
71+
### Components
72+
73+
Components live in `./src/components` and are targeted by the build process with an export in `./src/index.ts`.
74+
75+
### Storybook
76+
77+
Storybook stories live in `./src/stories`.
78+
79+
Run `npm run storybook-dev` to access the Storybook instance for the component library.
80+
81+
### Vite kitchen sink application
82+
83+
Vite uses the components code directly from `./src/components` in groups of content in `./src/pages`.
84+
85+
Run `npm run vite-dev` to access the Vite React demo app.
86+
87+
### Publish new versions
88+
89+
To generate an updated copy of the package for distribution, run the included Rollup script: `npm run rollup`.
90+
91+
This will place artifacts in the `dist` folder, which is targeted for publishing in `package.json` with the [`files` field](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#files).
92+
93+
Update the package version in `package.json` and run `npm publish` to push a new version.

packages/react-components/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>BC Design System React Components Vite Kitchen Sink</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)