Skip to content

Commit 5e027df

Browse files
committed
Update generators
Better reflects the patterns currently used See #81
1 parent 0dab0a4 commit 5e027df

File tree

3 files changed

+38
-23
lines changed

3 files changed

+38
-23
lines changed

generators/Component.hbs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
1-
import React from 'react'
2-
import { styled } from 'stitches.config'
1+
import * as Polymorphic from '@radix-ui/react-polymorphic'
2+
import React, { forwardRef } from 'react'
3+
import { CSS, StitchesVariants, styled } from 'stitches.config'
34

5+
const DEFAULT_TAG = 'div'
46

57
/**
6-
* {{ name }} component
7-
*/
8-
export const Styled{{ name }} = styled('div', {})
8+
* Styled{{ name }} base component
9+
*/
10+
const Styled{{ name }} = styled(DEFAULT_TAG, {})
911

10-
11-
type Styled{{ name }}Props = React.ComponentProps<typeof Styled{{ name }}>
12-
export type {{ name }}Props = Styled{{ name }}Props & {}
13-
14-
15-
export const {{ name }}: React.FC<{{ name }}Props> = Styled{{ name }}
16-
{{ name }}.toString = () => `.${Styled{{ name }}.className}`
12+
// Either export the component above directly removing the Styled prefix.
13+
// Or if polymorphism is required or further action on the bases component uncomment below.
14+
//
15+
// type {{ name }}CSSProp = { css?: CSS }
16+
// type {{ name }}Variants = StitchesVariants<typeof Styled{{ name }}>
17+
// type {{ name }}OwnProps = {{ name }}CSSProp & {{ name }}Variants
18+
//
19+
// type {{ name }}Component = Polymorphic.ForwardRefComponent<
20+
// typeof DEFAULT_TAG,
21+
// {{ name }}OwnProps
22+
// >
23+
//
24+
// /**
25+
// * {{ name }} component
26+
// */
27+
// export const {{ name }} = forwardRef(({ ...props }, ref) => (
28+
// <Styled{{ name }}
29+
// ref={ref}
30+
// {...props}
31+
// />
32+
// )) as {{ name }}Component
33+
// {{ name }} .toString = () => `.${Styled{{ name }}.className}`

generators/Component.stories.hbs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import React from 'react'
22
import { Story, Meta } from '@storybook/react'
3-
import { {{ name }}, {{ name }}Props } from '.'
3+
import { {{ name }} } from '.'
44

55
export default {
66
title: 'Components/{{ name }}',
77
component: {{ name }},
88
} as Meta
99

10-
export const Default: React.FC = () => {
11-
return
12-
<{{ name }} />
13-
}
10+
export const Default: Story = (args) => <{{ name }} {...args} />
1411

15-
const Template: Story<{{ name }}Props> = (args) =>
16-
<{{ name }} {...args} />
12+
// Use for Template args setup
13+
// const Template: Story = (args) => <{{ name }} {...args} />
14+
// export const Primary = Template.bind({})
15+
// Primary.args = {
16+
// }
1717

18-
export const Primary = Template.bind({})
19-
Primary.args = {
20-
}
18+
// Use for separate stories
19+
// export const Simple: React.FC = () => <{{ name }} />

generators/Component.test.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import { renderLight, renderDark } from 'test-utils'
33
import { Default } from './{{ name }}.stories'
4-
import { {{ name }} } from '.'
54

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

0 commit comments

Comments
 (0)