carbon-react 158.3.1 → 158.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/components/tabs/__next__/tabs.component.d.ts +2 -2
- package/esm/components/tabs/__next__/tabs.component.js +1 -1
- package/esm/components/tabs/__next__/tabs.types.d.ts +7 -0
- package/lib/components/tabs/__next__/tabs.component.d.ts +2 -2
- package/lib/components/tabs/__next__/tabs.component.js +1 -1
- package/lib/components/tabs/__next__/tabs.types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { TabListProps, TabPanelProps, TabProps, TabsProps } from "./tabs.types";
|
|
2
|
+
import { TabsHandle, TabListProps, TabPanelProps, TabProps, TabsProps } from "./tabs.types";
|
|
3
3
|
export declare const TabPanel: ({ children, id, tabId }: TabPanelProps) => React.JSX.Element;
|
|
4
4
|
export declare const Tab: ({ controls, error, id, label, leftSlot, rightSlot, warning, info, }: TabProps) => React.JSX.Element;
|
|
5
|
-
export declare const TabList:
|
|
5
|
+
export declare const TabList: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<TabsHandle>>;
|
|
6
6
|
export declare const Tabs: ({ children, labelledBy, orientation, selectedTabId, size, }: TabsProps) => React.JSX.Element;
|
|
7
7
|
export default Tabs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import n,
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as r}from"react/jsx-runtime";import{forwardRef as n,useState as i,useEffect as o,useRef as l,useImperativeHandle as a,useCallback as c}from"react";import{Typography as s}from"../../typography/typography.component.js";import{TabsProvider as d,useTabs as b}from"./tabs.context.js";import{StyledTabs as u,StyledTab as f,StyledTabListWrapper as h,StyledTabList as p,Spacer as g,StyledTabPanel as m,StyledScrollButton as v,StyledScrollButtonPlaceholder as y}from"./tabs.style.js";import I from"../../../__internal__/utils/logger/index.js";import w from"../../../hooks/__internal__/useResizeObserver/useResizeObserver.js";import x from"../../icon/icon.component.js";import{TabProvider as k}from"./tab.context.js";const z=({children:t,id:r,tabId:n})=>{const{activeTab:i}=b();return e(k,{tabId:n,visible:n===i,children:e(m,{id:r,role:"tabpanel","aria-labelledby":n,children:t})})};let T=!1;const j=({controls:r,error:n=!1,id:l,label:a,leftSlot:c,rightSlot:s,warning:d=!1,info:u=!1})=>{const[h,p]=i(n),[g,m]=i(d),[v,y]=i(u),{activeTab:w,focusIndex:z,orientation:j,setActiveTab:S,setCurrentTabId:_,setFocusIndex:A,size:L,errors:O,warnings:R,infos:C}=b(),N=w===l;o((()=>{N&&_(l)}),[l,N,_]),!c&&!s||"string"==typeof a||T||(I.warn("[WARNING] Using `leftSlot` and/or `rightSlot` is not supported when `label` is not a string. Please use `leftSlot` and/or `rightSlot` alongside a string `label`, or use the `label` prop exclusively."),T=!0),o((()=>{if(z===l){const e=document.getElementById(l);null==e||e.focus()}}),[z,l,_]),o((()=>{let e=O[l],t=R[l],r=C[l];if(n&&!e&&(e={static:n}),d&&!t&&(t={static:d}),u&&!r&&(r={static:u}),!e)return void p(!1);const i=Object.keys(e).map((t=>e[t])).filter((e=>!1!==e)),o=n||i.length>0;if(p(o),!t)return void m(!1);const a=Object.keys(t).map((e=>t[e])).filter((e=>!1!==e)),c=d||a.length>0;if(m(c),!r)return void y(!1);const s=Object.keys(r).map((e=>r[e])).filter((e=>!1!==e)),b=u||s.length>0;y(b)}),[n,l,O,R,d,C,u]);const B=()=>{if(h||g||v){if(h)return e(x,{"data-role":"icon-error",type:"error",color:"#db004e"});if(g)return e(x,{"data-role":"icon-warning",type:"warning",color:"#d64309"});if(v)return e(x,{"data-role":"icon-info",type:"info",color:"#0060a7ff"})}return null};return e(k,{tabId:l,visible:!0,children:e(f,{activeTab:w===l,"aria-controls":r,"aria-selected":N?"true":"false",error:h,info:v,id:l,onClick:()=>{S(l),A(l)},orientation:j,role:"tab",size:L,type:"button",tabIndex:w===l?0:-1,warning:g,children:t("span","string"==typeof a?{className:"tab-title-content-wrapper",children:[c,a,s,B()]}:{className:"tab-title-content-wrapper",children:[a,B()]})})})},S=n((({ariaLabel:n,children:d},u)=>{const f=l(null),{activeTab:m,focusIndex:I,orientation:k,selectedTabId:z,setFocusIndex:T,setActiveTab:j,size:S}=b();a(u,(()=>({focusTab:e=>{var t;const r=null===(t=f.current)||void 0===t?void 0:t.querySelector(`#${e}`);null==r||r.focus(),T(e),j(e)}})));const _=c((()=>{var e;const t=(null===(e=f.current)||void 0===e?void 0:e.querySelectorAll("[role='tab']"))||[];return Array.from(t).map((e=>e.id)).filter((e=>e))}),[]);o((()=>{if(z)j(z);else if(!m){const e=_()[0];j(e)}}),[m,_,z,j]);const[A,L]=i(!1),[O,R]=i(!1),[C,N]=i(!1),B=c((()=>{if(f.current){const e=f.current.scrollWidth-f.current.clientWidth-20;L(e>0),R(f.current.scrollLeft>=20),N(f.current.scrollLeft<=e)}}),[]);w(f,(()=>{B()})),o((()=>{f.current&&B()}),[B]);const E=e=>{f.current&&("left"===e?f.current.scrollLeft-=200:f.current.scrollLeft+=200,B())};return t(r,{children:[e(s,{id:"tablist-aria-label",screenReaderOnly:!0,children:n}),t(h,{children:["vertical"!==k&&A?O?e(v,{"data-role":"tab-navigation-button-left",id:"tab-navigation-button-left",onClick:()=>E("left"),size:S,tabIndex:-1,title:"Scroll Tabs Left",type:"button",children:e(x,{type:"chevron_left"})}):e(y,{size:S}):null,t(p,{ariaLabel:n,"aria-labelledby":"tablist-aria-label",id:"tablist",onKeyDown:e=>{const t=_(),r=t.indexOf(I||m),n=t.length-1;if(-1===r)return;let i=r;switch(e.key){case"Home":i=0;break;case"End":i=n;break;case"ArrowRight":i=(r+1)%t.length;break;case"ArrowLeft":i=(r-1+t.length)%t.length;break;case"ArrowUp":"vertical"===k&&(i=(r-1+t.length)%t.length);break;case"ArrowDown":"vertical"===k&&(i=(r+1)%t.length);break;case"Enter":case" ":return void j(m);default:return}T(t[i])},orientation:k,ref:f,role:"tablist",size:S,tabIndex:-1,children:[d,e(g,{})]}),"vertical"!==k&&A?C?e(v,{"data-role":"tab-navigation-button-right",id:"tab-navigation-button-right",onClick:()=>E("right"),size:S,tabIndex:-1,title:"Scroll Tabs Right",type:"button",children:e(x,{type:"chevron_right"})}):e(y,{size:S}):null]})]})})),_=({children:t,labelledBy:r="",orientation:n="horizontal",selectedTabId:i,size:o="medium"})=>e(d,{labelledBy:r,orientation:n,selectedTabId:i,size:o,children:e(u,{id:"tabs-container",orientation:n,children:t})});export{j as Tab,S as TabList,z as TabPanel,_ as Tabs,_ as default};
|
|
@@ -4,6 +4,13 @@ export type ValidationRecord = Record<string, TabValidationRecord>;
|
|
|
4
4
|
export interface TabContextProps {
|
|
5
5
|
tabId?: string;
|
|
6
6
|
}
|
|
7
|
+
export type TabsHandle = {
|
|
8
|
+
/**
|
|
9
|
+
* Programmatically focus on a specific tab.
|
|
10
|
+
* @param id - The ID of the tab to focus. Must match the `id` prop of the target `Tab` component.
|
|
11
|
+
*/
|
|
12
|
+
focusTab: (id: string) => void;
|
|
13
|
+
};
|
|
7
14
|
export interface TabsContextProps {
|
|
8
15
|
activeTab: string;
|
|
9
16
|
currentTabId?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { TabListProps, TabPanelProps, TabProps, TabsProps } from "./tabs.types";
|
|
2
|
+
import { TabsHandle, TabListProps, TabPanelProps, TabProps, TabsProps } from "./tabs.types";
|
|
3
3
|
export declare const TabPanel: ({ children, id, tabId }: TabPanelProps) => React.JSX.Element;
|
|
4
4
|
export declare const Tab: ({ controls, error, id, label, leftSlot, rightSlot, warning, info, }: TabProps) => React.JSX.Element;
|
|
5
|
-
export declare const TabList:
|
|
5
|
+
export declare const TabList: React.ForwardRefExoticComponent<TabListProps & React.RefAttributes<TabsHandle>>;
|
|
6
6
|
export declare const Tabs: ({ children, labelledBy, orientation, selectedTabId, size, }: TabsProps) => React.JSX.Element;
|
|
7
7
|
export default Tabs;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../../typography/typography.component.js"),a=require("./tabs.context.js"),l=require("./tabs.style.js"),n=require("../../../__internal__/utils/logger/index.js"),i=require("../../../hooks/__internal__/useResizeObserver/useResizeObserver.js"),s=require("../../icon/icon.component.js"),o=require("./tab.context.js");
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),r=require("../../typography/typography.component.js"),a=require("./tabs.context.js"),l=require("./tabs.style.js"),n=require("../../../__internal__/utils/logger/index.js"),i=require("../../../hooks/__internal__/useResizeObserver/useResizeObserver.js"),s=require("../../icon/icon.component.js"),o=require("./tab.context.js");let c=!1;const d=t.forwardRef((({ariaLabel:n,children:o},c)=>{const d=t.useRef(null),{activeTab:u,focusIndex:b,orientation:f,selectedTabId:h,setFocusIndex:p,setActiveTab:x,size:y}=a.useTabs();t.useImperativeHandle(c,(()=>({focusTab:e=>{var t;const r=null===(t=d.current)||void 0===t?void 0:t.querySelector(`#${e}`);null==r||r.focus(),p(e),x(e)}})));const g=t.useCallback((()=>{var e;const t=(null===(e=d.current)||void 0===e?void 0:e.querySelectorAll("[role='tab']"))||[];return Array.from(t).map((e=>e.id)).filter((e=>e))}),[]);t.useEffect((()=>{if(h)x(h);else if(!u){const e=g()[0];x(e)}}),[u,g,h,x]);const[v,j]=t.useState(!1),[S,T]=t.useState(!1),[I,m]=t.useState(!1),w=t.useCallback((()=>{if(d.current){const e=d.current.scrollWidth-d.current.clientWidth-20;j(e>0),T(d.current.scrollLeft>=20),m(d.current.scrollLeft<=e)}}),[]);i.default(d,(()=>{w()})),t.useEffect((()=>{d.current&&w()}),[w]);const k=e=>{d.current&&("left"===e?d.current.scrollLeft-=200:d.current.scrollLeft+=200,w())};return e.jsxs(e.Fragment,{children:[e.jsx(r.Typography,{id:"tablist-aria-label",screenReaderOnly:!0,children:n}),e.jsxs(l.StyledTabListWrapper,{children:["vertical"!==f&&v?S?e.jsx(l.StyledScrollButton,{"data-role":"tab-navigation-button-left",id:"tab-navigation-button-left",onClick:()=>k("left"),size:y,tabIndex:-1,title:"Scroll Tabs Left",type:"button",children:e.jsx(s.default,{type:"chevron_left"})}):e.jsx(l.StyledScrollButtonPlaceholder,{size:y}):null,e.jsxs(l.StyledTabList,{ariaLabel:n,"aria-labelledby":"tablist-aria-label",id:"tablist",onKeyDown:e=>{const t=g(),r=t.indexOf(b||u),a=t.length-1;if(-1===r)return;let l=r;switch(e.key){case"Home":l=0;break;case"End":l=a;break;case"ArrowRight":l=(r+1)%t.length;break;case"ArrowLeft":l=(r-1+t.length)%t.length;break;case"ArrowUp":"vertical"===f&&(l=(r-1+t.length)%t.length);break;case"ArrowDown":"vertical"===f&&(l=(r+1)%t.length);break;case"Enter":case" ":return void x(u);default:return}p(t[l])},orientation:f,ref:d,role:"tablist",size:y,tabIndex:-1,children:[o,e.jsx(l.Spacer,{})]}),"vertical"!==f&&v?I?e.jsx(l.StyledScrollButton,{"data-role":"tab-navigation-button-right",id:"tab-navigation-button-right",onClick:()=>k("right"),size:y,tabIndex:-1,title:"Scroll Tabs Right",type:"button",children:e.jsx(s.default,{type:"chevron_right"})}):e.jsx(l.StyledScrollButtonPlaceholder,{size:y}):null]})]})})),u=({children:t,labelledBy:r="",orientation:n="horizontal",selectedTabId:i,size:s="medium"})=>e.jsx(a.TabsProvider,{labelledBy:r,orientation:n,selectedTabId:i,size:s,children:e.jsx(l.StyledTabs,{id:"tabs-container",orientation:n,children:t})});exports.Tab=({controls:r,error:i=!1,id:d,label:u,leftSlot:b,rightSlot:f,warning:h=!1,info:p=!1})=>{const[x,y]=t.useState(i),[g,v]=t.useState(h),[j,S]=t.useState(p),{activeTab:T,focusIndex:I,orientation:m,setActiveTab:w,setCurrentTabId:k,setFocusIndex:z,size:_,errors:q,warnings:L,infos:A}=a.useTabs(),P=T===d;t.useEffect((()=>{P&&k(d)}),[d,P,k]),!b&&!f||"string"==typeof u||c||(n.default.warn("[WARNING] Using `leftSlot` and/or `rightSlot` is not supported when `label` is not a string. Please use `leftSlot` and/or `rightSlot` alongside a string `label`, or use the `label` prop exclusively."),c=!0),t.useEffect((()=>{if(I===d){const e=document.getElementById(d);null==e||e.focus()}}),[I,d,k]),t.useEffect((()=>{let e=q[d],t=L[d],r=A[d];if(i&&!e&&(e={static:i}),h&&!t&&(t={static:h}),p&&!r&&(r={static:p}),!e)return void y(!1);const a=Object.keys(e).map((t=>e[t])).filter((e=>!1!==e)),l=i||a.length>0;if(y(l),!t)return void v(!1);const n=Object.keys(t).map((e=>t[e])).filter((e=>!1!==e)),s=h||n.length>0;if(v(s),!r)return void S(!1);const o=Object.keys(r).map((e=>r[e])).filter((e=>!1!==e)),c=p||o.length>0;S(c)}),[i,d,q,L,h,A,p]);const E=()=>{if(x||g||j){if(x)return e.jsx(s.default,{"data-role":"icon-error",type:"error",color:"#db004e"});if(g)return e.jsx(s.default,{"data-role":"icon-warning",type:"warning",color:"#d64309"});if(j)return e.jsx(s.default,{"data-role":"icon-info",type:"info",color:"#0060a7ff"})}return null};return e.jsx(o.TabProvider,{tabId:d,visible:!0,children:e.jsx(l.StyledTab,{activeTab:T===d,"aria-controls":r,"aria-selected":P?"true":"false",error:x,info:j,id:d,onClick:()=>{w(d),z(d)},orientation:m,role:"tab",size:_,type:"button",tabIndex:T===d?0:-1,warning:g,children:"string"==typeof u?e.jsxs("span",{className:"tab-title-content-wrapper",children:[b,u,f,E()]}):e.jsxs("span",{className:"tab-title-content-wrapper",children:[u,E()]})})})},exports.TabList=d,exports.TabPanel=({children:t,id:r,tabId:n})=>{const{activeTab:i}=a.useTabs();return e.jsx(o.TabProvider,{tabId:n,visible:n===i,children:e.jsx(l.StyledTabPanel,{id:r,role:"tabpanel","aria-labelledby":n,children:t})})},exports.Tabs=u,exports.default=u;
|
|
@@ -4,6 +4,13 @@ export type ValidationRecord = Record<string, TabValidationRecord>;
|
|
|
4
4
|
export interface TabContextProps {
|
|
5
5
|
tabId?: string;
|
|
6
6
|
}
|
|
7
|
+
export type TabsHandle = {
|
|
8
|
+
/**
|
|
9
|
+
* Programmatically focus on a specific tab.
|
|
10
|
+
* @param id - The ID of the tab to focus. Must match the `id` prop of the target `Tab` component.
|
|
11
|
+
*/
|
|
12
|
+
focusTab: (id: string) => void;
|
|
13
|
+
};
|
|
7
14
|
export interface TabsContextProps {
|
|
8
15
|
activeTab: string;
|
|
9
16
|
currentTabId?: string;
|