diff --git a/packages/docs/global.md b/packages/docs/global.md new file mode 100644 index 0000000000000000000000000000000000000000..304d9c082fdb569b818fc5cb219a8af7fe47cab5 --- /dev/null +++ b/packages/docs/global.md @@ -0,0 +1,10 @@ +# 全局配置 + +## 方法 + +| name | type | 默认值 | 说明 | +| :------ | :---------- | :-------- | :----------------------------------- | +| shape | ShapeT | 'normal' | 形状: large \| normal \| small | +| size | SizeT | 'normal' | 形状 normal \| round | +| type | ButtonTypeT | 'outline' | 形状 primary \|outline\| text \|link | +| loading | boolean | false | 加载状态 | diff --git a/packages/opendesign/src/components/_shared/dom.ts b/packages/opendesign/src/components/_shared/dom.ts index 879a065f0636a417251ba79cdbf67afc8f688622..4af7fb196e8f582d85ab67c8d9c7f08b57f20142 100644 --- a/packages/opendesign/src/components/_shared/dom.ts +++ b/packages/opendesign/src/components/_shared/dom.ts @@ -1,3 +1,5 @@ +import { isArray } from './utils'; + export type DirectionT = 'left' | 'right' | 'top' | 'bottom'; export function isElement(el: any) { @@ -79,7 +81,7 @@ export function getElementBorder(el: HTMLElement, dir?: DirectionT | DirectionT[ if (typeof dir === 'string') { d = [dir]; } else { - d = Array.isArray(dir) ? dir : ['left', 'right', 'bottom', 'top']; + d = isArray(dir) ? dir : ['left', 'right', 'bottom', 'top']; } const rlt: { left?: number, diff --git a/packages/opendesign/src/components/_shared/export.ts b/packages/opendesign/src/components/_shared/export.ts new file mode 100644 index 0000000000000000000000000000000000000000..03cc56910ac84dbaaa403028d218d925bb1b89e3 --- /dev/null +++ b/packages/opendesign/src/components/_shared/export.ts @@ -0,0 +1,7 @@ +export { initSize, initShape } from './global'; + +export { + initLoadingIcon, + initLinkArrowIcon, + initLinkPrefixIcon +} from './icons'; \ No newline at end of file diff --git a/packages/opendesign/src/components/_shared/global.ts b/packages/opendesign/src/components/_shared/global.ts index f86e3eca8fa2004c9c239a57eddaa55d21358f79..f6e0c94417577af5951dc0576b6a3132c6b1bea2 100644 --- a/packages/opendesign/src/components/_shared/global.ts +++ b/packages/opendesign/src/components/_shared/global.ts @@ -2,18 +2,14 @@ import { ref } from 'vue'; // 尺寸 export type SizeT = 'large' | 'normal' | 'small' - export const defaultSize = ref('normal'); - export function initSize(type: SizeT) { defaultSize.value = type; } // 形状 export type ShapeT = 'round' | 'normal' - export const defaultShape = ref('normal'); - export function initShape(type: ShapeT) { defaultShape.value = type; -} +} \ No newline at end of file diff --git a/packages/opendesign/src/components/_shared/icons.ts b/packages/opendesign/src/components/_shared/icons.ts index 4b46b1b1ffcd40e8f5130c79862dca018ea2b60b..27320a3ab9b3c2a25158422c09227d97e40b1ef9 100644 --- a/packages/opendesign/src/components/_shared/icons.ts +++ b/packages/opendesign/src/components/_shared/icons.ts @@ -1,30 +1,33 @@ /** * 定义全局图标,支持全局初始化自定义 */ -import { IconLoading, IconLink, IconArrowRight } from '../icons'; -import type { Component } from 'vue'; +import { Component, shallowRef } from 'vue'; +import { + IconLoading as _IconLoading, + IconLink as IconLink, + IconArrowRight +} from '../icons'; -let iLoading: Component = IconLoading; -export function setLoadingIcon(icon: Component) { - iLoading = icon; -} -export function getLoadingIcon() { - return iLoading; +/** + * 全局loading图标 + */ +export const IconLoading = shallowRef(_IconLoading); +export function initLoadingIcon(icon: Component) { + IconLoading.value = icon; } - -let iLink: Component = IconLink; -export function setLinkIcon(icon: Component) { - iLink = icon; -} -export function getLinkIcon() { - return iLink; +/** + * link前缀图标 + */ +export const IconLinkPrefix = shallowRef(IconLink); +export function initLinkPrefixIcon(icon: Component) { + IconLinkPrefix.value = icon; } -let iLinkArrow: Component = IconArrowRight; -export function setLinkArrowIcon(icon: Component) { - iLinkArrow = icon; -} -export function getLinkArrowIcon() { - return iLinkArrow; +/** + * link箭头图标 + */ +export const IconLinkArrow = shallowRef(IconArrowRight); +export function initLinkArrowIcon(icon: Component) { + IconLinkArrow.value = icon; } \ No newline at end of file diff --git a/packages/opendesign/src/components/button/OButton.vue b/packages/opendesign/src/components/button/OButton.vue index c857ebc7f2c9b477b0ff567efb0dbffa420f0596..74885620d3527a2fca5ea8389389d2e7d26c9113 100644 --- a/packages/opendesign/src/components/button/OButton.vue +++ b/packages/opendesign/src/components/button/OButton.vue @@ -2,7 +2,7 @@ import { defaultSize, defaultShape } from '../_shared/global'; import type { SizeT, ShapeT } from '../_shared/global'; import { ButtonTypeT } from './types'; -import { getLoadingIcon } from '../_shared/icons'; +import { IconLoading } from '../_shared/icons'; interface ButtonPropT { /** @@ -24,10 +24,9 @@ interface ButtonPropT { } const props = withDefaults(defineProps(), { type: 'outline', - size: defaultSize.value, - shape: defaultShape.value, + size: undefined, + shape: undefined, }); -const IconLoading = getLoadingIcon();