Skip to content
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

Closed
1 of 2 tasks
manudeli opened this issue Jan 19, 2023 · 18 comments · Fixed by #963
Closed
1 of 2 tasks

[Feature]: Support codesandbox to provide interactive examples #7

manudeli opened this issue Jan 19, 2023 · 18 comments · Fixed by #963
Assignees

Comments

@manudeli
Copy link
Member

Package Scope

docs

  • Add to an existing package
  • New package

Package name:

Overview

Describe the solution you'd like

Additional context

@manudeli
Copy link
Member Author

@minsoo-web How about making Pull Request for adding codesandbox embed in documentation
Let's make our documentation like Panda CSS. Can I assign you with me?

@minsoo-web
Copy link
Member

Of course. It is my pleasure. I will do my best 🚀🚀🚀

@minsoo-web
Copy link
Member

image

How about like this case ?
https://polaris.shopify.com/components/typography/text

manudeli added a commit that referenced this issue Oct 29, 2023
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.
@manudeli
Copy link
Member Author

manudeli commented Nov 2, 2023

@manudeli
Copy link
Member Author

@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?

@minsoo-web
Copy link
Member

@minsoo-web Could I assign you for v2 docs soon?

Of course, I'll work on it

@sonsurim
Copy link
Contributor

@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?

@manudeli
Sure, that's great, I'll see it out and leave a comment!

@sonsurim
Copy link
Contributor

sonsurim commented Jan 19, 2024

@manudeli I was just wondering, Could I see it when it's done?

@manudeli
Copy link
Member Author

manudeli commented Jan 19, 2024

@manudeli I was just wondering, Could I see it when it's done?

@sonsurim I guess that v2 will be release until at least in March, After then We need to do this work(codesandbox for interactive examples) in v2. at that time We need your help for new examples or comment or review

@manudeli
Copy link
Member Author

manudeli commented Jan 19, 2024

reference

https://github.com/TanStack/query/blob/main/.codesandbox/ci.json

We can check examples in Pull Request too.
image

@minsoo-web
Copy link
Member

@manudeli

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 react-live or sandpack is the right way to go!

@manudeli
Copy link
Member Author

@kangju2000 @minsoo-web Make and share plan to implement this feature on https://suspensive.org/ please

@kangju2000
Copy link
Collaborator

@manudeli @minsoo-web

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 plugin

next.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',
  },
})

Usage

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

2024-06-24.1.32.43.mov

How about using this instead of implementing it ourselves?

@kangju2000
Copy link
Collaborator

The differences in markdown rules on react.dev are as follows:

  • Import Sandpack component at the top
  • Pass dependencies as component props (on react.dev, these are written in code blocks)

@manudeli
Copy link
Member Author

manudeli commented Jun 24, 2024

Wow.........!!!!!!!!! So much cooool! Could you make Pull Request too?

How about using this instead of implementing it ourselves?

Cool! I agree this

@manudeli
Copy link
Member Author

@kangju2000
Could you make playgrounds of Suspensive 1 page by 1 page or 1 feature by 1 feaure please?

manudeli pushed a commit that referenced this issue Jun 27, 2024
… 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.
@kangju2000
Copy link
Collaborator

kangju2000 commented Jun 30, 2024

@manudeli manudeli added this to the v2 minor feature milestone Jul 18, 2024
manudeli added a commit that referenced this issue Aug 3, 2024
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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
… 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.
manudeli added a commit that referenced this issue Aug 3, 2024
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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
# 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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
… 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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
# 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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
… 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.
manudeli added a commit that referenced this issue Aug 3, 2024
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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
# 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.
manudeli pushed a commit that referenced this issue Aug 3, 2024
… 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.
Copy link

coauthors bot commented Sep 4, 2024

People can be co-author:

Candidate Reasons Count Add this as commit message
@manudeli #7 #7 (comment) #7 (comment) #7 (comment) #7 (comment) #7 (comment) #7 (comment) #7 (comment) #7 (comment) 9 Co-authored-by: manudeli <61593290+manudeli@users.noreply.github.com>
@minsoo-web #7 (comment) #7 (comment) #7 (comment) #7 (comment) 4 Co-authored-by: minsoo-web <57122180+minsoo-web@users.noreply.github.com>
@kangju2000 #7 (comment) #7 (comment) #7 (comment) 3 Co-authored-by: kangju2000 <23312485+kangju2000@users.noreply.github.com>
@sonsurim #7 (comment) #7 (comment) 2 Co-authored-by: sonsurim <47546413+sonsurim@users.noreply.github.com>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants