Skip to content

Commit bb0cc7e

Browse files
committed
feat(ui): auto-detect icon-only buttons for consistent spacing
Detect icon-only buttons with useSlot
1 parent ccebf91 commit bb0cc7e

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

app/components/Button/Base.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const props = withDefaults(
1818
)
1919
2020
const el = useTemplateRef('el')
21+
const slots = useSlots()
22+
const iconOnly = computed(() => !!props.classicon && !slots.default)
2123
2224
defineExpose({
2325
focus: () => el.value?.focus(),
@@ -32,12 +34,14 @@ defineExpose({
3234
:class="{
3335
'inline-flex': !block,
3436
'flex': block,
35-
'text-sm py-2': size === 'medium',
36-
'px-4': size === 'medium' && !classicon,
37-
'ps-3 pe-4': size === 'medium' && !!classicon,
38-
'text-xs py-0.5': size === 'small',
39-
'px-2': size === 'small' && !classicon,
40-
'ps-1.5 pe-2': size === 'small' && !!classicon,
37+
'text-sm py-2': size === 'medium' && !iconOnly,
38+
'text-sm p-2': size === 'medium' && !!iconOnly,
39+
'px-4': size === 'medium' && !classicon && !iconOnly,
40+
'ps-3 pe-4': size === 'medium' && !!classicon && !iconOnly,
41+
'text-xs py-0.5': size === 'small' && !iconOnly,
42+
'text-xs p-0.5': size === 'small' && !!iconOnly,
43+
'px-2': size === 'small' && !classicon && !iconOnly,
44+
'ps-1.5 pe-2': size === 'small' && !!classicon && !iconOnly,
4145
'bg-transparent text-fg hover:enabled:(bg-fg/10) focus-visible:enabled:(bg-fg/10) aria-pressed:(bg-fg/10 border-fg/20 hover:enabled:(bg-fg/20 text-fg/50))':
4246
variant === 'secondary',
4347
'text-bg bg-fg hover:enabled:(bg-fg/50) focus-visible:enabled:(bg-fg/50) aria-pressed:(bg-fg text-bg border-fg hover:enabled:(text-bg/50))':

app/components/Link/Base.vue

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const isLink = computed(() => props.variant === 'link')
5555
const isButton = computed(() => !isLink.value)
5656
const isButtonSmall = computed(() => props.size === 'small' && !isLink.value)
5757
const isButtonMedium = computed(() => props.size === 'medium' && !isLink.value)
58+
const slots = useSlots()
59+
const iconOnly = computed(() => !!props.classicon && !slots.default)
5860
</script>
5961

6062
<template>
@@ -65,12 +67,14 @@ const isButtonMedium = computed(() => props.size === 'medium' && !isLink.value)
6567
'inline-flex': !block,
6668
'opacity-50 gap-x-1 items-center justify-center font-mono border border-transparent rounded-md':
6769
isButton,
68-
'text-sm py-2': isButtonMedium,
69-
'px-4': isButtonMedium && !classicon,
70-
'ps-3 pe-4': isButtonMedium && !!classicon,
71-
'text-xs py-0.5': isButtonSmall,
72-
'px-2': isButtonSmall && !classicon,
73-
'ps-1.5 pe-2': isButtonSmall && !!classicon,
70+
'text-sm py-2': isButtonMedium && !iconOnly,
71+
'text-sm p-2': isButtonMedium && !!iconOnly,
72+
'px-4': isButtonMedium && !classicon && !iconOnly,
73+
'ps-3 pe-4': isButtonMedium && !!classicon && !iconOnly,
74+
'text-xs py-0.5': isButtonSmall && !iconOnly,
75+
'text-xs p-0.5': isButtonSmall && !!iconOnly,
76+
'px-2': isButtonSmall && !classicon && !iconOnly,
77+
'ps-1.5 pe-2': isButtonSmall && !!classicon && !iconOnly,
7478
'text-bg bg-fg': variant === 'button-primary',
7579
'bg-transparent text-fg': variant === 'button-secondary',
7680
}"
@@ -89,12 +93,14 @@ const isButtonMedium = computed(() => props.size === 'medium' && !isLink.value)
8993
isLink,
9094
'justify-center font-mono border border-border rounded-md transition-all duration-200':
9195
isButton,
92-
'text-sm py-2': isButtonMedium,
93-
'px-4': isButtonMedium && !classicon,
94-
'ps-3 pe-4': isButtonMedium && !!classicon,
95-
'text-xs py-0.5': isButtonSmall,
96-
'px-2': isButtonSmall && !classicon,
97-
'ps-1.5 pe-2': isButtonSmall && !!classicon,
96+
'text-sm py-2': isButtonMedium && !iconOnly,
97+
'text-sm p-2': isButtonMedium && iconOnly,
98+
'px-4': isButtonMedium && !classicon && !iconOnly,
99+
'ps-3 pe-4': isButtonMedium && !!classicon && !iconOnly,
100+
'text-xs py-0.5': isButtonSmall && !iconOnly,
101+
'text-xs p-0.5': isButtonSmall && iconOnly,
102+
'px-2': isButtonSmall && !classicon && !iconOnly,
103+
'ps-1.5 pe-2': isButtonSmall && !!classicon && !iconOnly,
98104
'bg-transparent text-fg hover:(bg-fg/10 text-accent) focus-visible:(bg-fg/10 text-accent) aria-[current=true]:(bg-fg/10 text-accent border-fg/20 hover:enabled:(bg-fg/20 text-fg/50))':
99105
variant === 'button-secondary',
100106
'text-bg bg-fg hover:(bg-fg/50 text-accent) focus-visible:(bg-fg/50) aria-current:(bg-fg text-bg border-fg hover:enabled:(text-bg/50))':

0 commit comments

Comments
 (0)