@gitlab/ui 99.1.0 → 100.0.0
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/CHANGELOG.md +22 -0
- package/dist/components/base/badge/badge.js +88 -4
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/vendor/bootstrap-vue/src/constants/components.js +1 -2
- package/dist/vendor/bootstrap-vue/src/index.js +0 -1
- package/package.json +2 -2
- package/src/components/base/badge/badge.md +5 -13
- package/src/components/base/badge/badge.scss +6 -1
- package/src/components/base/badge/badge.vue +86 -10
- package/src/vendor/bootstrap-vue/src/constants/components.js +0 -1
- package/src/vendor/bootstrap-vue/src/index.js +0 -3
- package/dist/vendor/bootstrap-vue/src/components/badge/badge.js +0 -53
- package/dist/vendor/bootstrap-vue/src/components/badge/index.js +0 -1
- package/src/vendor/bootstrap-vue/src/components/badge/README.md +0 -126
- package/src/vendor/bootstrap-vue/src/components/badge/badge.js +0 -55
- package/src/vendor/bootstrap-vue/src/components/badge/badge.spec.js +0 -141
- package/src/vendor/bootstrap-vue/src/components/badge/index.d.ts +0 -7
- package/src/vendor/bootstrap-vue/src/components/badge/index.js +0 -3
- package/src/vendor/bootstrap-vue/src/components/badge/package.json +0 -29
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Component names
|
|
2
|
-
const NAME_BADGE = 'BBadge';
|
|
3
2
|
const NAME_BREADCRUMB = 'BBreadcrumb';
|
|
4
3
|
const NAME_BREADCRUMB_ITEM = 'BBreadcrumbItem';
|
|
5
4
|
const NAME_BREADCRUMB_LINK = 'BBreadcrumbLink';
|
|
@@ -72,4 +71,4 @@ const NAME_TRANSITION = 'BVTransition';
|
|
|
72
71
|
const NAME_TRANSPORTER = 'BVTransporter';
|
|
73
72
|
const NAME_TRANSPORTER_TARGET = 'BVTransporterTarget';
|
|
74
73
|
|
|
75
|
-
export {
|
|
74
|
+
export { NAME_BREADCRUMB, NAME_BREADCRUMB_ITEM, NAME_BREADCRUMB_LINK, NAME_BUTTON, NAME_BUTTON_CLOSE, NAME_BUTTON_GROUP, NAME_COL, NAME_COLLAPSE, NAME_COLLAPSE_HELPER, NAME_DROPDOWN, NAME_DROPDOWN_DIVIDER, NAME_DROPDOWN_FORM, NAME_DROPDOWN_GROUP, NAME_DROPDOWN_HEADER, NAME_DROPDOWN_ITEM, NAME_DROPDOWN_ITEM_BUTTON, NAME_DROPDOWN_TEXT, NAME_FORM, NAME_FORM_BUTTON_LABEL_CONTROL, NAME_FORM_CHECKBOX, NAME_FORM_CHECKBOX_GROUP, NAME_FORM_GROUP, NAME_FORM_INPUT, NAME_FORM_INVALID_FEEDBACK, NAME_FORM_RADIO, NAME_FORM_RADIO_GROUP, NAME_FORM_RATING_STAR, NAME_FORM_ROW, NAME_FORM_SELECT, NAME_FORM_SELECT_OPTION, NAME_FORM_SELECT_OPTION_GROUP, NAME_FORM_TEXT, NAME_FORM_TEXTAREA, NAME_FORM_VALID_FEEDBACK, NAME_INPUT_GROUP, NAME_INPUT_GROUP_ADDON, NAME_INPUT_GROUP_APPEND, NAME_INPUT_GROUP_PREPEND, NAME_INPUT_GROUP_TEXT, NAME_LINK, NAME_MODAL, NAME_NAV, NAME_NAV_ITEM, NAME_NAV_ITEM_DROPDOWN, NAME_POPOVER, NAME_POPOVER_HELPER, NAME_POPOVER_TEMPLATE, NAME_POPPER, NAME_TAB, NAME_TABLE, NAME_TABLE_CELL, NAME_TABLE_LITE, NAME_TABLE_SIMPLE, NAME_TABS, NAME_TAB_BUTTON_HELPER, NAME_TBODY, NAME_TFOOT, NAME_TH, NAME_THEAD, NAME_TOAST, NAME_TOASTER, NAME_TOAST_POP, NAME_TOOLTIP, NAME_TOOLTIP_HELPER, NAME_TOOLTIP_TEMPLATE, NAME_TR, NAME_TRANSITION, NAME_TRANSPORTER, NAME_TRANSPORTER_TARGET };
|
|
@@ -2,7 +2,6 @@ import { installFactory } from './utils/plugins';
|
|
|
2
2
|
import { componentsPlugin } from './components';
|
|
3
3
|
export { BVConfigPlugin as BVConfig, BVConfigPlugin } from './bv-config';
|
|
4
4
|
export { BVToastPlugin } from './components/toast/helpers/bv-toast';
|
|
5
|
-
export { BBadge } from './components/badge/badge';
|
|
6
5
|
export { BBreadcrumb } from './components/breadcrumb/breadcrumb';
|
|
7
6
|
export { BBreadcrumbItem } from './components/breadcrumb/breadcrumb-item';
|
|
8
7
|
export { BButton } from './components/button/button';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitlab/ui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "100.0.0",
|
|
4
4
|
"description": "GitLab UI Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"babel-jest": "29.0.1",
|
|
147
147
|
"babel-loader": "^8.0.5",
|
|
148
148
|
"bootstrap": "4.6.2",
|
|
149
|
-
"cypress": "13.15.
|
|
149
|
+
"cypress": "13.15.1",
|
|
150
150
|
"cypress-axe": "^1.4.0",
|
|
151
151
|
"cypress-real-events": "^1.11.0",
|
|
152
152
|
"dompurify": "^3.1.2",
|
|
@@ -23,16 +23,8 @@ badge for best accessibility.
|
|
|
23
23
|
<gl-badge icon="eye" aria-label="Mark as confidential" />
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
##
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
`
|
|
31
|
-
|
|
32
|
-
- Has a different set of valid `variant`s. See the examples or props
|
|
33
|
-
documentation for those values.
|
|
34
|
-
- Always sets the `pill` prop of the underlying
|
|
35
|
-
[`BBadge`](https://bootstrap-vue.org/docs/components/badge) to `true`. Any passed
|
|
36
|
-
in `pill` prop value is ignored.
|
|
37
|
-
- Does _not_ scale itself to match the size of its immediate parent, like
|
|
38
|
-
[`BBadge`](https://bootstrap-vue.org/docs/components/badge) does.
|
|
26
|
+
## Link badges
|
|
27
|
+
|
|
28
|
+
Badges can be made actionable and turn into links by providing the `href` prop,
|
|
29
|
+
which can be used in combination with the props `rel`, `target`, `active`, and `disabled`.
|
|
30
|
+
The prop `tag` will be ignored and the `BLink` component will be used instead.
|
|
@@ -27,7 +27,7 @@ $badge-min-width: $gl-spacing-scale-3;
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
a.gl-badge.badge-#{$variant} {
|
|
30
|
+
a.gl-badge.badge-#{$variant}:not(.disabled) {
|
|
31
31
|
&:hover {
|
|
32
32
|
color: $hover-color;
|
|
33
33
|
// Needed to override bootstrap's badge variant background
|
|
@@ -117,6 +117,11 @@ $badge-min-width: $gl-spacing-scale-3;
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
a.gl-badge.disabled {
|
|
121
|
+
cursor: not-allowed;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
120
125
|
/* Variants */
|
|
121
126
|
|
|
122
127
|
@include gl-badge-variant(
|
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
<!-- eslint-disable vue/multi-word-component-names -->
|
|
2
2
|
<script>
|
|
3
|
-
import {
|
|
3
|
+
import { BLink } from '../../../vendor/bootstrap-vue/src/components/link/link';
|
|
4
4
|
import { badgeVariantOptions, badgeIconSizeOptions } from '../../../utils/constants';
|
|
5
5
|
import GlIcon from '../icon/icon.vue';
|
|
6
6
|
|
|
7
|
+
const variantClass = {
|
|
8
|
+
[badgeVariantOptions.muted]: 'badge-muted',
|
|
9
|
+
[badgeVariantOptions.neutral]: 'badge-neutral',
|
|
10
|
+
[badgeVariantOptions.info]: 'badge-info',
|
|
11
|
+
[badgeVariantOptions.success]: 'badge-success',
|
|
12
|
+
[badgeVariantOptions.warning]: 'badge-warning',
|
|
13
|
+
[badgeVariantOptions.danger]: 'badge-danger',
|
|
14
|
+
[badgeVariantOptions.tier]: 'badge-tier',
|
|
15
|
+
};
|
|
16
|
+
|
|
7
17
|
export default {
|
|
8
18
|
name: 'GlBadge',
|
|
9
19
|
components: {
|
|
10
|
-
|
|
20
|
+
BLink,
|
|
11
21
|
GlIcon,
|
|
12
22
|
},
|
|
13
|
-
inheritAttrs: false,
|
|
14
23
|
props: {
|
|
15
24
|
/**
|
|
16
25
|
* The variant of the badge.
|
|
@@ -48,6 +57,54 @@ export default {
|
|
|
48
57
|
default: false,
|
|
49
58
|
required: false,
|
|
50
59
|
},
|
|
60
|
+
/**
|
|
61
|
+
* Custom tag to use (unless `href` is defined)
|
|
62
|
+
*/
|
|
63
|
+
tag: {
|
|
64
|
+
type: String,
|
|
65
|
+
required: false,
|
|
66
|
+
default: 'span',
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Creates the badge as link (ignores `tag` property)
|
|
70
|
+
*/
|
|
71
|
+
href: {
|
|
72
|
+
type: String,
|
|
73
|
+
required: false,
|
|
74
|
+
default: undefined,
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Sets the `rel` attributes, when `href` is defined
|
|
78
|
+
*/
|
|
79
|
+
rel: {
|
|
80
|
+
type: String,
|
|
81
|
+
required: false,
|
|
82
|
+
default: null,
|
|
83
|
+
},
|
|
84
|
+
/**
|
|
85
|
+
* Sets the `target`, when `href` is defined
|
|
86
|
+
*/
|
|
87
|
+
target: {
|
|
88
|
+
type: String,
|
|
89
|
+
required: false,
|
|
90
|
+
default: '_self',
|
|
91
|
+
},
|
|
92
|
+
/**
|
|
93
|
+
* Adds the `active` class, when `href` is defined
|
|
94
|
+
*/
|
|
95
|
+
active: {
|
|
96
|
+
type: Boolean,
|
|
97
|
+
required: false,
|
|
98
|
+
default: false,
|
|
99
|
+
},
|
|
100
|
+
/**
|
|
101
|
+
* Disables the link, when `href` is defined
|
|
102
|
+
*/
|
|
103
|
+
disabled: {
|
|
104
|
+
type: Boolean,
|
|
105
|
+
required: false,
|
|
106
|
+
default: false,
|
|
107
|
+
},
|
|
51
108
|
},
|
|
52
109
|
computed: {
|
|
53
110
|
hasIconOnly() {
|
|
@@ -70,19 +127,38 @@ export default {
|
|
|
70
127
|
iconSizeComputed() {
|
|
71
128
|
return badgeIconSizeOptions[this.iconSize];
|
|
72
129
|
},
|
|
130
|
+
isLink() {
|
|
131
|
+
return Boolean(this.href);
|
|
132
|
+
},
|
|
133
|
+
computedTag() {
|
|
134
|
+
return this.isLink ? BLink : this.tag;
|
|
135
|
+
},
|
|
136
|
+
computedProps() {
|
|
137
|
+
if (!this.isLink) return {};
|
|
138
|
+
|
|
139
|
+
const { href, rel, target, active, disabled } = this;
|
|
140
|
+
return { href, rel, target, active, disabled };
|
|
141
|
+
},
|
|
142
|
+
classes() {
|
|
143
|
+
return [
|
|
144
|
+
'gl-badge',
|
|
145
|
+
'badge',
|
|
146
|
+
'badge-pill',
|
|
147
|
+
variantClass[this.variant],
|
|
148
|
+
{ '!gl-px-2': !this.$scopedSlots.default },
|
|
149
|
+
];
|
|
150
|
+
},
|
|
73
151
|
},
|
|
74
152
|
};
|
|
75
153
|
</script>
|
|
76
154
|
|
|
77
155
|
<template>
|
|
78
|
-
<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class="
|
|
82
|
-
:class="{ '!gl-px-2': !$scopedSlots.default }"
|
|
156
|
+
<component
|
|
157
|
+
:is="computedTag"
|
|
158
|
+
v-bind="computedProps"
|
|
159
|
+
:class="classes"
|
|
83
160
|
:role="role"
|
|
84
161
|
:aria-label="ariaLabel"
|
|
85
|
-
pill
|
|
86
162
|
>
|
|
87
163
|
<gl-icon
|
|
88
164
|
v-if="icon"
|
|
@@ -95,5 +171,5 @@ export default {
|
|
|
95
171
|
<span v-if="$slots.default" class="gl-badge-content">
|
|
96
172
|
<slot></slot>
|
|
97
173
|
</span>
|
|
98
|
-
</
|
|
174
|
+
</component>
|
|
99
175
|
</template>
|
|
@@ -51,9 +51,6 @@ export { BVToastPlugin } from './components/toast/helpers/bv-toast'
|
|
|
51
51
|
|
|
52
52
|
// --- Export all individual components and component group plugins as named exports ---
|
|
53
53
|
|
|
54
|
-
// export * from './components/badge'
|
|
55
|
-
export { BBadge } from './components/badge/badge'
|
|
56
|
-
|
|
57
54
|
// export * from './components/breadcrumb'
|
|
58
55
|
export { BBreadcrumb } from './components/breadcrumb/breadcrumb'
|
|
59
56
|
export { BBreadcrumbItem } from './components/breadcrumb/breadcrumb-item'
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { extend, mergeData } from '../../vue';
|
|
2
|
-
import { NAME_BADGE } from '../../constants/components';
|
|
3
|
-
import { PROP_TYPE_BOOLEAN, PROP_TYPE_STRING } from '../../constants/props';
|
|
4
|
-
import { omit, sortKeys } from '../../utils/object';
|
|
5
|
-
import { makePropsConfigurable, makeProp, pluckProps } from '../../utils/props';
|
|
6
|
-
import { isLink } from '../../utils/router';
|
|
7
|
-
import { props as props$1, BLink } from '../link/link';
|
|
8
|
-
|
|
9
|
-
// --- Props ---
|
|
10
|
-
|
|
11
|
-
const linkProps = omit(props$1, ['event', 'routerTag']);
|
|
12
|
-
delete linkProps.href.default;
|
|
13
|
-
delete linkProps.to.default;
|
|
14
|
-
const props = makePropsConfigurable(sortKeys({
|
|
15
|
-
...linkProps,
|
|
16
|
-
pill: makeProp(PROP_TYPE_BOOLEAN, false),
|
|
17
|
-
tag: makeProp(PROP_TYPE_STRING, 'span'),
|
|
18
|
-
variant: makeProp(PROP_TYPE_STRING, 'secondary')
|
|
19
|
-
}), NAME_BADGE);
|
|
20
|
-
|
|
21
|
-
// --- Main component ---
|
|
22
|
-
|
|
23
|
-
// @vue/component
|
|
24
|
-
const BBadge = /*#__PURE__*/extend({
|
|
25
|
-
name: NAME_BADGE,
|
|
26
|
-
functional: true,
|
|
27
|
-
props,
|
|
28
|
-
render(h, _ref) {
|
|
29
|
-
let {
|
|
30
|
-
props,
|
|
31
|
-
data,
|
|
32
|
-
children
|
|
33
|
-
} = _ref;
|
|
34
|
-
const {
|
|
35
|
-
active,
|
|
36
|
-
disabled
|
|
37
|
-
} = props;
|
|
38
|
-
const link = isLink(props);
|
|
39
|
-
const tag = link ? BLink : props.tag;
|
|
40
|
-
const variant = props.variant || 'secondary';
|
|
41
|
-
return h(tag, mergeData(data, {
|
|
42
|
-
staticClass: 'badge',
|
|
43
|
-
class: [`badge-${variant}`, {
|
|
44
|
-
'badge-pill': props.pill,
|
|
45
|
-
active,
|
|
46
|
-
disabled
|
|
47
|
-
}],
|
|
48
|
-
props: link ? pluckProps(linkProps, props) : {}
|
|
49
|
-
}), children);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export { BBadge, props };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BBadge } from './badge';
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
# Badge
|
|
2
|
-
|
|
3
|
-
> Small and adaptive tag for adding context to just about any content.
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
Badges scale to match the size of the immediate parent element by using relative font sizing and
|
|
8
|
-
`em` units.
|
|
9
|
-
|
|
10
|
-
```html
|
|
11
|
-
<div>
|
|
12
|
-
<h2>Example heading <b-badge>New</b-badge></h2>
|
|
13
|
-
<h3>Example heading <b-badge>New</b-badge></h3>
|
|
14
|
-
<h4>Example heading <b-badge>New</b-badge></h4>
|
|
15
|
-
<h5>Example heading <b-badge>New</b-badge></h5>
|
|
16
|
-
<h6>Example heading <b-badge>New</b-badge></h6>
|
|
17
|
-
</div>
|
|
18
|
-
|
|
19
|
-
<!-- b-badges.vue -->
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Badges can be used as part of links or buttons to provide a counter (or similar flag).
|
|
23
|
-
|
|
24
|
-
```html
|
|
25
|
-
<div class="text-center">
|
|
26
|
-
<b-button variant="primary">
|
|
27
|
-
Notifications <b-badge variant="light">4</b-badge>
|
|
28
|
-
</b-button>
|
|
29
|
-
</div>
|
|
30
|
-
|
|
31
|
-
<!-- b-badge-button.vue -->
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
Note that depending on how they are used, badges may be confusing for users of screen readers and
|
|
35
|
-
similar assistive technologies. While the styling of badges provides a visual cue as to their
|
|
36
|
-
purpose, these users will simply be presented with the content of the badge. Depending on the
|
|
37
|
-
specific situation, these badges may seem like random additional words or numbers at the end of a
|
|
38
|
-
sentence, link, or button.
|
|
39
|
-
|
|
40
|
-
Unless the context is clear (as with the "Notifications" example, where it is understood that the
|
|
41
|
-
"4" is the number of notifications), consider including additional context with a visually hidden
|
|
42
|
-
piece of additional text.
|
|
43
|
-
|
|
44
|
-
```html
|
|
45
|
-
<div class="text-center">
|
|
46
|
-
<b-button variant="primary">
|
|
47
|
-
Profile
|
|
48
|
-
<b-badge variant="light">9 <span class="sr-only">unread messages</span></b-badge>
|
|
49
|
-
</b-button>
|
|
50
|
-
</div>
|
|
51
|
-
|
|
52
|
-
<!-- b-badge-button-aria.vue -->
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## Contextual variations
|
|
56
|
-
|
|
57
|
-
Add any of the following variants via the `variant` prop to change the appearance of a `<b-badge>`:
|
|
58
|
-
`default`, `primary`, `success`, `warning`, `info`, and `danger`. If no variant is specified
|
|
59
|
-
`default` will be used.
|
|
60
|
-
|
|
61
|
-
```html
|
|
62
|
-
<div>
|
|
63
|
-
<b-badge variant="primary">Primary</b-badge>
|
|
64
|
-
<b-badge variant="secondary">Secondary</b-badge>
|
|
65
|
-
<b-badge variant="success">Success</b-badge>
|
|
66
|
-
<b-badge variant="danger">Danger</b-badge>
|
|
67
|
-
<b-badge variant="warning">Warning</b-badge>
|
|
68
|
-
<b-badge variant="info">Info</b-badge>
|
|
69
|
-
<b-badge variant="light">Light</b-badge>
|
|
70
|
-
<b-badge variant="dark">Dark</b-badge>
|
|
71
|
-
</div>
|
|
72
|
-
|
|
73
|
-
<!-- b-badge-variants.vue -->
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### Conveying meaning to assistive technologies
|
|
77
|
-
|
|
78
|
-
Using color to add meaning only provides a visual indication, which will not be conveyed to users of
|
|
79
|
-
assistive technologies – such as screen readers. Ensure that information denoted by the color is
|
|
80
|
-
either obvious from the content itself (e.g. the visible text), or is included through alternative
|
|
81
|
-
means, such as additional text hidden with the `.sr-only` class.
|
|
82
|
-
|
|
83
|
-
## Pill badges
|
|
84
|
-
|
|
85
|
-
Use the `pill` prop to make badges more rounded (with a larger border-radius and additional
|
|
86
|
-
horizontal padding). Useful if you miss the badges from Bootstrap v3.
|
|
87
|
-
|
|
88
|
-
```html
|
|
89
|
-
<div>
|
|
90
|
-
<b-badge pill variant="primary">Primary</b-badge>
|
|
91
|
-
<b-badge pill variant="secondary">Secondary</b-badge>
|
|
92
|
-
<b-badge pill variant="success">Success</b-badge>
|
|
93
|
-
<b-badge pill variant="danger">Danger</b-badge>
|
|
94
|
-
<b-badge pill variant="warning">Warning</b-badge>
|
|
95
|
-
<b-badge pill variant="info">Info</b-badge>
|
|
96
|
-
<b-badge pill variant="light">Light</b-badge>
|
|
97
|
-
<b-badge pill variant="dark">Dark</b-badge>
|
|
98
|
-
</div>
|
|
99
|
-
|
|
100
|
-
<!-- b-badge-pill.vue -->
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Actionable badges
|
|
104
|
-
|
|
105
|
-
Quickly provide actionable badges with hover and focus states by specifying either the `href` prop
|
|
106
|
-
(links) or `to` prop (router-links):
|
|
107
|
-
|
|
108
|
-
```html
|
|
109
|
-
<div>
|
|
110
|
-
<b-badge href="#" variant="primary">Primary</b-badge>
|
|
111
|
-
<b-badge href="#" variant="secondary">Secondary</b-badge>
|
|
112
|
-
<b-badge href="#" variant="success">Success</b-badge>
|
|
113
|
-
<b-badge href="#" variant="danger">Danger</b-badge>
|
|
114
|
-
<b-badge href="#" variant="warning">Warning</b-badge>
|
|
115
|
-
<b-badge href="#" variant="info">Info</b-badge>
|
|
116
|
-
<b-badge href="#" variant="light">Light</b-badge>
|
|
117
|
-
<b-badge href="#" variant="dark">Dark</b-badge>
|
|
118
|
-
</div>
|
|
119
|
-
|
|
120
|
-
<!-- b-badge-action.vue -->
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Refer to the [Router support](?path=/docs/base-link--docs#router-link-support) reference page for
|
|
124
|
-
router-link specific props.
|
|
125
|
-
|
|
126
|
-
<!-- Component reference added automatically from component package.json -->
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { extend, mergeData } from '../../vue'
|
|
2
|
-
import { NAME_BADGE } from '../../constants/components'
|
|
3
|
-
import { PROP_TYPE_BOOLEAN, PROP_TYPE_STRING } from '../../constants/props'
|
|
4
|
-
import { omit, sortKeys } from '../../utils/object'
|
|
5
|
-
import { makeProp, makePropsConfigurable, pluckProps } from '../../utils/props'
|
|
6
|
-
import { isLink } from '../../utils/router'
|
|
7
|
-
import { BLink, props as BLinkProps } from '../link/link'
|
|
8
|
-
|
|
9
|
-
// --- Props ---
|
|
10
|
-
|
|
11
|
-
const linkProps = omit(BLinkProps, ['event', 'routerTag'])
|
|
12
|
-
delete linkProps.href.default
|
|
13
|
-
delete linkProps.to.default
|
|
14
|
-
|
|
15
|
-
export const props = makePropsConfigurable(
|
|
16
|
-
sortKeys({
|
|
17
|
-
...linkProps,
|
|
18
|
-
pill: makeProp(PROP_TYPE_BOOLEAN, false),
|
|
19
|
-
tag: makeProp(PROP_TYPE_STRING, 'span'),
|
|
20
|
-
variant: makeProp(PROP_TYPE_STRING, 'secondary')
|
|
21
|
-
}),
|
|
22
|
-
NAME_BADGE
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
// --- Main component ---
|
|
26
|
-
|
|
27
|
-
// @vue/component
|
|
28
|
-
export const BBadge = /*#__PURE__*/ extend({
|
|
29
|
-
name: NAME_BADGE,
|
|
30
|
-
functional: true,
|
|
31
|
-
props,
|
|
32
|
-
render(h, { props, data, children }) {
|
|
33
|
-
const { active, disabled } = props
|
|
34
|
-
const link = isLink(props)
|
|
35
|
-
const tag = link ? BLink : props.tag
|
|
36
|
-
const variant = props.variant || 'secondary'
|
|
37
|
-
|
|
38
|
-
return h(
|
|
39
|
-
tag,
|
|
40
|
-
mergeData(data, {
|
|
41
|
-
staticClass: 'badge',
|
|
42
|
-
class: [
|
|
43
|
-
`badge-${variant}`,
|
|
44
|
-
{
|
|
45
|
-
'badge-pill': props.pill,
|
|
46
|
-
active,
|
|
47
|
-
disabled
|
|
48
|
-
}
|
|
49
|
-
],
|
|
50
|
-
props: link ? pluckProps(linkProps, props) : {}
|
|
51
|
-
}),
|
|
52
|
-
children
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
})
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { mount } from '@vue/test-utils'
|
|
2
|
-
import { BBadge } from './badge'
|
|
3
|
-
|
|
4
|
-
describe('badge', () => {
|
|
5
|
-
it('should have base classes', async () => {
|
|
6
|
-
const wrapper = mount(BBadge)
|
|
7
|
-
|
|
8
|
-
expect(wrapper.element.tagName).toBe('SPAN')
|
|
9
|
-
expect(wrapper.classes()).toContain('badge')
|
|
10
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
11
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
12
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
13
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
14
|
-
expect(wrapper.attributes('href')).toBeUndefined()
|
|
15
|
-
|
|
16
|
-
wrapper.destroy()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('should have default slot content', async () => {
|
|
20
|
-
const wrapper = mount(BBadge, {
|
|
21
|
-
slots: {
|
|
22
|
-
default: 'foobar'
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
expect(wrapper.element.tagName).toBe('SPAN')
|
|
27
|
-
expect(wrapper.text()).toBe('foobar')
|
|
28
|
-
expect(wrapper.classes()).toContain('badge')
|
|
29
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
30
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
31
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
32
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
33
|
-
expect(wrapper.attributes('href')).toBeUndefined()
|
|
34
|
-
|
|
35
|
-
wrapper.destroy()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('should apply variant class', async () => {
|
|
39
|
-
const wrapper = mount(BBadge, {
|
|
40
|
-
propsData: {
|
|
41
|
-
variant: 'danger'
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
expect(wrapper.element.tagName).toBe('SPAN')
|
|
46
|
-
expect(wrapper.classes()).toContain('badge-danger')
|
|
47
|
-
expect(wrapper.classes()).toContain('badge')
|
|
48
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
49
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
50
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
51
|
-
|
|
52
|
-
wrapper.destroy()
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('should apply pill class', async () => {
|
|
56
|
-
const wrapper = mount(BBadge, {
|
|
57
|
-
propsData: {
|
|
58
|
-
pill: true
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
expect(wrapper.element.tagName).toBe('SPAN')
|
|
63
|
-
expect(wrapper.classes()).toContain('badge-pill')
|
|
64
|
-
expect(wrapper.classes()).toContain('badge')
|
|
65
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
66
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
67
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
68
|
-
|
|
69
|
-
wrapper.destroy()
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('should have active class when prop active set', async () => {
|
|
73
|
-
const wrapper = mount(BBadge, {
|
|
74
|
-
propsData: {
|
|
75
|
-
active: true
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
expect(wrapper.element.tagName).toBe('SPAN')
|
|
80
|
-
expect(wrapper.classes()).toContain('active')
|
|
81
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
82
|
-
expect(wrapper.classes()).toContain('badge')
|
|
83
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
84
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
85
|
-
|
|
86
|
-
wrapper.destroy()
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('should have disabled class when prop disabled set', async () => {
|
|
90
|
-
const wrapper = mount(BBadge, {
|
|
91
|
-
propsData: {
|
|
92
|
-
disabled: true
|
|
93
|
-
}
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
expect(wrapper.element.tagName).toBe('SPAN')
|
|
97
|
-
expect(wrapper.classes()).toContain('disabled')
|
|
98
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
99
|
-
expect(wrapper.classes()).toContain('badge')
|
|
100
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
101
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
102
|
-
|
|
103
|
-
wrapper.destroy()
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('renders custom root element', async () => {
|
|
107
|
-
const wrapper = mount(BBadge, {
|
|
108
|
-
propsData: {
|
|
109
|
-
tag: 'small'
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
expect(wrapper.element.tagName).toBe('SMALL')
|
|
114
|
-
expect(wrapper.classes()).toContain('badge')
|
|
115
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
116
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
117
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
118
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
119
|
-
|
|
120
|
-
wrapper.destroy()
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('renders link when href provided', async () => {
|
|
124
|
-
const wrapper = mount(BBadge, {
|
|
125
|
-
propsData: {
|
|
126
|
-
href: '/foo/bar'
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
expect(wrapper.element.tagName).toBe('A')
|
|
131
|
-
expect(wrapper.attributes('href')).toBeDefined()
|
|
132
|
-
expect(wrapper.attributes('href')).toBe('/foo/bar')
|
|
133
|
-
expect(wrapper.classes()).toContain('badge')
|
|
134
|
-
expect(wrapper.classes()).toContain('badge-secondary')
|
|
135
|
-
expect(wrapper.classes()).not.toContain('badge-pill')
|
|
136
|
-
expect(wrapper.classes()).not.toContain('active')
|
|
137
|
-
expect(wrapper.classes()).not.toContain('disabled')
|
|
138
|
-
|
|
139
|
-
wrapper.destroy()
|
|
140
|
-
})
|
|
141
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@bootstrap-vue/badge",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"meta": {
|
|
5
|
-
"title": "Badge",
|
|
6
|
-
"description": "Small and adaptive tag for adding context to just about any content.",
|
|
7
|
-
"components": [
|
|
8
|
-
{
|
|
9
|
-
"component": "BBadge",
|
|
10
|
-
"props": [
|
|
11
|
-
{
|
|
12
|
-
"prop": "pill",
|
|
13
|
-
"description": "When set to 'true', renders the badge in pill style"
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
"prop": "variant",
|
|
17
|
-
"description": "Applies one of the Bootstrap theme color variants to the component"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"slots": [
|
|
21
|
-
{
|
|
22
|
-
"name": "default",
|
|
23
|
-
"description": "Content to place in the badge"
|
|
24
|
-
}
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|