Nenhuma descrição

Payment.stories.tsx 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import React, { MouseEvent } from "react";
  2. import { storiesOf } from "@storybook/react";
  3. import { action } from "@storybook/addon-actions";
  4. import { withInfo } from "@storybook/addon-info";
  5. import {
  6. withKnobs,
  7. number,
  8. boolean,
  9. select,
  10. text,
  11. array
  12. } from "@storybook/addon-knobs";
  13. import { addReadme } from "storybook-readme";
  14. import { Divider, Button } from "antd";
  15. import ConsumeListView from "@/components/Payment/ConsumeListView";
  16. import ConsumeListViewDoc from "@components/Payment/ConsumeListView/README.md";
  17. import PayPlatFormOptions, {
  18. PAY_CHANNEL
  19. } from "@/components/Payment/PayPlatformOptions";
  20. import PayPlatFormOptionsDoc from "@components/Payment/PayPlatformOptions/README.md";
  21. import PriceOptions from "@/components/Payment/PriceOptions";
  22. import PriceOptionsDoc from "@components/Payment/PriceOptions/README.md";
  23. import WaitPayInfoView from "@/components/Payment/WaitPayInfoView";
  24. import WaitPayInfoViewDoc from "@components/Payment/WaitPayInfoView/README.md";
  25. import AllocWantedModal from "@/components/Payment/AllocWantedModal";
  26. import WantedPublishView from "@/components/Payment/WantedPublishView";
  27. import WantedPublishPopover from "@/components/Payment/WantedPublishPopover";
  28. import WantedPublishModal from "@/components/Payment/WantedPublishModal";
  29. import { formatMoney } from "@components/Payment/Utils/utils";
  30. import { consumeList } from "./data/consumeList.json";
  31. const consumeData: any = consumeList;
  32. const stories = storiesOf("Payment", module);
  33. stories.addDecorator(storyFn => (
  34. <div style={{ padding: "0px 40px" }}>{storyFn()}</div>
  35. ));
  36. stories.addDecorator(withKnobs);
  37. stories.addDecorator(withInfo);
  38. stories.addDecorator(addReadme);
  39. stories.add(
  40. "ConsumeListView",
  41. () => {
  42. const [toggle, setToggle] = React.useState(false);
  43. return (
  44. <ConsumeListView
  45. isToggle={toggle}
  46. onToggleChange={() => setToggle(!toggle)}
  47. onConsumeItemClick={(e: MouseEvent, clickData: any) => {
  48. console.log(clickData);
  49. }}
  50. dataSource={consumeData}
  51. listLength={consumeData.length}
  52. showLength={number("showLength", 5)}
  53. />
  54. );
  55. },
  56. {
  57. info: {
  58. inline: true,
  59. text: `
  60. ~~~typescript
  61. <ConsumeListView
  62. isToggle={toggle}
  63. onToggleChange={() => setToggle(!toggle)}
  64. dataSource={consumeData}
  65. listLength={consumeData.length}
  66. showLength={number("showLength", 5)}
  67. />
  68. ~~~
  69. `,
  70. source: false,
  71. maxPropStringLength: 500
  72. },
  73. notes: "A very simple example of addon notes",
  74. readme: {
  75. sidebar: ConsumeListViewDoc
  76. }
  77. }
  78. );
  79. stories.add(
  80. "PayPlatFormOptions",
  81. () => {
  82. const [payChannel, setPayChannel] = React.useState(PAY_CHANNEL.PAYPAL);
  83. return (
  84. <PayPlatFormOptions
  85. payChannel={payChannel}
  86. onPayChannelChange={value => {
  87. action(`PayItemChange: ${value}`);
  88. setPayChannel(value);
  89. }}
  90. isMobile={boolean("isMobile", false)}
  91. size={select(
  92. "size",
  93. { Small: "small", Normal: "normal", Large: "large" },
  94. "normal"
  95. )}
  96. withTitle={boolean("withTitle", false)}
  97. locale={select("locale", { ZH: "zh", EN: "en" }, "zh")}
  98. />
  99. );
  100. },
  101. {
  102. info: {
  103. inline: true,
  104. text: ``,
  105. source: false,
  106. maxPropStringLength: 500
  107. },
  108. notes: "A very simple example of addon notes",
  109. readme: {
  110. sidebar: PayPlatFormOptionsDoc
  111. }
  112. }
  113. );
  114. stories.add(
  115. "PriceOptions",
  116. () => {
  117. const [price, setPrice] = React.useState(0);
  118. const refInput = React.useRef(null);
  119. return (
  120. <div style={{ width: text("style_width", "auto") }}>
  121. <PriceOptions
  122. price={price}
  123. rowMode={select(
  124. "rowMode",
  125. { single: "single", multi: "multi" },
  126. "single"
  127. )}
  128. onPriceChange={v => setPrice(v)}
  129. size={select(
  130. "size",
  131. { Small: "small", Normal: "normal", Large: "large" },
  132. "normal"
  133. )}
  134. withTitle={boolean("withTitle", false)}
  135. titleText={text("titleText", "")}
  136. inputPlaceholderText={text("inputPlaceholderText", "其他金额")}
  137. focusScroll={boolean("focusScroll", false)}
  138. priceOptions={array("priceOptions", ["100", "600", "800"])}
  139. priceRender={(i: number) => `${formatMoney(i / 100, 0)}¥`}
  140. inputRef={refInput}
  141. />
  142. <Divider />
  143. <div>price: {price}</div>
  144. </div>
  145. );
  146. },
  147. {
  148. info: {
  149. inline: true,
  150. text: ``,
  151. source: false,
  152. maxPropStringLength: 500
  153. },
  154. notes: "A very simple example of addon notes",
  155. readme: {
  156. sidebar: PriceOptionsDoc
  157. }
  158. }
  159. );
  160. stories.add(
  161. "WaitPayInfoView",
  162. () => {
  163. return <WaitPayInfoView />;
  164. },
  165. {
  166. info: { inline: true, text: ``, source: false, maxPropStringLength: 500 },
  167. notes: "A very simple example of addon notes",
  168. readme: {
  169. sidebar: WaitPayInfoViewDoc
  170. }
  171. }
  172. );
  173. stories.add(
  174. "AllocWantedModal",
  175. () => {
  176. return (
  177. <AllocWantedModal
  178. allocValue={number("allocValue", 100)}
  179. sendValueRange={[number("minValue", 0), number("maxValue", 100)]}
  180. sendRequest={(...args: any) => {
  181. console.log(args);
  182. }}
  183. sendGiftData={{
  184. answerId: text("answerId", "1"),
  185. questionId: text("questionId", "1"),
  186. toUserId: text("toUserId", "1")
  187. }}
  188. handleVisibleChange={visiable => {
  189. console.log(visiable);
  190. }}
  191. >
  192. <Button>Click it</Button>
  193. </AllocWantedModal>
  194. );
  195. },
  196. {
  197. info: { inline: true },
  198. notes: "A very simple example of addon notes"
  199. }
  200. );
  201. stories.add(
  202. "WantedPushView",
  203. () => {
  204. const [currentWanted, setCurrentWanted] = React.useState(0);
  205. return (
  206. <>
  207. <WantedPublishView
  208. type={select(
  209. "type",
  210. {
  211. POP: "pop",
  212. Modal: "modal"
  213. },
  214. "pop"
  215. )}
  216. wrapperClass="test_wrapper"
  217. current_wanted={currentWanted}
  218. InputWantedValueChange={(value: any) => setCurrentWanted(value)}
  219. InputWantedOnBlur={(blurValue: any) => setCurrentWanted(blurValue)}
  220. InputWantedClear={() => setCurrentWanted(0)}
  221. InputWantedPressEnter={(enterValue: any) =>
  222. setCurrentWanted(enterValue)
  223. }
  224. CloseFunction={() => {
  225. console.log("Close Button");
  226. }}
  227. />
  228. <Divider />
  229. <div>currentWanted: {currentWanted}</div>
  230. </>
  231. );
  232. },
  233. {
  234. info: { inline: true },
  235. notes: "A very simple example of addon notes"
  236. }
  237. );
  238. stories.add(
  239. "WantedPublishPopover And Modal",
  240. () => {
  241. const [wanted, setWanted] = React.useState("");
  242. return (
  243. <div>
  244. <div>
  245. <WantedPublishModal>
  246. <div>ModalClick</div>
  247. </WantedPublishModal>
  248. </div>
  249. <Divider />
  250. <div>
  251. <WantedPublishPopover
  252. popoverConfig={{
  253. placement: select(
  254. "popoverConfigPlacement",
  255. {
  256. Undefined: undefined,
  257. Left: "left",
  258. Right: "right",
  259. Top: "top",
  260. Bottom: "bottom",
  261. TopLeft: "topLeft",
  262. TopRight: "topRight",
  263. BottomLeft: "bottomLeft",
  264. BottomRight: "bottomRight",
  265. LeftTop: "leftTop",
  266. LeftBottom: "leftBottom",
  267. RightTop: "rightTop",
  268. RightBottom: "rightBottom"
  269. },
  270. undefined
  271. ),
  272. trigger: select(
  273. "popoverConfigTrigger",
  274. {
  275. Undefined: undefined,
  276. Hover: "hover",
  277. Click: "click",
  278. Focus: "focus",
  279. ContextMenu: "contextMenu"
  280. },
  281. undefined
  282. )
  283. }}
  284. handleConfirm={(value: any) => {
  285. setWanted(value);
  286. }}
  287. >
  288. <Button>HoverIt{wanted}</Button>
  289. </WantedPublishPopover>
  290. </div>
  291. <Divider />
  292. {/* 下面用于分割wanted值的渲染,防止Error */}
  293. {(wanted => (
  294. <div>wanted{wanted}</div>
  295. ))(wanted)}
  296. </div>
  297. );
  298. },
  299. {
  300. info: { inline: true },
  301. notes: "A very simple example of addon notes"
  302. }
  303. );