@ovotech/element-native 5.5.0 → 5.7.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/components/Accordion/styles.d.ts +3 -1725
- package/dist/components/ActionList/Action.d.ts +23 -0
- package/dist/components/ActionList/Action.js +29 -0
- package/dist/components/ActionList/ActionList.d.ts +11 -27
- package/dist/components/ActionList/ActionList.js +9 -25
- package/dist/components/ActionList/ActionListItems/DataListItem.d.ts +23 -0
- package/dist/components/ActionList/ActionListItems/DataListItem.js +23 -0
- package/dist/components/ActionList/ActionListItems/EditableListItem.d.ts +43 -0
- package/dist/components/ActionList/ActionListItems/EditableListItem.js +134 -0
- package/dist/components/ActionList/ActionListItems/NavigationListItem.d.ts +16 -0
- package/dist/components/ActionList/ActionListItems/NavigationListItem.js +30 -0
- package/dist/components/ActionList/ActionListItems/ProgressRing.d.ts +7 -0
- package/dist/components/ActionList/ActionListItems/ProgressRing.js +66 -0
- package/dist/components/ActionList/ActionListItems/ToggleListItem.d.ts +9 -0
- package/dist/components/ActionList/ActionListItems/ToggleListItem.js +12 -0
- package/dist/components/ActionList/ActionListItems/styles.d.ts +51 -0
- package/dist/components/ActionList/ActionListItems/styles.js +173 -0
- package/dist/components/ActionList/components/ActionListHeading.d.ts +9 -0
- package/dist/components/ActionList/components/ActionListHeading.js +11 -0
- package/dist/components/ActionList/index.d.ts +6 -1
- package/dist/components/ActionList/index.js +11 -2
- package/dist/components/ActionList/styled.d.ts +12 -5756
- package/dist/components/ActionList/styled.js +24 -9
- package/dist/components/Badge/Badge.d.ts +1 -575
- package/dist/components/BottomActionBar/BottomActionBar.d.ts +12 -0
- package/dist/components/BottomActionBar/BottomActionBar.js +80 -0
- package/dist/components/BottomActionBar/OverlayProvider.d.ts +8 -0
- package/dist/components/BottomActionBar/OverlayProvider.js +38 -0
- package/dist/components/BottomActionBar/index.d.ts +2 -0
- package/dist/components/BottomActionBar/index.js +7 -0
- package/dist/components/Button/Button.js +1 -1
- package/dist/components/Button/Button.styles.d.ts +5 -2300
- package/dist/components/Card/Card.d.ts +7 -4
- package/dist/components/Card/Card.js +44 -22
- package/dist/components/Card/Card.styles.d.ts +4 -1725
- package/dist/components/Card/Card.styles.js +7 -11
- package/dist/components/Cards/AccountCard/AccountCard.styles.d.ts +8 -4600
- package/dist/components/Cards/BalanceCard/BalanceCard.styles.d.ts +15 -8625
- package/dist/components/Cards/BalanceCard/BalanceCard.styles.js +2 -2
- package/dist/components/Cards/DisruptiveCard/DisruptiveCard.d.ts +13 -0
- package/dist/components/Cards/DisruptiveCard/DisruptiveCard.js +45 -0
- package/dist/components/Cards/DisruptiveCard/DisruptiveCard.styles.d.ts +3 -0
- package/dist/components/Cards/DisruptiveCard/DisruptiveCard.styles.js +11 -0
- package/dist/components/Cards/DisruptiveCard/index.d.ts +1 -0
- package/dist/components/Cards/DisruptiveCard/index.js +17 -0
- package/dist/components/Cards/HeroImageCard/HeroImageCard.d.ts +12 -0
- package/dist/components/Cards/HeroImageCard/HeroImageCard.js +65 -0
- package/dist/components/Cards/HeroImageCard/HeroImageCard.styles.d.ts +10 -0
- package/dist/components/Cards/HeroImageCard/HeroImageCard.styles.js +27 -0
- package/dist/components/Cards/HeroImageCard/index.d.ts +1 -0
- package/dist/components/Cards/HeroImageCard/index.js +17 -0
- package/dist/components/Cards/IconDataCard/IconDataCard.styles.d.ts +4 -2300
- package/dist/components/Cards/IconTextCard/IconTextCard.js +3 -16
- package/dist/components/Cards/IconTextCard/IconTextCard.styles.d.ts +3 -2300
- package/dist/components/Cards/IconTextCard/IconTextCard.styles.js +1 -6
- package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.d.ts +14 -0
- package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.js +26 -0
- package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.d.ts +18 -0
- package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.js +33 -0
- package/dist/components/Cards/IllustrationTextCard/index.d.ts +1 -0
- package/dist/components/Cards/IllustrationTextCard/index.js +17 -0
- package/dist/components/Cards/LinkTextCard/LinkTextCard.d.ts +2 -2
- package/dist/components/Cards/LinkTextCard/LinkTextCard.js +7 -6
- package/dist/components/Cards/LinkTextCard/LinkTextCard.styles.d.ts +8 -2875
- package/dist/components/Cards/LinkTextCard/LinkTextCard.styles.js +9 -6
- package/dist/components/Cards/OfferCard/OfferCard.d.ts +22 -0
- package/dist/components/Cards/OfferCard/OfferCard.js +36 -0
- package/dist/components/Cards/OfferCard/OfferCard.styles.d.ts +34 -0
- package/dist/components/Cards/OfferCard/OfferCard.styles.js +61 -0
- package/dist/components/Cards/OfferCard/index.d.ts +1 -0
- package/dist/components/Cards/OfferCard/index.js +17 -0
- package/dist/components/Cards/ProgressBarCard/ProgressBarCard.styles.d.ts +9 -5175
- package/dist/components/Cards/QuickLinkCard/QuickLinkCard.d.ts +12 -0
- package/dist/components/Cards/QuickLinkCard/QuickLinkCard.js +27 -0
- package/dist/components/Cards/QuickLinkCard/QuickLinkCard.styles.d.ts +12 -0
- package/dist/components/Cards/QuickLinkCard/QuickLinkCard.styles.js +31 -0
- package/dist/components/Cards/QuickLinkCard/index.d.ts +1 -0
- package/dist/components/Cards/QuickLinkCard/index.js +17 -0
- package/dist/components/Cards/ServicesImageCard/ServicesImageCard.d.ts +12 -0
- package/dist/components/Cards/ServicesImageCard/ServicesImageCard.js +24 -0
- package/dist/components/Cards/ServicesImageCard/ServicesImageCard.styles.d.ts +17 -0
- package/dist/components/Cards/ServicesImageCard/ServicesImageCard.styles.js +38 -0
- package/dist/components/Cards/ServicesImageCard/index.d.ts +1 -0
- package/dist/components/Cards/ServicesImageCard/index.js +17 -0
- package/dist/components/Cards/components.d.ts +15 -0
- package/dist/components/Cards/components.js +24 -0
- package/dist/components/Cards/index.d.ts +5 -0
- package/dist/components/Cards/index.js +11 -1
- package/dist/components/Cards/shared.styles.d.ts +11 -3451
- package/dist/components/Cards/shared.styles.js +18 -2
- package/dist/components/Cards/utils.d.ts +1 -0
- package/dist/components/Cards/utils.js +13 -1
- package/dist/components/Checkbox/Checkbox.d.ts +2 -13
- package/dist/components/Checkbox/Checkbox.js +3 -49
- package/dist/components/Checkbox/styled.d.ts +21 -0
- package/dist/components/Checkbox/styled.js +52 -0
- package/dist/components/Checkbox/types.d.ts +16 -0
- package/dist/components/Checkbox/types.js +2 -0
- package/dist/components/CurrencyInput/CurrencyInput.d.ts +2 -1
- package/dist/components/CurrencyInput/CurrencyInput.js +11 -4
- package/dist/components/CurrencyInput/styled.d.ts +10 -0
- package/dist/components/CurrencyInput/styled.js +39 -0
- package/dist/components/DataTable/styles.d.ts +13 -7475
- package/dist/components/Disclosure/Disclosure.d.ts +1 -575
- package/dist/components/Divider/Divider.d.ts +1 -1
- package/dist/components/Divider/Divider.js +3 -1
- package/dist/components/Em/Em.d.ts +1 -575
- package/dist/components/EmailInput/EmailInput.d.ts +4 -1
- package/dist/components/EmailInput/EmailInput.js +18 -2
- package/dist/components/EmptyState/EmptyState.d.ts +2 -0
- package/dist/components/EmptyState/EmptyState.js +17 -0
- package/dist/components/EmptyState/EmptyState.test.d.ts +1 -0
- package/dist/components/EmptyState/EmptyState.test.js +92 -0
- package/dist/components/EmptyState/index.d.ts +1 -0
- package/dist/components/EmptyState/index.js +17 -0
- package/dist/components/EmptyState/styles.d.ts +2 -0
- package/dist/components/EmptyState/styles.js +23 -0
- package/dist/components/EmptyState/types.d.ts +18 -0
- package/dist/components/EmptyState/types.js +2 -0
- package/dist/components/ErrorText/ErrorText.d.ts +1 -575
- package/dist/components/Field/Field.d.ts +3 -2
- package/dist/components/Field/Field.js +3 -2
- package/dist/components/Grid/Col.d.ts +1 -575
- package/dist/components/HintText/HintText.d.ts +1 -575
- package/dist/components/Input/Input.d.ts +2 -1
- package/dist/components/Input/Input.js +6 -97
- package/dist/components/Input/styled.d.ts +16 -0
- package/dist/components/Input/styled.js +96 -0
- package/dist/components/LabelText/LabelText.d.ts +1 -575
- package/dist/components/LargeValueReference/LargeValueReference.d.ts +11 -0
- package/dist/components/LargeValueReference/LargeValueReference.js +49 -0
- package/dist/components/LargeValueReference/index.d.ts +1 -0
- package/dist/components/LargeValueReference/index.js +17 -0
- package/dist/components/LargeValueReference/styles.d.ts +10 -0
- package/dist/components/LargeValueReference/styles.js +29 -0
- package/dist/components/LineThrough/LineThrough.d.ts +1 -575
- package/dist/components/List/styled.d.ts +4 -2300
- package/dist/components/Margin/Margin.d.ts +1 -575
- package/dist/components/NavHeader/NavHeader.styles.d.ts +11 -6325
- package/dist/components/Notification/Notification.d.ts +2 -2
- package/dist/components/Notification/Notification.js +20 -12
- package/dist/components/Notification/Notification.styles.d.ts +13 -5175
- package/dist/components/Notification/Notification.styles.js +21 -2
- package/dist/components/PasswordInput/PasswordInput.styled.d.ts +1 -577
- package/dist/components/PasswordInput/PasswordInput.styled.js +5 -3
- package/dist/components/PasswordInput/PasswordVisibilityToggle.js +2 -8
- package/dist/components/Radio/Radio.d.ts +2 -2
- package/dist/components/Radio/Radio.js +5 -43
- package/dist/components/Radio/Radio.styles.d.ts +9 -0
- package/dist/components/Radio/Radio.styles.js +74 -0
- package/dist/components/RadioCard/RadioCard.d.ts +2 -1
- package/dist/components/RadioCard/RadioCard.js +7 -57
- package/dist/components/RadioCard/RadioCard.styles.d.ts +16 -0
- package/dist/components/RadioCard/RadioCard.styles.js +97 -0
- package/dist/components/Rail/Rail.d.ts +12 -0
- package/dist/components/Rail/Rail.js +58 -0
- package/dist/components/Rail/RailIndicator.d.ts +7 -0
- package/dist/components/Rail/RailIndicator.js +81 -0
- package/dist/components/Rail/index.d.ts +1 -0
- package/dist/components/Rail/index.js +5 -0
- package/dist/components/Rail/styles.d.ts +13 -0
- package/dist/components/Rail/styles.js +55 -0
- package/dist/components/Rail/useRailPaging.d.ts +13 -0
- package/dist/components/Rail/useRailPaging.js +95 -0
- package/dist/components/SelectField/Select.d.ts +5 -579
- package/dist/components/SelectField/Select.js +7 -107
- package/dist/components/SelectField/SelectField.d.ts +2 -2
- package/dist/components/SelectField/SelectField.js +2 -2
- package/dist/components/SelectField/styled.d.ts +26 -0
- package/dist/components/SelectField/styled.js +118 -0
- package/dist/components/SkeletonText/SkeletonText.js +4 -4
- package/dist/components/Strong/Strong.d.ts +1 -575
- package/dist/components/SubLabelText/SubLabelText.d.ts +1 -575
- package/dist/components/Tabs/Tab.d.ts +1 -575
- package/dist/components/TextareaInput/TextareaInput.js +12 -6
- package/dist/components/Toast/Toast.d.ts +10 -4
- package/dist/components/Toast/Toast.js +40 -27
- package/dist/components/Toggle/Toggle.d.ts +3 -1
- package/dist/components/Toggle/Toggle.js +4 -6
- package/dist/components/Toggle/styles.d.ts +5 -2300
- package/dist/components/Toggle/styles.js +3 -3
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/esm/components/ActionList/Action.js +26 -0
- package/dist/esm/components/ActionList/ActionList.js +12 -28
- package/dist/esm/components/ActionList/ActionListItems/DataListItem.js +19 -0
- package/dist/esm/components/ActionList/ActionListItems/EditableListItem.js +131 -0
- package/dist/esm/components/ActionList/ActionListItems/NavigationListItem.js +26 -0
- package/dist/esm/components/ActionList/ActionListItems/ProgressRing.js +29 -0
- package/dist/esm/components/ActionList/ActionListItems/ToggleListItem.js +8 -0
- package/dist/esm/components/ActionList/ActionListItems/styles.js +137 -0
- package/dist/esm/components/ActionList/components/ActionListHeading.js +7 -0
- package/dist/esm/components/ActionList/index.js +6 -1
- package/dist/esm/components/ActionList/styled.js +23 -8
- package/dist/esm/components/BottomActionBar/BottomActionBar.js +40 -0
- package/dist/esm/components/BottomActionBar/OverlayProvider.js +30 -0
- package/dist/esm/components/BottomActionBar/index.js +2 -0
- package/dist/esm/components/Button/Button.js +1 -1
- package/dist/esm/components/Card/Card.js +45 -23
- package/dist/esm/components/Card/Card.styles.js +8 -12
- package/dist/esm/components/Cards/BalanceCard/BalanceCard.styles.js +2 -2
- package/dist/esm/components/Cards/DisruptiveCard/DisruptiveCard.js +41 -0
- package/dist/esm/components/Cards/DisruptiveCard/DisruptiveCard.styles.js +5 -0
- package/dist/esm/components/Cards/DisruptiveCard/index.js +1 -0
- package/dist/esm/components/Cards/HeroImageCard/HeroImageCard.js +28 -0
- package/dist/esm/components/Cards/HeroImageCard/HeroImageCard.styles.js +21 -0
- package/dist/esm/components/Cards/HeroImageCard/index.js +1 -0
- package/dist/esm/components/Cards/IconTextCard/IconTextCard.js +5 -18
- package/dist/esm/components/Cards/IconTextCard/IconTextCard.styles.js +0 -5
- package/dist/esm/components/Cards/IllustrationTextCard/IllustrationTextCard.js +22 -0
- package/dist/esm/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.js +27 -0
- package/dist/esm/components/Cards/IllustrationTextCard/index.js +1 -0
- package/dist/esm/components/Cards/LinkTextCard/LinkTextCard.js +7 -6
- package/dist/esm/components/Cards/LinkTextCard/LinkTextCard.styles.js +9 -6
- package/dist/esm/components/Cards/OfferCard/OfferCard.js +32 -0
- package/dist/esm/components/Cards/OfferCard/OfferCard.styles.js +55 -0
- package/dist/esm/components/Cards/OfferCard/index.js +1 -0
- package/dist/esm/components/Cards/QuickLinkCard/QuickLinkCard.js +23 -0
- package/dist/esm/components/Cards/QuickLinkCard/QuickLinkCard.styles.js +25 -0
- package/dist/esm/components/Cards/QuickLinkCard/index.js +1 -0
- package/dist/esm/components/Cards/ServicesImageCard/ServicesImageCard.js +20 -0
- package/dist/esm/components/Cards/ServicesImageCard/ServicesImageCard.styles.js +32 -0
- package/dist/esm/components/Cards/ServicesImageCard/index.js +1 -0
- package/dist/esm/components/Cards/components.js +19 -0
- package/dist/esm/components/Cards/index.js +5 -0
- package/dist/esm/components/Cards/shared.styles.js +17 -1
- package/dist/esm/components/Cards/utils.js +11 -0
- package/dist/esm/components/Checkbox/Checkbox.js +2 -45
- package/dist/esm/components/Checkbox/styled.js +46 -0
- package/dist/esm/components/Checkbox/types.js +1 -0
- package/dist/esm/components/CurrencyInput/CurrencyInput.js +12 -5
- package/dist/esm/components/CurrencyInput/styled.js +33 -0
- package/dist/esm/components/Divider/Divider.js +3 -1
- package/dist/esm/components/EmailInput/EmailInput.js +18 -2
- package/dist/esm/components/EmptyState/EmptyState.js +13 -0
- package/dist/esm/components/EmptyState/EmptyState.test.js +90 -0
- package/dist/esm/components/EmptyState/index.js +1 -0
- package/dist/esm/components/EmptyState/styles.js +17 -0
- package/dist/esm/components/EmptyState/types.js +1 -0
- package/dist/esm/components/Field/Field.js +3 -2
- package/dist/esm/components/Input/Input.js +6 -64
- package/dist/esm/components/Input/styled.js +60 -0
- package/dist/esm/components/LargeValueReference/LargeValueReference.js +45 -0
- package/dist/esm/components/LargeValueReference/index.js +1 -0
- package/dist/esm/components/LargeValueReference/styles.js +23 -0
- package/dist/esm/components/Notification/Notification.js +21 -13
- package/dist/esm/components/Notification/Notification.styles.js +20 -1
- package/dist/esm/components/PasswordInput/PasswordInput.styled.js +5 -3
- package/dist/esm/components/PasswordInput/PasswordVisibilityToggle.js +2 -8
- package/dist/esm/components/Radio/Radio.js +4 -39
- package/dist/esm/components/Radio/Radio.styles.js +38 -0
- package/dist/esm/components/RadioCard/RadioCard.js +5 -52
- package/dist/esm/components/RadioCard/RadioCard.styles.js +61 -0
- package/dist/esm/components/Rail/Rail.js +21 -0
- package/dist/esm/components/Rail/RailIndicator.js +44 -0
- package/dist/esm/components/Rail/index.js +1 -0
- package/dist/esm/components/Rail/styles.js +49 -0
- package/dist/esm/components/Rail/useRailPaging.js +92 -0
- package/dist/esm/components/SelectField/Select.js +7 -74
- package/dist/esm/components/SelectField/SelectField.js +3 -3
- package/dist/esm/components/SelectField/styled.js +82 -0
- package/dist/esm/components/SkeletonText/SkeletonText.js +4 -4
- package/dist/esm/components/TextareaInput/TextareaInput.js +12 -6
- package/dist/esm/components/Toast/Toast.js +40 -27
- package/dist/esm/components/Toggle/Toggle.js +4 -6
- package/dist/esm/components/Toggle/styles.js +3 -3
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/hooks/use-font-scaling.js +32 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/test/utils.js +12 -0
- package/dist/esm/utils/utils.js +12 -1
- package/dist/hooks/use-font-scaling.d.ts +26 -0
- package/dist/hooks/use-font-scaling.js +35 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/styled.native.d.ts +1 -3445
- package/dist/test/utils.d.ts +4 -0
- package/dist/test/utils.js +28 -0
- package/dist/utils/utils.d.ts +11 -1
- package/dist/utils/utils.js +12 -0
- package/package.json +5 -5
- package/dist/components/ErrorWrapper/styles.d.ts +0 -0
- package/dist/components/ErrorWrapper/styles.js +0 -1
- package/dist/esm/components/ErrorWrapper/styles.js +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
//Epsilon allowable margin for nearly equal comparisons
|
|
3
|
+
const EPS = 0.5;
|
|
4
|
+
function nearlyEqual(a, b, eps = EPS) {
|
|
5
|
+
return Math.abs(a - b) <= eps;
|
|
6
|
+
}
|
|
7
|
+
function clamp(n, lo, hi) {
|
|
8
|
+
return Math.max(lo, Math.min(n, hi));
|
|
9
|
+
}
|
|
10
|
+
function uniqueNearlyEqual(values, eps = EPS) {
|
|
11
|
+
const out = [];
|
|
12
|
+
for (const v of values) {
|
|
13
|
+
if (out.length === 0 || !nearlyEqual(out[out.length - 1], v, eps))
|
|
14
|
+
out.push(v);
|
|
15
|
+
}
|
|
16
|
+
return out;
|
|
17
|
+
}
|
|
18
|
+
export function useRailPaging({ itemCount }) {
|
|
19
|
+
const safeItemCount = Math.max(0, itemCount);
|
|
20
|
+
const [containerWidth, setContainerWidth] = useState(0);
|
|
21
|
+
const [contentWidth, setContentWidth] = useState(0);
|
|
22
|
+
const [itemWidth, setItemWidth] = useState(0);
|
|
23
|
+
const [activeStartIndex, setActiveStartIndex] = useState(0);
|
|
24
|
+
const stride = itemWidth;
|
|
25
|
+
const isScrollable = containerWidth > 0 && contentWidth > containerWidth + 1;
|
|
26
|
+
const visibleCount = useMemo(() => {
|
|
27
|
+
const maxVisible = Math.max(1, safeItemCount);
|
|
28
|
+
if (safeItemCount === 0)
|
|
29
|
+
return 1;
|
|
30
|
+
if (containerWidth <= 0 || stride <= 0)
|
|
31
|
+
return 1;
|
|
32
|
+
return clamp(Math.ceil(containerWidth / stride), 1, maxVisible);
|
|
33
|
+
}, [containerWidth, stride, safeItemCount]);
|
|
34
|
+
const maxStartIndex = useMemo(() => {
|
|
35
|
+
if (safeItemCount <= 0)
|
|
36
|
+
return 0;
|
|
37
|
+
return clamp(safeItemCount - visibleCount, 0, safeItemCount - 1);
|
|
38
|
+
}, [safeItemCount, visibleCount]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setActiveStartIndex(prev => clamp(prev, 0, maxStartIndex));
|
|
41
|
+
}, [maxStartIndex]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
setActiveStartIndex(0);
|
|
44
|
+
}, [safeItemCount]);
|
|
45
|
+
const snapOffsets = useMemo(() => {
|
|
46
|
+
var _a;
|
|
47
|
+
if (safeItemCount === 0)
|
|
48
|
+
return [0];
|
|
49
|
+
if (containerWidth <= 0 || contentWidth <= 0 || stride <= 0)
|
|
50
|
+
return [0];
|
|
51
|
+
const maxScrollX = Math.max(0, contentWidth - containerWidth);
|
|
52
|
+
const offsets = [];
|
|
53
|
+
for (let index = 0; index <= maxStartIndex; index++) {
|
|
54
|
+
offsets.push(index * stride);
|
|
55
|
+
}
|
|
56
|
+
const last = (_a = offsets[offsets.length - 1]) !== null && _a !== void 0 ? _a : 0;
|
|
57
|
+
if (!nearlyEqual(last, maxScrollX))
|
|
58
|
+
offsets.push(maxScrollX);
|
|
59
|
+
return uniqueNearlyEqual(offsets);
|
|
60
|
+
}, [safeItemCount, containerWidth, contentWidth, stride, maxStartIndex]);
|
|
61
|
+
const onContainerLayout = useCallback((width) => {
|
|
62
|
+
setContainerWidth(width > 0 ? width : 0);
|
|
63
|
+
}, []);
|
|
64
|
+
const onContentSizeChange = useCallback((width) => {
|
|
65
|
+
setContentWidth(width > 0 ? width : 0);
|
|
66
|
+
}, []);
|
|
67
|
+
/**
|
|
68
|
+
* NOTE: This measures ONE item width (e.g. the first child) and assumes all
|
|
69
|
+
* items are the same width.
|
|
70
|
+
*/
|
|
71
|
+
const onItemLayout = useCallback((width) => {
|
|
72
|
+
if (width > 0)
|
|
73
|
+
setItemWidth(width);
|
|
74
|
+
}, []);
|
|
75
|
+
const onMomentumEnd = useCallback((offsetX) => {
|
|
76
|
+
if (stride <= 0)
|
|
77
|
+
return;
|
|
78
|
+
const raw = Math.round(offsetX / stride);
|
|
79
|
+
const nextStart = clamp(raw, 0, maxStartIndex);
|
|
80
|
+
setActiveStartIndex(prev => (prev === nextStart ? prev : nextStart));
|
|
81
|
+
}, [stride, maxStartIndex]);
|
|
82
|
+
return {
|
|
83
|
+
snapOffsets,
|
|
84
|
+
isScrollable,
|
|
85
|
+
activeStartIndex,
|
|
86
|
+
visibleCount,
|
|
87
|
+
onContainerLayout,
|
|
88
|
+
onContentSizeChange,
|
|
89
|
+
onItemLayout,
|
|
90
|
+
onMomentumEnd,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -1,94 +1,27 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { numToPx } from '@ovotech/element-core';
|
|
3
2
|
import groupBy from 'lodash.groupby';
|
|
4
3
|
import { Fragment, useState } from 'react';
|
|
5
4
|
import { Dimensions, Modal, ScrollView, View, } from 'react-native';
|
|
6
|
-
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
7
|
-
import styled, { css } from '../../styled.native';
|
|
8
5
|
import { Icon } from '../Icon';
|
|
9
6
|
import { P } from '../P';
|
|
10
7
|
import { Strong } from '../Strong';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
flex-direction: row;
|
|
14
|
-
align-items: center;
|
|
15
|
-
background-color: transparent;
|
|
16
|
-
border-color: ${hasError
|
|
17
|
-
? theme.input.color.borderError
|
|
18
|
-
: theme.input.color.border};
|
|
19
|
-
border-width: ${numToPx(theme.border.width.md)};
|
|
20
|
-
border-radius: ${numToPx(theme.border.radius.sm)};
|
|
21
|
-
padding: ${numToPx(theme.space[200])};
|
|
22
|
-
padding-right: ${numToPx(theme.space[350])};
|
|
23
|
-
height: ${numToPx(theme.space[1100])};
|
|
24
|
-
`;
|
|
25
|
-
});
|
|
26
|
-
const DropdownWrapper = styled.TouchableOpacity(({ theme }) => css `
|
|
27
|
-
flex: 1;
|
|
28
|
-
justify-content: center;
|
|
29
|
-
align-items: center;
|
|
30
|
-
|
|
31
|
-
/* 80 is an opacity for hex https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4 */
|
|
32
|
-
background-color: ${theme.color.brand.dark}80;
|
|
33
|
-
`);
|
|
34
|
-
const DropdownContainer = styled(SafeAreaView)(({ theme }) => css `
|
|
35
|
-
width: 95%;
|
|
36
|
-
max-height: 70%;
|
|
37
|
-
border-radius: ${numToPx(theme.border.radius.sm)};
|
|
38
|
-
background-color: ${theme.color.surface.bright};
|
|
39
|
-
`);
|
|
40
|
-
const SelectOption = styled.TouchableOpacity(({ theme, isLastOption }) => css `
|
|
41
|
-
flex-direction: row;
|
|
42
|
-
align-items: center;
|
|
43
|
-
border-bottom-color: ${theme.color.input.borderDim};
|
|
44
|
-
border-bottom-width: ${isLastOption ? 0 : 1}px;
|
|
45
|
-
padding: 0 ${numToPx(theme.space[400])};
|
|
46
|
-
`);
|
|
47
|
-
const Radio = styled.View(({ theme, isChecked }) => css `
|
|
48
|
-
background-color: ${isChecked
|
|
49
|
-
? theme.input.color.selectedTint
|
|
50
|
-
: 'transparent'};
|
|
51
|
-
width: ${numToPx(theme.space[600])};
|
|
52
|
-
height: ${numToPx(theme.space[600])};
|
|
53
|
-
margin-left: auto;
|
|
54
|
-
border-radius: ${numToPx(theme.space[600])};
|
|
55
|
-
border-width: ${numToPx(theme.border.width.md)};
|
|
56
|
-
border-color: ${theme.input.color[isChecked ? 'selected' : 'border']};
|
|
57
|
-
`);
|
|
58
|
-
const RadioDot = styled.View(({ theme, isChecked }) => css `
|
|
59
|
-
background-color: ${theme.input.color.selected};
|
|
60
|
-
position: absolute;
|
|
61
|
-
top: ${numToPx(theme.space[100])};
|
|
62
|
-
width: ${numToPx(theme.space[300])};
|
|
63
|
-
height: ${numToPx(theme.space[300])};
|
|
64
|
-
border-radius: ${numToPx(theme.space[300])};
|
|
65
|
-
align-self: center;
|
|
66
|
-
opacity: ${isChecked ? 1 : 0};
|
|
67
|
-
`);
|
|
68
|
-
const StyledP = styled(P)(({ theme }) => css `
|
|
69
|
-
margin-top: ${numToPx(theme.space[300])};
|
|
70
|
-
margin-bottom: ${numToPx(theme.space[300])};
|
|
71
|
-
`);
|
|
72
|
-
const StyledCategory = styled(P)(({ theme }) => css `
|
|
73
|
-
font-size: ${numToPx(theme.font.size.xs.mediaQuery.lg)};
|
|
74
|
-
color: ${theme.color.surface.onSurface};
|
|
75
|
-
background-color: ${theme.color.surface.surface};
|
|
76
|
-
padding: ${numToPx(theme.space[100])} ${numToPx(theme.space[400])};
|
|
77
|
-
`);
|
|
78
|
-
export const Select = ({ options = [], defaultSelected = { label: '', value: 'default' }, noOptionMessage = 'No option selected', onSelected = () => null, hasError = false, testID = 'select', ref, }) => {
|
|
8
|
+
import { DropdownContainer, DropdownWrapper, Radio, RadioDot, SelectInput, SelectOption, StyledCategory, StyledP, } from './styled';
|
|
9
|
+
export const Select = ({ options = [], defaultSelected = { label: '', value: 'default' }, noOptionMessage = 'No option selected', onSelected = () => null, hasError = false, selected, size = 'medium', testID = 'select', ref, }) => {
|
|
79
10
|
const [isOpen, setOpen] = useState(false);
|
|
80
|
-
const [
|
|
11
|
+
const [selectedVal, setSelectedVal] = useState(defaultSelected);
|
|
12
|
+
const isSmall = size === 'small';
|
|
13
|
+
const iconName = `chevron-down${isSmall ? '-small' : ''}`;
|
|
81
14
|
const height = Dimensions.get('window').height;
|
|
82
15
|
const dropdownContainerMaxHeight = height * 0.7;
|
|
83
16
|
const handleOptionPress = (val) => {
|
|
84
17
|
onSelected(val);
|
|
85
18
|
setOpen(false);
|
|
86
|
-
|
|
19
|
+
setSelectedVal(val);
|
|
87
20
|
};
|
|
88
21
|
const optionsByCategories = groupBy(options, 'category');
|
|
89
22
|
const requiredOption = {
|
|
90
23
|
label: `-- ${noOptionMessage} --`,
|
|
91
24
|
value: 'default',
|
|
92
25
|
};
|
|
93
|
-
return (_jsxs(View, { children: [_jsxs(SelectInput, { testID: testID, hasError: hasError, onPress: () => setOpen(!isOpen), ref: ref, children: [_jsx(P, { style: { marginTop: 0, marginBottom: 0 }, children:
|
|
26
|
+
return (_jsxs(View, { children: [_jsxs(SelectInput, { testID: testID, hasError: hasError, isSelected: selected, size: size, onPress: () => setOpen(!isOpen), ref: ref, children: [_jsx(P, { style: { marginTop: 0, marginBottom: 0 }, children: selectedVal.value === 'default' ? '' : selectedVal.label }), _jsx(Icon, { name: iconName, size: isSmall ? 16 : 20, style: { marginLeft: 'auto' } })] }), _jsx(Modal, { transparent: true, visible: isOpen, animationType: "fade", onRequestClose: () => setOpen(false), children: _jsx(DropdownWrapper, { onPress: () => setOpen(false), children: _jsx(DropdownContainer, { style: { maxHeight: dropdownContainerMaxHeight }, children: _jsxs(ScrollView, { nestedScrollEnabled: true, testID: `${testID}-OptionsScrollView`, children: [_jsxs(SelectOption, { accessible: true, accessibilityRole: "radio", onPress: () => handleOptionPress(requiredOption), children: [_jsx(StyledP, { children: _jsx(Strong, { children: requiredOption.label }) }), _jsx(Radio, { isChecked: selectedVal.value === requiredOption.value, children: _jsx(RadioDot, { isChecked: selectedVal.value === requiredOption.value }) })] }), Object.keys(optionsByCategories).map(category => (_jsxs(Fragment, { children: [category !== 'undefined' ? (_jsx(StyledCategory, { children: category })) : null, optionsByCategories[category].map((option, i) => (_jsxs(SelectOption, { accessible: true, accessibilityRole: "radio", isLastOption: i === optionsByCategories[category].length - 1, onPress: () => handleOptionPress(option), children: [_jsx(StyledP, { children: _jsx(Strong, { children: option.label }) }), _jsx(Radio, { isChecked: selectedVal.value === option.value, children: _jsx(RadioDot, { isChecked: selectedVal.value === option.value }) })] }, option.label)))] }, category)))] }) }) }) })] }));
|
|
94
27
|
};
|
|
@@ -9,10 +9,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { Field } from '../Field';
|
|
14
14
|
import { Select } from './Select';
|
|
15
15
|
export const SelectField = (_a) => {
|
|
16
|
-
var { error, options, onSelected, noOptionMessage, defaultSelected, testID, ref } = _a, rest = __rest(_a, ["error", "options", "onSelected", "noOptionMessage", "defaultSelected", "testID", "ref"]);
|
|
17
|
-
return (_jsx(Field, Object.assign({ affixWidth: 20, error: error }, rest, { children: _jsx(
|
|
16
|
+
var { error, options, onSelected, noOptionMessage, defaultSelected, size = 'medium', testID, ref } = _a, rest = __rest(_a, ["error", "options", "onSelected", "noOptionMessage", "defaultSelected", "size", "testID", "ref"]);
|
|
17
|
+
return (_jsx(Field, Object.assign({ affixWidth: 20, error: error }, rest, { children: _jsx(Select, { onSelected: onSelected, options: options, noOptionMessage: noOptionMessage, defaultSelected: defaultSelected, hasError: Boolean(error), size: size, testID: testID, ref: ref }) })));
|
|
18
18
|
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
2
|
+
import styled, { css } from '../../styled.native';
|
|
3
|
+
import { numToPx } from '../../theme';
|
|
4
|
+
import { getShadowCSS } from '../../utils';
|
|
5
|
+
import { P } from '../P';
|
|
6
|
+
export const SelectInput = styled.TouchableOpacity(({ theme, hasError, isSelected, size }) => {
|
|
7
|
+
const isSmall = size === 'small';
|
|
8
|
+
let borderColor = 'transparent';
|
|
9
|
+
/* prioritise error and selected states for border, even when focused */
|
|
10
|
+
if (hasError) {
|
|
11
|
+
borderColor = theme.color.alert.error;
|
|
12
|
+
}
|
|
13
|
+
else if (isSelected) {
|
|
14
|
+
borderColor = theme.color.surface.onSurface;
|
|
15
|
+
}
|
|
16
|
+
return css `
|
|
17
|
+
flex-direction: row;
|
|
18
|
+
align-items: center;
|
|
19
|
+
background-color: ${theme.color.surface.bright};
|
|
20
|
+
border-color: ${borderColor};
|
|
21
|
+
border-width: ${numToPx(theme.border.width.md)};
|
|
22
|
+
border-radius: ${numToPx(theme.border.radius.md)};
|
|
23
|
+
padding-top: ${numToPx(theme.space[isSmall ? 200 : 400])};
|
|
24
|
+
padding-bottom: ${numToPx(theme.space[isSmall ? 200 : 400])};
|
|
25
|
+
padding-left: ${numToPx(theme.space[400])};
|
|
26
|
+
padding-right: ${numToPx(theme.space[400])};
|
|
27
|
+
min-height: ${numToPx(theme.space[isSmall ? 1100 : 1600])};
|
|
28
|
+
${getShadowCSS({ theme })}
|
|
29
|
+
`;
|
|
30
|
+
});
|
|
31
|
+
export const DropdownWrapper = styled.TouchableOpacity(({ theme }) => css `
|
|
32
|
+
flex: 1;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
align-items: center;
|
|
35
|
+
|
|
36
|
+
/* 80 is an opacity for hex https://gist.github.com/lopspower/03fb1cc0ac9f32ef38f4 */
|
|
37
|
+
background-color: ${theme.color.brand.dark}80;
|
|
38
|
+
`);
|
|
39
|
+
export const DropdownContainer = styled(SafeAreaView)(({ theme }) => css `
|
|
40
|
+
width: 95%;
|
|
41
|
+
max-height: 70%;
|
|
42
|
+
border-radius: ${numToPx(theme.border.radius.md)};
|
|
43
|
+
background-color: ${theme.color.surface.bright};
|
|
44
|
+
`);
|
|
45
|
+
export const SelectOption = styled.TouchableOpacity(({ theme, isLastOption }) => css `
|
|
46
|
+
flex-direction: row;
|
|
47
|
+
align-items: center;
|
|
48
|
+
border-bottom-color: ${theme.color.input.borderDim};
|
|
49
|
+
border-bottom-width: ${isLastOption ? 0 : 1}px;
|
|
50
|
+
padding: 0 ${numToPx(theme.space[400])};
|
|
51
|
+
`);
|
|
52
|
+
export const Radio = styled.View(({ theme, isChecked }) => css `
|
|
53
|
+
background-color: ${isChecked
|
|
54
|
+
? theme.input.color.selectedTint
|
|
55
|
+
: 'transparent'};
|
|
56
|
+
width: ${numToPx(theme.space[600])};
|
|
57
|
+
height: ${numToPx(theme.space[600])};
|
|
58
|
+
margin-left: auto;
|
|
59
|
+
border-radius: ${numToPx(theme.space[600])};
|
|
60
|
+
border-width: ${numToPx(theme.border.width.md)};
|
|
61
|
+
border-color: ${theme.input.color[isChecked ? 'selected' : 'border']};
|
|
62
|
+
`);
|
|
63
|
+
export const RadioDot = styled.View(({ theme, isChecked }) => css `
|
|
64
|
+
background-color: ${theme.input.color.selected};
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: ${numToPx(theme.space[100])};
|
|
67
|
+
width: ${numToPx(theme.space[300])};
|
|
68
|
+
height: ${numToPx(theme.space[300])};
|
|
69
|
+
border-radius: ${numToPx(theme.space[300])};
|
|
70
|
+
align-self: center;
|
|
71
|
+
opacity: ${isChecked ? 1 : 0};
|
|
72
|
+
`);
|
|
73
|
+
export const StyledP = styled(P)(({ theme }) => css `
|
|
74
|
+
margin-top: ${numToPx(theme.space[300])};
|
|
75
|
+
margin-bottom: ${numToPx(theme.space[300])};
|
|
76
|
+
`);
|
|
77
|
+
export const StyledCategory = styled(P)(({ theme }) => css `
|
|
78
|
+
font-size: ${numToPx(theme.font.size.xs.mediaQuery.lg)};
|
|
79
|
+
color: ${theme.color.surface.onSurface};
|
|
80
|
+
background-color: ${theme.color.surface.surface};
|
|
81
|
+
padding: ${numToPx(theme.space[100])} ${numToPx(theme.space[400])};
|
|
82
|
+
`);
|
|
@@ -15,10 +15,10 @@ import { useBreakpoint } from '../../hooks';
|
|
|
15
15
|
import styled from '../../styled.native';
|
|
16
16
|
import { P } from '../P';
|
|
17
17
|
import { SkeletonAnimation } from '../SkeletonAnimation';
|
|
18
|
-
const StyledSkeletonText = styled.View(({ theme, aboveSmallBreakpoint, short, size,
|
|
18
|
+
const StyledSkeletonText = styled.View(({ theme, aboveSmallBreakpoint, short, size, isLast }) => {
|
|
19
19
|
return `
|
|
20
20
|
background-color: ${theme.color.surface.dim};
|
|
21
|
-
margin-bottom: ${
|
|
21
|
+
margin-bottom: ${isLast ? 0 : numToPx(theme.space[200])};
|
|
22
22
|
border-radius: ${numToPx(theme.border.radius.sm)};
|
|
23
23
|
height: ${aboveSmallBreakpoint
|
|
24
24
|
? numToPx(theme.font.size.md.mediaQuery.lg)
|
|
@@ -31,9 +31,9 @@ export const SkeletonText = (_a) => {
|
|
|
31
31
|
var { lines = 1, size } = _a, rest = __rest(_a, ["lines", "size"]);
|
|
32
32
|
const generatedLines = [];
|
|
33
33
|
const { smallAndUp } = useBreakpoint();
|
|
34
|
-
const hasMultipleLines = lines > 1;
|
|
35
34
|
for (let i = 1; i <= lines; i++) {
|
|
36
|
-
|
|
35
|
+
const isLast = i === lines;
|
|
36
|
+
generatedLines.push(_jsx(StyledSkeletonText, { short: lines > 1 && isLast, aboveSmallBreakpoint: smallAndUp, size: size, isLast: isLast }, `line-${i}`));
|
|
37
37
|
}
|
|
38
38
|
return (
|
|
39
39
|
// @ts-ignore styled components stuff
|
|
@@ -11,15 +11,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { numToPx } from '@ovotech/element-core';
|
|
14
|
+
import { useBreakpoint } from '../../hooks';
|
|
14
15
|
import styled, { css } from '../../styled.native';
|
|
15
16
|
import { Input } from '../Input/Input';
|
|
16
|
-
const StyledInput = styled(Input)(({ theme, rows }) =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const StyledInput = styled(Input)(({ theme, rows, smallAndUp, }) => {
|
|
18
|
+
const lineHeight = smallAndUp
|
|
19
|
+
? theme.font.lineHeight.md.mediaQuery.lg
|
|
20
|
+
: theme.font.lineHeight.md.mediaQuery.sm;
|
|
21
|
+
return css `
|
|
22
|
+
min-height: ${theme.space[800] * rows}px;
|
|
23
|
+
line-height: ${rows > 1 ? numToPx(lineHeight) : 'normal'};
|
|
24
|
+
`;
|
|
25
|
+
});
|
|
21
26
|
const TextareaInput = (_a) => {
|
|
22
27
|
var { rows = 3, ref } = _a, rest = __rest(_a, ["rows", "ref"]);
|
|
23
|
-
|
|
28
|
+
const breakpoints = useBreakpoint();
|
|
29
|
+
return (_jsx(StyledInput, Object.assign({}, rest, breakpoints, { keyboardType: "default", multiline: true, textAlignVertical: "top", rows: rows, ref: ref })));
|
|
24
30
|
};
|
|
25
31
|
export { TextareaInput };
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import { toast, ToastPosition, Toasts, } from '@backpackapp-io/react-native-toast';
|
|
3
14
|
import { numToPx } from '@ovotech/element-core';
|
|
@@ -8,7 +19,13 @@ import styled, { css } from '../../styled.native';
|
|
|
8
19
|
import { Action } from '../ActionList';
|
|
9
20
|
import { Icon } from '../Icon';
|
|
10
21
|
import { P } from '../P';
|
|
11
|
-
|
|
22
|
+
const TOAST_PADDING = 20;
|
|
23
|
+
export const ToastsContainer = (_a) => {
|
|
24
|
+
var { top = -80, left, inModal = false } = _a, rest = __rest(_a, ["top", "left", "inModal"]);
|
|
25
|
+
// Extra right inset if in modal, unless it's been explicitly passed
|
|
26
|
+
const leftInset = inModal ? -20 : left !== null && left !== void 0 ? left : 0;
|
|
27
|
+
return _jsx(Toasts, Object.assign({ extraInsets: { top, left: leftInset } }, rest));
|
|
28
|
+
};
|
|
12
29
|
const StyledView = styled.View(({ theme, variant }) => css `
|
|
13
30
|
background-color: ${variant === 'default'
|
|
14
31
|
? theme.color.alert.success
|
|
@@ -39,29 +56,24 @@ const StyledCloseIcon = styled(TouchableOpacity)(({ theme }) => css `
|
|
|
39
56
|
align-items: center;
|
|
40
57
|
justify-content: center;
|
|
41
58
|
`);
|
|
42
|
-
export const showToast = ({ message, dismissible = false, action, actionTitle, variant = 'default', duration = 5000, }) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
disableShadow: true,
|
|
55
|
-
customToast: t => (_jsx(CustomToastWithTimeIndicator, Object.assign({}, t, { variant: variant }), message)),
|
|
56
|
-
});
|
|
59
|
+
export const showToast = ({ message, dismissible = false, action, actionTitle, inlineContent, variant = 'default', duration = 5000, providerKey = 'DEFAULT', }) => {
|
|
60
|
+
const baseToastProps = {
|
|
61
|
+
id: 'clipboard',
|
|
62
|
+
position: ToastPosition.BOTTOM,
|
|
63
|
+
disableShadow: true,
|
|
64
|
+
providerKey,
|
|
65
|
+
};
|
|
66
|
+
// Uses toast.loading for manual dismissal with action or dismiss
|
|
67
|
+
// Otherwise, use regular toast for auto-hiding with time indicator.
|
|
68
|
+
action || dismissible
|
|
69
|
+
? toast.loading(message, Object.assign(Object.assign({}, baseToastProps), { duration: 0, customToast: t => (_jsx(CustomToast, Object.assign({}, t, { dismissible: dismissible, action: action, actionTitle: actionTitle, variant: variant, inline: inlineContent }), message)) }))
|
|
70
|
+
: toast(message, Object.assign(Object.assign({}, baseToastProps), { duration, customToast: t => (_jsx(CustomToastWithTimeIndicator, Object.assign({}, t, { variant: variant, inline: inlineContent }), message)) }));
|
|
57
71
|
};
|
|
58
|
-
const CustomToastWithTimeIndicator = ({ message, duration = 5000, variant, }) => {
|
|
59
|
-
const toastPadding = 20;
|
|
72
|
+
const CustomToastWithTimeIndicator = ({ message, duration = 5000, variant, inline = false, }) => {
|
|
60
73
|
const textRef = useRef(null);
|
|
61
74
|
const [textHeight, setTextHeight] = useState(0);
|
|
62
75
|
const windowWidth = Dimensions.get('window').width;
|
|
63
|
-
const
|
|
64
|
-
const toastWidth = windowWidth - screenPadding;
|
|
76
|
+
const toastWidth = windowWidth - TOAST_PADDING * 2;
|
|
65
77
|
const sharedWidth = useSharedValue(toastWidth);
|
|
66
78
|
const style = useAnimatedStyle(() => {
|
|
67
79
|
return {
|
|
@@ -76,8 +88,9 @@ const CustomToastWithTimeIndicator = ({ message, duration = 5000, variant, }) =>
|
|
|
76
88
|
}, []);
|
|
77
89
|
return (_jsxs(StyledView, { variant: variant, style: {
|
|
78
90
|
width: toastWidth,
|
|
79
|
-
height: textHeight +
|
|
91
|
+
height: textHeight + TOAST_PADDING,
|
|
80
92
|
flexWrap: 'wrap',
|
|
93
|
+
flexDirection: inline ? 'row' : 'column',
|
|
81
94
|
}, children: [_jsx(StyledP, { ref: textRef, onLayout: () => {
|
|
82
95
|
var _a;
|
|
83
96
|
(_a = textRef.current) === null || _a === void 0 ? void 0 : _a.measureInWindow((_x, _y, _width, height) => {
|
|
@@ -85,13 +98,13 @@ const CustomToastWithTimeIndicator = ({ message, duration = 5000, variant, }) =>
|
|
|
85
98
|
});
|
|
86
99
|
}, children: message }), _jsx(View, { style: { position: 'absolute', bottom: 0 }, children: _jsx(StyledBorder, { variant: variant, style: style }) })] }));
|
|
87
100
|
};
|
|
88
|
-
const CustomToast = ({ id, message, dismissible, action, actionTitle, width, variant, }) => {
|
|
89
|
-
const toastPadding = 20;
|
|
101
|
+
const CustomToast = ({ id, message, dismissible, action, actionTitle, inline = false, width, variant, }) => {
|
|
90
102
|
const textRef = useRef(null);
|
|
91
103
|
const actionRef = useRef(null);
|
|
92
104
|
const [textHeight, setTextHeight] = useState(0);
|
|
93
105
|
const [actionHeight, setActionHeight] = useState(0);
|
|
94
106
|
const toastHeight = textHeight + actionHeight;
|
|
107
|
+
const hasAction = action && actionTitle;
|
|
95
108
|
const handleAction = () => {
|
|
96
109
|
if (action && actionTitle) {
|
|
97
110
|
action();
|
|
@@ -100,10 +113,10 @@ const CustomToast = ({ id, message, dismissible, action, actionTitle, width, var
|
|
|
100
113
|
};
|
|
101
114
|
return (_jsxs(StyledView, { variant: variant, style: {
|
|
102
115
|
width,
|
|
103
|
-
height: toastHeight +
|
|
104
|
-
alignItems:
|
|
116
|
+
height: toastHeight + TOAST_PADDING,
|
|
117
|
+
alignItems: dismissible ? 'flex-start' : 'center',
|
|
105
118
|
}, children: [_jsxs(View, { style: {
|
|
106
|
-
flexDirection: 'row',
|
|
119
|
+
flexDirection: inline ? 'row' : 'column',
|
|
107
120
|
flexWrap: 'wrap',
|
|
108
121
|
justifyContent: 'space-between',
|
|
109
122
|
flex: 1,
|
|
@@ -112,7 +125,7 @@ const CustomToast = ({ id, message, dismissible, action, actionTitle, width, var
|
|
|
112
125
|
(_a = textRef.current) === null || _a === void 0 ? void 0 : _a.measureInWindow((_x, _y, _width, height) => {
|
|
113
126
|
setTextHeight(height);
|
|
114
127
|
});
|
|
115
|
-
}, children: message }),
|
|
128
|
+
}, children: message }), hasAction ? (_jsx(Action, { ref: actionRef, style: Object.assign({ width: 'auto', paddingBottom: 0 }, (inline ? { paddingTop: 0 } : {})), inverted: true, standalone: true, iconRight: "chevron-right-small", onPress: handleAction, onLayout: () => {
|
|
116
129
|
var _a;
|
|
117
130
|
(_a = actionRef.current) === null || _a === void 0 ? void 0 : _a.measureInWindow((_x, _y, _width, height) => {
|
|
118
131
|
setActionHeight(height);
|
|
@@ -17,7 +17,7 @@ import { HintText } from '../HintText/HintText';
|
|
|
17
17
|
import { LabelText } from '../LabelText';
|
|
18
18
|
import { StyledToggleDot, StyledToggleInput, StyledToggleInputWrapper, StyledWrapper, } from './styles';
|
|
19
19
|
const Input = (_a) => {
|
|
20
|
-
var { checked, labelPosition, testID } = _a, rest = __rest(_a, ["checked", "labelPosition", "testID"]);
|
|
20
|
+
var { checked, labelPosition, testID, toggleBackgroundColor } = _a, rest = __rest(_a, ["checked", "labelPosition", "testID", "toggleBackgroundColor"]);
|
|
21
21
|
const theme = useTheme();
|
|
22
22
|
const leftVal = useRef(new Animated.Value(checked ? theme.space[600] : theme.space[100])).current;
|
|
23
23
|
useEffect(() => {
|
|
@@ -27,12 +27,10 @@ const Input = (_a) => {
|
|
|
27
27
|
useNativeDriver: true,
|
|
28
28
|
}).start();
|
|
29
29
|
}, [checked]);
|
|
30
|
-
return (_jsx(StyledToggleInputWrapper, Object.assign({ labelPosition: labelPosition }, rest, { children: _jsx(StyledToggleInput, { checked: checked, testID: testID, children: _jsx(StyledToggleDot, { style: {
|
|
31
|
-
transform: [{ translateX: leftVal }],
|
|
32
|
-
}, checked: checked }) }) })));
|
|
30
|
+
return (_jsx(StyledToggleInputWrapper, Object.assign({ labelPosition: labelPosition }, rest, { children: _jsx(StyledToggleInput, { checked: checked, testID: testID, toggleBackgroundColor: toggleBackgroundColor, children: _jsx(StyledToggleDot, { style: { transform: [{ translateX: leftVal }] }, checked: checked }) }) })));
|
|
33
31
|
};
|
|
34
32
|
export const Toggle = (_a) => {
|
|
35
|
-
var { activeOpacity = 0.8, checked = false, label, hint, inline, labelPosition = 'left', testID, ref } = _a, rest = __rest(_a, ["activeOpacity", "checked", "label", "hint", "inline", "labelPosition", "testID", "ref"]);
|
|
33
|
+
var { activeOpacity = 0.8, checked = false, label, hint, inline, labelPosition = 'left', testID, ref, toggleBackgroundColor } = _a, rest = __rest(_a, ["activeOpacity", "checked", "label", "hint", "inline", "labelPosition", "testID", "ref", "toggleBackgroundColor"]);
|
|
36
34
|
const hasLabel = label !== undefined;
|
|
37
|
-
return (_jsxs(StyledWrapper, Object.assign({ ref: ref, accessible: true, accessibilityRole: "checkbox", activeOpacity: activeOpacity, accessibilityState: { checked }, hitSlop: 10, hasLabel: hasLabel, labelPosition: labelPosition, inline: inline }, rest, { children: [hasLabel ? (_jsxs(View, { style: { flexShrink: 1 }, children: [_jsx(LabelText, { children: label }), hint ? _jsx(HintText, { children: hint }) : null] })) : null, _jsx(Input, { checked: checked, testID: testID, labelPosition: hasLabel ? labelPosition : undefined })] })));
|
|
35
|
+
return (_jsxs(StyledWrapper, Object.assign({ ref: ref, accessible: true, accessibilityRole: "checkbox", activeOpacity: activeOpacity, accessibilityState: { checked }, hitSlop: 10, hasLabel: hasLabel, labelPosition: labelPosition, inline: inline }, rest, { children: [hasLabel ? (_jsxs(View, { style: { flexShrink: 1 }, children: [_jsx(LabelText, { children: label }), hint ? _jsx(HintText, { children: hint }) : null] })) : null, _jsx(Input, { checked: checked, testID: testID, labelPosition: hasLabel ? labelPosition : undefined, toggleBackgroundColor: toggleBackgroundColor })] })));
|
|
38
36
|
};
|
|
@@ -19,14 +19,14 @@ export const StyledToggleInputWrapper = styled.View(({ theme, labelPosition }) =
|
|
|
19
19
|
: ''}
|
|
20
20
|
`;
|
|
21
21
|
});
|
|
22
|
-
export const StyledToggleInput = styled.View(({ theme, checked }) => {
|
|
22
|
+
export const StyledToggleInput = styled.View(({ theme, checked, toggleBackgroundColor }) => {
|
|
23
23
|
return `
|
|
24
24
|
width: ${numToPx(theme.space[1100])};
|
|
25
25
|
height: ${numToPx(theme.space[600])};
|
|
26
26
|
justify-content: center;
|
|
27
27
|
border-radius: ${numToPx(theme.border.radius.lg)};
|
|
28
|
-
background: ${checked
|
|
29
|
-
? theme.color.outline.outer
|
|
28
|
+
background-color: ${checked
|
|
29
|
+
? toggleBackgroundColor || theme.color.outline.outer
|
|
30
30
|
: theme.color.surface.onSurfaceVariant};
|
|
31
31
|
`;
|
|
32
32
|
});
|
|
@@ -2,6 +2,7 @@ export * from './Accordion';
|
|
|
2
2
|
export * from './ActionCard';
|
|
3
3
|
export * from './ActionList';
|
|
4
4
|
export * from './Badge';
|
|
5
|
+
export * from './BottomActionBar';
|
|
5
6
|
export * from './Button';
|
|
6
7
|
export * from './Card';
|
|
7
8
|
export * from './Cards';
|
|
@@ -16,10 +17,13 @@ export * from './Divider';
|
|
|
16
17
|
export * from './Em';
|
|
17
18
|
export * from './EmailField';
|
|
18
19
|
export * from './EmailInput';
|
|
20
|
+
export * from './EmptyState';
|
|
21
|
+
export * from './ErrorWrapper';
|
|
19
22
|
export * from './Field';
|
|
20
23
|
export * from './Grid';
|
|
21
24
|
export * from './Heading';
|
|
22
25
|
export * from './Icon';
|
|
26
|
+
export * from './LargeValueReference';
|
|
23
27
|
export * from './LineThrough';
|
|
24
28
|
export * from './Link';
|
|
25
29
|
export * from './List';
|
|
@@ -37,6 +41,7 @@ export * from './PhoneInput';
|
|
|
37
41
|
export * from './Pictogram';
|
|
38
42
|
export * from './Radio';
|
|
39
43
|
export * from './RadioCard';
|
|
44
|
+
export * from './Rail';
|
|
40
45
|
export * from './RemoteImage';
|
|
41
46
|
export * from './ScreenView';
|
|
42
47
|
export * from './SegmentedControls';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useWindowDimensions } from 'react-native';
|
|
2
|
+
import { useBreakpoint } from './use-breakpoint.native';
|
|
3
|
+
/**
|
|
4
|
+
* A hook to get information about the current font scaling.
|
|
5
|
+
* It uses `useWindowDimensions` to get the `fontScale` and will update when it changes.
|
|
6
|
+
* It also uses `useBreakpoint` to only figure out scaling information below the small breakpoint, and otherwise returns defaults
|
|
7
|
+
*
|
|
8
|
+
* @returns An object with font scaling information.
|
|
9
|
+
*/
|
|
10
|
+
export function useFontScaling() {
|
|
11
|
+
const { smallAndUp } = useBreakpoint();
|
|
12
|
+
const { fontScale } = useWindowDimensions();
|
|
13
|
+
// For larger than "small" screens, we're not as concerned about font-scaling
|
|
14
|
+
// so we maintain defaults
|
|
15
|
+
if (smallAndUp) {
|
|
16
|
+
return {
|
|
17
|
+
fontScale: 1,
|
|
18
|
+
isFontScalingSmall: false,
|
|
19
|
+
isFontScalingLarge: false,
|
|
20
|
+
isFontScalingDefault: true,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const isFontScalingSmall = fontScale < 1;
|
|
24
|
+
const isFontScalingLarge = fontScale > 1;
|
|
25
|
+
const isFontScalingDefault = fontScale === 1;
|
|
26
|
+
return {
|
|
27
|
+
fontScale,
|
|
28
|
+
isFontScalingSmall,
|
|
29
|
+
isFontScalingLarge,
|
|
30
|
+
isFontScalingDefault,
|
|
31
|
+
};
|
|
32
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { themeNative } from '@ovotech/element-core';
|
|
3
|
+
import { render } from '@testing-library/react-native';
|
|
4
|
+
import { ThemeProvider } from '../styled.native';
|
|
5
|
+
function Wrapper({ children }) {
|
|
6
|
+
return _jsx(ThemeProvider, { theme: themeNative, children: children });
|
|
7
|
+
}
|
|
8
|
+
const customRender = (ui, options) => render(ui, Object.assign({ wrapper: Wrapper }, options));
|
|
9
|
+
// re-export everything
|
|
10
|
+
export * from '@testing-library/react-native';
|
|
11
|
+
// override render method
|
|
12
|
+
export { customRender as render };
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Children, } from 'react';
|
|
3
3
|
import { useBreakpoint } from '../hooks';
|
|
4
|
+
import { css } from '../styled.native';
|
|
5
|
+
import { numToPx } from '../theme';
|
|
4
6
|
function mergeRefs(...refs) {
|
|
5
7
|
return value => {
|
|
6
8
|
refs.forEach(ref => {
|
|
@@ -66,4 +68,13 @@ function filterChildrenByType(children, type) {
|
|
|
66
68
|
function getValidChildren(children) {
|
|
67
69
|
return Children.toArray(children).filter(Boolean);
|
|
68
70
|
}
|
|
69
|
-
|
|
71
|
+
function getShadowCSS({ theme, shadowColor, shadowOffsetX, shadowOffsetY, shadowOpacity = 0.1, shadowRadius, elevation = 5, }) {
|
|
72
|
+
return css `
|
|
73
|
+
shadow-color: ${shadowColor || theme.color.neutral.black};
|
|
74
|
+
shadow-offset: ${`${shadowOffsetX > 0 ? numToPx(shadowOffsetX) : 0} ${numToPx(shadowOffsetY || theme.space[100])}`};
|
|
75
|
+
shadow-opacity: ${shadowOpacity || '0.1'};
|
|
76
|
+
shadow-radius: ${numToPx(shadowRadius || theme.space[200])};
|
|
77
|
+
elevation: ${elevation || 5};
|
|
78
|
+
`;
|
|
79
|
+
}
|
|
80
|
+
export { callAll, filterChildrenByType, getErrorMessage, getShadowCSS, getText, getValidChildren, mergeRefs, responsiveStyle, styledComponentWithBreakpoints, };
|