@widergy/mobile-ui 1.13.2 → 1.13.4
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 +14 -0
- package/lib/components/Button/index.js +4 -0
- package/lib/components/Icon/{assets → components/CustomIcon/assets}/eye-off.svg +1 -1
- package/lib/components/Icon/{assets → components/CustomIcon/assets}/eye.svg +1 -1
- package/lib/components/Icon/components/CustomIcon/constants.js +9 -0
- package/lib/components/Icon/components/CustomIcon/index.js +25 -0
- package/lib/components/Icon/constants.js +3 -5
- package/lib/components/Icon/index.js +6 -1
- package/lib/components/IconButton/index.js +4 -0
- package/lib/components/Label/index.js +4 -0
- package/lib/components/UTCheckBox/README.md +66 -0
- package/lib/components/UTCheckBox/constants.js +2 -0
- package/lib/components/UTCheckBox/index.js +45 -0
- package/lib/components/UTCheckBox/proptypes.js +21 -0
- package/lib/components/UTCheckBox/theme.js +72 -0
- package/lib/components/UTCheckList/README.MD +101 -0
- package/lib/components/UTCheckList/index.js +150 -0
- package/lib/components/UTCheckList/styles.js +23 -0
- package/lib/components/UTCheckList/utils.js +4 -0
- package/lib/components/UTLoading/components/Spinner/styles.js +3 -0
- package/lib/components/UTRequiredLabel/constants.js +1 -0
- package/lib/components/UTRequiredLabel/index.js +31 -0
- package/lib/components/UTRequiredLabel/styles.js +7 -0
- package/lib/components/UTTextInput/versions/V0/components/BaseInput/index.js +20 -8
- package/lib/components/UTTextInput/versions/V1/components/TextInputField/index.js +3 -0
- package/lib/components/UTTextInput/versions/V1/constants.js +0 -2
- package/lib/components/UTTextInput/versions/V1/index.js +5 -11
- package/lib/components/UTTextInput/versions/V1/styles.js +0 -3
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.13.4](https://github.com/widergy/mobile-ui/compare/v1.13.3...v1.13.4) (2024-07-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add UTCheckBox and UTCheckList ([#304](https://github.com/widergy/mobile-ui/issues/304)) ([edf9c95](https://github.com/widergy/mobile-ui/commit/edf9c95122a765b41e3b8f1031f6c8a34b8e8085))
|
|
7
|
+
|
|
8
|
+
## [1.13.3](https://github.com/widergy/mobile-ui/compare/v1.13.2...v1.13.3) (2024-07-17)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* some fixes in icon ([#311](https://github.com/widergy/mobile-ui/issues/311)) ([9d57432](https://github.com/widergy/mobile-ui/commit/9d57432197c15b3200a6b1dafe982dc37c54cb5c))
|
|
14
|
+
|
|
1
15
|
## [1.13.2](https://github.com/widergy/mobile-ui/compare/v1.13.1...v1.13.2) (2024-07-15)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -105,4 +105,8 @@ Button.displayName = 'Button';
|
|
|
105
105
|
|
|
106
106
|
Button.propTypes = propTypes;
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated The Button component is deprecated and will be removed in a future release.
|
|
110
|
+
* Please use the UTButton component instead.
|
|
111
|
+
*/
|
|
108
112
|
export default withTheme(Button);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
2
|
<g id="eye-off">
|
|
3
|
-
<path id="Vector (Stroke)" fill-rule="evenodd" clip-rule="evenodd" d="M1.91078 1.91058C2.23622 1.58514 2.76386 1.58514 3.0893 1.91058L14.9861 13.8074C15.0321 13.8444 15.0748 13.8867 15.113 13.9343L18.0893 16.9106C18.4147 17.236 18.4147 17.7637 18.0893 18.0891C17.7639 18.4145 17.2362 18.4145 16.9108 18.0891L14.3384 15.5167C13.0039 16.2804 11.5544 16.6665 10 16.6665C6.2667 16.6665 3.25604 14.4606 0.943181 10.4133C0.796755 10.1571 0.796773 9.8425 0.943227 9.58629C1.92481 7.86906 3.03083 6.48078 4.27262 5.45092L1.91078 3.08909C1.58535 2.76366 1.58535 2.23602 1.91078 1.91058ZM5.45722 6.63553C4.45474 7.43811 3.5102 8.55088 2.63331 9.99993C4.71491 13.442 7.17738 14.9998 10 14.9998C11.1045 14.9998 12.1366 14.763 13.1068 14.2851L11.0783 12.2566C10.744 12.4166 10.3751 12.502 9.99748 12.5018C9.33435 12.5016 8.69848 12.2379 8.22974 11.7689C7.761 11.2998 7.4978 10.6637 7.49803 10.0006C7.49816 9.62354 7.58346 9.25529 7.74327 8.92157L5.45722 6.63553ZM9.3635 10.5418C9.37784 10.5587 9.39291 10.575 9.40867 10.5908C9.42457 10.6067 9.44104 10.6219 9.45805 10.6364L9.3635 10.5418ZM9.99709 4.99983C9.33243 4.99748 8.67077 5.08906 8.03173 5.27186C7.58925 5.39845 7.12792 5.14235 7.00134 4.69986C6.87476 4.25738 7.13086 3.79605 7.57335 3.66947C8.36287 3.44362 9.18033 3.3304 10.0015 3.33317C13.7342 3.33375 16.7443 5.53961 19.0569 9.58637C19.2033 9.84261 19.2033 10.1572 19.0568 10.4134C18.3832 11.5918 17.6523 12.6144 16.8595 13.4721C16.5471 13.8101 16.0199 13.8309 15.6819 13.5185C15.3439 13.2061 15.3232 12.6789 15.6356 12.3409C16.2384 11.6886 16.8161 10.9099 17.3668 9.99975C15.2852 6.55771 12.8227 4.99984 10 4.99984L9.99709 4.99983Z"
|
|
3
|
+
<path id="Vector (Stroke)" fill-rule="evenodd" clip-rule="evenodd" d="M1.91078 1.91058C2.23622 1.58514 2.76386 1.58514 3.0893 1.91058L14.9861 13.8074C15.0321 13.8444 15.0748 13.8867 15.113 13.9343L18.0893 16.9106C18.4147 17.236 18.4147 17.7637 18.0893 18.0891C17.7639 18.4145 17.2362 18.4145 16.9108 18.0891L14.3384 15.5167C13.0039 16.2804 11.5544 16.6665 10 16.6665C6.2667 16.6665 3.25604 14.4606 0.943181 10.4133C0.796755 10.1571 0.796773 9.8425 0.943227 9.58629C1.92481 7.86906 3.03083 6.48078 4.27262 5.45092L1.91078 3.08909C1.58535 2.76366 1.58535 2.23602 1.91078 1.91058ZM5.45722 6.63553C4.45474 7.43811 3.5102 8.55088 2.63331 9.99993C4.71491 13.442 7.17738 14.9998 10 14.9998C11.1045 14.9998 12.1366 14.763 13.1068 14.2851L11.0783 12.2566C10.744 12.4166 10.3751 12.502 9.99748 12.5018C9.33435 12.5016 8.69848 12.2379 8.22974 11.7689C7.761 11.2998 7.4978 10.6637 7.49803 10.0006C7.49816 9.62354 7.58346 9.25529 7.74327 8.92157L5.45722 6.63553ZM9.3635 10.5418C9.37784 10.5587 9.39291 10.575 9.40867 10.5908C9.42457 10.6067 9.44104 10.6219 9.45805 10.6364L9.3635 10.5418ZM9.99709 4.99983C9.33243 4.99748 8.67077 5.08906 8.03173 5.27186C7.58925 5.39845 7.12792 5.14235 7.00134 4.69986C6.87476 4.25738 7.13086 3.79605 7.57335 3.66947C8.36287 3.44362 9.18033 3.3304 10.0015 3.33317C13.7342 3.33375 16.7443 5.53961 19.0569 9.58637C19.2033 9.84261 19.2033 10.1572 19.0568 10.4134C18.3832 11.5918 17.6523 12.6144 16.8595 13.4721C16.5471 13.8101 16.0199 13.8309 15.6819 13.5185C15.3439 13.2061 15.3232 12.6789 15.6356 12.3409C16.2384 11.6886 16.8161 10.9099 17.3668 9.99975C15.2852 6.55771 12.8227 4.99984 10 4.99984L9.99709 4.99983Z" />
|
|
4
4
|
</g>
|
|
5
5
|
</svg>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.15986 12C5.65779 16.1305 8.61278 18 12 18C15.3872 18 18.3422 16.1305 20.8401 12C18.3422 7.86948 15.3872 6 12 6C8.61278 6 5.65779 7.86948 3.15986 12ZM1.13177 11.5038C3.9072 6.64709 7.51999 4 12 4C16.48 4 20.0928 6.64709 22.8682 11.5038C23.0439 11.8113 23.0439 12.1887 22.8682 12.4962C20.0928 17.3529 16.48 20 12 20C7.51999 20 3.9072 17.3529 1.13177 12.4962C0.956077 12.1887 0.956077 11.8113 1.13177 11.5038ZM12 11C11.4477 11 11 11.4477 11 12C11 12.5523 11.4477 13 12 13C12.5523 13 13 12.5523 13 12C13 11.4477 12.5523 11 12 11ZM9 12C9 10.3431 10.3431 9 12 9C13.6569 9 15 10.3431 15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12Z"
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.15986 12C5.65779 16.1305 8.61278 18 12 18C15.3872 18 18.3422 16.1305 20.8401 12C18.3422 7.86948 15.3872 6 12 6C8.61278 6 5.65779 7.86948 3.15986 12ZM1.13177 11.5038C3.9072 6.64709 7.51999 4 12 4C16.48 4 20.0928 6.64709 22.8682 11.5038C23.0439 11.8113 23.0439 12.1887 22.8682 12.4962C20.0928 17.3529 16.48 20 12 20C7.51999 20 3.9072 17.3529 1.13177 12.4962C0.956077 12.1887 0.956077 11.8113 1.13177 11.5038ZM12 11C11.4477 11 11 11.4477 11 12C11 12.5523 11.4477 13 12 13C12.5523 13 13 12.5523 13 12C13 11.4477 12.5523 11 12 11ZM9 12C9 10.3431 10.3431 9 12 9C13.6569 9 15 10.3431 15 12C15 13.6569 13.6569 15 12 15C10.3431 15 9 13.6569 9 12Z" />
|
|
3
3
|
</svg>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { string, number } from 'prop-types';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
import { CUSTOM_ICONS, DEFAULT_ICON_SIZE } from './constants';
|
|
5
|
+
|
|
6
|
+
const CustomIcon = ({ height, name, size, width, fill = '#677489' }) => {
|
|
7
|
+
const CustomIconComponent = CUSTOM_ICONS[name];
|
|
8
|
+
return (
|
|
9
|
+
<CustomIconComponent
|
|
10
|
+
height={size || height || DEFAULT_ICON_SIZE}
|
|
11
|
+
width={size || width || DEFAULT_ICON_SIZE}
|
|
12
|
+
fill={fill}
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
CustomIcon.propTypes = {
|
|
18
|
+
height: number,
|
|
19
|
+
name: string,
|
|
20
|
+
size: number,
|
|
21
|
+
width: number,
|
|
22
|
+
fill: string
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default CustomIcon;
|
|
@@ -11,8 +11,7 @@ import SimpleLineIcon from 'react-native-vector-icons/SimpleLineIcons';
|
|
|
11
11
|
import FeatherIcon from 'react-native-vector-icons/Feather';
|
|
12
12
|
import AntIcon from 'react-native-vector-icons/AntDesign';
|
|
13
13
|
|
|
14
|
-
import
|
|
15
|
-
import Visibility from './assets/eye.svg';
|
|
14
|
+
import CustomIcon from './components/CustomIcon';
|
|
16
15
|
|
|
17
16
|
const DEFAULT_ICON_COMPONENT = MaterialIcon;
|
|
18
17
|
export const DEFAULT_ICON_TYPE = 'material';
|
|
@@ -29,9 +28,8 @@ const ICON_TYPES = {
|
|
|
29
28
|
'material-community': MaterialCommunityIcon,
|
|
30
29
|
octicon: OcticonIcon,
|
|
31
30
|
'simple-line-icon': SimpleLineIcon,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
zocial: ZocialIcon
|
|
31
|
+
zocial: ZocialIcon,
|
|
32
|
+
custom: CustomIcon
|
|
35
33
|
};
|
|
36
34
|
|
|
37
35
|
export const getIconComponent = type => ICON_TYPES[type] || DEFAULT_ICON_COMPONENT;
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import propTypes from './propTypes';
|
|
4
4
|
import { getIconComponent, DEFAULT_ICON_TYPE, DEFAULT_ICON_SIZE } from './constants';
|
|
5
5
|
|
|
6
|
-
const Icon = ({ color, height, name, size, style, type, width }) => {
|
|
6
|
+
const Icon = ({ color, height, name, size, style, type, width, fill }) => {
|
|
7
7
|
const IconComponent = getIconComponent(type);
|
|
8
8
|
return (
|
|
9
9
|
<IconComponent
|
|
@@ -14,6 +14,7 @@ const Icon = ({ color, height, name, size, style, type, width }) => {
|
|
|
14
14
|
style={style}
|
|
15
15
|
type={type}
|
|
16
16
|
width={size || width || DEFAULT_ICON_SIZE}
|
|
17
|
+
fill={fill}
|
|
17
18
|
/>
|
|
18
19
|
);
|
|
19
20
|
};
|
|
@@ -24,4 +25,8 @@ Icon.defaultProps = {
|
|
|
24
25
|
type: DEFAULT_ICON_TYPE
|
|
25
26
|
};
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated The Icon component is deprecated and will be removed in a future release.
|
|
30
|
+
* Please use the UTIcon component instead.
|
|
31
|
+
*/
|
|
27
32
|
export default Icon;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# UTCheckBox
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTCheckBox` is a checkbox component used within the `UTCheckList` component. It supports various states such as checked, indeterminate, and disabled, and can be customized with labels and styles.
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| ------------- | ------------ | ------- | ------------------------------------------------------- |
|
|
11
|
+
| checked | bool | false | Indicates if the checkbox is checked. |
|
|
12
|
+
| disabled | bool | false | Disables the checkbox, making it unclickable. |
|
|
13
|
+
| indeterminate | bool | false | Indicates if the checkbox is in an indeterminate state. |
|
|
14
|
+
| label | string | | Label to display next to the checkbox. |
|
|
15
|
+
| onPress | func | | Function to call when the checkbox is pressed. |
|
|
16
|
+
| reversed | bool | false | If true, reverses the order of label and checkbox. |
|
|
17
|
+
| style | shape | {} | Custom styles to apply to the checkbox. Can contain `root`, `icon`, `touchable`. |
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Basic Example
|
|
22
|
+
|
|
23
|
+
```jsx
|
|
24
|
+
import React from 'react';
|
|
25
|
+
import UTCheckBox from './UTCheckBox';
|
|
26
|
+
|
|
27
|
+
const Example = () => {
|
|
28
|
+
const [checked, setChecked] = React.useState(false);
|
|
29
|
+
|
|
30
|
+
return <UTCheckBox checked={checked} label="Check me" onPress={() => setChecked(!checked)} />;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default Example;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
### Custom Styles Example
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
import React from 'react';
|
|
40
|
+
import UTCheckBox from './UTCheckBox';
|
|
41
|
+
|
|
42
|
+
const customStyles = {
|
|
43
|
+
root: { padding: 10 },
|
|
44
|
+
icon: { backgroundColor: 'lightgrey' },
|
|
45
|
+
touchable: {
|
|
46
|
+
root: { margin: 5 },
|
|
47
|
+
pressed: { opacity: 0.5 }
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const Example = () => {
|
|
52
|
+
const [checked, setChecked] = React.useState(false);
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<UTCheckBox
|
|
56
|
+
checked={checked}
|
|
57
|
+
label="Check me"
|
|
58
|
+
onPress={() => setChecked(!checked)}
|
|
59
|
+
style={customStyles}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default Example;
|
|
65
|
+
|
|
66
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Pressable } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { useTheme } from '../../theming';
|
|
5
|
+
import UTIcon from '../UTIcon';
|
|
6
|
+
import UTLabel from '../UTLabel';
|
|
7
|
+
|
|
8
|
+
import { CHECKED_ICON, INDETERMINATE_ICON } from './constants';
|
|
9
|
+
import { retrieveStyle } from './theme';
|
|
10
|
+
import propTypes from './proptypes';
|
|
11
|
+
|
|
12
|
+
const UTCheckBox = ({ checked, disabled, indeterminate, label, onPress, reversed, style }) => {
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
const { containerStyles, iconContainerStyles, touchableStyles } = retrieveStyle({
|
|
15
|
+
checked,
|
|
16
|
+
disabled,
|
|
17
|
+
indeterminate,
|
|
18
|
+
reversed,
|
|
19
|
+
style,
|
|
20
|
+
theme
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const combinedTouchableStyles = ({ pressed }) => [touchableStyles.root, pressed && touchableStyles.pressed];
|
|
24
|
+
|
|
25
|
+
const iconName = indeterminate ? INDETERMINATE_ICON : checked ? CHECKED_ICON : '';
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<View style={containerStyles}>
|
|
29
|
+
<Pressable disabled={disabled} onPress={onPress} style={combinedTouchableStyles}>
|
|
30
|
+
<View style={iconContainerStyles}>
|
|
31
|
+
<UTIcon color="light" name={iconName} size={16} />
|
|
32
|
+
</View>
|
|
33
|
+
</Pressable>
|
|
34
|
+
<UTLabel>{label}</UTLabel>
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
UTCheckBox.defaultProps = {
|
|
40
|
+
style: {}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
UTCheckBox.propTypes = propTypes;
|
|
44
|
+
|
|
45
|
+
export default UTCheckBox;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { bool, func, shape, string } from 'prop-types';
|
|
2
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
3
|
+
|
|
4
|
+
export const styleProptypes = shape({
|
|
5
|
+
root: ViewPropTypes.style,
|
|
6
|
+
icon: ViewPropTypes.style,
|
|
7
|
+
touchable: shape({
|
|
8
|
+
root: ViewPropTypes.style,
|
|
9
|
+
pressed: ViewPropTypes.style
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
checked: bool,
|
|
15
|
+
disabled: bool,
|
|
16
|
+
indeterminate: bool,
|
|
17
|
+
label: string,
|
|
18
|
+
onPress: func,
|
|
19
|
+
reversed: bool,
|
|
20
|
+
style: styleProptypes
|
|
21
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const baseCheckBoxTheme = theme => ({
|
|
2
|
+
container: {
|
|
3
|
+
alignItems: 'center',
|
|
4
|
+
columnGap: 16,
|
|
5
|
+
flexDirection: 'row',
|
|
6
|
+
justifyContent: 'flex-start'
|
|
7
|
+
},
|
|
8
|
+
iconContainer: {
|
|
9
|
+
borderColor: theme.Palette.gray['04'],
|
|
10
|
+
borderRadius: 5,
|
|
11
|
+
borderWidth: 2,
|
|
12
|
+
height: 20,
|
|
13
|
+
width: 20
|
|
14
|
+
},
|
|
15
|
+
touchable: {
|
|
16
|
+
root: {
|
|
17
|
+
borderRadius: 25,
|
|
18
|
+
padding: 6
|
|
19
|
+
},
|
|
20
|
+
pressed: {
|
|
21
|
+
backgroundColor: theme.Palette.accent['02'],
|
|
22
|
+
borderColor: theme.Palette.accent['03'],
|
|
23
|
+
borderWidth: 1,
|
|
24
|
+
padding: 5
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const conditionalContainerStyle = (reversed, disabled) => ({
|
|
30
|
+
...(reversed && {
|
|
31
|
+
flexDirection: 'row-reverse'
|
|
32
|
+
}),
|
|
33
|
+
...(disabled && {
|
|
34
|
+
opacity: 0.5
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const conditionalIconContainerStyle = (checked, indeterminate, theme) => ({
|
|
39
|
+
...((checked || indeterminate) && {
|
|
40
|
+
backgroundColor: theme.Palette.accent['04'],
|
|
41
|
+
borderColor: theme.Palette.accent['04']
|
|
42
|
+
})
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
export const retrieveStyle = ({ checked, disabled, indeterminate, reversed, style = {}, theme }) => {
|
|
46
|
+
const baseTheme = baseCheckBoxTheme(theme);
|
|
47
|
+
|
|
48
|
+
const containerStyles = {
|
|
49
|
+
...baseTheme.container,
|
|
50
|
+
...conditionalContainerStyle(reversed, disabled),
|
|
51
|
+
...style.root
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const iconContainerStyles = {
|
|
55
|
+
...baseTheme.iconContainer,
|
|
56
|
+
...conditionalIconContainerStyle(checked, indeterminate, theme),
|
|
57
|
+
...style.icon
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const touchableStyles = {
|
|
61
|
+
root: {
|
|
62
|
+
...baseTheme.touchable.root,
|
|
63
|
+
...style.touchable?.root
|
|
64
|
+
},
|
|
65
|
+
pressed: {
|
|
66
|
+
...baseTheme.touchable.pressed,
|
|
67
|
+
...style.touchable?.pressed
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return { containerStyles, iconContainerStyles, touchableStyles };
|
|
72
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# UTCheckList
|
|
2
|
+
|
|
3
|
+
## Description
|
|
4
|
+
|
|
5
|
+
`UTCheckList` is a customizable component that renders a list of checkboxes, allowing users to select multiple options from a provided list. It supports features like select all, indeterminate state, error display, and dynamic options. The "Select All" checkbox only affects options that are not disabled.
|
|
6
|
+
|
|
7
|
+
## Props
|
|
8
|
+
|
|
9
|
+
| Name | Type | Default | Description |
|
|
10
|
+
| -------------- | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| error | string | | Error message to display. |
|
|
12
|
+
| input | shape | | Input configuration object containing `value` and `onChange`. |
|
|
13
|
+
| label | string | | Label for the checklist. |
|
|
14
|
+
| options | array | | Array of options to be displayed as checkboxes. Each option is an object with `label` and `value`. |
|
|
15
|
+
| required | bool | false | Indicates if the checklist is required. |
|
|
16
|
+
| reversed | bool | false | If true, reverses the order of label and checkbox. |
|
|
17
|
+
| selectAllLabel | string | | Label for the "Select All" checkbox. |
|
|
18
|
+
| style | shape | {} | Custom styles to apply to the checklist. Can contain `root`, `header`, `checkboxesContainer`, `item`, and `selectAll`. |
|
|
19
|
+
|
|
20
|
+
### Input Object
|
|
21
|
+
|
|
22
|
+
The `input` prop is an object that should contain the following keys:
|
|
23
|
+
|
|
24
|
+
| Name | Type | Description |
|
|
25
|
+
| -------- | --------------- | -------------------------------------------- |
|
|
26
|
+
| value | arrayOf(string) | Array of selected values. |
|
|
27
|
+
| onChange | func | Function to call when the selection changes. |
|
|
28
|
+
|
|
29
|
+
### Option Object
|
|
30
|
+
|
|
31
|
+
The `options` prop is an array of objects, each representing an option:
|
|
32
|
+
|
|
33
|
+
| Name | Type | Description |
|
|
34
|
+
| -------- | ------ | ------------------------------------ |
|
|
35
|
+
| checked | bool | Indicates if the option is checked. |
|
|
36
|
+
| disabled | bool | Indicates if the option is disabled. |
|
|
37
|
+
| label | string | Label to display for the option. |
|
|
38
|
+
| value | string | Value of the option. |
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
### Basic Example
|
|
43
|
+
|
|
44
|
+
```jsx
|
|
45
|
+
import React from 'react';
|
|
46
|
+
import UTCheckList from './UTCheckList';
|
|
47
|
+
|
|
48
|
+
const options = [
|
|
49
|
+
{ label: 'Option 1', value: '1' },
|
|
50
|
+
{ label: 'Option 2', value: '2' },
|
|
51
|
+
{ label: 'Option 3', value: '3', disabled: true, checked: true }
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
const Example = () => {
|
|
55
|
+
const [selectedOptions, setSelectedOptions] = React.useState([]);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<UTCheckList
|
|
59
|
+
label="Select Options"
|
|
60
|
+
options={options}
|
|
61
|
+
input={{
|
|
62
|
+
value: selectedOptions,
|
|
63
|
+
onChange: setSelectedOptions
|
|
64
|
+
}}
|
|
65
|
+
selectAllLabel="Select All"
|
|
66
|
+
required
|
|
67
|
+
error="Please select at least one option"
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export default Example;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Custom Styles Example
|
|
76
|
+
|
|
77
|
+
```jsx
|
|
78
|
+
import React from 'react';
|
|
79
|
+
import UTCheckBox from './UTCheckBox';
|
|
80
|
+
|
|
81
|
+
const customStyles = {
|
|
82
|
+
root: { padding: 10 },
|
|
83
|
+
iconContainer: { backgroundColor: 'lightgrey' },
|
|
84
|
+
label: { color: 'blue' }
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const Example = () => {
|
|
88
|
+
const [checked, setChecked] = React.useState(false);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<UTCheckBox
|
|
92
|
+
checked={checked}
|
|
93
|
+
label="Check me"
|
|
94
|
+
onPress={() => setChecked(!checked)}
|
|
95
|
+
style={customStyles}
|
|
96
|
+
/>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default Example;
|
|
101
|
+
```
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import React, { useEffect, useCallback, useMemo, Fragment } from 'react';
|
|
2
|
+
import { arrayOf, bool, func, shape, string } from 'prop-types';
|
|
3
|
+
import { isEmpty } from '@widergy/web-utils/lib/array';
|
|
4
|
+
import { isString } from 'lodash';
|
|
5
|
+
import { View } from 'react-native';
|
|
6
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
7
|
+
|
|
8
|
+
import { styleProptypes as checboxStyleProptypes } from '../UTCheckBox/proptypes';
|
|
9
|
+
import UTCheckBox from '../UTCheckBox';
|
|
10
|
+
import UTLabel from '../UTLabel';
|
|
11
|
+
import UTRequiredLabel from '../UTRequiredLabel';
|
|
12
|
+
|
|
13
|
+
import { keyExtractor, isChecked } from './utils';
|
|
14
|
+
import styles from './styles';
|
|
15
|
+
|
|
16
|
+
const UTCheckList = ({
|
|
17
|
+
error,
|
|
18
|
+
input,
|
|
19
|
+
label,
|
|
20
|
+
options,
|
|
21
|
+
required,
|
|
22
|
+
reversed,
|
|
23
|
+
selectAllLabel,
|
|
24
|
+
showSelectAll,
|
|
25
|
+
style
|
|
26
|
+
}) => {
|
|
27
|
+
const convertIfIsString = value =>
|
|
28
|
+
isString(value) ? (value.length === 0 ? [] : JSON.parse(value.replace(/'/g, '"'))) : value;
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const convertedValue = convertIfIsString(input.value);
|
|
32
|
+
if (JSON.stringify(convertedValue) !== JSON.stringify(input.value)) {
|
|
33
|
+
input.onChange(convertedValue);
|
|
34
|
+
}
|
|
35
|
+
}, [input.value, input]);
|
|
36
|
+
|
|
37
|
+
const enabledOptions = useMemo(() => options.filter(option => !option.disabled), [options]);
|
|
38
|
+
|
|
39
|
+
const areAllSelected = useMemo(
|
|
40
|
+
() => enabledOptions.every(option => input.value?.includes(option.value)),
|
|
41
|
+
[enabledOptions, input.value]
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
const isIndeterminate = useMemo(
|
|
45
|
+
() => enabledOptions.some(option => input.value?.includes(option.value)) && !areAllSelected,
|
|
46
|
+
[enabledOptions, input.value, areAllSelected]
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const handleChange = useCallback(
|
|
50
|
+
receivedValue => () => {
|
|
51
|
+
const { onChange, value } = input;
|
|
52
|
+
const newValues = !value?.find?.(elem => elem === receivedValue)
|
|
53
|
+
? [...(value || []), receivedValue]
|
|
54
|
+
: value?.filter(elem => elem !== receivedValue);
|
|
55
|
+
if (onChange) onChange(isEmpty(newValues) ? [] : newValues);
|
|
56
|
+
},
|
|
57
|
+
[input]
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleCheckAll = () => {
|
|
61
|
+
if (!areAllSelected && options) {
|
|
62
|
+
input.onChange(enabledOptions.map(item => item.value));
|
|
63
|
+
} else {
|
|
64
|
+
input.onChange([]);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<View style={[styles.container, style.root]}>
|
|
70
|
+
<View style={[styles.headerContainer, style.header]}>
|
|
71
|
+
{label && <UTRequiredLabel required={required}>{label}</UTRequiredLabel>}
|
|
72
|
+
{error && (
|
|
73
|
+
<UTLabel colorTheme="error" variant="small">
|
|
74
|
+
{error}
|
|
75
|
+
</UTLabel>
|
|
76
|
+
)}
|
|
77
|
+
</View>
|
|
78
|
+
<View
|
|
79
|
+
style={[
|
|
80
|
+
styles.checkboxesContainer,
|
|
81
|
+
reversed && styles.reversedCheckBoxesContainer,
|
|
82
|
+
style.checkboxesContainer
|
|
83
|
+
]}
|
|
84
|
+
>
|
|
85
|
+
{showSelectAll && (
|
|
86
|
+
<UTCheckBox
|
|
87
|
+
checked={areAllSelected}
|
|
88
|
+
indeterminate={isIndeterminate}
|
|
89
|
+
label={selectAllLabel}
|
|
90
|
+
onPress={handleCheckAll}
|
|
91
|
+
reversed={reversed}
|
|
92
|
+
style={style.selectAll}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
{!!options?.length &&
|
|
96
|
+
options.map((item, index) => {
|
|
97
|
+
const { label: itemLabel, disabled, value } = item;
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<Fragment key={keyExtractor(item, index)}>
|
|
101
|
+
<UTCheckBox
|
|
102
|
+
checked={isChecked(item, input.value)}
|
|
103
|
+
disabled={disabled}
|
|
104
|
+
label={itemLabel}
|
|
105
|
+
onPress={handleChange(value)}
|
|
106
|
+
reversed={reversed}
|
|
107
|
+
style={style.item}
|
|
108
|
+
/>
|
|
109
|
+
</Fragment>
|
|
110
|
+
);
|
|
111
|
+
})}
|
|
112
|
+
</View>
|
|
113
|
+
</View>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
UTCheckList.defaultProps = {
|
|
118
|
+
showSelectAll: true,
|
|
119
|
+
style: {}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
UTCheckList.propTypes = {
|
|
123
|
+
error: string,
|
|
124
|
+
label: string,
|
|
125
|
+
input: shape({
|
|
126
|
+
value: arrayOf(string),
|
|
127
|
+
onChange: func
|
|
128
|
+
}),
|
|
129
|
+
options: arrayOf(
|
|
130
|
+
shape({
|
|
131
|
+
checked: bool,
|
|
132
|
+
disabled: bool,
|
|
133
|
+
label: string,
|
|
134
|
+
value: string
|
|
135
|
+
})
|
|
136
|
+
),
|
|
137
|
+
required: bool,
|
|
138
|
+
reversed: bool,
|
|
139
|
+
selectAllLabel: string,
|
|
140
|
+
showSelectAll: bool,
|
|
141
|
+
style: shape({
|
|
142
|
+
checkboxesContainer: ViewPropTypes.style,
|
|
143
|
+
header: ViewPropTypes.style,
|
|
144
|
+
item: checboxStyleProptypes,
|
|
145
|
+
root: ViewPropTypes.style,
|
|
146
|
+
selectAll: ViewPropTypes.style
|
|
147
|
+
})
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export default UTCheckList;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export default StyleSheet.create({
|
|
4
|
+
checkboxesContainer: {
|
|
5
|
+
rowGap: 16
|
|
6
|
+
},
|
|
7
|
+
container: {
|
|
8
|
+
rowGap: 16,
|
|
9
|
+
flexGrow: 1
|
|
10
|
+
},
|
|
11
|
+
headerContainer: {
|
|
12
|
+
rowGap: 8
|
|
13
|
+
},
|
|
14
|
+
itemSeparator: {
|
|
15
|
+
height: 16
|
|
16
|
+
},
|
|
17
|
+
label: {
|
|
18
|
+
flexDirection: 'row'
|
|
19
|
+
},
|
|
20
|
+
reversedCheckBoxesContainer: {
|
|
21
|
+
alignItems: 'flex-end'
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const REQUIRED_LABEL = ' *';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { bool, string } from 'prop-types';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import UTLabel from '../UTLabel';
|
|
6
|
+
|
|
7
|
+
import { REQUIRED_LABEL } from './constants';
|
|
8
|
+
import styles from './styles';
|
|
9
|
+
|
|
10
|
+
const UTRequiredLabel = ({ children, colorTheme, required, variant }) => {
|
|
11
|
+
return (
|
|
12
|
+
<View style={styles.label}>
|
|
13
|
+
<UTLabel colorTheme={colorTheme} variant={variant}>
|
|
14
|
+
{children}
|
|
15
|
+
</UTLabel>
|
|
16
|
+
{required && (
|
|
17
|
+
<UTLabel colorTheme="error" shade="04" variant={variant}>
|
|
18
|
+
{REQUIRED_LABEL}
|
|
19
|
+
</UTLabel>
|
|
20
|
+
)}
|
|
21
|
+
</View>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
UTRequiredLabel.propTypes = {
|
|
26
|
+
colorTheme: string,
|
|
27
|
+
required: bool,
|
|
28
|
+
variant: string
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default UTRequiredLabel;
|
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useState,
|
|
3
|
+
forwardRef,
|
|
4
|
+
useImperativeHandle,
|
|
5
|
+
useRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
Fragment
|
|
9
|
+
} from 'react';
|
|
10
|
+
import _ from 'lodash';
|
|
1
11
|
import { bool, elementType, func, oneOf, shape, string } from 'prop-types';
|
|
2
|
-
import React, { useState, forwardRef, useImperativeHandle, useRef, useEffect, useMemo } from 'react';
|
|
3
|
-
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
4
12
|
import { TextInput } from 'react-native';
|
|
5
|
-
import
|
|
13
|
+
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
6
14
|
|
|
7
15
|
import { withTheme } from '../../../../../../theming';
|
|
8
16
|
import Icon from '../../../../../Icon';
|
|
9
17
|
import Touchable from '../../../../../Touchable';
|
|
10
18
|
|
|
11
19
|
import { DEBOUNCE_DELAY, DEBOUNCE_CONFIG, VISIBILITY, VISIBILITY_OFF } from './constants';
|
|
12
|
-
import styles from './styles';
|
|
20
|
+
import styles, { ICON_SIZE } from './styles';
|
|
13
21
|
|
|
14
22
|
const BaseInput = forwardRef(
|
|
15
23
|
(
|
|
@@ -62,13 +70,15 @@ const BaseInput = forwardRef(
|
|
|
62
70
|
|
|
63
71
|
const hiddenInputProps = hiddenInput
|
|
64
72
|
? {
|
|
65
|
-
|
|
73
|
+
name: showInput ? VISIBILITY : VISIBILITY_OFF,
|
|
74
|
+
size: ICON_SIZE,
|
|
75
|
+
color: theme.UTTextInput?.passwordEyeColor || theme.colors.primary,
|
|
66
76
|
...(RightIcon || {})
|
|
67
77
|
}
|
|
68
78
|
: {};
|
|
69
79
|
|
|
70
80
|
return (
|
|
71
|
-
|
|
81
|
+
<Fragment>
|
|
72
82
|
<TextInput
|
|
73
83
|
autoCorrect={false}
|
|
74
84
|
ref={textInputRef}
|
|
@@ -85,8 +95,9 @@ const BaseInput = forwardRef(
|
|
|
85
95
|
select && { color: theme.fonts?.fontColor },
|
|
86
96
|
select && disabled && { color: theme.fonts?.fontDisabledColor }
|
|
87
97
|
]}
|
|
98
|
+
id={props?.id ? `${props.id}` : undefined}
|
|
88
99
|
/>
|
|
89
|
-
{RightIcon && (
|
|
100
|
+
{(RightIcon || hiddenInput) && (
|
|
90
101
|
<Touchable
|
|
91
102
|
borderless
|
|
92
103
|
onPress={hiddenInput ? toggleShowInput : onRightIconPress}
|
|
@@ -105,7 +116,7 @@ const BaseInput = forwardRef(
|
|
|
105
116
|
)}
|
|
106
117
|
</Touchable>
|
|
107
118
|
)}
|
|
108
|
-
|
|
119
|
+
</Fragment>
|
|
109
120
|
);
|
|
110
121
|
}
|
|
111
122
|
);
|
|
@@ -118,6 +129,7 @@ BaseInput.propTypes = {
|
|
|
118
129
|
onChange: func.isRequired,
|
|
119
130
|
disabled: bool,
|
|
120
131
|
value: string,
|
|
132
|
+
id: string,
|
|
121
133
|
RightIcon: oneOf([shape({ name: string, type: string, color: string }), elementType]),
|
|
122
134
|
hiddenInput: bool,
|
|
123
135
|
onRightIconPress: func,
|
|
@@ -28,6 +28,7 @@ const TextInputField = forwardRef(
|
|
|
28
28
|
alwaysShowPlaceholder,
|
|
29
29
|
disabled,
|
|
30
30
|
error,
|
|
31
|
+
id,
|
|
31
32
|
inputSize,
|
|
32
33
|
LeftIcon,
|
|
33
34
|
maxCount,
|
|
@@ -145,6 +146,7 @@ const TextInputField = forwardRef(
|
|
|
145
146
|
autoCapitalize={autoCapitalize}
|
|
146
147
|
autoCorrect={false}
|
|
147
148
|
editable={!disabled && !readOnly}
|
|
149
|
+
id={id ? `${id}` : undefined}
|
|
148
150
|
keyboardType={keyboardType}
|
|
149
151
|
maxLength={maxCount}
|
|
150
152
|
multiline={multiline}
|
|
@@ -206,6 +208,7 @@ TextInputField.propTypes = {
|
|
|
206
208
|
alwaysShowPlaceholder: bool,
|
|
207
209
|
disabled: bool,
|
|
208
210
|
error: string,
|
|
211
|
+
id: string,
|
|
209
212
|
inputSize: string,
|
|
210
213
|
LeftIcon: elementType,
|
|
211
214
|
maxCount: number,
|
|
@@ -2,9 +2,10 @@ import React from 'react';
|
|
|
2
2
|
import { View } from 'react-native';
|
|
3
3
|
|
|
4
4
|
import UTLabel from '../../../UTLabel';
|
|
5
|
+
import UTRequiredLabel from '../../../UTRequiredLabel';
|
|
5
6
|
import UTValidation from '../../../UTValidation';
|
|
6
7
|
|
|
7
|
-
import { DEFAULT_PROPS,
|
|
8
|
+
import { DEFAULT_PROPS, SMALL } from './constants';
|
|
8
9
|
import { formatErrorToValidation } from './utils';
|
|
9
10
|
import propTypes from './proptypes';
|
|
10
11
|
import styles from './styles';
|
|
@@ -47,16 +48,9 @@ const UTTextInput = ({
|
|
|
47
48
|
return (
|
|
48
49
|
<View style={[styles.container, style.root]}>
|
|
49
50
|
{label && (
|
|
50
|
-
<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</UTLabel>
|
|
54
|
-
{required && (
|
|
55
|
-
<UTLabel colorTheme="error" shade="04" variant={labelComponentVariant}>
|
|
56
|
-
{REQUIRED_LABEL}
|
|
57
|
-
</UTLabel>
|
|
58
|
-
)}
|
|
59
|
-
</View>
|
|
51
|
+
<UTRequiredLabel colorTheme={labelColorTheme} required={required} variant={labelComponentVariant}>
|
|
52
|
+
{label}
|
|
53
|
+
</UTRequiredLabel>
|
|
60
54
|
)}
|
|
61
55
|
<TextInputField
|
|
62
56
|
action={action}
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,8 @@ export { default as ImageLabel } from './components/ImageLabel';
|
|
|
27
27
|
export { default as CheckList } from './components/CheckList';
|
|
28
28
|
export { default as UTCBUInput } from './components/UTCBUInput';
|
|
29
29
|
export { default as UTPasswordField } from './components/UTPasswordField';
|
|
30
|
+
export { default as UTCheckList } from './components/UTCheckList';
|
|
31
|
+
export { default as UTCheckBox } from './components/UTCheckBox';
|
|
30
32
|
|
|
31
33
|
// Icons
|
|
32
34
|
export { default as Icon } from './components/Icon';
|
package/package.json
CHANGED