├── .editorconfig ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .storybook ├── main.ts └── preview.ts ├── README.md ├── example ├── .env ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt ├── src │ ├── App.js │ ├── App.test.js │ ├── index.js │ ├── reportWebVitals.js │ └── setupTests.js └── yarn.lock ├── jest.config.js ├── jest.setup.ts ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── _normalize.scss ├── _variables.scss ├── components │ ├── Button │ │ ├── Button.module.scss │ │ ├── Button.stories.tsx │ │ ├── Button.test.tsx │ │ ├── Button.tsx │ │ ├── Button.types.ts │ │ └── index.ts │ ├── TestComponent │ │ ├── TestCompoenent.tsx │ │ ├── TestComponent.module.scss │ │ ├── TestComponent.stories.tsx │ │ ├── TestComponent.test.tsx │ │ ├── TestComponent.types.ts │ │ └── index.ts │ └── index.ts ├── declarations.d.ts └── styles.scss └── tsconfig.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | [*] 3 | charset = utf-8 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | dist 2 | node_modules -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true, 5 | "jest": true 6 | }, 7 | "extends": ["plugin:react/recommended", "airbnb"], 8 | "parser": "@typescript-eslint/parser", 9 | "settings": { 10 | "import/resolver": { 11 | "node": { "extensions": [".js", ".jsx", ".ts", ".tsx"] } 12 | } 13 | }, 14 | "parserOptions": { 15 | "ecmaFeatures": { 16 | "jsx": true 17 | }, 18 | "ecmaVersion": 12, 19 | "sourceType": "module" 20 | }, 21 | "plugins": ["react", "@typescript-eslint"], 22 | "rules": { 23 | "no-unused-vars": "warn", 24 | "import/extensions": "off", 25 | "no-use-before-define": "off", 26 | "react/prop-types": "off", 27 | "react/jsx-props-no-spreading": "off", 28 | "@typescript-eslint/no-use-before-define": "error", 29 | "react/react-in-jsx-scope": "off", 30 | "react/jsx-filename-extension": [ 31 | 1, 32 | { "extensions": [".js", ".jsx", ".ts", ".tsx"] } 33 | ], 34 | "import/prefer-default-export": "off", 35 | "import/no-extraneous-dependencies": "off" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .vscode -------------------------------------------------------------------------------- /.storybook/main.ts: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], 5 | addons: ['@storybook/addon-links', '@storybook/addon-essentials'], 6 | webpackFinal: async (config, { configType }) => { 7 | // `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION' 8 | // You can change the configuration based on that. 9 | // 'PRODUCTION' is used when building the static version of storybook. 10 | 11 | // Make whatever fine-grained changes you need 12 | config.module.rules.push({ 13 | test: /\.scss$/, 14 | use: ['style-loader', 'css-loader', 'sass-loader'], 15 | include: path.resolve(__dirname, '../'), 16 | }); 17 | 18 | // Return the altered config 19 | return config; 20 | }, 21 | }; 22 | -------------------------------------------------------------------------------- /.storybook/preview.ts: -------------------------------------------------------------------------------- 1 | import { Parameters } from '@storybook/react'; 2 | import '../src/styles.scss'; 3 | 4 | export const parameters: Parameters = { 5 | actions: { argTypesRegex: '^on[A-Z].*' }, 6 | layout: 'padded', 7 | options: { 8 | storySort: (a, b) => 9 | a[1].kind === b[1].kind 10 | ? 0 11 | : a[1].id.localeCompare(b[1].id, undefined, { numeric: true }), 12 | }, 13 | }; 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 📦 React Component Library Startup Files 2 | 3 | ## `🎉Rollup - TS - Jest - React Testing Library - SCSS 🎉` 4 | 5 | 6 | |Scripts 💻 | npm run ... | 7 | |---------------------------|--| 8 | | Setup *first time only*| setup| 9 | | Development | dev | 10 | | Storybook | storybook| 11 | | Production | build | 12 | | Testing | test:watch| 13 | 14 | 15 | **If setup didn't go well, Insatll dependencies manually** 16 | 17 | 18 | 19 | 1. npm i 20 | 2. npm run build 21 | 3. cd example 22 | 4. npm i 23 | -------------------------------------------------------------------------------- /example/.env: -------------------------------------------------------------------------------- 1 | SKIP_PREFLIGHT_CHECK=true -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `yarn build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "react": "^17.0.2", 10 | "react-component-lib": "file:..", 11 | "react-dom": "^17.0.2", 12 | "react-scripts": "4.0.3", 13 | "web-vitals": "^1.0.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MomenSherif/react-lib-boilerplate/deac78421bd5248a5a62be25f0e28b42fd67216e/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /example/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MomenSherif/react-lib-boilerplate/deac78421bd5248a5a62be25f0e28b42fd67216e/example/public/logo192.png -------------------------------------------------------------------------------- /example/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MomenSherif/react-lib-boilerplate/deac78421bd5248a5a62be25f0e28b42fd67216e/example/public/logo512.png -------------------------------------------------------------------------------- /example/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /example/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /example/src/App.js: -------------------------------------------------------------------------------- 1 | import { TestComponent } from "react-component-lib"; 2 | function App() { 3 | return ( 4 |
5 |
6 |

Hello From Mo'men 🐱‍👤

7 |

8 | 9 | Github Repo 10 | 11 | ⭐ will be appreciated ❤ 12 |

13 |
14 | 15 |
16 | ); 17 | } 18 | 19 | export default App; 20 | -------------------------------------------------------------------------------- /example/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from "@testing-library/react"; 2 | import App from "./App"; 3 | 4 | test("renders learn react link", () => { 5 | render(); 6 | }); 7 | -------------------------------------------------------------------------------- /example/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "react-component-lib/dist/styles.css"; 4 | import App from "./App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById("root") 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /example/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /example/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | roots: ['./src'], 3 | setupFilesAfterEnv: ['./jest.setup.ts'], 4 | moduleFileExtensions: ['ts', 'tsx', 'js'], 5 | testPathIgnorePatterns: ['node_modules/'], 6 | transform: { 7 | '^.+\\.tsx?$': 'ts-jest', 8 | }, 9 | testMatch: ['**/*.test.(ts|tsx)'], 10 | moduleNameMapper: { 11 | // Mocks out all these file formats when tests are run 12 | '\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': 13 | 'identity-obj-proxy', 14 | '\\.(css|less|scss|sass)$': 'identity-obj-proxy', 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /jest.setup.ts: -------------------------------------------------------------------------------- 1 | import '@testing-library/jest-dom'; 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-component-lib", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "dist/index.js", 6 | "module": "dist/index.js", 7 | "style": "dist/styles.scss", 8 | "files": [ 9 | "dist" 10 | ], 11 | "sideEffects": false, 12 | "scripts": { 13 | "setup": "npm i && npm run build && cd example && npm i", 14 | "dev": "concurrently \" npm run watch \" \" npm run start --prefix example \" ", 15 | "prebuild": "rm -rf dist", 16 | "build": "rollup -c", 17 | "watch": "rollup -c -w", 18 | "test": "jest", 19 | "test:watch": "jest --watch", 20 | "storybook": "start-storybook -p 6006", 21 | "build:storybook": "build-storybook", 22 | "lint:fix": "eslint . --fix" 23 | }, 24 | "author": "Momen Sherif", 25 | "license": "ISC", 26 | "devDependencies": { 27 | "@babel/core": "^7.13.10", 28 | "@rollup/plugin-commonjs": "^17.1.0", 29 | "@rollup/plugin-node-resolve": "^11.2.0", 30 | "@storybook/addon-actions": "^6.1.21", 31 | "@storybook/addon-essentials": "^6.1.21", 32 | "@storybook/addon-links": "^6.1.21", 33 | "@storybook/react": "^6.1.21", 34 | "@testing-library/jest-dom": "^5.11.9", 35 | "@testing-library/react": "^11.2.5", 36 | "@testing-library/user-event": "^13.0.7", 37 | "@types/jest": "^26.0.21", 38 | "@types/react": "^17.0.3", 39 | "@typescript-eslint/eslint-plugin": "^4.18.0", 40 | "@typescript-eslint/parser": "^4.18.0", 41 | "autoprefixer": "^10.2.5", 42 | "babel-loader": "^8.2.2", 43 | "babel-preset-react-app": "^10.0.0", 44 | "concurrently": "^6.0.0", 45 | "css-loader": "^5.1.3", 46 | "cssnano": "^4.1.10", 47 | "eslint": "^7.22.0", 48 | "eslint-config-airbnb": "^18.2.1", 49 | "eslint-plugin-import": "^2.22.1", 50 | "eslint-plugin-jsx-a11y": "^6.4.1", 51 | "eslint-plugin-react": "^7.22.0", 52 | "eslint-plugin-react-hooks": "^4.2.0", 53 | "identity-obj-proxy": "^3.0.0", 54 | "jest": "^26.6.3", 55 | "node-sass": "^5.0.0", 56 | "postcss": "^8.2.8", 57 | "react": "^17.0.1", 58 | "react-dom": "^17.0.1", 59 | "rollup": "^2.42.1", 60 | "rollup-plugin-copy": "^3.4.0", 61 | "rollup-plugin-multi-input": "^1.2.0", 62 | "rollup-plugin-peer-deps-external": "^2.2.4", 63 | "rollup-plugin-postcss": "^4.0.0", 64 | "rollup-plugin-terser": "^7.0.2", 65 | "rollup-plugin-typescript2": "^0.30.0", 66 | "sass-loader": "^10.1.1", 67 | "storybook-css-modules-preset": "^1.0.7", 68 | "style-loader": "^2.0.0", 69 | "ts-jest": "^26.5.4", 70 | "typescript": "^4.2.3" 71 | }, 72 | "peerDependencies": { 73 | "react": ">=16.8.0", 74 | "react-dom": ">=16.8.0" 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import peerDepsExternal from 'rollup-plugin-peer-deps-external'; 2 | import multiInput from 'rollup-plugin-multi-input'; 3 | import resolve from '@rollup/plugin-node-resolve'; 4 | import commonjs from '@rollup/plugin-commonjs'; 5 | import typescript from 'rollup-plugin-typescript2'; 6 | import { terser } from 'rollup-plugin-terser'; 7 | import postcss from 'rollup-plugin-postcss'; 8 | import autoprefixer from 'autoprefixer'; 9 | import cssnano from 'cssnano'; 10 | import copy from 'rollup-plugin-copy'; 11 | 12 | export default [ 13 | { 14 | input: [ 15 | 'src/components/**/*.tsx', 16 | 'src/components/**/index.ts', 17 | '!src/components/**/*.test.tsx', 18 | '!src/components/**/*.stories.tsx', 19 | ], 20 | output: [ 21 | { 22 | dir: 'dist', 23 | format: 'esm', 24 | sourcemap: true, 25 | }, 26 | ], 27 | plugins: [ 28 | multiInput({ 29 | relative: 'src/components', 30 | }), 31 | peerDepsExternal(), 32 | resolve(), 33 | commonjs(), 34 | postcss({ 35 | modules: true, 36 | plugins: [autoprefixer(), cssnano()], 37 | }), 38 | typescript({ 39 | useTsconfigDeclarationDir: true, 40 | }), 41 | terser(), 42 | ], 43 | }, 44 | { 45 | input: 'src/styles.scss', 46 | output: { 47 | file: 'dist/styles.css', 48 | }, 49 | plugins: [ 50 | postcss({ 51 | extract: true, 52 | plugins: [autoprefixer(), cssnano()], 53 | }), 54 | copy({ 55 | targets: [ 56 | { 57 | src: ['src/_variables.scss'], 58 | dest: 'dist', 59 | }, 60 | ], 61 | }), 62 | ], 63 | }, 64 | ]; 65 | -------------------------------------------------------------------------------- /src/_normalize.scss: -------------------------------------------------------------------------------- 1 | /** 2 | * Minified by jsDelivr using clean-css v4.2.3. 3 | * Original file: /npm/modern-normalize@1.0.0/modern-normalize.css 4 | * 5 | * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files 6 | */ 7 | /*! modern-normalize v1.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ 8 | *, 9 | ::after, 10 | ::before { 11 | box-sizing: border-box; 12 | } 13 | :root { 14 | -moz-tab-size: 4; 15 | tab-size: 4; 16 | } 17 | html { 18 | line-height: 1.15; 19 | -webkit-text-size-adjust: 100%; 20 | } 21 | body { 22 | margin: 0; 23 | } 24 | body { 25 | font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, 26 | sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji'; 27 | } 28 | hr { 29 | height: 0; 30 | color: inherit; 31 | } 32 | abbr[title] { 33 | text-decoration: underline dotted; 34 | } 35 | b, 36 | strong { 37 | font-weight: bolder; 38 | } 39 | code, 40 | kbd, 41 | pre, 42 | samp { 43 | font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, 44 | monospace; 45 | font-size: 1em; 46 | } 47 | small { 48 | font-size: 80%; 49 | } 50 | sub, 51 | sup { 52 | font-size: 75%; 53 | line-height: 0; 54 | position: relative; 55 | vertical-align: baseline; 56 | } 57 | sub { 58 | bottom: -0.25em; 59 | } 60 | sup { 61 | top: -0.5em; 62 | } 63 | table { 64 | text-indent: 0; 65 | border-color: inherit; 66 | } 67 | button, 68 | input, 69 | optgroup, 70 | select, 71 | textarea { 72 | font-family: inherit; 73 | font-size: 100%; 74 | line-height: 1.15; 75 | margin: 0; 76 | } 77 | button, 78 | select { 79 | text-transform: none; 80 | } 81 | [type='button'], 82 | [type='reset'], 83 | [type='submit'], 84 | button { 85 | -webkit-appearance: button; 86 | } 87 | ::-moz-focus-inner { 88 | border-style: none; 89 | padding: 0; 90 | } 91 | :-moz-focusring { 92 | outline: 1px dotted ButtonText; 93 | } 94 | :-moz-ui-invalid { 95 | box-shadow: none; 96 | } 97 | legend { 98 | padding: 0; 99 | } 100 | progress { 101 | vertical-align: baseline; 102 | } 103 | ::-webkit-inner-spin-button, 104 | ::-webkit-outer-spin-button { 105 | height: auto; 106 | } 107 | [type='search'] { 108 | -webkit-appearance: textfield; 109 | outline-offset: -2px; 110 | } 111 | ::-webkit-search-decoration { 112 | -webkit-appearance: none; 113 | } 114 | ::-webkit-file-upload-button { 115 | -webkit-appearance: button; 116 | font: inherit; 117 | } 118 | summary { 119 | display: list-item; 120 | } 121 | /*# sourceMappingURL=/sm/3c8a72540b353e8066a63580fff1b7fbff35925789e51ac52bb6794c81144ab3.map */ 122 | -------------------------------------------------------------------------------- /src/_variables.scss: -------------------------------------------------------------------------------- 1 | $primary: goldenrod; 2 | -------------------------------------------------------------------------------- /src/components/Button/Button.module.scss: -------------------------------------------------------------------------------- 1 | .button { 2 | all: unset; 3 | display: inline-block; 4 | padding: 10px 20px; 5 | background-color: goldenrod; 6 | color: white; 7 | 8 | &.secondary { 9 | background-color: blue; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/components/Button/Button.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Story, Meta } from '@storybook/react'; 3 | 4 | import Button from '.'; 5 | import { ButtonProps } from './Button.types'; 6 | 7 | export default { 8 | title: 'Button', 9 | component: Button, 10 | } as Meta; 11 | 12 | const Template: Story = (args) => , 14 | ); 15 | const button = screen.getByRole('button', { name: /click me/i }); 16 | userEvent.click(button); 17 | expect(mockedFn).toBeCalledTimes(1); 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /src/components/Button/Button.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import { ButtonProps } from './Button.types'; 4 | import styles from './Button.module.scss'; 5 | 6 | // * Storybook can not catch default export types 7 | export const Button: React.FC = ({ 8 | variant, children, className, ...rest 9 | }) => ( 10 | 17 | ); 18 | -------------------------------------------------------------------------------- /src/components/Button/Button.types.ts: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export type ButtonProps = { 4 | variant: 'primary' | 'secondary'; 5 | children?: React.ReactNode; 6 | type: 'button' | 'submit' | 'reset'; 7 | } & React.HTMLProps; 8 | -------------------------------------------------------------------------------- /src/components/Button/index.ts: -------------------------------------------------------------------------------- 1 | export { Button as default } from './Button'; 2 | -------------------------------------------------------------------------------- /src/components/TestComponent/TestCompoenent.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import { TestComponentProps } from './TestComponent.types'; 4 | import styles from './TestComponent.module.scss'; 5 | 6 | // * Storybook can no't catch default export types 7 | export const TestComponent: React.FC = ({ theme, children }) => ( 8 |
12 |

Test Component 😢

13 | {children} 14 |
15 | ); 16 | -------------------------------------------------------------------------------- /src/components/TestComponent/TestComponent.module.scss: -------------------------------------------------------------------------------- 1 | .test-component { 2 | background-color: white; 3 | border: 1px solid black; 4 | padding: 16px; 5 | width: 360px; 6 | text-align: center; 7 | 8 | &.test-component-secondary { 9 | background-color: black; 10 | color: white; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/components/TestComponent/TestComponent.stories.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Story, Meta } from '@storybook/react'; 3 | 4 | import TestComponent from '.'; 5 | import { TestComponentProps } from './TestComponent.types'; 6 | 7 | export default { 8 | title: 'TestComponent', 9 | component: TestComponent, 10 | } as Meta; 11 | 12 | const Template: Story = (args) => ; 13 | 14 | export const Default = Template.bind({}) as Story; 15 | Default.args = { 16 | theme: 'primary', 17 | }; 18 | 19 | export const Secondary = Template.bind({}); 20 | Secondary.args = { 21 | theme: 'secondary', 22 | children: 'Mama', 23 | }; 24 | -------------------------------------------------------------------------------- /src/components/TestComponent/TestComponent.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | 4 | import TestComponent from '.'; 5 | 6 | describe('', () => { 7 | it('should have primary className with default props', () => { 8 | render(); 9 | const testComponent = screen.getByTestId('test-component'); 10 | expect(testComponent).toHaveClass('test-component-primary'); 11 | }); 12 | 13 | it('should have secondary className with theme set as secondary', () => { 14 | render(); 15 | const testComponent = screen.getByTestId('test-component'); 16 | expect(testComponent).toHaveClass('test-component-secondary'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /src/components/TestComponent/TestComponent.types.ts: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | export type TestComponentProps = { 4 | /** 5 | * Theme colors 6 | */ 7 | theme: 'primary' | 'secondary'; 8 | children?: React.ReactNode; 9 | }; 10 | -------------------------------------------------------------------------------- /src/components/TestComponent/index.ts: -------------------------------------------------------------------------------- 1 | export { TestComponent as default } from './TestCompoenent'; 2 | -------------------------------------------------------------------------------- /src/components/index.ts: -------------------------------------------------------------------------------- 1 | export { default as TestComponent } from './TestComponent'; 2 | export { default as Button } from './Button'; 3 | -------------------------------------------------------------------------------- /src/declarations.d.ts: -------------------------------------------------------------------------------- 1 | declare module '*.scss' { 2 | const content: { [className: string]: string }; 3 | export = content; 4 | } 5 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | @import './variables'; 2 | @import './normalize'; 3 | 4 | html { 5 | font-size: 62.5%; 6 | } 7 | 8 | body { 9 | font-size: 1.6rem; 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "declarationDir": "dist", 5 | "module": "esnext", 6 | "target": "es5", 7 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 8 | "jsx": "react", 9 | "moduleResolution": "node", 10 | "allowSyntheticDefaultImports": true, 11 | "esModuleInterop": true, 12 | "noImplicitReturns": true, 13 | "noUnusedParameters": true, 14 | "resolveJsonModule": true, 15 | "skipLibCheck": true 16 | }, 17 | "include": ["src/**/*"], 18 | "exclude": [ 19 | "node_modules", 20 | "build", 21 | "src/**/*.stories.tsx", 22 | "src/**/*.test.tsx", 23 | "src/utils" 24 | ] 25 | } 26 | --------------------------------------------------------------------------------