From 66043aa3b56ecdf2f19b03c463d081800cd51c35 Mon Sep 17 00:00:00 2001 From: msidolphin Date: Fri, 5 Nov 2021 18:10:07 +0800 Subject: [PATCH] refactor(components): [el-config-provider] improve componomponent extendiability (#4175) re #4146 added button configuration added useGlobalConfig hook --- docs/en-US/component/button.md | 25 ++++++------ docs/en-US/component/config-provider.md | 23 +++++++++-- docs/examples/config-provider/button.vue | 28 +++++++++++++ packages/components/button/src/button.ts | 8 +++- packages/components/button/src/button.vue | 10 +++-- .../__tests__/config-provider.spec.ts | 39 +++++++++++++++++-- .../config-provider/config-provider.ts | 17 -------- packages/components/config-provider/index.ts | 2 +- .../config-provider/src/config-provider.ts | 16 ++++++++ .../components/config-provider/src/index.ts | 14 +++++++ packages/hooks/index.ts | 1 + packages/hooks/use-global-config/index.ts | 13 +++++++ packages/hooks/use-locale/index.ts | 10 ++--- packages/tokens/config-provider.ts | 7 ++++ packages/tokens/index.ts | 1 + 15 files changed, 168 insertions(+), 46 deletions(-) create mode 100644 docs/examples/config-provider/button.vue delete mode 100644 packages/components/config-provider/config-provider.ts create mode 100644 packages/components/config-provider/src/config-provider.ts create mode 100644 packages/components/config-provider/src/index.ts create mode 100644 packages/hooks/use-global-config/index.ts create mode 100644 packages/tokens/config-provider.ts diff --git a/docs/en-US/component/button.md b/docs/en-US/component/button.md index 9ed120295c..b03cb940e0 100644 --- a/docs/en-US/component/button.md +++ b/docs/en-US/component/button.md @@ -77,18 +77,19 @@ button/size ## Button Attributes -| Attribute | Description | Type | Accepted Values | Default | -| ----------- | -------------------------------------- | ------------------ | -------------------------------------------------- | ------- | -| size | button size | string | medium / small / mini | — | -| type | button type | string | primary / success / warning / danger / info / text | — | -| plain | determine whether it's a plain 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 | -| disabled | disable the button | boolean | — | false | -| icon | icon component | string / Component | — | — | -| autofocus | same as native button's `autofocus` | boolean | — | false | -| native-type | same as native button's `type` | string | button / submit / reset | button | +| Attribute | Description | Type | Accepted Values | Default | +| ----------------- | ----------------------------------------------------------- | ------------------ | -------------------------------------------------- | ------- | +| size | button size | string | medium / small / mini | — | +| type | button type | string | primary / success / warning / danger / info / text | — | +| plain | determine whether it's a plain 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 | +| disabled | disable the button | boolean | — | false | +| icon | icon component | string / Component | — | — | +| autofocus | same as native button's `autofocus` | boolean | — | false | +| native-type | same as native button's `type` | string | button / submit / reset | button | +| auto-insert-space | automatically insert a space between two chinese characters | boolean | | — | ## Button Slots diff --git a/docs/en-US/component/config-provider.md b/docs/en-US/component/config-provider.md index 3928ad9df4..1fd300b8c7 100644 --- a/docs/en-US/component/config-provider.md +++ b/docs/en-US/component/config-provider.md @@ -17,12 +17,27 @@ config-provider/usage ::: +## button configurations + +:::demo Use two attributes to provide i18n related config + +config-provider/button + +::: + ## Config Provider Attributes -| Attribute | Description | Type | Accepted Values | Default | -| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------- | ------- | -| locale | Locale Object | Object\ | [languages](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang) | English | -| i18n | External translator, when this attribute is provided, it will be used at first, and it will fallback to default translator when this method returns nullish value | Function\<(...args: []) =\> string\> | - | - | +| Attribute | Description | Type | Accepted Values | Default | +| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------ | --------------------------------------------------------------------------------------- | ----------------------- | +| locale | Locale Object | Object\ | [languages](https://github.com/element-plus/element-plus/tree/dev/packages/locale/lang) | English | +| i18n | External translator, when this attribute is provided, it will be used at first, and it will fallback to default translator when this method returns nullish value | Function\<(...args: []) =\> string\> | - | - | +| button | button related configuration, [see the following table](#button-attributes) | ButtonGlobalConfig | - | see the following table | + +### Button Attributes + +| Attribute | Description | Type | Accepted Values | Default | +| --------------- | ----------------------------------------------------------- | ------- | --------------- | ------- | +| autoInsertSpace | automatically insert a space between two chinese characters | boolean | - | true | ## ConfigProvider Slots diff --git a/docs/examples/config-provider/button.vue b/docs/examples/config-provider/button.vue new file mode 100644 index 0000000000..067a094f80 --- /dev/null +++ b/docs/examples/config-provider/button.vue @@ -0,0 +1,28 @@ + + + diff --git a/packages/components/button/src/button.ts b/packages/components/button/src/button.ts index fc81dd41ab..b5a5c21d10 100644 --- a/packages/components/button/src/button.ts +++ b/packages/components/button/src/button.ts @@ -1,6 +1,5 @@ import { useFormItemProps } from '@element-plus/hooks' import { buildProps, definePropType } from '@element-plus/utils/props' - import type { ExtractPropTypes, Component } from 'vue' export const buttonType = [ @@ -37,8 +36,15 @@ export const buttonProps = buildProps({ autofocus: Boolean, round: Boolean, circle: Boolean, + autoInsertSpace: { + type: Boolean, + }, } as const) +export interface ButtonConfigContext { + autoInsertSpace?: boolean +} + export const buttonEmits = { click: (evt: MouseEvent) => evt instanceof MouseEvent, } diff --git a/packages/components/button/src/button.vue b/packages/components/button/src/button.vue index 522d5d30a0..77f17c2999 100644 --- a/packages/components/button/src/button.vue +++ b/packages/components/button/src/button.vue @@ -33,10 +33,9 @@