mtrl 0.3.1 → 0.3.3

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 (162) hide show
  1. package/.env +15 -0
  2. package/CONTRIBUTING.md +62 -23
  3. package/DOCS.md +3 -3
  4. package/README.md +43 -20
  5. package/TESTING.md +128 -18
  6. package/dist/index.js +14865 -0
  7. package/git-user-stats.js +545 -0
  8. package/index.ts +9 -67
  9. package/package.json +8 -3
  10. package/src/components/badge/api.ts +15 -1
  11. package/src/components/badge/badge.ts +43 -4
  12. package/src/components/badge/config.ts +40 -8
  13. package/src/components/badge/index.ts +64 -3
  14. package/src/components/badge/types.ts +175 -33
  15. package/src/components/button/api.ts +63 -1
  16. package/src/components/button/button.ts +39 -3
  17. package/src/components/button/config.ts +21 -4
  18. package/src/components/button/index.ts +26 -1
  19. package/src/components/button/types.ts +7 -1
  20. package/src/components/card/api.ts +78 -9
  21. package/src/components/card/card.ts +58 -3
  22. package/src/components/card/config.ts +41 -11
  23. package/src/components/card/features.ts +39 -12
  24. package/src/components/card/index.ts +84 -19
  25. package/src/components/card/types.ts +218 -29
  26. package/src/components/carousel/carousel.ts +92 -28
  27. package/src/components/carousel/constants.ts +107 -21
  28. package/src/components/carousel/index.ts +31 -13
  29. package/src/components/checkbox/checkbox.ts +83 -16
  30. package/src/components/checkbox/index.ts +43 -1
  31. package/src/components/checkbox/types.ts +219 -32
  32. package/src/components/chips/api.ts +194 -0
  33. package/src/components/{chip → chips/chip}/api.ts +42 -2
  34. package/src/components/chips/chip/chip.ts +131 -0
  35. package/src/components/{chip → chips/chip}/config.ts +3 -3
  36. package/src/components/chips/chip/index.ts +3 -0
  37. package/src/components/chips/chips.md +481 -0
  38. package/src/components/chips/chips.ts +75 -0
  39. package/src/components/chips/config.ts +109 -0
  40. package/src/components/chips/constants.ts +61 -0
  41. package/src/components/chips/features/chip-items.ts +33 -0
  42. package/src/components/chips/features/container.ts +77 -0
  43. package/src/components/chips/features/controller.ts +448 -0
  44. package/src/components/chips/features/index.ts +5 -0
  45. package/src/components/chips/features/label.ts +108 -0
  46. package/src/components/chips/index.ts +11 -0
  47. package/src/components/chips/schema.ts +61 -0
  48. package/src/components/{chip → chips}/types.ts +203 -92
  49. package/src/components/dialog/dialog.ts +99 -16
  50. package/src/components/dialog/index.ts +97 -1
  51. package/src/components/dialog/types.ts +375 -69
  52. package/src/components/divider/config.ts +90 -6
  53. package/src/components/divider/divider.ts +32 -2
  54. package/src/components/divider/features.ts +26 -0
  55. package/src/components/divider/index.ts +30 -0
  56. package/src/components/divider/types.ts +86 -9
  57. package/src/components/extended-fab/api.ts +53 -1
  58. package/src/components/extended-fab/config.ts +29 -1
  59. package/src/components/extended-fab/extended-fab.ts +28 -0
  60. package/src/components/extended-fab/index.ts +36 -0
  61. package/src/components/extended-fab/types.ts +458 -13
  62. package/src/components/fab/api.ts +42 -2
  63. package/src/components/fab/config.ts +29 -1
  64. package/src/components/fab/fab.ts +16 -2
  65. package/src/components/fab/index.ts +35 -0
  66. package/src/components/fab/types.ts +374 -10
  67. package/src/components/list/api.ts +12 -2
  68. package/src/components/list/config.ts +21 -0
  69. package/src/components/list/features.ts +6 -0
  70. package/src/components/list/index.ts +56 -1
  71. package/src/components/list/list-item.ts +46 -2
  72. package/src/components/list/list.ts +73 -2
  73. package/src/components/list/types.ts +172 -0
  74. package/src/components/list/utils.ts +26 -2
  75. package/src/components/menu/api.ts +217 -20
  76. package/src/components/menu/config.ts +27 -0
  77. package/src/components/menu/features/visibility.ts +55 -6
  78. package/src/components/menu/index.ts +64 -0
  79. package/src/components/menu/menu-item.ts +46 -3
  80. package/src/components/menu/menu.ts +77 -1
  81. package/src/components/menu/types.ts +404 -39
  82. package/src/components/navigation/nav-item.ts +13 -2
  83. package/src/components/sheet/config.ts +1 -2
  84. package/src/components/sheet/features/gestures.ts +1 -1
  85. package/src/components/sheet/features/position.ts +1 -2
  86. package/src/components/sheet/features/state.ts +1 -1
  87. package/src/components/sheet/index.ts +10 -2
  88. package/src/components/sheet/sheet.ts +1 -2
  89. package/src/components/sheet/types.ts +29 -1
  90. package/src/components/slider/api.ts +1 -1
  91. package/src/components/slider/config.ts +1 -1
  92. package/src/components/slider/features/controller.ts +1 -1
  93. package/src/components/slider/features/handlers.ts +1 -1
  94. package/src/components/slider/features/states.ts +1 -1
  95. package/src/components/slider/index.ts +12 -5
  96. package/src/components/slider/schema.ts +1 -1
  97. package/src/components/slider/types.ts +31 -0
  98. package/src/components/tabs/tab-api.ts +1 -1
  99. package/src/components/tabs/types.ts +1 -1
  100. package/src/components/tooltip/api.ts +6 -2
  101. package/src/components/tooltip/config.ts +9 -28
  102. package/src/components/tooltip/index.ts +10 -1
  103. package/src/components/tooltip/types.ts +38 -3
  104. package/src/core/dom/create.ts +57 -51
  105. package/src/index.ts +129 -31
  106. package/src/styles/abstract/_mixins.scss +23 -9
  107. package/src/styles/abstract/_variables.scss +14 -4
  108. package/src/styles/components/_card.scss +1 -1
  109. package/src/styles/components/_chip.scss +323 -113
  110. package/src/styles/components/_tabs.scss +1 -1
  111. package/src/styles/themes/_autumn.scss +3 -0
  112. package/CLAUDE.md +0 -33
  113. package/src/components/checkbox/constants.ts +0 -37
  114. package/src/components/chip/chip-set.ts +0 -225
  115. package/src/components/chip/chip.ts +0 -118
  116. package/src/components/chip/constants.ts +0 -28
  117. package/src/components/chip/index.ts +0 -12
  118. package/src/components/list/constants.ts +0 -116
  119. package/src/components/sheet/constants.ts +0 -20
  120. package/src/components/slider/constants.ts +0 -32
  121. package/src/components/tooltip/constants.ts +0 -27
  122. package/test/components/badge.test.ts +0 -545
  123. package/test/components/bottom-app-bar.test.ts +0 -303
  124. package/test/components/button.test.ts +0 -233
  125. package/test/components/card.test.ts +0 -560
  126. package/test/components/carousel.test.ts +0 -951
  127. package/test/components/checkbox.test.ts +0 -462
  128. package/test/components/chip.test.ts +0 -692
  129. package/test/components/datepicker.test.ts +0 -1124
  130. package/test/components/dialog.test.ts +0 -990
  131. package/test/components/divider.test.ts +0 -412
  132. package/test/components/extended-fab.test.ts +0 -672
  133. package/test/components/fab.test.ts +0 -561
  134. package/test/components/list.test.ts +0 -365
  135. package/test/components/menu.test.ts +0 -718
  136. package/test/components/navigation.test.ts +0 -186
  137. package/test/components/progress.test.ts +0 -567
  138. package/test/components/radios.test.ts +0 -699
  139. package/test/components/search.test.ts +0 -1135
  140. package/test/components/segmented-button.test.ts +0 -732
  141. package/test/components/sheet.test.ts +0 -641
  142. package/test/components/slider.test.ts +0 -1220
  143. package/test/components/snackbar.test.ts +0 -461
  144. package/test/components/switch.test.ts +0 -452
  145. package/test/components/tabs.test.ts +0 -1369
  146. package/test/components/textfield.test.ts +0 -400
  147. package/test/components/timepicker.test.ts +0 -592
  148. package/test/components/tooltip.test.ts +0 -630
  149. package/test/components/top-app-bar.test.ts +0 -566
  150. package/test/core/dom.attributes.test.ts +0 -148
  151. package/test/core/dom.classes.test.ts +0 -152
  152. package/test/core/dom.events.test.ts +0 -243
  153. package/test/core/emitter.test.ts +0 -141
  154. package/test/core/ripple.test.ts +0 -99
  155. package/test/core/state.store.test.ts +0 -189
  156. package/test/core/utils.normalize.test.ts +0 -61
  157. package/test/core/utils.object.test.ts +0 -120
  158. package/test/setup.js +0 -371
  159. package/test/setup.ts +0 -451
  160. package/tsconfig.json +0 -22
  161. package/typedoc.json +0 -28
  162. package/typedoc.simple.json +0 -14
@@ -1,5 +1,33 @@
1
1
  // src/components/sheet/types.ts
2
- import { SHEET_VARIANTS, SHEET_POSITIONS } from './constants';
2
+
3
+ /**
4
+ * Sheet variants
5
+ */
6
+ export const SHEET_VARIANTS = {
7
+ STANDARD: 'standard',
8
+ MODAL: 'modal',
9
+ EXPANDED: 'expanded'
10
+ } as const;
11
+
12
+ /**
13
+ * Sheet positions
14
+ */
15
+ export const SHEET_POSITIONS = {
16
+ BOTTOM: 'bottom',
17
+ TOP: 'top',
18
+ LEFT: 'left',
19
+ RIGHT: 'right'
20
+ } as const;
21
+
22
+ /**
23
+ * Sheet events
24
+ */
25
+ export const SHEET_EVENTS = {
26
+ OPEN: 'open',
27
+ CLOSE: 'close',
28
+ DRAG_START: 'dragstart',
29
+ DRAG_END: 'dragend'
30
+ } as const;
3
31
 
4
32
  /**
5
33
  * Configuration interface for the Sheet component
@@ -1,6 +1,6 @@
1
1
  // src/components/slider/api.ts
2
2
  import { SliderComponent, SliderEvent } from './types';
3
- import { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS } from './constants';
3
+ import { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS } from './types';
4
4
 
5
5
  /**
6
6
  * API options interface - structured by feature area
@@ -4,7 +4,7 @@ import {
4
4
  createElementConfig
5
5
  } from '../../core/config/component-config';
6
6
  import { SliderConfig } from './types';
7
- import { SLIDER_COLORS, SLIDER_SIZES } from './constants';
7
+ import { SLIDER_COLORS, SLIDER_SIZES } from './types';
8
8
  import { createSliderSchema } from './schema';
9
9
 
10
10
  /**
@@ -1,5 +1,5 @@
1
1
  // src/components/slider/features/controller.ts
2
- import { SLIDER_EVENTS } from '../constants';
2
+ import { SLIDER_EVENTS } from '../types';
3
3
  import { SliderConfig } from '../types';
4
4
  import { createHandlers } from './handlers';
5
5
 
@@ -1,5 +1,5 @@
1
1
  // src/components/slider/features/handlers.ts
2
- import { SLIDER_EVENTS } from '../constants';
2
+ import { SLIDER_EVENTS } from '../types';
3
3
  import { SliderConfig, SliderEvent } from '../types';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  // src/components/slider/features/states.ts
2
- import { SLIDER_COLORS, SLIDER_SIZES } from '../constants';
2
+ import { SLIDER_COLORS, SLIDER_SIZES } from '../types';
3
3
  import { SliderConfig } from '../types';
4
4
 
5
5
  /**
@@ -3,8 +3,15 @@
3
3
  // Export main component creator
4
4
  export { default } from './slider';
5
5
 
6
- // Export constants
7
- export { SLIDER_COLORS, SLIDER_SIZES, SLIDER_EVENTS } from './constants';
8
-
9
- // Export types for TypeScript users
10
- export type { SliderConfig, SliderComponent, SliderEvent } from './types';
6
+ // Export constants and types
7
+ export {
8
+ // Constants
9
+ SLIDER_COLORS,
10
+ SLIDER_SIZES,
11
+ SLIDER_EVENTS,
12
+
13
+ // Types
14
+ type SliderConfig,
15
+ type SliderComponent,
16
+ type SliderEvent
17
+ } from './types';
@@ -22,7 +22,7 @@ export function createSliderSchema(component, config: SliderConfig) {
22
22
  // Calculate initial position
23
23
  const valuePercent = ((value - min) / (max - min)) * 100;
24
24
 
25
- // Return base structure definition formatted for createStructure
25
+ // Return base structure definition formatted for createLayout
26
26
  return {
27
27
  element: {
28
28
  options: {
@@ -1,5 +1,36 @@
1
1
  // src/components/slider/types.ts
2
2
 
3
+ /**
4
+ * Available slider color variants
5
+ */
6
+ export const SLIDER_COLORS = {
7
+ PRIMARY: 'primary',
8
+ SECONDARY: 'secondary',
9
+ TERTIARY: 'tertiary',
10
+ ERROR: 'error'
11
+ } as const;
12
+
13
+ /**
14
+ * Available slider size variants
15
+ */
16
+ export const SLIDER_SIZES = {
17
+ SMALL: 'small',
18
+ MEDIUM: 'medium',
19
+ LARGE: 'large'
20
+ } as const;
21
+
22
+ /**
23
+ * Available slider events
24
+ */
25
+ export const SLIDER_EVENTS = {
26
+ CHANGE: 'change',
27
+ INPUT: 'input',
28
+ FOCUS: 'focus',
29
+ BLUR: 'blur',
30
+ START: 'start',
31
+ END: 'end'
32
+ } as const;
33
+
3
34
  /**
4
35
  * Available slider color variants
5
36
  */
@@ -1,6 +1,6 @@
1
1
  // src/components/tabs/tab-api.ts
2
2
  import { TabComponent } from './types';
3
- import { BadgeComponent } from '../badge/types';
3
+ import type { BadgeComponent } from '../badge';
4
4
  import createBadge from '../badge';
5
5
 
6
6
  const TAB_LAYOUT = {
@@ -1,5 +1,5 @@
1
1
  // src/components/tabs/types.ts
2
- import { BadgeComponent } from '../badge/types';
2
+ import type { BadgeComponent } from '../badge';
3
3
  import { TabIndicator } from './indicator';
4
4
 
5
5
  /**
@@ -1,6 +1,10 @@
1
1
  // src/components/tooltip/api.ts
2
- import { TooltipComponent } from './types';
3
- import { TOOLTIP_POSITIONS, DEFAULT_OFFSET, DEFAULT_ARROW_SIZE } from './config';
2
+ import {
3
+ TooltipComponent,
4
+ TOOLTIP_POSITIONS,
5
+ DEFAULT_OFFSET,
6
+ DEFAULT_ARROW_SIZE
7
+ } from './types';
4
8
 
5
9
  interface ApiOptions {
6
10
  lifecycle: {
@@ -3,34 +3,15 @@ import {
3
3
  createComponentConfig,
4
4
  createElementConfig
5
5
  } from '../../core/config/component-config';
6
- import { TooltipConfig } from './types';
7
-
8
-
9
- export const TOOLTIP_POSITIONS = {
10
- TOP: 'top',
11
- RIGHT: 'right',
12
- BOTTOM: 'bottom',
13
- LEFT: 'left',
14
- TOP_START: 'top-start',
15
- TOP_END: 'top-end',
16
- RIGHT_START: 'right-start',
17
- RIGHT_END: 'right-end',
18
- BOTTOM_START: 'bottom-start',
19
- BOTTOM_END: 'bottom-end',
20
- LEFT_START: 'left-start',
21
- LEFT_END: 'left-end'
22
- }
23
-
24
- export const TOOLTIP_VARIANTS = {
25
- DEFAULT: 'default',
26
- RICH: 'rich',
27
- PLAIN: 'plain'
28
- }
29
-
30
- export const DEFAULT_SHOW_DELAY = 300
31
- export const DEFAULT_HIDE_DELAY = 100
32
- export const DEFAULT_OFFSET = 8
33
- export const DEFAULT_ARROW_SIZE = 8
6
+ import {
7
+ TooltipConfig,
8
+ TOOLTIP_POSITIONS,
9
+ TOOLTIP_VARIANTS,
10
+ DEFAULT_SHOW_DELAY,
11
+ DEFAULT_HIDE_DELAY,
12
+ DEFAULT_OFFSET,
13
+ DEFAULT_ARROW_SIZE
14
+ } from './types';
34
15
 
35
16
  /**
36
17
  * Default configuration for the Tooltip component
@@ -1,3 +1,12 @@
1
1
  // src/components/tooltip/index.ts
2
2
  export { default } from './tooltip';
3
- export { TooltipConfig, TooltipComponent } from './types';
3
+ export {
4
+ TooltipConfig,
5
+ TooltipComponent,
6
+ TOOLTIP_POSITIONS,
7
+ TOOLTIP_VARIANTS,
8
+ DEFAULT_SHOW_DELAY,
9
+ DEFAULT_HIDE_DELAY,
10
+ DEFAULT_OFFSET,
11
+ DEFAULT_ARROW_SIZE
12
+ } from './types';
@@ -1,12 +1,47 @@
1
1
  // src/components/tooltip/types.ts
2
2
 
3
3
  /**
4
- * Available Textfield variants
4
+ * Tooltip positions
5
+ */
6
+ export const TOOLTIP_POSITIONS = {
7
+ TOP: 'top',
8
+ RIGHT: 'right',
9
+ BOTTOM: 'bottom',
10
+ LEFT: 'left',
11
+ TOP_START: 'top-start',
12
+ TOP_END: 'top-end',
13
+ RIGHT_START: 'right-start',
14
+ RIGHT_END: 'right-end',
15
+ BOTTOM_START: 'bottom-start',
16
+ BOTTOM_END: 'bottom-end',
17
+ LEFT_START: 'left-start',
18
+ LEFT_END: 'left-end'
19
+ } as const;
20
+
21
+ /**
22
+ * Tooltip variants
23
+ */
24
+ export const TOOLTIP_VARIANTS = {
25
+ DEFAULT: 'default',
26
+ RICH: 'rich',
27
+ PLAIN: 'plain'
28
+ } as const;
29
+
30
+ /**
31
+ * Default values
32
+ */
33
+ export const DEFAULT_SHOW_DELAY = 300;
34
+ export const DEFAULT_HIDE_DELAY = 100;
35
+ export const DEFAULT_OFFSET = 8;
36
+ export const DEFAULT_ARROW_SIZE = 8;
37
+
38
+ /**
39
+ * Available Tooltip variants
5
40
  */
6
41
  export type TooltipVariant = 'default' | 'rich' | 'plain';
7
42
 
8
43
  /**
9
- * Available Textfield states
44
+ * Available Tooltip positions
10
45
  */
11
46
  export type TooltipPosition = 'top' | 'right' | 'bottom' | 'left' | 'top-start' | 'top-end' | 'right-start' | 'right-end' | 'bottom-start' | 'bottom-end' | 'left-start' | 'left-end';
12
47
 
@@ -38,7 +73,7 @@ export interface TooltipConfig {
38
73
  * Tooltip variant that determines visual styling
39
74
  * @default 'default'
40
75
  */
41
- variant?: TooltipVariants | string;
76
+ variant?: TooltipVariant | string;
42
77
 
43
78
  /**
44
79
  * Whether the tooltip is initially visible
@@ -6,6 +6,17 @@
6
6
 
7
7
  import { setAttributes } from './attributes';
8
8
  import { normalizeClasses } from '../utils';
9
+ import { PREFIX } from '../config';
10
+
11
+ /**
12
+ * Event handler function type
13
+ */
14
+ export type EventHandler = (event: Event) => void;
15
+
16
+ /**
17
+ * Event condition type - either a boolean or a function that returns a boolean
18
+ */
19
+ export type EventCondition = boolean | ((context: any, event: Event) => boolean);
9
20
 
10
21
  /**
11
22
  * Options for element creation
@@ -59,7 +70,7 @@ export interface CreateElementOptions {
59
70
  /**
60
71
  * Events to forward when component has emit method
61
72
  */
62
- forwardEvents?: Record<string, boolean | ((context: any, event: Event) => boolean)>;
73
+ forwardEvents?: Record<string, EventCondition>;
63
74
 
64
75
  /**
65
76
  * Callback after element creation
@@ -81,9 +92,12 @@ export interface CreateElementOptions {
81
92
  * Event handler storage to facilitate cleanup
82
93
  */
83
94
  export interface EventHandlerStorage {
84
- [eventName: string]: EventListener;
95
+ [eventName: string]: EventHandler;
85
96
  }
86
97
 
98
+ // Constant for prefix with dash
99
+ const PREFIX_WITH_DASH = `${PREFIX}-`;
100
+
87
101
  /**
88
102
  * Creates a DOM element with the specified options
89
103
  *
@@ -108,89 +122,78 @@ export const createElement = (options: CreateElementOptions = {}): HTMLElement =
108
122
 
109
123
  const element = document.createElement(tag);
110
124
 
111
- // Handle content
125
+ // Apply basic properties
112
126
  if (html) element.innerHTML = html;
113
127
  if (text) element.textContent = text;
114
128
  if (id) element.id = id;
115
129
 
116
130
  // Handle classes
117
131
  if (className) {
118
- const normalizedClasses = normalizeClasses(className);
119
- if (normalizedClasses.length) {
120
- element.classList.add(...normalizedClasses);
132
+ const classes = normalizeClasses(className);
133
+ if (classes.length) {
134
+ // Apply prefix to classes in a single operation
135
+ element.classList.add(...classes.map(cls =>
136
+ cls && !cls.startsWith(PREFIX_WITH_DASH) ? PREFIX_WITH_DASH + cls : cls
137
+ ).filter(Boolean));
121
138
  }
122
139
  }
123
140
 
124
- // Handle data attributes
125
- Object.entries(data).forEach(([key, value]) => {
126
- element.dataset[key] = value;
127
- });
141
+ // Handle data attributes directly
142
+ for (const key in data) {
143
+ element.dataset[key] = data[key];
144
+ }
128
145
 
129
- // Handle all other attributes
146
+ // Handle regular attributes
130
147
  const allAttrs = { ...attrs, ...rest };
131
- Object.entries(allAttrs).forEach(([key, value]) => {
148
+ for (const key in allAttrs) {
149
+ const value = allAttrs[key];
132
150
  if (value != null) element.setAttribute(key, String(value));
133
- });
134
-
135
- // Initialize event handler storage if not present
136
- if (!element.__eventHandlers) {
137
- element.__eventHandlers = {};
138
151
  }
139
152
 
140
- // Handle event forwarding if context has emit method or is a component with on method
153
+ // Handle event forwarding
141
154
  if (forwardEvents && (context?.emit || context?.on)) {
142
- Object.entries(forwardEvents).forEach(([nativeEvent, eventConfig]) => {
143
- // Create a wrapper handler function to evaluate condition and forward event
155
+ element.__eventHandlers = {};
156
+
157
+ for (const nativeEvent in forwardEvents) {
158
+ const eventConfig = forwardEvents[nativeEvent];
159
+
144
160
  const handler = (event: Event) => {
145
- // Determine if the event should be forwarded
146
161
  let shouldForward = true;
147
162
 
148
163
  if (typeof eventConfig === 'function') {
149
164
  try {
150
- // If it's a function, call with component context and event
151
- shouldForward = eventConfig({ ...context, element }, event);
165
+ // Create a lightweight context clone
166
+ const ctxWithElement = { ...context, element };
167
+ shouldForward = eventConfig(ctxWithElement, event);
152
168
  } catch (error) {
153
169
  console.warn(`Error in event condition for ${nativeEvent}:`, error);
154
170
  shouldForward = false;
155
171
  }
156
172
  } else {
157
- // If it's a boolean, use directly
158
173
  shouldForward = Boolean(eventConfig);
159
174
  }
160
175
 
161
- // Forward the event if condition passes
162
176
  if (shouldForward) {
163
177
  if (context.emit) {
164
178
  context.emit(nativeEvent, { event, element, originalEvent: event });
165
179
  } else if (context.on) {
166
- // This is a component with on method but no emit method
167
- // Dispatch a custom event that can be listened to
168
- const customEvent = new CustomEvent(nativeEvent, {
180
+ element.dispatchEvent(new CustomEvent(nativeEvent, {
169
181
  detail: { event, element, originalEvent: event },
170
182
  bubbles: true,
171
183
  cancelable: true
172
- });
173
- element.dispatchEvent(customEvent);
184
+ }));
174
185
  }
175
186
  }
176
187
  };
177
188
 
178
- // Store the handler for future removal
179
189
  element.__eventHandlers[nativeEvent] = handler;
180
-
181
- // Add the actual event listener
182
190
  element.addEventListener(nativeEvent, handler);
183
- });
191
+ }
184
192
  }
185
193
 
186
194
  // Append to container if provided
187
- if (container) {
188
- container.appendChild(element);
189
- }
190
-
191
- if (typeof onCreate === 'function') {
192
- onCreate(element, context);
193
- }
195
+ if (container) container.appendChild(element);
196
+ if (onCreate) onCreate(element, context);
194
197
 
195
198
  return element;
196
199
  };
@@ -200,10 +203,11 @@ export const createElement = (options: CreateElementOptions = {}): HTMLElement =
200
203
  * @param element - Element to cleanup
201
204
  */
202
205
  export const removeEventHandlers = (element: HTMLElement): void => {
203
- if (element.__eventHandlers) {
204
- Object.entries(element.__eventHandlers).forEach(([eventName, handler]) => {
205
- element.removeEventListener(eventName, handler);
206
- });
206
+ const handlers = element.__eventHandlers;
207
+ if (handlers) {
208
+ for (const event in handlers) {
209
+ element.removeEventListener(event, handlers[event]);
210
+ }
207
211
  delete element.__eventHandlers;
208
212
  }
209
213
  };
@@ -228,7 +232,9 @@ export const withClasses = (...classes: (string | string[])[]) =>
228
232
  (element: HTMLElement): HTMLElement => {
229
233
  const normalizedClasses = normalizeClasses(...classes);
230
234
  if (normalizedClasses.length) {
231
- element.classList.add(...normalizedClasses);
235
+ element.classList.add(...normalizedClasses.map(cls =>
236
+ cls && !cls.startsWith(PREFIX_WITH_DASH) ? PREFIX_WITH_DASH + cls : cls
237
+ ).filter(Boolean));
232
238
  }
233
239
  return element;
234
240
  };
@@ -240,17 +246,17 @@ export const withClasses = (...classes: (string | string[])[]) =>
240
246
  */
241
247
  export const withContent = (content: Node | string) =>
242
248
  (element: HTMLElement): HTMLElement => {
243
- if (content instanceof Node) {
244
- element.appendChild(content);
245
- } else {
246
- element.textContent = content;
247
- }
249
+ if (content instanceof Node) element.appendChild(content);
250
+ else element.textContent = content;
248
251
  return element;
249
252
  };
250
253
 
251
254
  // Extend HTMLElement interface to add eventHandlers property
252
255
  declare global {
253
256
  interface HTMLElement {
257
+ /**
258
+ * Storage for event handlers to enable cleanup
259
+ */
254
260
  __eventHandlers?: EventHandlerStorage;
255
261
  }
256
262
  }
package/src/index.ts CHANGED
@@ -1,32 +1,130 @@
1
1
  // src/index.ts
2
- export { createElement } from './core/dom/create'
3
- export { default as createLayout } from './core/layout'
4
- export { default as createButton } from './components/button'
5
- export { default as createFab } from './components/fab'
6
- export { default as createExtendedFab } from './components/extended-fab'
7
- export { default as createSegmentedButton } from './components/segmented-button'
8
- export { default as createBottomAppBar } from './components/bottom-app-bar'
9
- export { default as createBadge } from './components/badge'
10
- export { default as createCard } from './components/card'
11
- export { default as createCarousel } from './components/carousel'
12
- export { default as createCheckbox } from './components/checkbox'
13
- export { default as createChip } from './components/chip'
14
- export { default as createDatePicker } from './components/datepicker'
15
- export { default as createDialog } from './components/dialog'
16
- export { default as createDivider } from './components/divider'
17
- export { default as createMenu } from './components/menu'
18
- export { default as createNavigation } from './components/navigation'
19
- export { default as createNavigationSystem } from './components/navigation'
20
- export { default as createProgress } from './components/progress'
21
- export { default as createRadios } from './components/radios'
22
- export { default as createSearch } from './components/search'
23
- export { default as createSheet } from './components/sheet'
24
- export { default as createSlider } from './components/slider'
25
- export { default as createSnackbar } from './components/snackbar'
26
- export { default as createSwitch } from './components/switch'
27
- export { default as createTabs } from './components/tabs'
28
- export { default as createTextfield } from './components/textfield'
29
- export { default as createTimePicker } from './components/timepicker'
30
- export { default as createTopAppBar } from './components/top-app-bar'
31
- export { default as createTooltip } from './components/tooltip'
32
- export { default as createList } from './components/list'
2
+ /**
3
+ * Main mtrl library exports
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ // Direct component imports
9
+ import { createElement } from './core/dom/create';
10
+ import createLayout from './core/layout';
11
+ import createBadge from './components/badge';
12
+ import createBottomAppBar from './components/bottom-app-bar';
13
+ import createButton from './components/button';
14
+ import createCard from './components/card';
15
+ import {
16
+ createCardContent,
17
+ createCardHeader,
18
+ createCardActions,
19
+ createCardMedia
20
+ } from './components/card/content';
21
+ import createCarousel from './components/carousel';
22
+ import createCheckbox from './components/checkbox';
23
+ import { createChip, createChips } from './components/chips';
24
+ import createDatePicker from './components/datepicker';
25
+ import createDialog from './components/dialog';
26
+ import { createDivider } from './components/divider';
27
+ import createFab from './components/fab';
28
+ import createExtendedFab from './components/extended-fab';
29
+ import createList, { createListItem } from './components/list';
30
+ import createMenu from './components/menu';
31
+ import createNavigation, { createNavigationSystem } from './components/navigation';
32
+ import createProgress from './components/progress';
33
+ import createRadios from './components/radios';
34
+ import createSearch from './components/search';
35
+ import createSegmentedButton, { createSegment } from './components/segmented-button';
36
+ import createSheet from './components/sheet';
37
+ import createSlider from './components/slider';
38
+ import createSnackbar from './components/snackbar';
39
+ import createSwitch from './components/switch';
40
+ import createTabs, { createTab } from './components/tabs';
41
+ import createTextfield from './components/textfield';
42
+ import createTimePicker from './components/timepicker';
43
+ import createTopAppBar from './components/top-app-bar';
44
+ import createTooltip from './components/tooltip';
45
+
46
+ // Export all "create*" functions
47
+ export {
48
+ createElement,
49
+ createLayout,
50
+ createBadge,
51
+ createBottomAppBar,
52
+ createButton,
53
+ createCard,
54
+ createCardContent,
55
+ createCardHeader,
56
+ createCardActions,
57
+ createCardMedia,
58
+ createCarousel,
59
+ createCheckbox,
60
+ createChip,
61
+ createChipSet,
62
+ createDatePicker,
63
+ createDialog,
64
+ createDivider,
65
+ createFab,
66
+ createExtendedFab,
67
+ createList,
68
+ createListItem,
69
+ createMenu,
70
+ createNavigation,
71
+ createNavigationSystem,
72
+ createProgress,
73
+ createRadios,
74
+ createSearch,
75
+ createSegmentedButton,
76
+ createSegment,
77
+ createSheet,
78
+ createSlider,
79
+ createSnackbar,
80
+ createSwitch,
81
+ createTabs,
82
+ createTab,
83
+ createTextfield,
84
+ createTimePicker,
85
+ createTopAppBar,
86
+ createTooltip
87
+ };
88
+
89
+ // Export all "f*" aliases
90
+ export {
91
+ createElement as fElement,
92
+ createLayout as fLayout,
93
+ createBadge as fBadge,
94
+ createBottomAppBar as fBottomAppBar,
95
+ createButton as fButton,
96
+ createCard as fCard,
97
+ createCardContent as fCardContent,
98
+ createCardHeader as fCardHeader,
99
+ createCardActions as fCardActions,
100
+ createCardMedia as fCardMedia,
101
+ createCarousel as fCarousel,
102
+ createCheckbox as fCheckbox,
103
+ createChip as fChip,
104
+ createChips as fChips,
105
+ createDatePicker as fDatePicker,
106
+ createDialog as fDialog,
107
+ createDivider as fDivider,
108
+ createFab as fFab,
109
+ createExtendedFab as fExtendedFab,
110
+ createList as fList,
111
+ createListItem as fListItem,
112
+ createMenu as fMenu,
113
+ createNavigation as fNavigation,
114
+ createNavigationSystem as fNavigationSystem,
115
+ createProgress as fProgress,
116
+ createRadios as fRadios,
117
+ createSearch as fSearch,
118
+ createSegmentedButton as fSegmentedButton,
119
+ createSegment as fSegment,
120
+ createSheet as fSheet,
121
+ createSlider as fSlider,
122
+ createSnackbar as fSnackbar,
123
+ createSwitch as fSwitch,
124
+ createTabs as fTabs,
125
+ createTab as fTab,
126
+ createTextfield as fTextfield,
127
+ createTimePicker as fTimePicker,
128
+ createTopAppBar as fTopAppBar,
129
+ createTooltip as fTooltip
130
+ };