mithril-materialized 3.9.0 → 3.10.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/badge.d.ts +129 -0
- package/dist/components.css +227 -0
- package/dist/index.css +227 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +101 -1
- package/dist/index.js +101 -0
- package/dist/index.min.css +1 -1
- package/dist/index.umd.js +101 -0
- package/package.json +1 -1
- package/sass/components/_badge-component.scss +203 -0
- package/sass/materialize.scss +2 -0
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { FactoryComponent, Attributes } from 'mithril';
|
|
2
|
+
import { MaterialColor, ColorIntensity } from './types';
|
|
3
|
+
/** Badge positioning anchor origin */
|
|
4
|
+
export interface BadgeAnchorOrigin {
|
|
5
|
+
/** Vertical positioning: 'top' | 'bottom' */
|
|
6
|
+
vertical: 'top' | 'bottom';
|
|
7
|
+
/** Horizontal positioning: 'left' | 'right' */
|
|
8
|
+
horizontal: 'left' | 'right';
|
|
9
|
+
}
|
|
10
|
+
/** Badge display variant */
|
|
11
|
+
export type BadgeVariant = 'standard' | 'dot';
|
|
12
|
+
/** Badge overlap mode affecting positioning offset */
|
|
13
|
+
export type BadgeOverlap = 'rectangular' | 'circular';
|
|
14
|
+
/**
|
|
15
|
+
* Badge component attributes
|
|
16
|
+
*
|
|
17
|
+
* Displays a badge anchored to a child element, commonly used for notifications,
|
|
18
|
+
* counts, or status indicators.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* // Standard notification badge
|
|
23
|
+
* m(Badge, { badgeContent: 4 },
|
|
24
|
+
* m('button.btn', 'Notifications')
|
|
25
|
+
* )
|
|
26
|
+
*
|
|
27
|
+
* // Dot variant with custom color
|
|
28
|
+
* m(Badge, {
|
|
29
|
+
* variant: 'dot',
|
|
30
|
+
* color: 'green',
|
|
31
|
+
* anchorOrigin: { vertical: 'bottom', horizontal: 'right' }
|
|
32
|
+
* },
|
|
33
|
+
* m(Icon, { iconName: 'notifications' })
|
|
34
|
+
* )
|
|
35
|
+
*
|
|
36
|
+
* // Badge with max value capping
|
|
37
|
+
* m(Badge, { badgeContent: 150, max: 99 },
|
|
38
|
+
* m('span', 'Inbox')
|
|
39
|
+
* )
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface BadgeAttrs extends Attributes {
|
|
43
|
+
/**
|
|
44
|
+
* Content to display in badge (number or string)
|
|
45
|
+
* For 'dot' variant, this is ignored
|
|
46
|
+
*/
|
|
47
|
+
badgeContent?: string | number;
|
|
48
|
+
/**
|
|
49
|
+
* Maximum value to display - if badgeContent exceeds this, shows "max+"
|
|
50
|
+
* @default undefined (no capping)
|
|
51
|
+
*/
|
|
52
|
+
max?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Badge positioning relative to child element
|
|
55
|
+
* @default { vertical: 'top', horizontal: 'right' }
|
|
56
|
+
*/
|
|
57
|
+
anchorOrigin?: BadgeAnchorOrigin;
|
|
58
|
+
/**
|
|
59
|
+
* Overlap mode affecting positioning offset
|
|
60
|
+
* - 'rectangular': Badge positioned at corner edge
|
|
61
|
+
* - 'circular': Badge overlaps slightly for circular child elements
|
|
62
|
+
* @default 'rectangular'
|
|
63
|
+
*/
|
|
64
|
+
overlap?: BadgeOverlap;
|
|
65
|
+
/**
|
|
66
|
+
* Badge display variant
|
|
67
|
+
* - 'standard': Shows badgeContent
|
|
68
|
+
* - 'dot': Displays minimal dot indicator
|
|
69
|
+
* @default 'standard'
|
|
70
|
+
*/
|
|
71
|
+
variant?: BadgeVariant;
|
|
72
|
+
/**
|
|
73
|
+
* Badge background color from MaterialColor palette
|
|
74
|
+
* @default 'red'
|
|
75
|
+
*/
|
|
76
|
+
color?: MaterialColor;
|
|
77
|
+
/**
|
|
78
|
+
* Color intensity modifier
|
|
79
|
+
* @example 'lighten-2', 'darken-3'
|
|
80
|
+
*/
|
|
81
|
+
colorIntensity?: ColorIntensity;
|
|
82
|
+
/**
|
|
83
|
+
* Force hide badge regardless of badgeContent
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
invisible?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Show badge even when badgeContent is 0
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
showZero?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* ARIA label for accessibility
|
|
94
|
+
* Automatically generated from badgeContent if not provided
|
|
95
|
+
*/
|
|
96
|
+
'aria-label'?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Additional CSS class for badge element (not wrapper)
|
|
99
|
+
*/
|
|
100
|
+
badgeClassName?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Additional CSS class for wrapper element
|
|
103
|
+
*/
|
|
104
|
+
className?: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Badge component
|
|
108
|
+
*
|
|
109
|
+
* Displays a badge anchored to a child element. Commonly used for notifications,
|
|
110
|
+
* counts, or status indicators. Supports flexible positioning, colors, and variants.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* // Basic notification badge
|
|
115
|
+
* m(Badge, { badgeContent: 5 },
|
|
116
|
+
* m('button.btn', 'Messages')
|
|
117
|
+
* )
|
|
118
|
+
*
|
|
119
|
+
* // Dot badge on avatar
|
|
120
|
+
* m(Badge, {
|
|
121
|
+
* variant: 'dot',
|
|
122
|
+
* color: 'green',
|
|
123
|
+
* overlap: 'circular'
|
|
124
|
+
* },
|
|
125
|
+
* m('img.circle', { src: 'avatar.jpg' })
|
|
126
|
+
* )
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare const Badge: FactoryComponent<BadgeAttrs>;
|
package/dist/components.css
CHANGED
|
@@ -4529,3 +4529,230 @@ nav .theme-toggle:focus {
|
|
|
4529
4529
|
display: none;
|
|
4530
4530
|
}
|
|
4531
4531
|
}
|
|
4532
|
+
/* Badge Component
|
|
4533
|
+
========================================================================== */
|
|
4534
|
+
.badge-wrapper {
|
|
4535
|
+
position: relative;
|
|
4536
|
+
display: inline-flex;
|
|
4537
|
+
vertical-align: middle;
|
|
4538
|
+
flex-shrink: 0;
|
|
4539
|
+
}
|
|
4540
|
+
|
|
4541
|
+
.m-badge {
|
|
4542
|
+
position: absolute;
|
|
4543
|
+
display: flex;
|
|
4544
|
+
align-items: center;
|
|
4545
|
+
justify-content: center;
|
|
4546
|
+
box-sizing: border-box;
|
|
4547
|
+
font-family: Roboto, sans-serif;
|
|
4548
|
+
font-weight: 500;
|
|
4549
|
+
line-height: 1;
|
|
4550
|
+
white-space: nowrap;
|
|
4551
|
+
text-align: center;
|
|
4552
|
+
border-radius: 10px;
|
|
4553
|
+
background-color: #F44336;
|
|
4554
|
+
color: #fff;
|
|
4555
|
+
z-index: 1;
|
|
4556
|
+
transition: transform 225ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
4557
|
+
}
|
|
4558
|
+
.m-badge.m-badge--standard {
|
|
4559
|
+
min-width: 20px;
|
|
4560
|
+
height: 20px;
|
|
4561
|
+
padding: 0 6px;
|
|
4562
|
+
font-size: 12px;
|
|
4563
|
+
}
|
|
4564
|
+
.m-badge.m-badge--dot {
|
|
4565
|
+
width: 8px;
|
|
4566
|
+
height: 8px;
|
|
4567
|
+
min-width: 8px;
|
|
4568
|
+
padding: 0;
|
|
4569
|
+
border-radius: 50%;
|
|
4570
|
+
}
|
|
4571
|
+
.m-badge.m-badge--invisible {
|
|
4572
|
+
transform: scale(0);
|
|
4573
|
+
opacity: 0;
|
|
4574
|
+
}
|
|
4575
|
+
.m-badge.m-badge--top-right {
|
|
4576
|
+
top: 0;
|
|
4577
|
+
right: 0;
|
|
4578
|
+
transform: scale(1) translate(50%, -50%);
|
|
4579
|
+
transform-origin: 100% 0%;
|
|
4580
|
+
}
|
|
4581
|
+
.m-badge.m-badge--top-right.m-badge--rectangular {
|
|
4582
|
+
transform: scale(1) translate(50%, -50%);
|
|
4583
|
+
}
|
|
4584
|
+
.m-badge.m-badge--top-right.m-badge--circular {
|
|
4585
|
+
transform: scale(1) translate(30%, -30%);
|
|
4586
|
+
}
|
|
4587
|
+
.m-badge.m-badge--top-right.m-badge--invisible {
|
|
4588
|
+
transform: scale(0) translate(50%, -50%);
|
|
4589
|
+
}
|
|
4590
|
+
.m-badge.m-badge--top-left {
|
|
4591
|
+
top: 0;
|
|
4592
|
+
left: 0;
|
|
4593
|
+
transform: scale(1) translate(-50%, -50%);
|
|
4594
|
+
transform-origin: 0% 0%;
|
|
4595
|
+
}
|
|
4596
|
+
.m-badge.m-badge--top-left.m-badge--rectangular {
|
|
4597
|
+
transform: scale(1) translate(-50%, -50%);
|
|
4598
|
+
}
|
|
4599
|
+
.m-badge.m-badge--top-left.m-badge--circular {
|
|
4600
|
+
transform: scale(1) translate(-30%, -30%);
|
|
4601
|
+
}
|
|
4602
|
+
.m-badge.m-badge--top-left.m-badge--invisible {
|
|
4603
|
+
transform: scale(0) translate(-50%, -50%);
|
|
4604
|
+
}
|
|
4605
|
+
.m-badge.m-badge--bottom-right {
|
|
4606
|
+
bottom: 0;
|
|
4607
|
+
right: 0;
|
|
4608
|
+
transform: scale(1) translate(50%, 50%);
|
|
4609
|
+
transform-origin: 100% 100%;
|
|
4610
|
+
}
|
|
4611
|
+
.m-badge.m-badge--bottom-right.m-badge--rectangular {
|
|
4612
|
+
transform: scale(1) translate(50%, 50%);
|
|
4613
|
+
}
|
|
4614
|
+
.m-badge.m-badge--bottom-right.m-badge--circular {
|
|
4615
|
+
transform: scale(1) translate(30%, 30%);
|
|
4616
|
+
}
|
|
4617
|
+
.m-badge.m-badge--bottom-right.m-badge--invisible {
|
|
4618
|
+
transform: scale(0) translate(50%, 50%);
|
|
4619
|
+
}
|
|
4620
|
+
.m-badge.m-badge--bottom-left {
|
|
4621
|
+
bottom: 0;
|
|
4622
|
+
left: 0;
|
|
4623
|
+
transform: scale(1) translate(-50%, 50%);
|
|
4624
|
+
transform-origin: 0% 100%;
|
|
4625
|
+
}
|
|
4626
|
+
.m-badge.m-badge--bottom-left.m-badge--rectangular {
|
|
4627
|
+
transform: scale(1) translate(-50%, 50%);
|
|
4628
|
+
}
|
|
4629
|
+
.m-badge.m-badge--bottom-left.m-badge--circular {
|
|
4630
|
+
transform: scale(1) translate(-30%, 30%);
|
|
4631
|
+
}
|
|
4632
|
+
.m-badge.m-badge--bottom-left.m-badge--invisible {
|
|
4633
|
+
transform: scale(0) translate(-50%, 50%);
|
|
4634
|
+
}
|
|
4635
|
+
|
|
4636
|
+
.m-badge--red {
|
|
4637
|
+
background-color: #F44336;
|
|
4638
|
+
}
|
|
4639
|
+
|
|
4640
|
+
.m-badge--pink {
|
|
4641
|
+
background-color: #e91e63;
|
|
4642
|
+
}
|
|
4643
|
+
|
|
4644
|
+
.m-badge--purple {
|
|
4645
|
+
background-color: #9c27b0;
|
|
4646
|
+
}
|
|
4647
|
+
|
|
4648
|
+
.m-badge--deep-purple {
|
|
4649
|
+
background-color: #673ab7;
|
|
4650
|
+
}
|
|
4651
|
+
|
|
4652
|
+
.m-badge--indigo {
|
|
4653
|
+
background-color: #3f51b5;
|
|
4654
|
+
}
|
|
4655
|
+
|
|
4656
|
+
.m-badge--blue {
|
|
4657
|
+
background-color: #2196F3;
|
|
4658
|
+
}
|
|
4659
|
+
|
|
4660
|
+
.m-badge--light-blue {
|
|
4661
|
+
background-color: #03a9f4;
|
|
4662
|
+
}
|
|
4663
|
+
|
|
4664
|
+
.m-badge--cyan {
|
|
4665
|
+
background-color: #00bcd4;
|
|
4666
|
+
}
|
|
4667
|
+
|
|
4668
|
+
.m-badge--teal {
|
|
4669
|
+
background-color: #009688;
|
|
4670
|
+
}
|
|
4671
|
+
|
|
4672
|
+
.m-badge--green {
|
|
4673
|
+
background-color: #4CAF50;
|
|
4674
|
+
}
|
|
4675
|
+
|
|
4676
|
+
.m-badge--light-green {
|
|
4677
|
+
background-color: #8bc34a;
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
.m-badge--lime {
|
|
4681
|
+
background-color: #cddc39;
|
|
4682
|
+
}
|
|
4683
|
+
|
|
4684
|
+
.m-badge--yellow {
|
|
4685
|
+
background-color: #ffeb3b;
|
|
4686
|
+
color: #000;
|
|
4687
|
+
}
|
|
4688
|
+
|
|
4689
|
+
.m-badge--amber {
|
|
4690
|
+
background-color: #ffc107;
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4693
|
+
.m-badge--orange {
|
|
4694
|
+
background-color: #ff9800;
|
|
4695
|
+
}
|
|
4696
|
+
|
|
4697
|
+
.m-badge--deep-orange {
|
|
4698
|
+
background-color: #ff5722;
|
|
4699
|
+
}
|
|
4700
|
+
|
|
4701
|
+
.m-badge--brown {
|
|
4702
|
+
background-color: #795548;
|
|
4703
|
+
}
|
|
4704
|
+
|
|
4705
|
+
.m-badge--grey {
|
|
4706
|
+
background-color: #9e9e9e;
|
|
4707
|
+
}
|
|
4708
|
+
|
|
4709
|
+
.m-badge--blue-grey {
|
|
4710
|
+
background-color: #607d8b;
|
|
4711
|
+
}
|
|
4712
|
+
|
|
4713
|
+
.m-badge--lighten-5 {
|
|
4714
|
+
filter: brightness(1.4);
|
|
4715
|
+
}
|
|
4716
|
+
|
|
4717
|
+
.m-badge--lighten-4 {
|
|
4718
|
+
filter: brightness(1.3);
|
|
4719
|
+
}
|
|
4720
|
+
|
|
4721
|
+
.m-badge--lighten-3 {
|
|
4722
|
+
filter: brightness(1.2);
|
|
4723
|
+
}
|
|
4724
|
+
|
|
4725
|
+
.m-badge--lighten-2 {
|
|
4726
|
+
filter: brightness(1.1);
|
|
4727
|
+
}
|
|
4728
|
+
|
|
4729
|
+
.m-badge--lighten-1 {
|
|
4730
|
+
filter: brightness(1.05);
|
|
4731
|
+
}
|
|
4732
|
+
|
|
4733
|
+
.m-badge--darken-1 {
|
|
4734
|
+
filter: brightness(0.95);
|
|
4735
|
+
}
|
|
4736
|
+
|
|
4737
|
+
.m-badge--darken-2 {
|
|
4738
|
+
filter: brightness(0.9);
|
|
4739
|
+
}
|
|
4740
|
+
|
|
4741
|
+
.m-badge--darken-3 {
|
|
4742
|
+
filter: brightness(0.8);
|
|
4743
|
+
}
|
|
4744
|
+
|
|
4745
|
+
.m-badge--darken-4 {
|
|
4746
|
+
filter: brightness(0.7);
|
|
4747
|
+
}
|
|
4748
|
+
|
|
4749
|
+
@media (prefers-reduced-motion: reduce) {
|
|
4750
|
+
.m-badge {
|
|
4751
|
+
transition: none;
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
@media (prefers-contrast: high) {
|
|
4755
|
+
.m-badge {
|
|
4756
|
+
border: 2px solid currentColor;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
package/dist/index.css
CHANGED
|
@@ -12518,4 +12518,231 @@ body.dark {
|
|
|
12518
12518
|
[data-theme=dark] .linear-progress__track {
|
|
12519
12519
|
background-color: rgba(255, 255, 255, 0.3);
|
|
12520
12520
|
}
|
|
12521
|
+
}
|
|
12522
|
+
/* Badge Component
|
|
12523
|
+
========================================================================== */
|
|
12524
|
+
.badge-wrapper {
|
|
12525
|
+
position: relative;
|
|
12526
|
+
display: inline-flex;
|
|
12527
|
+
vertical-align: middle;
|
|
12528
|
+
flex-shrink: 0;
|
|
12529
|
+
}
|
|
12530
|
+
|
|
12531
|
+
.m-badge {
|
|
12532
|
+
position: absolute;
|
|
12533
|
+
display: flex;
|
|
12534
|
+
align-items: center;
|
|
12535
|
+
justify-content: center;
|
|
12536
|
+
box-sizing: border-box;
|
|
12537
|
+
font-family: Roboto, sans-serif;
|
|
12538
|
+
font-weight: 500;
|
|
12539
|
+
line-height: 1;
|
|
12540
|
+
white-space: nowrap;
|
|
12541
|
+
text-align: center;
|
|
12542
|
+
border-radius: 10px;
|
|
12543
|
+
background-color: #F44336;
|
|
12544
|
+
color: #fff;
|
|
12545
|
+
z-index: 1;
|
|
12546
|
+
transition: transform 225ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
12547
|
+
}
|
|
12548
|
+
.m-badge.m-badge--standard {
|
|
12549
|
+
min-width: 20px;
|
|
12550
|
+
height: 20px;
|
|
12551
|
+
padding: 0 6px;
|
|
12552
|
+
font-size: 12px;
|
|
12553
|
+
}
|
|
12554
|
+
.m-badge.m-badge--dot {
|
|
12555
|
+
width: 8px;
|
|
12556
|
+
height: 8px;
|
|
12557
|
+
min-width: 8px;
|
|
12558
|
+
padding: 0;
|
|
12559
|
+
border-radius: 50%;
|
|
12560
|
+
}
|
|
12561
|
+
.m-badge.m-badge--invisible {
|
|
12562
|
+
transform: scale(0);
|
|
12563
|
+
opacity: 0;
|
|
12564
|
+
}
|
|
12565
|
+
.m-badge.m-badge--top-right {
|
|
12566
|
+
top: 0;
|
|
12567
|
+
right: 0;
|
|
12568
|
+
transform: scale(1) translate(50%, -50%);
|
|
12569
|
+
transform-origin: 100% 0%;
|
|
12570
|
+
}
|
|
12571
|
+
.m-badge.m-badge--top-right.m-badge--rectangular {
|
|
12572
|
+
transform: scale(1) translate(50%, -50%);
|
|
12573
|
+
}
|
|
12574
|
+
.m-badge.m-badge--top-right.m-badge--circular {
|
|
12575
|
+
transform: scale(1) translate(30%, -30%);
|
|
12576
|
+
}
|
|
12577
|
+
.m-badge.m-badge--top-right.m-badge--invisible {
|
|
12578
|
+
transform: scale(0) translate(50%, -50%);
|
|
12579
|
+
}
|
|
12580
|
+
.m-badge.m-badge--top-left {
|
|
12581
|
+
top: 0;
|
|
12582
|
+
left: 0;
|
|
12583
|
+
transform: scale(1) translate(-50%, -50%);
|
|
12584
|
+
transform-origin: 0% 0%;
|
|
12585
|
+
}
|
|
12586
|
+
.m-badge.m-badge--top-left.m-badge--rectangular {
|
|
12587
|
+
transform: scale(1) translate(-50%, -50%);
|
|
12588
|
+
}
|
|
12589
|
+
.m-badge.m-badge--top-left.m-badge--circular {
|
|
12590
|
+
transform: scale(1) translate(-30%, -30%);
|
|
12591
|
+
}
|
|
12592
|
+
.m-badge.m-badge--top-left.m-badge--invisible {
|
|
12593
|
+
transform: scale(0) translate(-50%, -50%);
|
|
12594
|
+
}
|
|
12595
|
+
.m-badge.m-badge--bottom-right {
|
|
12596
|
+
bottom: 0;
|
|
12597
|
+
right: 0;
|
|
12598
|
+
transform: scale(1) translate(50%, 50%);
|
|
12599
|
+
transform-origin: 100% 100%;
|
|
12600
|
+
}
|
|
12601
|
+
.m-badge.m-badge--bottom-right.m-badge--rectangular {
|
|
12602
|
+
transform: scale(1) translate(50%, 50%);
|
|
12603
|
+
}
|
|
12604
|
+
.m-badge.m-badge--bottom-right.m-badge--circular {
|
|
12605
|
+
transform: scale(1) translate(30%, 30%);
|
|
12606
|
+
}
|
|
12607
|
+
.m-badge.m-badge--bottom-right.m-badge--invisible {
|
|
12608
|
+
transform: scale(0) translate(50%, 50%);
|
|
12609
|
+
}
|
|
12610
|
+
.m-badge.m-badge--bottom-left {
|
|
12611
|
+
bottom: 0;
|
|
12612
|
+
left: 0;
|
|
12613
|
+
transform: scale(1) translate(-50%, 50%);
|
|
12614
|
+
transform-origin: 0% 100%;
|
|
12615
|
+
}
|
|
12616
|
+
.m-badge.m-badge--bottom-left.m-badge--rectangular {
|
|
12617
|
+
transform: scale(1) translate(-50%, 50%);
|
|
12618
|
+
}
|
|
12619
|
+
.m-badge.m-badge--bottom-left.m-badge--circular {
|
|
12620
|
+
transform: scale(1) translate(-30%, 30%);
|
|
12621
|
+
}
|
|
12622
|
+
.m-badge.m-badge--bottom-left.m-badge--invisible {
|
|
12623
|
+
transform: scale(0) translate(-50%, 50%);
|
|
12624
|
+
}
|
|
12625
|
+
|
|
12626
|
+
.m-badge--red {
|
|
12627
|
+
background-color: #F44336;
|
|
12628
|
+
}
|
|
12629
|
+
|
|
12630
|
+
.m-badge--pink {
|
|
12631
|
+
background-color: #e91e63;
|
|
12632
|
+
}
|
|
12633
|
+
|
|
12634
|
+
.m-badge--purple {
|
|
12635
|
+
background-color: #9c27b0;
|
|
12636
|
+
}
|
|
12637
|
+
|
|
12638
|
+
.m-badge--deep-purple {
|
|
12639
|
+
background-color: #673ab7;
|
|
12640
|
+
}
|
|
12641
|
+
|
|
12642
|
+
.m-badge--indigo {
|
|
12643
|
+
background-color: #3f51b5;
|
|
12644
|
+
}
|
|
12645
|
+
|
|
12646
|
+
.m-badge--blue {
|
|
12647
|
+
background-color: #2196F3;
|
|
12648
|
+
}
|
|
12649
|
+
|
|
12650
|
+
.m-badge--light-blue {
|
|
12651
|
+
background-color: #03a9f4;
|
|
12652
|
+
}
|
|
12653
|
+
|
|
12654
|
+
.m-badge--cyan {
|
|
12655
|
+
background-color: #00bcd4;
|
|
12656
|
+
}
|
|
12657
|
+
|
|
12658
|
+
.m-badge--teal {
|
|
12659
|
+
background-color: #009688;
|
|
12660
|
+
}
|
|
12661
|
+
|
|
12662
|
+
.m-badge--green {
|
|
12663
|
+
background-color: #4CAF50;
|
|
12664
|
+
}
|
|
12665
|
+
|
|
12666
|
+
.m-badge--light-green {
|
|
12667
|
+
background-color: #8bc34a;
|
|
12668
|
+
}
|
|
12669
|
+
|
|
12670
|
+
.m-badge--lime {
|
|
12671
|
+
background-color: #cddc39;
|
|
12672
|
+
}
|
|
12673
|
+
|
|
12674
|
+
.m-badge--yellow {
|
|
12675
|
+
background-color: #ffeb3b;
|
|
12676
|
+
color: #000;
|
|
12677
|
+
}
|
|
12678
|
+
|
|
12679
|
+
.m-badge--amber {
|
|
12680
|
+
background-color: #ffc107;
|
|
12681
|
+
}
|
|
12682
|
+
|
|
12683
|
+
.m-badge--orange {
|
|
12684
|
+
background-color: #ff9800;
|
|
12685
|
+
}
|
|
12686
|
+
|
|
12687
|
+
.m-badge--deep-orange {
|
|
12688
|
+
background-color: #ff5722;
|
|
12689
|
+
}
|
|
12690
|
+
|
|
12691
|
+
.m-badge--brown {
|
|
12692
|
+
background-color: #795548;
|
|
12693
|
+
}
|
|
12694
|
+
|
|
12695
|
+
.m-badge--grey {
|
|
12696
|
+
background-color: #9e9e9e;
|
|
12697
|
+
}
|
|
12698
|
+
|
|
12699
|
+
.m-badge--blue-grey {
|
|
12700
|
+
background-color: #607d8b;
|
|
12701
|
+
}
|
|
12702
|
+
|
|
12703
|
+
.m-badge--lighten-5 {
|
|
12704
|
+
filter: brightness(1.4);
|
|
12705
|
+
}
|
|
12706
|
+
|
|
12707
|
+
.m-badge--lighten-4 {
|
|
12708
|
+
filter: brightness(1.3);
|
|
12709
|
+
}
|
|
12710
|
+
|
|
12711
|
+
.m-badge--lighten-3 {
|
|
12712
|
+
filter: brightness(1.2);
|
|
12713
|
+
}
|
|
12714
|
+
|
|
12715
|
+
.m-badge--lighten-2 {
|
|
12716
|
+
filter: brightness(1.1);
|
|
12717
|
+
}
|
|
12718
|
+
|
|
12719
|
+
.m-badge--lighten-1 {
|
|
12720
|
+
filter: brightness(1.05);
|
|
12721
|
+
}
|
|
12722
|
+
|
|
12723
|
+
.m-badge--darken-1 {
|
|
12724
|
+
filter: brightness(0.95);
|
|
12725
|
+
}
|
|
12726
|
+
|
|
12727
|
+
.m-badge--darken-2 {
|
|
12728
|
+
filter: brightness(0.9);
|
|
12729
|
+
}
|
|
12730
|
+
|
|
12731
|
+
.m-badge--darken-3 {
|
|
12732
|
+
filter: brightness(0.8);
|
|
12733
|
+
}
|
|
12734
|
+
|
|
12735
|
+
.m-badge--darken-4 {
|
|
12736
|
+
filter: brightness(0.7);
|
|
12737
|
+
}
|
|
12738
|
+
|
|
12739
|
+
@media (prefers-reduced-motion: reduce) {
|
|
12740
|
+
.m-badge {
|
|
12741
|
+
transition: none;
|
|
12742
|
+
}
|
|
12743
|
+
}
|
|
12744
|
+
@media (prefers-contrast: high) {
|
|
12745
|
+
.m-badge {
|
|
12746
|
+
border: 2px solid currentColor;
|
|
12747
|
+
}
|
|
12521
12748
|
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -505,6 +505,106 @@ const Autocomplete = () => {
|
|
|
505
505
|
};
|
|
506
506
|
};
|
|
507
507
|
|
|
508
|
+
/**
|
|
509
|
+
* Badge component
|
|
510
|
+
*
|
|
511
|
+
* Displays a badge anchored to a child element. Commonly used for notifications,
|
|
512
|
+
* counts, or status indicators. Supports flexible positioning, colors, and variants.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* // Basic notification badge
|
|
517
|
+
* m(Badge, { badgeContent: 5 },
|
|
518
|
+
* m('button.btn', 'Messages')
|
|
519
|
+
* )
|
|
520
|
+
*
|
|
521
|
+
* // Dot badge on avatar
|
|
522
|
+
* m(Badge, {
|
|
523
|
+
* variant: 'dot',
|
|
524
|
+
* color: 'green',
|
|
525
|
+
* overlap: 'circular'
|
|
526
|
+
* },
|
|
527
|
+
* m('img.circle', { src: 'avatar.jpg' })
|
|
528
|
+
* )
|
|
529
|
+
* ```
|
|
530
|
+
*/
|
|
531
|
+
const Badge = () => {
|
|
532
|
+
return {
|
|
533
|
+
view: ({ attrs, children }) => {
|
|
534
|
+
const { badgeContent, max, anchorOrigin = { vertical: 'top', horizontal: 'right' }, overlap = 'rectangular', variant = 'standard', color = 'red', colorIntensity, invisible = false, showZero = false, 'aria-label': ariaLabel, badgeClassName = '', className = '' } = attrs, params = __rest(attrs, ["badgeContent", "max", "anchorOrigin", "overlap", "variant", "color", "colorIntensity", "invisible", "showZero", 'aria-label', "badgeClassName", "className"]);
|
|
535
|
+
// === VALIDATION: Single child element ===
|
|
536
|
+
const childArray = Array.isArray(children) ? children : children ? [children] : [];
|
|
537
|
+
if (childArray.length === 0) {
|
|
538
|
+
console.warn('Badge component requires a child element');
|
|
539
|
+
return null;
|
|
540
|
+
}
|
|
541
|
+
if (childArray.length > 1) {
|
|
542
|
+
console.warn('Badge component should only wrap a single child element. Using first child only.');
|
|
543
|
+
}
|
|
544
|
+
const child = childArray[0];
|
|
545
|
+
// === VISIBILITY LOGIC ===
|
|
546
|
+
// Hide badge if:
|
|
547
|
+
// 1. invisible prop is true, OR
|
|
548
|
+
// 2. For standard variant: badgeContent is undefined/null OR (badgeContent is 0 AND !showZero)
|
|
549
|
+
const shouldHideBadge = invisible ||
|
|
550
|
+
(variant === 'standard' &&
|
|
551
|
+
(badgeContent === undefined ||
|
|
552
|
+
badgeContent === null ||
|
|
553
|
+
(badgeContent === 0 && !showZero)));
|
|
554
|
+
// === BADGE CONTENT FORMATTING ===
|
|
555
|
+
// Apply max capping: if badgeContent > max, show "max+"
|
|
556
|
+
const getDisplayContent = () => {
|
|
557
|
+
if (variant === 'dot')
|
|
558
|
+
return '';
|
|
559
|
+
if (typeof badgeContent === 'number' && max !== undefined && badgeContent > max) {
|
|
560
|
+
return `${max}+`;
|
|
561
|
+
}
|
|
562
|
+
return String(badgeContent !== null && badgeContent !== void 0 ? badgeContent : '');
|
|
563
|
+
};
|
|
564
|
+
const displayContent = getDisplayContent();
|
|
565
|
+
// === CSS CLASS ASSEMBLY ===
|
|
566
|
+
// Wrapper classes
|
|
567
|
+
const wrapperClasses = ['badge-wrapper', className].filter(Boolean).join(' ').trim() || undefined;
|
|
568
|
+
// Badge element classes - using m-badge prefix to avoid Materialize conflicts
|
|
569
|
+
const positionClass = `m-badge--${anchorOrigin.vertical}-${anchorOrigin.horizontal}`;
|
|
570
|
+
const badgeClasses = [
|
|
571
|
+
'm-badge',
|
|
572
|
+
`m-badge--${variant}`,
|
|
573
|
+
positionClass,
|
|
574
|
+
`m-badge--${overlap}`,
|
|
575
|
+
`m-badge--${color}`,
|
|
576
|
+
colorIntensity ? `m-badge--${colorIntensity}` : '',
|
|
577
|
+
shouldHideBadge ? 'm-badge--invisible' : '',
|
|
578
|
+
badgeClassName,
|
|
579
|
+
]
|
|
580
|
+
.filter(Boolean)
|
|
581
|
+
.join(' ')
|
|
582
|
+
.trim();
|
|
583
|
+
// === ARIA ATTRIBUTES ===
|
|
584
|
+
const badgeAriaLabel = ariaLabel ||
|
|
585
|
+
(variant === 'dot'
|
|
586
|
+
? 'notification indicator'
|
|
587
|
+
: displayContent
|
|
588
|
+
? `${displayContent} notifications`
|
|
589
|
+
: 'notification badge');
|
|
590
|
+
// === RENDER ===
|
|
591
|
+
return m('.badge-wrapper', Object.assign(Object.assign({}, params), { className: wrapperClasses }), [
|
|
592
|
+
// Child element
|
|
593
|
+
child,
|
|
594
|
+
// Badge element - only render if not hidden
|
|
595
|
+
!shouldHideBadge
|
|
596
|
+
? m('span', {
|
|
597
|
+
className: badgeClasses,
|
|
598
|
+
'aria-label': badgeAriaLabel,
|
|
599
|
+
role: 'status',
|
|
600
|
+
'aria-live': 'polite',
|
|
601
|
+
}, variant === 'standard' ? displayContent : null)
|
|
602
|
+
: null,
|
|
603
|
+
]);
|
|
604
|
+
},
|
|
605
|
+
};
|
|
606
|
+
};
|
|
607
|
+
|
|
508
608
|
/**
|
|
509
609
|
* A simple material icon, defined by its icon name.
|
|
510
610
|
*
|
|
@@ -11028,4 +11128,4 @@ const isValidationError = (result) => !isValidationSuccess(result);
|
|
|
11028
11128
|
// ============================================================================
|
|
11029
11129
|
// All types are already exported via individual export declarations above
|
|
11030
11130
|
|
|
11031
|
-
export { AnalogClock, AnchorItem, Autocomplete, Breadcrumb, BreadcrumbManager, Button, ButtonFactory, Carousel, CharacterCounter, Chips, CircularProgress, CodeBlock, Collapsible, CollapsibleItem, Collection, CollectionMode, ColorInput, DataTable, DatePicker, DigitalClock, DoubleRangeSlider, Dropdown, EmailInput, FileInput, FileUpload, FlatButton, FloatingActionButton, HelperText, Icon, IconButton, ImageList, InputCheckbox, Label, LargeButton, LinearProgress, ListItem, Mandatory, Masonry, MaterialBox, MaterialIcon, ModalPanel, NumberInput, Options, OptionsList, Pagination, PaginationControls, Parallax, PasswordInput, Pushpin, PushpinComponent, RadioButton, RadioButtons, RangeInput, Rating, RoundIconButton, SearchSelect, SecondaryContent, Select, Sidenav, SidenavItem, SidenavManager, SingleRangeSlider, SmallButton, Stepper, SubmitButton, Switch, Tabs, TextArea, TextInput, ThemeManager, ThemeSwitcher, ThemeToggle, TimePicker, TimeRangePicker, Timeline, Toast, ToastComponent, ToggleGroup, Tooltip, TooltipComponent, TreeView, UrlInput, Wizard, addLeadingZero, clearPortal, createBreadcrumb, formatTime, generateHourOptions, generateMinuteOptions, getDropdownStyles, getPortalContainer, initPushpins, initTooltips, isNumeric, isTimeDisabled, isValidationError, isValidationSuccess, padLeft, parseTime, range, releasePortalContainer, renderToPortal, scrollToValue, snapToNearestItem, sortOptions, timeToMinutes, toast, uniqueId, uuid4 };
|
|
11131
|
+
export { AnalogClock, AnchorItem, Autocomplete, Badge, Breadcrumb, BreadcrumbManager, Button, ButtonFactory, Carousel, CharacterCounter, Chips, CircularProgress, CodeBlock, Collapsible, CollapsibleItem, Collection, CollectionMode, ColorInput, DataTable, DatePicker, DigitalClock, DoubleRangeSlider, Dropdown, EmailInput, FileInput, FileUpload, FlatButton, FloatingActionButton, HelperText, Icon, IconButton, ImageList, InputCheckbox, Label, LargeButton, LinearProgress, ListItem, Mandatory, Masonry, MaterialBox, MaterialIcon, ModalPanel, NumberInput, Options, OptionsList, Pagination, PaginationControls, Parallax, PasswordInput, Pushpin, PushpinComponent, RadioButton, RadioButtons, RangeInput, Rating, RoundIconButton, SearchSelect, SecondaryContent, Select, Sidenav, SidenavItem, SidenavManager, SingleRangeSlider, SmallButton, Stepper, SubmitButton, Switch, Tabs, TextArea, TextInput, ThemeManager, ThemeSwitcher, ThemeToggle, TimePicker, TimeRangePicker, Timeline, Toast, ToastComponent, ToggleGroup, Tooltip, TooltipComponent, TreeView, UrlInput, Wizard, addLeadingZero, clearPortal, createBreadcrumb, formatTime, generateHourOptions, generateMinuteOptions, getDropdownStyles, getPortalContainer, initPushpins, initTooltips, isNumeric, isTimeDisabled, isValidationError, isValidationSuccess, padLeft, parseTime, range, releasePortalContainer, renderToPortal, scrollToValue, snapToNearestItem, sortOptions, timeToMinutes, toast, uniqueId, uuid4 };
|