2.0.10 • Published 10 months ago

snap-component v2.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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 NameLanguage (TS/JS)TestCSS Framework (CSS/Styled-components)Storybook
headingbothonly JestStyled-componentsYes
tooltipbothonly JestbothYes

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.

2.0.10

10 months ago

2.0.9

10 months ago

2.0.8

10 months ago

2.0.7

10 months ago

2.0.6

10 months ago

2.0.5

10 months ago

2.0.4

10 months ago

2.0.3

10 months ago

2.0.2

10 months ago

2.0.1

10 months ago

2.0.0

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago