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 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,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 模块。
@@ -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: '#36547a',
25
- onPrimary: '#ffffff',
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
- .ll-attachment--error { border-color: #a9362d; }
41
- .ll-attachment--uploading { border-color: #36547a; }
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
- .ll-avatar--you { border-color: #36547a; }.ll-avatar--marker { border-color: #d9a629; }.ll-avatar--none { border-color: transparent; }
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
- return { backgroundColor: fill[props.variant], color: props.variant === 'default' || props.variant === 'destructive' ? theme.value.onPrimary : theme.value.ink }
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
- 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,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
- const style = computed(() => ({
16
- color: props.disabled ? theme.value.muted : isSolid.value ? theme.value.onPrimary : theme.value.ink,
17
- '--ll-btn-fill': isSolid.value && !props.disabled ? tone.value : 'transparent',
18
- '--ll-btn-focus': theme.value.primary,
19
- backgroundImage: box.value && buttonInk(box.value.width, box.value.height, props.variant, props.seed, theme.value, props.disabled),
20
- }))
21
-
22
- function activate(event: unknown) {
23
- // 原生禁用态和事件闸门共同约束一次有效激活。
24
- if (!props.disabled) emit('click', event)
25
- }
26
-
27
- function keyDown(event: KeyboardEvent) {
28
- if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
29
- }
30
-
31
- function keyUp(event: KeyboardEvent) {
32
- // 松键时再打开弹层,避免同一次 Enter 落到新聚焦的输入框并确认它。
33
- if (event.key === 'Enter' || event.key === ' ') activate(event)
34
- }
35
- </script>
36
-
37
- <template>
38
- <!-- 让调用方的 ID 直接落在可点击的原生按钮上。 -->
39
- <button
40
- :id="id"
41
- class="ll-button"
42
- :class="['ll-button--' + size, { 'll-button--drawn': box }]"
43
- :style="style"
44
- :disabled="disabled"
45
- :aria-label="ariaLabel"
46
- :role="role"
47
- :tabindex="disabled ? -1 : tabIndex"
48
- :aria-disabled="disabled"
49
- hover-class="ll-button--pressed"
50
- @click.stop="activate"
51
- @keydown="keyDown"
52
- @keyup="keyUp"
53
- >
54
- <slot />
55
- </button>
56
- </template>
57
-
58
- <style scoped>
59
- /* 文字和点击区由原生 button 提供,绘制图层只承担外观。 */
60
- .ll-button {
61
- box-sizing: border-box;
62
- display: inline-flex;
63
- align-items: center;
64
- justify-content: center;
65
- min-height: 36px;
66
- padding: 6px 16px;
67
- margin: 0;
68
- border: 0;
69
- border-radius: 4px;
70
- background-color: var(--ll-btn-fill);
71
- background-repeat: no-repeat;
72
- background-size: 100% 100%;
73
- font: inherit;
74
- font-weight: 700;
75
- line-height: 1.25;
76
- white-space: normal;
77
- vertical-align: middle;
78
- }
79
- .ll-button::after { border: 0; }
80
- .ll-button--drawn { background-color: transparent; }
81
- .ll-button--pressed, .ll-button:active { transform: translateY(1px); }
82
- .ll-button:focus-visible { outline: 2px dashed var(--ll-btn-focus); outline-offset: 3px; }
83
- .ll-button--xs { min-height: 24px; padding: 3px 8px; font-size: 14px; }
84
- .ll-button--sm { min-height: 32px; padding: 4px 12px; font-size: 15px; }
85
- .ll-button--lg { min-height: 40px; padding: 7px 24px; font-size: 17px; }
86
- .ll-button--icon, .ll-button--icon-xs, .ll-button--icon-sm, .ll-button--icon-lg { padding: 0; }
87
- .ll-button--icon { width: 36px; }
88
- .ll-button--icon-xs { width: 24px; min-height: 24px; }
89
- .ll-button--icon-sm { width: 32px; min-height: 32px; }
90
- .ll-button--icon-lg { width: 40px; min-height: 40px; }
91
- </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,54 +1,70 @@
1
- <script setup lang="ts">
2
- import LlIcon from '../ll-icon/ll-icon.vue'
3
-
4
- const props = defineProps<{ modelValue: boolean; indeterminate?: boolean; disabled?: boolean; invalid?: boolean; label?: string }>()
5
- const emit = defineEmits<{ 'update:modelValue': [checked: boolean] }>()
6
- function toggle() {
7
- // 半选完成后变为全选,宿主同步自己的父子选项状态。
8
- if (!props.disabled) emit('update:modelValue', props.indeterminate || !props.modelValue)
9
- }
10
- </script>
11
-
12
- <template>
13
- <button
14
- class="ll-checkbox"
15
- role="checkbox"
16
- :aria-checked="indeterminate ? 'mixed' : modelValue"
17
- :aria-label="label"
18
- :aria-invalid="invalid"
19
- :disabled="disabled"
20
- @click.stop="toggle"
21
- >
22
- <view
23
- class="ll-checkbox__box"
24
- aria-hidden="true"
25
- :class="{ 'll-checkbox__box--invalid': invalid }"
26
- >
27
- <ll-icon
28
- v-if="indeterminate || modelValue"
29
- :name="indeterminate ? 'minus' : 'check'"
30
- />
31
- </view>
32
- <slot>{{ label }}</slot>
33
- </button>
34
- </template>
35
-
36
- <style scoped>
37
- /* 文本与笔画同属一个点击目标,点文字只触发一次更新。 */
38
- .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; }
39
- .ll-checkbox::after { border: 0; }
40
- /* 固定 16px 图标的占位,切换勾选状态时方框和标签位置保持一致。 */
41
- .ll-checkbox__box {
42
- display: inline-flex;
43
- flex: none;
44
- box-sizing: content-box;
45
- width: 16px;
46
- height: 16px;
47
- padding: 1px;
48
- background-color: #fffaf0;
49
- border: 1px solid #594839;
50
- border-radius: 4px 2px 4px 3px;
51
- }
52
- .ll-checkbox__box--invalid { border-color: #a9362d; }
53
- .ll-checkbox[disabled] { opacity: .55; }
54
- </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>