cynx-lib 1.3.57 → 1.3.58
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/package.json +1 -1
- package/vue/components/Button.vue +23 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, useSlots } from "vue";
|
|
2
|
+
import { computed, useSlots, type VNode } from "vue";
|
|
3
3
|
import Spinner from "./Spinner.vue";
|
|
4
4
|
|
|
5
5
|
const VARIANTS: Record<string, any> = {
|
|
@@ -116,6 +116,7 @@ const props = withDefaults(
|
|
|
116
116
|
disabled?: boolean;
|
|
117
117
|
loading?: boolean;
|
|
118
118
|
type?: "button" | "submit" | "reset";
|
|
119
|
+
iconOnly?: boolean;
|
|
119
120
|
}>(),
|
|
120
121
|
{
|
|
121
122
|
variant: "default",
|
|
@@ -123,6 +124,7 @@ const props = withDefaults(
|
|
|
123
124
|
disabled: false,
|
|
124
125
|
loading: false,
|
|
125
126
|
type: "button",
|
|
127
|
+
iconOnly: false,
|
|
126
128
|
}
|
|
127
129
|
);
|
|
128
130
|
|
|
@@ -133,14 +135,31 @@ const emit = defineEmits<{
|
|
|
133
135
|
const slots = useSlots();
|
|
134
136
|
const v = computed(() => VARIANTS[props.variant] || VARIANTS.default);
|
|
135
137
|
const s = computed(() => SIZES[props.size] || SIZES.md);
|
|
136
|
-
|
|
138
|
+
|
|
139
|
+
const hasDefaultText = computed(() => {
|
|
140
|
+
if (!slots.default) return false;
|
|
141
|
+
const nodes = slots.default();
|
|
142
|
+
if (!nodes || nodes.length === 0) return false;
|
|
143
|
+
return nodes.some((node: VNode) => {
|
|
144
|
+
if (node.type === Symbol.for("v-cmt")) return false;
|
|
145
|
+
if (typeof node.children === "string") return node.children.trim().length > 0;
|
|
146
|
+
if (Array.isArray(node.children)) return node.children.length > 0;
|
|
147
|
+
return Boolean(node.type);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const isIconOnly = computed(() => {
|
|
152
|
+
if (props.iconOnly || props.variant === "icon") return true;
|
|
153
|
+
const hasIconSlot = Boolean(slots.icon) || Boolean(slots.iconRight);
|
|
154
|
+
return hasIconSlot && !hasDefaultText.value;
|
|
155
|
+
});
|
|
137
156
|
</script>
|
|
138
157
|
|
|
139
158
|
<template>
|
|
140
159
|
<button
|
|
141
160
|
:type="type"
|
|
142
161
|
:disabled="disabled || loading"
|
|
143
|
-
:class="[`btn btn-${variant}`, 'inline-flex items-center justify-center gap-1.5 font-medium transition select-none']"
|
|
162
|
+
:class="[`btn btn-${variant}`, 'inline-flex items-center justify-center gap-1.5 font-medium transition select-none flex-shrink-0']"
|
|
144
163
|
:style="{
|
|
145
164
|
borderRadius: 'var(--rads, 8px)',
|
|
146
165
|
fontFamily: 'var(--f, var(--sans, inherit))',
|
|
@@ -159,6 +178,7 @@ const isIconOnly = computed(() => props.variant === "icon" || (!slots.default &&
|
|
|
159
178
|
height: `${s.height}px`,
|
|
160
179
|
width: isIconOnly ? `${s.height}px` : undefined,
|
|
161
180
|
minWidth: isIconOnly ? `${s.height}px` : undefined,
|
|
181
|
+
maxWidth: isIconOnly ? `${s.height}px` : undefined,
|
|
162
182
|
...(v.paddingLeft !== undefined && { paddingLeft: v.paddingLeft }),
|
|
163
183
|
...(v.paddingRight !== undefined && { paddingRight: v.paddingRight }),
|
|
164
184
|
}"
|