import * as React from "react";
import {
ActivityIndicator,
View,
Text,
StyleSheet,
StyleProp,
ViewStyle,
TextStyle,
Pressable,
PressableProps,
} from "react-native";
import color from "color";
import Config from "../components/Config";
import Elevation from "../components/Elevation";
import { withTheme } from "@draftbit/theme";
import type { ReadTheme } from "@draftbit/theme";
import type { IconSlot } from "../interfaces/Icon";
/**
* A button is component that the user can press to trigger an action.
*
*
*
*
* Text button
*
*
*
* Outlined button
*
*
*
* Contained button
*
*
*
* ## Usage
* ```js
* import * as React from 'react';
* import { Button } from '@draftbit/ui';
*
* const MyComponent = () => (
* console.log('Pressed')}>
* Press me
*
* );
*
* export default MyComponent;
* ```
*/
type Props = {
disabled?: boolean;
type?: "solid" | "outline" | "text";
loading?: boolean;
icon?: string;
labelColor?: string;
color?: string;
children?: React.ReactNode;
onPress: () => void;
elevation?: number;
style?: StyleProp;
theme: ReadTheme;
} & PressableProps &
IconSlot;
/**
* @deprecated DEPRECATED
*/
const Button: React.FC> = ({
Icon,
icon,
disabled = false,
type = "solid",
loading = false,
labelColor,
color: colorOverride,
children,
onPress,
elevation = 0,
theme: { colors, typography },
...rest
}) => {
let backgroundColor, borderColor, textColor, borderWidth;
const buttonColor = colorOverride || colors.branding.primary;
if (type === "solid") {
backgroundColor = buttonColor;
if (disabled) {
textColor = color(colors.background.base).alpha(0.5).rgb().string();
} else {
textColor = labelColor || colors.background.base;
}
} else {
backgroundColor = "transparent";
if (disabled) {
textColor = color(buttonColor).alpha(0.5).rgb().string();
} else {
textColor = labelColor || 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 = {
backgroundColor,
borderColor,
borderWidth,
borderRadius: 8,
};
const textStyle: StyleProp = {
textAlign: "center",
color: textColor,
marginVertical: 16,
marginHorizontal: 16,
};
const iconStyle = [
styles.icon,
{
marginLeft: 16,
marginRight: -8,
width: Config.buttonIconSize,
},
];
return (
{icon && loading !== true ? (
) : null}
{loading ? (
) : null}
{children}
);
};
const styles = StyleSheet.create({
button: {
minWidth: 64,
borderStyle: "solid",
},
content: {
flexDirection: "row",
alignItems: "center",
justifyContent: "center",
},
icon: {
width: Config.buttonIconSize,
},
});
export default withTheme(Button);