Skip to content

Commit

Permalink
feat: 完善tdesign-vue-next适配
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed Apr 25, 2023
1 parent 26835f6 commit ea4af42
Show file tree
Hide file tree
Showing 24 changed files with 334 additions and 128 deletions.
23 changes: 23 additions & 0 deletions packages/design/src/Badge.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<template>
<component class="tmagic-design-badge" :is="uiComponent.component" v-bind="uiProps">
<slot></slot>
</component>
</template>

<script setup lang="ts" name="TMBadge">
import { computed } from 'vue';
import { getConfig } from './config';
const props = defineProps<{
value?: string | number;
type?: 'primary' | 'success' | 'warning' | 'danger' | 'info';
max?: number;
isDot?: boolean;
hidden?: boolean;
}>();
const uiComponent = getConfig('components').badge;
const uiProps = computed(() => uiComponent.props(props));
</script>
6 changes: 6 additions & 0 deletions packages/design/src/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
<template #append v-if="$slots.append">
<slot name="append"></slot>
</template>
<template #prefix v-if="$slots.prefix">
<slot name="prefix"></slot>
</template>
<template #suffix v-if="$slots.suffix">
<slot name="suffix"></slot>
</template>
</component>
</template>

Expand Down
21 changes: 21 additions & 0 deletions packages/design/src/RadioButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<component class="tmagic-design-radio-button" :is="uiComponent.component" v-bind="uiProps">
<slot></slot>
</component>
</template>

<script setup lang="ts" name="TMRadioButton">
import { computed } from 'vue';
import { getConfig } from './config';
const props = defineProps<{
label?: string | number | boolean;
disabled?: boolean;
name?: string;
}>();
const uiComponent = getConfig('components').radioButton;
const uiProps = computed(() => uiComponent.props(props));
</script>
1 change: 1 addition & 0 deletions packages/design/src/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const props = defineProps<{
allowCreate?: boolean;
valueKey?: string;
remoteMethod?: any;
loading?: boolean;
size?: 'large' | 'default' | 'small';
}>();
Expand Down
10 changes: 10 additions & 0 deletions packages/design/src/defaultAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export default {
components: {
badge: {
component: 'el-badge',
props: (props: any) => props,
},

button: {
component: 'el-button',
props: (props: any) => props,
Expand Down Expand Up @@ -130,6 +135,11 @@ export default {
props: (props: any) => props,
},

radioButton: {
component: 'el-radio-button',
props: (props: any) => props,
},

radioGroup: {
component: 'el-radio-group',
props: (props: any) => props,
Expand Down
6 changes: 6 additions & 0 deletions packages/design/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './type';
export * from './config';

/* eslint-disable @typescript-eslint/no-unused-vars */
export { default as TMagicBadge } from './Badge.vue';
export { default as TMagicButton } from './Button.vue';
export { default as TMagicCard } from './Card.vue';
export { default as TMagicCascader } from './Cascader.vue';
Expand All @@ -33,6 +34,7 @@ export { default as TMagicOptionGroup } from './OptionGroup.vue';
export { default as TMagicPagination } from './Pagination.vue';
export { default as TMagicPopover } from './Popover.vue';
export { default as TMagicRadio } from './Radio.vue';
export { default as TMagicRadioButton } from './RadioButton.vue';
export { default as TMagicRadioGroup } from './RadioGroup.vue';
export { default as TMagicRow } from './Row.vue';
export { default as TMagicScrollbar } from './Scrollbar.vue';
Expand Down Expand Up @@ -95,6 +97,10 @@ export default {
tMagicMessageBox.close = options.messageBox?.close;
}

if (options.loading) {
app.directive('loading', options.loading);
}

app.config.globalProperties.$MAGIC_DESIGN = options;
setConfig(options);
},
Expand Down
13 changes: 13 additions & 0 deletions packages/design/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Directive } from 'vue';

export interface CascaderOption {
/** 指定选项的值为选项对象的某个属性值 */
value: any;
Expand Down Expand Up @@ -33,9 +35,20 @@ export interface TMagicMessageBox {
close(): void;
}

export type LoadingBinding = boolean;

const INSTANCE_KEY = Symbol('TdesignLoading');

export interface ElementLoading extends HTMLElement {
[INSTANCE_KEY]?: {
instance: any;
};
}

export interface PluginOptions {
message?: TMagicMessage;
messageBox?: TMagicMessageBox;
components?: Record<string, any>;
loading?: Directive<ElementLoading, LoadingBinding>;
[key: string]: any;
}
9 changes: 6 additions & 3 deletions packages/editor/src/components/SearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
size="small"
placeholder="输入关键字进行过滤"
clearable
:prefix-icon="Search"
@input="filterTextChangeHandler"
></TMagicInput>
>
<template #prefix>
<TMagicIcon><Search /></TMagicIcon>
</template>
</TMagicInput>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Search } from '@element-plus/icons-vue';
import { TMagicInput } from '@tmagic/design';
import { TMagicIcon, TMagicInput } from '@tmagic/design';
const emit = defineEmits(['search']);
Expand Down
19 changes: 10 additions & 9 deletions packages/editor/src/layouts/sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<template>
<TMagicTabs
<component
v-if="data.type === 'tabs' && data.items.length"
class="m-editor-sidebar"
v-model="activeTabName"
type="card"
tab-position="left"
class="m-editor-sidebar tmagic-design-tabs"
v-bind="tabsComponent.props({ type: 'card', tabPosition: 'left' })"
:is="tabsComponent.component"
>
<component
:is="uiComponent.component"
v-for="(config, index) in sideBarItems"
v-bind="tabPaneComponent.props({ name: config.text })"
:is="tabPaneComponent.component"
:key="config.$key || index"
:name="config.text"
>
<template #label>
<div :key="config.text">
Expand Down Expand Up @@ -80,14 +80,14 @@
</template>
</component>
</component>
</TMagicTabs>
</component>
</template>

<script lang="ts" setup name="MEditorSidebar">
import { computed, ref, watch } from 'vue';
import { Coin, EditPen, Files } from '@element-plus/icons-vue';
import { getConfig, TMagicTabs } from '@tmagic/design';
import { getConfig } from '@tmagic/design';
import MIcon from '@editor/components/Icon.vue';
import type { MenuButton, MenuComponent, SideComponent, SideItem } from '@editor/type';
Expand All @@ -107,7 +107,8 @@ const props = withDefaults(
},
);
const uiComponent = getConfig('components').tabPane;
const tabPaneComponent = getConfig('components').tabPane;
const tabsComponent = getConfig('components').tabs;
const activeTabName = ref(props.data?.status);
Expand Down
32 changes: 26 additions & 6 deletions packages/editor/src/theme/sidebar.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
.m-editor-sidebar {
.m-editor-sidebar.tmagic-design-tabs {
height: 100%;

&.el-tabs--left .el-tabs__header {
.el-tabs__header,
.t-tabs__header {
background: $--sidebar-heder-background-color;
border: 0;
height: 100%;

.t-tabs__nav--card {
background-color: transparent;
}

&.is-left {
.t-tabs__nav--card.t-tabs__nav-item:not(.t-is-disabled):not(
.t-is-active
):hover {
background-color: transparent;
}

&.is-left,
&.t-is-left {
width: 40px;
margin-right: 0;
}
Expand All @@ -23,16 +36,19 @@
margin-left: 2px;
}

.el-tabs__item.is-left {
.el-tabs__item.is-left,
.t-tabs__nav-item {
line-height: 15px;
border: 0;
height: auto;
padding: 8px;
color: rgb(255, 255, 255);
box-sizing: border-box;

&.is-left {
&.is-active {
&.is-left,
&.t-is-left {
&.is-active,
&.t-is-active {
background: $--sidebar-content-background-color;
border: 0;

Expand All @@ -51,6 +67,10 @@
}
}

.t-tabs__nav-item {
padding: 7px;
}

i {
font-size: 25px;
color: rgba(255, 255, 255, 0.6);
Expand Down
12 changes: 12 additions & 0 deletions packages/element-plus-adapter/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ElBadge,
ElButton,
ElCard,
ElCascader,
Expand Down Expand Up @@ -27,6 +28,7 @@ import {
ElPagination,
ElPopover,
ElRadio,
ElRadioButton,
ElRadioGroup,
ElRow,
ElScrollbar,
Expand All @@ -49,6 +51,11 @@ const adapter: any = {
message: ElMessage,
messageBox: ElMessageBox,
components: {
badge: {
component: ElBadge,
props: (props: any) => props,
},

button: {
component: ElButton,
props: (props: any) => props,
Expand Down Expand Up @@ -179,6 +186,11 @@ const adapter: any = {
props: (props: any) => props,
},

radioButton: {
component: ElRadioButton,
props: (props: any) => props,
},

radioGroup: {
component: ElRadioGroup,
props: (props: any) => props,
Expand Down
Loading

0 comments on commit ea4af42

Please sign in to comment.