-
Notifications
You must be signed in to change notification settings - Fork 6
add feature to have two icons at the same time #336
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
Changes from all commits
10d7d56
38c7a50
702f7d5
3eb21cd
c4f55dc
e72428b
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 | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,11 +1,12 @@ | ||||||||
| <script setup lang="ts"> | ||||||||
| import { BCC_CONTEXTS } from "@/composables/contexts"; | ||||||||
| import type { VueComponent } from "@/types"; | ||||||||
| import { computed, defineProps, withDefaults } from "vue"; | ||||||||
|
|
||||||||
| withDefaults( | ||||||||
| const props = withDefaults( | ||||||||
| defineProps<{ | ||||||||
| icon?: VueComponent; | ||||||||
| iconRight?: boolean; | ||||||||
| iconRight?: boolean | VueComponent; | ||||||||
| size?: "xs" | "sm" | "md"; | ||||||||
| contrast?: "light" | "dark"; | ||||||||
| bordered?: boolean; | ||||||||
|
|
@@ -19,16 +20,24 @@ | |||||||
| context: "neutral", | ||||||||
| } | ||||||||
| ); | ||||||||
|
|
||||||||
| const shouldShowRightIcon = computed(() => { | ||||||||
| return (props.iconRight && typeof props.iconRight !== 'boolean') || (props.icon && props.iconRight === true) | ||||||||
| }) | ||||||||
| </script> | ||||||||
|
|
||||||||
| <template> | ||||||||
| <div class="bcc-badge" :class="[BCC_CONTEXTS[context], contrast, size, { bordered }]"> | ||||||||
| <component | ||||||||
|
Check failure on line 31 in design-library/src/components/BccBadge/BccBadge.vue
|
||||||||
| v-if="icon" | ||||||||
| v-if="icon && iconRight !== true" | ||||||||
|
||||||||
| :is="icon" | ||||||||
| class="bcc-badge-icon" | ||||||||
| :class="[iconRight ? 'order-3' : 'order-1']" | ||||||||
| class="bcc-badge-icon order-1" | ||||||||
| /> | ||||||||
| <span class="order-2 empty:hidden"><slot></slot></span> | ||||||||
| <component | ||||||||
| v-if="shouldShowRightIcon" | ||||||||
| :is="typeof iconRight !== 'boolean' ? iconRight : icon" | ||||||||
|
||||||||
| :is="typeof iconRight !== 'boolean' ? iconRight : icon" | |
| v-if="rightIconComponent" | |
| :is="rightIconComponent" |
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 am going to leave the :is logic because it's trying to overwrite the v-if statement that is already there
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.
But if the rightIconComponent computed property returns the correct icon then you can just test it and display it?
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.
[nitpick] The logic for determining when to show the right icon is complex and could be simplified. Consider extracting the conditions into separate boolean variables with descriptive names like
hasCustomRightIconandhasIconMovedRightfor better readability.