Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Tabs): style fixes and align with design spec #832

Merged
merged 6 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 33 additions & 51 deletions src/tabs.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export const outerBorder = style({

export const outer = style([
sprinkles({
height: TAB_HEIGHT,
minHeight: TAB_HEIGHT,
width: '100%',
position: 'relative',
overflow: 'hidden',
}),
{
'@media': {
Expand All @@ -25,88 +25,71 @@ export const outer = style([
},
},
]);
export const inner = style([
sprinkles({
position: 'absolute',
left: 0,
right: 0,
// this height is to hide the scrollbar
height: 80,
}),
{
// if tabs don't fit horizontally they can be scrolled
overflowX: 'scroll',
overflowY: 'hidden',
export const inner = style({
position: 'relative',
width: '100%',
// if tabs don't fit horizontally they can be scrolled
overflowX: 'scroll',

// hide scrollbar
scrollbarWidth: 'none', // Firefox
'::-webkit-scrollbar': {
display: 'none', // Chrome/Safari
},
]);
});
export const tabsContainer = sprinkles({
height: TAB_HEIGHT,
minHeight: TAB_HEIGHT,
width: '100%',
display: 'flex',
});

const baseTab = style([
sprinkles({
display: 'inline-flex',
flexShrink: 0,
alignItems: 'center',
justifyContent: 'center',
paddingLeft: 16,
paddingRight: 16,
height: TAB_HEIGHT,
paddingX: 16,
minWidth: 80,
minHeight: TAB_HEIGHT,
background: 'transparent',
}),
{
flex: '1 0 80px',
textAlign: 'center',
verticalAlign: 'baseline',
borderBottom: '2px solid transparent',
borderTop: 'initial',
borderRight: 'initial',
borderLeft: 'initial',
maxWidth: TAB_MAX_WIDTH,
'@media': {
[mq.supportsHover]: {
':hover': {
color: vars.colors.textPrimary,
},
},
[mq.desktopOrBigger]: {
flex: '0 1 208px',
padding: `16px 32px`,
maxWidth: TAB_MAX_WIDTH,
},
},
},
]);

export const tabVariants = styleVariants({
default: [
default: [baseTab],
fullWidth: [
baseTab,
style({
maxWidth: TAB_MAX_WIDTH,
}),
],
tabs2: [
baseTab,
style({
maxWidth: [`max(50%, ${TAB_MAX_WIDTH}px)`, TAB_MAX_WIDTH], // max() is not supported by all browsers
}),
],
tabs3: [
baseTab,
style({
maxWidth: [`max(33.33%, ${TAB_MAX_WIDTH}px)`, TAB_MAX_WIDTH], // max() is not supported by all browsers
}),
],
});

export const tabWithIcon = style({
flexBasis: 112,
'@media': {
[mq.desktopOrBigger]: {
flexBasis: 208,
{
'@media': {
[mq.tabletOrSmaller]: {
flex: '1 1 0px',
},
},
},
},
],
});

const tabSelectedBae = sprinkles({
const tabSelectedBase = sprinkles({
color: vars.colors.textPrimary,
});

Expand All @@ -117,21 +100,20 @@ export const tabSelectionVariants = styleVariants({
}),
],
selected: [
tabSelectedBae,
tabSelectedBase,
style({
borderBottom: `2px solid ${vars.colors.controlActivated}`,
}),
],
selectedAnimating: [
tabSelectedBae,
tabSelectedBase,
style({
borderBottom: '2px solid transparent',
}),
],
});

export const icon = style({
marginRight: 8,
height: pxToRem(24),
width: pxToRem(24),
});
Expand Down
38 changes: 20 additions & 18 deletions src/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import {Text} from './text';
import {isRunningAcceptanceTest} from './utils/platform';
import {getPrefixedDataAttributes} from './utils/dom';
import * as styles from './tabs.css';
import Inline from './inline';

import type {DataAttributes, TrackingEvent} from './utils/types';

const LINE_ANIMATION_DURATION_MS = isRunningAcceptanceTest() ? 0 : 300;

const getTabVariant = (numberOfTabs: number): keyof typeof styles.tabVariants => {
switch (numberOfTabs) {
case 1:
case 2:
return 'tabs2';
case 3:
return 'tabs3';
return 'fullWidth';
default:
return 'default';
}
Expand Down Expand Up @@ -57,9 +58,9 @@ const Tabs: React.FC<TabsProps> = ({selectedIndex, onChange, tabs, dataAttribute
line.style.transform = `translate(${tabFrom.offsetLeft - scrollable.scrollLeft}px, 0)`;
Promise.resolve().then(() => {
// set final line styles
line.style.transition = `transform ${LINE_ANIMATION_DURATION_MS}ms, width ${LINE_ANIMATION_DURATION_MS}ms`;
line.style.width = `${tabTo.offsetWidth}px`;
line.style.transform = `translate(${tabTo.offsetLeft - scrollable.scrollLeft}px, 0)`;
line.style.transition = `transform ${LINE_ANIMATION_DURATION_MS}ms, width ${LINE_ANIMATION_DURATION_MS}ms`;
});
setTimeout(() => {
// hide line
Expand Down Expand Up @@ -94,8 +95,7 @@ const Tabs: React.FC<TabsProps> = ({selectedIndex, onChange, tabs, dataAttribute
? isAnimating
? styles.tabSelectionVariants.selectedAnimating
: styles.tabSelectionVariants.selected
: styles.tabSelectionVariants.noSelected,
icon && styles.tabWithIcon
: styles.tabSelectionVariants.noSelected
)}
onPress={() => {
if (!isAnimating && selectedIndex !== index) {
Expand All @@ -108,19 +108,21 @@ const Tabs: React.FC<TabsProps> = ({selectedIndex, onChange, tabs, dataAttribute
aria-controls={ariaControls}
aria-selected={isSelected ? 'true' : 'false'}
>
{icon && <div className={styles.icon}>{icon}</div>}
<Text
desktopSize={textPresets.tabsLabel.size.desktop}
mobileSize={textPresets.tabsLabel.size.mobile}
desktopLineHeight={textPresets.tabsLabel.lineHeight.desktop}
mobileLineHeight={textPresets.tabsLabel.lineHeight.mobile}
weight={textPresets.tabsLabel.weight}
color="inherit"
wordBreak={false}
textAlign="center"
>
{text}
</Text>
<Inline space={!!icon && !!text ? 8 : 0} alignItems="center">
{icon && <div className={styles.icon}>{icon}</div>}
<Text
desktopSize={textPresets.tabsLabel.size.desktop}
mobileSize={textPresets.tabsLabel.size.mobile}
desktopLineHeight={textPresets.tabsLabel.lineHeight.desktop}
mobileLineHeight={textPresets.tabsLabel.lineHeight.mobile}
weight={textPresets.tabsLabel.weight}
color="inherit"
wordBreak={false}
textAlign="center"
>
{text}
</Text>
</Inline>
</BaseTouchable>
);
})}
Expand Down
Loading