@widergy/mobile-ui 1.19.1 → 1.19.2

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.19.2](https://github.com/widergy/mobile-ui/compare/v1.19.1...v1.19.2) (2024-08-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * update utbadge and counter on utbutton ([#343](https://github.com/widergy/mobile-ui/issues/343)) ([6dcc9dd](https://github.com/widergy/mobile-ui/commit/6dcc9dd1b9bd00b126cf50b0dcf66d87a2a94559))
7
+
1
8
  ## [1.19.1](https://github.com/widergy/mobile-ui/compare/v1.19.0...v1.19.1) (2024-08-26)
2
9
 
3
10
 
@@ -1,13 +1,5 @@
1
- export const COLORS_MAPPER = {
2
- alert: 'error',
3
- identity: 'accent',
4
- identitySecondary: 'neutral',
5
- information: 'information',
6
- negative: 'negative',
7
- success: 'success',
8
- warning: 'warning'
9
- };
1
+ import { COLOR_THEMES } from '../../constants/Palette';
10
2
 
11
3
  export const DEFAULT_PROPS = {
12
- colorTheme: 'alert'
4
+ colorTheme: COLOR_THEMES.error
13
5
  };
@@ -1,23 +1,16 @@
1
1
  import { StyleSheet } from 'react-native';
2
2
 
3
- import { COLORS_MAPPER, DEFAULT_PROPS } from './constants';
3
+ import { COLOR_THEMES } from '../../constants/Palette';
4
+ import { getDefaultColorShade } from '../../utils/styleUtils';
4
5
 
5
- export const variantsColorTheme = (theme, colorTheme) => {
6
- const colorName = COLORS_MAPPER[colorTheme] || COLORS_MAPPER[DEFAULT_PROPS.colorTheme];
7
- const paletteTheme = theme.Palette[colorName];
6
+ import { DEFAULT_PROPS } from './constants';
8
7
 
9
- const backgroundColorMapper = {
10
- alert: paletteTheme['04'],
11
- information: paletteTheme['05'],
12
- warning: paletteTheme['05'],
13
- success: paletteTheme['05'],
14
- identity: paletteTheme['05'],
15
- identitySecondary: paletteTheme['05'],
16
- negative: paletteTheme['04']
17
- };
8
+ export const variantsColorTheme = (theme, colorTheme) => {
9
+ const colorThemeDefinition = theme.Palette[colorTheme] || theme.Palette[DEFAULT_PROPS.colorTheme];
10
+ const colorShade = getDefaultColorShade(colorTheme);
18
11
 
19
12
  return {
20
- backgroundColor: backgroundColorMapper[colorTheme]
13
+ backgroundColor: colorThemeDefinition[colorShade]
21
14
  };
22
15
  };
23
16
 
@@ -51,6 +44,6 @@ export const retrieveStyle = ({ theme, colorTheme, children }) => {
51
44
  ...textTheme,
52
45
  ...variantTheme
53
46
  },
54
- textColorTheme: colorTheme === 'negative' ? 'dark' : 'negative'
47
+ textColorTheme: [COLOR_THEMES.negative, COLOR_THEMES.light].includes(colorTheme) ? 'dark' : 'negative'
55
48
  };
56
49
  };
@@ -1,6 +1,13 @@
1
1
  export const ELEVATION = 2;
2
2
  export const PRESSED_ELEVATION = 2;
3
- export const PRIMARY = 'primary';
3
+
4
+ export const VARIANTS_NAMES = {
5
+ filled: 'filled',
6
+ outlined: 'outlined',
7
+ semitransparent: 'semitransparent',
8
+ shadow: 'shadow',
9
+ text: 'text'
10
+ };
4
11
 
5
12
  export const SIZES = {
6
13
  SMALL: 'small',
@@ -20,9 +27,3 @@ export const COLORS_MAPPER = {
20
27
  secondary: 'neutral',
21
28
  success: 'success'
22
29
  };
23
-
24
- export const COUNTER_THEMES = {
25
- IDENTITY: 'identity',
26
- IDENTITY_SECONDARY: 'identitySecondary',
27
- NEGATIVE: 'negative'
28
- };
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { Pressable, View } from 'react-native';
3
3
 
4
+ import { COLOR_THEMES } from '../../constants/Palette';
4
5
  import { isUTIcon } from '../UTIcon/utils';
5
6
  import { useTheme } from '../../theming';
6
7
  import UTBadge from '../UTBadge';
@@ -8,8 +9,8 @@ import UTIcon from '../UTIcon';
8
9
  import UTLabel from '../UTLabel';
9
10
  import UTLoading from '../UTLoading';
10
11
 
12
+ import { COLORS_MAPPER, ICON_PLACEMENTS, VARIANTS_NAMES } from './constants';
11
13
  import { defaultProps, propTypes } from './proptypes';
12
- import { ICON_PLACEMENTS } from './constants';
13
14
  import { retrieveStyle } from './theme';
14
15
 
15
16
  const UTButton = ({
@@ -29,7 +30,6 @@ const UTButton = ({
29
30
 
30
31
  const {
31
32
  buttonStyles: themeButtonStyles,
32
- counterStyles,
33
33
  childrenContainerStyles: themeChildrenContainerStyles,
34
34
  disabledStyles,
35
35
  iconStyles: themeIconStyles,
@@ -37,7 +37,6 @@ const UTButton = ({
37
37
  } = retrieveStyle({
38
38
  style,
39
39
  colorTheme,
40
- iconPlacement,
41
40
  size,
42
41
  theme,
43
42
  variant
@@ -45,10 +44,16 @@ const UTButton = ({
45
44
 
46
45
  const iconStyles = children ? themeIconStyles.icon : themeIconStyles.iconOnly;
47
46
 
48
- const { colorTheme: counterTheme, iconLeftAndCounter, ...remainingCounterStyles } = counterStyles;
47
+ const counterColorTheme =
48
+ variant === VARIANTS_NAMES.filled
49
+ ? colorTheme === COLOR_THEMES.negative
50
+ ? COLOR_THEMES.dark
51
+ : COLOR_THEMES.negative
52
+ : COLORS_MAPPER[colorTheme];
49
53
 
50
54
  const buttonStyles = ({ pressed }) => [
51
55
  themeButtonStyles,
56
+ !children && themeButtonStyles.iconOnly,
52
57
  (disabled || loading) && disabledStyles,
53
58
  pressed ? themeButtonStyles.pressed : themeButtonStyles.notPressed
54
59
  ];
@@ -57,13 +62,13 @@ const UTButton = ({
57
62
  Icon &&
58
63
  (isUTIcon(Icon) ? (
59
64
  (() => {
60
- const { fontSize, color, ...remainingIconStyles } = iconStyles;
65
+ const { size: iconSize, color, ...remainingIconStyles } = iconStyles;
61
66
 
62
67
  return (
63
68
  <UTIcon
64
69
  colorTheme={textStyles.colorTheme}
65
70
  name={Icon}
66
- size={fontSize}
71
+ size={iconSize}
67
72
  style={remainingIconStyles}
68
73
  />
69
74
  );
@@ -74,17 +79,8 @@ const UTButton = ({
74
79
 
75
80
  const RenderedChildren = (
76
81
  <View style={themeChildrenContainerStyles}>
82
+ {count && <UTBadge colorTheme={counterColorTheme}>{count}</UTBadge>}
77
83
  {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}
88
84
  {children && (
89
85
  <UTLabel colorTheme={textStyles.colorTheme} variant={textStyles.variant} weight={textStyles.weight}>
90
86
  {children}
@@ -1,7 +1,7 @@
1
+ import { COLOR_THEMES } from '../../constants/Palette';
1
2
  import { getShadow } from '../../utils/styleUtils';
2
- import { COLOR_THEMES } from '../UTLabel/constants';
3
3
 
4
- import { COLORS_MAPPER, COUNTER_THEMES, ELEVATION, PRESSED_ELEVATION, PRIMARY } from './constants';
4
+ import { COLORS_MAPPER, ELEVATION, PRESSED_ELEVATION } from './constants';
5
5
  import { defaultProps } from './proptypes';
6
6
 
7
7
  const baseButtonTheme = () => ({
@@ -14,29 +14,22 @@ const baseButtonTheme = () => ({
14
14
  borderWidth: 0,
15
15
  minWidth: 'auto',
16
16
  paddingHorizontal: 12,
17
- paddingVertical: 8
18
- },
19
- counter: {
20
- marginRight: 8
21
- },
22
- iconLeftAndCounter: {
23
- marginLeft: 8,
24
- marginRight: 0
17
+ paddingVertical: 8,
18
+ iconOnly: {
19
+ paddingHorizontal: 8,
20
+ paddingVertical: 8
21
+ }
25
22
  },
26
23
  icon: {
27
- fontSize: 20
24
+ size: 20
28
25
  },
29
26
  iconOnly: {
30
- fontSize: 24,
31
- height: 24,
32
- marginHorizontal: -4,
33
- marginLeft: 0,
34
- marginRight: 0,
35
- width: 24
27
+ size: 24
36
28
  },
37
29
  childrenContainer: {
38
30
  alignItems: 'center',
39
31
  display: 'flex',
32
+ columnGap: 8,
40
33
  flexDirection: 'row',
41
34
  justifyContent: 'flex-start'
42
35
  }
@@ -61,12 +54,8 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
61
54
  backgroundColor: actionTheme['05']
62
55
  }
63
56
  },
64
- counter: {
65
- colorTheme:
66
- colorTheme === COLORS_MAPPER.negative ? COUNTER_THEMES.IDENTITY_SECONDARY : COUNTER_THEMES.NEGATIVE
67
- },
68
57
  text: {
69
- colorTheme: colorTheme === COLORS_MAPPER.negative ? COLOR_THEMES.NEUTRAL : COLOR_THEMES.NEGATIVE
58
+ colorTheme: colorTheme === COLORS_MAPPER.negative ? COLOR_THEMES.neutral : COLOR_THEMES.negative
70
59
  },
71
60
  icon: {
72
61
  color: colorTheme === COLORS_MAPPER.negative ? neutralTheme['05'] : negativeTheme['05']
@@ -82,14 +71,6 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
82
71
  backgroundColor: actionTheme['03']
83
72
  }
84
73
  },
85
- counter: {
86
- colorTheme:
87
- colorTheme === COLORS_MAPPER.negative
88
- ? colorTheme
89
- : colorTheme === PRIMARY
90
- ? COUNTER_THEMES.IDENTITY
91
- : COUNTER_THEMES.IDENTITY_SECONDARY
92
- },
93
74
  text: {
94
75
  colorTheme: colorName
95
76
  },
@@ -106,14 +87,6 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
106
87
  backgroundColor: actionTheme['02']
107
88
  }
108
89
  },
109
- counter: {
110
- colorTheme:
111
- colorTheme === COLORS_MAPPER.negative
112
- ? colorTheme
113
- : colorTheme === PRIMARY
114
- ? COUNTER_THEMES.IDENTITY
115
- : COUNTER_THEMES.IDENTITY_SECONDARY
116
- },
117
90
  text: {
118
91
  colorTheme: colorName
119
92
  },
@@ -130,14 +103,6 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
130
103
  backgroundColor: actionTheme['02']
131
104
  }
132
105
  },
133
- counter: {
134
- colorTheme:
135
- colorTheme === COLORS_MAPPER.negative
136
- ? colorTheme
137
- : colorTheme === PRIMARY
138
- ? COUNTER_THEMES.IDENTITY
139
- : COUNTER_THEMES.IDENTITY_SECONDARY
140
- },
141
106
  text: {
142
107
  colorTheme: colorName
143
108
  },
@@ -157,14 +122,6 @@ const variantsColorTheme = (theme, colorTheme, variant) => {
157
122
  },
158
123
  notPressed: shadow
159
124
  },
160
- counter: {
161
- colorTheme:
162
- colorTheme === COLORS_MAPPER.negative
163
- ? colorTheme
164
- : colorTheme === PRIMARY
165
- ? COUNTER_THEMES.IDENTITY
166
- : COUNTER_THEMES.IDENTITY_SECONDARY
167
- },
168
125
  text: {
169
126
  colorTheme: colorName
170
127
  },
@@ -182,33 +139,41 @@ const sizeButtonTheme = size => {
182
139
  large: {
183
140
  button: {
184
141
  paddingHorizontal: 16,
185
- paddingVertical: 12
142
+ paddingVertical: 12,
143
+ iconOnly: {
144
+ paddingHorizontal: 12,
145
+ paddingVertical: 12
146
+ }
186
147
  },
187
148
  text: {
188
149
  variant: 'body',
189
150
  weight: 'medium'
190
151
  },
191
152
  icon: {
192
- fontSize: 20
153
+ size: 20
193
154
  },
194
155
  iconOnly: {
195
- fontSize: 24
156
+ size: 24
196
157
  }
197
158
  },
198
159
  small: {
199
160
  button: {
200
161
  paddingHorizontal: 8,
201
- paddingVertical: 4
162
+ paddingVertical: 4,
163
+ iconOnly: {
164
+ paddingHorizontal: 4,
165
+ paddingVertical: 4
166
+ }
202
167
  },
203
168
  text: {
204
169
  weight: 'medium',
205
170
  variant: 'small'
206
171
  },
207
172
  icon: {
208
- fontSize: 20
173
+ size: 20
209
174
  },
210
175
  iconOnly: {
211
- fontSize: 20
176
+ size: 20
212
177
  }
213
178
  }
214
179
  };
@@ -216,23 +181,10 @@ const sizeButtonTheme = size => {
216
181
  return definition[size] || {};
217
182
  };
218
183
 
219
- const iconButtonPlacementTheme = iconPlacement => {
220
- const definition = {
221
- left: {
222
- marginRight: 8
223
- },
224
- right: {
225
- marginLeft: 8
226
- }
227
- };
228
- return definition[iconPlacement] || {};
229
- };
230
-
231
- export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size, iconPlacement }) => {
184
+ export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size }) => {
232
185
  const baseTheme = baseButtonTheme();
233
186
  const variantTheme = variantsColorTheme(theme, colorTheme, variant);
234
187
  const sizeTheme = sizeButtonTheme(size);
235
- const iconPlacementTheme = iconButtonPlacementTheme(iconPlacement);
236
188
 
237
189
  const buttonStyles = {
238
190
  ...baseTheme.button,
@@ -241,14 +193,6 @@ export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size, ic
241
193
  ...style.root
242
194
  };
243
195
 
244
- const counterStyles = {
245
- ...baseTheme.counter,
246
- ...variantTheme.counter,
247
- iconLeftAndCounter: {
248
- ...baseTheme.iconLeftAndCounter
249
- }
250
- };
251
-
252
196
  const textStyles = {
253
197
  colorTheme: variantTheme.text.colorTheme,
254
198
  variant: sizeTheme.text?.variant || baseTheme.text?.variant,
@@ -260,7 +204,6 @@ export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size, ic
260
204
  ...baseTheme.icon,
261
205
  ...sizeTheme.icon,
262
206
  ...variantTheme.icon,
263
- ...iconPlacementTheme,
264
207
  ...style.icon
265
208
  },
266
209
  iconOnly: {
@@ -271,11 +214,14 @@ export const retrieveStyle = ({ style = {}, colorTheme, variant, theme, size, ic
271
214
  }
272
215
  };
273
216
 
274
- const childrenContainerStyles = { ...baseTheme.childrenContainer, ...style.childrenContainer };
217
+ const childrenContainerStyles = {
218
+ ...baseTheme.childrenContainer,
219
+ ...style.childrenContainer
220
+ };
275
221
 
276
222
  const disabledStyles = {
277
223
  opacity: 0.5
278
224
  };
279
225
 
280
- return { buttonStyles, counterStyles, textStyles, disabledStyles, iconStyles, childrenContainerStyles };
226
+ return { buttonStyles, textStyles, disabledStyles, iconStyles, childrenContainerStyles };
281
227
  };
@@ -1,3 +1,5 @@
1
+ import { COLOR_SHADES, COLOR_THEMES } from '../../constants/Palette';
2
+
1
3
  import EnergyIconCar from './components/EnergyIcons/EnergyIconCar.svg';
2
4
  import EnergyIconCart from './components/EnergyIcons/EnergyIconCart.svg';
3
5
  import EnergyIconChartPie from './components/EnergyIcons/EnergyIconChartPie.svg';
@@ -7,32 +9,11 @@ import EnergyIconHome2 from './components/EnergyIcons/EnergyIconHome2.svg';
7
9
  import EnergyIconHome3 from './components/EnergyIcons/EnergyIconHome3.svg';
8
10
  import EnergyIconTruck from './components/EnergyIcons/EnergyIconTruck.svg';
9
11
 
10
- export const SHADES = {
11
- shade01: '01',
12
- shade02: '02',
13
- shade03: '03',
14
- shade04: '04',
15
- shade05: '05'
16
- };
17
-
18
- export const COLOR_THEMES = {
19
- accent: 'accent',
20
- dark: 'dark',
21
- error: 'error',
22
- gray: 'gray',
23
- information: 'information',
24
- light: 'light',
25
- negative: 'negative',
26
- neutral: 'neutral',
27
- success: 'success',
28
- warning: 'warning'
29
- };
30
-
31
12
  export const DEFAULT_PROPS = {
32
- color: 'dark'
13
+ color: COLOR_THEMES.dark
33
14
  };
34
15
 
35
- export const DEFAULT_INTERNAL_SHADE = SHADES.shade02;
16
+ export const DEFAULT_INTERNAL_SHADE = COLOR_SHADES.shade02;
36
17
 
37
18
  export const ENERGY_ICONS = {
38
19
  EnergyIconCar,
@@ -1,11 +1,6 @@
1
- import { COLOR_THEMES, DEFAULT_PROPS, SHADES } from './constants';
1
+ import { getDefaultColorShade } from '../../utils/styleUtils';
2
2
 
3
- const getDefaultColorShade = colorTheme =>
4
- colorTheme === COLOR_THEMES.gray
5
- ? SHADES.shade04
6
- : colorTheme === COLOR_THEMES.light
7
- ? SHADES.shade01
8
- : SHADES.shade05;
3
+ import { DEFAULT_PROPS } from './constants';
9
4
 
10
5
  export const retrieveColor = ({ colorTheme, shade, theme }) => {
11
6
  const colorThemeDefinition = theme.Palette[colorTheme] || theme.Palette[DEFAULT_PROPS.color];
@@ -1,10 +1,4 @@
1
- export const SHADES = {
2
- shade01: '01',
3
- shade02: '02',
4
- shade03: '03',
5
- shade04: '04',
6
- shade05: '05'
7
- };
1
+ import { COLOR_THEMES } from '../../constants/Palette';
8
2
 
9
3
  export const VARIANTS_SIZES = {
10
4
  title1: 30,
@@ -37,21 +31,8 @@ export const WEIGHTS = {
37
31
  black: 900
38
32
  };
39
33
 
40
- export const COLOR_THEMES = {
41
- ACCENT: 'accent',
42
- DARK: 'dark',
43
- ERROR: 'error',
44
- GRAY: 'gray',
45
- INFORMATION: 'information',
46
- LIGHT: 'light',
47
- NEGATIVE: 'negative',
48
- NEUTRAL: 'neutral',
49
- SUCCESS: 'success',
50
- WARNING: 'warning'
51
- };
52
-
53
34
  export const DEFAULT_PROPS = {
54
- colorTheme: COLOR_THEMES.DARK,
35
+ colorTheme: COLOR_THEMES.dark,
55
36
  field: {},
56
37
  style: {},
57
38
  variant: 'body',
@@ -1,17 +1,12 @@
1
+ import { COLOR_SHADES } from '../../constants/Palette';
2
+ import { getDefaultColorShade } from '../../utils/styleUtils';
1
3
  import { IS_IOS } from '../../utils/platformUtils/constants';
2
4
 
3
- import { COLOR_THEMES, DEFAULT_PROPS, LINE_HEIGHTS, SHADES, VARIANTS_SIZES, WEIGHTS } from './constants';
4
-
5
- const getDefaultColorShade = colorTheme =>
6
- colorTheme === COLOR_THEMES.GRAY
7
- ? SHADES.shade04
8
- : colorTheme === COLOR_THEMES.LIGHT
9
- ? SHADES.shade01
10
- : SHADES.shade05;
5
+ import { DEFAULT_PROPS, LINE_HEIGHTS, VARIANTS_SIZES, WEIGHTS } from './constants';
11
6
 
12
7
  const variantsColorTheme = (colorTheme, shade, theme) => {
13
8
  const colorThemeDefinition = theme.Palette[colorTheme] || theme.Palette[DEFAULT_PROPS.colorTheme];
14
- const colorShade = Object.values(SHADES).includes(shade) ? shade : getDefaultColorShade(colorTheme);
9
+ const colorShade = Object.values(COLOR_SHADES).includes(shade) ? shade : getDefaultColorShade(colorTheme);
15
10
  return colorThemeDefinition[colorShade] || '#000';
16
11
  };
17
12
 
@@ -0,0 +1,20 @@
1
+ export const COLOR_SHADES = {
2
+ shade01: '01',
3
+ shade02: '02',
4
+ shade03: '03',
5
+ shade04: '04',
6
+ shade05: '05'
7
+ };
8
+
9
+ export const COLOR_THEMES = {
10
+ accent: 'accent',
11
+ dark: 'dark',
12
+ error: 'error',
13
+ gray: 'gray',
14
+ information: 'information',
15
+ light: 'light',
16
+ negative: 'negative',
17
+ neutral: 'neutral',
18
+ success: 'success',
19
+ warning: 'warning'
20
+ };
@@ -1,8 +1,17 @@
1
1
  import isArray from 'lodash/isArray';
2
2
  import mergeWith from 'lodash/mergeWith';
3
3
 
4
+ import { COLOR_SHADES, COLOR_THEMES } from '../../constants/Palette';
5
+
4
6
  export const SHADOW_OPACITY = 0.1;
5
7
 
8
+ export const getDefaultColorShade = colorTheme =>
9
+ colorTheme === COLOR_THEMES.gray
10
+ ? COLOR_SHADES.shade04
11
+ : colorTheme === COLOR_THEMES.light
12
+ ? COLOR_SHADES.shade01
13
+ : COLOR_SHADES.shade05;
14
+
6
15
  const shadowLevels = {
7
16
  1: {
8
17
  elevation: 6,
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@widergy/mobile-ui",
3
3
  "description": "Widergy Mobile Components",
4
4
  "author": "widergy",
5
- "version": "1.19.1",
5
+ "version": "1.19.2",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [