mtrl 0.3.1 → 0.3.2
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/.env +15 -0
- package/CONTRIBUTING.md +8 -8
- package/DOCS.md +3 -3
- package/README.md +43 -20
- package/TESTING.md +128 -18
- package/dist/index.js +14865 -0
- package/git-user-stats.js +545 -0
- package/index.ts +9 -67
- package/package.json +8 -3
- package/src/components/badge/api.ts +15 -1
- package/src/components/badge/badge.ts +43 -4
- package/src/components/badge/config.ts +40 -8
- package/src/components/badge/index.ts +64 -3
- package/src/components/badge/types.ts +175 -33
- package/src/components/button/api.ts +63 -1
- package/src/components/button/button.ts +39 -3
- package/src/components/button/config.ts +21 -4
- package/src/components/button/index.ts +26 -1
- package/src/components/button/types.ts +7 -1
- package/src/components/card/api.ts +78 -9
- package/src/components/card/card.ts +58 -3
- package/src/components/card/config.ts +41 -11
- package/src/components/card/features.ts +39 -12
- package/src/components/card/index.ts +84 -19
- package/src/components/card/types.ts +218 -29
- package/src/components/carousel/carousel.ts +92 -28
- package/src/components/carousel/constants.ts +107 -21
- package/src/components/carousel/index.ts +31 -13
- package/src/components/checkbox/checkbox.ts +83 -16
- package/src/components/checkbox/index.ts +43 -1
- package/src/components/checkbox/types.ts +219 -32
- package/src/components/chips/api.ts +194 -0
- package/src/components/{chip → chips/chip}/api.ts +42 -2
- package/src/components/chips/chip/chip.ts +131 -0
- package/src/components/{chip → chips/chip}/config.ts +3 -3
- package/src/components/chips/chip/index.ts +3 -0
- package/src/components/chips/chips.md +481 -0
- package/src/components/chips/chips.ts +75 -0
- package/src/components/chips/config.ts +109 -0
- package/src/components/chips/constants.ts +61 -0
- package/src/components/chips/features/chip-items.ts +33 -0
- package/src/components/chips/features/container.ts +77 -0
- package/src/components/chips/features/controller.ts +448 -0
- package/src/components/chips/features/index.ts +5 -0
- package/src/components/chips/features/label.ts +108 -0
- package/src/components/chips/index.ts +11 -0
- package/src/components/chips/schema.ts +61 -0
- package/src/components/{chip → chips}/types.ts +203 -92
- package/src/components/dialog/dialog.ts +99 -16
- package/src/components/dialog/index.ts +97 -1
- package/src/components/dialog/types.ts +375 -69
- package/src/components/divider/config.ts +90 -6
- package/src/components/divider/divider.ts +32 -2
- package/src/components/divider/features.ts +26 -0
- package/src/components/divider/index.ts +30 -0
- package/src/components/divider/types.ts +86 -9
- package/src/components/extended-fab/api.ts +53 -1
- package/src/components/extended-fab/config.ts +29 -1
- package/src/components/extended-fab/extended-fab.ts +28 -0
- package/src/components/extended-fab/index.ts +36 -0
- package/src/components/extended-fab/types.ts +458 -13
- package/src/components/fab/api.ts +42 -2
- package/src/components/fab/config.ts +29 -1
- package/src/components/fab/fab.ts +16 -2
- package/src/components/fab/index.ts +35 -0
- package/src/components/fab/types.ts +374 -10
- package/src/components/list/api.ts +12 -2
- package/src/components/list/config.ts +21 -0
- package/src/components/list/features.ts +6 -0
- package/src/components/list/index.ts +56 -1
- package/src/components/list/list-item.ts +46 -2
- package/src/components/list/list.ts +73 -2
- package/src/components/list/types.ts +172 -0
- package/src/components/list/utils.ts +26 -2
- package/src/components/menu/api.ts +217 -20
- package/src/components/menu/config.ts +27 -0
- package/src/components/menu/features/visibility.ts +55 -6
- package/src/components/menu/index.ts +64 -0
- package/src/components/menu/menu-item.ts +46 -3
- package/src/components/menu/menu.ts +77 -1
- package/src/components/menu/types.ts +404 -39
- package/src/components/sheet/config.ts +1 -2
- package/src/components/sheet/features/gestures.ts +1 -1
- package/src/components/sheet/features/position.ts +1 -2
- package/src/components/sheet/features/state.ts +1 -1
- package/src/components/sheet/index.ts +10 -2
- package/src/components/sheet/sheet.ts +1 -2
- package/src/components/sheet/types.ts +29 -1
- package/src/components/slider/api.ts +1 -1
- package/src/components/slider/config.ts +1 -1
- package/src/components/slider/features/controller.ts +1 -1
- package/src/components/slider/features/handlers.ts +1 -1
- package/src/components/slider/features/states.ts +1 -1
- package/src/components/slider/index.ts +12 -5
- package/src/components/slider/schema.ts +1 -1
- package/src/components/slider/types.ts +31 -0
- package/src/components/tabs/tab-api.ts +1 -1
- package/src/components/tabs/types.ts +1 -1
- package/src/components/tooltip/api.ts +6 -2
- package/src/components/tooltip/config.ts +9 -28
- package/src/components/tooltip/index.ts +10 -1
- package/src/components/tooltip/types.ts +38 -3
- package/src/index.ts +129 -31
- package/src/styles/abstract/_mixins.scss +23 -9
- package/src/styles/abstract/_variables.scss +14 -4
- package/src/styles/components/_card.scss +1 -1
- package/src/styles/components/_chip.scss +323 -113
- package/src/styles/components/_tabs.scss +1 -1
- package/CLAUDE.md +0 -33
- package/src/components/checkbox/constants.ts +0 -37
- package/src/components/chip/chip-set.ts +0 -225
- package/src/components/chip/chip.ts +0 -118
- package/src/components/chip/constants.ts +0 -28
- package/src/components/chip/index.ts +0 -12
- package/src/components/list/constants.ts +0 -116
- package/src/components/sheet/constants.ts +0 -20
- package/src/components/slider/constants.ts +0 -32
- package/src/components/tooltip/constants.ts +0 -27
- package/test/components/badge.test.ts +0 -545
- package/test/components/bottom-app-bar.test.ts +0 -303
- package/test/components/button.test.ts +0 -233
- package/test/components/card.test.ts +0 -560
- package/test/components/carousel.test.ts +0 -951
- package/test/components/checkbox.test.ts +0 -462
- package/test/components/chip.test.ts +0 -692
- package/test/components/datepicker.test.ts +0 -1124
- package/test/components/dialog.test.ts +0 -990
- package/test/components/divider.test.ts +0 -412
- package/test/components/extended-fab.test.ts +0 -672
- package/test/components/fab.test.ts +0 -561
- package/test/components/list.test.ts +0 -365
- package/test/components/menu.test.ts +0 -718
- package/test/components/navigation.test.ts +0 -186
- package/test/components/progress.test.ts +0 -567
- package/test/components/radios.test.ts +0 -699
- package/test/components/search.test.ts +0 -1135
- package/test/components/segmented-button.test.ts +0 -732
- package/test/components/sheet.test.ts +0 -641
- package/test/components/slider.test.ts +0 -1220
- package/test/components/snackbar.test.ts +0 -461
- package/test/components/switch.test.ts +0 -452
- package/test/components/tabs.test.ts +0 -1369
- package/test/components/textfield.test.ts +0 -400
- package/test/components/timepicker.test.ts +0 -592
- package/test/components/tooltip.test.ts +0 -630
- package/test/components/top-app-bar.test.ts +0 -566
- package/test/core/dom.attributes.test.ts +0 -148
- package/test/core/dom.classes.test.ts +0 -152
- package/test/core/dom.events.test.ts +0 -243
- package/test/core/emitter.test.ts +0 -141
- package/test/core/ripple.test.ts +0 -99
- package/test/core/state.store.test.ts +0 -189
- package/test/core/utils.normalize.test.ts +0 -61
- package/test/core/utils.object.test.ts +0 -120
- package/test/setup.js +0 -371
- package/test/setup.ts +0 -451
- package/tsconfig.json +0 -22
- package/typedoc.json +0 -28
- package/typedoc.simple.json +0 -14
|
@@ -18,24 +18,63 @@ import { BadgeConfig, BadgeComponent } from './types';
|
|
|
18
18
|
import { createBaseConfig, getElementConfig, getApiConfig } from './config';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
* Creates a new Badge component
|
|
21
|
+
* Creates a new Badge component following Material Design 3 guidelines.
|
|
22
|
+
*
|
|
23
|
+
* The Badge component displays a small circle or numerical indicator to
|
|
24
|
+
* draw attention to items requiring user attention, like notifications
|
|
25
|
+
* or counts. Badges can be attached to any element.
|
|
26
|
+
*
|
|
22
27
|
* @param {BadgeConfig} config - Badge configuration object
|
|
23
|
-
* @returns {BadgeComponent} Badge component instance
|
|
28
|
+
* @returns {BadgeComponent} Badge component instance with methods for
|
|
29
|
+
* managing the badge appearance, content, and visibility
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} Throws an error if badge creation fails
|
|
32
|
+
*
|
|
33
|
+
* @category Components
|
|
24
34
|
*
|
|
25
35
|
* @example
|
|
26
|
-
* // Create a small dot badge
|
|
36
|
+
* // Create a small dot badge (notification indicator)
|
|
27
37
|
* const notificationBadge = createBadge({
|
|
28
38
|
* variant: 'small',
|
|
39
|
+
* color: 'error',
|
|
29
40
|
* target: document.querySelector('.icon-button')
|
|
30
41
|
* });
|
|
31
42
|
*
|
|
32
43
|
* @example
|
|
33
|
-
* // Create a large badge with a count
|
|
44
|
+
* // Create a large badge with a count (numbered indicator)
|
|
34
45
|
* const countBadge = createBadge({
|
|
35
46
|
* variant: 'large',
|
|
36
47
|
* label: 5,
|
|
48
|
+
* color: 'primary',
|
|
37
49
|
* target: document.querySelector('.notification-icon')
|
|
38
50
|
* });
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Create a badge with a maximum value
|
|
54
|
+
* const messagesBadge = createBadge({
|
|
55
|
+
* variant: 'large',
|
|
56
|
+
* label: 1250,
|
|
57
|
+
* max: 999, // Will display "999+"
|
|
58
|
+
* color: 'info',
|
|
59
|
+
* position: 'bottom-right'
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Control badge visibility programmatically
|
|
64
|
+
* const toggleBadge = createBadge({
|
|
65
|
+
* variant: 'small',
|
|
66
|
+
* color: 'success',
|
|
67
|
+
* target: document.querySelector('.toggle-button')
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // Toggle badge visibility
|
|
71
|
+
* function toggleNotification() {
|
|
72
|
+
* if (toggleBadge.isVisible()) {
|
|
73
|
+
* toggleBadge.hide();
|
|
74
|
+
* } else {
|
|
75
|
+
* toggleBadge.show();
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
39
78
|
*/
|
|
40
79
|
const createBadge = (config: BadgeConfig = {}): BadgeComponent => {
|
|
41
80
|
const baseConfig = createBaseConfig(config);
|
|
@@ -7,43 +7,62 @@ import { BadgeConfig } from './types';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Maximum character count for badge labels
|
|
10
|
+
* @category Components
|
|
11
|
+
* @internal
|
|
10
12
|
*/
|
|
11
13
|
export const BADGE_MAX_CHARACTERS = 4;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* Default configuration for the Badge component
|
|
17
|
+
* These values will be used when not explicitly specified by the user.
|
|
18
|
+
*
|
|
19
|
+
* @category Components
|
|
15
20
|
*/
|
|
16
21
|
export const defaultConfig: BadgeConfig = {
|
|
22
|
+
/** Default to large badge (with text capability) */
|
|
17
23
|
variant: 'large',
|
|
24
|
+
/** Default to error (red) color */
|
|
18
25
|
color: 'error',
|
|
26
|
+
/** Default to top-right corner positioning */
|
|
19
27
|
position: 'top-right',
|
|
28
|
+
/** Default to empty label */
|
|
20
29
|
label: '',
|
|
30
|
+
/** Default to visible */
|
|
21
31
|
visible: true
|
|
22
32
|
};
|
|
23
33
|
|
|
24
34
|
/**
|
|
25
|
-
* Creates the base configuration for Badge component
|
|
35
|
+
* Creates the base configuration for Badge component by merging user-provided
|
|
36
|
+
* config with default values.
|
|
37
|
+
*
|
|
26
38
|
* @param {BadgeConfig} config - User provided configuration
|
|
27
39
|
* @returns {BadgeConfig} Complete configuration with defaults applied
|
|
40
|
+
* @category Components
|
|
41
|
+
* @internal
|
|
28
42
|
*/
|
|
29
43
|
export const createBaseConfig = (config: BadgeConfig = {}): BadgeConfig =>
|
|
30
44
|
createComponentConfig(defaultConfig, config, 'badge') as BadgeConfig;
|
|
31
45
|
|
|
32
46
|
/**
|
|
33
|
-
* Generates element configuration for the Badge component
|
|
47
|
+
* Generates element configuration for the Badge component.
|
|
48
|
+
* This function creates the necessary attributes and configuration
|
|
49
|
+
* for the DOM element creation process.
|
|
50
|
+
*
|
|
34
51
|
* @param {BadgeConfig} config - Badge configuration
|
|
35
52
|
* @returns {Object} Element configuration object for withElement
|
|
53
|
+
* @category Components
|
|
54
|
+
* @internal
|
|
36
55
|
*/
|
|
37
56
|
export const getElementConfig = (config: BadgeConfig) => {
|
|
38
57
|
// Create the attributes object
|
|
39
58
|
const attrs: Record<string, any> = {};
|
|
40
59
|
|
|
41
|
-
// For large badges, set appropriate ARIA attributes
|
|
60
|
+
// For large badges, set appropriate ARIA attributes for screen readers
|
|
42
61
|
if (config.variant !== 'small') {
|
|
43
62
|
attrs.role = 'status';
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
// Format the label if needed
|
|
65
|
+
// Format the label if needed - small badges have no text
|
|
47
66
|
const formattedLabel = config.variant === 'small'
|
|
48
67
|
? ''
|
|
49
68
|
: formatBadgeLabel(config.label || '', config.max);
|
|
@@ -57,9 +76,14 @@ export const getElementConfig = (config: BadgeConfig) => {
|
|
|
57
76
|
};
|
|
58
77
|
|
|
59
78
|
/**
|
|
60
|
-
* Creates API configuration for the Badge component
|
|
79
|
+
* Creates API configuration for the Badge component.
|
|
80
|
+
* This connects the core component features (like visibility)
|
|
81
|
+
* to the public API methods exposed to users.
|
|
82
|
+
*
|
|
61
83
|
* @param {Object} comp - Component with visibility and lifecycle features
|
|
62
84
|
* @returns {Object} API configuration object
|
|
85
|
+
* @category Components
|
|
86
|
+
* @internal
|
|
63
87
|
*/
|
|
64
88
|
export const getApiConfig = (comp) => ({
|
|
65
89
|
visibility: {
|
|
@@ -74,13 +98,21 @@ export const getApiConfig = (comp) => ({
|
|
|
74
98
|
});
|
|
75
99
|
|
|
76
100
|
/**
|
|
77
|
-
* Format a label
|
|
101
|
+
* Format a badge label following Material Design 3 guidelines:
|
|
78
102
|
* - Max 4 characters including "+" for overflow
|
|
79
103
|
* - Add "+" for numeric values exceeding max
|
|
80
104
|
*
|
|
81
105
|
* @param {string|number} label - Original label
|
|
82
106
|
* @param {number} max - Maximum value before using "+"
|
|
83
|
-
* @returns {string} Formatted label
|
|
107
|
+
* @returns {string} Formatted label that fits within badge constraints
|
|
108
|
+
* @category Components
|
|
109
|
+
* @internal
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* formatBadgeLabel(5) // "5"
|
|
113
|
+
* formatBadgeLabel(1250, 999) // "999+"
|
|
114
|
+
* formatBadgeLabel("New") // "New"
|
|
115
|
+
* formatBadgeLabel("VeryLong") // "Very" (truncated)
|
|
84
116
|
*/
|
|
85
117
|
export const formatBadgeLabel = (label: string | number, max?: number): string => {
|
|
86
118
|
// Handle empty or undefined labels
|
|
@@ -92,7 +124,7 @@ export const formatBadgeLabel = (label: string | number, max?: number): string =
|
|
|
92
124
|
|
|
93
125
|
const numericLabel = Number(label);
|
|
94
126
|
|
|
95
|
-
// Apply max value formatting
|
|
127
|
+
// Apply max value formatting for numbers
|
|
96
128
|
if (max !== undefined && !isNaN(numericLabel) && numericLabel > max) {
|
|
97
129
|
formattedLabel = `${max}+`;
|
|
98
130
|
}
|
|
@@ -1,29 +1,90 @@
|
|
|
1
1
|
// src/components/badge/index.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Badge component module
|
|
5
|
+
* @module components/badge
|
|
6
|
+
* @description A small element that communicates status, shows a count,
|
|
7
|
+
* or highlights an element requiring attention.
|
|
8
|
+
*/
|
|
9
|
+
|
|
2
10
|
export { default } from './badge';
|
|
3
|
-
export { BadgeConfig, BadgeComponent, BadgeVariant, BadgeColor, BadgePosition } from './types';
|
|
11
|
+
export type { BadgeConfig, BadgeComponent, BadgeVariant, BadgeColor, BadgePosition } from './types';
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Badge size variant constants
|
|
15
|
+
* Use these instead of string literals for better code completion and type safety.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import { createBadge, BADGE_VARIANTS } from 'mtrl';
|
|
19
|
+
*
|
|
20
|
+
* const badge = createBadge({ variant: BADGE_VARIANTS.SMALL });
|
|
21
|
+
*
|
|
22
|
+
* @category Components
|
|
23
|
+
*/
|
|
6
24
|
export const BADGE_VARIANTS = {
|
|
25
|
+
/** 6dp dot badge (no text content) */
|
|
7
26
|
SMALL: 'small',
|
|
27
|
+
/** 16dp height badge (can contain text) */
|
|
8
28
|
LARGE: 'large'
|
|
9
29
|
} as const;
|
|
10
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Badge color constants
|
|
33
|
+
* Colors follow Material Design 3 color system.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import { createBadge, BADGE_COLORS } from 'mtrl';
|
|
37
|
+
*
|
|
38
|
+
* const badge = createBadge({ color: BADGE_COLORS.ERROR });
|
|
39
|
+
*
|
|
40
|
+
* @category Components
|
|
41
|
+
*/
|
|
11
42
|
export const BADGE_COLORS = {
|
|
43
|
+
/** Red color for error states */
|
|
12
44
|
ERROR: 'error',
|
|
45
|
+
/** Primary theme color */
|
|
13
46
|
PRIMARY: 'primary',
|
|
47
|
+
/** Secondary theme color */
|
|
14
48
|
SECONDARY: 'secondary',
|
|
49
|
+
/** Tertiary theme color */
|
|
15
50
|
TERTIARY: 'tertiary',
|
|
51
|
+
/** Green color for success states */
|
|
16
52
|
SUCCESS: 'success',
|
|
53
|
+
/** Orange/yellow color for warning states */
|
|
17
54
|
WARNING: 'warning',
|
|
55
|
+
/** Blue color for information states */
|
|
18
56
|
INFO: 'info'
|
|
19
57
|
} as const;
|
|
20
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Badge position constants
|
|
61
|
+
* Defines where the badge appears relative to its target element.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* import { createBadge, BADGE_POSITIONS } from 'mtrl';
|
|
65
|
+
*
|
|
66
|
+
* const badge = createBadge({
|
|
67
|
+
* position: BADGE_POSITIONS.BOTTOM_RIGHT,
|
|
68
|
+
* target: document.querySelector('#notification-bell')
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* @category Components
|
|
72
|
+
*/
|
|
21
73
|
export const BADGE_POSITIONS = {
|
|
74
|
+
/** Position in the top-right corner (default) */
|
|
22
75
|
TOP_RIGHT: 'top-right',
|
|
76
|
+
/** Position in the top-left corner */
|
|
23
77
|
TOP_LEFT: 'top-left',
|
|
78
|
+
/** Position in the bottom-right corner */
|
|
24
79
|
BOTTOM_RIGHT: 'bottom-right',
|
|
80
|
+
/** Position in the bottom-left corner */
|
|
25
81
|
BOTTOM_LEFT: 'bottom-left'
|
|
26
82
|
} as const;
|
|
27
83
|
|
|
28
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Maximum number of characters to display in a badge
|
|
86
|
+
* When label text exceeds this length, it will be truncated.
|
|
87
|
+
*
|
|
88
|
+
* @category Components
|
|
89
|
+
*/
|
|
29
90
|
export const BADGE_MAX_CHARACTERS = 4;
|
|
@@ -1,137 +1,279 @@
|
|
|
1
1
|
// src/components/badge/types.ts
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Badge variant types
|
|
4
|
+
* Badge variant types - determines the badge size and appearance
|
|
5
5
|
* @category Components
|
|
6
|
+
* @remarks
|
|
7
|
+
* - small: A 6dp circular dot badge without text (for notification indicators)
|
|
8
|
+
* - large: A 16dp height badge that can contain text (for counts or short labels)
|
|
6
9
|
*/
|
|
7
10
|
export type BadgeVariant = 'small' | 'large';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
|
-
* Badge color types
|
|
13
|
+
* Badge color types - determines the badge's background color
|
|
11
14
|
* @category Components
|
|
15
|
+
* @remarks
|
|
16
|
+
* Based on Material Design 3 color system:
|
|
17
|
+
* - error: Red color for error states (default)
|
|
18
|
+
* - primary: Primary theme color
|
|
19
|
+
* - secondary: Secondary theme color
|
|
20
|
+
* - tertiary: Tertiary theme color
|
|
21
|
+
* - success: Green color for success states
|
|
22
|
+
* - warning: Orange/yellow color for warning states
|
|
23
|
+
* - info: Blue color for information states
|
|
12
24
|
*/
|
|
13
25
|
export type BadgeColor = 'error' | 'primary' | 'secondary' | 'tertiary' | 'success' | 'warning' | 'info';
|
|
14
26
|
|
|
15
27
|
/**
|
|
16
|
-
* Badge position types
|
|
28
|
+
* Badge position types - determines where the badge appears relative to its target
|
|
17
29
|
* @category Components
|
|
30
|
+
* @remarks
|
|
31
|
+
* - top-right: Position in the top-right corner (default)
|
|
32
|
+
* - top-left: Position in the top-left corner
|
|
33
|
+
* - bottom-right: Position in the bottom-right corner
|
|
34
|
+
* - bottom-left: Position in the bottom-left corner
|
|
18
35
|
*/
|
|
19
36
|
export type BadgePosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
20
37
|
|
|
21
38
|
/**
|
|
22
39
|
* Configuration interface for the Badge component
|
|
23
|
-
*
|
|
40
|
+
* @category Components
|
|
41
|
+
* @description
|
|
42
|
+
* Defines the appearance and behavior of a badge component.
|
|
43
|
+
* All properties are optional with sensible defaults.
|
|
24
44
|
*/
|
|
25
45
|
export interface BadgeConfig {
|
|
26
46
|
/**
|
|
27
47
|
* Badge variant (small dot or large numbered)
|
|
28
48
|
* Small badge (6dp) or Large badge (16dp height)
|
|
29
49
|
* @default 'large'
|
|
50
|
+
* @example 'small' | 'large'
|
|
30
51
|
*/
|
|
31
52
|
variant?: BadgeVariant | string;
|
|
32
53
|
|
|
33
54
|
/**
|
|
34
|
-
* Badge color (
|
|
55
|
+
* Badge color (follows Material Design 3 color system)
|
|
35
56
|
* @default 'error'
|
|
57
|
+
* @example 'error' | 'primary' | 'secondary' | 'tertiary' | 'success' | 'warning' | 'info'
|
|
36
58
|
*/
|
|
37
59
|
color?: BadgeColor | string;
|
|
38
60
|
|
|
39
61
|
/**
|
|
40
|
-
* Badge position relative to its container
|
|
62
|
+
* Badge position relative to its container element
|
|
41
63
|
* @default 'top-right'
|
|
64
|
+
* @example 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
|
|
42
65
|
*/
|
|
43
66
|
position?: BadgePosition | string;
|
|
44
67
|
|
|
45
68
|
/**
|
|
46
69
|
* Text label inside the badge (for large badges)
|
|
47
|
-
* Up to 4 characters,
|
|
70
|
+
* Up to 4 characters, numbers exceeding max will show "{max}+"
|
|
71
|
+
* @example "3" | "99+" | "New"
|
|
48
72
|
*/
|
|
49
73
|
label?: string | number;
|
|
50
74
|
|
|
51
75
|
/**
|
|
52
76
|
* Maximum value to display (shows "{max}+" if label exceeds max)
|
|
53
77
|
* Usually 999+ for large numbers
|
|
78
|
+
* @example 99 | 999
|
|
54
79
|
*/
|
|
55
80
|
max?: number;
|
|
56
81
|
|
|
57
|
-
/**
|
|
82
|
+
/**
|
|
83
|
+
* Whether the badge should be initially visible
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
58
86
|
visible?: boolean;
|
|
59
87
|
|
|
60
|
-
/**
|
|
88
|
+
/**
|
|
89
|
+
* Target element to which badge will be attached
|
|
90
|
+
* When provided, the badge will be positioned relative to this element
|
|
91
|
+
*/
|
|
61
92
|
target?: HTMLElement;
|
|
62
93
|
|
|
63
|
-
/**
|
|
94
|
+
/**
|
|
95
|
+
* Additional CSS classes to apply to the badge element
|
|
96
|
+
* @example "custom-badge highlighted-badge"
|
|
97
|
+
*/
|
|
64
98
|
class?: string;
|
|
65
99
|
|
|
66
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* CSS class prefix for all badge classes
|
|
102
|
+
* @default "mtrl"
|
|
103
|
+
*/
|
|
67
104
|
prefix?: string;
|
|
68
105
|
|
|
69
|
-
/**
|
|
106
|
+
/**
|
|
107
|
+
* Component name used in CSS class generation
|
|
108
|
+
* @default "badge"
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
70
111
|
componentName?: string;
|
|
71
112
|
}
|
|
72
113
|
|
|
73
114
|
/**
|
|
74
115
|
* Badge component interface
|
|
75
|
-
*
|
|
116
|
+
* Provides methods for controlling a Material Design 3 badge
|
|
117
|
+
*
|
|
118
|
+
* @category Components
|
|
76
119
|
*/
|
|
77
120
|
export interface BadgeComponent {
|
|
78
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* The badge's root DOM element
|
|
123
|
+
*/
|
|
79
124
|
element: HTMLElement;
|
|
80
125
|
|
|
81
|
-
/**
|
|
126
|
+
/**
|
|
127
|
+
* Badge wrapper element (if badge is attached to target)
|
|
128
|
+
* This is the parent element that contains both the target and the badge
|
|
129
|
+
*/
|
|
82
130
|
wrapper?: HTMLElement;
|
|
83
131
|
|
|
84
|
-
/**
|
|
132
|
+
/**
|
|
133
|
+
* Sets the badge's text label
|
|
134
|
+
* @param label - Text or number to display in the badge
|
|
135
|
+
* @returns Badge component for method chaining
|
|
136
|
+
* @example
|
|
137
|
+
* badge.setLabel(5); // Shows "5"
|
|
138
|
+
* badge.setLabel("New"); // Shows "New"
|
|
139
|
+
* badge.setLabel(1250); // With max=999, shows "999+"
|
|
140
|
+
*/
|
|
85
141
|
setLabel: (label: string | number) => BadgeComponent;
|
|
86
142
|
|
|
87
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Gets the badge's current text label
|
|
145
|
+
* @returns Current text content of the badge
|
|
146
|
+
*/
|
|
88
147
|
getLabel: () => string;
|
|
89
148
|
|
|
90
|
-
/**
|
|
149
|
+
/**
|
|
150
|
+
* Shows the badge (makes it visible)
|
|
151
|
+
* @returns Badge component for method chaining
|
|
152
|
+
*/
|
|
91
153
|
show: () => BadgeComponent;
|
|
92
154
|
|
|
93
|
-
/**
|
|
155
|
+
/**
|
|
156
|
+
* Hides the badge (makes it invisible)
|
|
157
|
+
* @returns Badge component for method chaining
|
|
158
|
+
*/
|
|
94
159
|
hide: () => BadgeComponent;
|
|
95
160
|
|
|
96
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Toggles badge visibility
|
|
163
|
+
* @param visible - Optional explicit visibility state
|
|
164
|
+
* @returns Badge component for method chaining
|
|
165
|
+
* @example
|
|
166
|
+
* badge.toggle(); // Toggles current state
|
|
167
|
+
* badge.toggle(true); // Forces visible
|
|
168
|
+
*/
|
|
97
169
|
toggle: (visible?: boolean) => BadgeComponent;
|
|
98
170
|
|
|
99
|
-
/**
|
|
171
|
+
/**
|
|
172
|
+
* Checks if the badge is currently visible
|
|
173
|
+
* @returns True if badge is visible, false otherwise
|
|
174
|
+
*/
|
|
100
175
|
isVisible: () => boolean;
|
|
101
176
|
|
|
102
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Sets maximum value (after which badge shows max+)
|
|
179
|
+
* @param max - Maximum number to display before showing "+"
|
|
180
|
+
* @returns Badge component for method chaining
|
|
181
|
+
* @example
|
|
182
|
+
* badge.setMax(99); // Shows "99+" for values > 99
|
|
183
|
+
*/
|
|
103
184
|
setMax: (max: number) => BadgeComponent;
|
|
104
185
|
|
|
105
|
-
/**
|
|
186
|
+
/**
|
|
187
|
+
* Sets badge color
|
|
188
|
+
* @param color - Badge color from Material Design 3 palette
|
|
189
|
+
* @returns Badge component for method chaining
|
|
190
|
+
* @example
|
|
191
|
+
* badge.setColor('primary');
|
|
192
|
+
* badge.setColor(BADGE_COLORS.SUCCESS);
|
|
193
|
+
*/
|
|
106
194
|
setColor: (color: BadgeColor | string) => BadgeComponent;
|
|
107
195
|
|
|
108
|
-
/**
|
|
196
|
+
/**
|
|
197
|
+
* Sets badge variant (size style)
|
|
198
|
+
* @param variant - Badge variant ('small' or 'large')
|
|
199
|
+
* @returns Badge component for method chaining
|
|
200
|
+
* @example
|
|
201
|
+
* badge.setVariant('small'); // Dot indicator
|
|
202
|
+
* badge.setVariant(BADGE_VARIANTS.LARGE); // Numbered indicator
|
|
203
|
+
*/
|
|
109
204
|
setVariant: (variant: BadgeVariant | string) => BadgeComponent;
|
|
110
205
|
|
|
111
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* Sets badge position relative to target
|
|
208
|
+
* @param position - Badge position
|
|
209
|
+
* @returns Badge component for method chaining
|
|
210
|
+
* @example
|
|
211
|
+
* badge.setPosition('bottom-left');
|
|
212
|
+
*/
|
|
112
213
|
setPosition: (position: BadgePosition | string) => BadgeComponent;
|
|
113
214
|
|
|
114
|
-
/**
|
|
215
|
+
/**
|
|
216
|
+
* Attaches badge to a target element
|
|
217
|
+
* @param target - Element to attach badge to
|
|
218
|
+
* @returns Badge component for method chaining
|
|
219
|
+
* @example
|
|
220
|
+
* badge.attachTo(document.querySelector('#notification-bell'));
|
|
221
|
+
*/
|
|
115
222
|
attachTo: (target: HTMLElement) => BadgeComponent;
|
|
116
223
|
|
|
117
|
-
/**
|
|
224
|
+
/**
|
|
225
|
+
* Makes badge standalone (removes from wrapper)
|
|
226
|
+
* @returns Badge component for method chaining
|
|
227
|
+
*/
|
|
118
228
|
detach: () => BadgeComponent;
|
|
119
229
|
|
|
120
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* Destroys the badge component and cleans up resources
|
|
232
|
+
* Removes the badge from the DOM and clears event listeners
|
|
233
|
+
*/
|
|
121
234
|
destroy: () => void;
|
|
122
235
|
|
|
123
|
-
/**
|
|
236
|
+
/**
|
|
237
|
+
* Gets a class name with the component's prefix
|
|
238
|
+
* @param name - Base class name
|
|
239
|
+
* @returns Prefixed class name
|
|
240
|
+
* @internal
|
|
241
|
+
*/
|
|
124
242
|
getClass: (name: string) => string;
|
|
125
243
|
|
|
126
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* Adds CSS classes to the badge element
|
|
246
|
+
* @param classes - One or more class names to add
|
|
247
|
+
* @returns Badge component for method chaining
|
|
248
|
+
* @example
|
|
249
|
+
* badge.addClass('highlighted', 'animated');
|
|
250
|
+
*/
|
|
127
251
|
addClass: (...classes: string[]) => BadgeComponent;
|
|
128
252
|
|
|
129
|
-
/**
|
|
253
|
+
/**
|
|
254
|
+
* Removes CSS classes from the badge element
|
|
255
|
+
* @param classes - One or more class names to remove
|
|
256
|
+
* @returns Badge component for method chaining
|
|
257
|
+
* @example
|
|
258
|
+
* badge.removeClass('highlighted', 'animated');
|
|
259
|
+
*/
|
|
130
260
|
removeClass: (...classes: string[]) => BadgeComponent;
|
|
131
261
|
|
|
132
|
-
/**
|
|
262
|
+
/**
|
|
263
|
+
* Adds an event listener to the badge
|
|
264
|
+
* @param event - Event name ('click', 'mouseover', etc.)
|
|
265
|
+
* @param handler - Event handler function
|
|
266
|
+
* @returns Badge component for method chaining
|
|
267
|
+
* @example
|
|
268
|
+
* badge.on('click', () => console.log('Badge clicked'));
|
|
269
|
+
*/
|
|
133
270
|
on: (event: string, handler: Function) => BadgeComponent;
|
|
134
271
|
|
|
135
|
-
/**
|
|
272
|
+
/**
|
|
273
|
+
* Removes an event listener from the badge
|
|
274
|
+
* @param event - Event name
|
|
275
|
+
* @param handler - Event handler function
|
|
276
|
+
* @returns Badge component for method chaining
|
|
277
|
+
*/
|
|
136
278
|
off: (event: string, handler: Function) => BadgeComponent;
|
|
137
279
|
}
|