-
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.
Merge branch 'main' into feature/update-tokens
- Loading branch information
Showing
30 changed files
with
517 additions
and
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const capitalize = (str: string): string => { | ||
return str.charAt(0).toUpperCase() + str.slice(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { highlightCode } from "@/components/highlightCode"; | ||
|
||
export async function formatCode(code: string, language: string) { | ||
return await highlightCode(` | ||
\`\`\`${language} | ||
${code} | ||
\`\`\` | ||
`); | ||
} |
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,20 @@ | ||
export interface PropItemTypeValue { | ||
name: string; | ||
value?: Array<{ value: string; name: string }>; | ||
raw?: string; | ||
} | ||
|
||
export function 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; | ||
} |
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,3 @@ | ||
export function generateUniqueKey() { | ||
return `${Date.now()}-${Math.random()}`; | ||
} |
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,47 @@ | ||
import { promises as fs } from "fs"; | ||
import path from "path"; | ||
import type { ComponentDocWithGroups } from "@/scripts/generateComponentData.mjs"; | ||
import type { PropItem } from "react-docgen-typescript/lib/parser"; | ||
import { getType } from "@/app/lib/gePropsType.ts"; | ||
import { formatCode } from "@/app/lib/formatingCode.ts"; | ||
import { generateUniqueKey } from "@/app/lib/generateUniqueKey.ts"; | ||
|
||
const filePath = path.join(process.cwd(), "datas", "components"); | ||
|
||
export const formatData = async (prop: PropItem) => { | ||
const { name, type, defaultValue, description } = prop; | ||
const formatType = getType(type); | ||
const code = await formatCode(formatType, "tsx"); | ||
const formatedDescription = description.replace(/<form>/g, ""); | ||
|
||
return ({ | ||
id: generateUniqueKey(), | ||
name, | ||
type: code, | ||
defaultValue: defaultValue ? defaultValue.value : "", | ||
description: formatedDescription | ||
}); | ||
}; | ||
|
||
async function formatPropTable(data: ComponentDocWithGroups[]) { | ||
const result = []; | ||
for (const item of data) { | ||
const { groups } = item; | ||
for (const group of Object.keys(groups)) { | ||
const groupItems = await Promise.all(Object.keys(groups[group]).map(key => formatData(groups[group][key]))); | ||
result.push({ [group]: groupItems }); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export async function getComponentProps(component: string) { | ||
const file = await fs.readFile(filePath + `/${component}.json`, "utf8"); | ||
const data = JSON.parse(file); | ||
const [item] = data; | ||
|
||
const groups = await formatPropTable(data); | ||
|
||
return ({ description: item.description, groups }); | ||
} |
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 |
---|---|---|
|
@@ -9,6 +9,5 @@ | |
} | ||
|
||
.hd-heading__links { | ||
display: flex; | ||
gap: var(--hd-space-1); | ||
margin-inline: calc(var(--hd-space-1) * -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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.hd-link-list { | ||
--hd-link-list-direction: column; | ||
|
||
display: flex; | ||
flex-direction: var(--hd-link-list-direction); | ||
align-items: flex-start; | ||
gap: var(--hd-space-1); | ||
|
||
@media screen and (width >= 37.5rem) { | ||
--hd-link-list-direction: row; | ||
} | ||
} | ||
|
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
Oops, something went wrong.