react-scryfall-components
Version:
Library of components based on scryfall api
1 lines • 9.32 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReactScryfallComponents=t():e.ReactScryfallComponents=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=8)}([function(e,t){e.exports=require("react")},function(e,t){e.exports=require("prop-types")},function(e,t){e.exports=require("react-emotion")},function(e,t){e.exports=require("axios")},function(e,t){e.exports=require("lru-cache")},function(e,t){e.exports=require("axios-extensions")},function(e,t){e.exports=require("libreact/lib/HoverSensor")},function(e,t){e.exports=require("libreact/lib/FocusSensor")},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),i=n(1),a=n.n(i),u=n(3),c=n.n(u),l=n(4),s=n.n(l),d=n(5),p=c.a.create({baseURL:"https://api.scryfall.com",adapter:Object(d.cacheAdapterEnhancer)(c.a.defaults.adapter,{defaultCache:new s.a({maxAge:864e5,size:1500})})});function f(e){return(f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function h(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function m(e,t){return!t||"object"!==f(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function y(e){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function S(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var g=function(e){function t(e){var n;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(n=m(this,y(t).call(this,e))).state={status:t.STATUS_IDLE,result:null},n}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(t,o.a.Component),function(e,t,n){t&&h(e.prototype,t),n&&h(e,n)}(t,[{key:"componentDidMount",value:function(){var e=this,n=this.props.endpoint;this.setState({status:t.STATUS_FETCHING}),p.get(n).then(function(n){e.setState({result:n.data,status:t.STATUS_SUCCESS})}).catch(function(r){console.error("There was an error while performing request to endpoint ".concat(n,"."),r.response.data),e.setState({result:r.response.data,status:t.STATUS_ERROR})})}},{key:"render",value:function(){var e=this.state,t=e.result,n=e.status;return(0,this.props.children)(t,n)}}]),t}();S(g,"displayName","Get"),S(g,"STATUS_IDLE","idle"),S(g,"STATUS_FETCHING","fetching"),S(g,"STATUS_SUCCESS","success"),S(g,"STATUS_ERROR","error"),S(g,"propTypes",{endpoint:a.a.string.isRequired,children:a.a.func.isRequired});var v=g;g.__docgenInfo={description:"",methods:[],displayName:"Get",props:{endpoint:{type:{name:"string"},required:!0,description:"endpoint of the scryfall api to fetch."},children:{type:{name:"func"},required:!0,description:"render function. Will be called with the result of the call, and a status.\nStatus can be IDLE, FETCHING, SUCCESS or ERROR\nresult is null when status is IDLE or FETCHING\nresult contains the data if status is SUCCESS, or the error if status is ERROR"}}};var E=n(2),x=n.n(E),_=x()("div",{target:"e1i2ck7j0"})(function(e){var t=e.width,n=e.height;return"\n display: flex;\n justify-content: center;\n align-items: center;\n width: ".concat(t,";\n height: ").concat(n,";\n & > div {\n display: inline-block;\n position: relative;\n width: 64px;\n height: 64px;\n\n & > div {\n display: inline-block;\n position: absolute;\n left: 6px;\n width: 13px;\n background: #fff;\n animation: lds-facebook 1.2s cubic-bezier(0, 0.5, 0.5, 1) infinite;\n }\n & > div:nth-child(1) {\n left: 6px;\n animation-delay: -0.24s;\n }\n & > div:nth-child(2) {\n left: 26px;\n animation-delay: -0.12s;\n }\n & > div:nth-child(3) {\n left: 45px;\n animation-delay: 0;\n }\n @keyframes lds-facebook {\n 0% {\n top: 6px;\n height: 51px;\n }\n 50%,\n 100% {\n top: 19px;\n height: 26px;\n }\n }\n }\n")}),w=function(e){var t=e.width,n=e.height;return o.a.createElement(_,{width:t?"".concat(t,"px"):"100%",height:n?"".concat(n,"px"):"100%"},o.a.createElement("div",null,o.a.createElement("div",null),o.a.createElement("div",null),o.a.createElement("div",null)))};w.propTypes={width:a.a.number,height:a.a.number},w.defaultProps={width:null,height:null};var T=w;w.__docgenInfo={description:"",methods:[],displayName:"LoadingIndicator",props:{width:{defaultValue:{value:"null",computed:!1},type:{name:"number"},required:!1,description:""},height:{defaultValue:{value:"null",computed:!1},type:{name:"number"},required:!1,description:""}}};var C={small:{w:146,h:204},normal:{w:488,h:680},large:{w:672,h:936}},O=function(e){var t=e.id,n=e.size;return o.a.createElement(v,{endpoint:"/cards/".concat(t)},function(e,t){return t===v.STATUS_SUCCESS?o.a.createElement("img",{style:{display:"block"},src:e.image_uris[n],alt:e.name,width:C[n].w,height:C[n].h}):o.a.createElement(T,{width:C[n].w,height:C[n].h})})};O.SIZE_SMALL="small",O.SIZE_NORMAL="normal",O.SIZE_LARGE="large",O.displayName="Card",O.propTypes={id:a.a.string.isRequired,size:a.a.oneOf([O.SIZE_SMALL,O.SIZE_NORMAL,O.SIZE_LARGE])},O.defaultProps={size:O.SIZE_NORMAL};var R=O;O.__docgenInfo={description:"Renders a card image from scryfall.",methods:[],displayName:"Card",props:{size:{defaultValue:{value:"Card.SIZE_NORMAL",computed:!0},type:{name:"enum",value:[{value:"Card.SIZE_SMALL",computed:!0},{value:"Card.SIZE_NORMAL",computed:!0},{value:"Card.SIZE_LARGE",computed:!0}]},required:!1,description:"Size of the image to render"},id:{type:{name:"string"},required:!0,description:"Scryfall ID of the card to render. This is a uuid that should look like this : eb28b35c-28a5-4042-b21d-6d43658a16eb"}}};var I=function(){return o.a.createElement("p",null,"This is a card autocomplete")},A=n(6),L=n(7);function j(e,t,n){e[n]&&(t[n]=e[n])}function k(){return(k=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}var q=x()("div",{target:"e130gayk0"})({position:"relative",display:"inline-block","& a":{"text-decoration":"underline dotted"},".tooltip":{"z-index":10,"text-align":"center",position:"absolute","background-color":"#ddd",bottom:"160%",left:"50%","margin-left":"-146px",width:"292px",height:"408px","& img":{width:"292px",height:"408px"},"&.hide":{display:"none"}},".tooltip::after":{content:'" "',position:"absolute",top:"100%",left:"50%","margin-left":"-5px","border-width":"5px","border-style":"solid","border-color":"black transparent transparent transparent"}}),N=function(e){var t=e.children,n=e.hover,r=n.isHover,i=n.bond,a=e.focus,u=a.isFocused,c=a.bond;return o.a.createElement(v,{endpoint:"/cards/named?fuzzy=".concat(t)},function(e,n){return n===v.STATUS_SUCCESS?o.a.createElement(q,k({},i,c),function(e){return o.a.createElement("span",{className:r||u?"tooltip":"tooltip hide"},o.a.createElement(R,{id:e,size:R.SIZE_NORMAL}))}(e.id),o.a.createElement("a",{href:e.scryfall_uri},t)):t})};N.displayName="CardLink",N.propTypes={children:a.a.string.isRequired};var U=function(e,t){var n=e.reduce(function(e,t){return t(e)},t);return j(t,n,"displayName"),j(t,n,"propTypes"),j(t,n,"defaultProps"),n.BaseComponent=t,n}([L.withFocus,A.withHover],N);N.__docgenInfo={description:"Renders a link to the scryfall page of a card. The link also features a tooltip showing the card's image.",methods:[],displayName:"CardLink",props:{children:{type:{name:"string"},required:!0,description:"Name of the card. The link will be to the scryfall page of the card, or if it can't be found, to the search page with this string as the query."}}},n.d(t,"Card",function(){return R}),n.d(t,"CardAutocomplete",function(){return I}),n.d(t,"CardLink",function(){return U})}])});