import * as React from "react";
import {
ActivityIndicator,
View,
StyleSheet,
StyleProp,
ViewStyle,
TextStyle,
Pressable,
PressableProps,
} from "react-native";
import color from "color";
import Config from "../components/Config";
import Text from "../components/Text";
import Elevation from "../components/Elevation";
import { withTheme } from "@draftbit/theme";
import type { ReadTheme } from "@draftbit/theme";
import type { IconSlot } from "../interfaces/Icon";
/**
* A floating action button represents the primary action in an application.
*
*
*

*

*
*
* ## Usage
* ```js
* import * as React from 'react';
* import { StyleSheet } from 'react-native';
* import { FAB } from '@draftbit/ui';
*
* const MyComponent = () => (
* console.log('Pressed')}
* />
* );
*
* const styles = StyleSheet.create({
* fab: {
* position: 'absolute',
* margin: 16,
* right: 0,
* bottom: 0,
* },
* })
*
* export default MyComponent;
* ```
*/
type Props = {
disabled?: boolean;
type?: "solid" | "extended" | "outline" | "fixed" | "standard";
loading?: boolean;
icon?: string;
color?: string;
label?: string;
onPress: () => void;
elevation?: number;
theme: ReadTheme;
style?: StyleProp;
} & PressableProps &
IconSlot;
/**
* @deprecated DEPRECATED
*/
const FAB: React.FC> = ({
Icon,
icon,
disabled = false,
type = "solid",
loading = false,
color: colorOverride,
label,
onPress,
elevation = 0,
style,
theme: { colors, typography },
...rest
}) => {
let backgroundColor, borderColor, textColor, borderWidth;
const buttonColor = colorOverride || colors.branding.primary;
if (type === "standard" || type === "extended" || type === "fixed") {
backgroundColor = buttonColor;
if (disabled) {
textColor = color(colors.background.base).alpha(0.5).rgb().string();
} else {
textColor = colors.background.base;
}
} else {
backgroundColor = "transparent";
if (disabled) {
textColor = color(buttonColor).alpha(0.5).rgb().string();
} else {
textColor = buttonColor;
}
}
if (type === "outline") {
if (disabled) {
borderColor = color(buttonColor).alpha(0.5).rgb().string();
} else {
borderColor = buttonColor;
}
borderWidth = StyleSheet.hairlineWidth;
} else {
borderColor = "transparent";
borderWidth = 0;
}
const buttonStyle: StyleProp = {
backgroundColor,
borderColor,
borderWidth,
borderRadius: 8,
alignItems: "center",
justifyContent: "center",
};
const buttonStyles: StyleProp[] = [styles.button, buttonStyle];
const contentStyle: StyleProp[] = [styles.content];
const textStyle: StyleProp = {
textAlign: "center",
color: textColor,
};
const iconStyle: StyleProp[] = [
styles.icon,
{
width: Config.buttonIconSize,
},
];
if (type === "standard" || type === "outline") {
buttonStyle.width = Config.FABSize;
buttonStyle.height = Config.FABSize;
buttonStyle.borderRadius = Config.FABBorderRadius;
contentStyle.push({
width: Config.FABSize,
height: Config.FABSize,
});
}
if (type === "extended" || type === "fixed") {
iconStyle.push({
marginLeft: 16,
marginRight: -8,
});
textStyle.margin = 16;
}
if (type === "fixed") {
buttonStyles.push({
height: Config.FABFixedHeight,
alignSelf: "stretch",
});
}
return (
{icon && loading !== true ? (
) : null}
{loading ? (
) : null}
{label ? (
{label}
) : null}
);
};
const styles = StyleSheet.create({
button: {
borderStyle: "solid",
},
content: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
icon: {
alignItems: "center",
justifyContent: "center",
width: Config.buttonIconSize,
},
});
export default withTheme(FAB);