mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-17 11:49:41 +08:00
feat(components): [el-button-group] add type prop (#3702)
* feat(components): [el-button-group] add type prop * fix breadcrumb import
This commit is contained in:
parent
8583c70fdc
commit
93f0a35905
@ -152,4 +152,23 @@ describe('Button Group', () => {
|
|||||||
wrapper.findAll('.el-button-group button.el-button--mini').length
|
wrapper.findAll('.el-button-group button.el-button--mini').length
|
||||||
).toBe(1)
|
).toBe(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('button group type', async () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
setup() {
|
||||||
|
return () =>
|
||||||
|
h(ButtonGroup, { type: 'warning' }, () => [
|
||||||
|
h(Button, { type: 'primary' }, () => 'Prev'),
|
||||||
|
h(Button, {}, () => 'Next'),
|
||||||
|
])
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(wrapper.classes()).toContain('el-button-group')
|
||||||
|
expect(
|
||||||
|
wrapper.findAll('.el-button-group button.el-button--primary').length
|
||||||
|
).toBe(1)
|
||||||
|
expect(
|
||||||
|
wrapper.findAll('.el-button-group button.el-button--warning').length
|
||||||
|
).toBe(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
9
packages/components/button/src/button-group.ts
Normal file
9
packages/components/button/src/button-group.ts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import { buttonProps } from './button'
|
||||||
|
|
||||||
|
import type { ExtractPropTypes } from 'vue'
|
||||||
|
|
||||||
|
export const buttonGroupProps = {
|
||||||
|
size: buttonProps.size,
|
||||||
|
type: buttonProps.type,
|
||||||
|
} as const
|
||||||
|
export type ButtonGroupProps = ExtractPropTypes<typeof buttonGroupProps>
|
@ -6,24 +6,18 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, provide, reactive, toRef } from 'vue'
|
import { defineComponent, provide, reactive, toRef } from 'vue'
|
||||||
import { elButtonGroupKey } from '@element-plus/tokens'
|
import { elButtonGroupKey } from '@element-plus/tokens'
|
||||||
import { isValidComponentSize } from '@element-plus/utils/validators'
|
import { buttonGroupProps } from './button-group'
|
||||||
|
|
||||||
import type { PropType } from 'vue'
|
|
||||||
import type { ComponentSize } from '@element-plus/utils/types'
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'ElButtonGroup',
|
name: 'ElButtonGroup',
|
||||||
props: {
|
props: buttonGroupProps,
|
||||||
size: {
|
|
||||||
type: String as PropType<ComponentSize>,
|
|
||||||
validator: isValidComponentSize,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
setup(props) {
|
setup(props) {
|
||||||
provide(
|
provide(
|
||||||
elButtonGroupKey,
|
elButtonGroupKey,
|
||||||
reactive({
|
reactive({
|
||||||
size: toRef(props, 'size'),
|
size: toRef(props, 'size'),
|
||||||
|
type: toRef(props, 'type'),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
@ -11,6 +11,7 @@ export const buttonType = [
|
|||||||
'info',
|
'info',
|
||||||
'danger',
|
'danger',
|
||||||
'text',
|
'text',
|
||||||
|
'',
|
||||||
] as const
|
] as const
|
||||||
export const buttonSize = ['', 'large', 'medium', 'small', 'mini'] as const
|
export const buttonSize = ['', 'large', 'medium', 'small', 'mini'] as const
|
||||||
export const buttonNativeType = ['button', 'submit', 'reset'] as const
|
export const buttonNativeType = ['button', 'submit', 'reset'] as const
|
||||||
@ -20,7 +21,7 @@ export const buttonProps = {
|
|||||||
type: buildProp({
|
type: buildProp({
|
||||||
type: String,
|
type: String,
|
||||||
values: buttonType,
|
values: buttonType,
|
||||||
default: 'default',
|
default: '',
|
||||||
} as const),
|
} as const),
|
||||||
icon: {
|
icon: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<button
|
<button
|
||||||
:class="[
|
:class="[
|
||||||
'el-button',
|
'el-button',
|
||||||
type ? 'el-button--' + type : '',
|
buttonType ? 'el-button--' + buttonType : '',
|
||||||
buttonSize ? 'el-button--' + buttonSize : '',
|
buttonSize ? 'el-button--' + buttonSize : '',
|
||||||
{
|
{
|
||||||
'is-disabled': buttonDisabled,
|
'is-disabled': buttonDisabled,
|
||||||
@ -40,6 +40,9 @@ export default defineComponent({
|
|||||||
const { size: buttonSize, disabled: buttonDisabled } = useFormItem({
|
const { size: buttonSize, disabled: buttonDisabled } = useFormItem({
|
||||||
size: computed(() => elBtnGroup?.size),
|
size: computed(() => elBtnGroup?.size),
|
||||||
})
|
})
|
||||||
|
const buttonType = computed(
|
||||||
|
() => props.type || elBtnGroup?.type || 'default'
|
||||||
|
)
|
||||||
|
|
||||||
const elForm = inject(elFormKey, undefined)
|
const elForm = inject(elFormKey, undefined)
|
||||||
|
|
||||||
@ -52,7 +55,9 @@ export default defineComponent({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
buttonSize,
|
buttonSize,
|
||||||
|
buttonType,
|
||||||
buttonDisabled,
|
buttonDisabled,
|
||||||
|
|
||||||
handleClick,
|
handleClick,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import type { InjectionKey } from 'vue'
|
import type { InjectionKey } from 'vue'
|
||||||
import type { BreadcrumbProps } from '@element-plus/components/breadcrumb/src/breadcrumb'
|
import type { BreadcrumbProps } from '@element-plus/components/breadcrumb'
|
||||||
|
|
||||||
export const elBreadcrumbKey: InjectionKey<BreadcrumbProps> =
|
export const elBreadcrumbKey: InjectionKey<BreadcrumbProps> =
|
||||||
Symbol('elBreadcrumbKey')
|
Symbol('elBreadcrumbKey')
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import type { InjectionKey } from 'vue'
|
import type { InjectionKey } from 'vue'
|
||||||
|
|
||||||
import type { ComponentSize } from '@element-plus/utils/types'
|
import type { ButtonProps } from '@element-plus/components/button'
|
||||||
|
|
||||||
export interface ElButtonGroupContext {
|
export interface ElButtonGroupContext {
|
||||||
size?: ComponentSize
|
size?: ButtonProps['size']
|
||||||
|
type?: ButtonProps['type']
|
||||||
}
|
}
|
||||||
|
|
||||||
export const elButtonGroupKey: InjectionKey<ElButtonGroupContext> = Symbol()
|
export const elButtonGroupKey: InjectionKey<ElButtonGroupContext> = Symbol()
|
||||||
|
Loading…
Reference in New Issue
Block a user