← Back
Editing: product-sale-badge-frontend.js
(globalThis.webpackChunkwebpackWcBlocksFrontendJsonp=globalThis.webpackChunkwebpackWcBlocksFrontendJsonp||[]).push([[442],{3651:(e,t,o)=>{"use strict";o.d(t,{p:()=>i});var n=o(4921),r=o(3993),s=o(7356),c=o(9786);function a(e={}){const t={};return(0,c.getCSSRules)(e,{selector:""}).forEach(e=>{t[e.key]=e.value}),t}function l(e,t){return e&&t?`has-${(0,s.c)(t)}-${e}`:""}const i=e=>{const t=(e=>{const t=(0,r.isObject)(e)?e:{style:{}};let o=t.style;return(0,r.isString)(o)&&(o=JSON.parse(o)||{}),(0,r.isObject)(o)||(o={}),{...t,style:o}})(e),o=function(e){const{backgroundColor:t,textColor:o,gradient:s,style:c}=e,i=l("background-color",t),u=l("color",o),p=function(e){if(e)return`has-${e}-gradient-background`}(s),d=p||c?.color?.gradient;return{className:(0,n.A)(u,p,{[i]:!d&&!!i,"has-text-color":o||c?.color?.text,"has-background":t||c?.color?.background||s||c?.color?.gradient,"has-link-color":(0,r.isObject)(c?.elements?.link)?c?.elements?.link?.color:void 0}),style:a({color:c?.color||{}})}}(t),s=function(e){const t=e.style?.border||{};return{className:function(e){const{borderColor:t,style:o}=e,r=t?l("border-color",t):"";return(0,n.A)({"has-border-color":!!t||!!o?.border?.color,[r]:!!r})}(e),style:a({border:t})}}(t),c=function(e){return{className:void 0,style:a({spacing:e.style?.spacing||{}})}}(t),i=(e=>{const t=(0,r.isObject)(e.style.typography)?e.style.typography:{},o=(0,r.isString)(t.fontFamily)?t.fontFamily:"";return{className:e.fontFamily?`has-${e.fontFamily}-font-family`:o,style:{fontSize:e.fontSize?`var(--wp--preset--font-size--${e.fontSize})`:t.fontSize,fontStyle:t.fontStyle,fontWeight:t.fontWeight,letterSpacing:t.letterSpacing,lineHeight:t.lineHeight,textDecoration:t.textDecoration,textTransform:t.textTransform}}})(t);return{className:(0,n.A)(i.className,o.className,s.className,c.className),style:{...i.style,...o.style,...s.style,...c.style}}}},6475:(e,t,o)=>{"use strict";o.r(t),o.d(t,{Block:()=>p,default:()=>d});var n=o(7723),r=o(910),s=o(4921),c=o(4656),a=o(2796),l=o(3651),i=o(1616);o(4324);var u=o(790);const p=e=>{const{className:t,align:o,isDescendentOfSingleProductTemplate:i}=e,p=(0,l.p)(e),{parentClassName:d}=(0,a.useInnerBlockLayoutContext)(),{product:g}=(0,a.useProductDataContext)();if(!(g.id&&g.on_sale||i))return null;const f="amount"===e.badgeContent||"percentage"===e.badgeContent;let m=e.saleText||(0,n.__)("Sale","woocommerce");if(f&&"grouped"!==g.type){const t="prices"in g?g.prices:void 0,o=(e=>{const t=Number(e?.regular_price),o=t-Number(e?.price);return t>0&&o>0?{amount:o,percentage:Math.round(o/t*100)}:null})(t);if(o){if("percentage"===e.badgeContent&&0===o.percentage)return null;const s="percentage"===e.badgeContent?(0,n.sprintf)(/* translators: %s: discount percentage. %% is the percent sign. */ /* translators: %s: discount percentage. %% is the percent sign. */ (0,n.__)("%s%%","woocommerce"),o.percentage):(0,r.formatPrice)(o.amount,(0,r.getCurrencyFromPriceResponse)(t));m="variable"===g.type?(0,n.sprintf)(/* translators: %s: approximate discount for a variable product in the editor. */ /* translators: %s: approximate discount for a variable product in the editor. */ (0,n.__)("Up to %s","woocommerce"),s):`${e.prefix??""}${s}${e.suffix??""}`}}const y="string"==typeof o?`wc-block-components-product-sale-badge--align-${o}`:"";return(0,u.jsx)("div",{className:(0,s.A)("wc-block-components-product-sale-badge",t,y,{[`${d}__product-onsale`]:d},p.className),style:p.style,children:(0,u.jsx)(c.Label,{label:m,screenReaderLabel:(0,n.sprintf)(/* translators: %s: sale badge text. */ /* translators: %s: sale badge text. */ (0,n.__)("Product on sale: %s","woocommerce"),m)})})},d=(0,i.withProductDataContext)(p)},4324:()=>{}}]);
Save File
Cancel