mtrl 0.2.7 → 0.2.9
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/index.ts +2 -0
- package/package.json +14 -3
- package/src/components/badge/api.ts +23 -14
- package/src/components/badge/badge.ts +2 -2
- package/src/components/badge/config.ts +10 -11
- package/src/components/badge/features.ts +15 -10
- package/src/components/badge/index.ts +27 -2
- package/src/components/badge/types.ts +28 -8
- package/src/components/bottom-app-bar/bottom-app-bar.ts +2 -44
- package/src/components/bottom-app-bar/config.ts +1 -45
- package/src/components/bottom-app-bar/index.ts +7 -1
- package/src/components/bottom-app-bar/types.ts +7 -1
- package/src/components/button/button.ts +0 -1
- package/src/components/button/config.ts +1 -2
- package/src/components/button/index.ts +10 -2
- package/src/components/button/types.ts +14 -2
- package/src/components/card/config.ts +17 -9
- package/src/components/card/content.ts +8 -10
- package/src/components/card/features.ts +4 -6
- package/src/components/card/index.ts +29 -2
- package/src/components/card/types.ts +6 -23
- package/src/components/checkbox/config.ts +3 -4
- package/src/components/checkbox/index.ts +1 -2
- package/src/components/checkbox/types.ts +12 -3
- package/src/components/chip/api.ts +170 -221
- package/src/components/chip/chip.ts +34 -302
- package/src/components/chip/config.ts +1 -2
- package/src/components/chip/index.ts +10 -2
- package/src/components/chip/types.ts +224 -35
- package/src/components/datepicker/api.ts +18 -25
- package/src/components/datepicker/config.ts +9 -12
- package/src/components/datepicker/datepicker.ts +7 -12
- package/src/components/datepicker/index.ts +10 -7
- package/src/components/datepicker/render.ts +16 -18
- package/src/components/datepicker/types.ts +164 -35
- package/src/components/datepicker/utils.ts +1 -2
- package/src/components/dialog/api.ts +7 -8
- package/src/components/dialog/config.ts +3 -4
- package/src/components/dialog/features.ts +56 -22
- package/src/components/dialog/index.ts +38 -8
- package/src/components/dialog/types.ts +33 -10
- package/src/components/divider/index.ts +5 -1
- package/src/components/extended-fab/config.ts +6 -2
- package/src/components/extended-fab/index.ts +7 -2
- package/src/components/extended-fab/types.ts +21 -4
- package/src/components/fab/config.ts +3 -4
- package/src/components/fab/fab.ts +1 -1
- package/src/components/fab/index.ts +7 -2
- package/src/components/fab/types.ts +21 -4
- package/src/components/list/config.ts +4 -5
- package/src/components/list/features.ts +6 -7
- package/src/components/list/index.ts +7 -9
- package/src/components/list/list-item.ts +12 -13
- package/src/components/list/types.ts +50 -5
- package/src/components/list/utils.ts +30 -3
- package/src/components/menu/features/items-manager.ts +9 -9
- package/src/components/menu/features/positioning.ts +7 -7
- package/src/components/menu/features/visibility.ts +7 -7
- package/src/components/menu/index.ts +7 -9
- package/src/components/menu/menu-item.ts +6 -6
- package/src/components/menu/menu.ts +22 -0
- package/src/components/menu/types.ts +29 -10
- package/src/components/menu/utils.ts +67 -0
- package/src/components/navigation/api.ts +131 -96
- package/src/components/navigation/config.ts +22 -10
- package/src/components/navigation/features/controller.ts +273 -0
- package/src/components/navigation/features/items.ts +160 -87
- package/src/components/navigation/index.ts +0 -6
- package/src/components/navigation/nav-item.ts +12 -24
- package/src/components/navigation/navigation.ts +21 -8
- package/src/components/navigation/system-types.ts +124 -0
- package/src/components/navigation/system.ts +776 -0
- package/src/components/navigation/types.ts +228 -203
- package/src/components/progress/api.ts +2 -3
- package/src/components/progress/config.ts +2 -3
- package/src/components/progress/index.ts +0 -1
- package/src/components/progress/progress.ts +1 -2
- package/src/components/progress/types.ts +186 -33
- package/src/components/radios/config.ts +1 -1
- package/src/components/radios/index.ts +0 -1
- package/src/components/radios/types.ts +0 -7
- package/src/components/search/config.ts +1 -2
- package/src/components/search/features/search.ts +14 -15
- package/src/components/search/features/states.ts +5 -1
- package/src/components/search/features/structure.ts +3 -4
- package/src/components/search/index.ts +0 -3
- package/src/components/search/types.ts +18 -6
- package/src/components/segmented-button/config.ts +20 -7
- package/src/components/segmented-button/segment.ts +6 -7
- package/src/components/segmented-button/segmented-button.ts +4 -5
- package/src/components/segmented-button/types.ts +37 -2
- package/src/components/slider/config.ts +20 -2
- package/src/components/slider/features/controller.ts +761 -0
- package/src/components/slider/features/handlers.ts +18 -15
- package/src/components/slider/features/index.ts +3 -2
- package/src/components/slider/features/range.ts +104 -0
- package/src/components/slider/slider.ts +34 -14
- package/src/components/slider/structure.ts +152 -0
- package/src/components/slider/types.ts +34 -8
- package/src/components/snackbar/config.ts +2 -3
- package/src/components/snackbar/constants.ts +0 -32
- package/src/components/snackbar/index.ts +0 -1
- package/src/components/snackbar/position.ts +9 -1
- package/src/components/snackbar/types.ts +122 -46
- package/src/components/switch/config.ts +2 -3
- package/src/components/switch/index.ts +0 -1
- package/src/components/switch/types.ts +3 -2
- package/src/components/tabs/config.ts +3 -4
- package/src/components/tabs/index.ts +0 -15
- package/src/components/tabs/tab-api.ts +12 -4
- package/src/components/tabs/tab.ts +18 -6
- package/src/components/tabs/types.ts +13 -3
- package/src/components/textfield/api.ts +53 -0
- package/src/components/textfield/config.ts +2 -3
- package/src/components/textfield/features.ts +322 -0
- package/src/components/textfield/index.ts +0 -1
- package/src/components/textfield/textfield.ts +8 -0
- package/src/components/textfield/types.ts +29 -6
- package/src/components/timepicker/api.ts +1 -1
- package/src/components/timepicker/clockdial.ts +2 -5
- package/src/components/timepicker/config.ts +102 -4
- package/src/components/timepicker/index.ts +1 -6
- package/src/components/timepicker/render.ts +1 -1
- package/src/components/timepicker/timepicker.ts +1 -1
- package/src/components/tooltip/api.ts +1 -1
- package/src/components/tooltip/config.ts +27 -6
- package/src/components/tooltip/index.ts +0 -1
- package/src/components/tooltip/types.ts +13 -3
- package/src/core/compose/features/textinput.ts +15 -2
- package/src/core/compose/features/textlabel.ts +0 -3
- package/src/core/composition/features/dom.ts +33 -0
- package/src/core/composition/features/icon.ts +131 -0
- package/src/core/composition/features/index.ts +11 -0
- package/src/core/composition/features/label.ts +156 -0
- package/src/core/composition/features/structure.ts +22 -0
- package/src/core/composition/index.ts +26 -0
- package/src/core/index.ts +1 -1
- package/src/core/structure.ts +288 -0
- package/src/index.ts +1 -0
- package/src/styles/components/_navigation-mobile.scss +244 -0
- package/src/styles/components/_navigation-system.scss +151 -0
- package/src/{components/tabs/_styles.scss → styles/components/_tabs.scss} +1 -1
- package/src/{components/textfield/_styles.scss → styles/components/_textfield.scss} +314 -72
- package/src/styles/main.scss +98 -49
- package/src/components/badge/constants.ts +0 -40
- package/src/components/button/constants.ts +0 -11
- package/src/components/card/constants.ts +0 -84
- package/src/components/datepicker/constants.ts +0 -98
- package/src/components/dialog/constants.ts +0 -32
- package/src/components/extended-fab/constants.ts +0 -36
- package/src/components/fab/constants.ts +0 -41
- package/src/components/menu/constants.ts +0 -154
- package/src/components/navigation/constants.ts +0 -200
- package/src/components/progress/constants.ts +0 -29
- package/src/components/search/constants.ts +0 -21
- package/src/components/segmented-button/constants.ts +0 -42
- package/src/components/slider/features/slider.ts +0 -318
- package/src/components/slider/features/structure.ts +0 -181
- package/src/components/slider/features/ui.ts +0 -388
- package/src/components/switch/constants.ts +0 -80
- package/src/components/tabs/constants.ts +0 -89
- package/src/components/textfield/constants.ts +0 -100
- package/src/components/timepicker/constants.ts +0 -138
- /package/src/{components/badge/_styles.scss → styles/components/_badge.scss} +0 -0
- /package/src/{components/bottom-app-bar/_styles.scss → styles/components/_bottom-app-bar.scss} +0 -0
- /package/src/{components/button/_styles.scss → styles/components/_button.scss} +0 -0
- /package/src/{components/card/_styles.scss → styles/components/_card.scss} +0 -0
- /package/src/{components/carousel/_styles.scss → styles/components/_carousel.scss} +0 -0
- /package/src/{components/checkbox/_styles.scss → styles/components/_checkbox.scss} +0 -0
- /package/src/{components/chip/_styles.scss → styles/components/_chip.scss} +0 -0
- /package/src/{components/datepicker/_styles.scss → styles/components/_datepicker.scss} +0 -0
- /package/src/{components/dialog/_styles.scss → styles/components/_dialog.scss} +0 -0
- /package/src/{components/divider/_styles.scss → styles/components/_divider.scss} +0 -0
- /package/src/{components/extended-fab/_styles.scss → styles/components/_extended-fab.scss} +0 -0
- /package/src/{components/fab/_styles.scss → styles/components/_fab.scss} +0 -0
- /package/src/{components/list/_styles.scss → styles/components/_list.scss} +0 -0
- /package/src/{components/menu/_styles.scss → styles/components/_menu.scss} +0 -0
- /package/src/{components/navigation/_styles.scss → styles/components/_navigation.scss} +0 -0
- /package/src/{components/progress/_styles.scss → styles/components/_progress.scss} +0 -0
- /package/src/{components/radios/_styles.scss → styles/components/_radios.scss} +0 -0
- /package/src/{components/search/_styles.scss → styles/components/_search.scss} +0 -0
- /package/src/{components/segmented-button/_styles.scss → styles/components/_segmented-button.scss} +0 -0
- /package/src/{components/sheet/_styles.scss → styles/components/_sheet.scss} +0 -0
- /package/src/{components/slider/_styles.scss → styles/components/_slider.scss} +0 -0
- /package/src/{components/snackbar/_styles.scss → styles/components/_snackbar.scss} +0 -0
- /package/src/{components/switch/_styles.scss → styles/components/_switch.scss} +0 -0
- /package/src/{components/timepicker/_styles.scss → styles/components/_timepicker.scss} +0 -0
- /package/src/{components/tooltip/_styles.scss → styles/components/_tooltip.scss} +0 -0
- /package/src/{components/top-app-bar/_styles.scss → styles/components/_top-app-bar.scss} +0 -0
- /package/src/styles/utilities/{_color.scss → _colors.scss} +0 -0
package/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
createList,
|
|
19
19
|
createMenu,
|
|
20
20
|
createNavigation,
|
|
21
|
+
createNavigationSystem,
|
|
21
22
|
createProgress,
|
|
22
23
|
createRadios,
|
|
23
24
|
createSearch,
|
|
@@ -51,6 +52,7 @@ export {
|
|
|
51
52
|
createList,
|
|
52
53
|
createMenu,
|
|
53
54
|
createNavigation,
|
|
55
|
+
createNavigationSystem,
|
|
54
56
|
createProgress,
|
|
55
57
|
createRadios,
|
|
56
58
|
createSearch,
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mtrl",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "A functional TypeScript/JavaScript component library with composable architecture based on Material Design 3",
|
|
5
|
+
"author": "floor",
|
|
6
|
+
"license": "MIT License",
|
|
5
7
|
"keywords": [
|
|
6
8
|
"component",
|
|
7
9
|
"library",
|
|
@@ -13,8 +15,18 @@
|
|
|
13
15
|
"material design 3",
|
|
14
16
|
"md3"
|
|
15
17
|
],
|
|
18
|
+
"type": "module",
|
|
16
19
|
"main": "index.js",
|
|
17
20
|
"scripts": {
|
|
21
|
+
"start": "bun run server.js",
|
|
22
|
+
"dev": "bun --watch server.js",
|
|
23
|
+
"build:demo": "bun run demo/build.ts",
|
|
24
|
+
"dev:demo": "bun run demo/build.ts --watch",
|
|
25
|
+
"clean:demo": "rm -rf demo/dist",
|
|
26
|
+
"build:js": "bun build demo/main.js --outfile=demo/dist/bundle.js --format=esm",
|
|
27
|
+
"build:css": "sass src/styles/main.scss:demo/dist/styles.css --style=compressed",
|
|
28
|
+
"build": "bun run build:js && bun run build:css",
|
|
29
|
+
"build:watch": "bun build --watch demo/main.js --outfile=demo/dist/bundle.js & sass --watch src/styles/main.scss:demo/dist/styles.css",
|
|
18
30
|
"test": "bun test",
|
|
19
31
|
"test:watch": "bun test --watch",
|
|
20
32
|
"test:coverage": "bun test --coverage",
|
|
@@ -29,9 +41,8 @@
|
|
|
29
41
|
"type": "git",
|
|
30
42
|
"url": "https://github.com/floor/mtrl.git"
|
|
31
43
|
},
|
|
32
|
-
"author": "floor",
|
|
33
|
-
"license": "MIT License",
|
|
34
44
|
"devDependencies": {
|
|
45
|
+
"sass": "^1.85.1",
|
|
35
46
|
"typedoc": "^0.27.9"
|
|
36
47
|
}
|
|
37
48
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
// src/components/badge/api.ts
|
|
2
|
-
import { BadgeComponent } from './types';
|
|
3
|
-
import {
|
|
4
|
-
BADGE_VARIANTS,
|
|
5
|
-
BADGE_COLORS,
|
|
6
|
-
BADGE_POSITIONS
|
|
7
|
-
} from './constants';
|
|
2
|
+
import { BadgeComponent, BadgeColor, BadgeVariant, BadgePosition } from './types';
|
|
8
3
|
import { formatBadgeLabel } from './config';
|
|
9
4
|
|
|
10
5
|
interface ApiOptions {
|
|
@@ -34,6 +29,20 @@ interface ComponentWithElements {
|
|
|
34
29
|
off: (event: string, handler: Function) => any;
|
|
35
30
|
}
|
|
36
31
|
|
|
32
|
+
// Common variant constants for internal use
|
|
33
|
+
const VARIANT_SMALL = 'small';
|
|
34
|
+
|
|
35
|
+
// Map of all badge colors for class removal
|
|
36
|
+
const ALL_COLORS = [
|
|
37
|
+
'error', 'primary', 'secondary', 'tertiary', 'success', 'warning', 'info'
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// Map of all badge variants for class removal
|
|
41
|
+
const ALL_VARIANTS = ['small', 'large'];
|
|
42
|
+
|
|
43
|
+
// Map of all badge positions for class removal
|
|
44
|
+
const ALL_POSITIONS = ['top-right', 'top-left', 'bottom-right', 'bottom-left'];
|
|
45
|
+
|
|
37
46
|
/**
|
|
38
47
|
* Enhances a badge component with API methods
|
|
39
48
|
* @param {ApiOptions} options - API configuration options
|
|
@@ -53,7 +62,7 @@ export const withAPI = ({ visibility, lifecycle }: ApiOptions) =>
|
|
|
53
62
|
component.config.label = label;
|
|
54
63
|
|
|
55
64
|
// Small badges (dot variant) don't have text
|
|
56
|
-
if (component.config.variant ===
|
|
65
|
+
if (component.config.variant === VARIANT_SMALL) {
|
|
57
66
|
component.element.textContent = '';
|
|
58
67
|
return this;
|
|
59
68
|
}
|
|
@@ -146,9 +155,9 @@ export const withAPI = ({ visibility, lifecycle }: ApiOptions) =>
|
|
|
146
155
|
* @param {string} color - Color variant to apply
|
|
147
156
|
* @returns {BadgeComponent} Badge component instance for chaining
|
|
148
157
|
*/
|
|
149
|
-
setColor(color:
|
|
158
|
+
setColor(color: BadgeColor | string) {
|
|
150
159
|
// Remove existing color classes
|
|
151
|
-
|
|
160
|
+
ALL_COLORS.forEach(colorName => {
|
|
152
161
|
component.element.classList.remove(`${component.getClass('badge')}--${colorName}`);
|
|
153
162
|
});
|
|
154
163
|
|
|
@@ -162,9 +171,9 @@ export const withAPI = ({ visibility, lifecycle }: ApiOptions) =>
|
|
|
162
171
|
* @param {string} variant - Variant to apply (small or large)
|
|
163
172
|
* @returns {BadgeComponent} Badge component instance for chaining
|
|
164
173
|
*/
|
|
165
|
-
setVariant(variant:
|
|
174
|
+
setVariant(variant: BadgeVariant | string) {
|
|
166
175
|
// Remove existing variant classes
|
|
167
|
-
|
|
176
|
+
ALL_VARIANTS.forEach(variantName => {
|
|
168
177
|
component.element.classList.remove(`${component.getClass('badge')}--${variantName}`);
|
|
169
178
|
});
|
|
170
179
|
|
|
@@ -175,7 +184,7 @@ export const withAPI = ({ visibility, lifecycle }: ApiOptions) =>
|
|
|
175
184
|
component.config.variant = variant;
|
|
176
185
|
|
|
177
186
|
// Update accessibility attributes
|
|
178
|
-
if (variant ===
|
|
187
|
+
if (variant === VARIANT_SMALL) {
|
|
179
188
|
component.element.textContent = '';
|
|
180
189
|
component.element.setAttribute('aria-hidden', 'true');
|
|
181
190
|
} else {
|
|
@@ -195,9 +204,9 @@ export const withAPI = ({ visibility, lifecycle }: ApiOptions) =>
|
|
|
195
204
|
* @param {string} position - Position variant to apply
|
|
196
205
|
* @returns {BadgeComponent} Badge component instance for chaining
|
|
197
206
|
*/
|
|
198
|
-
setPosition(position:
|
|
207
|
+
setPosition(position: BadgePosition | string) {
|
|
199
208
|
// Remove existing position classes
|
|
200
|
-
|
|
209
|
+
ALL_POSITIONS.forEach(posName => {
|
|
201
210
|
component.element.classList.remove(`${component.getClass('badge')}--${posName}`);
|
|
202
211
|
});
|
|
203
212
|
|
|
@@ -25,14 +25,14 @@ import { createBaseConfig, getElementConfig, getApiConfig } from './config';
|
|
|
25
25
|
* @example
|
|
26
26
|
* // Create a small dot badge
|
|
27
27
|
* const notificationBadge = createBadge({
|
|
28
|
-
* variant:
|
|
28
|
+
* variant: 'small',
|
|
29
29
|
* target: document.querySelector('.icon-button')
|
|
30
30
|
* });
|
|
31
31
|
*
|
|
32
32
|
* @example
|
|
33
33
|
* // Create a large badge with a count
|
|
34
34
|
* const countBadge = createBadge({
|
|
35
|
-
* variant:
|
|
35
|
+
* variant: 'large',
|
|
36
36
|
* label: 5,
|
|
37
37
|
* target: document.querySelector('.notification-icon')
|
|
38
38
|
* });
|
|
@@ -4,20 +4,19 @@ import {
|
|
|
4
4
|
createElementConfig
|
|
5
5
|
} from '../../core/config/component-config';
|
|
6
6
|
import { BadgeConfig } from './types';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} from './constants';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Maximum character count for badge labels
|
|
10
|
+
*/
|
|
11
|
+
export const BADGE_MAX_CHARACTERS = 4;
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Default configuration for the Badge component
|
|
16
15
|
*/
|
|
17
16
|
export const defaultConfig: BadgeConfig = {
|
|
18
|
-
variant:
|
|
19
|
-
color:
|
|
20
|
-
position:
|
|
17
|
+
variant: 'large',
|
|
18
|
+
color: 'error',
|
|
19
|
+
position: 'top-right',
|
|
21
20
|
label: '',
|
|
22
21
|
visible: true
|
|
23
22
|
};
|
|
@@ -40,12 +39,12 @@ export const getElementConfig = (config: BadgeConfig) => {
|
|
|
40
39
|
const attrs: Record<string, any> = {};
|
|
41
40
|
|
|
42
41
|
// For large badges, set appropriate ARIA attributes
|
|
43
|
-
if (config.variant !==
|
|
42
|
+
if (config.variant !== 'small') {
|
|
44
43
|
attrs.role = 'status';
|
|
45
44
|
}
|
|
46
45
|
|
|
47
46
|
// Format the label if needed
|
|
48
|
-
const formattedLabel = config.variant ===
|
|
47
|
+
const formattedLabel = config.variant === 'small'
|
|
49
48
|
? ''
|
|
50
49
|
: formatBadgeLabel(config.label || '', config.max);
|
|
51
50
|
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
// src/components/badge/features.ts
|
|
2
|
-
import {
|
|
3
|
-
BADGE_VARIANTS,
|
|
4
|
-
BADGE_COLORS,
|
|
5
|
-
BADGE_POSITIONS
|
|
6
|
-
} from './constants';
|
|
7
2
|
import { BadgeConfig } from './types';
|
|
8
3
|
import { formatBadgeLabel } from './config';
|
|
9
4
|
|
|
5
|
+
// Common badge variants
|
|
6
|
+
const VARIANT_SMALL = 'small';
|
|
7
|
+
const VARIANT_LARGE = 'large';
|
|
8
|
+
|
|
9
|
+
// Common badge colors
|
|
10
|
+
const COLOR_ERROR = 'error';
|
|
11
|
+
|
|
12
|
+
// Common badge positions
|
|
13
|
+
const POSITION_TOP_RIGHT = 'top-right';
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Higher-order function that adds visibility control features to a component
|
|
12
17
|
* @returns {Function} Component enhancer with visibility features
|
|
@@ -69,13 +74,13 @@ export const withVisibility = () => component => {
|
|
|
69
74
|
*/
|
|
70
75
|
export const withVariant = (config: BadgeConfig) => component => {
|
|
71
76
|
// Get variant from config with fallback to default
|
|
72
|
-
const variant = config.variant ||
|
|
77
|
+
const variant = config.variant || VARIANT_LARGE;
|
|
73
78
|
|
|
74
79
|
// Apply variant class
|
|
75
80
|
component.element.classList.add(`${component.getClass('badge')}--${variant}`);
|
|
76
81
|
|
|
77
82
|
// Small badges (dot variant) don't have text
|
|
78
|
-
if (variant ===
|
|
83
|
+
if (variant === VARIANT_SMALL) {
|
|
79
84
|
component.element.textContent = '';
|
|
80
85
|
component.element.setAttribute('aria-hidden', 'true');
|
|
81
86
|
} else {
|
|
@@ -100,7 +105,7 @@ export const withVariant = (config: BadgeConfig) => component => {
|
|
|
100
105
|
*/
|
|
101
106
|
export const withColor = (config: BadgeConfig) => component => {
|
|
102
107
|
// Get color from config with fallback to default
|
|
103
|
-
const color = config.color ||
|
|
108
|
+
const color = config.color || COLOR_ERROR;
|
|
104
109
|
|
|
105
110
|
// Apply color class
|
|
106
111
|
component.element.classList.add(`${component.getClass('badge')}--${color}`);
|
|
@@ -115,7 +120,7 @@ export const withColor = (config: BadgeConfig) => component => {
|
|
|
115
120
|
*/
|
|
116
121
|
export const withPosition = (config: BadgeConfig) => component => {
|
|
117
122
|
// Get position from config with fallback to default
|
|
118
|
-
const position = config.position ||
|
|
123
|
+
const position = config.position || POSITION_TOP_RIGHT;
|
|
119
124
|
|
|
120
125
|
// Apply position class
|
|
121
126
|
component.element.classList.add(`${component.getClass('badge')}--${position}`);
|
|
@@ -135,7 +140,7 @@ export const withPosition = (config: BadgeConfig) => component => {
|
|
|
135
140
|
*/
|
|
136
141
|
export const withMax = (config: BadgeConfig) => component => {
|
|
137
142
|
// Skip if no max is defined or for small badges
|
|
138
|
-
if (config.max === undefined || config.variant ===
|
|
143
|
+
if (config.max === undefined || config.variant === VARIANT_SMALL) {
|
|
139
144
|
return component;
|
|
140
145
|
}
|
|
141
146
|
|
|
@@ -1,4 +1,29 @@
|
|
|
1
1
|
// src/components/badge/index.ts
|
|
2
2
|
export { default } from './badge';
|
|
3
|
-
export {
|
|
4
|
-
|
|
3
|
+
export { BadgeConfig, BadgeComponent, BadgeVariant, BadgeColor, BadgePosition } from './types';
|
|
4
|
+
|
|
5
|
+
// Export common badge constants for convenience and backward compatibility
|
|
6
|
+
export const BADGE_VARIANTS = {
|
|
7
|
+
SMALL: 'small',
|
|
8
|
+
LARGE: 'large'
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const BADGE_COLORS = {
|
|
12
|
+
ERROR: 'error',
|
|
13
|
+
PRIMARY: 'primary',
|
|
14
|
+
SECONDARY: 'secondary',
|
|
15
|
+
TERTIARY: 'tertiary',
|
|
16
|
+
SUCCESS: 'success',
|
|
17
|
+
WARNING: 'warning',
|
|
18
|
+
INFO: 'info'
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export const BADGE_POSITIONS = {
|
|
22
|
+
TOP_RIGHT: 'top-right',
|
|
23
|
+
TOP_LEFT: 'top-left',
|
|
24
|
+
BOTTOM_RIGHT: 'bottom-right',
|
|
25
|
+
BOTTOM_LEFT: 'bottom-left'
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
// Export max characters constant
|
|
29
|
+
export const BADGE_MAX_CHARACTERS = 4;
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
// src/components/badge/types.ts
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Badge variant types
|
|
5
|
+
* @category Components
|
|
6
|
+
*/
|
|
7
|
+
export type BadgeVariant = 'small' | 'large';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Badge color types
|
|
11
|
+
* @category Components
|
|
12
|
+
*/
|
|
13
|
+
export type BadgeColor = 'error' | 'primary' | 'secondary' | 'tertiary' | 'success' | 'warning' | 'info';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Badge position types
|
|
17
|
+
* @category Components
|
|
18
|
+
*/
|
|
19
|
+
export type BadgePosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
3
20
|
|
|
4
21
|
/**
|
|
5
22
|
* Configuration interface for the Badge component
|
|
@@ -9,18 +26,21 @@ export interface BadgeConfig {
|
|
|
9
26
|
/**
|
|
10
27
|
* Badge variant (small dot or large numbered)
|
|
11
28
|
* Small badge (6dp) or Large badge (16dp height)
|
|
29
|
+
* @default 'large'
|
|
12
30
|
*/
|
|
13
|
-
variant?:
|
|
31
|
+
variant?: BadgeVariant | string;
|
|
14
32
|
|
|
15
33
|
/**
|
|
16
34
|
* Badge color (error is default)
|
|
35
|
+
* @default 'error'
|
|
17
36
|
*/
|
|
18
|
-
color?:
|
|
37
|
+
color?: BadgeColor | string;
|
|
19
38
|
|
|
20
39
|
/**
|
|
21
|
-
* Badge position relative to its container
|
|
40
|
+
* Badge position relative to its container
|
|
41
|
+
* @default 'top-right'
|
|
22
42
|
*/
|
|
23
|
-
position?:
|
|
43
|
+
position?: BadgePosition | string;
|
|
24
44
|
|
|
25
45
|
/**
|
|
26
46
|
* Text label inside the badge (for large badges)
|
|
@@ -83,13 +103,13 @@ export interface BadgeComponent {
|
|
|
83
103
|
setMax: (max: number) => BadgeComponent;
|
|
84
104
|
|
|
85
105
|
/** Sets badge color */
|
|
86
|
-
setColor: (color:
|
|
106
|
+
setColor: (color: BadgeColor | string) => BadgeComponent;
|
|
87
107
|
|
|
88
108
|
/** Sets badge variant */
|
|
89
|
-
setVariant: (variant:
|
|
109
|
+
setVariant: (variant: BadgeVariant | string) => BadgeComponent;
|
|
90
110
|
|
|
91
111
|
/** Sets badge position */
|
|
92
|
-
setPosition: (position:
|
|
112
|
+
setPosition: (position: BadgePosition | string) => BadgeComponent;
|
|
93
113
|
|
|
94
114
|
/** Attaches badge to a target element */
|
|
95
115
|
attachTo: (target: HTMLElement) => BadgeComponent;
|
|
@@ -13,50 +13,8 @@ import {
|
|
|
13
13
|
BaseComponent
|
|
14
14
|
} from '../../core/compose';
|
|
15
15
|
|
|
16
|
-
import { createConfig
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Bottom app bar component interface
|
|
20
|
-
*/
|
|
21
|
-
export interface BottomAppBar extends ElementComponent {
|
|
22
|
-
/**
|
|
23
|
-
* Adds an action button to the bottom bar
|
|
24
|
-
* @param {HTMLElement} button - Button element to add
|
|
25
|
-
* @returns {BottomAppBar} BottomAppBar instance for chaining
|
|
26
|
-
*/
|
|
27
|
-
addAction: (button: HTMLElement) => BottomAppBar;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Adds a floating action button to the bottom bar
|
|
31
|
-
* @param {HTMLElement} fab - FAB element to add
|
|
32
|
-
* @returns {BottomAppBar} BottomAppBar instance for chaining
|
|
33
|
-
*/
|
|
34
|
-
addFab: (fab: HTMLElement) => BottomAppBar;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Shows the bottom bar
|
|
38
|
-
* @returns {BottomAppBar} BottomAppBar instance for chaining
|
|
39
|
-
*/
|
|
40
|
-
show: () => BottomAppBar;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Hides the bottom bar
|
|
44
|
-
* @returns {BottomAppBar} BottomAppBar instance for chaining
|
|
45
|
-
*/
|
|
46
|
-
hide: () => BottomAppBar;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Checks if the bottom bar is visible
|
|
50
|
-
* @returns {boolean} Whether the bottom bar is visible
|
|
51
|
-
*/
|
|
52
|
-
isVisible: () => boolean;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Get the actions container element
|
|
56
|
-
* @returns {HTMLElement} Actions container element
|
|
57
|
-
*/
|
|
58
|
-
getActionsContainer: () => HTMLElement;
|
|
59
|
-
}
|
|
16
|
+
import { createConfig } from './config';
|
|
17
|
+
import { BottomAppBar, BottomAppBarConfig } from './types';
|
|
60
18
|
|
|
61
19
|
/**
|
|
62
20
|
* Creates a bottom app bar component
|
|
@@ -6,51 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { createComponentConfig, BaseComponentConfig } from '../../core/config/component-config';
|
|
8
8
|
import { PREFIX } from '../../core/config';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Configuration options for bottom app bar
|
|
12
|
-
*/
|
|
13
|
-
export interface BottomAppBarConfig extends BaseComponentConfig {
|
|
14
|
-
/**
|
|
15
|
-
* Element to use for the container
|
|
16
|
-
* @default 'div'
|
|
17
|
-
*/
|
|
18
|
-
tag?: string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Whether to show FAB in the bottom bar
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
hasFab?: boolean;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* FAB position in bottom bar
|
|
28
|
-
* @default 'end'
|
|
29
|
-
*/
|
|
30
|
-
fabPosition?: 'center' | 'end';
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Additional CSS classes to apply
|
|
34
|
-
*/
|
|
35
|
-
class?: string;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Whether to enable auto-hide on scroll
|
|
39
|
-
* @default false
|
|
40
|
-
*/
|
|
41
|
-
autoHide?: boolean;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Transition duration for show/hide in ms
|
|
45
|
-
* @default 300
|
|
46
|
-
*/
|
|
47
|
-
transitionDuration?: number;
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Optional callback when scrolling shows/hides the bar
|
|
51
|
-
*/
|
|
52
|
-
onVisibilityChange?: (visible: boolean) => void;
|
|
53
|
-
}
|
|
9
|
+
import { BottomAppBarConfig } from './types';
|
|
54
10
|
|
|
55
11
|
/**
|
|
56
12
|
* Default configuration for bottom app bar
|
|
@@ -8,4 +8,10 @@ import { createBottomAppBar } from './bottom-app-bar';
|
|
|
8
8
|
|
|
9
9
|
export default createBottomAppBar;
|
|
10
10
|
export { createBottomAppBar };
|
|
11
|
-
export type { BottomAppBarConfig } from './
|
|
11
|
+
export type { BottomAppBarConfig, BottomAppBar } from './types';
|
|
12
|
+
|
|
13
|
+
// Export position constants for convenience and backward compatibility
|
|
14
|
+
export const FAB_POSITIONS = {
|
|
15
|
+
CENTER: 'center',
|
|
16
|
+
END: 'end'
|
|
17
|
+
} as const;
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
import { ElementComponent } from '../../core/compose';
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* FAB position type for Bottom App Bar
|
|
11
|
+
* @category Components
|
|
12
|
+
*/
|
|
13
|
+
export type FabPosition = 'center' | 'end';
|
|
14
|
+
|
|
9
15
|
/**
|
|
10
16
|
* Configuration options for Bottom App Bar component
|
|
11
17
|
* @category Components
|
|
@@ -27,7 +33,7 @@ export interface BottomAppBarConfig {
|
|
|
27
33
|
* FAB position in bottom bar
|
|
28
34
|
* @default 'end'
|
|
29
35
|
*/
|
|
30
|
-
fabPosition?:
|
|
36
|
+
fabPosition?: FabPosition;
|
|
31
37
|
|
|
32
38
|
/**
|
|
33
39
|
* Additional CSS classes to apply
|
|
@@ -13,7 +13,6 @@ import {
|
|
|
13
13
|
} from '../../core/compose/features';
|
|
14
14
|
import { withAPI } from './api';
|
|
15
15
|
import { ButtonConfig } from './types';
|
|
16
|
-
import { BUTTON_VARIANTS } from './constants';
|
|
17
16
|
import { createBaseConfig, getElementConfig, getApiConfig } from './config';
|
|
18
17
|
|
|
19
18
|
/**
|
|
@@ -5,13 +5,12 @@ import {
|
|
|
5
5
|
BaseComponentConfig
|
|
6
6
|
} from '../../core/config/component-config';
|
|
7
7
|
import { ButtonConfig } from './types';
|
|
8
|
-
import { BUTTON_VARIANTS } from './constants';
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Default configuration for the Button component
|
|
12
11
|
*/
|
|
13
12
|
export const defaultConfig: ButtonConfig = {
|
|
14
|
-
variant:
|
|
13
|
+
variant: 'filled',
|
|
15
14
|
type: 'button'
|
|
16
15
|
// Don't set disabled: false as default - it should be undefined by default
|
|
17
16
|
};
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
// src/components/button/index.ts
|
|
2
2
|
export { default } from './button'
|
|
3
|
-
export {
|
|
4
|
-
|
|
3
|
+
export { ButtonConfig, ButtonComponent, ButtonVariant } from './types'
|
|
4
|
+
|
|
5
|
+
// Export common button variants for convenience
|
|
6
|
+
export const BUTTON_VARIANTS = {
|
|
7
|
+
FILLED: 'filled',
|
|
8
|
+
TONAL: 'tonal',
|
|
9
|
+
OUTLINED: 'outlined',
|
|
10
|
+
ELEVATED: 'elevated',
|
|
11
|
+
TEXT: 'text'
|
|
12
|
+
} as const;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// src/components/button/types.ts
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Button variant types
|
|
5
|
+
* @category Components
|
|
6
|
+
*/
|
|
7
|
+
export type ButtonVariant = 'filled' | 'tonal' | 'outlined' | 'elevated' | 'text';
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Configuration interface for the Button component
|
|
@@ -10,7 +15,7 @@ export interface ButtonConfig {
|
|
|
10
15
|
* Button variant that determines visual styling
|
|
11
16
|
* @default 'filled'
|
|
12
17
|
*/
|
|
13
|
-
variant?:
|
|
18
|
+
variant?: ButtonVariant | string;
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Whether the button is initially disabled
|
|
@@ -260,4 +265,11 @@ export interface ButtonComponent {
|
|
|
260
265
|
* @returns The button component for chaining
|
|
261
266
|
*/
|
|
262
267
|
addClass: (...classes: string[]) => ButtonComponent;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Sets the aria-label attribute for accessibility
|
|
271
|
+
* @param label - Aria label text
|
|
272
|
+
* @returns The button component for chaining
|
|
273
|
+
*/
|
|
274
|
+
setAriaLabel: (label: string) => ButtonComponent;
|
|
263
275
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
// src/components/card/config.ts
|
|
2
|
-
|
|
3
2
|
import {
|
|
4
3
|
createComponentConfig,
|
|
5
4
|
createElementConfig
|
|
6
5
|
} from '../../core/config/component-config';
|
|
7
|
-
import { CARD_VARIANTS, CARD_ELEVATIONS } from './constants';
|
|
8
6
|
import {
|
|
9
7
|
createCardHeader,
|
|
10
8
|
createCardContent,
|
|
@@ -18,7 +16,7 @@ import { CardComponent, CardSchema, ButtonConfig, BaseComponent } from './types'
|
|
|
18
16
|
* @const {CardSchema}
|
|
19
17
|
*/
|
|
20
18
|
export const defaultConfig: CardSchema = {
|
|
21
|
-
variant:
|
|
19
|
+
variant: 'elevated',
|
|
22
20
|
interactive: false,
|
|
23
21
|
fullWidth: false,
|
|
24
22
|
clickable: false,
|
|
@@ -191,6 +189,16 @@ export const getApiConfig = (comp: any) => ({
|
|
|
191
189
|
}
|
|
192
190
|
});
|
|
193
191
|
|
|
192
|
+
/**
|
|
193
|
+
* Card elevation levels
|
|
194
|
+
*/
|
|
195
|
+
export const CARD_ELEVATION_LEVELS = {
|
|
196
|
+
LEVEL0: 0,
|
|
197
|
+
LEVEL1: 1,
|
|
198
|
+
LEVEL2: 2,
|
|
199
|
+
LEVEL4: 4
|
|
200
|
+
};
|
|
201
|
+
|
|
194
202
|
/**
|
|
195
203
|
* Adds interactive behavior to card component
|
|
196
204
|
* Uses the MTRL elevation system for proper elevation levels
|
|
@@ -206,14 +214,14 @@ export const withInteractiveBehavior = (comp: BaseComponent): BaseComponent => {
|
|
|
206
214
|
if (isInteractive) {
|
|
207
215
|
// Mouse interactions
|
|
208
216
|
comp.element.addEventListener('mouseenter', () => {
|
|
209
|
-
if (config.variant ===
|
|
210
|
-
comp.element.style.setProperty('--card-elevation', String(
|
|
217
|
+
if (config.variant === 'elevated') {
|
|
218
|
+
comp.element.style.setProperty('--card-elevation', String(CARD_ELEVATION_LEVELS.LEVEL2));
|
|
211
219
|
}
|
|
212
220
|
});
|
|
213
221
|
|
|
214
222
|
comp.element.addEventListener('mouseleave', () => {
|
|
215
|
-
if (config.variant ===
|
|
216
|
-
comp.element.style.setProperty('--card-elevation', String(
|
|
223
|
+
if (config.variant === 'elevated') {
|
|
224
|
+
comp.element.style.setProperty('--card-elevation', String(CARD_ELEVATION_LEVELS.LEVEL1));
|
|
217
225
|
}
|
|
218
226
|
});
|
|
219
227
|
|
|
@@ -241,7 +249,7 @@ export const withInteractiveBehavior = (comp: BaseComponent): BaseComponent => {
|
|
|
241
249
|
comp.element.setAttribute('draggable', 'true');
|
|
242
250
|
|
|
243
251
|
comp.element.addEventListener('dragstart', (e: DragEvent) => {
|
|
244
|
-
comp.element.style.setProperty('--card-elevation', String(
|
|
252
|
+
comp.element.style.setProperty('--card-elevation', String(CARD_ELEVATION_LEVELS.LEVEL4));
|
|
245
253
|
comp.element.classList.add(`${comp.getClass('card')}--dragging`);
|
|
246
254
|
comp.emit?.('dragstart', { event: e });
|
|
247
255
|
|
|
@@ -254,7 +262,7 @@ export const withInteractiveBehavior = (comp: BaseComponent): BaseComponent => {
|
|
|
254
262
|
});
|
|
255
263
|
|
|
256
264
|
comp.element.addEventListener('dragend', (e: DragEvent) => {
|
|
257
|
-
comp.element.style.setProperty('--card-elevation', String(
|
|
265
|
+
comp.element.style.setProperty('--card-elevation', String(CARD_ELEVATION_LEVELS.LEVEL1));
|
|
258
266
|
comp.element.classList.remove(`${comp.getClass('card')}--dragging`);
|
|
259
267
|
comp.emit?.('dragend', { event: e });
|
|
260
268
|
});
|