sbwb-ds 1.0.17 → 1.0.19
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/dist/sbwb-ds.js +7 -8
- package/dist/sbwb-ds.umd.cjs +6 -7
- package/dist/src/data/mocks/mock-data.d.ts +6 -0
- package/dist/src/presentation/components/atoms/Tree/index.d.ts +11 -0
- package/dist/src/presentation/components/atoms/Tree/index.spec.d.ts +1 -0
- package/dist/src/presentation/components/atoms/Tree/styles.d.ts +6 -0
- package/package.json +1 -1
- package/src/data/mocks/mock-data.ts +31 -0
- package/src/presentation/components/atoms/Select/styles.ts +0 -2
- package/src/presentation/components/atoms/Tree/Tree.stories.tsx +31 -0
- package/src/presentation/components/atoms/Tree/index.spec.tsx +71 -0
- package/src/presentation/components/atoms/Tree/index.tsx +62 -0
- package/src/presentation/components/atoms/Tree/styles.ts +42 -0
- package/src/presentation/components/molecules/TabBar/styles.ts +2 -3
- package/src/presentation/components/molecules/Table/index.tsx +4 -2
- package/src/presentation/components/molecules/Table/styles.ts +3 -1
package/dist/sbwb-ds.js
CHANGED
|
@@ -3502,8 +3502,6 @@ const HO = X.div`
|
|
|
3502
3502
|
width: fit-content;
|
|
3503
3503
|
}
|
|
3504
3504
|
`, eV = X.span`
|
|
3505
|
-
display: flex;
|
|
3506
|
-
flex-wrap: wrap;
|
|
3507
3505
|
color: ${({ error: r }) => r ? S.colors.feedbackColors.colorFeedbackError : S.colors.neutralColors.colorNeutralCloudy};
|
|
3508
3506
|
font-size: ${({ size: r }) => r === "Small" ? S.fonts.fontSize.fontSizeBodyMd : S.fonts.fontSize.fontSizeBodyLg};
|
|
3509
3507
|
font-family: ${S.fonts.fontFamily.fontFamilyPrimary};
|
|
@@ -58832,6 +58830,7 @@ const Uve = X.aside`
|
|
|
58832
58830
|
overflow-x: hidden;
|
|
58833
58831
|
}
|
|
58834
58832
|
& > svg {
|
|
58833
|
+
flex-shrink: 0;
|
|
58835
58834
|
height: ${({ size: r }) => r === "Small" ? S.icons.iconSizeSm : S.icons.iconSizeAnt};
|
|
58836
58835
|
width: ${({ size: r }) => r === "Small" ? S.icons.iconSizeSm : S.icons.iconSizeAnt};
|
|
58837
58836
|
}
|
|
@@ -58861,9 +58860,7 @@ const Uve = X.aside`
|
|
|
58861
58860
|
`, t2e = X.div`
|
|
58862
58861
|
flex: 1;
|
|
58863
58862
|
height: ${({ size: r }) => r === "Small" ? "32px" : "40px"};
|
|
58864
|
-
${({ direction: r }) => r === "horizontal" ? fe`
|
|
58865
|
-
border-bottom: 1px solid ${S.colors.neutralColors.colorNeutralSoft};
|
|
58866
|
-
` : fe`
|
|
58863
|
+
${({ direction: r }) => r === "horizontal" ? fe`` : fe`
|
|
58867
58864
|
border-left: 1px solid ${S.colors.neutralColors.colorNeutralSoft};
|
|
58868
58865
|
`};
|
|
58869
58866
|
`, r2e = X.div`
|
|
@@ -59025,7 +59022,9 @@ const Uve = X.aside`
|
|
|
59025
59022
|
justify-content: ${({ isComponentRendered: r }) => r && "center"};
|
|
59026
59023
|
width: 100%;
|
|
59027
59024
|
max-width: ${({ maxWidth: r }) => r};
|
|
59028
|
-
height:
|
|
59025
|
+
height: auto;
|
|
59026
|
+
min-height: ${({ size: r }) => r === "Large" ? "4rem" : "3.2rem"};
|
|
59027
|
+
|
|
59029
59028
|
padding: ${({ hasSubText: r, size: t, isComponentRendered: e }) => t === "Large" ? r || e ? `${e ? "0" : "0.2rem"} ${S.spacings.spacingInline.spacingInlineAnt}` : S.spacings.spacingInset.spacingInsetXs : r ? `0.2rem ${S.spacings.spacingInline.spacingInlineXs}` : S.spacings.spacingInset.spacingInsetNano};
|
|
59030
59029
|
|
|
59031
59030
|
font-family: ${S.fonts.fontFamily.fontFamilyPrimary};
|
|
@@ -59245,8 +59244,8 @@ const Uve = X.aside`
|
|
|
59245
59244
|
maxWidth: b.maxWidth,
|
|
59246
59245
|
size: e,
|
|
59247
59246
|
children: T != null && T.value ? /* @__PURE__ */ xe(qu, { children: [
|
|
59248
|
-
/* @__PURE__ */ H("p", { children: T == null ? void 0 : T.value }),
|
|
59249
|
-
(T == null ? void 0 : T.subText) && /* @__PURE__ */ H("p", { children: T == null ? void 0 : T.subText })
|
|
59247
|
+
/* @__PURE__ */ H("p", { title: T == null ? void 0 : T.value, children: T == null ? void 0 : T.value }),
|
|
59248
|
+
(T == null ? void 0 : T.subText) && /* @__PURE__ */ H("p", { title: T == null ? void 0 : T.subText, children: T == null ? void 0 : T.subText })
|
|
59250
59249
|
] }) : T
|
|
59251
59250
|
},
|
|
59252
59251
|
`${m}-${_}`
|
package/dist/sbwb-ds.umd.cjs
CHANGED
|
@@ -662,8 +662,6 @@ See https://s-c.sh/2BAXzed for more info.`),window["__styled-components-init__"]
|
|
|
662
662
|
width: fit-content;
|
|
663
663
|
}
|
|
664
664
|
`,gI=j.span`
|
|
665
|
-
display: flex;
|
|
666
|
-
flex-wrap: wrap;
|
|
667
665
|
color: ${({error:r})=>r?S.colors.feedbackColors.colorFeedbackError:S.colors.neutralColors.colorNeutralCloudy};
|
|
668
666
|
font-size: ${({size:r})=>r==="Small"?S.fonts.fontSize.fontSizeBodyMd:S.fonts.fontSize.fontSizeBodyLg};
|
|
669
667
|
font-family: ${S.fonts.fontFamily.fontFamilyPrimary};
|
|
@@ -2457,6 +2455,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
2457
2455
|
overflow-x: hidden;
|
|
2458
2456
|
}
|
|
2459
2457
|
& > svg {
|
|
2458
|
+
flex-shrink: 0;
|
|
2460
2459
|
height: ${({size:r})=>r==="Small"?S.icons.iconSizeSm:S.icons.iconSizeAnt};
|
|
2461
2460
|
width: ${({size:r})=>r==="Small"?S.icons.iconSizeSm:S.icons.iconSizeAnt};
|
|
2462
2461
|
}
|
|
@@ -2479,9 +2478,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
2479
2478
|
`,Ife=j.div`
|
|
2480
2479
|
flex: 1;
|
|
2481
2480
|
height: ${({size:r})=>r==="Small"?"32px":"40px"};
|
|
2482
|
-
${({direction:r})=>r==="horizontal"?fe`
|
|
2483
|
-
border-bottom: 1px solid ${S.colors.neutralColors.colorNeutralSoft};
|
|
2484
|
-
`:fe`
|
|
2481
|
+
${({direction:r})=>r==="horizontal"?fe``:fe`
|
|
2485
2482
|
border-left: 1px solid ${S.colors.neutralColors.colorNeutralSoft};
|
|
2486
2483
|
`};
|
|
2487
2484
|
`,Pfe=j.div`
|
|
@@ -2598,7 +2595,9 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
2598
2595
|
justify-content: ${({isComponentRendered:r})=>r&&"center"};
|
|
2599
2596
|
width: 100%;
|
|
2600
2597
|
max-width: ${({maxWidth:r})=>r};
|
|
2601
|
-
height:
|
|
2598
|
+
height: auto;
|
|
2599
|
+
min-height: ${({size:r})=>r==="Large"?"4rem":"3.2rem"};
|
|
2600
|
+
|
|
2602
2601
|
padding: ${({hasSubText:r,size:t,isComponentRendered:e})=>t==="Large"?r||e?`${e?"0":"0.2rem"} ${S.spacings.spacingInline.spacingInlineAnt}`:S.spacings.spacingInset.spacingInsetXs:r?`0.2rem ${S.spacings.spacingInline.spacingInlineXs}`:S.spacings.spacingInset.spacingInsetNano};
|
|
2603
2602
|
|
|
2604
2603
|
font-family: ${S.fonts.fontFamily.fontFamilyPrimary};
|
|
@@ -2655,4 +2654,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
2655
2654
|
background-color: ${S.colors.backgroundColors.colorBackgroundCarpet};
|
|
2656
2655
|
cursor: pointer;
|
|
2657
2656
|
}
|
|
2658
|
-
`,wA=R.createContext(void 0),Wfe=({children:r})=>{const[t,e]=R.useState({}),n=R.useMemo(()=>({selectedCheckboxes:t,setSelectedCheckboxes:e}),[t]);return W(wA.Provider,{value:n,children:r})},SA=()=>{const r=R.useContext(wA);if(!r)throw new Error("You cannot access this context outside a provider");return r},Gfe=(r,t)=>{const{selectedCheckboxes:e,setSelectedCheckboxes:n}=SA();R.useEffect(()=>(n(Object.fromEntries(r.map((M,D)=>[D,!1]))),()=>{n({})}),[]);const[a,i]=R.useState(""),[o,s]=R.useState(),[l,u]=R.useState(r),[c,f]=R.useState(!1),[h,d]=R.useState(null),v=R.useMemo(()=>t.filter(M=>!M.isHidden),[t]),p=(M,D)=>{const T=[...l].sort((E,k)=>E.rowData[M].content.toString().localeCompare(k.rowData[M].content.toString(),"en",{numeric:!0})*(D==="asc"?1:-1));u(T),n(Object.fromEntries(r.map((E,k)=>[k,!1]))),f(!1)},g=M=>{const D=M===a&&o==="asc"?"desc":"asc";i(M),s(D),p(M,D)},m=M=>{f(M),n(Object.fromEntries(r.map((D,T)=>[T,M])))},y=M=>{n(D=>({...D,[M]:!D[M]})),c&&f(!1)};function C(M,D){return M.split(".").reduce((T,E)=>T&&T[E],D)}const w=ze.ExpandLessSm,b=ze.ExpandMoreSm,_=ze.UnfoldMoreSm;return{selectedCheckboxes:e,filteredColumns:v,checkedAllCell:c,order:o,dataTable:l,handleSortingChange:g,toggleAllCheckbox:m,toggleCheckbox:y,getValueFromKeyPath:C,getIcon:()=>o?o==="asc"?W(b,{}):W(w,{}):W(_,{}),setHoverRow:d,hoverRow:h}},Zfe=({rows:r,columns:t,size:e="Large",maxHeight:n="40rem",withCheckbox:a=!1})=>{const{selectedCheckboxes:i,filteredColumns:o,checkedAllCell:s,dataTable:l,handleSortingChange:u,toggleAllCheckbox:c,toggleCheckbox:f,getValueFromKeyPath:h,getIcon:d,setHoverRow:v,hoverRow:p}=Gfe(r,t);return W($fe,{maxHeight:n,children:W(Vfe,{items:o.length,"data-testid":"table-component",children:xe("tbody",{children:[W(CA,{topBorderRadius:!0,isHeader:!0,children:o.map((g,m)=>xe(ru,{children:[m===0&&a&&W(Ffe,{onClick:()=>c(!s),size:e,children:W(qh,{name:"allCheck",id:"allcheck","data-testid":"allcheck",size:e==="Large"?"Medium":"Small",checked:s,onChange:y=>c(!y.target.checked)})},`${m}-check`),xe(Bfe,{onClick:()=>(g==null?void 0:g.sortable)&&u(g.path),isSortable:g==null?void 0:g.sortable,maxWidth:g.maxWidth,size:e,children:[W("p",{children:g.label}),W("span",{children:(g==null?void 0:g.sortable)&&d()})]},`${m}-${g.path}`)]}))}),l==null?void 0:l.map((g,m)=>{const{rowData:y,params:C={}}=g,{onClick:w=()=>null}=C;return W(CA,{BottomBorderRadius:l.length-1===m,onClick:()=>w(y),onMouseEnter:()=>v(m),onMouseLeave:()=>v(null),children:o.map((b,_)=>{const x=h(b.path,y),M=typeof(x==null?void 0:x.content)!="object"?x.content:" ",D=typeof(x==null?void 0:x.subText)!="object"?x.subText:" ",T=b!=null&&b.content?b.content(y):{value:M!==""?M:" ",subText:D};return xe(ru,{children:[_===0&&a&&W(zfe,{selected:i[m],isHover:p===m,onClick:()=>f(m),size:e,children:W(qh,{id:`${m}`,"data-testid":`${m}-check`,size:e==="Large"?"Medium":"Small",checked:i[m],onChange:()=>f(m)})},`${m}-check`),W(Hfe,{selected:i[m],isHover:p===m,hasSubText:!!T.subText,isComponentRendered:!(T!=null&&T.value),maxWidth:b.maxWidth,size:e,children:T!=null&&T.value?xe(ru,{children:[W("p",{children:T==null?void 0:T.value}),(T==null?void 0:T.subText)&&W("p",{children:T==null?void 0:T.subText})]}):T},`${m}-${_}`)]})})},m)})]})})})};Ze.Accordion=Ok,Ze.ActionButton=iu,Ze.Actions=Fk,Ze.Autocomplete=J4,Ze.BackgroundSection=_I,Ze.Breadcrumb=lP,Ze.Button=eo,Ze.ChartPie=Vae,Ze.Checkbox=qh,Ze.Column=Gae,Ze.Container=Yae,Ze.DatePicker=yA,Ze.Divider=Doe,Ze.GridArea=jae,Ze.Icon=Kae,Ze.Input=L5,Ze.ItemList=lie,Ze.MenuSelect=Ec,Ze.Modal=Tie,Ze.Pagination=Iie,Ze.Radio=kL,Ze.Row=Vie,Ze.Select=Xd,Ze.Sidebar=Efe,Ze.SkeletonLoading=Hie,Ze.Status=Wie,Ze.Stepper=jie,Ze.Switch=toe,Ze.TabBar=Rfe,Ze.Table=Zfe,Ze.TableProvider=Wfe,Ze.Tag=ioe,Ze.Textarea=NL,Ze.TokenArea=woe,Ze.Tooltip=boe,Ze.useTableContext=SA,Object.defineProperty(Ze,Symbol.toStringTag,{value:"Module"})});
|
|
2657
|
+
`,wA=R.createContext(void 0),Wfe=({children:r})=>{const[t,e]=R.useState({}),n=R.useMemo(()=>({selectedCheckboxes:t,setSelectedCheckboxes:e}),[t]);return W(wA.Provider,{value:n,children:r})},SA=()=>{const r=R.useContext(wA);if(!r)throw new Error("You cannot access this context outside a provider");return r},Gfe=(r,t)=>{const{selectedCheckboxes:e,setSelectedCheckboxes:n}=SA();R.useEffect(()=>(n(Object.fromEntries(r.map((M,D)=>[D,!1]))),()=>{n({})}),[]);const[a,i]=R.useState(""),[o,s]=R.useState(),[l,u]=R.useState(r),[c,f]=R.useState(!1),[h,d]=R.useState(null),v=R.useMemo(()=>t.filter(M=>!M.isHidden),[t]),p=(M,D)=>{const T=[...l].sort((E,k)=>E.rowData[M].content.toString().localeCompare(k.rowData[M].content.toString(),"en",{numeric:!0})*(D==="asc"?1:-1));u(T),n(Object.fromEntries(r.map((E,k)=>[k,!1]))),f(!1)},g=M=>{const D=M===a&&o==="asc"?"desc":"asc";i(M),s(D),p(M,D)},m=M=>{f(M),n(Object.fromEntries(r.map((D,T)=>[T,M])))},y=M=>{n(D=>({...D,[M]:!D[M]})),c&&f(!1)};function C(M,D){return M.split(".").reduce((T,E)=>T&&T[E],D)}const w=ze.ExpandLessSm,b=ze.ExpandMoreSm,_=ze.UnfoldMoreSm;return{selectedCheckboxes:e,filteredColumns:v,checkedAllCell:c,order:o,dataTable:l,handleSortingChange:g,toggleAllCheckbox:m,toggleCheckbox:y,getValueFromKeyPath:C,getIcon:()=>o?o==="asc"?W(b,{}):W(w,{}):W(_,{}),setHoverRow:d,hoverRow:h}},Zfe=({rows:r,columns:t,size:e="Large",maxHeight:n="40rem",withCheckbox:a=!1})=>{const{selectedCheckboxes:i,filteredColumns:o,checkedAllCell:s,dataTable:l,handleSortingChange:u,toggleAllCheckbox:c,toggleCheckbox:f,getValueFromKeyPath:h,getIcon:d,setHoverRow:v,hoverRow:p}=Gfe(r,t);return W($fe,{maxHeight:n,children:W(Vfe,{items:o.length,"data-testid":"table-component",children:xe("tbody",{children:[W(CA,{topBorderRadius:!0,isHeader:!0,children:o.map((g,m)=>xe(ru,{children:[m===0&&a&&W(Ffe,{onClick:()=>c(!s),size:e,children:W(qh,{name:"allCheck",id:"allcheck","data-testid":"allcheck",size:e==="Large"?"Medium":"Small",checked:s,onChange:y=>c(!y.target.checked)})},`${m}-check`),xe(Bfe,{onClick:()=>(g==null?void 0:g.sortable)&&u(g.path),isSortable:g==null?void 0:g.sortable,maxWidth:g.maxWidth,size:e,children:[W("p",{children:g.label}),W("span",{children:(g==null?void 0:g.sortable)&&d()})]},`${m}-${g.path}`)]}))}),l==null?void 0:l.map((g,m)=>{const{rowData:y,params:C={}}=g,{onClick:w=()=>null}=C;return W(CA,{BottomBorderRadius:l.length-1===m,onClick:()=>w(y),onMouseEnter:()=>v(m),onMouseLeave:()=>v(null),children:o.map((b,_)=>{const x=h(b.path,y),M=typeof(x==null?void 0:x.content)!="object"?x.content:" ",D=typeof(x==null?void 0:x.subText)!="object"?x.subText:" ",T=b!=null&&b.content?b.content(y):{value:M!==""?M:" ",subText:D};return xe(ru,{children:[_===0&&a&&W(zfe,{selected:i[m],isHover:p===m,onClick:()=>f(m),size:e,children:W(qh,{id:`${m}`,"data-testid":`${m}-check`,size:e==="Large"?"Medium":"Small",checked:i[m],onChange:()=>f(m)})},`${m}-check`),W(Hfe,{selected:i[m],isHover:p===m,hasSubText:!!T.subText,isComponentRendered:!(T!=null&&T.value),maxWidth:b.maxWidth,size:e,children:T!=null&&T.value?xe(ru,{children:[W("p",{title:T==null?void 0:T.value,children:T==null?void 0:T.value}),(T==null?void 0:T.subText)&&W("p",{title:T==null?void 0:T.subText,children:T==null?void 0:T.subText})]}):T},`${m}-${_}`)]})})},m)})]})})})};Ze.Accordion=Ok,Ze.ActionButton=iu,Ze.Actions=Fk,Ze.Autocomplete=J4,Ze.BackgroundSection=_I,Ze.Breadcrumb=lP,Ze.Button=eo,Ze.ChartPie=Vae,Ze.Checkbox=qh,Ze.Column=Gae,Ze.Container=Yae,Ze.DatePicker=yA,Ze.Divider=Doe,Ze.GridArea=jae,Ze.Icon=Kae,Ze.Input=L5,Ze.ItemList=lie,Ze.MenuSelect=Ec,Ze.Modal=Tie,Ze.Pagination=Iie,Ze.Radio=kL,Ze.Row=Vie,Ze.Select=Xd,Ze.Sidebar=Efe,Ze.SkeletonLoading=Hie,Ze.Status=Wie,Ze.Stepper=jie,Ze.Switch=toe,Ze.TabBar=Rfe,Ze.Table=Zfe,Ze.TableProvider=Wfe,Ze.Tag=ioe,Ze.Textarea=NL,Ze.TokenArea=woe,Ze.Tooltip=boe,Ze.useTableContext=SA,Object.defineProperty(Ze,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TreeItem } from 'data/mocks/mock-data';
|
|
3
|
+
interface Props {
|
|
4
|
+
title: string;
|
|
5
|
+
content: string;
|
|
6
|
+
children?: TreeItem[];
|
|
7
|
+
onClickTitle: (titulo: string) => void;
|
|
8
|
+
onClickContent: (content: string) => void;
|
|
9
|
+
}
|
|
10
|
+
declare const Tree: React.FC<Props>;
|
|
11
|
+
export default Tree;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom/extend-expect';
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface TreeItem {
|
|
2
|
+
code: string;
|
|
3
|
+
content: string;
|
|
4
|
+
children?: TreeItem[];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const generateRandomItem = (depth: number): TreeItem => {
|
|
8
|
+
const code = `Código (P-${Math.floor(Math.random() * 100)})`;
|
|
9
|
+
const content = 'Balcão de Riser';
|
|
10
|
+
|
|
11
|
+
const item: TreeItem = {
|
|
12
|
+
code,
|
|
13
|
+
content,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
if (depth > 1 && Math.random() > 0.5) {
|
|
17
|
+
const numChildren = Math.floor(Math.random() * 3) + 1;
|
|
18
|
+
item.children = [];
|
|
19
|
+
for (let i = 1; i <= numChildren; i++) {
|
|
20
|
+
item.children.push(generateRandomItem(depth - 1));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return item;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const mockData: TreeItem[] = [];
|
|
27
|
+
|
|
28
|
+
for (let i = 1; i <= 5; i++) {
|
|
29
|
+
// Altere o valor de i para gerar mais itens
|
|
30
|
+
mockData.push(generateRandomItem(5));
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Tree from './';
|
|
3
|
+
import { mockData } from '../../../../data/mocks/mock-data';
|
|
4
|
+
|
|
5
|
+
interface TreeProps {
|
|
6
|
+
title: string;
|
|
7
|
+
content: string;
|
|
8
|
+
children?: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
title: 'Components/Tree',
|
|
13
|
+
component: Tree,
|
|
14
|
+
args: {
|
|
15
|
+
title: 'Sample Title',
|
|
16
|
+
content: 'Sample Content',
|
|
17
|
+
children: [],
|
|
18
|
+
},
|
|
19
|
+
tags: ['autodocs'],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const Template = (args: TreeProps) => <Tree {...args} />;
|
|
23
|
+
|
|
24
|
+
export const Default = Template.bind({});
|
|
25
|
+
|
|
26
|
+
Default.args = {
|
|
27
|
+
title: mockData[0]?.code,
|
|
28
|
+
content: mockData[0]?.content,
|
|
29
|
+
onClickContent: () => {},
|
|
30
|
+
onClickTitle: () => {},
|
|
31
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
2
|
+
import Tree from './';
|
|
3
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
4
|
+
|
|
5
|
+
describe('<Tree />', () => {
|
|
6
|
+
const mockData = {
|
|
7
|
+
title: 'TestTitle',
|
|
8
|
+
content: 'TestContent',
|
|
9
|
+
children: [
|
|
10
|
+
{
|
|
11
|
+
code: 'Child1',
|
|
12
|
+
content: 'ChildContent1',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
code: 'Child2',
|
|
16
|
+
content: 'ChildContent2',
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
it('renders correctly', () => {
|
|
22
|
+
const { getByText } = render(
|
|
23
|
+
<Tree
|
|
24
|
+
title={mockData.title}
|
|
25
|
+
content={mockData.content}
|
|
26
|
+
onClickTitle={() => {}}
|
|
27
|
+
onClickContent={() => {}}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
expect(getByText(mockData.title)).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('calls onClickTitle and onClickContent correctly', () => {
|
|
34
|
+
const onClickTitleMock = jest.fn();
|
|
35
|
+
const onClickContentMock = jest.fn();
|
|
36
|
+
|
|
37
|
+
const { getByText } = render(
|
|
38
|
+
<Tree
|
|
39
|
+
title={mockData.title}
|
|
40
|
+
content={mockData.content}
|
|
41
|
+
onClickTitle={onClickTitleMock}
|
|
42
|
+
onClickContent={onClickContentMock}
|
|
43
|
+
/>
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
fireEvent.click(getByText(mockData.title));
|
|
47
|
+
expect(onClickTitleMock).toHaveBeenCalledWith(mockData.title);
|
|
48
|
+
|
|
49
|
+
fireEvent.click(getByText(mockData.content));
|
|
50
|
+
expect(onClickContentMock).toHaveBeenCalledWith(mockData.content);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('shows children correctly when header is clicked', () => {
|
|
54
|
+
const { getByText, queryByText } = render(
|
|
55
|
+
<Tree
|
|
56
|
+
title={mockData.title}
|
|
57
|
+
content={mockData.content}
|
|
58
|
+
children={mockData.children}
|
|
59
|
+
onClickTitle={() => {}}
|
|
60
|
+
onClickContent={() => {}}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(queryByText(mockData.children[0].code)).toBeNull();
|
|
65
|
+
|
|
66
|
+
fireEvent.click(getByText(mockData.title));
|
|
67
|
+
|
|
68
|
+
expect(getByText(mockData.children[0].code)).toBeInTheDocument();
|
|
69
|
+
expect(getByText(mockData.children[1].code)).toBeInTheDocument();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import * as C from './styles';
|
|
3
|
+
import Icon from '../Icon';
|
|
4
|
+
import { TreeItem } from 'data/mocks/mock-data';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
title: string;
|
|
8
|
+
content: string;
|
|
9
|
+
children?: TreeItem[];
|
|
10
|
+
onClickTitle: (titulo: string) => void;
|
|
11
|
+
onClickContent: (content: string) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Tree: React.FC<Props> = ({
|
|
15
|
+
title,
|
|
16
|
+
content,
|
|
17
|
+
children,
|
|
18
|
+
onClickTitle,
|
|
19
|
+
onClickContent,
|
|
20
|
+
}) => {
|
|
21
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<C.TreeWrapper>
|
|
25
|
+
<C.Header onClick={() => setIsOpen(!isOpen)}>
|
|
26
|
+
<Icon
|
|
27
|
+
iconName={isOpen ? 'DoNotDisturbOnSm' : 'AddCircleSm'}
|
|
28
|
+
width="16px"
|
|
29
|
+
height="16px"
|
|
30
|
+
/>
|
|
31
|
+
<C.Title onClick={() => onClickTitle(title)}>{title}</C.Title>
|
|
32
|
+
</C.Header>
|
|
33
|
+
{isOpen && (
|
|
34
|
+
<C.Content>
|
|
35
|
+
<C.TreeItem>
|
|
36
|
+
<Icon
|
|
37
|
+
iconName="FiberManualRecordFill1Sm"
|
|
38
|
+
color="#4E5666"
|
|
39
|
+
width="16px"
|
|
40
|
+
height="16px"
|
|
41
|
+
/>
|
|
42
|
+
<C.TreeItemTitle onClick={() => onClickContent(content)}>
|
|
43
|
+
{content}
|
|
44
|
+
</C.TreeItemTitle>
|
|
45
|
+
</C.TreeItem>
|
|
46
|
+
{children?.map((item, index) => (
|
|
47
|
+
<Tree
|
|
48
|
+
key={index}
|
|
49
|
+
title={item.code}
|
|
50
|
+
content={item.content}
|
|
51
|
+
children={item.children}
|
|
52
|
+
onClickTitle={onClickTitle}
|
|
53
|
+
onClickContent={onClickContent}
|
|
54
|
+
/>
|
|
55
|
+
))}
|
|
56
|
+
</C.Content>
|
|
57
|
+
)}
|
|
58
|
+
</C.TreeWrapper>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default Tree;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
|
|
3
|
+
export const TreeWrapper = styled.div`
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
align-items: flex-start;
|
|
7
|
+
margin-top: 8px;
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
export const Header = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: flex-start;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
export const Content = styled.div`
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-direction: column;
|
|
20
|
+
padding-left: 16px;
|
|
21
|
+
border-top: none;
|
|
22
|
+
background-color: #fff;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const Title = styled.h5`
|
|
27
|
+
font-size: 10px;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
color: #4e5666;
|
|
30
|
+
margin-left: 8px;
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export const TreeItem = styled.div`
|
|
34
|
+
display: flex;
|
|
35
|
+
align-items: center;
|
|
36
|
+
cursor: pointer;
|
|
37
|
+
margin-top: 8px;
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
export const TreeItemTitle = styled.p`
|
|
41
|
+
margin-left: 8px;
|
|
42
|
+
`;
|
|
@@ -67,6 +67,7 @@ export const TabHeader = styled.div<{
|
|
|
67
67
|
overflow-x: hidden;
|
|
68
68
|
}
|
|
69
69
|
& > svg {
|
|
70
|
+
flex-shrink: 0;
|
|
70
71
|
height: ${({ size }) =>
|
|
71
72
|
size === 'Small' ? sg.icons.iconSizeSm : sg.icons.iconSizeAnt};
|
|
72
73
|
width: ${({ size }) =>
|
|
@@ -107,9 +108,7 @@ export const EmptySpace = styled.div`
|
|
|
107
108
|
height: ${({ size }) => (size === 'Small' ? '32px' : '40px')};
|
|
108
109
|
${({ direction }) =>
|
|
109
110
|
direction === 'horizontal'
|
|
110
|
-
? css
|
|
111
|
-
border-bottom: 1px solid ${sg.colors.neutralColors.colorNeutralSoft};
|
|
112
|
-
`
|
|
111
|
+
? css``
|
|
113
112
|
: css`
|
|
114
113
|
border-left: 1px solid ${sg.colors.neutralColors.colorNeutralSoft};
|
|
115
114
|
`};
|
|
@@ -141,9 +141,11 @@ const Table: React.FC<TableProps> = ({
|
|
|
141
141
|
renderData
|
|
142
142
|
) : (
|
|
143
143
|
<>
|
|
144
|
-
<p>{renderData?.value}</p>
|
|
144
|
+
<p title={renderData?.value}>{renderData?.value}</p>
|
|
145
145
|
{renderData?.subText && (
|
|
146
|
-
<p
|
|
146
|
+
<p title={renderData?.subText}>
|
|
147
|
+
{renderData?.subText}
|
|
148
|
+
</p>
|
|
147
149
|
)}
|
|
148
150
|
</>
|
|
149
151
|
)}
|
|
@@ -137,7 +137,9 @@ export const DynamicTableTd = styled.td<{ DynamicTableProps }>`
|
|
|
137
137
|
isComponentRendered && 'center'};
|
|
138
138
|
width: 100%;
|
|
139
139
|
max-width: ${({ maxWidth }) => maxWidth};
|
|
140
|
-
height:
|
|
140
|
+
height: auto;
|
|
141
|
+
min-height: ${({ size }) => (size === 'Large' ? '4rem' : '3.2rem')};
|
|
142
|
+
|
|
141
143
|
padding: ${({ hasSubText, size, isComponentRendered }) => {
|
|
142
144
|
if (size === 'Large') {
|
|
143
145
|
return hasSubText || isComponentRendered
|