@telus-uds/components-base 1.14.2 → 1.16.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.
Files changed (161) hide show
  1. package/CHANGELOG.md +40 -2
  2. package/__tests17__/A11yText/A11yText.test.jsx +34 -0
  3. package/__tests17__/ActivityIndicator/ActivityIndicator.test.jsx +68 -0
  4. package/__tests17__/ActivityIndicator/__snapshots__/ActivityIndicator.test.jsx.snap +299 -0
  5. package/__tests17__/Box/Box.test.jsx +111 -0
  6. package/__tests17__/Button/Button.test.jsx +86 -0
  7. package/__tests17__/Button/ButtonBase.test.jsx +82 -0
  8. package/__tests17__/Button/ButtonGroup.test.jsx +347 -0
  9. package/__tests17__/Button/ButtonLink.test.jsx +61 -0
  10. package/__tests17__/Card/Card.test.jsx +63 -0
  11. package/__tests17__/Carousel/Carousel.test.jsx +128 -0
  12. package/__tests17__/Carousel/CarouselTabs.test.jsx +142 -0
  13. package/__tests17__/Checkbox/Checkbox.test.jsx +94 -0
  14. package/__tests17__/Checkbox/CheckboxGroup.test.jsx +246 -0
  15. package/__tests17__/Divider/Divider.test.jsx +91 -0
  16. package/__tests17__/ExpandCollapse/ExpandCollapse.test.jsx +109 -0
  17. package/__tests17__/Feedback/Feedback.test.jsx +42 -0
  18. package/__tests17__/FlexGrid/Col.test.jsx +261 -0
  19. package/__tests17__/FlexGrid/FlexGrid.test.jsx +136 -0
  20. package/__tests17__/FlexGrid/Row.test.jsx +273 -0
  21. package/__tests17__/HorizontalScroll/HorizontalScroll.test.jsx +165 -0
  22. package/__tests17__/Icon/Icon.test.jsx +61 -0
  23. package/__tests17__/IconButton/IconButton.test.jsx +52 -0
  24. package/__tests17__/InputLabel/InputLabel.test.jsx +28 -0
  25. package/__tests17__/InputLabel/__snapshots__/InputLabel.test.jsx.snap +3 -0
  26. package/__tests17__/InputSupports/InputSupports.test.jsx +60 -0
  27. package/__tests17__/Link/Link.test.jsx +63 -0
  28. package/__tests17__/Link/TextButton.test.jsx +35 -0
  29. package/__tests17__/List/List.test.jsx +82 -0
  30. package/__tests17__/Modal/Modal.test.jsx +47 -0
  31. package/__tests17__/Notification/Notification.test.jsx +20 -0
  32. package/__tests17__/Pagination/Pagination.test.jsx +160 -0
  33. package/__tests17__/Progress/Progress.test.jsx +79 -0
  34. package/__tests17__/Radio/Radio.test.jsx +87 -0
  35. package/__tests17__/Radio/RadioGroup.test.jsx +220 -0
  36. package/__tests17__/RadioCard/RadioCard.test.jsx +87 -0
  37. package/__tests17__/RadioCard/RadioCardGroup.test.jsx +246 -0
  38. package/__tests17__/Search/Search.test.jsx +87 -0
  39. package/__tests17__/Select/Select.test.jsx +94 -0
  40. package/__tests17__/SideNav/SideNav.test.jsx +110 -0
  41. package/__tests17__/Skeleton/Skeleton.test.jsx +61 -0
  42. package/__tests17__/SkipLink/SkipLink.test.jsx +61 -0
  43. package/__tests17__/Spacer/Spacer.test.jsx +63 -0
  44. package/__tests17__/StackView/StackView.test.jsx +211 -0
  45. package/__tests17__/StackView/StackWrap.test.jsx +47 -0
  46. package/__tests17__/StackView/getStackedContent.test.jsx +295 -0
  47. package/__tests17__/StepTracker/StepTracker.test.jsx +108 -0
  48. package/__tests17__/Tabs/Tabs.test.jsx +49 -0
  49. package/__tests17__/Tags/Tags.test.jsx +327 -0
  50. package/__tests17__/TextInput/TextArea.test.jsx +35 -0
  51. package/__tests17__/TextInput/TextInputBase.test.jsx +125 -0
  52. package/__tests17__/ThemeProvider/ThemeProvider.test.jsx +80 -0
  53. package/__tests17__/ThemeProvider/useThemeTokens.test.jsx +514 -0
  54. package/__tests17__/ThemeProvider/utils/theme-tokens.test.js +41 -0
  55. package/__tests17__/ToggleSwitch/ToggleSwitch.test.jsx +82 -0
  56. package/__tests17__/ToggleSwitch/ToggleSwitchGroup.test.jsx +192 -0
  57. package/__tests17__/Tooltip/Tooltip.test.jsx +65 -0
  58. package/__tests17__/Tooltip/getTooltipPosition.test.js +79 -0
  59. package/__tests17__/Typography/typography.test.jsx +90 -0
  60. package/__tests17__/utils/children.test.jsx +128 -0
  61. package/__tests17__/utils/containUniqueFields.test.js +25 -0
  62. package/__tests17__/utils/input.test.js +375 -0
  63. package/__tests17__/utils/props.test.js +36 -0
  64. package/__tests17__/utils/semantics.test.jsx +34 -0
  65. package/__tests17__/utils/useCopy.test.js +42 -0
  66. package/__tests17__/utils/useResponsiveProp.test.jsx +202 -0
  67. package/__tests17__/utils/useSpacingScale.test.jsx +273 -0
  68. package/__tests17__/utils/useUniqueId.test.js +31 -0
  69. package/component-docs.json +120 -85
  70. package/lib/A11yInfoProvider/index.js +14 -5
  71. package/lib/Button/ButtonGroup.js +3 -2
  72. package/lib/Carousel/Carousel.js +18 -2
  73. package/lib/Carousel/CarouselTabs/CarouselTabs.js +6 -7
  74. package/lib/Checkbox/Checkbox.js +9 -6
  75. package/lib/ExpandCollapse/Control.js +6 -5
  76. package/lib/ExpandCollapse/Panel.js +5 -4
  77. package/lib/List/ListItem.js +10 -236
  78. package/lib/List/ListItemBase.js +162 -0
  79. package/lib/List/ListItemContent.js +85 -0
  80. package/lib/List/ListItemMark.js +158 -0
  81. package/lib/List/PressableListItemBase.js +147 -0
  82. package/lib/Notification/Notification.js +2 -1
  83. package/lib/Pagination/Pagination.js +4 -3
  84. package/lib/Radio/Radio.js +9 -6
  85. package/lib/RadioCard/RadioCard.js +9 -6
  86. package/lib/Select/Select.js +1 -0
  87. package/lib/Skeleton/Skeleton.js +18 -13
  88. package/lib/Skeleton/useSkeletonNativeAnimation.js +4 -2
  89. package/lib/Tabs/Tabs.js +12 -3
  90. package/lib/Tags/Tags.js +3 -3
  91. package/lib/TextInput/TextInput.js +5 -4
  92. package/lib/ToggleSwitch/ToggleSwitch.js +24 -19
  93. package/lib/ViewportProvider/useViewportListener.js +11 -5
  94. package/lib/utils/hasOwnProperty.js +18 -0
  95. package/lib/utils/props/a11yProps.js +171 -1
  96. package/lib/utils/props/getPropSelector.js +47 -5
  97. package/lib/utils/ssr.js +116 -1
  98. package/lib/utils/useResponsiveProp.js +5 -3
  99. package/lib/utils/withLinkRouter.js +3 -5
  100. package/lib-module/A11yInfoProvider/index.js +14 -4
  101. package/lib-module/Button/ButtonGroup.js +3 -2
  102. package/lib-module/Carousel/Carousel.js +16 -2
  103. package/lib-module/Carousel/CarouselTabs/CarouselTabs.js +7 -6
  104. package/lib-module/Checkbox/Checkbox.js +9 -6
  105. package/lib-module/ExpandCollapse/Control.js +6 -5
  106. package/lib-module/ExpandCollapse/Panel.js +5 -4
  107. package/lib-module/List/ListItem.js +13 -235
  108. package/lib-module/List/ListItemBase.js +139 -0
  109. package/lib-module/List/ListItemContent.js +66 -0
  110. package/lib-module/List/ListItemMark.js +143 -0
  111. package/lib-module/List/PressableListItemBase.js +117 -0
  112. package/lib-module/Notification/Notification.js +2 -1
  113. package/lib-module/Pagination/Pagination.js +5 -3
  114. package/lib-module/Radio/Radio.js +9 -6
  115. package/lib-module/RadioCard/RadioCard.js +9 -6
  116. package/lib-module/Select/Select.js +1 -0
  117. package/lib-module/Skeleton/Skeleton.js +15 -13
  118. package/lib-module/Skeleton/useSkeletonNativeAnimation.js +3 -2
  119. package/lib-module/Tabs/Tabs.js +13 -4
  120. package/lib-module/Tags/Tags.js +3 -3
  121. package/lib-module/TextInput/TextInput.js +5 -4
  122. package/lib-module/ToggleSwitch/ToggleSwitch.js +24 -19
  123. package/lib-module/ViewportProvider/useViewportListener.js +10 -4
  124. package/lib-module/utils/hasOwnProperty.js +11 -0
  125. package/lib-module/utils/props/a11yProps.js +169 -1
  126. package/lib-module/utils/props/getPropSelector.js +44 -5
  127. package/lib-module/utils/ssr.js +106 -0
  128. package/lib-module/utils/useResponsiveProp.js +3 -4
  129. package/lib-module/utils/withLinkRouter.js +3 -5
  130. package/package.json +12 -17
  131. package/src/A11yInfoProvider/index.jsx +20 -4
  132. package/src/Button/ButtonGroup.jsx +4 -2
  133. package/src/Carousel/Carousel.jsx +15 -2
  134. package/src/Carousel/CarouselTabs/CarouselTabs.jsx +5 -3
  135. package/src/Checkbox/Checkbox.jsx +7 -3
  136. package/src/ExpandCollapse/Control.jsx +8 -5
  137. package/src/ExpandCollapse/Panel.jsx +7 -5
  138. package/src/List/ListItem.jsx +12 -191
  139. package/src/List/ListItemBase.jsx +118 -0
  140. package/src/List/ListItemContent.jsx +52 -0
  141. package/src/List/ListItemMark.jsx +99 -0
  142. package/src/List/PressableListItemBase.jsx +102 -0
  143. package/src/Notification/Notification.jsx +1 -1
  144. package/src/Pagination/Pagination.jsx +6 -1
  145. package/src/Radio/Radio.jsx +7 -3
  146. package/src/RadioCard/RadioCard.jsx +7 -3
  147. package/src/Select/Select.jsx +1 -1
  148. package/src/Skeleton/Skeleton.jsx +25 -19
  149. package/src/Skeleton/useSkeletonNativeAnimation.js +3 -3
  150. package/src/Tabs/Tabs.jsx +19 -2
  151. package/src/Tags/Tags.jsx +3 -3
  152. package/src/TextInput/TextInput.jsx +4 -4
  153. package/src/ToggleSwitch/ToggleSwitch.jsx +3 -3
  154. package/src/ViewportProvider/useViewportListener.js +10 -5
  155. package/src/utils/hasOwnProperty.js +11 -0
  156. package/src/utils/props/a11yProps.js +107 -1
  157. package/src/utils/props/getPropSelector.js +45 -4
  158. package/src/utils/ssr.jsx +124 -0
  159. package/src/utils/useResponsiveProp.js +3 -3
  160. package/src/utils/withLinkRouter.jsx +1 -3
  161. package/src/utils/ssr.js +0 -35
@@ -16,6 +16,8 @@ import SkipLink from '../SkipLink';
16
16
  import A11yText from '../A11yText';
17
17
  import CarouselStepTracker from './CarouselStepTracker';
18
18
  import CarouselThumbnailNavigation from './CarouselThumbnailNavigation';
19
+ import CarouselTabsPanel from './CarouselTabs/CarouselTabsPanel';
20
+ import CarouselTabsPanelItem from './CarouselTabs/CarouselTabsPanelItem';
19
21
  import dictionary from './dictionary';
20
22
  import { jsx as _jsx } from "react/jsx-runtime";
21
23
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -138,7 +140,8 @@ const Carousel = /*#__PURE__*/React.forwardRef((_ref, ref) => {
138
140
  onAnimationEnd,
139
141
  onIndexChanged,
140
142
  skipLinkHref,
141
- refocus,
143
+ tabs,
144
+ refocus = Boolean(tabs),
142
145
  title = 'carousel',
143
146
  springConfig = undefined,
144
147
  thumbnails = undefined,
@@ -161,6 +164,7 @@ const Carousel = /*#__PURE__*/React.forwardRef((_ref, ref) => {
161
164
  nextIcon,
162
165
  showPreviousNextNavigation,
163
166
  showPanelNavigation,
167
+ showPanelTabs,
164
168
  spaceBetweenSlideAndPreviousNextNavigation
165
169
  } = themeTokens;
166
170
  const [activeIndex, setActiveIndex] = React.useState(0);
@@ -389,6 +393,9 @@ const Carousel = /*#__PURE__*/React.forwardRef((_ref, ref) => {
389
393
 
390
394
  return "".concat(copyText[0].toUpperCase()).concat(copyText.slice(1));
391
395
  }, [activeIndex, childrenArray.length, itemLabel, getCopy, title]);
396
+ const activePanelNavigation = tabs && showPanelTabs ? /*#__PURE__*/_jsx(CarouselTabsPanel, {
397
+ items: tabs
398
+ }) : panelNavigation;
392
399
  return /*#__PURE__*/_jsxs(CarouselProvider, {
393
400
  activeIndex: activeIndex,
394
401
  goTo: goTo,
@@ -462,7 +469,7 @@ const Carousel = /*#__PURE__*/React.forwardRef((_ref, ref) => {
462
469
  accessibilityLabel: getCopyWithPlaceholders('iconButtonLabel').replace('%{targetStep}', activeIndex + 2)
463
470
  })
464
471
  })]
465
- }), showPanelNavigation ? panelNavigation : null]
472
+ }), showPanelNavigation ? activePanelNavigation : null]
466
473
  });
467
474
  });
468
475
  Carousel.propTypes = { ...selectedSystemPropTypes,
@@ -543,6 +550,13 @@ Carousel.propTypes = { ...selectedSystemPropTypes,
543
550
  */
544
551
  skipLinkHref: PropTypes.string,
545
552
 
553
+ /**
554
+ * If provided, defaults the navigation panel to a CarouselTabsPanel element passing each item as props for one tab.
555
+ *
556
+ * Be careful to ensure that the order of each element in the items array matches the order of each child in the Carousel.
557
+ */
558
+ tabs: PropTypes.arrayOf(PropTypes.shape(CarouselTabsPanelItem.propTypes || {})),
559
+
546
560
  /**
547
561
  * If true, whenever a new slide comes into view, the focus of the Carousel switches to the start.
548
562
  *
@@ -4,7 +4,10 @@ import React, { forwardRef } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import { useResponsiveProp } from '../../utils';
6
6
  import Carousel from '../Carousel';
7
- import CarouselTabsPanel from './CarouselTabsPanel';
7
+ /**
8
+ * @deprecated Please use Carousel and pass the `tabs` prop.
9
+ */
10
+
8
11
  import { jsx as _jsx } from "react/jsx-runtime";
9
12
  const CarouselTabs = /*#__PURE__*/forwardRef((_ref, ref) => {
10
13
  let {
@@ -12,16 +15,14 @@ const CarouselTabs = /*#__PURE__*/forwardRef((_ref, ref) => {
12
15
  refocus = true,
13
16
  ...carouselProps
14
17
  } = _ref;
15
- const panelNavigation = useResponsiveProp({
16
- md: /*#__PURE__*/_jsx(CarouselTabsPanel, {
17
- items: items
18
- })
18
+ const tabs = useResponsiveProp({
19
+ md: items
19
20
  });
20
21
  return /*#__PURE__*/_jsx(Carousel, {
21
22
  refocus: refocus,
22
23
  ...carouselProps,
23
24
  ref: ref,
24
- panelNavigation: panelNavigation,
25
+ tabs: tabs,
25
26
  children: items.map(_ref2 => {
26
27
  let {
27
28
  title,
@@ -191,6 +191,14 @@ const Checkbox = /*#__PURE__*/forwardRef((_ref5, ref) => {
191
191
  const {
192
192
  themeOptions
193
193
  } = useTheme();
194
+ const selectedProps = selectProps({
195
+ accessibilityRole: 'checkbox',
196
+ accessibilityState: {
197
+ checked: isChecked,
198
+ disabled: inactive
199
+ },
200
+ ...rest
201
+ });
194
202
  return /*#__PURE__*/_jsx(View, {
195
203
  style: staticStyles.wrapper,
196
204
  ref: ref,
@@ -201,12 +209,7 @@ const Checkbox = /*#__PURE__*/forwardRef((_ref5, ref) => {
201
209
  disabled: inactive,
202
210
  onKeyDown: handleKeyDown,
203
211
  onPress: handleChange,
204
- accessibilityRole: "checkbox",
205
- accessibilityState: {
206
- checked: isChecked,
207
- disabled: inactive
208
- },
209
- ...selectProps(rest),
212
+ ...selectedProps,
210
213
  children: _ref6 => {
211
214
  let {
212
215
  focused: focus,
@@ -67,12 +67,13 @@ const ExpandCollapseControl = /*#__PURE__*/forwardRef((_ref3, ref) => {
67
67
  ...rest
68
68
  } = _ref3;
69
69
  const getTokens = useThemeTokensCallback('ExpandCollapseControl', tokens, variant);
70
- const selectedProps = selectProps({ ...rest,
71
- accessibilityRole
70
+ const selectedProps = selectProps({
71
+ accessibilityRole,
72
+ ...rest,
73
+ accessibilityState: { ...(rest.accessibilityState || {}),
74
+ expanded: isExpanded
75
+ }
72
76
  });
73
- selectedProps.accessibilityState = { ...(selectedProps.accessibilityState || {}),
74
- expanded: isExpanded
75
- };
76
77
 
77
78
  const getControlState = _ref4 => {
78
79
  let {
@@ -55,10 +55,11 @@ const ExpandCollapsePanel = /*#__PURE__*/forwardRef((_ref2, ref) => {
55
55
  } = _ref2;
56
56
  const [containerHeight, setContainerHeight] = useState(null);
57
57
  const isExpanded = openIds.includes(panelId);
58
- const selectedProps = selectProps(rest);
59
- selectedProps.accessibilityState = { ...(selectedProps.accessibilityState || {}),
60
- expanded: isExpanded
61
- };
58
+ const selectedProps = selectProps({ ...rest,
59
+ accessibilityState: { ...(rest.accessibilityState || {}),
60
+ expanded: isExpanded
61
+ }
62
+ });
62
63
  const themeTokens = useThemeTokens('ExpandCollapsePanel', tokens, variant, {
63
64
  expanded: isExpanded
64
65
  });
@@ -1,252 +1,30 @@
1
1
  import React, { forwardRef } from 'react';
2
- import View from "react-native-web/dist/exports/View";
3
- import Platform from "react-native-web/dist/exports/Platform";
4
- import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
- import PropTypes from 'prop-types';
6
- import { useTheme, useThemeTokens, applyTextStyles } from '../ThemeProvider';
7
- import { a11yProps, getTokensPropType, selectSystemProps, variantProp, viewProps, wrapStringsInText } from '../utils';
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- import { Fragment as _Fragment } from "react/jsx-runtime";
10
- import { jsxs as _jsxs } from "react/jsx-runtime";
11
- const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
12
-
13
- const selectBulletStyles = _ref => {
14
- let {
15
- itemBulletWidth,
16
- itemBulletHeight,
17
- itemBulletColor
18
- } = _ref;
19
- return {
20
- width: itemBulletWidth,
21
- height: itemBulletHeight,
22
- borderRadius: itemBulletHeight / 2,
23
- backgroundColor: itemBulletColor
24
- };
25
- };
26
-
27
- const selectBulletContainerStyles = _ref2 => {
28
- let {
29
- itemBulletContainerWidth,
30
- itemBulletContainerAlign
31
- } = _ref2;
32
- return {
33
- width: itemBulletContainerWidth,
34
- alignItems: itemBulletContainerAlign
35
- };
36
- };
37
-
38
- const selectItemIconTokens = _ref3 => {
39
- let {
40
- itemIconSize,
41
- itemIconColor
42
- } = _ref3;
43
- return {
44
- size: itemIconSize,
45
- color: itemIconColor
46
- };
47
- };
48
-
49
- const selectSideItemContainerStyles = _ref4 => {
50
- let {
51
- listGutter,
52
- iconMarginTop
53
- } = _ref4;
54
- return {
55
- marginTop: iconMarginTop,
56
- marginRight: listGutter
57
- };
58
- }; // Align bullets with the top line of text the same way icons are aligned
59
-
60
-
61
- const selectBulletPositioningStyles = _ref5 => {
62
- let {
63
- itemIconSize
64
- } = _ref5;
65
- return {
66
- width: itemIconSize,
67
- height: itemIconSize
68
- };
69
- };
70
-
71
- const selectItemStyles = (_ref6, themeOptions) => {
72
- let {
73
- itemFontWeight,
74
- itemFontSize,
75
- itemLineHeight,
76
- itemFontName
77
- } = _ref6;
78
- return applyTextStyles({
79
- fontWeight: itemFontWeight,
80
- fontSize: itemFontSize,
81
- lineHeight: itemLineHeight,
82
- fontName: itemFontName,
83
- themeOptions
84
- });
85
- };
86
-
87
- const selectItemBlockStyles = _ref7 => {
88
- let {
89
- interItemMargin
90
- } = _ref7;
91
- return {
92
- marginBottom: interItemMargin
93
- };
94
- };
95
-
96
- const selectDividerStyles = _ref8 => {
97
- let {
98
- dividerColor,
99
- dividerSize,
100
- interItemMarginWithDivider
101
- } = _ref8;
102
- return {
103
- borderBottomWidth: dividerSize,
104
- borderColor: dividerColor,
105
- marginBottom: interItemMarginWithDivider,
106
- paddingBottom: interItemMarginWithDivider
107
- };
108
- };
2
+ import ListItemBase from './ListItemBase';
3
+ import { useThemeTokens } from '../ThemeProvider';
4
+ import { variantProp } from '../utils';
109
5
  /**
110
6
  * ListItem is responsible for rendering icon or a bullet as side item
111
7
  */
112
8
 
113
-
114
- const ListItem = /*#__PURE__*/forwardRef((_ref9, ref) => {
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ const ListItem = /*#__PURE__*/forwardRef((_ref, ref) => {
115
11
  let {
116
12
  tokens,
117
13
  variant,
118
- icon,
119
- iconColor,
120
- iconSize,
121
- showDivider,
122
14
  children,
123
- isLastItem,
124
- accessibilityRole = Platform.select({
125
- web: 'listitem',
126
- default: undefined
127
- }),
128
- ...rest
129
- } = _ref9;
15
+ ...listItemProps
16
+ } = _ref;
130
17
  const themeTokens = useThemeTokens('List', tokens, variant);
131
- const {
132
- themeOptions
133
- } = useTheme();
134
- const itemStyles = selectItemStyles(themeTokens, themeOptions);
135
- const itemBlockStyles = selectItemBlockStyles(themeTokens);
136
- const dividerStyles = selectDividerStyles(themeTokens);
137
- const itemBulletContainerStyles = selectBulletContainerStyles(themeTokens);
138
- const itemBulletStyles = selectBulletStyles(themeTokens);
139
- const itemBulletPositioningStyles = selectBulletPositioningStyles(themeTokens);
140
- const iconTokens = selectItemIconTokens(themeTokens);
141
- const sideItemContainerStyles = selectSideItemContainerStyles(themeTokens);
142
-
143
- const renderItem = () => /*#__PURE__*/_jsx(View, {
144
- style: staticStyles.wrap,
145
- children: wrapStringsInText(children, {
146
- style: itemStyles
147
- })
148
- });
149
- /**
150
- * Function responsible returning styling, in case the item is the last shouldn't
151
- * add extra margin on the bottom, if "showDivider" is true it should add a divider
152
- * and custom margin and padding, otherwise just adds a margin to the bottom
153
- */
154
-
155
-
156
- const getContainerStyle = () => {
157
- if (isLastItem) {
158
- return undefined;
159
- }
160
-
161
- if (showDivider) {
162
- return dividerStyles;
163
- }
164
-
165
- return itemBlockStyles;
166
- };
167
- /**
168
- * Renders item bullet or Icon in case it's defined
169
- * in case children are string the icon is centered otherwise
170
- * it will align itself at start of the container
171
- */
172
-
173
-
174
- const renderMarker = () => {
175
- const IconComponent = icon || /*#__PURE__*/_jsx(_Fragment, {});
176
-
177
- if (icon) {
178
- return /*#__PURE__*/_jsx(View, {
179
- style: sideItemContainerStyles,
180
- children: /*#__PURE__*/_jsx(IconComponent, {
181
- size: iconSize || iconTokens.size,
182
- color: iconColor || iconTokens.color
183
- })
184
- });
185
- }
186
-
187
- return /*#__PURE__*/_jsx(View, {
188
- style: [sideItemContainerStyles, itemBulletContainerStyles],
189
- children: /*#__PURE__*/_jsx(View, {
190
- style: [staticStyles.bulletPositioning, itemBulletPositioningStyles],
191
- children: /*#__PURE__*/_jsx(View, {
192
- style: itemBulletStyles,
193
- testID: "unordered-item-bullet"
194
- })
195
- })
196
- });
197
- };
198
-
199
- return /*#__PURE__*/_jsxs(View, {
18
+ return /*#__PURE__*/_jsx(ListItemBase, {
19
+ tokens: themeTokens,
200
20
  ref: ref,
201
- style: [staticStyles.itemContainer, getContainerStyle()],
202
- accessibilityRole: accessibilityRole,
203
- ...selectProps(rest),
204
- children: [renderMarker(), renderItem()]
21
+ ...listItemProps,
22
+ children: children
205
23
  });
206
24
  });
207
25
  ListItem.displayName = 'ListItem';
208
- const staticStyles = StyleSheet.create({
209
- itemContainer: {
210
- flexDirection: 'row'
211
- },
212
- wrap: {
213
- flex: 1
214
- },
215
- bulletPositioning: {
216
- alignItems: 'center',
217
- justifyContent: 'center'
218
- }
219
- });
220
- ListItem.propTypes = { ...selectedSystemPropTypes,
221
- tokens: getTokensPropType('List'),
26
+ ListItem.propTypes = {
222
27
  variant: variantProp.propType,
223
- children: PropTypes.node.isRequired,
224
-
225
- /**
226
- * Renders side item icon
227
- */
228
- icon: PropTypes.elementType,
229
-
230
- /**
231
- * Will set display icon color
232
- */
233
- iconColor: PropTypes.string,
234
-
235
- /**
236
- * Allow the user define the icon size if not defined the theme's file
237
- */
238
- iconSize: PropTypes.number,
239
-
240
- /**
241
- * @ignore
242
- * Defined by parent if it's last item on the list
243
- */
244
- isLastItem: PropTypes.bool,
245
-
246
- /**
247
- * @ignore
248
- * In case it is not the last item allow display divider
249
- */
250
- showDivider: PropTypes.bool
28
+ ...ListItemBase.propTypes
251
29
  };
252
30
  export default ListItem;
@@ -0,0 +1,139 @@
1
+ import React, { forwardRef } from 'react';
2
+ import View from "react-native-web/dist/exports/View";
3
+ import Platform from "react-native-web/dist/exports/Platform";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import PropTypes from 'prop-types';
6
+ import { a11yProps, getTokensPropType, selectSystemProps, variantProp, viewProps } from '../utils';
7
+ import ListItemContent from './ListItemContent';
8
+ import ListItemMark from './ListItemMark';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ const [selectProps, selectedSystemPropTypes] = selectSystemProps([a11yProps, viewProps]);
13
+
14
+ const selectItemBlockStyles = _ref => {
15
+ let {
16
+ interItemMargin
17
+ } = _ref;
18
+ return {
19
+ marginBottom: interItemMargin
20
+ };
21
+ };
22
+
23
+ const selectDividerStyles = _ref2 => {
24
+ let {
25
+ dividerColor,
26
+ dividerSize,
27
+ interItemMarginWithDivider
28
+ } = _ref2;
29
+ return {
30
+ borderBottomWidth: dividerSize,
31
+ borderColor: dividerColor,
32
+ marginBottom: interItemMarginWithDivider,
33
+ paddingBottom: interItemMarginWithDivider
34
+ };
35
+ };
36
+ /**
37
+ * ListItem is responsible for rendering icon or a bullet as side item
38
+ */
39
+
40
+
41
+ const ListItemBase = /*#__PURE__*/forwardRef((_ref3, ref) => {
42
+ let {
43
+ tokens,
44
+ icon,
45
+ iconColor,
46
+ iconSize,
47
+ showDivider,
48
+ children,
49
+ isLastItem,
50
+ accessibilityRole = Platform.select({
51
+ web: 'listitem',
52
+ default: undefined
53
+ }),
54
+ ...rest
55
+ } = _ref3;
56
+ const themeTokens = typeof tokens === 'function' ? tokens() : tokens;
57
+ const itemBlockStyles = selectItemBlockStyles(themeTokens);
58
+ const dividerStyles = selectDividerStyles(themeTokens);
59
+ /**
60
+ * Function responsible returning styling, in case the item is the last shouldn't
61
+ * add extra margin on the bottom, if "showDivider" is true it should add a divider
62
+ * and custom margin and padding, otherwise just adds a margin to the bottom
63
+ */
64
+
65
+ const getContainerStyle = () => {
66
+ if (isLastItem) {
67
+ return undefined;
68
+ }
69
+
70
+ if (showDivider) {
71
+ return dividerStyles;
72
+ }
73
+
74
+ return itemBlockStyles;
75
+ };
76
+
77
+ return /*#__PURE__*/_jsx(View, {
78
+ ref: ref,
79
+ style: [staticStyles.itemContainer, getContainerStyle()],
80
+ accessibilityRole: accessibilityRole,
81
+ ...selectProps(rest),
82
+ children: typeof children === 'function' ? children({
83
+ tokens,
84
+ icon,
85
+ iconColor,
86
+ iconSize,
87
+ isLastItem
88
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
89
+ children: [/*#__PURE__*/_jsx(ListItemMark, {
90
+ tokens: tokens,
91
+ icon: icon,
92
+ iconColor: iconColor,
93
+ iconSize: iconSize
94
+ }), /*#__PURE__*/_jsx(ListItemContent, {
95
+ tokens: tokens,
96
+ children: children
97
+ })]
98
+ })
99
+ });
100
+ });
101
+ ListItemBase.displayName = 'ListItem';
102
+ const staticStyles = StyleSheet.create({
103
+ itemContainer: {
104
+ flexDirection: 'row'
105
+ }
106
+ });
107
+ ListItemBase.propTypes = { ...selectedSystemPropTypes,
108
+ tokens: getTokensPropType('List'),
109
+ variant: variantProp.propType,
110
+ children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
111
+
112
+ /**
113
+ * Renders side item icon
114
+ */
115
+ icon: PropTypes.elementType,
116
+
117
+ /**
118
+ * Will set display icon color
119
+ */
120
+ iconColor: PropTypes.string,
121
+
122
+ /**
123
+ * Allow the user define the icon size if not defined the theme's file
124
+ */
125
+ iconSize: PropTypes.number,
126
+
127
+ /**
128
+ * @ignore
129
+ * Defined by parent if it's last item on the list
130
+ */
131
+ isLastItem: PropTypes.bool,
132
+
133
+ /**
134
+ * @ignore
135
+ * In case it is not the last item allow display divider
136
+ */
137
+ showDivider: PropTypes.bool
138
+ };
139
+ export default ListItemBase;
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import View from "react-native-web/dist/exports/View";
4
+ import StyleSheet from "react-native-web/dist/exports/StyleSheet";
5
+ import { wrapStringsInText } from '../utils';
6
+ import { useTheme, applyTextStyles } from '../ThemeProvider';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export const tokenTypes = {
9
+ itemFontWeight: PropTypes.string.isRequired,
10
+ itemFontSize: PropTypes.number.isRequired,
11
+ itemLineHeight: PropTypes.number.isRequired,
12
+ itemFontName: PropTypes.string.isRequired
13
+ };
14
+
15
+ const selectItemTextStyles = (_ref, themeOptions) => {
16
+ let {
17
+ itemFontWeight,
18
+ itemFontSize,
19
+ itemLineHeight,
20
+ itemFontName
21
+ } = _ref;
22
+ return applyTextStyles({
23
+ fontWeight: itemFontWeight,
24
+ fontSize: itemFontSize,
25
+ lineHeight: itemLineHeight,
26
+ fontName: itemFontName,
27
+ themeOptions
28
+ });
29
+ };
30
+ /**
31
+ * Subcomponent used within ListItem and similar components for rendering content that fills
32
+ * and wraps available space in a { flexDirection: row } container alongside a ListIconMark,
33
+ * and that applies text styles to strings via supplied tokens.
34
+ *
35
+ * It's the responsibility of themes to make sure that these text tokens align the first line of
36
+ * text nicely against the bullet or icon rendered by ListIconMark.
37
+ */
38
+
39
+
40
+ const ListItemContent = _ref2 => {
41
+ let {
42
+ tokens,
43
+ children
44
+ } = _ref2;
45
+ const {
46
+ themeOptions
47
+ } = useTheme();
48
+ const textStyles = selectItemTextStyles(tokens, themeOptions);
49
+ return /*#__PURE__*/_jsx(View, {
50
+ style: staticStyles.wrap,
51
+ children: wrapStringsInText(children, {
52
+ style: textStyles
53
+ })
54
+ });
55
+ };
56
+
57
+ const staticStyles = StyleSheet.create({
58
+ wrap: {
59
+ flex: 1
60
+ }
61
+ });
62
+ ListItemContent.propTypes = {
63
+ tokens: PropTypes.shape(tokenTypes).isRequired,
64
+ children: PropTypes.node.isRequired
65
+ };
66
+ export default ListItemContent;