Skip to content

Commit

Permalink
fix: refactor component props to make them optional (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode authored Feb 28, 2024
1 parent edff7c7 commit 7fe1233
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions fixtures/Button.mist.css.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import './Button.mist.css'

type Props = {
children: React.ReactNode
size: 'lg' | 'sm'
danger: boolean
children?: React.ReactNode
size?: 'lg' | 'sm'
danger?: boolean
}

export function Button({ children, size, danger, ...props }: Props) {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ function renderProps(parsedInput: ParsedInput): string {
.map((attribute) => {
const values = parsedInput.data[attribute]
if (Array.isArray(values)) {
return `${attribute}: ${values
return `${attribute}?: ${values
.map((value) => `'${value}'`)
.join(' | ')}`
}

return ` ${attribute}: boolean`
return ` ${attribute}?: boolean`
})
.join('\n')
}
Expand All @@ -80,7 +80,7 @@ export function render(name: string, parsedInput: ParsedInput): string {
import './${name}.mist.css'
type Props = {
children: React.ReactNode
children?: React.ReactNode
${renderProps(parsedInput)}
}
Expand Down

0 comments on commit 7fe1233

Please sign in to comment.