@dloizides/ui-layout 1.49.2 → 1.50.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/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import React16, { createContext, useMemo, useState, useRef, useEffect, useCallba
2
2
  import { StyleSheet, Platform, Text, View, useWindowDimensions, Modal as Modal$1, Animated, ScrollView, TouchableOpacity, Pressable, FlatList, Easing } from 'react-native';
3
3
  import { MODAL_OVERLAY_COLOR, useUi } from '@dloizides/ui-feedback';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
- import { Z_INDEX, UI_MAIN_STEP, UI_DEEP_STEP, isHexColor, canCarryAccessibleInk, resolveOnBrand } from '@dloizides/design-tokens';
5
+ import { Z_INDEX, UI_MAIN_STEP, UI_DEEP_STEP, isHexColor, canCarryAccessibleInk, resolveOnBrand, contrastRatio, AA_NORMAL_TEXT_RATIO } from '@dloizides/design-tokens';
6
6
  import { IconButton, Button } from '@dloizides/ui-buttons';
7
7
  import { SvgIcon } from '@dloizides/ui-icons';
8
8
  import { useEnterExit, Collapse } from '@dloizides/ui-motion';
@@ -251,6 +251,43 @@ var BadgeTone = /* @__PURE__ */ ((BadgeTone2) => {
251
251
  BadgeTone2["Danger"] = "danger";
252
252
  return BadgeTone2;
253
253
  })(BadgeTone || {});
254
+ var CHANNEL_MAX = 255;
255
+ var HEX_RADIX = 16;
256
+ var CHANNEL_WIDTH = 2;
257
+ var RGB_LENGTH = 6;
258
+ var RGBA_LENGTH = 8;
259
+ var MIX_STEPS = 10;
260
+ function parseHex(value) {
261
+ const digits = value.trim().replace(/^#/, "").toLowerCase();
262
+ if (!/^[0-9a-f]+$/.test(digits) || digits.length !== RGB_LENGTH && digits.length !== RGBA_LENGTH) return null;
263
+ const pairs = digits.match(/../g) ?? [];
264
+ const numbers = pairs.map((pair) => parseInt(pair, HEX_RADIX));
265
+ const alpha = digits.length === RGBA_LENGTH ? (numbers[RGB_LENGTH / CHANNEL_WIDTH] ?? CHANNEL_MAX) / CHANNEL_MAX : 1;
266
+ return { channels: numbers.slice(0, RGB_LENGTH / CHANNEL_WIDTH), alpha };
267
+ }
268
+ function toHex(channels) {
269
+ return `#${channels.map((channel) => Math.round(channel).toString(HEX_RADIX).padStart(CHANNEL_WIDTH, "0")).join("")}`;
270
+ }
271
+ function mix(from, to, weight) {
272
+ return toHex(from.map((channel, index) => channel * (1 - weight) + (to[index] ?? channel) * weight));
273
+ }
274
+ function compositeOver(background, surface) {
275
+ const top = parseHex(background);
276
+ const base = isHexColor(surface) ? parseHex(surface) : null;
277
+ if (top === null || base === null) return null;
278
+ return mix(base.channels, top.channels, top.alpha);
279
+ }
280
+ function readableRawInk(theme, ink, background) {
281
+ const ground = compositeOver(background, theme.colors.surface);
282
+ const source = isHexColor(ink) ? parseHex(ink) : null;
283
+ const target = isHexColor(theme.colors.text) ? parseHex(theme.colors.text) : null;
284
+ if (ground === null || source === null || target === null) return ink;
285
+ for (let step = 0; step <= MIX_STEPS; step += 1) {
286
+ const candidate = step === 0 ? ink : mix(source.channels, target.channels, step / MIX_STEPS);
287
+ if (contrastRatio(candidate, ground) >= AA_NORMAL_TEXT_RATIO) return candidate;
288
+ }
289
+ return theme.colors.text;
290
+ }
254
291
  function scaleFor(theme, tone) {
255
292
  const semantic = theme.semantic;
256
293
  if (tone === "danger" /* Danger */) return theme.semantic.error;
@@ -317,8 +354,11 @@ var StatusBadge = ({
317
354
  }) => {
318
355
  const { t, theme } = useUi();
319
356
  const toned = useMemo(() => resolveToneColors(theme, tone), [theme, tone]);
320
- const color = rawColor ?? toned.color;
321
357
  const backgroundColor = rawBackground ?? toned.backgroundColor;
358
+ const color = useMemo(
359
+ () => rawColor === void 0 ? toned.color : readableRawInk(theme, rawColor, backgroundColor),
360
+ [rawColor, toned.color, theme, backgroundColor]
361
+ );
322
362
  const dynamicBadge = useMemo(() => ({ backgroundColor }), [backgroundColor]);
323
363
  const dashedColor = useMemo(() => ({ borderColor: color }), [color]);
324
364
  const dynamicText = useMemo(() => ({ color }), [color]);
@@ -410,12 +450,17 @@ var styles6 = StyleSheet.create({
410
450
  stackPane: { width: "100%", minWidth: 0 },
411
451
  fixedPane: { flexGrow: 0, flexShrink: 0, minWidth: 0 }
412
452
  });
453
+ function sidePaneStyle(weight, fixedWidth) {
454
+ if (fixedWidth === void 0) return [styles6.sidePane, { flexGrow: weight }];
455
+ return [styles6.fixedPane, { width: fixedWidth }];
456
+ }
413
457
  var SplitPanes = ({
414
458
  start,
415
459
  end,
416
460
  layout = "auto" /* Auto */,
417
461
  startWeight = DEFAULT_WEIGHT,
418
462
  endWeight = DEFAULT_WEIGHT,
463
+ startWidth,
419
464
  endWidth,
420
465
  gap = DEFAULT_GAP,
421
466
  breakpoint = LAYOUT_COLLAPSE_BREAKPOINT,
@@ -424,9 +469,8 @@ var SplitPanes = ({
424
469
  const { width } = useWindowDimensions();
425
470
  const isSide = isSplitSideBySide(layout, width, breakpoint);
426
471
  const container = useMemo(() => [isSide ? styles6.row : styles6.column, { gap }], [isSide, gap]);
427
- const startStyle = isSide ? [styles6.sidePane, { flexGrow: startWeight }] : styles6.stackPane;
428
- const sideEnd = endWidth === void 0 ? [styles6.sidePane, { flexGrow: endWeight }] : [styles6.fixedPane, { width: endWidth }];
429
- const endStyle = isSide ? sideEnd : styles6.stackPane;
472
+ const startStyle = isSide ? sidePaneStyle(startWeight, startWidth) : styles6.stackPane;
473
+ const endStyle = isSide ? sidePaneStyle(endWeight, endWidth) : styles6.stackPane;
430
474
  return /* @__PURE__ */ jsxs(View, { style: container, testID, children: [
431
475
  /* @__PURE__ */ jsx(View, { style: startStyle, testID: `${testID}-start`, children: start }),
432
476
  /* @__PURE__ */ jsx(View, { style: endStyle, testID: `${testID}-end`, children: end })
@@ -3252,6 +3296,12 @@ var ListRow = ({
3252
3296
  ] });
3253
3297
  };
3254
3298
 
3299
+ // src/ListRow/utils/rowSelection.ts
3300
+ function rowSelection(isDesktop, rowKey, keys) {
3301
+ if (isDesktop) return { selected: keys.shownKey === rowKey, style: "accent-bar" /* AccentBar */ };
3302
+ return { selected: keys.selectedKey === rowKey, style: "outline" /* Outline */ };
3303
+ }
3304
+
3255
3305
  // src/SectionIndexLayout/ChipOverflow.ts
3256
3306
  var ChipOverflow = /* @__PURE__ */ ((ChipOverflow2) => {
3257
3307
  ChipOverflow2["Wrap"] = "wrap";
@@ -3665,6 +3715,6 @@ var WidgetCard = ({ title, children, icon, headerRight, footer, testID }) => {
3665
3715
  ] });
3666
3716
  };
3667
3717
 
3668
- export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BadgeTone, BottomSheet, Breadcrumb, BuildInfoFooter, COPY_FEEDBACK_MS, ChipOverflow, ConfirmDialog, ConfirmDialogFocus, CopyStatus, CopyableId, CountBadge, DEFAULT_BILLING_ROUTE, DayCard, DropdownVariant, ELLIPSIS, FigureStrip, FormDialog, HEADER_STACK_BREAKPOINT, Heading, IdChip, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, RecordActionButton, RecordHeader, RowSelectedStyle, SECTION_INDEX_BREAKPOINT, ScreenColumn, Section, SectionChips, SectionDensity, SectionIndex, SectionIndexLayout, SectionVariant, SegmentedControl, SelectedMarker, SideSheet, SplitLayout, SplitPanes, StatusBadge, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TextKind, Timeline, ToggleSection, TruncatedText, UnderlineTabs, UpgradePrompt, WidgetCard, copyText, figureCell, formatBuildInfo, formatCount, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isRecordHeaderCompact, isSplitSideBySide, isWideWebViewport, pageScale, resolveActiveKey, resolveRowLook, resolveToneColors, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
3718
+ export { A4_PAGE, API_COMMIT_SEPARATOR, Accordion, AccordionItem, AppText, BUILD_INFO_PREFIX, BadgeTone, BottomSheet, Breadcrumb, BuildInfoFooter, COPY_FEEDBACK_MS, ChipOverflow, ConfirmDialog, ConfirmDialogFocus, CopyStatus, CopyableId, CountBadge, DEFAULT_BILLING_ROUTE, DayCard, DropdownVariant, ELLIPSIS, FigureStrip, FormDialog, HEADER_STACK_BREAKPOINT, Heading, IdChip, LAYOUT_COLLAPSE_BREAKPOINT, LAYOUT_I18N, LAYOUT_TEST_IDS, ListRow, MIN_TARGET_PX, MODAL_FOOTER_STACK_BELOW, Modal, ModalDropdown, ModalShell, PageFrame, RecordActionButton, RecordHeader, RowSelectedStyle, SECTION_INDEX_BREAKPOINT, ScreenColumn, Section, SectionChips, SectionDensity, SectionIndex, SectionIndexLayout, SectionVariant, SegmentedControl, SelectedMarker, SideSheet, SplitLayout, SplitPanes, StatusBadge, StickyPreview, TYPE_SCALE_BREAKPOINT, Tabs, TabsCollapsedTrigger, TextKind, Timeline, ToggleSection, TruncatedText, UnderlineTabs, UpgradePrompt, WidgetCard, copyText, figureCell, formatBuildInfo, formatCount, formatUrlForDisplay, isKeyboardOpen, isModalFooterStacked, isRecordHeaderCompact, isSplitSideBySide, isWideWebViewport, pageScale, resolveActiveKey, resolveRowLook, resolveToneColors, rowSelection, scaledFrame, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap, useIsWideViewport, useListRowTone, useVisibleViewport };
3669
3719
  //# sourceMappingURL=index.mjs.map
3670
3720
  //# sourceMappingURL=index.mjs.map