@cdek-it/react-native-ui-kit 0.6.9 → 1.0.0-beta.1

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.
Files changed (130) hide show
  1. package/README.md +9 -0
  2. package/dist/components/Accordion/Accordion.js +9 -10
  3. package/dist/components/Avatar/Avatar.js +7 -9
  4. package/dist/components/Badge/Badge.js +28 -20
  5. package/dist/components/Button/BaseButton.d.ts +3 -3
  6. package/dist/components/Button/BaseButton.js +12 -41
  7. package/dist/components/Button/Button.js +6 -4
  8. package/dist/components/Button/ButtonBadge.js +13 -12
  9. package/dist/components/Button/ButtonSeverity.js +6 -4
  10. package/dist/components/Button/index.d.ts +1 -1
  11. package/dist/components/Button/types.d.ts +2 -25
  12. package/dist/components/Button/utils/ButtonActivityIndicator.d.ts +3 -3
  13. package/dist/components/Button/utils/ButtonActivityIndicator.js +16 -12
  14. package/dist/components/Button/utils/ButtonContainer.d.ts +15 -6
  15. package/dist/components/Button/utils/ButtonContainer.js +424 -4
  16. package/dist/components/Button/utils/ButtonIcon.d.ts +8 -4
  17. package/dist/components/Button/utils/ButtonIcon.js +147 -4
  18. package/dist/components/Button/utils/ButtonLabel.d.ts +9 -4
  19. package/dist/components/Button/utils/ButtonLabel.js +139 -4
  20. package/dist/components/Button/utils/ButtonLeftArea.d.ts +9 -4
  21. package/dist/components/Button/utils/ButtonLeftArea.js +3 -3
  22. package/dist/components/Button/utils/ButtonPressedContext.d.ts +1 -0
  23. package/dist/components/Button/utils/ButtonPressedContext.js +2 -0
  24. package/dist/components/Button/utils/ButtonRightArea.d.ts +9 -3
  25. package/dist/components/Button/utils/ButtonRightArea.js +3 -3
  26. package/dist/components/Button/utils/ButtonVariantContext.d.ts +6 -0
  27. package/dist/components/Button/utils/ButtonVariantContext.js +4 -0
  28. package/dist/components/Checkbox/Checkbox.d.ts +6 -7
  29. package/dist/components/Checkbox/Checkbox.js +74 -22
  30. package/dist/components/Chip/Chip.js +13 -7
  31. package/dist/components/Dialog/DialogComponent.js +2 -3
  32. package/dist/components/Dialog/DialogHeader.js +17 -13
  33. package/dist/components/Divider/Divider.js +6 -6
  34. package/dist/components/Input/InputGroup.js +6 -13
  35. package/dist/components/Input/InputGroupAddon.js +5 -5
  36. package/dist/components/Input/InputOtp/InputOtp.js +2 -3
  37. package/dist/components/Input/InputOtp/InputOtpItem.js +2 -3
  38. package/dist/components/Input/InputSwitch/InputSwitch.js +2 -2
  39. package/dist/components/Input/InputSwitch/styles/useHandleStyles.js +13 -11
  40. package/dist/components/Input/InputSwitch/styles/useSliderStyles.d.ts +6 -5
  41. package/dist/components/Input/InputSwitch/styles/useSliderStyles.js +36 -29
  42. package/dist/components/Input/InputTextBase/InputTextBase.d.ts +0 -5
  43. package/dist/components/Input/InputTextBase/InputTextBase.js +41 -26
  44. package/dist/components/Input/InputTextBase/useInputStyles.d.ts +6 -5
  45. package/dist/components/Input/InputTextBase/useInputStyles.js +6 -9
  46. package/dist/components/Input/index.d.ts +0 -1
  47. package/dist/components/Input/index.js +0 -1
  48. package/dist/components/List/Base/ListBase.js +9 -12
  49. package/dist/components/MenuItem/MenuItemAccessory.js +5 -5
  50. package/dist/components/MenuItem/MenuItemIcon.js +4 -5
  51. package/dist/components/MenuItem/Template/MenuItemTemplate.js +8 -5
  52. package/dist/components/Message/Message.js +54 -38
  53. package/dist/components/ProgressBar/ProgressBar.js +2 -3
  54. package/dist/components/ProgressSpinner/ProgressSpinner.js +3 -4
  55. package/dist/components/RadioButton/RadioButton.js +87 -104
  56. package/dist/components/Rating/Rating.js +2 -3
  57. package/dist/components/Rating/RatingClear.js +10 -11
  58. package/dist/components/Rating/RatingItem.js +23 -24
  59. package/dist/components/Rating/RatingItemContainer.js +2 -3
  60. package/dist/components/SelectButton/SelectButton.js +2 -3
  61. package/dist/components/SelectButton/SelectButtonItem.js +22 -49
  62. package/dist/components/Skeleton/Skeleton.js +2 -3
  63. package/dist/components/Slider/Slider.js +4 -6
  64. package/dist/components/Tabs/TabItem/TabItem.js +12 -21
  65. package/dist/components/Tabs/Tabs.js +2 -3
  66. package/dist/components/Tag/Tag.js +44 -29
  67. package/dist/components/Timer/Timer.js +2 -3
  68. package/dist/components/Timer/TimerFlip.js +2 -3
  69. package/dist/components/ToggleButton/ToggleButton.js +159 -35
  70. package/dist/components/Typography/Anchor.js +11 -7
  71. package/dist/components/Typography/Body.js +2 -3
  72. package/dist/components/Typography/Caption.js +9 -4
  73. package/dist/components/Typography/Service.js +13 -7
  74. package/dist/components/Typography/Subtitle.js +3 -6
  75. package/dist/components/Typography/Title.js +3 -6
  76. package/dist/hooks/useChangeTheme.d.ts +2 -1
  77. package/dist/hooks/useChangeTheme.js +10 -3
  78. package/dist/hooks/useFonts.d.ts +2 -1
  79. package/dist/hooks/useFonts.js +3 -3
  80. package/dist/hooks/useLoadingRotationAnimation.d.ts +2 -2
  81. package/dist/hooks/useTheme.d.ts +2 -1
  82. package/dist/hooks/useTheme.js +6 -4
  83. package/dist/index.d.ts +3 -2
  84. package/dist/index.js +2 -1
  85. package/dist/theme/ThemeContext.d.ts +9 -7
  86. package/dist/theme/ThemeContext.js +21 -14
  87. package/dist/theme/darkTheme.js +1 -0
  88. package/dist/theme/index.d.ts +1 -1
  89. package/dist/theme/index.js +1 -1
  90. package/dist/theme/lightTheme.js +1 -0
  91. package/dist/theme/types.d.ts +1 -0
  92. package/dist/utils/SvgUniversal.d.ts +9 -14
  93. package/dist/utils/SvgUniversal.js +10 -2
  94. package/dist/utils/index.d.ts +1 -0
  95. package/dist/utils/index.js +1 -0
  96. package/package.json +45 -34
  97. package/dist/components/Button/styles/index.d.ts +0 -2
  98. package/dist/components/Button/styles/index.js +0 -2
  99. package/dist/components/Button/styles/useBasicButtonStyles.d.ts +0 -98
  100. package/dist/components/Button/styles/useBasicButtonStyles.js +0 -81
  101. package/dist/components/Button/styles/useDangerButtonStyles.d.ts +0 -63
  102. package/dist/components/Button/styles/useDangerButtonStyles.js +0 -57
  103. package/dist/components/Button/styles/useInfoButtonStyles.d.ts +0 -63
  104. package/dist/components/Button/styles/useInfoButtonStyles.js +0 -56
  105. package/dist/components/Button/styles/useSeverityButtonStyles.d.ts +0 -64
  106. package/dist/components/Button/styles/useSeverityButtonStyles.js +0 -29
  107. package/dist/components/Button/styles/useSuccessButtonStyles.d.ts +0 -63
  108. package/dist/components/Button/styles/useSuccessButtonStyles.js +0 -61
  109. package/dist/components/Button/styles/useWarningButtonStyles.d.ts +0 -63
  110. package/dist/components/Button/styles/useWarningButtonStyles.js +0 -61
  111. package/dist/components/Button/utils/useButtonContainerCallbackStyle.d.ts +0 -3
  112. package/dist/components/Button/utils/useButtonContainerCallbackStyle.js +0 -141
  113. package/dist/components/Button/utils/useButtonLabelStyle.d.ts +0 -3
  114. package/dist/components/Button/utils/useButtonLabelStyle.js +0 -40
  115. package/dist/components/Button/utils/useIconStyle.d.ts +0 -7
  116. package/dist/components/Button/utils/useIconStyle.js +0 -35
  117. package/dist/components/Button/utils/useTypeBasedStyle.d.ts +0 -2
  118. package/dist/components/Button/utils/useTypeBasedStyle.js +0 -4
  119. package/dist/components/Checkbox/hooks/usePressableStyles.d.ts +0 -15
  120. package/dist/components/Checkbox/hooks/usePressableStyles.js +0 -91
  121. package/dist/components/Input/FloatLabel.d.ts +0 -22
  122. package/dist/components/Input/FloatLabel.js +0 -19
  123. package/dist/components/ToggleButton/hooks/useIconSize.d.ts +0 -14
  124. package/dist/components/ToggleButton/hooks/useIconSize.js +0 -26
  125. package/dist/components/ToggleButton/hooks/useLabelSize.d.ts +0 -8
  126. package/dist/components/ToggleButton/hooks/useLabelSize.js +0 -19
  127. package/dist/components/ToggleButton/hooks/useStateStyles.d.ts +0 -11
  128. package/dist/components/ToggleButton/hooks/useStateStyles.js +0 -92
  129. package/dist/utils/makeStyles.d.ts +0 -11
  130. package/dist/utils/makeStyles.js +0 -19
package/README.md CHANGED
@@ -51,6 +51,15 @@ UI kit использует следующие виды шрифтов.
51
51
  />
52
52
  ```
53
53
 
54
+ После этого шрифты доступны через `useUnistyles().theme.fonts` или прямо в
55
+ `StyleSheet.create(({ fonts }) => ...)`.
56
+
57
+ `ThemeContextProvider` только настраивает темы и шрифты для `unistyles`.
58
+ `ThemeContext` остается пустым и всегда имеет значение `null`.
59
+
60
+ Провайдер также принимает `lightTheme` и `darkTheme`, если нужно переопределить
61
+ темы целиком.
62
+
54
63
  ### Пример подключения шрифтов с помощью expo-fonts через плагин
55
64
 
56
65
  ```ts
@@ -2,8 +2,8 @@ import { IconChevronRight } from '@tabler/icons-react-native';
2
2
  import React, { useCallback, useState } from 'react';
3
3
  import { View, Text, Pressable } from 'react-native';
4
4
  import Animated, { interpolate, useAnimatedStyle, useSharedValue, withTiming, } from 'react-native-reanimated';
5
+ import { StyleSheet } from 'react-native-unistyles';
5
6
  import { SvgUniversal } from '../../utils/SvgUniversal';
6
- import { makeStyles } from '../../utils/makeStyles';
7
7
  /**
8
8
  * Компонент Гармошка - умеет скрывать и раскрывать контент по нажатию на заголовок
9
9
  * @param title - Текст заголовка
@@ -15,7 +15,6 @@ import { makeStyles } from '../../utils/makeStyles';
15
15
  * @link https://www.figma.com/design/4TYeki0MDLhfPGJstbIicf/UI-kit-PrimeFace--DS-?node-id=1207-1852&m=dev
16
16
  */
17
17
  export const Accordion = ({ Icon, title, isInitiallyExpanded: initiallyExpanded = false, withSeparator = false, disabled = false, titleExtra, testID, children, ...rest }) => {
18
- const styles = useStyles();
19
18
  const contentHeight = useSharedValue(0);
20
19
  const contentOpenFraction = useSharedValue(initiallyExpanded ? 1 : 0);
21
20
  const [isExpanded, setIsExpanded] = useState(initiallyExpanded);
@@ -40,9 +39,13 @@ export const Accordion = ({ Icon, title, isInitiallyExpanded: initiallyExpanded
40
39
  return (<View style={[styles.component, withSeparator ? styles.separator : {}]} testID={testID || AccordionTestIds.component} {...rest}>
41
40
  <Pressable accessible accessibilityLabel={title} accessibilityRole='button' accessibilityState={isExpanded ? { expanded: true } : {}} disabled={disabled} style={[styles.header, disabled ? styles.disabled : {}]} testID={AccordionTestIds.header} onPress={toggle}>
42
41
  <Animated.View style={arrowAnimatedStyle} testID={AccordionTestIds.arrow}>
43
- <IconChevronRight {...styles.icon}/>
42
+ <SvgUniversal {...styles.icon} source={IconChevronRight} uniProps={({ theme }) => ({
43
+ color: theme.Panel.Accordion.accordionHeaderTextColor,
44
+ })}/>
44
45
  </Animated.View>
45
- {Icon ? (<SvgUniversal source={Icon} {...styles.icon} testID={AccordionTestIds.icon}/>) : null}
46
+ {Icon ? (<SvgUniversal {...styles.icon} source={Icon} testID={AccordionTestIds.icon} uniProps={({ theme }) => ({
47
+ color: theme.Panel.Accordion.accordionHeaderTextColor,
48
+ })}/>) : null}
46
49
  <Text style={styles.title}>{title}</Text>
47
50
  {titleExtra ? (<View testID={AccordionTestIds.titleExtra}>{titleExtra}</View>) : null}
48
51
  </Pressable>
@@ -64,7 +67,7 @@ export const AccordionTestIds = {
64
67
  contentWrapper: 'ContentWrapper',
65
68
  separator: 'Separator',
66
69
  };
67
- const useStyles = makeStyles(({ theme, fonts }) => ({
70
+ const styles = StyleSheet.create(({ theme, fonts }) => ({
68
71
  component: { width: '100%' },
69
72
  header: {
70
73
  paddingVertical: theme.Panel.Accordion.accordionHeaderPaddingTopBottom,
@@ -73,11 +76,7 @@ const useStyles = makeStyles(({ theme, fonts }) => ({
73
76
  alignItems: 'center',
74
77
  backgroundColor: theme.Panel.Accordion.accordionHeaderBg,
75
78
  },
76
- icon: {
77
- width: 17.5,
78
- height: 17.5,
79
- color: theme.Panel.Accordion.accordionHeaderTextColor,
80
- },
79
+ icon: { width: 17.5, height: 17.5 },
81
80
  title: {
82
81
  fontSize: 15.75,
83
82
  includeFontPadding: false,
@@ -1,7 +1,7 @@
1
1
  import { memo, useCallback, useEffect, useMemo, useState, } from 'react';
2
2
  import { Image, Text, useWindowDimensions, View, } from 'react-native';
3
+ import { StyleSheet } from 'react-native-unistyles';
3
4
  import { SvgUniversal } from '../../utils/SvgUniversal';
4
- import { makeStyles } from '../../utils/makeStyles';
5
5
  const SizeMap = {
6
6
  normal: 28,
7
7
  large: 35,
@@ -22,7 +22,6 @@ const ICON_MULTIPLIER = 0.43;
22
22
  * @link https://www.figma.com/design/4TYeki0MDLhfPGJstbIicf/UI-kit-PrimeFace-(DS)?node-id=484-4972&m=dev
23
23
  */
24
24
  export const Avatar = memo(({ type, size = 'normal', shape = 'circle', style, children, source, Icon, badge, showBadge = true, testID, onError, iconColor, }) => {
25
- const styles = useStyles();
26
25
  const window = useWindowDimensions();
27
26
  const [badgeLayout, setBadgeLayout] = useState();
28
27
  const calculatedSize = useMemo(() => {
@@ -51,8 +50,10 @@ export const Avatar = memo(({ type, size = 'normal', shape = 'circle', style, ch
51
50
  else if (size === 'xlarge') {
52
51
  iconSize = styles.iconXLarge.width;
53
52
  }
54
- return (<SvgUniversal color={iconColor || styles.icon.color} height={iconSize} source={Icon} testID={AvatarTestId.icon} width={iconSize}/>);
55
- }, [Icon, calculatedSize, iconColor, size, styles, type]);
53
+ return (<SvgUniversal height={iconSize} source={Icon} testID={AvatarTestId.icon} uniProps={({ theme }) => ({
54
+ color: iconColor ?? theme.Misc.Avatar.avatarTextColor,
55
+ })} width={iconSize}/>);
56
+ }, [Icon, calculatedSize, iconColor, size, type]);
56
57
  useEffect(() => {
57
58
  if (badge) {
58
59
  setBadgeLayout(undefined);
@@ -82,7 +83,7 @@ export const Avatar = memo(({ type, size = 'normal', shape = 'circle', style, ch
82
83
  </View>) : null}
83
84
  </View>);
84
85
  });
85
- const useStyles = makeStyles(({ theme, border, typography, fonts }) => ({
86
+ const styles = StyleSheet.create(({ theme, border, typography, fonts }) => ({
86
87
  container: {
87
88
  justifyContent: 'center',
88
89
  alignItems: 'center',
@@ -104,10 +105,7 @@ const useStyles = makeStyles(({ theme, border, typography, fonts }) => ({
104
105
  },
105
106
  badgeContainer: { position: 'absolute', right: 0, top: -7 },
106
107
  badgeMeasureContainer: { alignSelf: 'flex-start' },
107
- icon: {
108
- width: typography.Size['text-base'],
109
- color: theme.Misc.Avatar.avatarTextColor,
110
- },
108
+ icon: { width: typography.Size['text-base'] },
111
109
  iconXLarge: { width: typography.Size['text-2xl'] },
112
110
  }));
113
111
  export const AvatarTestId = {
@@ -1,6 +1,6 @@
1
1
  import { memo, useCallback, useState } from 'react';
2
2
  import { Dimensions, Text, View, } from 'react-native';
3
- import { makeStyles } from '../../utils/makeStyles';
3
+ import { StyleSheet } from 'react-native-unistyles';
4
4
  /**
5
5
  * Компонент Badge
6
6
  * @param children - Текст внутри бейджа
@@ -10,23 +10,23 @@ import { makeStyles } from '../../utils/makeStyles';
10
10
  * @link https://www.figma.com/design/4TYeki0MDLhfPGJstbIicf/UI-kit-PrimeFace-(DS)?node-id=484-4871&m=dev
11
11
  */
12
12
  export const Badge = memo(({ children, dot, severity = 'basic', style, testID, ...rest }) => {
13
- const styles = useStyles();
13
+ badgeStyles.useVariants({ severity });
14
14
  const [textLayout, setTextLayout] = useState();
15
15
  const onTextLayout = useCallback((e) => {
16
16
  setTextLayout(e.nativeEvent.layout);
17
17
  }, []);
18
- return (<View style={[styles.container, style]} {...rest}>
19
- {dot ? (<View style={[styles.dot, styles[severity]]} testID={testID}/>) : (<>
20
- <View style={[styles.textBadgeContainer, styles[severity]]} testID={testID}>
21
- <Text numberOfLines={1} style={[styles.textBadge, { minWidth: textLayout?.width }]}>
18
+ return (<View style={[badgeStyles.container, style]} {...rest}>
19
+ {dot ? (<View style={[badgeStyles.dot, badgeStyles.dotShape]} testID={testID}/>) : (<>
20
+ <View style={[badgeStyles.dot, badgeStyles.textBadgeContainer]} testID={testID}>
21
+ <Text numberOfLines={1} style={[badgeStyles.textBadge, { minWidth: textLayout?.width }]}>
22
22
  {children}
23
23
  </Text>
24
24
  </View>
25
25
 
26
26
  {/* скрытый элемент для подсчета ширины текста в 1 строку */}
27
- <View accessibilityElementsHidden importantForAccessibility='no-hide-descendants' style={styles.hiddenContainer}>
27
+ <View accessibilityElementsHidden importantForAccessibility='no-hide-descendants' style={badgeStyles.hiddenContainer}>
28
28
  <View collapsable={false}>
29
- <Text numberOfLines={1} style={styles.textBadge} onLayout={onTextLayout}>
29
+ <Text numberOfLines={1} style={badgeStyles.textBadge} onLayout={onTextLayout}>
30
30
  {children}
31
31
  </Text>
32
32
  </View>
@@ -34,9 +34,28 @@ export const Badge = memo(({ children, dot, severity = 'basic', style, testID, .
34
34
  </>)}
35
35
  </View>);
36
36
  });
37
- const useStyles = makeStyles(({ theme, border, typography, fonts }) => ({
37
+ const badgeStyles = StyleSheet.create(({ theme, border, typography, fonts }) => ({
38
38
  container: { alignItems: 'flex-start' },
39
39
  dot: {
40
+ variants: {
41
+ severity: {
42
+ basic: { backgroundColor: theme.Misc.Badge.badgeBg },
43
+ info: {
44
+ backgroundColor: theme.Button.Severity.Info.Basic.infoButtonBg,
45
+ },
46
+ success: {
47
+ backgroundColor: theme.Button.Severity.Success.Basic.successButtonBg,
48
+ },
49
+ warning: {
50
+ backgroundColor: theme.Button.Severity.Warning.Basic.warningButtonBg,
51
+ },
52
+ danger: {
53
+ backgroundColor: theme.Button.Severity.Danger.Basic.dangerButtonBg,
54
+ },
55
+ },
56
+ },
57
+ },
58
+ dotShape: {
40
59
  width: theme.Misc.Badge.badgeDotSize,
41
60
  height: theme.Misc.Badge.badgeDotSize,
42
61
  borderRadius: border.Radius['rounded-full'],
@@ -54,17 +73,6 @@ const useStyles = makeStyles(({ theme, border, typography, fonts }) => ({
54
73
  verticalAlign: 'middle',
55
74
  fontFamily: fonts.primary,
56
75
  },
57
- basic: { backgroundColor: theme.Misc.Badge.badgeBg },
58
- info: { backgroundColor: theme.Button.Severity.Info.Basic.infoButtonBg },
59
- success: {
60
- backgroundColor: theme.Button.Severity.Success.Basic.successButtonBg,
61
- },
62
- warning: {
63
- backgroundColor: theme.Button.Severity.Warning.Basic.warningButtonBg,
64
- },
65
- danger: {
66
- backgroundColor: theme.Button.Severity.Danger.Basic.dangerButtonBg,
67
- },
68
76
  hiddenContainer: {
69
77
  width: Dimensions.get('window').width,
70
78
  height: 0,
@@ -1,5 +1,5 @@
1
- import type { ButtonProps, ButtonVariant, VariantStyles } from './types';
1
+ import type { ButtonProps, ButtonVariant } from './types';
2
2
  export type BaseButtonComponentProps<Variant extends ButtonVariant> = Omit<ButtonProps<Variant>, 'variant'> & {
3
3
  readonly variant: Variant;
4
- } & VariantStyles<Variant>;
5
- export declare const BaseButton: <Variant extends ButtonVariant>({ size, shape, loading, variant, disabled, iconOnly, iconPosition, Icon, label, style, containerVariantStyles, labelVariantStyles, pressedVariantStyles, iconVariantStyles, pressedLabelVariantStyles, onPressIn: onPressInProp, onPressOut: onPressOutProp, ...props }: BaseButtonComponentProps<Variant>) => import("react").JSX.Element;
4
+ };
5
+ export declare const BaseButton: <Variant extends ButtonVariant>({ size, shape, loading, variant, disabled, iconOnly, iconPosition, Icon, label, style, onPressIn: onPressInProp, onPressOut: onPressOutProp, ...props }: BaseButtonComponentProps<Variant>) => import("react").JSX.Element;
@@ -1,7 +1,9 @@
1
1
  import { useCallback, useState } from 'react';
2
2
  import { genericMemo } from '../../utils/genericMemo';
3
3
  import { ButtonLeftArea, ButtonRightArea, ButtonLabel, ButtonContainer, } from './utils';
4
- const BaseButtonComponent = ({ size = 'base', shape = 'square', loading = false, variant, disabled = false, iconOnly, iconPosition = 'prefix', Icon, label, style, containerVariantStyles, labelVariantStyles, pressedVariantStyles, iconVariantStyles, pressedLabelVariantStyles, onPressIn: onPressInProp, onPressOut: onPressOutProp, ...props }) => {
4
+ import { ButtonPressedContext } from './utils/ButtonPressedContext';
5
+ const BaseButtonComponent = ({ size = 'base', shape = 'square', loading = false, variant, disabled = false, iconOnly, iconPosition = 'prefix', Icon, label, style, onPressIn: onPressInProp, onPressOut: onPressOutProp, ...props }) => {
6
+ const isDisabled = !!disabled;
5
7
  const [pressed, setPressed] = useState(false);
6
8
  const onPressIn = useCallback((event) => {
7
9
  onPressInProp?.(event);
@@ -11,52 +13,21 @@ const BaseButtonComponent = ({ size = 'base', shape = 'square', loading = false,
11
13
  onPressOutProp?.(event);
12
14
  setPressed(false);
13
15
  }, [onPressOutProp]);
14
- return (<ButtonContainer {...{
16
+ return (<ButtonPressedContext.Provider value={pressed}>
17
+ <ButtonContainer {...{
15
18
  size,
16
- variant,
17
19
  shape,
18
- disabled,
20
+ disabled: isDisabled,
19
21
  loading,
20
- iconOnly,
22
+ isIconOnly: !!iconOnly,
21
23
  style,
22
- containerVariantStyles,
23
- pressedVariantStyles,
24
24
  onPressIn,
25
25
  onPressOut,
26
26
  }} {...props}>
27
- <ButtonLeftArea {...{
28
- size,
29
- variant,
30
- loading,
31
- disabled,
32
- Icon,
33
- iconPosition,
34
- iconVariantStyles: pressed
35
- ? pressedLabelVariantStyles
36
- : iconVariantStyles,
37
- }}/>
38
- <ButtonLabel {...{
39
- size,
40
- variant,
41
- loading,
42
- disabled,
43
- iconOnly,
44
- label,
45
- labelVariantStyles: pressed
46
- ? pressedLabelVariantStyles
47
- : labelVariantStyles,
48
- }}/>
49
- <ButtonRightArea {...{
50
- size,
51
- variant,
52
- loading,
53
- disabled,
54
- Icon,
55
- iconPosition,
56
- iconVariantStyles: pressed
57
- ? pressedLabelVariantStyles
58
- : iconVariantStyles,
59
- }}/>
60
- </ButtonContainer>);
27
+ <ButtonLeftArea {...{ size, loading, disabled: isDisabled, Icon, iconPosition }}/>
28
+ <ButtonLabel {...{ size, loading, disabled: isDisabled, iconOnly, label }}/>
29
+ <ButtonRightArea {...{ size, loading, disabled: isDisabled, Icon, iconPosition }}/>
30
+ </ButtonContainer>
31
+ </ButtonPressedContext.Provider>);
61
32
  };
62
33
  export const BaseButton = genericMemo(BaseButtonComponent);
@@ -1,6 +1,6 @@
1
- import { memo } from 'react';
1
+ import { memo, useMemo } from 'react';
2
2
  import { BaseButton } from './BaseButton';
3
- import { useBasicButtonStyles } from './styles';
3
+ import { ButtonVariantContext } from './utils/ButtonVariantContext';
4
4
  /**
5
5
  * Button component
6
6
  * @param size - button size
@@ -16,6 +16,8 @@ import { useBasicButtonStyles } from './styles';
16
16
  * @see BaseButton
17
17
  */
18
18
  export const Button = memo(({ variant = 'primary', ...props }) => {
19
- const buttonStyles = useBasicButtonStyles();
20
- return <BaseButton variant={variant} {...props} {...buttonStyles}/>;
19
+ const variantContextValue = useMemo(() => ({ variant }), [variant]);
20
+ return (<ButtonVariantContext.Provider value={variantContextValue}>
21
+ <BaseButton variant={variant} {...props}/>
22
+ </ButtonVariantContext.Provider>);
21
23
  });
@@ -1,9 +1,9 @@
1
1
  import { memo, useCallback, useMemo, useState } from 'react';
2
2
  import { View, } from 'react-native';
3
- import { makeStyles } from '../../utils/makeStyles';
3
+ import { StyleSheet } from 'react-native-unistyles';
4
4
  import { Badge } from '../Badge';
5
5
  import { BaseButton } from './BaseButton';
6
- import { useBasicButtonStyles } from './styles';
6
+ import { ButtonVariantContext } from './utils/ButtonVariantContext';
7
7
  /**
8
8
  * Button component with badge
9
9
  * @param size - button size
@@ -21,9 +21,8 @@ import { useBasicButtonStyles } from './styles';
21
21
  * @see BaseButton
22
22
  */
23
23
  export const ButtonBadge = memo(({ badgeLabel, badgeSeverity, variant = 'primary', ...props }) => {
24
- const buttonStyles = useBasicButtonStyles();
25
- const styles = useStyles();
26
24
  const [badgeLayout, setBadgeLayout] = useState();
25
+ const variantContextValue = useMemo(() => ({ variant }), [variant]);
27
26
  const badgeContainerStyle = useMemo(() => ({
28
27
  position: 'absolute',
29
28
  top: badgeLayout ? -Math.round(badgeLayout.height / 2) : 0,
@@ -31,20 +30,22 @@ export const ButtonBadge = memo(({ badgeLabel, badgeSeverity, variant = 'primary
31
30
  }), [badgeLayout]);
32
31
  const onLayout = useCallback((e) => setBadgeLayout(e.nativeEvent.layout), []);
33
32
  const badgeCommonProps = useMemo(() => ({ severity: badgeSeverity, testID: ButtonBadgeTestId.badge }), [badgeSeverity]);
34
- return (<View style={styles.root}>
35
- <View style={[
33
+ return (<ButtonVariantContext.Provider value={variantContextValue}>
34
+ <View style={styles.root}>
35
+ <View style={[
36
36
  styles.contentContainer,
37
37
  props.iconOnly && styles.iconOnlyContainer,
38
38
  ]}>
39
- <BaseButton variant={variant} {...props} {...buttonStyles}/>
39
+ <BaseButton variant={variant} {...props}/>
40
40
 
41
- {badgeLabel ? (<Badge {...badgeCommonProps} style={badgeContainerStyle} onLayout={onLayout}>
42
- {badgeLabel}
43
- </Badge>) : (<Badge {...badgeCommonProps} dot style={styles.badgeDot}/>)}
41
+ {badgeLabel ? (<Badge {...badgeCommonProps} style={badgeContainerStyle} onLayout={onLayout}>
42
+ {badgeLabel}
43
+ </Badge>) : (<Badge {...badgeCommonProps} dot style={styles.badgeDot}/>)}
44
+ </View>
44
45
  </View>
45
- </View>);
46
+ </ButtonVariantContext.Provider>);
46
47
  });
47
- const useStyles = makeStyles(() => ({
48
+ const styles = StyleSheet.create(() => ({
48
49
  root: { flexDirection: 'row' },
49
50
  contentContainer: { flex: 1 },
50
51
  iconOnlyContainer: { flex: 0 },
@@ -1,6 +1,6 @@
1
- import { memo } from 'react';
1
+ import { memo, useMemo } from 'react';
2
2
  import { BaseButton } from './BaseButton';
3
- import { useSeverityButtonStyles } from './styles';
3
+ import { ButtonVariantContext } from './utils/ButtonVariantContext';
4
4
  /**
5
5
  * Button component
6
6
  * @param size - button size
@@ -17,6 +17,8 @@ import { useSeverityButtonStyles } from './styles';
17
17
  * @see BaseButton
18
18
  */
19
19
  export const ButtonSeverity = memo(({ severity, variant = 'basic', ...props }) => {
20
- const buttonStyles = useSeverityButtonStyles(severity);
21
- return <BaseButton variant={variant} {...props} {...buttonStyles}/>;
20
+ const variantContextValue = useMemo(() => ({ variant, severity }), [severity, variant]);
21
+ return (<ButtonVariantContext.Provider value={variantContextValue}>
22
+ <BaseButton variant={variant} {...props}/>
23
+ </ButtonVariantContext.Provider>);
22
24
  });
@@ -1,4 +1,4 @@
1
1
  export { Button } from './Button';
2
2
  export { ButtonBadge } from './ButtonBadge';
3
3
  export { ButtonSeverity } from './ButtonSeverity';
4
- export type { ButtonProps, ButtonBadgeProps, ButtonSeverityProps, VariantStyles, } from './types';
4
+ export type { ButtonProps, ButtonBadgeProps, ButtonSeverityProps, } from './types';
@@ -1,5 +1,5 @@
1
1
  import type { Ref } from 'react';
2
- import type { ColorValue, PressableProps, TextStyle, View, ViewStyle } from 'react-native';
2
+ import type { PressableProps, View } from 'react-native';
3
3
  import type { SvgSource } from '../../utils/SvgUniversal';
4
4
  import type { BadgeSeverity } from '../Badge/Badge';
5
5
  export type ButtonBaseVariant = 'primary' | 'secondary' | 'tertiary' | 'text' | 'link';
@@ -7,11 +7,7 @@ export type ButtonSeverityVariant = 'basic' | 'outlined' | 'text';
7
7
  export type ButtonVariant = ButtonBaseVariant | ButtonSeverityVariant;
8
8
  export type ButtonSize = 'xlarge' | 'large' | 'base' | 'small';
9
9
  export type ButtonShape = 'square' | 'circle';
10
- export type ButtonIconPosition =
11
- /** @deprecated */
12
- 'left'
13
- /** @deprecated */
14
- | 'right' | 'prefix' | 'postfix';
10
+ export type ButtonIconPosition = 'prefix' | 'postfix';
15
11
  export interface BaseButtonProps<Variant extends ButtonVariant> extends PressableProps {
16
12
  /**
17
13
  * Controls button size
@@ -34,9 +30,6 @@ export interface BaseButtonProps<Variant extends ButtonVariant> extends Pressabl
34
30
  variant?: Variant;
35
31
  /**
36
32
  * Icon position
37
- *
38
- * Важно: значения left и right - deprecated!!! Используйте prefix и postfix
39
- *
40
33
  * @default 'prefix'
41
34
  */
42
35
  iconPosition?: ButtonIconPosition;
@@ -69,22 +62,6 @@ export interface IconOnlyButtonProps<Variant extends ButtonVariant> extends Base
69
62
  label?: never;
70
63
  }
71
64
  export type ButtonProps<Variant extends ButtonVariant> = IconTextButton<Variant> | IconOnlyButtonProps<Variant>;
72
- export type LabelVariantStyles<Variant extends ButtonVariant> = Record<Required<BaseButtonProps<Variant>>['variant'], TextStyle>;
73
- export type PressedVariantStyles<Variant extends ButtonVariant> = Record<Required<BaseButtonProps<Variant>>['variant'], ViewStyle>;
74
- export type ContainerVariantStyles<Variant extends ButtonVariant> = Record<Required<BaseButtonProps<Variant>>['variant'], ViewStyle>;
75
- export type IconVariantStyles<Variant extends ButtonVariant> = Record<Required<BaseButtonProps<Variant>>['variant'], {
76
- color: ColorValue;
77
- }>;
78
- export type PressedLabelVariantStyles<Variant extends ButtonVariant> = Record<Required<BaseButtonProps<Variant>>['variant'], {
79
- color: ColorValue;
80
- }>;
81
- export interface VariantStyles<Variant extends ButtonVariant> {
82
- containerVariantStyles: ContainerVariantStyles<Variant>;
83
- pressedVariantStyles: PressedVariantStyles<Variant>;
84
- labelVariantStyles: LabelVariantStyles<Variant>;
85
- iconVariantStyles: IconVariantStyles<Variant>;
86
- pressedLabelVariantStyles: PressedLabelVariantStyles<Variant>;
87
- }
88
65
  export type ButtonSeverity = 'info' | 'success' | 'warning' | 'danger';
89
66
  export interface ButtonSeverityProps {
90
67
  /**
@@ -1,3 +1,3 @@
1
- import type { BaseButtonProps, ButtonVariant } from '../types';
2
- export type ButtonActivityIndicatorProps<Variant extends ButtonVariant> = Pick<Required<BaseButtonProps<Variant>>, 'size'>;
3
- export declare const ButtonActivityIndicator: <Variant extends ButtonVariant>({ size, }: ButtonActivityIndicatorProps<Variant>) => import("react").JSX.Element;
1
+ import type { BaseButtonProps } from '../types';
2
+ export type ButtonActivityIndicatorProps = Pick<Required<BaseButtonProps<never>>, 'size'>;
3
+ export declare const ButtonActivityIndicator: ({ size, }: ButtonActivityIndicatorProps) => import("react").JSX.Element;
@@ -1,17 +1,21 @@
1
1
  import { ActivityIndicator } from 'react-native';
2
+ import { StyleSheet } from 'react-native-unistyles';
2
3
  import { genericMemo } from '../../../utils/genericMemo';
3
- import { makeStyles } from '../../../utils/makeStyles';
4
- import { useTypeBasedStyle } from './useTypeBasedStyle';
5
4
  const ButtonActivityIndicatorComponent = ({ size, }) => {
6
- const styles = useStyles();
7
- const sizeBasedStyle = useTypeBasedStyle(size, styles);
8
- return (<ActivityIndicator color={styles.activityIndicator.color} size={sizeBasedStyle.height ?? 'small'} testID='Button_ActivityIndicator'/>);
5
+ buttonActivityIndicatorStyles.useVariants({ size });
6
+ return (<ActivityIndicator color={buttonActivityIndicatorStyles.indicator.color} size={buttonActivityIndicatorStyles.indicator.height} testID='Button_ActivityIndicator'/>);
9
7
  };
10
- const useStyles = makeStyles(({ theme }) => ({
11
- xlarge: { height: 21 },
12
- large: { height: 21 },
13
- base: { height: 17.5 },
14
- small: { height: 14 },
15
- activityIndicator: { color: theme.Button.Disabled.disabledButtonTextColor },
16
- }));
17
8
  export const ButtonActivityIndicator = genericMemo(ButtonActivityIndicatorComponent);
9
+ const buttonActivityIndicatorStyles = StyleSheet.create(({ theme }) => ({
10
+ indicator: {
11
+ color: theme.Button.Disabled.disabledButtonTextColor,
12
+ variants: {
13
+ size: {
14
+ xlarge: { height: 21 },
15
+ large: { height: 21 },
16
+ base: { height: 17.5 },
17
+ small: { height: 14 },
18
+ },
19
+ },
20
+ },
21
+ }));
@@ -1,7 +1,16 @@
1
- import type { ReactNode } from 'react';
2
- import type { BaseButtonProps, ButtonVariant, VariantStyles } from '../types';
3
- export type ButtonContainerComponentProps<Variant extends ButtonVariant> = Omit<BaseButtonProps<Variant>, 'size' | 'variant' | 'disabled' | 'loading' | 'shape' | 'Icon' | 'iconPosition' | 'label'> & Pick<Required<BaseButtonProps<Variant>>, 'size' | 'variant' | 'disabled' | 'loading' | 'shape'> & {
1
+ import { type ReactNode } from 'react';
2
+ import type { BaseButtonProps, ButtonShape, ButtonSize } from '../types';
3
+ export interface ButtonContainerComponentProps {
4
+ readonly size: ButtonSize;
5
+ readonly shape: ButtonShape;
6
+ readonly disabled: boolean;
7
+ readonly loading: boolean;
8
+ readonly isIconOnly: boolean;
9
+ readonly style?: BaseButtonProps<never>['style'];
10
+ readonly pressableRef?: BaseButtonProps<never>['pressableRef'];
4
11
  readonly children: ReactNode;
5
- } & Pick<VariantStyles<Variant>, 'containerVariantStyles' | 'pressedVariantStyles'>;
6
- export declare const ButtonContainerComponent: <Variant extends ButtonVariant>({ style, size, disabled, loading, variant, shape, iconOnly, children, containerVariantStyles, pressedVariantStyles, pressableRef, ...props }: ButtonContainerComponentProps<Variant>) => import("react").JSX.Element;
7
- export declare const ButtonContainer: <Variant extends ButtonVariant>({ style, size, disabled, loading, variant, shape, iconOnly, children, containerVariantStyles, pressedVariantStyles, pressableRef, ...props }: ButtonContainerComponentProps<Variant>) => import("react").JSX.Element;
12
+ readonly onPressIn?: BaseButtonProps<never>['onPressIn'];
13
+ readonly onPressOut?: BaseButtonProps<never>['onPressOut'];
14
+ [key: string]: unknown;
15
+ }
16
+ export declare const ButtonContainer: ({ style, size, disabled, loading, shape, isIconOnly, children, pressableRef, onPressIn, onPressOut, ...props }: ButtonContainerComponentProps) => import("react").JSX.Element;