feat(button): tag prop

This commit is contained in:
07akioni 2021-05-19 12:03:35 +08:00
parent 7b9bd91f2e
commit b792f0b529
10 changed files with 60 additions and 37 deletions

View File

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## Pending
### Feats
- `n-button` add `tag` prop.
## 2.8.0 ## 2.8.0
### Perf ### Perf

View File

@ -1,5 +1,11 @@
# CHANGELOG # CHANGELOG
## Pending
### Feats
- `n-button` 新增 `tag` 属性
## 2.8.0 ## 2.8.0
### Perf ### Perf

View File

@ -9,6 +9,7 @@ basic
dashed dashed
size size
text text
tag
disabled disabled
icon icon
events events

View File

@ -0,0 +1,14 @@
# Tag
You can render button as different tags. For example `<a />`. 你可以把按钮渲染成不同的标签,比如 `<a />`
```html
<n-button
text
tag="a"
href="https://anyway.fm/news.php"
target="_blank"
type="primary"
>Anyway.News</n-button
>
```

View File

@ -1,6 +1,6 @@
# Text Button # Text Button
Somebody also calls it `link` button. Just look like text.
```html ```html
<n-button text> <n-button text>

View File

@ -9,6 +9,7 @@ basic
dashed dashed
size size
text text
tag
disabled disabled
icon icon
events events

View File

@ -0,0 +1,14 @@
# 标签
你可以把按钮渲染成不同的标签,比如 `<a />`
```html
<n-button
text
tag="a"
href="https://anyway.fm/news.php"
target="_blank"
type="primary"
>安妮薇时报</n-button
>
```

View File

@ -1,6 +1,6 @@
# 文本按钮 # 文本按钮
有些人也会叫他 `link` 按钮 长得就像文本
```html ```html
<n-button text> <n-button text>

View File

@ -31,35 +31,14 @@ import style from './styles/button.cssr'
const buttonProps = { const buttonProps = {
...(useTheme.props as ThemeProps<ButtonTheme>), ...(useTheme.props as ThemeProps<ButtonTheme>),
color: String, color: String,
text: { text: Boolean,
type: Boolean, block: Boolean,
default: false loading: Boolean,
}, disabled: Boolean,
block: { circle: Boolean,
type: Boolean,
default: false
},
loading: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
},
circle: {
type: Boolean,
default: false
},
size: String as PropType<Size>, size: String as PropType<Size>,
ghost: { ghost: Boolean,
type: Boolean, round: Boolean,
default: false
},
round: {
type: Boolean,
default: false
},
focusable: { focusable: {
type: Boolean, type: Boolean,
default: true default: true
@ -68,14 +47,15 @@ const buttonProps = {
type: Boolean, type: Boolean,
default: true default: true
}, },
tag: {
type: String as PropType<keyof HTMLElementTagNameMap>,
default: 'button'
},
type: { type: {
type: String as PropType<Type>, type: String as PropType<Type>,
default: 'default' default: 'default'
}, },
dashed: { dashed: Boolean,
type: Boolean,
default: false
},
iconPlacement: { iconPlacement: {
type: String as PropType<'left' | 'right'>, type: String as PropType<'left' | 'right'>,
default: 'left' default: 'left'
@ -389,9 +369,9 @@ export default defineComponent({
} }
}, },
render () { render () {
const { $slots, mergedClsPrefix } = this const { $slots, mergedClsPrefix, tag: Component } = this
return ( return (
<button <Component
ref="selfRef" ref="selfRef"
class={[ class={[
`${mergedClsPrefix}-button`, `${mergedClsPrefix}-button`,
@ -470,7 +450,7 @@ export default defineComponent({
style={this.customColorCssVars as CSSProperties} style={this.customColorCssVars as CSSProperties}
/> />
) : null} ) : null}
</button> </Component>
) )
} }
}) })

View File

@ -58,6 +58,7 @@ export default c([
user-select: none; user-select: none;
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
text-decoration: none;
transition: transition:
color .3s var(--bezier), color .3s var(--bezier),
background-color .3s var(--bezier), background-color .3s var(--bezier),