Skip to content

Commit

Permalink
feat: setup hooks package
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiwat10 committed Nov 29, 2021
1 parent 9fd8056 commit 8225a18
Show file tree
Hide file tree
Showing 25 changed files with 15,555 additions and 101 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ yarn-error.log
# storybook
.out

/coverage
/coverage

dist
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@web3-ui/root",
"license": "MIT",
"version": "0.0.0",
"private": "true",
"private": "false",
"engines": {
"node": ">=16.0.0",
"yarn": "^1.5"
Expand All @@ -15,8 +15,12 @@
"prepare": "husky install",
"pre-commit-hook": "yarn lint-staged",
"format": "prettier --write",
"build": "yarn workspace @web3-ui/components build",
"test": "yarn workspace @web3-ui/components test"
"build:components": "yarn workspace @web3-ui/components build",
"build:hooks": "yarn workspace @web3-ui/hooks build",
"build": "yarn build:components && yarn build:hooks",
"test": "yarn workspace @web3-ui/components test",
"dev:components": "yarn workspace @web3-ui/components dev",
"dev:hooks": "yarn workspace @web3-ui/hooks dev"
},
"lint-staged": {
"*.{ts,tsx,json,js,jsx}": "yarn format"
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"node": ">=16.0.0",
"yarn": "^1.5"
},
"description": "React components for web3, built with Chakra-UI",
"description": "React UI components for web3",
"author": "Developer DAO",
"homepage": "https://github.com/Developer-DAO/web3-ui/",
"bugs": {
Expand Down
17 changes: 13 additions & 4 deletions packages/components/src/components/Address/Address.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ import { storiesOf } from '@storybook/react';
import React from 'react';
import { Address } from '.';

import { useWallet } from '@web3-ui/hooks';
import { useWallet, Provider } from '@web3-ui/hooks';
import { Button } from '@chakra-ui/react';

storiesOf('Address', module).add('Default', () => <Address />);
storiesOf('Address', module).add('Default', () => <Address value='This is an input' />);

const WithWallet = () => {
useWallet();
return <Address />;
const { connected, connectWallet, connection } = useWallet();

return (
<Provider network='rinkeby'>
<Address
value={connected ? connection.ens || connection.userAddress || '' : 'Not connected'}
/>
<Button onClick={connectWallet}>Connect wallet</Button>
</Provider>
);
};

storiesOf('Address', module).add('WithWallet', () => <WithWallet />);
8 changes: 5 additions & 3 deletions packages/components/src/components/Address/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Input } from '@chakra-ui/input';
import React from 'react';

export interface AddressProps {}
export interface AddressProps {
value: string;
}

export const Address: React.FC<AddressProps> = ({}) => {
return <Input />;
export const Address: React.FC<AddressProps> = ({ value }) => {
return <Input value={value} />;
};

This file was deleted.

Empty file added packages/hooks/.gitignore
Empty file.
7 changes: 7 additions & 0 deletions packages/hooks/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
printWidth: 100,
semi: true,
singleQuote: true,
trailingComma: 'es5',
jsxSingleQuote: true,
};
5 changes: 5 additions & 0 deletions packages/hooks/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/react',
};
9 changes: 9 additions & 0 deletions packages/hooks/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};
19 changes: 19 additions & 0 deletions packages/hooks/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License

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.
2 changes: 0 additions & 2 deletions packages/hooks/index.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/hooks/index.js

This file was deleted.

22 changes: 22 additions & 0 deletions packages/hooks/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testMatch: [
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
'<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}',
],
coveragePathIgnorePatterns: [
'/node_modules/',
'dist/',
'<rootDir>/src/index.ts',
'<rootDir>/src/components/index.ts',
],
collectCoverageFrom: ['<rootDir>/src/**/*.{js,ts,tsx,jsx}'],
coverageThreshold: {
global: {
branches: 90,
functions: 90,
lines: 90,
statements: 90,
},
},
};
62 changes: 55 additions & 7 deletions packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@web3-ui/hooks",
"license": "MIT",
"version": "0.0.1",
"version": "0.1.0",
"private": false,
"engines": {
"node": ">=16.0.0",
Expand All @@ -17,16 +17,64 @@
"type": "git",
"url": "git+https://github.com/Developer-DAO/web3-ui/"
},
"main": "index.js",
"scripts": {
"types": "index.d.ts",
"test": "echo \"Error: no test specified\" && exit 1"
"build": "yarn clean; rollup -c",
"clean": "rimraf dist",
"format": "prettier --write \"src/**/*.{ts,tsx,json,js,jsx}\"",
"format:check": "prettier --list-different \"src/**/*.{ts,tsx,json,js,jsx}\"",
"test": "jest --maxWorkers=2",
"test:watch": "yarn test --watch",
"test:coverage": "jest --coverage --colors --maxWorkers=2",
"hygen": "hygen",
"component:new": "hygen component with-prompt",
"pre-commit-hook": "yarn lint-staged",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"dev": "yarn storybook"
},
"keywords": [],
"main": "dist/index.js",
"module": "dist/index.esm.js",
"types": "dist/index.d.ts",
"dependencies": {
"react": "^17.0.2"
"@walletconnect/web3-provider": "^1.6.6",
"ethers": "^5.5.1",
"web3modal": "^1.9.4"
},
"peerDependencies": {
"react": ">=16.8.6"
"react": "*",
"react-dom": "*"
},
"devDependencies": {
"@babel/core": "^7.12.7",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@storybook/addon-actions": "^6.4.0",
"@storybook/addon-essentials": "^6.4.0",
"@storybook/addon-links": "^6.4.0",
"@storybook/react": "^6.4.0",
"@testing-library/react": "^12.1.2",
"@types/jest": "^26.0.15",
"@types/node": "^16.11.9",
"@types/react": "^17.0.36",
"@types/react-dom": "^16.9.10",
"babel-loader": "^8.2.1",
"husky": "^7.0.0",
"hygen": "^6.0.4",
"jest": "^26.6.3",
"lint-staged": "^12.1.2",
"prettier": "^2.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"rimraf": "^3.0.2",
"rollup": "^2.33.3",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-terser": "7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"ts-jest": "^26.4.4",
"ts-loader": "^8.0.11",
"typescript": "^4.1.0"
},
"lint-staged": {
"*.{ts,tsx,json,js,jsx}": "yarn format"
}
}
71 changes: 71 additions & 0 deletions packages/hooks/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import typescript from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import pkg from './package.json';
import resolve from '@rollup/plugin-node-resolve';
import copy from 'rollup-plugin-copy';
import ts from 'typescript';

export default {
input: './src/index.ts',
external: [...Object.keys(pkg.dependencies || {}), ...Object.keys(pkg.peerDependencies || {})],
output: [
{
file: `./${pkg.module}`,
format: 'es',
sourcemap: true,
},
{
file: `./${pkg.main}`,
format: 'cjs',
sourcemap: true,
},
],
plugins: [
resolve(),
commonjs(),
typescript({
typescript: ts,
tsconfig: 'tsconfig.json',
tsconfigDefaults: {
exclude: [
'**/*.spec.ts',
'**/*.test.ts',
'**/*.spec.tsx',
'**/*.test.tsx',
'node_modules',
'bower_components',
'jspm_packages',
'dist',
'**/*.stories.tsx',
'**/*.stories.ts',
],
compilerOptions: {
sourceMap: true,
declaration: true,
},
},
}),
terser({
output: {
comments: false,
},
}),
copy({
targets: [
{ src: '../../LICENSE', dest: 'dist' },
{ src: '../../README.md', dest: 'dist' },
{
src: 'package.json',
dest: 'dist',
transform: (content) => {
const { scripts, devDependencies, husky, release, engines, ...keep } = JSON.parse(
content.toString()
);
return JSON.stringify(keep, null, 2);
},
},
],
}),
],
};
Loading

0 comments on commit 8225a18

Please sign in to comment.