-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from scroll-tech/ui-refactor
UI refactor
- Loading branch information
Showing
120 changed files
with
4,462 additions
and
1,087 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { BlockContent } from "mdast" | ||
import type { MdxJsxAttribute, MdxJsxFlowElement } from "mdast-util-mdx-jsx" | ||
|
||
interface NodeProps { | ||
attributes?: Record<string, string | boolean | number | undefined | null> | ||
} | ||
|
||
/** | ||
* Create AST node for a custom component injection. | ||
* | ||
* @example | ||
* makeComponentNode('MyComponent', { prop: 'val' }, h('p', 'Paragraph inside component')) | ||
* | ||
*/ | ||
export function makeComponentNode( | ||
name: string, | ||
{ attributes = {} }: NodeProps = {}, | ||
...children: BlockContent[] | ||
): MdxJsxFlowElement { | ||
return { | ||
type: "mdxJsxFlowElement", | ||
name, | ||
attributes: Object.entries(attributes) | ||
// Filter out non-truthy attributes to avoid empty attrs being parsed as `true`. | ||
.filter(([_k, v]) => v !== false && Boolean(v)) | ||
.map(([name, value]) => ({ | ||
type: "mdxJsxAttribute", | ||
name, | ||
value: value as MdxJsxAttribute["value"], | ||
})), | ||
children, | ||
} | ||
} |
Oops, something went wrong.