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

fix(docs): [autocomplete] #10426

Merged
merged 1 commit into from Nov 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/.vitepress/config/plugins.ts
Expand Up @@ -5,6 +5,7 @@ import mdContainer from 'markdown-it-container'
import { docRoot } from '@element-plus/build-utils'
import externalLinkIcon from '../plugins/external-link-icon'
import tableWrapper from '../plugins/table-wrapper'
import { ApiTableContainer } from '../plugins/api-table'
import { highlight } from '../utils/highlight'
import type Token from 'markdown-it/lib/token'
import type Renderer from 'markdown-it/lib/renderer'
Expand Down Expand Up @@ -57,4 +58,6 @@ export const mdPlugin = (md: MarkdownIt) => {
}
},
} as ContainerOpts)

md.use(ApiTableContainer)
}
40 changes: 40 additions & 0 deletions docs/.vitepress/plugins/api-table.ts
@@ -0,0 +1,40 @@
import markdown from 'markdown-it'

import type MarkdownIt from 'markdown-it'

const ApiMd = new markdown()

export const ApiTableContainer = (md: MarkdownIt) => {
const fence = md.renderer.rules.fence!

ApiMd.renderer.rules = md.renderer.rules
md.renderer.rules.fence = (...args) => {
const [tokens, idx, ...rest] = args
const [options, env] = rest
const token = tokens[idx]
if (token.info === 'api') {
const newTokens = md.parse(token.content, env)

let result = ''
const { rules } = md.renderer
newTokens.forEach((newToken, idx) => {
const { type } = newToken
if (type === 'inline') {
result += md.renderer.renderInline(newToken.children!, options, env)
} else if (typeof rules[type] !== 'undefined') {
result += rules[newToken.type]!(
newTokens,
idx,
options,
env,
md.renderer
)
} else {
result += md.renderer.renderToken(newTokens, idx, options)
}
})
return result
}
return fence.call(md, ...args)
}
}
11 changes: 7 additions & 4 deletions docs/.vitepress/vitepress/components/globals/vp-api-function.vue
Expand Up @@ -22,10 +22,13 @@ const props = defineProps({

const mappedParams = computed(() =>
props.params
.reduce(
(params, [key, val]) => params.concat([`${key}: ${val}`]),
[] as string[]
)
.reduce((params, [key, val]) => {
let type = val
if (Array.isArray(val)) {
type = val.join(' | ')
}
return params.concat([`${key}: ${type}`])
}, [] as string[])
.join(', ')
)

Expand Down
24 changes: 20 additions & 4 deletions docs/en-US/component/autocomplete.md
Expand Up @@ -41,6 +41,8 @@ autocomplete/remote-search

### Attributes

```api

| Name | Description | Type | Default |
| --------------------------------- | -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------ |
| placeholder | the placeholder of Autocomplete | <StringType /> | — |
Expand All @@ -62,8 +64,12 @@ autocomplete/remote-search
| highlight-first-item | whether to highlight first item in remote search suggestions by default | <BooleanType /> | false |
| fit-input-width | whether the width of the dropdown is the same as the input | <BooleanType /> | false |

```

### Slots

```api

| Name | Description |
| ------- | --------------------------------------------------------------------- |
| default | Custom content for input suggestions. The scope parameter is { item } |
Expand All @@ -72,15 +78,23 @@ autocomplete/remote-search
| prepend | content to prepend before Input |
| append | content to append after Input |

```

### Events

| Name | Description | Type |
| ------ | ------------------------------------------------ | ---------------------------------------------------------------------------- |
| select | triggers when a suggestion is clicked | <FunctionType :params="[['item', '{ value: typeof modelValue } \| any']]" /> |
| change | triggers when the icon inside Input value change | <FunctionType :params="[['value', 'string \| number']]" /> |
```api

| Name | Description | Type |
| ------ | ------------------------------------------------ | ------------------------------------------------------------------------------ |
| select | triggers when a suggestion is clicked | <FunctionType :params="[['item', ['{ value: typeof modelValue }', 'any']]]" /> |
| change | triggers when the icon inside Input value change | <FunctionType :params="[['value', ['string', 'number']]]" /> |

```

### Instance Exposes

```api

| Name | Description | Type |
| ---------------- | ------------------------------------------- | -------------------------------------------------------------------- |
| activated | if autocomplete activated | <RefType type="boolean" /> |
Expand All @@ -95,3 +109,5 @@ autocomplete/remote-search
| loading | remote search loading indicator | <RefType type="boolean" /> |
| popperRef | el-tooltip component instance | <RefType type="ElTooltipInstance" /> |
| suggestions | fetch suggestions result | <RefType type="Record<string, any>" /> |

```