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

docs: Implement Sandpack component for interactive examples in documentation #338

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { defineConfig } from 'vitepress';
import container from 'markdown-it-container';
import { renderSandbox } from 'vitepress-plugin-sandpack';
import { en } from './en.mts';
import { ko } from './ko.mts';
import { zh_hans } from './zh_hans.mts';
Expand All @@ -11,4 +13,13 @@ export default defineConfig({
ko: { label: '한국어', ...ko },
zh_hans: { label: '简体中文', ...zh_hans },
},
markdown: {
config(md) {
md.use(container, 'sandpack', {
render(tokens: any[], idx: number) {
return renderSandbox(tokens, idx, 'sandpack');
},
});
},
},
});
9 changes: 8 additions & 1 deletion docs/.vitepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import DefaultTheme from 'vitepress/theme';
import Sandpack from '../../components/Sandpack.vue';
import './index.css';

export default DefaultTheme;
export default {
...DefaultTheme,
enhanceApp(ctx) {
DefaultTheme.enhanceApp(ctx);
ctx.app.component('Sandpack', Sandpack);
},
};
35 changes: 35 additions & 0 deletions docs/components/Sandpack.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<template>
<Sandbox
:rtl="rtl"
template="vanilla-ts"
:light-theme="lightTheme"
:dark-theme="darkTheme"
:options="{
...props,
showLineNumbers: true,
showConsole: true,
showTabs: false,
}"
:custom-setup="{
...props,
deps: {
'es-toolkit': 'latest',
},
}"
:code-options="codeOptions"
>
<slot />
</Sandbox>
</template>

<script setup>
import { Sandbox, sandboxProps } from 'vitepress-plugin-sandpack';

const props = defineProps(sandboxProps);
</script>

<style>
.sp-preview {
display: none !important;
}
</style>
12 changes: 12 additions & 0 deletions docs/ko/reference/array/chunk.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
// Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
```

## 사용해보기

::: sandpack

```ts index.ts
import { chunk } from 'es-toolkit/array';

console.log(chunk([1, 2, 3, 4, 5], 2));
```

:::

## Lodash 호환성

`es-toolkit/compat`에서 `chunk`를 가져오면 lodash와 호환돼요.
Expand Down
5 changes: 4 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "docs",
"private": true,
"devDependencies": {
"vitepress": "^1.2.2"
"markdown-it-container": "^4.0.0",
"vitepress": "^1.2.2",
"vitepress-plugin-sandpack": "^1.1.4",
"vue": "^3.4.34"
},
"scripts": {
"docs:dev": "vitepress dev",
Expand Down
14 changes: 13 additions & 1 deletion docs/reference/array/chunk.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
// Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
```

## Demo

::: sandpack

```ts index.ts
import { chunk } from 'es-toolkit/array';

console.log(chunk([1, 2, 3, 4, 5], 2));
```

:::

## Lodash Compatibility

Import `chunk` from `es-toolkit/compat` for full compatibility with lodash.
Expand All @@ -58,4 +70,4 @@ chunk([1, 2, 3], 0); // Returns []
| ----------------- | ----------------------------------- | ----------------------------------- |
| es-toolkit | 238 bytes (92.4% smaller) | 9,338,821 times (11% slower) |
| es-toolkit/compat | 307 bytes (90.2% smaller) | 9,892,157 times (5% slower) |
| lodash-es | 3,153 bytes | 10,523,270 times |
| lodash-es | 3,153 bytes | 10,523,270 times |
20 changes: 16 additions & 4 deletions docs/zh_hans/reference/array/chunk.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);
// 返回: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]
```

## 試用

::: sandpack

```ts index.ts
import { chunk } from 'es-toolkit/array';

console.log(chunk([1, 2, 3, 4, 5], 2));
```

:::

## Lodash兼容性

从`es-toolkit/compat`中导入`chunk`以实现与lodash的完全兼容。
Expand All @@ -55,7 +67,7 @@ chunk([1, 2, 3], 0); // Returns []
## 性能对比

| | [包大小](../../bundle-size.md) | [性能](../../performance.md) |
| ----------------- | ------------------------------ | ----------------------------------- |
| es-toolkit | 238 字节 (小 92.4%) | 9,338,821 次 (慢 11%) |
| es-toolkit/compat | 307 字节 (小 90.2%) | 9,892,157 次 (慢 5%) |
| lodash-es | 3,153 字节 | 10,523,270 次 |
| ----------------- | ------------------------------ | ---------------------------- |
| es-toolkit | 238 字节 (小 92.4%) | 9,338,821 次 (慢 11%) |
| es-toolkit/compat | 307 字节 (小 90.2%) | 9,892,157 次 (慢 5%) |
| lodash-es | 3,153 字节 | 10,523,270 次 |
Loading