@dloizides/ui-layout 1.19.0 → 1.20.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';
@@ -634,6 +634,12 @@ var MODAL_MIN_WIDTH = 200;
634
634
  var MODAL_MAX_HEIGHT = 300;
635
635
  var CONTAINER_PADDING_H = 12;
636
636
  var CONTAINER_PADDING_V = 10;
637
+ var MIN_TOUCH_TARGET = 44;
638
+ var CARET_FONT_SIZE = 12;
639
+ var CARET_GAP = 8;
640
+ var CARET_GLYPH = "\u25BE";
641
+ var CARET_OPEN_ROTATION = "180deg";
642
+ var CARET_CLOSED_ROTATION = "0deg";
637
643
  var styles7 = StyleSheet.create({
638
644
  anchor: { position: "relative" },
639
645
  container: {
@@ -642,7 +648,20 @@ var styles7 = StyleSheet.create({
642
648
  paddingHorizontal: CONTAINER_PADDING_H,
643
649
  paddingVertical: CONTAINER_PADDING_V
644
650
  },
651
+ // Caret variant: a row with the label leading and the caret pinned to the trailing edge, at a
652
+ // phone-friendly minimum height. Only applied when `showCaret` is set, so field dropdowns are
653
+ // untouched.
654
+ containerMenu: {
655
+ minHeight: MIN_TOUCH_TARGET,
656
+ flexDirection: "row",
657
+ alignItems: "center",
658
+ justifyContent: "space-between",
659
+ columnGap: CARET_GAP
660
+ },
645
661
  selectedText: { fontSize: BODY_FONT_SIZE2 },
662
+ // The label may shrink/ellipsize; the caret never does.
663
+ selectedTextMenu: { flexShrink: 1 },
664
+ caret: { fontSize: CARET_FONT_SIZE, flexShrink: 0 },
646
665
  modalOverlay: {
647
666
  flex: 1,
648
667
  justifyContent: "center",
@@ -666,7 +685,8 @@ var ModalDropdown = ({
666
685
  variant,
667
686
  renderTrigger,
668
687
  optionTestID,
669
- menuMinWidth
688
+ menuMinWidth,
689
+ showCaret = false
670
690
  }) => {
671
691
  const { theme, t } = useUi();
672
692
  const { colors } = theme;
@@ -701,8 +721,19 @@ var ModalDropdown = ({
701
721
  [onChange]
702
722
  );
703
723
  const containerStyle = useMemo(
704
- () => renderTrigger !== void 0 ? void 0 : [styles7.container, { borderColor: colors.border, backgroundColor: colors.surface }],
705
- [colors.border, colors.surface, renderTrigger]
724
+ () => renderTrigger !== void 0 ? void 0 : [
725
+ styles7.container,
726
+ showCaret ? styles7.containerMenu : null,
727
+ { borderColor: colors.border, backgroundColor: colors.surface }
728
+ ],
729
+ [colors.border, colors.surface, renderTrigger, showCaret]
730
+ );
731
+ const caretStyle = useMemo(
732
+ () => [
733
+ styles7.caret,
734
+ { color: colors.textSecondary, transform: [{ rotate: isOpen ? CARET_OPEN_ROTATION : CARET_CLOSED_ROTATION }] }
735
+ ],
736
+ [colors.textSecondary, isOpen]
706
737
  );
707
738
  const optionTestIDFor = useCallback(
708
739
  (optionValue) => optionTestID !== void 0 ? optionTestID(optionValue) : `${testID}-option-${String(optionValue)}`,
@@ -731,7 +762,10 @@ var ModalDropdown = ({
731
762
  const keyExtractor = useCallback((item) => String(item.value), []);
732
763
  return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: anchorStyle, children: [
733
764
  /* @__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 }),
765
+ renderTrigger !== void 0 ? renderTrigger({ label: selectedLabel, isOpen }) : showCaret ? /* @__PURE__ */ jsxs(Fragment, { children: [
766
+ /* @__PURE__ */ jsx(Text, { numberOfLines: 1, style: [styles7.selectedText, styles7.selectedTextMenu, { color: colors.text }], children: selectedLabel }),
767
+ /* @__PURE__ */ jsx(Text, { style: caretStyle, children: CARET_GLYPH })
768
+ ] }) : /* @__PURE__ */ jsx(Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel }),
735
769
  hintNode
736
770
  ] }),
737
771
  isMenu && isOpen ? /* @__PURE__ */ jsx(
@@ -803,6 +837,7 @@ var TabsMenu = ({
803
837
  accessibilityLabel,
804
838
  optionTestID,
805
839
  options,
840
+ showCaret: true,
806
841
  testID,
807
842
  value: activeKey,
808
843
  onChange