Skip to content

Commit

Permalink
test: add overlay-scrollbars usecase for further comparation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionad-Morotar committed Dec 14, 2023
1 parent fcf494c commit 10ffda0
Show file tree
Hide file tree
Showing 9 changed files with 483 additions and 22 deletions.
3 changes: 2 additions & 1 deletion play/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#play {
height: 100%;
width: 100%;
background: var(--el-bg-color);
}

.segment {
Expand All @@ -34,7 +35,7 @@
grid-template: auto minmax(0, 1fr) / minmax(0, 1fr);
box-sizing: border-box;
padding: 8px;
border: solid 2px #eee;
border: solid 2px var(--el-border-color-dark);
height: 100%;
width: 100%;
overflow: hidden;
Expand Down
26 changes: 17 additions & 9 deletions play/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,28 @@ import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
// import 'ant-design-vue/dist/antd.css'
import 'element-plus/dist/index.css'
import 'overlayscrollbars/styles/overlayscrollbars.css';

// main
;(async () => {
const apps = import.meta.glob('./src/*.vue')
const name = location.pathname.replace(/^\//, '') || 'App'
const file = apps[`./src/${name}.vue`]
if (!file) {
location.pathname = 'App'
return
const pages = import.meta.glob("./src/**/*.vue");
const pathname = location.pathname.replace(/^\//, "") || "home";

const fileRaw = pages[`./src/${pathname}.vue`];
const fileIndex = pages[`./src/${pathname}/index.vue`];

if (!fileRaw && !fileIndex) {
location.pathname = "home";
return;
}

// @ts-ignore
const App = (await file()).default
const app = createApp(App)
const component = fileRaw
? // @ts-ignore
(await fileRaw())?.default
: // @ts-ignore
(await fileIndex())?.default;

const app = createApp(component);

app.use(VXETable)
app.use(ElementPlus)
Expand Down
112 changes: 101 additions & 11 deletions play/src/compare-styles.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,79 @@
</div>
<div class="compare-container">

<h4>use-scrollbars</h4>
<div class="complex-component-example cutom-scrollbar" :class="kls" ref="elemRef">
<div class="content-wrapper">
<pre class="content">
// use-scrollbar
function hello() {
console.log('hello world!')
console.log('I like cola and cola and longcola and longcola and longcola and longcola and longcola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
}

function world() {
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
}

function world() {
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
console.log('hello world!')
console.log('I like cola and cola')
}
</pre>
</div>
</div>

<!-- native-scrollbar -->
<h4>native scrollbar</h4>
<div class="complex-component-example" :class="kls">
<div class="content-wrapper">
<pre class="content">
Expand Down Expand Up @@ -81,11 +153,12 @@ function world() {
</div>
</div>

<!-- custom-scrollbar -->
<div class="complex-component-example cutom-scrollbar" :class="kls" ref="elemRef">
<div class="content-wrapper">
<!-- OverlayScrollbars -->
<h4>overlay-scrollbars-vue</h4>
<div class="complex-component-example" :class="kls">
<div class="content-wrapper" ref="overlayScrollbarDivRef">
<pre class="content">
// use-scrollbar
// OverlayScrollbars
function hello() {
console.log('hello world!')
console.log('I like cola and cola and longcola and longcola and longcola and longcola and longcola')
Expand Down Expand Up @@ -151,12 +224,14 @@ function world() {
</pre>
</div>
</div>

</div>
</div>
</template>

<script lang="ts" setup>
import { ref, computed, reactive, watchEffect } from "vue";
import { ref, computed, reactive, watchEffect, onMounted } from "vue";
import { useOverlayScrollbars } from "overlayscrollbars-vue";
import { useScrollbar } from "@/hooks";
import type { Theme } from "@/hooks";
Expand Down Expand Up @@ -200,6 +275,15 @@ watchEffect(() => {
})
console.log('[debug] barStates', barStates);
const overlayScrollbarDivRef = ref(null);
const reactiveParams = reactive({ options: {}, events: {}, defer: false });
const [initialize, instance] = useOverlayScrollbars(reactiveParams);
onMounted(() => {
console.log('overlayScrollbarDivRef.value')
initialize({ target: overlayScrollbarDivRef.value! });
})
</script>

<style scoped>
Expand All @@ -209,22 +293,28 @@ console.log('[debug] barStates', barStates);
}
.compare-container {
display: flex;
justify-content: center;
align-items: center;
gap: 2em;
flex-direction: column;
gap: 1em;
box-sizing: border-box;
padding-bottom: 12vh;
width: 100%;
height: 100%;
border: solid 1px #eee;
height: auto;
border: solid 1px var(--el-border-color-dark);
overflow: auto;
h4 {
margin: 1em 0 0 0;
font-size: 16px;
line-height: 1;
}
}
.complex-component-example {
position: relative;
padding: 8px;
width: 600px;
height: 372px;
border: solid 2px black;
background: #eee;
background: solid 1px var(--el-border-color-dark);
}
.content-wrapper {
box-sizing: border-box;
Expand Down
2 changes: 1 addition & 1 deletion play/src/gantt-elastic/components/chart/row/row-task.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
:width="32"
:height="32"
>
<img class="prefix-image" :src="task.image" :title="task.imageTitle || ''" />
<img class="prefix-image" :src="task.image" :title="task.imageTitle || ''" :alt="task.imageTitle" />
</foreignObject>
<svg
class="gantt-elastic__chart-row-bar gantt-elastic__chart-row-task"
Expand Down
File renamed without changes.
159 changes: 159 additions & 0 deletions play/src/overlay-scrollbars/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<template>
<main>
<h1>
<a href="https://www.npmjs.com/package/overlayscrollbars-vue" target="_blank">
OverlayScrollbars Vue
</a>
</h1>
<section class="slot">
<OverlayScrollbarsComponent
v-if="overlayScrollbarsApplied"
class="overlayscrollbars-vue"
ref="osRef"
:style="{ display: elementHidden ? 'none' : undefined }"
:options="{
scrollbars: {
theme: 'os-theme-light',
},
}"
:events="{
initialized: () => activateEvent('initialized'),
destroyed: () => activateEvent('destroyed'),
updated: () => activateEvent('updated'),
scroll: () => activateEvent('scroll'),
}"
defer
>
<div v-if="!contentHidden" class="logo">
<img alt="Vue logo" src="./logo.svg" />
</div>
</OverlayScrollbarsComponent>
<div v-else class="overlayscrollbars-vue">
<div class="logo">
<img alt="Vue logo" src="./logo.svg" />
</div>
</div>
</section>
<section>
<p class="title">Actions:</p>
<div class="items">
<template v-if="overlayScrollbarsApplied">
<button @click="scrollContent">Scroll</button>
<button @click="toggleContent">
<template v-if="contentHidden"> Show </template>
<template v-else> Hide </template>
Content
</button>
<button @click="toggleElement">
<template v-if="elementHidden"> Show </template>
<template v-else> Hide </template>
Element
</button>
</template>
<button @click="overlayScrollbarsApplied = !overlayScrollbarsApplied">
<template v-if="overlayScrollbarsApplied"> Destroy </template>
<template v-else> Initialize </template>
OverlayScrollbars
</button>
</div>
</section>
<section>
<p class="title">Events:</p>
<div class="items">
<div
v-for="[eventName, event] in Object.entries(activeEvents)"
:class="`event ${event.active ? 'active' : ''}`"
>
{{ eventName }} ({{ event.count }})
</div>
</div>
</section>
</main>
<footer>
<section v-if="bodyOverlayScrollbarsApplied !== null">
<div class="items">
<button @click="toggleBodyOverlayScrollbars">
<template v-if="bodyOverlayScrollbarsApplied"> Destroy </template>
<template v-else> Initialize </template>
Body OverlayScrollbars
</button>
</div>
</section>
<a
href="https://github.com/KingSora/OverlayScrollbars/tree/master/examples/vue"
target="_blank"
>
Open source code of this example.
</a>
</footer>
</template>

<script setup lang="ts">
import { OverlayScrollbarsComponent, useOverlayScrollbars } from 'overlayscrollbars-vue';
import type { OverlayScrollbarsComponentRef } from 'overlayscrollbars-vue';
import { onMounted, ref } from 'vue';
import { useEventObserver } from './useEventObserver';
const contentHidden = ref(false);
const elementHidden = ref(false);
const overlayScrollbarsApplied = ref(true);
const bodyOverlayScrollbarsApplied = ref<boolean | null>(null);
const osRef = ref<OverlayScrollbarsComponentRef | null>(null);
const [activeEvents, activateEvent] = useEventObserver();
const [initBodyOverlayScrollbars, getBodyOverlayScrollbarsInstance] = useOverlayScrollbars({
defer: true,
events: {
initialized: () => {
bodyOverlayScrollbarsApplied.value = true;
},
destroyed: () => {
bodyOverlayScrollbarsApplied.value = false;
},
},
options: {
scrollbars: {
theme: 'os-theme-light',
},
},
});
const scrollContent = () => {
const osInstance = osRef?.value?.osInstance();
if (!osInstance) {
return;
}
const { overflowAmount } = osInstance.state();
const { scrollOffsetElement } = osInstance.elements();
const { scrollLeft, scrollTop } = scrollOffsetElement;
scrollOffsetElement.scrollTo({
behavior: 'smooth',
left: Math.round((overflowAmount.x - scrollLeft) / overflowAmount.x) * overflowAmount.x,
top: Math.round((overflowAmount.y - scrollTop) / overflowAmount.y) * overflowAmount.y,
});
};
const toggleContent = () => (contentHidden.value = !contentHidden.value);
const toggleElement = () => (elementHidden.value = !elementHidden.value);
const toggleBodyOverlayScrollbars = () => {
const bodyOsInstance = getBodyOverlayScrollbarsInstance();
if (bodyOsInstance && !bodyOsInstance.state().destroyed) {
bodyOsInstance.destroy();
} else {
initBodyOverlayScrollbars({
target: document.body,
cancel: {
body: false,
},
});
}
};
onMounted(() => initBodyOverlayScrollbars(document.body));
</script>

<style lang="less">
@import "./main.css";
</style>
1 change: 1 addition & 0 deletions play/src/overlay-scrollbars/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 10ffda0

Please sign in to comment.