looseleaf-uni 0.1.0 → 0.2.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/attributes.json +4 -0
- package/lib/CHANGELOG.md +12 -0
- package/lib/common/theme.ts +3 -3
- package/lib/components/ll-attachment/ll-attachment.vue +6 -2
- package/lib/components/ll-avatar/ll-avatar.vue +8 -1
- package/lib/components/ll-badge/ll-badge.vue +6 -1
- package/lib/components/ll-button/button.ts +43 -42
- package/lib/components/ll-button/ll-button.vue +99 -91
- package/lib/components/ll-checkbox/ll-checkbox.vue +70 -54
- package/lib/components/ll-dialog/ll-dialog.vue +160 -159
- package/lib/components/ll-icon/ll-icon.vue +41 -37
- package/lib/components/ll-input/ll-input.vue +73 -73
- package/lib/components/ll-input-otp/ll-input-otp.vue +73 -60
- package/lib/components/ll-progress/ll-progress.vue +12 -2
- package/lib/components/ll-radio-group/ll-radio-group.vue +25 -0
- package/lib/components/ll-ribbon/ll-ribbon.vue +10 -3
- package/lib/components/ll-slider/ll-slider.vue +25 -1
- package/lib/components/ll-switch/ll-switch.vue +40 -0
- package/lib/components/ll-textarea/ll-textarea.vue +31 -26
- package/package.json +1 -1
- package/tags.json +1 -0
- package/web-types.json +10 -1
|
@@ -1,159 +1,160 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { nextTick, onMounted, onUnmounted, ref, watch, type ComponentPublicInstance } from 'vue'
|
|
3
|
-
import LlButton from '../ll-button/ll-button.vue'
|
|
4
|
-
import LlPaper from '../ll-paper/ll-paper.vue'
|
|
5
|
-
import { dialogProps, type DialogCloseReason } from './dialog'
|
|
6
|
-
|
|
7
|
-
defineOptions({ options: { virtualHost: true } })
|
|
8
|
-
|
|
9
|
-
const props = defineProps(dialogProps)
|
|
10
|
-
const emit = defineEmits<{ 'update:open': [open: boolean]; 'close': [reason: DialogCloseReason] }>()
|
|
11
|
-
const panel = ref<HTMLElement | ComponentPublicInstance>()
|
|
12
|
-
let returnFocus: HTMLElement | undefined
|
|
13
|
-
let mounted = false
|
|
14
|
-
|
|
15
|
-
function requestClose(reason: DialogCloseReason) {
|
|
16
|
-
// 父级拥有 open;拒绝回写时仍保持弹层打开。
|
|
17
|
-
emit('update:open', false)
|
|
18
|
-
emit('close', reason)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function backdrop() {
|
|
22
|
-
if (props.closeOnBackdrop) requestClose('backdrop')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// #ifdef H5
|
|
26
|
-
function panelElement() {
|
|
27
|
-
return panel.value instanceof HTMLElement ? panel.value : panel.value?.$el as HTMLElement | undefined
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function keyboard(event: KeyboardEvent) {
|
|
31
|
-
if (event.key === 'Escape') {
|
|
32
|
-
event.preventDefault()
|
|
33
|
-
event.stopPropagation()
|
|
34
|
-
requestClose('escape')
|
|
35
|
-
}
|
|
36
|
-
if (event.key !== 'Tab') return
|
|
37
|
-
const root = panelElement()
|
|
38
|
-
const controls = root?.querySelectorAll<HTMLElement>('button:not(:disabled), input:not(:disabled), textarea:not(:disabled), select:not(:disabled), a[href], [tabindex="0"]')
|
|
39
|
-
if (!controls?.length) {
|
|
40
|
-
event.preventDefault()
|
|
41
|
-
return
|
|
42
|
-
}
|
|
43
|
-
const first = controls[0]!
|
|
44
|
-
const last = controls[controls.length - 1]!
|
|
45
|
-
const origin = document.activeElement
|
|
46
|
-
// 保持 Tab 循环在弹层内,焦点离开时从相应端点重新进入。
|
|
47
|
-
if (event.shiftKey && (origin === first || origin === root) || !event.shiftKey && (origin === last || origin === root)) {
|
|
48
|
-
event.preventDefault()
|
|
49
|
-
if (event.shiftKey) last.focus()
|
|
50
|
-
else first.focus()
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function syncFocus(open: boolean) {
|
|
55
|
-
if (open) {
|
|
56
|
-
if (document.activeElement instanceof HTMLElement) returnFocus = document.activeElement
|
|
57
|
-
await nextTick()
|
|
58
|
-
const root = panelElement()
|
|
59
|
-
if (mounted && props.open && root && !root.contains(document.activeElement)) root.focus()
|
|
60
|
-
} else {
|
|
61
|
-
await nextTick()
|
|
62
|
-
if (mounted && !props.open) returnFocus?.focus()
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
onMounted(() => {
|
|
67
|
-
mounted = true
|
|
68
|
-
if (props.open) void syncFocus(true)
|
|
69
|
-
})
|
|
70
|
-
watch(panel, (_, __, onCleanup) => {
|
|
71
|
-
const element = panelElement()
|
|
72
|
-
if (!element) return
|
|
73
|
-
// 只在 H5 挂到真实面板上,面板关闭或销毁时同步移除监听。
|
|
74
|
-
element.addEventListener('keydown', keyboard)
|
|
75
|
-
onCleanup(() => element.removeEventListener('keydown', keyboard))
|
|
76
|
-
}, { flush: 'post' })
|
|
77
|
-
watch(() => props.open, syncFocus)
|
|
78
|
-
onUnmounted(() => {
|
|
79
|
-
mounted = false
|
|
80
|
-
returnFocus?.focus()
|
|
81
|
-
})
|
|
82
|
-
// #endif
|
|
83
|
-
</script>
|
|
84
|
-
|
|
85
|
-
<template>
|
|
86
|
-
<view
|
|
87
|
-
v-if="open"
|
|
88
|
-
class="ll-dialog"
|
|
89
|
-
:class="'ll-dialog--' + placement"
|
|
90
|
-
>
|
|
91
|
-
<view
|
|
92
|
-
class="ll-dialog__backdrop"
|
|
93
|
-
aria-hidden="true"
|
|
94
|
-
@click.stop="backdrop"
|
|
95
|
-
@touchmove.stop.prevent
|
|
96
|
-
/>
|
|
97
|
-
<view
|
|
98
|
-
ref="panel"
|
|
99
|
-
class="ll-dialog__panel"
|
|
100
|
-
role="dialog"
|
|
101
|
-
aria-modal="true"
|
|
102
|
-
:aria-label="title"
|
|
103
|
-
tabindex="-1"
|
|
104
|
-
>
|
|
105
|
-
<ll-paper :tilt="false">
|
|
106
|
-
<view class="ll-dialog__inside">
|
|
107
|
-
<view class="ll-dialog__header">
|
|
108
|
-
<text class="ll-dialog__title">
|
|
109
|
-
{{ title }}
|
|
110
|
-
</text>
|
|
111
|
-
<ll-button
|
|
112
|
-
v-if="showCloseButton"
|
|
113
|
-
variant="ghost"
|
|
114
|
-
size="icon-sm"
|
|
115
|
-
aria-label="关闭"
|
|
116
|
-
@click="requestClose('close-button')"
|
|
117
|
-
>
|
|
118
|
-
×
|
|
119
|
-
</ll-button>
|
|
120
|
-
</view>
|
|
121
|
-
<view class="ll-dialog__body">
|
|
122
|
-
<slot />
|
|
123
|
-
</view>
|
|
124
|
-
<view
|
|
125
|
-
v-if="$slots.footer"
|
|
126
|
-
class="ll-dialog__footer"
|
|
127
|
-
>
|
|
128
|
-
<slot name="footer" />
|
|
129
|
-
</view>
|
|
130
|
-
</view>
|
|
131
|
-
</ll-paper>
|
|
132
|
-
</view>
|
|
133
|
-
</view>
|
|
134
|
-
</template>
|
|
135
|
-
|
|
136
|
-
<style scoped>
|
|
137
|
-
/* 在页面根挂载时,背景、滚动内容和安全区各占独立层。 */
|
|
138
|
-
.ll-dialog { position: fixed; z-index: 1000; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
|
|
139
|
-
.ll-dialog__backdrop { position: absolute; inset: 0; background: #261e1765; pointer-events: auto; }
|
|
140
|
-
.ll-dialog__panel { position: relative; box-sizing: border-box; max-height: 88vh; width: 440px; max-width: calc(100% - 32px); overflow: auto; overscroll-behavior: contain; outline: none; pointer-events: auto; }
|
|
141
|
-
.ll-dialog__inside { padding: 20px 24px 24px; }
|
|
142
|
-
.ll-dialog__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
143
|
-
|
|
144
|
-
.ll-
|
|
145
|
-
.ll-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
.ll-dialog--center
|
|
149
|
-
.ll-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
.ll-dialog--
|
|
153
|
-
.ll-dialog--
|
|
154
|
-
.ll-dialog--
|
|
155
|
-
.ll-dialog--left {
|
|
156
|
-
.ll-dialog--
|
|
157
|
-
.ll-dialog--
|
|
158
|
-
.ll-dialog--left .ll-
|
|
159
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { nextTick, onMounted, onUnmounted, ref, watch, type ComponentPublicInstance } from 'vue'
|
|
3
|
+
import LlButton from '../ll-button/ll-button.vue'
|
|
4
|
+
import LlPaper from '../ll-paper/ll-paper.vue'
|
|
5
|
+
import { dialogProps, type DialogCloseReason } from './dialog'
|
|
6
|
+
|
|
7
|
+
defineOptions({ options: { virtualHost: true } })
|
|
8
|
+
|
|
9
|
+
const props = defineProps(dialogProps)
|
|
10
|
+
const emit = defineEmits<{ 'update:open': [open: boolean]; 'close': [reason: DialogCloseReason] }>()
|
|
11
|
+
const panel = ref<HTMLElement | ComponentPublicInstance>()
|
|
12
|
+
let returnFocus: HTMLElement | undefined
|
|
13
|
+
let mounted = false
|
|
14
|
+
|
|
15
|
+
function requestClose(reason: DialogCloseReason) {
|
|
16
|
+
// 父级拥有 open;拒绝回写时仍保持弹层打开。
|
|
17
|
+
emit('update:open', false)
|
|
18
|
+
emit('close', reason)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function backdrop() {
|
|
22
|
+
if (props.closeOnBackdrop) requestClose('backdrop')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// #ifdef H5
|
|
26
|
+
function panelElement() {
|
|
27
|
+
return panel.value instanceof HTMLElement ? panel.value : panel.value?.$el as HTMLElement | undefined
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function keyboard(event: KeyboardEvent) {
|
|
31
|
+
if (event.key === 'Escape') {
|
|
32
|
+
event.preventDefault()
|
|
33
|
+
event.stopPropagation()
|
|
34
|
+
requestClose('escape')
|
|
35
|
+
}
|
|
36
|
+
if (event.key !== 'Tab') return
|
|
37
|
+
const root = panelElement()
|
|
38
|
+
const controls = root?.querySelectorAll<HTMLElement>('button:not(:disabled), input:not(:disabled), textarea:not(:disabled), select:not(:disabled), a[href], [tabindex="0"]')
|
|
39
|
+
if (!controls?.length) {
|
|
40
|
+
event.preventDefault()
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
const first = controls[0]!
|
|
44
|
+
const last = controls[controls.length - 1]!
|
|
45
|
+
const origin = document.activeElement
|
|
46
|
+
// 保持 Tab 循环在弹层内,焦点离开时从相应端点重新进入。
|
|
47
|
+
if (event.shiftKey && (origin === first || origin === root) || !event.shiftKey && (origin === last || origin === root)) {
|
|
48
|
+
event.preventDefault()
|
|
49
|
+
if (event.shiftKey) last.focus()
|
|
50
|
+
else first.focus()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function syncFocus(open: boolean) {
|
|
55
|
+
if (open) {
|
|
56
|
+
if (document.activeElement instanceof HTMLElement) returnFocus = document.activeElement
|
|
57
|
+
await nextTick()
|
|
58
|
+
const root = panelElement()
|
|
59
|
+
if (mounted && props.open && root && !root.contains(document.activeElement)) root.focus()
|
|
60
|
+
} else {
|
|
61
|
+
await nextTick()
|
|
62
|
+
if (mounted && !props.open) returnFocus?.focus()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
onMounted(() => {
|
|
67
|
+
mounted = true
|
|
68
|
+
if (props.open) void syncFocus(true)
|
|
69
|
+
})
|
|
70
|
+
watch(panel, (_, __, onCleanup) => {
|
|
71
|
+
const element = panelElement()
|
|
72
|
+
if (!element) return
|
|
73
|
+
// 只在 H5 挂到真实面板上,面板关闭或销毁时同步移除监听。
|
|
74
|
+
element.addEventListener('keydown', keyboard)
|
|
75
|
+
onCleanup(() => element.removeEventListener('keydown', keyboard))
|
|
76
|
+
}, { flush: 'post' })
|
|
77
|
+
watch(() => props.open, syncFocus)
|
|
78
|
+
onUnmounted(() => {
|
|
79
|
+
mounted = false
|
|
80
|
+
returnFocus?.focus()
|
|
81
|
+
})
|
|
82
|
+
// #endif
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<template>
|
|
86
|
+
<view
|
|
87
|
+
v-if="open"
|
|
88
|
+
class="ll-dialog"
|
|
89
|
+
:class="'ll-dialog--' + placement"
|
|
90
|
+
>
|
|
91
|
+
<view
|
|
92
|
+
class="ll-dialog__backdrop"
|
|
93
|
+
aria-hidden="true"
|
|
94
|
+
@click.stop="backdrop"
|
|
95
|
+
@touchmove.stop.prevent
|
|
96
|
+
/>
|
|
97
|
+
<view
|
|
98
|
+
ref="panel"
|
|
99
|
+
class="ll-dialog__panel"
|
|
100
|
+
role="dialog"
|
|
101
|
+
aria-modal="true"
|
|
102
|
+
:aria-label="title"
|
|
103
|
+
tabindex="-1"
|
|
104
|
+
>
|
|
105
|
+
<ll-paper :tilt="false">
|
|
106
|
+
<view class="ll-dialog__inside">
|
|
107
|
+
<view class="ll-dialog__header">
|
|
108
|
+
<text class="ll-dialog__title">
|
|
109
|
+
{{ title }}
|
|
110
|
+
</text>
|
|
111
|
+
<ll-button
|
|
112
|
+
v-if="showCloseButton"
|
|
113
|
+
variant="ghost"
|
|
114
|
+
size="icon-sm"
|
|
115
|
+
aria-label="关闭"
|
|
116
|
+
@click="requestClose('close-button')"
|
|
117
|
+
>
|
|
118
|
+
×
|
|
119
|
+
</ll-button>
|
|
120
|
+
</view>
|
|
121
|
+
<view class="ll-dialog__body">
|
|
122
|
+
<slot />
|
|
123
|
+
</view>
|
|
124
|
+
<view
|
|
125
|
+
v-if="$slots.footer"
|
|
126
|
+
class="ll-dialog__footer"
|
|
127
|
+
>
|
|
128
|
+
<slot name="footer" />
|
|
129
|
+
</view>
|
|
130
|
+
</view>
|
|
131
|
+
</ll-paper>
|
|
132
|
+
</view>
|
|
133
|
+
</view>
|
|
134
|
+
</template>
|
|
135
|
+
|
|
136
|
+
<style scoped>
|
|
137
|
+
/* 在页面根挂载时,背景、滚动内容和安全区各占独立层。 */
|
|
138
|
+
.ll-dialog { position: fixed; z-index: 1000; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
|
|
139
|
+
.ll-dialog__backdrop { position: absolute; inset: 0; background: #261e1765; pointer-events: auto; }
|
|
140
|
+
.ll-dialog__panel { position: relative; box-sizing: border-box; max-height: 88vh; width: 440px; max-width: calc(100% - 32px); overflow: auto; overscroll-behavior: contain; outline: none; pointer-events: auto; }
|
|
141
|
+
.ll-dialog__inside { padding: 20px 24px 24px; }
|
|
142
|
+
.ll-dialog__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
|
|
143
|
+
/* 宿主可单独调整标题字体,正文和操作区继续按各自的排版渲染。 */
|
|
144
|
+
.ll-dialog__title { font-family: var(--ll-dialog-title-font-family, inherit); font-size: 21px; font-weight: var(--ll-dialog-title-font-weight, 700); line-height: 1.3; }
|
|
145
|
+
.ll-dialog__body { margin-top: 16px; }
|
|
146
|
+
.ll-dialog__footer { margin-top: 20px; }
|
|
147
|
+
@media (max-width: 639px) {
|
|
148
|
+
.ll-dialog--center { align-items: flex-end; }
|
|
149
|
+
.ll-dialog--center .ll-dialog__panel { max-width: 100%; width: 100%; }
|
|
150
|
+
.ll-dialog__inside { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
|
|
151
|
+
}
|
|
152
|
+
.ll-dialog--top { align-items: flex-start; }
|
|
153
|
+
.ll-dialog--bottom { align-items: flex-end; }
|
|
154
|
+
.ll-dialog--top .ll-dialog__panel, .ll-dialog--bottom .ll-dialog__panel { width: 100%; max-width: 100%; }
|
|
155
|
+
.ll-dialog--left, .ll-dialog--right { align-items: stretch; }
|
|
156
|
+
.ll-dialog--left { justify-content: flex-start; }
|
|
157
|
+
.ll-dialog--right { justify-content: flex-end; }
|
|
158
|
+
.ll-dialog--left .ll-dialog__panel, .ll-dialog--right .ll-dialog__panel { max-height: 100%; max-width: 92%; }
|
|
159
|
+
.ll-dialog--left .ll-dialog__inside, .ll-dialog--right .ll-dialog__inside { min-height: 100vh; box-sizing: border-box; }
|
|
160
|
+
</style>
|
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue'
|
|
3
|
-
import { renderArt } from '../../common/art'
|
|
4
|
-
import glyphs from '../../common/icons.json'
|
|
5
|
-
import aliases from '../../common/icon-aliases.json'
|
|
6
|
-
import { useLooseleafTheme } from '../../common/theme'
|
|
7
|
-
|
|
8
|
-
const props = withDefaults(defineProps<{ name: string; size?: number; label?: string; flip?: boolean | 'x' | 'y' }>(), { size: 16 })
|
|
9
|
-
const theme = useLooseleafTheme()
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { renderArt } from '../../common/art'
|
|
4
|
+
import glyphs from '../../common/icons.json'
|
|
5
|
+
import aliases from '../../common/icon-aliases.json'
|
|
6
|
+
import { useLooseleafTheme } from '../../common/theme'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{ name: string; size?: number; label?: string; flip?: boolean | 'x' | 'y' }>(), { size: 16 })
|
|
9
|
+
const theme = useLooseleafTheme()
|
|
10
|
+
// 避免微信开发者工具为数组解构引入无法加载的 SWC 运行时辅助模块。
|
|
11
|
+
const aliasMap = new Map<string, string>()
|
|
12
|
+
Object.entries(aliases).forEach(entry => {
|
|
13
|
+
entry[1].forEach(name => aliasMap.set(name, entry[0]))
|
|
14
|
+
})
|
|
15
|
+
const definition = computed(() => {
|
|
16
|
+
const id = aliasMap.get(props.name) ?? props.name
|
|
17
|
+
return Object.prototype.hasOwnProperty.call(glyphs, id) ? glyphs[id as keyof typeof glyphs] : undefined
|
|
18
|
+
})
|
|
19
|
+
const style = computed(() => ({
|
|
20
|
+
width: props.size + 'px',
|
|
21
|
+
height: props.size + 'px',
|
|
22
|
+
backgroundImage: definition.value && renderArt(definition.value, props.size, theme.value.ink),
|
|
23
|
+
transform: props.flip ? props.flip === 'y' ? 'scaleY(-1)' : 'scaleX(-1)' : 'none',
|
|
24
|
+
}))
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<view
|
|
29
|
+
v-if="definition"
|
|
30
|
+
class="ll-icon"
|
|
31
|
+
:style="style"
|
|
32
|
+
:aria-hidden="!label"
|
|
33
|
+
:role="label ? 'img' : undefined"
|
|
34
|
+
:aria-label="label"
|
|
35
|
+
/>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<style scoped>
|
|
39
|
+
/* 装饰图标默认略过,具名图标交给读屏报告。 */
|
|
40
|
+
.ll-icon { display: inline-block; vertical-align: middle; flex-shrink: 0; background-repeat: no-repeat; background-size: contain; pointer-events: none; }
|
|
41
|
+
</style>
|
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { computed } from 'vue'
|
|
3
|
-
import { inkOutline, svgBackground } from '../../common/ink'
|
|
4
|
-
import { useLooseleafTheme } from '../../common/theme'
|
|
5
|
-
import { useInkBox } from '../../composables/use-ink-box'
|
|
6
|
-
import { inputProps } from './input'
|
|
7
|
-
|
|
8
|
-
defineOptions({ options: { virtualHost: true } })
|
|
9
|
-
|
|
10
|
-
const props = defineProps(inputProps)
|
|
11
|
-
const emit = defineEmits<{
|
|
12
|
-
'update:modelValue': [value: string]
|
|
13
|
-
'focus': [event: unknown]
|
|
14
|
-
'blur': [event: unknown]
|
|
15
|
-
'confirm': [value: string]
|
|
16
|
-
}>()
|
|
17
|
-
const theme = useLooseleafTheme()
|
|
18
|
-
const box = useInkBox('.ll-input')
|
|
19
|
-
const style = computed(() => {
|
|
20
|
-
const color = props.invalid ? theme.value.destructive : theme.value.muted
|
|
21
|
-
const size = box.value
|
|
22
|
-
return {
|
|
23
|
-
color: theme.value.ink,
|
|
24
|
-
backgroundColor: theme.value.slip,
|
|
25
|
-
'--ll-input-stroke': color,
|
|
26
|
-
'--ll-input-focus': theme.value.primary,
|
|
27
|
-
backgroundImage: size && svgBackground(size.width, size.height, `<path d="${inkOutline(size.width, size.height, props.seed, 3)}" stroke="${color}" fill="none" stroke-width="1.4"/>`),
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
function readValue(event: unknown) {
|
|
32
|
-
return (event as { detail: { value: string } }).detail.value
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function update(event:
|
|
36
|
-
//
|
|
37
|
-
emit('update:modelValue', readValue(event))
|
|
38
|
-
}
|
|
39
|
-
</script>
|
|
40
|
-
|
|
41
|
-
<template>
|
|
42
|
-
<view
|
|
43
|
-
class="ll-input"
|
|
44
|
-
:class="{ 'll-input--drawn': box }"
|
|
45
|
-
:style="style"
|
|
46
|
-
>
|
|
47
|
-
<input
|
|
48
|
-
:id="id"
|
|
49
|
-
class="ll-input__control"
|
|
50
|
-
:name="name"
|
|
51
|
-
type="text"
|
|
52
|
-
:value="modelValue"
|
|
53
|
-
:placeholder="placeholder"
|
|
54
|
-
:disabled="disabled"
|
|
55
|
-
:focus="focus"
|
|
56
|
-
:maxlength="maxlength"
|
|
57
|
-
:aria-label="ariaLabel"
|
|
58
|
-
:aria-invalid="invalid"
|
|
59
|
-
@input="update"
|
|
60
|
-
@focus="emit('focus', $event)"
|
|
61
|
-
@blur="emit('blur', $event)"
|
|
62
|
-
@confirm="emit('confirm', readValue($event))"
|
|
63
|
-
>
|
|
64
|
-
</view>
|
|
65
|
-
</template>
|
|
66
|
-
|
|
67
|
-
<style scoped>
|
|
68
|
-
/* 输入框保留端侧输入法、键盘和确认键行为。 */
|
|
69
|
-
.ll-input { position: relative; border: 1px solid var(--ll-input-stroke); border-radius: 3px; background-size: 100% 100%; }
|
|
70
|
-
.ll-input--drawn { border-color: transparent; }
|
|
71
|
-
.ll-input:focus-within { outline: 2px dashed var(--ll-input-focus); outline-offset: 2px; }
|
|
72
|
-
.ll-input__control { box-sizing: border-box; width: 100%; height: 40px; padding: 0 12px; font-size: 16px; color: inherit; }
|
|
73
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
import { inkOutline, svgBackground } from '../../common/ink'
|
|
4
|
+
import { useLooseleafTheme } from '../../common/theme'
|
|
5
|
+
import { useInkBox } from '../../composables/use-ink-box'
|
|
6
|
+
import { inputProps } from './input'
|
|
7
|
+
|
|
8
|
+
defineOptions({ options: { virtualHost: true } })
|
|
9
|
+
|
|
10
|
+
const props = defineProps(inputProps)
|
|
11
|
+
const emit = defineEmits<{
|
|
12
|
+
'update:modelValue': [value: string]
|
|
13
|
+
'focus': [event: unknown]
|
|
14
|
+
'blur': [event: unknown]
|
|
15
|
+
'confirm': [value: string]
|
|
16
|
+
}>()
|
|
17
|
+
const theme = useLooseleafTheme()
|
|
18
|
+
const box = useInkBox('.ll-input')
|
|
19
|
+
const style = computed(() => {
|
|
20
|
+
const color = props.invalid ? theme.value.destructive : theme.value.muted
|
|
21
|
+
const size = box.value
|
|
22
|
+
return {
|
|
23
|
+
color: theme.value.ink,
|
|
24
|
+
backgroundColor: theme.value.slip,
|
|
25
|
+
'--ll-input-stroke': color,
|
|
26
|
+
'--ll-input-focus': theme.value.primary,
|
|
27
|
+
backgroundImage: size && svgBackground(size.width, size.height, `<path d="${inkOutline(size.width, size.height, props.seed, 3)}" stroke="${color}" fill="none" stroke-width="1.4"/>`),
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
function readValue(event: unknown) {
|
|
32
|
+
return (event as { detail: { value: string } }).detail.value
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function update(event: unknown) {
|
|
36
|
+
// 微信事件不实现 DOM Event,只读取 uni-app 定义的 detail.value。
|
|
37
|
+
emit('update:modelValue', readValue(event))
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<view
|
|
43
|
+
class="ll-input"
|
|
44
|
+
:class="{ 'll-input--drawn': box }"
|
|
45
|
+
:style="style"
|
|
46
|
+
>
|
|
47
|
+
<input
|
|
48
|
+
:id="id"
|
|
49
|
+
class="ll-input__control"
|
|
50
|
+
:name="name"
|
|
51
|
+
type="text"
|
|
52
|
+
:value="modelValue"
|
|
53
|
+
:placeholder="placeholder"
|
|
54
|
+
:disabled="disabled"
|
|
55
|
+
:focus="focus"
|
|
56
|
+
:maxlength="maxlength"
|
|
57
|
+
:aria-label="ariaLabel"
|
|
58
|
+
:aria-invalid="invalid"
|
|
59
|
+
@input="update"
|
|
60
|
+
@focus="emit('focus', $event)"
|
|
61
|
+
@blur="emit('blur', $event)"
|
|
62
|
+
@confirm="emit('confirm', readValue($event))"
|
|
63
|
+
>
|
|
64
|
+
</view>
|
|
65
|
+
</template>
|
|
66
|
+
|
|
67
|
+
<style scoped>
|
|
68
|
+
/* 输入框保留端侧输入法、键盘和确认键行为。 */
|
|
69
|
+
.ll-input { position: relative; border: 1px solid var(--ll-input-stroke); border-radius: 3px; background-size: 100% 100%; }
|
|
70
|
+
.ll-input--drawn { border-color: transparent; }
|
|
71
|
+
.ll-input:focus-within { outline: 2px dashed var(--ll-input-focus); outline-offset: 2px; }
|
|
72
|
+
.ll-input__control { box-sizing: border-box; width: 100%; height: 40px; padding: 0 12px; font-size: 16px; color: inherit; }
|
|
73
|
+
</style>
|