index.tsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import {
  2. useLayoutEffect
  3. } from "react";
  4. import {
  5. View
  6. } from "react-native";
  7. import stylesheet from "./stylesheet";
  8. import {
  9. NCoreUIKitLocalize,
  10. NCoreUIKitTheme,
  11. PageContainer,
  12. CodeViewer,
  13. Button,
  14. Header,
  15. Text
  16. } from "ncore-ui-kit";
  17. import {
  18. useNavigation
  19. } from "@react-navigation/native";
  20. import type RootStackParamList from "../../../navigation/type";
  21. import type {
  22. NativeStackNavigationProp
  23. } from "@react-navigation/native-stack";
  24. import {
  25. ChevronLeftIcon,
  26. ChevronRightIcon
  27. } from "lucide-react-native";
  28. const ToolsUsage = () => {
  29. const {
  30. colors,
  31. spaces
  32. } = NCoreUIKitTheme.useContext();
  33. const {
  34. localize
  35. } = NCoreUIKitLocalize.useContext();
  36. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  37. useLayoutEffect(() => {
  38. navigation.setOptions({
  39. header: () => <Header
  40. title={localize("toolsUsage-title")}
  41. isWrapSafeareaContext={false}
  42. navigation={navigation as unknown as NCoreUIKit.Navigation}
  43. isGoBackEnable={true}
  44. />,
  45. headerShown: true
  46. });
  47. }, [
  48. navigation,
  49. localize
  50. ]);
  51. const codeTheme = `import {
  52. NCoreUIKitTheme
  53. } from "ncore-ui-kit";
  54. const MyComponent = () => {
  55. // ${localize("toolsUsage-codeThemeComment")}
  56. const {
  57. activePalette,
  58. activeTheme,
  59. spaces,
  60. colors
  61. } = NCoreUIKitTheme.useContext();
  62. return (
  63. <View
  64. style={[
  65. stylesheet.borderedCard,
  66. {
  67. backgroundColor: colors.content.container.default, padding: spaces.spacingMd
  68. }
  69. ]}
  70. >
  71. <Text
  72. style={{
  73. color: colors.content.text.high
  74. }}
  75. >
  76. Current Theme: {activeTheme}
  77. </Text>
  78. </View>
  79. );
  80. };`;
  81. const codeLocale = `import {
  82. NCoreUIKitLocalize
  83. } from "ncore-ui-kit";
  84. const MyComponent = () => {
  85. // ${localize("toolsUsage-codeLocaleComment")}
  86. const {
  87. activeLocale,
  88. localize
  89. } = NCoreUIKitLocalize.useContext();
  90. return (
  91. <Text>
  92. {localize("hello-world")} - Current: {activeLocale}
  93. </Text>
  94. );
  95. };`;
  96. const codeToast = `import {
  97. NCoreUIKitToast
  98. } from "ncore-ui-kit";
  99. const MyComponent = () => {
  100. const handlePress = () => {
  101. NCoreUIKitToast.open({
  102. title: "Success",
  103. content: "Action completed successfully!",
  104. variant: "success",
  105. duration: 3000
  106. });
  107. };
  108. return <Button
  109. onPress={handlePress}
  110. title="Show Toast"
  111. />;
  112. };`;
  113. return <PageContainer
  114. isWorkWithHeaderSpace={false}
  115. isScrollable={true}
  116. >
  117. <Text
  118. variant="headlineSmallSize"
  119. color="high"
  120. >
  121. {localize("toolsUsage-title")}
  122. </Text>
  123. <Text
  124. color="mid"
  125. >
  126. {localize("toolsUsage-desc")}
  127. </Text>
  128. <Text
  129. variant="titleMediumSize"
  130. color="high"
  131. style={{
  132. marginTop: spaces.spacingXl
  133. }}
  134. >
  135. NCoreUIKitTheme.useContext
  136. </Text>
  137. <Text
  138. color="mid"
  139. style={{
  140. marginTop: spaces.spacingXs
  141. }}
  142. >
  143. {localize("toolsUsage-ncoreThemeDesc")}
  144. </Text>
  145. <View
  146. style={{
  147. marginTop: spaces.spacingLg
  148. }}
  149. >
  150. <CodeViewer
  151. code={codeTheme}
  152. language="tsx"
  153. />
  154. </View>
  155. <Text
  156. variant="titleMediumSize"
  157. color="high"
  158. style={{
  159. marginTop: spaces.spacingXl
  160. }}
  161. >
  162. NCoreUIKitLocalize.useContext
  163. </Text>
  164. <Text
  165. color="mid"
  166. style={{
  167. marginTop: spaces.spacingXs
  168. }}
  169. >
  170. {localize("toolsUsage-ncoreLocalizeDesc")}
  171. </Text>
  172. <View
  173. style={{
  174. marginTop: spaces.spacingLg
  175. }}
  176. >
  177. <CodeViewer
  178. code={codeLocale}
  179. language="tsx"
  180. />
  181. </View>
  182. <Text
  183. variant="titleMediumSize"
  184. color="high"
  185. style={{
  186. marginTop: spaces.spacingXl
  187. }}
  188. >
  189. NCoreUIKitToast.open
  190. </Text>
  191. <Text
  192. color="mid"
  193. style={{
  194. marginTop: spaces.spacingXs
  195. }}
  196. >
  197. {localize("toolsUsage-ncoreToastDesc")}
  198. </Text>
  199. <View
  200. style={{
  201. marginTop: spaces.spacingLg
  202. }}
  203. >
  204. <CodeViewer
  205. code={codeToast}
  206. language="tsx"
  207. />
  208. </View>
  209. <View
  210. style={[
  211. stylesheet.rowSpaceBetween,
  212. {
  213. marginTop: spaces.spacingXl
  214. }
  215. ]}
  216. >
  217. <Button
  218. icon={({
  219. color,
  220. size
  221. }) => {
  222. return <ChevronLeftIcon
  223. color={colors.content.icon[color]}
  224. size={size + 3}
  225. />;
  226. }}
  227. title={localize("implementation")}
  228. onPress={() => {
  229. navigation.navigate("GettingStarted", {
  230. screen: "Implementation"
  231. });
  232. }}
  233. />
  234. <Button
  235. icon={({
  236. color,
  237. size
  238. }) => {
  239. return <ChevronRightIcon
  240. color={colors.content.icon[color]}
  241. size={size + 3}
  242. />;
  243. }}
  244. title={localize("themeExamples-title")}
  245. iconDirection="right"
  246. onPress={() => {
  247. navigation.navigate("CoreFeatures", {
  248. screen: "ThemeExamples"
  249. });
  250. }}
  251. />
  252. </View>
  253. </PageContainer>;
  254. };
  255. export default ToolsUsage;