-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New components Table, Collapsible and refactoring (#247)
- Loading branch information
Showing
32 changed files
with
768 additions
and
311 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { promises as fs } from "fs"; | ||
import path from "path"; | ||
import type { PropItem } from "react-docgen-typescript/lib/parser"; | ||
import type { ComponentDocWithGroups } from "@/scripts/generateComponentData.mjs"; | ||
import Collapsible from "@/components/collapsible/Collapsible.tsx"; | ||
import Title from "@/components/title/Title.tsx"; | ||
|
||
import "./propTable.css"; | ||
|
||
export interface PropTableProps { | ||
component: string; | ||
} | ||
|
||
interface PropItemTypeValue { | ||
name: string; | ||
value?: Array<{ value: string; name: string }>; | ||
raw?: string; | ||
} | ||
|
||
const filePath = path.join(process.cwd(), "datas", "components"); | ||
|
||
const getType = (type: PropItemTypeValue) => { | ||
const handler: { | ||
[key: string]: (type: PropItemTypeValue) => string; | ||
} = { | ||
enum: t => | ||
t.value ? t.value.map(item => item.value.replace(/'/g, "")).join(" \\| ") : "", | ||
union: t => t.value ? t.value.map(item => item.name).join(" \\| ") : "" | ||
}; | ||
if (typeof handler[type.name] === "function") { | ||
return handler[type.name](type).replace(/\|/g, ""); | ||
} | ||
|
||
return type.name; | ||
}; | ||
|
||
const renderRow = (key: string, prop: PropItem) => { | ||
const { name, type, defaultValue, required, description } = prop; | ||
|
||
return ( | ||
<tr key={key}> | ||
<td>{name}</td> | ||
<td>{getType(type)}</td> | ||
<td>{defaultValue?.value}</td> | ||
<td>{required ? "✓" : "✗"}</td> | ||
<td>{description}</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default async function PropTable({ component }: PropTableProps) { | ||
const file = await fs.readFile(filePath + `/${component}.json`, "utf8"); | ||
const data = JSON.parse(file); | ||
|
||
return data.map((item: ComponentDocWithGroups) => { | ||
const { description, displayName, groups } = item; | ||
|
||
return ( | ||
<> | ||
<p>{displayName}</p> | ||
<p>{description}</p> | ||
{Object.keys(groups).map(group => { | ||
return ( | ||
<Collapsible | ||
key={group} | ||
title={ | ||
<Title as="h3" level={3}> | ||
{group} | ||
</Title> | ||
} | ||
className="props__section" | ||
> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Property</th> | ||
<th>Type</th> | ||
<th>Default</th> | ||
<th>Required</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{Object.keys(groups[group]).map(key => renderRow(key, groups[group][key]))} | ||
</tbody> | ||
</table> | ||
</Collapsible> | ||
); | ||
})} | ||
</> | ||
); | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.props__section { | ||
margin-top: var(--hd-space-1); | ||
} | ||
|
||
.props__section .hd-collapsible__content { | ||
margin-top: var(--hd-space-1); | ||
} |
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 was deleted.
Oops, something went wrong.
8 changes: 4 additions & 4 deletions
8
...ocs/app/ui/tokens/table/Table.stories.tsx → ...pp/ui/tokens/table/TokenTable.stories.tsx
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Table from "@/components/table/Table"; | ||
|
||
import Preview from "@/app/ui/tokens/preview/Preview"; | ||
import Code from "@/components/code/Code"; | ||
|
||
import "./tokenTable.css"; | ||
|
||
interface TableProps { | ||
category: string; | ||
noPreview?: boolean; | ||
data: { | ||
name: string; | ||
value: string; | ||
}[]; | ||
} | ||
|
||
const TokenTable = ({ category, data, noPreview }: TableProps) => { | ||
const formattedData = data.map(token => { | ||
const { name, value } = token; | ||
|
||
return { | ||
name: <Code value={`--${name}`}>{`--${name}`}</Code>, | ||
value: value, | ||
preview: !noPreview && <Preview value={value} name={name} category={category} /> | ||
}; | ||
}); | ||
|
||
|
||
return <Table head={["Name", "Value", !noPreview && "Preview"]} | ||
data={formattedData} | ||
lastColumnAlignment="right" | ||
ariaLabel="Tokens" | ||
/>; | ||
}; | ||
|
||
export default TokenTable; |
Oops, something went wrong.