暂无描述

index.js.map 8.3KB

1
  1. {"version":3,"file":"index.js","sources":["../../src/components/Payment/PriceOptions/index.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport classnames from \"classnames\";\nimport { Input } from \"antd\";\nimport styles from \"./PriceOptions.less\";\nimport { exportStyleSizeClass } from '../Utils/utils';\n\n/**\n * rowModa: \"single\" 单行 | \"multi\" 两行\n * price:number 金额\n * onPriceChange: (value: price) => void\n * size: \"small\" | \"normal\" | \"large\" 样式暂无支持\n * focusScroll:boolean 点击时是否自动滚动到输入框处\n * withTitle:boolean 是否显示标题\n * titleText:string|dom 标题内容 \n * inputPlaceholderText:string 输入框默认内容\n * priceOptions:Array 金额按钮数组,默认为 [100, 600, 800]\n * priceRender:Function 金额按钮内部数字渲染字样\n * inputPriceRender:Function 输入框金额字体渲染字样\n * inputSuffix:string|dom Antd组件Suffix属性\n * injectOptions: { priceBtnClass, priceInputClass } 分别控制具体渲染按钮和输入框样式 \n * inputRef:React.RefObject<any> Input的Ref \n * @interface Props\n */\ninterface Props {\n rowMode: \"single\" | \"multi\";\n price: number;\n onPriceChange: (v: number) => void;\n size: \"small\" | \"normal\" | \"large\";\n focusScroll: boolean;\n withTitle: boolean;\n titleText?: string | JSX.Element[] | JSX.Element;\n inputPlaceholderText?: string;\n priceOptions?: Array<any>;\n priceRender?: Function;\n inputPriceRender?: Function;\n inputSuffix?: string | JSX.Element[] | JSX.Element;\n injectOptions?: {\n priceBtnClass: (isActive: boolean) => any;\n priceInputClass: Function;\n }\n inputRef: React.RefObject<any>;\n}\n\nconst PriceOptions = ({\n price,\n onPriceChange,\n rowMode = \"single\",\n size = \"normal\",\n focusScroll = true,\n withTitle = true,\n titleText = \"Price\",\n inputPlaceholderText = \"Others\",\n priceOptions = [100, 600, 800],\n priceRender = (i: any) => i / 100,\n inputPriceRender = (i: any) => (i ? i / 100 : \"\"),\n inputSuffix = \"¥\",\n injectOptions = {\n priceBtnClass: () => undefined,\n priceInputClass: () => undefined,\n },\n inputRef\n}: Props) => {\n const defaultOptions = priceOptions;\n // 控制是否为其他金额输入情况\n const [inputStatus, setInputStatus] = useState(false);\n const [inputPrice, setInputPrice] = useState('');\n\n return (\n <div className={classnames(styles.options, {\n [styles.multi]: rowMode === \"multi\",\n ...exportStyleSizeClass(styles, size),\n })}>\n {withTitle ? (titleText || null) : null}\n <div className={styles.infoItem}>\n <span className={styles.priceBtn}>\n {defaultOptions.map(item => (\n <span\n className={classnames({\n [styles.priceItem]: true,\n [styles.active]: price === item && !inputStatus,\n ...injectOptions.priceBtnClass(price === item && !inputStatus),\n })}\n key={item}\n onClick={() => {\n onPriceChange(item);\n setInputStatus(false);\n }}\n >\n {priceRender(item)}\n </span>\n ))}\n </span>\n <Input\n ref={inputRef}\n className={classnames(styles.priceInput, {...injectOptions.priceInputClass()})}\n onMouseEnter={() => {\n if (inputStatus && inputRef && inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }}\n suffix={inputSuffix}\n value={inputStatus ? inputPriceRender(inputPrice) : \"\"}\n placeholder={inputPlaceholderText}\n onChange={e => {\n const n = +e.target.value;\n if (Number.isNaN(n)) {\n return;\n }\n // 测试暂时改成1分\n setInputPrice(`${n * 100}`);\n onPriceChange(n * 100);\n }}\n onClick={e => {\n if (!inputStatus) {\n setInputPrice('');\n setInputStatus(true);\n }\n }}\n onFocus={e => {\n e.target.placeholder = \"\";\n if (inputStatus) {\n setInputPrice(`${price}`);\n } else {\n setInputPrice('');\n setInputStatus(true);\n }\n if (focusScroll) {\n e.target.scrollIntoView();\n }\n }}\n onBlur={e => {\n e.target.placeholder = inputPlaceholderText;\n if (inputPrice) {\n setInputStatus(true);\n } else {\n setInputStatus(false);\n }\n }}\n />\n </div>\n </div>\n );\n};\n\nexport default PriceOptions;\n"],"names":["PriceOptions","price","onPriceChange","rowMode","size","focusScroll","withTitle","titleText","inputPlaceholderText","priceOptions","priceRender","i","inputPriceRender","inputSuffix","injectOptions","priceBtnClass","undefined","priceInputClass","inputRef","defaultOptions","useState","inputStatus","setInputStatus","inputPrice","setInputPrice","React","createElement","className","classnames","styles","options","multi","exportStyleSizeClass","infoItem","priceBtn","map","item","priceItem","active","key","onClick","Input","ref","priceInput","onMouseEnter","current","focus","select","suffix","value","placeholder","onChange","e","n","target","Number","isNaN","onFocus","scrollIntoView","onBlur"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAMA,YAAY,GAAG,SAAfA,YAAe,KAAA,EAkBT;MAjBVC,KAiBU,QAjBVA;MACAC,aAgBU,QAhBVA;0BACAC;MAAAA,OAeU,6BAfA;uBACVC;MAAAA,IAcU,0BAdH;8BACPC;MAAAA,WAaU,iCAbI;4BACdC;MAAAA,SAYU,+BAZE;4BACZC;MAAAA,SAWU,+BAXE;mCACZC;MAAAA,oBAUU,sCAVa;+BACvBC;MAAAA,YASU,kCATK,CAAC,GAAD,EAAM,GAAN,EAAW,GAAX;8BACfC;MAAAA,WAQU,iCARI,UAACC,CAAD;WAAYA,CAAC,GAAG;AAQpB;mCAPVC;MAAAA,gBAOU,sCAPS,UAACD,CAAD;WAAaA,CAAC,GAAGA,CAAC,GAAG,GAAP,GAAa;AAOpC;8BANVE;MAAAA,WAMU,iCANI;gCACdC;MAAAA,aAKU,mCALM;AACdC,IAAAA,aAAa,EAAE,sBAAA;aAAMC;AADP,KAAA;AAEdC,IAAAA,eAAe,EAAE,wBAAA;aAAMD;;AAFT;MAIhBE,QACU,QADVA;MAEMC,cAAc,GAAGV;;kBAEeW,QAAQ,CAAC,KAAD;;MAAvCC,WAHG;MAGUC,cAHV;;mBAI0BF,QAAQ,CAAC,EAAD;;MAArCG,UAJG;MAISC,aAJT;;SAORC,KAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AAAKC,IAAAA,SAAS,EAAEC,UAAU,CAACC,MAAM,CAACC,OAAR,oCACvBD,MAAM,CAACE,OAAQ5B,OAAO,KAAK,UACzB6B,oBAAoB,CAACH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