-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request is intended to add the Badge component. Closes: 8
- Loading branch information
Selemondev
authored and
Selemondev
committed
Jul 28, 2023
1 parent
c5986b0
commit 09ddea5
Showing
8 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<script setup lang='ts'> | ||
import { computed, defineComponent, useSlots } from 'vue' | ||
import classNames from 'classnames' | ||
import { Positions } from '../../Types/enums/Positions' | ||
import { Components } from '../../Types/enums/Components' | ||
import { getVariantPropsWithClassesList } from '../../utils/getVariantProps' | ||
import type { WBadge } from '../../Types/componentsTypes/components' | ||
import { useVariants } from '../../composables/useVariants' | ||
import windiTheme from '../../theme/windiTheme' | ||
const props = defineProps({ | ||
...getVariantPropsWithClassesList<WBadge>(), | ||
square: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
chip: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
position: { | ||
type: String, | ||
default: Positions.TR, | ||
}, | ||
maxValue: { | ||
type: Number, | ||
default: null, | ||
}, | ||
value: { | ||
type: [String, Number], | ||
default: null, | ||
}, | ||
}) | ||
const variant = useVariants<WBadge>(Components.WBadge, props) | ||
const slots = useSlots() | ||
const badgeValue = computed(() => { | ||
if (props.chip || !props.value) | ||
return | ||
if (props.maxValue !== null) | ||
return Number(props.value) > props.maxValue ? `${props.maxValue}+` : props.value | ||
else | ||
return props.value | ||
}) | ||
const badgePosition = computed(() => { | ||
return classNames( | ||
slots.default && windiTheme.WBadge.base.badgePosition[props.position], | ||
) | ||
}) | ||
const badgeChip = computed(() => { | ||
return classNames( | ||
props.chip && variant.chip, | ||
) | ||
}) | ||
const badgeSquare = computed(() => { | ||
return classNames( | ||
props.square && variant.square, | ||
) | ||
}) | ||
</script> | ||
|
||
<script lang="ts"> | ||
export default defineComponent({ | ||
name: Components.WBadge, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div :class="variant.root"> | ||
<span :class="variant.default"> | ||
<slot /> | ||
<Transition v-bind="variant.transitions?.fade"> | ||
<span | ||
:class="[ | ||
variant.body, badgePosition, badgeChip, badgeSquare, | ||
]" | ||
> | ||
<slot name="badgeValue">{{ badgeValue }}</slot> | ||
</span> | ||
</Transition> | ||
</span> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import Badge from './WBadge.vue' | ||
|
||
export default { | ||
Badge, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters