-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: icon only buttons #4642
feat: icon only buttons #4642
Changes from all commits
408f31e
a8e8f1f
d5df284
8b17f65
d4ed6ac
ecf502b
90f6efe
66bea4c
d7d45d5
c95bc82
f35ff17
c92fb22
601d0c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,25 @@ const props = withDefaults( | |
icon?: string; | ||
iconPosition?: ButtonIconPosition; | ||
disabled?: boolean; | ||
iconOnly?: boolean; | ||
tooltip?: string; | ||
}>(), | ||
{ | ||
type: "primary", | ||
size: "medium", | ||
label: "", | ||
iconPosition: "left", | ||
disabled: false, | ||
iconOnly: false, | ||
} | ||
); | ||
|
||
watchEffect(() => { | ||
if (props.iconOnly && (props.label === "" || props.label === undefined)) { | ||
console.error("Icon only buttons must have a label"); | ||
} | ||
}); | ||
|
||
const COLOR_MAPPING = { | ||
primary: | ||
"tracking-widest uppercase font-display bg-button-primary text-button-primary border-button-primary hover:bg-button-primary-hover hover:text-button-primary-hover hover:border-button-primary-hover", | ||
|
@@ -55,22 +64,26 @@ const colorClasses = computed(() => { | |
}); | ||
|
||
const sizeClasses = computed(() => { | ||
return SIZE_MAPPING[props.size]; | ||
return props.iconOnly ? "p-[8px]" : SIZE_MAPPING[props.size]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible create a mapping for icon only buttons? I can imagine a few instances (in the dashboards) where we want an icon only button, but would like to have a larger button. This option would make the icon only option more useful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes , i initially added it similar to the text sizing , but its not used in the current design, so i'm not sure we need it , propose we keep it simple until there is a need for this , then we can test it in the context the usecase |
||
}); | ||
|
||
const iconPositionClass = computed(() => { | ||
return ICON_POSITION_MAPPING[props.iconPosition]; | ||
}); | ||
|
||
const tooltipText = computed(() => { | ||
return props.tooltip || props.iconOnly ? props.label : ""; | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to make the label required if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not really as far as i know , but we can trow a warning i guess , i think it would mean adding a watch as the prop can change , so it might not be worth extra run time code |
||
</script> | ||
|
||
<template> | ||
<button | ||
v-tooltip.bottom="tooltipText" | ||
class="flex items-center border rounded-input group-[.button-bar]:rounded-none group-[.button-bar]:first:rounded-l-input group-[.button-bar]:last:rounded-r-input" | ||
:class="`${colorClasses} ${sizeClasses} ${iconPositionClass} transition-colors`" | ||
> | ||
<span v-if="icon"> | ||
<BaseIcon :name="icon" /> | ||
</span> | ||
<span>{{ label }}<slot /></span> | ||
<BaseIcon v-if="icon" :name="icon" /> | ||
|
||
<span :class="{ 'sr-only': iconOnly }">{{ label }}<slot /></span> | ||
</button> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not possible automatic by checken if there are child elements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise I don't mind for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i tried something like that , but it did not work , i'll have a look if de links contain additional info , i'm not even really sure i like the slot option in the case as it can get a bit weird when passing non string stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be able to use
UseTemplateRef
and evaluate if there is inner html.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is also possible to use a named slot and check if that has content.