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
package/attributes.json
CHANGED
package/lib/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# 更新日志
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Button 增加 `block`,在原生按钮上应用全宽样式。
|
|
6
|
+
- Dialog 增加标题字体和字重 CSS 变量,Sheet 和 Drawer 同样适用。
|
|
7
|
+
- 兼容微信小程序的输入事件类型、图标别名编译和复选框禁用样式。
|
|
8
|
+
|
|
9
|
+
## 0.1.1
|
|
10
|
+
|
|
11
|
+
- 默认主色改为暖橙,文档品牌色同步调整,主色文字使用深墨色。
|
|
12
|
+
- H5 开关、单选组和滑块使用纸白底、墨线描边及暖橙选中态,保留端侧交互。开关示例增加点阵纸与可点击标签。
|
|
13
|
+
- 进度条、复选框、多行输入、验证码输入、头像、纸带和附件的相关状态接入共享主题。
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
- 接入 uni-app 示例、VitePress 文档、本地 npm 包及 uni_modules 模块。
|
package/lib/common/theme.ts
CHANGED
|
@@ -13,7 +13,7 @@ export interface LooseleafTheme {
|
|
|
13
13
|
highlight: string
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
//
|
|
16
|
+
// 使用固定快照的纸色、石墨与橙色记号笔,主色上的文字沿用深墨色。
|
|
17
17
|
export const looseleafTheme: Readonly<LooseleafTheme> = {
|
|
18
18
|
ink: '#2a2420',
|
|
19
19
|
paper: '#f8f5ee',
|
|
@@ -21,8 +21,8 @@ export const looseleafTheme: Readonly<LooseleafTheme> = {
|
|
|
21
21
|
graph: '#f4f7ef',
|
|
22
22
|
slip: '#fbf8f1',
|
|
23
23
|
muted: '#6f6256',
|
|
24
|
-
primary: '#
|
|
25
|
-
onPrimary: '#
|
|
24
|
+
primary: '#df6b3c',
|
|
25
|
+
onPrimary: '#2a2420',
|
|
26
26
|
destructive: '#a9362d',
|
|
27
27
|
highlight: '#f3d47c',
|
|
28
28
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { useLooseleafTheme } from '../../common/theme'
|
|
2
3
|
import LlIcon from '../ll-icon/ll-icon.vue'
|
|
3
4
|
import LlButton from '../ll-button/ll-button.vue'
|
|
4
5
|
withDefaults(defineProps<{ name: string; description?: string; state?: 'done' | 'uploading' | 'error'; removable?: boolean }>(), { state: 'done' })
|
|
5
6
|
const emit = defineEmits<{ remove: [] }>()
|
|
7
|
+
const theme = useLooseleafTheme()
|
|
6
8
|
</script>
|
|
7
9
|
<template>
|
|
8
10
|
<view
|
|
9
11
|
class="ll-attachment"
|
|
10
12
|
:class="'ll-attachment--' + state"
|
|
13
|
+
:style="{ '--ll-attachment-uploading': theme.primary, '--ll-attachment-error': theme.destructive }"
|
|
11
14
|
>
|
|
12
15
|
<ll-icon
|
|
13
16
|
name="paperclip"
|
|
@@ -37,6 +40,7 @@ const emit = defineEmits<{ remove: [] }>()
|
|
|
37
40
|
.ll-attachment { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px dashed #8b745f; }
|
|
38
41
|
.ll-attachment__body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
|
|
39
42
|
.ll-attachment__description { display: block; color: #6b5d50; font-size: 13px; }
|
|
40
|
-
|
|
41
|
-
.ll-attachment--
|
|
43
|
+
/* 上传中使用记号笔主色,错误边框使用主题的危险色。 */
|
|
44
|
+
.ll-attachment--error { border-color: var(--ll-attachment-error); }
|
|
45
|
+
.ll-attachment--uploading { border-color: var(--ll-attachment-uploading); }
|
|
42
46
|
</style>
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { ref, watch } from 'vue'
|
|
3
|
+
import { useLooseleafTheme } from '../../common/theme'
|
|
4
|
+
|
|
3
5
|
const props = withDefaults(defineProps<{ src?: string; label: string; size?: 'sm' | 'default' | 'lg' | 'xl'; ring?: 'ink' | 'you' | 'marker' | 'none' }>(), { size: 'default', ring: 'ink' })
|
|
6
|
+
const theme = useLooseleafTheme()
|
|
4
7
|
const loaded = ref(false)
|
|
5
8
|
watch(() => props.src, () => { loaded.value = false })
|
|
6
9
|
</script>
|
|
@@ -8,6 +11,7 @@ watch(() => props.src, () => { loaded.value = false })
|
|
|
8
11
|
<view
|
|
9
12
|
class="ll-avatar"
|
|
10
13
|
:class="['ll-avatar--' + size, 'll-avatar--' + ring]"
|
|
14
|
+
:style="{ '--ll-avatar-marker': theme.primary }"
|
|
11
15
|
role="img"
|
|
12
16
|
:aria-label="label"
|
|
13
17
|
>
|
|
@@ -41,7 +45,10 @@ watch(() => props.src, () => { loaded.value = false })
|
|
|
41
45
|
<style scoped>
|
|
42
46
|
.ll-avatar { display: inline-flex; position: relative; width: 36px; height: 36px; border: 1px solid #59493b; border-radius: 49% 51% 47% 53%; background: #efdfbf; vertical-align: middle; }
|
|
43
47
|
.ll-avatar--sm { width: 24px; height: 24px; }.ll-avatar--lg { width: 44px; height: 44px; }.ll-avatar--xl { width: 58px; height: 58px; }
|
|
44
|
-
|
|
48
|
+
/* 记号笔环随主色切换,蓝墨签名环仍使用独立笔色。 */
|
|
49
|
+
.ll-avatar--you { border-color: #36547a; }
|
|
50
|
+
.ll-avatar--marker { border-color: var(--ll-avatar-marker); }
|
|
51
|
+
.ll-avatar--none { border-color: transparent; }
|
|
45
52
|
.ll-avatar__photo, .ll-avatar__fallback { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: inherit; }
|
|
46
53
|
.ll-avatar__photo { opacity: 0; }.ll-avatar__photo--loaded { opacity: 1; }
|
|
47
54
|
.ll-avatar__fallback { display: grid; place-items: center; }.ll-avatar__badge { position: absolute; inset-inline-end: -2px; inset-block-end: -1px; }
|
|
@@ -7,7 +7,12 @@ const props = withDefaults(defineProps<{ variant?: ButtonVariant; size?: 'sm' |
|
|
|
7
7
|
const theme = useLooseleafTheme()
|
|
8
8
|
const style = computed(() => {
|
|
9
9
|
const fill = { default: theme.value.primary, destructive: theme.value.destructive, secondary: theme.value.highlight, outline: 'transparent', ghost: 'transparent', link: 'transparent' }
|
|
10
|
-
|
|
10
|
+
// 危险徽记在深红底上使用纸白色,主色徽记使用主题的主色文字。
|
|
11
|
+
const ink = props.variant === 'destructive' ? theme.value.slip : theme.value.ink
|
|
12
|
+
return {
|
|
13
|
+
backgroundColor: fill[props.variant],
|
|
14
|
+
color: props.variant === 'default' ? theme.value.onPrimary : ink,
|
|
15
|
+
}
|
|
11
16
|
})
|
|
12
17
|
</script>
|
|
13
18
|
|
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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,91 +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
|
-
|
|
17
|
-
|
|
18
|
-
'
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
:
|
|
47
|
-
|
|
48
|
-
:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
.ll-button
|
|
86
|
-
.ll-button--
|
|
87
|
-
.ll-button--
|
|
88
|
-
.ll-button
|
|
89
|
-
.ll-button--
|
|
90
|
-
.ll-button--
|
|
91
|
-
|
|
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,54 +1,70 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
:
|
|
18
|
-
|
|
19
|
-
:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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>
|