index.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. import {
  2. useLayoutEffect,
  3. useState
  4. } from "react";
  5. import {
  6. StyleSheet,
  7. View
  8. } from "react-native";
  9. import {
  10. NCoreUIKitCoreComplexProvider,
  11. type ActivityStatusType,
  12. type IUserShortcutProps,
  13. STATUS_CHEAT_SHEET,
  14. NCoreUIKitTheme,
  15. PageContainer,
  16. UserShortcut,
  17. CodeViewer,
  18. SelectBox,
  19. TextInput,
  20. Switch,
  21. Text
  22. } from "ncore-ui-kit";
  23. import {
  24. useNavigation
  25. } from "@react-navigation/native";
  26. import type RootStackParamList from "../../../navigation/type";
  27. import type {
  28. NativeStackNavigationProp
  29. } from "@react-navigation/native-stack";
  30. const STATUS_INDICATOR_TYPES_DATA = Object.keys(STATUS_CHEAT_SHEET).map((type) => ({
  31. __title: type.charAt(0).toUpperCase() + type.slice(1),
  32. __key: type
  33. }));
  34. const SPREAD_BEHAVIOURS: Array<NonNullable<IUserShortcutProps["spreadBehaviour"]>> = [
  35. "baseline",
  36. "stretch",
  37. "free"
  38. ];
  39. const SPREAD_BEHAVIOURS_DATA = SPREAD_BEHAVIOURS.map((type) => ({
  40. __title: type ? type.charAt(0).toUpperCase() + type.slice(1) : "None",
  41. __key: type
  42. }));
  43. const VARIANT_TYPES: Array<NonNullable<IUserShortcutProps["variant"]>> = [
  44. "default",
  45. "compact"
  46. ];
  47. const VARIANT_TYPES_DATA = VARIANT_TYPES.map((type) => ({
  48. __title: type.charAt(0).toUpperCase() + type.slice(1),
  49. __key: type
  50. }));
  51. const UserShortcutPage = () => {
  52. const {
  53. borders,
  54. spaces,
  55. colors
  56. } = NCoreUIKitTheme.useContext();
  57. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  58. const bgColorKeys = Object.keys(colors.content.container);
  59. const [
  60. statusIndicatorTypeIndex,
  61. setStatusIndicatorTypeIndex
  62. ] = useState(Object.keys(STATUS_CHEAT_SHEET).findIndex(e => e === "online"));
  63. const [
  64. spreadBehaviourIndex,
  65. setSpreadBehaviourIndex
  66. ] = useState(0);
  67. const [
  68. variantIndex,
  69. setVariantIndex
  70. ] = useState(0);
  71. const [
  72. backgroundColor,
  73. setBackgroundColor
  74. ] = useState<NonNullable<IUserShortcutProps["backgroundColor"]>>("mid");
  75. const BACKGROUND_COLORS_DATA = [
  76. "transparent",
  77. ...bgColorKeys
  78. ].map((color) => ({
  79. __title: color.charAt(0).toUpperCase() + color.slice(1),
  80. __key: color
  81. }));
  82. const [
  83. statusText,
  84. setStatusText
  85. ] = useState("");
  86. const [
  87. isDisabled,
  88. setIsDisabled
  89. ] = useState(false);
  90. const [
  91. subTitle,
  92. setSubTitle
  93. ] = useState("Product Designer");
  94. const [
  95. title,
  96. setTitle
  97. ] = useState("Furkan Atakan BOZKURT");
  98. const [
  99. isShowLoginButtonWhenNoSession,
  100. setIsShowLoginButtonWhenNoSession
  101. ] = useState(true);
  102. const [
  103. isWorkWithCoreComplex,
  104. setIsWorkWithCoreComplex
  105. ] = useState(false);
  106. const [
  107. isShowRegisterButton,
  108. setIsShowRegisterButton
  109. ] = useState(false);
  110. const [
  111. isShowLogoutButton,
  112. setIsShowLogoutButton
  113. ] = useState(true);
  114. const [
  115. isShowArrowButton,
  116. setIsShowArrowButton
  117. ] = useState(true);
  118. const [
  119. isSessionActive,
  120. setIsSessionActive
  121. ] = useState(true);
  122. useLayoutEffect(() => {
  123. navigation.setOptions({
  124. headerTitle: "UserShortcut",
  125. headerShown: true
  126. });
  127. }, [
  128. navigation
  129. ]);
  130. const statusIndicatorType = Object.keys(STATUS_CHEAT_SHEET)[statusIndicatorTypeIndex] as ActivityStatusType;
  131. const spreadBehaviour = SPREAD_BEHAVIOURS[spreadBehaviourIndex];
  132. const variant = VARIANT_TYPES[variantIndex];
  133. const styles = StyleSheet.create({
  134. controlsContainer: {
  135. gap: spaces.spacingMd
  136. },
  137. rowContainer: {
  138. flexDirection: "row",
  139. alignItems: "center",
  140. display: "flex"
  141. }
  142. });
  143. return <PageContainer
  144. isScrollable={true}
  145. >
  146. <View
  147. style={{
  148. paddingHorizontal: spaces.spacingMd,
  149. paddingVertical: spaces.spacingLg
  150. }}
  151. >
  152. <View
  153. style={{
  154. borderColor: colors.content.container.mid,
  155. paddingHorizontal: spaces.spacingMd,
  156. paddingVertical: spaces.spacingLg,
  157. marginBottom: spaces.spacingXl,
  158. borderRadius: spaces.spacingMd,
  159. borderWidth: borders.line,
  160. justifyContent: "center",
  161. alignItems: "center"
  162. }}
  163. >
  164. <NCoreUIKitCoreComplexProvider
  165. privateKeyID="test"
  166. rsaPublicKey="test"
  167. privateKey="test"
  168. appID="test"
  169. >
  170. <UserShortcut
  171. isShowLoginButtonWhenNoSession={isShowLoginButtonWhenNoSession}
  172. actionButtons={[
  173. {
  174. onPress: () => console.log("Profile pressed"),
  175. title: "Profile"
  176. },
  177. {
  178. onPress: () => console.log("Settings pressed"),
  179. title: "Settings"
  180. }
  181. ]}
  182. avatarProps={{
  183. statusIndicatorType: statusIndicatorType,
  184. title
  185. }}
  186. isWorkWithCoreComplex={isWorkWithCoreComplex}
  187. isShowRegisterButton={isShowRegisterButton}
  188. isShowLogoutButton={isShowLogoutButton}
  189. onLogoutPress={(response, error) => {
  190. console.log("Logout pressed", {
  191. response,
  192. error
  193. });
  194. }}
  195. isShowArrowButton={isShowArrowButton}
  196. onRegisterPress={() => {
  197. console.log("Register pressed");
  198. }}
  199. onLoginPress={() => {
  200. console.log("Login pressed");
  201. }}
  202. backgroundColor={backgroundColor}
  203. spreadBehaviour={spreadBehaviour}
  204. isSessionActive={isSessionActive}
  205. onPress={() => {
  206. console.log("Card pressed");
  207. }}
  208. isDisabled={isDisabled}
  209. statusText={statusText}
  210. subTitle={subTitle}
  211. variant={variant}
  212. title={title}
  213. />
  214. </NCoreUIKitCoreComplexProvider>
  215. </View>
  216. <View
  217. style={{
  218. marginBottom: spaces.spacingXl
  219. }}
  220. >
  221. <Text
  222. style={{
  223. marginBottom: spaces.spacingSm
  224. }}
  225. variant="headlineSmallSize"
  226. >
  227. Controls
  228. </Text>
  229. <View
  230. style={styles.controlsContainer}
  231. >
  232. <View
  233. style={[
  234. styles.rowContainer,
  235. {
  236. gap: spaces.spacingMd
  237. }
  238. ]}
  239. >
  240. <SelectBox
  241. onChange={(selectedItems) => {
  242. if (selectedItems.length > 0) {
  243. const index = Object.keys(STATUS_CHEAT_SHEET).indexOf(selectedItems[0]!.__key as ActivityStatusType);
  244. if (index !== -1) {
  245. setStatusIndicatorTypeIndex(index);
  246. }
  247. }
  248. }}
  249. initialSelectedItems={
  250. STATUS_INDICATOR_TYPES_DATA[statusIndicatorTypeIndex]
  251. ? [
  252. STATUS_INDICATOR_TYPES_DATA[statusIndicatorTypeIndex]!
  253. ]
  254. : []
  255. }
  256. keyExtractor={(item) => item.__key as string}
  257. titleExtractor={(item) => item.__title}
  258. data={STATUS_INDICATOR_TYPES_DATA}
  259. title="Status Indicator"
  260. spreadBehaviour="free"
  261. />
  262. <SelectBox
  263. initialSelectedItems={
  264. SPREAD_BEHAVIOURS_DATA[spreadBehaviourIndex]
  265. ? [
  266. {
  267. ...SPREAD_BEHAVIOURS_DATA[spreadBehaviourIndex]!,
  268. __key: SPREAD_BEHAVIOURS_DATA[spreadBehaviourIndex]!.__key as NonNullable<IUserShortcutProps["spreadBehaviour"]>
  269. }
  270. ]
  271. : []
  272. }
  273. onChange={(selectedItems) => {
  274. if (selectedItems.length > 0) {
  275. const index = SPREAD_BEHAVIOURS.indexOf(selectedItems[0]!.__key as NonNullable<IUserShortcutProps["spreadBehaviour"]>);
  276. if (index !== -1) setSpreadBehaviourIndex(index);
  277. }
  278. }}
  279. keyExtractor={(item) => item.__key as string}
  280. titleExtractor={(item) => item.__title}
  281. data={SPREAD_BEHAVIOURS_DATA}
  282. title="Spread Behaviour"
  283. spreadBehaviour="free"
  284. />
  285. </View>
  286. <View
  287. style={[
  288. styles.rowContainer,
  289. {
  290. gap: spaces.spacingMd
  291. }
  292. ]}
  293. >
  294. <SelectBox
  295. onChange={(selectedItems) => {
  296. if (selectedItems.length > 0) {
  297. const index = VARIANT_TYPES.indexOf(selectedItems[0]!.__key as NonNullable<IUserShortcutProps["variant"]>);
  298. if (index !== -1) setVariantIndex(index);
  299. }
  300. }}
  301. initialSelectedItems={
  302. VARIANT_TYPES_DATA[variantIndex]
  303. ? [
  304. {
  305. ...VARIANT_TYPES_DATA[variantIndex]!,
  306. __key: VARIANT_TYPES_DATA[variantIndex]!.__key as NonNullable<IUserShortcutProps["variant"]>
  307. }
  308. ]
  309. : []
  310. }
  311. keyExtractor={(item) => item.__key as string}
  312. titleExtractor={(item) => item.__title}
  313. data={VARIANT_TYPES_DATA}
  314. spreadBehaviour="free"
  315. title="Variant"
  316. />
  317. <SelectBox
  318. onChange={(selectedItems) => {
  319. if (selectedItems.length > 0) {
  320. setBackgroundColor(selectedItems[0]!.__key as NonNullable<IUserShortcutProps["backgroundColor"]>);
  321. }
  322. }}
  323. initialSelectedItems={
  324. BACKGROUND_COLORS_DATA.filter(i => i.__key === backgroundColor).length > 0
  325. ? [
  326. {
  327. ...BACKGROUND_COLORS_DATA.find(i => i.__key === backgroundColor)!,
  328. __key: backgroundColor as string
  329. }
  330. ]
  331. : []
  332. }
  333. keyExtractor={(item) => item.__key as string}
  334. titleExtractor={(item) => item.__title}
  335. data={BACKGROUND_COLORS_DATA}
  336. title="Background Color"
  337. spreadBehaviour="free"
  338. />
  339. </View>
  340. <TextInput
  341. spreadBehaviour="stretch"
  342. onChangeText={setTitle}
  343. title="Title"
  344. value={title}
  345. />
  346. <TextInput
  347. onChangeText={setSubTitle}
  348. spreadBehaviour="stretch"
  349. title="Sub Title"
  350. value={subTitle}
  351. />
  352. <TextInput
  353. onChangeText={setStatusText}
  354. spreadBehaviour="stretch"
  355. title="Status Text"
  356. value={statusText}
  357. />
  358. <View
  359. style={[
  360. styles.rowContainer,
  361. {
  362. gap: spaces.spacingMd
  363. }
  364. ]}
  365. >
  366. <Switch
  367. onPress={() => setIsDisabled(!isDisabled)}
  368. spreadBehaviour="baseline"
  369. isActive={isDisabled}
  370. title="Disabled"
  371. />
  372. <Switch
  373. onPress={() => setIsWorkWithCoreComplex(!isWorkWithCoreComplex)}
  374. isActive={isWorkWithCoreComplex}
  375. title="isWorkWithCoreComplex"
  376. spreadBehaviour="baseline"
  377. />
  378. </View>
  379. <View
  380. style={[
  381. styles.rowContainer,
  382. {
  383. gap: spaces.spacingMd
  384. }
  385. ]}
  386. >
  387. <Switch
  388. onPress={() => setIsShowLogoutButton(!isShowLogoutButton)}
  389. isActive={isShowLogoutButton}
  390. spreadBehaviour="baseline"
  391. title="isShowLogoutButton"
  392. />
  393. <Switch
  394. onPress={() => setIsShowArrowButton(!isShowArrowButton)}
  395. isActive={isShowArrowButton}
  396. spreadBehaviour="baseline"
  397. title="isShowArrowButton"
  398. />
  399. </View>
  400. <View
  401. style={[
  402. styles.rowContainer,
  403. {
  404. gap: spaces.spacingMd
  405. }
  406. ]}
  407. >
  408. <Switch
  409. onPress={() => setIsShowLoginButtonWhenNoSession(!isShowLoginButtonWhenNoSession)}
  410. isActive={isShowLoginButtonWhenNoSession}
  411. title="isShowLoginButtonWhenNoSession"
  412. spreadBehaviour="baseline"
  413. />
  414. <Switch
  415. onPress={() => setIsSessionActive(!isSessionActive)}
  416. spreadBehaviour="baseline"
  417. isActive={isSessionActive}
  418. title="isSessionActive"
  419. />
  420. </View>
  421. <View
  422. style={[
  423. styles.rowContainer,
  424. {
  425. gap: spaces.spacingMd
  426. }
  427. ]}
  428. >
  429. <Switch
  430. onPress={() => setIsShowRegisterButton(!isShowRegisterButton)}
  431. isActive={isShowRegisterButton}
  432. title="isShowRegisterButton"
  433. spreadBehaviour="baseline"
  434. />
  435. </View>
  436. </View>
  437. </View>
  438. <View
  439. style={{
  440. marginBottom: spaces.spacingMd
  441. }}
  442. >
  443. <Text
  444. style={{
  445. marginBottom: spaces.spacingSm
  446. }}
  447. variant="headlineSmallSize"
  448. >
  449. Usage
  450. </Text>
  451. <CodeViewer
  452. 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/>"}
  453. language="tsx"
  454. />
  455. </View>
  456. </View>
  457. </PageContainer>;
  458. };
  459. export default UserShortcutPage;