index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {
  2. useLayoutEffect,
  3. useState
  4. } from "react";
  5. import {
  6. View
  7. } from "react-native";
  8. import stylesheet from "./stylesheet";
  9. import {
  10. NCoreUIKitLocalize,
  11. NCoreUIKitTheme,
  12. MarkdownViewer,
  13. PageContainer,
  14. TextAreaInput,
  15. CodeViewer,
  16. Header,
  17. Text
  18. } from "ncore-ui-kit";
  19. import {
  20. useNavigation
  21. } from "@react-navigation/native";
  22. import type RootStackParamList from "../../../navigation/type";
  23. import type {
  24. NativeStackNavigationProp
  25. } from "@react-navigation/native-stack";
  26. const MarkdownViewerPage = () => {
  27. const {
  28. radiuses,
  29. borders,
  30. spaces,
  31. colors
  32. } = NCoreUIKitTheme.useContext();
  33. const {
  34. localize
  35. } = NCoreUIKitLocalize.useContext();
  36. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  37. const [
  38. content,
  39. setContent
  40. ] = useState<string>(
  41. "# Markdown Viewer\n\nThis is a **MarkdownViewer** component from *NCore UI Kit*.\n\n- It supports lists\n- And bold text",
  42. );
  43. useLayoutEffect(() => {
  44. navigation.setOptions({
  45. header: () => <Header
  46. title={localize("markdownViewer-title")}
  47. isWrapSafeareaContext={false}
  48. navigation={navigation}
  49. isGoBackEnable={true}
  50. />,
  51. headerShown: true
  52. });
  53. }, []);
  54. return <PageContainer
  55. scrollViewProps={{
  56. contentContainerStyle: stylesheet.scrollContent
  57. }}
  58. isWorkWithHeaderSpace={false}
  59. scrollViewStyle={[
  60. stylesheet.container
  61. ]}
  62. isScrollable={true}
  63. >
  64. <View
  65. style={[
  66. stylesheet.contentContainer
  67. ]}
  68. >
  69. <Text
  70. style={stylesheet.marginContainer}
  71. variant="bodyMediumSize"
  72. color="mid"
  73. >
  74. {localize("markdownViewer-desc")}
  75. </Text>
  76. <TextAreaInput
  77. placeholder={localize("markdownViewer-enterContent")}
  78. title={localize("markdownViewer-contentLabel")}
  79. spreadBehaviour="stretch"
  80. onChangeText={setContent}
  81. isUpdateOnRealtime={true}
  82. value={content}
  83. />
  84. <View
  85. style={[
  86. stylesheet.paddedMarginContainer,
  87. {
  88. borderColor: colors.content.border.subtle,
  89. borderRadius: radiuses.form,
  90. marginTop: spaces.spacingMd,
  91. borderWidth: borders.line,
  92. padding: spaces.spacingMd
  93. }
  94. ]}
  95. >
  96. <MarkdownViewer
  97. content={content}
  98. />
  99. </View>
  100. <View
  101. style={{
  102. marginTop: spaces.spacingMd
  103. }}
  104. >
  105. <Text
  106. style={{
  107. marginBottom: spaces.spacingSm
  108. }}
  109. variant="headlineSmallSize"
  110. >
  111. {localize("usage")}
  112. </Text>
  113. <CodeViewer
  114. code={"import {\n MarkdownViewer\n} from \"ncore-ui-kit\";\n\n<MarkdownViewer\n content=\"# Hello World\"\n/>"}
  115. language="tsx"
  116. />
  117. </View>
  118. </View>
  119. </PageContainer>;
  120. };
  121. export default MarkdownViewerPage;