| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- import {
- useLayoutEffect,
- useState
- } from "react";
- import {
- View
- } from "react-native";
- import stylesheet from "./stylesheet";
- import {
- NCoreUIKitLocalize,
- NCoreUIKitTheme,
- PageContainer,
- TextAreaInput,
- CodeViewer,
- SelectBox,
- TextInput,
- Button,
- 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 {
- ITextAreaInputProps
- } from "ncore-ui-kit";
- const TYPES: Array<ITextAreaInputProps["type"]> = [
- "default",
- "danger",
- "warning",
- "question",
- "success",
- "info"
- ];
- const SPREAD_BEHAVIOURS: Array<ITextAreaInputProps["spreadBehaviour"]> = [
- "baseline",
- "stretch",
- "free"
- ];
- const TYPES_DATA = TYPES.map((item) => ({
- __title: item as string,
- __key: item as string
- }));
- const TextAreaInputPage = () => {
- const {
- radiuses,
- borders,
- spaces,
- colors
- } = NCoreUIKitTheme.useContext();
- const {
- localize
- } = NCoreUIKitLocalize.useContext();
- const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
- const [
- typeIndex,
- setTypeIndex
- ] = useState<number>(0);
- const [
- spreadIndex,
- setSpreadIndex
- ] = useState<number>(0);
- const [
- title,
- setTitle
- ] = useState<string>("");
- const [
- isDisabled,
- setIsDisabled
- ] = useState<boolean>(false);
- const [
- isCleanEnabled,
- setIsCleanEnabled
- ] = useState<boolean>(true);
- const [
- isRequired,
- setIsRequired
- ] = useState<boolean>(false);
- const [
- isOptional,
- setIsOptional
- ] = useState<boolean>(false);
- const [
- val,
- setVal
- ] = useState<string>("");
- useLayoutEffect(() => {
- navigation.setOptions({
- header: () => <Header
- title={localize("textAreaInput-title")}
- isWrapSafeareaContext={false}
- navigation={navigation}
- isGoBackEnable={true}
- />,
- headerShown: true
- });
- }, []);
- return <PageContainer
- scrollViewProps={{
- contentContainerStyle: stylesheet.scrollContent
- }}
- isWorkWithHeaderSpace={false}
- scrollViewStyle={[
- stylesheet.container
- ]}
- isScrollable={true}
- >
- <View
- style={[
- stylesheet.contentContainer
- ]}
- >
- <Text
- style={stylesheet.descText}
- variant="bodyMediumSize"
- color="mid"
- >
- {localize("textAreaInput-desc")}
- </Text>
- <View
- style={[
- stylesheet.previewContainer,
- {
- borderColor: colors.content.border.subtle,
- marginBottom: spaces.spacingMd,
- borderRadius: radiuses.form,
- borderWidth: borders.line,
- padding: spaces.spacingMd
- }
- ]}
- >
- <TextAreaInput
- spreadBehaviour={SPREAD_BEHAVIOURS[spreadIndex]}
- title={
- title ||
- localize("textAreaInput-exampleTitle")
- }
- placeholder={localize(
- "textAreaInput-placeholder",
- )}
- isCleanEnabled={isCleanEnabled}
- isUpdateOnRealtime={true}
- type={TYPES[typeIndex]}
- isDisabled={isDisabled}
- isRequired={isRequired}
- isOptional={isOptional}
- onChangeText={setVal}
- value={val}
- />
- </View>
- <View
- style={{
- marginBottom: spaces.spacingMd
- }}
- >
- <Text
- style={{
- marginBottom: spaces.spacingSm
- }}
- variant="headlineSmallSize"
- >
- {localize("usage")}
- </Text>
- <CodeViewer
- code={"import {\n TextAreaInput\n} from \"ncore-ui-kit\";\n\n<TextAreaInput\n title=\"Title\"\n placeholder=\"Placeholder\"\n value={value}\n onChangeText={setValue}\n/>"}
- language="tsx"
- />
- </View>
- <TextInput
- placeholder={localize("textAreaInput-enterTitle")}
- title={localize("textAreaInput-titleLabel")}
- style={{
- marginBottom: spaces.spacingMd
- }}
- spreadBehaviour="stretch"
- onChangeText={setTitle}
- value={title}
- />
- <View
- style={[
- stylesheet.rowContainer,
- {
- gap: spaces.spacingMd
- }
- ]}
- >
- <SelectBox
- onChange={(selectedItems) => {
- if (selectedItems.length > 0) {
- const index = TYPES.indexOf(
- selectedItems[0]!
- .__key as unknown as ITextAreaInputProps["type"],
- );
- if (index !== -1) setTypeIndex(index);
- }
- }}
- title={localize("textAreaInput-changeType")}
- titleExtractor={(item) => item.__title}
- keyExtractor={(item) => item.__key}
- initialSelectedItems={
- TYPES_DATA[typeIndex] ? [
- TYPES_DATA[typeIndex]!
- ] : []
- }
- spreadBehaviour="free"
- data={TYPES_DATA}
- />
- <Button
- title={
- `${localize("textAreaInput-changeSpread")}: ${SPREAD_BEHAVIOURS[spreadIndex]}`
- }
- onPress={() => {
- setSpreadIndex((prev) =>
- prev + 1 > SPREAD_BEHAVIOURS.length - 1
- ? 0
- : prev + 1,
- );
- }}
- spreadBehaviour="free"
- />
- <View
- style={stylesheet.switchesContainer}
- >
- <Switch
- onPress={() => setIsDisabled(!isDisabled)}
- title={localize(
- "textAreaInput-toggleDisabled",
- )}
- spreadBehaviour="free"
- isActive={isDisabled}
- />
- <Switch
- onPress={() => setIsCleanEnabled(!isCleanEnabled)}
- title={localize("textAreaInput-toggleClean")}
- isActive={isCleanEnabled}
- spreadBehaviour="free"
- />
- <Switch
- onPress={() => setIsRequired(!isRequired)}
- title={localize(
- "textAreaInput-toggleRequired",
- )}
- spreadBehaviour="free"
- isActive={isRequired}
- />
- <Switch
- onPress={() => setIsOptional(!isOptional)}
- title={localize(
- "textAreaInput-toggleOptional",
- )}
- spreadBehaviour="free"
- isActive={isOptional}
- />
- </View>
- </View>
- </View>
- </PageContainer>;
- };
- export default TextAreaInputPage;
|