Skip to content

Commit

Permalink
fix: make imperative component calls respect global theme config
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Jan 19, 2024
1 parent 7d3e8b6 commit 6f86aa4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
13 changes: 1 addition & 12 deletions packages/veui-theme-dls/components/toast-list.less
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,7 @@
align-items: center;
flex-flow: column;

.@{veui-prefix}-toast {
.veui-transition(opacity, top, transform);
transform: translateY(0);
& > div {
margin-bottom: @dls-toast-spacing;

&-enter,
&-leave-to {
opacity: 0;
}

&-enter {
transform: translateY(-100%);
}
}
}
11 changes: 11 additions & 0 deletions packages/veui-theme-dls/components/toast.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
background-color: @dls-toast-background-color;
color: @dls-toast-font-color;
box-shadow: @dls-toast-shadow;
transform: translateY(0);
.veui-transition(opacity, top, transform);

&-enter,
&-leave-to {
opacity: 0;
}

&-enter {
transform: translateY(-100%);
}

&-multiline {
.padding(@dls-toast-padding-y, _);
Expand Down
9 changes: 6 additions & 3 deletions packages/veui/demo/cases/Plugins.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
</template>

<script>
import config from '@/managers/config'
config.set({ theme: 'ai' })
export default {
name: 'plugins-demo',
components: {},
Expand All @@ -25,7 +29,7 @@ export default {
methods: {
handleToast () {
this.$toast.info('我是提示', {
theme: 'ai'
theme: Math.random() > 0.5 ? 'd20' : 'ai'
})
},
async handleRemove () {
Expand Down Expand Up @@ -53,8 +57,7 @@ export default {
})
},
okLabel: '恢复它',
cancelLabel: '不恢复它',
theme: 'ai'
cancelLabel: '不恢复它'
})
},
async handlePromptInput () {
Expand Down
5 changes: 3 additions & 2 deletions packages/veui/src/components/Toast.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<transition :name="$c('toast')" appear>
<transition :name="$c('toast')" :appear="appear">
<div
v-if="realOpen"
:ui="realUi"
Expand Down Expand Up @@ -90,7 +90,8 @@ export default {
open: Boolean,
duration: {
type: Number
}
},
appear: Boolean
},
data () {
return {
Expand Down
1 change: 1 addition & 0 deletions packages/veui/src/components/ToastList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default {
<Toast
key={m.__message_id__}
open
appear
status={m.status || m.type}
message={typeof m.message === 'string' ? m.message : null}
closable={m.closable}
Expand Down
6 changes: 5 additions & 1 deletion packages/veui/src/managers/simple-dialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import { remove } from 'lodash'
import config from './config'

export default class SimpleDialog {
components = []
Expand All @@ -12,7 +13,10 @@ export default class SimpleDialog {
}

create (data) {
const component = this.createComponent(data)
const component = this.createComponent({
theme: config.get('theme'),
...data
})
const el = document.createElement('div')
document.body.appendChild(el)
component.$mount(el)
Expand Down
8 changes: 5 additions & 3 deletions packages/veui/src/managers/toast.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Vue from 'vue'
import { isString, isObject, isNumber } from 'lodash'
import ToastList from '../components/ToastList'
import warn from '../utils/warn'
import config from './config'

let Container = Vue.extend(ToastList)

Expand All @@ -22,11 +23,13 @@ export class ToastManager {
this.init()
}

const theme = config.get('theme')

let messages = []
if (Array.isArray(option)) {
messages = option.map((item) => this.container.add(item))
messages = option.map((item) => this.container.add({ theme, ...item }))
} else if (isObject(option)) {
messages = [this.container.add(option)]
messages = [this.container.add({ theme, ...option })]
} else {
warn('[toast-manager] Invalid arguments for Toasts.')
}
Expand All @@ -48,7 +51,6 @@ export class ToastManager {
}

show (message, status) {
console.log(status)
let options = {}
if (isObject(message)) {
options = { ...message }
Expand Down

1 comment on commit 6f86aa4

@vercel
Copy link

@vercel vercel bot commented on 6f86aa4 Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

veui – ./

veui-git-main-ecomfe.vercel.app
veui-demo.vercel.app
main.veui.dev
veui-ecomfe.vercel.app

Please sign in to comment.