Skip to content
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

Merged
merged 13 commits into from
Jan 30, 2025
Merged

feat: icon only buttons #4642

merged 13 commits into from
Jan 30, 2025

Conversation

connoratrug
Copy link
Contributor

What are the main changes you did

feat: icon only buttons

  • button can be set as icon only using a prop
  • the btn label is used as default tooltip
  • additional tooltip can be set with tooltip property

How to test

  • see playground

Checklist

  • updated docs in case of new feature
  • added/updated tests
  • added/updated testplan to include a test for this fix, including ref to bug using # notation

- button can be set as icon only using a prop
- the btn label is used as default tooltip
- additional tooltip can be set with tooltip property
@connoratrug connoratrug linked an issue Jan 27, 2025 that may be closed by this pull request
Copy link
Member

@mswertz mswertz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you might instead of iconOnly check for an empty slot?
https://mokkapps.de/vue-tips/check-if-slot-is-empty

Otherwise looks great so if you don't think this is possible/better please merge as is.

@@ -13,13 +13,16 @@ const props = withDefaults(
icon?: string;
iconPosition?: ButtonIconPosition;
disabled?: boolean;
iconOnly?: boolean;
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

@davidruvolo51 davidruvolo51 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great and it looks nice in the story. I have two minor points.

  1. I think we can remove the span that wraps the icon. The v-if can be moved the BaseIcon line. (Unless this was needed for another reason).
  2. I think the label should be required if the icon only option is true. The validation should also flag issues if the label is blank or only spaces. Otherwise, the context is missing for the icon/button.

@@ -13,13 +13,16 @@ const props = withDefaults(
icon?: string;
iconPosition?: ButtonIconPosition;
disabled?: boolean;
iconOnly?: boolean;
Copy link
Contributor

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.

@@ -55,22 +58,27 @@ const colorClasses = computed(() => {
});

const sizeClasses = computed(() => {
return SIZE_MAPPING[props.size];
return props.iconOnly ? "p-[8px]" : SIZE_MAPPING[props.size];
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 tooltipText = computed(() => {
return props.tooltip || props.iconOnly ? props.label : "";
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make the label required if the iconOnly prop is true? Alternatively, there could be a check here that throws a warning that the label is missing or blank. Otherwise, the context is lost if the default value for label is "".

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

apps/tailwind-components/components/Button.vue Outdated Show resolved Hide resolved
@connoratrug connoratrug merged commit b4a61dc into master Jan 30, 2025
7 checks passed
@connoratrug connoratrug deleted the feat/icon-only-buttons branch January 30, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Icon only button in tailwind comp lib
4 participants