index.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. PageContainer,
  13. CodeViewer,
  14. StateCard,
  15. TextInput,
  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. import {
  27. Home as HomeIcon
  28. } from "lucide-react-native";
  29. const StateCardPage = () => {
  30. const {
  31. radiuses,
  32. borders,
  33. spaces,
  34. colors
  35. } = NCoreUIKitTheme.useContext();
  36. const {
  37. localize
  38. } = NCoreUIKitLocalize.useContext();
  39. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  40. const [
  41. title,
  42. setTitle
  43. ] = useState<string>("");
  44. const [
  45. subTitle,
  46. setSubTitle
  47. ] = useState<string>("");
  48. const [
  49. value,
  50. setValue
  51. ] = useState<string>("");
  52. useLayoutEffect(() => {
  53. navigation.setOptions({
  54. header: () => <Header
  55. title={localize("stateCard-title")}
  56. isWrapSafeareaContext={false}
  57. navigation={navigation}
  58. isGoBackEnable={true}
  59. />,
  60. headerShown: true
  61. });
  62. }, []);
  63. return <PageContainer
  64. scrollViewProps={{
  65. contentContainerStyle: stylesheet.scrollContent
  66. }}
  67. scrollViewStyle={[
  68. stylesheet.container
  69. ]}
  70. isWorkWithHeaderSpace={false}
  71. isScrollable={true}
  72. >
  73. <View
  74. style={[
  75. stylesheet.contentContainer
  76. ]}
  77. >
  78. <Text
  79. variant="bodyMediumSize"
  80. color="mid"
  81. style={stylesheet.descText}
  82. >
  83. {localize("stateCard-desc")}
  84. </Text>
  85. <View
  86. style={[
  87. stylesheet.previewContainer,
  88. {
  89. borderColor: colors.content.border.subtle,
  90. marginBottom: spaces.spacingMd,
  91. borderRadius: radiuses.form,
  92. borderWidth: borders.line,
  93. padding: spaces.spacingMd
  94. }
  95. ]}
  96. >
  97. <StateCard
  98. icon={({
  99. color,
  100. size
  101. }) => <HomeIcon
  102. color={
  103. colors.content.icon[
  104. color as keyof typeof colors.content.icon
  105. ]
  106. }
  107. size={size}
  108. />
  109. }
  110. subTitle={
  111. subTitle ||
  112. localize("stateCard-exampleSubTitle")
  113. }
  114. title={
  115. title || localize("stateCard-exampleTitle")
  116. }
  117. />
  118. </View>
  119. <View
  120. style={{
  121. marginBottom: spaces.spacingMd
  122. }}
  123. >
  124. <Text
  125. variant="headlineSmallSize"
  126. style={{
  127. marginBottom: spaces.spacingSm
  128. }}
  129. >
  130. {localize("usage")}
  131. </Text>
  132. <CodeViewer
  133. code={"import {\n StateCard\n} from \"ncore-ui-kit\";\n\n<StateCard\n title=\"Title\"\n subTitle=\"Subtitle\"\n/>"}
  134. language="tsx"
  135. />
  136. </View>
  137. <TextInput
  138. placeholder={localize("stateCard-enterTitle")}
  139. title={localize("stateCard-titleLabel")}
  140. style={{
  141. marginBottom: spaces.spacingMd
  142. }}
  143. spreadBehaviour="stretch"
  144. onChangeText={setTitle}
  145. value={title}
  146. />
  147. <TextInput
  148. placeholder={localize("stateCard-enterSubTitle")}
  149. title={localize("stateCard-subTitleLabel")}
  150. style={{
  151. marginBottom: spaces.spacingMd
  152. }}
  153. onChangeText={setSubTitle}
  154. spreadBehaviour="stretch"
  155. value={subTitle}
  156. />
  157. <TextInput
  158. placeholder={localize("stateCard-enterValue")}
  159. title={localize("stateCard-valueLabel")}
  160. style={{
  161. marginBottom: spaces.spacingMd
  162. }}
  163. spreadBehaviour="stretch"
  164. onChangeText={setValue}
  165. value={value}
  166. />
  167. </View>
  168. </PageContainer>;
  169. };
  170. export default StateCardPage;