-
Notifications
You must be signed in to change notification settings - Fork 41
feat: support overridableVariables in recipes; add overrides prop to ActionButton
#927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
te6-in
wants to merge
9
commits into
dev
Choose a base branch
from
feat/overridable-variables
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b080b74
feat: support `overridableVariables` in recipes
te6-in d00a2ba
feat: make ActionButtonProps extend OverridableProps
te6-in 3aabe0c
docs
te6-in e69c12d
refactor
te6-in 5497a5d
docs: changeset
te6-in 55919a6
feat: add `union-literal-table` mdx component
te6-in caef0db
refactor
te6-in ceae5e0
Merge branch 'dev' into feat/overridable-variables
te6-in 2a63702
Merge branch 'dev' into feat/overridable-variables
te6-in File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,6 @@ | ||
| --- | ||
| "@seed-design/react": patch | ||
| "@seed-design/css": patch | ||
| --- | ||
|
|
||
| `ActionButton`에서 `overrides` prop을 통해 배경 색상을 오버라이드할 수 있도록 합니다. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,26 @@ | ||
| import { ActionButton } from "seed-design/ui/action-button"; | ||
| import { vars } from "@seed-design/css/vars"; | ||
| import { HStack } from "@seed-design/react"; | ||
|
|
||
| export default function ActionButtonOverriding() { | ||
| return ( | ||
| <HStack gap="x3"> | ||
| <ActionButton | ||
| overrides={{ | ||
| "--seed-action-button-enabled-background": vars.$color.bg.informativeSolid, | ||
| "--seed-action-button-active-background": vars.$color.bg.informativeSolidPressed, | ||
| }} | ||
| > | ||
| 라벨 | ||
| </ActionButton> | ||
| <ActionButton | ||
| overrides={{ | ||
| "--seed-action-button-enabled-background": `linear-gradient(135deg, ${vars.$color.palette.purple400} 0%, ${vars.$color.palette.purple800} 100%)`, | ||
| "--seed-action-button-active-background": `linear-gradient(135deg, ${vars.$color.palette.purple500} 0%, ${vars.$color.palette.purple900} 100%)`, | ||
| }} | ||
| > | ||
| 라벨 | ||
| </ActionButton> | ||
| </HStack> | ||
| ); | ||
| } |
This file contains hidden or 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,51 @@ | ||
| import { Project } from "ts-morph"; | ||
| import * as path from "node:path"; | ||
|
|
||
| export interface UnionLiteralTableProps { | ||
| path: string; | ||
| name: string; | ||
| } | ||
|
|
||
| export interface UnionLiteralResult { | ||
| name: string; | ||
| literals: string[]; | ||
| } | ||
|
|
||
| const project = new Project({ skipAddingFilesFromTsConfig: true }); | ||
|
|
||
| export async function getUnionLiterals({ | ||
| path: filePath, | ||
| name, | ||
| }: UnionLiteralTableProps): Promise<UnionLiteralResult> { | ||
| const resolvedPath = resolveTypePath(filePath); | ||
| const sourceFile = project.addSourceFileAtPath(resolvedPath); | ||
|
|
||
| const typeAlias = sourceFile.getTypeAlias(name); | ||
|
|
||
| if (!typeAlias) throw new Error(`Type "${name}" not found in ${filePath}`); | ||
|
|
||
| const type = typeAlias.getType(); | ||
| if (!type) throw new Error(`Type "${name}" not found in ${filePath}`); | ||
|
|
||
| const literals = (type.isUnion() ? type.getUnionTypes() : [type]) | ||
| .map((t) => t.getText()) | ||
| .filter((v): v is string => !!v); | ||
|
|
||
| return { name, literals }; | ||
| } | ||
|
|
||
| // TODO: do this better with require.resolve or something | ||
| // import.meta.resolve will work but not currently supported in Next.js | ||
| function resolveTypePath(filePath: string): string { | ||
| if (filePath.startsWith("@seed-design/")) { | ||
| const packagePath = filePath.replace("@seed-design/", ""); | ||
|
|
||
| return path.join(process.cwd(), "../packages", `${packagePath}.d.ts`); | ||
| } | ||
|
|
||
| if (filePath.startsWith("./") || filePath.startsWith("../")) { | ||
| return path.resolve(process.cwd(), filePath); | ||
| } | ||
|
|
||
| return filePath; | ||
| } |
This file contains hidden or 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 hidden or 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,85 @@ | ||
| import type { Root } from "mdast"; | ||
| import type { Transformer } from "unified"; | ||
| import { visit, SKIP } from "unist-util-visit"; | ||
| import { getUnionLiterals } from "./get-union-literals"; | ||
|
|
||
| export interface RemarkUnionLiteralTableOptions { | ||
| /** | ||
| * @defaultValue 'union-literal-table' | ||
| */ | ||
| name?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Compile `union-literal-table` into a simple table at build time | ||
| */ | ||
| export function remarkUnionLiteralTable({ | ||
| name = "union-literal-table", | ||
| }: RemarkUnionLiteralTableOptions = {}): Transformer<Root, Root> { | ||
| return async (tree) => { | ||
| const queue: Promise<void>[] = []; | ||
|
|
||
| visit(tree, "mdxJsxFlowElement", (node) => { | ||
| if (node.name !== name) return; | ||
|
|
||
| const props: Record<string, string> = {}; | ||
|
|
||
| for (const attr of node.attributes) { | ||
| if (attr.type !== "mdxJsxAttribute" || typeof attr.value !== "string") | ||
| throw new Error("`union-literal-table` does not support non-string attributes"); | ||
|
|
||
| props[attr.name] = attr.value; | ||
| } | ||
|
|
||
| async function run() { | ||
| const result = await getUnionLiterals({ | ||
| path: props.path, | ||
| name: props.name, | ||
| }); | ||
|
|
||
| // Create a proper markdown table AST structure | ||
| const tableNode = { | ||
| type: "table", | ||
| align: ["left"], | ||
| children: [ | ||
| { | ||
| type: "tableRow", | ||
| children: [ | ||
| { | ||
| type: "tableCell", | ||
| children: [ | ||
| { | ||
| type: "text", | ||
| value: "Possible Values", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ...result.literals.map((literal) => ({ | ||
| type: "tableRow", | ||
| children: [ | ||
| { | ||
| type: "tableCell", | ||
| children: [ | ||
| { | ||
| type: "inlineCode", | ||
| value: literal, | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| })), | ||
| ], | ||
| }; | ||
|
|
||
| Object.assign(node, tableNode); | ||
| } | ||
|
|
||
| queue.push(run()); | ||
| return SKIP; | ||
| }); | ||
|
|
||
| await Promise.all(queue); | ||
| }; | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.