Skip to content

Commit ed1fc05

Browse files
committed
docs: demo inside iframe
1 parent 2b185fd commit ed1fc05

File tree

7 files changed

+86
-26
lines changed

7 files changed

+86
-26
lines changed

.github/workflows/release-docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ jobs:
2121

2222
- run: yarn install
2323
- run: yarn build
24+
- run: |
25+
cd demo
26+
yarn install
27+
yarn build-all
2428
- run: |
2529
cd docs
2630
yarn install

demo/vite.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ const flavor = process.env.VITE_FLAVOR
77

88
// https://vitejs.dev/config/
99
export default defineConfig({
10-
base: flavor,
10+
base: `demo/${flavor}`,
1111
plugins: [vue()],
1212
resolve: {
1313
alias: {
1414
'@': fileURLToPath(new URL('./src', import.meta.url)),
1515
},
1616
},
1717
build: {
18-
outDir: `../docs/src/.vuepress/public/${flavor}`,
18+
outDir: `../docs/src/.vuepress/public/demo/${flavor}`,
1919
},
2020
})

docs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ config.local.js
1212
basement_dist
1313
.cache
1414
.temp
15+
16+
src/.vuepress/public/demo

docs/src/.vuepress/client.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,33 @@ import 'element-plus/dist/index.css'
1818

1919
import Ant from 'ant-design-vue'
2020
// import 'ant-design-vue/dist/antd.css'
21-
import '../styles/antd.css'
21+
// import '../styles/antd.css'
2222

2323
import { defineClientConfig } from '@vuepress/client'
2424

2525
import { variables } from './vars'
2626

27+
function prefersDark() {
28+
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
29+
}
30+
2731
export default defineClientConfig({
2832
enhance ({ app, router, siteData }) {
33+
const myTheme = {
34+
dark: prefersDark(),
35+
colors: {
36+
secondary: '#3AA675',
37+
},
38+
}
39+
2940
const vuetify = createVuetify({
3041
components,
3142
directives,
32-
ssr: true
43+
ssr: true,
44+
theme: {
45+
defaultTheme: 'myTheme',
46+
themes: {myTheme}
47+
}
3348
})
3449

3550
app.use(vuetify)

docs/src/.vuepress/components/cron-demo.vue

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
color="secondary"
88
group
99
density="compact"
10-
class="mb-2 elevation-5">
10+
class="mb-5 elevation-5">
1111

1212
<v-btn v-for="item in flavors" :value="item.name" :key="item.name" @click="flavor = item">
1313
{{item.name}}
@@ -22,67 +22,97 @@
2222
color="secondary"
2323
group
2424
density="compact"
25-
class="mb-10 elevation-5">
25+
class="mb-5 elevation-5">
2626

2727
<v-btn v-for="item in locales" :value="item" :key="item">
2828
{{item}}
2929
</v-btn>
30+
</v-btn-toggle>
31+
32+
<p>Format</p>
33+
<v-btn-toggle
34+
v-model="format"
35+
tile
36+
color="secondary"
37+
group
38+
density="compact"
39+
class="mb-10 elevation-5">
40+
41+
<v-btn v-for="item in formats" :value="item" :key="item">
42+
{{item}}
43+
</v-btn>
3044

3145
</v-btn-toggle>
3246

33-
<p class="mb-2">
34-
<template v-for="l in locales" :key=l>
35-
<component v-if="l == locale" :is="flavor.component" v-model="value" :locale="locale"></component>
36-
</template>
37-
</p>
38-
<p class="text-lightest mb-5">
39-
cron expression: {{value}}
40-
</p>
47+
<iframe :src="src"></iframe>
4148

4249
</div>
4350
</template>
4451

4552
<script>
46-
import { ref } from 'vue'
53+
import { withBase, } from '@vuepress/client'
54+
import { computed, ref } from 'vue'
4755
4856
export default {
49-
setup () {
57+
props: {
58+
index: {
59+
type: Number,
60+
default: 0,
61+
}
62+
},
63+
setup (props) {
5064
const flavors = [
5165
{
5266
name: 'Light',
53-
component: 'cron-light'
5467
},
5568
{
5669
name: 'Vuetify',
57-
component: 'cron-vuetify'
5870
},
5971
{
6072
name: 'Element Plus',
61-
component: 'cron-element-plus'
6273
},
6374
{
6475
name: 'Ant',
65-
component: 'cron-ant'
76+
},
77+
{
78+
name: 'Quasar',
6679
}
6780
]
68-
6981
const locales = ['en', 'de', 'pt', 'es', 'da', 'zh-cn']
70-
71-
const flavor = flavors[0]
82+
const formats = ['crontab', 'quartz']
83+
84+
const flavor = ref(flavors[props.index])
85+
const locale = ref('en')
86+
const format = ref(formats[0])
7287
7388
const selectFlavor = (name) => {
7489
let i = flavors.map(f => f.name).indexOf(name)
7590
i = i >= 0 ? i : 0
7691
return flavors[i]
7792
}
7893
94+
const src = computed(() => {
95+
const params = {
96+
locale: locale.value,
97+
format: format.value,
98+
'initial-value': format.value == 'quartz' ? '* * * * * *' : '* * * * *'
99+
}
100+
const query = new URLSearchParams(params)
101+
const path = 'demo/' + flavor.value.name.replace(' ', '-').toLowerCase() + '/index.html?' + query.toString()
102+
103+
return withBase(path)
104+
})
105+
79106
return {
80-
flavor: ref(flavor),
107+
src,
108+
flavor: flavor,
81109
flavors,
82110
selectFlavor,
83111
text: ref(flavor.name),
84112
locales,
85-
locale: ref('en'),
113+
locale: locale,
114+
formats,
115+
format,
86116
value: ref('* * * * *')
87117
}
88118
}

docs/src/.vuepress/styles/index.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@
1616

1717
.text-lightest {
1818
color: var(--c-text-lightest)
19+
}
20+
21+
iframe {
22+
width: 100%;
23+
height: 500px;
24+
border: none;
25+
overflow: hidden;
26+
border-radius: 15px;
1927
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"dry-run": "multi-semantic-release --dry-run --ignore-private-packages",
3535
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts",
3636
"lint-fix": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix",
37-
"build-readme": "npx cron-cli readme ."
37+
"build-readme": "npx cron-cli readme .",
38+
"build-demo": "cd demo && yarn build-all"
3839
},
3940
"devDependencies": {
4041
"@babel/core": "^7.12.13",

0 commit comments

Comments
 (0)