@widergy/mobile-ui 1.12.4 → 1.12.6

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/components/UTBadge/README.md +17 -26
  3. package/lib/components/UTBadge/index.js +6 -5
  4. package/lib/components/UTButton/README.md +78 -26
  5. package/lib/components/UTButton/index.js +4 -4
  6. package/lib/components/UTIcon/README.md +53 -51
  7. package/lib/components/UTIcon/index.js +5 -3
  8. package/lib/components/UTLabel/README.md +62 -39
  9. package/lib/components/UTLabel/index.js +14 -6
  10. package/lib/components/UTLabel/theme.js +24 -9
  11. package/lib/components/UTLoading/index.js +5 -1
  12. package/lib/components/UTPasswordField/index.js +9 -42
  13. package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/ErrorMessage/index.js +3 -3
  14. package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/Validation/index.js +3 -3
  15. package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/index.js +1 -1
  16. package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/styles.js +1 -2
  17. package/lib/components/UTPasswordField/versions/V0/index.js +49 -0
  18. package/lib/components/UTPasswordField/versions/V1/README.md +23 -0
  19. package/lib/components/UTPasswordField/versions/V1/constants.js +7 -0
  20. package/lib/components/UTPasswordField/versions/V1/index.js +32 -0
  21. package/lib/components/UTTextArea/README.md +32 -0
  22. package/lib/components/UTTextInput/versions/V0/components/BaseInput/index.js +1 -1
  23. package/lib/components/UTTextInput/versions/V1/README.md +236 -0
  24. package/lib/components/UTTextInput/versions/V1/components/TextInputField/index.js +179 -148
  25. package/lib/components/UTTextInput/versions/V1/components/TextInputField/theme.js +30 -27
  26. package/lib/components/UTTextInput/versions/V1/components/TextInputField/utils.js +7 -5
  27. package/lib/components/UTTextInput/versions/V1/index.js +13 -5
  28. package/lib/components/UTTextInput/versions/V1/proptypes.js +3 -0
  29. package/lib/components/UTValidation/README.md +33 -18
  30. package/lib/components/UTValidation/index.js +8 -6
  31. package/package.json +1 -1
  32. /package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/ErrorMessage/styles.js +0 -0
  33. /package/lib/components/UTPasswordField/{components → versions/V0/components}/PasswordValidations/components/Validation/styles.js +0 -0
  34. /package/lib/components/UTPasswordField/{proptypes.js → versions/V0/proptypes.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.12.6](https://github.com/widergy/mobile-ui/compare/v1.12.5...v1.12.6) (2024-07-03)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add UTPasswordField and some fixes ([#303](https://github.com/widergy/mobile-ui/issues/303)) ([1cfe9fd](https://github.com/widergy/mobile-ui/commit/1cfe9fd00f5f3daf758dc327ec36436ff62be824))
7
+
8
+ ## [1.12.5](https://github.com/widergy/mobile-ui/compare/v1.12.4...v1.12.5) (2024-07-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * fixes loading styles ([#309](https://github.com/widergy/mobile-ui/issues/309)) ([8240a0b](https://github.com/widergy/mobile-ui/commit/8240a0b4ddc4eaa4c94bfd2edadc53db833acd3c))
14
+
1
15
  ## [1.12.4](https://github.com/widergy/mobile-ui/compare/v1.12.3...v1.12.4) (2024-07-01)
2
16
 
3
17
 
@@ -1,10 +1,18 @@
1
1
  # UTBadge
2
2
 
3
- ### Description
3
+ ## Description
4
4
 
5
- Basic badge component for displaying labels with various color themes.
5
+ `UTBadge` is a basic badge component for displaying labels with various color themes. It can be used to show statuses, counts, or any short text information that needs to be highlighted.
6
6
 
7
- ### Color Themes
7
+ ## Props
8
+
9
+ | Name | Type | Default | Description |
10
+ | ---------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------- |
11
+ | children | string | | The text content to be displayed inside the badge. |
12
+ | colorTheme | string | 'alert' | The color theme to use. One of: `alert`, `identity`, `identitySecondary`, `negative`, `information`, `warning`, `success`. |
13
+ | style | object | | The style to be applied to the Badge. |
14
+
15
+ ## Color Themes
8
16
 
9
17
  The color themes are defined by the UX team and are:
10
18
 
@@ -16,30 +24,13 @@ The color themes are defined by the UX team and are:
16
24
  - `warning`: Consumes the warning variant.
17
25
  - `success`: Consumes the success variant.
18
26
 
19
- These color themes will change how the badge looks.
20
-
21
- ### Props
22
-
23
- | Name | Type | Default | Description |
24
- | ---------- | ------ | ------- | -------------------------------------------------------------------------------------------------------------------------- |
25
- | children | string | | The text content to be displayed inside the badge. |
26
- | colorTheme | string | 'alert' | The color theme to use. One of: `alert`, `identity`, `identitySecondary`, `negative`, `information`, `warning`, `success`. |
27
- | style | | | The style to be aplied to the Badge |
27
+ These color themes will change how the badge looks, ensuring consistency with the overall design system.
28
28
 
29
- ### Example
29
+ ## Example Usage
30
30
 
31
31
  ```jsx
32
- import React from 'react';
33
- import UTBadge from '@widergy/energy-ui';
34
-
35
- const App = () => (
36
- <div>
37
- <UTBadge />
38
- <UTBadge colorTheme="identity">0</UTBadge>
39
- <UTBadge colorTheme="information">999+</UTBadge>
40
- <UTBadge colorTheme="success">Success Badge</UTBadge>
41
- </div>
42
- );
43
-
44
- export default App;
32
+ <UTBadge />
33
+ <UTBadge colorTheme="identity">0</UTBadge>
34
+ <UTBadge colorTheme="information">999+</UTBadge>
35
+ <UTBadge colorTheme="success">Success Badge</UTBadge>
45
36
  ```
@@ -3,13 +3,15 @@ import { string } from 'prop-types';
3
3
  import { View } from 'react-native';
4
4
  import { ViewPropTypes } from 'deprecated-react-native-prop-types';
5
5
 
6
- import { themeType, withTheme } from '../../theming';
6
+ import { useTheme } from '../../theming';
7
7
  import UTLabel from '../UTLabel';
8
8
 
9
9
  import { DEFAULT_PROPS } from './constants';
10
10
  import { retrieveStyle } from './theme';
11
11
 
12
- const UTBadge = ({ children, colorTheme, style, theme }) => {
12
+ const UTBadge = ({ children, colorTheme, style }) => {
13
+ const theme = useTheme();
14
+
13
15
  const classes = retrieveStyle({ theme, children, colorTheme });
14
16
  const Component = children ? UTLabel : View;
15
17
  return (
@@ -29,8 +31,7 @@ UTBadge.defaultProps = DEFAULT_PROPS;
29
31
  UTBadge.propTypes = {
30
32
  children: string,
31
33
  colorTheme: string,
32
- style: ViewPropTypes.style,
33
- theme: themeType
34
+ style: ViewPropTypes.style
34
35
  };
35
36
 
36
- export default withTheme(UTBadge);
37
+ export default UTBadge;
@@ -1,37 +1,89 @@
1
1
  # UTButton
2
2
 
3
- ### Description
3
+ ## Description
4
4
 
5
- Basic button component.
5
+ `UTButton` is a versatile button component that can be customized with various themes, sizes, icons, and loading states. It is designed to be used in different scenarios, providing a consistent look and feel across your application.
6
6
 
7
- ### Variants
7
+ ## Props
8
8
 
9
- These variants were defined by the UX team and are:
9
+ | Name | Type | Default | Description |
10
+ | ------------- | ----------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | colorTheme | string | 'secondary' | The color theme to use. One of: `error`, `negative`, `primary`, `secondary`, `success`. |
12
+ | disabled | bool | false | Disables the button, making it unclickable and applying a disabled style. |
13
+ | 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
+ | iconPlacement | string | 'left' | Position of the icon relative to the text. One of: `left`, `right`. |
15
+ | loading | bool | false | Shows a loading spinner inside the button when true. |
16
+ | onPress | func | | Function to be called when the button is pressed. |
17
+ | size | string | 'medium' | Size of the button. One of: `small`, `medium`, `large`. |
18
+ | style | object | | Custom styles to apply to the button. Can contain `root`, `childrenContainer`, and `icon` styles. |
19
+ | variant | string | 'filled' | Variant of the button. Can be `filled`, `outlined`, `text`, `semitransparent`, or `shadow`. |
10
20
 
11
- - `filled`
12
- - `outlined`
13
- - `text`
14
- - `semitransparent`
21
+ ## Color Themes
15
22
 
16
- All these variants are defined in the component theme.
23
+ The color themes are defined by the UX team and are:
17
24
 
18
- ### Color Themes
25
+ - `error` (consume error)
26
+ - `negative` (consume negative)
27
+ - `primary` (consume accent)
28
+ - `secondary` (consume neutral)
29
+ - `success` (consume success)
19
30
 
20
- The color themes are defined by the component consumer and will vary accordingly.They define a set of variables (colors and opacities) that then combined with the variant will change how the buttons looks.
21
- The components supports an infinite amount of color themes but requieres the consumer to pass at least a `primary` one that works as a default.
31
+ These themes change the button's appearance to match the desired context.
22
32
 
23
- ### Props
33
+ ## Icon Placement
24
34
 
25
- | Name | Type | Default | Description |
26
- | -------------------- | ----------------------------------------------------- | --------- | ------------------------------------------------------------------------------ |
27
- | children | node | | The component contents. |
28
- | styles | object | | Overrides the default button theme. |
29
- | colorTheme | string | 'primary' | The color theme to use. |
30
- | disabled | bool | false | If `true` the button is unclickable. |
31
- | Icon | node | | An Icon component that can be displayed within the button. |
32
- | iconPlacement | 'left' \| 'right' | 'left' | Indicates where the icon is placed in relation with the contents of the button |
33
- | loading | bool | false | If `true` a spinner is shown over the component. |
34
- | onClick | func | | Callback fired when the user clicks the component. |
35
- | showTextOnResponsive | bool | false | If `true` and Icon is not `null` the contents of the button are not displayed. |
36
- | size | 'small' \| 'medium' \| 'large' | 'medium' | The size of the component. |
37
- | variant | 'filled' \| 'outlined' \| 'text' \| 'semitransparent' | 'filled' | The variant to use. |
35
+ The icon can be placed either on the left or the right side of the button text.
36
+
37
+ - `left`: Places the icon to the left of the text.
38
+ - `right`: Places the icon to the right of the text.
39
+
40
+ ## Button Sizes
41
+
42
+ The button can be one of the following sizes:
43
+
44
+ - `small`
45
+ - `medium`
46
+ - `large`
47
+
48
+ ## Variants
49
+
50
+ The button can be one of the following variants:
51
+
52
+ - `filled`: A solid button with background color.
53
+ - `outlined`: A button with a border and transparent background.
54
+ - `text`: A button with no border or background.
55
+ - `semitransparent`: A button with a semi-transparent background.
56
+ - `shadow`: A button with a shadow effect.
57
+
58
+ ## Custom Styles
59
+
60
+ The `style` prop is an object that can contain the following keys to customize the appearance of the button:
61
+
62
+ - `root`: Style for the root of the button.
63
+ - `childrenContainer`: Style for the container that wraps the button's children.
64
+ - `icon`: Style for the icon inside the button.
65
+
66
+ ## Using Icons
67
+
68
+ The `Icon` prop can be used to display an icon inside the button. It accepts two types of values:
69
+
70
+ 1. **Text**: The name of the icon from the `tabler icons` library. In this case, the `UTIcon` component is used to render the icon.
71
+ 2. **React Component**: A React component, such as an SVG. This allows for custom icons to be used inside the button.
72
+
73
+ ### Example with Text Icon
74
+
75
+ ```jsx
76
+ <UTButton colorTheme="primary" Icon="check" onPress={() => alert('Button Pressed!')}>
77
+ Primary Button
78
+ </UTButton>
79
+ ```
80
+
81
+ ### Example with React Component Icon
82
+
83
+ ```jsx
84
+ import { ReactComponent as CustomIcon } from './path/to/customIcon.svg';
85
+
86
+ <UTButton colorTheme="primary" Icon={CustomIcon} onPress={() => alert('Button Pressed!')}>
87
+ Primary Button
88
+ </UTButton>;
89
+ ```
@@ -3,7 +3,7 @@ import { bool, func, elementType, string, shape } from 'prop-types';
3
3
  import { Pressable, View } from 'react-native';
4
4
  import { ViewPropTypes } from 'deprecated-react-native-prop-types';
5
5
 
6
- import { themeType, withTheme } from '../../theming';
6
+ import { useTheme } from '../../theming';
7
7
  import UTIcon from '../UTIcon';
8
8
  import UTLabel from '../UTLabel';
9
9
  import UTLoading from '../UTLoading';
@@ -22,9 +22,10 @@ const UTButton = ({
22
22
  onPress,
23
23
  size,
24
24
  style,
25
- theme,
26
25
  variant
27
26
  }) => {
27
+ const theme = useTheme();
28
+
28
29
  const {
29
30
  buttonStyles: themeButtonStyles,
30
31
  childrenContainerStyles: themeChildrenContainerStyles,
@@ -97,8 +98,7 @@ UTButton.propTypes = {
97
98
  icon: ViewPropTypes.style,
98
99
  root: ViewPropTypes.style
99
100
  }),
100
- theme: themeType,
101
101
  variant: string
102
102
  };
103
103
 
104
- export default withTheme(UTButton);
104
+ export default UTButton;
@@ -1,77 +1,79 @@
1
1
  # UTIcon
2
2
 
3
- ### Description
3
+ ## Description
4
4
 
5
- Icon component using Tabler Icons library.
5
+ `UTIcon` is an icon component that uses the Tabler Icons library. It allows for easy integration of vector icons in your application, providing various customization options such as color, size, and style.
6
6
 
7
- ### UX/UI Icon Lists
7
+ ## UX/UI Icon Lists
8
+
9
+ For a comprehensive list of available icons and their design specifications, refer to the following resources:
8
10
 
9
11
  - [Figma](https://www.figma.com/file/upiqGm1l10mBTbV9gn35Fh/Icons---Stylesheet?type=design&node-id=3-5&mode=design)
10
12
  - [Zeroheight](https://zeroheight.com/6d447f9f5/p/87aa21-resources)
11
13
 
12
- ### Name
14
+ ## Props
13
15
 
14
- Icon names must be PascalCase.
16
+ | Name | Type | Default | Description |
17
+ | ----- | ------ | ------- | --------------------------------------------------- |
18
+ | color | string | 'dark' | The icon color, must be from the theme palette. |
19
+ | name | string | | The name of the icon from the Tabler Icons library. |
20
+ | shade | string | | The shade of the color theme to use. |
21
+ | size | number | | The size of the icon. |
22
+ | style | object | | Custom styles to apply to the icon. |
15
23
 
16
- Usually, icon names are a convertion from figma's or zeroheight's snake_case to PascalCase, adding `Icon` as a prefix.
24
+ ## Icon Names
17
25
 
18
- ```
19
- Figma: truck-delivery
20
- UTIcon: IconTruckDelivery
21
- ```
26
+ Icon names must be in PascalCase. Typically, icon names are a conversion from Figma's or Zeroheight's snake_case to PascalCase, adding `Icon` as a prefix.
22
27
 
23
- Sometimes icons will be called {icon-name}-old. In these cases, usually, the icon name is made in the same way already explained, but subtracting the
24
- `-old` suffix.
28
+ Example:
25
29
 
26
- ```
27
- Figma: chevron-right-old
28
- UTIcon: IconChevronRight
29
- ```
30
+ - **Figma**: `truck-delivery`
31
+ - **UTIcon**: `IconTruckDelivery`
30
32
 
31
- Exceptions may exists to these rules.
33
+ In some cases, icons will have the suffix `-old`. In these cases, the icon name is made in the same way, but without the `-old` suffix.
32
34
 
33
- ### Color
35
+ Example:
34
36
 
35
- Android always requires a color value, so the prop defaults to "dark".
37
+ - **Figma**: `chevron-right-old`
38
+ - **UTIcon**: `IconChevronRight`
36
39
 
37
- It must be one of these:
40
+ Exceptions to these rules may exist.
38
41
 
39
- - "accent",
40
- - "dark",
41
- - "error",
42
- - "gray",
43
- - "information",
44
- - "light",
45
- - "negative",
46
- - "neutral",
47
- - "success",
48
- - "warning"
42
+ ## Color Themes
49
43
 
50
- ### Props
44
+ The `color` prop must be one of these values:
51
45
 
52
- | Name | Description | Default |
53
- | ----- | ---------------------------------------- | ------- |
54
- | color | The icon color, must be from the Palette | 'dark' |
55
- | name | The name of the icon in TablerIcons | ------- |
56
- | size | The icon size | ------- |
57
- | style | The style to be aplied to the Icon | ------- |
46
+ - `accent`
47
+ - `dark`
48
+ - `error`
49
+ - `gray`
50
+ - `information`
51
+ - `light`
52
+ - `negative`
53
+ - `neutral`
54
+ - `success`
55
+ - `warning`
58
56
 
59
- ### Usage
57
+ ## Shade
60
58
 
61
- ```javascript
62
- import { UTIcon } from '@widergy/mobile-ui';
63
- import { View } from 'react-native';
64
- import React from 'react';
59
+ The `shade` prop must be one of these:
60
+
61
+ - `01`
62
+ - `02`
63
+ - `03`
64
+ - `04`
65
+ - `05`
66
+
67
+ ### Default shade
65
68
 
66
- import styles from './styles';
69
+ The default shade for each color theme is defined as follows:
67
70
 
68
- const MyComponent = () => {
69
- return (
70
- <View>
71
- <UTIcon color="skyBlue" name="IconTruckDelivery" size={48} style={styles.iconStyle} />
72
- </View>
73
- );
74
- };
71
+ For `gray`: `shade04`
72
+ For `light`: `shade01`
73
+ For all others: `shade05`
75
74
 
76
- export default MyComponent;
75
+ ## Usage
76
+
77
+ ```javascript
78
+ <UTIcon color="primary" name="IconTruckDelivery" size={48} />
77
79
  ```
@@ -3,11 +3,13 @@ import { number, string } from 'prop-types';
3
3
  import { ViewPropTypes } from 'deprecated-react-native-prop-types';
4
4
  import * as TablerIcons from '@tabler/icons-react-native';
5
5
 
6
- import { withTheme } from '../../theming';
6
+ import { useTheme } from '../../theming';
7
7
 
8
8
  import { retrieveStyle } from './theme';
9
9
 
10
- const UTIcon = ({ color = 'dark', name, shade, size, style, theme }) => {
10
+ const UTIcon = ({ color = 'dark', name, shade, size, style }) => {
11
+ const theme = useTheme();
12
+
11
13
  const IconComponent = TablerIcons[name];
12
14
  if (!IconComponent) return null;
13
15
 
@@ -28,4 +30,4 @@ UTIcon.propTypes = {
28
30
  style: ViewPropTypes.style
29
31
  };
30
32
 
31
- export default withTheme(UTIcon);
33
+ export default UTIcon;
@@ -1,50 +1,57 @@
1
1
  # UTLabel
2
2
 
3
- Component used for displaying text values and markdown.
3
+ ## Description
4
+
5
+ `UTLabel` is a versatile text component used for displaying text values and markdown content. It provides various customization options such as color themes, font sizes, weights, and styles.
4
6
 
5
7
  ## Props
6
8
 
7
- | Name | Type | Default | Description |
8
- | ----------------- | ------ | ---------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9
- | colorTheme | string | 'primary' | Color theme to style the UTLabel. Has to be defined in the proyect theme. [Example](#colortheme). |
10
- | markdownRenderers | object | [MARKDOWN_RENDERERS](./constants.js#L36) | ⚠️ Requires `withMarkdown` to be set to `true` <br />Object mapping tag names to React components. The keys in components are HTML equivalents for the things you write with markdown [List of tags](#markdown-renderers). |
11
- | shade | string | | The colorTheme shade |
12
- | style | object | | Additional style. |
13
- | title | string | | [Title global attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title). |
14
- | variant | string | 'body' | Defines html component to use. For a list of available variants, check [here](#variants). Font sizes can be overwritten (⚠️ for the entire proyect) through the proyect's theme. |
15
- | weight | string | 'regular' | Defines font-weight to be used. For a list of available options, check [here](#font-weights). |
16
- | withMarkdown | bool | false | Tells the component whether or not to render text inside as markdown. |
17
-
18
- ### colorTheme
19
-
20
- It must be one of these:
21
-
22
- - "accent",
23
- - "dark",
24
- - "error",
25
- - "gray",
26
- - "information",
27
- - "light",
28
- - "negative",
29
- - "neutral",
30
- - "success",
31
- - "warning"
32
-
33
- ```JSX
34
- <UTLabel colorTheme='error'>Your text here</UTLabel>
35
- ```
9
+ | Name | Type | Default | Description |
10
+ | ----------------- | ------ | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | colorTheme | string | 'dark' | Color theme to style the `UTLabel`. It must be defined in the project theme. [Example](#colortheme). |
12
+ | field | any | {} | Field configuration for advanced customization. |
13
+ | markdownRenderers | object | | ⚠️ Requires `withMarkdown` to be set to `true`. Object mapping tag names to React components. The keys in components are HTML equivalents for the things you write with markdown [List of tags](#markdown-renderers). |
14
+ | numberOfLines | number | | Limits the number of lines displayed in the label. When set, `ellipsizeMode` is automatically set to 'tail'. |
15
+ | shade | string | | The color theme shade. |
16
+ | style | object | {} | Additional style. |
17
+ | variant | string | 'body' | Defines the font size and component to use. For a list of available variants, check [here](#variants). Font sizes can be overwritten (⚠️ for the entire project) through the project's theme. |
18
+ | weight | string | 'regular' | Defines the font weight to be used. For a list of available options, check [here](#weights). |
19
+ | withMarkdown | bool | false | Indicates whether or not to render text inside as markdown. |
20
+
21
+ ## Color Themes
22
+
23
+ The `color` prop must be one of these values:
24
+
25
+ - `accent`
26
+ - `dark`
27
+ - `error`
28
+ - `gray`
29
+ - `information`
30
+ - `light`
31
+ - `negative`
32
+ - `neutral`
33
+ - `success`
34
+ - `warning`
35
+
36
+ ## Shade
37
+
38
+ The `shade` prop must be one of these:
39
+
40
+ - `01`
41
+ - `02`
42
+ - `03`
43
+ - `04`
44
+ - `05`
36
45
 
37
- ### shade
46
+ ### Default shade
38
47
 
39
- It must be one of these:
48
+ The default shade for each color theme is defined as follows:
40
49
 
41
- - "01",
42
- - "02",
43
- - "03",
44
- - "04",
45
- - "05"
50
+ For `gray`: `shade04`
51
+ For `light`: `shade01`
52
+ For all others: `shade05`
46
53
 
47
- ### variants
54
+ ## Variants
48
55
 
49
56
  | Variant | Component | Default font size |
50
57
  | --------- | --------- | ----------------- |
@@ -59,7 +66,7 @@ It must be one of these:
59
66
  | th | th | 16px |
60
67
  | td | td | 16px |
61
68
 
62
- ### weights
69
+ ## Weights
63
70
 
64
71
  | Name | Weight |
65
72
  | ---------- | ------ |
@@ -72,3 +79,19 @@ It must be one of these:
72
79
  | bold | 700 |
73
80
  | extrabold | 800 |
74
81
  | black | 900 |
82
+
83
+ ## Usage
84
+
85
+ ### Basic Example
86
+
87
+ ```jsx
88
+ <UTLabel variant="title1" colorTheme="primary">
89
+ Hello, World!
90
+ </UTLabel>
91
+ ```
92
+
93
+ ### Example with Markdown
94
+
95
+ ```jsx
96
+ <UTLabel withMarkdown>{`This is **bold** and this is *italic* text.`}</UTLabel>
97
+ ```
@@ -1,10 +1,10 @@
1
1
  import React from 'react';
2
- import { any, bool, func, objectOf, string } from 'prop-types';
2
+ import { any, bool, func, number, objectOf, string } from 'prop-types';
3
3
  import { Text } from 'react-native';
4
4
  import { ViewPropTypes } from 'deprecated-react-native-prop-types';
5
5
  import Markdown from 'react-native-markdown-display';
6
6
 
7
- import { themeType, withTheme } from '../../theming';
7
+ import { useTheme } from '../../theming';
8
8
 
9
9
  import { DEFAULT_PROPS } from './constants';
10
10
  import { markdownFormat } from './utils';
@@ -15,13 +15,15 @@ const UTLabel = ({
15
15
  colorTheme,
16
16
  field,
17
17
  markdownRenderers,
18
+ numberOfLines,
18
19
  shade,
19
20
  style,
20
- theme,
21
21
  variant,
22
22
  weight,
23
23
  withMarkdown
24
24
  }) => {
25
+ const theme = useTheme();
26
+
25
27
  if (!children) return null;
26
28
 
27
29
  const themeStyles = retrieveStyle({ colorTheme, field, shade, theme, variant, weight });
@@ -29,8 +31,14 @@ const UTLabel = ({
29
31
 
30
32
  const LabelRenderer = withMarkdown ? Markdown : Text;
31
33
 
34
+ const additionalProps = numberOfLines ? { ellipsizeMode: 'tail', numberOfLines } : {};
35
+
32
36
  return (
33
- <LabelRenderer style={withMarkdown ? { body: labelStyles } : labelStyles} rules={markdownRenderers}>
37
+ <LabelRenderer
38
+ {...additionalProps}
39
+ rules={markdownRenderers}
40
+ style={withMarkdown ? { body: labelStyles } : labelStyles}
41
+ >
34
42
  {withMarkdown ? markdownFormat(children) : children}
35
43
  </LabelRenderer>
36
44
  );
@@ -43,12 +51,12 @@ UTLabel.propTypes = {
43
51
  // eslint-disable-next-line react/forbid-prop-types
44
52
  field: any,
45
53
  markdownRenderers: objectOf(func),
54
+ numberOfLines: number,
46
55
  shade: string,
47
56
  style: ViewPropTypes.style,
48
- theme: themeType,
49
57
  variant: string,
50
58
  weight: string,
51
59
  withMarkdown: bool
52
60
  };
53
61
 
54
- export default withTheme(UTLabel);
62
+ export default UTLabel;
@@ -15,9 +15,21 @@ const variantsColorTheme = (colorTheme, shade, theme) => {
15
15
  return colorThemeDefinition[colorShade] || '#000';
16
16
  };
17
17
 
18
- const getFontFamily = (theme, weight) => {
19
- if (weight === WEIGHTS[DEFAULT_PROPS.weight] || IS_IOS) return theme.fonts.fontFamily;
20
- return theme.fonts?.customVariants?.[weight]?.fontFamily;
18
+ export const getFontFamily = (theme, weight) =>
19
+ weight === WEIGHTS[DEFAULT_PROPS.weight] || IS_IOS
20
+ ? theme.fonts.fontFamily
21
+ : theme.fonts?.customVariants?.[weight]?.fontFamily;
22
+
23
+ export const getFontSize = variant => VARIANTS_SIZES[variant] || VARIANTS_SIZES[DEFAULT_PROPS.variant];
24
+
25
+ export const getFontWeight = weight => (IS_IOS ? WEIGHTS[weight] || WEIGHTS[DEFAULT_PROPS.weight] : null);
26
+
27
+ export const getFontStyles = ({ theme, variant, weight }) => {
28
+ const fontFamily = getFontFamily(theme, weight);
29
+ const fontSize = getFontSize(variant);
30
+ const fontWeight = getFontWeight(weight);
31
+
32
+ return { fontFamily, fontSize, fontWeight };
21
33
  };
22
34
 
23
35
  export const retrieveStyle = ({ colorTheme, field, shade, theme, variant, weight }) => ({
@@ -26,10 +38,13 @@ export const retrieveStyle = ({ colorTheme, field, shade, theme, variant, weight
26
38
  field?.configuration?.shade ?? shade,
27
39
  theme
28
40
  ),
29
- fontFamily: getFontFamily(theme, field?.configuration?.weight ?? weight),
30
- fontSize: VARIANTS_SIZES[field?.configuration?.variant ?? variant] || VARIANTS_SIZES[DEFAULT_PROPS.variant],
31
- fontWeight: IS_IOS
32
- ? WEIGHTS[field?.configuration?.weight ?? weight] || WEIGHTS[DEFAULT_PROPS.weight]
33
- : null,
34
- margin: 0
41
+ ...getFontStyles({
42
+ theme,
43
+ variant: field?.configuration?.variant ?? variant,
44
+ weight: field?.configuration?.weight ?? weight
45
+ }),
46
+ includeFontPadding: false,
47
+ margin: 0,
48
+ paddingVertical: 0,
49
+ textAlignVertical: 'center'
35
50
  });