mtrl 0.8.0-next.49 → 0.8.0-next.50

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 (79) hide show
  1. package/dist/components/button-group/button-group.js +6 -4
  2. package/dist/components/button-group/config.d.ts +1 -1
  3. package/dist/components/button-group/config.js +7 -7
  4. package/dist/components/button-group/constants.d.ts +8 -0
  5. package/dist/components/button-group/constants.js +1 -0
  6. package/dist/components/card/config.js +4 -4
  7. package/dist/components/card/features.js +2 -2
  8. package/dist/components/carousel/features/scroll.js +2 -2
  9. package/dist/components/divider/divider.d.ts +1 -1
  10. package/dist/components/drawer/drawer.js +1 -1
  11. package/dist/components/slider/types.d.ts +2 -1
  12. package/dist/index.cjs +11 -11
  13. package/dist/package.json +1 -1
  14. package/dist/styles/badge.css +1 -1
  15. package/dist/styles/base.css +2 -2
  16. package/dist/styles/bottom-app-bar.css +1 -1
  17. package/dist/styles/bottom-sheet.css +1 -1
  18. package/dist/styles/button-group.css +2 -2
  19. package/dist/styles/button.css +1 -1
  20. package/dist/styles/card.css +2 -2
  21. package/dist/styles/carousel.css +1 -1
  22. package/dist/styles/checkbox.css +1 -1
  23. package/dist/styles/chips.css +2 -2
  24. package/dist/styles/dialog.css +2 -2
  25. package/dist/styles/divider.css +1 -1
  26. package/dist/styles/drawer.css +2 -2
  27. package/dist/styles/extended-fab.css +2 -2
  28. package/dist/styles/fab.css +1 -1
  29. package/dist/styles/icon-button.css +2 -2
  30. package/dist/styles/list.css +2 -2
  31. package/dist/styles/loading-indicator.css +1 -1
  32. package/dist/styles/menu.css +1 -1
  33. package/dist/styles/navigation-rail.css +1 -1
  34. package/dist/styles/navigation.css +1 -1
  35. package/dist/styles/progress.css +1 -1
  36. package/dist/styles/radios.css +1 -1
  37. package/dist/styles/search.css +1 -1
  38. package/dist/styles/segmented-button.css +2 -2
  39. package/dist/styles/select.css +1 -1
  40. package/dist/styles/side-sheet.css +2 -2
  41. package/dist/styles/slider.css +1 -1
  42. package/dist/styles/snackbar.css +1 -1
  43. package/dist/styles/split-button.css +1 -1
  44. package/dist/styles/switch.css +1 -1
  45. package/dist/styles/tabs.css +1 -1
  46. package/dist/styles/textfield.css +1 -1
  47. package/dist/styles/timepicker.css +1 -1
  48. package/dist/styles/top-app-bar.css +2 -2
  49. package/dist/styles/utilities.css +1 -1
  50. package/dist/styles.css +2 -2
  51. package/dist/themes/autumn.css +1 -1
  52. package/dist/themes/baseline.css +1 -1
  53. package/dist/themes/brownbeige.css +1 -1
  54. package/dist/themes/browngreen.css +1 -1
  55. package/dist/themes/desert.css +1 -1
  56. package/dist/themes/forest.css +1 -1
  57. package/dist/themes/highcontrast.css +1 -1
  58. package/dist/themes/legacy.css +1 -1
  59. package/dist/themes/material.css +1 -1
  60. package/dist/themes/ocean.css +1 -1
  61. package/dist/themes/sageivory.css +1 -1
  62. package/dist/themes/spring.css +1 -1
  63. package/dist/themes/summer.css +1 -1
  64. package/dist/themes/sunset.css +1 -1
  65. package/dist/themes/tealcaramel.css +1 -1
  66. package/dist/themes/winter.css +1 -1
  67. package/package.json +1 -1
  68. package/src/styles/abstract/_variables.scss +1 -1
  69. package/src/styles/components/_button-group.scss +58 -38
  70. package/src/styles/components/_card.scss +1 -1
  71. package/src/styles/components/_carousel.scss +3 -3
  72. package/src/styles/components/_chips.scss +2 -2
  73. package/src/styles/components/_drawer.scss +4 -4
  74. package/src/styles/components/_extended-fab.scss +16 -16
  75. package/src/styles/components/_icon-button.scss +54 -7
  76. package/src/styles/components/_list.scss +2 -2
  77. package/src/styles/components/_navigation-system.scss +3 -1
  78. package/src/styles/components/_segmented-button.scss +43 -43
  79. package/src/styles/components/_slider.scss +10 -10
@@ -5,7 +5,7 @@ import { createEmitter } from "../../core/state/emitter.js";
5
5
  import createIconButton from "../icon-button/icon-button.js";
6
6
  import createButton from "../button/index.js";
7
7
  import { createBaseConfig, getContainerConfig, getSizeStyles, getButtonConfig } from "./config.js";
8
- import { BUTTON_GROUP_DEFAULTS, BUTTON_GROUP_DENSITY, BUTTON_GROUP_EXPANDED_RATIO } from "./constants.js";
8
+ import { BUTTON_GROUP_DEFAULTS, BUTTON_GROUP_DENSITY, BUTTON_GROUP_EXPANDED_RATIO, BUTTON_GROUP_COMPRESSION_LIMIT } from "./constants.js";
9
9
  const createButtonGroup = (config = {}) => {
10
10
  const baseConfig = createBaseConfig(config);
11
11
  const emitter = createEmitter();
@@ -19,7 +19,7 @@ const createButtonGroup = (config = {}) => {
19
19
  try {
20
20
  const component = pipe(createBase, withEvents(), withElement(getContainerConfig(baseConfig)), withLifecycle())(baseConfig);
21
21
  const applySizeStyles = (density) => {
22
- Object.entries(getSizeStyles(baseConfig.size, kind, density)).forEach(([prop, value]) => {
22
+ Object.entries(getSizeStyles(baseConfig.prefix, baseConfig.size, kind, density)).forEach(([prop, value]) => {
23
23
  component.element.style.setProperty(prop, value);
24
24
  });
25
25
  };
@@ -76,11 +76,13 @@ const createButtonGroup = (config = {}) => {
76
76
  const share = expandedRatio * widths[index] / (middle ? 2 : 1);
77
77
  let growth = 0;
78
78
  const compress = (i, side) => {
79
- const limit = Math.min(share, padding(i, side), widths[i]);
79
+ const limit = Math.min(share, BUTTON_GROUP_COMPRESSION_LIMIT, widths[i]);
80
80
  if (limit <= 0)
81
81
  return;
82
82
  buttons[i].element.style.width = `${widths[i] - limit}px`;
83
- buttons[i].element.style[side] = `${padding(i, side) - limit}px`;
83
+ const facing = padding(i, side);
84
+ if (facing > 0)
85
+ buttons[i].element.style[side] = `${Math.max(0, facing - limit)}px`;
84
86
  growth += limit;
85
87
  };
86
88
  if (previous >= 0)
@@ -40,7 +40,7 @@ export declare const getContainerConfig: (config: ButtonGroupConfig) => {
40
40
  * (Material 3 button group specs). Density lowers the container height by
41
41
  * 4dp per step; the buttons follow the container height.
42
42
  */
43
- export declare const getSizeStyles: (size: ButtonGroupConfig["size"], kind: ButtonGroupConfig["kind"], density?: ButtonGroupDensity) => Record<string, string>;
43
+ export declare const getSizeStyles: (prefix: string, size: ButtonGroupConfig["size"], kind: ButtonGroupConfig["kind"], density?: ButtonGroupDensity) => Record<string, string>;
44
44
  /**
45
45
  * Generates configuration for a button element within the group
46
46
  * @param {Object} buttonConfig - Button configuration
@@ -62,17 +62,17 @@ const DENSITY_STEPS = {
62
62
  [BUTTON_GROUP_DENSITY.COMFORTABLE]: 1,
63
63
  [BUTTON_GROUP_DENSITY.COMPACT]: 2
64
64
  };
65
- export const getSizeStyles = (size, kind, density = BUTTON_GROUP_DENSITY.DEFAULT) => {
65
+ export const getSizeStyles = (prefix, size, kind, density = BUTTON_GROUP_DENSITY.DEFAULT) => {
66
66
  const tokens = BUTTON_GROUP_SIZE_TOKENS[size || BUTTON_GROUP_DEFAULTS.SIZE] || BUTTON_GROUP_SIZE_TOKENS.s;
67
67
  const gap = kind === 'connected' ? BUTTON_GROUP_CONNECTED_GAP : tokens.standardGap;
68
68
  const height = tokens.height - BUTTON_GROUP_DENSITY_STEP * (DENSITY_STEPS[density] ?? 0);
69
69
  return {
70
- '--button-group-height': `${height}px`,
71
- '--button-group-icon': `${tokens.icon}px`,
72
- '--button-group-gap': `${gap}px`,
73
- '--button-group-inner-corner': `${tokens.connectedCorner}px`,
74
- '--button-group-pressed-corner': `${BUTTON_GROUP_CONNECTED_PRESSED_CORNER}px`,
75
- '--button-group-radius': `${height / 2}px`
70
+ [`--${prefix}-button-group-height`]: `${height}px`,
71
+ [`--${prefix}-button-group-icon`]: `${tokens.icon}px`,
72
+ [`--${prefix}-button-group-gap`]: `${gap}px`,
73
+ [`--${prefix}-button-group-inner-corner`]: `${tokens.connectedCorner}px`,
74
+ [`--${prefix}-button-group-pressed-corner`]: `${BUTTON_GROUP_CONNECTED_PRESSED_CORNER}px`,
75
+ [`--${prefix}-button-group-radius`]: `${height / 2}px`
76
76
  };
77
77
  };
78
78
  export const getButtonConfig = (buttonConfig, index, total, groupConfig) => {
@@ -119,6 +119,14 @@ export declare const BUTTON_GROUP_CONNECTED_MIN_WIDTH = 48;
119
119
  * its neighbours give up the difference (ButtonGroupDefaults.ExpandedRatio)
120
120
  */
121
121
  export declare const BUTTON_GROUP_EXPANDED_RATIO = 0.15;
122
+ /**
123
+ * The most a neighbour gives up when a button in a standard group is pressed:
124
+ * the trailing content padding of a button (Compose ButtonGroup compression
125
+ * limit, ButtonDefaults.ContentPadding end, BaselineButtonTokens.TrailingSpace).
126
+ * It applies to every neighbour, so an icon button with no padding still makes
127
+ * room for the pressed button.
128
+ */
129
+ export declare const BUTTON_GROUP_COMPRESSION_LIMIT = 24;
122
130
  /** Density reduces the container height by 4dp per step */
123
131
  export declare const BUTTON_GROUP_DENSITY_STEP = 4;
124
132
  /**
@@ -51,6 +51,7 @@ export const BUTTON_GROUP_CONNECTED_GAP = 2;
51
51
  export const BUTTON_GROUP_CONNECTED_PRESSED_CORNER = 4;
52
52
  export const BUTTON_GROUP_CONNECTED_MIN_WIDTH = 48;
53
53
  export const BUTTON_GROUP_EXPANDED_RATIO = 0.15;
54
+ export const BUTTON_GROUP_COMPRESSION_LIMIT = 24;
54
55
  export const BUTTON_GROUP_DENSITY_STEP = 4;
55
56
  export const BUTTON_GROUP_LABELS = {
56
57
  ALWAYS: 'always',
@@ -117,12 +117,12 @@ export const withInteractiveBehavior = (comp) => {
117
117
  if (isInteractive) {
118
118
  comp.element.addEventListener("mouseenter", () => {
119
119
  if (config.variant === CARD_VARIANTS.ELEVATED) {
120
- comp.element.style.setProperty("--card-elevation", String(CARD_ELEVATION_LEVELS.LEVEL2));
120
+ comp.element.style.setProperty(`--${config.prefix}-card-elevation`, String(CARD_ELEVATION_LEVELS.LEVEL2));
121
121
  }
122
122
  });
123
123
  comp.element.addEventListener("mouseleave", () => {
124
124
  if (config.variant === CARD_VARIANTS.ELEVATED) {
125
- comp.element.style.setProperty("--card-elevation", String(CARD_ELEVATION_LEVELS.LEVEL1));
125
+ comp.element.style.setProperty(`--${config.prefix}-card-elevation`, String(CARD_ELEVATION_LEVELS.LEVEL1));
126
126
  }
127
127
  });
128
128
  comp.element.addEventListener("keydown", (e) => {
@@ -141,7 +141,7 @@ export const withInteractiveBehavior = (comp) => {
141
141
  if (config.draggable) {
142
142
  comp.element.setAttribute("draggable", "true");
143
143
  comp.element.addEventListener("dragstart", (e) => {
144
- comp.element.style.setProperty("--card-elevation", String(CARD_ELEVATION_LEVELS.LEVEL4));
144
+ comp.element.style.setProperty(`--${config.prefix}-card-elevation`, String(CARD_ELEVATION_LEVELS.LEVEL4));
145
145
  comp.element.classList.add(`${comp.getClass("card")}--dragging`);
146
146
  comp.emit?.("dragstart", { event: e });
147
147
  if (e.dataTransfer) {
@@ -151,7 +151,7 @@ export const withInteractiveBehavior = (comp) => {
151
151
  }
152
152
  });
153
153
  comp.element.addEventListener("dragend", (e) => {
154
- comp.element.style.setProperty("--card-elevation", String(CARD_ELEVATION_LEVELS.LEVEL1));
154
+ comp.element.style.setProperty(`--${config.prefix}-card-elevation`, String(CARD_ELEVATION_LEVELS.LEVEL1));
155
155
  comp.element.classList.remove(`${comp.getClass("card")}--dragging`);
156
156
  comp.emit?.("dragend", { event: e });
157
157
  });
@@ -47,10 +47,10 @@ export const withLoading = (config = {}) => (component) => {
47
47
  export const withElevation = (component) => {
48
48
  const config = component.config;
49
49
  if (config.variant === "elevated") {
50
- component.element.style.setProperty("--card-elevation", String(CARD_ELEVATION_LEVELS.LEVEL1));
50
+ component.element.style.setProperty(`--${config.prefix}-card-elevation`, String(CARD_ELEVATION_LEVELS.LEVEL1));
51
51
  }
52
52
  else {
53
- component.element.style.setProperty("--card-elevation", String(CARD_ELEVATION_LEVELS.LEVEL0));
53
+ component.element.style.setProperty(`--${config.prefix}-card-elevation`, String(CARD_ELEVATION_LEVELS.LEVEL0));
54
54
  }
55
55
  return component;
56
56
  };
@@ -121,7 +121,7 @@ export const withScroll = (config) => (component) => {
121
121
  el.style[vertical ? "height" : "width"] = `${strategy.itemSize}px`;
122
122
  el.style[vertical ? "width" : "height"] = "";
123
123
  });
124
- element.style.setProperty("--mtrl-carousel-corner", `${cornerRadius}px`);
124
+ element.style.setProperty(`--${config.prefix}-carousel-corner`, `${cornerRadius}px`);
125
125
  };
126
126
  const layout = () => {
127
127
  if (!strategy)
@@ -154,7 +154,7 @@ export const withScroll = (config) => (component) => {
154
154
  el.style.clipPath = vertical
155
155
  ? `inset(${inset}px 0 round ${cornerRadius}px)`
156
156
  : `inset(0 ${inset}px round ${cornerRadius}px)`;
157
- el.style.setProperty("--mtrl-carousel-fade", fade.toFixed(3));
157
+ el.style.setProperty(`--${config.prefix}-carousel-fade`, fade.toFixed(3));
158
158
  }
159
159
  if (pending !== null) {
160
160
  if (Math.abs(scrollPosition() - (snapPositions[pending] ?? 0)) < 1)
@@ -31,7 +31,7 @@ import { DividerComponent } from "./types.js";
31
31
  * });
32
32
  *
33
33
  * // Later, change the divider's appearance
34
- * divider.setColor('var(--md-sys-color-outline)');
34
+ * divider.setColor('var(--mtrl-sys-color-outline)');
35
35
  * divider.setThickness(1);
36
36
  * divider.setVariant('inset');
37
37
  * ```
@@ -17,7 +17,7 @@ const createDrawer = (config = {}) => {
17
17
  ? `${width}px`
18
18
  : width
19
19
  : `${DRAWER_DEFAULTS.WIDTH}px`;
20
- component.element.style.setProperty("--drawer-width", widthValue);
20
+ component.element.style.setProperty(`--${baseConfig.prefix}-drawer-width`, widthValue);
21
21
  if (component.headlineElement) {
22
22
  sheetEl.appendChild(component.headlineElement);
23
23
  }
@@ -28,7 +28,8 @@ export interface SliderConfig extends BaseComponentConfig {
28
28
  disabled?: boolean;
29
29
  /** Color variant of the slider *
30
30
  * A stylesheet can override the drawn colours per slider with the custom
31
- * properties --mtrl-slider-color and --mtrl-slider-on-color.
31
+ * properties `--<prefix>-slider-color` and `--<prefix>-slider-on-color`,
32
+ * where `<prefix>` is the configured component prefix (mtrl by default).
32
33
  */
33
34
  color?: SliderColor;
34
35
  /** Size variant of the slider */