-
-
Notifications
You must be signed in to change notification settings - Fork 152
feat: implement BAvatar badge-offset #2692
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -37,8 +37,9 @@ | |
:dot-indicator="props.badgeDotIndicator || badgeImplicitlyDot" | ||
:variant="props.badgeVariant" | ||
:bg-variant="props.badgeBgVariant" | ||
:badge-offset="props.badgeOffset" | ||
:text-variant="props.badgeTextVariant" | ||
:style="badgeStyle" | ||
:style="[badgeStyle, badgeOffsetStyle]" | ||
:placement="props.badgePlacement" | ||
> | ||
<slot name="badge"> | ||
|
@@ -59,6 +60,7 @@ import {isEmptySlot} from '../../utils/dom' | |
import {useNumberishToStyle} from '../../composables/useNumberishToStyle' | ||
import {useRadiusElementClasses} from '../../composables/useRadiusElementClasses' | ||
import {useColorVariantClasses} from '../../composables/useColorVariantClasses' | ||
import {useRtl} from '../../composables/useRtl' | ||
import type {Size} from '../../types' | ||
|
||
const props = withDefaults(defineProps<BAvatarProps>(), { | ||
|
@@ -69,6 +71,7 @@ const props = withDefaults(defineProps<BAvatarProps>(), { | |
badgeVariant: 'primary', | ||
badgePlacement: 'bottom-end', | ||
badgeDotIndicator: false, | ||
badgeOffset: null, | ||
badgePill: false, | ||
button: false, | ||
buttonType: 'button', | ||
|
@@ -134,6 +137,7 @@ const slots = defineSlots<{ | |
const {computedLink, computedLinkProps} = useBLinkHelper(props) | ||
|
||
const parentData = inject(avatarGroupInjectionKey, null) | ||
const {isRtl} = useRtl() | ||
|
||
const SIZES = Object.freeze([ | ||
null, | ||
|
@@ -216,6 +220,35 @@ const textFontStyle = computed<StyleValue>(() => { | |
return fontSize ? {fontSize} : {} | ||
}) | ||
|
||
const badgeOffsetStyle = computed<StyleValue>(() => { | ||
const offset = props.badgeOffset | ||
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. If you are to make this change, the placement prop should handle both sides -- similar to the bdropdown. Offset becomes similar again to the dropdown offset, but in this case we don't have access to useFloating's middleware to handle the offset for us. So either the new functionality can be added, or not. But the goal here would be to have placement and offset |
||
const placement = props.badgePlacement | ||
const rtlEnabled = isRtl?.value ?? false | ||
|
||
let x = `-50%` | ||
let y = `-50%` | ||
|
||
if (placement.includes('top')) { | ||
y = `calc(-50% + ${offset})` | ||
} else if (placement.includes('bottom')) { | ||
y = `calc(-50% - ${offset})` | ||
} | ||
|
||
if (placement.includes('end')) { | ||
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. Does this code properly work when using RTL formats? 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. @VividLemon just add support for RTL and LTR layouts, When ever you have a moment, could you take another look? Thanks! 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. Looks correct, but still move this code into a composable |
||
// In LTR: “end” = push left (calc(-50% - offset)) | ||
// In RTL: “end” = push right (calc(-50% + offset)) | ||
x = rtlEnabled ? `calc(-50% + ${offset})` : `calc(-50% - ${offset})` | ||
} else if (placement.includes('start')) { | ||
// In LTR: “start” = push right (calc(-50% + offset)) | ||
// In RTL: “start” = push left (calc(-50% - offset)) | ||
x = rtlEnabled ? `calc(-50% - ${offset})` : `calc(-50% + ${offset})` | ||
} | ||
|
||
return { | ||
transform: `translate(${x}, ${y}) !important`, | ||
} | ||
}) | ||
|
||
const marginStyle = computed(() => { | ||
const overlapScale = parentData?.overlapScale?.value || 0 | ||
|
||
|
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.
Maybe move this computed into a composable