|
|
@@ -0,0 +1,183 @@
|
|
|
+import {
|
|
|
+ type TextStyle,
|
|
|
+ type ViewStyle,
|
|
|
+ StyleSheet
|
|
|
+} from "react-native";
|
|
|
+import {
|
|
|
+ type CheckBoxDynamicStyleType,
|
|
|
+ type CheckBoxTypeConstantType,
|
|
|
+ type CheckBoxTypes,
|
|
|
+ type CheckBoxType
|
|
|
+} from "./type";
|
|
|
+import type {
|
|
|
+ Mutable
|
|
|
+} from "../../types";
|
|
|
+
|
|
|
+export const CHECK_BOX_TYPE_STYLES: Record<
|
|
|
+ CheckBoxType,
|
|
|
+ {
|
|
|
+ containerColor: keyof NCoreUIKit.ContainerContentColors;
|
|
|
+ subTitleColor: keyof NCoreUIKit.TextContentColors;
|
|
|
+ borderColor: keyof NCoreUIKit.BorderContentColors;
|
|
|
+ titleColor: keyof NCoreUIKit.TextContentColors;
|
|
|
+ }
|
|
|
+> = {
|
|
|
+ primary: {
|
|
|
+ subTitleColor: "emphasized",
|
|
|
+ containerColor: "primary",
|
|
|
+ borderColor: "emphasized",
|
|
|
+ titleColor: "emphasized"
|
|
|
+ },
|
|
|
+ danger: {
|
|
|
+ containerColor: "danger",
|
|
|
+ subTitleColor: "danger",
|
|
|
+ borderColor: "danger",
|
|
|
+ titleColor: "danger"
|
|
|
+ },
|
|
|
+ success: {
|
|
|
+ containerColor: "success",
|
|
|
+ subTitleColor: "success",
|
|
|
+ borderColor: "success",
|
|
|
+ titleColor: "success"
|
|
|
+ },
|
|
|
+ warning: {
|
|
|
+ containerColor: "warning",
|
|
|
+ subTitleColor: "warning",
|
|
|
+ borderColor: "warning",
|
|
|
+ titleColor: "warning"
|
|
|
+ },
|
|
|
+ info: {
|
|
|
+ containerColor: "info",
|
|
|
+ subTitleColor: "info",
|
|
|
+ borderColor: "info",
|
|
|
+ titleColor: "info"
|
|
|
+ },
|
|
|
+ neutral: {
|
|
|
+ containerColor: "subtle",
|
|
|
+ borderColor: "subtle",
|
|
|
+ subTitleColor: "mid",
|
|
|
+ titleColor: "mid"
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+export const getCheckBoxType = ({
|
|
|
+ type
|
|
|
+}: CheckBoxTypeConstantType): CheckBoxTypes => {
|
|
|
+ const currentType = CHECK_BOX_TYPE_STYLES[type];
|
|
|
+
|
|
|
+ return currentType;
|
|
|
+};
|
|
|
+
|
|
|
+const stylesheet = StyleSheet.create({
|
|
|
+ container: {
|
|
|
+ backgroundColor: "transparent",
|
|
|
+ borderColor: "transparent",
|
|
|
+ flexDirection: "row",
|
|
|
+ borderStyle: "solid",
|
|
|
+ alignItems: "center",
|
|
|
+ display: "flex"
|
|
|
+ },
|
|
|
+ indicatorContainer: {
|
|
|
+ position: "relative"
|
|
|
+ },
|
|
|
+ contentContainer: {
|
|
|
+
|
|
|
+ },
|
|
|
+ titleContainer: {
|
|
|
+ flexDirection: "row",
|
|
|
+ alignItems: "center"
|
|
|
+ },
|
|
|
+ title: {
|
|
|
+ margin: "0",
|
|
|
+ },
|
|
|
+ loading: {},
|
|
|
+ overlay: {
|
|
|
+ position: "absolute",
|
|
|
+ display: "none",
|
|
|
+ bottom: 0,
|
|
|
+ right: 0,
|
|
|
+ left: 0,
|
|
|
+ top: 0
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+export const useStyles = ({
|
|
|
+ displayBehaviourWhileLoading,
|
|
|
+ spreadBehaviour,
|
|
|
+ inlineSpaces,
|
|
|
+ currentType,
|
|
|
+ isDisabled,
|
|
|
+ isLoading,
|
|
|
+ radiuses,
|
|
|
+ borders,
|
|
|
+ colors,
|
|
|
+ isFlip,
|
|
|
+ spaces,
|
|
|
+ type
|
|
|
+}: CheckBoxDynamicStyleType) => {
|
|
|
+ const styleType = type === "danger" ? "error" : type;
|
|
|
+
|
|
|
+ const styles = {
|
|
|
+ container: {
|
|
|
+ borderWidth: borders.line,
|
|
|
+ padding: spaces.spacingSm
|
|
|
+ } as Mutable<ViewStyle>,
|
|
|
+ indicatorContainer: {
|
|
|
+ backgroundColor: colors.content.container[currentType.containerColor],
|
|
|
+ borderRadius: radiuses.actions,
|
|
|
+ padding: spaces.spacingXs
|
|
|
+ } as Mutable<ViewStyle>,
|
|
|
+ contentContainer: {
|
|
|
+ marginLeft: spaces.spacingSm
|
|
|
+ } as Mutable<ViewStyle>,
|
|
|
+ titleContainer: {
|
|
|
+
|
|
|
+ } as Mutable<ViewStyle>,
|
|
|
+ title: {
|
|
|
+ } as Mutable<TextStyle>,
|
|
|
+ loading: {
|
|
|
+ } as Mutable<ViewStyle>,
|
|
|
+ overlay: {
|
|
|
+ borderRadius: radiuses.actions - 2
|
|
|
+ } as Mutable<ViewStyle>,
|
|
|
+ optionalText: {
|
|
|
+ marginLeft: inlineSpaces.subTitle
|
|
|
+ } as Mutable<TextStyle>
|
|
|
+ };
|
|
|
+
|
|
|
+ styles.indicatorContainer.borderColor = styles.indicatorContainer.backgroundColor;
|
|
|
+
|
|
|
+ if (isLoading) {
|
|
|
+ if (displayBehaviourWhileLoading === "disabled") {
|
|
|
+ styles.indicatorContainer.borderColor = colors.system.state.overlay.disabled[styleType];
|
|
|
+
|
|
|
+ styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
|
|
|
+ styles.overlay.display = "flex";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isFlip) {
|
|
|
+ styles.contentContainer.marginRight = spaces.spacingSm;
|
|
|
+ styles.contentContainer.marginLeft = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (spreadBehaviour === "baseline") {
|
|
|
+ styles.indicatorContainer.alignSelf = spreadBehaviour;
|
|
|
+ styles.indicatorContainer.width = "auto";
|
|
|
+ } else if (spreadBehaviour === "stretch") {
|
|
|
+ styles.indicatorContainer.alignSelf = spreadBehaviour;
|
|
|
+ styles.indicatorContainer.justifyContent = "center";
|
|
|
+ styles.indicatorContainer.flexShrink = 1;
|
|
|
+ styles.indicatorContainer.width = "100%";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isDisabled) {
|
|
|
+ styles.indicatorContainer.borderColor = colors.system.state.overlay.disabled[styleType];
|
|
|
+
|
|
|
+ styles.overlay.backgroundColor = colors.system.state.overlay.disabled[styleType];
|
|
|
+ styles.overlay.display = "flex";
|
|
|
+ }
|
|
|
+
|
|
|
+ return styles;
|
|
|
+};
|
|
|
+export default stylesheet;
|