Skip to content
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

feat(badge): [badge] Adapting to the SMB theme #2087

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions examples/sites/demos/pc/app/badge/is-dot-composition-api.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<template>
<tiny-badge is-dot>小圆点显示</tiny-badge>
<br /><br />
<tiny-badge is-dot>
<template #default>
<tiny-button type="text" :icon="TinyIconMail"> </tiny-button>
</template>
</tiny-badge>
</template>

<script setup>
import { Badge as TinyBadge } from '@opentiny/vue'
import { iconMail } from '@opentiny/vue-icon'
import { Button as TinyButton } from '@opentiny/vue'

const TinyIconMail = iconMail()
</script>
7 changes: 5 additions & 2 deletions examples/sites/demos/pc/app/badge/is-dot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ test('小圆点标记', async ({ page }) => {
page.on('pageerror', (exception) => expect(exception).toBeNull())
await page.goto('badge#is-dot')

const demo = page.locator('#is-dot')
const badge = demo.locator('.tiny-badge')
const demo = page
.locator('div')
.filter({ hasText: /^小圆点显示$/ })
.first()
const badge = demo.locator('.tiny-badge').first()

await expect(badge).toHaveClass(/tiny-badge--default/)
await expect(badge).toHaveCSS('width', '6px')
Expand Down
14 changes: 14 additions & 0 deletions examples/sites/demos/pc/app/badge/is-dot.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
<template>
<tiny-badge is-dot>小圆点显示</tiny-badge>
<br /><br />
<tiny-badge is-dot>
<template #default>
<tiny-button type="text" :icon="TinyIconMail"> </tiny-button>
</template>
</tiny-badge>
</template>

<script>
import { Badge } from '@opentiny/vue'
import { Button } from '@opentiny/vue'
import { iconMail } from '@opentiny/vue-icon'

export default {
components: {
TinyButton: Button,
TinyBadge: Badge
},
data() {
return {
TinyIconMail: iconMail()
}
}
}
</script>
6 changes: 5 additions & 1 deletion examples/sites/demos/pc/app/badge/max-composition-api.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<template>
<tiny-badge :value="5" :max="2">最大值显示</tiny-badge>
<tiny-badge :value="10" :max="9">最大值显示</tiny-badge>
<br />
<tiny-badge value="100" :max="99" data="我的待办"></tiny-badge>
<br />
<tiny-badge value="1000" :max="999" data="我的待办"></tiny-badge>
</template>

<script setup>
Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/badge/max.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test('计数最大值', async ({ page }) => {
await page.goto('badge#max')

const demo = page.locator('#max')
const badge = demo.locator('.tiny-badge')
const badge = demo.locator('.tiny-badge').first()

await expect(badge).toContainText('2+')
await expect(badge).toContainText('9+')
})
8 changes: 7 additions & 1 deletion examples/sites/demos/pc/app/badge/max.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<template>
<tiny-badge :value="5" :max="2">最大值显示</tiny-badge>
<template>
<tiny-badge :value="10" :max="9">最大值显示</tiny-badge>
<br />
<tiny-badge value="100" :max="99" data="我的待办"></tiny-badge>
<br />
<tiny-badge value="1000" :max="999" data="我的待办"></tiny-badge>
</template>
</template>

<script>
Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/badge/offset-composition-api.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div>
<p>使用字符串:</p>
<br />
<tiny-badge :value="2" :offset="['0', '-50%']">我的待办</tiny-badge>
<tiny-badge :value="2" :offset="['0', '-20%']">我的待办</tiny-badge>
<br /><br />
<p>使用数字:</p>
<br />
<tiny-badge :value="2" :offset="[0, -10]">我的待办</tiny-badge>
<tiny-badge :value="2" :offset="[0, -6]">我的待办</tiny-badge>
</div>
</template>

Expand Down
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/badge/offset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ test('标记的位置', async ({ page }) => {
const demo = page.locator('#offset')
const badge = demo.locator('.tiny-badge')

await expect(badge.first()).toHaveCSS('transform', 'matrix(1, 0, 0, 1, 0, -10)')
await expect(badge.nth(1)).toHaveCSS('transform', 'matrix(1, 0, 0, 1, 0, -10)')
await expect(badge.first()).toHaveCSS('transform', 'matrix(1, 0, 0, 1, 0, -4)')
await expect(badge.nth(1)).toHaveCSS('transform', 'matrix(1, 0, 0, 1, 0, -6)')
})
4 changes: 2 additions & 2 deletions examples/sites/demos/pc/app/badge/offset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div>
<p>使用字符串:</p>
<br />
<tiny-badge :value="2" :offset="['0', '-50%']">我的待办</tiny-badge>
<tiny-badge :value="2" :offset="['0', '-20%']">我的待办</tiny-badge>
<br /><br />
<p>使用数字:</p>
<br />
<tiny-badge :value="2" :offset="[0, -10]">我的待办</tiny-badge>
<tiny-badge :value="2" :offset="[0, -6]">我的待办</tiny-badge>
</div>
</template>

Expand Down
12 changes: 6 additions & 6 deletions packages/renderless/src/badge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import type { StyleValue } from 'vue'
export const computedContent =
({ props, state }: Pick<IBadgeRenderlessParams, 'props' | 'state'>) =>
(): IBadgeContent =>
typeof state.valueRef === 'number' && typeof props.max === 'number'
? props.max < state.valueRef
(typeof props.value === 'number' || typeof props.value === 'string') && typeof props.max === 'number'
? props.max < Number(state.valueRef)
? `${props.max}+`
: state.valueRef
: state.valueRef

export const computedValueRef =
({ props }: Pick<IBadgeRenderlessParams, 'props'>) =>
(): number | undefined => {
if (typeof props.value === 'number') {
(): number | string | undefined => {
if (typeof props.value === 'number' || typeof props.value === 'string') {
return props.value
} else {
return undefined
}

return typeof props.modelValue === 'number' ? props.modelValue : undefined
}

export const computedTransform =
Expand Down
3 changes: 2 additions & 1 deletion packages/theme/src/badge/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
vertical-align: baseline;
white-space: nowrap;
text-align: center;
margin-left: 4px;
margin-left: var(--ti-badge-margin-left);
border: var(--ti-badge-border) solid #FFFFFF;

&:empty {
Expand Down Expand Up @@ -84,6 +84,7 @@
vertical-align: top;
padding: 0;
border-radius: 50%;
border: unset;
}

&--primary {
Expand Down
4 changes: 3 additions & 1 deletion packages/theme/src/badge/smb-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ export const tinyBadgeSmbTheme = {
'ti-badge-font-size': 'var(--ti-common-font-size-0)',
'ti-badge-text-color': 'var(--ti-base-color-bg-7)',
'ti-badge-border-radius': 'var(--ti-common-border-radius-4)',
'ti-badge-border': 'var(--ti-common-border-weight-normal)'
'ti-badge-border': 'var(--ti-common-border-weight-normal)',
'ti-badge-font-weight': 'var(--ti-common-font-weight-normal)',
'ti-badge-margin-left': '0'
}
1 change: 1 addition & 0 deletions packages/theme/src/badge/vars.less
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
--ti-badge-danger-bg-color: var(--ti-base-color-error-3, #f66f6a);
--ti-badge-info-bg-color: var(--ti-common-color-info-normal, #252b3a);
--ti-badge-border: 0;
--ti-badge-margin-left: 4px;
}
2 changes: 1 addition & 1 deletion packages/vue/src/badge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const badgeProps = {
badgeClass: String,
offset: {
type: Array,
default: () => [0, 0]
default: () => ['0', '-50%']
},
data: [String, Number]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vue/src/badge/src/pc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
type ? 'tiny-badge--' + type : '',
badgeClass || ''
]"
:style="state.transform"
:style="!isDot ? state.transform : ''"
>
<slot name="content">
<a v-if="state.href" :href="state.href" :target="target" rel="noopener noreferrer">{{ state.content }}</a>
Expand Down
Loading