@channel.io/bezier-react 3.3.1 → 3.4.1
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/cjs/components/SegmentedControl/SegmentedControl.js +15 -4
- package/dist/cjs/components/SegmentedControl/SegmentedControl.js.map +1 -1
- package/dist/cjs/components/SegmentedControl/SegmentedControl.module.scss.js +1 -1
- package/dist/cjs/components/Tabs/Tabs.js +57 -12
- package/dist/cjs/components/Tabs/Tabs.js.map +1 -1
- package/dist/cjs/components/Tabs/Tabs.module.scss.js +1 -1
- package/dist/cjs/hooks/useElementTruncated.js +28 -0
- package/dist/cjs/hooks/useElementTruncated.js.map +1 -0
- package/dist/cjs/styles.css +1 -1
- package/dist/esm/components/SegmentedControl/SegmentedControl.mjs +15 -4
- package/dist/esm/components/SegmentedControl/SegmentedControl.mjs.map +1 -1
- package/dist/esm/components/SegmentedControl/SegmentedControl.module.scss.mjs +1 -1
- package/dist/esm/components/Tabs/Tabs.mjs +60 -15
- package/dist/esm/components/Tabs/Tabs.mjs.map +1 -1
- package/dist/esm/components/Tabs/Tabs.module.scss.mjs +1 -1
- package/dist/esm/hooks/useElementTruncated.mjs +24 -0
- package/dist/esm/hooks/useElementTruncated.mjs.map +1 -0
- package/dist/esm/styles.css +1 -1
- package/dist/types/components/Button/Button.types.d.ts +1 -1
- package/dist/types/components/Button/Button.types.d.ts.map +1 -1
- package/dist/types/components/SegmentedControl/SegmentedControl.d.ts.map +1 -1
- package/dist/types/components/Tabs/Tabs.d.ts.map +1 -1
- package/dist/types/components/Tabs/Tabs.types.d.ts +2 -0
- package/dist/types/components/Tabs/Tabs.types.d.ts.map +1 -1
- package/dist/types/hooks/useElementTruncated.d.ts +4 -0
- package/dist/types/hooks/useElementTruncated.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/Button/Button.types.ts +1 -1
- package/src/components/SegmentedControl/SegmentedControl.module.scss +9 -0
- package/src/components/SegmentedControl/SegmentedControl.tsx +26 -3
- package/src/components/Tabs/Tabs.module.scss +61 -1
- package/src/components/Tabs/Tabs.stories.tsx +7 -2
- package/src/components/Tabs/Tabs.tsx +65 -13
- package/src/components/Tabs/Tabs.types.ts +2 -0
- package/src/hooks/useElementTruncated.ts +36 -0
|
@@ -46,7 +46,7 @@ interface ButtonOwnProps {
|
|
|
46
46
|
*/
|
|
47
47
|
colorVariant?: ButtonColorVariant;
|
|
48
48
|
}
|
|
49
|
-
export interface ButtonProps extends BezierComponentProps<'button'>, PolymorphicProps, SizeProps<ButtonSize>, DisableProps, SideContentProps<SideContent, SideContent>, ButtonOwnProps {
|
|
49
|
+
export interface ButtonProps extends Omit<BezierComponentProps<'button'>, 'children'>, PolymorphicProps, SizeProps<ButtonSize>, DisableProps, SideContentProps<SideContent, SideContent>, ButtonOwnProps {
|
|
50
50
|
}
|
|
51
51
|
export {};
|
|
52
52
|
//# sourceMappingURL=Button.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.types.d.ts","sourceRoot":"","sources":["../../../../src/components/Button/Button.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACf,0BAAyB;AAE1B,MAAM,MAAM,kBAAkB,GAC1B,SAAS,GACT,WAAW,GACX,UAAU,GACV,UAAU,GACV,cAAc,CAAA;AAElB,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,KAAK,GACL,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ;AACV;;GAEG;GACD,YAAY,GACZ,kBAAkB,GAClB,iBAAiB,CAAA;AAErB,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAA;AAEtD,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,GAAG,UAAU,CAAA;AAEtD,UAAU,cAAc;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA;IAEpC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAA;IAEjC;;;OAGG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAA;CAClC;AAED,MAAM,WAAW,WACf,SAAQ,oBAAoB,CAAC,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"Button.types.d.ts","sourceRoot":"","sources":["../../../../src/components/Button/Button.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACf,0BAAyB;AAE1B,MAAM,MAAM,kBAAkB,GAC1B,SAAS,GACT,WAAW,GACX,UAAU,GACV,UAAU,GACV,cAAc,CAAA;AAElB,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,KAAK,GACL,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ;AACV;;GAEG;GACD,YAAY,GACZ,kBAAkB,GAClB,iBAAiB,CAAA;AAErB,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAA;AAEtD,MAAM,MAAM,WAAW,GAAG,KAAK,CAAC,SAAS,GAAG,UAAU,CAAA;AAEtD,UAAU,cAAc;IACtB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA;IAEpC;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAA;IAEjC;;;OAGG;IACH,YAAY,CAAC,EAAE,kBAAkB,CAAA;CAClC;AAED,MAAM,WAAW,WACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,EACtD,gBAAgB,EAChB,SAAS,CAAC,UAAU,CAAC,EACrB,YAAY,EACZ,gBAAgB,CAAC,WAAW,EAAE,WAAW,CAAC,EAC1C,cAAc;CAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../../../src/components/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,GAAG,EAKT,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAkB9B,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAG1B,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EAEjC,KAAK,oBAAoB,EAC1B,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"SegmentedControl.d.ts","sourceRoot":"","sources":["../../../../src/components/SegmentedControl/SegmentedControl.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,GAAG,EAKT,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAkB9B,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,qBAAqB,EAG1B,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EAEjC,KAAK,oBAAoB,EAC1B,MAAM,0BAA0B,CAAA;AAoKjC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,EAA+B,CACjE,KAAK,EAAE,4BAA4B,GAAG;IACpC,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;CACzC,KACE,GAAG,CAAC,OAAO,CAAA;AAEhB;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,EAA4B,CACjE,KAAK,SAAS,MAAM,EAEpB,KAAK,EAAE,+BAA+B,CAAC,KAAK,CAAC,GAAG;IAC9C,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;CACzC,KACE,GAAG,CAAC,OAAO,CAAA;AA+ChB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,gBAAgB,EAAuC,CAClE,IAAI,SAAS,oBAAoB,EACjC,KAAK,SAAS,MAAM,EAEpB,KAAK,EAAE,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG;IAC1C,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,CAAA;CACzC,KACE,GAAG,CAAC,OAAO,CAAA;AAgGhB;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,EAA2C,CAC1E,KAAK,SAAS,MAAM,EAEpB,KAAK,EAAE,yBAAyB,CAAC,KAAK,CAAC,GAAG;IACxC,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAA;CAC5C,KACE,GAAG,CAAC,OAAO,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../../../src/components/Tabs/Tabs.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"Tabs.d.ts","sourceRoot":"","sources":["../../../../src/components/Tabs/Tabs.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,GAAG,EAA+B,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAa9B,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,aAAa,EAElB,KAAK,YAAY,EAEjB,KAAK,SAAS,EACf,qBAAwC;AAMzC;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,IAAI,kFAef,CAAA;AAOF;;GAEG;AACH,eAAO,MAAM,OAAO,qFAyBnB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,sFAYpB,CAAA;AAgED;;GAEG;AACH,eAAO,MAAM,OAAO,wFA6BnB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,wFAYtB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,wFActB,CAAA;AAsBD;;;GAGG;AACH,eAAO,MAAM,SAAS,EAsDhB,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS,EACpC,KAAK,EAAE,cAAc,CAAC,IAAI,CAAC,GAAG;IAC5B,GAAG,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAA;CACjD,KACE,GAAG,CAAC,OAAO,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
+
import { type CSSProperties } from 'react';
|
|
2
3
|
import { type BezierComponentProps, type ChildrenProps, type DisableProps, type SizeProps } from "../../types/props";
|
|
3
4
|
export type TabSize = 'l' | 'm' | 's';
|
|
4
5
|
export interface TabListContextValue {
|
|
@@ -39,6 +40,7 @@ interface TabItemOwnProps {
|
|
|
39
40
|
* A unique value that associates the trigger with a content.
|
|
40
41
|
*/
|
|
41
42
|
value: string;
|
|
43
|
+
maxWidth?: CSSProperties['maxWidth'];
|
|
42
44
|
}
|
|
43
45
|
interface TabContentOwnProps {
|
|
44
46
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.types.d.ts","sourceRoot":"","sources":["../../../../src/components/Tabs/Tabs.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"Tabs.types.d.ts","sourceRoot":"","sources":["../../../../src/components/Tabs/Tabs.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,OAAO,EACL,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,0BAAyB;AAE1B,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAErC,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAA;CACd;AAED,UAAU,YAAY;IACpB;;;;OAIG;IACH,cAAc,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;IACvC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED,UAAU,iBAAiB,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS;IACzD;;OAEG;IACH,IAAI,CAAC,EAAE,IAAI,CAAA;IACX;;OAEG;IACH,OAAO,CAAC,EAAE,IAAI,SAAS,MAAM,GACzB,KAAK,GACL,KAAK,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAA;CAC/C;AAED,UAAU,eAAe;IACvB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAA;CACrC;AAED,UAAU,kBAAkB;IAC1B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,SACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,YAAY,CAAC,EAC3D,aAAa,EACb,YAAY;CAAG;AAEnB,MAAM,WAAW,YACf,SAAQ,oBAAoB,CAAC,KAAK,CAAC,EACjC,aAAa,EACb,SAAS,CAAC,OAAO,CAAC;CAAG;AAEzB,MAAM,WAAW,aACf,SAAQ,oBAAoB,CAAC,KAAK,CAAC,EACjC,aAAa;CAAG;AAEpB,MAAM,WAAW,YACf,SAAQ,IAAI,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,MAAM,eAAe,CAAC,EACjE,aAAa,EACb,YAAY,EACZ,eAAe;CAAG;AAEtB,MAAM,WAAW,eACf,SAAQ,oBAAoB,CAAC,KAAK,CAAC,EACjC,aAAa;CAAG;AAEpB,MAAM,MAAM,gBAAgB,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GACxD,iBAAiB,GACjB,iBAAiB,CAAA;AAErB,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,MAAM,GAAG,SAAS,CAC7D,SAAQ,IAAI,CAAC,oBAAoB,EAAE,MAAM,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,EACzE,aAAa,EACb,iBAAiB,CAAC,IAAI,CAAC,EACvB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC;CAAG;AAEpE,MAAM,WAAW,eACf,SAAQ,oBAAoB,CAAC,KAAK,CAAC,EACjC,aAAa,EACb,kBAAkB;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useElementTruncated.d.ts","sourceRoot":"","sources":["../../../src/hooks/useElementTruncated.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,QAAA,MAAM,mBAAmB,GAAI,OAAO,SAAS,WAAW,OACjD,SAAS,CAAC,OAAO,GAAG,IAAI,CAAC,KAC7B,OA4BF,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
package/package.json
CHANGED
|
@@ -65,6 +65,29 @@ const [
|
|
|
65
65
|
'SegmentedControlItemList'
|
|
66
66
|
)
|
|
67
67
|
|
|
68
|
+
function SegmentedControlDivider({
|
|
69
|
+
index,
|
|
70
|
+
selectedItemIndex,
|
|
71
|
+
}: {
|
|
72
|
+
index: number
|
|
73
|
+
selectedItemIndex: number | null
|
|
74
|
+
}) {
|
|
75
|
+
const isAdjacentToSelectedItem =
|
|
76
|
+
!isNil(selectedItemIndex) &&
|
|
77
|
+
(selectedItemIndex + 1 === index || selectedItemIndex === index)
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Divider
|
|
81
|
+
className={classNames(
|
|
82
|
+
styles.SegmentedControlDivider,
|
|
83
|
+
isAdjacentToSelectedItem && styles.hidden
|
|
84
|
+
)}
|
|
85
|
+
withoutParallelIndent
|
|
86
|
+
orientation="vertical"
|
|
87
|
+
/>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
68
91
|
function SegmentedControlItemListImpl<
|
|
69
92
|
Type extends SegmentedControlType,
|
|
70
93
|
Value extends string,
|
|
@@ -120,9 +143,9 @@ function SegmentedControlItemListImpl<
|
|
|
120
143
|
{React.Children.map(children, (child, index) => (
|
|
121
144
|
<>
|
|
122
145
|
{index !== 0 && (
|
|
123
|
-
<
|
|
124
|
-
|
|
125
|
-
|
|
146
|
+
<SegmentedControlDivider
|
|
147
|
+
index={index}
|
|
148
|
+
selectedItemIndex={selectedItemIndex}
|
|
126
149
|
/>
|
|
127
150
|
)}
|
|
128
151
|
<SegmentedControlItemContextProvider value={index}>
|
|
@@ -31,10 +31,20 @@ $tab-item-indicator-height: 3px;
|
|
|
31
31
|
display: flex;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
.
|
|
34
|
+
.TabItemButton {
|
|
35
|
+
position: relative;
|
|
35
36
|
top: 4px;
|
|
37
|
+
|
|
36
38
|
overflow: visible;
|
|
37
39
|
|
|
40
|
+
box-sizing: border-box;
|
|
41
|
+
|
|
42
|
+
background-color: transparent;
|
|
43
|
+
|
|
44
|
+
transition:
|
|
45
|
+
background-color var(--transition-s),
|
|
46
|
+
box-shadow var(--transition-s);
|
|
47
|
+
|
|
38
48
|
&::after {
|
|
39
49
|
content: '';
|
|
40
50
|
|
|
@@ -51,6 +61,56 @@ $tab-item-indicator-height: 3px;
|
|
|
51
61
|
transition: height var(--transition-s);
|
|
52
62
|
}
|
|
53
63
|
|
|
64
|
+
&:where(.size-s) {
|
|
65
|
+
min-width: 24px;
|
|
66
|
+
height: 24px;
|
|
67
|
+
padding: 0 4px;
|
|
68
|
+
border-radius: var(--radius-8);
|
|
69
|
+
|
|
70
|
+
& :where(.TabItemButtonText) {
|
|
71
|
+
padding: 0 3px;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
&:where(.size-m) {
|
|
76
|
+
min-width: 36px;
|
|
77
|
+
height: 36px;
|
|
78
|
+
padding: 0 10px;
|
|
79
|
+
border-radius: var(--radius-8);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&:where(.size-l) {
|
|
83
|
+
min-width: 44px;
|
|
84
|
+
height: 44px;
|
|
85
|
+
padding: 0 12px;
|
|
86
|
+
border-radius: var(--radius-12);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
&:where(.size-m, .size-l) {
|
|
90
|
+
& :where(.TabItemButtonContent) {
|
|
91
|
+
gap: 2px;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
& :where(.TabItemButtonText) {
|
|
95
|
+
padding: 0 4px;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
&:where(.active, :hover):where(:not(:disabled)) {
|
|
100
|
+
background-color: var(--bg-black-lighter);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* NOTE: If there is no text, button is square, so padding is 0 */
|
|
104
|
+
&:not(:has(.TabItemButtonText)) {
|
|
105
|
+
padding: 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&:disabled {
|
|
109
|
+
cursor: not-allowed;
|
|
110
|
+
opacity: var(--opacity-disabled);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* stylelint-disable-next-line no-descending-specificity */
|
|
54
114
|
&:where([data-state='active']) {
|
|
55
115
|
color: var(--bgtxt-blue-normal);
|
|
56
116
|
|
|
@@ -66,7 +66,12 @@ function TabsComposition({
|
|
|
66
66
|
<TabItems>
|
|
67
67
|
<TabItem value="One">Tab1</TabItem>
|
|
68
68
|
<TabItem value="Two">Tab2</TabItem>
|
|
69
|
-
<TabItem
|
|
69
|
+
<TabItem
|
|
70
|
+
value="Three"
|
|
71
|
+
maxWidth={50}
|
|
72
|
+
>
|
|
73
|
+
LongLongLabelTab
|
|
74
|
+
</TabItem>
|
|
70
75
|
</TabItems>
|
|
71
76
|
|
|
72
77
|
<TabActions>
|
|
@@ -95,7 +100,7 @@ function TabsComposition({
|
|
|
95
100
|
</TabContent>
|
|
96
101
|
<TabContent value="Three">
|
|
97
102
|
<Center height={100}>
|
|
98
|
-
<Text color="txt-black-darkest">
|
|
103
|
+
<Text color="txt-black-darkest">LongLongLabelTab content</Text>
|
|
99
104
|
</Center>
|
|
100
105
|
</TabContent>
|
|
101
106
|
</Tabs>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { type JSX, forwardRef, useMemo } from 'react'
|
|
3
|
+
import { type JSX, forwardRef, useMemo, useRef } from 'react'
|
|
4
4
|
import * as React from 'react'
|
|
5
5
|
|
|
6
6
|
import { OpenInNewIcon } from '@channel.io/bezier-icons'
|
|
@@ -8,11 +8,11 @@ import * as TabsPrimitive from '@radix-ui/react-tabs'
|
|
|
8
8
|
import * as ToolbarPrimitive from '@radix-ui/react-toolbar'
|
|
9
9
|
import classNames from 'classnames'
|
|
10
10
|
|
|
11
|
+
import useElementTruncated from '~/src/hooks/useElementTruncated'
|
|
11
12
|
import { createContext } from '~/src/utils/react'
|
|
12
13
|
import { isNil } from '~/src/utils/type'
|
|
13
14
|
|
|
14
15
|
import { BaseButton } from '~/src/components/BaseButton'
|
|
15
|
-
import { Button } from '~/src/components/Button'
|
|
16
16
|
import { Icon } from '~/src/components/Icon'
|
|
17
17
|
import {
|
|
18
18
|
type TabActionElement,
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
type TabsProps,
|
|
28
28
|
} from '~/src/components/Tabs/Tabs.types'
|
|
29
29
|
import { Text } from '~/src/components/Text'
|
|
30
|
+
import { Tooltip } from '~/src/components/Tooltip'
|
|
30
31
|
|
|
31
32
|
import styles from './Tabs.module.scss'
|
|
32
33
|
|
|
@@ -130,16 +131,66 @@ function getButtonSizeBy(size: TabSize) {
|
|
|
130
131
|
)[size]
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
function getTypography(size: TabSize) {
|
|
135
|
+
return (
|
|
136
|
+
{
|
|
137
|
+
s: '13',
|
|
138
|
+
m: '14',
|
|
139
|
+
l: '15',
|
|
140
|
+
} as const
|
|
141
|
+
)[size]
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const TabItemButton = forwardRef<HTMLButtonElement, TabItemProps>(
|
|
145
|
+
function TabItemButton(
|
|
146
|
+
{ className, disabled, value, children, maxWidth, style, ...rest },
|
|
147
|
+
forwardedRef
|
|
148
|
+
) {
|
|
149
|
+
const contentRef = useRef<HTMLElement>(null)
|
|
150
|
+
const isTruncated = useElementTruncated(contentRef)
|
|
151
|
+
|
|
152
|
+
const { size } = useTabListContext()
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<Tooltip
|
|
156
|
+
content={children}
|
|
157
|
+
disabled={!isTruncated}
|
|
158
|
+
offset={6}
|
|
159
|
+
>
|
|
160
|
+
<BaseButton
|
|
161
|
+
className={classNames(
|
|
162
|
+
styles.TabItemButton,
|
|
163
|
+
styles[`size-${getButtonSizeBy(size)}`],
|
|
164
|
+
className
|
|
165
|
+
)}
|
|
166
|
+
disabled={disabled}
|
|
167
|
+
ref={forwardedRef}
|
|
168
|
+
style={{ maxWidth, ...style }}
|
|
169
|
+
{...rest}
|
|
170
|
+
>
|
|
171
|
+
<Text
|
|
172
|
+
ref={contentRef}
|
|
173
|
+
className={styles.TabItemButtonText}
|
|
174
|
+
typo={getTypography(size)}
|
|
175
|
+
bold
|
|
176
|
+
truncated
|
|
177
|
+
>
|
|
178
|
+
{children}
|
|
179
|
+
</Text>
|
|
180
|
+
</BaseButton>
|
|
181
|
+
</Tooltip>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
)
|
|
185
|
+
|
|
133
186
|
/**
|
|
134
187
|
* `TabItem` is a button that activates its associated content.
|
|
135
188
|
*/
|
|
136
189
|
export const TabItem = forwardRef<HTMLButtonElement, TabItemProps>(
|
|
137
190
|
function TabItem(
|
|
138
|
-
{ className, disabled, value, children, ...rest },
|
|
191
|
+
{ className, disabled, value, children, maxWidth, style, ...rest },
|
|
139
192
|
forwardedRef
|
|
140
193
|
) {
|
|
141
|
-
const { size } = useTabListContext()
|
|
142
|
-
|
|
143
194
|
if (typeof children !== 'string') {
|
|
144
195
|
return null
|
|
145
196
|
}
|
|
@@ -150,16 +201,17 @@ export const TabItem = forwardRef<HTMLButtonElement, TabItemProps>(
|
|
|
150
201
|
value={value}
|
|
151
202
|
asChild
|
|
152
203
|
>
|
|
153
|
-
<
|
|
154
|
-
className={classNames(styles.TabItem, className)}
|
|
155
|
-
disabled={disabled}
|
|
156
|
-
text={children}
|
|
157
|
-
size={getButtonSizeBy(size)}
|
|
158
|
-
colorVariant="monochrome-light"
|
|
159
|
-
styleVariant="tertiary"
|
|
204
|
+
<TabItemButton
|
|
160
205
|
ref={forwardedRef}
|
|
206
|
+
className={className}
|
|
207
|
+
disabled={disabled}
|
|
208
|
+
value={value}
|
|
209
|
+
maxWidth={maxWidth}
|
|
210
|
+
style={style}
|
|
161
211
|
{...rest}
|
|
162
|
-
|
|
212
|
+
>
|
|
213
|
+
{children}
|
|
214
|
+
</TabItemButton>
|
|
163
215
|
</TabsPrimitive.TabsTrigger>
|
|
164
216
|
)
|
|
165
217
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type React from 'react'
|
|
2
|
+
import { type CSSProperties } from 'react'
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
type BezierComponentProps,
|
|
@@ -52,6 +53,7 @@ interface TabItemOwnProps {
|
|
|
52
53
|
* A unique value that associates the trigger with a content.
|
|
53
54
|
*/
|
|
54
55
|
value: string
|
|
56
|
+
maxWidth?: CSSProperties['maxWidth']
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
interface TabContentOwnProps {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { RefObject } from 'react'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
const useElementTruncated = <Element extends HTMLElement>(
|
|
5
|
+
ref: RefObject<Element | null>
|
|
6
|
+
): boolean => {
|
|
7
|
+
const [isTruncated, setTruncated] = useState(false)
|
|
8
|
+
|
|
9
|
+
useEffect(
|
|
10
|
+
function initResizeObserver() {
|
|
11
|
+
if (ref.current) {
|
|
12
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
13
|
+
const firstEntry = entries[0]
|
|
14
|
+
if (firstEntry.target) {
|
|
15
|
+
setTruncated(
|
|
16
|
+
firstEntry.target.scrollWidth > firstEntry.target.clientWidth ||
|
|
17
|
+
firstEntry.target.scrollHeight > firstEntry.target.clientHeight
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
resizeObserver.observe(ref.current)
|
|
22
|
+
|
|
23
|
+
return function cleanup() {
|
|
24
|
+
return resizeObserver.disconnect()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return undefined
|
|
29
|
+
},
|
|
30
|
+
[ref]
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
return isTruncated
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default useElementTruncated
|