|
@@ -3,7 +3,6 @@ import {
|
|
|
useState
|
|
useState
|
|
|
} from "react";
|
|
} from "react";
|
|
|
import {
|
|
import {
|
|
|
- ScrollView,
|
|
|
|
|
View
|
|
View
|
|
|
} from "react-native";
|
|
} from "react-native";
|
|
|
import stylesheet from "./stylesheet";
|
|
import stylesheet from "./stylesheet";
|
|
@@ -12,8 +11,10 @@ import {
|
|
|
type IButtonProps,
|
|
type IButtonProps,
|
|
|
NCoreUIKitTheme,
|
|
NCoreUIKitTheme,
|
|
|
PageContainer,
|
|
PageContainer,
|
|
|
|
|
+ SelectBox,
|
|
|
TextInput,
|
|
TextInput,
|
|
|
Button,
|
|
Button,
|
|
|
|
|
+ Switch,
|
|
|
Header
|
|
Header
|
|
|
} from "ncore-ui-kit";
|
|
} from "ncore-ui-kit";
|
|
|
import {
|
|
import {
|
|
@@ -54,6 +55,21 @@ const BUTTON_SIZES: Array<IButtonProps["size"]> = [
|
|
|
"large"
|
|
"large"
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
|
|
+const BUTTON_TYPES_DATA = BUTTON_TYPES.map(item => ({
|
|
|
|
|
+ __key: item as string,
|
|
|
|
|
+ __title: item as string
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
|
|
+const BUTTON_VARIANTS_DATA = BUTTON_VARIANTS.map(item => ({
|
|
|
|
|
+ __key: item as string,
|
|
|
|
|
+ __title: item as string
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
|
|
+const BUTTON_SIZES_DATA = BUTTON_SIZES.map(item => ({
|
|
|
|
|
+ __key: item as string,
|
|
|
|
|
+ __title: item as string
|
|
|
|
|
+}));
|
|
|
|
|
+
|
|
|
const ButtonPage = () => {
|
|
const ButtonPage = () => {
|
|
|
const {
|
|
const {
|
|
|
radiuses,
|
|
radiuses,
|
|
@@ -68,17 +84,55 @@ const ButtonPage = () => {
|
|
|
|
|
|
|
|
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
|
|
const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
|
|
|
|
|
|
|
|
- const [typeIndex, setTypeIndex] = useState<number>(0);
|
|
|
|
|
- const [spreadIndex, setSpreadIndex] = useState<number>(0);
|
|
|
|
|
- const [variantIndex, setVariantIndex] = useState<number>(0);
|
|
|
|
|
- const [sizeIndex, setSizeIndex] = useState<number>(1);
|
|
|
|
|
- const [title, setTitle] = useState<string>("");
|
|
|
|
|
|
|
+ const [
|
|
|
|
|
+ typeIndex,
|
|
|
|
|
+ setTypeIndex
|
|
|
|
|
+ ] = useState<number>(0);
|
|
|
|
|
+
|
|
|
|
|
+ const [
|
|
|
|
|
+ spreadIndex,
|
|
|
|
|
+ setSpreadIndex
|
|
|
|
|
+ ] = useState<number>(0);
|
|
|
|
|
+
|
|
|
|
|
+ const [
|
|
|
|
|
+ variantIndex,
|
|
|
|
|
+ setVariantIndex
|
|
|
|
|
+ ] = useState<number>(0);
|
|
|
|
|
+
|
|
|
|
|
+ const [
|
|
|
|
|
+ sizeIndex,
|
|
|
|
|
+ setSizeIndex
|
|
|
|
|
+ ] = useState<number>(1);
|
|
|
|
|
+
|
|
|
|
|
+ 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 [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");
|
|
|
|
|
|
|
+ const [
|
|
|
|
|
+ iconDirection,
|
|
|
|
|
+ setIconDirection
|
|
|
|
|
+ ] = useState<"left" | "right">("left");
|
|
|
|
|
|
|
|
useLayoutEffect(() => {
|
|
useLayoutEffect(() => {
|
|
|
navigation.setOptions({
|
|
navigation.setOptions({
|
|
@@ -94,8 +148,11 @@ const ButtonPage = () => {
|
|
|
|
|
|
|
|
return <PageContainer
|
|
return <PageContainer
|
|
|
isWorkWithHeaderSpace={false}
|
|
isWorkWithHeaderSpace={false}
|
|
|
- isScrollable={false}
|
|
|
|
|
- style={[
|
|
|
|
|
|
|
+ isScrollable={true}
|
|
|
|
|
+ scrollViewProps={{
|
|
|
|
|
+ contentContainerStyle: stylesheet.scrollContent
|
|
|
|
|
+ }}
|
|
|
|
|
+ scrollViewStyle={[
|
|
|
stylesheet.container
|
|
stylesheet.container
|
|
|
]}
|
|
]}
|
|
|
>
|
|
>
|
|
@@ -118,8 +175,8 @@ const ButtonPage = () => {
|
|
|
>
|
|
>
|
|
|
<Button
|
|
<Button
|
|
|
spreadBehaviour={BUTTON_SPREAD_BEHAVIOURS[spreadIndex]}
|
|
spreadBehaviour={BUTTON_SPREAD_BEHAVIOURS[spreadIndex]}
|
|
|
|
|
+ title={title || localize("example-button")}
|
|
|
variant={BUTTON_VARIANTS[variantIndex]}
|
|
variant={BUTTON_VARIANTS[variantIndex]}
|
|
|
- title={title || "Example Button"}
|
|
|
|
|
isCustomPadding={isCustomPadding}
|
|
isCustomPadding={isCustomPadding}
|
|
|
type={BUTTON_TYPES[typeIndex]}
|
|
type={BUTTON_TYPES[typeIndex]}
|
|
|
size={BUTTON_SIZES[sizeIndex]}
|
|
size={BUTTON_SIZES[sizeIndex]}
|
|
@@ -141,10 +198,10 @@ const ButtonPage = () => {
|
|
|
/>
|
|
/>
|
|
|
</View>
|
|
</View>
|
|
|
<TextInput
|
|
<TextInput
|
|
|
|
|
+ placeholder={localize("enter-text")}
|
|
|
|
|
+ title={localize("button-title")}
|
|
|
spreadBehaviour="stretch"
|
|
spreadBehaviour="stretch"
|
|
|
- placeholder="Enter text"
|
|
|
|
|
onChangeText={setTitle}
|
|
onChangeText={setTitle}
|
|
|
- title="Button Title"
|
|
|
|
|
value={title}
|
|
value={title}
|
|
|
style={{
|
|
style={{
|
|
|
marginBottom: spaces.spacingMd
|
|
marginBottom: spaces.spacingMd
|
|
@@ -152,93 +209,116 @@ const ButtonPage = () => {
|
|
|
/>
|
|
/>
|
|
|
<View
|
|
<View
|
|
|
style={{
|
|
style={{
|
|
|
|
|
+ justifyContent: "space-between",
|
|
|
gap: spaces.spacingMd,
|
|
gap: spaces.spacingMd,
|
|
|
flexDirection: "row",
|
|
flexDirection: "row",
|
|
|
flexWrap: "wrap",
|
|
flexWrap: "wrap",
|
|
|
width: "100%"
|
|
width: "100%"
|
|
|
}}
|
|
}}
|
|
|
>
|
|
>
|
|
|
- <Button
|
|
|
|
|
- title={`Change Type: ${BUTTON_TYPES[typeIndex]}`}
|
|
|
|
|
- spreadBehaviour="free"
|
|
|
|
|
- variant="outline"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setTypeIndex((typeIndex + 1) % BUTTON_TYPES.length);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <Button
|
|
|
|
|
- title={`Change Variant: ${BUTTON_VARIANTS[variantIndex]}`}
|
|
|
|
|
- spreadBehaviour="free"
|
|
|
|
|
- variant="outline"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setVariantIndex((variantIndex + 1) % BUTTON_VARIANTS.length);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <Button
|
|
|
|
|
- title={`Change Spread: ${BUTTON_SPREAD_BEHAVIOURS[spreadIndex]}`}
|
|
|
|
|
|
|
+ <SelectBox
|
|
|
|
|
+ initialSelectedItems={BUTTON_TYPES_DATA[typeIndex] ? [
|
|
|
|
|
+ BUTTON_TYPES_DATA[typeIndex]
|
|
|
|
|
+ ] : []}
|
|
|
|
|
+ titleExtractor={(item) => item.__title}
|
|
|
|
|
+ keyExtractor={(item) => item.__key}
|
|
|
|
|
+ title={localize("change-type")}
|
|
|
spreadBehaviour="free"
|
|
spreadBehaviour="free"
|
|
|
- variant="outline"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setSpreadIndex((spreadIndex + 1) % BUTTON_SPREAD_BEHAVIOURS.length);
|
|
|
|
|
|
|
+ data={BUTTON_TYPES_DATA}
|
|
|
|
|
+ onChange={(selectedItems) => {
|
|
|
|
|
+ if (selectedItems.length > 0) {
|
|
|
|
|
+ const index = BUTTON_TYPES.indexOf(selectedItems[0]!.__key as IButtonProps["type"]);
|
|
|
|
|
+ if (index !== -1) setTypeIndex(index);
|
|
|
|
|
+ }
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
- <Button
|
|
|
|
|
- title={`Change Size: ${BUTTON_SIZES[sizeIndex]}`}
|
|
|
|
|
|
|
+ <SelectBox
|
|
|
|
|
+ initialSelectedItems={BUTTON_VARIANTS_DATA[variantIndex] ? [
|
|
|
|
|
+ BUTTON_VARIANTS_DATA[variantIndex]
|
|
|
|
|
+ ] : []}
|
|
|
|
|
+ titleExtractor={(item) => item.__title}
|
|
|
|
|
+ keyExtractor={(item) => item.__key}
|
|
|
|
|
+ title={localize("change-variant")}
|
|
|
|
|
+ data={BUTTON_VARIANTS_DATA}
|
|
|
spreadBehaviour="free"
|
|
spreadBehaviour="free"
|
|
|
- variant="outline"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setSizeIndex((sizeIndex + 1) % BUTTON_SIZES.length);
|
|
|
|
|
|
|
+ onChange={(selectedItems) => {
|
|
|
|
|
+ if (selectedItems.length > 0) {
|
|
|
|
|
+ const index = BUTTON_VARIANTS.indexOf(selectedItems[0]!.__key as IButtonProps["variant"]);
|
|
|
|
|
+ if (index !== -1) setVariantIndex(index);
|
|
|
|
|
+ }
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
<Button
|
|
<Button
|
|
|
- title={`Toggle Icon: ${showIcon ? "ON" : "OFF"}`}
|
|
|
|
|
- variant={showIcon ? "filled" : "outline"}
|
|
|
|
|
|
|
+ title={`${localize("change-spread")}: ${BUTTON_SPREAD_BEHAVIOURS[spreadIndex]}`}
|
|
|
|
|
+ verticalLocationForStretchFix="center"
|
|
|
|
|
+ isFixVerticalStretch={true}
|
|
|
spreadBehaviour="free"
|
|
spreadBehaviour="free"
|
|
|
- size="small"
|
|
|
|
|
onPress={() => {
|
|
onPress={() => {
|
|
|
- setShowIcon(!showIcon);
|
|
|
|
|
|
|
+ setSpreadIndex(prev => prev + 1 > BUTTON_SPREAD_BEHAVIOURS.length - 1 ? 0 : prev + 1);
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
- <Button
|
|
|
|
|
- title={`Toggle Icon Direction: ${iconDirection}`}
|
|
|
|
|
|
|
+ <SelectBox
|
|
|
|
|
+ initialSelectedItems={BUTTON_SIZES_DATA[sizeIndex] ? [
|
|
|
|
|
+ BUTTON_SIZES_DATA[sizeIndex]
|
|
|
|
|
+ ] : []}
|
|
|
|
|
+ titleExtractor={(item) => item.__title}
|
|
|
|
|
+ keyExtractor={(item) => item.__key}
|
|
|
|
|
+ title={localize("change-size")}
|
|
|
spreadBehaviour="free"
|
|
spreadBehaviour="free"
|
|
|
- variant="outline"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setIconDirection(iconDirection === "left" ? "right" : "left");
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <Button
|
|
|
|
|
- title={`Toggle Loading: ${isLoading ? "ON" : "OFF"}`}
|
|
|
|
|
- variant={isLoading ? "filled" : "outline"}
|
|
|
|
|
- spreadBehaviour="free"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setIsLoading(!isLoading);
|
|
|
|
|
|
|
+ data={BUTTON_SIZES_DATA}
|
|
|
|
|
+ onChange={(selectedItems) => {
|
|
|
|
|
+ if (selectedItems.length > 0) {
|
|
|
|
|
+ const index = BUTTON_SIZES.indexOf(selectedItems[0]!.__key as IButtonProps["size"]);
|
|
|
|
|
+ if (index !== -1) setSizeIndex(index);
|
|
|
|
|
+ }
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
- <Button
|
|
|
|
|
- title={`Toggle Disabled: ${isDisabled ? "ON" : "OFF"}`}
|
|
|
|
|
- variant={isDisabled ? "filled" : "outline"}
|
|
|
|
|
- spreadBehaviour="free"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setIsDisabled(!isDisabled);
|
|
|
|
|
- }}
|
|
|
|
|
- />
|
|
|
|
|
- <Button
|
|
|
|
|
- title={`Toggle Custom Padding: ${isCustomPadding ? "ON" : "OFF"}`}
|
|
|
|
|
- variant={isCustomPadding ? "filled" : "outline"}
|
|
|
|
|
- spreadBehaviour="free"
|
|
|
|
|
- size="small"
|
|
|
|
|
- onPress={() => {
|
|
|
|
|
- setIsCustomPadding(!isCustomPadding);
|
|
|
|
|
|
|
+ <View
|
|
|
|
|
+ style={{
|
|
|
|
|
+ justifyContent: "space-between",
|
|
|
|
|
+ flexDirection: "row",
|
|
|
|
|
+ alignItems: "center",
|
|
|
|
|
+ flexWrap: "wrap",
|
|
|
|
|
+ width: "100%"
|
|
|
}}
|
|
}}
|
|
|
- />
|
|
|
|
|
|
|
+ >
|
|
|
|
|
+ <Switch
|
|
|
|
|
+ title={localize("toggle-icon-direction")}
|
|
|
|
|
+ isActive={iconDirection === "right"}
|
|
|
|
|
+ subTitle={localize(iconDirection)}
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ setIconDirection(iconDirection === "left" ? "right" : "left");
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Switch
|
|
|
|
|
+ title={localize("toggle-icon")}
|
|
|
|
|
+ isActive={showIcon}
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ setShowIcon(!showIcon);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Switch
|
|
|
|
|
+ title={localize("toggle-loading")}
|
|
|
|
|
+ isActive={isLoading}
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ setIsLoading(!isLoading);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Switch
|
|
|
|
|
+ title={localize("toggle-disabled")}
|
|
|
|
|
+ isActive={isDisabled}
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ setIsDisabled(!isDisabled);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Switch
|
|
|
|
|
+ title={localize("toggle-custom-padding")}
|
|
|
|
|
+ isActive={isCustomPadding}
|
|
|
|
|
+ onPress={() => {
|
|
|
|
|
+ setIsCustomPadding(!isCustomPadding);
|
|
|
|
|
+ }}
|
|
|
|
|
+ />
|
|
|
|
|
+ </View>
|
|
|
</View>
|
|
</View>
|
|
|
</View>
|
|
</View>
|
|
|
</PageContainer>;
|
|
</PageContainer>;
|