Skip to content
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
15 changes: 8 additions & 7 deletions script/create/constant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { resolve } from 'pathe'
export const PROJECT_DIR = process.cwd()
export const resolver = (dir: string) => resolve(PROJECT_DIR, dir)
export const createStoryComponent = (category: string, component: string) => `\

export const createStoryComponent = (category: CategoryType, component: ComponentType) => `\
<script setup lang="ts">
import type { ${component}Props } from 'element-plus'
</script>
Expand All @@ -17,21 +18,21 @@ import type { ${component}Props } from 'element-plus'
</Story>
</template>

<docs lang="md">
## Basic usage
${component} usage
</docs>

<style>
</style>
`

export const createStoryMd = (component: ComponentType) => `\
## ${component} Attributes
`

export const componentCollection = {
Basic: {
components: [
'Button',
'Border',
'Color',
'LayoutContainer',
'Container',
'Icon',
'Layout',
'Link',
Expand Down
29 changes: 20 additions & 9 deletions script/create/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs'
import { lowerFirst, upperFirst } from '../utils'
import type { CategoryType, ComponentType } from './constant'
import { categoryList, componentCollection, createStoryComponent, createStoryMd, resolver } from './constant'
import { getCategory } from './questions/category'
import { categoryList, componentCollection, createStoryComponent, resolver } from './constant'

export const getComponentChoices = async () => {
const category: CategoryType = await getCategory()
Expand Down Expand Up @@ -35,27 +35,38 @@ export const generateStoryDoc = (component: ComponentType) => {
return console.log(`${component} not a legal component of EP, please check and re-enter!`)

// 确定生成路径
const fileName = `${lowerFirst(component)}.story.vue`
const storyDocDir = resolver(`src/components/${category}/`)
const storyDocFile = resolver(`src/components/${category}/${fileName}`)
const fileVueName = `${lowerFirst(component)}.story.vue`
const fileMdName = `${lowerFirst(component)}.story.md`
const storyDocDir = resolver(`src/components/${category}/${component}`)
const storyDocFileVue = resolver(`src/components/${category}/${component}/${fileVueName}`)
const storyDocFileMd = resolver(`src/components/${category}/${component}/${fileMdName}`)

// 读取模板
const template = createStoryComponent(category, component)
const md = createStoryMd(component)
// 生成文件
try {
// 目录不存在则新建
if (!existsSync(storyDocDir))
mkdirSync(storyDocDir)

// 组件文档存在则退出
if (existsSync(storyDocFile)) {
console.log(`${fileName} Already existed!`)
if (existsSync(storyDocFileVue)) {
console.log(`${storyDocFileVue} Already existed!`)
return
}
writeFileSync(storyDocFile, template, { encoding: 'utf-8' })
writeFileSync(storyDocFileVue, template, { encoding: 'utf-8' })

console.log(`${fileName} Creation success!`)
console.log(`path: ${storyDocFile}`)
if (existsSync(storyDocFileMd)) {
console.log(`${storyDocFileMd} Already existed!`)
return
}
writeFileSync(storyDocFileMd, md, { encoding: 'utf-8' })

console.log(`${storyDocFileVue} Creation success!`)
console.log(`${storyDocFileMd} Creation success!`)
console.log(`path: ${storyDocFileVue}`)
console.log(`path: ${storyDocFileMd}`)
}
catch (e) {
console.error(e.toString())
Expand Down
2 changes: 1 addition & 1 deletion src/components/Basic/Button/button.story.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
| plain | determine whether it's a plain button | boolean | — | false |
| text <VersionTag version="2.2.0" /> | determine whether it's a text button | boolean | — | false |
| bg <VersionTag version="2.2.0" /> | determine whether the text button background color is always on | boolean | — | false |
| link <VersionTag version="2.2.1" /> | determine whether it's a link button | boolean | — | false |
| link | determine whether it's a link button | boolean | — | false |
| round | determine whether it's a round button | boolean | — | false |
| circle | determine whether it's a circle button | boolean | — | false |
| loading | determine whether it's loading | boolean | — | false |
Expand Down
53 changes: 53 additions & 0 deletions src/components/Basic/Container/container.story.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
## Container Attributes

| Name | Description | Type | Accepted Values | Default |
| --------- | ----------------------------------- | ------ | --------------------- | -------------------------------------------------------------------------- |
| direction | layout direction for child elements | string | horizontal / vertical | vertical when nested with `el-header` or `el-footer`; horizontal otherwise |

## Container Slots

| Name | Description | Subtags |
| ---- | ------------------------- | ------------------------------------------ |
| — | customize default content | Container / Header / Aside / Main / Footer |

## Header Attributes

| Name | Description | Type | Accepted Values | Default |
| ------ | -------------------- | ------ | --------------- | ------- |
| height | height of the header | string | — | 60px |

## Header Slots

| Name | Description |
| ---- | ------------------------- |
| — | customize default content |

## Aside Attributes

| Name | Description | Type | Accepted Values | Default |
| ----- | ------------------------- | ------ | --------------- | ------- |
| width | width of the side section | string | — | 300px |

## Aside Slots

| Name | Description |
| ---- | ------------------------- |
| — | customize default content |

## Main Slots

| Name | Description |
| ---- | ------------------------- |
| — | customize default content |

## Footer Attributes

| Name | Description | Type | Accepted Values | Default |
| ------ | -------------------- | ------ | --------------- | ------- |
| height | height of the footer | string | — | 60px |

## Footer Slots

| Name | Description |
| ---- | ------------------------- |
| — | customize default content |
60 changes: 60 additions & 0 deletions src/components/Basic/Container/container.story.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<script setup lang="ts">
import { ref } from 'vue'

const headerHeight = ref(60)
const footerHeight = ref(60)
const asideWidth = ref(100)
</script>

<template>
<Story title="Basic/Container" icon="carbon:container-software">
<Variant title="Basic Usage">
<div class="common-layout">
<el-container>
<el-header :height="`${headerHeight}px`">
Header
</el-header>
<el-container>
<el-aside :width="`${asideWidth}px`">
Aside
</el-aside>
<el-container>
<el-main>Main</el-main>
<el-footer :height="`${footerHeight}px`">
Footer
</el-footer>
</el-container>
</el-container>
</el-container>
</div>
<template #controls>
<HstNumber v-model="headerHeight" title="HeaderHeight" />
<HstNumber v-model="footerHeight" title="FooterHeight" />
<HstNumber v-model="asideWidth" title="AsideWidth" />
</template>
</Variant>
</Story>
</template>

<style>
.el-header, .el-footer {
background-color: #c6e2ff;
color: #333;
text-align: center;
line-height: 60px;
}

.el-aside {
background-color: #d9ecff;
color: #333;
text-align: center;
line-height: 200px;
}

.el-main {
background-color: #ecf5ff;
color: #333;
text-align: center;
line-height: 160px;
}
</style>