@artsy/palette-mobile 13.2.33 → 13.2.35
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/Theme.js +9 -13
- package/dist/animation/CssTransition.js +8 -12
- package/dist/animation/index.js +1 -17
- package/dist/constants.js +4 -8
- package/dist/elements/ArtsyKeyboardAvoidingView/ArtsyKeyboardAvoidingView.js +19 -23
- package/dist/elements/ArtsyKeyboardAvoidingView/index.js +1 -17
- package/dist/elements/Autocomplete/Autocomplete.js +4 -8
- package/dist/elements/Autocomplete/Autocomplete.tests.js +9 -11
- package/dist/elements/Autocomplete/index.js +1 -17
- package/dist/elements/Avatar/Avatar.js +17 -44
- package/dist/elements/Avatar/Avatar.stories.js +7 -11
- package/dist/elements/Avatar/Avatar.tests.js +8 -10
- package/dist/elements/Avatar/index.js +1 -17
- package/dist/elements/BackButton/BackButton.js +9 -14
- package/dist/elements/BackButton/BackButton.stories.js +8 -12
- package/dist/elements/BackButton/index.js +1 -17
- package/dist/elements/Banner/Banner.js +14 -18
- package/dist/elements/Banner/Banner.stories.js +7 -11
- package/dist/elements/Banner/index.js +1 -17
- package/dist/elements/BorderBox/BorderBox.js +9 -15
- package/dist/elements/BorderBox/index.js +1 -17
- package/dist/elements/Box/Box.js +11 -17
- package/dist/elements/Box/Box.stories.js +14 -20
- package/dist/elements/Box/index.js +1 -17
- package/dist/elements/Button/Button.js +30 -37
- package/dist/elements/Button/Button.stories.js +18 -25
- package/dist/elements/Button/CTAButton.js +3 -7
- package/dist/elements/Button/FollowButton.js +7 -11
- package/dist/elements/Button/LinkButton.js +4 -8
- package/dist/elements/Button/colors.js +3 -7
- package/dist/elements/Button/index.js +4 -20
- package/dist/elements/ButtonNew/Button.js +32 -62
- package/dist/elements/ButtonNew/Button.stories.js +36 -50
- package/dist/elements/ButtonNew/Button.tests.js +13 -15
- package/dist/elements/ButtonNew/CTAButton.js +3 -7
- package/dist/elements/ButtonNew/FollowButton.js +7 -11
- package/dist/elements/ButtonNew/LinkButton.js +4 -8
- package/dist/elements/ButtonNew/colors.js +3 -7
- package/dist/elements/ButtonNew/index.js +4 -20
- package/dist/elements/Checkbox/Check.js +29 -56
- package/dist/elements/Checkbox/Checkbox.js +22 -30
- package/dist/elements/Checkbox/Checkbox.stories.js +8 -12
- package/dist/elements/Checkbox/index.js +2 -18
- package/dist/elements/ClassTheme/ClassTheme.js +5 -9
- package/dist/elements/ClassTheme/index.js +1 -17
- package/dist/elements/Collapse/Collapse.js +4 -8
- package/dist/elements/Collapse/Collapse.stories.js +9 -13
- package/dist/elements/Collapse/index.js +1 -17
- package/dist/elements/CollapsibleMenuItem/CollapsibleMenuItem.js +18 -21
- package/dist/elements/CollapsibleMenuItem/CollapsibleMenuItem.stories.js +30 -38
- package/dist/elements/CollapsibleMenuItem/index.js +1 -17
- package/dist/elements/Dialog/Dialog.js +20 -24
- package/dist/elements/Dialog/Dialog.stories.js +14 -16
- package/dist/elements/Dialog/Dialog.tests.js +12 -14
- package/dist/elements/Dialog/index.js +1 -17
- package/dist/elements/EntityHeader/EntityHeader.js +14 -18
- package/dist/elements/EntityHeader/EntityHeader.stories.js +17 -25
- package/dist/elements/EntityHeader/index.js +1 -17
- package/dist/elements/Flex/Flex.js +4 -7
- package/dist/elements/Flex/index.js +1 -17
- package/dist/elements/Header/ArtsyLogoHeader.js +8 -12
- package/dist/elements/Header/index.js +1 -17
- package/dist/elements/Histogram/Histogram.js +6 -10
- package/dist/elements/Histogram/index.js +1 -17
- package/dist/elements/Image/Image.js +26 -55
- package/dist/elements/Image/Image.stories.js +14 -16
- package/dist/elements/Image/index.js +1 -17
- package/dist/elements/Input/Input.js +127 -157
- package/dist/elements/Input/Input.stories.js +9 -11
- package/dist/elements/Input/Input.tests.js +17 -19
- package/dist/elements/Input/InputTitle.js +4 -8
- package/dist/elements/Input/helpers.d.ts +1 -1
- package/dist/elements/Input/helpers.js +51 -56
- package/dist/elements/Input/index.js +3 -19
- package/dist/elements/Input/maskValue.js +5 -10
- package/dist/elements/Input/maskValue.tests.js +11 -13
- package/dist/elements/Join/Join.js +6 -10
- package/dist/elements/Join/index.js +1 -17
- package/dist/elements/LazyFlatlist/LazyFlatlist.js +3 -7
- package/dist/elements/LazyFlatlist/index.js +2 -18
- package/dist/elements/LazyFlatlist/useHasSeenItem.js +6 -10
- package/dist/elements/LegacyScreen/LegacyScreen.js +51 -59
- package/dist/elements/LegacyScreen/index.js +1 -17
- package/dist/elements/LegacyTabs/ContentTabs.js +8 -12
- package/dist/elements/LegacyTabs/NavigationalTabs.js +11 -15
- package/dist/elements/LegacyTabs/StepTabs.js +15 -19
- package/dist/elements/LegacyTabs/Tab.js +9 -13
- package/dist/elements/LegacyTabs/TabBarContainer.js +28 -34
- package/dist/elements/LegacyTabs/index.js +9 -15
- package/dist/elements/List/BulletedItem.js +7 -11
- package/dist/elements/List/List.stories.js +8 -10
- package/dist/elements/List/index.js +1 -17
- package/dist/elements/MeasuredView/MeasuredView.js +10 -15
- package/dist/elements/MeasuredView/index.js +1 -17
- package/dist/elements/MenuItem/MenuItem.js +9 -13
- package/dist/elements/MenuItem/MenuItem.stories.js +5 -9
- package/dist/elements/MenuItem/index.js +1 -17
- package/dist/elements/Message/Message.js +15 -19
- package/dist/elements/Message/Message.stories.js +10 -12
- package/dist/elements/Message/Message.tests.js +9 -11
- package/dist/elements/Message/index.js +1 -17
- package/dist/elements/Pill/Pill.js +53 -83
- package/dist/elements/Pill/Pill.stories.js +16 -18
- package/dist/elements/Pill/Pill.tests.js +8 -10
- package/dist/elements/Pill/index.js +1 -17
- package/dist/elements/PopIn/PopIn.js +8 -12
- package/dist/elements/PopIn/index.js +1 -17
- package/dist/elements/Popover/Popover.js +21 -28
- package/dist/elements/Popover/Popover.stories.js +15 -17
- package/dist/elements/Popover/index.js +1 -17
- package/dist/elements/ProgressBar/ProgressBar.js +16 -43
- package/dist/elements/ProgressBar/ProgressBar.stories.js +6 -8
- package/dist/elements/ProgressBar/ProgressBar.tests.js +7 -9
- package/dist/elements/ProgressBar/index.js +1 -17
- package/dist/elements/Radio/RadioButton.js +20 -28
- package/dist/elements/Radio/RadioButton.stories.js +13 -15
- package/dist/elements/Radio/RadioDot.js +10 -14
- package/dist/elements/Radio/index.js +2 -7
- package/dist/elements/Screen/Background.js +3 -7
- package/dist/elements/Screen/Body.js +9 -13
- package/dist/elements/Screen/BottomView.js +9 -16
- package/dist/elements/Screen/FloatingHeader.js +9 -13
- package/dist/elements/Screen/FullWidthDivider.js +5 -9
- package/dist/elements/Screen/FullWidthItem.js +5 -9
- package/dist/elements/Screen/Header.js +21 -49
- package/dist/elements/Screen/Screen.stories.js +18 -20
- package/dist/elements/Screen/ScreenBase.js +9 -13
- package/dist/elements/Screen/ScreenFlatList.js +8 -15
- package/dist/elements/Screen/ScreenScrollContext.js +9 -14
- package/dist/elements/Screen/ScreenScrollView.js +8 -15
- package/dist/elements/Screen/StickySubHeader.js +20 -47
- package/dist/elements/Screen/constants.js +5 -8
- package/dist/elements/Screen/hooks/useAnimatedHeaderScrolling.js +10 -14
- package/dist/elements/Screen/hooks/useListenForScreenScroll.js +10 -14
- package/dist/elements/Screen/index.js +29 -46
- package/dist/elements/SearchInput/SearchInput.js +6 -10
- package/dist/elements/SearchInput/index.js +1 -17
- package/dist/elements/Separator/Separator.js +9 -15
- package/dist/elements/Separator/Separator.stories.js +6 -10
- package/dist/elements/Separator/ShadowSeparator.js +3 -9
- package/dist/elements/Separator/index.js +2 -18
- package/dist/elements/SimpleMessage/SimpleMessage.js +9 -16
- package/dist/elements/SimpleMessage/index.js +1 -17
- package/dist/elements/Skeleton/Skeleton.js +16 -45
- package/dist/elements/Skeleton/Skeleton.stories.js +10 -14
- package/dist/elements/Skeleton/index.js +1 -17
- package/dist/elements/Spacer/Spacer.js +3 -7
- package/dist/elements/Spacer/Spacer.stories.js +15 -20
- package/dist/elements/Spacer/index.js +1 -17
- package/dist/elements/Spinner/Spinner.js +15 -23
- package/dist/elements/Spinner/index.js +1 -17
- package/dist/elements/Switch/Switch.js +8 -12
- package/dist/elements/Switch/Switch.stories.js +11 -15
- package/dist/elements/Switch/index.js +1 -17
- package/dist/elements/Tabs/SubTabBar.js +11 -15
- package/dist/elements/Tabs/TabFlashList.js +8 -12
- package/dist/elements/Tabs/TabFlatList.js +8 -12
- package/dist/elements/Tabs/TabMasonry.js +8 -12
- package/dist/elements/Tabs/TabScrollView.js +8 -12
- package/dist/elements/Tabs/Tabs.js +24 -27
- package/dist/elements/Tabs/Tabs.stories.js +11 -13
- package/dist/elements/Tabs/TabsContainer.js +15 -19
- package/dist/elements/Tabs/TabsWithHeader.js +8 -12
- package/dist/elements/Tabs/hooks/useListenForTabContentScroll.js +8 -12
- package/dist/elements/Tabs/index.js +1 -17
- package/dist/elements/Text/LinkText.js +3 -7
- package/dist/elements/Text/Text.js +15 -21
- package/dist/elements/Text/Text.stories.js +18 -27
- package/dist/elements/Text/Text.tests.js +3 -5
- package/dist/elements/Text/helpers.js +5 -10
- package/dist/elements/Text/index.js +3 -19
- package/dist/elements/ToolTip/ToolTip.js +29 -34
- package/dist/elements/ToolTip/ToolTip.stories.js +11 -13
- package/dist/elements/ToolTip/ToolTip.tests.js +7 -9
- package/dist/elements/ToolTip/ToolTipFlyout.js +19 -47
- package/dist/elements/ToolTip/index.js +1 -17
- package/dist/elements/Touchable/Touchable.js +12 -19
- package/dist/elements/Touchable/Touchable.stories.js +9 -13
- package/dist/elements/Touchable/TouchableHighlightColor.js +6 -10
- package/dist/elements/Touchable/TouchableWithScale.js +7 -11
- package/dist/elements/Touchable/index.js +3 -19
- package/dist/elements/VisualClue/VisualClue.stories.js +6 -8
- package/dist/elements/VisualClue/VisualClueDot.js +6 -10
- package/dist/elements/VisualClue/VisualClueText.js +9 -13
- package/dist/elements/VisualClue/index.js +2 -18
- package/dist/elements/index.js +45 -61
- package/dist/index.js +10 -26
- package/dist/setupJest.js +2 -7
- package/dist/storybook/decorators.js +20 -28
- package/dist/storybook/helpers.js +6 -12
- package/dist/svgs/AddCircleFillIcon.js +6 -10
- package/dist/svgs/AddCircleIcon.js +6 -10
- package/dist/svgs/AddIcon.js +6 -10
- package/dist/svgs/AlertCircleFillIcon.js +6 -10
- package/dist/svgs/AlertIcon.js +6 -10
- package/dist/svgs/ArrowCircleFillIcons.js +7 -12
- package/dist/svgs/ArrowDownCircleIcon.js +6 -10
- package/dist/svgs/ArrowDownIcon.js +6 -10
- package/dist/svgs/ArrowLeftCircleIcon.js +6 -10
- package/dist/svgs/ArrowLeftIcon.js +6 -10
- package/dist/svgs/ArrowRightCircleIcon.js +6 -10
- package/dist/svgs/ArrowRightIcon.js +6 -10
- package/dist/svgs/ArrowUpCircleIcon.js +6 -10
- package/dist/svgs/ArrowUpIcon.js +6 -10
- package/dist/svgs/ArtsyLogoBlackIcon.js +6 -10
- package/dist/svgs/ArtsyLogoWhiteIcon.js +4 -8
- package/dist/svgs/ArtsyMarkBlackIcon.js +6 -10
- package/dist/svgs/ArtsyMarkWhiteIcon.js +4 -8
- package/dist/svgs/ArtworkIcon.js +6 -10
- package/dist/svgs/AuctionIcon.js +6 -10
- package/dist/svgs/BellFillIcon.js +6 -10
- package/dist/svgs/BellIcon.js +6 -10
- package/dist/svgs/BlueChipIcon.js +6 -10
- package/dist/svgs/BoltCircleFill.js +6 -10
- package/dist/svgs/BoltFill.js +6 -10
- package/dist/svgs/BookmarkFill.js +6 -10
- package/dist/svgs/BriefcaseIcon.js +6 -10
- package/dist/svgs/CertificateIcon.js +6 -10
- package/dist/svgs/CheckCircleFillIcon.js +6 -10
- package/dist/svgs/CheckCircleIcon.js +6 -10
- package/dist/svgs/CheckIcon.js +6 -10
- package/dist/svgs/ChevronIcon.js +11 -15
- package/dist/svgs/ClockFill.js +6 -10
- package/dist/svgs/CloseCircleFillIcon.js +6 -10
- package/dist/svgs/CloseCircleIcon.js +6 -10
- package/dist/svgs/CloseIcon.js +6 -10
- package/dist/svgs/CollapseIcon.js +6 -10
- package/dist/svgs/CreditCardIcon.js +14 -18
- package/dist/svgs/DecreaseIcon.js +6 -10
- package/dist/svgs/DocumentIcon.js +6 -10
- package/dist/svgs/DownloadIcon.js +6 -10
- package/dist/svgs/EditIcon.js +6 -10
- package/dist/svgs/EmptyCheckCircleIcon.js +6 -10
- package/dist/svgs/EnterIcon.js +6 -10
- package/dist/svgs/EnvelopeIcon.js +6 -10
- package/dist/svgs/EstablishedIcon.js +6 -10
- package/dist/svgs/ExclamationMarkCircleFill.js +6 -10
- package/dist/svgs/ExpandIcon.js +6 -10
- package/dist/svgs/EyeClosedIcon.js +6 -10
- package/dist/svgs/EyeOpenedIcon.js +6 -10
- package/dist/svgs/FacebookIcon.js +6 -10
- package/dist/svgs/FairIcon.js +6 -10
- package/dist/svgs/FilterIcon.js +6 -10
- package/dist/svgs/FullWidthIcon.js +6 -10
- package/dist/svgs/GenomeIcon.js +6 -10
- package/dist/svgs/GraphIcon.js +6 -10
- package/dist/svgs/GridIcon.js +6 -10
- package/dist/svgs/GuaranteeIcon.js +7 -11
- package/dist/svgs/HeartFillIcon.js +6 -10
- package/dist/svgs/HeartIcon.js +6 -10
- package/dist/svgs/HideIcon.js +6 -10
- package/dist/svgs/HomeIcon.js +6 -10
- package/dist/svgs/Icon.js +15 -30
- package/dist/svgs/ImageIcon.js +6 -10
- package/dist/svgs/ImageSetIcon.js +6 -10
- package/dist/svgs/IncreaseIcon.js +6 -10
- package/dist/svgs/InfoCircleIcon.js +6 -10
- package/dist/svgs/InstagramAppIcon.js +3 -7
- package/dist/svgs/InstitutionIcon.js +6 -10
- package/dist/svgs/LinkIcon.js +6 -10
- package/dist/svgs/LoaderIcon.js +6 -10
- package/dist/svgs/LockIcon.js +6 -10
- package/dist/svgs/LogoutIcon.js +6 -10
- package/dist/svgs/MagnifyingGlassIcon.js +6 -10
- package/dist/svgs/MapPinIcon.js +6 -10
- package/dist/svgs/MenuIcon.js +6 -10
- package/dist/svgs/MessageIcon.js +7 -11
- package/dist/svgs/MessagesAppIcon.js +4 -8
- package/dist/svgs/MoneyCircleIcon.js +6 -10
- package/dist/svgs/MoneyFillIcon.js +6 -10
- package/dist/svgs/MoreIcon.js +6 -10
- package/dist/svgs/MultiplePersonsIcon.js +6 -10
- package/dist/svgs/NoArtworkIcon.js +6 -10
- package/dist/svgs/NoImageIcon.js +6 -10
- package/dist/svgs/PageIcon.js +6 -10
- package/dist/svgs/Payment2Icon.js +6 -10
- package/dist/svgs/PaymentIcon.js +6 -10
- package/dist/svgs/PersonIcon.js +6 -10
- package/dist/svgs/PublicationIcon.js +6 -10
- package/dist/svgs/QuestionCircleIcon.js +6 -10
- package/dist/svgs/ReloadIcon.js +6 -10
- package/dist/svgs/SecureLockIcon.js +6 -10
- package/dist/svgs/SettingsIcon.js +6 -10
- package/dist/svgs/ShareIcon.js +6 -10
- package/dist/svgs/ShieldFilledIcon.js +6 -10
- package/dist/svgs/ShieldIcon.js +6 -10
- package/dist/svgs/StarCircleFill.js +6 -10
- package/dist/svgs/StarCircleIcon.js +6 -10
- package/dist/svgs/Stopwatch.js +6 -10
- package/dist/svgs/Tag2Icon.js +7 -11
- package/dist/svgs/TagIcon.js +6 -10
- package/dist/svgs/TimerIcon.js +6 -10
- package/dist/svgs/TopEmergingIcon.js +6 -10
- package/dist/svgs/TrashIcon.js +6 -10
- package/dist/svgs/TrendingIcon.js +6 -10
- package/dist/svgs/TriangleDown.js +6 -10
- package/dist/svgs/TwitterIcon.js +6 -10
- package/dist/svgs/UserMultiIcon.js +6 -10
- package/dist/svgs/UserSingleIcon.js +6 -10
- package/dist/svgs/VerifiedIcon.js +6 -10
- package/dist/svgs/VerifiedPersonIcon.js +6 -10
- package/dist/svgs/WhatsAppAppIcon.js +4 -8
- package/dist/svgs/WorldGlobeCircleIcon.js +6 -10
- package/dist/svgs/XCircleIcon.js +6 -10
- package/dist/svgs/icons.stories.js +11 -38
- package/dist/svgs/index.js +113 -129
- package/dist/tokens.js +9 -12
- package/dist/types.js +5 -10
- package/dist/utils/Wrap.js +7 -11
- package/dist/utils/colors.stories.js +16 -20
- package/dist/utils/createGeminiUrl.js +6 -10
- package/dist/utils/flattenChildren.js +5 -9
- package/dist/utils/formatLargeNumber.js +1 -5
- package/dist/utils/formatLargeNumbers.tests.js +8 -10
- package/dist/utils/hooks/index.js +4 -20
- package/dist/utils/hooks/useColor.js +2 -6
- package/dist/utils/hooks/useMeasure.js +4 -8
- package/dist/utils/hooks/useScreenDimensions.js +11 -16
- package/dist/utils/hooks/useSpace.js +2 -6
- package/dist/utils/hooks/useTheme.js +6 -10
- package/dist/utils/normalizeText.js +1 -5
- package/dist/utils/space.stories.js +9 -13
- package/dist/utils/tests/renderWithWrappers.js +7 -12
- package/dist/utils/text.js +9 -13
- package/dist/utils/types.js +1 -2
- package/dist/utils/webTokensToMobile.js +4 -9
- package/package.json +14 -14
|
@@ -1,108 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Input = exports.SELECT_COMPONENT_WIDTH = exports.LEFT_COMPONENT_WIDTH = exports.LABEL_HEIGHT = exports.MULTILINE_INPUT_MAX_HEIGHT = exports.MULTILINE_INPUT_MIN_HEIGHT = exports.INPUT_MIN_HEIGHT = exports.INPUT_BORDER_RADIUS = exports.HORIZONTAL_PADDING = exports.emitInputClearEvent = exports.inputEvents = void 0;
|
|
30
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
31
|
-
const events_1 = require("events");
|
|
32
|
-
const palette_tokens_1 = require("@artsy/palette-tokens");
|
|
33
|
-
const theme_get_1 = __importDefault(require("@styled-system/theme-get"));
|
|
34
|
-
const isArray_1 = __importDefault(require("lodash/isArray"));
|
|
35
|
-
const isString_1 = __importDefault(require("lodash/isString"));
|
|
36
|
-
const react_1 = require("react");
|
|
37
|
-
const react_native_1 = require("react-native");
|
|
38
|
-
const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
|
|
39
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
40
|
-
const helpers_1 = require("./helpers");
|
|
41
|
-
const maskValue_1 = require("./maskValue");
|
|
42
|
-
const svgs_1 = require("../../svgs");
|
|
43
|
-
const hooks_1 = require("../../utils/hooks");
|
|
44
|
-
const useMeasure_1 = require("../../utils/hooks/useMeasure");
|
|
45
|
-
const Flex_1 = require("../Flex");
|
|
46
|
-
const Spinner_1 = require("../Spinner");
|
|
47
|
-
const Text_1 = require("../Text");
|
|
48
|
-
const Touchable_1 = require("../Touchable");
|
|
49
|
-
exports.inputEvents = new events_1.EventEmitter();
|
|
50
|
-
const emitInputClearEvent = () => {
|
|
51
|
-
exports.inputEvents.emit("clear");
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { THEME } from "@artsy/palette-tokens";
|
|
4
|
+
import themeGet from "@styled-system/theme-get";
|
|
5
|
+
import isArray from "lodash/isArray";
|
|
6
|
+
import isString from "lodash/isString";
|
|
7
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from "react";
|
|
8
|
+
import { LayoutAnimation, Platform, TextInput, TouchableOpacity, } from "react-native";
|
|
9
|
+
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
10
|
+
import styled from "styled-components";
|
|
11
|
+
import { INPUT_VARIANTS, getInputState, getInputVariant } from "./helpers";
|
|
12
|
+
import { maskValue, unmaskText } from "./maskValue";
|
|
13
|
+
import { EyeClosedIcon, EyeOpenedIcon, TriangleDown, XCircleIcon } from "../../svgs";
|
|
14
|
+
import { useTheme } from "../../utils/hooks";
|
|
15
|
+
import { useMeasure } from "../../utils/hooks/useMeasure";
|
|
16
|
+
import { Flex } from "../Flex";
|
|
17
|
+
import { Spinner } from "../Spinner";
|
|
18
|
+
import { Text } from "../Text";
|
|
19
|
+
import { Touchable } from "../Touchable";
|
|
20
|
+
export const inputEvents = new EventEmitter();
|
|
21
|
+
export const emitInputClearEvent = () => {
|
|
22
|
+
inputEvents.emit("clear");
|
|
52
23
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const [
|
|
65
|
-
const [
|
|
66
|
-
const [value, setValue] = (0, react_1.useState)((0, maskValue_1.maskValue)({
|
|
24
|
+
export const HORIZONTAL_PADDING = 15;
|
|
25
|
+
export const INPUT_BORDER_RADIUS = 4;
|
|
26
|
+
export const INPUT_MIN_HEIGHT = 56;
|
|
27
|
+
export const MULTILINE_INPUT_MIN_HEIGHT = 110;
|
|
28
|
+
export const MULTILINE_INPUT_MAX_HEIGHT = 300;
|
|
29
|
+
export const LABEL_HEIGHT = 25;
|
|
30
|
+
export const LEFT_COMPONENT_WIDTH = 40;
|
|
31
|
+
export const SELECT_COMPONENT_WIDTH = 120;
|
|
32
|
+
export const Input = forwardRef(({ addClearListener = false, defaultValue, disabled = false, enableClearButton = false, fixedRightPlaceholder, hintText = "What's this?", icon, leftComponentWidth = LEFT_COMPONENT_WIDTH, mask, selectComponentWidth = SELECT_COMPONENT_WIDTH, loading = false, onBlur, onChangeText, onClear, onFocus, onSelectTap, placeholder, secureTextEntry = false, style: styleProp = {}, unit, value: propValue, selectDisplayLabel, ...props }, ref) => {
|
|
33
|
+
const { color, theme, space } = useTheme();
|
|
34
|
+
const [focused, setIsFocused] = useState(false);
|
|
35
|
+
const [delayedFocused, setDelayedFocused] = useState(false);
|
|
36
|
+
const [value, setValue] = useState(maskValue({
|
|
67
37
|
currentValue: propValue ?? defaultValue,
|
|
68
38
|
mask: mask,
|
|
69
39
|
}));
|
|
70
|
-
const [showPassword, setShowPassword] =
|
|
71
|
-
const [inputWidth, setInputWidth] =
|
|
72
|
-
const placeholderWidths =
|
|
73
|
-
const rightComponentRef =
|
|
74
|
-
const inputRef =
|
|
75
|
-
const variant =
|
|
40
|
+
const [showPassword, setShowPassword] = useState(!secureTextEntry);
|
|
41
|
+
const [inputWidth, setInputWidth] = useState(0);
|
|
42
|
+
const placeholderWidths = useRef([]);
|
|
43
|
+
const rightComponentRef = useRef(null);
|
|
44
|
+
const inputRef = useRef();
|
|
45
|
+
const variant = getInputVariant({
|
|
76
46
|
hasError: !!props.error,
|
|
77
47
|
disabled: disabled,
|
|
78
48
|
});
|
|
79
|
-
const hasLeftComponent =
|
|
80
|
-
const animatedState =
|
|
49
|
+
const hasLeftComponent = useMemo(() => !!unit || !!icon || !!onSelectTap, [unit, icon, onSelectTap]);
|
|
50
|
+
const animatedState = useSharedValue(getInputState({
|
|
81
51
|
isFocused: !!focused,
|
|
82
52
|
value: value,
|
|
83
53
|
}));
|
|
84
|
-
|
|
85
|
-
|
|
54
|
+
useImperativeHandle(ref, () => inputRef.current);
|
|
55
|
+
useEffect(() => {
|
|
86
56
|
// If the prop value changes, update the local state
|
|
87
57
|
// This optimisation is not needed if no propValue has been specified
|
|
88
58
|
if (propValue !== undefined && propValue !== value) {
|
|
89
|
-
setValue(
|
|
59
|
+
setValue(maskValue({ currentValue: propValue || "", mask }));
|
|
90
60
|
}
|
|
91
61
|
}, [propValue, value, mask]);
|
|
92
|
-
|
|
62
|
+
useEffect(() => {
|
|
93
63
|
// If the mask value changes, update the value state to be formatted again
|
|
94
|
-
setValue(
|
|
64
|
+
setValue(maskValue({ currentValue: value, mask }));
|
|
95
65
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
66
|
}, [mask]);
|
|
97
67
|
const fontFamily = theme.fonts.sans.regular;
|
|
98
|
-
|
|
68
|
+
useEffect(() => {
|
|
99
69
|
/* to make the font work for secure text inputs,
|
|
100
70
|
see https://github.com/facebook/react-native/issues/30123#issuecomment-711076098 */
|
|
101
71
|
inputRef.current?.setNativeProps({
|
|
102
72
|
style: { fontFamily },
|
|
103
73
|
});
|
|
104
74
|
}, [fontFamily]);
|
|
105
|
-
|
|
75
|
+
useEffect(() => {
|
|
106
76
|
// We don't need to delay hiding the placeholder
|
|
107
77
|
if (!focused && delayedFocused) {
|
|
108
78
|
setDelayedFocused(false);
|
|
@@ -120,56 +90,56 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
120
90
|
}
|
|
121
91
|
};
|
|
122
92
|
}, [focused, delayedFocused]);
|
|
123
|
-
const handleChangeText =
|
|
93
|
+
const handleChangeText = useCallback((text) => {
|
|
124
94
|
if (mask) {
|
|
125
|
-
const newText =
|
|
95
|
+
const newText = maskValue({ currentValue: text, mask: mask, previousValue: value }) || "";
|
|
126
96
|
setValue(newText);
|
|
127
|
-
onChangeText?.(newText,
|
|
97
|
+
onChangeText?.(newText, unmaskText(text));
|
|
128
98
|
}
|
|
129
99
|
else {
|
|
130
100
|
setValue(text);
|
|
131
101
|
onChangeText?.(text);
|
|
132
102
|
}
|
|
133
103
|
}, [onChangeText, value, mask]);
|
|
134
|
-
const handleClear =
|
|
135
|
-
|
|
104
|
+
const handleClear = useCallback(() => {
|
|
105
|
+
LayoutAnimation.configureNext({ ...LayoutAnimation.Presets.easeInEaseOut, duration: 200 });
|
|
136
106
|
inputRef.current?.clear();
|
|
137
107
|
handleChangeText("");
|
|
138
108
|
onClear?.();
|
|
139
109
|
}, [onClear, handleChangeText]);
|
|
140
|
-
|
|
110
|
+
useEffect(() => {
|
|
141
111
|
if (!addClearListener) {
|
|
142
112
|
return;
|
|
143
113
|
}
|
|
144
|
-
|
|
114
|
+
inputEvents.addListener("clear", handleClear);
|
|
145
115
|
return () => {
|
|
146
|
-
|
|
116
|
+
inputEvents.removeListener("clear", handleClear);
|
|
147
117
|
};
|
|
148
118
|
}, [addClearListener, handleClear]);
|
|
149
|
-
const { width: rightComponentWidth = 0 } =
|
|
150
|
-
const textInputPaddingLeft =
|
|
119
|
+
const { width: rightComponentWidth = 0 } = useMeasure({ ref: rightComponentRef });
|
|
120
|
+
const textInputPaddingLeft = useMemo(() => {
|
|
151
121
|
if (!hasLeftComponent) {
|
|
152
|
-
return
|
|
122
|
+
return HORIZONTAL_PADDING;
|
|
153
123
|
}
|
|
154
124
|
if (onSelectTap) {
|
|
155
|
-
return selectComponentWidth +
|
|
125
|
+
return selectComponentWidth + HORIZONTAL_PADDING;
|
|
156
126
|
}
|
|
157
127
|
return leftComponentWidth;
|
|
158
128
|
}, [hasLeftComponent, leftComponentWidth, onSelectTap, selectComponentWidth]);
|
|
159
|
-
const styles =
|
|
129
|
+
const styles = useMemo(() => {
|
|
160
130
|
return {
|
|
161
131
|
fontFamily: fontFamily,
|
|
162
|
-
fontSize: parseInt(
|
|
163
|
-
minHeight: props.multiline ?
|
|
164
|
-
maxHeight: props.multiline ?
|
|
165
|
-
height: props.multiline ?
|
|
132
|
+
fontSize: parseInt(THEME.textVariants["sm-display"].fontSize, 10),
|
|
133
|
+
minHeight: props.multiline ? MULTILINE_INPUT_MIN_HEIGHT : INPUT_MIN_HEIGHT,
|
|
134
|
+
maxHeight: props.multiline ? MULTILINE_INPUT_MAX_HEIGHT : undefined,
|
|
135
|
+
height: props.multiline ? MULTILINE_INPUT_MIN_HEIGHT : undefined,
|
|
166
136
|
borderWidth: 1,
|
|
167
|
-
paddingRight: rightComponentWidth +
|
|
137
|
+
paddingRight: rightComponentWidth + HORIZONTAL_PADDING,
|
|
168
138
|
paddingLeft: textInputPaddingLeft,
|
|
169
139
|
...styleProp,
|
|
170
140
|
};
|
|
171
141
|
}, [fontFamily, styleProp, props.multiline, rightComponentWidth, textInputPaddingLeft]);
|
|
172
|
-
const labelStyles =
|
|
142
|
+
const labelStyles = useMemo(() => {
|
|
173
143
|
return {
|
|
174
144
|
// this is neeeded too make sure the label is on top of the input
|
|
175
145
|
backgroundColor: "white",
|
|
@@ -178,32 +148,32 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
178
148
|
fontFamily: fontFamily,
|
|
179
149
|
};
|
|
180
150
|
}, [fontFamily, space]);
|
|
181
|
-
animatedState.value =
|
|
151
|
+
animatedState.value = getInputState({
|
|
182
152
|
isFocused: !!focused,
|
|
183
153
|
value: value,
|
|
184
154
|
});
|
|
185
|
-
const textInputAnimatedStyles =
|
|
155
|
+
const textInputAnimatedStyles = useAnimatedStyle(() => {
|
|
186
156
|
return {
|
|
187
|
-
borderColor:
|
|
188
|
-
color:
|
|
157
|
+
borderColor: withTiming(INPUT_VARIANTS[variant][animatedState.value].inputBorderColor),
|
|
158
|
+
color: withTiming(INPUT_VARIANTS[variant][animatedState.value].inputTextColor),
|
|
189
159
|
};
|
|
190
160
|
});
|
|
191
|
-
const labelAnimatedStyles =
|
|
161
|
+
const labelAnimatedStyles = useAnimatedStyle(() => {
|
|
192
162
|
const hasValue = !!value;
|
|
193
163
|
// Only add a margin if the input has a left component and it is not focused and has no value
|
|
194
164
|
const marginLeft = textInputPaddingLeft && !focused && !hasValue
|
|
195
165
|
? textInputPaddingLeft - 3
|
|
196
|
-
:
|
|
166
|
+
: HORIZONTAL_PADDING;
|
|
197
167
|
return {
|
|
198
|
-
color:
|
|
199
|
-
top:
|
|
200
|
-
fontSize:
|
|
201
|
-
marginLeft:
|
|
168
|
+
color: withTiming(INPUT_VARIANTS[variant][animatedState.value].labelColor),
|
|
169
|
+
top: withTiming(INPUT_VARIANTS[variant][animatedState.value].labelTop),
|
|
170
|
+
fontSize: withTiming(INPUT_VARIANTS[variant][animatedState.value].labelFontSize),
|
|
171
|
+
marginLeft: withTiming(marginLeft),
|
|
202
172
|
};
|
|
203
173
|
});
|
|
204
|
-
const selectComponentStyles =
|
|
174
|
+
const selectComponentStyles = useAnimatedStyle(() => {
|
|
205
175
|
return {
|
|
206
|
-
borderColor:
|
|
176
|
+
borderColor: withTiming(INPUT_VARIANTS[variant][animatedState.value].inputBorderColor),
|
|
207
177
|
};
|
|
208
178
|
});
|
|
209
179
|
const handleFocus = (e) => {
|
|
@@ -215,32 +185,32 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
215
185
|
onBlur?.(e);
|
|
216
186
|
};
|
|
217
187
|
const hasTitle = !!props.title;
|
|
218
|
-
const renderLeftComponent =
|
|
188
|
+
const renderLeftComponent = useCallback(() => {
|
|
219
189
|
const leftComponentSharedStyles = {
|
|
220
190
|
position: "absolute",
|
|
221
|
-
paddingHorizontal:
|
|
222
|
-
height:
|
|
223
|
-
top: hasTitle ?
|
|
191
|
+
paddingHorizontal: HORIZONTAL_PADDING,
|
|
192
|
+
height: INPUT_MIN_HEIGHT,
|
|
193
|
+
top: hasTitle ? LABEL_HEIGHT : 0,
|
|
224
194
|
alignItems: "center",
|
|
225
195
|
zIndex: 100,
|
|
226
196
|
};
|
|
227
197
|
if (unit || icon) {
|
|
228
|
-
return ((
|
|
198
|
+
return (_jsxs(Flex, { style: {
|
|
229
199
|
...leftComponentSharedStyles,
|
|
230
200
|
justifyContent: "center",
|
|
231
201
|
width: leftComponentWidth,
|
|
232
|
-
}, children: [unit && ((
|
|
202
|
+
}, children: [unit && (_jsx(Text, { color: disabled ? "black30" : "black60", variant: "sm-display", children: unit })), icon] }));
|
|
233
203
|
}
|
|
234
204
|
if (onSelectTap) {
|
|
235
|
-
return ((
|
|
205
|
+
return (_jsx(TouchableOpacity, { onPress: onSelectTap, style: [
|
|
236
206
|
leftComponentSharedStyles,
|
|
237
207
|
{
|
|
238
208
|
width: selectComponentWidth,
|
|
239
209
|
},
|
|
240
|
-
], hitSlop: { top: 10, right: 10, bottom: 10, left: 10 }, children: (
|
|
210
|
+
], hitSlop: { top: 10, right: 10, bottom: 10, left: 10 }, children: _jsxs(AnimatedFlex, { style: [
|
|
241
211
|
{
|
|
242
|
-
paddingHorizontal:
|
|
243
|
-
height:
|
|
212
|
+
paddingHorizontal: HORIZONTAL_PADDING,
|
|
213
|
+
height: INPUT_MIN_HEIGHT,
|
|
244
214
|
alignItems: "center",
|
|
245
215
|
width: selectComponentWidth,
|
|
246
216
|
flexDirection: "row",
|
|
@@ -248,7 +218,7 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
248
218
|
justifyContent: "space-between",
|
|
249
219
|
},
|
|
250
220
|
selectComponentStyles,
|
|
251
|
-
], children: [(
|
|
221
|
+
], children: [_jsx(Text, { color: disabled ? "black30" : "black100", children: selectDisplayLabel }), _jsx(TriangleDown, { fill: "black60", width: 10 })] }) }));
|
|
252
222
|
}
|
|
253
223
|
return null;
|
|
254
224
|
}, [
|
|
@@ -262,28 +232,28 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
262
232
|
selectComponentStyles,
|
|
263
233
|
selectDisplayLabel,
|
|
264
234
|
]);
|
|
265
|
-
const renderRightComponent =
|
|
235
|
+
const renderRightComponent = useCallback(() => {
|
|
266
236
|
if (fixedRightPlaceholder) {
|
|
267
|
-
return ((
|
|
237
|
+
return (_jsx(Flex, { justifyContent: "center", position: "absolute", right: `${HORIZONTAL_PADDING}px`, top: hasTitle ? LABEL_HEIGHT : 0, height: INPUT_MIN_HEIGHT, ref: rightComponentRef, children: _jsx(Text, { color: disabled ? "black30" : "black60", children: fixedRightPlaceholder }) }));
|
|
268
238
|
}
|
|
269
239
|
if (loading) {
|
|
270
|
-
return ((
|
|
240
|
+
return (_jsx(Flex, { justifyContent: "center", position: "absolute", right: `${HORIZONTAL_PADDING}px`, top: hasTitle ? LABEL_HEIGHT : 0, height: INPUT_MIN_HEIGHT, ref: rightComponentRef, children: _jsx(Spinner, { size: "medium", style: {
|
|
271
241
|
right: 0,
|
|
272
242
|
width: 15,
|
|
273
243
|
backgroundColor: color("black60"),
|
|
274
244
|
} }) }));
|
|
275
245
|
}
|
|
276
246
|
if (enableClearButton && value) {
|
|
277
|
-
return ((
|
|
247
|
+
return (_jsx(Flex, { justifyContent: "center", position: "absolute", right: `${HORIZONTAL_PADDING}px`, top: hasTitle ? LABEL_HEIGHT : 0, height: INPUT_MIN_HEIGHT, zIndex: 100, ref: rightComponentRef, children: _jsx(Touchable, { haptic: "impactMedium", onPress: handleClear, hitSlop: { bottom: 40, right: 40, left: 0, top: 40 }, accessibilityLabel: "Clear input button", testID: "clear-input-button", children: _jsx(XCircleIcon, { fill: "black30" }) }) }));
|
|
278
248
|
}
|
|
279
249
|
if (secureTextEntry) {
|
|
280
|
-
return ((
|
|
281
|
-
|
|
282
|
-
...
|
|
250
|
+
return (_jsx(Flex, { justifyContent: "center", position: "absolute", right: `${HORIZONTAL_PADDING}px`, top: hasTitle ? LABEL_HEIGHT : 0, height: INPUT_MIN_HEIGHT, zIndex: 100, ref: rightComponentRef, children: _jsx(Touchable, { haptic: true, onPress: () => {
|
|
251
|
+
LayoutAnimation.configureNext({
|
|
252
|
+
...LayoutAnimation.Presets.easeInEaseOut,
|
|
283
253
|
duration: 200,
|
|
284
254
|
});
|
|
285
255
|
setShowPassword(!showPassword);
|
|
286
|
-
}, accessibilityLabel: showPassword ? "hide password button" : "show password button", hitSlop: { bottom: 40, right: 40, left: 0, top: 40 }, children: !showPassword ? (
|
|
256
|
+
}, accessibilityLabel: showPassword ? "hide password button" : "show password button", hitSlop: { bottom: 40, right: 40, left: 0, top: 40 }, children: !showPassword ? _jsx(EyeClosedIcon, { fill: "black30" }) : _jsx(EyeOpenedIcon, { fill: "black60" }) }) }));
|
|
287
257
|
}
|
|
288
258
|
return null;
|
|
289
259
|
}, [
|
|
@@ -298,37 +268,37 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
298
268
|
handleClear,
|
|
299
269
|
showPassword,
|
|
300
270
|
]);
|
|
301
|
-
const renderBottomComponent =
|
|
271
|
+
const renderBottomComponent = useCallback(() => {
|
|
302
272
|
if (!!props.error) {
|
|
303
|
-
return ((
|
|
273
|
+
return (_jsx(Text, { color: "red100", variant: "xs", px: `${HORIZONTAL_PADDING}px`, mt: 0.5, children: props.error }));
|
|
304
274
|
}
|
|
305
|
-
return ((
|
|
275
|
+
return (_jsxs(Flex, { flexDirection: "row", justifyContent: "space-between", children: [!!props.required || !!props.optional ? (_jsxs(Text, { color: "black60", variant: "xs", pl: `${HORIZONTAL_PADDING}px`, mt: 0.5, children: [!!props.required && "* Required", !!props.optional && "* Optional"] })) : (
|
|
306
276
|
// Adding this empty flex to make sure that the maxLength text is always on the right
|
|
307
|
-
(
|
|
277
|
+
_jsx(Flex, {})), !!props.maxLength && !!props.showLimit && (_jsxs(Text, { color: "black60", variant: "xs", pr: `${HORIZONTAL_PADDING}px`, mt: 0.5, children: [(value || "").length, " / ", props.maxLength] }))] }));
|
|
308
278
|
}, [props.error, props.maxLength, props.optional, props.required, props.showLimit, value]);
|
|
309
|
-
const renderHint =
|
|
279
|
+
const renderHint = useCallback(() => {
|
|
310
280
|
if (!props.onHintPress) {
|
|
311
281
|
return null;
|
|
312
282
|
}
|
|
313
|
-
return ((
|
|
283
|
+
return (_jsx(Flex, { style: {
|
|
314
284
|
alignItems: "flex-end",
|
|
315
285
|
top: space(2),
|
|
316
|
-
}, children: (
|
|
286
|
+
}, children: _jsx(Touchable, { onPress: props.onHintPress, haptic: "impactLight", hitSlop: {
|
|
317
287
|
top: 5,
|
|
318
288
|
right: 10,
|
|
319
289
|
bottom: 5,
|
|
320
290
|
left: 10,
|
|
321
|
-
}, children: (
|
|
291
|
+
}, children: _jsx(Text, { underline: true, variant: "xs", color: "black60", children: hintText }) }) }));
|
|
322
292
|
}, [hintText, props.onHintPress, space]);
|
|
323
|
-
const getPlatformSpecificPlaceholder =
|
|
293
|
+
const getPlatformSpecificPlaceholder = useCallback(() => {
|
|
324
294
|
if (!placeholder) {
|
|
325
295
|
return "";
|
|
326
296
|
}
|
|
327
|
-
if (
|
|
328
|
-
return (
|
|
297
|
+
if (Platform.OS === "ios") {
|
|
298
|
+
return isArray(placeholder) ? placeholder[0] : placeholder;
|
|
329
299
|
}
|
|
330
300
|
// if it's android and we only have one string, return that string
|
|
331
|
-
if ((
|
|
301
|
+
if (isString(placeholder)) {
|
|
332
302
|
return placeholder;
|
|
333
303
|
}
|
|
334
304
|
// otherwise, find a placeholder that has longest width that fits in the inputtext
|
|
@@ -341,7 +311,7 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
341
311
|
// otherwise just return the shortest placeholder
|
|
342
312
|
return placeholder[placeholder.length - 1];
|
|
343
313
|
}, [inputWidth, placeholder]);
|
|
344
|
-
const getPlaceholder =
|
|
314
|
+
const getPlaceholder = useCallback(() => {
|
|
345
315
|
// Show placeholder always if there is no title
|
|
346
316
|
// This is because we won't have a title animation
|
|
347
317
|
if (!props.title) {
|
|
@@ -354,40 +324,40 @@ exports.Input = (0, react_1.forwardRef)(({ addClearListener = false, defaultValu
|
|
|
354
324
|
// On focus, we want to show the placeholder after the title animation has finished
|
|
355
325
|
return "";
|
|
356
326
|
}, [delayedFocused, getPlatformSpecificPlaceholder, props.title]);
|
|
357
|
-
const renderAnimatedTitle =
|
|
327
|
+
const renderAnimatedTitle = useCallback(() => {
|
|
358
328
|
if (!props.title) {
|
|
359
329
|
return null;
|
|
360
330
|
}
|
|
361
|
-
return ((
|
|
331
|
+
return (_jsx(Flex, { flexDirection: "row", zIndex: 100, pointerEvents: "none", height: LABEL_HEIGHT, children: _jsxs(AnimatedText, { style: [labelStyles, labelAnimatedStyles], numberOfLines: 1, children: [" ", props.title, " "] }) }));
|
|
362
332
|
}, [labelStyles, labelAnimatedStyles, props.title]);
|
|
363
|
-
const renderAndroidPlaceholderMeasuringHack =
|
|
364
|
-
if (
|
|
333
|
+
const renderAndroidPlaceholderMeasuringHack = useCallback(() => {
|
|
334
|
+
if (Platform.OS === "ios" || !isArray(placeholder)) {
|
|
365
335
|
return null;
|
|
366
336
|
}
|
|
367
337
|
// Do not render the hack if we have already measured the placeholder
|
|
368
338
|
if (placeholderWidths.current.length > 0) {
|
|
369
339
|
return null;
|
|
370
340
|
}
|
|
371
|
-
return ((
|
|
341
|
+
return (_jsx(Flex, { style: {
|
|
372
342
|
position: "absolute",
|
|
373
343
|
top: -10000,
|
|
374
344
|
width: 10000,
|
|
375
345
|
alignItems: "baseline", // this is to make Texts get the smallest width they can get to fit the text
|
|
376
|
-
}, children: placeholder.map((placeholderString, index) => ((
|
|
346
|
+
}, children: placeholder.map((placeholderString, index) => (_jsx(Text, { onLayout: (event) => {
|
|
377
347
|
placeholderWidths.current[index] = event.nativeEvent.layout.width;
|
|
378
348
|
}, numberOfLines: 1, style: {
|
|
379
349
|
...styles,
|
|
380
350
|
}, children: placeholderString }))) }));
|
|
381
351
|
}, [placeholder, styles]);
|
|
382
|
-
return ((
|
|
352
|
+
return (_jsxs(Flex, { flexGrow: 1, children: [renderAndroidPlaceholderMeasuringHack(), renderHint(), renderAnimatedTitle(), _jsx(AnimatedStyledInput, { value: value, onChangeText: handleChangeText, style: [styles, textInputAnimatedStyles], onFocus: handleFocus, onBlur: handleBlur, onLayout: (event) => {
|
|
383
353
|
setInputWidth(event.nativeEvent.layout.width);
|
|
384
354
|
}, scrollEnabled: props.multiline, editable: !disabled, textAlignVertical: props.multiline ? "top" : "center", ref: inputRef, placeholderTextColor: color("black60"), placeholder: getPlaceholder(), secureTextEntry: !showPassword, ...props }), renderRightComponent(), renderLeftComponent(), renderBottomComponent()] }));
|
|
385
355
|
});
|
|
386
|
-
const StyledInput = (
|
|
387
|
-
padding: ${
|
|
388
|
-
font-family: ${(
|
|
389
|
-
border-radius: ${
|
|
356
|
+
const StyledInput = styled(TextInput) `
|
|
357
|
+
padding: ${HORIZONTAL_PADDING}px;
|
|
358
|
+
font-family: ${themeGet("fonts.sans.regular")};
|
|
359
|
+
border-radius: ${INPUT_BORDER_RADIUS}px;
|
|
390
360
|
`;
|
|
391
|
-
const AnimatedStyledInput =
|
|
392
|
-
const AnimatedText =
|
|
393
|
-
const AnimatedFlex =
|
|
361
|
+
const AnimatedStyledInput = Animated.createAnimatedComponent(StyledInput);
|
|
362
|
+
const AnimatedText = Animated.createAnimatedComponent(Text);
|
|
363
|
+
const AnimatedFlex = Animated.createAnimatedComponent(Flex);
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const Text_1 = require("../Text");
|
|
11
|
-
(0, react_native_1.storiesOf)("Input", module).add("Variants", () => ((0, jsx_runtime_1.jsx)(helpers_1.List, { contentContainerStyle: { marginHorizontal: 20, alignItems: "stretch" }, children: (0, jsx_runtime_1.jsxs)(Join_1.Join, { separator: (0, jsx_runtime_1.jsx)(Separator_1.Separator, { my: 2 }), children: [(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "Default" }), (0, jsx_runtime_1.jsx)(Input_1.Input, {})] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title" })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and required" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title", required: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and optional" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title", optional: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and clear button" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title", enableClearButton: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and loading" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title", loading: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and icon" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title", icon: (0, jsx_runtime_1.jsx)(svgs_1.MagnifyingGlassIcon, {}) })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and error" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Title", error: "this is an error" })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and disabled" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Disabled", disabled: true })] }), (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(Input_1.Input, { placeholder: "I'm a placeholder" }) }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title, clear button and value" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { value: "5", enableClearButton: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With fixed right placeholder" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { fixedRightPlaceholder: "cm" })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With placeholder" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { placeholder: "I'm a placeholder" })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and placeholder" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "full text", value: "Wow this is a long text, I wonder if I can read the whole thing!" })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With text limit" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Text with limit", maxLength: 100, showLimit: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "multine Without limit" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Text area", multiline: true })] }), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Text_1.Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "multine With limit" }), (0, jsx_runtime_1.jsx)(Input_1.Input, { title: "Text area with limit", multiline: true, maxLength: 150, showLimit: true })] })] }) })));
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { storiesOf } from "@storybook/react-native";
|
|
3
|
+
import { Input } from "./Input";
|
|
4
|
+
import { List } from "../../storybook/helpers";
|
|
5
|
+
import { MagnifyingGlassIcon } from "../../svgs";
|
|
6
|
+
import { Join } from "../Join";
|
|
7
|
+
import { Separator } from "../Separator";
|
|
8
|
+
import { Text } from "../Text";
|
|
9
|
+
storiesOf("Input", module).add("Variants", () => (_jsx(List, { contentContainerStyle: { marginHorizontal: 20, alignItems: "stretch" }, children: _jsxs(Join, { separator: _jsx(Separator, { my: 2 }), children: [_jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "Default" }), _jsx(Input, {})] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title" }), _jsx(Input, { title: "Title" })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and required" }), _jsx(Input, { title: "Title", required: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and optional" }), _jsx(Input, { title: "Title", optional: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and clear button" }), _jsx(Input, { title: "Title", enableClearButton: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and loading" }), _jsx(Input, { title: "Title", loading: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and icon" }), _jsx(Input, { title: "Title", icon: _jsx(MagnifyingGlassIcon, {}) })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and error" }), _jsx(Input, { title: "Title", error: "this is an error" })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and disabled" }), _jsx(Input, { title: "Disabled", disabled: true })] }), _jsx(_Fragment, { children: _jsx(Input, { placeholder: "I'm a placeholder" }) }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title, clear button and value" }), _jsx(Input, { value: "5", enableClearButton: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With fixed right placeholder" }), _jsx(Input, { fixedRightPlaceholder: "cm" })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With placeholder" }), _jsx(Input, { placeholder: "I'm a placeholder" })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With title and placeholder" }), _jsx(Input, { title: "full text", value: "Wow this is a long text, I wonder if I can read the whole thing!" })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "With text limit" }), _jsx(Input, { title: "Text with limit", maxLength: 100, showLimit: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "multine Without limit" }), _jsx(Input, { title: "Text area", multiline: true })] }), _jsxs(_Fragment, { children: [_jsx(Text, { mb: 1, variant: "sm-display", fontWeight: "bold", children: "multine With limit" }), _jsx(Input, { title: "Text area with limit", multiline: true, maxLength: 150, showLimit: true })] })] }) })));
|
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Input_1 = require("./Input");
|
|
6
|
-
const renderWithWrappers_1 = require("../../utils/tests/renderWithWrappers");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { fireEvent } from "@testing-library/react-native";
|
|
3
|
+
import { Input } from "./Input";
|
|
4
|
+
import { renderWithWrappers } from "../../utils/tests/renderWithWrappers";
|
|
7
5
|
describe("Input", () => {
|
|
8
6
|
const testID = "input";
|
|
9
7
|
it("renders an instance of native TextInput", () => {
|
|
10
|
-
const { getByTestId } =
|
|
8
|
+
const { getByTestId } = renderWithWrappers(_jsx(Input, { testID: testID }));
|
|
11
9
|
expect(getByTestId(testID).type).toEqual("TextInput");
|
|
12
10
|
});
|
|
13
11
|
it("uses correct font family", () => {
|
|
14
|
-
const { getByTestId } =
|
|
12
|
+
const { getByTestId } = renderWithWrappers(_jsx(Input, { testID: testID }));
|
|
15
13
|
expect(getByTestId(testID).props.style[0].fontFamily).toEqual("Unica77LL-Regular");
|
|
16
14
|
});
|
|
17
15
|
it("mutates given text as value", () => {
|
|
18
|
-
const { getByTestId, getByDisplayValue } =
|
|
19
|
-
|
|
16
|
+
const { getByTestId, getByDisplayValue } = renderWithWrappers(_jsx(Input, { testID: testID }));
|
|
17
|
+
fireEvent.changeText(getByTestId(testID), "mockStr");
|
|
20
18
|
getByDisplayValue("mockStr");
|
|
21
19
|
});
|
|
22
20
|
it("Shows an error message when input has an error", () => {
|
|
23
|
-
const { getByText } =
|
|
21
|
+
const { getByText } = renderWithWrappers(_jsx(Input, { value: "", error: "input has an error" }));
|
|
24
22
|
getByText("input has an error");
|
|
25
23
|
});
|
|
26
24
|
it("should render the clear button when input is not empty and pressing it should clear the input", () => {
|
|
27
|
-
const { getByDisplayValue, queryByDisplayValue, getByPlaceholderText, getByLabelText } =
|
|
25
|
+
const { getByDisplayValue, queryByDisplayValue, getByPlaceholderText, getByLabelText } = renderWithWrappers(_jsx(Input, { placeholder: "USD", enableClearButton: true }));
|
|
28
26
|
// placeholder is rendered
|
|
29
27
|
getByPlaceholderText("USD");
|
|
30
|
-
|
|
28
|
+
fireEvent(getByPlaceholderText("USD"), "onChangeText", "Banksy");
|
|
31
29
|
getByDisplayValue("Banksy");
|
|
32
30
|
getByLabelText("Clear input button");
|
|
33
|
-
|
|
31
|
+
fireEvent.press(getByLabelText("Clear input button"));
|
|
34
32
|
expect(queryByDisplayValue("Banksy")).toBeFalsy();
|
|
35
33
|
});
|
|
36
34
|
it("should show the correct show/hide password icon", () => {
|
|
37
|
-
const { getByPlaceholderText, queryByLabelText, getByLabelText } =
|
|
35
|
+
const { getByPlaceholderText, queryByLabelText, getByLabelText } = renderWithWrappers(_jsx(Input, { placeholder: "password", secureTextEntry: true }));
|
|
38
36
|
getByPlaceholderText("password");
|
|
39
37
|
getByLabelText("show password button");
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
fireEvent(getByPlaceholderText("password"), "onChangeText", "123456");
|
|
39
|
+
fireEvent.press(getByLabelText("show password button"));
|
|
42
40
|
expect(queryByLabelText("show password button")).toBeFalsy();
|
|
43
41
|
getByLabelText("hide password button");
|
|
44
|
-
|
|
42
|
+
fireEvent.press(getByLabelText("hide password button"));
|
|
45
43
|
expect(queryByLabelText("hide password button")).toBeFalsy();
|
|
46
44
|
getByLabelText("show password button");
|
|
47
45
|
});
|
|
48
46
|
it("enables scrolling when multiline is true", () => {
|
|
49
|
-
const { getByTestId } =
|
|
47
|
+
const { getByTestId } = renderWithWrappers(_jsx(Input, { testID: testID, multiline: true }));
|
|
50
48
|
expect(getByTestId(testID).props.scrollEnabled).toBe(true);
|
|
51
49
|
});
|
|
52
50
|
});
|