Skip to content

Commit

Permalink
Update generators
Browse files Browse the repository at this point in the history
Better reflects the patterns currently used

See #81
  • Loading branch information
stuarthendren committed May 25, 2021
1 parent 0dab0a4 commit 5e027df
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
41 changes: 29 additions & 12 deletions generators/Component.hbs
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import React from 'react'
import { styled } from 'stitches.config'
import * as Polymorphic from '@radix-ui/react-polymorphic'
import React, { forwardRef } from 'react'
import { CSS, StitchesVariants, styled } from 'stitches.config'

const DEFAULT_TAG = 'div'

/**
* {{ name }} component
*/
export const Styled{{ name }} = styled('div', {})
* Styled{{ name }} base component
*/
const Styled{{ name }} = styled(DEFAULT_TAG, {})


type Styled{{ name }}Props = React.ComponentProps<typeof Styled{{ name }}>
export type {{ name }}Props = Styled{{ name }}Props & {}


export const {{ name }}: React.FC<{{ name }}Props> = Styled{{ name }}
{{ name }}.toString = () => `.${Styled{{ name }}.className}`
// Either export the component above directly removing the Styled prefix.
// Or if polymorphism is required or further action on the bases component uncomment below.
//
// type {{ name }}CSSProp = { css?: CSS }
// type {{ name }}Variants = StitchesVariants<typeof Styled{{ name }}>
// type {{ name }}OwnProps = {{ name }}CSSProp & {{ name }}Variants
//
// type {{ name }}Component = Polymorphic.ForwardRefComponent<
// typeof DEFAULT_TAG,
// {{ name }}OwnProps
// >
//
// /**
// * {{ name }} component
// */
// export const {{ name }} = forwardRef(({ ...props }, ref) => (
// <Styled{{ name }}
// ref={ref}
// {...props}
// />
// )) as {{ name }}Component
// {{ name }} .toString = () => `.${Styled{{ name }}.className}`
19 changes: 9 additions & 10 deletions generators/Component.stories.hbs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import React from 'react'
import { Story, Meta } from '@storybook/react'
import { {{ name }}, {{ name }}Props } from '.'
import { {{ name }} } from '.'

export default {
title: 'Components/{{ name }}',
component: {{ name }},
} as Meta

export const Default: React.FC = () => {
return
<{{ name }} />
}
export const Default: Story = (args) => <{{ name }} {...args} />

const Template: Story<{{ name }}Props> = (args) =>
<{{ name }} {...args} />
// Use for Template args setup
// const Template: Story = (args) => <{{ name }} {...args} />
// export const Primary = Template.bind({})
// Primary.args = {
// }

export const Primary = Template.bind({})
Primary.args = {
}
// Use for separate stories
// export const Simple: React.FC = () => <{{ name }} />
1 change: 0 additions & 1 deletion generators/Component.test.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { renderLight, renderDark } from 'test-utils'
import { Default } from './{{ name }}.stories'
import { {{ name }} } from '.'

it('renders light without error', () => {
const { asFragment } = renderLight(<Default />)
Expand Down

0 comments on commit 5e027df

Please sign in to comment.