carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 3.02 kB
JavaScript
import{jsxs as e,jsx as r}from"react/jsx-runtime";import{useState as t,useRef as n}from"react";import"../../style/utils/filter-styled-system-padding-props.js";import o from"../../style/utils/filter-styled-system-margin-props.js";import{StyledBadgeWrapper as i,StyledBadge as l,StyledCounter as a}from"./badge.style.js";import s from"../icon/icon.component.js";import c from"../../__internal__/utils/helpers/tags/tags.js";import p from"../../__internal__/utils/helpers/guid/index.js";import d from"../../__internal__/utils/logger/index.js";function u(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}let b=!1,m=!1,f=!1;const y=y=>{var{"aria-label":g,children:O,counter:j=0,color:h,onClick:v,id:w,size:P="medium",variant:_="typical",inverse:k=!1}=y,x=function(e,r){if(null==e)return{};var t,n,o=function(e,r){if(null==e)return{};var t,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||(o[t]=e[t]);return o}(e,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)t=i[n],r.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}(y,["aria-label","children","counter","color","onClick","id","size","variant","inverse"]);v&&!b&&(d.deprecate("The `onClick` prop in `Badge` is deprecated and will soon be removed."),b=!0),g&&!m&&(d.deprecate("The `aria-label` prop in `Badge` is deprecated and will soon be removed."),m=!0),h&&!f&&(d.deprecate("The `color` prop in `Badge` is deprecated and will soon be removed."),f=!0);const[C,S]=t(!1),[B,D]=t(!1),{current:E}=n(w||p());let T=!0;const z=v&&"small"!==P,M=z&&(C||B);let F=j;"string"==typeof j?(j.length>4&&(F=j.substring(0,4)),""===j&&(T=!1)):"number"==typeof j&&(j>999&&(F="999+"),(j<=0||j%1!=0)&&(T=!1));const I=()=>{return T?r(l,(e=function(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),n.forEach((function(r){u(e,r,t[r])}))}return e}({customColor:h,id:E,"aria-label":g,size:P,variant:_,inverse:k,hasChildren:!!O,onFocus:()=>{S(!0)},onBlur:()=>{S(!1)},onMouseEnter:()=>{D(!0)},onMouseLeave:()=>{D(!1)}},z&&{buttonType:"secondary",onClick:v},c("badge",x),o(x)),t=null!=(t={children:M?r(s,{"data-role":"badge-cross-icon","data-element":"badge-cross-icon",type:"cross",color:"white"}):"small"!==P?r(a,{"data-element":"badge-counter",children:F}):null})?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r.push.apply(r,t)}return r}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e)):null;var e,t};return O?e(i,{"data-role":"badge-wrapper",children:[O,I()]}):I()};export{y as Badge,y as default};