Skip to content

Commit 06af55e

Browse files
authored
fix: adjust label and icon props optionality (#3613)
1 parent 9e50236 commit 06af55e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/components/FAB/AnimatedFAB.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export type Props = $RemoveChildren<typeof Surface> & {
9191
*/
9292
extended: boolean;
9393
/**
94-
* @supported Available in v3.x with theme version 3
94+
* @supported Available in v5.x with theme version 3
9595
*
9696
* Color mappings variant for combinations of container and icon colors.
9797
*/

src/components/FAB/FAB.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,25 @@ type FABSize = 'small' | 'medium' | 'large';
2323

2424
type FABMode = 'flat' | 'elevated';
2525

26+
type IconOrLabel =
27+
| {
28+
icon: IconSource;
29+
label?: string;
30+
}
31+
| {
32+
icon?: IconSource;
33+
label: string;
34+
};
35+
2636
export type Props = $RemoveChildren<typeof Surface> & {
37+
// For `icon` and `label` props their types are duplicated due to the generation of documentation.
38+
// Appropriate type for them is `IconOrLabel` contains the both union and intersection types.
2739
/**
28-
* Icon to display for the `FAB`.
40+
* Icon to display for the `FAB`. It's optional only if `label` is defined.
2941
*/
30-
icon: IconSource;
42+
icon?: IconSource;
3143
/**
32-
* Optional label for extended `FAB`.
44+
* Optional label for extended `FAB`. It's optional only if `icon` is defined.
3345
*/
3446
label?: string;
3547
/**
@@ -117,7 +129,7 @@ export type Props = $RemoveChildren<typeof Surface> & {
117129
theme?: ThemeProp;
118130
testID?: string;
119131
ref?: React.RefObject<View>;
120-
};
132+
} & IconOrLabel;
121133

122134
/**
123135
* A floating action button represents the primary action in an application.

0 commit comments

Comments
 (0)