Initial commit of akmon project
This commit is contained in:
36
uni_modules/lime-overlay/components/l-overlay/index.scss
Normal file
36
uni_modules/lime-overlay/components/l-overlay/index.scss
Normal file
@@ -0,0 +1,36 @@
|
||||
@import '~@/uni_modules/lime-style/index.scss';
|
||||
$prefix: l !default;
|
||||
$overlay: #{$prefix}-overlay;
|
||||
|
||||
|
||||
$overlay-bg-color: create-var(overlay-bg-color, rgba(0, 0, 0, 0.6));
|
||||
$overlay-z-index: create-var(overlay-z-index, 998);
|
||||
$overlay-transition-duration: create-var(overlay-transition-duration, 300ms);
|
||||
/* #ifndef APP-ANDROID || APP-IOS || APP-NVUE || APP-HARMONY */
|
||||
$overlay-blur: blur(create-var(overlay-blur, 4px));
|
||||
/* #endif */
|
||||
|
||||
.#{$overlay}{
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
bottom: 0;
|
||||
background-color: $overlay-bg-color;
|
||||
transition-duration: $overlay-transition-duration;
|
||||
transition-property: opacity;
|
||||
transition-timing-function: ease;
|
||||
z-index: $overlay-z-index;
|
||||
opacity: 1; // uniapp x ios 必须要设置
|
||||
/* #ifndef APP-ANDROID || APP-IOS || APP-NVUE || APP-HARMONY */
|
||||
backdrop-filter: $overlay-blur;
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.l-fade-enter {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.l-fade-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
80
uni_modules/lime-overlay/components/l-overlay/l-overlay.uvue
Normal file
80
uni_modules/lime-overlay/components/l-overlay/l-overlay.uvue
Normal file
@@ -0,0 +1,80 @@
|
||||
<template>
|
||||
<view v-if="inited"
|
||||
class="l-overlay"
|
||||
ref="overlayRef"
|
||||
:class="[lClass, classes]"
|
||||
:style="[styles, lStyle]"
|
||||
@click.stop="onClick"
|
||||
@touchmove.stop="noop"
|
||||
@transitionend="finished"
|
||||
:aria-role="ariaRole"
|
||||
:aria-label="ariaLabel">
|
||||
<slot></slot>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="uts" setup>
|
||||
import { useTransition, UseTransitionOptions, TransitionEmitStatus } from '@/uni_modules/lime-transition';
|
||||
import { OverlayProps } from './type';
|
||||
defineOptions({
|
||||
name:'l-overlay'
|
||||
})
|
||||
|
||||
const props = withDefaults(defineProps<OverlayProps>(), {
|
||||
ariaLabel: '关闭',
|
||||
ariaRole: 'button',
|
||||
preventScrollThrough: true,
|
||||
zIndex: 998,
|
||||
visible: false,
|
||||
duration: 300,
|
||||
})
|
||||
|
||||
const emit = defineEmits(['click', 'before-enter', 'enter', 'after-enter', 'before-leave', 'leave', 'after-leave'])
|
||||
|
||||
const {inited, display, classes, finished} = useTransition({
|
||||
defaultName: 'fade',
|
||||
appear: props.visible,
|
||||
emits: (name:TransitionEmitStatus) => { emit(name) },
|
||||
visible: (): boolean => props.visible,
|
||||
duration: props.duration,
|
||||
} as UseTransitionOptions)
|
||||
|
||||
const styles = computed<Map<string,any>>(():Map<string,any> => {
|
||||
const style = new Map<string,any>();
|
||||
if (props.bgColor != null) {
|
||||
style.set("background", props.bgColor!)
|
||||
}
|
||||
if (props.zIndex > 0) {
|
||||
style.set("z-index", props.zIndex)
|
||||
}
|
||||
// #ifndef APP || WEB
|
||||
style.set('transition-duration', props.duration + 'ms')
|
||||
if (!display.value) {
|
||||
style.set("display", "none")
|
||||
}
|
||||
// #endif
|
||||
return style
|
||||
})
|
||||
|
||||
const noop = () => {}
|
||||
const onClick = (event: UniPointerEvent) =>{
|
||||
// event.stopPropagation()
|
||||
emit('click', !props.visible)
|
||||
}
|
||||
// #ifdef APP || WEB
|
||||
const overlayRef = ref<UniElement|null>(null)
|
||||
|
||||
watchEffect(()=>{
|
||||
overlayRef.value?.style.setProperty('transition-duration', `${props.duration}ms`)
|
||||
if(!display.value){
|
||||
overlayRef.value?.style.setProperty('display', "none")
|
||||
} else {
|
||||
overlayRef.value?.style.setProperty('display', "flex")
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
||||
</script>
|
||||
<style lang="scss">
|
||||
@import './index';
|
||||
</style>
|
||||
70
uni_modules/lime-overlay/components/l-overlay/l-overlay.vue
Normal file
70
uni_modules/lime-overlay/components/l-overlay/l-overlay.vue
Normal file
@@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<view
|
||||
v-if="inited"
|
||||
class="l-overlay"
|
||||
:class="[lClass, classes]"
|
||||
:style="[styles, lStyle]"
|
||||
@click.stop="onClick"
|
||||
@touchmove.stop="noop"
|
||||
@transitionend="finished"
|
||||
:aria-role="ariaRole || 'button'"
|
||||
:aria-label="ariaLabel || '关闭'">
|
||||
<slot></slot>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
// @ts-nocheck
|
||||
import { computed, defineComponent } from '@/uni_modules/lime-shared/vue';
|
||||
import { useTransition, UseTransitionOptions, TransitionEmitStatus } from '@/uni_modules/lime-transition';
|
||||
import overlayProps from './props';
|
||||
|
||||
export default defineComponent({
|
||||
props: overlayProps,
|
||||
emits: ['click', 'before-enter', 'enter', 'after-enter', 'before-leave', 'leave', 'after-leave'],
|
||||
options: {
|
||||
addGlobalClass: true,
|
||||
virtualHost: true,
|
||||
externalClasses: true,
|
||||
},
|
||||
externalClasses: ['l-class'],
|
||||
setup(props, { emit }) {
|
||||
|
||||
const {inited, display, classes, finished} = useTransition({
|
||||
defaultName: 'fade',
|
||||
appear: props.visible,
|
||||
emits: (name:TransitionEmitStatus) => { emit(name) },
|
||||
visible: (): boolean => props.visible,
|
||||
duration: props.duration,
|
||||
} as UseTransitionOptions)
|
||||
|
||||
|
||||
const styles = computed(() => ({
|
||||
'transition-duration': props.duration + 'ms',
|
||||
'background': props.bgColor,
|
||||
'z-index': props.zIndex,
|
||||
'display': !display.value ? 'none' : '',
|
||||
}))
|
||||
|
||||
const onClick = () => {
|
||||
emit('click', !props.visible)
|
||||
}
|
||||
const noop = (e) => {
|
||||
e?.preventDefault();
|
||||
return
|
||||
}
|
||||
|
||||
return {
|
||||
inited,
|
||||
styles,
|
||||
classes,
|
||||
noop,
|
||||
onClick,
|
||||
finished
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<style lang="scss">
|
||||
@import './index';
|
||||
</style>
|
||||
20
uni_modules/lime-overlay/components/l-overlay/props.ts
Normal file
20
uni_modules/lime-overlay/components/l-overlay/props.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export default {
|
||||
visible: Boolean,
|
||||
zIndex: {
|
||||
type: Number,
|
||||
default: 998,
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
default: 300
|
||||
},
|
||||
preventScrollThrough: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
bgColor: String,
|
||||
lStyle: String,
|
||||
lClass: String,
|
||||
ariaLabel: String,
|
||||
ariaRole: String,
|
||||
}
|
||||
30
uni_modules/lime-overlay/components/l-overlay/type.ts
Normal file
30
uni_modules/lime-overlay/components/l-overlay/type.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// @ts-nocheck
|
||||
export interface OverlayProps {
|
||||
ariaLabel: string;
|
||||
ariaRole: string;
|
||||
lClass?: string;
|
||||
/**
|
||||
* 遮罩层的背景色
|
||||
*/
|
||||
bgColor ?: string;
|
||||
/**
|
||||
* 遮罩层自定义样式。优先级低于其他属性
|
||||
*/
|
||||
lStyle ?: string;
|
||||
/**
|
||||
* 背景色过渡时间,单位毫秒
|
||||
*/
|
||||
duration : number;
|
||||
/**
|
||||
* 防止滚动穿透,即不允许点击和滚动
|
||||
*/
|
||||
preventScrollThrough : boolean;
|
||||
/**
|
||||
* 是否展示
|
||||
*/
|
||||
visible : boolean;
|
||||
/**
|
||||
* 遮罩的层级
|
||||
*/
|
||||
zIndex : number;
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<template>
|
||||
<view class="demo-block">
|
||||
<text class="demo-block__title-text ultra">遮罩层</text>
|
||||
<text class="demo-block__desc-text">通过遮罩层,可以强调部分内容</text>
|
||||
<view class="demo-block__body">
|
||||
<view class="demo-block">
|
||||
<text class="demo-block__title-text">基础使用</text>
|
||||
<view class="demo-block__body">
|
||||
<button @click="onClick">显示</button>
|
||||
<l-overlay :visible="show" @click="onClick"></l-overlay>
|
||||
</view>
|
||||
</view>
|
||||
<view class="demo-block">
|
||||
<text class="demo-block__title-text">嵌入内容</text>
|
||||
<view class="demo-block__body">
|
||||
<button @click="show2 = true">显示</button>
|
||||
<l-overlay :visible="show2" @click="show2 = !show2">
|
||||
<view class="wrapper">
|
||||
<view class="block" />
|
||||
</view>
|
||||
</l-overlay>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script lang="uts" setup>
|
||||
const show = ref(false);
|
||||
const show2 = ref(false);
|
||||
const onClick = () => {
|
||||
show.value = !show.value
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.block {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
background-color: #fff;
|
||||
}
|
||||
.demo-block {
|
||||
margin: 32px 20px 0;
|
||||
overflow: visible;
|
||||
&__title {
|
||||
margin: 0;
|
||||
margin-top: 8px;
|
||||
&-text {
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
font-weight: 400;
|
||||
font-size: 14px;
|
||||
line-height: 16px;
|
||||
|
||||
&.large {
|
||||
color: rgba(0, 0, 0, 0.9);
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
line-height: 26px;
|
||||
}
|
||||
&.ultra {
|
||||
color: rgba(0, 0, 0, 0.9);
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
}
|
||||
&__desc-text {
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
margin: 8px 16px 0 0;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
}
|
||||
&__body {
|
||||
margin: 16px 0;
|
||||
overflow: visible;
|
||||
.demo-block {
|
||||
// margin-top: 0px;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,98 @@
|
||||
<template>
|
||||
<view class="demo-block">
|
||||
<text class="demo-block__title-text ultra">遮罩层</text>
|
||||
<text class="demo-block__desc-text">通过遮罩层,可以强调部分内容</text>
|
||||
<view class="demo-block__body">
|
||||
<view class="demo-block">
|
||||
<text class="demo-block__title-text">基础使用</text>
|
||||
<view class="demo-block__body">
|
||||
<button @click="onClick">显示</button>
|
||||
<l-overlay :visible="show" @click="onClick"></l-overlay>
|
||||
</view>
|
||||
</view>
|
||||
<view class="demo-block">
|
||||
<text class="demo-block__title-text">嵌入内容</text>
|
||||
<view class="demo-block__body">
|
||||
<button @click="show2 = true">显示</button>
|
||||
<l-overlay :visible="show2" @click="show2 = !show2">
|
||||
<view class="wrapper">
|
||||
<view class="block" />
|
||||
</view>
|
||||
</l-overlay>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
show: false,
|
||||
show2: false,
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
onClick(){
|
||||
this.show = !this.show
|
||||
console.log(`show`, this.show)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.block {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.demo-block {
|
||||
margin: 32px 20px 0;
|
||||
overflow: visible;
|
||||
&__title {
|
||||
margin: 0;
|
||||
margin-top: 8px;
|
||||
&-text {
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
font-weight: 400;
|
||||
font-size: 14px;
|
||||
line-height: 16px;
|
||||
|
||||
&.large {
|
||||
color: rgba(0, 0, 0, 0.9);
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
line-height: 26px;
|
||||
}
|
||||
&.ultra {
|
||||
color: rgba(0, 0, 0, 0.9);
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
line-height: 32px;
|
||||
}
|
||||
}
|
||||
}
|
||||
&__desc-text {
|
||||
color: rgba(0, 0, 0, 0.6);
|
||||
margin: 8px 16px 0 0;
|
||||
font-size: 14px;
|
||||
line-height: 22px;
|
||||
}
|
||||
&__body {
|
||||
margin: 16px 0;
|
||||
overflow: visible;
|
||||
.demo-block {
|
||||
// margin-top: 0px;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user