-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
191 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<template> | ||
<div | ||
class="var-snackbar" | ||
:style="{ alignItems, pointerEvents: forbidClick ? 'auto' : 'none' }" | ||
v-show="show" | ||
> | ||
<div | ||
:class="`var-snackbar__wrapper var-elevation--4 ${ | ||
vertical ? 'var-snackbar__vertical' : '' | ||
}`" | ||
:style="snackbarStyle" | ||
> | ||
<div :class="`var-snackbar__content ${contentClass}`"> | ||
<var-loading | ||
:type="loadingType" | ||
:size="loadingSize" | ||
v-if="type === 'loading'" | ||
/> | ||
<slot> | ||
{{ content }} | ||
</slot> | ||
</div> | ||
<div class="var-snackbar__action"> | ||
<var-button | ||
type="primary" | ||
size="small" | ||
v-if="['success', 'error', 'info', 'warning'].includes(type)" | ||
> | ||
{{ type }} | ||
</var-button> | ||
<slot name="action"></slot> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { | ||
defineComponent, | ||
reactive, | ||
computed, | ||
watch, | ||
ref, | ||
Ref, | ||
onMounted, | ||
} from 'vue' | ||
import Loading from '../loading' | ||
import Button from '../button' | ||
import { useZIndex } from '../context/zIndex' | ||
import { useTeleport } from '../utils/teleport' | ||
import { props, emits } from './propsEmits' | ||
import { useLock } from '../context/lock' | ||
export default defineComponent({ | ||
name: 'VarSnackbarCore', | ||
components: { | ||
[Loading.name]: Loading, | ||
[Button.name]: Button, | ||
}, | ||
props, | ||
emits, | ||
setup(props, ctx) { | ||
const timer: Ref<any> = ref(null) | ||
const { disabled } = useTeleport() | ||
const { zIndex } = useZIndex(props, 'show', 1) | ||
useLock(props, 'show', 'lockScroll') | ||
const alignItems = computed(() => { | ||
if (props.position === 'top') return 'flex-start' | ||
if (props.position === 'center') return 'center' | ||
if (props.position === 'bottom') return 'flex-end' | ||
}) | ||
const snackbarStyle = reactive({ | ||
backgroundColor: props.color, | ||
width: typeof props.width === 'string' ? props.width : props.width + 'px', | ||
height: | ||
typeof props.height === 'string' ? props.height : props.height + 'px', | ||
zIndex, | ||
}) | ||
watch( | ||
() => props.show, | ||
(show) => { | ||
if (show) { | ||
props.onOpen && props.onOpen() | ||
timer.value = setTimeout(() => { | ||
ctx.emit('update:show', false) | ||
}, props.duration) | ||
} else if (show === false) { | ||
props.onClose && props.onClose() | ||
} | ||
} | ||
) | ||
watch( | ||
() => props._update, | ||
() => { | ||
clearTimeout(timer.value) | ||
timer.value = setTimeout(() => { | ||
ctx.emit('update:show', false) | ||
}, props.duration) | ||
} | ||
) | ||
onMounted(() => { | ||
if (props.show) { | ||
props.onOpen && props.onOpen() | ||
timer.value = setTimeout(() => { | ||
ctx.emit('update:show', false) | ||
}, props.duration) | ||
} | ||
}) | ||
return { | ||
snackbarStyle, | ||
alignItems, | ||
disabled, | ||
} | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="less"> | ||
@import 'snackbarCore'; | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Snackbar = require('../../../cjs/snackbar-core').default | ||
const { render } = require('@testing-library/vue') | ||
|
||
test('test snackbar-core', async () => { | ||
const wrapper = render(Snackbar) | ||
console.log(wrapper) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import SnackbarCore from './SnackbarCore.vue' | ||
|
||
SnackbarCore.install = function (app: any) { | ||
app.component(SnackbarCore.name, SnackbarCore) | ||
} | ||
|
||
export default SnackbarCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
const Snackbar = require('../../../cjs/snackbar').default | ||
const SnackbarTransition = require('../../../cjs/snackbar-core-transition') | ||
.default | ||
const { render } = require('@testing-library/vue') | ||
|
||
test('test snackbar', async () => { | ||
const wrapper = render(Snackbar) | ||
test('test snackbarTransition', async () => { | ||
const wrapper = render(SnackbarTransition) | ||
console.log(wrapper) | ||
}) |
Oops, something went wrong.