15 lines
8.1 KiB
JavaScript
15 lines
8.1 KiB
JavaScript
import{S as G,i as H,s as K,k as le,d as C,t as y,v as se,h as T,w as re,f as A,X as ne,D as ae,g as j,m as z,j as M,y as R,o as b,b as f,P as ie,r as k,Q as oe,V as fe,z as W,e as _,A as N,F as U,C as Z}from"./index-06834efe.js";import{g as $,a as x}from"./spread-8a54911c.js";import{w as ce,p as me,M as ue,T as de,S as _e}from"./collect-stories-3e05a7a9.js";import{e as J}from"./each-e59479a4.js";import{B as pe}from"./Block-3bcdcbfd.js";import{g as E}from"./time-f9db70de.js";import{w as he}from"./withParams-47e2ab71.js";import"./_commonjsHelpers-de833af9.js";const ge=`The \`ReferralBlock\` component creates a set of referral links from recent dotcom stories using the [recent stories by section API](https://www.reuters.com/pf/api/v3/content/fetch/recent-stories-by-sections-v1?query=%7B%22section_ids%22%3A%22%2Fworld%2F%22%2C%22size%22%3A20%2C%22website%22%3A%22reuters%22%7D).
|
|
|
|
> The \`section\` prop determines which section stories are from.
|
|
>
|
|
> You can get the section ID from the section page on dotcom. For example, the section ID for World - Europe stories at \`www.reuters.com/world/europe/\` would be \`/world/europe/\`. (The leading and trailing slashes are required!)
|
|
|
|
\`\`\`svelte
|
|
<script>
|
|
import { ReferralBlock } from '@reuters-graphics/graphics-components';
|
|
<\/script>
|
|
|
|
<ReferralBlock section="/lifestyle/sports/" />
|
|
\`\`\`
|
|
`,L=ce([]);function Q(n,t,s){const e=n.slice();return e[10]=t[s],e}function V(n){let t,s;return t=new pe({props:{width:n[3],id:n[4],class:"referrals-block fmy-8 "+n[5],$$slots:{default:[we]},$$scope:{ctx:n}}}),{c(){j(t.$$.fragment)},m(e,l){z(t,e,l),s=!0},p(e,l){const a={};l&8&&(a.width=e[3]),l&16&&(a.id=e[4]),l&32&&(a.class="referrals-block fmy-8 "+e[5]),l&8390&&(a.$$scope={dirty:l,ctx:e}),t.$set(a)},i(e){s||(y(t.$$.fragment,e),s=!0)},o(e){T(t.$$.fragment,e),s=!1},d(e){M(t,e)}}}function X(n){let t,s;return{c(){t=b("div"),s=W(n[2]),f(t,"class","heading h4 font-bold svelte-1tl145l"),k(t,"stacked",n[6]&&n[6]<750)},m(e,l){C(e,t,l),_(t,s)},p(e,l){l&4&&N(s,e[2]),l&64&&k(t,"stacked",e[6]&&e[6]<750)},d(e){e&&A(t)}}}function Y(n){let t,s,e,l,a,o=n[10].kicker.name+"",i,u,r,m=n[10].title+"",v,B,c,S=E(new Date(n[10].display_time))+"",p,w,D,h,q,P,F,I,O;return{c(){t=b("div"),s=b("a"),e=b("div"),l=b("div"),a=b("div"),i=W(o),u=R(),r=b("div"),v=W(m),B=R(),c=b("div"),p=W(S),w=R(),D=b("div"),h=b("img"),O=R(),f(a,"class","kicker m-0 body-caption leading-tighter svelte-1tl145l"),f(a,"data-chromatic","ignore"),f(r,"class","title m-0 body-caption leading-tighter svelte-1tl145l"),f(r,"data-chromatic","ignore"),f(c,"class","publish-time body-caption leading-tighter svelte-1tl145l"),f(c,"data-chromatic","ignore"),f(l,"class","headline svelte-1tl145l"),k(l,"xs",n[6]&&n[6]<450),f(h,"class","block object-cover m-0 w-full svelte-1tl145l"),f(h,"data-chromatic","ignore"),U(h.src,q=n[10].thumbnail.renditions.landscape["240w"])||f(h,"src",q),f(h,"alt",P=n[10].thumbnail.caption||n[10].thumbnail.alt_text),f(D,"class","image-container block m-0 overflow-hidden relative svelte-1tl145l"),k(D,"xs",n[6]&&n[6]<450),f(e,"class","referral-pack flex justify-around my-0 mx-auto"),f(s,"href",F="https://www.reuters.com"+n[10].canonical_url),f(s,"target",n[1]),f(s,"rel",I=n[1]==="_blank"?"noreferrer":null),f(s,"class","svelte-1tl145l"),f(t,"class","referral svelte-1tl145l")},m(d,g){C(d,t,g),_(t,s),_(s,e),_(e,l),_(l,a),_(a,i),_(l,u),_(l,r),_(r,v),_(l,B),_(l,c),_(c,p),_(e,w),_(e,D),_(D,h),_(t,O)},p(d,g){g&128&&o!==(o=d[10].kicker.name+"")&&N(i,o),g&128&&m!==(m=d[10].title+"")&&N(v,m),g&128&&S!==(S=E(new Date(d[10].display_time))+"")&&N(p,S),g&64&&k(l,"xs",d[6]&&d[6]<450),g&128&&!U(h.src,q=d[10].thumbnail.renditions.landscape["240w"])&&f(h,"src",q),g&128&&P!==(P=d[10].thumbnail.caption||d[10].thumbnail.alt_text)&&f(h,"alt",P),g&64&&k(D,"xs",d[6]&&d[6]<450),g&128&&F!==(F="https://www.reuters.com"+d[10].canonical_url)&&f(s,"href",F),g&2&&f(s,"target",d[1]),g&2&&I!==(I=d[1]==="_blank"?"noreferrer":null)&&f(s,"rel",I)},d(d){d&&A(t)}}}function we(n){let t,s,e,l=n[2]&&X(n),a=J(n[7]),o=[];for(let i=0;i<a.length;i+=1)o[i]=Y(Q(n,a,i));return{c(){l&&l.c(),t=R(),s=b("div");for(let i=0;i<o.length;i+=1)o[i].c();f(s,"class","referral-container inline-flex flex-wrap w-full justify-between svelte-1tl145l"),ie(()=>n[9].call(s)),k(s,"stacked",n[6]&&n[6]<750),k(s,"xs",n[6]&&n[6]<450)},m(i,u){l&&l.m(i,u),C(i,t,u),C(i,s,u);for(let r=0;r<o.length;r+=1)o[r]&&o[r].m(s,null);e=oe(s,n[9].bind(s))},p(i,u){if(i[2]?l?l.p(i,u):(l=X(i),l.c(),l.m(t.parentNode,t)):l&&(l.d(1),l=null),u&194){a=J(i[7]);let r;for(r=0;r<a.length;r+=1){const m=Q(i,a,r);o[r]?o[r].p(m,u):(o[r]=Y(m),o[r].c(),o[r].m(s,null))}for(;r<o.length;r+=1)o[r].d(1);o.length=a.length}u&64&&k(s,"stacked",i[6]&&i[6]<750),u&64&&k(s,"xs",i[6]&&i[6]<450)},d(i){i&&(A(t),A(s)),l&&l.d(i),fe(o,i),e()}}}function be(n){let t,s,e=n[7].length===n[0]&&V(n);return{c(){e&&e.c(),t=le()},m(l,a){e&&e.m(l,a),C(l,t,a),s=!0},p(l,[a]){l[7].length===l[0]?e?(e.p(l,a),a&129&&y(e,1)):(e=V(l),e.c(),y(e,1),e.m(t.parentNode,t)):e&&(se(),T(e,1,1,()=>{e=null}),re())},i(l){s||(y(e),s=!0)},o(l){T(e),s=!1},d(l){l&&A(t),e&&e.d(l)}}}function ke(n,t,s){let e;ne(n,L,c=>s(7,e=c));let{section:l="/world/"}=t,{number:a=4}=t,{linkTarget:o="_self"}=t,{heading:i=""}=t,{width:u="wide"}=t,{id:r=""}=t,{class:m=""}=t,v;ae(async()=>{try{const S=(await(await fetch("https://www.reuters.com/pf/api/v3/content/fetch/recent-stories-by-sections-v1?"+new URLSearchParams({query:JSON.stringify({section_ids:l,size:20,website:"reuters"})}))).json()).result.articles.filter(p=>{var w;return(w=p==null?void 0:p.kicker)==null?void 0:w.name}).filter(p=>{var w,D,h;return(h=(D=(w=p==null?void 0:p.thumbnail)==null?void 0:w.renditions)==null?void 0:D.landscape)==null?void 0:h["240w"]}).filter(p=>{var w;return!((w=p==null?void 0:p.content)!=null&&w.third_party)}).slice(0,a);L.set(S)}catch{console.warn("Unable to fetch referral links.")}}),E();function B(){v=this.clientWidth,s(6,v)}return n.$$set=c=>{"section"in c&&s(8,l=c.section),"number"in c&&s(0,a=c.number),"linkTarget"in c&&s(1,o=c.linkTarget),"heading"in c&&s(2,i=c.heading),"width"in c&&s(3,u=c.width),"id"in c&&s(4,r=c.id),"class"in c&&s(5,m=c.class)},[a,o,i,u,r,m,v,e,l,B]}class ee extends G{constructor(t){super(),H(this,t,ke,be,K,{section:8,number:0,linkTarget:1,heading:2,width:3,id:4,class:5})}}function ve(n){let t,s;const e=[n[1]];let l={};for(let a=0;a<e.length;a+=1)l=Z(l,e[a]);return t=new ee({props:l}),{c(){j(t.$$.fragment)},m(a,o){z(t,a,o),s=!0},p(a,o){const i=o&2?$(e,[x(a[1])]):{};t.$set(i)},i(a){s||(y(t.$$.fragment,a),s=!0)},o(a){T(t.$$.fragment,a),s=!1},d(a){M(t,a)}}}function De(n){let t,s,e,l,a,o;const i=[{title:"Components/ReferralBlock"},{component:ee},n[0]];let u={};for(let r=0;r<i.length;r+=1)u=Z(u,i[r]);return t=new ue({props:u}),e=new de({props:{$$slots:{default:[ve,({args:r})=>({1:r}),({args:r})=>r?2:0]},$$scope:{ctx:n}}}),a=new _e({props:{name:"Default",args:{section:"/lifestyle/sports/",number:4,class:"fmy-5",heading:"More World Cup coverage"}}}),{c(){j(t.$$.fragment),s=R(),j(e.$$.fragment),l=R(),j(a.$$.fragment)},m(r,m){z(t,r,m),C(r,s,m),z(e,r,m),C(r,l,m),z(a,r,m),o=!0},p(r,[m]){const v=m&1?$(i,[i[0],i[1],x(r[0])]):{};t.$set(v);const B={};m&6&&(B.$$scope={dirty:m,ctx:r}),e.$set(B)},i(r){o||(y(t.$$.fragment,r),y(e.$$.fragment,r),y(a.$$.fragment,r),o=!0)},o(r){T(t.$$.fragment,r),T(e.$$.fragment,r),T(a.$$.fragment,r),o=!1},d(r){r&&(A(s),A(l)),M(t,r),M(e,r),M(a,r)}}}function ye(n){return[{...he(ge),argTypes:{width:{control:"select",options:["normal","wide","wider","widest","fluid"]},section:{control:"select",options:["/world/","/world/europe/","/lifestyle/","/lifestyle/sports/","/legal/","/business/","/business/energy/"]},number:{control:"select",options:[2,4,6,8]}}}]}class Be extends G{constructor(t){super(),H(this,t,ye,De,K,{})}}const te=me(Be,{meta:{title:"Components/ReferralBlock"},stories:{"tpl:default":{name:"default",template:!0,source:"<ReferralBlock {...args} />",hasArgs:!0},Default:{name:"Default",template:!1,source:"",hasArgs:!1}},allocatedIds:["default","Meta","Template","Story","componentDocs","ReferralBlock","withComponentDocs"]}),qe=te.meta,Pe=["Default"],Fe=te.stories.Default;export{Fe as Default,Pe as __namedExportsOrder,qe as default};
|
|
//# sourceMappingURL=ReferralBlock.stories-755c05d7.js.map
|