@ledgerhq/lumen-ui-rnative 0.1.49 → 0.1.51
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/dist/module/lib/Components/BaseInput/BaseInput.js +84 -25
- package/dist/module/lib/Components/BaseInput/BaseInput.js.map +1 -1
- package/dist/module/lib/Components/Button/ButtonGroup.figma.js +19 -0
- package/dist/module/lib/Components/Button/ButtonGroup.figma.js.map +1 -0
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.js +31 -9
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.js.map +1 -1
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.mdx +10 -7
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.stories.js +29 -40
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.stories.js.map +1 -1
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.test.js +22 -0
- package/dist/module/lib/Components/DescriptionItem/DescriptionItem.test.js.map +1 -1
- package/dist/module/lib/Components/ListItem/ListItem.figma.js +11 -0
- package/dist/module/lib/Components/ListItem/ListItem.figma.js.map +1 -1
- package/dist/module/lib/Components/ListItem/ListItem.js +78 -20
- package/dist/module/lib/Components/ListItem/ListItem.js.map +1 -1
- package/dist/module/lib/Components/ListItem/ListItem.mdx +17 -0
- package/dist/module/lib/Components/ListItem/ListItem.stories.js +132 -0
- package/dist/module/lib/Components/ListItem/ListItem.stories.js.map +1 -1
- package/dist/module/lib/Components/ListItem/ListItem.test.js +80 -0
- package/dist/module/lib/Components/ListItem/ListItem.test.js.map +1 -1
- package/dist/module/lib/Components/SectionHeader/SectionHeader.figma.js +22 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.figma.js.map +1 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.js +99 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.js.map +1 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.mdx +79 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.stories.js +104 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.stories.js.map +1 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.test.js +108 -0
- package/dist/module/lib/Components/SectionHeader/SectionHeader.test.js.map +1 -0
- package/dist/module/lib/Components/SectionHeader/index.js +5 -0
- package/dist/module/lib/Components/SectionHeader/index.js.map +1 -0
- package/dist/module/lib/Components/SectionHeader/types.js +4 -0
- package/dist/module/lib/Components/SectionHeader/types.js.map +1 -0
- package/dist/module/lib/Components/TextInput/TextInput.figma.js +5 -0
- package/dist/module/lib/Components/TextInput/TextInput.figma.js.map +1 -1
- package/dist/module/lib/Components/TextInput/TextInput.mdx +43 -73
- package/dist/module/lib/Components/TextInput/TextInput.stories.js +58 -1
- package/dist/module/lib/Components/TextInput/TextInput.stories.js.map +1 -1
- package/dist/module/lib/Components/TextInput/TextInput.test.js +45 -1
- package/dist/module/lib/Components/TextInput/TextInput.test.js.map +1 -1
- package/dist/module/lib/Components/TileButton/TileButton.figma.js +5 -0
- package/dist/module/lib/Components/TileButton/TileButton.figma.js.map +1 -1
- package/dist/module/lib/Components/TileButton/TileButton.js +39 -27
- package/dist/module/lib/Components/TileButton/TileButton.js.map +1 -1
- package/dist/module/lib/Components/TileButton/TileButton.mdx +10 -1
- package/dist/module/lib/Components/TileButton/TileButton.stories.js +33 -2
- package/dist/module/lib/Components/TileButton/TileButton.stories.js.map +1 -1
- package/dist/module/lib/Components/TileButton/TileButton.test.js +26 -0
- package/dist/module/lib/Components/TileButton/TileButton.test.js.map +1 -1
- package/dist/module/lib/Components/index.js +1 -0
- package/dist/module/lib/Components/index.js.map +1 -1
- package/dist/module/lib/Symbols/Icons/Atm.js +50 -0
- package/dist/module/lib/Symbols/Icons/Atm.js.map +1 -0
- package/dist/module/lib/Symbols/Icons/Cutlery.js +50 -0
- package/dist/module/lib/Symbols/Icons/Cutlery.js.map +1 -0
- package/dist/module/lib/Symbols/Icons/GameControler.js +50 -0
- package/dist/module/lib/Symbols/Icons/GameControler.js.map +1 -0
- package/dist/module/lib/Symbols/Icons/Upload.js +50 -0
- package/dist/module/lib/Symbols/Icons/Upload.js.map +1 -0
- package/dist/module/lib/Symbols/index.js +4 -0
- package/dist/module/lib/Symbols/index.js.map +1 -1
- package/dist/typescript/src/lib/Components/BaseInput/BaseInput.d.ts +1 -1
- package/dist/typescript/src/lib/Components/BaseInput/BaseInput.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/BaseInput/types.d.ts +16 -0
- package/dist/typescript/src/lib/Components/BaseInput/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/DescriptionItem/DescriptionItem.d.ts +1 -1
- package/dist/typescript/src/lib/Components/DescriptionItem/DescriptionItem.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/DescriptionItem/types.d.ts +6 -0
- package/dist/typescript/src/lib/Components/DescriptionItem/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/ListItem/ListItem.d.ts +1 -1
- package/dist/typescript/src/lib/Components/ListItem/ListItem.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/ListItem/types.d.ts +11 -1
- package/dist/typescript/src/lib/Components/ListItem/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/SectionHeader/SectionHeader.d.ts +20 -0
- package/dist/typescript/src/lib/Components/SectionHeader/SectionHeader.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/SectionHeader/index.d.ts +3 -0
- package/dist/typescript/src/lib/Components/SectionHeader/index.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/SectionHeader/types.d.ts +27 -0
- package/dist/typescript/src/lib/Components/SectionHeader/types.d.ts.map +1 -0
- package/dist/typescript/src/lib/Components/TileButton/TileButton.d.ts +1 -1
- package/dist/typescript/src/lib/Components/TileButton/TileButton.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/TileButton/types.d.ts +5 -0
- package/dist/typescript/src/lib/Components/TileButton/types.d.ts.map +1 -1
- package/dist/typescript/src/lib/Components/index.d.ts +1 -0
- package/dist/typescript/src/lib/Components/index.d.ts.map +1 -1
- package/dist/typescript/src/lib/Symbols/Icons/Atm.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/Atm.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/Icons/Cutlery.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/Cutlery.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/Icons/GameControler.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/GameControler.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/Icons/Upload.d.ts +35 -0
- package/dist/typescript/src/lib/Symbols/Icons/Upload.d.ts.map +1 -0
- package/dist/typescript/src/lib/Symbols/index.d.ts +4 -0
- package/dist/typescript/src/lib/Symbols/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/lib/Components/BaseInput/BaseInput.tsx +93 -22
- package/src/lib/Components/BaseInput/types.ts +18 -0
- package/src/lib/Components/Button/ButtonGroup.figma.tsx +15 -0
- package/src/lib/Components/DescriptionItem/DescriptionItem.mdx +10 -7
- package/src/lib/Components/DescriptionItem/DescriptionItem.stories.tsx +21 -41
- package/src/lib/Components/DescriptionItem/DescriptionItem.test.tsx +24 -0
- package/src/lib/Components/DescriptionItem/DescriptionItem.tsx +31 -8
- package/src/lib/Components/DescriptionItem/types.ts +6 -0
- package/src/lib/Components/ListItem/ListItem.figma.tsx +43 -8
- package/src/lib/Components/ListItem/ListItem.mdx +17 -0
- package/src/lib/Components/ListItem/ListItem.stories.tsx +92 -0
- package/src/lib/Components/ListItem/ListItem.test.tsx +78 -0
- package/src/lib/Components/ListItem/ListItem.tsx +64 -19
- package/src/lib/Components/ListItem/types.ts +11 -1
- package/src/lib/Components/SectionHeader/SectionHeader.figma.tsx +24 -0
- package/src/lib/Components/SectionHeader/SectionHeader.mdx +79 -0
- package/src/lib/Components/SectionHeader/SectionHeader.stories.tsx +95 -0
- package/src/lib/Components/SectionHeader/SectionHeader.test.tsx +103 -0
- package/src/lib/Components/SectionHeader/SectionHeader.tsx +125 -0
- package/src/lib/Components/SectionHeader/index.ts +6 -0
- package/src/lib/Components/SectionHeader/types.ts +30 -0
- package/src/lib/Components/TextInput/TextInput.figma.tsx +6 -1
- package/src/lib/Components/TextInput/TextInput.mdx +43 -73
- package/src/lib/Components/TextInput/TextInput.stories.tsx +57 -1
- package/src/lib/Components/TextInput/TextInput.test.tsx +60 -1
- package/src/lib/Components/TileButton/TileButton.figma.tsx +5 -0
- package/src/lib/Components/TileButton/TileButton.mdx +10 -1
- package/src/lib/Components/TileButton/TileButton.stories.tsx +28 -4
- package/src/lib/Components/TileButton/TileButton.test.tsx +35 -1
- package/src/lib/Components/TileButton/TileButton.tsx +47 -28
- package/src/lib/Components/TileButton/types.ts +5 -0
- package/src/lib/Components/index.ts +1 -0
- package/src/lib/Symbols/Icons/Atm.tsx +45 -0
- package/src/lib/Symbols/Icons/Cutlery.tsx +45 -0
- package/src/lib/Symbols/Icons/GameControler.tsx +45 -0
- package/src/lib/Symbols/Icons/Upload.tsx +45 -0
- package/src/lib/Symbols/index.ts +4 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import type { ViewStyle } from 'react-native';
|
|
2
|
+
import { StyleSheet } from 'react-native';
|
|
3
|
+
import { useStyleSheet } from '../../../styles';
|
|
4
|
+
import { Box, Text } from '../Utility';
|
|
5
|
+
import type {
|
|
6
|
+
SectionHeaderAppearance,
|
|
7
|
+
SectionHeaderLeadingProps,
|
|
8
|
+
SectionHeaderProps,
|
|
9
|
+
SectionHeaderTitleProps,
|
|
10
|
+
} from './types';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Leading slot for the SectionHeader. Use for optional icons or other leading content.
|
|
14
|
+
*/
|
|
15
|
+
export const SectionHeaderLeading = ({
|
|
16
|
+
children,
|
|
17
|
+
lx,
|
|
18
|
+
style,
|
|
19
|
+
...props
|
|
20
|
+
}: SectionHeaderLeadingProps) => {
|
|
21
|
+
const styles = useStyleSheet(
|
|
22
|
+
() => ({
|
|
23
|
+
leading: StyleSheet.flatten([
|
|
24
|
+
{
|
|
25
|
+
flexShrink: 0,
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
justifyContent: 'center',
|
|
28
|
+
},
|
|
29
|
+
]),
|
|
30
|
+
}),
|
|
31
|
+
[],
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<Box lx={lx} style={[styles.leading, style]} {...props}>
|
|
36
|
+
{children}
|
|
37
|
+
</Box>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Title component for the SectionHeader. Displays the muted label text.
|
|
43
|
+
*/
|
|
44
|
+
export const SectionHeaderTitle = ({
|
|
45
|
+
children,
|
|
46
|
+
lx,
|
|
47
|
+
style,
|
|
48
|
+
...props
|
|
49
|
+
}: SectionHeaderTitleProps) => {
|
|
50
|
+
const styles = useStyleSheet(
|
|
51
|
+
(t) => ({
|
|
52
|
+
title: StyleSheet.flatten([
|
|
53
|
+
t.typographies.body2SemiBold,
|
|
54
|
+
{
|
|
55
|
+
flexShrink: 1,
|
|
56
|
+
minWidth: 0,
|
|
57
|
+
color: t.colors.text.muted,
|
|
58
|
+
},
|
|
59
|
+
]),
|
|
60
|
+
}),
|
|
61
|
+
[],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Text
|
|
66
|
+
lx={lx}
|
|
67
|
+
style={[styles.title, style]}
|
|
68
|
+
numberOfLines={1}
|
|
69
|
+
ellipsizeMode='tail'
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</Text>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A compact section label used to title grouped content areas.
|
|
79
|
+
* Uses a composable API where you explicitly nest sub-components to define the layout.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* <SectionHeader>
|
|
83
|
+
* <SectionHeaderTitle>Label</SectionHeaderTitle>
|
|
84
|
+
* </SectionHeader>
|
|
85
|
+
*/
|
|
86
|
+
export const SectionHeader = ({
|
|
87
|
+
appearance = 'no-background',
|
|
88
|
+
lx,
|
|
89
|
+
style,
|
|
90
|
+
children,
|
|
91
|
+
...props
|
|
92
|
+
}: SectionHeaderProps) => {
|
|
93
|
+
const styles = useStyleSheet(
|
|
94
|
+
(t) => {
|
|
95
|
+
const appearanceStyles = {
|
|
96
|
+
'no-background': {},
|
|
97
|
+
plain: {
|
|
98
|
+
backgroundColor: t.colors.bg.surface,
|
|
99
|
+
paddingHorizontal: t.spacings.s8,
|
|
100
|
+
paddingVertical: t.spacings.s1,
|
|
101
|
+
borderRadius: t.borderRadius.xs,
|
|
102
|
+
},
|
|
103
|
+
} satisfies Record<SectionHeaderAppearance, ViewStyle>;
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
container: StyleSheet.flatten([
|
|
107
|
+
{
|
|
108
|
+
flexDirection: 'row',
|
|
109
|
+
alignItems: 'center',
|
|
110
|
+
gap: t.spacings.s4,
|
|
111
|
+
minWidth: 0,
|
|
112
|
+
},
|
|
113
|
+
appearanceStyles[appearance],
|
|
114
|
+
]),
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
[appearance],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<Box lx={lx} style={[styles.container, style]} {...props}>
|
|
122
|
+
{children}
|
|
123
|
+
</Box>
|
|
124
|
+
);
|
|
125
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyledTextProps, StyledViewProps } from '../../../styles';
|
|
3
|
+
|
|
4
|
+
export type SectionHeaderAppearance = 'no-background' | 'plain';
|
|
5
|
+
|
|
6
|
+
export type SectionHeaderProps = {
|
|
7
|
+
/**
|
|
8
|
+
* The visual style of the section header container.
|
|
9
|
+
* @default 'no-background'
|
|
10
|
+
*/
|
|
11
|
+
appearance?: SectionHeaderAppearance;
|
|
12
|
+
/**
|
|
13
|
+
* The children of the section header: SectionHeaderLeading and SectionHeaderTitle.
|
|
14
|
+
*/
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
17
|
+
|
|
18
|
+
export type SectionHeaderLeadingProps = {
|
|
19
|
+
/**
|
|
20
|
+
* Optional leading content such as an icon.
|
|
21
|
+
*/
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
} & Omit<StyledViewProps, 'children'>;
|
|
24
|
+
|
|
25
|
+
export type SectionHeaderTitleProps = {
|
|
26
|
+
/**
|
|
27
|
+
* The label text of the section header.
|
|
28
|
+
*/
|
|
29
|
+
children: string;
|
|
30
|
+
} & Omit<StyledTextProps, 'children'>;
|
|
@@ -24,8 +24,12 @@ figma.connect(
|
|
|
24
24
|
helperText: figma.nestedProps('.status', {
|
|
25
25
|
label: figma.string('label'),
|
|
26
26
|
}),
|
|
27
|
+
maxCount: figma.boolean('show-counter', {
|
|
28
|
+
true: figma.string('counter'),
|
|
29
|
+
false: undefined,
|
|
30
|
+
}),
|
|
27
31
|
},
|
|
28
|
-
example: (props) => (
|
|
32
|
+
example: (props: any) => (
|
|
29
33
|
<TextInput
|
|
30
34
|
disabled={props.disabled}
|
|
31
35
|
label={props.label}
|
|
@@ -33,6 +37,7 @@ figma.connect(
|
|
|
33
37
|
value={props.value}
|
|
34
38
|
helperText={props.helperText.label}
|
|
35
39
|
status={props.status}
|
|
40
|
+
maxCount={props.maxCount}
|
|
36
41
|
onChangeText={() => {}}
|
|
37
42
|
/>
|
|
38
43
|
),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Meta, Canvas, Controls } from '@storybook/addon-docs/blocks';
|
|
1
|
+
import { Meta, Canvas, Controls, Source } from '@storybook/addon-docs/blocks';
|
|
2
2
|
import * as TextInputStories from './TextInput.stories';
|
|
3
3
|
import { TextInput } from './TextInput';
|
|
4
4
|
import { CustomTabs, Tab } from '../../../../.storybook/components';
|
|
@@ -60,6 +60,26 @@ The input supports error handling through `helperText` and `status` (`'error'` \
|
|
|
60
60
|
|
|
61
61
|
<Canvas of={TextInputStories.WithError} />
|
|
62
62
|
|
|
63
|
+
### Character Counter
|
|
64
|
+
|
|
65
|
+
Set `maxCount` to show a character counter below the input. The counter displays as `count/maxCount` on the bottom-right, sharing the row with helper text on the left.
|
|
66
|
+
|
|
67
|
+
Exceeding `maxCount` does not truncate input — this is a soft limit for visual feedback only. For hard truncation, use the native `maxLength` prop. The component does not change status on its own; handle validation in your app.
|
|
68
|
+
|
|
69
|
+
<Canvas of={TextInputStories.WithCounter} />
|
|
70
|
+
|
|
71
|
+
#### **Validation**
|
|
72
|
+
|
|
73
|
+
When the count exceeds `maxCount`, handle validation in your app — pass `status` and `helperText` yourself:
|
|
74
|
+
|
|
75
|
+
<Canvas of={TextInputStories.WithCounterExceeded} />
|
|
76
|
+
|
|
77
|
+
#### **Hard Limit with Native `maxLength`**
|
|
78
|
+
|
|
79
|
+
Pair `maxCount` with the native `maxLength` prop to hard-cap input at the same limit. The platform prevents typing beyond `maxLength`, so the counter never exceeds `maxCount`.
|
|
80
|
+
|
|
81
|
+
<Canvas of={TextInputStories.WithNativeMaxLength} />
|
|
82
|
+
|
|
63
83
|
### Disabled State
|
|
64
84
|
|
|
65
85
|
The input can be fully disabled using the `disabled` prop, which prevents interaction and applies a muted visual style.
|
|
@@ -133,16 +153,7 @@ Install and set up the library with our [Setup Guide →](?path=/docs/getting-st
|
|
|
133
153
|
|
|
134
154
|
### Basic Usage
|
|
135
155
|
|
|
136
|
-
|
|
137
|
-
import { TextInput } from '@ledgerhq/lumen-ui-rnative';
|
|
138
|
-
import { useState } from 'react';
|
|
139
|
-
|
|
140
|
-
function MyComponent() {
|
|
141
|
-
const [value, setValue] = useState('');
|
|
142
|
-
|
|
143
|
-
return <TextInput label='Username' value={value} onChangeText={setValue} />;
|
|
144
|
-
}
|
|
145
|
-
```
|
|
156
|
+
<Source of={TextInputStories.Base} />
|
|
146
157
|
|
|
147
158
|
> **Note:** Clear button appears automatically when input has content. Use `hideClearButton` to hide it.
|
|
148
159
|
|
|
@@ -150,81 +161,40 @@ function MyComponent() {
|
|
|
150
161
|
|
|
151
162
|
Use `hideClearButton` to prevent the clear button from appearing:
|
|
152
163
|
|
|
153
|
-
|
|
154
|
-
import { TextInput } from '@ledgerhq/lumen-ui-rnative';
|
|
155
|
-
import { useState } from 'react';
|
|
156
|
-
|
|
157
|
-
function MyComponent() {
|
|
158
|
-
const [value, setValue] = useState('');
|
|
159
|
-
|
|
160
|
-
return (
|
|
161
|
-
<TextInput
|
|
162
|
-
label='Username'
|
|
163
|
-
value={value}
|
|
164
|
-
onChangeText={setValue}
|
|
165
|
-
hideClearButton // Clear button will not appear
|
|
166
|
-
/>
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
```
|
|
164
|
+
<Source of={TextInputStories.WithHiddenClearButton} />
|
|
170
165
|
|
|
171
166
|
#### **Extending the Clear Behavior**
|
|
172
167
|
|
|
173
168
|
Provide `onClear` to extend the default clear behavior with additional logic:
|
|
174
169
|
|
|
175
|
-
|
|
176
|
-
import { TextInput } from '@ledgerhq/lumen-ui-rnative';
|
|
177
|
-
import { useState } from 'react';
|
|
178
|
-
|
|
179
|
-
function MyComponent() {
|
|
180
|
-
const [value, setValue] = useState('');
|
|
181
|
-
|
|
182
|
-
return (
|
|
183
|
-
<TextInput
|
|
184
|
-
label='Search'
|
|
185
|
-
value={value}
|
|
186
|
-
onChangeText={setValue}
|
|
187
|
-
onClear={() => {
|
|
188
|
-
// Default clearing happens automatically
|
|
189
|
-
// Add your custom logic here
|
|
190
|
-
analytics.track('search_cleared');
|
|
191
|
-
}}
|
|
192
|
-
/>
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
```
|
|
170
|
+
<Source of={TextInputStories.WithClearCallback} />
|
|
196
171
|
|
|
197
172
|
### With Error State
|
|
198
173
|
|
|
199
174
|
The Input component supports error states and messages:
|
|
200
175
|
|
|
201
|
-
|
|
202
|
-
import { TextInput } from '@ledgerhq/lumen-ui-rnative';
|
|
203
|
-
import { useState } from 'react';
|
|
204
|
-
|
|
205
|
-
function MyComponent() {
|
|
206
|
-
const [value, setValue] = useState('');
|
|
207
|
-
const [error, setError] = useState('');
|
|
208
|
-
|
|
209
|
-
const handleChange = (text: string) => {
|
|
210
|
-
setValue(text);
|
|
211
|
-
setError(text.length < 3 ? 'Must be at least 3 characters' : '');
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
<TextInput
|
|
216
|
-
label='Username'
|
|
217
|
-
value={value}
|
|
218
|
-
onChangeText={handleChange}
|
|
219
|
-
helperText={error || undefined}
|
|
220
|
-
status={error ? 'error' : undefined}
|
|
221
|
-
/>
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
```
|
|
176
|
+
<Source of={TextInputStories.WithError} />
|
|
225
177
|
|
|
226
178
|
> **Note:** Helper text is optional. Use `helperText` with `status="error"` to show validation feedback below the input.
|
|
227
179
|
|
|
180
|
+
### With Character Counter
|
|
181
|
+
|
|
182
|
+
Set `maxCount` to enable the character counter. Exceeding the limit does not truncate input.
|
|
183
|
+
|
|
184
|
+
<Source of={TextInputStories.WithCounter} />
|
|
185
|
+
|
|
186
|
+
### With Character Counter Validation
|
|
187
|
+
|
|
188
|
+
When the count exceeds `maxCount`, handle validation in your app — pass `status` and `helperText` yourself:
|
|
189
|
+
|
|
190
|
+
<Source of={TextInputStories.WithCounterExceeded} />
|
|
191
|
+
|
|
192
|
+
### With Native `maxLength` Hard Limit
|
|
193
|
+
|
|
194
|
+
Combine `maxCount` with the native `maxLength` prop to hard-cap the input. The platform blocks input beyond `maxLength`, keeping the counter within bounds:
|
|
195
|
+
|
|
196
|
+
<Source of={TextInputStories.WithNativeMaxLength} />
|
|
197
|
+
|
|
228
198
|
### With Custom Styling
|
|
229
199
|
|
|
230
200
|
While the component comes with predefined styles, you can extend them using the `style` prop:
|
|
@@ -13,7 +13,7 @@ const meta: Meta<typeof TextInput> = {
|
|
|
13
13
|
source: {
|
|
14
14
|
language: 'tsx',
|
|
15
15
|
format: true,
|
|
16
|
-
type: '
|
|
16
|
+
type: 'dynamic',
|
|
17
17
|
},
|
|
18
18
|
},
|
|
19
19
|
},
|
|
@@ -90,6 +90,62 @@ export const WithError: Story = {
|
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
export const WithCounter: Story = {
|
|
94
|
+
render: (args) => <TextInputStory {...args} />,
|
|
95
|
+
args: {
|
|
96
|
+
label: 'Label',
|
|
97
|
+
helperText: 'Info text',
|
|
98
|
+
maxCount: 32,
|
|
99
|
+
editable: true,
|
|
100
|
+
hideClearButton: false,
|
|
101
|
+
keyboardType: 'default',
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const WithCounterExceeded: Story = {
|
|
106
|
+
render: () => {
|
|
107
|
+
const [value, setValue] = useState('This text exceeds the character limit');
|
|
108
|
+
const maxCount = 32;
|
|
109
|
+
const isOverLimit = value.length > maxCount;
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<View
|
|
113
|
+
style={{
|
|
114
|
+
flex: 1,
|
|
115
|
+
minHeight: 96,
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
justifyContent: 'center',
|
|
118
|
+
padding: 24,
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<View style={{ width: '100%', maxWidth: 400 }}>
|
|
122
|
+
<TextInput
|
|
123
|
+
label='Label'
|
|
124
|
+
value={value}
|
|
125
|
+
onChangeText={setValue}
|
|
126
|
+
helperText={isOverLimit ? 'Character limit exceeded' : 'Info text'}
|
|
127
|
+
status={isOverLimit ? 'error' : undefined}
|
|
128
|
+
maxCount={maxCount}
|
|
129
|
+
/>
|
|
130
|
+
</View>
|
|
131
|
+
</View>
|
|
132
|
+
);
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const WithNativeMaxLength: Story = {
|
|
137
|
+
render: (args) => <TextInputStory {...args} />,
|
|
138
|
+
args: {
|
|
139
|
+
label: 'Label',
|
|
140
|
+
helperText: 'Input is capped at 8 characters',
|
|
141
|
+
maxLength: 8,
|
|
142
|
+
maxCount: 8,
|
|
143
|
+
editable: true,
|
|
144
|
+
hideClearButton: false,
|
|
145
|
+
keyboardType: 'default',
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
|
|
93
149
|
export const WithSuccess: Story = {
|
|
94
150
|
render: (args) => (
|
|
95
151
|
<TextInputStory
|
|
@@ -4,6 +4,7 @@ import { render, screen } from '@testing-library/react-native';
|
|
|
4
4
|
import type { ReactElement } from 'react';
|
|
5
5
|
import { CheckmarkCircleFill } from '../../Symbols/Icons/CheckmarkCircleFill';
|
|
6
6
|
import { DeleteCircleFill } from '../../Symbols/Icons/DeleteCircleFill';
|
|
7
|
+
import { InformationFill } from '../../Symbols/Icons/InformationFill';
|
|
7
8
|
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
|
|
8
9
|
import { TextInput } from './TextInput';
|
|
9
10
|
|
|
@@ -36,7 +37,7 @@ describe('TextInput', () => {
|
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
describe('Helper text', () => {
|
|
39
|
-
it('renders neutral helper text
|
|
40
|
+
it('renders neutral helper text with an info icon', () => {
|
|
40
41
|
renderWithProvider(
|
|
41
42
|
<TextInput label='Address' helperText='Enter your ETH address' />,
|
|
42
43
|
);
|
|
@@ -47,6 +48,7 @@ describe('TextInput', () => {
|
|
|
47
48
|
expect(helperText.props.style).toEqual(
|
|
48
49
|
expect.objectContaining({ color: colors.text.muted }),
|
|
49
50
|
);
|
|
51
|
+
expect(screen.UNSAFE_getByType(InformationFill)).toBeTruthy();
|
|
50
52
|
expect(screen.UNSAFE_queryByType(DeleteCircleFill)).toBeNull();
|
|
51
53
|
expect(screen.UNSAFE_queryByType(CheckmarkCircleFill)).toBeNull();
|
|
52
54
|
});
|
|
@@ -87,4 +89,61 @@ describe('TextInput', () => {
|
|
|
87
89
|
expect(screen.UNSAFE_queryByType(DeleteCircleFill)).toBeNull();
|
|
88
90
|
});
|
|
89
91
|
});
|
|
92
|
+
|
|
93
|
+
describe('Character counter', () => {
|
|
94
|
+
it('renders character counter when maxCount is set', () => {
|
|
95
|
+
renderWithProvider(
|
|
96
|
+
<TextInput
|
|
97
|
+
label='Bio'
|
|
98
|
+
value='Hello'
|
|
99
|
+
onChangeText={() => {}}
|
|
100
|
+
maxCount={32}
|
|
101
|
+
/>,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(screen.getByText('5/32')).toBeTruthy();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('does not render character counter when maxCount is omitted', () => {
|
|
108
|
+
renderWithProvider(
|
|
109
|
+
<TextInput label='Bio' value='Hello' onChangeText={() => {}} />,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(screen.queryByText(/\d+\/\d+/)).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('keeps counter muted when count exceeds maxCount', () => {
|
|
116
|
+
const longValue = 'This text exceeds the character limit';
|
|
117
|
+
|
|
118
|
+
renderWithProvider(
|
|
119
|
+
<TextInput
|
|
120
|
+
label='Bio'
|
|
121
|
+
value={longValue}
|
|
122
|
+
onChangeText={() => {}}
|
|
123
|
+
maxCount={32}
|
|
124
|
+
/>,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
const counter = screen.getByText(`${longValue.length}/32`);
|
|
128
|
+
|
|
129
|
+
expect(counter.props.style).toEqual(
|
|
130
|
+
expect.objectContaining({ color: colors.text.muted }),
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('does not truncate input when count exceeds maxCount', () => {
|
|
135
|
+
const longValue = 'This text exceeds the character limit';
|
|
136
|
+
|
|
137
|
+
renderWithProvider(
|
|
138
|
+
<TextInput
|
|
139
|
+
label='Bio'
|
|
140
|
+
value={longValue}
|
|
141
|
+
onChangeText={() => {}}
|
|
142
|
+
maxCount={32}
|
|
143
|
+
/>,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
expect(screen.getByDisplayValue(longValue)).toBeTruthy();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
90
149
|
});
|
|
@@ -15,6 +15,10 @@ figma.connect(
|
|
|
15
15
|
disabled: figma.enum('state', {
|
|
16
16
|
disabled: true,
|
|
17
17
|
}),
|
|
18
|
+
appearance: figma.enum('appearance', {
|
|
19
|
+
gray: 'gray',
|
|
20
|
+
red: 'red',
|
|
21
|
+
}),
|
|
18
22
|
children: figma.string('label'),
|
|
19
23
|
icon: Placeholder,
|
|
20
24
|
},
|
|
@@ -25,6 +29,7 @@ figma.connect(
|
|
|
25
29
|
) => (
|
|
26
30
|
<TileButton
|
|
27
31
|
disabled={props.disabled}
|
|
32
|
+
appearance={props.appearance}
|
|
28
33
|
icon={props.icon}
|
|
29
34
|
onPress={() => {}}
|
|
30
35
|
>
|
|
@@ -30,9 +30,18 @@ TileButton is a compact interactive component that displays an icon above a labe
|
|
|
30
30
|
<Canvas of={TileButtonStories.Base} />
|
|
31
31
|
<Controls of={TileButtonStories.Base} />
|
|
32
32
|
|
|
33
|
+
### Appearance
|
|
34
|
+
|
|
35
|
+
TileButton comes in two appearances:
|
|
36
|
+
|
|
37
|
+
- **gray** (default): neutral surface background with base text and icon color
|
|
38
|
+
- **red**: same surface background but with red text and icon, for destructive or error actions
|
|
39
|
+
|
|
40
|
+
<Canvas of={TileButtonStories.AppearanceShowcase} />
|
|
41
|
+
|
|
33
42
|
### States
|
|
34
43
|
|
|
35
|
-
TileButton supports default, pressed, and disabled states:
|
|
44
|
+
TileButton supports default, pressed, and disabled states. The disabled state renders identically regardless of appearance:
|
|
36
45
|
|
|
37
46
|
<Canvas of={TileButtonStories.DisabledShowcase} />
|
|
38
47
|
|
|
@@ -23,6 +23,10 @@ const meta: Meta<typeof TileButton> = {
|
|
|
23
23
|
mapping: iconOptions,
|
|
24
24
|
control: { type: 'select' },
|
|
25
25
|
},
|
|
26
|
+
appearance: {
|
|
27
|
+
options: ['gray', 'red'],
|
|
28
|
+
control: { type: 'select' },
|
|
29
|
+
},
|
|
26
30
|
onPress: {
|
|
27
31
|
action: 'pressed',
|
|
28
32
|
},
|
|
@@ -47,14 +51,34 @@ export const Base: Story = {
|
|
|
47
51
|
},
|
|
48
52
|
};
|
|
49
53
|
|
|
54
|
+
export const AppearanceShowcase: Story = {
|
|
55
|
+
render: (args) => (
|
|
56
|
+
<View style={{ gap: 16 }}>
|
|
57
|
+
<View style={{ flexDirection: 'row', gap: 16 }}>
|
|
58
|
+
<TileButton icon={Settings} onPress={args.onPress}>
|
|
59
|
+
Gray
|
|
60
|
+
</TileButton>
|
|
61
|
+
<TileButton icon={Settings} appearance='red' onPress={args.onPress}>
|
|
62
|
+
Red
|
|
63
|
+
</TileButton>
|
|
64
|
+
</View>
|
|
65
|
+
</View>
|
|
66
|
+
),
|
|
67
|
+
};
|
|
68
|
+
|
|
50
69
|
export const DisabledShowcase: Story = {
|
|
51
70
|
render: (args) => (
|
|
52
71
|
<View style={{ flexDirection: 'row', gap: 16 }}>
|
|
53
|
-
<TileButton icon={Settings} onPress={args.onPress}>
|
|
54
|
-
Enabled
|
|
55
|
-
</TileButton>
|
|
56
72
|
<TileButton icon={Settings} onPress={args.onPress} disabled>
|
|
57
|
-
|
|
73
|
+
Gray disabled
|
|
74
|
+
</TileButton>
|
|
75
|
+
<TileButton
|
|
76
|
+
icon={Settings}
|
|
77
|
+
appearance='red'
|
|
78
|
+
onPress={args.onPress}
|
|
79
|
+
disabled
|
|
80
|
+
>
|
|
81
|
+
Red disabled
|
|
58
82
|
</TileButton>
|
|
59
83
|
</View>
|
|
60
84
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect, jest } from '@jest/globals';
|
|
2
2
|
import { ledgerLiveThemes } from '@ledgerhq/lumen-design-core';
|
|
3
3
|
import { render, screen, fireEvent } from '@testing-library/react-native';
|
|
4
|
-
import type { ViewStyle } from 'react-native';
|
|
4
|
+
import type { TextStyle, ViewStyle } from 'react-native';
|
|
5
5
|
|
|
6
6
|
import { Settings } from '../../Symbols';
|
|
7
7
|
import { ThemeProvider } from '../ThemeProvider/ThemeProvider';
|
|
@@ -100,4 +100,38 @@ describe('TileButton Component', () => {
|
|
|
100
100
|
expect(button.props.style).toBeDefined();
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
|
+
|
|
104
|
+
describe('Appearances', () => {
|
|
105
|
+
const { dark: darkTheme } = ledgerLiveThemes;
|
|
106
|
+
|
|
107
|
+
it.each([
|
|
108
|
+
['gray' as const, darkTheme.colors.text.base],
|
|
109
|
+
['red' as const, darkTheme.colors.text.error],
|
|
110
|
+
])(
|
|
111
|
+
'should apply correct text color for %s appearance',
|
|
112
|
+
(appearance, expectedColor) => {
|
|
113
|
+
renderWithProvider(
|
|
114
|
+
<TileButton icon={Settings} appearance={appearance}>
|
|
115
|
+
Label
|
|
116
|
+
</TileButton>,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const label = screen.getByText('Label');
|
|
120
|
+
const style = label.props.style as TextStyle;
|
|
121
|
+
expect(style.color).toBe(expectedColor);
|
|
122
|
+
},
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
it('should override red appearance with disabled color when disabled', () => {
|
|
126
|
+
renderWithProvider(
|
|
127
|
+
<TileButton icon={Settings} appearance='red' disabled>
|
|
128
|
+
Label
|
|
129
|
+
</TileButton>,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const label = screen.getByText('Label');
|
|
133
|
+
const style = label.props.style as TextStyle;
|
|
134
|
+
expect(style.color).toBe(darkTheme.colors.text.disabled);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
103
137
|
});
|