Skip to content

Commit 5ff2ac0

Browse files
committed
feat(*): docs and cleanup
1 parent 0b30b48 commit 5ff2ac0

21 files changed

Lines changed: 681 additions & 1376 deletions

src/components/Avatar/Avatar.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Display avatar image, with default for name initials
1515
<Playground>
1616
<Avatar
1717
source={{ uri: 'https://picsum.photos/200/200', width: 200, height: 200 }}
18-
// Defaults to name if source is not provided
18+
// Fallbacks to name if source is not provided
1919
name="Bill Gates"
2020
size="large"
2121
/>

src/components/Inputs/TextInput.mdx

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Box, State, Icon, TextInput } from '..';
99

1010
# TextInput
1111

12-
Composes of React Native's `TextInput` component (i.e. you can pass its props). [See more details](https://facebook.github.io/react-native/docs/textinput)
12+
Composes React Native's `TextInput`
1313

1414
### Usage
1515

@@ -18,23 +18,44 @@ Composes of React Native's `TextInput` component (i.e. you can pass its props).
1818
{({ state, setState }) => (
1919
<TextInput
2020
value={state.value}
21-
placeholder="Add your own placeholder"
21+
placeholder="TextInput"
2222
size="large"
23-
isDisabled={false}
24-
isInvalid={false}
25-
textContentType="emailAddress" // Enables autofill
26-
keyboardType="email-address"
2723
onChangeText={text => setState({ value: text })}
28-
onSubmitEditing={e => console.log('Submit on enter')}
2924
leftIcon={<Icon name="menu" size={24} />}
30-
rightIcon={undefined}
31-
isClearable={true} // Mutually exclusive with rightIcon
25+
isInvalid={false}
26+
isClearable // Mutually exclusive with rightIcon
3227
onClear={() => console.log('Cleared!')} // Only triggered with `isClearable`
33-
getStyles={(props, theme) => ({
34-
inputStyle: {},
35-
placeholderTextColor: theme.colors.text.muted,
36-
})}
3728
/>
3829
)}
3930
</State>
4031
</Playground>
32+
33+
### Props
34+
35+
<Props of={TextInput} />
36+
37+
### Customization
38+
39+
Using `getStyles` prop
40+
41+
```tsx
42+
TextInputStyles {
43+
inputStyle: TextStyle;
44+
placeholderTextColor: string;
45+
containerStyle: ViewStyle;
46+
leftContainerStyle: ViewStyle;
47+
rightContainerStyle: ViewStyle;
48+
}
49+
50+
getStyles={(TextInputProps, Theme) => TextInputStyles}
51+
```
52+
53+
Markup
54+
55+
```tsx
56+
<View containerStyle>
57+
<View leftContainerStyle>{leftIcon}</View>
58+
<RNTextInput inputStyle placeholderTextColor />
59+
<View rightContainerStyle>{rightIcon}</View>
60+
</View>
61+
```

src/components/Inputs/TextInput.styles.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
import { TextStyle, ViewStyle } from 'react-native';
22

3-
import { ControlSize, Theme } from '../../theme/Theme';
3+
import { Theme } from '../../theme/Theme';
4+
import { TextInputProps } from './TextInput';
45

56
export interface TextInputStyles {
67
inputStyle: TextStyle;
7-
focusedStyle: TextStyle;
88
placeholderTextColor: string;
99
containerStyle: ViewStyle;
1010
leftContainerStyle: ViewStyle;
1111
rightContainerStyle: ViewStyle;
1212
}
1313

14-
export interface TextInputStylesProps {
15-
size: ControlSize;
16-
isDisabled: boolean;
17-
isInvalid: boolean;
18-
numberOfLines?: number;
19-
hasLeftIcon: boolean;
20-
hasRightIcon: boolean;
21-
}
22-
2314
export type GetTextInputStyles = (
24-
textInputStylesProps: TextInputStylesProps,
15+
props: TextInputProps,
2516
theme: Theme,
2617
) => TextInputStyles;
2718

2819
export const getTextInputStyles: GetTextInputStyles = (
29-
{ size, isDisabled, isInvalid, numberOfLines, hasLeftIcon, hasRightIcon },
20+
{
21+
size = 'medium',
22+
isClearable = false,
23+
isDisabled = false,
24+
isInvalid = false,
25+
numberOfLines,
26+
leftIcon,
27+
rightIcon,
28+
},
3029
theme,
3130
) => {
31+
const hasLeftIcon = !!leftIcon;
32+
const hasRightIcon = !!(rightIcon || isClearable);
3233
const controlHeight = theme.controlHeights[size];
3334

3435
return {
3536
containerStyle: {
3637
position: 'relative',
3738
},
38-
focusedStyle: {},
3939
inputStyle: {
4040
backgroundColor: theme.colors.background.content,
4141
borderColor: theme.colors.border.default,

src/components/Inputs/TextInput.tsx

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,48 @@ import {
1717
} from './TextInput.styles';
1818

1919
export interface TextInputProps extends RNTextInputProps {
20-
children?: React.ReactNode;
21-
innerRef?: React.Ref<RNTextInput>;
20+
/**
21+
* Size of the text input.
22+
* @default medium
23+
*/
2224
size?: ControlSize;
25+
26+
/**
27+
* When true, text input is disabled
28+
*/
2329
isDisabled?: boolean;
30+
31+
/**
32+
* When true, text input will be highlighted as invalid
33+
*/
2434
isInvalid?: boolean;
35+
36+
/**
37+
* Icon placed on the left side
38+
*/
2539
leftIcon?: React.ReactNode;
40+
41+
/**
42+
* Icon placed on the left side
43+
*/
2644
rightIcon?: React.ReactNode;
45+
46+
/**
47+
* Called when clear icon is pressed.
48+
*/
2749
onClear?: () => void;
50+
51+
/**
52+
* When true, when value is not empty, a clear icon is displayed
53+
*/
2854
isClearable?: boolean;
55+
56+
/** Use `ref` instead */
57+
innerRef?: React.Ref<RNTextInput>;
58+
59+
/**
60+
* Callback to get element styles.
61+
*/
2962
getStyles?: ReplaceReturnType<
3063
GetTextInputStyles,
3164
DeepPartial<TextInputStyles>
@@ -36,11 +69,10 @@ const TextInputBase = (props: TextInputProps) => {
3669
const {
3770
getStyles,
3871
innerRef,
39-
isClearable,
72+
isClearable = false,
4073
isDisabled = false,
4174
isInvalid = false,
4275
leftIcon,
43-
numberOfLines,
4476
onClear = () => {
4577
return;
4678
},
@@ -62,30 +94,19 @@ const TextInputBase = (props: TextInputProps) => {
6294
containerStyle,
6395
leftContainerStyle,
6496
rightContainerStyle,
65-
} = mergeStyles(getTextInputStyles, getStyles)(
66-
{
67-
hasLeftIcon: !!leftIcon,
68-
hasRightIcon: !!(rightIcon || isClearable),
69-
isDisabled,
70-
isInvalid,
71-
numberOfLines,
72-
size,
73-
},
74-
theme,
75-
);
97+
} = mergeStyles(getTextInputStyles, getStyles)(props, theme);
7698

7799
return (
78100
<View style={containerStyle}>
79101
{leftIcon && <View style={leftContainerStyle}>{leftIcon}</View>}
80102
{/*
81-
// @ts-ignore: name prop being passed */}
103+
// @ts-ignore: name prop being passed for web */}
82104
<RNTextInput
83105
ref={innerRef}
84106
style={inputStyle}
85107
editable={!isDisabled}
86108
placeholderTextColor={placeholderTextColorProp || placeholderTextColor}
87109
name={textContentType}
88-
numberOfLines={numberOfLines}
89110
value={value}
90111
onChangeText={onChangeText}
91112
textContentType={textContentType}

src/components/KitchenSink/KitchenSink.tsx

Lines changed: 13 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const KitchenSink = () => {
8888
width: 200,
8989
height: 200,
9090
}}
91-
// Defaults to name if source is not provided
91+
// Fallbacks to name if source is not provided
9292
name="Bill Gates"
9393
size="large"
9494
/>
@@ -373,22 +373,13 @@ export const KitchenSink = () => {
373373
{({ state, setState }) => (
374374
<TextInput
375375
value={state.value}
376-
placeholder="Add your own placeholder"
376+
placeholder="TextInput"
377377
size="large"
378-
isDisabled={false}
379-
isInvalid={false}
380-
textContentType="emailAddress" // Enables autofill
381-
keyboardType="email-address"
382378
onChangeText={text => setState({ value: text })}
383-
onSubmitEditing={e => console.log('Submit on enter')}
384379
leftIcon={<Icon name="menu" size={24} />}
385-
rightIcon={undefined}
386-
isClearable={true} // Mutually exclusive with rightIcon
380+
isInvalid={false}
381+
isClearable // Mutually exclusive with rightIcon
387382
onClear={() => console.log('Cleared!')} // Only triggered with `isClearable`
388-
getStyles={(props, theme) => ({
389-
inputStyle: {},
390-
placeholderTextColor: theme.colors.text.muted,
391-
})}
392383
/>
393384
)}
394385
</State>
@@ -977,23 +968,11 @@ export const KitchenSink = () => {
977968
{({ state, setState }) => (
978969
<Tabs
979970
activeTabIndex={state.activeTabIndex}
980-
onChange={index => setState({ activeTabIndex: index })}
981-
getStyles={(props, theme) => ({
982-
containerStyle: {},
983-
})}
971+
onTabPress={index => setState({ activeTabIndex: index })}
984972
>
985-
{new Array(4).fill(0).map((v, i) => {
986-
if (i === 0) {
987-
return (
988-
<Tab
989-
key={0}
990-
title="Custom"
991-
onPress={() => setState({ activeTabIndex: 0 })}
992-
/>
993-
);
994-
}
995-
return <Tab key={i} title={`Tab ${i + 1}`} />;
996-
})}
973+
{new Array(4).fill(0).map((v, i) => (
974+
<Tab key={i} title={`Tab ${i + 1}`} />
975+
))}
997976
</Tabs>
998977
)}
999978
</State>
@@ -1006,84 +985,23 @@ export const KitchenSink = () => {
1006985
</Box>
1007986

1008987
<Playground>
1009-
<ToastProvider
1010-
getStyles={(props, theme) => ({
1011-
containerStyle: {},
1012-
})}
1013-
>
988+
<ToastProvider>
1014989
<ToastContext.Consumer>
1015990
{({ notify }) => (
1016991
<Button
1017-
onPress={() => {
992+
onPress={() =>
1018993
notify({
1019994
title: 'Title',
1020995
description: 'Description',
1021-
component: null, // A React Component that overrides title and description
1022-
offset: 16,
1023-
duration: 3000,
1024-
// ...Alert props e.g. getStyles
1025-
});
1026-
}}
1027-
title="Use"
996+
})
997+
}
998+
title="Open toast"
1028999
/>
10291000
)}
10301001
</ToastContext.Consumer>
10311002
</ToastProvider>
10321003
</Playground>
10331004

1034-
<Playground>
1035-
<ToastProvider>
1036-
<ToastContext.Consumer>
1037-
{({ notify }) => (
1038-
<>
1039-
<Button
1040-
onPress={() =>
1041-
notify({
1042-
title: 'Title',
1043-
description: 'Description',
1044-
})
1045-
}
1046-
title="Open default toast"
1047-
/>
1048-
<Button
1049-
onPress={() =>
1050-
notify({
1051-
description: 'Description',
1052-
intent: 'success',
1053-
title: 'Title',
1054-
})
1055-
}
1056-
color="primary"
1057-
title="Open success toast"
1058-
/>
1059-
<Button
1060-
onPress={() =>
1061-
notify({
1062-
description: 'Description',
1063-
intent: 'danger',
1064-
title: 'Title',
1065-
})
1066-
}
1067-
color="danger"
1068-
title="Open danger toast"
1069-
/>
1070-
<Button
1071-
onPress={() =>
1072-
notify({
1073-
description: 'Description',
1074-
intent: 'warning',
1075-
title: 'Title',
1076-
})
1077-
}
1078-
color="secondary"
1079-
title="Open warning toast"
1080-
/>
1081-
</>
1082-
)}
1083-
</ToastContext.Consumer>
1084-
</ToastProvider>
1085-
</Playground>
1086-
10871005
<Box paddingTop={96}>
10881006
<Heading size="xxxlarge" weight="500">
10891007
Heading

src/components/Layout/Container.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Box, Container, LayoutProvider, Text } from '..';
1111

1212
`Container` centers the content with a max-width of defined by Layout (varies depending on screen size)
1313

14-
Recommended usage with `Row and Column` to provide Grid margin
14+
Refer to `Layout` docs for setup
1515

1616
### Usage
1717

0 commit comments

Comments
 (0)