@xsolla/xui-context-menu 0.196.0 → 0.197.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -0
- package/native/index.d.mts +15 -0
- package/native/index.d.ts +15 -0
- package/native/index.js +46 -2
- package/native/index.js.map +1 -1
- package/native/index.mjs +46 -2
- package/native/index.mjs.map +1 -1
- package/package.json +10 -10
- package/web/index.d.mts +15 -0
- package/web/index.d.ts +15 -0
- package/web/index.js +51 -3
- package/web/index.js.map +1 -1
- package/web/index.mjs +51 -3
- package/web/index.mjs.map +1 -1
package/README.md
CHANGED
|
@@ -109,6 +109,7 @@ Choose the preset path for typical menus where the data is uniform; choose the c
|
|
|
109
109
|
| `leadingControl` | `"checkbox" \| "radio"` | Renders a `Checkbox` or `Radio` at the start. |
|
|
110
110
|
| `leadingIcon` | `ReactNode` | Icon node before the label group. |
|
|
111
111
|
| `status` | `ReactNode` | Status indicator slot (e.g. `<Status>`). |
|
|
112
|
+
| `statusTopAlignment` | `boolean` | Aligns `status` to the **first line** of the label instead of centring it on the whole cell. Defaults to `true`. |
|
|
112
113
|
| `iconWrapper` | `ReactNode` | Wrapped icon / avatar slot. |
|
|
113
114
|
| `slot` / `slotContent` | `ReactNode` | Generic slot before the label. |
|
|
114
115
|
| `value` | `ReactNode` | Right-side primary text (e.g. shortcut value, dial code). |
|
|
@@ -125,6 +126,33 @@ Choose the preset path for typical menus where the data is uniform; choose the c
|
|
|
125
126
|
|
|
126
127
|
Render order (left → right): `leadingControl`, `leadingIcon`, `status`, `iconWrapper`, `slotContent`, `label` (with optional `description` below), `value` (with optional `hint` below), `keyboardShortcut`, submenu chevron, `trailingIcon`.
|
|
127
128
|
|
|
129
|
+
#### Status alignment
|
|
130
|
+
|
|
131
|
+
Every cell lays its slots out on a single centred row, which reads correctly while the label is one line. As soon as the label wraps or a `description` is present the cell grows taller and a vertically-centred status dot drifts away from the text it annotates.
|
|
132
|
+
|
|
133
|
+
`statusTopAlignment` (default `true`) pins the `status` slot to the top of the cell and sizes it to one label line, so the dot centres on the **first line** of the label and stays there no matter how tall the cell becomes. The line height is read from the label's typography token for the active `size`, so the alignment holds across `sm` / `md` / `lg` / `xl`, both themes, and every responsive breakpoint.
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
// Default — dot sits on the first line of a wrapping label.
|
|
137
|
+
<ContextMenuItem
|
|
138
|
+
type="option"
|
|
139
|
+
label="Deployment blocked by a failing health check"
|
|
140
|
+
description="Retried 3 times in the last hour"
|
|
141
|
+
status={<Status palette="alert" size="lg" />}
|
|
142
|
+
/>
|
|
143
|
+
|
|
144
|
+
// Opt out — dot is centred on the full height of the cell.
|
|
145
|
+
<ContextMenuItem
|
|
146
|
+
type="option"
|
|
147
|
+
label="Deployment blocked by a failing health check"
|
|
148
|
+
description="Retried 3 times in the last hour"
|
|
149
|
+
status={<Status palette="alert" size="lg" />}
|
|
150
|
+
statusTopAlignment={false}
|
|
151
|
+
/>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
> **Breaking change.** `true` is the default, so multi-line cells that already pass a `status` slot will render the indicator higher than before. Pass `statusTopAlignment={false}` to keep the previous centred rendering.
|
|
155
|
+
|
|
128
156
|
### `type="search"`
|
|
129
157
|
|
|
130
158
|
| Prop | Type | Purpose |
|
package/native/index.d.mts
CHANGED
|
@@ -42,7 +42,22 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
42
42
|
description?: ReactNode;
|
|
43
43
|
leadingControl?: "checkbox" | "radio";
|
|
44
44
|
leadingIcon?: ReactNode;
|
|
45
|
+
/** Status indicator slot rendered before the label group (e.g. `<Status />`). */
|
|
45
46
|
status?: ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* Vertical placement of the `status` slot within the cell.
|
|
49
|
+
*
|
|
50
|
+
* - `true` (default) — the indicator is aligned to the **first line** of the
|
|
51
|
+
* label and stays there when the label wraps or a `description` makes the
|
|
52
|
+
* cell taller.
|
|
53
|
+
* - `false` — the indicator is centred on the full height of the cell. This
|
|
54
|
+
* restores the previous behaviour for consumers that depend on it.
|
|
55
|
+
*
|
|
56
|
+
* Has no effect when `status` is not provided.
|
|
57
|
+
*
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
statusTopAlignment?: boolean;
|
|
46
61
|
iconWrapper?: ReactNode;
|
|
47
62
|
slot?: ReactNode;
|
|
48
63
|
slotContent?: ReactNode;
|
package/native/index.d.ts
CHANGED
|
@@ -42,7 +42,22 @@ interface ContextMenuOptionItemProps extends ContextMenuItemBaseProps {
|
|
|
42
42
|
description?: ReactNode;
|
|
43
43
|
leadingControl?: "checkbox" | "radio";
|
|
44
44
|
leadingIcon?: ReactNode;
|
|
45
|
+
/** Status indicator slot rendered before the label group (e.g. `<Status />`). */
|
|
45
46
|
status?: ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* Vertical placement of the `status` slot within the cell.
|
|
49
|
+
*
|
|
50
|
+
* - `true` (default) — the indicator is aligned to the **first line** of the
|
|
51
|
+
* label and stays there when the label wraps or a `description` makes the
|
|
52
|
+
* cell taller.
|
|
53
|
+
* - `false` — the indicator is centred on the full height of the cell. This
|
|
54
|
+
* restores the previous behaviour for consumers that depend on it.
|
|
55
|
+
*
|
|
56
|
+
* Has no effect when `status` is not provided.
|
|
57
|
+
*
|
|
58
|
+
* @default true
|
|
59
|
+
*/
|
|
60
|
+
statusTopAlignment?: boolean;
|
|
46
61
|
iconWrapper?: ReactNode;
|
|
47
62
|
slot?: ReactNode;
|
|
48
63
|
slotContent?: ReactNode;
|
package/native/index.js
CHANGED
|
@@ -258,6 +258,23 @@ var sizeToVariants = {
|
|
|
258
258
|
var sizeLabelOverride = {
|
|
259
259
|
xl: { fontSize: 20, lineHeight: "26px" }
|
|
260
260
|
};
|
|
261
|
+
var labelLineMetrics = {
|
|
262
|
+
bodyLg: { token: "body-lg", scaleStep: "175", lineHeight: "24px" },
|
|
263
|
+
bodyMd: { token: "body-md", scaleStep: "150", lineHeight: "20px" },
|
|
264
|
+
bodySm: { token: "body-sm", scaleStep: "125", lineHeight: "18px" },
|
|
265
|
+
bodyXs: { token: "body-xs", scaleStep: "100", lineHeight: "16px" }
|
|
266
|
+
};
|
|
267
|
+
var toCssLength = (value) => typeof value === "number" ? `${value}px` : value;
|
|
268
|
+
var resolveLabelLineHeight = (theme, size, variant, responsive) => {
|
|
269
|
+
const override = sizeLabelOverride[size];
|
|
270
|
+
if (override) return override.lineHeight;
|
|
271
|
+
const metrics = labelLineMetrics[variant];
|
|
272
|
+
const token = theme?.typographyTokens?.basic?.[metrics.token];
|
|
273
|
+
const lineHeight = toCssLength(token?.lineHeight ?? metrics.lineHeight);
|
|
274
|
+
if (!responsive) return lineHeight;
|
|
275
|
+
const step = token?.scaleStep ?? metrics.scaleStep;
|
|
276
|
+
return `var(--xui-lh-compact-${step}, ${lineHeight})`;
|
|
277
|
+
};
|
|
261
278
|
var SUBMENU_GAP = 8;
|
|
262
279
|
var SUBMENU_VIEWPORT_PADDING = 8;
|
|
263
280
|
var clipsOverflow = (style) => {
|
|
@@ -343,6 +360,7 @@ var OptionCell = ({
|
|
|
343
360
|
leadingControl,
|
|
344
361
|
leadingIcon,
|
|
345
362
|
status,
|
|
363
|
+
statusTopAlignment = true,
|
|
346
364
|
iconWrapper,
|
|
347
365
|
slot,
|
|
348
366
|
slotContent,
|
|
@@ -359,16 +377,24 @@ var OptionCell = ({
|
|
|
359
377
|
themeProductContext,
|
|
360
378
|
"data-testid": testId
|
|
361
379
|
}) => {
|
|
362
|
-
const
|
|
380
|
+
const resolvedTheme = (0, import_xui_core.useResolvedTheme)({
|
|
363
381
|
themeMode,
|
|
364
382
|
themeProductContext
|
|
365
383
|
});
|
|
384
|
+
const { theme: rawTheme } = resolvedTheme;
|
|
385
|
+
const responsive = resolvedTheme.responsive ?? true;
|
|
366
386
|
const theme = rawTheme;
|
|
367
387
|
const overlayLayer = (0, import_xui_core.useOverlayLayer)();
|
|
368
388
|
const ctx = useContextMenu();
|
|
369
389
|
const size = propSize ?? ctx?.size ?? "md";
|
|
370
390
|
const sizing = theme.sizing.contextMenu(size);
|
|
371
391
|
const variants = sizeToVariants[size];
|
|
392
|
+
const labelLineHeight = resolveLabelLineHeight(
|
|
393
|
+
theme,
|
|
394
|
+
size,
|
|
395
|
+
variants.label,
|
|
396
|
+
responsive
|
|
397
|
+
);
|
|
372
398
|
const id = (0, import_xui_core.useId)();
|
|
373
399
|
const registerCell = ctx?.registerCell;
|
|
374
400
|
const unregisterCell = ctx?.unregisterCell;
|
|
@@ -630,7 +656,25 @@ var OptionCell = ({
|
|
|
630
656
|
}
|
|
631
657
|
),
|
|
632
658
|
leadingIcon,
|
|
633
|
-
status,
|
|
659
|
+
status != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
660
|
+
"span",
|
|
661
|
+
{
|
|
662
|
+
"data-testid": "ctxmenu-status",
|
|
663
|
+
"data-status-alignment": statusTopAlignment ? "top" : "center",
|
|
664
|
+
style: {
|
|
665
|
+
display: "inline-flex",
|
|
666
|
+
alignItems: "center",
|
|
667
|
+
flexShrink: 0,
|
|
668
|
+
// Top alignment pins the slot to the top of the row and gives it
|
|
669
|
+
// the height of one label line, so the dot centres on the FIRST
|
|
670
|
+
// line and stays there when the label wraps or a `description`
|
|
671
|
+
// pushes the row taller. Without it the row's `alignItems:center`
|
|
672
|
+
// floats the dot to the middle of a multi-line cell.
|
|
673
|
+
...statusTopAlignment ? { alignSelf: "flex-start", minHeight: labelLineHeight } : {}
|
|
674
|
+
},
|
|
675
|
+
children: status
|
|
676
|
+
}
|
|
677
|
+
),
|
|
634
678
|
iconWrapper,
|
|
635
679
|
slot,
|
|
636
680
|
slotContent,
|