@widergy/mobile-ui 1.17.1 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.18.0](https://github.com/widergy/mobile-ui/compare/v1.17.1...v1.18.0) (2024-08-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* button counter ([#333](https://github.com/widergy/mobile-ui/issues/333)) ([7a87e45](https://github.com/widergy/mobile-ui/commit/7a87e452d04a227bc7b18b3d5db54435ca9f1345))
|
|
7
|
+
|
|
1
8
|
## [1.17.1](https://github.com/widergy/mobile-ui/compare/v1.17.0...v1.17.1) (2024-08-12)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Description
|
|
4
4
|
|
|
5
|
-
`UTButton` is a versatile button component that can be customized with various themes, sizes, icons, and loading states.
|
|
5
|
+
`UTButton` is a versatile button component that can be customized with various themes, sizes, icons, counters, and loading states.
|
|
6
6
|
|
|
7
7
|
## Props
|
|
8
8
|
|
|
9
9
|
| Name | Type | Default | Description |
|
|
10
10
|
| ------------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
11
|
| colorTheme | string | 'secondary' | The color theme to use. One of: `error`, `negative`, `primary`, `secondary`, `success`. |
|
|
12
|
+
| count | number | | The value to be shown inside the `UTBadge` component |
|
|
12
13
|
| disabled | bool | false | Disables the button, making it unclickable and applying a disabled style. |
|
|
13
14
|
| Icon | elementType | | Icon component to be displayed inside the button. Can be a text (name of the icon from tabler icons) or a React component (e.g., SVG). |
|
|
14
15
|
| iconPlacement | string | 'left' | Position of the icon relative to the text. One of: `left`, `right`. |
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export const ELEVATION = 2;
|
|
2
2
|
export const PRESSED_ELEVATION = 2;
|
|
3
|
+
export const PRIMARY = 'primary';
|
|
3
4
|
|
|
4
5
|
export const SIZES = {
|
|
5
6
|
SMALL: 'small',
|
|
@@ -19,3 +20,9 @@ export const COLORS_MAPPER = {
|
|
|
19
20
|
secondary: 'neutral',
|
|
20
21
|
success: 'success'
|
|
21
22
|
};
|
|
23
|
+
|
|
24
|
+
export const COUNTER_THEMES = {
|
|
25
|
+
IDENTITY: 'identity',
|
|
26
|
+
IDENTITY_SECONDARY: 'identitySecondary',
|
|
27
|
+
NEGATIVE: 'negative'
|
|
28
|
+
};
|
|
@@ -3,6 +3,7 @@ import { Pressable, View } from 'react-native';
|
|
|
3
3
|
|
|
4
4
|
import { isUTIcon } from '../UTIcon/utils';
|
|
5
5
|
import { useTheme } from '../../theming';
|
|
6
|
+
import UTBadge from '../UTBadge';
|
|
6
7
|
import UTIcon from '../UTIcon';
|
|
7
8
|
import UTLabel from '../UTLabel';
|
|
8
9
|
import UTLoading from '../UTLoading';
|
|
@@ -14,6 +15,7 @@ import { retrieveStyle } from './theme';
|
|
|
14
15
|
const UTButton = ({
|
|
15
16
|
children,
|
|
16
17
|
colorTheme,
|
|
18
|
+
count,
|
|
17
19
|
disabled,
|
|
18
20
|
Icon,
|
|
19
21
|
iconPlacement,
|
|
@@ -27,6 +29,7 @@ const UTButton = ({
|
|
|
27
29
|
|
|
28
30
|
const {
|
|
29
31
|
buttonStyles: themeButtonStyles,
|
|
32
|
+
counterStyles,
|
|
30
33
|
childrenContainerStyles: themeChildrenContainerStyles,
|
|
31
34
|
disabledStyles,
|
|
32
35
|
iconStyles: themeIconStyles,
|
|
@@ -42,6 +45,8 @@ const UTButton = ({
|
|
|
42
45
|
|
|
43
46
|
const iconStyles = children ? themeIconStyles.icon : themeIconStyles.iconOnly;
|
|
44
47
|
|
|
48
|
+
const { colorTheme: counterTheme, iconLeftAndCounter, ...remainingCounterStyles } = counterStyles;
|
|
49
|
+
|
|
45
50
|
const buttonStyles = ({ pressed }) => [
|
|
46
51
|
themeButtonStyles,
|
|
47
52
|
(disabled || loading) && disabledStyles,
|
|
@@ -70,6 +75,16 @@ const UTButton = ({
|
|
|
70
75
|
const RenderedChildren = (
|
|
71
76
|
<View style={themeChildrenContainerStyles}>
|
|
72
77
|
{iconPlacement === ICON_PLACEMENTS.LEFT && IconToShow}
|
|
78
|
+
{count && count > 0 ? (
|
|
79
|
+
<UTBadge
|
|
80
|
+
colorTheme={counterTheme}
|
|
81
|
+
style={
|
|
82
|
+
iconPlacement === ICON_PLACEMENTS.LEFT && !children ? iconLeftAndCounter : remainingCounterStyles
|
|
83
|
+
}
|
|
84
|
+
>
|
|
85
|
+
{count}
|
|
86
|
+
</UTBadge>
|
|
87
|
+
) : null}
|
|
73
88
|
{children && (
|
|
74
89
|
<UTLabel colorTheme={textStyles.colorTheme} variant={textStyles.variant} weight={textStyles.weight}>
|
|
75
90
|
{children}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bool, func, elementType, string, shape } from 'prop-types';
|
|
1
|
+
import { bool, func, elementType, string, shape, number } from 'prop-types';
|
|
2
2
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
3
3
|
|
|
4
4
|
import { ICON_PLACEMENTS, SIZES } from './constants';
|
|
@@ -14,6 +14,7 @@ export const defaultProps = {
|
|
|
14
14
|
|
|
15
15
|
export const propTypes = {
|
|
16
16
|
colorTheme: string,
|
|
17
|
+
count: number,
|
|
17
18
|
disabled: bool,
|
|
18
19
|
Icon: elementType,
|
|
19
20
|
iconPlacement: string,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getShadow } from '../../utils/styleUtils';
|
|
2
2
|
import { COLOR_THEMES } from '../UTLabel/constants';
|
|
3
3
|
|
|
4
|
-
import { COLORS_MAPPER, ELEVATION, PRESSED_ELEVATION } from './constants';
|
|
4
|
+
import { COLORS_MAPPER, COUNTER_THEMES, ELEVATION, PRESSED_ELEVATION, PRIMARY } from './constants';
|
|
5
5
|
import { defaultProps } from './proptypes';
|
|
6
6
|
|
|
7
7
|
const baseButtonTheme = () => ({
|
|
@@ -16,6 +16,13 @@ const baseButtonTheme = () => ({
|
|
|
16
16
|
paddingHorizontal: 12,
|
|
17
17
|
paddingVertical: 8
|
|
18
18
|
},
|
|
19
|
+
counter: {
|
|
20
|
+
marginRight: 8
|
|
21
|
+
},
|
|
22
|
+
iconLeftAndCounter: {
|
|
23
|
+
marginLeft: 8,
|
|
24
|
+
marginRight: 0
|
|
25
|
+
},
|
|
19
26
|
icon: {
|
|
20
27
|
fontSize: 20
|
|
21
28
|
},
|
|
@@ -54,6 +61,10 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
|
|
|
54
61
|
backgroundColor: actionTheme['05']
|
|
55
62
|
}
|
|
56
63
|
},
|
|
64
|
+
counter: {
|
|
65
|
+
colorTheme:
|
|
66
|
+
colorTheme === COLORS_MAPPER.negative ? COUNTER_THEMES.IDENTITY_SECONDARY : COUNTER_THEMES.NEGATIVE
|
|
67
|
+
},
|
|
57
68
|
text: {
|
|
58
69
|
colorTheme: colorTheme === COLORS_MAPPER.negative ? COLOR_THEMES.NEUTRAL : COLOR_THEMES.NEGATIVE
|
|
59
70
|
},
|
|
@@ -71,6 +82,14 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
|
|
|
71
82
|
backgroundColor: actionTheme['03']
|
|
72
83
|
}
|
|
73
84
|
},
|
|
85
|
+
counter: {
|
|
86
|
+
colorTheme:
|
|
87
|
+
colorTheme === COLORS_MAPPER.negative
|
|
88
|
+
? colorTheme
|
|
89
|
+
: colorTheme === PRIMARY
|
|
90
|
+
? COUNTER_THEMES.IDENTITY
|
|
91
|
+
: COUNTER_THEMES.IDENTITY_SECONDARY
|
|
92
|
+
},
|
|
74
93
|
text: {
|
|
75
94
|
colorTheme: colorName
|
|
76
95
|
},
|
|
@@ -87,6 +106,14 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
|
|
|
87
106
|
backgroundColor: actionTheme['02']
|
|
88
107
|
}
|
|
89
108
|
},
|
|
109
|
+
counter: {
|
|
110
|
+
colorTheme:
|
|
111
|
+
colorTheme === COLORS_MAPPER.negative
|
|
112
|
+
? colorTheme
|
|
113
|
+
: colorTheme === PRIMARY
|
|
114
|
+
? COUNTER_THEMES.IDENTITY
|
|
115
|
+
: COUNTER_THEMES.IDENTITY_SECONDARY
|
|
116
|
+
},
|
|
90
117
|
text: {
|
|
91
118
|
colorTheme: colorName
|
|
92
119
|
},
|
|
@@ -103,6 +130,14 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
|
|
|
103
130
|
backgroundColor: actionTheme['02']
|
|
104
131
|
}
|
|
105
132
|
},
|
|
133
|
+
counter: {
|
|
134
|
+
colorTheme:
|
|
135
|
+
colorTheme === COLORS_MAPPER.negative
|
|
136
|
+
? colorTheme
|
|
137
|
+
: colorTheme === PRIMARY
|
|
138
|
+
? COUNTER_THEMES.IDENTITY
|
|
139
|
+
: COUNTER_THEMES.IDENTITY_SECONDARY
|
|
140
|
+
},
|
|
106
141
|
text: {
|
|
107
142
|
colorTheme: colorName
|
|
108
143
|
},
|
|
@@ -122,6 +157,14 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
|
|
|
122
157
|
},
|
|
123
158
|
notPressed: shadow
|
|
124
159
|
},
|
|
160
|
+
counter: {
|
|
161
|
+
colorTheme:
|
|
162
|
+
colorTheme === COLORS_MAPPER.negative
|
|
163
|
+
? colorTheme
|
|
164
|
+
: colorTheme === PRIMARY
|
|
165
|
+
? COUNTER_THEMES.IDENTITY
|
|
166
|
+
: COUNTER_THEMES.IDENTITY_SECONDARY
|
|
167
|
+
},
|
|
125
168
|
text: {
|
|
126
169
|
colorTheme: colorName
|
|
127
170
|
},
|
|
@@ -198,6 +241,14 @@ export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size, ic
|
|
|
198
241
|
...style.root
|
|
199
242
|
};
|
|
200
243
|
|
|
244
|
+
const counterStyles = {
|
|
245
|
+
...baseTheme.counter,
|
|
246
|
+
...variantTheme.counter,
|
|
247
|
+
iconLeftAndCounter: {
|
|
248
|
+
...baseTheme.iconLeftAndCounter
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
201
252
|
const textStyles = {
|
|
202
253
|
colorTheme: variantTheme.text.colorTheme,
|
|
203
254
|
variant: sizeTheme.text?.variant || baseTheme.text?.variant,
|
|
@@ -226,5 +277,5 @@ export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size, ic
|
|
|
226
277
|
opacity: 0.5
|
|
227
278
|
};
|
|
228
279
|
|
|
229
|
-
return { buttonStyles, textStyles, disabledStyles, iconStyles, childrenContainerStyles };
|
|
280
|
+
return { buttonStyles, counterStyles, textStyles, disabledStyles, iconStyles, childrenContainerStyles };
|
|
230
281
|
};
|
package/package.json
CHANGED