-
Notifications
You must be signed in to change notification settings - Fork 29
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
Showing
9 changed files
with
179 additions
and
28 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,99 @@ | ||
import { | ||
ComponentSpecExpression, | ||
stringifyTokenExpression, | ||
stringifyValueExpression, | ||
} from "@seed-design/rootage-core"; | ||
import { getRootage } from "./get-rootage"; | ||
import { Fragment } from "react"; | ||
|
||
interface ComponentSpecTableProps { | ||
id: string; | ||
} | ||
|
||
function stringifyVariantKey(key: Record<string, string>) { | ||
const entries = Object.entries(key); | ||
|
||
if (entries.length === 0) { | ||
return "base"; | ||
} | ||
|
||
return entries.map(([key, value]) => `${key}=${value}`).join(", "); | ||
} | ||
|
||
function VariantTable(props: { variant: ComponentSpecExpression[number] }) { | ||
const { variant } = props; | ||
const tableItems = variant.state.flatMap((state) => { | ||
const stateKey = state.key.join(", "); | ||
return state.slot.flatMap((slot) => { | ||
const slotKey = slot.key; | ||
return slot.property.map((property) => { | ||
const propertyKey = property.key; | ||
const value = property.value; | ||
return { | ||
stateKey, | ||
slotKey, | ||
propertyKey, | ||
value, | ||
}; | ||
}); | ||
}); | ||
}); | ||
|
||
return ( | ||
<table> | ||
<colgroup> | ||
<col style={{ width: "15%" }} /> | ||
<col style={{ width: "15%" }} /> | ||
<col style={{ width: "15%" }} /> | ||
<col /> | ||
</colgroup> | ||
<thead> | ||
<tr> | ||
<th>상태</th> | ||
<th>슬롯</th> | ||
<th>속성</th> | ||
<th>값</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{tableItems.map(({ stateKey, slotKey, propertyKey, value }, index) => { | ||
const prevItem = tableItems[index - 1]; | ||
const shouldRenderState = stateKey !== prevItem?.stateKey; | ||
const shouldRenderSlot = shouldRenderState || slotKey !== prevItem?.slotKey; | ||
const shouldRenderProperty = shouldRenderSlot || propertyKey !== prevItem?.propertyKey; | ||
return ( | ||
<tr key={`${stateKey}/${slotKey}/${propertyKey}`}> | ||
<td>{shouldRenderState ? stateKey : null}</td> | ||
<td>{shouldRenderSlot ? slotKey : null}</td> | ||
<td>{shouldRenderProperty ? propertyKey : null}</td> | ||
<td> | ||
{value.type === "token" | ||
? stringifyTokenExpression(value) | ||
: stringifyValueExpression(value)} | ||
</td> | ||
</tr> | ||
); | ||
})} | ||
</tbody> | ||
</table> | ||
); | ||
} | ||
|
||
export async function ComponentSpecTable(props: ComponentSpecTableProps) { | ||
const rootage = await getRootage(); | ||
const componentSpec = rootage.componentSpecs.find((spec) => spec.id === props.id); | ||
|
||
if (!componentSpec) { | ||
return <div>Component spec {props.id} not found</div>; | ||
} | ||
|
||
return componentSpec.data.map((variant) => { | ||
const variantKey = stringifyVariantKey(variant.key); | ||
return ( | ||
<Fragment key={variantKey}> | ||
<h3>{variantKey}</h3> | ||
<VariantTable variant={variant} /> | ||
</Fragment> | ||
); | ||
}); | ||
} |
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 @@ | ||
import { Model, parse } from "@seed-design/rootage-core"; | ||
|
||
export const getRootage = async () => { | ||
const index: { resources: { path: string }[] } = await import("@/public/rootage/index.json").then( | ||
(module) => { | ||
return module.default; | ||
}, | ||
); | ||
const models: Model[] = await Promise.all( | ||
index.resources.map((resource) => import(`@/public/rootage${resource.path}`)), | ||
); | ||
return parse(models); | ||
}; |
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,49 @@ | ||
import { stringifyTokenExpression, stringifyValueExpression } from "@seed-design/rootage-core"; | ||
import { getRootage } from "./get-rootage"; | ||
|
||
interface TokenTableProps { | ||
groups: string[]; | ||
} | ||
|
||
export async function TokenTable(props: TokenTableProps) { | ||
const rootage = await getRootage(); | ||
const tokenDeclsToRender = rootage.tokens.filter((tokenDecl) => | ||
props.groups.every((group, index) => tokenDecl.token.group[index] === group), | ||
); | ||
const collectionName = tokenDeclsToRender[0].collection; | ||
const collection = rootage.tokenCollections.find( | ||
(collection) => collection.name === collectionName, | ||
); | ||
const modes = collection?.modes ?? []; | ||
const tableItems = tokenDeclsToRender.map((decl) => ({ | ||
name: stringifyTokenExpression(decl.token), | ||
values: decl.values, | ||
})); | ||
|
||
return ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>이름</th> | ||
{modes.map((mode) => ( | ||
<th key={mode}>{mode === "default" ? "값" : mode}</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{tableItems.map((item) => ( | ||
<tr key={item.name}> | ||
<td>{item.name}</td> | ||
{item.values.map(({ mode, value }) => ( | ||
<td key={mode}> | ||
{value.type === "token" | ||
? stringifyTokenExpression(value) | ||
: stringifyValueExpression(value)} | ||
</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
} |
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