mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-14 12:14:41 +01:00
chore(Button): handle compact
This commit is contained in:
@@ -7,7 +7,12 @@
|
||||
v-bind="buttonProps"
|
||||
>
|
||||
<Icon v-if="isLeading && leadingIconName" :name="leadingIconName" :class="leadingIconClass" aria-hidden="true" />
|
||||
<slot><span :class="truncate ? 'text-left break-all line-clamp-1' : ''">{{ label }}</span></slot>
|
||||
<slot>
|
||||
<span :class="[truncate ? 'text-left break-all line-clamp-1' : '', compact ? 'hidden sm:block' : '']">
|
||||
<span :class="[labelCompact && 'hidden sm:block']">{{ label }}</span>
|
||||
<span v-if="labelCompact" class="sm:hidden">{{ labelCompact }}</span>
|
||||
</span>
|
||||
</slot>
|
||||
<Icon v-if="isTrailing && trailingIconName" :name="trailingIconName" :class="trailingIconClass" aria-hidden="true" />
|
||||
</component>
|
||||
</template>
|
||||
@@ -34,6 +39,10 @@ const props = defineProps({
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
labelCompact: {
|
||||
type: String,
|
||||
default: null
|
||||
},
|
||||
loading: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
@@ -127,6 +136,10 @@ const props = defineProps({
|
||||
truncate: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
compact: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
@@ -164,7 +177,7 @@ const buttonClass = computed(() => {
|
||||
return classNames(
|
||||
props.baseClass,
|
||||
$ui.button.size[props.size],
|
||||
$ui.button[isSquare.value ? 'square' : 'spacing'][props.size],
|
||||
$ui.button[isSquare.value ? 'square' : (props.compact ? 'compact' : 'spacing')][props.size],
|
||||
$ui.button.variant[props.variant],
|
||||
props.block ? 'w-full flex justify-center items-center' : 'inline-flex items-center',
|
||||
props.rounded ? 'rounded-full' : props.roundedClass,
|
||||
@@ -192,7 +205,7 @@ const leadingIconClass = computed(() => {
|
||||
return classNames(
|
||||
props.iconBaseClass,
|
||||
$ui.button.icon.size[props.size],
|
||||
(!!slots.default || !!props.label?.length) && $ui.button.icon.leading.spacing[props.size],
|
||||
(!!slots.default || !!props.label?.length) && $ui.button.icon.leading[props.compact ? 'compactSpacing' : 'spacing'][props.size],
|
||||
props.leadingIconClass,
|
||||
props.loading && 'animate-spin'
|
||||
)
|
||||
@@ -202,7 +215,7 @@ const trailingIconClass = computed(() => {
|
||||
return classNames(
|
||||
props.iconBaseClass,
|
||||
$ui.button.icon.size[props.size],
|
||||
(!!slots.default || !!props.label?.length) && $ui.button.icon.trailing.spacing[props.size],
|
||||
(!!slots.default || !!props.label?.length) && $ui.button.icon.trailing[props.compact ? 'compactSpacing' : 'spacing'][props.size],
|
||||
props.trailingIconClass,
|
||||
props.loading && !isLeading.value && 'animate-spin'
|
||||
)
|
||||
|
||||
@@ -26,6 +26,14 @@ export default function defaultPreset (variantColors: string[]) {
|
||||
lg: 'p-2',
|
||||
xl: 'p-3'
|
||||
},
|
||||
compact: {
|
||||
xxs: 'p-1 sm:px-2',
|
||||
xs: 'p-1.5 sm:px-2.5',
|
||||
sm: 'p-2 sm:px-3',
|
||||
md: 'p-2 sm:px-4',
|
||||
lg: 'p-2 sm:px-4',
|
||||
xl: 'p-3 sm:px-6'
|
||||
},
|
||||
variant: {
|
||||
...variantColors.reduce((acc: any, color: string) => {
|
||||
acc[color] = `shadow-sm border border-transparent text-white bg-${color}-600 hover:bg-${color}-700 disabled:bg-${color}-600 focus:ring-2 focus:ring-offset-2 focus:ring-${color}-500`
|
||||
@@ -57,6 +65,14 @@ export default function defaultPreset (variantColors: string[]) {
|
||||
md: '-ml-1 mr-2',
|
||||
lg: '-ml-1 mr-3',
|
||||
xl: '-ml-1 mr-3'
|
||||
},
|
||||
compactSpacing: {
|
||||
xxs: 'sm:-ml-0.5 sm:mr-1',
|
||||
xs: 'sm:-ml-0.5 sm:mr-1.5',
|
||||
sm: 'sm:-ml-0.5 sm:mr-2',
|
||||
md: 'sm:-ml-1 sm:mr-2',
|
||||
lg: 'sm:-ml-1 sm:mr-3',
|
||||
xl: 'sm:-ml-1 sm:mr-3'
|
||||
}
|
||||
},
|
||||
trailing: {
|
||||
@@ -67,6 +83,14 @@ export default function defaultPreset (variantColors: string[]) {
|
||||
md: 'ml-2 -mr-1',
|
||||
lg: 'ml-3 -mr-1',
|
||||
xl: 'ml-3 -mr-1'
|
||||
},
|
||||
compactSpacing: {
|
||||
xxs: 'sm:ml-1 sm:-mr-0.5',
|
||||
xs: 'sm:ml-1.5 sm:-mr-0.5',
|
||||
sm: 'sm:ml-2 sm:-mr-0.5',
|
||||
md: 'sm:ml-2 sm:-mr-1',
|
||||
lg: 'sm:ml-3 sm:-mr-1',
|
||||
xl: 'sm:ml-3 sm:-mr-1'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user