Skip to content

Commit 8245f07

Browse files
committed
fix: allow booleans in place of strings
1 parent c7e57d9 commit 8245f07

9 files changed

Lines changed: 41 additions & 24 deletions

File tree

src/components/Alert/Alert.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import { View, ViewProps } from 'react-native';
44

55
import { useTheme } from '../../theme';
66
import { getOverrides, WithOverrides } from '../../utils/overrides';
7+
import { OptionalString } from '../../utils/types';
78
import { Icon, IconProps } from '../Icon';
89
import { Text, TextProps } from '../Typography';
910

1011
export type Intent = 'danger' | 'info' | 'success' | 'warning';
1112

1213
interface AlertBaseProps {
1314
/** Title of the alert. */
14-
title?: string;
15+
title?: OptionalString;
1516

1617
/** Description of the alert. */
17-
description?: string;
18+
description?: OptionalString;
1819

1920
/**
2021
* Intent of the alert.
@@ -206,12 +207,14 @@ const StyledBody = (props: BodyProps) => {
206207
};
207208

208209
interface TitleProps extends TextProps, PropsWithIntent {
209-
title?: string;
210+
title?: OptionalString;
210211
}
211212

212213
const StyledTitle = (props: TitleProps) => {
213214
const { title, intent = defaultProps.intent, ...textProps } = props;
214215

216+
if (!title) return null;
217+
215218
return (
216219
<Text weight="bold" {...textProps}>
217220
{title}
@@ -220,12 +223,14 @@ const StyledTitle = (props: TitleProps) => {
220223
};
221224

222225
interface DescriptionProps extends TextProps, PropsWithIntent {
223-
description?: string;
226+
description?: OptionalString;
224227
}
225228

226229
const StyledDescription = (props: DescriptionProps) => {
227230
const { description, intent = defaultProps.intent, ...textProps } = props;
228231

232+
if (!description) return null;
233+
229234
return <Text {...textProps}>{description}</Text>;
230235
};
231236

src/components/Badge/Badge.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { useTheme } from '../../theme';
66
import { ContainerShape, ControlSize, FillColor } from '../../theme/Theme';
77
import { isControlSize } from '../../utils/isControlSize';
88
import { getOverrides, WithOverrides } from '../../utils/overrides';
9+
import { OptionalString } from '../../utils/types';
910
import { Text, TextProps } from '../Typography';
1011

1112
interface BadgeBaseProps {
1213
/** Title of the badge */
13-
title?: string;
14+
title?: OptionalString;
1415

1516
/**
1617
* Color of the badge
@@ -178,7 +179,7 @@ const StyledRoot = (props: RootProps) => {
178179

179180
interface TitleProps extends TextProps {
180181
color?: FillColor;
181-
title?: string;
182+
title?: OptionalString;
182183
isSolid?: boolean;
183184
}
184185

src/components/Button/Button.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import {
1010
import { ButtonColor, ControlSize, Theme, useTheme } from '../../theme';
1111
import { isControlSize } from '../../utils/isControlSize';
1212
import { getOverrides, WithOverrides } from '../../utils/overrides';
13+
import { OptionalString } from '../../utils/types';
1314
import { Dots } from '../LoadingIndicators';
1415
import { Text, TextProps } from '../Typography';
1516

1617
interface ButtonBaseProps {
1718
/** Title of the button */
18-
title?: string;
19+
title?: OptionalString;
1920

2021
/**
2122
* The color of the button.
@@ -340,7 +341,7 @@ const getButtonTextColor = (theme: Theme): ButtonTextColors => {
340341
interface TitleProps extends TextProps {
341342
size?: ControlSize | number;
342343
color?: ButtonColor;
343-
title?: string;
344+
title?: OptionalString;
344345
appearance?: ButtonAppearance;
345346
isDisabled?: boolean;
346347
}
@@ -361,6 +362,8 @@ const StyledTitle = (props: TitleProps) => {
361362
? theme.textSizes[size]
362363
: theme.textSizes.medium;
363364

365+
if (!title) return null;
366+
364367
return (
365368
<Text
366369
weight="bold"
@@ -404,7 +407,7 @@ const StyledLoading = (props: LoadingProps) => {
404407
interface IconProps extends PropsWithChildren {
405408
size?: ControlSize | number;
406409
color?: ButtonColor;
407-
title?: string;
410+
title?: OptionalString;
408411
appearance?: ButtonAppearance;
409412
isDisabled?: boolean;
410413
isLoading?: boolean;

src/components/Collapsible/Collapsible.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import {
99

1010
import { useTheme } from '../../theme';
1111
import { getOverrides, WithOverrides } from '../../utils/overrides';
12+
import { OptionalString } from '../../utils/types';
1213
import { Icon } from '../Icon';
1314
import { Text, TextProps } from '../Typography';
1415

1516
interface CollapsibleBaseProps {
1617
/** Title of the collapsible */
17-
title?: string;
18+
title?: OptionalString;
1819

1920
/** Content revealed when collapsible is opened */
2021
children?: React.ReactNode;
@@ -167,12 +168,14 @@ const StyledTouchable = (props: TouchableProps) => {
167168
};
168169

169170
interface TitleProps extends TextProps {
170-
title?: string;
171+
title?: OptionalString;
171172
}
172173

173174
const StyledTitle = (props: TitleProps) => {
174175
const { title, style, ...textProps } = props;
175176

177+
if (!title) return null;
178+
176179
return (
177180
<Text size="large" style={[{}, style]} {...textProps}>
178181
{title}

src/components/Form/FormField.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { View, ViewProps } from 'react-native';
44

55
import { useTheme } from '../../theme';
66
import { getOverrides, WithOverrides } from '../../utils/overrides';
7+
import { OptionalString } from '../../utils/types';
78
import { Label, LabelProps, Text, TextProps } from '../Typography';
89

910
type FormFieldLabelPosition = 'top' | 'left' | 'right';
@@ -12,12 +13,12 @@ interface FormFieldBaseProps {
1213
/**
1314
* Error message of the field
1415
*/
15-
error?: string | false;
16+
error?: OptionalString;
1617

1718
/**
1819
* Label of the field.
1920
*/
20-
label?: string | false;
21+
label?: OptionalString;
2122

2223
/**
2324
* Position of the field.
@@ -28,7 +29,7 @@ interface FormFieldBaseProps {
2829
/**
2930
* Description of the field.
3031
*/
31-
description?: string;
32+
description?: OptionalString;
3233

3334
/** Content to wrap FormField with. */
3435
children?: React.ReactNode;
@@ -112,7 +113,7 @@ const StyledRoot = (props: RootProps) => {
112113
};
113114

114115
interface DescriptionProps extends TextProps, PropsWithChildren {
115-
description?: string | false;
116+
description?: OptionalString;
116117
}
117118

118119
const StyledDescription = (props: DescriptionProps) => {
@@ -137,7 +138,7 @@ const StyledDescription = (props: DescriptionProps) => {
137138
};
138139

139140
interface ErrorProps extends TextProps, PropsWithChildren {
140-
error?: string | false;
141+
error?: OptionalString;
141142
}
142143

143144
const StyledError = (props: ErrorProps) => {

src/components/ListItem/ListItem.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ import {
1111

1212
import { useTheme } from '../../theme';
1313
import { getOverrides, WithOverrides } from '../../utils/overrides';
14+
import { OptionalString } from '../../utils/types';
1415
import { Avatar, AvatarProps } from '../Avatar';
1516
import { Text, TextProps } from '../Typography';
1617

1718
interface ListItemBaseProps {
1819
/**
1920
* Title of the list item
2021
*/
21-
title?: string | false;
22+
title?: OptionalString;
2223

2324
/**
2425
* Description of the list item
2526
*/
26-
description?: string | false;
27+
description?: OptionalString;
2728

2829
/**
2930
* Source of the avatar
@@ -194,7 +195,7 @@ const StyledTouchable = (props: TouchableProps) => {
194195
};
195196

196197
interface TitleProps extends TextProps {
197-
title?: string | false;
198+
title?: OptionalString;
198199
}
199200

200201
const StyledTitle = (props: TitleProps) => {
@@ -231,7 +232,7 @@ const StyledTextWrapper = (props: TextWrapperProps) => {
231232
};
232233

233234
interface DescriptionProps extends TextProps {
234-
description?: string | false;
235+
description?: OptionalString;
235236
}
236237

237238
const StyledDescription = (props: DescriptionProps) => {

src/components/ListPicker/ListPicker.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { FlatList, FlatListProps } from 'react-native';
44

55
import { useTheme } from '../../theme';
66
import { getOverrides, Override, WithOverrides } from '../../utils/overrides';
7+
import { OptionalString } from '../../utils/types';
78
import { Box } from '../Box';
89
import { Checkbox } from '../Checkbox';
910
import { ListItem, ListItemProps } from '../ListItem';
@@ -15,7 +16,7 @@ type Value<TIsMulti extends boolean, TValue extends any> = TIsMulti extends true
1516
export interface ListPickerOption<TValue extends any> {
1617
value: TValue;
1718
label: string;
18-
description?: string;
19+
description?: OptionalString;
1920
}
2021

2122
interface ListPickerBaseProps<TIsMulti extends boolean, TValue extends any> {
@@ -155,7 +156,7 @@ interface ListPickerItemProps<TValue extends any> {
155156
onPress?: (value: TValue, index: number, isSelected: boolean) => void;
156157
value: TValue;
157158
label: string;
158-
description?: string;
159+
description?: OptionalString;
159160
override?: Override<ListPickerItemProps<TValue>, ListItemProps>;
160161
}
161162

src/components/Typography/Label.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Platform, View, ViewProps, ViewStyle } from 'react-native';
44

55
import { useTheme } from '../../theme';
66
import { getOverrides, WithOverrides } from '../../utils/overrides';
7+
import { OptionalString } from '../../utils/types';
78
import { Text, TextProps } from './Text';
89

910
type LabelPosition = 'top' | 'left' | 'right';
@@ -12,7 +13,7 @@ interface LabelBaseProps {
1213
/**
1314
* Label of the field.
1415
*/
15-
label?: string | false;
16+
label?: OptionalString;
1617

1718
/**
1819
* Position of the field.
@@ -139,7 +140,7 @@ const StyledWrapper = (props: WrapperProps) => {
139140
};
140141

141142
interface LabelTextProps extends TextProps, PropsWithChildren {
142-
label?: string | false;
143+
label?: OptionalString;
143144
position?: LabelPosition;
144145
}
145146

src/utils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type OptionalString = string | false | null | undefined;

0 commit comments

Comments
 (0)