Skip to content

Commit

Permalink
Ensure optionalness is visible in prop table
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenpetryk committed Feb 25, 2024
1 parent 04959f3 commit 25e5f37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion docs/components/PropTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,18 @@ export function PropTable({ of: displayName }: PropTableProps) {
}

function PropName({ prop }: { prop: DocgenProp }) {
const formattedName = <code>{prop.name}</code>
const formattedName = (
<code>
{prop.name}
{prop.required ? (
<sup aria-label="required" className="text-red-400">
*
</sup>
) : (
""
)}
</code>
)
return <span className="font-semibold p-1 rounded-md">{formattedName}</span>
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const srcRoot = path.join(projectRoot, "src")
const docsRoot = path.join(projectRoot, "docs")

const tsconfig = path.join(projectRoot, "tsconfig.json")
const customDocgen = docgen.withCustomConfig(tsconfig, {})
const customDocgen = docgen.withCustomConfig(tsconfig, { shouldRemoveUndefinedFromOptional: true })
const parse = customDocgen.parseWithProgramProvider

function startTSDocgen() {
Expand Down
4 changes: 3 additions & 1 deletion scripts/docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import docgen from "react-docgen-typescript"

const projectRoot = path.join(path.dirname(fileURLToPath(import.meta.url)), "..")
const tsConfigPath = path.join(projectRoot, "tsconfig.json")
const parse = docgen.withCustomConfig(tsConfigPath, {}).parseWithProgramProvider
const parse = docgen.withCustomConfig(tsConfigPath, {
shouldRemoveUndefinedFromOptional: true,
}).parseWithProgramProvider

export function writeDocgenResults(docgenInfo: docgen.ComponentDoc[]) {
const writePath = path.join(projectRoot, "docs/generated-docgen.tsx")
Expand Down

0 comments on commit 25e5f37

Please sign in to comment.