|
1 | 1 | import React, {PureComponent} from 'react';
|
2 |
| -import {Platform, StyleSheet, LayoutAnimation, Image, ImageStyle, LayoutChangeEvent} from 'react-native'; |
| 2 | +import {Platform, StyleSheet, LayoutAnimation, Image, LayoutChangeEvent, ImageStyle, TextStyle} from 'react-native'; |
3 | 3 | import _ from 'lodash';
|
| 4 | +import { |
| 5 | + asBaseComponent, |
| 6 | + forwardRef, |
| 7 | + BaseComponentInjectedProps, |
| 8 | + ForwardRefInjectedProps, |
| 9 | + TypographyModifiers, |
| 10 | + ColorsModifiers, |
| 11 | + BackgroundColorModifier, |
| 12 | + MarginModifiers |
| 13 | +} from '../../commons/new'; |
4 | 14 | //@ts-ignore
|
5 | 15 | import {Constants} from '../../helpers';
|
6 | 16 | import {Colors, Typography, ThemeManager, BorderRadiuses} from '../../style';
|
7 |
| -import {asBaseComponent, forwardRef, BaseComponentInjectedProps, ForwardRefInjectedProps} from '../../commons/new'; |
8 | 17 | import {extractColorValue, extractTypographyValue} from '../../commons/modifiers';
|
9 | 18 | import TouchableOpacity from '../touchableOpacity';
|
10 |
| -import Text from '../text'; |
11 |
| -import {ButtonPropTypes, ButtonState} from './type'; |
| 19 | +import Text, {TextPropTypes} from '../text'; |
| 20 | + |
| 21 | +export type ButtonPropTypes = TextPropTypes & |
| 22 | + TypographyModifiers & |
| 23 | + ColorsModifiers & |
| 24 | + BackgroundColorModifier & |
| 25 | + MarginModifiers & { |
| 26 | + /** |
| 27 | + * Text to show inside the button |
| 28 | + */ |
| 29 | + label?: string; |
| 30 | + /** |
| 31 | + * The Button text color (inherited from Text component) |
| 32 | + */ |
| 33 | + color?: string; |
| 34 | + /** |
| 35 | + * Icon image source |
| 36 | + */ |
| 37 | + iconSource?: object | number | Function; |
| 38 | + /** |
| 39 | + * Icon image style |
| 40 | + */ |
| 41 | + iconStyle?: ImageStyle; |
| 42 | + /** |
| 43 | + * Should the icon be right to the label |
| 44 | + */ |
| 45 | + iconOnRight?: boolean; |
| 46 | + /** |
| 47 | + * Color of the button background |
| 48 | + */ |
| 49 | + backgroundColor?: string; |
| 50 | + /** |
| 51 | + * Size of the button [large, medium, small, xSmall] |
| 52 | + */ |
| 53 | + size?: 'xSmall' | 'small' | 'medium' | 'large'; |
| 54 | + /** |
| 55 | + * Custom border radius. |
| 56 | + */ |
| 57 | + borderRadius?: number; |
| 58 | + /** |
| 59 | + * Actions handler |
| 60 | + */ |
| 61 | + onPress?: Function; |
| 62 | + /** |
| 63 | + * Disable interactions for the component |
| 64 | + */ |
| 65 | + disabled?: boolean; |
| 66 | + /** |
| 67 | + * Button will have outline style |
| 68 | + */ |
| 69 | + outline?: boolean; |
| 70 | + /** |
| 71 | + * The outline color |
| 72 | + */ |
| 73 | + outlineColor?: string; |
| 74 | + /** |
| 75 | + * The outline width |
| 76 | + */ |
| 77 | + outlineWidth?: number; |
| 78 | + /** |
| 79 | + * Button will look like a link |
| 80 | + */ |
| 81 | + link?: boolean; |
| 82 | + /** |
| 83 | + * label color for when it's displayed as link |
| 84 | + */ |
| 85 | + linkColor?: string; |
| 86 | + /** |
| 87 | + * Additional styles for label text |
| 88 | + */ |
| 89 | + labelStyle?: TextStyle; |
| 90 | + /** |
| 91 | + * Props that will be passed to the button's Text label. |
| 92 | + */ |
| 93 | + labelProps?: object; |
| 94 | + /** |
| 95 | + * should the button act as a coast to coast button (no border radius) |
| 96 | + */ |
| 97 | + fullWidth?: boolean; |
| 98 | + /** |
| 99 | + * should the button be a round button |
| 100 | + */ |
| 101 | + round?: boolean; |
| 102 | + /** |
| 103 | + * Control shadow visibility (iOS-only) |
| 104 | + */ |
| 105 | + enableShadow?: boolean; |
| 106 | + /** |
| 107 | + * avoid inner button padding |
| 108 | + */ |
| 109 | + avoidInnerPadding?: boolean; |
| 110 | + /** |
| 111 | + * avoid minimum width constraints |
| 112 | + */ |
| 113 | + avoidMinWidth?: boolean; |
| 114 | + /** |
| 115 | + * callback for getting activeBackgroundColor (e.g. (calculatedBackgroundColor, prop) => {...}) |
| 116 | + * better set using ThemeManager |
| 117 | + */ |
| 118 | + getActiveBackgroundColor?: Function; |
| 119 | + /** |
| 120 | + * should animate layout change |
| 121 | + * Note?: For Android you must set 'setLayoutAnimationEnabledExperimental(true)' via RN's 'UIManager' |
| 122 | + */ |
| 123 | + animateLayout?: boolean; |
| 124 | + /** |
| 125 | + * the direction of the animation ('left' and 'right' will effect the button's own alignment) |
| 126 | + */ |
| 127 | + animateTo?: 'center' | 'left' | 'right'; |
| 128 | + }; |
| 129 | + |
| 130 | +export type ButtonState = { |
| 131 | + size?: number; |
| 132 | + borderRadius?: number; |
| 133 | + isLandscape?: boolean; |
| 134 | +}; |
12 | 135 |
|
13 | 136 | const PADDINGS = {
|
14 | 137 | XSMALL: 3,
|
|
0 commit comments