8000 feat: implement BAvatar badge-offset by william-castillo-jr · Pull Request #2692 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion packages/bootstrap-vue-next/src/components/BAvatar/BAvatar.vue
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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>(), {
Expand All @@ -69,6 +71,7 @@ const props = withDefaults(defineProps<BAvatarProps>(), {
badgeVariant: 'primary',
badgePlacement: 'bottom-end',
badgeDotIndicator: false,
badgeOffset: null,
badgePill: false,
button: false,
buttonType: 'button',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -216,6 +220,35 @@ const textFontStyle = computed<StyleValue>(() => {
return fontSize ? {fontSize} : {}
})

const badgeOffsetStyle = computed<StyleValue>(() => {
Copy link
Member

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

const offsetStyle = (offset: MaybeRefOrGetter<>, placement: MaybeRefOrGetter<>) => computed<StyleValue>(() => {

const offset = props.badgeOffset
Copy link
Member

Choose a reason for hiding this comment

The 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. top-start bottom-right etc etc.

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 top,bottom,start,end into one prop like the others

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')) {
Copy link
Member

Choose a reason for hiding this comment

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

Does this code properly work when using RTL formats?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

The 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

Expand Down
1 change: 1 addition & 0 deletions packages/bootstrap-vue-next/src/types/ComponentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ export interface BAvatarProps
alt?: string
badge?: boolean | string
badgeBgVariant?: BgColorVariant | null
badgeOffset?: string | null
badgePlacement?: CombinedPlacement
badgeTextVariant?: TextColorVariant | null
badgeVariant?: ColorVariant | null
Expand Down
0