Skip to content

Commit

Permalink
feat(repo): shared ui lib (#17021)
Browse files Browse the repository at this point in the history
Co-authored-by: bearni95 <[email protected]>
  • Loading branch information
bearni95 and bearni95 authored May 20, 2024
1 parent 7bc0683 commit 940b965
Show file tree
Hide file tree
Showing 98 changed files with 7,157 additions and 127 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ui-lib--ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: UI Lib Build and Checks

on: workflow_call

jobs:
build:
runs-on: [taiko-runner]
steps:
- name: Cancel previous runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install pnpm dependencies
uses: ./.github/actions/install-pnpm-dependencies

- name: Svelte build
working-directory: ./packages/ui-lib
run: pnpm build

- name: Storybook build
working-directory: ./packages/ui-lib
run: pnpm build-storybook

- name: Svelte check
working-directory: ./packages/ui-lib
run: pnpm check

- name: Check formatting
working-directory: ./packages/ui-lib
run: pnpm lint

- name: Unit tests
env:
SKIP_ENV_VALIDATION: "true"
working-directory: ./packages/ui-lib
run: pnpm test:unit
13 changes: 13 additions & 0 deletions packages/ui-lib/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
32 changes: 32 additions & 0 deletions packages/ui-lib/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/** @type { import("eslint").Linter.Config } */
module.exports = {
root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier',
'plugin:storybook/recommended'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
},
env: {
browser: true,
es2017: true,
node: true
},
overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};
13 changes: 13 additions & 0 deletions packages/ui-lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
node_modules
/build
/dist
/.svelte-kit
/package
.env
.env.*
!.env.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/storybook-static
*storybook.log
1 change: 1 addition & 0 deletions packages/ui-lib/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
5 changes: 5 additions & 0 deletions packages/ui-lib/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
storybook-static
8 changes: 8 additions & 0 deletions packages/ui-lib/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
29 changes: 29 additions & 0 deletions packages/ui-lib/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { StorybookConfig } from '@storybook/sveltekit';

export const framework = {
name: '@storybook/sveltekit',
options: {}
};

export const docs = { autodocs: false };
export const addons = [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@chromatic-com/storybook',
'@storybook/addon-interactions',
'@storybook/addon-themes'
];

const config: StorybookConfig = {
//framework: '@taiko/ui-lib',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
staticDirs: ['../static'],
framework: {
name: '@storybook/sveltekit',
options: {}
},
addons,
docs
};

export default config;
31 changes: 31 additions & 0 deletions packages/ui-lib/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Preview } from '@storybook/svelte';
import { withThemeByDataAttribute } from '@storybook/addon-themes';
import '../src/lib/styles/app.css';

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i
}
}
},

tags: ['autodocs']
};

/* snipped for brevity */

export const decorators = [
withThemeByDataAttribute({
themes: {
light: 'light',
dark: 'dark'
},
defaultTheme: 'light',
attributeName: 'data-theme'
})
];

export default preview;
71 changes: 71 additions & 0 deletions packages/ui-lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Taiko UI Library

## Components

- [x] Footer
- [ ] Icons
- [ ] Button
- [ ] ResponsiveController

## Exported values

- [x] UI Kit colors
- [x] Dark Theme colors
- [x] Light Theme colors
- [ ] Typography

## Contributing

### Development

The library includes [Storybook](https://storybook.js.org/) for development. To start the Storybook server, run:

```bash
$ pnpm storybook
```

### Build

The library builds and packs as a [Svelte library] with the following command:

```bash
$ pnpm build
```

### Adding components

In order to add new components into the library to be used outside:

1. Create a new component under `src/lib/components/` directory.
2. Export the component on `src/lib/index.ts`:

```typescript
import { NewComponent } from './components/NewComponent';

export {
Footer,
...
NewComponent
};

```

3. Now you can import it and use it in another project:

```typescript
import { NewComponent } from '@taiko/ui-lib';

...

<NewComponent />
```

### Exported values

Besides from the components, the library exports the configurations for TailwindCSS in `src/theme/`:

- `colors.js`: [Taiko's UI Kit](https://www.figma.com/design/3zuVeAbGDICzyhVvSI15nG/Taiko---UI-Kit-%26-Components?node-id=26-122&t=R6fMNiuhGixl6nxX-0) core colors
- `dark-mode.js`: TailwindCSS/DaisyUI dark mode configuration
- `light-mode.js`: TailwindCSS/DaisyUI light mode configuration

All exported values from the `src/theme` directory are prefixed with `tko-` to avoid conflicts with other libraries and local definitions.
82 changes: 82 additions & 0 deletions packages/ui-lib/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@taiko/ui-lib",
"version": "0.0.1",
"type": "module",
"engines": {
"node": ">=20"
},
"scripts": {
"dev": "vite dev",
"build": "vite build && npm run package",
"preview": "vite preview",
"package": "svelte-kit sync && svelte-package && publint",
"prepublishOnly": "npm run package",
"test": "npm run test:integration && npm run test:unit",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check ./src && eslint ./src --fix",
"format": "prettier --write .",
"test:integration": "playwright test",
"test:unit": "vitest",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js",
"main": "./dist/index.js"
},
"./tailwind": "./tailwind.config.js"
},
"files": [
"tailwind.config.js",
"dist",
"!dist/**/*.test.*",
"!dist/**/*.spec.*"
],
"peerDependencies": {
"svelte": "^4.0.0"
},
"devDependencies": {
"@chromatic-com/storybook": "^1.3.4",
"@playwright/test": "^1.28.1",
"@storybook/addon-essentials": "^8.0.10",
"@storybook/addon-interactions": "^8.0.10",
"@storybook/addon-links": "^8.0.10",
"@storybook/addon-themes": "^8.1.1",
"@storybook/blocks": "^8.0.10",
"@storybook/svelte": "^8.0.10",
"@storybook/sveltekit": "^8.0.10",
"@storybook/test": "^8.0.10",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/package": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@types/eslint": "^8.56.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"autoprefixer": "^10.4.19",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-storybook": "^0.8.0",
"eslint-plugin-svelte": "^2.35.1",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"publint": "^0.1.9",
"storybook": "^8.0.10",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"tailwindcss": "^3.4.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.11",
"vitest": "^1.2.0"
},
"svelte": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"daisyui": "^4.11.1",
"tailwindcss-image-rendering": "^1.0.2"
}
}
12 changes: 12 additions & 0 deletions packages/ui-lib/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { PlaywrightTestConfig } from '@playwright/test';

const config: PlaywrightTestConfig = {
webServer: {
command: 'npm run build && npm run preview',
port: 4173
},
testDir: 'tests',
testMatch: /(.+\.)?(test|spec)\.[jt]s/
};

export default config;
6 changes: 6 additions & 0 deletions packages/ui-lib/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
};
13 changes: 13 additions & 0 deletions packages/ui-lib/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
12 changes: 12 additions & 0 deletions packages/ui-lib/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div>%sveltekit.body%</div>
</body>
</html>
7 changes: 7 additions & 0 deletions packages/ui-lib/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { describe, it, expect } from 'vitest';

describe('sum test', () => {
it('adds 1 + 2 to equal 3', () => {
expect(1 + 2).toBe(3);
});
});
Loading

0 comments on commit 940b965

Please sign in to comment.