Giter Site home page Giter Site logo

timonwa / demo-ui-library Goto Github PK

View Code? Open in Web Editor NEW
35.0 1.0 20.0 348 KB

A demo on how to create a React UI component library using React, Typescript, Rollup, Storybook, Jest and React testing library.

License: MIT License

TypeScript 51.16% JavaScript 48.84%
turorial article react-lib ui-library beginner-friendly beginner-project component-library demo

demo-ui-library's Introduction

My Demo UI Library

This is a demo UI component library created using React, TypeScript, Rollup, Storybook, Jest, and React Testing Library. It was created for an article update for LogRocket on how to create a UI component library in React. You can read the article here.

Visit my blog, Timonwa's Notes, for awesome technical contents like articles, code snippets, tech goodies, community projects and more.

Installation

You can install this demo UI library using npm:

npm install @timonwa/demo-ui-library

Usage

To use this demo UI library in your project, import the components you need from the library and use them in your React components.

import React from "react";
import { Input, Button } from "@timonwa/demo-ui-library";

function App() {
  return (
    <div>
      <Input
        id="name"
        disabled={false}
        label="Enter your name"
        message="This field is required"
        error={false}
        success={false}
        onChange={(e) => console.log(e.target.value)}
        placeholder="Enter your name here"
      />
      <Button
        size="medium"
        primary={true}
        disabled={false}
        text="Click me!"
        onClick={() => alert("Button clicked!")}
      />
    </div>
  );
}

export default App;

Contributing

This library is a demo for learning purposes only and is not intended to be contributed to. You can fork the repository and use the code for your personal use or learning.

Steps

  • Fork the repository.
  • Clone the repository to your local machine.
  • Install the dependencies using npm install.
  • View the components in the browser using npm run storybook.
  • Make your changes.
  • Test the changes using npm test.
  • Build the library using npm run build.
  • Commit the changes and push them to your forked repository.
  • Publish the package on npm.
  • Install and use the package in your project.

License

This demo UI library is licensed under the MIT License.

Connect

More of my articles can be found in Timonwa's Notes. Connect with me on Twitter: @timonwa_

demo-ui-library's People

Contributors

code-forger avatar timonwa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

demo-ui-library's Issues

Import not wroking

When I try to import, it is not working, giving type missing error and event exported types are not present

Why is `react` not a dev dependency?

Thanks for sharing this template and the accompanying article.

Could you dive into a little bit more detail about why react is only a peer dependency, and not a dev dependency, too?

https://github.com/Timonwa/demo-ui-library/blob/main/package.json#L62-L65

It looks like React is imported in the actual code - doesn't this mean that it should be a dev dependency?

import React from "react";

Based on this StackOverflow answer, I would be inclined to believe that react should be added in devDependencies.

Side note: would you like to enable GitHub Discussions in this repository? I would have created a discussion instead of a repo.

Webpack Failed to build the preview

ISSUE: Storybook complained about the version been outdated, i ran npx storybook upgrade command to update all storybook dependency to latest, which was successful

ERROR: After successful upgrade i ran npm run storybook to start storybook and preview my components following your example, i ran into this error linking to @storybook\builder-webpack5

PACKAGE JSON:

"dependencies": {
    "prop-types": "^15.8.1",
    "styled-components": "^5.3.10"
  },
  "devDependencies": {
    "@babel/preset-env": "^7.21.5",
    "@babel/preset-react": "^7.18.6",
    "@babel/preset-typescript": "^7.21.5",
    "@rollup/plugin-commonjs": "^24.1.0",
    "@rollup/plugin-node-resolve": "^15.0.2",
    "@rollup/plugin-terser": "^0.4.4",
    "@rollup/plugin-typescript": "^11.1.0",
    "@storybook/addon-essentials": "7.6.0",
    "@storybook/addon-interactions": "7.6.0",
    "@storybook/addon-links": "7.6.0",
    "@storybook/blocks": "7.6.0",
    "@storybook/react": "7.6.0",
    "@storybook/react-webpack5": "7.6.0",
    "@storybook/testing-library": "0.2.2",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^14.0.0",
    "@testing-library/user-event": "^14.4.3",
    "@types/jest": "^29.5.1",
    "@types/react": "^18.2.2",
    "@types/styled-components": "^5.1.26",
    "jest": "^29.5.0",
    "jest-environment-jsdom": "^29.5.0",
    "rollup": "^3.0.0",
    "rollup-plugin-dts": "^5.3.0",
    "rollup-plugin-peer-deps-external": "^2.2.4",
    "storybook": "7.6.0",
    "typescript": "^5.0.4"
  },
  "peerDependencies": {
    "react": "^18.2.0",
    "react-dom": "18.2.0"
  }


#



ERROR LOG : 
 
 @dom000/[email protected] storybook
 storybook dev -p 6006

@storybook/cli v7.6.0

info => Starting manager..
WARN No story files found for the specified pattern: src\**\*.mdx
info => Starting preview..
info Using Babel compiler
info Addon-docs: using MDX2
info => Using implicit CSS loaders
info => Using default Webpack5 setup
 [webpack-dev-middleware] wait until bundle finished
 [webpack-dev-middleware] wait until bundle finished: /__webpack_hmr
ERROR in ./node_modules/markdown-to-jsx/dist/index.modern.js
Module build failed (from ./node_modules/@storybook/preset-react-webpack/dist/loaders/react-docgen-loader.js):
TypeError: Attempted to resolveName for an unsupported path. resolveName does not accept ObjectMethod".
    at resolveName (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\utils\getMemberExpressionValuePath.js:72:9)  
    at getMemberExpressionValuePath (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\utils\getMemberExpressionValuePath.js:91:21)
    at getMemberValuePath (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\utils\getMemberValuePath.js:95:62)    
    at resolveToValue (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\utils\resolveToValue.js:139:66)
    at isReactBuiltinReference (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\utils\isReactBuiltinReference.js:61:51)
    at isReactBuiltinCall (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\utils\isReactBuiltinCall.js:41:53)    
    at Object.enter (C:\Users\hp\Desktop\demo-ui-library\node_modules\react-docgen\dist\handlers\componentMethodsHandler.js:74:48)  
    at NodePath._call (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:46:20)
    at NodePath.call (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:36:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:82:31)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitSingle (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:65:19)
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:109:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitMultiple (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:61:17)       
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:107:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitMultiple (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:61:17)       
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:107:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitSingle (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:65:19)
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:109:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitMultiple (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:61:17)       
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:107:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitSingle (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:65:19)
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:109:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitMultiple (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:61:17)       
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:107:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
    at TraversalContext.visitQueue (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:86:16)
    at TraversalContext.visitSingle (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:65:19)
    at TraversalContext.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\context.js:109:19)
    at traverseNode (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\traverse-node.js:22:17)
    at NodePath.visit (C:\Users\hp\Desktop\demo-ui-library\node_modules\@babel\traverse\lib\path\context.js:88:52)
 @ ./node_modules/@storybook/blocks/dist/index.mjs 10:0-39 41:6440-6448 101:38-46
 @ ./node_modules/@storybook/addon-docs/dist/chunk-HLWAVYOI.mjs 3:0-81 5:28-43 5:46-55 5:59-69 5:583-587
 @ ./node_modules/@storybook/addon-docs/dist/DocsRenderer-NNNQARDV.mjs 1:0-71 1:0-71 1:0-71
 @ ./node_modules/@storybook/addon-docs/dist/preview.mjs 1:65-102
 @ ./node_modules/@storybook/addon-essentials/dist/docs/preview.js 1:0-51 1:0-51
 @ ./storybook-config-entry.js 9:349-467 33:2-36:4 33:1193-36:3

preview compiled with 1 error
=> Failed to build the preview
99% end closing watch compilationWARN Force closed preview build
SB_BUILDER-WEBPACK5_0003 (WebpackCompilationError): There were problems when compiling your code with Webpack.
Run Storybook with --debug-webpack for more information.
    at starter (.\node_modules\@storybook\builder-webpack5\dist\index.js:1:9660)
    at starter.next ()
    at Module.start (.\node_modules\@storybook\builder-webpack5\dist\index.js:1:11692)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async storybookDevServer (.\node_modules\@storybook\core-server\dist\index.js:66:2459)
    at async buildOrThrow (.\node_modules\@storybook\core-server\dist\index.js:60:8290)
    at async buildDevStandalone (.\node_modules\@storybook\core-server\dist\index.js:120:1397)
    at async withTelemetry (.\node_modules\@storybook\core-server\dist\index.js:65:3948)
    at async dev (.\node_modules\@storybook\cli\dist\generate.js:478:401)
    at async Command. (.\node_modules\@storybook\cli\dist\generate.js:493:225)

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

REPRODUCE ERROR STEPS :

  1. Clone repo, run npm i

  2. Storybooks complain about dependency conflict and outdated run npx storybook upgrade

  3. after successful upgrade run npm run storybook

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.