From 58476856b5bcf3ff07a082192fcb3a214b947e02 Mon Sep 17 00:00:00 2001
From: sdhushu <1426732052@qq.com>
Date: Thu, 24 Nov 2022 22:30:00 +0800
Subject: [PATCH] feat: init overlay component
---
packages/varlet-ui/src/overlay/Overlay.tsx | 41 ++++++++++++++++
packages/varlet-ui/src/overlay/docs/en-US.md | 1 +
packages/varlet-ui/src/overlay/docs/zh-CN.md | 1 +
.../varlet-ui/src/overlay/example/index.vue | 48 +++++++++++++++++++
.../src/overlay/example/local/en-US.ts | 5 ++
.../src/overlay/example/local/index.ts | 23 +++++++++
.../src/overlay/example/local/zh-CN.ts | 5 ++
packages/varlet-ui/src/overlay/index.ts | 10 ++++
packages/varlet-ui/src/overlay/overlay.less | 18 +++++++
packages/varlet-ui/src/overlay/props.ts | 17 +++++++
packages/varlet-ui/varlet.config.mjs | 8 ++++
11 files changed, 177 insertions(+)
create mode 100644 packages/varlet-ui/src/overlay/Overlay.tsx
create mode 100644 packages/varlet-ui/src/overlay/docs/en-US.md
create mode 100644 packages/varlet-ui/src/overlay/docs/zh-CN.md
create mode 100644 packages/varlet-ui/src/overlay/example/index.vue
create mode 100644 packages/varlet-ui/src/overlay/example/local/en-US.ts
create mode 100644 packages/varlet-ui/src/overlay/example/local/index.ts
create mode 100644 packages/varlet-ui/src/overlay/example/local/zh-CN.ts
create mode 100644 packages/varlet-ui/src/overlay/index.ts
create mode 100644 packages/varlet-ui/src/overlay/overlay.less
create mode 100644 packages/varlet-ui/src/overlay/props.ts
diff --git a/packages/varlet-ui/src/overlay/Overlay.tsx b/packages/varlet-ui/src/overlay/Overlay.tsx
new file mode 100644
index 00000000000..104beb2ee6c
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/Overlay.tsx
@@ -0,0 +1,41 @@
+import { defineComponent, defineEmits } from 'vue'
+import { props } from './props'
+import { useZIndex } from '../context/zIndex'
+import { createNamespace } from '../utils/components'
+
+import '../styles/common.less'
+import './overlay.less'
+
+const { n, classes } = createNamespace('overlay')
+
+export default defineComponent({
+ name: 'VarOverlay',
+ inheritAttrs: false,
+ props,
+ setup(props, { slots }) {
+ const { zIndex } = useZIndex(() => props.show, 3)
+ const hideOverlay = () => {
+ props['onUpdate:show']?.(false)
+ }
+
+ const renderOverlay = () => {
+ const { overlayClass = '', overlayStyle } = props
+ return (
+
+ {slots.default?.()}
+
+ )
+ }
+ return () => {
+ const { show } = props
+ return show && renderOverlay()
+ }
+ },
+})
diff --git a/packages/varlet-ui/src/overlay/docs/en-US.md b/packages/varlet-ui/src/overlay/docs/en-US.md
new file mode 100644
index 00000000000..6507c15ed50
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/docs/en-US.md
@@ -0,0 +1 @@
+# Overlay
\ No newline at end of file
diff --git a/packages/varlet-ui/src/overlay/docs/zh-CN.md b/packages/varlet-ui/src/overlay/docs/zh-CN.md
new file mode 100644
index 00000000000..6507c15ed50
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/docs/zh-CN.md
@@ -0,0 +1 @@
+# Overlay
\ No newline at end of file
diff --git a/packages/varlet-ui/src/overlay/example/index.vue b/packages/varlet-ui/src/overlay/example/index.vue
new file mode 100644
index 00000000000..056d3d7df06
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/example/index.vue
@@ -0,0 +1,48 @@
+
+
+
+ {{ pack.overlayBase }}
+
+ {{ pack.showOverlay }}
+
+
+
+
+ {{ pack.overlayContent }}
+
+ {{ pack.overlayContent }}
+
+
+
+
+
+
+
+
diff --git a/packages/varlet-ui/src/overlay/example/local/en-US.ts b/packages/varlet-ui/src/overlay/example/local/en-US.ts
new file mode 100644
index 00000000000..d6143129625
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/example/local/en-US.ts
@@ -0,0 +1,5 @@
+export default {
+ overlayBase: 'overlayBase',
+ overlayContent: 'overlayContent',
+ showOverlay: 'showOverlay',
+}
diff --git a/packages/varlet-ui/src/overlay/example/local/index.ts b/packages/varlet-ui/src/overlay/example/local/index.ts
new file mode 100644
index 00000000000..d2e375e6090
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/example/local/index.ts
@@ -0,0 +1,23 @@
+// lib
+import _zhCN from '../../../locale/zh-CN'
+import _enCN from '../../../locale/en-US'
+// mobile example doc
+import zhCN from './zh-CN'
+import enUS from './en-US'
+import { useLocale, add as _add, use as _use } from '../../../locale'
+
+const { add, use: exampleUse, pack, packs, merge } = useLocale()
+
+const use = (lang: string) => {
+ _use(lang)
+ exampleUse(lang)
+}
+
+export { add, pack, packs, merge, use }
+
+// lib
+_add('zh-CN', _zhCN)
+_add('en-US', _enCN)
+// mobile example doc
+add('zh-CN', zhCN as any)
+add('en-US', enUS as any)
diff --git a/packages/varlet-ui/src/overlay/example/local/zh-CN.ts b/packages/varlet-ui/src/overlay/example/local/zh-CN.ts
new file mode 100644
index 00000000000..cabcf05365c
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/example/local/zh-CN.ts
@@ -0,0 +1,5 @@
+export default {
+ overlayBase: '基础用法',
+ overlayContent: '嵌入内容',
+ showOverlay: '显示遮罩层',
+}
diff --git a/packages/varlet-ui/src/overlay/index.ts b/packages/varlet-ui/src/overlay/index.ts
new file mode 100644
index 00000000000..d5dc6019da7
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/index.ts
@@ -0,0 +1,10 @@
+import type { App } from 'vue'
+import Overlay from './Overlay'
+
+Overlay.install = function (app: App) {
+ app.component(Overlay.name, Overlay)
+}
+
+export const _PopupComponent = Overlay
+
+export default Overlay
diff --git a/packages/varlet-ui/src/overlay/overlay.less b/packages/varlet-ui/src/overlay/overlay.less
new file mode 100644
index 00000000000..8e3f2429232
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/overlay.less
@@ -0,0 +1,18 @@
+:root {
+ --popup-overlay-background-color: rgba(0, 0, 0, 0.6);
+}
+
+.var-overlay {
+ &__overlay {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ position: fixed;
+ top: 0;
+ right: 0;
+ bottom: 0;
+ left: 0;
+ background-color: var(--popup-overlay-background-color);
+ transition: all 0.25s;
+ }
+}
diff --git a/packages/varlet-ui/src/overlay/props.ts b/packages/varlet-ui/src/overlay/props.ts
new file mode 100644
index 00000000000..4ca67356b51
--- /dev/null
+++ b/packages/varlet-ui/src/overlay/props.ts
@@ -0,0 +1,17 @@
+import { PropType } from 'vue'
+
+export const props = {
+ show: {
+ type: Boolean,
+ default: false,
+ },
+ overlayClass: {
+ type: String,
+ },
+ overlayStyle: {
+ type: Object,
+ },
+ 'onUpdate:show': {
+ type: Function as PropType<(show: boolean) => void>,
+ },
+}
diff --git a/packages/varlet-ui/varlet.config.mjs b/packages/varlet-ui/varlet.config.mjs
index ea74a149250..435cb062e36 100644
--- a/packages/varlet-ui/varlet.config.mjs
+++ b/packages/varlet-ui/varlet.config.mjs
@@ -418,6 +418,14 @@ export default defineConfig({
doc: 'pull-refresh',
type: 2,
},
+ {
+ text: {
+ 'zh-CN': 'Overlay 遮罩层',
+ 'en-US': 'Overlay'
+ },
+ doc: 'overlay',
+ type: 2,
+ },
{
text: {
'zh-CN': 'Popup 弹出层',