@nuralyui/badge 0.0.4 → 0.0.5

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.
Files changed (2) hide show
  1. package/bundle.js +267 -2
  2. package/package.json +1 -1
package/bundle.js CHANGED
@@ -3,9 +3,274 @@ import{css as r,LitElement as o,html as a,nothing as t}from"lit";import{property
3
3
  * @license
4
4
  * Copyright 2023 Nuraly, Laabidi Aymen
5
5
  * SPDX-License-Identifier: MIT
6
- */const s=r`:host{display:inline-block;position:relative;font-family:var(--nuraly-font-family);font-size:var(--nuraly-badge-text-font-size,12px);line-height:1;vertical-align:middle}.badge-wrapper{position:relative;display:inline-block}.badge-indicator{position:absolute;top:0;right:0;transform:translate(50%,-50%);transform-origin:100% 0;z-index:var(--nuraly-badge-indicator-z-index,auto);display:inline-flex;align-items:center;justify-content:center;min-width:var(--nuraly-badge-indicator-height,20px);height:var(--nuraly-badge-indicator-height,20px);padding:0 6px;font-size:var(--nuraly-badge-text-font-size,12px);font-weight:var(--nuraly-badge-text-font-weight,normal);line-height:var(--nuraly-badge-indicator-height,20px);white-space:nowrap;text-align:center;background-color:var(--nuraly-color-error,#ff4d4f);color:#fff;border-radius:10px;box-shadow:0 0 0 1px var(--nuraly-color-background,#fff);transition:all var(--nuraly-transition-fast,.15s) ease}.badge-indicator.small{min-width:var(--nuraly-badge-indicator-height-sm,14px);height:var(--nuraly-badge-indicator-height-sm,14px);padding:0 4px;font-size:var(--nuraly-badge-text-font-size-sm,12px);line-height:var(--nuraly-badge-indicator-height-sm,14px);border-radius:7px}.badge-indicator.dot{min-width:var(--nuraly-badge-dot-size,6px);width:var(--nuraly-badge-dot-size,6px);height:var(--nuraly-badge-dot-size,6px);padding:0;border-radius:50%}.badge-standalone{position:relative;display:inline-block;transform:none}.badge-status{display:inline-flex;align-items:center;gap:var(--nuraly-spacing-2,.5rem)}.badge-status-dot{width:var(--nuraly-badge-status-size,6px);height:var(--nuraly-badge-status-size,6px);border-radius:50%;display:inline-block}.badge-status-text{color:var(--nuraly-color-text);font-size:var(--nuraly-font-size-base,14px)}.badge-status-dot.success{background-color:var(--nuraly-color-success,#52c41a)}.badge-status-dot.processing{background-color:var(--nuraly-color-primary,#1890ff);position:relative}.badge-status-dot.processing::after{content:'';position:absolute;top:-1px;left:-1px;width:100%;height:100%;border:1px solid var(--nuraly-color-primary,#1890ff);border-radius:50%;animation:badge-processing 1.2s infinite ease-in-out}@keyframes badge-processing{0%{transform:scale(.8);opacity:.5}100%{transform:scale(2.4);opacity:0}}.badge-status-dot.default{background-color:var(--nuraly-color-text-secondary,#8c8c8c)}.badge-status-dot.error{background-color:var(--nuraly-color-error,#ff4d4f)}.badge-status-dot.warning{background-color:var(--nuraly-color-warning,#faad14)}.badge-indicator.pink{background-color:#eb2f96}.badge-indicator.red{background-color:#f5222d}.badge-indicator.yellow{background-color:#fadb14;color:rgba(0,0,0,.85)}.badge-indicator.orange{background-color:#fa8c16}.badge-indicator.cyan{background-color:#13c2c2}.badge-indicator.green{background-color:#52c41a}.badge-indicator.blue{background-color:#1890ff}.badge-indicator.purple{background-color:#722ed1}.badge-indicator.geekblue{background-color:#2f54eb}.badge-indicator.magenta{background-color:#eb2f96}.badge-indicator.volcano{background-color:#fa541c}.badge-indicator.gold{background-color:#faad14;color:rgba(0,0,0,.85)}.badge-indicator.lime{background-color:#a0d911;color:rgba(0,0,0,.85)}.badge-ribbon-wrapper{position:relative}.badge-ribbon{position:absolute;top:var(--nuraly-spacing-2,.5rem);height:22px;padding:0 var(--nuraly-spacing-2,.5rem);color:#fff;line-height:22px;white-space:nowrap;background-color:var(--nuraly-color-primary,#1890ff);border-radius:2px}.badge-ribbon.start{left:calc(-1 * var(--nuraly-spacing-1,.25rem));padding-left:var(--nuraly-spacing-2,.5rem)}.badge-ribbon.end{right:calc(-1 * var(--nuraly-spacing-1,.25rem));padding-right:var(--nuraly-spacing-2,.5rem)}.badge-ribbon::after{content:'';position:absolute;top:100%;width:0;height:0;border:4px solid transparent}.badge-ribbon.start::after{left:0;border-top-color:currentColor;border-left-color:currentColor;filter:brightness(.7)}.badge-ribbon.end::after{right:0;border-top-color:currentColor;border-right-color:currentColor;filter:brightness(.7)}.badge-ribbon.pink{background-color:#eb2f96;color:#fff}.badge-ribbon.red{background-color:#f5222d;color:#fff}.badge-ribbon.yellow{background-color:#fadb14;color:rgba(0,0,0,.85)}.badge-ribbon.orange{background-color:#fa8c16;color:#fff}.badge-ribbon.cyan{background-color:#13c2c2;color:#fff}.badge-ribbon.green{background-color:#52c41a;color:#fff}.badge-ribbon.blue{background-color:#1890ff;color:#fff}.badge-ribbon.purple{background-color:#722ed1;color:#fff}.badge-ribbon.geekblue{background-color:#2f54eb;color:#fff}.badge-ribbon.magenta{background-color:#eb2f96;color:#fff}.badge-ribbon.volcano{background-color:#fa541c;color:#fff}.badge-ribbon.gold{background-color:#faad14;color:rgba(0,0,0,.85)}.badge-ribbon.lime{background-color:#a0d911;color:rgba(0,0,0,.85)}.badge-hidden{display:none}:host([dir=rtl]) .badge-indicator{right:auto;left:0;transform:translate(-50%,-50%);transform-origin:0 0}:host([dir=rtl]) .badge-ribbon.start{left:auto;right:calc(-1 * var(--nuraly-spacing-1,.25rem))}:host([dir=rtl]) .badge-ribbon.end{right:auto;left:calc(-1 * var(--nuraly-spacing-1,.25rem))}`
6
+ */const s=r`
7
+ :host {
8
+ display: inline-block;
9
+ position: relative;
10
+ font-family: var(--nuraly-font-family);
11
+ font-size: var(--nuraly-badge-text-font-size, 12px);
12
+ line-height: 1;
13
+ vertical-align: middle;
14
+ }
15
+
16
+ /* Badge wrapper for positioning */
17
+ .badge-wrapper {
18
+ position: relative;
19
+ display: inline-block;
20
+ }
21
+
22
+ /* Main badge indicator (count or dot) */
23
+ .badge-indicator {
24
+ position: absolute;
25
+ top: 0;
26
+ right: 0;
27
+ transform: translate(50%, -50%);
28
+ transform-origin: 100% 0%;
29
+ z-index: var(--nuraly-badge-indicator-z-index, auto);
30
+ display: inline-flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ min-width: var(--nuraly-badge-indicator-height, 20px);
34
+ height: var(--nuraly-badge-indicator-height, 20px);
35
+ padding: 0 6px;
36
+ font-size: var(--nuraly-badge-text-font-size, 12px);
37
+ font-weight: var(--nuraly-badge-text-font-weight, normal);
38
+ line-height: var(--nuraly-badge-indicator-height, 20px);
39
+ white-space: nowrap;
40
+ text-align: center;
41
+ background-color: var(--nuraly-color-error, #ff4d4f);
42
+ color: #fff;
43
+ border-radius: 10px;
44
+ box-shadow: 0 0 0 1px var(--nuraly-color-background, #fff);
45
+ transition: all var(--nuraly-transition-fast, 0.15s) ease;
46
+ }
47
+
48
+ /* Small size badge */
49
+ .badge-indicator.small {
50
+ min-width: var(--nuraly-badge-indicator-height-sm, 14px);
51
+ height: var(--nuraly-badge-indicator-height-sm, 14px);
52
+ padding: 0 4px;
53
+ font-size: var(--nuraly-badge-text-font-size-sm, 12px);
54
+ line-height: var(--nuraly-badge-indicator-height-sm, 14px);
55
+ border-radius: 7px;
56
+ }
57
+
58
+ /* Dot badge (small indicator without count) */
59
+ .badge-indicator.dot {
60
+ min-width: var(--nuraly-badge-dot-size, 6px);
61
+ width: var(--nuraly-badge-dot-size, 6px);
62
+ height: var(--nuraly-badge-dot-size, 6px);
63
+ padding: 0;
64
+ border-radius: 50%;
65
+ }
66
+
67
+ /* Standalone badge (no children) */
68
+ .badge-standalone {
69
+ position: relative;
70
+ display: inline-block;
71
+ transform: none;
72
+ }
73
+
74
+ /* Status badge styles */
75
+ .badge-status {
76
+ display: inline-flex;
77
+ align-items: center;
78
+ gap: var(--nuraly-spacing-2, 0.5rem);
79
+ }
80
+
81
+ .badge-status-dot {
82
+ width: var(--nuraly-badge-status-size, 6px);
83
+ height: var(--nuraly-badge-status-size, 6px);
84
+ border-radius: 50%;
85
+ display: inline-block;
86
+ }
87
+
88
+ .badge-status-text {
89
+ color: var(--nuraly-color-text);
90
+ font-size: var(--nuraly-font-size-base, 14px);
91
+ }
92
+
93
+ /* Status colors */
94
+ .badge-status-dot.success {
95
+ background-color: var(--nuraly-color-success, #52c41a);
96
+ }
97
+
98
+ .badge-status-dot.processing {
99
+ background-color: var(--nuraly-color-primary, #1890ff);
100
+ position: relative;
101
+ }
102
+
103
+ .badge-status-dot.processing::after {
104
+ content: '';
105
+ position: absolute;
106
+ top: -1px;
107
+ left: -1px;
108
+ width: 100%;
109
+ height: 100%;
110
+ border: 1px solid var(--nuraly-color-primary, #1890ff);
111
+ border-radius: 50%;
112
+ animation: badge-processing 1.2s infinite ease-in-out;
113
+ }
114
+
115
+ @keyframes badge-processing {
116
+ 0% {
117
+ transform: scale(0.8);
118
+ opacity: 0.5;
119
+ }
120
+ 100% {
121
+ transform: scale(2.4);
122
+ opacity: 0;
123
+ }
124
+ }
125
+
126
+ .badge-status-dot.default {
127
+ background-color: var(--nuraly-color-text-secondary, #8c8c8c);
128
+ }
129
+
130
+ .badge-status-dot.error {
131
+ background-color: var(--nuraly-color-error, #ff4d4f);
132
+ }
133
+
134
+ .badge-status-dot.warning {
135
+ background-color: var(--nuraly-color-warning, #faad14);
136
+ }
137
+
138
+ /* Color variants for badge indicator */
139
+ .badge-indicator.pink { background-color: #eb2f96; }
140
+ .badge-indicator.red { background-color: #f5222d; }
141
+ .badge-indicator.yellow { background-color: #fadb14; color: rgba(0, 0, 0, 0.85); }
142
+ .badge-indicator.orange { background-color: #fa8c16; }
143
+ .badge-indicator.cyan { background-color: #13c2c2; }
144
+ .badge-indicator.green { background-color: #52c41a; }
145
+ .badge-indicator.blue { background-color: #1890ff; }
146
+ .badge-indicator.purple { background-color: #722ed1; }
147
+ .badge-indicator.geekblue { background-color: #2f54eb; }
148
+ .badge-indicator.magenta { background-color: #eb2f96; }
149
+ .badge-indicator.volcano { background-color: #fa541c; }
150
+ .badge-indicator.gold { background-color: #faad14; color: rgba(0, 0, 0, 0.85); }
151
+ .badge-indicator.lime { background-color: #a0d911; color: rgba(0, 0, 0, 0.85); }
152
+
153
+ /* Ribbon badge styles */
154
+ .badge-ribbon-wrapper {
155
+ position: relative;
156
+ }
157
+
158
+ .badge-ribbon {
159
+ position: absolute;
160
+ top: var(--nuraly-spacing-2, 0.5rem);
161
+ height: 22px;
162
+ padding: 0 var(--nuraly-spacing-2, 0.5rem);
163
+ color: #fff;
164
+ line-height: 22px;
165
+ white-space: nowrap;
166
+ background-color: var(--nuraly-color-primary, #1890ff);
167
+ border-radius: 2px;
168
+ }
169
+
170
+ .badge-ribbon.start {
171
+ left: calc(-1 * var(--nuraly-spacing-1, 0.25rem));
172
+ padding-left: var(--nuraly-spacing-2, 0.5rem);
173
+ }
174
+
175
+ .badge-ribbon.end {
176
+ right: calc(-1 * var(--nuraly-spacing-1, 0.25rem));
177
+ padding-right: var(--nuraly-spacing-2, 0.5rem);
178
+ }
179
+
180
+ .badge-ribbon::after {
181
+ content: '';
182
+ position: absolute;
183
+ top: 100%;
184
+ width: 0;
185
+ height: 0;
186
+ border: 4px solid transparent;
187
+ }
188
+
189
+ .badge-ribbon.start::after {
190
+ left: 0;
191
+ border-top-color: currentColor;
192
+ border-left-color: currentColor;
193
+ filter: brightness(0.7);
194
+ }
195
+
196
+ .badge-ribbon.end::after {
197
+ right: 0;
198
+ border-top-color: currentColor;
199
+ border-right-color: currentColor;
200
+ filter: brightness(0.7);
201
+ }
202
+
203
+ /* Ribbon color variants */
204
+ .badge-ribbon.pink { background-color: #eb2f96; color: #fff; }
205
+ .badge-ribbon.red { background-color: #f5222d; color: #fff; }
206
+ .badge-ribbon.yellow { background-color: #fadb14; color: rgba(0, 0, 0, 0.85); }
207
+ .badge-ribbon.orange { background-color: #fa8c16; color: #fff; }
208
+ .badge-ribbon.cyan { background-color: #13c2c2; color: #fff; }
209
+ .badge-ribbon.green { background-color: #52c41a; color: #fff; }
210
+ .badge-ribbon.blue { background-color: #1890ff; color: #fff; }
211
+ .badge-ribbon.purple { background-color: #722ed1; color: #fff; }
212
+ .badge-ribbon.geekblue { background-color: #2f54eb; color: #fff; }
213
+ .badge-ribbon.magenta { background-color: #eb2f96; color: #fff; }
214
+ .badge-ribbon.volcano { background-color: #fa541c; color: #fff; }
215
+ .badge-ribbon.gold { background-color: #faad14; color: rgba(0, 0, 0, 0.85); }
216
+ .badge-ribbon.lime { background-color: #a0d911; color: rgba(0, 0, 0, 0.85); }
217
+
218
+ /* Hidden state */
219
+ .badge-hidden {
220
+ display: none;
221
+ }
222
+
223
+ /* RTL Support */
224
+ :host([dir="rtl"]) .badge-indicator {
225
+ right: auto;
226
+ left: 0;
227
+ transform: translate(-50%, -50%);
228
+ transform-origin: 0% 0%;
229
+ }
230
+
231
+ :host([dir="rtl"]) .badge-ribbon.start {
232
+ left: auto;
233
+ right: calc(-1 * var(--nuraly-spacing-1, 0.25rem));
234
+ }
235
+
236
+ :host([dir="rtl"]) .badge-ribbon.end {
237
+ right: auto;
238
+ left: calc(-1 * var(--nuraly-spacing-1, 0.25rem));
239
+ }
240
+ `
7
241
  /**
8
242
  * @license
9
243
  * Copyright 2023 Nuraly, Laabidi Aymen
10
244
  * SPDX-License-Identifier: MIT
11
- */;var c=function(r,o,a,t){for(var e,i=arguments.length,n=i<3?o:null===t?t=Object.getOwnPropertyDescriptor(o,a):t,d=r.length-1;d>=0;d--)(e=r[d])&&(n=(i<3?e(n):i>3?e(o,a,n):e(o,a))||n);return i>3&&n&&Object.defineProperty(o,a,n),n};let b=class extends(l(o)){constructor(){super(...arguments),this.dot=!1,this.overflowCount=99,this.showZero=!1,this.size="default",this.ribbonPlacement="end"}getDisplayCount(){if(void 0===this.count)return"";const r=Number(this.count);return r>this.overflowCount?`${this.overflowCount}+`:String(r)}shouldHideBadge(){return!this.dot&&(void 0===this.count||0===this.count&&!this.showZero)}getCustomColorStyle(){if(!this.color)return{};return!["pink","red","yellow","orange","cyan","green","blue","purple","geekblue","magenta","volcano","gold","lime"].includes(this.color)?{backgroundColor:this.color,color:"#fff"}:{}}getOffsetStyle(){if(!this.offset)return{};const[r,o]=this.offset;return{right:`calc(0px - ${r}px)`,top:`${o}px`}}renderStatusBadge(){return a`<span class="badge-status"><span class="badge-status-dot ${this.status}"></span> ${this.text?a`<span class="badge-status-text">${this.text}</span>`:t}</span>`}renderRibbonBadge(){const r={"badge-ribbon":!0,[this.ribbonPlacement]:!0,[this.color||""]:!!this.color},o=this.getCustomColorStyle();return a`<div class="badge-ribbon-wrapper"><slot></slot><div class="${n(r)}" style="${d(o)}">${this.ribbon}</div></div>`}renderCountBadge(){const r=!(null!==this.querySelector(":not([slot])")),o=this.shouldHideBadge(),e=this.color&&["pink","red","yellow","orange","cyan","green","blue","purple","geekblue","magenta","volcano","gold","lime"].includes(this.color),i=Object.assign({"badge-indicator":!0,"badge-standalone":r,"badge-hidden":o,dot:this.dot,small:"small"===this.size},this.color&&e?{[this.color]:!0}:{}),l=Object.assign(Object.assign({},this.getCustomColorStyle()),this.getOffsetStyle()),s=this.dot?t:this.getDisplayCount();return r?a`<span class="${n(i)}" style="${d(l)}" title="${this.badgeTitle||""}">${s}</span>`:a`<span class="badge-wrapper"><slot></slot><span class="${n(i)}" style="${d(l)}" title="${this.badgeTitle||""}">${s}</span></span>`}render(){return this.ribbon?this.renderRibbonBadge():this.status?this.renderStatusBadge():this.renderCountBadge()}};b.styles=s,c([e({type:Number})],b.prototype,"count",void 0),c([e({type:Boolean})],b.prototype,"dot",void 0),c([e({type:Number,attribute:"overflow-count"})],b.prototype,"overflowCount",void 0),c([e({type:Boolean,attribute:"show-zero"})],b.prototype,"showZero",void 0),c([e({type:Array})],b.prototype,"offset",void 0),c([e({type:String})],b.prototype,"color",void 0),c([e({type:String})],b.prototype,"size",void 0),c([e({type:String})],b.prototype,"status",void 0),c([e({type:String})],b.prototype,"text",void 0),c([e({type:String})],b.prototype,"badgeTitle",void 0),c([e({type:String})],b.prototype,"ribbon",void 0),c([e({type:String,attribute:"ribbon-placement"})],b.prototype,"ribbonPlacement",void 0),b=c([i("nr-badge")],b);export{b as NrBadgeElement};
245
+ */;var b=function(r,o,a,t){for(var e,i=arguments.length,n=i<3?o:null===t?t=Object.getOwnPropertyDescriptor(o,a):t,d=r.length-1;d>=0;d--)(e=r[d])&&(n=(i<3?e(n):i>3?e(o,a,n):e(o,a))||n);return i>3&&n&&Object.defineProperty(o,a,n),n};let c=class extends(l(o)){constructor(){super(...arguments),this.dot=!1,this.overflowCount=99,this.showZero=!1,this.size="default",this.ribbonPlacement="end"}getDisplayCount(){if(void 0===this.count)return"";const r=Number(this.count);return r>this.overflowCount?`${this.overflowCount}+`:String(r)}shouldHideBadge(){return!this.dot&&(void 0===this.count||0===this.count&&!this.showZero)}getCustomColorStyle(){if(!this.color)return{};return!["pink","red","yellow","orange","cyan","green","blue","purple","geekblue","magenta","volcano","gold","lime"].includes(this.color)?{backgroundColor:this.color,color:"#fff"}:{}}getOffsetStyle(){if(!this.offset)return{};const[r,o]=this.offset;return{right:`calc(0px - ${r}px)`,top:`${o}px`}}renderStatusBadge(){return a`
246
+ <span class="badge-status">
247
+ <span class="badge-status-dot ${this.status}"></span>
248
+ ${this.text?a`<span class="badge-status-text">${this.text}</span>`:t}
249
+ </span>
250
+ `}renderRibbonBadge(){const r={"badge-ribbon":!0,[this.ribbonPlacement]:!0,[this.color||""]:!!this.color},o=this.getCustomColorStyle();return a`
251
+ <div class="badge-ribbon-wrapper">
252
+ <slot></slot>
253
+ <div class=${n(r)} style=${d(o)}>
254
+ ${this.ribbon}
255
+ </div>
256
+ </div>
257
+ `}renderCountBadge(){const r=!(null!==this.querySelector(":not([slot])")),o=this.shouldHideBadge(),e=this.color&&["pink","red","yellow","orange","cyan","green","blue","purple","geekblue","magenta","volcano","gold","lime"].includes(this.color),i=Object.assign({"badge-indicator":!0,"badge-standalone":r,"badge-hidden":o,dot:this.dot,small:"small"===this.size},this.color&&e?{[this.color]:!0}:{}),l=Object.assign(Object.assign({},this.getCustomColorStyle()),this.getOffsetStyle()),s=this.dot?t:this.getDisplayCount();return r?a`
258
+ <span
259
+ class=${n(i)}
260
+ style=${d(l)}
261
+ title=${this.badgeTitle||""}
262
+ >
263
+ ${s}
264
+ </span>
265
+ `:a`
266
+ <span class="badge-wrapper">
267
+ <slot></slot>
268
+ <span
269
+ class=${n(i)}
270
+ style=${d(l)}
271
+ title=${this.badgeTitle||""}
272
+ >
273
+ ${s}
274
+ </span>
275
+ </span>
276
+ `}render(){return this.ribbon?this.renderRibbonBadge():this.status?this.renderStatusBadge():this.renderCountBadge()}};c.styles=s,b([e({type:Number})],c.prototype,"count",void 0),b([e({type:Boolean})],c.prototype,"dot",void 0),b([e({type:Number,attribute:"overflow-count"})],c.prototype,"overflowCount",void 0),b([e({type:Boolean,attribute:"show-zero"})],c.prototype,"showZero",void 0),b([e({type:Array})],c.prototype,"offset",void 0),b([e({type:String})],c.prototype,"color",void 0),b([e({type:String})],c.prototype,"size",void 0),b([e({type:String})],c.prototype,"status",void 0),b([e({type:String})],c.prototype,"text",void 0),b([e({type:String})],c.prototype,"badgeTitle",void 0),b([e({type:String})],c.prototype,"ribbon",void 0),b([e({type:String,attribute:"ribbon-placement"})],c.prototype,"ribbonPlacement",void 0),c=b([i("nr-badge")],c);export{c as NrBadgeElement};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuralyui/badge",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Badge component for NuralyUI library",
5
5
  "main": "index.js",
6
6
  "type": "module",