@@ -18,16 +18,20 @@ const COMPONENT_ID = 'tabs.tab';
1818
1919interface IStyledTabProps {
2020 isSelected ?: boolean ;
21+ isVertical ?: boolean ;
2122}
2223
23- /**
24- * 1. A high specificity is needed to apply the border-color in vertical orientations
25- */
26- const colorStyles = ( { theme, isSelected } : IStyledTabProps & ThemeProps < DefaultTheme > ) => {
24+ const colorStyles = ( {
25+ theme,
26+ isSelected,
27+ isVertical
28+ } : IStyledTabProps & ThemeProps < DefaultTheme > ) => {
29+ const borderColor = isSelected ? 'currentcolor' : 'transparent' ;
2730 const selectedColor = getColorV8 ( 'primaryHue' , 600 , theme ) ;
2831
2932 return css `
30- border-color : ${ isSelected && 'currentcolor !important' } ; /* [1] */
33+ border-bottom-color : ${ isVertical ? undefined : borderColor } ;
34+ border-${ theme . rtl ? 'right' : 'left' } -color : ${ isVertical ? borderColor : undefined } ;
3135 color : ${ isSelected ? selectedColor : 'inherit' } ;
3236
3337 & : hover {
@@ -55,43 +59,73 @@ const colorStyles = ({ theme, isSelected }: IStyledTabProps & ThemeProps<Default
5559 ` ;
5660} ;
5761
58- const sizeStyles = ( { theme } : ThemeProps < DefaultTheme > ) => {
59- const paddingTop = theme . space . base * 2.5 ;
60- const paddingHorizontal = theme . space . base * 7 ;
61- const paddingBottom =
62- paddingTop -
63- ( stripUnit ( theme . borderWidths . md ) as number ) -
64- ( stripUnit ( theme . borderWidths . sm ) as number ) ;
62+ const sizeStyles = ( { theme, isVertical } : IStyledTabProps & ThemeProps < DefaultTheme > ) => {
63+ const borderWidth = theme . borderWidths . md ;
64+ const focusHeight = `${ theme . space . base * 5 } px` ;
65+ let marginBottom ;
66+ let padding ;
67+
68+ if ( isVertical ) {
69+ marginBottom = `${ theme . space . base * 5 } px` ;
70+ padding = `${ theme . space . base } px ${ theme . space . base * 2 } px` ;
71+ } else {
72+ const paddingTop = theme . space . base * 2.5 ;
73+ const paddingHorizontal = theme . space . base * 7 ;
74+ const paddingBottom =
75+ paddingTop -
76+ ( stripUnit ( theme . borderWidths . md ) as number ) -
77+ ( stripUnit ( theme . borderWidths . sm ) as number ) ;
78+
79+ padding = `${ paddingTop } px ${ paddingHorizontal } px ${ paddingBottom } px` ;
80+ }
6581
6682 return css `
67- padding : ${ paddingTop } px ${ paddingHorizontal } px ${ paddingBottom } px;
83+ margin-bottom : ${ marginBottom } ;
84+ border-width : ${ borderWidth } ;
85+ padding : ${ padding } ;
86+
87+ & : focus-visible ::before ,
88+ & [data-garden-focus-visible ]::before {
89+ height : ${ focusHeight } ;
90+ }
91+
92+ & : last-of-type {
93+ margin-bottom : 0 ;
94+ }
6895 ` ;
6996} ;
7097
71- /**
98+ /*
7299 * 1. Text truncation (requires `max-width`).
73100 * 2. Overflow compensation.
74101 * 3. Override default anchor styling
75102 */
76- export const StyledTab = styled . div . attrs < IStyledTabProps > ( {
103+ export const StyledTab = styled . div . attrs ( {
77104 'data-garden-id' : COMPONENT_ID ,
78105 'data-garden-version' : PACKAGE_VERSION
79106} ) < IStyledTabProps > `
80- display: inline-block;
107+ display: ${ props => ( props . isVertical ? 'block' : ' inline-block' ) } ;
81108 position: relative;
82109 transition: color 0.25s ease-in-out;
83- border-bottom: ${ props => props . theme . borderStyles . solid } transparent ;
84- border-width: ${ props => props . theme . borderWidths . md } ;
110+ border-bottom: ${ props => ( props . isVertical ? undefined : props . theme . borderStyles . solid ) } ;
111+ border-${ props => ( props . theme . rtl ? 'right' : 'left' ) } : ${ props => ( props . isVertical ? props . theme . borderStyles . solid : undefined ) } ;
85112 cursor: pointer;
86113 overflow: hidden; /* [1] */
87114 vertical-align: top; /* [2] */
88115 user-select: none;
89- text-align: center;
116+ text-align: ${ props => {
117+ if ( props . isVertical ) {
118+ return props . theme . rtl ? 'right' : 'left' ;
119+ }
120+
121+ return 'center' ;
122+ } } ;
90123 text-decoration: none; /* [3] */
91124 text-overflow: ellipsis; /* [1] */
92125
93- ${ sizeStyles }
94- ${ colorStyles }
126+ ${ sizeStyles } ;
127+
128+ ${ colorStyles } ;
95129
96130 &:focus {
97131 text-decoration: none;
@@ -105,11 +139,10 @@ export const StyledTab = styled.div.attrs<IStyledTabProps>({
105139 &:focus-visible::before,
106140 &[data-garden-focus-visible]::before {
107141 position: absolute;
108- top: ${ props => props . theme . space . base * 2.5 } px;
109- right: ${ props => props . theme . space . base * 6 } px;
110- left: ${ props => props . theme . space . base * 6 } px;
142+ top: ${ props => props . theme . space . base * ( props . isVertical ? 1 : 2.5 ) } px;
143+ right: ${ props => props . theme . space . base * ( props . isVertical ? 1 : 6 ) } px;
144+ left: ${ props => props . theme . space . base * ( props . isVertical ? 1 : 6 ) } px;
111145 border-radius: ${ props => props . theme . borderRadii . md } ;
112- height: ${ props => props . theme . space . base * 5 } px;
113146 pointer-events: none;
114147 }
115148
0 commit comments