Skip to content

Commit

Permalink
feat(ui): update tokens, clean up component, add doc ui references
Browse files Browse the repository at this point in the history
  • Loading branch information
waldronmatt committed Oct 10, 2023
1 parent 070c562 commit a3838e6
Show file tree
Hide file tree
Showing 17 changed files with 7,610 additions and 2,141 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,6 @@ coverage/

# nx
nx-cloud.env

# Storybook
storybook-static
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Delete workspace root `node_modules` and `pnpm-lock.yaml` files:
**Note**: Install `rimraf` globally and make sure it is not installed in the workspace root so errors aren't thrown.

```bash
pnpm clear
pnpm delete
```

Lint root and `configs/` `js/cjs` files, check for secrets, lint dependency versions, validate published packages, and verify monorepo best practices:
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
"packages": ["apps/*", "configs/*", "packages/*"],
"packages": ["apps/*", "configs/*", "docs/*", "packages/*"],
"npmClient": "pnpm",
"loglevel": "verbose",
"version": "independent",
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
"workspaces": [
"apps/*",
"configs/**",
"docs/**",
"packages/*"
],
"scripts": {
"prepare": "husky install",
"commit": "git-cz",
"clear": "rimraf pnpm-lock.yaml node_modules",
"delete": "rimraf pnpm-lock.yaml node_modules",
"nx:graph": "npx nx graph",
"format": "prettier --write .",
"preview:version": "lerna version --dry-run --yes",
Expand All @@ -31,8 +32,8 @@
"preview": "npx nx run-many -t preview",
"stub": "npx nx run-many -t stub",
"bootstrap:ci": "pnpm i --frozen-lockfile",
"lint:ci": "npx nx affected -t lint --parallel=3",
"build:ci": "npx nx affected -t build --parallel=3",
"lint:ci": "npx nx affected -t lint --parallel=3",
"test:ci": "npx nx affected -t test:prod --parallel=3",
"version:ci": "lerna version --yes",
"publish:ci": "lerna publish from-package --yes"
Expand Down
21 changes: 21 additions & 0 deletions packages/ui/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Matthew Waldron

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 3 additions & 2 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pnpm add @waldronmatt/demo-ui
Used named imports to enable `js` and `css` treeshaking:

```tsx
import '@waldronmatt/demo-ui/styles/global.css'; // add global tokens
// add global tokens
import '@waldronmatt/demo-ui/styles/global.css';
import { Button } from '@waldronmatt/demo-ui';
// or import the component directly
// import { Button } from '@waldronmatt/demo-ui/components/Button/index.js';
Expand All @@ -33,7 +34,7 @@ export default App;

## Styles

This component library was tested and built using [the-new-css-reset/css/reset.css](https://github.com/elad2412/the-new-css-reset) reset library and the [sanitize.css](https://github.com/csstools/sanitize.css/). However, this library **does not** come with these libraries included. To use, import into your app's entrypoint above the app and component imports:
This component library was tested and built using [the-new-css-reset](https://github.com/elad2412/the-new-css-reset) reset library and the [sanitize.css](https://github.com/csstools/sanitize.css/) normalize library. However, this library **does not** come with these libraries included. To use, import into your app's entrypoint above the app and component imports:

```bash
pnpm add the-new-css-reset sanitize.css
Expand Down
9 changes: 6 additions & 3 deletions packages/ui/lib/components/Button/button.module.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
.button {
border: 1px solid #000;
background-color: #d3d3d3;
cursor: pointer;
padding: 1rem;
}

.sm {
font-size: var(--font-size-sm);
font-size: var(--demo-ui-font-size-sm);
}

.md {
font-size: var(--font-size-md);
font-size: var(--demo-ui-font-size-md);
}

.lg {
font-size: var(--font-size-lg);
font-size: var(--demo-ui-font-size-lg);
}
2 changes: 1 addition & 1 deletion packages/ui/lib/components/Button/button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Button } from '@/Button/index.js';

test('loads and displays greeting', async () => {
test('loads and displays greeting', () => {
render(<Button>Hello World</Button>);
expect(screen.getByRole('button')).toHaveAttribute('type', 'button');
// css module class names get randomized on prod build,
Expand Down
5 changes: 1 addition & 4 deletions packages/ui/lib/components/Button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElemen
}

export function Button({ children, variant = 'md', ...nativeProps }: ButtonProps): JSX.Element {
const { className, ...props } = nativeProps;
return (
<button type="button" className={`${className} ${styles.button} ${styles[variant]}`} {...props}>
<button type="button" className={`${styles.button} ${styles[variant]}`} {...nativeProps}>
{children}
</button>
);
}

Button.displayName = 'Button';
10 changes: 6 additions & 4 deletions packages/ui/lib/components/Link/link.module.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
.a {
.link {
color: #0f62fe;
text-decoration: underline;
padding: 1rem;
}

.sm {
font-size: var(--font-size-sm);
font-size: var(--demo-ui-font-size-sm);
}

.md {
font-size: var(--font-size-md);
font-size: var(--demo-ui-font-size-md);
}

.lg {
font-size: var(--font-size-lg);
font-size: var(--demo-ui-font-size-lg);
}
2 changes: 1 addition & 1 deletion packages/ui/lib/components/Link/link.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Link } from '@/Link/index.js';

test('loads and displays greeting', async () => {
test('loads and displays greeting', () => {
render(<Link href="/">Hello World</Link>);
expect(screen.getByRole('link')).toBeEnabled();
// css module class names get randomized on prod build,
Expand Down
5 changes: 1 addition & 4 deletions packages/ui/lib/components/Link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement>
}

export function Link({ children, variant = 'md', ...nativeProps }: LinkProps): JSX.Element {
const { className, ...props } = nativeProps;
return (
<a className={`${className} ${styles.link} ${styles[variant]}`} {...props}>
<a className={`${styles.link} ${styles[variant]}`} {...nativeProps}>
{children}
</a>
);
}

Link.displayName = 'Link';
5 changes: 0 additions & 5 deletions packages/ui/lib/global.css

This file was deleted.

5 changes: 5 additions & 0 deletions packages/ui/lib/styles/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:root {
--demo-ui-font-size-sm: 10px;
--demo-ui-font-size-md: 20px;
--demo-ui-font-size-lg: 30px;
}
7 changes: 4 additions & 3 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"types": "./dist/main.d.ts",
"import": "./dist/main.js"
},
"./*": "./dist/*"
"./*": "./dist/*",
"./lib/*": "./lib/*"
},
"files": [
"dist",
Expand All @@ -25,8 +26,8 @@
"test": "jest --coverage",
"test:watch": "jest --watch",
"test:prod": "cross-env TEST_ENV=prod NODE_OPTIONS=--experimental-vm-modules jest",
"clean": "rimraf dist coverage tsconfig.build.tsbuildinfo",
"build": "tsc --p ./tsconfig.build.json && vite build"
"build": "tsc --p ./tsconfig.build.json && vite build",
"clean": "rimraf dist coverage tsconfig.build.tsbuildinfo"
},
"publishConfig": {
"access": "public"
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export default defineConfig({
viteStaticCopy({
targets: [
{
src: 'lib/global.css',
dest: 'styles',
src: 'lib/styles/global.css',
dest: 'styles/',
},
],
}),
Expand Down
Loading

0 comments on commit a3838e6

Please sign in to comment.