@citizenplane/pimp 8.20.3 → 8.21.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/dist/pimp.es.js +3538 -3515
- package/dist/pimp.umd.js +4 -4
- package/dist/style.css +1 -1
- package/package.json +16 -16
- package/src/README.md +1 -6
- package/src/components/atomic-elements/CpBadge.vue +82 -138
- package/src/components/index.js +0 -2
- package/src/stories/CpBadge.stories.ts +80 -90
- package/src/components/atomic-elements/CpBadgeNew.vue +0 -145
- package/src/stories/CpBadgeNew.stories.ts +0 -148
|
@@ -1,35 +1,59 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="cpBadge" :class="
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
<div class="cpBadge" :class="componentDynamicClasses">
|
|
3
|
+
<slot name="leading-icon">
|
|
4
|
+
<cp-icon v-if="leadingIcon" :type="leadingIcon" class="cpBadge__icon" />
|
|
5
|
+
</slot>
|
|
6
|
+
|
|
7
|
+
<span class="cpBadge__label">
|
|
8
|
+
<slot>{{ label }}</slot>
|
|
9
|
+
</span>
|
|
10
|
+
|
|
11
|
+
<slot v-if="!isClearable" name="trailing-icon">
|
|
12
|
+
<cp-icon v-if="trailingIcon" :type="trailingIcon" class="cpBadge__icon" />
|
|
13
|
+
</slot>
|
|
14
|
+
|
|
15
|
+
<button v-if="isClearable" class="cpBadge__clear" @click="onClear">
|
|
16
|
+
<cp-icon type="x" class="cpBadge__icon" />
|
|
8
17
|
</button>
|
|
9
18
|
</div>
|
|
10
19
|
</template>
|
|
11
20
|
|
|
12
|
-
<script>
|
|
13
|
-
// Need to be declared in module scope, see https://stackoverflow.com/a/70947352
|
|
14
|
-
const badgeColors = ['neutral', 'blue', 'green', 'red', 'orange', 'purple', 'teal', 'pink', 'yellow']
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
21
|
<script setup>
|
|
18
|
-
import { computed
|
|
22
|
+
import { computed } from 'vue'
|
|
23
|
+
|
|
24
|
+
import { Colors } from '@/constants'
|
|
25
|
+
|
|
26
|
+
import { Sizes } from '@/utils/constants'
|
|
19
27
|
|
|
20
28
|
import { capitalizeFirstLetter } from '@/helpers'
|
|
21
29
|
|
|
22
30
|
const props = defineProps({
|
|
23
31
|
color: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: Colors.GRAY,
|
|
34
|
+
validator: (value) => Object.values(Colors).includes(value),
|
|
35
|
+
},
|
|
36
|
+
size: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: false,
|
|
39
|
+
default: Sizes.MD,
|
|
40
|
+
validator(value) {
|
|
41
|
+
return Object.values(Sizes).includes(value)
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
label: {
|
|
24
45
|
type: String,
|
|
25
46
|
default: '',
|
|
26
|
-
validator: (value) => badgeColors.includes(value) || value === '',
|
|
27
47
|
},
|
|
28
|
-
|
|
29
|
-
type:
|
|
30
|
-
default:
|
|
48
|
+
leadingIcon: {
|
|
49
|
+
type: String,
|
|
50
|
+
default: '',
|
|
51
|
+
},
|
|
52
|
+
trailingIcon: {
|
|
53
|
+
type: String,
|
|
54
|
+
default: '',
|
|
31
55
|
},
|
|
32
|
-
|
|
56
|
+
isStroked: {
|
|
33
57
|
type: Boolean,
|
|
34
58
|
default: false,
|
|
35
59
|
},
|
|
@@ -37,164 +61,84 @@ const props = defineProps({
|
|
|
37
61
|
type: Boolean,
|
|
38
62
|
default: false,
|
|
39
63
|
},
|
|
40
|
-
icon: {
|
|
41
|
-
type: String,
|
|
42
|
-
default: '',
|
|
43
|
-
},
|
|
44
64
|
})
|
|
45
65
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const hasIconSlot = computed(() => {
|
|
55
|
-
return !!slots.icon
|
|
66
|
+
const componentDynamicClasses = computed(() => {
|
|
67
|
+
return [
|
|
68
|
+
`cpBadge--${props.size}`,
|
|
69
|
+
`cpBadge--is${capitalizeFirstLetter(props.color)}`,
|
|
70
|
+
{ 'cpBadge--isStroked': props.isStroked },
|
|
71
|
+
{ 'cpBadge--isClearable': props.isClearable },
|
|
72
|
+
]
|
|
56
73
|
})
|
|
57
|
-
|
|
58
|
-
const computedClasses = computed(() => {
|
|
59
|
-
const hasIcon = props.icon !== '' || hasIconSlot.value
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
'cpBadge--isSolid': props.isSolid,
|
|
63
|
-
'cpBadge--isPlain': props.isPlain,
|
|
64
|
-
'cpBadge--hasIcon': hasIcon,
|
|
65
|
-
'cpBadge--isClearable': props.isClearable,
|
|
66
|
-
[`cpBadge--is${capitalizedColor.value}`]: capitalizedColor.value,
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const onClear = () => {
|
|
71
|
-
emits('on-clear')
|
|
72
|
-
}
|
|
73
74
|
</script>
|
|
74
75
|
|
|
75
76
|
<style lang="scss">
|
|
76
|
-
@mixin cp-badge-color-
|
|
77
|
-
|
|
78
|
-
border-color: transparent;
|
|
79
|
-
color: $color;
|
|
80
|
-
|
|
81
|
-
.cpBadge__clear:hover,
|
|
82
|
-
.cpBadge__clear:focus-visible {
|
|
83
|
-
background-color: $color;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@mixin cp-badge-color-solid($color) {
|
|
88
|
-
color: colors.$neutral-light;
|
|
89
|
-
background-color: $color;
|
|
90
|
-
border-color: transparent;
|
|
91
|
-
|
|
92
|
-
.cpBadge__clear:hover,
|
|
93
|
-
.cpBadge__clear:focus-visible {
|
|
77
|
+
@mixin cp-badge-themed($className, $color, $bg-color, $outline-color) {
|
|
78
|
+
&--is#{$className} {
|
|
94
79
|
color: $color;
|
|
95
|
-
background-color:
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
@mixin cp-badge-style($color, $className) {
|
|
100
|
-
&--is#{$className}:not(#{&}--isSolid) {
|
|
101
|
-
@include cp-badge-color-default($color);
|
|
102
|
-
}
|
|
80
|
+
background-color: $bg-color;
|
|
81
|
+
outline-color: $outline-color;
|
|
103
82
|
|
|
104
|
-
|
|
105
|
-
|
|
83
|
+
.cpBadge__clear:hover,
|
|
84
|
+
.cpBadge__clear:focus-visible {
|
|
85
|
+
background-color: $color;
|
|
86
|
+
}
|
|
106
87
|
}
|
|
107
88
|
}
|
|
108
89
|
|
|
109
90
|
.cpBadge {
|
|
110
91
|
display: inline-flex;
|
|
92
|
+
padding: sp.$space-sm sp.$space;
|
|
111
93
|
align-items: center;
|
|
112
|
-
|
|
94
|
+
border-radius: fn.px-to-rem(8);
|
|
95
|
+
background-color: colors.$neutral-dark-5;
|
|
113
96
|
font-size: fn.px-to-em(14);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
border: 1px solid colors.$border-color;
|
|
117
|
-
background-color: colors.$neutral-light;
|
|
118
|
-
|
|
119
|
-
@include cp-badge-style(colors.$neutral-dark, 'Neutral');
|
|
120
|
-
@include cp-badge-style(colors.$secondary-color, 'Blue');
|
|
121
|
-
@include cp-badge-style(colors.$green-2, 'Green');
|
|
122
|
-
@include cp-badge-style(colors.$red, 'Red');
|
|
123
|
-
@include cp-badge-style(colors.$orange, 'Orange');
|
|
124
|
-
@include cp-badge-style(colors.$purple, 'Purple');
|
|
125
|
-
@include cp-badge-style(colors.$blue-1, 'Teal');
|
|
126
|
-
@include cp-badge-style(colors.$pink, 'Pink');
|
|
127
|
-
@include cp-badge-style(colors.$yellow, 'Yellow');
|
|
128
|
-
|
|
129
|
-
&--isYellow#{&}--isSolid {
|
|
130
|
-
color: darken(colors.$yellow, 20);
|
|
131
|
-
|
|
132
|
-
&:before {
|
|
133
|
-
background-color: darken(colors.$yellow, 20);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
97
|
+
color: colors.$neutral-dark;
|
|
98
|
+
gap: sp.$space-sm;
|
|
136
99
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
width: fn.px-to-rem(6);
|
|
140
|
-
height: fn.px-to-rem(6);
|
|
141
|
-
margin-right: fn.px-to-rem(6);
|
|
142
|
-
border-radius: 100%;
|
|
143
|
-
flex-shrink: 0;
|
|
144
|
-
background-color: currentColor;
|
|
100
|
+
&--isStroked {
|
|
101
|
+
outline: 1px solid currentColor;
|
|
145
102
|
}
|
|
146
103
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
104
|
+
@include cp-badge-themed('Blue', colors.$blue, colors.$blue-100, colors.$blue-200);
|
|
105
|
+
@include cp-badge-themed('Gray', colors.$astronaut, colors.$gray-5, colors.$gray-4);
|
|
106
|
+
@include cp-badge-themed('Green', colors.$green, colors.$green-100, colors.$green-200);
|
|
107
|
+
@include cp-badge-themed('Orange', colors.$orange, colors.$orange-100, colors.$orange-200);
|
|
108
|
+
@include cp-badge-themed('Pink', colors.$pink, colors.$pink-100, colors.$pink-200);
|
|
109
|
+
@include cp-badge-themed('Purple', colors.$purple, colors.$purple-100, colors.$purple-200);
|
|
110
|
+
@include cp-badge-themed('Red', colors.$red, colors.$red-100, colors.$red-200);
|
|
111
|
+
@include cp-badge-themed('Yellow', colors.$yellow-500, colors.$yellow-100, colors.$yellow-200);
|
|
150
112
|
|
|
151
|
-
&--
|
|
152
|
-
|
|
153
|
-
padding-right: sp.$space-sm;
|
|
154
|
-
}
|
|
113
|
+
&--sm {
|
|
114
|
+
font-size: fn.px-to-em(12);
|
|
155
115
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
min-width: 0;
|
|
116
|
+
.cpBadge__label {
|
|
117
|
+
line-height: fn.px-to-rem(16);
|
|
118
|
+
}
|
|
160
119
|
}
|
|
161
120
|
|
|
162
121
|
&__icon {
|
|
163
|
-
color: currentColor;
|
|
164
122
|
width: fn.px-to-rem(16);
|
|
165
123
|
height: fn.px-to-rem(16);
|
|
124
|
+
aspect-ratio: 1/1;
|
|
125
|
+
}
|
|
166
126
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
&--isClear svg {
|
|
172
|
-
stroke-width: fn.px-to-rem(2);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
> * {
|
|
176
|
-
width: 100%;
|
|
177
|
-
height: 100%;
|
|
178
|
-
}
|
|
127
|
+
&__label {
|
|
128
|
+
line-height: fn.px-to-rem(20);
|
|
179
129
|
}
|
|
180
130
|
|
|
181
131
|
&__clear {
|
|
182
132
|
display: flex;
|
|
183
133
|
align-items: center;
|
|
184
134
|
justify-content: center;
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
border-radius: 100%;
|
|
135
|
+
padding: sp.$space-xs;
|
|
136
|
+
border-radius: 50%;
|
|
188
137
|
color: inherit;
|
|
189
138
|
|
|
190
139
|
&:hover,
|
|
191
140
|
&:focus-visible {
|
|
192
141
|
color: colors.$neutral-light;
|
|
193
|
-
background-color: colors.$neutral-dark;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
&:focus {
|
|
197
|
-
outline: none !important;
|
|
198
142
|
}
|
|
199
143
|
}
|
|
200
144
|
}
|
package/src/components/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { vTooltip } from 'floating-vue'
|
|
|
9
9
|
// COMPONENTS
|
|
10
10
|
// Atomic elements
|
|
11
11
|
import CpBadge from './atomic-elements/CpBadge.vue'
|
|
12
|
-
import CpBadgeNew from './atomic-elements/CpBadgeNew.vue'
|
|
13
12
|
import CpDialog from './atomic-elements/CpDialog.vue'
|
|
14
13
|
import CpDialogWrapper from './atomic-elements/CpDialogWrapper.vue'
|
|
15
14
|
import CpTooltip from './atomic-elements/CpTooltip.vue'
|
|
@@ -74,7 +73,6 @@ import createToaster from '@/plugins/toaster'
|
|
|
74
73
|
const Components = {
|
|
75
74
|
CpToaster,
|
|
76
75
|
CpBadge,
|
|
77
|
-
CpBadgeNew,
|
|
78
76
|
CpHeading,
|
|
79
77
|
CpButton,
|
|
80
78
|
CpDialogWrapper,
|
|
@@ -8,151 +8,141 @@ const meta = {
|
|
|
8
8
|
argTypes: {
|
|
9
9
|
color: {
|
|
10
10
|
control: 'select',
|
|
11
|
-
options: ['
|
|
11
|
+
options: ['gray', 'blue', 'green', 'red', 'orange', 'purple', 'pink', 'yellow'],
|
|
12
12
|
description: 'The color variant of the badge',
|
|
13
13
|
},
|
|
14
|
-
|
|
15
|
-
control: '
|
|
16
|
-
|
|
14
|
+
size: {
|
|
15
|
+
control: 'select',
|
|
16
|
+
options: ['sm', 'md'],
|
|
17
|
+
description: 'The size of the badge',
|
|
17
18
|
},
|
|
18
|
-
|
|
19
|
+
isStroked: {
|
|
19
20
|
control: 'boolean',
|
|
20
|
-
description: 'Whether the badge has a
|
|
21
|
+
description: 'Whether the badge has a stroked border',
|
|
21
22
|
},
|
|
22
|
-
|
|
23
|
-
control: '
|
|
24
|
-
|
|
23
|
+
leadingIcon: {
|
|
24
|
+
control: 'select',
|
|
25
|
+
options: ['check', 'arrow-right', 'arrow-left', 'arrow-up', 'arrow-down'],
|
|
26
|
+
description: 'Type of leading icon (if any)',
|
|
25
27
|
},
|
|
26
|
-
|
|
28
|
+
trailingIcon: {
|
|
27
29
|
control: 'select',
|
|
28
|
-
options: ['
|
|
29
|
-
description: '
|
|
30
|
+
options: ['check', 'arrow-right', 'arrow-left', 'arrow-up', 'arrow-down'],
|
|
31
|
+
description: 'Type of trailing icon (if any)',
|
|
32
|
+
},
|
|
33
|
+
label: {
|
|
34
|
+
control: 'text',
|
|
35
|
+
description: 'The label text',
|
|
30
36
|
},
|
|
31
|
-
onClear: { action: 'cleared' },
|
|
32
37
|
},
|
|
33
38
|
} satisfies Meta<typeof CpBadge>
|
|
34
39
|
|
|
35
40
|
export default meta
|
|
41
|
+
|
|
36
42
|
type Story = StoryObj<typeof meta>
|
|
37
43
|
|
|
38
44
|
export const Default: Story = {
|
|
39
45
|
args: {
|
|
40
|
-
color: '
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
color: 'gray',
|
|
47
|
+
size: 'md',
|
|
48
|
+
isStroked: false,
|
|
49
|
+
leadingIcon: '',
|
|
50
|
+
trailingIcon: '',
|
|
51
|
+
label: 'Badge',
|
|
45
52
|
},
|
|
46
53
|
render: (args) => ({
|
|
47
54
|
components: { CpBadge },
|
|
48
55
|
setup() {
|
|
49
56
|
return { args }
|
|
50
57
|
},
|
|
51
|
-
template: '<CpBadge v-bind="args"
|
|
58
|
+
template: '<CpBadge v-bind="args" />',
|
|
52
59
|
}),
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
export const WithColors: Story = {
|
|
56
|
-
render: (
|
|
63
|
+
render: () => ({
|
|
57
64
|
components: { CpBadge },
|
|
58
|
-
setup() {
|
|
59
|
-
return { args }
|
|
60
|
-
},
|
|
61
65
|
template: `
|
|
62
66
|
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
|
63
|
-
<CpBadge color="
|
|
64
|
-
<CpBadge color="blue"
|
|
65
|
-
<CpBadge color="green"
|
|
66
|
-
<CpBadge color="red"
|
|
67
|
-
<CpBadge color="orange"
|
|
68
|
-
<CpBadge color="purple"
|
|
69
|
-
<CpBadge color="
|
|
70
|
-
<CpBadge color="
|
|
71
|
-
<CpBadge color="yellow">Yellow</CpBadge>
|
|
67
|
+
<CpBadge color="gray" label="Gray" />
|
|
68
|
+
<CpBadge color="blue" label="Blue" />
|
|
69
|
+
<CpBadge color="green" label="Green" />
|
|
70
|
+
<CpBadge color="red" label="Red" />
|
|
71
|
+
<CpBadge color="orange" label="Orange" />
|
|
72
|
+
<CpBadge color="purple" label="Purple" />
|
|
73
|
+
<CpBadge color="pink" label="Pink" />
|
|
74
|
+
<CpBadge color="yellow" label="Yellow" />
|
|
72
75
|
</div>
|
|
73
76
|
`,
|
|
74
77
|
}),
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
export const
|
|
78
|
-
render: (
|
|
80
|
+
export const WithSizes: Story = {
|
|
81
|
+
render: () => ({
|
|
79
82
|
components: { CpBadge },
|
|
80
|
-
setup() {
|
|
81
|
-
return { args }
|
|
82
|
-
},
|
|
83
83
|
template: `
|
|
84
|
-
<div style="display: flex; gap: 8px;
|
|
85
|
-
<CpBadge
|
|
86
|
-
<CpBadge
|
|
87
|
-
<CpBadge color="green" is-solid>Green</CpBadge>
|
|
88
|
-
<CpBadge color="red" is-solid>Red</CpBadge>
|
|
89
|
-
<CpBadge color="orange" is-solid>Orange</CpBadge>
|
|
90
|
-
<CpBadge color="purple" is-solid>Purple</CpBadge>
|
|
91
|
-
<CpBadge color="teal" is-solid>Teal</CpBadge>
|
|
92
|
-
<CpBadge color="pink" is-solid>Pink</CpBadge>
|
|
93
|
-
<CpBadge color="yellow" is-solid>Yellow</CpBadge>
|
|
84
|
+
<div style="display: flex; gap: 8px; align-items: center;">
|
|
85
|
+
<CpBadge size="sm" label="Small" />
|
|
86
|
+
<CpBadge size="md" label="Medium" />
|
|
94
87
|
</div>
|
|
95
88
|
`,
|
|
96
89
|
}),
|
|
97
90
|
}
|
|
98
91
|
|
|
99
|
-
export const
|
|
100
|
-
|
|
101
|
-
color: 'blue',
|
|
102
|
-
icon: 'check',
|
|
103
|
-
},
|
|
104
|
-
render: (args) => ({
|
|
92
|
+
export const IsStroked: Story = {
|
|
93
|
+
render: () => ({
|
|
105
94
|
components: { CpBadge },
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
template: `
|
|
96
|
+
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
|
97
|
+
<CpBadge color="blue" isStroked label="Stroked" />
|
|
98
|
+
<CpBadge color="green" isStroked label="Stroked" />
|
|
99
|
+
<CpBadge color="red" isStroked label="Stroked" />
|
|
100
|
+
</div>
|
|
101
|
+
`,
|
|
110
102
|
}),
|
|
111
103
|
}
|
|
112
104
|
|
|
113
|
-
export const
|
|
114
|
-
|
|
115
|
-
color: 'blue',
|
|
116
|
-
isClearable: true,
|
|
117
|
-
},
|
|
118
|
-
render: (args) => ({
|
|
105
|
+
export const WithIcons: Story = {
|
|
106
|
+
render: () => ({
|
|
119
107
|
components: { CpBadge },
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
template: `
|
|
109
|
+
<div style="display: flex; gap: 8px; align-items: center;">
|
|
110
|
+
<CpBadge color="blue" leading-icon="check" label="Leading Icon" />
|
|
111
|
+
<CpBadge color="green" trailing-icon="arrow-right" label="Trailing Icon" />
|
|
112
|
+
<CpBadge color="red" leading-icon="check" trailing-icon="arrow-right" label="Both Icons" />
|
|
113
|
+
</div>
|
|
114
|
+
`,
|
|
124
115
|
}),
|
|
125
116
|
}
|
|
126
117
|
|
|
127
|
-
export const
|
|
128
|
-
|
|
129
|
-
color: 'green',
|
|
130
|
-
isPlain: true,
|
|
131
|
-
},
|
|
132
|
-
render: (args) => ({
|
|
118
|
+
export const IsClearable: Story = {
|
|
119
|
+
render: () => ({
|
|
133
120
|
components: { CpBadge },
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
121
|
+
template: `
|
|
122
|
+
<div style="display: flex; gap: 8px; align-items: center;">
|
|
123
|
+
<CpBadge color="blue" isClearable label="Clearable" />
|
|
124
|
+
<CpBadge color="green" isClearable label="Clearable" />
|
|
125
|
+
<CpBadge color="red" isClearable label="Clearable" />
|
|
126
|
+
</div>
|
|
127
|
+
`,
|
|
138
128
|
}),
|
|
139
129
|
}
|
|
140
130
|
|
|
141
|
-
export const
|
|
142
|
-
render: (
|
|
131
|
+
export const WithSlot: Story = {
|
|
132
|
+
render: () => ({
|
|
143
133
|
components: { CpBadge },
|
|
144
|
-
setup() {
|
|
145
|
-
return { args }
|
|
146
|
-
},
|
|
147
134
|
template: `
|
|
148
|
-
<
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
<
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
135
|
+
<CpBadge color="purple">
|
|
136
|
+
<template #leading-icon>
|
|
137
|
+
<span style="font-size: 16px; margin-right: 4px;">🌟</span>
|
|
138
|
+
</template>
|
|
139
|
+
<div>
|
|
140
|
+
Custom div inside default slot
|
|
141
|
+
</div>
|
|
142
|
+
<template #trailing-icon>
|
|
143
|
+
<span style="font-size: 16px; margin-left: 4px;">🚀</span>
|
|
144
|
+
</template>
|
|
145
|
+
</CpBadge>
|
|
156
146
|
`,
|
|
157
147
|
}),
|
|
158
148
|
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="cpBadgeNew" :class="componentDynamicClasses">
|
|
3
|
-
<slot name="leading-icon">
|
|
4
|
-
<cp-icon v-if="leadingIcon" :type="leadingIcon" class="cpBadgeNew__icon" />
|
|
5
|
-
</slot>
|
|
6
|
-
|
|
7
|
-
<span class="cpBadgeNew__label">
|
|
8
|
-
<slot>{{ label }}</slot>
|
|
9
|
-
</span>
|
|
10
|
-
|
|
11
|
-
<slot v-if="!isClearable" name="trailing-icon">
|
|
12
|
-
<cp-icon v-if="trailingIcon" :type="trailingIcon" class="cpBadgeNew__icon" />
|
|
13
|
-
</slot>
|
|
14
|
-
|
|
15
|
-
<button v-if="isClearable" class="cpBadgeNew__clear" @click="onClear">
|
|
16
|
-
<cp-icon type="x" class="cpBadgeNew__icon" />
|
|
17
|
-
</button>
|
|
18
|
-
</div>
|
|
19
|
-
</template>
|
|
20
|
-
|
|
21
|
-
<script setup>
|
|
22
|
-
import { computed } from 'vue'
|
|
23
|
-
|
|
24
|
-
import { Colors } from '@/constants'
|
|
25
|
-
|
|
26
|
-
import { Sizes } from '@/utils/constants'
|
|
27
|
-
|
|
28
|
-
import { capitalizeFirstLetter } from '@/helpers'
|
|
29
|
-
|
|
30
|
-
const props = defineProps({
|
|
31
|
-
color: {
|
|
32
|
-
type: String,
|
|
33
|
-
default: Colors.GRAY,
|
|
34
|
-
validator: (value) => Object.values(Colors).includes(value),
|
|
35
|
-
},
|
|
36
|
-
size: {
|
|
37
|
-
type: String,
|
|
38
|
-
required: false,
|
|
39
|
-
default: Sizes.MD,
|
|
40
|
-
validator(value) {
|
|
41
|
-
return Object.values(Sizes).includes(value)
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
label: {
|
|
45
|
-
type: String,
|
|
46
|
-
default: '',
|
|
47
|
-
},
|
|
48
|
-
leadingIcon: {
|
|
49
|
-
type: String,
|
|
50
|
-
default: '',
|
|
51
|
-
},
|
|
52
|
-
trailingIcon: {
|
|
53
|
-
type: String,
|
|
54
|
-
default: '',
|
|
55
|
-
},
|
|
56
|
-
isStroked: {
|
|
57
|
-
type: Boolean,
|
|
58
|
-
default: false,
|
|
59
|
-
},
|
|
60
|
-
isClearable: {
|
|
61
|
-
type: Boolean,
|
|
62
|
-
default: false,
|
|
63
|
-
},
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const componentDynamicClasses = computed(() => {
|
|
67
|
-
return [
|
|
68
|
-
`cpBadgeNew--${props.size}`,
|
|
69
|
-
`cpBadgeNew--is${capitalizeFirstLetter(props.color)}`,
|
|
70
|
-
{ 'cpBadgeNew--isStroked': props.isStroked },
|
|
71
|
-
{ 'cpBadgeNew--isClearable': props.isClearable },
|
|
72
|
-
]
|
|
73
|
-
})
|
|
74
|
-
</script>
|
|
75
|
-
|
|
76
|
-
<style lang="scss">
|
|
77
|
-
@mixin cp-badge-new-themed($className, $color, $bg-color, $outline-color) {
|
|
78
|
-
&--is#{$className} {
|
|
79
|
-
color: $color;
|
|
80
|
-
background-color: $bg-color;
|
|
81
|
-
outline-color: $outline-color;
|
|
82
|
-
|
|
83
|
-
.cpBadgeNew__clear:hover,
|
|
84
|
-
.cpBadgeNew__clear:focus-visible {
|
|
85
|
-
background-color: $color;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.cpBadgeNew {
|
|
91
|
-
display: inline-flex;
|
|
92
|
-
padding: sp.$space-sm sp.$space;
|
|
93
|
-
align-items: center;
|
|
94
|
-
border-radius: fn.px-to-rem(8);
|
|
95
|
-
background-color: colors.$neutral-dark-5;
|
|
96
|
-
font-size: fn.px-to-em(14);
|
|
97
|
-
color: colors.$neutral-dark;
|
|
98
|
-
gap: sp.$space-sm;
|
|
99
|
-
|
|
100
|
-
&--isStroked {
|
|
101
|
-
outline: 1px solid currentColor;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
@include cp-badge-new-themed('Blue', colors.$blue, colors.$blue-100, colors.$blue-200);
|
|
105
|
-
@include cp-badge-new-themed('Gray', colors.$astronaut, colors.$gray-5, colors.$gray-4);
|
|
106
|
-
@include cp-badge-new-themed('Green', colors.$green, colors.$green-100, colors.$green-200);
|
|
107
|
-
@include cp-badge-new-themed('Orange', colors.$orange, colors.$orange-100, colors.$orange-200);
|
|
108
|
-
@include cp-badge-new-themed('Pink', colors.$pink, colors.$pink-100, colors.$pink-200);
|
|
109
|
-
@include cp-badge-new-themed('Purple', colors.$purple, colors.$purple-100, colors.$purple-200);
|
|
110
|
-
@include cp-badge-new-themed('Red', colors.$red, colors.$red-100, colors.$red-200);
|
|
111
|
-
@include cp-badge-new-themed('Yellow', colors.$yellow-500, colors.$yellow-100, colors.$yellow-200);
|
|
112
|
-
|
|
113
|
-
&--sm {
|
|
114
|
-
font-size: fn.px-to-em(12);
|
|
115
|
-
|
|
116
|
-
.cpBadgeNew__label {
|
|
117
|
-
line-height: fn.px-to-rem(16);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
&__icon {
|
|
122
|
-
width: fn.px-to-rem(16);
|
|
123
|
-
height: fn.px-to-rem(16);
|
|
124
|
-
aspect-ratio: 1/1;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
&__label {
|
|
128
|
-
line-height: fn.px-to-rem(20);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
&__clear {
|
|
132
|
-
display: flex;
|
|
133
|
-
align-items: center;
|
|
134
|
-
justify-content: center;
|
|
135
|
-
padding: sp.$space-xs;
|
|
136
|
-
border-radius: 50%;
|
|
137
|
-
color: inherit;
|
|
138
|
-
|
|
139
|
-
&:hover,
|
|
140
|
-
&:focus-visible {
|
|
141
|
-
color: colors.$neutral-light;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
</style>
|