@dloizides/ui-layout 1.19.0 → 1.21.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
@@ -1,7 +1,7 @@
1
1
  import React9, { createContext, useMemo, useRef, useEffect, useState, useCallback, useContext, useLayoutEffect } from 'react';
2
2
  import { StyleSheet, Platform, View, Text, Pressable, TouchableOpacity, Modal, FlatList, ScrollView, Animated, Easing, useWindowDimensions, LayoutAnimation, UIManager } from 'react-native';
3
3
  import { MODAL_OVERLAY_COLOR, useUi } from '@dloizides/ui-feedback';
4
- import { jsx, jsxs } from 'react/jsx-runtime';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { useA11y } from '@dloizides/a11y';
6
6
  import { createPortal } from 'react-dom';
7
7
  import { SvgIcon } from '@dloizides/ui-icons';
@@ -230,6 +230,13 @@ function SegmentedControl({
230
230
  }
231
231
  );
232
232
  }
233
+
234
+ // src/Tabs/TabsCollapsedTrigger.ts
235
+ var TabsCollapsedTrigger = /* @__PURE__ */ ((TabsCollapsedTrigger2) => {
236
+ TabsCollapsedTrigger2["Caret"] = "caret";
237
+ TabsCollapsedTrigger2["Hamburger"] = "hamburger";
238
+ return TabsCollapsedTrigger2;
239
+ })(TabsCollapsedTrigger || {});
233
240
  var FOCUSABLE_SELECTOR = [
234
241
  "a[href]",
235
242
  "button:not([disabled])",
@@ -634,6 +641,14 @@ var MODAL_MIN_WIDTH = 200;
634
641
  var MODAL_MAX_HEIGHT = 300;
635
642
  var CONTAINER_PADDING_H = 12;
636
643
  var CONTAINER_PADDING_V = 10;
644
+ var MIN_TOUCH_TARGET = 44;
645
+ var CARET_FONT_SIZE = 12;
646
+ var CARET_GAP = 8;
647
+ var CARET_GLYPH = "\u25BE";
648
+ var HAMBURGER_GLYPH = "\u2630";
649
+ var HAMBURGER_FONT_SIZE = 18;
650
+ var CARET_OPEN_ROTATION = "180deg";
651
+ var CARET_CLOSED_ROTATION = "0deg";
637
652
  var styles7 = StyleSheet.create({
638
653
  anchor: { position: "relative" },
639
654
  container: {
@@ -642,7 +657,30 @@ var styles7 = StyleSheet.create({
642
657
  paddingHorizontal: CONTAINER_PADDING_H,
643
658
  paddingVertical: CONTAINER_PADDING_V
644
659
  },
660
+ // Caret variant: a row with the label leading and the caret pinned to the trailing edge, at a
661
+ // phone-friendly minimum height. Only applied when `showCaret` is set, so field dropdowns are
662
+ // untouched.
663
+ containerMenu: {
664
+ minHeight: MIN_TOUCH_TARGET,
665
+ flexDirection: "row",
666
+ alignItems: "center",
667
+ justifyContent: "space-between",
668
+ columnGap: CARET_GAP
669
+ },
670
+ // Hamburger variant: the ☰ glyph LEADS the label (icon-first, like a phone nav button), so the
671
+ // row packs to the start rather than pushing a trailing caret to the far edge. Same tap target.
672
+ containerHamburger: {
673
+ minHeight: MIN_TOUCH_TARGET,
674
+ flexDirection: "row",
675
+ alignItems: "center",
676
+ justifyContent: "flex-start",
677
+ columnGap: CARET_GAP
678
+ },
645
679
  selectedText: { fontSize: BODY_FONT_SIZE2 },
680
+ // The label may shrink/ellipsize; the caret / hamburger glyph never does.
681
+ selectedTextMenu: { flexShrink: 1 },
682
+ caret: { fontSize: CARET_FONT_SIZE, flexShrink: 0 },
683
+ hamburger: { fontSize: HAMBURGER_FONT_SIZE, flexShrink: 0 },
646
684
  modalOverlay: {
647
685
  flex: 1,
648
686
  justifyContent: "center",
@@ -666,7 +704,9 @@ var ModalDropdown = ({
666
704
  variant,
667
705
  renderTrigger,
668
706
  optionTestID,
669
- menuMinWidth
707
+ menuMinWidth,
708
+ showCaret = false,
709
+ showHamburger = false
670
710
  }) => {
671
711
  const { theme, t } = useUi();
672
712
  const { colors } = theme;
@@ -700,9 +740,26 @@ var ModalDropdown = ({
700
740
  },
701
741
  [onChange]
702
742
  );
743
+ const isHamburger = showHamburger;
744
+ const isCaret = showCaret && !isHamburger;
703
745
  const containerStyle = useMemo(
704
- () => renderTrigger !== void 0 ? void 0 : [styles7.container, { borderColor: colors.border, backgroundColor: colors.surface }],
705
- [colors.border, colors.surface, renderTrigger]
746
+ () => renderTrigger !== void 0 ? void 0 : [
747
+ styles7.container,
748
+ isHamburger ? styles7.containerHamburger : isCaret ? styles7.containerMenu : null,
749
+ { borderColor: colors.border, backgroundColor: colors.surface }
750
+ ],
751
+ [colors.border, colors.surface, renderTrigger, isHamburger, isCaret]
752
+ );
753
+ const hamburgerStyle = useMemo(
754
+ () => [styles7.hamburger, { color: colors.textSecondary }],
755
+ [colors.textSecondary]
756
+ );
757
+ const caretStyle = useMemo(
758
+ () => [
759
+ styles7.caret,
760
+ { color: colors.textSecondary, transform: [{ rotate: isOpen ? CARET_OPEN_ROTATION : CARET_CLOSED_ROTATION }] }
761
+ ],
762
+ [colors.textSecondary, isOpen]
706
763
  );
707
764
  const optionTestIDFor = useCallback(
708
765
  (optionValue) => optionTestID !== void 0 ? optionTestID(optionValue) : `${testID}-option-${String(optionValue)}`,
@@ -731,7 +788,13 @@ var ModalDropdown = ({
731
788
  const keyExtractor = useCallback((item) => String(item.value), []);
732
789
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: anchorStyle, children: [
733
790
  /* @__PURE__ */ jsxs(TouchableOpacity, { ...a11yProps, style: containerStyle, onPress: handleToggle, children: [
734
- renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : /* @__PURE__ */ jsx(Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
791
+ renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : isHamburger ? /* @__PURE__ */ jsxs(Fragment, { children: [
792
+ /* @__PURE__ */ jsx(Text, { style: hamburgerStyle, children: HAMBURGER_GLYPH }),
793
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles7.selectedText, styles7.selectedTextMenu, { color: colors.text }], children: selectedLabel })
794
+ ] }) : isCaret ? /* @__PURE__ */ jsxs(Fragment, { children: [
795
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles7.selectedText, styles7.selectedTextMenu, { color: colors.text }], children: selectedLabel }),
796
+ /* @__PURE__ */ jsx(Text, { style: caretStyle, children: CARET_GLYPH })
797
+ ] }) : /* @__PURE__ */ jsx(Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
735
798
  hintNode
736
799
  ] }),
737
800
  isMenu && isOpen ? /* @__PURE__ */ jsx(
@@ -782,7 +845,8 @@ var TabsMenu = ({
782
845
  onChange,
783
846
  accessibilityLabel,
784
847
  idPrefix,
785
- testID
848
+ testID,
849
+ collapsedTrigger = "caret" /* Caret */
786
850
  }) => {
787
851
  const { t } = useUi();
788
852
  const options = useMemo(
@@ -796,6 +860,7 @@ var TabsMenu = ({
796
860
  },
797
861
  [tabs, idPrefix]
798
862
  );
863
+ const isHamburger = collapsedTrigger === "hamburger" /* Hamburger */;
799
864
  return /* @__PURE__ */ jsx(
800
865
  ModalDropdown,
801
866
  {
@@ -803,6 +868,8 @@ var TabsMenu = ({
803
868
  accessibilityLabel,
804
869
  optionTestID,
805
870
  options,
871
+ showCaret: !isHamburger,
872
+ showHamburger: isHamburger,
806
873
  testID,
807
874
  value: activeKey,
808
875
  onChange
@@ -915,6 +982,7 @@ var Tabs = ({
915
982
  children,
916
983
  idPrefix = "tabs",
917
984
  collapseBelow = TABS_COLLAPSE_BREAKPOINT,
985
+ collapsedTrigger = "caret" /* Caret */,
918
986
  style,
919
987
  stripStyle,
920
988
  panelStyle,
@@ -932,6 +1000,7 @@ var Tabs = ({
932
1000
  {
933
1001
  accessibilityLabel,
934
1002
  activeKey,
1003
+ collapsedTrigger,
935
1004
  idPrefix,
936
1005
  tabs,
937
1006
  testID: `${idPrefix}-menu`,
@@ -1657,6 +1726,6 @@ var CopyableId = ({
1657
1726
  ] });
1658
1727
  };
1659
1728
 
1660
- export { Accordion, AccordionItem, COPY_FEEDBACK_MS, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, Heading, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, Tabs, TruncatedText, UpgradePrompt, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
1729
+ export { Accordion, AccordionItem, COPY_FEEDBACK_MS, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, Heading, LAYOUT_I18N, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, Tabs, TabsCollapsedTrigger, TruncatedText, UpgradePrompt, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
1661
1730
  //# sourceMappingURL=index.mjs.map
1662
1731
  //# sourceMappingURL=index.mjs.map