import { useLayoutEffect, useState } from "react"; import { View } from "react-native"; import stylesheet from "./stylesheet"; import { NCoreUIKitLocalize, NCoreUIKitTheme, HighlightButton, PageContainer, SelectBox, TextInput, Header, Switch , Text } from "ncore-ui-kit"; import { useNavigation } from "@react-navigation/native"; import type RootStackParamList from "../../navigation/type"; import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; import type { IHighlightButtonProps } from "ncore-ui-kit"; import { Home as HomeIcon } from "lucide-react-native"; const TYPES: Array = [ "primary", "danger", "warning", "neutral", "success", "info", "glass" ]; const SIZES: Array = [ "small", "medium", "large" ]; const SPREAD_BEHAVIOURS: Array = [ "baseline", "stretch", "free" ]; const TYPES_DATA = TYPES.map((item) => ({ __title: item as string, __key: item as string })); const SIZES_DATA = SIZES.map((item) => ({ __title: item as string, __key: item as string })); const HighlightButtonPage = () => { const { radiuses, borders, spaces, colors } = NCoreUIKitTheme.useContext(); const { localize } = NCoreUIKitLocalize.useContext(); const navigation = useNavigation>(); const [ typeIndex, setTypeIndex ] = useState(0); const [ sizeIndex, setSizeIndex ] = useState(1); const [ spreadIndex, setSpreadIndex ] = useState(0); const [ title, setTitle ] = useState(""); const [ isLoading, setIsLoading ] = useState(false); const [ isDisabled, setIsDisabled ] = useState(false); const [ isCustomPadding, setIsCustomPadding ] = useState(false); const [ showIcon, setShowIcon ] = useState(false); const [ iconDirection, setIconDirection ] = useState<"left" | "right">("left"); useLayoutEffect(() => { navigation.setOptions({ header: () => (
), headerShown: true }); }, []); return ( {localize("highlightButton-desc")} ( ) : undefined } title={ title || localize("highlightButton-example") } spreadBehaviour={SPREAD_BEHAVIOURS[spreadIndex]} isCustomPadding={isCustomPadding} iconDirection={iconDirection} type={TYPES[typeIndex]} size={SIZES[sizeIndex]} isDisabled={isDisabled} isLoading={isLoading} onPress={() => {}} /> { if (selectedItems.length > 0) { const index = TYPES.indexOf( selectedItems[0]! .__key as unknown as IHighlightButtonProps["type"], ); if (index !== -1) setTypeIndex(index); } }} initialSelectedItems={ TYPES_DATA[typeIndex] ? [TYPES_DATA[typeIndex]] : [] } title={localize("highlightButton-changeType")} titleExtractor={(item) => item.__title} keyExtractor={(item) => item.__key} spreadBehaviour="free" data={TYPES_DATA} /> { setSpreadIndex((prev) => prev + 1 > SPREAD_BEHAVIOURS.length - 1 ? 0 : prev + 1, ); }} title={ `${localize("highlightButton-changeSpread")}: ${SPREAD_BEHAVIOURS[spreadIndex]}` } spreadBehaviour="free" /> { if (selectedItems.length > 0) { const index = SIZES.indexOf( selectedItems[0]! .__key as unknown as IHighlightButtonProps["size"], ); if (index !== -1) setSizeIndex(index); } }} initialSelectedItems={ SIZES_DATA[sizeIndex] ? [SIZES_DATA[sizeIndex]] : [] } title={localize("highlightButton-changeSize")} titleExtractor={(item) => item.__title} keyExtractor={(item) => item.__key} spreadBehaviour="free" data={SIZES_DATA} /> setIconDirection( iconDirection === "left" ? "right" : "left", ) } title={localize( "highlightButton-toggleIconDir", )} isActive={iconDirection === "right"} /> setShowIcon(!showIcon)} isActive={showIcon} /> setIsLoading(!isLoading)} isActive={isLoading} /> setIsDisabled(!isDisabled)} isActive={isDisabled} /> setIsCustomPadding(!isCustomPadding)} isActive={isCustomPadding} /> ); }; export default HighlightButtonPage;