index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. import {
  2. useLayoutEffect,
  3. useState
  4. } from "react";
  5. import {
  6. StyleSheet,
  7. View
  8. } from "react-native";
  9. import {
  10. type ActivityStatusType,
  11. type IUserShortcutProps,
  12. STATUS_CHEAT_SHEET,
  13. NCoreUIKitTheme,
  14. PageContainer,
  15. UserShortcut,
  16. CodeViewer,
  17. SelectBox,
  18. TextInput,
  19. Switch,
  20. Text
  21. } from "ncore-ui-kit";
  22. import {
  23. useNavigation
  24. } from "@react-navigation/native";
  25. import type RootStackParamList from "../../../navigation/type";
  26. import type {
  27. NativeStackNavigationProp
  28. } from "@react-navigation/native-stack";
  29. const STATUS_INDICATOR_TYPES_DATA = Object.keys(STATUS_CHEAT_SHEET).map((type) => ({
  30. __title: type.charAt(0).toUpperCase() + type.slice(1),
  31. __key: type
  32. }));
  33. const SPREAD_BEHAVIOURS: Array<NonNullable<IUserShortcutProps["spreadBehaviour"]>> = [
  34. "baseline",
  35. "stretch",
  36. "free"
  37. ];
  38. const SPREAD_BEHAVIOURS_DATA = SPREAD_BEHAVIOURS.map((type) => ({
  39. __title: type ? type.charAt(0).toUpperCase() + type.slice(1) : "None",
  40. __key: type
  41. }));
  42. const UserShortcutPage = () => {
  43. const {
  44. borders,
  45. spaces,
  46. colors
  47. } = NCoreUIKitTheme.useContext();
  48. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  49. const bgColorKeys = Object.keys(colors.content.container);
  50. const [
  51. statusIndicatorTypeIndex,
  52. setStatusIndicatorTypeIndex
  53. ] = useState(0);
  54. const [
  55. spreadBehaviourIndex,
  56. setSpreadBehaviourIndex
  57. ] = useState(0);
  58. const [
  59. backgroundColor,
  60. setBackgroundColor
  61. ] = useState<NonNullable<IUserShortcutProps["backgroundColor"]>>("mid");
  62. const BACKGROUND_COLORS_DATA = [
  63. "transparent",
  64. ...bgColorKeys
  65. ].map((color) => ({
  66. __title: color.charAt(0).toUpperCase() + color.slice(1),
  67. __key: color
  68. }));
  69. const [
  70. statusText,
  71. setStatusText
  72. ] = useState("");
  73. const [
  74. isDisabled,
  75. setIsDisabled
  76. ] = useState(false);
  77. const [
  78. subTitle,
  79. setSubTitle
  80. ] = useState("Product Designer");
  81. const [
  82. title,
  83. setTitle
  84. ] = useState("Furkan Atakan BOZKURT");
  85. useLayoutEffect(() => {
  86. navigation.setOptions({
  87. headerTitle: "UserShortcut",
  88. headerShown: true
  89. });
  90. }, [
  91. navigation
  92. ]);
  93. const statusIndicatorType = Object.keys(STATUS_CHEAT_SHEET)[statusIndicatorTypeIndex] as ActivityStatusType;
  94. const spreadBehaviour = SPREAD_BEHAVIOURS[spreadBehaviourIndex];
  95. const styles = StyleSheet.create({
  96. controlsContainer: {
  97. gap: spaces.spacingMd
  98. },
  99. rowContainer: {
  100. flexDirection: "row",
  101. alignItems: "center",
  102. display: "flex"
  103. }
  104. });
  105. return <PageContainer
  106. isScrollable={true}
  107. >
  108. <View
  109. style={{
  110. paddingHorizontal: spaces.spacingMd,
  111. paddingVertical: spaces.spacingLg
  112. }}
  113. >
  114. <View
  115. style={{
  116. borderColor: colors.content.container.mid,
  117. paddingHorizontal: spaces.spacingMd,
  118. paddingVertical: spaces.spacingLg,
  119. marginBottom: spaces.spacingXl,
  120. borderRadius: spaces.spacingMd,
  121. borderWidth: borders.line,
  122. justifyContent: "center",
  123. alignItems: "center"
  124. }}
  125. >
  126. <UserShortcut
  127. actionButtons={[
  128. {
  129. onPress: () => console.log("Profile pressed"),
  130. title: "Profile"
  131. },
  132. {
  133. onPress: () => console.log("Settings pressed"),
  134. title: "Settings"
  135. }
  136. ]}
  137. avatarProps={{
  138. statusIndicatorType: statusIndicatorType,
  139. title
  140. }}
  141. onLogoutPress={() => {
  142. console.log("Logout pressed");
  143. }}
  144. spreadBehaviour={spreadBehaviour}
  145. backgroundColor={backgroundColor}
  146. onPress={() => {
  147. console.log("Card pressed");
  148. }}
  149. isDisabled={isDisabled}
  150. statusText={statusText}
  151. subTitle={subTitle}
  152. title={title}
  153. />
  154. </View>
  155. <View
  156. style={{
  157. marginBottom: spaces.spacingXl
  158. }}
  159. >
  160. <Text
  161. style={{
  162. marginBottom: spaces.spacingSm
  163. }}
  164. variant="headlineSmallSize"
  165. >
  166. Controls
  167. </Text>
  168. <View
  169. style={styles.controlsContainer}
  170. >
  171. <View
  172. style={[
  173. styles.rowContainer,
  174. {
  175. gap: spaces.spacingMd
  176. }
  177. ]}
  178. >
  179. <SelectBox
  180. onChange={(selectedItems) => {
  181. if (selectedItems.length > 0) {
  182. const index = Object.keys(STATUS_CHEAT_SHEET).indexOf(selectedItems[0]!.__key as ActivityStatusType);
  183. if (index !== -1) {
  184. setStatusIndicatorTypeIndex(index);
  185. }
  186. }
  187. }}
  188. initialSelectedItems={
  189. STATUS_INDICATOR_TYPES_DATA[statusIndicatorTypeIndex]
  190. ? [
  191. STATUS_INDICATOR_TYPES_DATA[statusIndicatorTypeIndex]!
  192. ]
  193. : []
  194. }
  195. keyExtractor={(item) => item.__key as string}
  196. titleExtractor={(item) => item.__title}
  197. data={STATUS_INDICATOR_TYPES_DATA}
  198. title="Status Indicator"
  199. spreadBehaviour="free"
  200. />
  201. <SelectBox
  202. initialSelectedItems={
  203. SPREAD_BEHAVIOURS_DATA[spreadBehaviourIndex]
  204. ? [
  205. {
  206. ...SPREAD_BEHAVIOURS_DATA[spreadBehaviourIndex]!,
  207. __key: SPREAD_BEHAVIOURS_DATA[spreadBehaviourIndex]!.__key as NonNullable<IUserShortcutProps["spreadBehaviour"]>
  208. }
  209. ]
  210. : []
  211. }
  212. onChange={(selectedItems) => {
  213. if (selectedItems.length > 0) {
  214. const index = SPREAD_BEHAVIOURS.indexOf(selectedItems[0]!.__key as NonNullable<IUserShortcutProps["spreadBehaviour"]>);
  215. if (index !== -1) setSpreadBehaviourIndex(index);
  216. }
  217. }}
  218. keyExtractor={(item) => item.__key as string}
  219. titleExtractor={(item) => item.__title}
  220. data={SPREAD_BEHAVIOURS_DATA}
  221. title="Spread Behaviour"
  222. spreadBehaviour="free"
  223. />
  224. </View>
  225. <View
  226. style={[
  227. styles.rowContainer,
  228. {
  229. gap: spaces.spacingMd
  230. }
  231. ]}
  232. >
  233. <SelectBox
  234. onChange={(selectedItems) => {
  235. if (selectedItems.length > 0) {
  236. setBackgroundColor(selectedItems[0]!.__key as NonNullable<IUserShortcutProps["backgroundColor"]>);
  237. }
  238. }}
  239. initialSelectedItems={
  240. BACKGROUND_COLORS_DATA.filter(i => i.__key === backgroundColor).length > 0
  241. ? [
  242. {
  243. ...BACKGROUND_COLORS_DATA.find(i => i.__key === backgroundColor)!,
  244. __key: backgroundColor as string
  245. }
  246. ]
  247. : []
  248. }
  249. keyExtractor={(item) => item.__key as string}
  250. titleExtractor={(item) => item.__title}
  251. data={BACKGROUND_COLORS_DATA}
  252. title="Background Color"
  253. spreadBehaviour="free"
  254. />
  255. </View>
  256. <TextInput
  257. spreadBehaviour="stretch"
  258. onChangeText={setTitle}
  259. title="Title"
  260. value={title}
  261. />
  262. <TextInput
  263. onChangeText={setSubTitle}
  264. spreadBehaviour="stretch"
  265. title="Sub Title"
  266. value={subTitle}
  267. />
  268. <TextInput
  269. onChangeText={setStatusText}
  270. spreadBehaviour="stretch"
  271. title="Status Text"
  272. value={statusText}
  273. />
  274. <View
  275. style={[
  276. styles.rowContainer,
  277. {
  278. gap: spaces.spacingMd
  279. }
  280. ]}
  281. >
  282. <Switch
  283. onPress={() => setIsDisabled(!isDisabled)}
  284. spreadBehaviour="baseline"
  285. isActive={isDisabled}
  286. title="Disabled"
  287. />
  288. </View>
  289. </View>
  290. </View>
  291. <View
  292. style={{
  293. marginBottom: spaces.spacingMd
  294. }}
  295. >
  296. <Text
  297. style={{
  298. marginBottom: spaces.spacingSm
  299. }}
  300. variant="headlineSmallSize"
  301. >
  302. Usage
  303. </Text>
  304. <CodeViewer
  305. code={"import {\n UserShortcut\n} from \"ncore-ui-kit\";\n\n<UserShortcut\n avatarProps={{\n title: \"Murat Enes\",\n statusIndicatorType: \"online\"\n }}\n onPress={() => {\n // open bottom sheet\n }}\n subTitle=\"Product Designer\"\n statusText=\"Online\"\n title=\"Murat Enes\"\n/>"}
  306. language="tsx"
  307. />
  308. </View>
  309. </View>
  310. </PageContainer>;
  311. };
  312. export default UserShortcutPage;