Skip to content

Commit

Permalink
Show token comments and font families in docs (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersticka authored Apr 15, 2020
1 parent b4868b1 commit 4c7b036
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions .theo/formats/stories.mdx.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,40 @@ function mdxColors(props) {
* property table.
*
* @param {Object} prop - Theo property
* @param {Boolean} includeComment - If `true`, include a comment cell.
* @returns {String}
*/
function mdxProp(prop) {
return `
<tr>
<th scope="row">$${kebabCase(prop.name)}</th>
<td>${prop.value}</td>
</tr>
`.trim();
function mdxProp(prop, includeComment) {
// First cell has small percentage to give values and comments more room.
let content = `<td style={{width:'10%'}}><code>$${kebabCase(
prop.name
)}</code></td>`;

if (prop.category === 'font-family') {
// Create an array for each of the fonts in the family string
let fonts = prop.value.split(',');
// Start a new array to hold the preview elements we're about to create
const fontStrings = [];
// For each font string we create, we are going to remove the first font
// element using `shift`. This allows each segment to be previewed along
// with its remaining fallbacks.
while (fonts.length) {
fontStrings.push(
`<span style={{ fontFamily: \`${fonts.join(
','
)}\`}}>${fonts.shift().trim()}</span>`
);
}
content += `<td>${fontStrings.join(', ')}</td>`;
} else {
content += `<td><code>${prop.value}</code></td>`;
}

if (includeComment) {
content += `<td>${prop.comment || '&nbsp;'}</td>`;
}

return `<tr>${content.trim()}</tr>`;
}

/**
Expand All @@ -54,12 +79,15 @@ function mdxProp(prop) {
* @returns {String}
*/
function mdxProps(props) {
const rows = props.map(mdxProp);
const commentedProps = props.filter((prop) => !!prop.comment);
const includeComments = commentedProps.length > 0;
const rows = props.map((prop) => mdxProp(prop, includeComments));
return `
<table>
<thead>
<th>Name</th>
<th>Value</th>
${includeComments ? `<th>Comment</th>` : ''}
</thead>
<tbody>${rows.join('\n')}</tbody>
</table>`.trim();
Expand Down

0 comments on commit 4c7b036

Please sign in to comment.