@pagopa/io-app-design-system 3.0.1 → 4.0.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/lib/commonjs/components/alert/Alert.js +1 -2
- package/lib/commonjs/components/alert/Alert.js.map +1 -1
- package/lib/commonjs/components/alert/AlertEdgeToEdge.js +2 -2
- package/lib/commonjs/components/alert/AlertEdgeToEdge.js.map +1 -1
- package/lib/commonjs/components/banner/Banner.js +1 -1
- package/lib/commonjs/components/banner/Banner.js.map +1 -1
- package/lib/commonjs/components/banner/__test__/__snapshots__/banner.test.tsx.snap +2 -2
- package/lib/commonjs/components/buttons/ButtonLink.js +1 -1
- package/lib/commonjs/components/buttons/ButtonLink.js.map +1 -1
- package/lib/commonjs/components/buttons/ButtonOutline.js +1 -1
- package/lib/commonjs/components/buttons/ButtonOutline.js.map +1 -1
- package/lib/commonjs/components/buttons/__test__/__snapshots__/button.test.tsx.snap +3 -3
- package/lib/commonjs/components/featureInfo/FeatureInfo.js +3 -2
- package/lib/commonjs/components/featureInfo/FeatureInfo.js.map +1 -1
- package/lib/commonjs/components/index.js +11 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/layout/HeaderFirstLevel.js +1 -0
- package/lib/commonjs/components/layout/HeaderFirstLevel.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemCheckbox.js +1 -1
- package/lib/commonjs/components/listitems/ListItemCheckbox.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemInfo.js +1 -1
- package/lib/commonjs/components/listitems/ListItemInfo.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemInfoCopy.js +1 -1
- package/lib/commonjs/components/listitems/ListItemInfoCopy.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemNav.js +1 -1
- package/lib/commonjs/components/listitems/ListItemNav.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemNavAlert.js +1 -1
- package/lib/commonjs/components/listitems/ListItemNavAlert.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemRadio.js +1 -1
- package/lib/commonjs/components/listitems/ListItemRadio.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemRadioWithAmount.js +2 -2
- package/lib/commonjs/components/listitems/ListItemRadioWithAmount.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemSwitch.js +1 -1
- package/lib/commonjs/components/listitems/ListItemSwitch.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemTransaction.js +2 -2
- package/lib/commonjs/components/listitems/ListItemTransaction.js.map +1 -1
- package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +7 -7
- package/lib/commonjs/components/modules/ModuleAttachment.js +1 -1
- package/lib/commonjs/components/modules/ModuleAttachment.js.map +1 -1
- package/lib/commonjs/components/modules/ModuleCheckout.js +1 -1
- package/lib/commonjs/components/modules/ModuleCheckout.js.map +1 -1
- package/lib/commonjs/components/modules/ModuleCredential.js +1 -1
- package/lib/commonjs/components/modules/ModuleCredential.js.map +1 -1
- package/lib/commonjs/components/modules/ModuleNavigation.js +3 -2
- package/lib/commonjs/components/modules/ModuleNavigation.js.map +1 -1
- package/lib/commonjs/components/modules/ModulePaymentNotice.js +2 -2
- package/lib/commonjs/components/modules/ModulePaymentNotice.js.map +1 -1
- package/lib/commonjs/components/modules/ModuleSummary.js +1 -1
- package/lib/commonjs/components/modules/ModuleSummary.js.map +1 -1
- package/lib/commonjs/components/otpInput/BoxedInput.js +4 -6
- package/lib/commonjs/components/otpInput/BoxedInput.js.map +1 -1
- package/lib/commonjs/components/otpInput/OTPInput.js +5 -4
- package/lib/commonjs/components/otpInput/OTPInput.js.map +1 -1
- package/lib/commonjs/components/tabs/TabItem.js +1 -1
- package/lib/commonjs/components/tabs/TabItem.js.map +1 -1
- package/lib/commonjs/components/textInput/TextInputBase.js +2 -2
- package/lib/commonjs/components/textInput/TextInputBase.js.map +1 -1
- package/lib/commonjs/components/tooltip/Arrows.js +49 -0
- package/lib/commonjs/components/tooltip/Arrows.js.map +1 -0
- package/lib/commonjs/components/tooltip/Tooltip.js +174 -0
- package/lib/commonjs/components/tooltip/Tooltip.js.map +1 -0
- package/lib/commonjs/components/tooltip/index.js +17 -0
- package/lib/commonjs/components/tooltip/index.js.map +1 -0
- package/lib/commonjs/components/tooltip/styles.js +50 -0
- package/lib/commonjs/components/tooltip/styles.js.map +1 -0
- package/lib/commonjs/components/tooltip/utils/index.js +180 -0
- package/lib/commonjs/components/tooltip/utils/index.js.map +1 -0
- package/lib/commonjs/components/tooltip/utils/types.js +2 -0
- package/lib/commonjs/components/tooltip/utils/types.js.map +1 -0
- package/lib/commonjs/components/typography/{LabelSmall.js → BodySmall.js} +8 -10
- package/lib/commonjs/components/typography/BodySmall.js.map +1 -0
- package/lib/commonjs/components/typography/ButtonText.js +1 -3
- package/lib/commonjs/components/typography/ButtonText.js.map +1 -1
- package/lib/commonjs/components/typography/H3.js +3 -6
- package/lib/commonjs/components/typography/H3.js.map +1 -1
- package/lib/commonjs/components/typography/H6.js +4 -5
- package/lib/commonjs/components/typography/H6.js.map +1 -1
- package/lib/commonjs/components/typography/__test__/__snapshots__/typography.test.tsx.snap +118 -161
- package/lib/commonjs/components/typography/__test__/typography.test.js +6 -18
- package/lib/commonjs/components/typography/__test__/typography.test.js.map +1 -1
- package/lib/commonjs/components/typography/index.js +28 -72
- package/lib/commonjs/components/typography/index.js.map +1 -1
- package/lib/module/components/alert/Alert.js +2 -3
- package/lib/module/components/alert/Alert.js.map +1 -1
- package/lib/module/components/alert/AlertEdgeToEdge.js +2 -2
- package/lib/module/components/alert/AlertEdgeToEdge.js.map +1 -1
- package/lib/module/components/banner/Banner.js +2 -2
- package/lib/module/components/banner/Banner.js.map +1 -1
- package/lib/module/components/banner/__test__/__snapshots__/banner.test.tsx.snap +2 -2
- package/lib/module/components/buttons/ButtonLink.js +1 -1
- package/lib/module/components/buttons/ButtonLink.js.map +1 -1
- package/lib/module/components/buttons/ButtonOutline.js +1 -1
- package/lib/module/components/buttons/ButtonOutline.js.map +1 -1
- package/lib/module/components/buttons/__test__/__snapshots__/button.test.tsx.snap +3 -3
- package/lib/module/components/featureInfo/FeatureInfo.js +4 -3
- package/lib/module/components/featureInfo/FeatureInfo.js.map +1 -1
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/layout/HeaderFirstLevel.js +1 -0
- package/lib/module/components/layout/HeaderFirstLevel.js.map +1 -1
- package/lib/module/components/listitems/ListItemCheckbox.js +2 -2
- package/lib/module/components/listitems/ListItemCheckbox.js.map +1 -1
- package/lib/module/components/listitems/ListItemInfo.js +2 -2
- package/lib/module/components/listitems/ListItemInfo.js.map +1 -1
- package/lib/module/components/listitems/ListItemInfoCopy.js +2 -2
- package/lib/module/components/listitems/ListItemInfoCopy.js.map +1 -1
- package/lib/module/components/listitems/ListItemNav.js +2 -2
- package/lib/module/components/listitems/ListItemNav.js.map +1 -1
- package/lib/module/components/listitems/ListItemNavAlert.js +2 -2
- package/lib/module/components/listitems/ListItemNavAlert.js.map +1 -1
- package/lib/module/components/listitems/ListItemRadio.js +2 -2
- package/lib/module/components/listitems/ListItemRadio.js.map +1 -1
- package/lib/module/components/listitems/ListItemRadioWithAmount.js +3 -3
- package/lib/module/components/listitems/ListItemRadioWithAmount.js.map +1 -1
- package/lib/module/components/listitems/ListItemSwitch.js +2 -2
- package/lib/module/components/listitems/ListItemSwitch.js.map +1 -1
- package/lib/module/components/listitems/ListItemTransaction.js +3 -3
- package/lib/module/components/listitems/ListItemTransaction.js.map +1 -1
- package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +7 -7
- package/lib/module/components/modules/ModuleAttachment.js +2 -2
- package/lib/module/components/modules/ModuleAttachment.js.map +1 -1
- package/lib/module/components/modules/ModuleCheckout.js +2 -2
- package/lib/module/components/modules/ModuleCheckout.js.map +1 -1
- package/lib/module/components/modules/ModuleCredential.js +2 -2
- package/lib/module/components/modules/ModuleCredential.js.map +1 -1
- package/lib/module/components/modules/ModuleNavigation.js +4 -3
- package/lib/module/components/modules/ModuleNavigation.js.map +1 -1
- package/lib/module/components/modules/ModulePaymentNotice.js +3 -3
- package/lib/module/components/modules/ModulePaymentNotice.js.map +1 -1
- package/lib/module/components/modules/ModuleSummary.js +2 -2
- package/lib/module/components/modules/ModuleSummary.js.map +1 -1
- package/lib/module/components/otpInput/BoxedInput.js +5 -7
- package/lib/module/components/otpInput/BoxedInput.js.map +1 -1
- package/lib/module/components/otpInput/OTPInput.js +5 -4
- package/lib/module/components/otpInput/OTPInput.js.map +1 -1
- package/lib/module/components/tabs/TabItem.js +2 -2
- package/lib/module/components/tabs/TabItem.js.map +1 -1
- package/lib/module/components/textInput/TextInputBase.js +3 -3
- package/lib/module/components/textInput/TextInputBase.js.map +1 -1
- package/lib/module/components/tooltip/Arrows.js +36 -0
- package/lib/module/components/tooltip/Arrows.js.map +1 -0
- package/lib/module/components/tooltip/Tooltip.js +165 -0
- package/lib/module/components/tooltip/Tooltip.js.map +1 -0
- package/lib/module/components/tooltip/index.js +2 -0
- package/lib/module/components/tooltip/index.js.map +1 -0
- package/lib/module/components/tooltip/styles.js +43 -0
- package/lib/module/components/tooltip/styles.js.map +1 -0
- package/lib/module/components/tooltip/utils/index.js +163 -0
- package/lib/module/components/tooltip/utils/index.js.map +1 -0
- package/lib/module/components/tooltip/utils/types.js +2 -0
- package/lib/module/components/tooltip/utils/types.js.map +1 -0
- package/lib/module/components/typography/{LabelSmall.js → BodySmall.js} +6 -8
- package/lib/module/components/typography/BodySmall.js.map +1 -0
- package/lib/module/components/typography/ButtonText.js +1 -3
- package/lib/module/components/typography/ButtonText.js.map +1 -1
- package/lib/module/components/typography/H3.js +3 -6
- package/lib/module/components/typography/H3.js.map +1 -1
- package/lib/module/components/typography/H6.js +4 -5
- package/lib/module/components/typography/H6.js.map +1 -1
- package/lib/module/components/typography/__test__/__snapshots__/typography.test.tsx.snap +118 -161
- package/lib/module/components/typography/__test__/typography.test.js +6 -18
- package/lib/module/components/typography/__test__/typography.test.js.map +1 -1
- package/lib/module/components/typography/index.js +6 -10
- package/lib/module/components/typography/index.js.map +1 -1
- package/lib/typescript/components/alert/Alert.d.ts.map +1 -1
- package/lib/typescript/components/banner/Banner.d.ts +1 -1
- package/lib/typescript/components/banner/Banner.d.ts.map +1 -1
- package/lib/typescript/components/featureInfo/FeatureInfo.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/components/layout/HeaderFirstLevel.d.ts.map +1 -1
- package/lib/typescript/components/listitems/ListItemSwitch.d.ts.map +1 -1
- package/lib/typescript/components/modules/ModuleNavigation.d.ts.map +1 -1
- package/lib/typescript/components/otpInput/BoxedInput.d.ts.map +1 -1
- package/lib/typescript/components/otpInput/OTPInput.d.ts.map +1 -1
- package/lib/typescript/components/tooltip/Arrows.d.ts +14 -0
- package/lib/typescript/components/tooltip/Arrows.d.ts.map +1 -0
- package/lib/typescript/components/tooltip/Tooltip.d.ts +64 -0
- package/lib/typescript/components/tooltip/Tooltip.d.ts.map +1 -0
- package/lib/typescript/components/tooltip/index.d.ts +2 -0
- package/lib/typescript/components/tooltip/index.d.ts.map +1 -0
- package/lib/typescript/components/tooltip/styles.d.ts +41 -0
- package/lib/typescript/components/tooltip/styles.d.ts.map +1 -0
- package/lib/typescript/components/tooltip/utils/index.d.ts +89 -0
- package/lib/typescript/components/tooltip/utils/index.d.ts.map +1 -0
- package/lib/typescript/components/tooltip/utils/types.d.ts +10 -0
- package/lib/typescript/components/tooltip/utils/types.d.ts.map +1 -0
- package/lib/typescript/components/typography/Body.d.ts +1 -1
- package/lib/typescript/components/typography/Body.d.ts.map +1 -1
- package/lib/typescript/components/typography/BodySmall.d.ts +13 -0
- package/lib/typescript/components/typography/BodySmall.d.ts.map +1 -0
- package/lib/typescript/components/typography/ButtonText.d.ts.map +1 -1
- package/lib/typescript/components/typography/H3.d.ts +2 -0
- package/lib/typescript/components/typography/H3.d.ts.map +1 -1
- package/lib/typescript/components/typography/H6.d.ts.map +1 -1
- package/lib/typescript/components/typography/LabelMini.d.ts +1 -1
- package/lib/typescript/components/typography/LabelMini.d.ts.map +1 -1
- package/lib/typescript/components/typography/index.d.ts +6 -10
- package/lib/typescript/components/typography/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/alert/Alert.tsx +3 -4
- package/src/components/alert/AlertEdgeToEdge.tsx +3 -3
- package/src/components/banner/Banner.tsx +7 -5
- package/src/components/banner/__test__/__snapshots__/banner.test.tsx.snap +2 -2
- package/src/components/buttons/ButtonLink.tsx +1 -1
- package/src/components/buttons/ButtonOutline.tsx +1 -1
- package/src/components/buttons/__test__/__snapshots__/button.test.tsx.snap +3 -3
- package/src/components/featureInfo/FeatureInfo.tsx +6 -6
- package/src/components/index.tsx +1 -0
- package/src/components/layout/HeaderFirstLevel.tsx +1 -0
- package/src/components/listitems/ListItemCheckbox.tsx +3 -3
- package/src/components/listitems/ListItemInfo.tsx +3 -3
- package/src/components/listitems/ListItemInfoCopy.tsx +3 -3
- package/src/components/listitems/ListItemNav.tsx +3 -3
- package/src/components/listitems/ListItemNavAlert.tsx +3 -3
- package/src/components/listitems/ListItemRadio.tsx +3 -3
- package/src/components/listitems/ListItemRadioWithAmount.tsx +5 -5
- package/src/components/listitems/ListItemSwitch.tsx +4 -4
- package/src/components/listitems/ListItemTransaction.tsx +5 -5
- package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +7 -7
- package/src/components/modules/ModuleAttachment.tsx +3 -3
- package/src/components/modules/ModuleCheckout.tsx +3 -3
- package/src/components/modules/ModuleCredential.tsx +3 -3
- package/src/components/modules/ModuleNavigation.tsx +6 -4
- package/src/components/modules/ModulePaymentNotice.tsx +5 -5
- package/src/components/modules/ModuleSummary.tsx +3 -3
- package/src/components/otpInput/BoxedInput.tsx +6 -5
- package/src/components/otpInput/OTPInput.tsx +23 -8
- package/src/components/tabs/TabItem.tsx +3 -3
- package/src/components/textInput/TextInputBase.tsx +5 -5
- package/src/components/tooltip/Arrows.tsx +36 -0
- package/src/components/tooltip/Tooltip.tsx +313 -0
- package/src/components/tooltip/index.ts +1 -0
- package/src/components/tooltip/styles.ts +44 -0
- package/src/components/tooltip/utils/index.ts +179 -0
- package/src/components/tooltip/utils/types.ts +9 -0
- package/src/components/typography/Body.tsx +1 -1
- package/src/components/typography/{LabelSmall.tsx → BodySmall.tsx} +7 -14
- package/src/components/typography/ButtonText.tsx +2 -4
- package/src/components/typography/H3.tsx +11 -8
- package/src/components/typography/H6.tsx +5 -6
- package/src/components/typography/LabelMini.tsx +1 -1
- package/src/components/typography/__test__/__snapshots__/typography.test.tsx.snap +118 -161
- package/src/components/typography/__test__/typography.test.tsx +8 -24
- package/src/components/typography/index.tsx +6 -10
- package/lib/commonjs/components/typography/BaseTypography.js +0 -52
- package/lib/commonjs/components/typography/BaseTypography.js.map +0 -1
- package/lib/commonjs/components/typography/Chip.js +0 -41
- package/lib/commonjs/components/typography/Chip.js.map +0 -1
- package/lib/commonjs/components/typography/Factory.js +0 -62
- package/lib/commonjs/components/typography/Factory.js.map +0 -1
- package/lib/commonjs/components/typography/Label.js +0 -51
- package/lib/commonjs/components/typography/Label.js.map +0 -1
- package/lib/commonjs/components/typography/LabelSmall.js.map +0 -1
- package/lib/module/components/typography/BaseTypography.js +0 -44
- package/lib/module/components/typography/BaseTypography.js.map +0 -1
- package/lib/module/components/typography/Chip.js +0 -32
- package/lib/module/components/typography/Chip.js.map +0 -1
- package/lib/module/components/typography/Factory.js +0 -55
- package/lib/module/components/typography/Factory.js.map +0 -1
- package/lib/module/components/typography/Label.js +0 -42
- package/lib/module/components/typography/Label.js.map +0 -1
- package/lib/module/components/typography/LabelSmall.js.map +0 -1
- package/lib/typescript/components/typography/BaseTypography.d.ts +0 -29
- package/lib/typescript/components/typography/BaseTypography.d.ts.map +0 -1
- package/lib/typescript/components/typography/Chip.d.ts +0 -13
- package/lib/typescript/components/typography/Chip.d.ts.map +0 -1
- package/lib/typescript/components/typography/Factory.d.ts +0 -43
- package/lib/typescript/components/typography/Factory.d.ts.map +0 -1
- package/lib/typescript/components/typography/Label.d.ts +0 -13
- package/lib/typescript/components/typography/Label.d.ts.map +0 -1
- package/lib/typescript/components/typography/LabelSmall.d.ts +0 -13
- package/lib/typescript/components/typography/LabelSmall.d.ts.map +0 -1
- package/src/components/typography/BaseTypography.tsx +0 -71
- package/src/components/typography/Chip.tsx +0 -33
- package/src/components/typography/Factory.tsx +0 -98
- package/src/components/typography/Label.tsx +0 -62
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
useRef,
|
|
4
|
+
PropsWithChildren,
|
|
5
|
+
useEffect,
|
|
6
|
+
useCallback,
|
|
7
|
+
JSXElementConstructor,
|
|
8
|
+
useMemo,
|
|
9
|
+
ReactElement
|
|
10
|
+
} from "react";
|
|
11
|
+
import {
|
|
12
|
+
View,
|
|
13
|
+
Modal,
|
|
14
|
+
Dimensions,
|
|
15
|
+
LayoutChangeEvent,
|
|
16
|
+
TouchableWithoutFeedback
|
|
17
|
+
} from "react-native";
|
|
18
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
19
|
+
import { every, some } from "lodash";
|
|
20
|
+
import { IOColors } from "../../core";
|
|
21
|
+
import { Body, H6 } from "../typography";
|
|
22
|
+
import { IconButton } from "../buttons";
|
|
23
|
+
import { BottomArrow, LeftArrow, RightArrow, TopArrow } from "./Arrows";
|
|
24
|
+
import {
|
|
25
|
+
ARROW_HEIGHT,
|
|
26
|
+
EMPTY_SPACE,
|
|
27
|
+
getArrowBoxByPlacement,
|
|
28
|
+
getArrowCoords,
|
|
29
|
+
getArrowVerticalAlignment,
|
|
30
|
+
getDisplayInsets,
|
|
31
|
+
getTooltipCoords,
|
|
32
|
+
getTooltipVerticalAlignment,
|
|
33
|
+
isDefined,
|
|
34
|
+
isNotZero
|
|
35
|
+
} from "./utils";
|
|
36
|
+
import { getChildrenPosition, tooltipStyles } from "./styles";
|
|
37
|
+
import {
|
|
38
|
+
ChildrenCoords,
|
|
39
|
+
DisplayInsets,
|
|
40
|
+
Placement,
|
|
41
|
+
TooltipLayout
|
|
42
|
+
} from "./utils/types";
|
|
43
|
+
|
|
44
|
+
const screenDimensions = Dimensions.get("window");
|
|
45
|
+
const INITIAL_COORDS: ChildrenCoords = {
|
|
46
|
+
x: 0,
|
|
47
|
+
y: 0,
|
|
48
|
+
width: 0,
|
|
49
|
+
height: 0
|
|
50
|
+
};
|
|
51
|
+
const ARROWS_BY_PLACEMENT: Record<
|
|
52
|
+
Placement,
|
|
53
|
+
JSXElementConstructor<{ color: string }>
|
|
54
|
+
> = {
|
|
55
|
+
top: TopArrow,
|
|
56
|
+
bottom: BottomArrow,
|
|
57
|
+
left: LeftArrow,
|
|
58
|
+
right: RightArrow
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type CommonProps = {
|
|
62
|
+
/**
|
|
63
|
+
* The title text displayed at the top of the tooltip.
|
|
64
|
+
*/
|
|
65
|
+
title: string;
|
|
66
|
+
/**
|
|
67
|
+
* The tooltip text content.
|
|
68
|
+
*/
|
|
69
|
+
content: string;
|
|
70
|
+
/**
|
|
71
|
+
* Controls the visibility of the tooltip.
|
|
72
|
+
*/
|
|
73
|
+
isVisible: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Initial tooltip position; can be 'top', 'bottom', 'left', or 'right'.
|
|
76
|
+
* @default top
|
|
77
|
+
*/
|
|
78
|
+
placement?: Placement;
|
|
79
|
+
/**
|
|
80
|
+
* Insets for adjusting tooltip position within screen boundaries.
|
|
81
|
+
* @default {}
|
|
82
|
+
*/
|
|
83
|
+
displayInsets?: Partial<DisplayInsets>;
|
|
84
|
+
/**
|
|
85
|
+
* Accessibility label for the close icon button.
|
|
86
|
+
*/
|
|
87
|
+
closeIconAccessibilityLabel: string;
|
|
88
|
+
/**
|
|
89
|
+
* Determines whether interactions with the tooltip's children are allowed when `isVisible` is set to true.
|
|
90
|
+
* @default false
|
|
91
|
+
*/
|
|
92
|
+
childrenInteractionsEnabled?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Callback function triggered when the tooltip is closed.
|
|
95
|
+
*/
|
|
96
|
+
onClose: () => void;
|
|
97
|
+
};
|
|
98
|
+
type CloseWithTapOnBackground = {
|
|
99
|
+
/**
|
|
100
|
+
* Allows closing the tooltip by tapping outside of it.
|
|
101
|
+
*/
|
|
102
|
+
allowCloseOnBackgroundTap: true;
|
|
103
|
+
/**
|
|
104
|
+
* Accessibility label for the tooltip background mask.
|
|
105
|
+
*/
|
|
106
|
+
backgroundAccessibilityLabel: string;
|
|
107
|
+
};
|
|
108
|
+
type CloseWithBackgroundTapDisabled = {
|
|
109
|
+
allowCloseOnBackgroundTap?: false;
|
|
110
|
+
};
|
|
111
|
+
type Props = CommonProps & (CloseWithTapOnBackground | CloseWithBackgroundTapDisabled);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Tooltip component that displays a contextual tooltip around its children.
|
|
115
|
+
* The tooltip position is controlled by the `placement` prop and can adjust
|
|
116
|
+
* dynamically if there is insufficient space.
|
|
117
|
+
* @param {Props} props - The component props
|
|
118
|
+
*
|
|
119
|
+
* @returns {ReactElement} A tooltip component rendered around the specified children.
|
|
120
|
+
*/
|
|
121
|
+
export const Tooltip = ({
|
|
122
|
+
children,
|
|
123
|
+
title,
|
|
124
|
+
content,
|
|
125
|
+
placement: initialPlacement = "top",
|
|
126
|
+
closeIconAccessibilityLabel,
|
|
127
|
+
isVisible,
|
|
128
|
+
displayInsets = {},
|
|
129
|
+
allowCloseOnBackgroundTap,
|
|
130
|
+
childrenInteractionsEnabled = false,
|
|
131
|
+
onClose
|
|
132
|
+
}: PropsWithChildren<Props>): ReactElement => {
|
|
133
|
+
const insets = useSafeAreaInsets();
|
|
134
|
+
const [currentPlacement, setCurrentPlacement] =
|
|
135
|
+
useState<Placement>(initialPlacement);
|
|
136
|
+
const [childrenCoords, setChildrenCoords] = useState<ChildrenCoords>(INITIAL_COORDS);
|
|
137
|
+
const [tooltipLayout, setTooltipLayout] = useState<TooltipLayout>();
|
|
138
|
+
const childRef = useRef<View>(null);
|
|
139
|
+
const titleRef = useRef<View>(null);
|
|
140
|
+
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
|
|
141
|
+
|
|
142
|
+
const Arrow = useMemo(
|
|
143
|
+
() => ARROWS_BY_PLACEMENT[currentPlacement],
|
|
144
|
+
[currentPlacement]
|
|
145
|
+
);
|
|
146
|
+
const isChildrenMeasurementFinished =
|
|
147
|
+
every(childrenCoords, isDefined)
|
|
148
|
+
&& some(childrenCoords, isNotZero);
|
|
149
|
+
const isTooltipMeasurementCompleted = isDefined(tooltipLayout);
|
|
150
|
+
const tooltipVisibility = { opacity: isTooltipMeasurementCompleted ? 1 : 0 };
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* This function sets the `Tooltip` children coordinates
|
|
154
|
+
*/
|
|
155
|
+
const measureChildrenCoords = useCallback(() => {
|
|
156
|
+
if (childRef.current && typeof childRef.current.measure === "function") {
|
|
157
|
+
childRef.current.measure((_, __, width, height, px, py) => {
|
|
158
|
+
const coords = {
|
|
159
|
+
x: px,
|
|
160
|
+
y: py,
|
|
161
|
+
width,
|
|
162
|
+
height
|
|
163
|
+
};
|
|
164
|
+
if (every(coords, isDefined)) {
|
|
165
|
+
setChildrenCoords(coords);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
useEffect(() => {
|
|
172
|
+
if (isVisible) {
|
|
173
|
+
// A new measure is executed every time the `Tooltip` is visible
|
|
174
|
+
// This is required for use within ScrollView components.
|
|
175
|
+
// eslint-disable-next-line functional/immutable-data
|
|
176
|
+
timeoutRef.current = setTimeout(measureChildrenCoords, 100);
|
|
177
|
+
} else {
|
|
178
|
+
setChildrenCoords(INITIAL_COORDS);
|
|
179
|
+
setCurrentPlacement(initialPlacement);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return () => {
|
|
183
|
+
if (isVisible) {
|
|
184
|
+
clearTimeout(timeoutRef.current);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}, [isVisible, initialPlacement, measureChildrenCoords]);
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* This function works with `top` and `bottom` placement and sets the current placement to their opposite value
|
|
191
|
+
* if in the selected one there is no space to prompt the tooltip
|
|
192
|
+
*/
|
|
193
|
+
const invertPlacementIfNeeded = useCallback(
|
|
194
|
+
(nativeEvent: LayoutChangeEvent["nativeEvent"]) => {
|
|
195
|
+
if (initialPlacement === "top") {
|
|
196
|
+
const hasSpace = nativeEvent.layout.y >= insets.top;
|
|
197
|
+
|
|
198
|
+
if (!hasSpace) {
|
|
199
|
+
setCurrentPlacement("bottom");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (initialPlacement === "bottom") {
|
|
203
|
+
const remainingSpace =
|
|
204
|
+
screenDimensions.height - nativeEvent.layout.y - insets.bottom;
|
|
205
|
+
const tooltipMinHeight =
|
|
206
|
+
nativeEvent.layout.height + ARROW_HEIGHT + EMPTY_SPACE;
|
|
207
|
+
const hasSpace = remainingSpace >= tooltipMinHeight;
|
|
208
|
+
|
|
209
|
+
if (!hasSpace) {
|
|
210
|
+
setCurrentPlacement("top");
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
[insets.bottom, insets.top, initialPlacement]
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const handleTooltipOnLayout = useCallback(
|
|
218
|
+
({ nativeEvent }: LayoutChangeEvent) => {
|
|
219
|
+
invertPlacementIfNeeded(nativeEvent);
|
|
220
|
+
setTooltipLayout(nativeEvent.layout);
|
|
221
|
+
},
|
|
222
|
+
[invertPlacementIfNeeded]
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
const handleTapOnBackground = useCallback(() => {
|
|
226
|
+
if (allowCloseOnBackgroundTap) {
|
|
227
|
+
onClose();
|
|
228
|
+
}
|
|
229
|
+
}, [allowCloseOnBackgroundTap, onClose]);
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<>
|
|
233
|
+
<View
|
|
234
|
+
// This prop is necessary for .measure to work correctly, as explained here: https://github.com/facebook/react-native/issues/29712
|
|
235
|
+
collapsable={false}
|
|
236
|
+
ref={childRef}
|
|
237
|
+
>
|
|
238
|
+
{children}
|
|
239
|
+
</View>
|
|
240
|
+
<Modal transparent visible={isVisible && isChildrenMeasurementFinished}>
|
|
241
|
+
<View
|
|
242
|
+
accessibilityElementsHidden={!childrenInteractionsEnabled}
|
|
243
|
+
importantForAccessibility={childrenInteractionsEnabled ? 'auto' : 'no-hide-descendants'}
|
|
244
|
+
pointerEvents={childrenInteractionsEnabled ? "auto" : "box-only"}
|
|
245
|
+
style={[
|
|
246
|
+
tooltipStyles.childrenContainer,
|
|
247
|
+
getChildrenPosition(childrenCoords)
|
|
248
|
+
]}
|
|
249
|
+
>
|
|
250
|
+
{children}
|
|
251
|
+
</View>
|
|
252
|
+
<TouchableWithoutFeedback
|
|
253
|
+
accessible={allowCloseOnBackgroundTap}
|
|
254
|
+
accessibilityRole={allowCloseOnBackgroundTap ? "button" : "none"}
|
|
255
|
+
importantForAccessibility={allowCloseOnBackgroundTap ? 'yes' : 'no'}
|
|
256
|
+
accessibilityElementsHidden={!allowCloseOnBackgroundTap}
|
|
257
|
+
onPress={handleTapOnBackground}
|
|
258
|
+
>
|
|
259
|
+
<View
|
|
260
|
+
style={[
|
|
261
|
+
tooltipStyles.overlay,
|
|
262
|
+
{ height: screenDimensions.height }
|
|
263
|
+
]}
|
|
264
|
+
/>
|
|
265
|
+
</TouchableWithoutFeedback>
|
|
266
|
+
<View
|
|
267
|
+
onLayout={handleTooltipOnLayout}
|
|
268
|
+
style={[
|
|
269
|
+
tooltipStyles.tooltipContainer,
|
|
270
|
+
getTooltipCoords(
|
|
271
|
+
currentPlacement,
|
|
272
|
+
childrenCoords,
|
|
273
|
+
getDisplayInsets(displayInsets),
|
|
274
|
+
screenDimensions
|
|
275
|
+
),
|
|
276
|
+
getTooltipVerticalAlignment(
|
|
277
|
+
currentPlacement,
|
|
278
|
+
childrenCoords.height,
|
|
279
|
+
tooltipLayout?.height
|
|
280
|
+
),
|
|
281
|
+
tooltipVisibility
|
|
282
|
+
]}
|
|
283
|
+
>
|
|
284
|
+
<H6 ref={titleRef}>{title}</H6>
|
|
285
|
+
<View style={tooltipStyles.closeIcon}>
|
|
286
|
+
<IconButton
|
|
287
|
+
color="neutral"
|
|
288
|
+
icon="closeSmall"
|
|
289
|
+
accessibilityLabel={closeIconAccessibilityLabel}
|
|
290
|
+
onPress={onClose}
|
|
291
|
+
/>
|
|
292
|
+
</View>
|
|
293
|
+
<Body>{content}</Body>
|
|
294
|
+
</View>
|
|
295
|
+
<View
|
|
296
|
+
style={[
|
|
297
|
+
tooltipStyles.arrowContainer,
|
|
298
|
+
getArrowBoxByPlacement(currentPlacement),
|
|
299
|
+
getArrowCoords(
|
|
300
|
+
currentPlacement,
|
|
301
|
+
childrenCoords,
|
|
302
|
+
screenDimensions
|
|
303
|
+
),
|
|
304
|
+
getArrowVerticalAlignment(currentPlacement, childrenCoords.height),
|
|
305
|
+
tooltipVisibility
|
|
306
|
+
]}
|
|
307
|
+
>
|
|
308
|
+
<Arrow color={IOColors.white} />
|
|
309
|
+
</View>
|
|
310
|
+
</Modal>
|
|
311
|
+
</>
|
|
312
|
+
);
|
|
313
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Tooltip";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { IOColors } from '../../core';
|
|
3
|
+
import { ChildrenCoords } from './utils/types';
|
|
4
|
+
|
|
5
|
+
export const tooltipStyles = StyleSheet.create({
|
|
6
|
+
overlay: {
|
|
7
|
+
position: "absolute",
|
|
8
|
+
width: "100%",
|
|
9
|
+
height: "100%",
|
|
10
|
+
backgroundColor: IOColors["grey-850"],
|
|
11
|
+
opacity: 0.6,
|
|
12
|
+
zIndex: 997
|
|
13
|
+
},
|
|
14
|
+
childrenContainer: {
|
|
15
|
+
position: "absolute",
|
|
16
|
+
zIndex: 1000
|
|
17
|
+
},
|
|
18
|
+
tooltipContainer: {
|
|
19
|
+
position: "absolute",
|
|
20
|
+
paddingHorizontal: 16,
|
|
21
|
+
paddingVertical: 16,
|
|
22
|
+
backgroundColor: IOColors.white,
|
|
23
|
+
borderRadius: 8,
|
|
24
|
+
zIndex: 2000,
|
|
25
|
+
overflow: "visible"
|
|
26
|
+
},
|
|
27
|
+
arrowContainer: {
|
|
28
|
+
position: "absolute",
|
|
29
|
+
display: 'flex',
|
|
30
|
+
zIndex: 3000
|
|
31
|
+
},
|
|
32
|
+
closeIcon: {
|
|
33
|
+
position: 'absolute',
|
|
34
|
+
right: 8,
|
|
35
|
+
top: 9 // It's been used `9` instead of `8` to fix accessibility focus order. In this way title is read before close icon.
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const getChildrenPosition = (childrenCoords: ChildrenCoords) => ({
|
|
40
|
+
top: childrenCoords.y,
|
|
41
|
+
left: childrenCoords.x,
|
|
42
|
+
width: childrenCoords.width,
|
|
43
|
+
height: childrenCoords.height
|
|
44
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { ScaledSize } from 'react-native';
|
|
2
|
+
import { IOVisualCostants } from '../../../core';
|
|
3
|
+
import { ChildrenCoords, DisplayInsets, Placement } from './types';
|
|
4
|
+
|
|
5
|
+
export const ARROW_WIDTH = 24;
|
|
6
|
+
export const ARROW_HEIGHT = 14;
|
|
7
|
+
export const EMPTY_SPACE = 8;
|
|
8
|
+
const DEFAULT_INSETS: DisplayInsets = {
|
|
9
|
+
top: 0,
|
|
10
|
+
bottom: 0,
|
|
11
|
+
left: IOVisualCostants.appMarginDefault,
|
|
12
|
+
right: IOVisualCostants.appMarginDefault,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param displayInsets custom display insets
|
|
17
|
+
* @returns An `object` based on `DEFAULT_INSETS` and `displayInsets`
|
|
18
|
+
*/
|
|
19
|
+
export const getDisplayInsets = (
|
|
20
|
+
displayInsets: Partial<DisplayInsets>
|
|
21
|
+
): DisplayInsets => ({ ...DEFAULT_INSETS, ...displayInsets });
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param placement The `Tooltip` placement
|
|
26
|
+
* @returns The `Arrow` box `width` and `height` based on `placement` value
|
|
27
|
+
*/
|
|
28
|
+
export const getArrowBoxByPlacement = (placement: Placement) => {
|
|
29
|
+
switch (placement) {
|
|
30
|
+
case 'left':
|
|
31
|
+
case 'right':
|
|
32
|
+
return {
|
|
33
|
+
width: ARROW_HEIGHT,
|
|
34
|
+
height: ARROW_WIDTH,
|
|
35
|
+
};
|
|
36
|
+
default:
|
|
37
|
+
return {
|
|
38
|
+
height: ARROW_HEIGHT,
|
|
39
|
+
width: ARROW_WIDTH,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A utility function to calculate the `Tooltip` coordinates and dimensions
|
|
46
|
+
* @param placement The `Tooltip` placement in relation of its children
|
|
47
|
+
* @param childrenCoords The measures in screen of the `Tooltip` children
|
|
48
|
+
* @param displayInsets The active display insets
|
|
49
|
+
* @param screenDimensions The dimensions of the device screen
|
|
50
|
+
* @returns The `Tooltip` coordinates
|
|
51
|
+
*/
|
|
52
|
+
export const getTooltipCoords = (
|
|
53
|
+
placement: Placement,
|
|
54
|
+
childrenCoords: ChildrenCoords,
|
|
55
|
+
displayInsets: DisplayInsets,
|
|
56
|
+
screenDimensions: ScaledSize
|
|
57
|
+
) => {
|
|
58
|
+
const { width: screenWidth, height: screenHeight } = screenDimensions;
|
|
59
|
+
|
|
60
|
+
switch (placement) {
|
|
61
|
+
case "top":
|
|
62
|
+
return {
|
|
63
|
+
bottom: screenHeight - childrenCoords.y + ARROW_HEIGHT + EMPTY_SPACE,
|
|
64
|
+
left: displayInsets.left,
|
|
65
|
+
width: screenWidth - displayInsets.left - displayInsets.right
|
|
66
|
+
};
|
|
67
|
+
case "bottom":
|
|
68
|
+
return {
|
|
69
|
+
top: childrenCoords.y + childrenCoords.height + ARROW_HEIGHT + EMPTY_SPACE,
|
|
70
|
+
left: displayInsets.left,
|
|
71
|
+
width: screenWidth - displayInsets.left - displayInsets.right
|
|
72
|
+
};
|
|
73
|
+
case "left":
|
|
74
|
+
return {
|
|
75
|
+
top: childrenCoords.y,
|
|
76
|
+
left: displayInsets.left,
|
|
77
|
+
width:
|
|
78
|
+
screenWidth - (screenWidth - childrenCoords.x) - ARROW_HEIGHT - displayInsets.left - EMPTY_SPACE
|
|
79
|
+
};
|
|
80
|
+
case "right":
|
|
81
|
+
const elementSize = childrenCoords.width + childrenCoords.x + ARROW_HEIGHT + EMPTY_SPACE;
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
top: childrenCoords.y,
|
|
85
|
+
left: elementSize,
|
|
86
|
+
width:
|
|
87
|
+
screenWidth -
|
|
88
|
+
(elementSize + displayInsets.right)
|
|
89
|
+
};
|
|
90
|
+
// TODO: provide a default center position in case of Tooltip without children
|
|
91
|
+
default:
|
|
92
|
+
return {};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* A utility function to calculate the `Tooltip`'s `Arrow` coordinates
|
|
98
|
+
* @param placement The `Arrow` placement in relation of the `Tooltip` children
|
|
99
|
+
* @param childrenCoords The measures in screen of the `Tooltip` children
|
|
100
|
+
* @param screenDimensions The active display insets
|
|
101
|
+
* @returns The `Tooltip`'s Arrow coordinates
|
|
102
|
+
*/
|
|
103
|
+
export const getArrowCoords = (
|
|
104
|
+
placement: Placement,
|
|
105
|
+
childrenCoords: ChildrenCoords,
|
|
106
|
+
screenDimensions: ScaledSize
|
|
107
|
+
) => {
|
|
108
|
+
const { width: screenWidth, height: screenHeight } = screenDimensions;
|
|
109
|
+
|
|
110
|
+
switch (placement) {
|
|
111
|
+
case "top":
|
|
112
|
+
return {
|
|
113
|
+
bottom: screenHeight - childrenCoords.y + EMPTY_SPACE,
|
|
114
|
+
left: childrenCoords.x + childrenCoords.width / 2 - ARROW_WIDTH / 2
|
|
115
|
+
};
|
|
116
|
+
case "bottom":
|
|
117
|
+
return {
|
|
118
|
+
top: childrenCoords.y + childrenCoords.height + EMPTY_SPACE,
|
|
119
|
+
left: childrenCoords.x + childrenCoords.width / 2 - ARROW_WIDTH / 2
|
|
120
|
+
};
|
|
121
|
+
case "left":
|
|
122
|
+
return {
|
|
123
|
+
top: childrenCoords.y,
|
|
124
|
+
left: screenWidth - (screenWidth - childrenCoords.x) - ARROW_HEIGHT - EMPTY_SPACE - 1, // FIXME -> This `-1` is necessary because of the Svg size doesn't match the box size
|
|
125
|
+
};
|
|
126
|
+
case "right":
|
|
127
|
+
return {
|
|
128
|
+
top: childrenCoords.y,
|
|
129
|
+
left: childrenCoords.width + childrenCoords.x + EMPTY_SPACE
|
|
130
|
+
};
|
|
131
|
+
default:
|
|
132
|
+
// TODO: provide a default center position in case of Tooltip without children
|
|
133
|
+
return {};
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A utility function to calculate the `Tooltip` vertical alignment
|
|
139
|
+
* @param placement The `Tooltip` placement in relation of its children
|
|
140
|
+
* @param childrenHeight The `Tooltip`'s children height
|
|
141
|
+
* @param tooltipHeight The `Tooltip`'s height
|
|
142
|
+
* @returns If placement is `left` or `right` it returns the vertical tranlsation to align the `Tooltip` center with its `children` center,
|
|
143
|
+
* otherwise `null` is returned
|
|
144
|
+
*/
|
|
145
|
+
export const getTooltipVerticalAlignment = (placement: Placement, childrenHeight: number, tooltipHeight?: number) => {
|
|
146
|
+
if ((placement === "left" || placement === "right") && tooltipHeight) {
|
|
147
|
+
return {
|
|
148
|
+
transform: [
|
|
149
|
+
{
|
|
150
|
+
translateY:
|
|
151
|
+
-tooltipHeight / 2 + childrenHeight / 2
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* A utility function to calculate the `Arrow` vertical alignment
|
|
161
|
+
* @param placement The `Tooltip` placement in relation of its children
|
|
162
|
+
* @param childrenHeight The `Tooltip`'s children height
|
|
163
|
+
*/
|
|
164
|
+
export const getArrowVerticalAlignment = (placement: Placement, childrenHeight: number) => {
|
|
165
|
+
if (placement === "left" || placement === "right") {
|
|
166
|
+
return {
|
|
167
|
+
transform: [
|
|
168
|
+
{
|
|
169
|
+
translateY:
|
|
170
|
+
-ARROW_WIDTH / 2 + childrenHeight / 2
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const isDefined = <T>(v: T) => v !== undefined;
|
|
179
|
+
export const isNotZero = (v: number) => v !== 0;
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "./IOText";
|
|
11
11
|
|
|
12
12
|
type BodyStyleProps = TypographicStyleProps & {
|
|
13
|
-
weight?: Extract<IOFontWeight, "Regular" | "Semibold"
|
|
13
|
+
weight?: Extract<IOFontWeight, "Regular" | "Semibold">;
|
|
14
14
|
} & TypographicStyleAsLinkProps;
|
|
15
15
|
|
|
16
16
|
export const bodyFontSize = 16;
|
|
@@ -9,20 +9,17 @@ import {
|
|
|
9
9
|
TypographicStyleProps
|
|
10
10
|
} from "./IOText";
|
|
11
11
|
|
|
12
|
-
type
|
|
13
|
-
weight?: Extract<IOFontWeight, "Regular" | "Semibold"
|
|
12
|
+
type BodySmallProps = TypographicStyleProps & {
|
|
13
|
+
weight?: Extract<IOFontWeight, "Regular" | "Semibold">;
|
|
14
14
|
} & TypographicStyleAsLinkProps;
|
|
15
15
|
|
|
16
16
|
const fontName: IOFontFamily = "Titillio";
|
|
17
|
-
const fontWeight: IOFontWeight = "Semibold";
|
|
18
|
-
|
|
19
17
|
const legacyFontName: IOFontFamily = "TitilliumSansPro";
|
|
20
|
-
const legacyFontWeight: IOFontWeight = "Semibold";
|
|
21
18
|
|
|
22
19
|
/**
|
|
23
|
-
* `
|
|
20
|
+
* `BodySmall` typographic style
|
|
24
21
|
*/
|
|
25
|
-
export const
|
|
22
|
+
export const BodySmall = forwardRef<View, BodySmallProps>(
|
|
26
23
|
(
|
|
27
24
|
{ weight: customWeight, color: customColor, asLink, ...props },
|
|
28
25
|
ref?: ForwardedRef<View>
|
|
@@ -34,15 +31,11 @@ export const LabelSmall = forwardRef<View, LabelSmallProps>(
|
|
|
34
31
|
? theme["interactiveElem-default"]
|
|
35
32
|
: theme["textBody-tertiary"];
|
|
36
33
|
|
|
37
|
-
const
|
|
34
|
+
const BodySmallProps: IOTextProps = {
|
|
38
35
|
...props,
|
|
39
36
|
dynamicTypeRamp: "footnote" /* iOS only */,
|
|
40
37
|
font: isExperimental ? fontName : legacyFontName,
|
|
41
|
-
weight: customWeight
|
|
42
|
-
? customWeight
|
|
43
|
-
: isExperimental
|
|
44
|
-
? fontWeight
|
|
45
|
-
: legacyFontWeight,
|
|
38
|
+
weight: customWeight ?? "Regular",
|
|
46
39
|
size: 14,
|
|
47
40
|
lineHeight: 21,
|
|
48
41
|
color: customColor ?? defaultColor,
|
|
@@ -55,7 +48,7 @@ export const LabelSmall = forwardRef<View, LabelSmallProps>(
|
|
|
55
48
|
};
|
|
56
49
|
|
|
57
50
|
return (
|
|
58
|
-
<IOText ref={ref} {...
|
|
51
|
+
<IOText ref={ref} {...BodySmallProps}>
|
|
59
52
|
{props.children}
|
|
60
53
|
</IOText>
|
|
61
54
|
);
|
|
@@ -2,7 +2,7 @@ import React, { ForwardedRef, forwardRef } from "react";
|
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
import { useIOExperimentalDesign } from "../../core";
|
|
4
4
|
import { IOColors } from "../../core/IOColors";
|
|
5
|
-
import { IOFontFamily, IOFontSize
|
|
5
|
+
import { IOFontFamily, IOFontSize } from "../../utils/fonts";
|
|
6
6
|
import { IOText, IOTextProps, TypographicStyleProps } from "./IOText";
|
|
7
7
|
|
|
8
8
|
export const buttonTextFontSize: IOFontSize = 16;
|
|
@@ -10,11 +10,9 @@ export const buttonTextFontSize: IOFontSize = 16;
|
|
|
10
10
|
`AnimatedText` for color transition through Reanimated */
|
|
11
11
|
const defaultColor: IOColors = "white";
|
|
12
12
|
const fontName: IOFontFamily = "Titillio";
|
|
13
|
-
const fontWeight: IOFontWeight = "Semibold";
|
|
14
13
|
|
|
15
14
|
// TODO: Remove this when legacy look is deprecated https://pagopa.atlassian.net/browse/IOPLT-153
|
|
16
15
|
const legacyFontName: IOFontFamily = "TitilliumSansPro";
|
|
17
|
-
const legacyFontWeight: IOFontWeight = "Bold";
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* `ButtonText` typographic style
|
|
@@ -26,7 +24,7 @@ export const ButtonText = forwardRef<View, TypographicStyleProps>(
|
|
|
26
24
|
const ButtonTextProps: IOTextProps = {
|
|
27
25
|
...props,
|
|
28
26
|
font: isExperimental ? fontName : legacyFontName,
|
|
29
|
-
weight:
|
|
27
|
+
weight: "Semibold",
|
|
30
28
|
size: buttonTextFontSize,
|
|
31
29
|
lineHeight: 20,
|
|
32
30
|
color: customColor ?? defaultColor
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import React, { ForwardedRef, forwardRef } from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import {
|
|
3
|
+
import { useIOExperimentalDesign, useIOTheme } from "../../core";
|
|
4
4
|
import { IOFontFamily, IOFontSize, IOFontWeight } from "../../utils/fonts";
|
|
5
5
|
import { IOText, IOTextProps, TypographicStyleProps } from "./IOText";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
type H3StyleProps = TypographicStyleProps & {
|
|
8
|
+
weight?: Extract<IOFontWeight, "Semibold" | "Bold">;
|
|
9
|
+
};
|
|
8
10
|
|
|
9
11
|
/* Common typographic styles */
|
|
10
12
|
export const h3FontSize: IOFontSize = 22;
|
|
11
13
|
export const h3LineHeight = 33;
|
|
12
14
|
const fontName: IOFontFamily = "Titillio";
|
|
13
|
-
const fontWeight: IOFontWeight = "Semibold";
|
|
14
15
|
|
|
15
16
|
// TODO: Remove this when legacy look is deprecated https://pagopa.atlassian.net/browse/IOPLT-153
|
|
16
17
|
const legacyFontName: IOFontFamily = "TitilliumSansPro";
|
|
17
|
-
const legacyFontWeight: IOFontWeight = "Semibold";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* `H3` typographic style
|
|
21
21
|
*/
|
|
22
|
-
export const H3 = forwardRef<View,
|
|
23
|
-
(
|
|
22
|
+
export const H3 = forwardRef<View, H3StyleProps>(
|
|
23
|
+
(
|
|
24
|
+
{ weight: customWeight, color: customColor, ...props },
|
|
25
|
+
ref?: ForwardedRef<View>
|
|
26
|
+
) => {
|
|
24
27
|
const theme = useIOTheme();
|
|
25
28
|
const { isExperimental } = useIOExperimentalDesign();
|
|
26
29
|
|
|
@@ -28,10 +31,10 @@ export const H3 = forwardRef<View, TypographicStyleProps>(
|
|
|
28
31
|
...props,
|
|
29
32
|
dynamicTypeRamp: "title2", // iOS only
|
|
30
33
|
font: isExperimental ? fontName : legacyFontName,
|
|
31
|
-
weight:
|
|
34
|
+
weight: customWeight ?? "Semibold",
|
|
32
35
|
size: h3FontSize,
|
|
33
36
|
lineHeight: h3LineHeight,
|
|
34
|
-
color: customColor ?? theme[
|
|
37
|
+
color: customColor ?? theme["textHeading-default"]
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
return (
|