-
Notifications
You must be signed in to change notification settings - Fork 50
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
[Feature]: Support codesandbox to provide interactive examples #7
Comments
@minsoo-web How about making Pull Request for adding codesandbox embed in documentation |
Of course. It is my pleasure. I will do my best 🚀🚀🚀 |
How about like this case ? |
related with #7 # Overview <!-- A clear and concise description of what this pr is about. --> I initialize codesandbox ci followiing its guide <img width="1722" alt="image" src="https://github.com/suspensive/react/assets/61593290/fc01ffa9-88af-43ed-8777-3eb5fe7b6fc3"> ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
@minsoo-web Could I assign you for v2 docs soon? @sonsurim We need someone have no experience for this library to see how difficulty to onboard with this. Could you be the one to see it objectively? |
Of course, I'll work on it |
@manudeli I was just wondering, Could I see it when it's done? |
I'd like to ask for your opinion, the docs of @chara-ui/react, which I'm using as a reference, are provided as a library called react-live. I'm impressed that you can add scope, so that you can modify only the code blocks you need without separate function declarations and import syntax. However, I think the import syntax is necessary information for the user, and the function declaration and use-case should also show the entire code. I'd love to hear your thoughts on whether using |
@kangju2000 @minsoo-web Make and share plan to implement this feature on https://suspensive.org/ please |
While searching for references, I came across a plugin called remark-sandpack On react.dev, they compile MDX directly, but since Suspensive uses Nextra, we can attach the remark plugin. If you use the plugin, here's how to do it: Register remark pluginnext.config.js // eslint-disable-next-line @typescript-eslint/no-var-requires, import/order
const { remarkSandpack } = require('remark-sandpack')
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, import/order
const withNextra = require('nextra')({
theme: 'nextra-theme-docs',
themeConfig: './theme.config.tsx',
defaultShowCopyCode: true,
+ mdxOptions: {
+ remarkPlugins: [remarkSandpack],
+ },
})
/** @type {import('next').NextConfig} */
module.exports = withNextra({
i18n: {
locales: ['en', 'ko'],
defaultLocale: 'en',
},
}) Usageimport { Sandpack } from '@/components'
<Sandpack
customSetup={{
dependencies: {
'@suspensive/react': 'latest',
'@suspensive/react-query': 'latest',
'@tanstack/react-query': '^4.0.0',
},
}}
>
```js /App.tsx
import Example from './Example'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
const queryClient = new QueryClient()
export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Example />
</QueryClientProvider>
)
}
```
```js /Example.tsx active
import { wrap } from '@suspensive/react'
import { useSuspenseQuery } from '@suspensive/react-query'
import { api } from './api'
export default wrap
.ErrorBoundaryGroup({ blockOutside: false })
.ErrorBoundary({ fallback: ({ error }) => <>{error.message}</> })
.Suspense({ fallback: <>loading...</>, clientOnly: true })
.on(() => {
const query = useSuspenseQuery({
queryKey: ['key'],
queryFn: () => api.text(),
})
return <>{query.data.text}</>
})
```
```js /api.ts
export const api = {
text: async () => {
await new Promise((resolve) => setTimeout(resolve, 1000))
return { text: 'Hello, Suspensive!' }
},
}
```
</Sandpack>
Result2024-06-24.1.32.43.movHow about using this instead of implementing it ourselves? |
The differences in markdown rules on react.dev are as follows:
|
Wow.........!!!!!!!!! So much cooool! Could you make Pull Request too?
Cool! I agree this |
@kangju2000 |
… using sandpack (#995) related #7 # Overview <!-- A clear and concise description of what this pr is about. --> Add examples to the ErrorBoundary documentation using sandpack. ### Changes - Change template from vite-ts to react-ts - Hide [react-error-overlay](https://www.npmjs.com/package/react-error-overlay) - Implement custom ErrorOverlay for Sandpack ### Details Changed the template from `vite-ts` to `react-ts` to improve initial loading speed. The `react-ts` template is based on Create React App (CRA), which shows the `react-error-overlay` when an error occurs. This overlay prevents the fallback UI from being displayed immediately. To fix this, I set the `react-error-overlay` to `display: none`. Additionally, Sandpack has its own error overlay. To handle errors more effectively and ensure the fallback UI is displayed correctly, I customized the ErrorOverlay to not appear when an error is thrown. The rest of the logic was taken from Sandpack's source code: [Sandpack.tsx](https://github.com/codesandbox/sandpack/blob/main/sandpack-react/src/presets/Sandpack.tsx#L25). ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
related with #7 # Overview <!-- A clear and concise description of what this pr is about. --> I initialize codesandbox ci followiing its guide <img width="1722" alt="image" src="https://github.com/suspensive/react/assets/61593290/fc01ffa9-88af-43ed-8777-3eb5fe7b6fc3"> ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
… using sandpack (#995) related #7 # Overview <!-- A clear and concise description of what this pr is about. --> Add examples to the ErrorBoundary documentation using sandpack. ### Changes - Change template from vite-ts to react-ts - Hide [react-error-overlay](https://www.npmjs.com/package/react-error-overlay) - Implement custom ErrorOverlay for Sandpack ### Details Changed the template from `vite-ts` to `react-ts` to improve initial loading speed. The `react-ts` template is based on Create React App (CRA), which shows the `react-error-overlay` when an error occurs. This overlay prevents the fallback UI from being displayed immediately. To fix this, I set the `react-error-overlay` to `display: none`. Additionally, Sandpack has its own error overlay. To handle errors more effectively and ensure the fallback UI is displayed correctly, I customized the ErrorOverlay to not appear when an error is thrown. The rest of the logic was taken from Sandpack's source code: [Sandpack.tsx](https://github.com/codesandbox/sandpack/blob/main/sandpack-react/src/presets/Sandpack.tsx#L25). ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
related with #7 # Overview <!-- A clear and concise description of what this pr is about. --> I initialize codesandbox ci followiing its guide <img width="1722" alt="image" src="https://github.com/suspensive/react/assets/61593290/fc01ffa9-88af-43ed-8777-3eb5fe7b6fc3"> ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> related #867 closed #7 I have set up the documentation to easily add examples in MDX using Sandpack from CodeSandbox. I have also carried over the theme selected in the [related PR](#867). If there's anything else that needs to be configured, please let me know! ## Usage ````mdx import { Sandpack } from '@/components' <Sandpack customSetup={{ dependencies: { '@suspensive/react': 'latest', '@suspensive/react-query': 'latest', '@tanstack/react-query': '^4.0.0', }, }} > ```js /App.tsx import Example from './Example' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' const queryClient = new QueryClient() export default function App() { return ( <QueryClientProvider client={queryClient}> <Example /> </QueryClientProvider> ) } ``` ```js /Example.tsx active import { wrap } from '@suspensive/react' import { useSuspenseQuery } from '@suspensive/react-query' import { api } from './api' export default wrap .ErrorBoundaryGroup({ blockOutside: false }) .ErrorBoundary({ fallback: ({ error }) => <>{error.message}</> }) .Suspense({ fallback: <>loading...</>, clientOnly: true }) .on(() => { const query = useSuspenseQuery({ queryKey: ['key'], queryFn: () => api.text(), }) return <>{query.data.text}</> }) ``` ```js /api.ts export const api = { text: async () => { await new Promise((resolve) => setTimeout(resolve, 1000)) return { text: 'Hello, Suspensive!' } }, } ``` </Sandpack> ```` ### Result https://github.com/toss/suspensive/assets/23312485/370b6508-cd9b-494d-8ea6-28273eaabba8 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
… using sandpack (#995) related #7 # Overview <!-- A clear and concise description of what this pr is about. --> Add examples to the ErrorBoundary documentation using sandpack. ### Changes - Change template from vite-ts to react-ts - Hide [react-error-overlay](https://www.npmjs.com/package/react-error-overlay) - Implement custom ErrorOverlay for Sandpack ### Details Changed the template from `vite-ts` to `react-ts` to improve initial loading speed. The `react-ts` template is based on Create React App (CRA), which shows the `react-error-overlay` when an error occurs. This overlay prevents the fallback UI from being displayed immediately. To fix this, I set the `react-error-overlay` to `display: none`. Additionally, Sandpack has its own error overlay. To handle errors more effectively and ensure the fallback UI is displayed correctly, I customized the ErrorOverlay to not appear when an error is thrown. The rest of the logic was taken from Sandpack's source code: [Sandpack.tsx](https://github.com/codesandbox/sandpack/blob/main/sandpack-react/src/presets/Sandpack.tsx#L25). ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> related #867 closed #7 I have set up the documentation to easily add examples in MDX using Sandpack from CodeSandbox. I have also carried over the theme selected in the [related PR](#867). If there's anything else that needs to be configured, please let me know! ## Usage ````mdx import { Sandpack } from '@/components' <Sandpack customSetup={{ dependencies: { '@suspensive/react': 'latest', '@suspensive/react-query': 'latest', '@tanstack/react-query': '^4.0.0', }, }} > ```js /App.tsx import Example from './Example' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' const queryClient = new QueryClient() export default function App() { return ( <QueryClientProvider client={queryClient}> <Example /> </QueryClientProvider> ) } ``` ```js /Example.tsx active import { wrap } from '@suspensive/react' import { useSuspenseQuery } from '@suspensive/react-query' import { api } from './api' export default wrap .ErrorBoundaryGroup({ blockOutside: false }) .ErrorBoundary({ fallback: ({ error }) => <>{error.message}</> }) .Suspense({ fallback: <>loading...</>, clientOnly: true }) .on(() => { const query = useSuspenseQuery({ queryKey: ['key'], queryFn: () => api.text(), }) return <>{query.data.text}</> }) ``` ```js /api.ts export const api = { text: async () => { await new Promise((resolve) => setTimeout(resolve, 1000)) return { text: 'Hello, Suspensive!' } }, } ``` </Sandpack> ```` ### Result https://github.com/toss/suspensive/assets/23312485/370b6508-cd9b-494d-8ea6-28273eaabba8 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
… using sandpack (#995) related #7 # Overview <!-- A clear and concise description of what this pr is about. --> Add examples to the ErrorBoundary documentation using sandpack. ### Changes - Change template from vite-ts to react-ts - Hide [react-error-overlay](https://www.npmjs.com/package/react-error-overlay) - Implement custom ErrorOverlay for Sandpack ### Details Changed the template from `vite-ts` to `react-ts` to improve initial loading speed. The `react-ts` template is based on Create React App (CRA), which shows the `react-error-overlay` when an error occurs. This overlay prevents the fallback UI from being displayed immediately. To fix this, I set the `react-error-overlay` to `display: none`. Additionally, Sandpack has its own error overlay. To handle errors more effectively and ensure the fallback UI is displayed correctly, I customized the ErrorOverlay to not appear when an error is thrown. The rest of the logic was taken from Sandpack's source code: [Sandpack.tsx](https://github.com/codesandbox/sandpack/blob/main/sandpack-react/src/presets/Sandpack.tsx#L25). ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
related with #7 # Overview <!-- A clear and concise description of what this pr is about. --> I initialize codesandbox ci followiing its guide <img width="1722" alt="image" src="https://github.com/suspensive/react/assets/61593290/fc01ffa9-88af-43ed-8777-3eb5fe7b6fc3"> ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/suspensive/react/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
# Overview <!-- A clear and concise description of what this pr is about. --> related #867 closed #7 I have set up the documentation to easily add examples in MDX using Sandpack from CodeSandbox. I have also carried over the theme selected in the [related PR](#867). If there's anything else that needs to be configured, please let me know! ## Usage ````mdx import { Sandpack } from '@/components' <Sandpack customSetup={{ dependencies: { '@suspensive/react': 'latest', '@suspensive/react-query': 'latest', '@tanstack/react-query': '^4.0.0', }, }} > ```js /App.tsx import Example from './Example' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' const queryClient = new QueryClient() export default function App() { return ( <QueryClientProvider client={queryClient}> <Example /> </QueryClientProvider> ) } ``` ```js /Example.tsx active import { wrap } from '@suspensive/react' import { useSuspenseQuery } from '@suspensive/react-query' import { api } from './api' export default wrap .ErrorBoundaryGroup({ blockOutside: false }) .ErrorBoundary({ fallback: ({ error }) => <>{error.message}</> }) .Suspense({ fallback: <>loading...</>, clientOnly: true }) .on(() => { const query = useSuspenseQuery({ queryKey: ['key'], queryFn: () => api.text(), }) return <>{query.data.text}</> }) ``` ```js /api.ts export const api = { text: async () => { await new Promise((resolve) => setTimeout(resolve, 1000)) return { text: 'Hello, Suspensive!' } }, } ``` </Sandpack> ```` ### Result https://github.com/toss/suspensive/assets/23312485/370b6508-cd9b-494d-8ea6-28273eaabba8 ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
… using sandpack (#995) related #7 # Overview <!-- A clear and concise description of what this pr is about. --> Add examples to the ErrorBoundary documentation using sandpack. ### Changes - Change template from vite-ts to react-ts - Hide [react-error-overlay](https://www.npmjs.com/package/react-error-overlay) - Implement custom ErrorOverlay for Sandpack ### Details Changed the template from `vite-ts` to `react-ts` to improve initial loading speed. The `react-ts` template is based on Create React App (CRA), which shows the `react-error-overlay` when an error occurs. This overlay prevents the fallback UI from being displayed immediately. To fix this, I set the `react-error-overlay` to `display: none`. Additionally, Sandpack has its own error overlay. To handle errors more effectively and ensure the fallback UI is displayed correctly, I customized the ErrorOverlay to not appear when an error is thrown. The rest of the logic was taken from Sandpack's source code: [Sandpack.tsx](https://github.com/codesandbox/sandpack/blob/main/sandpack-react/src/presets/Sandpack.tsx#L25). ## PR Checklist - [x] I did below actions if need 1. I read the [Contributing Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md) 2. I added documents and tests.
People can be co-author:
|
Package Scope
docs
Package name:
Overview
Describe the solution you'd like
Additional context
The text was updated successfully, but these errors were encountered: