-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathKeyValueLabel.tsx
More file actions
67 lines (61 loc) · 2.19 KB
/
KeyValueLabel.tsx
File metadata and controls
67 lines (61 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import ButtonIcon from '../../../../component-library/components/Buttons/ButtonIcon';
import Label from '../../../../component-library/components/Form/Label';
import {
IconColor,
IconName,
} from '../../../../component-library/components/Icons/Icon';
import {
TextVariant,
TextColor,
} from '../../../../component-library/components/Texts/Text';
import { useStyles } from '../../../../component-library/hooks';
import useTooltipModal from '../../../../components/hooks/useTooltipModal';
import React from 'react';
import { View } from 'react-native';
import { KeyValueRowLabelProps, TooltipSizes } from '../KeyValueRow.types';
import styleSheet from './KeyValueLabel.styles';
import { isPreDefinedKeyValueRowLabel } from '../KeyValueRow.utils';
/**
* A label and tooltip component.
*
* @param {Object} props - Component props.
* @param {PreDefinedKeyValueRowLabel | ReactNode} props.label - The label content to display.
* @param {KeyValueRowTooltip} [props.tooltip] - Optional tooltip to render to the right of the label.
*
* @returns {JSX.Element} The rendered KeyValueRowLabel component.
*/
const KeyValueRowLabel = ({ label, tooltip }: KeyValueRowLabelProps) => {
const { styles } = useStyles(styleSheet, {});
const { openTooltipModal } = useTooltipModal();
const hasTooltip = tooltip?.title && tooltip?.content;
const onNavigateToTooltipModal = () => {
if (!hasTooltip) return;
openTooltipModal(tooltip.title, tooltip.content, undefined, undefined);
tooltip?.onPress?.();
};
return (
<View style={styles.labelContainer}>
{isPreDefinedKeyValueRowLabel(label) ? (
<Label
variant={label?.variant ?? TextVariant.BodyMDMedium}
color={label?.color ?? TextColor.Default}
>
{label.text}
</Label>
) : (
label
)}
{hasTooltip && (
<ButtonIcon
size={tooltip.size ?? TooltipSizes.Md}
iconColor={IconColor.Alternative}
iconName={tooltip.iconName ?? IconName.Question}
accessibilityRole="button"
accessibilityLabel={`${tooltip.title} tooltip`}
onPress={onNavigateToTooltipModal}
/>
)}
</View>
);
};
export default KeyValueRowLabel;