npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@markoarthofer22/react-components.dialog

v1.7.0

Published

The React-Components is library that contains various components intended for reusing on another projects.

Downloads

6

Readme

About The Project lerna

Coverage Status npm Bundlephobia minified size

Basic structure:

  • Collection of components written in ReactJS
  • Monorepo created with Lerna
  • Using StroyBook lib for presentation
  • Function based React, knowledge of Hooks is required
  • Normalize from Infinum :heart:
  • Typescript for typing. AirBnb convention
  • All components made from scratch
  • Using linter and prettier for code consistency
  • Using react-icons lib for icons (default in project is Material)

Built With

Getting Started

First, to discuss structure and typing in the app.

  • inside component folder you should have 2 files
    • .component (*.component.tsx) and Storybook for showing component (*.stories.tsx)
    • stylings go to scss folder (name it after component and import inside App.scss) => legacy
    • Changed from css to JSS (emotion)
    • stylings now go to styles.ts, styles are now scoped to component
  • use npm run build to create build for testing (build process in run trough GitHub Actions)
  • use npm run lint to run linter with --fix param
  • use npm run prettier to run prettier

Development

When running this, first install required node version using nvm install - if you dont have nvm install it using npm or brew

All commands can be run from individual packages, but it is not necessary to do so.

  • Run npm run prepare:local at the project root to install the dev dependencies and link them to each other.

On some systems, npx lerna bootstrap may fail with an error Unexpected end of JSON input while parsing near '...-imports":"^7.7.0","@' - in this case, try running npm cache clean --force

To run storybook locally npm start.

To add a new element, copy the template to the src/elements directory, update the package.json with the name and add your source code.

Styling

~~For .scss files please use BEM convention. This keeps it readable, neat and understandable to other devs :smile:~~

For styling we now use JSS (emotion). Each style is scoped to its own component.

Global styles are added to themes folder, where you can find <GlobalThemeProvider/> component. Variables are inside theme/styles.js

Important

Every component and model has className prop which you can add. This prop will rename base of every class inside component.

If you set className to "select-new" output will be as follows (select component):

<div
    // default is 'select'
    css={SelectStyles(theme)}
    className='select-new'
    ref={mainInput}
>
    <div
        className={`select-new--header ${
            isOpen ? `select-new--header-open` : ''
        } `}
        onClick={(e) => {
            toggleDropdown(e);
        }}
    >
        ...
    </div>
</div>

What is BEM?

According to creator definition of BEM is as follows:

"BEM is a highly useful, powerful, and simple naming convention that makes your front-end code easier to read and understand, easier to work with, easier to scale, more robust and explicit, and a lot more strict."

BEM structure

.block {
    //usually a wrapper that containes component
    position: relative;
    width: 100%;

    &--element {
        //this is how we define element inside of a block
        opacity: 0;

        &-modifier {
            opacity: 1;
            //modifier, such as "open", "disabled" ect
        }
    }
}

Example of BEM usage

.select {
    position: relative;
    width: 100%;

    &--header {
        position: relative;
        cursor: pointer;

        svg {
            fill: theme.colors.black;
            transform: rotateX(0deg);
            transition: all 0.4s ease;
        }

        &-open {
            svg {
                transform: rotateX(180deg);
                fill: theme.colors.blue;
            }
        }
    }
}

Typings

For Typescript types use interfaces. Respect naming convention. All of your interfaces should start with a capital "I". Also, if you are creating interface for component props they should end with "Props". Use T for type, E for enums etc...

Good Example

interface IComponentProps {
    propOne: string,
    propTwo: number
    ...
}

Linter and prettier

Prettier uses common rules to keep indent and other structural features clean. More on Prettier package

Linter is used for enforcing code style. Here we use lightly modified Airb'n'b convention with @typescript-eslint rules

Component writing

All of the components/models/pages are typed, so use .tsx extension when adding new. Also we enforce functional coding.

Here is a good example of how to add a new component/model/page

    // dont forget to add, so you can use emotion css prop
    /** @jsxImportSource @emotion/react */
    // import packages
    import * as React from "react";
    import { useTheme } from "emotion"

    import { stylesObj } from "./styles"

    // define prop types
    interface IComponentProps {
        propOne: string,
        propTwo: number
    }

    // add named export for storybook support (for args table)
    export const Component: React.FC<IComponentProps> = (props): JSX.Element => {
        // define theme hook
        const theme = useTheme()

        // define your state
        const [stateObj, setStateObj] = useState<type T>(initial value)

        // define your const
        const a = val

        // define functions
        const function = (): returnType | any | void => {
            // do something
        }

        // add lifecycle hook
        React.useEffect(()=>{
            // do something
        },[])

        return <div>Some markup</div>
    }

    export default Component

Precommiting

We use Husky for precommit, so you don't need to worry about your code before review

Installation

  1. Clone the repo
    https://github.com/markoarthofer22/react-components
  2. Install NPM packages and link all
    npm run prepare:local

Install lib from NPM

npm i @markoarthofer22/react-components

Storybook

The project includes a Storybook for developing and testing components in isolation.

To add a story for your component create a sandbox.stories.tsx file. You can create file in stories/ folder in a root of a package.

~~Additionaly you can add knobs (more on knobs) for adding props trough storybook UI.~~

~~You can also manually add stories using the Storybook storiesOf API.~~

THIS IS DEPRECATED

After updating to Storybook 6.4 we are using controls API and args API

For easier development and maintenance you must add development.mdx file where you will describe your component. For templating you can copy stories and docs from other packages! SEE DOCS and MDX USAGE

Usage

For starting Storybook on your localhost use

    npm start

List of components

These are some of the components that we have in mind. Will be populated over time with new ones. :smile:

Components

  1. Buttons :white_check_mark:
  2. Breadcrumbs :white_check_mark:
  3. Dropdown :white_check_mark:
  4. Input (default, phone, checkbox, radio) :white_check_mark:
  5. Global loader - removed
  6. Popup :white_check_mark:
  7. Select :white_check_mark:
  8. Tooltip :white_check_mark:
  9. Alerts Box/Bar :white_check_mark:
  10. Slider Bar :white_check_mark:
  11. Switch Button :white_check_mark:
  12. Avatar :white_check_mark:
  13. Badges :white_check_mark:
  14. Google Analyitcs Wrapper :white_check_mark:
  15. Hamburger :white_check_mark:
  16. Jump to top :white_check_mark:
  17. Input (quantity) :white_check_mark:
  18. Modal :white_check_mark:
  19. Table - In planning
  20. Grid :white_check_mark:
  21. Masonry layout :white_check_mark:
  22. SweetAlert Wrapper :white_check_mark:
  23. Helmet Wrapper :white_check_mark:

Models

  1. Dialog :white_check_mark:
  2. Hero Box - removed
  3. Notification Box :white_check_mark:
  4. Swiper - removed
  5. Container - added as <Grid/>
  6. List & ListItem :white_check_mark:
  7. Social Network Cards (facebook | instagram | custom) - removed
  8. Accordion :white_check_mark:
  9. Share Socials - In planning
  10. Side Navigation :white_check_mark:

Publishing

Do not do this until you are ready to merge and your PR has been approved! Justification below.

To preview which packages have changed, you can run npx lerna changed without publishing.

Once happy with the code changes, run npx lerna version and bump the versions accordingly.

If you have created new component there is no need to run npx lerna version. Publish under version 1.0.0

Lerna will generate a publish commit. Push that commit to your remote branch and once it gets merged to master, CI will publish the new versions to npm.

Build test

If you want to build locally just run npm run build for package, and npm run build:bundle to create a whole lib

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Marko Arthofer - GIT

Project Link: https://github.com/markoarthofer22/react-components

Acknowledgements