Brak opisu

Payment.stories.tsx 7.8KB

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