@sabrenski/spire-ui 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +233 -0
- package/dist/index.d.ts +4981 -0
- package/dist/spire-ui.css +1 -0
- package/dist/spire-ui.es.js +18403 -0
- package/dist/spire-ui.umd.js +45 -0
- package/package.json +83 -0
- package/src/components/Accordion/Accordion.test.ts +218 -0
- package/src/components/Accordion/AccordionContent.vue +112 -0
- package/src/components/Accordion/AccordionItem.vue +87 -0
- package/src/components/Accordion/AccordionRoot.vue +111 -0
- package/src/components/Accordion/AccordionTrigger.vue +125 -0
- package/src/components/Accordion/index.ts +11 -0
- package/src/components/Accordion/keys.ts +23 -0
- package/src/components/Avatar/Avatar.test.ts +181 -0
- package/src/components/Avatar/Avatar.vue +150 -0
- package/src/components/Avatar/index.ts +2 -0
- package/src/components/Badge/Badge.test.ts +141 -0
- package/src/components/Badge/Badge.vue +133 -0
- package/src/components/Badge/index.ts +2 -0
- package/src/components/BadgeContainer/BadgeContainer.test.ts +150 -0
- package/src/components/BadgeContainer/BadgeContainer.vue +90 -0
- package/src/components/BadgeContainer/index.ts +2 -0
- package/src/components/Breadcrumb/Breadcrumb.test.ts +342 -0
- package/src/components/Breadcrumb/BreadcrumbEllipsis.vue +96 -0
- package/src/components/Breadcrumb/BreadcrumbItem.vue +16 -0
- package/src/components/Breadcrumb/BreadcrumbLink.vue +67 -0
- package/src/components/Breadcrumb/BreadcrumbList.vue +20 -0
- package/src/components/Breadcrumb/BreadcrumbPage.vue +25 -0
- package/src/components/Breadcrumb/BreadcrumbRoot.vue +41 -0
- package/src/components/Breadcrumb/BreadcrumbSeparator.vue +63 -0
- package/src/components/Breadcrumb/index.ts +13 -0
- package/src/components/Breadcrumb/keys.ts +7 -0
- package/src/components/Button/Button.test.ts +231 -0
- package/src/components/Button/Button.vue +349 -0
- package/src/components/Button/index.ts +2 -0
- package/src/components/Callout/Callout.test.ts +260 -0
- package/src/components/Callout/Callout.vue +341 -0
- package/src/components/Callout/index.ts +2 -0
- package/src/components/Card/Card.test.ts +565 -0
- package/src/components/Card/Card.vue +209 -0
- package/src/components/Card/CardContent.vue +57 -0
- package/src/components/Card/CardFooter.vue +72 -0
- package/src/components/Card/CardHeader.vue +111 -0
- package/src/components/Card/CardImage.vue +124 -0
- package/src/components/Card/index.ts +14 -0
- package/src/components/Chart/BarChart.vue +208 -0
- package/src/components/Chart/BaseChart.vue +444 -0
- package/src/components/Chart/Chart.test.ts +359 -0
- package/src/components/Chart/DonutChart.vue +283 -0
- package/src/components/Chart/LineChart.vue +211 -0
- package/src/components/Chart/index.ts +20 -0
- package/src/components/Chart/useChartTheme.ts +192 -0
- package/src/components/Checkbox/Checkbox.test.ts +209 -0
- package/src/components/Checkbox/Checkbox.vue +285 -0
- package/src/components/Checkbox/index.ts +2 -0
- package/src/components/ChoiceChip/ChoiceChip.test.ts +142 -0
- package/src/components/ChoiceChip/ChoiceChip.vue +218 -0
- package/src/components/ChoiceChip/index.ts +2 -0
- package/src/components/ChoiceChipGroup/ChoiceChipGroup.test.ts +151 -0
- package/src/components/ChoiceChipGroup/ChoiceChipGroup.vue +70 -0
- package/src/components/ChoiceChipGroup/index.ts +2 -0
- package/src/components/ColorPicker/ColorArea.vue +159 -0
- package/src/components/ColorPicker/ColorPicker.test.ts +250 -0
- package/src/components/ColorPicker/ColorPicker.vue +339 -0
- package/src/components/ColorPicker/ColorSlider.vue +191 -0
- package/src/components/ColorPicker/index.ts +7 -0
- package/src/components/Combobox/Combobox.test.ts +891 -0
- package/src/components/Combobox/Combobox.vue +934 -0
- package/src/components/Combobox/index.ts +2 -0
- package/src/components/DataTable/DataTable.test.ts +1221 -0
- package/src/components/DataTable/DataTable.vue +1415 -0
- package/src/components/DataTable/index.ts +10 -0
- package/src/components/DatePicker/DatePicker.test.ts +625 -0
- package/src/components/DatePicker/DatePicker.vue +1586 -0
- package/src/components/DatePicker/index.ts +2 -0
- package/src/components/Drawer/Drawer.test.ts +336 -0
- package/src/components/Drawer/Drawer.vue +466 -0
- package/src/components/Drawer/index.ts +2 -0
- package/src/components/Dropdown/Dropdown.test.ts +607 -0
- package/src/components/Dropdown/Dropdown.vue +807 -0
- package/src/components/Dropdown/DropdownItem.vue +227 -0
- package/src/components/Dropdown/DropdownSeparator.vue +14 -0
- package/src/components/Dropdown/DropdownSub.vue +104 -0
- package/src/components/Dropdown/DropdownSubContent.vue +187 -0
- package/src/components/Dropdown/DropdownSubTrigger.vue +151 -0
- package/src/components/Dropdown/index.ts +14 -0
- package/src/components/EmptyState/EmptyState.test.ts +180 -0
- package/src/components/EmptyState/EmptyState.vue +137 -0
- package/src/components/EmptyState/index.ts +2 -0
- package/src/components/FileUpload/FileUpload.test.ts +1151 -0
- package/src/components/FileUpload/FileUpload.vue +1042 -0
- package/src/components/FileUpload/index.ts +2 -0
- package/src/components/Heading/Heading.test.ts +107 -0
- package/src/components/Heading/Heading.vue +67 -0
- package/src/components/Heading/index.ts +2 -0
- package/src/components/Icon/Icon.test.ts +157 -0
- package/src/components/Icon/Icon.vue +86 -0
- package/src/components/Icon/index.ts +2 -0
- package/src/components/Input/Input.test.ts +273 -0
- package/src/components/Input/Input.vue +388 -0
- package/src/components/Input/index.ts +2 -0
- package/src/components/Layout/Container.vue +67 -0
- package/src/components/Layout/Grid.vue +159 -0
- package/src/components/Layout/GridItem.vue +154 -0
- package/src/components/Layout/Layout.test.ts +202 -0
- package/src/components/Layout/Stack.vue +128 -0
- package/src/components/Layout/index.ts +9 -0
- package/src/components/Layout/keys.ts +7 -0
- package/src/components/Modal/Modal.test.ts +311 -0
- package/src/components/Modal/Modal.vue +336 -0
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Pagination/Pagination.test.ts +303 -0
- package/src/components/Pagination/Pagination.vue +212 -0
- package/src/components/Pagination/index.ts +3 -0
- package/src/components/Pagination/utils.ts +86 -0
- package/src/components/Popover/Popover.test.ts +285 -0
- package/src/components/Popover/Popover.vue +441 -0
- package/src/components/Popover/index.ts +2 -0
- package/src/components/Progress/Progress.test.ts +361 -0
- package/src/components/Progress/Progress.vue +363 -0
- package/src/components/Progress/index.ts +7 -0
- package/src/components/Radio/Radio.test.ts +216 -0
- package/src/components/Radio/Radio.vue +214 -0
- package/src/components/Radio/index.ts +2 -0
- package/src/components/Rating/Rating.test.ts +319 -0
- package/src/components/Rating/Rating.vue +247 -0
- package/src/components/Rating/index.ts +2 -0
- package/src/components/SegmentedControl/SegmentedControl.test.ts +292 -0
- package/src/components/SegmentedControl/SegmentedControl.vue +288 -0
- package/src/components/SegmentedControl/index.ts +2 -0
- package/src/components/Select/Select.test.ts +589 -0
- package/src/components/Select/Select.vue +666 -0
- package/src/components/Select/index.ts +2 -0
- package/src/components/Sidebar/Sidebar.test.ts +301 -0
- package/src/components/Sidebar/SidebarGroup.vue +103 -0
- package/src/components/Sidebar/SidebarItem.vue +196 -0
- package/src/components/Sidebar/SidebarLayout.vue +42 -0
- package/src/components/Sidebar/SidebarRoot.vue +122 -0
- package/src/components/Sidebar/index.ts +11 -0
- package/src/components/Sidebar/keys.ts +14 -0
- package/src/components/Skeleton/Skeleton.test.ts +130 -0
- package/src/components/Skeleton/Skeleton.vue +104 -0
- package/src/components/Skeleton/index.ts +2 -0
- package/src/components/Slider/Slider.test.ts +416 -0
- package/src/components/Slider/Slider.vue +435 -0
- package/src/components/Slider/index.ts +2 -0
- package/src/components/Slider/utils.ts +91 -0
- package/src/components/Spinner/Spinner.test.ts +79 -0
- package/src/components/Spinner/Spinner.vue +159 -0
- package/src/components/Spinner/index.ts +2 -0
- package/src/components/SpireProvider/SpireProvider.vue +71 -0
- package/src/components/SpireProvider/index.ts +11 -0
- package/src/components/Stepper/Stepper.test.ts +221 -0
- package/src/components/Stepper/StepperContent.vue +51 -0
- package/src/components/Stepper/StepperItem.vue +89 -0
- package/src/components/Stepper/StepperRoot.vue +101 -0
- package/src/components/Stepper/StepperSeparator.vue +52 -0
- package/src/components/Stepper/StepperTrigger.vue +144 -0
- package/src/components/Stepper/index.ts +11 -0
- package/src/components/Stepper/keys.ts +27 -0
- package/src/components/Switch/Switch.test.ts +214 -0
- package/src/components/Switch/Switch.vue +235 -0
- package/src/components/Switch/index.ts +2 -0
- package/src/components/Tabs/Tabs.test.ts +363 -0
- package/src/components/Tabs/Tabs.vue +318 -0
- package/src/components/Tabs/index.ts +2 -0
- package/src/components/Text/Text.test.ts +154 -0
- package/src/components/Text/Text.vue +100 -0
- package/src/components/Text/index.ts +2 -0
- package/src/components/Textarea/Textarea.test.ts +432 -0
- package/src/components/Textarea/Textarea.vue +411 -0
- package/src/components/Textarea/index.ts +2 -0
- package/src/components/TimePicker/TimePicker.test.ts +352 -0
- package/src/components/TimePicker/TimePicker.vue +569 -0
- package/src/components/TimePicker/index.ts +2 -0
- package/src/components/Timeline/Timeline.test.ts +193 -0
- package/src/components/Timeline/Timeline.vue +111 -0
- package/src/components/Timeline/TimelineItem.vue +167 -0
- package/src/components/Timeline/index.ts +13 -0
- package/src/components/Timeline/keys.ts +21 -0
- package/src/components/Toast/ToastItem.test.ts +289 -0
- package/src/components/Toast/ToastItem.vue +370 -0
- package/src/components/Toast/ToastProvider.test.ts +158 -0
- package/src/components/Toast/ToastProvider.vue +181 -0
- package/src/components/Toast/index.ts +83 -0
- package/src/components/Toast/toastState.test.ts +165 -0
- package/src/components/Toast/toastState.ts +161 -0
- package/src/components/ToggleButton/ToggleButton.test.ts +166 -0
- package/src/components/ToggleButton/ToggleButton.vue +197 -0
- package/src/components/ToggleButton/index.ts +2 -0
- package/src/components/ToggleGroup/ToggleGroup.test.ts +181 -0
- package/src/components/ToggleGroup/ToggleGroup.vue +130 -0
- package/src/components/ToggleGroup/index.ts +2 -0
- package/src/components/Tooltip/Tooltip.test.ts +238 -0
- package/src/components/Tooltip/Tooltip.vue +217 -0
- package/src/components/Tooltip/index.ts +2 -0
- package/src/components/TreeView/TreeView.test.ts +357 -0
- package/src/components/TreeView/TreeView.vue +251 -0
- package/src/components/TreeView/TreeViewItem.vue +288 -0
- package/src/components/TreeView/index.ts +11 -0
- package/src/components/TreeView/keys.ts +35 -0
- package/src/composables/index.ts +12 -0
- package/src/composables/useClickOutside.ts +36 -0
- package/src/composables/useClipboard.ts +35 -0
- package/src/composables/useEventListener.ts +48 -0
- package/src/composables/useFocusTrap.ts +58 -0
- package/src/composables/useHoverReveal.ts +98 -0
- package/src/composables/useId.ts +10 -0
- package/src/composables/useMagnetic.ts +171 -0
- package/src/composables/useRelativePosition.ts +127 -0
- package/src/composables/useRipple.ts +146 -0
- package/src/composables/useScrollLock.ts +25 -0
- package/src/composables/useSpireConfig.ts +27 -0
- package/src/composables/useStagger.ts +224 -0
- package/src/config/icons.test.ts +115 -0
- package/src/config/icons.ts +170 -0
- package/src/index.ts +361 -0
- package/src/styles/depth.css +129 -0
- package/src/styles/effects.css +169 -0
- package/src/styles/fallback.css +152 -0
- package/src/styles/main.css +25 -0
- package/src/styles/mood.css +211 -0
- package/src/styles/motion.css +159 -0
- package/src/styles/reset.css +97 -0
- package/src/styles/theme.css +708 -0
- package/src/styles/tokens.css +183 -0
- package/src/utils/.gitkeep +0 -0
- package/src/utils/color.ts +277 -0
- package/src/utils/date.test.ts +522 -0
- package/src/utils/date.ts +380 -0
- package/src/utils/index.ts +23 -0
- package/src/utils/object.test.ts +80 -0
- package/src/utils/object.ts +25 -0
- package/src/utils/string.test.ts +64 -0
- package/src/utils/string.ts +32 -0
- package/src/utils/time.ts +156 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, useSlots } from 'vue'
|
|
3
|
+
|
|
4
|
+
type BadgeVariant = 'default' | 'success' | 'warning' | 'danger' | 'info'
|
|
5
|
+
|
|
6
|
+
export interface BadgeProps {
|
|
7
|
+
/** Color variant */
|
|
8
|
+
variant?: BadgeVariant
|
|
9
|
+
/** Render as dot indicator instead of pill */
|
|
10
|
+
dot?: boolean
|
|
11
|
+
/** Add pulse animation (dot mode only) */
|
|
12
|
+
pulse?: boolean
|
|
13
|
+
/** Numeric value for count badges */
|
|
14
|
+
value?: number
|
|
15
|
+
/** Max value before showing "+" (default: 99) */
|
|
16
|
+
max?: number
|
|
17
|
+
/** Accessible label (required for numeric badges) */
|
|
18
|
+
label?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const props = withDefaults(defineProps<BadgeProps>(), {
|
|
22
|
+
variant: 'default',
|
|
23
|
+
max: 99
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const slots = useSlots()
|
|
27
|
+
|
|
28
|
+
const isDot = computed(() => props.dot || (!slots.default && props.value === undefined))
|
|
29
|
+
|
|
30
|
+
const displayText = computed(() => {
|
|
31
|
+
if (props.value === undefined) return null
|
|
32
|
+
return props.value > props.max ? `${props.max}+` : String(props.value)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const ariaLabel = computed(() => {
|
|
36
|
+
if (props.label) return props.label
|
|
37
|
+
if (props.value !== undefined) return String(props.value)
|
|
38
|
+
return undefined
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const classes = computed(() => [
|
|
42
|
+
'ui-badge',
|
|
43
|
+
`ui-badge--${props.variant}`,
|
|
44
|
+
{
|
|
45
|
+
'ui-badge--dot': isDot.value,
|
|
46
|
+
'ui-badge--pulse': props.pulse && isDot.value
|
|
47
|
+
}
|
|
48
|
+
])
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<span :class="classes" :aria-label="ariaLabel" role="status">
|
|
53
|
+
<template v-if="!isDot">
|
|
54
|
+
<slot>{{ displayText }}</slot>
|
|
55
|
+
</template>
|
|
56
|
+
</span>
|
|
57
|
+
</template>
|
|
58
|
+
|
|
59
|
+
<style scoped>
|
|
60
|
+
.ui-badge {
|
|
61
|
+
display: inline-flex;
|
|
62
|
+
align-items: center;
|
|
63
|
+
justify-content: center;
|
|
64
|
+
font-family: var(--font-sans);
|
|
65
|
+
font-size: var(--text-xs);
|
|
66
|
+
font-weight: 500;
|
|
67
|
+
line-height: 1;
|
|
68
|
+
white-space: nowrap;
|
|
69
|
+
user-select: none;
|
|
70
|
+
font-variant-numeric: tabular-nums;
|
|
71
|
+
border-radius: 9999px;
|
|
72
|
+
padding: 0.25em 0.625em;
|
|
73
|
+
border: 1px solid transparent;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.ui-badge--dot {
|
|
77
|
+
width: 0.5rem;
|
|
78
|
+
height: 0.5rem;
|
|
79
|
+
padding: 0;
|
|
80
|
+
border: none;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.ui-badge--pulse {
|
|
84
|
+
animation: ui-badge-pulse 2s ease-in-out infinite;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@keyframes ui-badge-pulse {
|
|
88
|
+
0%, 100% {
|
|
89
|
+
box-shadow: 0 0 0 0 currentColor;
|
|
90
|
+
opacity: 1;
|
|
91
|
+
}
|
|
92
|
+
50% {
|
|
93
|
+
box-shadow: 0 0 0 4px currentColor;
|
|
94
|
+
opacity: 0.6;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.ui-badge--default {
|
|
99
|
+
background-color: var(--badge-default-bg);
|
|
100
|
+
color: var(--badge-default-text);
|
|
101
|
+
border-color: var(--badge-default-border);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.ui-badge--success {
|
|
105
|
+
background-color: var(--badge-success-bg);
|
|
106
|
+
color: var(--badge-success-text);
|
|
107
|
+
border-color: var(--badge-success-border);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.ui-badge--warning {
|
|
111
|
+
background-color: var(--badge-warning-bg);
|
|
112
|
+
color: var(--badge-warning-text);
|
|
113
|
+
border-color: var(--badge-warning-border);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.ui-badge--danger {
|
|
117
|
+
background-color: var(--badge-danger-bg);
|
|
118
|
+
color: var(--badge-danger-text);
|
|
119
|
+
border-color: var(--badge-danger-border);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.ui-badge--info {
|
|
123
|
+
background-color: var(--badge-info-bg);
|
|
124
|
+
color: var(--badge-info-text);
|
|
125
|
+
border-color: var(--badge-info-border);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.ui-badge--dot.ui-badge--default { background-color: var(--badge-default-text); }
|
|
129
|
+
.ui-badge--dot.ui-badge--success { background-color: var(--badge-success-text); }
|
|
130
|
+
.ui-badge--dot.ui-badge--warning { background-color: var(--badge-warning-text); }
|
|
131
|
+
.ui-badge--dot.ui-badge--danger { background-color: var(--badge-danger-text); }
|
|
132
|
+
.ui-badge--dot.ui-badge--info { background-color: var(--badge-info-text); }
|
|
133
|
+
</style>
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import BadgeContainer from './BadgeContainer.vue'
|
|
4
|
+
|
|
5
|
+
describe('BadgeContainer', () => {
|
|
6
|
+
describe('Rendering', () => {
|
|
7
|
+
it('renders default slot content', () => {
|
|
8
|
+
const wrapper = mount(BadgeContainer, {
|
|
9
|
+
slots: { default: '<button>Click me</button>' }
|
|
10
|
+
})
|
|
11
|
+
expect(wrapper.find('button').exists()).toBe(true)
|
|
12
|
+
expect(wrapper.find('button').text()).toBe('Click me')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('renders badge slot when provided', () => {
|
|
16
|
+
const wrapper = mount(BadgeContainer, {
|
|
17
|
+
slots: {
|
|
18
|
+
default: '<button>Inbox</button>',
|
|
19
|
+
badge: '<span class="test-badge">3</span>'
|
|
20
|
+
}
|
|
21
|
+
})
|
|
22
|
+
expect(wrapper.find('.test-badge').exists()).toBe(true)
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('does not render badge wrapper when no badge slot', () => {
|
|
26
|
+
const wrapper = mount(BadgeContainer, {
|
|
27
|
+
slots: { default: '<button>Click</button>' }
|
|
28
|
+
})
|
|
29
|
+
expect(wrapper.find('.ui-badge-container__badge').exists()).toBe(false)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
describe('Positioning', () => {
|
|
34
|
+
it('defaults to top-right position', () => {
|
|
35
|
+
const wrapper = mount(BadgeContainer, {
|
|
36
|
+
slots: {
|
|
37
|
+
default: '<button>Test</button>',
|
|
38
|
+
badge: '<span>1</span>'
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
const badge = wrapper.find('.ui-badge-container__badge')
|
|
42
|
+
expect(badge.attributes('style')).toContain('top: 0')
|
|
43
|
+
expect(badge.attributes('style')).toContain('right: 0')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('applies top-left position', () => {
|
|
47
|
+
const wrapper = mount(BadgeContainer, {
|
|
48
|
+
props: { position: 'top-left' },
|
|
49
|
+
slots: {
|
|
50
|
+
default: '<button>Test</button>',
|
|
51
|
+
badge: '<span>1</span>'
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
const badge = wrapper.find('.ui-badge-container__badge')
|
|
55
|
+
expect(badge.attributes('style')).toContain('top: 0')
|
|
56
|
+
expect(badge.attributes('style')).toContain('left: 0')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('applies bottom-right position', () => {
|
|
60
|
+
const wrapper = mount(BadgeContainer, {
|
|
61
|
+
props: { position: 'bottom-right' },
|
|
62
|
+
slots: {
|
|
63
|
+
default: '<button>Test</button>',
|
|
64
|
+
badge: '<span>1</span>'
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
const badge = wrapper.find('.ui-badge-container__badge')
|
|
68
|
+
expect(badge.attributes('style')).toContain('bottom: 0')
|
|
69
|
+
expect(badge.attributes('style')).toContain('right: 0')
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('applies bottom-left position', () => {
|
|
73
|
+
const wrapper = mount(BadgeContainer, {
|
|
74
|
+
props: { position: 'bottom-left' },
|
|
75
|
+
slots: {
|
|
76
|
+
default: '<button>Test</button>',
|
|
77
|
+
badge: '<span>1</span>'
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
const badge = wrapper.find('.ui-badge-container__badge')
|
|
81
|
+
expect(badge.attributes('style')).toContain('bottom: 0')
|
|
82
|
+
expect(badge.attributes('style')).toContain('left: 0')
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
describe('Offset adjustments', () => {
|
|
87
|
+
it('applies custom offsetX', () => {
|
|
88
|
+
const wrapper = mount(BadgeContainer, {
|
|
89
|
+
props: { offsetX: '4px' },
|
|
90
|
+
slots: {
|
|
91
|
+
default: '<button>Test</button>',
|
|
92
|
+
badge: '<span>1</span>'
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
const badge = wrapper.find('.ui-badge-container__badge')
|
|
96
|
+
expect(badge.attributes('style')).toContain('4px')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('applies custom offsetY', () => {
|
|
100
|
+
const wrapper = mount(BadgeContainer, {
|
|
101
|
+
props: { offsetY: '-2px' },
|
|
102
|
+
slots: {
|
|
103
|
+
default: '<button>Test</button>',
|
|
104
|
+
badge: '<span>1</span>'
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
const badge = wrapper.find('.ui-badge-container__badge')
|
|
108
|
+
expect(badge.attributes('style')).toContain('-2px')
|
|
109
|
+
})
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
describe('Cutout effect', () => {
|
|
113
|
+
it('applies cutout class when cutout prop is true', () => {
|
|
114
|
+
const wrapper = mount(BadgeContainer, {
|
|
115
|
+
props: { cutout: true },
|
|
116
|
+
slots: {
|
|
117
|
+
default: '<button>Test</button>',
|
|
118
|
+
badge: '<span>1</span>'
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
expect(wrapper.find('.ui-badge-container__badge--cutout').exists()).toBe(true)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('does not apply cutout class by default', () => {
|
|
125
|
+
const wrapper = mount(BadgeContainer, {
|
|
126
|
+
slots: {
|
|
127
|
+
default: '<button>Test</button>',
|
|
128
|
+
badge: '<span>1</span>'
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
expect(wrapper.find('.ui-badge-container__badge--cutout').exists()).toBe(false)
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
describe('Structure', () => {
|
|
136
|
+
it('has ui-badge-container class on root', () => {
|
|
137
|
+
const wrapper = mount(BadgeContainer, {
|
|
138
|
+
slots: { default: '<button>Test</button>' }
|
|
139
|
+
})
|
|
140
|
+
expect(wrapper.classes()).toContain('ui-badge-container')
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('uses inline-flex display for proper alignment', () => {
|
|
144
|
+
const wrapper = mount(BadgeContainer, {
|
|
145
|
+
slots: { default: '<button>Test</button>' }
|
|
146
|
+
})
|
|
147
|
+
expect(wrapper.classes()).toContain('ui-badge-container')
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue'
|
|
3
|
+
|
|
4
|
+
type BadgePosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
|
|
5
|
+
|
|
6
|
+
export interface BadgeContainerProps {
|
|
7
|
+
/** Badge position relative to content */
|
|
8
|
+
position?: BadgePosition
|
|
9
|
+
/** Horizontal offset adjustment (CSS value) */
|
|
10
|
+
offsetX?: string
|
|
11
|
+
/** Vertical offset adjustment (CSS value) */
|
|
12
|
+
offsetY?: string
|
|
13
|
+
/** Show cutout border matching background */
|
|
14
|
+
cutout?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const props = withDefaults(defineProps<BadgeContainerProps>(), {
|
|
18
|
+
position: 'top-right',
|
|
19
|
+
offsetX: '0px',
|
|
20
|
+
offsetY: '0px',
|
|
21
|
+
cutout: false
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const badgeStyle = computed(() => {
|
|
25
|
+
const positions: Record<BadgePosition, Record<string, string>> = {
|
|
26
|
+
'top-right': {
|
|
27
|
+
top: '0',
|
|
28
|
+
right: '0',
|
|
29
|
+
transform: `translate(calc(50% + ${props.offsetX}), calc(-50% + ${props.offsetY}))`
|
|
30
|
+
},
|
|
31
|
+
'top-left': {
|
|
32
|
+
top: '0',
|
|
33
|
+
left: '0',
|
|
34
|
+
transform: `translate(calc(-50% + ${props.offsetX}), calc(-50% + ${props.offsetY}))`
|
|
35
|
+
},
|
|
36
|
+
'bottom-right': {
|
|
37
|
+
bottom: '0',
|
|
38
|
+
right: '0',
|
|
39
|
+
transform: `translate(calc(50% + ${props.offsetX}), calc(50% + ${props.offsetY}))`
|
|
40
|
+
},
|
|
41
|
+
'bottom-left': {
|
|
42
|
+
bottom: '0',
|
|
43
|
+
left: '0',
|
|
44
|
+
transform: `translate(calc(-50% + ${props.offsetX}), calc(50% + ${props.offsetY}))`
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return positions[props.position]
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const badgeClasses = computed(() => [
|
|
51
|
+
'ui-badge-container__badge',
|
|
52
|
+
{ 'ui-badge-container__badge--cutout': props.cutout }
|
|
53
|
+
])
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
57
|
+
<span class="ui-badge-container">
|
|
58
|
+
<!-- Content (Button, Avatar, etc.) -->
|
|
59
|
+
<slot />
|
|
60
|
+
|
|
61
|
+
<!-- Badge overlay -->
|
|
62
|
+
<span v-if="$slots.badge" :class="badgeClasses" :style="badgeStyle">
|
|
63
|
+
<slot name="badge" />
|
|
64
|
+
</span>
|
|
65
|
+
</span>
|
|
66
|
+
</template>
|
|
67
|
+
|
|
68
|
+
<style scoped>
|
|
69
|
+
.ui-badge-container {
|
|
70
|
+
display: inline-flex;
|
|
71
|
+
position: relative;
|
|
72
|
+
vertical-align: middle;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.ui-badge-container__badge {
|
|
76
|
+
position: absolute;
|
|
77
|
+
z-index: 10;
|
|
78
|
+
pointer-events: none;
|
|
79
|
+
line-height: 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* Cutout effect - creates visual separation from content */
|
|
83
|
+
.ui-badge-container__badge--cutout :deep(.ui-badge) {
|
|
84
|
+
box-shadow: 0 0 0 2px var(--bg-primary);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.ui-badge-container__badge--cutout :deep(.ui-badge--dot) {
|
|
88
|
+
box-shadow: 0 0 0 2px var(--bg-primary);
|
|
89
|
+
}
|
|
90
|
+
</style>
|