@widergy/mobile-ui 1.27.0 → 1.27.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.27.1](https://github.com/widergy/mobile-ui/compare/v1.27.0...v1.27.1) (2024-10-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fixes on utcheckbox ([#360](https://github.com/widergy/mobile-ui/issues/360)) ([db36603](https://github.com/widergy/mobile-ui/commit/db3660373bbba349c6b798f46bd91687096ffdc8))
7
+
1
8
  # [1.27.0](https://github.com/widergy/mobile-ui/compare/v1.26.5...v1.27.0) (2024-10-07)
2
9
 
3
10
 
@@ -141,4 +141,8 @@ class CheckList extends PureComponent {
141
141
 
142
142
  CheckList.propTypes = propTypes;
143
143
 
144
+ /**
145
+ * @deprecated The CheckList component is deprecated and will be removed in a future release.
146
+ * Please use the UTCheckList component instead.
147
+ */
144
148
  export default CheckList;
@@ -89,4 +89,8 @@ Checkbox.defaultProps = {
89
89
 
90
90
  Checkbox.propTypes = propTypes;
91
91
 
92
+ /**
93
+ * @deprecated The Checkbox component is deprecated and will be removed in a future release.
94
+ * Please use the UTCheckBox component instead.
95
+ */
92
96
  export default withTheme(Checkbox);
@@ -1,7 +1,6 @@
1
- export const getIconColorProps = (changeOnError, changeOnFocus, colorTheme, error, focused, shade) => {
2
- return changeOnError && error
1
+ export const getIconColorProps = (changeOnError, changeOnFocus, colorTheme, error, focused, shade) =>
2
+ changeOnError && error
3
3
  ? { colorTheme: 'error', shade: '04' }
4
4
  : changeOnFocus && focused
5
5
  ? { colorTheme: 'accent', shade: '04' }
6
6
  : { colorTheme: colorTheme || 'gray', shade };
7
- };
@@ -5,3 +5,5 @@ export const SPACING = {
5
5
  SMALL: 'small',
6
6
  LARGE: 'large'
7
7
  };
8
+
9
+ export const BUTTON_VARIANT = 'button';
@@ -5,23 +5,24 @@ import { useTheme } from '../../theming';
5
5
  import UTFieldLabel from '../UTFieldLabel';
6
6
  import UTIcon from '../UTIcon';
7
7
 
8
- import { CHECKED_ICON, INDETERMINATE_ICON } from './constants';
8
+ import { BUTTON_VARIANT, CHECKED_ICON, INDETERMINATE_ICON } from './constants';
9
9
  import { propTypes, defaultProps } from './proptypes';
10
10
  import { retrieveStyle } from './theme';
11
11
  import styles from './styles';
12
12
 
13
13
  const UTCheckBox = ({
14
- checked,
14
+ value,
15
+ onChange,
15
16
  disabled,
16
17
  indeterminate,
17
18
  isSimple,
18
- onPress,
19
19
  required,
20
20
  reversed,
21
21
  spacing,
22
22
  style,
23
23
  title,
24
- variant
24
+ variant,
25
+ withMarkdown
25
26
  }) => {
26
27
  const theme = useTheme();
27
28
  const [pressed, setPressed] = useState(false);
@@ -29,7 +30,7 @@ const UTCheckBox = ({
29
30
  const { containerStyles, iconContainerStyles, boxStyles, pressableStyles, titleStyles } = useMemo(
30
31
  () =>
31
32
  retrieveStyle({
32
- checked,
33
+ checked: value,
33
34
  disabled,
34
35
  indeterminate,
35
36
  pressed,
@@ -39,33 +40,36 @@ const UTCheckBox = ({
39
40
  theme,
40
41
  variant
41
42
  }),
42
- [checked, disabled, indeterminate, reversed, spacing, style, theme, variant, pressed]
43
+ [value, disabled, indeterminate, reversed, spacing, style, theme, variant, pressed]
43
44
  );
44
45
 
45
46
  const iconName = useMemo(
46
- () => (indeterminate ? INDETERMINATE_ICON : checked ? CHECKED_ICON : ''),
47
- [indeterminate, checked]
47
+ () => (indeterminate ? INDETERMINATE_ICON : value ? CHECKED_ICON : ''),
48
+ [indeterminate, value]
48
49
  );
49
50
 
50
51
  const handlePressIn = useCallback(() => setPressed(true), []);
51
52
  const handlePressOut = useCallback(() => setPressed(false), []);
52
53
 
54
+ const handlePress = useCallback(() => {
55
+ if (!disabled && onChange) {
56
+ onChange(!value);
57
+ }
58
+ }, [disabled, onChange, value]);
59
+
60
+ const shouldHighlightLabel = value && variant === BUTTON_VARIANT;
61
+
53
62
  return (
54
63
  <Pressable
55
64
  style={pressableStyles}
56
65
  disabled={disabled}
57
- onPress={onPress}
66
+ onPress={handlePress}
58
67
  onPressIn={handlePressIn}
59
68
  onPressOut={handlePressOut}
60
69
  >
61
70
  <View style={containerStyles}>
62
71
  {isSimple ? (
63
- <UTIcon
64
- name="IconCheck"
65
- shade="04"
66
- colorTheme="accent"
67
- style={checked ? undefined : styles.hidden}
68
- />
72
+ <UTIcon name="IconCheck" shade="04" colorTheme="accent" style={value ? undefined : styles.hidden} />
69
73
  ) : (
70
74
  <View style={boxStyles}>
71
75
  <View style={iconContainerStyles}>
@@ -73,7 +77,12 @@ const UTCheckBox = ({
73
77
  </View>
74
78
  </View>
75
79
  )}
76
- <UTFieldLabel colorTheme={checked ? 'accent' : 'dark'} required={required} style={titleStyles}>
80
+ <UTFieldLabel
81
+ colorTheme={shouldHighlightLabel ? 'accent' : 'dark'}
82
+ required={required}
83
+ style={titleStyles}
84
+ withMarkdown={withMarkdown}
85
+ >
77
86
  {title}
78
87
  </UTFieldLabel>
79
88
  </View>
@@ -1,6 +1,4 @@
1
- import { BUTTON_VARIANT } from '../UTCheckList/constants';
2
-
3
- import { SPACING } from './constants';
1
+ import { BUTTON_VARIANT, SPACING } from './constants';
4
2
 
5
3
  const NORMAL_SPACING = 16;
6
4
  const SMALL_SPACING = 8;
@@ -2,5 +2,3 @@ export const SPACING = {
2
2
  SMALL: 'small',
3
3
  LARGE: 'large'
4
4
  };
5
-
6
- export const BUTTON_VARIANT = 'button';
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useCallback, useMemo } from 'react';
2
2
  import { View } from 'react-native';
3
3
 
4
+ import { BUTTON_VARIANT } from '../UTCheckBox/constants';
4
5
  import { formatErrorToValidation } from '../UTValidation/utils';
5
6
  import UTCheckBox from '../UTCheckBox';
6
7
  import UTFieldLabel from '../UTFieldLabel';
@@ -9,7 +10,7 @@ import UTValidation from '../UTValidation';
9
10
  import { keyExtractor, isChecked, convertIfIsString, getPropValueBasedOnVariant } from './utils';
10
11
  import styles from './styles';
11
12
  import { defaultProps, propTypes } from './proptypes';
12
- import { BUTTON_VARIANT, SPACING } from './constants';
13
+ import { SPACING } from './constants';
13
14
 
14
15
  const UTCheckList = ({
15
16
  error,
@@ -54,7 +55,7 @@ const UTCheckList = ({
54
55
  );
55
56
 
56
57
  const handleChange = useCallback(
57
- receivedValue => () => {
58
+ receivedValue => {
58
59
  if (isSimple) {
59
60
  onChange([receivedValue]);
60
61
  } else {
@@ -89,10 +90,10 @@ const UTCheckList = ({
89
90
  >
90
91
  {showSelectAll && !isSimple && (
91
92
  <UTCheckBox
92
- checked={areAllSelected}
93
+ value={areAllSelected}
93
94
  indeterminate={isIndeterminate}
94
95
  title={selectAllLabel}
95
- onPress={handleCheckAll}
96
+ onChange={handleCheckAll}
96
97
  reversed={reversedBasedOnVariant}
97
98
  spacing={horizontalSpacing}
98
99
  style={style.selectAll}
@@ -102,11 +103,11 @@ const UTCheckList = ({
102
103
  {options?.map((item, index) => (
103
104
  <UTCheckBox
104
105
  isSimple={isSimple}
105
- checked={isChecked(item, value)}
106
+ value={isChecked(item, value)}
106
107
  disabled={item.disabled}
107
108
  key={keyExtractor(item, index)}
108
109
  title={item.label}
109
- onPress={handleChange(item.value)}
110
+ onChange={() => handleChange(item.value)}
110
111
  reversed={reversedBasedOnVariant}
111
112
  spacing={horizontalSpacing}
112
113
  style={style.item}
@@ -11,7 +11,8 @@ export default StyleSheet.create({
11
11
  },
12
12
  checkboxesContainer: {
13
13
  alignSelf: 'flex-start',
14
- rowGap: SPACING.LARGE
14
+ rowGap: SPACING.LARGE,
15
+ width: '100%'
15
16
  },
16
17
  container: {
17
18
  rowGap: SPACING.LARGE
@@ -1,11 +1,11 @@
1
1
  import { isString } from 'lodash';
2
2
 
3
- import { BUTTON_VARIANT } from './constants';
3
+ import { BUTTON_VARIANT } from '../UTCheckBox/constants';
4
4
 
5
5
  export const keyExtractor = (_, index) => `CB-${index}`;
6
6
 
7
7
  export const isChecked = (item, inputValue) =>
8
- !!inputValue?.find(elem => elem === item.value) || (item.disabled && item.checked);
8
+ (inputValue && !!inputValue?.find(elem => elem === item.value)) || (item.disabled && item.checked);
9
9
 
10
10
  export const convertIfIsString = value =>
11
11
  isString(value) ? (value.length === 0 ? [] : JSON.parse(value.replace(/'/g, '"'))) : value;
@@ -7,9 +7,9 @@ import UTLabel from '../UTLabel';
7
7
  import { REQUIRED_LABEL } from './constants';
8
8
  import styles from './styles';
9
9
 
10
- const UTFieldLabel = ({ children, colorTheme, required, style, variant, weight }) => (
10
+ const UTFieldLabel = ({ children, colorTheme, required, style, variant, weight, withMarkdown }) => (
11
11
  <View style={[styles.label, style]}>
12
- <UTLabel colorTheme={colorTheme} variant={variant}>
12
+ <UTLabel colorTheme={colorTheme} variant={variant} withMarkdown={withMarkdown}>
13
13
  {children}
14
14
  </UTLabel>
15
15
  {required && (
@@ -24,7 +24,8 @@ UTFieldLabel.propTypes = {
24
24
  colorTheme: string,
25
25
  required: bool,
26
26
  variant: string,
27
- weight: string
27
+ weight: string,
28
+ withMarkdown: bool
28
29
  };
29
30
 
30
31
  export default UTFieldLabel;
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.27.0",
5
+ "version": "1.27.1",
6
6
  "repository": "https://github.com/widergy/mobile-ui.git",
7
7
  "main": "lib/index.js",
8
8
  "files": [