@dloizides/ui-layout 1.3.0 → 1.4.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,5 +1,5 @@
1
1
  import React8, { createContext, useMemo, useRef, useEffect, useState, useCallback, useContext } from 'react';
2
- import { StyleSheet, View, Text, TouchableOpacity, Platform, Modal, FlatList, ScrollView, Animated, Easing, Pressable, useWindowDimensions, LayoutAnimation, UIManager } from 'react-native';
2
+ import { StyleSheet, View, Text, Pressable, TouchableOpacity, Platform, Modal, FlatList, ScrollView, Animated, Easing, useWindowDimensions, LayoutAnimation, UIManager } from 'react-native';
3
3
  import { MODAL_OVERLAY_COLOR, useUi } from '@dloizides/ui-feedback';
4
4
  import { jsx, jsxs } from 'react/jsx-runtime';
5
5
  import { SvgIcon } from '@dloizides/ui-icons';
@@ -85,6 +85,93 @@ var StatusBadge = ({
85
85
  }
86
86
  );
87
87
  };
88
+ var TRACK_PADDING = 3;
89
+ var TRACK_RADIUS = 999;
90
+ var SEGMENT_RADIUS = 999;
91
+ var SEGMENT_PAD_H = 15;
92
+ var SEGMENT_PAD_V = 7;
93
+ var SEGMENT_FONT = 14;
94
+ var SEGMENT_WEIGHT = "600";
95
+ var BORDER_WIDTH = 1;
96
+ var SHADOW_COLOR = "#141e32";
97
+ var SHADOW_OPACITY = 0.1;
98
+ var SHADOW_RADIUS = 3;
99
+ var SHADOW_OFFSET = { width: 0, height: 1 };
100
+ var SHADOW_ELEVATION = 2;
101
+ var TRANSPARENT = "transparent";
102
+ var styles4 = StyleSheet.create({
103
+ track: {
104
+ flexDirection: "row",
105
+ alignSelf: "flex-start",
106
+ alignItems: "center",
107
+ gap: TRACK_PADDING + 1,
108
+ padding: TRACK_PADDING,
109
+ borderRadius: TRACK_RADIUS,
110
+ borderWidth: BORDER_WIDTH
111
+ },
112
+ segment: {
113
+ paddingHorizontal: SEGMENT_PAD_H,
114
+ paddingVertical: SEGMENT_PAD_V,
115
+ borderRadius: SEGMENT_RADIUS
116
+ },
117
+ segmentSelected: {
118
+ shadowColor: SHADOW_COLOR,
119
+ shadowOpacity: SHADOW_OPACITY,
120
+ shadowRadius: SHADOW_RADIUS,
121
+ shadowOffset: SHADOW_OFFSET,
122
+ elevation: SHADOW_ELEVATION
123
+ },
124
+ label: {
125
+ fontSize: SEGMENT_FONT,
126
+ fontWeight: SEGMENT_WEIGHT,
127
+ textAlign: "center"
128
+ }
129
+ });
130
+ function ariaSelectedProps(selected) {
131
+ return { "aria-selected": selected };
132
+ }
133
+ function SegmentedControl({
134
+ options,
135
+ value,
136
+ onChange,
137
+ accessibilityLabel,
138
+ style,
139
+ testID
140
+ }) {
141
+ const { theme } = useUi();
142
+ const { colors } = theme;
143
+ return /* @__PURE__ */ jsx(
144
+ View,
145
+ {
146
+ accessibilityRole: "tablist",
147
+ "aria-label": accessibilityLabel,
148
+ style: [styles4.track, { backgroundColor: colors.background, borderColor: colors.border }, style],
149
+ testID,
150
+ children: options.map((opt) => {
151
+ const selected = opt.value === value;
152
+ return /* @__PURE__ */ jsx(
153
+ Pressable,
154
+ {
155
+ accessibilityRole: "tab",
156
+ accessibilityState: { selected },
157
+ accessibilityLabel: opt.accessibilityLabel ?? opt.label,
158
+ accessibilityHint: opt.accessibilityHint,
159
+ onPress: () => onChange(opt.value),
160
+ style: [
161
+ styles4.segment,
162
+ selected ? styles4.segmentSelected : null,
163
+ { backgroundColor: selected ? colors.surface : TRANSPARENT }
164
+ ],
165
+ testID: opt.testID,
166
+ ...ariaSelectedProps(selected),
167
+ children: /* @__PURE__ */ jsx(Text, { style: [styles4.label, { color: selected ? colors.text : colors.textSecondary }], children: opt.label })
168
+ },
169
+ opt.value
170
+ );
171
+ })
172
+ }
173
+ );
174
+ }
88
175
  var PROMPT_PADDING = 20;
89
176
  var PROMPT_BORDER_RADIUS = 12;
90
177
  var PROMPT_BORDER_WIDTH = 1;
@@ -97,7 +184,7 @@ var DISMISS_FONT_SIZE = 13;
97
184
  var TITLE_MARGIN_BOTTOM = 8;
98
185
  var MESSAGE_MARGIN_BOTTOM = 16;
99
186
  var CTA_MARGIN_BOTTOM = 8;
100
- var styles4 = StyleSheet.create({
187
+ var styles5 = StyleSheet.create({
101
188
  container: {
102
189
  padding: PROMPT_PADDING,
103
190
  borderRadius: PROMPT_BORDER_RADIUS,
@@ -125,21 +212,21 @@ var UpgradePrompt = ({
125
212
  return /* @__PURE__ */ jsxs(
126
213
  View,
127
214
  {
128
- style: [styles4.container, { borderColor: primary, backgroundColor: colors.surface }],
215
+ style: [styles5.container, { borderColor: primary, backgroundColor: colors.surface }],
129
216
  testID: LAYOUT_TEST_IDS.upgradePrompt,
130
217
  children: [
131
- /* @__PURE__ */ jsx(Text, { style: [styles4.title, { color: colors.text }], children: t("settings.billing.upgradePrompt.title") }),
132
- /* @__PURE__ */ jsx(Text, { style: [styles4.message, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.message", requiredTier, currentTier) }),
218
+ /* @__PURE__ */ jsx(Text, { style: [styles5.title, { color: colors.text }], children: t("settings.billing.upgradePrompt.title") }),
219
+ /* @__PURE__ */ jsx(Text, { style: [styles5.message, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.message", requiredTier, currentTier) }),
133
220
  /* @__PURE__ */ jsx(
134
221
  TouchableOpacity,
135
222
  {
136
223
  accessibilityHint: t("settings.billing.upgradePrompt.ctaHint"),
137
224
  accessibilityLabel: t("settings.billing.upgradePrompt.cta"),
138
225
  accessibilityRole: "button",
139
- style: [styles4.cta, { backgroundColor: primary }],
226
+ style: [styles5.cta, { backgroundColor: primary }],
140
227
  testID: LAYOUT_TEST_IDS.upgradePromptCta,
141
228
  onPress: handleUpgradePress,
142
- children: /* @__PURE__ */ jsx(Text, { style: [styles4.ctaText, { color: colors.surface }], children: t("settings.billing.upgradePrompt.cta") })
229
+ children: /* @__PURE__ */ jsx(Text, { style: [styles5.ctaText, { color: colors.surface }], children: t("settings.billing.upgradePrompt.cta") })
143
230
  }
144
231
  ),
145
232
  onDismiss ? /* @__PURE__ */ jsx(
@@ -148,10 +235,10 @@ var UpgradePrompt = ({
148
235
  accessibilityHint: t("settings.billing.upgradePrompt.dismissHint"),
149
236
  accessibilityLabel: t("settings.billing.upgradePrompt.dismiss"),
150
237
  accessibilityRole: "button",
151
- style: styles4.dismiss,
238
+ style: styles5.dismiss,
152
239
  testID: LAYOUT_TEST_IDS.upgradePromptDismiss,
153
240
  onPress: onDismiss,
154
- children: /* @__PURE__ */ jsx(Text, { style: [styles4.dismissText, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.dismiss") })
241
+ children: /* @__PURE__ */ jsx(Text, { style: [styles5.dismissText, { color: colors.textSecondary }], children: t("settings.billing.upgradePrompt.dismiss") })
155
242
  }
156
243
  ) : null
157
244
  ]
@@ -223,7 +310,7 @@ var BODY_FONT_SIZE = 14;
223
310
  var SELECTED_FONT_WEIGHT = "600";
224
311
  var OPTION_PADDING_H = 16;
225
312
  var OPTION_PADDING_V = 12;
226
- var styles5 = StyleSheet.create({
313
+ var styles6 = StyleSheet.create({
227
314
  option: {
228
315
  paddingHorizontal: OPTION_PADDING_H,
229
316
  paddingVertical: OPTION_PADDING_V,
@@ -245,8 +332,8 @@ var OptionRow = ({
245
332
  onSelect();
246
333
  }, [onSelect]);
247
334
  const isActive = isSelected || isHighlighted;
248
- const rowStyle = [styles5.option, isActive ? { backgroundColor: colors.surfaceElevated } : null];
249
- const textStyle = [styles5.optionText, { color: colors.text }, isSelected ? styles5.selectedText : null];
335
+ const rowStyle = [styles6.option, isActive ? { backgroundColor: colors.surfaceElevated } : null];
336
+ const textStyle = [styles6.optionText, { color: colors.text }, isSelected ? styles6.selectedText : null];
250
337
  return /* @__PURE__ */ jsx(
251
338
  TouchableOpacity,
252
339
  {
@@ -318,14 +405,14 @@ function useMenuKeyboard(params) {
318
405
  }, [containerRef, enabled, onClose, params]);
319
406
  }
320
407
  var BORDER_RADIUS = 8;
321
- var BORDER_WIDTH = 1;
408
+ var BORDER_WIDTH2 = 1;
322
409
  var MENU_PADDING = 4;
323
410
  var MENU_MAX_HEIGHT = 300;
324
411
  var MENU_TOP_GAP = 4;
325
412
  var MENU_Z_INDEX = 1e3;
326
413
  var MENU_ELEVATION = 8;
327
414
  var MENU_BOX_SHADOW = "0px 2px 8px rgba(0, 0, 0, 0.15)";
328
- var styles6 = StyleSheet.create({
415
+ var styles7 = StyleSheet.create({
329
416
  popover: {
330
417
  position: "absolute",
331
418
  top: "100%",
@@ -333,7 +420,7 @@ var styles6 = StyleSheet.create({
333
420
  right: 0,
334
421
  marginTop: MENU_TOP_GAP,
335
422
  zIndex: MENU_Z_INDEX,
336
- borderWidth: BORDER_WIDTH,
423
+ borderWidth: BORDER_WIDTH2,
337
424
  borderRadius: BORDER_RADIUS,
338
425
  padding: MENU_PADDING,
339
426
  maxHeight: MENU_MAX_HEIGHT,
@@ -379,7 +466,7 @@ var InlineMenu = ({
379
466
  onClose
380
467
  });
381
468
  const popoverStyle = useMemo(
382
- () => [styles6.popover, { borderColor: colors.border, backgroundColor: colors.surface }],
469
+ () => [styles7.popover, { borderColor: colors.border, backgroundColor: colors.surface }],
383
470
  [colors.border, colors.surface]
384
471
  );
385
472
  return /* @__PURE__ */ jsx(
@@ -415,17 +502,17 @@ function useResolvedDropdownVariant(explicit) {
415
502
  return resolveDropdownVariant(explicit, width, Platform.OS);
416
503
  }
417
504
  var BORDER_RADIUS2 = 8;
418
- var BORDER_WIDTH2 = 1;
505
+ var BORDER_WIDTH3 = 1;
419
506
  var BODY_FONT_SIZE2 = 14;
420
507
  var MODAL_PADDING = 8;
421
508
  var MODAL_MIN_WIDTH = 200;
422
509
  var MODAL_MAX_HEIGHT = 300;
423
510
  var CONTAINER_PADDING_H = 12;
424
511
  var CONTAINER_PADDING_V = 10;
425
- var styles7 = StyleSheet.create({
512
+ var styles8 = StyleSheet.create({
426
513
  anchor: { position: "relative" },
427
514
  container: {
428
- borderWidth: BORDER_WIDTH2,
515
+ borderWidth: BORDER_WIDTH3,
429
516
  borderRadius: BORDER_RADIUS2,
430
517
  paddingHorizontal: CONTAINER_PADDING_H,
431
518
  paddingVertical: CONTAINER_PADDING_V
@@ -479,11 +566,11 @@ var ModalDropdown = ({
479
566
  [onChange]
480
567
  );
481
568
  const containerStyle = useMemo(
482
- () => [styles7.container, { borderColor: colors.border, backgroundColor: colors.surface }],
569
+ () => [styles8.container, { borderColor: colors.border, backgroundColor: colors.surface }],
483
570
  [colors.border, colors.surface]
484
571
  );
485
572
  const modalContentStyle = useMemo(
486
- () => [styles7.modalContent, { backgroundColor: colors.surface }],
573
+ () => [styles8.modalContent, { backgroundColor: colors.surface }],
487
574
  [colors.surface]
488
575
  );
489
576
  const renderModalOption = useCallback(
@@ -499,7 +586,7 @@ var ModalDropdown = ({
499
586
  [handleSelect, testID, value]
500
587
  );
501
588
  const keyExtractor = useCallback((item) => String(item.value), []);
502
- return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles7.anchor, children: [
589
+ return /* @__PURE__ */ jsxs(View, { ref: anchorRef, style: styles8.anchor, children: [
503
590
  /* @__PURE__ */ jsx(
504
591
  TouchableOpacity,
505
592
  {
@@ -511,7 +598,7 @@ var ModalDropdown = ({
511
598
  style: containerStyle,
512
599
  testID,
513
600
  onPress: handleToggle,
514
- children: /* @__PURE__ */ jsx(Text, { style: [styles7.selectedText, { color: colors.text }], children: selectedLabel })
601
+ children: /* @__PURE__ */ jsx(Text, { style: [styles8.selectedText, { color: colors.text }], children: selectedLabel })
515
602
  }
516
603
  ),
517
604
  isMenu && isOpen ? /* @__PURE__ */ jsx(
@@ -534,7 +621,7 @@ var ModalDropdown = ({
534
621
  accessibilityLabel: t("common.dismissDropdown"),
535
622
  accessibilityRole: "button",
536
623
  activeOpacity: 1,
537
- style: styles7.modalOverlay,
624
+ style: styles8.modalOverlay,
538
625
  testID: `${testID}-backdrop`,
539
626
  onPress: handleClose,
540
627
  children: /* @__PURE__ */ jsx(
@@ -553,7 +640,7 @@ var ModalDropdown = ({
553
640
  ] });
554
641
  };
555
642
  var CLOSE_ICON_SIZE = 18;
556
- var styles8 = StyleSheet.create({
643
+ var styles9 = StyleSheet.create({
557
644
  container: {
558
645
  flex: 1,
559
646
  padding: 16
@@ -578,7 +665,7 @@ var ModalShell = ({
578
665
  }) => {
579
666
  const { theme, t } = useUi();
580
667
  const containerStyle = React8.useMemo(
581
- () => [styles8.container, { backgroundColor: theme.colors.background }, contentStyle],
668
+ () => [styles9.container, { backgroundColor: theme.colors.background }, contentStyle],
582
669
  [theme.colors.background, contentStyle]
583
670
  );
584
671
  const closeA11yLabel = t("quizTemplates.cancel");
@@ -598,7 +685,7 @@ var ModalShell = ({
598
685
  role: "dialog",
599
686
  style: containerStyle,
600
687
  children: [
601
- /* @__PURE__ */ jsxs(View, { style: styles8.headerRow, children: [
688
+ /* @__PURE__ */ jsxs(View, { style: styles9.headerRow, children: [
602
689
  /* @__PURE__ */ jsx(Heading, { children: title ?? t("close") }),
603
690
  showClose ? /* @__PURE__ */ jsx(
604
691
  TouchableOpacity,
@@ -606,7 +693,7 @@ var ModalShell = ({
606
693
  accessibilityHint: t("common.closeDialogHint"),
607
694
  accessibilityLabel: closeA11yLabel,
608
695
  accessibilityRole: "button",
609
- style: styles8.closeButton,
696
+ style: styles9.closeButton,
610
697
  testID: LAYOUT_TEST_IDS.modalShellClose,
611
698
  onPress: onCancel,
612
699
  children: /* @__PURE__ */ jsx(SvgIcon, { color: theme.colors.textSecondary, name: "close", size: CLOSE_ICON_SIZE })
@@ -647,7 +734,7 @@ function animateNextLayout() {
647
734
  } catch {
648
735
  }
649
736
  }
650
- var styles9 = StyleSheet.create({
737
+ var styles10 = StyleSheet.create({
651
738
  container: { alignSelf: "stretch" }
652
739
  });
653
740
  function computeInitialOpen(children, defaultOpenIds, allowMultiple) {
@@ -703,7 +790,7 @@ var Accordion = ({
703
790
  [openSet, toggle, allowMultiple]
704
791
  );
705
792
  const containerStyle = useMemo(
706
- () => style === void 0 ? [styles9.container] : [styles9.container, ...Array.isArray(style) ? style : [style]],
793
+ () => style === void 0 ? [styles10.container] : [styles10.container, ...Array.isArray(style) ? style : [style]],
707
794
  [style]
708
795
  );
709
796
  return /* @__PURE__ */ jsx(AccordionContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(View, { style: containerStyle, testID, children }) });
@@ -724,7 +811,7 @@ var EXPANDED_DEG = "180deg";
724
811
  var DISABLED_OPACITY = 0.5;
725
812
  var FULL_OPACITY = 1;
726
813
  var ROLE_REGION = "region";
727
- var styles10 = StyleSheet.create({
814
+ var styles11 = StyleSheet.create({
728
815
  item: { borderTopWidth: StyleSheet.hairlineWidth },
729
816
  header: {
730
817
  flexDirection: "row",
@@ -788,11 +875,11 @@ var AccordionItem = ({
788
875
  );
789
876
  const keyboardProps = Platform.OS === "web" ? { onKeyDown: handleKeyDown2 } : {};
790
877
  const itemStyle = useMemo(
791
- () => [styles10.item, { borderTopColor: colors.border }],
878
+ () => [styles11.item, { borderTopColor: colors.border }],
792
879
  [colors.border]
793
880
  );
794
881
  const headerStyle = useMemo(
795
- () => [styles10.header, { opacity: disabled ? DISABLED_OPACITY : FULL_OPACITY }],
882
+ () => [styles11.header, { opacity: disabled ? DISABLED_OPACITY : FULL_OPACITY }],
796
883
  [disabled]
797
884
  );
798
885
  const resolvedLabel = accessibilityLabel ?? (typeof title === "string" ? title : void 0);
@@ -812,18 +899,18 @@ var AccordionItem = ({
812
899
  onPress: handlePress,
813
900
  ...keyboardProps,
814
901
  children: [
815
- /* @__PURE__ */ jsx(View, { style: styles10.headerLeft, children: typeof title === "string" ? /* @__PURE__ */ jsx(Text, { style: [styles10.title, { color: colors.text }], children: title }) : title }),
816
- /* @__PURE__ */ jsxs(View, { style: styles10.headerRight, children: [
902
+ /* @__PURE__ */ jsx(View, { style: styles11.headerLeft, children: typeof title === "string" ? /* @__PURE__ */ jsx(Text, { style: [styles11.title, { color: colors.text }], children: title }) : title }),
903
+ /* @__PURE__ */ jsxs(View, { style: styles11.headerRight, children: [
817
904
  right,
818
- /* @__PURE__ */ jsx(Animated.View, { style: [styles10.chevron, { transform: [{ rotate }] }], children: /* @__PURE__ */ jsx(SvgIcon, { color: colors.textSecondary, name: "chevronDown", size: CHEVRON_SIZE, testID: chevronTestID }) })
905
+ /* @__PURE__ */ jsx(Animated.View, { style: [styles11.chevron, { transform: [{ rotate }] }], children: /* @__PURE__ */ jsx(SvgIcon, { color: colors.textSecondary, name: "chevronDown", size: CHEVRON_SIZE, testID: chevronTestID }) })
819
906
  ] })
820
907
  ]
821
908
  }
822
909
  ),
823
- expanded ? /* @__PURE__ */ jsx(View, { accessibilityLabel: resolvedLabel, nativeID: bodyTestID, role: ROLE_REGION, style: styles10.body, testID: bodyTestID, children }) : null
910
+ expanded ? /* @__PURE__ */ jsx(View, { accessibilityLabel: resolvedLabel, nativeID: bodyTestID, role: ROLE_REGION, style: styles11.body, testID: bodyTestID, children }) : null
824
911
  ] });
825
912
  };
826
913
 
827
- export { Accordion, AccordionItem, DEFAULT_BILLING_ROUTE, DropdownVariant, Heading, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, StatusBadge, UpgradePrompt, useFocusTrap };
914
+ export { Accordion, AccordionItem, DEFAULT_BILLING_ROUTE, DropdownVariant, Heading, LAYOUT_TEST_IDS, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, UpgradePrompt, useFocusTrap };
828
915
  //# sourceMappingURL=index.mjs.map
829
916
  //# sourceMappingURL=index.mjs.map