UNPKG

@lanaco/lnc-react-ui

Version:

React component library

27 lines (25 loc) 3.17 kB
"use strict";const _=require("react/jsx-runtime"),m=require("react"),j=require("./emotion-styled.browser.esm-DwHBgTPn.cjs"),t=require("./utils-BK6B_Y9X.cjs"),z=require("./emotion-element-f0de968e.browser.esm-B7k6i6lC.cjs"),f=require("./useUpdateEffect-BtMgpgIV.cjs"),H=e=>e=="small"?"3.125rem":e=="medium"?"3.375rem":"3.625rem",I=j.styled.div` box-sizing: border-box; ${e=>e.disabled===!0&&t.getDisabledStateCss(e.theme)}; min-width: 5.25rem; ${e=>e.fullWidth&&"width: 100%"}; display: flex; justify-content: center; align-items: center; height: ${e=>H(e.size)}; ${e=>t.getComponentTypographyCss(e.theme,a(e.type),e.size,"enabled")}; ${e=>!e.disabled&&"cursor: pointer"}; color: ${e=>!e.disabled&&t.getColorRgbaValue(e.theme,a(e.type),e.color,e.active?"active":"enabled","text")}; background-color: ${e=>e.type=="regular"||e.type=="pill"&&(e.disabled==!0||e.active==!1)?"transparent":!e.disabled&&t.getColorRgbaValue(e.theme,a(e.type),e.color,e.active?"active":"enabled","background","backgroundOpacity")}; ${e=>e.type=="underline"&&e.last==!1&&"border-right: 1px solid "+t.getColorRgbaValue(e.theme,a(e.type),e.color,"enabled","line")}; ${e=>h(e.theme,e.type,e.active,e.disabled,e.color,"enabled")}; ${e=>N(e.theme,e.type,e.first,e.last)}; &:hover { color: ${e=>!e.disabled&&t.getColorRgbaValue(e.theme,a(e.type),e.color,"hover","text")}; background-color: ${e=>e.type=="regular"?"transparent":!e.disabled&&t.getColorRgbaValue(e.theme,a(e.type),e.color,"hover","background","backgroundOpacity")}; ${e=>h(e.theme,e.type,e.active,e.disabled,e.color,"hover")}; } &:active { background: ${e=>t.getColorRgbaValue(e.theme,a(e.type),e.color,"active","background","backgroundOpacity")}; } `,a=e=>e=="underline"?"TabUnderline":e=="pill"?"TabPill":"TabRegular",N=(e,r,i,l)=>{if(r=="pill")return`border-radius: ${t.getBorderRadiusValueWithUnits(e,"regular")}`;if(r=="underline"&&i)return`border-radius: ${t.getBorderRadiusValueWithUnits(e,"regular")} 0 0 ${t.getBorderRadiusValueWithUnits(e,"regular")}`;if(r=="underline"&&l)return`border-radius: 0 ${t.getBorderRadiusValueWithUnits(e,"regular")} ${t.getBorderRadiusValueWithUnits(e,"regular")} 0`},h=(e,r,i,l,u,n)=>{if(r!="pill")return`border-bottom: ${!l&&(i||n=="hover")?e.components[r==="regular"?"TabRegular":"TabUnderline"].default.enabled.lineHeight+"":e.components[r==="regular"?"TabRegular":"TabUnderline"].default.hover.lineHeight+""} solid ${t.getColorRgbaValue(e,a(r),u,i&&!l?"active":l?"enabled":n,"line")}`},O=m.forwardRef((e,r)=>{const{type:i="underline",disabled:l,first:u=!1,last:n=!1,fullWidth:y=!1,active:d=!1,activeIndex:o,index:c,onFocus:v=()=>{},onBlur:$=()=>{},onClick:s=()=>{},onKeyDown:R=()=>{},itemClick:g=()=>{},size:C="small",color:k="primary",className:T="",style:V={},children:x,...U}=e,B=z.useTheme(),[W,b]=m.useState(d),q={theme:B,color:k,size:C,style:V,className:"lnc-ui-tabitem "+T},w=E=>{g&&!l&&g(c),s&&!l&&s(E)};return f.useUpdateEffect(()=>{b(d)},[d]),f.useUpdateEffect(()=>{b(o==c)},[o]),_.jsx(I,{ref:r,onFocus:v,onBlur:$,onClick:w,onKeyDown:R,disabled:l,type:i,first:u,last:n,fullWidth:y,active:W,...q,...U,children:x})});module.exports=O;