-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(badge): move to script setup
- Loading branch information
Showing
12 changed files
with
190 additions
and
182 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -719,6 +719,7 @@ | |
"name": "Badge", | ||
"cName": "徽标", | ||
"desc": "徽标", | ||
"setup": true, | ||
"author": "liqiong" | ||
}, | ||
{ | ||
|
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,66 @@ | ||
<template> | ||
<view class="nut-badge"> | ||
<view v-show="!hidden && !dot && $slots.icon" class="nut-badge__icon" :style="style"> | ||
<slot name="icon"></slot> | ||
</view> | ||
<slot></slot> | ||
<view | ||
v-show="!hidden && (content || dot)" | ||
class="nut-badge__content nut-badge__content--sup" | ||
:class="{ 'nut-badge__content--dot': dot, 'nut-badge__content--bubble': !dot && bubble }" | ||
:style="style" | ||
> | ||
{{ content }} | ||
</view> | ||
</view> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
defineOptions({ | ||
name: 'NutBadge' | ||
}) | ||
export type BadgeProps = Partial<{ | ||
value: string | number | ||
max: number | ||
dot: boolean | ||
bubble: boolean | ||
hidden: boolean | ||
top: string | ||
right: string | ||
zIndex: number | ||
color: string | ||
}> | ||
const props = withDefaults(defineProps<BadgeProps>(), { | ||
max: 10000, | ||
dot: false, | ||
bubble: false, | ||
hidden: false, | ||
top: '0', | ||
right: '0', | ||
zIndex: 9, | ||
color: '' | ||
}) | ||
const style = computed(() => { | ||
return { | ||
top: `${props.top}px`, | ||
right: `${props.right}px`, | ||
zIndex: props.zIndex, | ||
background: props.color | ||
} | ||
}) | ||
const content = computed(() => { | ||
if (props.dot) return | ||
const value = props.value | ||
const max = props.max | ||
if (typeof value === 'number' && typeof max === 'number') { | ||
return max < value ? `${max}+` : value | ||
} | ||
return value | ||
}) | ||
</script> |
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,66 @@ | ||
<template> | ||
<view class="nut-badge"> | ||
<view v-show="!hidden && !dot && $slots.icon" class="nut-badge__icon" :style="style"> | ||
<slot name="icon"></slot> | ||
</view> | ||
<slot></slot> | ||
<view | ||
v-show="!hidden && (content || dot)" | ||
class="nut-badge__content nut-badge__content--sup" | ||
:class="{ 'nut-badge__content--dot': dot, 'nut-badge__content--bubble': !dot && bubble }" | ||
:style="style" | ||
> | ||
{{ content }} | ||
</view> | ||
</view> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue' | ||
defineOptions({ | ||
name: 'NutBadge' | ||
}) | ||
export type BadgeProps = Partial<{ | ||
value: string | number | ||
max: number | ||
dot: boolean | ||
bubble: boolean | ||
hidden: boolean | ||
top: string | ||
right: string | ||
zIndex: number | ||
color: string | ||
}> | ||
const props = withDefaults(defineProps<BadgeProps>(), { | ||
max: 10000, | ||
dot: false, | ||
bubble: false, | ||
hidden: false, | ||
top: '0', | ||
right: '0', | ||
zIndex: 9, | ||
color: '' | ||
}) | ||
const style = computed(() => { | ||
return { | ||
top: `${props.top}px`, | ||
right: `${props.right}px`, | ||
zIndex: props.zIndex, | ||
background: props.color | ||
} | ||
}) | ||
const content = computed(() => { | ||
if (props.dot) return | ||
const value = props.value | ||
const max = props.max | ||
if (typeof value === 'number' && typeof max === 'number') { | ||
return max < value ? `${max}+` : value | ||
} | ||
return value | ||
}) | ||
</script> |
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,11 @@ | ||
import Badge from './badge.taro.vue' | ||
import type { ComponentPublicInstance } from 'vue' | ||
import { withInstall } from '@/packages/utils' | ||
|
||
withInstall(Badge) | ||
|
||
export type { BadgeProps } from './badge.taro.vue' | ||
|
||
export type BadgeInstance = ComponentPublicInstance & InstanceType<typeof Badge> | ||
|
||
export { Badge, Badge as default } |
This file was deleted.
Oops, something went wrong.
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,11 @@ | ||
import Badge from './badge.vue' | ||
import type { ComponentPublicInstance } from 'vue' | ||
import { withInstall } from '@/packages/utils' | ||
|
||
withInstall(Badge) | ||
|
||
export type { BadgeProps } from './badge.vue' | ||
|
||
export type BadgeInstance = ComponentPublicInstance & InstanceType<typeof Badge> | ||
|
||
export { Badge, Badge as default } |
Oops, something went wrong.