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

snap-component

v2.0.10

Published

CLI tool designed to streamline the creation of React components with full support for TypeScript, styled-components, Storybook, and Jest. It automates the setup of component files, including the component logic, styles, tests, and stories, allowing devel

Downloads

1,243

Readme

WARNING

This package is under development and may have unresolved issues. Please be aware that it might not be fully stable yet.

Snap Component

Snap component is a CLI tool to quicly create react's components with support to styles, storybook and tests. This package is thinked to your quaility of life while creating components

Instalation

npm i -D snap-component

or

pnpm i -D snap-component

Requeriments

Before using snap component, you must set up a snap-component.config.json file in the root of your project

{
    "language": "ts",
    "outputDir": "src/components",
    "cssFramework": "styled-components",
    "test": "jest",
    "useStorybook": true
}

Configuration

  • language: Choose the language (e.g,'ts','js').
  • outputDir: Defines the directory where the component's generated source code and associated files will be placed after creation.(default :src/components)
  • cssFramework: Choose the CSS framework (e.g., styled-components,css).
  • test: framework for test. for now, only jest is availible
  • useStorybook: Enables or disables the creation of Storybook files.

Usage

First of all, add the script to your package.json

{ "snap-component": "snap-component snap-component" }

Using npm

npm run snap-component ~componentName~

Using pnpm

pnpm snap-component  ~componentName~

Directory Structure Created

  • src/components/<component-name>/
    • index.tsx - The main component file.
    • index.stories.tsx - Storybook story file.
    • styles.ts - Styles file.
    • index.test.tsx - Unit tests file.

Output Generic Files Created

React Component

'use client'

import * as Styled from './styles'

export type SnapComponentProps = {
  name: string,
}

export const SnapComponent = ({ name }: SnapComponentProps) => {
  return <Styled.Wrapper>{name}</Styled.Wrapper>
}

Storybook Component


import type { Meta, StoryObj } from '@storybook/react'
import { SnapComponent } from '.'

const meta = {
  title: 'Component/SnapComponent',
  component: SnapComponent,
  parameters: {
    layout: 'centered',
  },
  tags: ['autodocs'],
  argTypes: {
    name: {
      control: 'text',
      description: 'description',
    },
  },
} satisfies Meta<typeof snap-component>

export default meta

type Story = StoryObj<typeof meta>

export const Default: Story = {
  args: { name: 'preset-story' },
}

Test Component


import { render } from '@testing-library/react'
import { snapComponent } from '.'

describe('snap-component', () => {
  it('should render the snap-component', () => {
    const { getByText } = render(<SnapComponent  name={'test'}/>)

    const component = getByText('test')

    expect(component).toBeInTheDocument()
  })
})

Styled Component

'use client'

import styled, { css } from 'styled-components'

export const Wrapper = styled.div`
    ${({ theme }) => css``}
`

Especific Component

This command will generate a well-designed heading with:

Tests: Comprehensive Jest tests. Styles: Styled-components for consistent and modular styling. Props: Specific props tailored for this component.

| Component Name | Language (TS/JS) | Test | CSS Framework (CSS/Styled-components) | Storybook | | -------------- | ---------------- | --------- | ------------------------------------- | --------- | | heading | both | only Jest | Styled-components | Yes | | tooltip | both | only Jest | both | Yes |

example

pnpm snap-component <one of the component name listed above>

Contribution

If you would like to contribute to Snap Component, feel free to fork the repository and submit pull requests. All contributions are welcome

LICENSE

This project is licensed under the MIT License. See the LICENSE file for details.