@dloizides/ui-layout 1.13.0 → 1.15.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/CHANGELOG.md +37 -0
- package/dist/index.d.mts +107 -1
- package/dist/index.d.ts +107 -1
- package/dist/index.js +188 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -62,7 +62,19 @@ var LAYOUT_I18N = {
|
|
|
62
62
|
upgradePromptCta: "settings.billing.upgradePrompt.cta",
|
|
63
63
|
upgradePromptCtaHint: "settings.billing.upgradePrompt.ctaHint",
|
|
64
64
|
upgradePromptDismiss: "settings.billing.upgradePrompt.dismiss",
|
|
65
|
-
upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint"
|
|
65
|
+
upgradePromptDismissHint: "settings.billing.upgradePrompt.dismissHint",
|
|
66
|
+
/** `CopyableId`: the copy control's label in each of its three states, plus its hint. */
|
|
67
|
+
copy: "common.copy",
|
|
68
|
+
copyHint: "common.copyHint",
|
|
69
|
+
copied: "common.copied",
|
|
70
|
+
/**
|
|
71
|
+
* Shown when the clipboard write genuinely failed — non-secure context, denied permission.
|
|
72
|
+
* This string reaching a user is CORRECT behaviour, not a defect: the alternative is them
|
|
73
|
+
* believing they hold an identifier they do not.
|
|
74
|
+
*/
|
|
75
|
+
copyFailed: "common.copyFailed",
|
|
76
|
+
/** `CopyableId`: hint on the value itself, explaining it is shortened for display. */
|
|
77
|
+
copyableIdHint: "common.copyableIdHint"
|
|
66
78
|
};
|
|
67
79
|
var styles2 = StyleSheet.create({
|
|
68
80
|
heading: {
|
|
@@ -1266,6 +1278,176 @@ var TruncatedText = ({
|
|
|
1266
1278
|
);
|
|
1267
1279
|
};
|
|
1268
1280
|
|
|
1269
|
-
|
|
1281
|
+
// src/CopyableId/CopyStatus.ts
|
|
1282
|
+
var CopyStatus = /* @__PURE__ */ ((CopyStatus2) => {
|
|
1283
|
+
CopyStatus2["Idle"] = "idle";
|
|
1284
|
+
CopyStatus2["Copied"] = "copied";
|
|
1285
|
+
CopyStatus2["Failed"] = "failed";
|
|
1286
|
+
return CopyStatus2;
|
|
1287
|
+
})(CopyStatus || {});
|
|
1288
|
+
|
|
1289
|
+
// src/CopyableId/copyText.ts
|
|
1290
|
+
var OFFSCREEN_POSITION = "-9999px";
|
|
1291
|
+
function hasDom() {
|
|
1292
|
+
return typeof document !== "undefined" && document.body !== null;
|
|
1293
|
+
}
|
|
1294
|
+
function copyViaExecCommand(value) {
|
|
1295
|
+
if (!hasDom()) return false;
|
|
1296
|
+
const area = document.createElement("textarea");
|
|
1297
|
+
area.value = value;
|
|
1298
|
+
area.readOnly = true;
|
|
1299
|
+
area.setAttribute("aria-hidden", "true");
|
|
1300
|
+
area.style.position = "fixed";
|
|
1301
|
+
area.style.top = OFFSCREEN_POSITION;
|
|
1302
|
+
area.style.left = OFFSCREEN_POSITION;
|
|
1303
|
+
area.style.opacity = "0";
|
|
1304
|
+
document.body.appendChild(area);
|
|
1305
|
+
try {
|
|
1306
|
+
area.select();
|
|
1307
|
+
area.setSelectionRange(0, value.length);
|
|
1308
|
+
return document.execCommand("copy");
|
|
1309
|
+
} catch {
|
|
1310
|
+
return false;
|
|
1311
|
+
} finally {
|
|
1312
|
+
document.body.removeChild(area);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
function hasAsyncClipboard() {
|
|
1316
|
+
return typeof navigator !== "undefined" && typeof navigator.clipboard?.writeText === "function";
|
|
1317
|
+
}
|
|
1318
|
+
async function copyText(value, writer) {
|
|
1319
|
+
if (value === "") return false;
|
|
1320
|
+
if (writer !== void 0) {
|
|
1321
|
+
try {
|
|
1322
|
+
await writer(value);
|
|
1323
|
+
return true;
|
|
1324
|
+
} catch {
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (hasAsyncClipboard()) {
|
|
1328
|
+
try {
|
|
1329
|
+
await navigator.clipboard.writeText(value);
|
|
1330
|
+
return true;
|
|
1331
|
+
} catch {
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
return copyViaExecCommand(value);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// src/CopyableId/useCopyToClipboard.ts
|
|
1338
|
+
var COPY_FEEDBACK_MS = 2e3;
|
|
1339
|
+
function useCopyToClipboard(value, writer) {
|
|
1340
|
+
const [status, setStatus] = useState("idle" /* Idle */);
|
|
1341
|
+
const timerRef = useRef(null);
|
|
1342
|
+
const mountedRef = useRef(true);
|
|
1343
|
+
useEffect(() => {
|
|
1344
|
+
mountedRef.current = true;
|
|
1345
|
+
return () => {
|
|
1346
|
+
mountedRef.current = false;
|
|
1347
|
+
if (timerRef.current !== null) clearTimeout(timerRef.current);
|
|
1348
|
+
};
|
|
1349
|
+
}, []);
|
|
1350
|
+
const copy = useCallback(() => {
|
|
1351
|
+
void (async () => {
|
|
1352
|
+
const ok = await copyText(value, writer);
|
|
1353
|
+
if (!mountedRef.current) return;
|
|
1354
|
+
setStatus(ok ? "copied" /* Copied */ : "failed" /* Failed */);
|
|
1355
|
+
if (timerRef.current !== null) clearTimeout(timerRef.current);
|
|
1356
|
+
timerRef.current = setTimeout(() => {
|
|
1357
|
+
if (mountedRef.current) setStatus("idle" /* Idle */);
|
|
1358
|
+
}, COPY_FEEDBACK_MS);
|
|
1359
|
+
})();
|
|
1360
|
+
}, [value, writer]);
|
|
1361
|
+
return { status, copy };
|
|
1362
|
+
}
|
|
1363
|
+
var LABEL_FONT_SIZE = 11;
|
|
1364
|
+
var VALUE_FONT_SIZE = 12;
|
|
1365
|
+
var ACTION_FONT_SIZE = 12;
|
|
1366
|
+
var ROW_GAP = 8;
|
|
1367
|
+
var CELL_GAP = 2;
|
|
1368
|
+
var LABEL_LETTER_SPACING = 0.4;
|
|
1369
|
+
var ACTION_PADDING_H = 6;
|
|
1370
|
+
var ACTION_PADDING_V = 2;
|
|
1371
|
+
var ACTION_RADIUS = 6;
|
|
1372
|
+
var styles13 = StyleSheet.create({
|
|
1373
|
+
cell: { gap: CELL_GAP },
|
|
1374
|
+
label: {
|
|
1375
|
+
fontSize: LABEL_FONT_SIZE,
|
|
1376
|
+
fontWeight: "700",
|
|
1377
|
+
letterSpacing: LABEL_LETTER_SPACING,
|
|
1378
|
+
textTransform: "uppercase"
|
|
1379
|
+
},
|
|
1380
|
+
row: { flexDirection: "row", alignItems: "center", gap: ROW_GAP },
|
|
1381
|
+
/**
|
|
1382
|
+
* The truncation width comes from this wrapper, not from the row: `TruncatedText` measures its
|
|
1383
|
+
* PARENT (see `useAvailableWidth`), and the row also holds the button. `minWidth: 0` is what
|
|
1384
|
+
* actually lets a flex child shrink below its content width — without it the row just grows and
|
|
1385
|
+
* nothing ever truncates.
|
|
1386
|
+
*/
|
|
1387
|
+
valueWrap: { flexShrink: 1, minWidth: 0 },
|
|
1388
|
+
value: { fontSize: VALUE_FONT_SIZE, fontWeight: "600" },
|
|
1389
|
+
action: {
|
|
1390
|
+
fontSize: ACTION_FONT_SIZE,
|
|
1391
|
+
fontWeight: "600",
|
|
1392
|
+
paddingHorizontal: ACTION_PADDING_H,
|
|
1393
|
+
paddingVertical: ACTION_PADDING_V,
|
|
1394
|
+
borderRadius: ACTION_RADIUS
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
var TONE_STEP = "500";
|
|
1398
|
+
function useActionState(status) {
|
|
1399
|
+
const { theme } = useUi();
|
|
1400
|
+
return useMemo(() => {
|
|
1401
|
+
const primary = theme.palette.primary[TONE_STEP];
|
|
1402
|
+
if (status === "copied" /* Copied */) {
|
|
1403
|
+
return { key: LAYOUT_I18N.copied, color: theme.semantic.success?.[TONE_STEP] ?? primary };
|
|
1404
|
+
}
|
|
1405
|
+
if (status === "failed" /* Failed */) {
|
|
1406
|
+
return { key: LAYOUT_I18N.copyFailed, color: theme.semantic.error[TONE_STEP] };
|
|
1407
|
+
}
|
|
1408
|
+
return { key: LAYOUT_I18N.copy, color: primary };
|
|
1409
|
+
}, [status, theme]);
|
|
1410
|
+
}
|
|
1411
|
+
var CopyableId = ({
|
|
1412
|
+
value,
|
|
1413
|
+
label,
|
|
1414
|
+
testID,
|
|
1415
|
+
accessibilityLabel,
|
|
1416
|
+
writer
|
|
1417
|
+
}) => {
|
|
1418
|
+
const { theme, t } = useUi();
|
|
1419
|
+
const { colors } = theme;
|
|
1420
|
+
const { status, copy } = useCopyToClipboard(value, writer);
|
|
1421
|
+
const action = useActionState(status);
|
|
1422
|
+
return /* @__PURE__ */ jsxs(View, { style: styles13.cell, testID, children: [
|
|
1423
|
+
label !== void 0 && /* @__PURE__ */ jsx(Text, { style: [styles13.label, { color: colors.textSecondary }], children: label }),
|
|
1424
|
+
/* @__PURE__ */ jsxs(View, { style: styles13.row, children: [
|
|
1425
|
+
/* @__PURE__ */ jsx(View, { style: styles13.valueWrap, children: /* @__PURE__ */ jsx(
|
|
1426
|
+
TruncatedText,
|
|
1427
|
+
{
|
|
1428
|
+
value,
|
|
1429
|
+
style: [styles13.value, { color: colors.text }],
|
|
1430
|
+
testID: `${testID}-value`,
|
|
1431
|
+
accessibilityLabel: accessibilityLabel ?? value,
|
|
1432
|
+
accessibilityHint: t(LAYOUT_I18N.copyableIdHint)
|
|
1433
|
+
}
|
|
1434
|
+
) }),
|
|
1435
|
+
/* @__PURE__ */ jsx(
|
|
1436
|
+
Text,
|
|
1437
|
+
{
|
|
1438
|
+
onPress: copy,
|
|
1439
|
+
accessibilityRole: "button",
|
|
1440
|
+
accessibilityLabel: t(action.key),
|
|
1441
|
+
accessibilityHint: t(LAYOUT_I18N.copyHint),
|
|
1442
|
+
testID: `${testID}-copy`,
|
|
1443
|
+
style: [styles13.action, { color: action.color }],
|
|
1444
|
+
children: t(action.key)
|
|
1445
|
+
}
|
|
1446
|
+
)
|
|
1447
|
+
] })
|
|
1448
|
+
] });
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1451
|
+
export { Accordion, AccordionItem, COPY_FEEDBACK_MS, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, Heading, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, TruncatedText, UpgradePrompt, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
|
|
1270
1452
|
//# sourceMappingURL=index.mjs.map
|
|
1271
1453
|
//# sourceMappingURL=index.mjs.map
|