| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320 |
- 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<IHighlightButtonProps["type"]> = [
- "primary",
- "danger",
- "warning",
- "neutral",
- "success",
- "info",
- "glass"
- ];
- const SIZES: Array<IHighlightButtonProps["size"]> = [
- "small",
- "medium",
- "large"
- ];
- const SPREAD_BEHAVIOURS: Array<IHighlightButtonProps["spreadBehaviour"]> = [
- "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<NativeStackNavigationProp<RootStackParamList>>();
- const [
- typeIndex,
- setTypeIndex
- ] = useState<number>(0);
- const [
- sizeIndex,
- setSizeIndex
- ] = useState<number>(1);
- const [
- spreadIndex,
- setSpreadIndex
- ] = useState<number>(0);
- const [
- title,
- setTitle
- ] = useState<string>("");
- const [
- isLoading,
- setIsLoading
- ] = useState<boolean>(false);
- const [
- isDisabled,
- setIsDisabled
- ] = useState<boolean>(false);
- const [
- isCustomPadding,
- setIsCustomPadding
- ] = useState<boolean>(false);
- const [
- showIcon,
- setShowIcon
- ] = useState<boolean>(false);
- const [
- iconDirection,
- setIconDirection
- ] = useState<"left" | "right">("left");
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => (
- <Header
- title={localize("highlightButton-title")}
- isWrapSafeareaContext={false}
- navigation={navigation}
- isGoBackEnable={true}
- />
- ),
- headerShown: true
- });
- }, []);
- return (
- <PageContainer
- scrollViewProps={{
- contentContainerStyle: stylesheet.scrollContent
- }}
- scrollViewStyle={[stylesheet.container]}
- isWorkWithHeaderSpace={false}
- isScrollable={true}
- >
- <View style={[stylesheet.contentContainer]}>
- <Text
- variant="bodyMediumSize"
- color="mid"
- style={{
- marginBottom: 20
- }}
- >
- {localize("highlightButton-desc")}
- </Text>
- <View
- style={{
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd,
- justifyContent: "center",
- alignItems: "center",
- minHeight: 120
- }}
- >
- <HighlightButton
- icon={
- showIcon
- ? ({
- color,
- size
- }) => (
- <HomeIcon
- color={colors.content.icon[color]}
- size={size}
- />
- )
- : 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={() => {}}
- />
- </View>
- <TextInput
- placeholder={localize("highlightButton-enterText")}
- title={localize("highlightButton-titleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setTitle}
- value={title}
- />
- <View
- style={{
- justifyContent: "space-between",
- gap: spaces.spacingMd,
- flexDirection: "row",
- flexWrap: "wrap",
- width: "100%"
- }}
- >
- <SelectBox
- onChange={(selectedItems) => {
- 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}
- />
- <HighlightButton
- onPress={() => {
- setSpreadIndex((prev) =>
- prev + 1 > SPREAD_BEHAVIOURS.length - 1
- ? 0
- : prev + 1,
- );
- }}
- title={
- `${localize("highlightButton-changeSpread")}: ${SPREAD_BEHAVIOURS[spreadIndex]}`
- }
- spreadBehaviour="free"
- />
- <SelectBox
- onChange={(selectedItems) => {
- 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}
- />
- <View
- style={{
- justifyContent: "space-between",
- flexDirection: "row",
- alignItems: "center",
- flexWrap: "wrap",
- width: "100%"
- }}
- >
- <Switch
- onPress={() =>
- setIconDirection(
- iconDirection === "left" ? "right" : "left",
- )
- }
- title={localize(
- "highlightButton-toggleIconDir",
- )}
- isActive={iconDirection === "right"}
- />
- <Switch
- title={localize(
- "highlightButton-toggleIcon",
- )}
- onPress={() => setShowIcon(!showIcon)}
- isActive={showIcon}
- />
- <Switch
- title={localize(
- "highlightButton-toggleLoading",
- )}
- onPress={() => setIsLoading(!isLoading)}
- isActive={isLoading}
- />
- <Switch
- title={localize(
- "highlightButton-toggleDisabled",
- )}
- onPress={() => setIsDisabled(!isDisabled)}
- isActive={isDisabled}
- />
- <Switch
- title={localize(
- "highlightButton-toggleCustomPadding",
- )}
- onPress={() => setIsCustomPadding(!isCustomPadding)}
- isActive={isCustomPadding}
- />
- </View>
- </View>
- </View>
- </PageContainer>
- );
- };
- export default HighlightButtonPage;
|