index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. HighlightButton,
  13. PageContainer,
  14. SelectBox,
  15. TextInput,
  16. Header,
  17. Switch
  18. ,
  19. Text
  20. } from "ncore-ui-kit";
  21. import {
  22. useNavigation
  23. } from "@react-navigation/native";
  24. import type RootStackParamList from "../../navigation/type";
  25. import type {
  26. NativeStackNavigationProp
  27. } from "@react-navigation/native-stack";
  28. import type {
  29. IHighlightButtonProps
  30. } from "ncore-ui-kit";
  31. import {
  32. Home as HomeIcon
  33. } from "lucide-react-native";
  34. const TYPES: Array<IHighlightButtonProps["type"]> = [
  35. "primary",
  36. "danger",
  37. "warning",
  38. "neutral",
  39. "success",
  40. "info",
  41. "glass"
  42. ];
  43. const SIZES: Array<IHighlightButtonProps["size"]> = [
  44. "small",
  45. "medium",
  46. "large"
  47. ];
  48. const SPREAD_BEHAVIOURS: Array<IHighlightButtonProps["spreadBehaviour"]> = [
  49. "baseline",
  50. "stretch",
  51. "free"
  52. ];
  53. const TYPES_DATA = TYPES.map((item) => ({
  54. __title: item as string,
  55. __key: item as string
  56. }));
  57. const SIZES_DATA = SIZES.map((item) => ({
  58. __title: item as string,
  59. __key: item as string
  60. }));
  61. const HighlightButtonPage = () => {
  62. const {
  63. radiuses,
  64. borders,
  65. spaces,
  66. colors
  67. } = NCoreUIKitTheme.useContext();
  68. const {
  69. localize
  70. } = NCoreUIKitLocalize.useContext();
  71. const navigation = useNavigation<NativeStackNavigationProp<RootStackParamList>>();
  72. const [
  73. typeIndex,
  74. setTypeIndex
  75. ] = useState<number>(0);
  76. const [
  77. sizeIndex,
  78. setSizeIndex
  79. ] = useState<number>(1);
  80. const [
  81. spreadIndex,
  82. setSpreadIndex
  83. ] = useState<number>(0);
  84. const [
  85. title,
  86. setTitle
  87. ] = useState<string>("");
  88. const [
  89. isLoading,
  90. setIsLoading
  91. ] = useState<boolean>(false);
  92. const [
  93. isDisabled,
  94. setIsDisabled
  95. ] = useState<boolean>(false);
  96. const [
  97. isCustomPadding,
  98. setIsCustomPadding
  99. ] = useState<boolean>(false);
  100. const [
  101. showIcon,
  102. setShowIcon
  103. ] = useState<boolean>(false);
  104. const [
  105. iconDirection,
  106. setIconDirection
  107. ] = useState<"left" | "right">("left");
  108. useLayoutEffect(() => {
  109. navigation.setOptions({
  110. header: () => (
  111. <Header
  112. title={localize("highlightButton-title")}
  113. isWrapSafeareaContext={false}
  114. navigation={navigation}
  115. isGoBackEnable={true}
  116. />
  117. ),
  118. headerShown: true
  119. });
  120. }, []);
  121. return (
  122. <PageContainer
  123. scrollViewProps={{
  124. contentContainerStyle: stylesheet.scrollContent
  125. }}
  126. scrollViewStyle={[stylesheet.container]}
  127. isWorkWithHeaderSpace={false}
  128. isScrollable={true}
  129. >
  130. <View style={[stylesheet.contentContainer]}>
  131. <Text
  132. variant="bodyMediumSize"
  133. color="mid"
  134. style={{
  135. marginBottom: 20
  136. }}
  137. >
  138. {localize("highlightButton-desc")}
  139. </Text>
  140. <View
  141. style={{
  142. borderColor: colors.content.border.subtle,
  143. marginBottom: spaces.spacingMd,
  144. borderRadius: radiuses.form,
  145. borderWidth: borders.line,
  146. padding: spaces.spacingMd,
  147. justifyContent: "center",
  148. alignItems: "center",
  149. minHeight: 120
  150. }}
  151. >
  152. <HighlightButton
  153. icon={
  154. showIcon
  155. ? ({
  156. color,
  157. size
  158. }) => (
  159. <HomeIcon
  160. color={colors.content.icon[color]}
  161. size={size}
  162. />
  163. )
  164. : undefined
  165. }
  166. title={
  167. title || localize("highlightButton-example")
  168. }
  169. spreadBehaviour={SPREAD_BEHAVIOURS[spreadIndex]}
  170. isCustomPadding={isCustomPadding}
  171. iconDirection={iconDirection}
  172. type={TYPES[typeIndex]}
  173. size={SIZES[sizeIndex]}
  174. isDisabled={isDisabled}
  175. isLoading={isLoading}
  176. onPress={() => {}}
  177. />
  178. </View>
  179. <TextInput
  180. placeholder={localize("highlightButton-enterText")}
  181. title={localize("highlightButton-titleLabel")}
  182. style={{
  183. marginBottom: spaces.spacingMd
  184. }}
  185. spreadBehaviour="stretch"
  186. onChangeText={setTitle}
  187. value={title}
  188. />
  189. <View
  190. style={{
  191. justifyContent: "space-between",
  192. gap: spaces.spacingMd,
  193. flexDirection: "row",
  194. flexWrap: "wrap",
  195. width: "100%"
  196. }}
  197. >
  198. <SelectBox
  199. onChange={(selectedItems) => {
  200. if (selectedItems.length > 0) {
  201. const index = TYPES.indexOf(
  202. selectedItems[0]!
  203. .__key as unknown as IHighlightButtonProps["type"],
  204. );
  205. if (index !== -1) setTypeIndex(index);
  206. }
  207. }}
  208. initialSelectedItems={
  209. TYPES_DATA[typeIndex] ? [TYPES_DATA[typeIndex]] : []
  210. }
  211. title={localize("highlightButton-changeType")}
  212. titleExtractor={(item) => item.__title}
  213. keyExtractor={(item) => item.__key}
  214. spreadBehaviour="free"
  215. data={TYPES_DATA}
  216. />
  217. <HighlightButton
  218. onPress={() => {
  219. setSpreadIndex((prev) =>
  220. prev + 1 > SPREAD_BEHAVIOURS.length - 1
  221. ? 0
  222. : prev + 1,
  223. );
  224. }}
  225. title={
  226. `${localize("highlightButton-changeSpread")}: ${SPREAD_BEHAVIOURS[spreadIndex]}`
  227. }
  228. spreadBehaviour="free"
  229. />
  230. <SelectBox
  231. onChange={(selectedItems) => {
  232. if (selectedItems.length > 0) {
  233. const index = SIZES.indexOf(
  234. selectedItems[0]!
  235. .__key as unknown as IHighlightButtonProps["size"],
  236. );
  237. if (index !== -1) setSizeIndex(index);
  238. }
  239. }}
  240. initialSelectedItems={
  241. SIZES_DATA[sizeIndex] ? [SIZES_DATA[sizeIndex]] : []
  242. }
  243. title={localize("highlightButton-changeSize")}
  244. titleExtractor={(item) => item.__title}
  245. keyExtractor={(item) => item.__key}
  246. spreadBehaviour="free"
  247. data={SIZES_DATA}
  248. />
  249. <View
  250. style={{
  251. justifyContent: "space-between",
  252. flexDirection: "row",
  253. alignItems: "center",
  254. flexWrap: "wrap",
  255. width: "100%"
  256. }}
  257. >
  258. <Switch
  259. onPress={() =>
  260. setIconDirection(
  261. iconDirection === "left" ? "right" : "left",
  262. )
  263. }
  264. title={localize(
  265. "highlightButton-toggleIconDir",
  266. )}
  267. isActive={iconDirection === "right"}
  268. />
  269. <Switch
  270. title={localize(
  271. "highlightButton-toggleIcon",
  272. )}
  273. onPress={() => setShowIcon(!showIcon)}
  274. isActive={showIcon}
  275. />
  276. <Switch
  277. title={localize(
  278. "highlightButton-toggleLoading",
  279. )}
  280. onPress={() => setIsLoading(!isLoading)}
  281. isActive={isLoading}
  282. />
  283. <Switch
  284. title={localize(
  285. "highlightButton-toggleDisabled",
  286. )}
  287. onPress={() => setIsDisabled(!isDisabled)}
  288. isActive={isDisabled}
  289. />
  290. <Switch
  291. title={localize(
  292. "highlightButton-toggleCustomPadding",
  293. )}
  294. onPress={() => setIsCustomPadding(!isCustomPadding)}
  295. isActive={isCustomPadding}
  296. />
  297. </View>
  298. </View>
  299. </View>
  300. </PageContainer>
  301. );
  302. };
  303. export default HighlightButtonPage;