@yunlefun/vue 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/YlfScrollFade.vue +66 -0
- package/components/YlfSelect.vue +29 -22
- package/components/scroll-fade/demo.vue +49 -0
- package/components/scroll-fade/index.md +40 -0
- package/components/scroll-fade.ts +52 -0
- package/dist/components/YlfScrollFade.vue.d.ts +24 -0
- package/dist/components/scroll-fade.d.ts +3 -0
- package/package.json +6 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { toRef } from 'vue'
|
|
3
|
+
import { useScrollFade } from './scroll-fade'
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(defineProps<{
|
|
6
|
+
/** The element inside the frame that owns vertical scrolling. */
|
|
7
|
+
viewport?: HTMLElement | null
|
|
8
|
+
/** CSS color of the surface behind the content. */
|
|
9
|
+
surface?: string
|
|
10
|
+
/** CSS length of the fade at each scroll edge. */
|
|
11
|
+
size?: string
|
|
12
|
+
}>(), {
|
|
13
|
+
surface: 'var(--ylf-c-surface, #fff)',
|
|
14
|
+
size: '24px',
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const fadeStyle = useScrollFade(toRef(() => props.viewport))
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<template>
|
|
21
|
+
<div
|
|
22
|
+
class="ylf-scroll-fade"
|
|
23
|
+
:style="[fadeStyle, { '--ylf-scroll-fade-surface': surface, '--ylf-scroll-fade-size': size }]"
|
|
24
|
+
>
|
|
25
|
+
<slot />
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<style scoped>
|
|
30
|
+
.ylf-scroll-fade {
|
|
31
|
+
position: relative;
|
|
32
|
+
isolation: isolate;
|
|
33
|
+
min-width: 0;
|
|
34
|
+
min-height: 0;
|
|
35
|
+
overflow: hidden;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.ylf-scroll-fade::before,
|
|
39
|
+
.ylf-scroll-fade::after {
|
|
40
|
+
position: absolute;
|
|
41
|
+
z-index: 1;
|
|
42
|
+
inset-inline: 0;
|
|
43
|
+
height: min(var(--ylf-scroll-fade-size), 50%);
|
|
44
|
+
pointer-events: none;
|
|
45
|
+
content: '';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.ylf-scroll-fade::before {
|
|
49
|
+
top: 0;
|
|
50
|
+
opacity: var(--scroll-fade-top);
|
|
51
|
+
background: linear-gradient(to bottom, var(--ylf-scroll-fade-surface), transparent);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.ylf-scroll-fade::after {
|
|
55
|
+
bottom: 0;
|
|
56
|
+
opacity: var(--scroll-fade-bottom);
|
|
57
|
+
background: linear-gradient(to top, var(--ylf-scroll-fade-surface), transparent);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@media (prefers-reduced-transparency: reduce), (forced-colors: active) {
|
|
61
|
+
.ylf-scroll-fade::before,
|
|
62
|
+
.ylf-scroll-fade::after {
|
|
63
|
+
display: none;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
</style>
|
package/components/YlfSelect.vue
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup generic="T extends string = string">
|
|
2
2
|
import { SelectContent, SelectIcon, SelectItem, SelectItemIndicator, SelectItemText, SelectPortal, SelectRoot, SelectTrigger, SelectValue, SelectViewport } from 'reka-ui'
|
|
3
|
-
import { computed } from 'vue'
|
|
3
|
+
import { computed, useTemplateRef } from 'vue'
|
|
4
|
+
import YlfScrollFade from './YlfScrollFade.vue'
|
|
4
5
|
|
|
5
6
|
defineOptions({ inheritAttrs: false })
|
|
6
7
|
|
|
@@ -25,6 +26,7 @@ const props = withDefaults(defineProps<{
|
|
|
25
26
|
|
|
26
27
|
const model = defineModel<T>()
|
|
27
28
|
const selectedOption = computed(() => props.options.find(option => option.value === model.value))
|
|
29
|
+
const viewport = useTemplateRef<HTMLElement>('viewport')
|
|
28
30
|
</script>
|
|
29
31
|
|
|
30
32
|
<template>
|
|
@@ -44,27 +46,31 @@ const selectedOption = computed(() => props.options.find(option => option.value
|
|
|
44
46
|
</SelectTrigger>
|
|
45
47
|
<SelectPortal :to="portalTo">
|
|
46
48
|
<SelectContent class="ylf-select__content" :data-size="size" position="popper" :side-offset="6" :collision-padding="16">
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
<
|
|
62
|
-
<
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
49
|
+
<YlfScrollFade :viewport="viewport" surface="var(--ylf-c-panel, var(--ylf-c-surface, #fff))">
|
|
50
|
+
<SelectViewport as-child>
|
|
51
|
+
<div ref="viewport" class="ylf-select__viewport">
|
|
52
|
+
<SelectItem
|
|
53
|
+
v-for="o in options"
|
|
54
|
+
:key="o.value"
|
|
55
|
+
:value="o.value"
|
|
56
|
+
:disabled="o.disabled"
|
|
57
|
+
class="ylf-select__item"
|
|
58
|
+
>
|
|
59
|
+
<SelectItemText class="ylf-select__label">
|
|
60
|
+
<span v-if="o.color" class="ylf-select__swatch" :style="{ backgroundColor: o.color }" aria-hidden="true" />
|
|
61
|
+
<span>{{ o.label }}</span>
|
|
62
|
+
</SelectItemText>
|
|
63
|
+
<SelectItemIndicator class="ylf-select__check">
|
|
64
|
+
<slot name="indicator">
|
|
65
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
|
|
66
|
+
<path d="M5 12.5l4.5 4.5L19 7" />
|
|
67
|
+
</svg>
|
|
68
|
+
</slot>
|
|
69
|
+
</SelectItemIndicator>
|
|
70
|
+
</SelectItem>
|
|
71
|
+
</div>
|
|
72
|
+
</SelectViewport>
|
|
73
|
+
</YlfScrollFade>
|
|
68
74
|
</SelectContent>
|
|
69
75
|
</SelectPortal>
|
|
70
76
|
</SelectRoot>
|
|
@@ -194,6 +200,7 @@ const selectedOption = computed(() => props.options.find(option => option.value
|
|
|
194
200
|
|
|
195
201
|
.ylf-select__viewport {
|
|
196
202
|
max-height: calc(var(--reka-select-content-available-height) - 14px);
|
|
203
|
+
scroll-padding-block: 24px;
|
|
197
204
|
}
|
|
198
205
|
|
|
199
206
|
.ylf-select__item {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useTemplateRef } from 'vue'
|
|
3
|
+
import YlfScrollFade from '../YlfScrollFade.vue'
|
|
4
|
+
|
|
5
|
+
withDefaults(defineProps<{ label?: string, itemLabel?: string }>(), {
|
|
6
|
+
label: '最近打开',
|
|
7
|
+
itemLabel: '项目',
|
|
8
|
+
})
|
|
9
|
+
const list = useTemplateRef<HTMLUListElement>('list')
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<YlfScrollFade :viewport="list" class="scroll-demo">
|
|
14
|
+
<ul ref="list" :aria-label="label" tabindex="0" class="scroll-demo-list">
|
|
15
|
+
<li v-for="entry in 12" :key="entry">
|
|
16
|
+
{{ itemLabel }} {{ entry }}
|
|
17
|
+
</li>
|
|
18
|
+
</ul>
|
|
19
|
+
</YlfScrollFade>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<style scoped>
|
|
23
|
+
.scroll-demo {
|
|
24
|
+
width: min(100%, 24rem);
|
|
25
|
+
border: 1px solid var(--ylf-c-border);
|
|
26
|
+
border-radius: var(--ylf-radius, 14px);
|
|
27
|
+
background: var(--ylf-c-surface, #fff);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.scroll-demo-list {
|
|
31
|
+
max-height: 9rem;
|
|
32
|
+
margin: 0;
|
|
33
|
+
padding: 0;
|
|
34
|
+
overflow-y: auto;
|
|
35
|
+
scroll-padding-block: 24px;
|
|
36
|
+
list-style: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.scroll-demo-list:focus-visible {
|
|
40
|
+
outline-offset: -3px;
|
|
41
|
+
}
|
|
42
|
+
.scroll-demo-list li {
|
|
43
|
+
margin: 0;
|
|
44
|
+
padding: 8px 14px;
|
|
45
|
+
}
|
|
46
|
+
.scroll-demo-list li + li {
|
|
47
|
+
border-top: 1px solid var(--ylf-c-border);
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Scroll Fade
|
|
3
|
+
title_zh: 滚动渐变
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
滚动区域默认使用 `YlfScrollFade` 提示边缘外还有内容。列表全部可见时不显示渐变,滚到边界时自动移除对应一侧的渐变。组件尊重系统的减少透明度和强制颜色偏好。
|
|
7
|
+
|
|
8
|
+
用组件包裹实际滚动的元素,通过 `viewport` 传入模板引用。滚动元素继续负责高度、`overflow`、键盘焦点和语义。自定义背景时,将同一个颜色或主题变量传给 `surface`。可用 `size` 调整渐变高度,默认 24px。
|
|
9
|
+
|
|
10
|
+
```vue
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import YlfScrollFade from '@yunlefun/vue/components/YlfScrollFade.vue'
|
|
13
|
+
import { useTemplateRef } from 'vue'
|
|
14
|
+
|
|
15
|
+
const list = useTemplateRef<HTMLUListElement>('list')
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<YlfScrollFade :viewport="list" class="panel">
|
|
20
|
+
<ul ref="list" aria-label="最近打开" tabindex="0" class="viewport">
|
|
21
|
+
<li v-for="entry in 12" :key="entry">
|
|
22
|
+
项目 {{ entry }}
|
|
23
|
+
</li>
|
|
24
|
+
</ul>
|
|
25
|
+
</YlfScrollFade>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<style scoped>
|
|
29
|
+
.panel {
|
|
30
|
+
background: var(--ylf-c-surface, #fff);
|
|
31
|
+
}
|
|
32
|
+
.viewport {
|
|
33
|
+
max-height: 8rem;
|
|
34
|
+
overflow-y: auto;
|
|
35
|
+
scroll-padding-block: 24px;
|
|
36
|
+
}
|
|
37
|
+
</style>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`YlfSelect` 已内置滚动渐变。带固定表头等特殊结构可以从 `@yunlefun/vue/components/scroll-fade` 导入 `useScrollFade`,获取两侧的透明度变量,按布局放置渐变。
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ComputedRef, CSSProperties, Ref } from 'vue'
|
|
2
|
+
import { computed, shallowRef, watch } from 'vue'
|
|
3
|
+
|
|
4
|
+
function edgeOpacity(distance: number): number {
|
|
5
|
+
// Layout heights are rounded to whole pixels, but scrollTop can be fractional.
|
|
6
|
+
return distance <= 1 ? 0 : Math.min(1, distance / 24)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Reveal the edges with more content, including before the first scroll. */
|
|
10
|
+
export function useScrollFade(viewport: Readonly<Ref<HTMLElement | null | undefined>>): ComputedRef<CSSProperties> {
|
|
11
|
+
const top = shallowRef(0)
|
|
12
|
+
const bottom = shallowRef(0)
|
|
13
|
+
watch(viewport, (element, _, onCleanup) => {
|
|
14
|
+
top.value = 0
|
|
15
|
+
bottom.value = 0
|
|
16
|
+
if (!element)
|
|
17
|
+
return
|
|
18
|
+
|
|
19
|
+
let frame = 0
|
|
20
|
+
const update = (): void => {
|
|
21
|
+
frame = 0
|
|
22
|
+
const range = Math.max(0, element.scrollHeight - element.clientHeight)
|
|
23
|
+
const offset = Math.min(range, Math.max(0, element.scrollTop))
|
|
24
|
+
top.value = edgeOpacity(offset)
|
|
25
|
+
bottom.value = edgeOpacity(range - offset)
|
|
26
|
+
}
|
|
27
|
+
const schedule = (): void => {
|
|
28
|
+
if (!frame)
|
|
29
|
+
frame = requestAnimationFrame(update)
|
|
30
|
+
}
|
|
31
|
+
const resize = new ResizeObserver(schedule)
|
|
32
|
+
const observeContent = (): void => {
|
|
33
|
+
resize.disconnect()
|
|
34
|
+
resize.observe(element)
|
|
35
|
+
for (const child of Array.from(element.children))
|
|
36
|
+
resize.observe(child)
|
|
37
|
+
schedule()
|
|
38
|
+
}
|
|
39
|
+
const content = new MutationObserver(observeContent)
|
|
40
|
+
content.observe(element, { childList: true, characterData: true, subtree: true })
|
|
41
|
+
observeContent()
|
|
42
|
+
element.addEventListener('scroll', schedule, { passive: true })
|
|
43
|
+
onCleanup(() => {
|
|
44
|
+
resize.disconnect()
|
|
45
|
+
content.disconnect()
|
|
46
|
+
cancelAnimationFrame(frame)
|
|
47
|
+
element.removeEventListener('scroll', schedule)
|
|
48
|
+
})
|
|
49
|
+
}, { immediate: true, flush: 'post' })
|
|
50
|
+
|
|
51
|
+
return computed(() => ({ '--scroll-fade-top': top.value, '--scroll-fade-bottom': bottom.value }))
|
|
52
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
/** The element inside the frame that owns vertical scrolling. */
|
|
3
|
+
viewport?: HTMLElement | null;
|
|
4
|
+
/** CSS color of the surface behind the content. */
|
|
5
|
+
surface?: string;
|
|
6
|
+
/** CSS length of the fade at each scroll edge. */
|
|
7
|
+
size?: string;
|
|
8
|
+
};
|
|
9
|
+
declare var __VLS_1: {};
|
|
10
|
+
type __VLS_Slots = {} & {
|
|
11
|
+
default?: (props: typeof __VLS_1) => any;
|
|
12
|
+
};
|
|
13
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
14
|
+
size: string;
|
|
15
|
+
surface: string;
|
|
16
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
18
|
+
declare const _default: typeof __VLS_export;
|
|
19
|
+
export default _default;
|
|
20
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
21
|
+
new (): {
|
|
22
|
+
$slots: S;
|
|
23
|
+
};
|
|
24
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yunlefun/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.0",
|
|
5
5
|
"description": "Vue components and Nuxt integration for YunLeFun Design",
|
|
6
6
|
"author": "YunLeFun",
|
|
7
7
|
"license": "MIT",
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"url": "https://github.com/YunLeFun/design/issues"
|
|
16
16
|
},
|
|
17
17
|
"exports": {
|
|
18
|
+
"./components/scroll-fade": {
|
|
19
|
+
"types": "./dist/components/scroll-fade.d.ts",
|
|
20
|
+
"default": "./components/scroll-fade.ts"
|
|
21
|
+
},
|
|
18
22
|
"./components/*.vue": {
|
|
19
23
|
"types": "./dist/components/*.vue.d.ts",
|
|
20
24
|
"default": "./components/*.vue"
|
|
@@ -74,7 +78,7 @@
|
|
|
74
78
|
"reka-ui": "^2.11.0"
|
|
75
79
|
},
|
|
76
80
|
"devDependencies": {
|
|
77
|
-
"nuxt": "^4.6.
|
|
81
|
+
"nuxt": "^4.6.4",
|
|
78
82
|
"sass": "^1.105.1",
|
|
79
83
|
"typescript": "6.0.3"
|
|
80
84
|
}
|