-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
abaeb2d
commit 69ec571
Showing
8 changed files
with
60 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,24 @@ | ||
--- | ||
import type { ConfigOption as ConfigOptionType } from "../../chromatic-config/generate-schema"; | ||
import configOptions from "../../chromatic-config/options.json"; | ||
import { markdown } from "../markdown"; | ||
const formatOption = ({ option, flag, shortFlag, restriction }: any) => { | ||
const lead = option ? option : `<code>${flag}</code>`; | ||
const hasBoth = option && flag; | ||
return [ | ||
`<strong>${lead}</strong>`, | ||
restriction ? ` (${restriction})` : "", | ||
hasBoth ? "<br/>" : "", | ||
hasBoth && flag ? `<code>${flag}</code>` : "", | ||
shortFlag ? ` (<code>${shortFlag}</code>)` : "", | ||
].join(""); | ||
import { ConfigOption } from "./ConfigOption"; | ||
const formatOption = async (option: ConfigOptionType) => { | ||
return { | ||
...option, | ||
option: option.option || option.flag, | ||
description: await markdown(option.description), | ||
example: await markdown(option.example), | ||
default: option.default | ||
? `<code>${option.default}</code>` | ||
: option.defaultComment, | ||
}; | ||
}; | ||
const formatType = (type: string | string[]) => { | ||
if (type === "array of glob") { | ||
return ["<code>glob</code>", "array of <code>glob</code>"].join(" or "); | ||
} | ||
if (Array.isArray(type)) { | ||
return type | ||
.map((t) => { | ||
return `<code>${t}</code>`; | ||
}) | ||
.join(" or "); | ||
} | ||
return `<code>${type}</code>`; | ||
}; | ||
function formatDefault(comment?: string, value?: string | boolean) { | ||
if (comment) { | ||
return comment; | ||
} | ||
if (value !== undefined) { | ||
return `<code>${value}</code>`; | ||
} | ||
} | ||
const formattedOptions = await Promise.all( | ||
(configOptions as ConfigOptionType[]).map(formatOption), | ||
); | ||
--- | ||
|
||
<div class="table-scroll" style="overflow: scroll"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Option / Flag</th> | ||
<th>Description</th> | ||
<th>Type</th> | ||
<th>Example value</th> | ||
<th>Default value</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{ | ||
configOptions.map(async (option) => ( | ||
<tr> | ||
<td set:html={formatOption(option)} /> | ||
<td set:html={await markdown(option.description)} /> | ||
<td set:html={formatType(option.type)} /> | ||
<td set:html={await markdown(option.example)} /> | ||
<td | ||
set:html={formatDefault(option.defaultComment, option.default)} | ||
/> | ||
</tr> | ||
)) | ||
} | ||
</tbody> | ||
</table> | ||
</div> | ||
{formattedOptions.map((option) => <ConfigOption {...option} />)} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters