@dloizides/ui-layout 1.50.0 → 1.50.1

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
@@ -277,14 +277,14 @@ function compositeOver(background, surface) {
277
277
  if (top === null || base === null) return null;
278
278
  return mix(base.channels, top.channels, top.alpha);
279
279
  }
280
- function readableRawInk(theme, ink, background) {
281
- const ground = compositeOver(background, theme.colors.surface);
280
+ function readableRawInk(theme, ink, background, ground = theme.colors.surface) {
281
+ const visible = compositeOver(background, ground);
282
282
  const source = isHexColor(ink) ? parseHex(ink) : null;
283
283
  const target = isHexColor(theme.colors.text) ? parseHex(theme.colors.text) : null;
284
- if (ground === null || source === null || target === null) return ink;
284
+ if (visible === null || source === null || target === null) return ink;
285
285
  for (let step = 0; step <= MIX_STEPS; step += 1) {
286
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;
287
+ if (contrastRatio(candidate, visible) >= AA_NORMAL_TEXT_RATIO) return candidate;
288
288
  }
289
289
  return theme.colors.text;
290
290
  }
@@ -2798,6 +2798,11 @@ var CopyStatus = /* @__PURE__ */ ((CopyStatus2) => {
2798
2798
  CopyStatus2["Failed"] = "failed";
2799
2799
  return CopyStatus2;
2800
2800
  })(CopyStatus || {});
2801
+ function readableTone(tone, backgrounds, fallback) {
2802
+ if (!isHexColor(tone) || !backgrounds.every(isHexColor)) return tone;
2803
+ const readable = backgrounds.every((background) => contrastRatio(tone, background) >= AA_NORMAL_TEXT_RATIO);
2804
+ return readable ? tone : fallback;
2805
+ }
2801
2806
 
2802
2807
  // src/CopyableId/copyText.ts
2803
2808
  var OFFSCREEN_POSITION = "-9999px";
@@ -2968,7 +2973,7 @@ var CopyableId = ({
2968
2973
  accessibilityLabel: t(action.key),
2969
2974
  accessibilityHint: t(LAYOUT_I18N.copyHint),
2970
2975
  testID: `${testID}-copy`,
2971
- style: [styles24.action, { color: action.color }],
2976
+ style: [styles24.action, { color: readableTone(action.color, [colors.background, colors.surfaceElevated], colors.text) }],
2972
2977
  children: t(action.key)
2973
2978
  }
2974
2979
  )
@@ -3652,6 +3657,30 @@ var IdChip = ({ label, value, testID, accessibilityLabel, accessibilityHint, dis
3652
3657
  }
3653
3658
  );
3654
3659
  };
3660
+ var STEP_WIDTH = 8;
3661
+ var STEP_OPACITIES = [0.35, 0.65, 0.9];
3662
+ var styles39 = StyleSheet.create({
3663
+ fade: { bottom: 0, flexDirection: "row", position: "absolute", right: 0, top: 0 },
3664
+ step: { width: STEP_WIDTH }
3665
+ });
3666
+ var EdgeFadeStrip = ({ color }) => /* @__PURE__ */ jsx(View, { "aria-hidden": true, pointerEvents: "none", style: styles39.fade, children: STEP_OPACITIES.map((opacity) => /* @__PURE__ */ jsx(View, { style: [styles39.step, { backgroundColor: color, opacity }] }, opacity)) });
3667
+ var SLACK_PX = 1;
3668
+ function showsEdgeFade({ contentWidth, viewportWidth, offset }) {
3669
+ return contentWidth - viewportWidth - offset > SLACK_PX;
3670
+ }
3671
+ function useEdgeFade() {
3672
+ const [metrics, setMetrics] = useState({ contentWidth: 0, viewportWidth: 0, offset: 0 });
3673
+ const onLayout = useCallback((event) => {
3674
+ const viewportWidth = event.nativeEvent.layout.width;
3675
+ setMetrics((prev) => ({ ...prev, viewportWidth }));
3676
+ }, []);
3677
+ const onContentSizeChange = useCallback((contentWidth) => setMetrics((prev) => ({ ...prev, contentWidth })), []);
3678
+ const onScroll = useCallback((event) => {
3679
+ const offset = event.nativeEvent.contentOffset.x;
3680
+ setMetrics((prev) => ({ ...prev, offset }));
3681
+ }, []);
3682
+ return { visible: showsEdgeFade(metrics), onLayout, onContentSizeChange, onScroll };
3683
+ }
3655
3684
  var UNDERLINE = 3;
3656
3685
  var PAD_H4 = 12;
3657
3686
  var GAP6 = 6;
@@ -3661,57 +3690,62 @@ var COUNT_MIN = 22;
3661
3690
  var COUNT_PAD = 6;
3662
3691
  var PILL = 999;
3663
3692
  var DEFAULT_UNDERLINE_STEP = "700";
3664
- var styles39 = StyleSheet.create({
3693
+ var SCROLL_THROTTLE_MS = 16;
3694
+ var styles40 = StyleSheet.create({
3665
3695
  count: { borderRadius: PILL, fontSize: COUNT_FONT, fontWeight: "700", minWidth: COUNT_MIN, paddingHorizontal: COUNT_PAD, textAlign: "center" },
3666
3696
  label: { fontSize: FONT_SIZE4, fontWeight: "600" },
3667
- strip: { borderBottomWidth: 1, width: "100%" },
3697
+ strip: { borderBottomWidth: 1, position: "relative", width: "100%" },
3668
3698
  tab: { alignItems: "center", borderBottomWidth: UNDERLINE, flexDirection: "row", gap: GAP6, justifyContent: "center", minHeight: MIN_TARGET_PX, minWidth: MIN_TARGET_PX, paddingHorizontal: PAD_H4 }
3669
3699
  });
3670
- var UnderlineTabs = ({ tabs, activeKey, onChange, accessibilityLabel, accessibilityHint, underlineColor, testID }) => {
3700
+ var UnderlineTabs = ({ tabs, activeKey, onChange, accessibilityLabel, accessibilityHint, underlineColor, fadeColor, testID }) => {
3671
3701
  const { theme } = useUi();
3672
3702
  const underline = underlineColor ?? theme.palette.primary[DEFAULT_UNDERLINE_STEP];
3673
- return /* @__PURE__ */ jsx(View, { style: [styles39.strip, { borderBottomColor: theme.colors.border }], testID, children: /* @__PURE__ */ jsx(ScrollView, { horizontal: true, accessibilityHint, accessibilityRole: "tablist", "aria-label": accessibilityLabel, showsHorizontalScrollIndicator: false, children: tabs.map((tab) => {
3674
- const selected = tab.key === activeKey;
3675
- return /* @__PURE__ */ jsxs(
3676
- Pressable,
3677
- {
3678
- accessibilityHint: tab.accessibilityHint,
3679
- accessibilityLabel: tab.label,
3680
- accessibilityRole: "tab",
3681
- accessibilityState: { selected },
3682
- "aria-selected": selected,
3683
- style: [styles39.tab, { borderBottomColor: selected ? underline : "transparent" }],
3684
- testID: tab.testID,
3685
- onPress: () => onChange(tab.key),
3686
- children: [
3687
- /* @__PURE__ */ jsx(Text, { style: [styles39.label, { color: selected ? theme.colors.text : theme.colors.textSecondary }], children: tab.label }),
3688
- tab.count === void 0 ? null : /* @__PURE__ */ jsx(Text, { style: [styles39.count, { backgroundColor: theme.colors.border, color: theme.colors.text }], children: String(tab.count) })
3689
- ]
3690
- },
3691
- tab.key
3692
- );
3693
- }) }) });
3703
+ const fade = useEdgeFade();
3704
+ return /* @__PURE__ */ jsxs(View, { style: [styles40.strip, { borderBottomColor: theme.colors.border }], testID, children: [
3705
+ /* @__PURE__ */ jsx(ScrollView, { horizontal: true, accessibilityHint, accessibilityRole: "tablist", "aria-label": accessibilityLabel, scrollEventThrottle: SCROLL_THROTTLE_MS, showsHorizontalScrollIndicator: false, onContentSizeChange: fade.onContentSizeChange, onLayout: fade.onLayout, onScroll: fade.onScroll, children: tabs.map((tab) => {
3706
+ const selected = tab.key === activeKey;
3707
+ return /* @__PURE__ */ jsxs(
3708
+ Pressable,
3709
+ {
3710
+ accessibilityHint: tab.accessibilityHint,
3711
+ accessibilityLabel: tab.label,
3712
+ accessibilityRole: "tab",
3713
+ accessibilityState: { selected },
3714
+ "aria-selected": selected,
3715
+ style: [styles40.tab, { borderBottomColor: selected ? underline : "transparent" }],
3716
+ testID: tab.testID,
3717
+ onPress: () => onChange(tab.key),
3718
+ children: [
3719
+ /* @__PURE__ */ jsx(Text, { style: [styles40.label, { color: selected ? theme.colors.text : theme.colors.textSecondary }], children: tab.label }),
3720
+ tab.count === void 0 ? null : /* @__PURE__ */ jsx(Text, { style: [styles40.count, { backgroundColor: theme.colors.border, color: theme.colors.text }], children: String(tab.count) })
3721
+ ]
3722
+ },
3723
+ tab.key
3724
+ );
3725
+ }) }),
3726
+ fade.visible ? /* @__PURE__ */ jsx(EdgeFadeStrip, { color: fadeColor ?? theme.colors.background }) : null
3727
+ ] });
3694
3728
  };
3695
3729
  var RADIUS3 = 12;
3696
3730
  var PAD = 16;
3697
3731
  var GAP7 = 8;
3698
3732
  var TITLE_FONT = 15;
3699
- var styles40 = StyleSheet.create({
3733
+ var styles41 = StyleSheet.create({
3700
3734
  card: { borderRadius: RADIUS3, borderWidth: 1, gap: GAP7, minWidth: 0, padding: PAD },
3701
- footer: { borderRadius: GAP7, borderWidth: 1, gap: GAP7, padding: PAD / 2 + GAP7 / 2 },
3735
+ footer: { alignItems: "flex-start", flexDirection: "row", flexWrap: "wrap", gap: GAP7 },
3702
3736
  head: { alignItems: "center", flexDirection: "row", gap: GAP7 },
3703
3737
  title: { flex: 1, fontSize: TITLE_FONT, fontWeight: "700" }
3704
3738
  });
3705
3739
  var WidgetCard = ({ title, children, icon, headerRight, footer, testID }) => {
3706
3740
  const { theme } = useUi();
3707
- return /* @__PURE__ */ jsxs(View, { style: [styles40.card, { backgroundColor: theme.colors.surfaceElevated, borderColor: theme.colors.border }], testID, children: [
3708
- /* @__PURE__ */ jsxs(View, { style: styles40.head, children: [
3741
+ return /* @__PURE__ */ jsxs(View, { style: [styles41.card, { backgroundColor: theme.colors.surfaceElevated, borderColor: theme.colors.border }], testID, children: [
3742
+ /* @__PURE__ */ jsxs(View, { style: styles41.head, children: [
3709
3743
  icon === void 0 ? null : /* @__PURE__ */ jsx(View, { "aria-hidden": true, children: icon }),
3710
- /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles40.title, { color: theme.colors.text }], children: title }),
3744
+ /* @__PURE__ */ jsx(Text, { accessibilityRole: "header", style: [styles41.title, { color: theme.colors.text }], children: title }),
3711
3745
  headerRight
3712
3746
  ] }),
3713
3747
  children,
3714
- footer === void 0 ? null : /* @__PURE__ */ jsx(View, { style: [styles40.footer, { backgroundColor: theme.colors.background, borderColor: theme.colors.border }], children: footer })
3748
+ footer === void 0 ? null : /* @__PURE__ */ jsx(View, { style: styles41.footer, children: footer })
3715
3749
  ] });
3716
3750
  };
3717
3751