Skip to content

Commit

Permalink
Merge pull request #7 from vtexdocs/feat/faststore
Browse files Browse the repository at this point in the history
Feat/faststore
  • Loading branch information
aliceoq authored Nov 30, 2023
2 parents 1cfd3ec + 19df90c commit ac79321
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 14 deletions.
3 changes: 2 additions & 1 deletion dist/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion dist/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ import { AlgoliaSearchOptions } from 'algoliasearch/lite';

interface MarkdownRendererProps {
serialized: MDXRemoteSerializeResult;
customComponents?: {
[name: string]: any;
};
scope?: {
[name: string]: any;
};
}

declare const MarkdownRenderer: ({ serialized }: MarkdownRendererProps) => react_jsx_runtime.JSX.Element;
declare const MarkdownRenderer: ({ serialized, customComponents, scope, }: MarkdownRendererProps) => react_jsx_runtime.JSX.Element;

interface SubItem {
title: string;
Expand Down
24 changes: 22 additions & 2 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5947,7 +5947,7 @@ var Callout = ({ node, icon: icon3, ...props }) => {
"blockquote",
{
className: `${styles_module_default.blockquote} ${blockquoteType === "info" ? styles_module_default.blockquoteInfo : blockquoteType === "danger" ? styles_module_default.blockquoteDanger : blockquoteType === "warning" ? styles_module_default.blockquoteWarning : blockquoteType === "success" ? styles_module_default.blockquoteSuccess : ""}`,
children: /* @__PURE__ */ jsx9("p", { ...props })
children: /* @__PURE__ */ jsx9("div", { ...props })
}
);
};
Expand Down Expand Up @@ -6024,6 +6024,9 @@ var components_default = {
table: ({ node, ...props }) => /* @__PURE__ */ jsx9("table", { ...props }),
td: ({ node, ...props }) => /* @__PURE__ */ jsx9("td", { ...props }),
img: ImageComponent,
text: ({ node, ...props }) => {
return /* @__PURE__ */ jsx9(Box5, { sx: { marginBlock: "1em" }, ...props });
},
blockquote: ({ ...props }) => {
return /* @__PURE__ */ jsx9(Callout, { ...props });
},
Expand Down Expand Up @@ -6082,7 +6085,24 @@ var components_default = {
// src/lib/markdown-renderer/MarkdownRenderer.tsx
import { jsx as jsx10 } from "react/jsx-runtime";
var MDXRemote2 = MDXRemote;
var MarkdownRenderer = ({ serialized }) => /* @__PURE__ */ jsx10(Box6, { children: /* @__PURE__ */ jsx10(MDXRemote2, { components: components_default, lazy: true, ...serialized }) });
var MarkdownRenderer = ({
serialized,
customComponents,
scope
}) => {
if (components_default && scope) {
return /* @__PURE__ */ jsx10(Box6, { children: /* @__PURE__ */ jsx10(
MDXRemote2,
{
components: { ...components_default, ...customComponents },
lazy: true,
...serialized,
scope
}
) });
}
return /* @__PURE__ */ jsx10(Box6, { children: /* @__PURE__ */ jsx10(MDXRemote2, { components: components_default, lazy: true, ...serialized }) });
};
var MarkdownRenderer_default = MarkdownRenderer;

// src/lib/table-of-contents/TableOfContents.tsx
Expand Down
2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/lib/markdown-renderer/MarkdownRenderer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import type { Meta, StoryObj } from '@storybook/react'
import { ThemeProvider } from '@vtex/brand-ui'
import { MarkdownRenderer } from 'index'
import LibraryContextProvider from 'utils/context/libraryContext'
import { exampleContextProps, serialized } from 'utils/storybook-constants'
import {
TestComponent,
exampleContextProps,
serialized,
} from 'utils/storybook-constants'

const meta = {
title: 'Example/MarkdownRenderer',
Expand All @@ -25,5 +29,6 @@ type Story = StoryObj<typeof meta>
export const SimpleMarkdownRenderer: Story = {
args: {
serialized: serialized,
customComponents: { TestComponent },
},
}
29 changes: 24 additions & 5 deletions src/lib/markdown-renderer/MarkdownRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,29 @@ import components from './components'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const MDXRemote2 = MDXRemote as any

const MarkdownRenderer = ({ serialized }: MarkdownRendererProps) => (
<Box>
<MDXRemote2 components={components} lazy {...serialized} />
</Box>
)
const MarkdownRenderer = ({
serialized,
customComponents,
scope,
}: MarkdownRendererProps) => {
if (components && scope) {
return (
<Box>
<MDXRemote2
components={{ ...components, ...customComponents }}
lazy
{...serialized}
scope={scope}
/>
</Box>
)
}

return (
<Box>
<MDXRemote2 components={components} lazy {...serialized} />
</Box>
)
}

export default MarkdownRenderer
7 changes: 7 additions & 0 deletions src/lib/markdown-renderer/MarkdownRenderer.types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { MDXRemoteSerializeResult } from 'next-mdx-remote'

export type Component = {
Expand All @@ -8,6 +9,12 @@ export type Component = {

export interface MarkdownRendererProps {
serialized: MDXRemoteSerializeResult
customComponents?: {
[name: string]: any
}
scope?: {
[name: string]: any
}
}

export interface ObservableHeadingProps {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/markdown-renderer/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const Callout = ({ node, icon, ...props }: Component) => {
: ''
}`}
>
<p {...props} />
<div {...props} />
</blockquote>
)
}
Expand Down Expand Up @@ -162,6 +162,9 @@ export default {
table: ({ node, ...props }: Component) => <table {...props} />,
td: ({ node, ...props }: Component) => <td {...props} />,
img: ImageComponent,
text: ({ node, ...props }: Component) => {
return <Box sx={{ marginBlock: '1em' }} {...props} />
},
blockquote: ({ ...props }: Component) => {
return <Callout {...props} />
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/markdown-renderer/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ table .code {
word-break: break-all;
}

.blockquote p{
.blockquote p, .blockquote div{
margin: 0px;
grid-column: 2 / -1;
grid-row: 1 / 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import APIGuidesIcon from 'components/icons/api-guides-icon'
import APIReferenceIcon from 'components/icons/api-reference-icon'
import { Component } from 'lib/markdown-renderer/MarkdownRenderer.types'
import { serialize } from 'next-mdx-remote/serialize'

export const sections = [
Expand Down Expand Up @@ -124,9 +125,16 @@ These are some of the features built-in our clients infrastructure:
![Clients on IO Services](https://imgur.com/i45O8MN.png)
<TestComponent text="Test component prop" />
Learn how to create Clients of your own by accessing [Managing Clients](https://developers.vtex.com/vtex-developer-docs/docs/vtex-io-documentation-how-to-create-and-use-clients) documentation.
`

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const TestComponent = ({ node, ...props }: Component) => {
return <div>{props.text}</div>
}

export const serialized = await serialize(markdown_example, {
mdxOptions: {
development: true,
Expand Down

0 comments on commit ac79321

Please sign in to comment.