@ledgerhq/lumen-ui-rnative 0.0.44 → 0.0.45
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/.storybook/Decorator.tsx +78 -13
- package/.storybook/docs/getting-started/ThemeProvider.mdx +1 -1
- package/.storybook/docs/style-system/lx.mdx +144 -0
- package/.storybook/docs/style-system/useCreate.mdx +95 -0
- package/.storybook/docs/style-system/useTheme.mdx +52 -0
- package/.storybook/preview-head.html +2 -2
- package/.storybook/{preview.ts → preview.tsx} +6 -1
- package/dist/package.json +2 -3
- package/dist/src/lib/Components/AddressInput/AddressInput.js +1 -1
- package/dist/src/lib/Components/AddressInput/AddressInput.stories.d.ts +7 -1
- package/dist/src/lib/Components/AddressInput/AddressInput.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/AddressInput/AddressInput.stories.js +98 -9
- package/dist/src/lib/Components/AmountInput/AmountInput.d.ts.map +1 -1
- package/dist/src/lib/Components/AmountInput/AmountInput.js +3 -3
- package/dist/src/lib/Components/AmountInput/AmountInput.stories.d.ts +10 -1
- package/dist/src/lib/Components/AmountInput/AmountInput.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/AmountInput/AmountInput.stories.js +162 -9
- package/dist/src/lib/Components/BaseInput/BaseInput.d.ts.map +1 -1
- package/dist/src/lib/Components/BaseInput/BaseInput.js +2 -19
- package/dist/src/lib/Components/BottomSheet/BottomSheet.js +1 -1
- package/dist/src/lib/Components/BottomSheet/BottomSheet.stories.js +8 -8
- package/dist/src/lib/Components/Button/BaseButton.d.ts +3 -3
- package/dist/src/lib/Components/Button/BaseButton.d.ts.map +1 -1
- package/dist/src/lib/Components/Button/BaseButton.js +99 -119
- package/dist/src/lib/Components/Button/Button.d.ts +4 -26
- package/dist/src/lib/Components/Button/Button.d.ts.map +1 -1
- package/dist/src/lib/Components/Button/Button.js +2 -2
- package/dist/src/lib/Components/Button/Button.stories.d.ts +1 -1
- package/dist/src/lib/Components/Button/Button.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/Button/Button.stories.js +25 -48
- package/dist/src/lib/Components/Button/index.d.ts +1 -1
- package/dist/src/lib/Components/Button/index.d.ts.map +1 -1
- package/dist/src/lib/Components/Button/index.js +1 -1
- package/dist/src/lib/Components/Button/{BaseButton.types.d.ts → types.d.ts} +15 -10
- package/dist/src/lib/Components/Button/types.d.ts.map +1 -0
- package/dist/src/lib/Components/CardButton/CardButton.d.ts +4 -3
- package/dist/src/lib/Components/CardButton/CardButton.d.ts.map +1 -1
- package/dist/src/lib/Components/CardButton/CardButton.js +65 -71
- package/dist/src/lib/Components/CardButton/CardButton.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/CardButton/CardButton.stories.js +28 -15
- package/dist/src/lib/Components/CardButton/index.d.ts +1 -1
- package/dist/src/lib/Components/CardButton/index.d.ts.map +1 -1
- package/dist/src/lib/Components/CardButton/index.js +1 -1
- package/dist/src/lib/Components/CardButton/{CardButton.types.d.ts → types.d.ts} +5 -4
- package/dist/src/lib/Components/CardButton/types.d.ts.map +1 -0
- package/dist/src/lib/Components/Icon/Icon.d.ts +6 -3
- package/dist/src/lib/Components/Icon/Icon.d.ts.map +1 -1
- package/dist/src/lib/Components/Icon/Icon.js +24 -25
- package/dist/src/lib/Components/Icon/Icon.stories.d.ts +2 -2
- package/dist/src/lib/Components/Icon/Icon.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/Icon/Icon.stories.js +73 -19
- package/dist/src/lib/Components/Icon/createIcon.d.ts +1 -1
- package/dist/src/lib/Components/Icon/createIcon.d.ts.map +1 -1
- package/dist/src/lib/Components/Icon/createIcon.js +1 -2
- package/dist/src/lib/Components/Icon/index.d.ts +1 -1
- package/dist/src/lib/Components/Icon/index.d.ts.map +1 -1
- package/dist/src/lib/Components/Icon/index.js +1 -1
- package/dist/src/lib/Components/Icon/{Icon.types.d.ts → types.d.ts} +7 -4
- package/dist/src/lib/Components/Icon/types.d.ts.map +1 -0
- package/dist/src/lib/Components/IconButton/IconButton.d.ts +2 -19
- package/dist/src/lib/Components/IconButton/IconButton.d.ts.map +1 -1
- package/dist/src/lib/Components/IconButton/IconButton.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/IconButton/IconButton.stories.js +9 -11
- package/dist/src/lib/Components/IconButton/index.d.ts +1 -0
- package/dist/src/lib/Components/IconButton/index.d.ts.map +1 -1
- package/dist/src/lib/Components/IconButton/index.js +1 -0
- package/dist/src/lib/Components/IconButton/types.d.ts +12 -0
- package/dist/src/lib/Components/IconButton/types.d.ts.map +1 -0
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.d.ts +2 -2
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.d.ts.map +1 -1
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.figma.js +1 -1
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.js +34 -34
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.stories.d.ts +1 -1
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/InteractiveIcon/InteractiveIcon.stories.js +22 -9
- package/dist/src/lib/Components/InteractiveIcon/types.d.ts +3 -7
- package/dist/src/lib/Components/InteractiveIcon/types.d.ts.map +1 -1
- package/dist/src/lib/Components/Link/Link.d.ts +7 -77
- package/dist/src/lib/Components/Link/Link.d.ts.map +1 -1
- package/dist/src/lib/Components/Link/Link.js +59 -75
- package/dist/src/lib/Components/Link/Link.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/Link/Link.stories.js +34 -11
- package/dist/src/lib/Components/Link/index.d.ts +1 -0
- package/dist/src/lib/Components/Link/index.d.ts.map +1 -1
- package/dist/src/lib/Components/Link/index.js +1 -0
- package/dist/src/lib/Components/Link/types.d.ts +43 -0
- package/dist/src/lib/Components/Link/types.d.ts.map +1 -0
- package/dist/src/lib/Components/Link/types.js +1 -0
- package/dist/src/lib/Components/Search/Search.stories.d.ts +6 -1
- package/dist/src/lib/Components/Search/Search.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/Search/Search.stories.js +71 -9
- package/dist/src/lib/Components/Select/Select.d.ts.map +1 -1
- package/dist/src/lib/Components/Select/Select.js +1 -17
- package/dist/src/lib/Components/Spinner/Spinner.d.ts +13 -16
- package/dist/src/lib/Components/Spinner/Spinner.d.ts.map +1 -1
- package/dist/src/lib/Components/Spinner/Spinner.js +33 -5
- package/dist/src/lib/Components/Spinner/Spinner.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/Spinner/Spinner.stories.js +1 -1
- package/dist/src/lib/Components/Spinner/index.d.ts +1 -0
- package/dist/src/lib/Components/Spinner/index.d.ts.map +1 -1
- package/dist/src/lib/Components/Spinner/index.js +1 -0
- package/dist/src/lib/Components/Spinner/types.d.ts +15 -0
- package/dist/src/lib/Components/Spinner/types.d.ts.map +1 -0
- package/dist/src/lib/Components/Spinner/types.js +1 -0
- package/dist/src/lib/Components/Tag/Tag.d.ts +2 -1
- package/dist/src/lib/Components/Tag/Tag.d.ts.map +1 -1
- package/dist/src/lib/Components/Tag/Tag.js +15 -4
- package/dist/src/lib/Components/Tag/Tag.stories.js +1 -1
- package/dist/src/lib/Components/Tag/Tag.types.d.ts +7 -1
- package/dist/src/lib/Components/Tag/Tag.types.d.ts.map +1 -1
- package/dist/src/lib/Components/TextInput/TextInput.stories.d.ts +8 -1
- package/dist/src/lib/Components/TextInput/TextInput.stories.d.ts.map +1 -1
- package/dist/src/lib/Components/TextInput/TextInput.stories.js +104 -9
- package/dist/src/lib/Components/Tile/Tile.js +2 -2
- package/dist/src/lib/Components/Tooltip/Tooltip.stories.js +2 -2
- package/dist/src/lib/Components/Utility/Box/Box.d.ts +39 -0
- package/dist/src/lib/Components/Utility/Box/Box.d.ts.map +1 -0
- package/dist/src/lib/Components/{Box → Utility/Box}/Box.js +10 -11
- package/dist/src/lib/Components/Utility/Box/Box.stories.d.ts.map +1 -0
- package/dist/src/lib/Components/{Box → Utility/Box}/Box.stories.js +13 -12
- package/dist/src/lib/Components/Utility/Box/index.d.ts +2 -0
- package/dist/src/lib/Components/Utility/Box/index.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/Pressable/Pressable.d.ts +34 -0
- package/dist/src/lib/Components/Utility/Pressable/Pressable.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/Pressable/Pressable.js +33 -0
- package/dist/src/lib/Components/Utility/Pressable/Pressable.stories.d.ts +7 -0
- package/dist/src/lib/Components/Utility/Pressable/Pressable.stories.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/Pressable/Pressable.stories.js +47 -0
- package/dist/src/lib/Components/Utility/Pressable/index.d.ts +3 -0
- package/dist/src/lib/Components/Utility/Pressable/index.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/Pressable/index.js +1 -0
- package/dist/src/lib/Components/Utility/Pressable/types.d.ts +3 -0
- package/dist/src/lib/Components/Utility/Pressable/types.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/Pressable/types.js +1 -0
- package/dist/src/lib/Components/Utility/Text/Text.d.ts +40 -0
- package/dist/src/lib/Components/Utility/Text/Text.d.ts.map +1 -0
- package/dist/src/lib/Components/{Text → Utility/Text}/Text.js +13 -9
- package/dist/src/lib/Components/Utility/Text/Text.stories.d.ts.map +1 -0
- package/dist/src/lib/Components/{Text → Utility/Text}/Text.stories.js +3 -3
- package/dist/src/lib/Components/Utility/Text/index.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/index.d.ts +4 -0
- package/dist/src/lib/Components/Utility/index.d.ts.map +1 -0
- package/dist/src/lib/Components/Utility/index.js +3 -0
- package/dist/src/lib/Components/index.d.ts +1 -3
- package/dist/src/lib/Components/index.d.ts.map +1 -1
- package/dist/src/lib/Components/index.js +1 -3
- package/dist/src/lib/utils/components/InjectStylesIntoChildren.d.ts +6 -5
- package/dist/src/lib/utils/components/InjectStylesIntoChildren.d.ts.map +1 -1
- package/dist/src/lib/utils/components/InjectStylesIntoChildren.js +6 -6
- package/dist/src/styles/LumenStyleSheet.d.ts +1 -1
- package/dist/src/styles/LumenStyleSheet.d.ts.map +1 -1
- package/dist/src/styles/Provider/createStylesheetTheme.d.ts +0 -1
- package/dist/src/styles/Provider/createStylesheetTheme.d.ts.map +1 -1
- package/dist/src/styles/Provider/createStylesheetTheme.js +0 -1
- package/dist/src/styles/create/useCreate.d.ts +2 -1
- package/dist/src/styles/create/useCreate.d.ts.map +1 -1
- package/dist/src/styles/create/useCreate.js +5 -5
- package/dist/src/styles/factories/areLxPropsEqual.d.ts +3 -0
- package/dist/src/styles/factories/areLxPropsEqual.d.ts.map +1 -0
- package/dist/src/styles/factories/areLxPropsEqual.js +15 -0
- package/dist/src/styles/factories/createStyledPressable.d.ts +26 -0
- package/dist/src/styles/factories/createStyledPressable.d.ts.map +1 -0
- package/dist/src/styles/factories/createStyledPressable.js +61 -0
- package/dist/src/styles/factories/createStyledText.d.ts +15 -26
- package/dist/src/styles/factories/createStyledText.d.ts.map +1 -1
- package/dist/src/styles/factories/createStyledText.js +13 -29
- package/dist/src/styles/factories/createStyledView.d.ts +7 -27
- package/dist/src/styles/factories/createStyledView.d.ts.map +1 -1
- package/dist/src/styles/factories/createStyledView.js +10 -30
- package/dist/src/styles/factories/index.d.ts +4 -0
- package/dist/src/styles/factories/index.d.ts.map +1 -0
- package/dist/src/styles/factories/index.js +3 -0
- package/dist/src/styles/index.d.ts +2 -3
- package/dist/src/styles/index.d.ts.map +1 -1
- package/dist/src/styles/index.js +2 -3
- package/dist/src/styles/resolveStyle/resolveConfig.d.ts +7 -7
- package/dist/src/styles/resolveStyle/resolveConfig.d.ts.map +1 -1
- package/dist/src/styles/resolveStyle/resolveConfig.js +9 -9
- package/dist/src/styles/resolveStyle/resolveStyle.d.ts +6 -20
- package/dist/src/styles/resolveStyle/resolveStyle.d.ts.map +1 -1
- package/dist/src/styles/resolveStyle/resolveStyle.js +4 -29
- package/dist/src/styles/types/create.types.d.ts +1 -1
- package/dist/src/styles/types/create.types.d.ts.map +1 -1
- package/dist/src/styles/types/styled.types.d.ts +72 -50
- package/dist/src/styles/types/styled.types.d.ts.map +1 -1
- package/dist/src/styles/types/utility.types.d.ts.map +1 -1
- package/dist/src/styles/utils/index.d.ts +2 -0
- package/dist/src/styles/utils/index.d.ts.map +1 -0
- package/dist/src/styles/utils/index.js +1 -0
- package/dist/src/styles/utils/mergeStyles.d.ts +16 -0
- package/dist/src/styles/utils/mergeStyles.d.ts.map +1 -0
- package/dist/src/styles/utils/mergeStyles.js +20 -0
- package/package.json +3 -4
- package/src/lib/Components/AddressInput/AddressInput.mdx +15 -4
- package/src/lib/Components/AddressInput/AddressInput.stories.tsx +133 -17
- package/src/lib/Components/AddressInput/AddressInput.tsx +1 -1
- package/src/lib/Components/AmountInput/AmountInput.mdx +20 -1
- package/src/lib/Components/AmountInput/AmountInput.stories.tsx +180 -17
- package/src/lib/Components/AmountInput/AmountInput.tsx +24 -15
- package/src/lib/Components/Banner/Banner.test.tsx +48 -15
- package/src/lib/Components/BaseInput/BaseInput.tsx +6 -35
- package/src/lib/Components/BottomSheet/BottomSheet.stories.tsx +8 -8
- package/src/lib/Components/BottomSheet/BottomSheet.tsx +1 -1
- package/src/lib/Components/Button/BaseButton.test.tsx +149 -0
- package/src/lib/Components/Button/BaseButton.tsx +193 -148
- package/src/lib/Components/Button/Button.mdx +34 -31
- package/src/lib/Components/Button/Button.stories.tsx +37 -58
- package/src/lib/Components/Button/Button.tsx +4 -11
- package/src/lib/Components/Button/index.ts +1 -1
- package/src/lib/Components/Button/{BaseButton.types.ts → types.ts} +14 -8
- package/src/lib/Components/CardButton/CardButton.mdx +15 -25
- package/src/lib/Components/CardButton/CardButton.stories.tsx +48 -22
- package/src/lib/Components/CardButton/CardButton.test.tsx +141 -0
- package/src/lib/Components/CardButton/CardButton.tsx +142 -108
- package/src/lib/Components/CardButton/index.ts +1 -1
- package/src/lib/Components/CardButton/{CardButton.types.ts → types.ts} +4 -3
- package/src/lib/Components/Checkbox/Checkbox.mdx +1 -1
- package/src/lib/Components/Checkbox/Checkbox.test.tsx +42 -17
- package/src/lib/Components/Icon/Icon.stories.tsx +143 -73
- package/src/lib/Components/Icon/Icon.test.tsx +84 -0
- package/src/lib/Components/Icon/Icon.tsx +32 -28
- package/src/lib/Components/Icon/createIcon.ts +2 -3
- package/src/lib/Components/Icon/index.ts +1 -1
- package/src/lib/Components/Icon/{Icon.types.ts → types.ts} +4 -3
- package/src/lib/Components/IconButton/IconButton.mdx +13 -10
- package/src/lib/Components/IconButton/IconButton.stories.tsx +12 -14
- package/src/lib/Components/IconButton/IconButton.test.tsx +141 -0
- package/src/lib/Components/IconButton/IconButton.tsx +3 -13
- package/src/lib/Components/IconButton/index.ts +1 -0
- package/src/lib/Components/IconButton/types.ts +12 -0
- package/src/lib/Components/InteractiveIcon/InteractiveIcon.figma.tsx +1 -1
- package/src/lib/Components/InteractiveIcon/InteractiveIcon.mdx +25 -27
- package/src/lib/Components/InteractiveIcon/InteractiveIcon.stories.tsx +82 -43
- package/src/lib/Components/InteractiveIcon/InteractiveIcon.test.tsx +30 -19
- package/src/lib/Components/InteractiveIcon/InteractiveIcon.tsx +78 -45
- package/src/lib/Components/InteractiveIcon/types.ts +4 -7
- package/src/lib/Components/Link/Link.mdx +8 -18
- package/src/lib/Components/Link/Link.stories.tsx +56 -25
- package/src/lib/Components/Link/Link.test.tsx +141 -51
- package/src/lib/Components/Link/Link.tsx +128 -150
- package/src/lib/Components/Link/index.ts +1 -0
- package/src/lib/Components/Link/types.ts +44 -0
- package/src/lib/Components/Search/Search.mdx +14 -1
- package/src/lib/Components/Search/Search.stories.tsx +94 -15
- package/src/lib/Components/Select/Select.test.tsx +8 -4
- package/src/lib/Components/Select/Select.tsx +4 -31
- package/src/lib/Components/Spinner/Spinner.stories.tsx +1 -5
- package/src/lib/Components/Spinner/Spinner.tsx +60 -34
- package/src/lib/Components/Spinner/index.ts +1 -0
- package/src/lib/Components/Spinner/types.ts +15 -0
- package/src/lib/Components/Switch/Switch.mdx +1 -1
- package/src/lib/Components/Tag/Tag.stories.tsx +2 -2
- package/src/lib/Components/Tag/Tag.tsx +22 -6
- package/src/lib/Components/Tag/Tag.types.ts +7 -8
- package/src/lib/Components/TextInput/TextInput.mdx +24 -4
- package/src/lib/Components/TextInput/TextInput.stories.tsx +131 -15
- package/src/lib/Components/Tile/Tile.test.tsx +100 -63
- package/src/lib/Components/Tile/Tile.tsx +2 -2
- package/src/lib/Components/Tooltip/Tooltip.stories.tsx +2 -2
- package/src/lib/Components/Tooltip/Tooltip.test.tsx +8 -4
- package/src/lib/Components/{Box → Utility/Box}/Box.mdx +15 -13
- package/src/lib/Components/{Box → Utility/Box}/Box.stories.tsx +13 -11
- package/src/lib/Components/{Box → Utility/Box}/Box.tsx +11 -12
- package/src/lib/Components/Utility/Box/index.ts +1 -0
- package/src/lib/Components/Utility/Pressable/Pressable.mdx +103 -0
- package/src/lib/Components/Utility/Pressable/Pressable.stories.tsx +51 -0
- package/src/lib/Components/Utility/Pressable/Pressable.test.tsx +221 -0
- package/src/lib/Components/Utility/Pressable/Pressable.tsx +34 -0
- package/src/lib/Components/Utility/Pressable/index.ts +2 -0
- package/src/lib/Components/Utility/Pressable/types.ts +3 -0
- package/src/lib/Components/{Text → Utility/Text}/Text.mdx +15 -7
- package/src/lib/Components/{Text → Utility/Text}/Text.stories.tsx +3 -3
- package/src/lib/Components/Utility/Text/Text.tsx +39 -0
- package/src/lib/Components/Utility/index.ts +3 -0
- package/src/lib/Components/index.ts +1 -3
- package/src/lib/utils/components/InjectStylesIntoChildren.tsx +23 -14
- package/src/styles/Provider/createStylesheetTheme.ts +0 -1
- package/src/styles/create/useCreate.ts +8 -4
- package/src/styles/factories/areLxPropsEqual.ts +32 -0
- package/src/styles/factories/createStyledPressable.test.tsx +253 -0
- package/src/styles/factories/createStyledPressable.tsx +97 -0
- package/src/styles/factories/createStyledText.test.tsx +28 -20
- package/src/styles/factories/createStyledText.tsx +29 -49
- package/src/styles/factories/createStyledView.test.tsx +22 -16
- package/src/styles/factories/createStyledView.tsx +19 -53
- package/src/styles/factories/index.ts +3 -0
- package/src/styles/index.ts +2 -3
- package/src/styles/resolveStyle/resolveConfig.ts +16 -15
- package/src/styles/resolveStyle/resolveStyle.test.ts +13 -141
- package/src/styles/resolveStyle/resolveStyle.ts +10 -60
- package/src/styles/types/create.types.ts +1 -1
- package/src/styles/types/styled.types.ts +73 -105
- package/src/styles/types/utility.types.ts +1 -0
- package/src/styles/utils/index.ts +1 -0
- package/src/styles/utils/mergeStyles.test.ts +45 -0
- package/src/styles/utils/mergeStyles.ts +25 -0
- package/.storybook/docs/getting-started/StyleSystem.mdx +0 -133
- package/dist/src/lib/Components/Box/Box.d.ts +0 -592
- package/dist/src/lib/Components/Box/Box.d.ts.map +0 -1
- package/dist/src/lib/Components/Box/Box.stories.d.ts.map +0 -1
- package/dist/src/lib/Components/Box/Box.types.d.ts +0 -3
- package/dist/src/lib/Components/Box/Box.types.d.ts.map +0 -1
- package/dist/src/lib/Components/Box/index.d.ts +0 -3
- package/dist/src/lib/Components/Box/index.d.ts.map +0 -1
- package/dist/src/lib/Components/Button/BaseButton.types.d.ts.map +0 -1
- package/dist/src/lib/Components/CardButton/CardButton.types.d.ts.map +0 -1
- package/dist/src/lib/Components/Icon/Icon.types.d.ts.map +0 -1
- package/dist/src/lib/Components/Text/Text.d.ts +0 -602
- package/dist/src/lib/Components/Text/Text.d.ts.map +0 -1
- package/dist/src/lib/Components/Text/Text.stories.d.ts.map +0 -1
- package/dist/src/lib/Components/Text/index.d.ts.map +0 -1
- package/dist/src/lib/Components/_ToRemove/ToRemove.d.ts +0 -9
- package/dist/src/lib/Components/_ToRemove/ToRemove.d.ts.map +0 -1
- package/dist/src/lib/Components/_ToRemove/ToRemove.js +0 -43
- package/dist/src/styles/utils/styleVarianceAuthority.d.ts +0 -30
- package/dist/src/styles/utils/styleVarianceAuthority.d.ts.map +0 -1
- package/dist/src/styles/utils/styleVarianceAuthority.js +0 -97
- package/src/lib/Components/Box/Box.types.ts +0 -3
- package/src/lib/Components/Box/index.ts +0 -2
- package/src/lib/Components/Text/Text.tsx +0 -35
- package/src/lib/Components/_ToRemove/ToRemove.tsx +0 -65
- package/src/styles/utils/styleVarianceAuthority.test.ts +0 -302
- package/src/styles/utils/styleVarianceAuthority.ts +0 -154
- /package/dist/src/lib/Components/{Box/Box.types.js → Button/types.js} +0 -0
- /package/dist/src/lib/Components/{Button/BaseButton.types.js → CardButton/types.js} +0 -0
- /package/dist/src/lib/Components/{CardButton/CardButton.types.js → Icon/types.js} +0 -0
- /package/dist/src/lib/Components/{Icon/Icon.types.js → IconButton/types.js} +0 -0
- /package/dist/src/lib/Components/{Box → Utility/Box}/Box.stories.d.ts +0 -0
- /package/dist/src/lib/Components/{Box → Utility/Box}/index.js +0 -0
- /package/dist/src/lib/Components/{Text → Utility/Text}/Text.stories.d.ts +0 -0
- /package/dist/src/lib/Components/{Text → Utility/Text}/index.d.ts +0 -0
- /package/dist/src/lib/Components/{Text → Utility/Text}/index.js +0 -0
- /package/src/lib/Components/{Text → Utility/Text}/index.ts +0 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { describe, expect, it, jest } from '@jest/globals';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react-native';
|
|
3
|
+
import React, { createRef } from 'react';
|
|
4
|
+
import {
|
|
5
|
+
Pressable,
|
|
6
|
+
PressableProps,
|
|
7
|
+
PressableStateCallbackType,
|
|
8
|
+
View,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import { LumenStyleSheetProvider } from '../Provider/LumenStyleSheetProvider';
|
|
11
|
+
import { createStyledPressable } from './createStyledPressable';
|
|
12
|
+
|
|
13
|
+
const testThemes: any = {
|
|
14
|
+
light: {
|
|
15
|
+
spacings: { s8: 8, s16: 16 },
|
|
16
|
+
sizes: { s48: 48, full: '100%' },
|
|
17
|
+
colors: { bg: { surface: '#F0F0F0', accent: '#6B21A8' }, border: {} },
|
|
18
|
+
borderRadius: { md: 12 },
|
|
19
|
+
shadows: {},
|
|
20
|
+
typographies: { sm: {} },
|
|
21
|
+
},
|
|
22
|
+
dark: {
|
|
23
|
+
spacings: { s8: 8, s16: 16 },
|
|
24
|
+
sizes: { s48: 48, full: '100%' },
|
|
25
|
+
colors: { bg: { surface: '#1C1C1E', accent: '#A855F7' }, border: {} },
|
|
26
|
+
borderRadius: { md: 12 },
|
|
27
|
+
shadows: {},
|
|
28
|
+
typographies: { sm: {} },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const renderWithProvider = (children: React.ReactElement) =>
|
|
33
|
+
render(
|
|
34
|
+
<LumenStyleSheetProvider themes={testThemes}>
|
|
35
|
+
{children}
|
|
36
|
+
</LumenStyleSheetProvider>,
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
describe('createStyledPressable', () => {
|
|
40
|
+
const StyledPressable = createStyledPressable(Pressable);
|
|
41
|
+
|
|
42
|
+
it('should have correct display name', () => {
|
|
43
|
+
expect(StyledPressable.displayName).toBe('StyledPressable(Pressable)');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should resolve token props to styles', () => {
|
|
47
|
+
renderWithProvider(
|
|
48
|
+
<StyledPressable
|
|
49
|
+
testID='pressable'
|
|
50
|
+
lx={{
|
|
51
|
+
padding: 's16',
|
|
52
|
+
width: 's48',
|
|
53
|
+
backgroundColor: 'surface',
|
|
54
|
+
borderRadius: 'md',
|
|
55
|
+
}}
|
|
56
|
+
/>,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const pressable = screen.getByTestId('pressable');
|
|
60
|
+
expect(pressable.props.style).toMatchObject({
|
|
61
|
+
padding: 16,
|
|
62
|
+
width: 48,
|
|
63
|
+
backgroundColor: '#F0F0F0',
|
|
64
|
+
borderRadius: 12,
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('should resolve full size token to 100%', () => {
|
|
69
|
+
renderWithProvider(
|
|
70
|
+
<StyledPressable testID='pressable' lx={{ width: 'full' }} />,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const pressable = screen.getByTestId('pressable');
|
|
74
|
+
expect(pressable.props.style.width).toBe('100%');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('should merge static style prop with resolved tokens', () => {
|
|
78
|
+
renderWithProvider(
|
|
79
|
+
<StyledPressable
|
|
80
|
+
testID='pressable'
|
|
81
|
+
lx={{ padding: 's16' }}
|
|
82
|
+
style={{ opacity: 0.5 }}
|
|
83
|
+
/>,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const pressable = screen.getByTestId('pressable');
|
|
87
|
+
expect(pressable.props.style.padding).toBe(16);
|
|
88
|
+
expect(pressable.props.style.opacity).toBe(0.5);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should merge style prop with resolved tokens', () => {
|
|
92
|
+
renderWithProvider(
|
|
93
|
+
<StyledPressable
|
|
94
|
+
testID='pressable'
|
|
95
|
+
lx={{ backgroundColor: 'surface' }}
|
|
96
|
+
style={{ opacity: 0.8 }}
|
|
97
|
+
/>,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const pressable = screen.getByTestId('pressable');
|
|
101
|
+
expect(pressable.props.style.backgroundColor).toBe('#F0F0F0');
|
|
102
|
+
expect(pressable.props.style.opacity).toBe(0.8);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should support function-based style prop', () => {
|
|
106
|
+
renderWithProvider(
|
|
107
|
+
<StyledPressable
|
|
108
|
+
testID='pressable'
|
|
109
|
+
lx={{ backgroundColor: 'surface' }}
|
|
110
|
+
style={({ pressed }) => ({
|
|
111
|
+
opacity: pressed ? 0.7 : 1,
|
|
112
|
+
})}
|
|
113
|
+
/>,
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const pressable = screen.getByTestId('pressable');
|
|
117
|
+
expect(pressable.props.style.backgroundColor).toBe('#F0F0F0');
|
|
118
|
+
expect(pressable.props.style.opacity).toBe(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe('array style support', () => {
|
|
122
|
+
it('should support array of static styles', () => {
|
|
123
|
+
renderWithProvider(
|
|
124
|
+
<StyledPressable
|
|
125
|
+
testID='pressable'
|
|
126
|
+
lx={{ padding: 's16' }}
|
|
127
|
+
style={[{ opacity: 0.5 }, { flex: 1 }]}
|
|
128
|
+
/>,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const pressable = screen.getByTestId('pressable');
|
|
132
|
+
expect(pressable.props.style.padding).toBe(16);
|
|
133
|
+
expect(pressable.props.style.opacity).toBe(0.5);
|
|
134
|
+
expect(pressable.props.style.flex).toBe(1);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should support array with function-based style', () => {
|
|
138
|
+
renderWithProvider(
|
|
139
|
+
<StyledPressable
|
|
140
|
+
testID='pressable'
|
|
141
|
+
lx={{ backgroundColor: 'surface' }}
|
|
142
|
+
style={[
|
|
143
|
+
{ flex: 1 },
|
|
144
|
+
({ pressed }: PressableStateCallbackType) => ({
|
|
145
|
+
opacity: pressed ? 0.7 : 1,
|
|
146
|
+
}),
|
|
147
|
+
]}
|
|
148
|
+
/>,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const pressable = screen.getByTestId('pressable');
|
|
152
|
+
expect(pressable.props.style.backgroundColor).toBe('#F0F0F0');
|
|
153
|
+
expect(pressable.props.style.flex).toBe(1);
|
|
154
|
+
expect(pressable.props.style.opacity).toBe(1);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('should support array with mixed static and function styles', () => {
|
|
158
|
+
renderWithProvider(
|
|
159
|
+
<StyledPressable
|
|
160
|
+
testID='pressable'
|
|
161
|
+
style={[
|
|
162
|
+
{ padding: 10 },
|
|
163
|
+
({ pressed }: PressableStateCallbackType) => ({
|
|
164
|
+
opacity: pressed ? 0.5 : 1,
|
|
165
|
+
}),
|
|
166
|
+
{ margin: 5 },
|
|
167
|
+
]}
|
|
168
|
+
/>,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
const pressable = screen.getByTestId('pressable');
|
|
172
|
+
expect(pressable.props.style.padding).toBe(10);
|
|
173
|
+
expect(pressable.props.style.margin).toBe(5);
|
|
174
|
+
expect(pressable.props.style.opacity).toBe(1);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should handle null/undefined in style array', () => {
|
|
178
|
+
renderWithProvider(
|
|
179
|
+
<StyledPressable
|
|
180
|
+
testID='pressable'
|
|
181
|
+
style={[null, { opacity: 0.8 }, undefined]}
|
|
182
|
+
/>,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const pressable = screen.getByTestId('pressable');
|
|
186
|
+
expect(pressable.props.style.opacity).toBe(0.8);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should forward ref', () => {
|
|
191
|
+
const ref = createRef<View>();
|
|
192
|
+
renderWithProvider(<StyledPressable ref={ref} testID='pressable' />);
|
|
193
|
+
expect(ref.current).toBeTruthy();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should handle onPress callback', () => {
|
|
197
|
+
const onPress = jest.fn();
|
|
198
|
+
renderWithProvider(
|
|
199
|
+
<StyledPressable testID='pressable' onPress={onPress} />,
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
fireEvent.press(screen.getByTestId('pressable'));
|
|
203
|
+
expect(onPress).toHaveBeenCalledTimes(1);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('performance (memo)', () => {
|
|
207
|
+
it('should not re-render when props are unchanged', () => {
|
|
208
|
+
const renderCount = jest.fn();
|
|
209
|
+
const TrackedPressable = (props: PressableProps) => {
|
|
210
|
+
renderCount();
|
|
211
|
+
return <Pressable {...props} />;
|
|
212
|
+
};
|
|
213
|
+
const StyledTracked = createStyledPressable(TrackedPressable as any);
|
|
214
|
+
|
|
215
|
+
const { rerender } = renderWithProvider(
|
|
216
|
+
<StyledTracked testID='pressable' lx={{ padding: 's16' }} />,
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
expect(renderCount).toHaveBeenCalledTimes(1);
|
|
220
|
+
|
|
221
|
+
rerender(
|
|
222
|
+
<LumenStyleSheetProvider themes={testThemes}>
|
|
223
|
+
<StyledTracked testID='pressable' lx={{ padding: 's16' }} />
|
|
224
|
+
</LumenStyleSheetProvider>,
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
expect(renderCount).toHaveBeenCalledTimes(1);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('should re-render when token props change', () => {
|
|
231
|
+
const renderCount = jest.fn();
|
|
232
|
+
const TrackedPressable = (props: PressableProps) => {
|
|
233
|
+
renderCount();
|
|
234
|
+
return <Pressable {...props} />;
|
|
235
|
+
};
|
|
236
|
+
const StyledTracked = createStyledPressable(TrackedPressable as any);
|
|
237
|
+
|
|
238
|
+
const { rerender } = renderWithProvider(
|
|
239
|
+
<StyledTracked testID='pressable' lx={{ padding: 's16' }} />,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect(renderCount).toHaveBeenCalledTimes(1);
|
|
243
|
+
|
|
244
|
+
rerender(
|
|
245
|
+
<LumenStyleSheetProvider themes={testThemes}>
|
|
246
|
+
<StyledTracked testID='pressable' lx={{ width: 's48' }} />
|
|
247
|
+
</LumenStyleSheetProvider>,
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
expect(renderCount).toHaveBeenCalledTimes(2);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { forwardRef, memo } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
Pressable,
|
|
5
|
+
PressableProps,
|
|
6
|
+
PressableStateCallbackType,
|
|
7
|
+
ViewStyle,
|
|
8
|
+
} from 'react-native';
|
|
9
|
+
import { useTheme } from '../Provider/useTheme';
|
|
10
|
+
import { resolveViewStyle } from '../resolveStyle/resolveStyle';
|
|
11
|
+
import { LumenPressableStyleLX } from '../types';
|
|
12
|
+
import { areLxPropsEqual } from './areLxPropsEqual';
|
|
13
|
+
|
|
14
|
+
type PressableRef = React.ElementRef<typeof Pressable>;
|
|
15
|
+
type StyleFn = (state: PressableStateCallbackType) => ViewStyle;
|
|
16
|
+
type StyleItem = ViewStyle | StyleFn | StyleItem[] | null | undefined;
|
|
17
|
+
|
|
18
|
+
export type StyledPressableProps = LumenPressableStyleLX &
|
|
19
|
+
Omit<PressableProps, 'style'> & {
|
|
20
|
+
style?: StyleItem;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Check if any style item (including nested arrays) is a function
|
|
25
|
+
*/
|
|
26
|
+
const hasStyleFunction = (style: StyleItem): boolean => {
|
|
27
|
+
if (Array.isArray(style)) {
|
|
28
|
+
return style.some((s) => hasStyleFunction(s));
|
|
29
|
+
}
|
|
30
|
+
return typeof style === 'function';
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Resolve all style functions in a style tree
|
|
35
|
+
*/
|
|
36
|
+
const resolveStyleFunctions = (
|
|
37
|
+
style: StyleItem,
|
|
38
|
+
state: PressableStateCallbackType,
|
|
39
|
+
): ViewStyle | (ViewStyle | null | undefined)[] | null | undefined => {
|
|
40
|
+
if (Array.isArray(style)) {
|
|
41
|
+
return style.map((s) => resolveStyleFunctions(s, state)) as (
|
|
42
|
+
| ViewStyle
|
|
43
|
+
| null
|
|
44
|
+
| undefined
|
|
45
|
+
)[];
|
|
46
|
+
}
|
|
47
|
+
return typeof style === 'function' ? style(state) : style;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Factory function to create a styled Pressable component.
|
|
52
|
+
*
|
|
53
|
+
* Supports `style` as an object, function, or array of objects/functions (including nested).
|
|
54
|
+
*
|
|
55
|
+
* ```tsx
|
|
56
|
+
* // Create a styled Pressable
|
|
57
|
+
* const Pressable = createStyledPressable(RNPressable);
|
|
58
|
+
*
|
|
59
|
+
* // Usage with array of styles
|
|
60
|
+
* <Pressable style={[props.style, ({ pressed }) => ({ opacity: pressed ? 0.8 : 1 })]} />
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export const createStyledPressable = (Component: typeof Pressable) => {
|
|
64
|
+
const StyledComponent = memo(
|
|
65
|
+
forwardRef<PressableRef, StyledPressableProps>(
|
|
66
|
+
({ lx = {}, style, ...props }, ref) => {
|
|
67
|
+
const { theme } = useTheme();
|
|
68
|
+
const resolvedLxStyle = resolveViewStyle(theme, lx);
|
|
69
|
+
|
|
70
|
+
if (!hasStyleFunction(style)) {
|
|
71
|
+
const finalStyle = StyleSheet.flatten([
|
|
72
|
+
resolvedLxStyle,
|
|
73
|
+
style as ViewStyle,
|
|
74
|
+
]);
|
|
75
|
+
return <Component ref={ref} {...props} style={finalStyle} />;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const mergedStyle = (state: PressableStateCallbackType): ViewStyle => {
|
|
79
|
+
const resolvedStyle = resolveStyleFunctions(style, state);
|
|
80
|
+
return StyleSheet.flatten([resolvedLxStyle, resolvedStyle]);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return <Component ref={ref} {...props} style={mergedStyle} />;
|
|
84
|
+
},
|
|
85
|
+
),
|
|
86
|
+
areLxPropsEqual,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Set display name for debugging
|
|
90
|
+
const componentName =
|
|
91
|
+
(Component as { displayName?: string }).displayName ||
|
|
92
|
+
(Component as { name?: string }).name ||
|
|
93
|
+
'Component';
|
|
94
|
+
StyledComponent.displayName = `StyledPressable(${componentName})`;
|
|
95
|
+
|
|
96
|
+
return StyledComponent;
|
|
97
|
+
};
|
|
@@ -64,9 +64,9 @@ describe('createStyledText', () => {
|
|
|
64
64
|
expect(StyledText.displayName).toBe('StyledText(Text)');
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
it('should apply typography
|
|
67
|
+
it('should apply typography typography', () => {
|
|
68
68
|
renderWithProvider(
|
|
69
|
-
<StyledText testID='text'
|
|
69
|
+
<StyledText testID='text' typography='body1'>
|
|
70
70
|
Hello
|
|
71
71
|
</StyledText>,
|
|
72
72
|
);
|
|
@@ -81,25 +81,34 @@ describe('createStyledText', () => {
|
|
|
81
81
|
|
|
82
82
|
it('should apply color token', () => {
|
|
83
83
|
renderWithProvider(
|
|
84
|
-
<StyledText testID='text' color
|
|
84
|
+
<StyledText testID='text' lx={{ color: 'muted' }}>
|
|
85
85
|
Muted
|
|
86
86
|
</StyledText>,
|
|
87
87
|
);
|
|
88
|
+
|
|
88
89
|
expect(screen.getByTestId('text').props.style.color).toBe('#666666');
|
|
89
90
|
});
|
|
90
91
|
|
|
91
|
-
it('should combine
|
|
92
|
+
it('should combine typography, color and spacing', () => {
|
|
92
93
|
renderWithProvider(
|
|
93
|
-
<StyledText
|
|
94
|
+
<StyledText
|
|
95
|
+
testID='text'
|
|
96
|
+
typography='body1'
|
|
97
|
+
lx={{ color: 'base', marginTop: 's8' }}
|
|
98
|
+
>
|
|
94
99
|
Styled
|
|
95
100
|
</StyledText>,
|
|
96
101
|
);
|
|
97
102
|
|
|
98
103
|
const style = screen.getByTestId('text').props.style;
|
|
104
|
+
|
|
99
105
|
expect(style).toMatchObject({
|
|
100
|
-
fontSize: 16,
|
|
101
106
|
color: '#000000',
|
|
102
107
|
marginTop: 8,
|
|
108
|
+
fontSize: 16,
|
|
109
|
+
fontWeight: '500',
|
|
110
|
+
lineHeight: 24,
|
|
111
|
+
letterSpacing: 0,
|
|
103
112
|
});
|
|
104
113
|
});
|
|
105
114
|
|
|
@@ -107,18 +116,17 @@ describe('createStyledText', () => {
|
|
|
107
116
|
renderWithProvider(
|
|
108
117
|
<StyledText
|
|
109
118
|
testID='text'
|
|
110
|
-
|
|
119
|
+
typography='body1'
|
|
111
120
|
style={{ textDecorationLine: 'underline' }}
|
|
112
121
|
>
|
|
113
122
|
Underlined
|
|
114
123
|
</StyledText>,
|
|
115
124
|
);
|
|
116
125
|
|
|
117
|
-
const
|
|
118
|
-
screen.getByTestId('text').props.style;
|
|
126
|
+
const style = screen.getByTestId('text').props.style;
|
|
119
127
|
|
|
120
|
-
expect(
|
|
121
|
-
expect(
|
|
128
|
+
expect(style.fontSize).toBe(16);
|
|
129
|
+
expect(style.textDecorationLine).toBe('underline');
|
|
122
130
|
});
|
|
123
131
|
|
|
124
132
|
it('should forward ref', () => {
|
|
@@ -138,10 +146,10 @@ describe('createStyledText', () => {
|
|
|
138
146
|
renderCount();
|
|
139
147
|
return <Text {...props} />;
|
|
140
148
|
};
|
|
141
|
-
const StyledTracked = createStyledText(TrackedText);
|
|
149
|
+
const StyledTracked = createStyledText(TrackedText as any);
|
|
142
150
|
|
|
143
151
|
const { rerender } = renderWithProvider(
|
|
144
|
-
<StyledTracked testID='text'
|
|
152
|
+
<StyledTracked testID='text' typography='body1'>
|
|
145
153
|
Hello
|
|
146
154
|
</StyledTracked>,
|
|
147
155
|
);
|
|
@@ -151,7 +159,7 @@ describe('createStyledText', () => {
|
|
|
151
159
|
// Re-render with same props
|
|
152
160
|
rerender(
|
|
153
161
|
<LumenStyleSheetProvider themes={testThemes}>
|
|
154
|
-
<StyledTracked testID='text'
|
|
162
|
+
<StyledTracked testID='text' typography='body1'>
|
|
155
163
|
Hello
|
|
156
164
|
</StyledTracked>
|
|
157
165
|
</LumenStyleSheetProvider>,
|
|
@@ -167,10 +175,10 @@ describe('createStyledText', () => {
|
|
|
167
175
|
renderCount();
|
|
168
176
|
return <Text {...props} />;
|
|
169
177
|
};
|
|
170
|
-
const StyledTracked = createStyledText(TrackedText);
|
|
178
|
+
const StyledTracked = createStyledText(TrackedText as any);
|
|
171
179
|
|
|
172
180
|
const { rerender } = renderWithProvider(
|
|
173
|
-
<StyledTracked testID='text'
|
|
181
|
+
<StyledTracked testID='text' typography='body1'>
|
|
174
182
|
Hello
|
|
175
183
|
</StyledTracked>,
|
|
176
184
|
);
|
|
@@ -180,7 +188,7 @@ describe('createStyledText', () => {
|
|
|
180
188
|
// Re-render with different props
|
|
181
189
|
rerender(
|
|
182
190
|
<LumenStyleSheetProvider themes={testThemes}>
|
|
183
|
-
<StyledTracked testID='text' color
|
|
191
|
+
<StyledTracked testID='text' lx={{ color: 'muted' }}>
|
|
184
192
|
Hello
|
|
185
193
|
</StyledTracked>
|
|
186
194
|
</LumenStyleSheetProvider>,
|
|
@@ -196,10 +204,10 @@ describe('createStyledText', () => {
|
|
|
196
204
|
renderCount();
|
|
197
205
|
return <Text {...props} />;
|
|
198
206
|
};
|
|
199
|
-
const StyledTracked = createStyledText(TrackedText);
|
|
207
|
+
const StyledTracked = createStyledText(TrackedText as any);
|
|
200
208
|
|
|
201
209
|
const { rerender } = renderWithProvider(
|
|
202
|
-
<StyledTracked testID='text'
|
|
210
|
+
<StyledTracked testID='text' typography='body1'>
|
|
203
211
|
Hello
|
|
204
212
|
</StyledTracked>,
|
|
205
213
|
);
|
|
@@ -209,7 +217,7 @@ describe('createStyledText', () => {
|
|
|
209
217
|
// Re-render with different children
|
|
210
218
|
rerender(
|
|
211
219
|
<LumenStyleSheetProvider themes={testThemes}>
|
|
212
|
-
<StyledTracked testID='text'
|
|
220
|
+
<StyledTracked testID='text' typography='body1'>
|
|
213
221
|
World
|
|
214
222
|
</StyledTracked>
|
|
215
223
|
</LumenStyleSheetProvider>,
|
|
@@ -1,68 +1,48 @@
|
|
|
1
|
-
import React, { forwardRef, memo
|
|
1
|
+
import React, { forwardRef, memo } from 'react';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
2
3
|
import type { Text, TextProps, TextStyle } from 'react-native';
|
|
3
4
|
import { useTheme } from '../Provider/useTheme';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '../resolveStyle/resolveStyle';
|
|
8
|
-
import type { LumenTextProps } from '../types';
|
|
5
|
+
import { resolveTextStyle } from '../resolveStyle/resolveStyle';
|
|
6
|
+
import type { LumenStyleSheetTheme, LumenTextStyleLX } from '../types';
|
|
7
|
+
import { areLxPropsEqual } from './areLxPropsEqual';
|
|
9
8
|
|
|
10
9
|
type TextRef = React.ElementRef<typeof Text>;
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export type StyledTextProps = LumenTextStyleLX &
|
|
11
|
+
TextProps & {
|
|
12
|
+
/**
|
|
13
|
+
* Typography preset
|
|
14
|
+
*/
|
|
15
|
+
typography?: keyof LumenStyleSheetTheme['typographies'];
|
|
16
|
+
};
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Factory function to create a styled Text component.
|
|
19
20
|
*
|
|
20
|
-
* Creates a component that accepts token-constrained style props directly,
|
|
21
|
-
* plus a `typo` prop for typography presets, resolving them to actual
|
|
22
|
-
* values at runtime using the current theme.
|
|
23
|
-
*
|
|
24
|
-
* @param Component - The base Text-like component to wrap
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
21
|
* ```tsx
|
|
28
|
-
* import { Text } from 'react-native';
|
|
29
|
-
* import { createStyledText } from '@ledgerhq/lumen-ui-rnative/styles';
|
|
30
|
-
*
|
|
31
22
|
* // Create a basic Text
|
|
32
23
|
* const StyledText = createStyledText(Text);
|
|
33
|
-
*
|
|
34
|
-
* // Usage - token props and typo are resolved
|
|
35
|
-
* <StyledText typo='body1'>Hello World</StyledText>
|
|
36
|
-
* <StyledText typo='heading2SemiBold' marginTop='s8' color='muted'>
|
|
37
|
-
* Subtitle
|
|
38
|
-
* </StyledText>
|
|
39
|
-
*
|
|
40
|
-
* // style prop for escape hatch
|
|
41
|
-
* <StyledText typo='body1' style={{ letterSpacing: 2 }} />
|
|
42
24
|
* ```
|
|
43
25
|
*/
|
|
44
|
-
export const createStyledText = (
|
|
45
|
-
Component: React.ComponentType<LumenTextProps>,
|
|
46
|
-
): ReturnComponentType => {
|
|
26
|
+
export const createStyledText = (Component: typeof Text) => {
|
|
47
27
|
const StyledComponent = memo(
|
|
48
|
-
forwardRef<TextRef,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
28
|
+
forwardRef<TextRef, StyledTextProps>(
|
|
29
|
+
({ typography = 'body3', lx = {}, style, ...props }, ref) => {
|
|
30
|
+
const { theme } = useTheme();
|
|
31
|
+
const resolvedStyle = resolveTextStyle(theme, lx);
|
|
32
|
+
const resolvedTypographyStyles = theme.typographies[
|
|
33
|
+
typography
|
|
34
|
+
] as TextStyle;
|
|
52
35
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
36
|
+
const finalStyle = StyleSheet.flatten([
|
|
37
|
+
resolvedStyle,
|
|
38
|
+
resolvedTypographyStyles,
|
|
39
|
+
style,
|
|
40
|
+
]);
|
|
57
41
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})}
|
|
63
|
-
/>
|
|
64
|
-
);
|
|
65
|
-
}),
|
|
42
|
+
return <Component ref={ref} {...props} style={finalStyle} />;
|
|
43
|
+
},
|
|
44
|
+
),
|
|
45
|
+
areLxPropsEqual,
|
|
66
46
|
);
|
|
67
47
|
|
|
68
48
|
// Set display name for debugging
|
|
@@ -42,10 +42,12 @@ describe('createStyledView', () => {
|
|
|
42
42
|
renderWithProvider(
|
|
43
43
|
<StyledView
|
|
44
44
|
testID='view'
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
lx={{
|
|
46
|
+
padding: 's16',
|
|
47
|
+
width: 's48',
|
|
48
|
+
backgroundColor: 'surface',
|
|
49
|
+
borderRadius: 'md',
|
|
50
|
+
}}
|
|
49
51
|
/>,
|
|
50
52
|
);
|
|
51
53
|
|
|
@@ -59,20 +61,23 @@ describe('createStyledView', () => {
|
|
|
59
61
|
});
|
|
60
62
|
|
|
61
63
|
it('should resolve full size token to 100%', () => {
|
|
62
|
-
renderWithProvider(<StyledView testID='view' width
|
|
64
|
+
renderWithProvider(<StyledView testID='view' lx={{ width: 'full' }} />);
|
|
63
65
|
expect(screen.getByTestId('view').props.style.width).toBe('100%');
|
|
64
66
|
});
|
|
65
67
|
|
|
66
68
|
it('should merge style prop with resolved tokens', () => {
|
|
67
69
|
renderWithProvider(
|
|
68
|
-
<StyledView
|
|
70
|
+
<StyledView
|
|
71
|
+
testID='view'
|
|
72
|
+
lx={{ padding: 's16' }}
|
|
73
|
+
style={{ opacity: 0.5 }}
|
|
74
|
+
/>,
|
|
69
75
|
);
|
|
70
76
|
|
|
71
|
-
const
|
|
72
|
-
screen.getByTestId('view').props.style;
|
|
77
|
+
const style = screen.getByTestId('view').props.style;
|
|
73
78
|
|
|
74
|
-
expect(
|
|
75
|
-
expect(
|
|
79
|
+
expect(style.padding).toBe(16);
|
|
80
|
+
expect(style.opacity).toBe(0.5);
|
|
76
81
|
});
|
|
77
82
|
|
|
78
83
|
it('should forward ref', () => {
|
|
@@ -88,10 +93,10 @@ describe('createStyledView', () => {
|
|
|
88
93
|
renderCount();
|
|
89
94
|
return <View {...props} />;
|
|
90
95
|
};
|
|
91
|
-
const StyledTracked = createStyledView(TrackedView);
|
|
96
|
+
const StyledTracked = createStyledView(TrackedView as any);
|
|
92
97
|
|
|
93
98
|
const { rerender } = renderWithProvider(
|
|
94
|
-
<StyledTracked testID='view' padding
|
|
99
|
+
<StyledTracked testID='view' lx={{ padding: 's16' }} />,
|
|
95
100
|
);
|
|
96
101
|
|
|
97
102
|
expect(renderCount).toHaveBeenCalledTimes(1);
|
|
@@ -99,7 +104,7 @@ describe('createStyledView', () => {
|
|
|
99
104
|
// Re-render with same props
|
|
100
105
|
rerender(
|
|
101
106
|
<LumenStyleSheetProvider themes={testThemes}>
|
|
102
|
-
<StyledTracked testID='view' padding
|
|
107
|
+
<StyledTracked testID='view' lx={{ padding: 's16' }} />
|
|
103
108
|
</LumenStyleSheetProvider>,
|
|
104
109
|
);
|
|
105
110
|
|
|
@@ -113,10 +118,11 @@ describe('createStyledView', () => {
|
|
|
113
118
|
renderCount();
|
|
114
119
|
return <View {...props} />;
|
|
115
120
|
};
|
|
116
|
-
|
|
121
|
+
|
|
122
|
+
const StyledTracked = createStyledView(TrackedView as any);
|
|
117
123
|
|
|
118
124
|
const { rerender } = renderWithProvider(
|
|
119
|
-
<StyledTracked testID='view' padding
|
|
125
|
+
<StyledTracked testID='view' lx={{ padding: 's16' }} />,
|
|
120
126
|
);
|
|
121
127
|
|
|
122
128
|
expect(renderCount).toHaveBeenCalledTimes(1);
|
|
@@ -124,7 +130,7 @@ describe('createStyledView', () => {
|
|
|
124
130
|
// Re-render with different props
|
|
125
131
|
rerender(
|
|
126
132
|
<LumenStyleSheetProvider themes={testThemes}>
|
|
127
|
-
<StyledTracked testID='view' width
|
|
133
|
+
<StyledTracked testID='view' lx={{ width: 's48' }} />
|
|
128
134
|
</LumenStyleSheetProvider>,
|
|
129
135
|
);
|
|
130
136
|
|