looseleaf-uni 0.1.1 → 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 CHANGED
@@ -7,6 +7,10 @@
7
7
  "description": "尺寸",
8
8
  "type": "ButtonSize"
9
9
  },
10
+ "ll-button/block": {
11
+ "description": "铺满容器宽度",
12
+ "type": "boolean"
13
+ },
10
14
  "ll-button/disabled": {
11
15
  "description": "禁止激活",
12
16
  "type": "boolean"
package/lib/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # 更新日志
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Button 增加 `block`,在原生按钮上应用全宽样式。
6
+ - Dialog 增加标题字体和字重 CSS 变量,Sheet 和 Drawer 同样适用。
7
+ - 兼容微信小程序的输入事件类型、图标别名编译和复选框禁用样式。
8
+
3
9
  ## 0.1.1
4
10
 
5
11
  - 默认主色改为暖橙,文档品牌色同步调整,主色文字使用深墨色。
@@ -1,42 +1,43 @@
1
- import type { ExtractPublicPropTypes, PropType } from 'vue'
2
- import { inkOutline, svgBackground, type InkSeed } from '../../common/ink'
3
- import type { LooseleafTheme } from '../../common/theme'
4
-
5
- export const buttonVariants = ['default', 'destructive', 'outline', 'secondary', 'ghost', 'link'] as const
6
- export const buttonSizes = ['default', 'xs', 'sm', 'lg', 'icon', 'icon-xs', 'icon-sm', 'icon-lg'] as const
7
- export type ButtonVariant = typeof buttonVariants[number]
8
- export type ButtonSize = typeof buttonSizes[number]
9
-
10
- // 运行时直接读取属性表,避免微信增量编译复用旧的类型推导结果。
11
- export const buttonProps = {
12
- variant: { type: String as PropType<ButtonVariant>, default: 'default' },
13
- size: { type: String as PropType<ButtonSize>, default: 'default' },
14
- disabled: Boolean,
15
- seed: { type: [String, Number] as PropType<InkSeed>, default: 'button' },
16
- id: String,
17
- ariaLabel: String,
18
- role: { type: String as PropType<'button' | 'tab' | 'checkbox'>, default: 'button' },
19
- tabIndex: { type: Number, default: 0 },
20
- } as const
21
-
22
- export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>
23
-
24
- export function buttonInk(width: number, height: number, variant: ButtonVariant, seed: InkSeed, theme: LooseleafTheme, disabled: boolean) {
25
- const fills: Record<ButtonVariant, string> = {
26
- default: theme.primary,
27
- destructive: theme.destructive,
28
- outline: 'none',
29
- secondary: theme.highlight,
30
- ghost: 'none',
31
- link: 'none',
32
- }
33
- // 胶片按实测宽高绘制,拉宽后笔触仍保持原来的像素宽度。
34
- const outline = inkOutline(width, height, seed)
35
- const fill = disabled ? 'none' : fills[variant]
36
- const stroke = disabled ? theme.muted : theme.ink
37
- const isFilled = variant !== 'ghost' && variant !== 'link'
38
- const shapes = isFilled
39
- ? `<path d="${outline}" fill="${fill}" stroke="${stroke}" stroke-width="1.15" ${disabled ? 'stroke-dasharray="3 2"' : ''}/>`
40
- : `<path d="M4 ${height - 4}Q${width / 2} ${height - 6} ${width - 4} ${height - 4}" fill="none" stroke="${stroke}" stroke-opacity="${variant === 'link' ? 0.7 : 0.22}"/>`
41
- return svgBackground(width, height, shapes)
42
- }
1
+ import type { ExtractPublicPropTypes, PropType } from 'vue'
2
+ import { inkOutline, svgBackground, type InkSeed } from '../../common/ink'
3
+ import type { LooseleafTheme } from '../../common/theme'
4
+
5
+ export const buttonVariants = ['default', 'destructive', 'outline', 'secondary', 'ghost', 'link'] as const
6
+ export const buttonSizes = ['default', 'xs', 'sm', 'lg', 'icon', 'icon-xs', 'icon-sm', 'icon-lg'] as const
7
+ export type ButtonVariant = typeof buttonVariants[number]
8
+ export type ButtonSize = typeof buttonSizes[number]
9
+
10
+ // 运行时直接读取属性表,避免微信增量编译复用旧的类型推导结果。
11
+ export const buttonProps = {
12
+ variant: { type: String as PropType<ButtonVariant>, default: 'default' },
13
+ size: { type: String as PropType<ButtonSize>, default: 'default' },
14
+ block: Boolean,
15
+ disabled: Boolean,
16
+ seed: { type: [String, Number] as PropType<InkSeed>, default: 'button' },
17
+ id: String,
18
+ ariaLabel: String,
19
+ role: { type: String as PropType<'button' | 'tab' | 'checkbox'>, default: 'button' },
20
+ tabIndex: { type: Number, default: 0 },
21
+ } as const
22
+
23
+ export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>
24
+
25
+ export function buttonInk(width: number, height: number, variant: ButtonVariant, seed: InkSeed, theme: LooseleafTheme, disabled: boolean) {
26
+ const fills: Record<ButtonVariant, string> = {
27
+ default: theme.primary,
28
+ destructive: theme.destructive,
29
+ outline: 'none',
30
+ secondary: theme.highlight,
31
+ ghost: 'none',
32
+ link: 'none',
33
+ }
34
+ // 胶片按实测宽高绘制,拉宽后笔触仍保持原来的像素宽度。
35
+ const outline = inkOutline(width, height, seed)
36
+ const fill = disabled ? 'none' : fills[variant]
37
+ const stroke = disabled ? theme.muted : theme.ink
38
+ const isFilled = variant !== 'ghost' && variant !== 'link'
39
+ const shapes = isFilled
40
+ ? `<path d="${outline}" fill="${fill}" stroke="${stroke}" stroke-width="1.15" ${disabled ? 'stroke-dasharray="3 2"' : ''}/>`
41
+ : `<path d="M4 ${height - 4}Q${width / 2} ${height - 6} ${width - 4} ${height - 4}" fill="none" stroke="${stroke}" stroke-opacity="${variant === 'link' ? 0.7 : 0.22}"/>`
42
+ return svgBackground(width, height, shapes)
43
+ }
@@ -1,97 +1,99 @@
1
- <script setup lang="ts">
2
- import { computed } from 'vue'
3
- import { useLooseleafTheme } from '../../common/theme'
4
- import { useInkBox } from '../../composables/use-ink-box'
5
- import { buttonInk, buttonProps } from './button'
6
-
7
- defineOptions({ options: { virtualHost: true } })
8
-
9
- const props = defineProps(buttonProps)
10
- const emit = defineEmits<{ click: [event: unknown] }>()
11
- const theme = useLooseleafTheme()
12
- const box = useInkBox('.ll-button')
13
- const isSolid = computed(() => props.variant === 'default' || props.variant === 'destructive')
14
- const tone = computed(() => props.variant === 'destructive' ? theme.value.destructive : theme.value.primary)
15
- // 橙色主按钮使用深墨字,红色危险按钮使用浅色纸白字以保留对比度。
16
- const textColor = computed(() => {
17
- if (props.disabled) return theme.value.muted
18
- if (props.variant === 'destructive') return theme.value.slip
19
- return isSolid.value ? theme.value.onPrimary : theme.value.ink
20
- })
21
- const style = computed(() => ({
22
- color: textColor.value,
23
- '--ll-btn-fill': isSolid.value && !props.disabled ? tone.value : 'transparent',
24
- '--ll-btn-focus': theme.value.primary,
25
- backgroundImage: box.value && buttonInk(box.value.width, box.value.height, props.variant, props.seed, theme.value, props.disabled),
26
- }))
27
-
28
- function activate(event: unknown) {
29
- // 原生禁用态和事件闸门共同约束一次有效激活。
30
- if (!props.disabled) emit('click', event)
31
- }
32
-
33
- function keyDown(event: KeyboardEvent) {
34
- if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
35
- }
36
-
37
- function keyUp(event: KeyboardEvent) {
38
- // 松键时再打开弹层,避免同一次 Enter 落到新聚焦的输入框并确认它。
39
- if (event.key === 'Enter' || event.key === ' ') activate(event)
40
- }
41
- </script>
42
-
43
- <template>
44
- <!-- 让调用方的 ID 直接落在可点击的原生按钮上。 -->
45
- <button
46
- :id="id"
47
- class="ll-button"
48
- :class="['ll-button--' + size, { 'll-button--drawn': box }]"
49
- :style="style"
50
- :disabled="disabled"
51
- :aria-label="ariaLabel"
52
- :role="role"
53
- :tabindex="disabled ? -1 : tabIndex"
54
- :aria-disabled="disabled"
55
- hover-class="ll-button--pressed"
56
- @click.stop="activate"
57
- @keydown="keyDown"
58
- @keyup="keyUp"
59
- >
60
- <slot />
61
- </button>
62
- </template>
63
-
64
- <style scoped>
65
- /* 文字和点击区由原生 button 提供,绘制图层只承担外观。 */
66
- .ll-button {
67
- box-sizing: border-box;
68
- display: inline-flex;
69
- align-items: center;
70
- justify-content: center;
71
- min-height: 36px;
72
- padding: 6px 16px;
73
- margin: 0;
74
- border: 0;
75
- border-radius: 4px;
76
- background-color: var(--ll-btn-fill);
77
- background-repeat: no-repeat;
78
- background-size: 100% 100%;
79
- font: inherit;
80
- font-weight: 700;
81
- line-height: 1.25;
82
- white-space: normal;
83
- vertical-align: middle;
84
- }
85
- .ll-button::after { border: 0; }
86
- .ll-button--drawn { background-color: transparent; }
87
- .ll-button--pressed, .ll-button:active { transform: translateY(1px); }
88
- .ll-button:focus-visible { outline: 2px dashed var(--ll-btn-focus); outline-offset: 3px; }
89
- .ll-button--xs { min-height: 24px; padding: 3px 8px; font-size: 14px; }
90
- .ll-button--sm { min-height: 32px; padding: 4px 12px; font-size: 15px; }
91
- .ll-button--lg { min-height: 40px; padding: 7px 24px; font-size: 17px; }
92
- .ll-button--icon, .ll-button--icon-xs, .ll-button--icon-sm, .ll-button--icon-lg { padding: 0; }
93
- .ll-button--icon { width: 36px; }
94
- .ll-button--icon-xs { width: 24px; min-height: 24px; }
95
- .ll-button--icon-sm { width: 32px; min-height: 32px; }
96
- .ll-button--icon-lg { width: 40px; min-height: 40px; }
97
- </style>
1
+ <script setup lang="ts">
2
+ import { computed } from 'vue'
3
+ import { useLooseleafTheme } from '../../common/theme'
4
+ import { useInkBox } from '../../composables/use-ink-box'
5
+ import { buttonInk, buttonProps } from './button'
6
+
7
+ defineOptions({ options: { virtualHost: true } })
8
+
9
+ const props = defineProps(buttonProps)
10
+ const emit = defineEmits<{ click: [event: unknown] }>()
11
+ const theme = useLooseleafTheme()
12
+ const box = useInkBox('.ll-button')
13
+ const isSolid = computed(() => props.variant === 'default' || props.variant === 'destructive')
14
+ const tone = computed(() => props.variant === 'destructive' ? theme.value.destructive : theme.value.primary)
15
+ // 橙色主按钮使用深墨字,红色危险按钮使用浅色纸白字以保留对比度。
16
+ const textColor = computed(() => {
17
+ if (props.disabled) return theme.value.muted
18
+ if (props.variant === 'destructive') return theme.value.slip
19
+ return isSolid.value ? theme.value.onPrimary : theme.value.ink
20
+ })
21
+ const style = computed(() => ({
22
+ color: textColor.value,
23
+ '--ll-btn-fill': isSolid.value && !props.disabled ? tone.value : 'transparent',
24
+ '--ll-btn-focus': theme.value.primary,
25
+ backgroundImage: box.value && buttonInk(box.value.width, box.value.height, props.variant, props.seed, theme.value, props.disabled),
26
+ }))
27
+
28
+ function activate(event: unknown) {
29
+ // 原生禁用态和事件闸门共同约束一次有效激活。
30
+ if (!props.disabled) emit('click', event)
31
+ }
32
+
33
+ function keyDown(event: KeyboardEvent) {
34
+ if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
35
+ }
36
+
37
+ function keyUp(event: KeyboardEvent) {
38
+ // 松键时再打开弹层,避免同一次 Enter 落到新聚焦的输入框并确认它。
39
+ if (event.key === 'Enter' || event.key === ' ') activate(event)
40
+ }
41
+ </script>
42
+
43
+ <template>
44
+ <!-- 让调用方的 ID 直接落在可点击的原生按钮上。 -->
45
+ <button
46
+ :id="id"
47
+ class="ll-button"
48
+ :class="['ll-button--' + size, { 'll-button--drawn': box, 'll-button--block': block }]"
49
+ :style="style"
50
+ :disabled="disabled"
51
+ :aria-label="ariaLabel"
52
+ :role="role"
53
+ :tabindex="disabled ? -1 : tabIndex"
54
+ :aria-disabled="disabled"
55
+ hover-class="ll-button--pressed"
56
+ @click.stop="activate"
57
+ @keydown="keyDown"
58
+ @keyup="keyUp"
59
+ >
60
+ <slot />
61
+ </button>
62
+ </template>
63
+
64
+ <style scoped>
65
+ /* 文字和点击区由原生 button 提供,绘制图层只承担外观。 */
66
+ .ll-button {
67
+ box-sizing: border-box;
68
+ display: inline-flex;
69
+ align-items: center;
70
+ justify-content: center;
71
+ min-height: 36px;
72
+ padding: 6px 16px;
73
+ margin: 0;
74
+ border: 0;
75
+ border-radius: 4px;
76
+ background-color: var(--ll-btn-fill);
77
+ background-repeat: no-repeat;
78
+ background-size: 100% 100%;
79
+ font: inherit;
80
+ font-weight: 700;
81
+ line-height: 1.25;
82
+ white-space: normal;
83
+ vertical-align: middle;
84
+ }
85
+ .ll-button::after { border: 0; }
86
+ .ll-button--drawn { background-color: transparent; }
87
+ .ll-button--pressed, .ll-button:active { transform: translateY(1px); }
88
+ .ll-button:focus-visible { outline: 2px dashed var(--ll-btn-focus); outline-offset: 3px; }
89
+ .ll-button--xs { min-height: 24px; padding: 3px 8px; font-size: 14px; }
90
+ .ll-button--sm { min-height: 32px; padding: 4px 12px; font-size: 15px; }
91
+ .ll-button--lg { min-height: 40px; padding: 7px 24px; font-size: 17px; }
92
+ .ll-button--icon, .ll-button--icon-xs, .ll-button--icon-sm, .ll-button--icon-lg { padding: 0; }
93
+ .ll-button--icon { width: 36px; }
94
+ .ll-button--icon-xs { width: 24px; min-height: 24px; }
95
+ .ll-button--icon-sm { width: 32px; min-height: 32px; }
96
+ .ll-button--icon-lg { width: 40px; min-height: 40px; }
97
+ /* 铺满状态直接作用于原生按钮,覆盖图标尺寸限定的宽度,同时保留对应最小高度。 */
98
+ .ll-button--block { display: flex; width: 100%; }
99
+ </style>
@@ -1,68 +1,70 @@
1
- <script setup lang="ts">
2
- import { useLooseleafTheme } from '../../common/theme'
3
- import LlIcon from '../ll-icon/ll-icon.vue'
4
-
5
- const props = defineProps<{ modelValue: boolean; indeterminate?: boolean; disabled?: boolean; invalid?: boolean; label?: string }>()
6
- const emit = defineEmits<{ 'update:modelValue': [checked: boolean] }>()
7
- const theme = useLooseleafTheme()
8
- function toggle() {
9
- // 半选完成后变为全选,宿主同步自己的父子选项状态。
10
- if (!props.disabled) emit('update:modelValue', props.indeterminate || !props.modelValue)
11
- }
12
- </script>
13
-
14
- <template>
15
- <button
16
- class="ll-checkbox"
17
- role="checkbox"
18
- :aria-checked="indeterminate ? 'mixed' : modelValue"
19
- :aria-label="label"
20
- :aria-invalid="invalid"
21
- :disabled="disabled"
22
- @click.stop="toggle"
23
- >
24
- <view
25
- class="ll-checkbox__box"
26
- aria-hidden="true"
27
- :class="{ 'll-checkbox__box--invalid': invalid, 'll-checkbox__box--marked': indeterminate || modelValue }"
28
- :style="{
29
- '--ll-checkbox-paper': theme.slip,
30
- '--ll-checkbox-ink': theme.ink,
31
- '--ll-checkbox-fill': disabled ? theme.muted : theme.primary,
32
- '--ll-checkbox-error': theme.destructive,
33
- }"
34
- >
35
- <ll-icon
36
- v-if="indeterminate || modelValue"
37
- :name="indeterminate ? 'minus' : 'check'"
38
- />
39
- </view>
40
- <slot>{{ label }}</slot>
41
- </button>
42
- </template>
43
-
44
- <style scoped>
45
- /* 文本与笔画同属一个点击目标,点文字只触发一次更新。 */
46
- .ll-checkbox { display: inline-flex; padding: 3px 0; margin: 0; border: 0; background: transparent; color: inherit; align-items: center; gap: 8px; text-align: start; font: inherit; }
47
- .ll-checkbox::after { border: 0; }
48
- /* 固定 16px 图标的占位,切换勾选状态时方框和标签位置保持一致。 */
49
- .ll-checkbox__box {
50
- display: inline-flex;
51
- flex: none;
52
- box-sizing: content-box;
53
- width: 16px;
54
- height: 16px;
55
- padding: 1px;
56
- background-color: var(--ll-checkbox-paper);
57
- border: 1px solid var(--ll-checkbox-ink);
58
- border-radius: 4px 2px 4px 3px;
59
- }
60
- /* 勾选和半选叠同一层记号笔,具体状态由勾或横线区分。 */
61
- .ll-checkbox__box--marked {
62
- background-color: var(--ll-checkbox-fill);
63
- background-image: radial-gradient(rgb(42 36 32 / 12%) .4px, transparent .75px);
64
- background-size: 3px 3px;
65
- }
66
- .ll-checkbox__box--invalid { border-color: var(--ll-checkbox-error); }
67
- .ll-checkbox[disabled] { opacity: .55; }
68
- </style>
1
+ <script setup lang="ts">
2
+ import { useLooseleafTheme } from '../../common/theme'
3
+ import LlIcon from '../ll-icon/ll-icon.vue'
4
+
5
+ const props = defineProps<{ modelValue: boolean; indeterminate?: boolean; disabled?: boolean; invalid?: boolean; label?: string }>()
6
+ const emit = defineEmits<{ 'update:modelValue': [checked: boolean] }>()
7
+ const theme = useLooseleafTheme()
8
+ function toggle() {
9
+ // 半选完成后变为全选,宿主同步自己的父子选项状态。
10
+ if (!props.disabled) emit('update:modelValue', props.indeterminate || !props.modelValue)
11
+ }
12
+ </script>
13
+
14
+ <template>
15
+ <button
16
+ class="ll-checkbox"
17
+ :class="{ 'll-checkbox--disabled': disabled }"
18
+ role="checkbox"
19
+ :aria-checked="indeterminate ? 'mixed' : modelValue"
20
+ :aria-label="label"
21
+ :aria-invalid="invalid"
22
+ :disabled="disabled"
23
+ @click.stop="toggle"
24
+ >
25
+ <view
26
+ class="ll-checkbox__box"
27
+ aria-hidden="true"
28
+ :class="{ 'll-checkbox__box--invalid': invalid, 'll-checkbox__box--marked': indeterminate || modelValue }"
29
+ :style="{
30
+ '--ll-checkbox-paper': theme.slip,
31
+ '--ll-checkbox-ink': theme.ink,
32
+ '--ll-checkbox-fill': disabled ? theme.muted : theme.primary,
33
+ '--ll-checkbox-error': theme.destructive,
34
+ }"
35
+ >
36
+ <ll-icon
37
+ v-if="indeterminate || modelValue"
38
+ :name="indeterminate ? 'minus' : 'check'"
39
+ />
40
+ </view>
41
+ <slot>{{ label }}</slot>
42
+ </button>
43
+ </template>
44
+
45
+ <style scoped>
46
+ /* 文本与笔画同属一个点击目标,点文字只触发一次更新。 */
47
+ .ll-checkbox { display: inline-flex; padding: 3px 0; margin: 0; border: 0; background: transparent; color: inherit; align-items: center; gap: 8px; text-align: start; font: inherit; }
48
+ .ll-checkbox::after { border: 0; }
49
+ /* 固定 16px 图标的占位,切换勾选状态时方框和标签位置保持一致。 */
50
+ .ll-checkbox__box {
51
+ display: inline-flex;
52
+ flex: none;
53
+ box-sizing: content-box;
54
+ width: 16px;
55
+ height: 16px;
56
+ padding: 1px;
57
+ background-color: var(--ll-checkbox-paper);
58
+ border: 1px solid var(--ll-checkbox-ink);
59
+ border-radius: 4px 2px 4px 3px;
60
+ }
61
+ /* 勾选和半选叠同一层记号笔,具体状态由勾或横线区分。 */
62
+ .ll-checkbox__box--marked {
63
+ background-color: var(--ll-checkbox-fill);
64
+ background-image: radial-gradient(rgb(42 36 32 / 12%) .4px, transparent .75px);
65
+ background-size: 3px 3px;
66
+ }
67
+ .ll-checkbox__box--invalid { border-color: var(--ll-checkbox-error); }
68
+ /* 微信组件 WXSS 使用状态类保留禁用外观。 */
69
+ .ll-checkbox--disabled { opacity: .55; }
70
+ </style>
@@ -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
- .ll-dialog__title { font-size: 21px; font-weight: 700; line-height: 1.3; }
144
- .ll-dialog__body { margin-top: 16px; }
145
- .ll-dialog__footer { margin-top: 20px; }
146
- @media (max-width: 639px) {
147
- .ll-dialog--center { align-items: flex-end; }
148
- .ll-dialog--center .ll-dialog__panel { max-width: 100%; width: 100%; }
149
- .ll-dialog__inside { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
150
- }
151
- .ll-dialog--top { align-items: flex-start; }
152
- .ll-dialog--bottom { align-items: flex-end; }
153
- .ll-dialog--top .ll-dialog__panel, .ll-dialog--bottom .ll-dialog__panel { width: 100%; max-width: 100%; }
154
- .ll-dialog--left, .ll-dialog--right { align-items: stretch; }
155
- .ll-dialog--left { justify-content: flex-start; }
156
- .ll-dialog--right { justify-content: flex-end; }
157
- .ll-dialog--left .ll-dialog__panel, .ll-dialog--right .ll-dialog__panel { max-height: 100%; max-width: 92%; }
158
- .ll-dialog--left .ll-dialog__inside, .ll-dialog--right .ll-dialog__inside { min-height: 100vh; box-sizing: border-box; }
159
- </style>
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
- const aliasMap = new Map(Object.entries(aliases).flatMap(([id, names]) => names.map(name => [name, id] as const)))
11
- const definition = computed(() => {
12
- const id = aliasMap.get(props.name) ?? props.name
13
- return Object.prototype.hasOwnProperty.call(glyphs, id) ? glyphs[id as keyof typeof glyphs] : undefined
14
- })
15
- const style = computed(() => ({
16
- width: props.size + 'px',
17
- height: props.size + 'px',
18
- backgroundImage: definition.value && renderArt(definition.value, props.size, theme.value.ink),
19
- transform: props.flip ? props.flip === 'y' ? 'scaleY(-1)' : 'scaleX(-1)' : 'none',
20
- }))
21
- </script>
22
-
23
- <template>
24
- <view
25
- v-if="definition"
26
- class="ll-icon"
27
- :style="style"
28
- :aria-hidden="!label"
29
- :role="label ? 'img' : undefined"
30
- :aria-label="label"
31
- />
32
- </template>
33
-
34
- <style scoped>
35
- /* 装饰图标默认略过,具名图标交给读屏报告。 */
36
- .ll-icon { display: inline-block; vertical-align: middle; flex-shrink: 0; background-repeat: no-repeat; background-size: contain; pointer-events: none; }
37
- </style>
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: Event) {
36
- // 只使用 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>
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>
@@ -1,73 +1,73 @@
1
- <script setup lang="ts">
2
- import { computed, ref } from 'vue'
3
- import { useLooseleafTheme } from '../../common/theme'
4
-
5
- const props = withDefaults(defineProps<{ modelValue: string; maxLength?: number; separatorAfter?: number[]; disabled?: boolean; invalid?: boolean; label?: string }>(), { maxLength: 6, separatorAfter: () => [] })
6
- const emit = defineEmits<{ 'update:modelValue': [value: string]; complete: [value: string] }>()
7
- const theme = useLooseleafTheme()
8
- const focused = ref(false)
9
- const positions = computed(() => Array.from({ length: props.maxLength }, (_, index) => index))
10
- function update(event: Event) {
11
- // 一条原生输入承载粘贴、键盘和焦点,格子只表示当前值。
12
- const raw = (event as Event & { detail: { value: string } }).detail.value
13
- const value = raw.replace(/[\s‐-―-]+/g, '').slice(0, props.maxLength)
14
- emit('update:modelValue', value)
15
- if (value.length === props.maxLength && props.modelValue.length !== props.maxLength) emit('complete', value)
16
- return value
17
- }
18
- </script>
19
-
20
- <template>
21
- <view
22
- class="ll-otp"
23
- :style="{
24
- color: theme.ink,
25
- '--ll-otp-paper': theme.slip,
26
- '--ll-otp-edge': theme.muted,
27
- '--ll-otp-focus': theme.primary,
28
- '--ll-otp-error': theme.destructive,
29
- }"
30
- >
31
- <view
32
- v-for="position in positions"
33
- :key="position"
34
- class="ll-otp__unit"
35
- aria-hidden="true"
36
- >
37
- <text
38
- class="ll-otp__slot"
39
- :class="{ 'll-otp__slot--focus': focused && position === modelValue.length, 'll-otp__slot--invalid': invalid }"
40
- >
41
- {{ modelValue[position] }}
42
- </text>
43
- <text
44
- v-if="separatorAfter.includes(position)"
45
- class="ll-otp__separator"
46
- >
47
- −
48
- </text>
49
- </view>
50
- <input
51
- class="ll-otp__input"
52
- :aria-label="label"
53
- :aria-invalid="invalid"
54
- :disabled="disabled"
55
- :value="modelValue"
56
- :maxlength="-1"
57
- @input="update"
58
- @focus="focused = true"
59
- @blur="focused = false"
60
- >
61
- </view>
62
- </template>
63
-
64
- <style scoped>
65
- .ll-otp { display: inline-flex; position: relative; gap: 4px; }
66
- .ll-otp__unit { display: inline-flex; align-items: center; }
67
- .ll-otp__slot { display: inline-flex; width: 29px; height: 34px; align-items: center; justify-content: center; border: 1px dashed var(--ll-otp-edge); border-radius: 3px 5px 3px 4px; background: var(--ll-otp-paper); }
68
- /* 焦点继承主色,错误仍由危险色边框标记。 */
69
- .ll-otp__slot--focus { outline: 2px solid var(--ll-otp-focus); outline-offset: 1px; }
70
- .ll-otp__slot--invalid { border-color: var(--ll-otp-error); }
71
- .ll-otp__separator { margin: 0 3px; }
72
- .ll-otp__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .01; color: transparent; font-size: 16px; }
73
- </style>
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue'
3
+ import { useLooseleafTheme } from '../../common/theme'
4
+
5
+ const props = withDefaults(defineProps<{ modelValue: string; maxLength?: number; separatorAfter?: number[]; disabled?: boolean; invalid?: boolean; label?: string }>(), { maxLength: 6, separatorAfter: () => [] })
6
+ const emit = defineEmits<{ 'update:modelValue': [value: string]; complete: [value: string] }>()
7
+ const theme = useLooseleafTheme()
8
+ const focused = ref(false)
9
+ const positions = computed(() => Array.from({ length: props.maxLength }, (_, index) => index))
10
+ function update(event: unknown) {
11
+ // 微信事件不实现 DOM Event,统一读取原生输入的 detail.value。
12
+ const raw = (event as { detail: { value: string } }).detail.value
13
+ const value = raw.replace(/[\s‐-―-]+/g, '').slice(0, props.maxLength)
14
+ emit('update:modelValue', value)
15
+ if (value.length === props.maxLength && props.modelValue.length !== props.maxLength) emit('complete', value)
16
+ return value
17
+ }
18
+ </script>
19
+
20
+ <template>
21
+ <view
22
+ class="ll-otp"
23
+ :style="{
24
+ color: theme.ink,
25
+ '--ll-otp-paper': theme.slip,
26
+ '--ll-otp-edge': theme.muted,
27
+ '--ll-otp-focus': theme.primary,
28
+ '--ll-otp-error': theme.destructive,
29
+ }"
30
+ >
31
+ <view
32
+ v-for="position in positions"
33
+ :key="position"
34
+ class="ll-otp__unit"
35
+ aria-hidden="true"
36
+ >
37
+ <text
38
+ class="ll-otp__slot"
39
+ :class="{ 'll-otp__slot--focus': focused && position === modelValue.length, 'll-otp__slot--invalid': invalid }"
40
+ >
41
+ {{ modelValue[position] }}
42
+ </text>
43
+ <text
44
+ v-if="separatorAfter.includes(position)"
45
+ class="ll-otp__separator"
46
+ >
47
+ −
48
+ </text>
49
+ </view>
50
+ <input
51
+ class="ll-otp__input"
52
+ :aria-label="label"
53
+ :aria-invalid="invalid"
54
+ :disabled="disabled"
55
+ :value="modelValue"
56
+ :maxlength="-1"
57
+ @input="update"
58
+ @focus="focused = true"
59
+ @blur="focused = false"
60
+ >
61
+ </view>
62
+ </template>
63
+
64
+ <style scoped>
65
+ .ll-otp { display: inline-flex; position: relative; gap: 4px; }
66
+ .ll-otp__unit { display: inline-flex; align-items: center; }
67
+ .ll-otp__slot { display: inline-flex; width: 29px; height: 34px; align-items: center; justify-content: center; border: 1px dashed var(--ll-otp-edge); border-radius: 3px 5px 3px 4px; background: var(--ll-otp-paper); }
68
+ /* 焦点继承主色,错误仍由危险色边框标记。 */
69
+ .ll-otp__slot--focus { outline: 2px solid var(--ll-otp-focus); outline-offset: 1px; }
70
+ .ll-otp__slot--invalid { border-color: var(--ll-otp-error); }
71
+ .ll-otp__separator { margin: 0 3px; }
72
+ .ll-otp__input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .01; color: transparent; font-size: 16px; }
73
+ </style>
@@ -1,31 +1,31 @@
1
- <script setup lang="ts">
2
- import { useLooseleafTheme } from '../../common/theme'
3
-
4
- withDefaults(defineProps<{ modelValue: string; placeholder?: string; maxlength?: number; autoHeight?: boolean; disabled?: boolean; ariaLabel?: string }>(), { maxlength: 140 })
5
- const emit = defineEmits<{ 'update:modelValue': [value: string] }>()
6
- const theme = useLooseleafTheme()
7
- function update(event: Event) {
8
- // 多行输入与单行输入共享 uni-app 的 detail.value 结构。
9
- emit('update:modelValue', (event as Event & { detail: { value: string } }).detail.value)
10
- }
11
- </script>
12
-
13
- <template>
14
- <textarea
15
- class="ll-textarea"
16
- :style="{ color: theme.ink, backgroundColor: theme.slip, '--ll-textarea-edge': theme.muted, '--ll-textarea-focus': theme.primary }"
17
- :value="modelValue"
18
- :placeholder="placeholder"
19
- :auto-height="autoHeight"
20
- :maxlength="maxlength"
21
- :disabled="disabled"
22
- :aria-label="ariaLabel"
23
- @input="update"
24
- />
25
- </template>
26
-
27
- <style scoped>
28
- /* 多行输入和单行输入使用相同的纸底与焦点墨色。 */
29
- .ll-textarea { box-sizing: border-box; display: block; width: 100%; min-height: 80px; padding: 10px 12px; border: 1px solid var(--ll-textarea-edge); border-radius: 5px 3px 5px 3px; font: inherit; }
30
- .ll-textarea:focus-within { outline: 2px dashed var(--ll-textarea-focus); outline-offset: 2px; }
31
- </style>
1
+ <script setup lang="ts">
2
+ import { useLooseleafTheme } from '../../common/theme'
3
+
4
+ withDefaults(defineProps<{ modelValue: string; placeholder?: string; maxlength?: number; autoHeight?: boolean; disabled?: boolean; ariaLabel?: string }>(), { maxlength: 140 })
5
+ const emit = defineEmits<{ 'update:modelValue': [value: string] }>()
6
+ const theme = useLooseleafTheme()
7
+ function update(event: unknown) {
8
+ // 微信事件不实现 DOM Event,多行输入仍通过 detail.value 读值。
9
+ emit('update:modelValue', (event as { detail: { value: string } }).detail.value)
10
+ }
11
+ </script>
12
+
13
+ <template>
14
+ <textarea
15
+ class="ll-textarea"
16
+ :style="{ color: theme.ink, backgroundColor: theme.slip, '--ll-textarea-edge': theme.muted, '--ll-textarea-focus': theme.primary }"
17
+ :value="modelValue"
18
+ :placeholder="placeholder"
19
+ :auto-height="autoHeight"
20
+ :maxlength="maxlength"
21
+ :disabled="disabled"
22
+ :aria-label="ariaLabel"
23
+ @input="update"
24
+ />
25
+ </template>
26
+
27
+ <style scoped>
28
+ /* 多行输入和单行输入使用相同的纸底与焦点墨色。 */
29
+ .ll-textarea { box-sizing: border-box; display: block; width: 100%; min-height: 80px; padding: 10px 12px; border: 1px solid var(--ll-textarea-edge); border-radius: 5px 3px 5px 3px; font: inherit; }
30
+ .ll-textarea:focus-within { outline: 2px dashed var(--ll-textarea-focus); outline-offset: 2px; }
31
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "looseleaf-uni",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "提供纸张、手绘墨线和原生交互的 Vue 3 uni-app 组件库",
5
5
  "keywords": [
6
6
  "uni-app",
package/tags.json CHANGED
@@ -4,6 +4,7 @@
4
4
  "attributes": [
5
5
  "variant",
6
6
  "size",
7
+ "block",
7
8
  "disabled",
8
9
  "seed",
9
10
  "id",
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://raw.githubusercontent.com/JetBrains/web-types/master/schema/web-types.json",
3
3
  "name": "looseleaf-uni",
4
- "version": "0.1.1",
4
+ "version": "0.2.0",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "elements": [
@@ -27,6 +27,15 @@
27
27
  "default": "default"
28
28
  }
29
29
  },
30
+ {
31
+ "name": "block",
32
+ "description": "铺满容器宽度",
33
+ "value": {
34
+ "kind": "expression",
35
+ "type": "boolean",
36
+ "default": "false"
37
+ }
38
+ },
30
39
  {
31
40
  "name": "disabled",
32
41
  "description": "禁止激活",