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

feat(react-tabs): add rounded tab appearance variants #32944

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
28 changes: 28 additions & 0 deletions apps/vr-tests-react-components/src/stories/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,31 @@ export const WithIconOnlyAndVertical = () => (
);
Copy link
Collaborator

@fabricteam fabricteam Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual regressions to review in the fluentuiv9 Visual Regression Report

Avatar Converged 2 screenshots
Image Name Diff(in Pixels) Image Type
Avatar Converged.badgeMask.chromium.png 9 Changed
Avatar Converged.Badge Mask RTL.chromium.png 13 Changed
Drawer 3 screenshots
Image Name Diff(in Pixels) Image Type
Drawer.Full Overlay Dark Mode.chromium.png 992 Changed
Drawer.overlay drawer full.chromium.png 1139 Changed
Drawer.Full Overlay High Contrast.chromium.png 4940 Changed
TabList and Tab Converged 6 screenshots
Image Name Diff(in Pixels) Image Type
TabList and Tab Converged.Filled Rounded Appearance Dark Mode.chromium.png 0 Added
TabList and Tab Converged.Filled Rounded Appearance High Contrast.chromium.png 0 Added
TabList and Tab Converged.Filled Rounded Appearance.chromium.png 0 Added
TabList and Tab Converged.Subtle Rounded Appearance Dark Mode.chromium.png 0 Added
TabList and Tab Converged.Subtle Rounded Appearance High Contrast.chromium.png 0 Added
TabList and Tab Converged.Subtle Rounded Appearance.chromium.png 0 Added


WithIconOnlyAndVertical.storyName = 'With icon only and vertical';

export const SubtleRoundedAppearance = () => (
<TabList appearance="subtle-rounded" defaultSelectedValue="1">
<Tab value="1">First</Tab>
<Tab className="mouse-target" value="2">
Second
</Tab>
<Tab value="3">Third</Tab>
</TabList>
);

export const SubtleRoundedAppearanceDarkMode = getStoryVariant(SubtleRoundedAppearance, DARK_MODE);

export const SubtleRoundedAppearanceHighContrast = getStoryVariant(SubtleRoundedAppearance, HIGH_CONTRAST);

export const FilledRoundedAppearance = () => (
<TabList appearance="filled-rounded" defaultSelectedValue="1">
<Tab value="1">First</Tab>
<Tab className="mouse-target" value="2">
Second
</Tab>
<Tab value="3">Third</Tab>
</TabList>
);

export const FilledRoundedAppearanceDarkMode = getStoryVariant(FilledRoundedAppearance, DARK_MODE);

export const FilledRoundedAppearanceHighContrast = getStoryVariant(FilledRoundedAppearance, HIGH_CONTRAST);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feature: add rounded tab variant",
"packageName": "@fluentui/react-tabs",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type TabListContextValues = {

// @public
export type TabListProps = ComponentProps<TabListSlots> & {
appearance?: 'transparent' | 'subtle';
appearance?: 'transparent' | 'subtle' | 'subtle-rounded' | 'filled-rounded';
reserveSelectedTabSpace?: boolean;
defaultSelectedValue?: TabValue;
disabled?: boolean;
Expand Down Expand Up @@ -109,7 +109,7 @@ export type TabSlots = {

// @public
export type TabState = ComponentState<TabInternalSlots> & Pick<TabProps, 'value'> & Required<Pick<TabProps, 'disabled'>> & {
appearance?: 'transparent' | 'subtle';
appearance?: 'transparent' | 'subtle' | 'subtle-rounded' | 'filled-rounded';
iconOnly: boolean;
selected: boolean;
contentReservedSpaceClassName?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ export type TabState = ComponentState<TabInternalSlots> &
Pick<TabProps, 'value'> &
Required<Pick<TabProps, 'disabled'>> & {
/**
* A tab supports 'transparent' and 'subtle' appearance.
* A tab supports 'transparent', 'subtle', `subtle-rounded` and `filled-rounded` appearance.
*/
appearance?: 'transparent' | 'subtle';
appearance?: 'transparent' | 'subtle' | 'subtle-rounded' | 'filled-rounded';

/**
* A tab can have only an icon slot filled and no content.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,89 +88,168 @@ const useRootStyles = makeStyles({
},
transparent: {
backgroundColor: tokens.colorTransparentBackground,
':hover': {
':enabled:hover': {
backgroundColor: tokens.colorTransparentBackgroundHover,
},
':active': {
':enabled:active': {
backgroundColor: tokens.colorTransparentBackgroundPressed,
},
'& .fui-Tab__icon': {
[`& .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForeground2,
},
':hover .fui-Tab__icon': {
[`:enabled:hover .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForeground2Hover,
},
':active .fui-Tab__icon': {
[`:enabled:active .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForeground2Pressed,
},
'& .fui-Tab__content': {
[`& .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground2,
},
':hover .fui-Tab__content': {
[`:enabled:hover .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground2Hover,
},
':active .fui-Tab__content': {
[`:enabled:active .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground2Pressed,
},
},
subtle: {
backgroundColor: tokens.colorSubtleBackground,
':hover': {
':enabled:hover': {
backgroundColor: tokens.colorSubtleBackgroundHover,
},
':active': {
':enabled:active': {
backgroundColor: tokens.colorSubtleBackgroundPressed,
},
'& .fui-Tab__icon': {
[`& .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForeground2,
},
':hover .fui-Tab__icon': {
[`:enabled:hover .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForeground2Hover,
},
':active .fui-Tab__icon': {
[`:enabled:active .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForeground2Pressed,
},
'& .fui-Tab__content': {
[`& .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground2,
},
':hover .fui-Tab__content': {
[`:enabled:hover .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground2Hover,
},
':active .fui-Tab__content': {
[`:enabled:active .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground2Pressed,
},
},
disabled: {
backgroundColor: tokens.colorTransparentBackground,

'& .fui-Tab__icon': {
[`& .${tabClassNames.icon}`]: {
color: tokens.colorNeutralForegroundDisabled,
},
'& .fui-Tab__content': {
[`& .${tabClassNames.content}`]: {
color: tokens.colorNeutralForegroundDisabled,
},
cursor: 'not-allowed',
},
selected: {
'& .fui-Tab__icon': {
[`& .${tabClassNames.icon}`]: {
color: tokens.colorCompoundBrandForeground1,
},
':hover .fui-Tab__icon': {
[`:enabled:hover .${tabClassNames.icon}`]: {
color: tokens.colorCompoundBrandForeground1Hover,
},
':active .fui-Tab__icon': {
[`:enabled:active .${tabClassNames.icon}`]: {
color: tokens.colorCompoundBrandForeground1Pressed,
},
'& .fui-Tab__content': {
[`& .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground1,
},
':hover .fui-Tab__content': {
[`:enabled:hover .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground1Hover,
},
':active .fui-Tab__content': {
[`:enabled:active .${tabClassNames.content}`]: {
color: tokens.colorNeutralForeground1Pressed,
},
},
rounded: {
borderRadius: tokens.borderRadiusCircular,
[`& .${tabClassNames.icon}`]: {
color: 'inherit',
},
[`& .${tabClassNames.content}`]: {
color: 'inherit',
},
},
subtleRounded: {
backgroundColor: tokens.colorTransparentBackground,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorTransparentStroke}`,
color: tokens.colorNeutralForeground2,
':enabled:hover': {
backgroundColor: tokens.colorNeutralBackground1Hover,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorNeutralStroke1Hover}`,
color: tokens.colorNeutralForeground2Hover,
},
':enabled:active': {
backgroundColor: tokens.colorNeutralBackground1Pressed,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorNeutralStroke1Pressed}`,
color: tokens.colorNeutralForeground2Pressed,
},
},
subtleRoundedSelected: {
backgroundColor: tokens.colorBrandBackground2,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorCompoundBrandStroke}`,
color: tokens.colorBrandForeground2,
':enabled:hover': {
backgroundColor: tokens.colorBrandBackground2Hover,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorCompoundBrandStrokeHover}`,
color: tokens.colorBrandForeground2Hover,
},
':enabled:active': {
backgroundColor: tokens.colorBrandBackground2Pressed,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorCompoundBrandStrokePressed}`,
color: tokens.colorBrandForeground2Pressed,
},
},
subtleRoundedDisabled: {
backgroundColor: tokens.colorTransparentBackground,
color: tokens.colorNeutralForegroundDisabled,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorTransparentStroke}`,
},
subtleRoundedDisabledSelected: {
border: `solid ${tokens.strokeWidthThin} ${tokens.colorNeutralStrokeDisabled}`,
},
filledRounded: {
backgroundColor: tokens.colorNeutralBackground3,
color: tokens.colorNeutralForeground2,
':enabled:hover': {
backgroundColor: tokens.colorNeutralBackground3Hover,
color: tokens.colorNeutralForeground2Hover,
},
':enabled:active': {
backgroundColor: tokens.colorNeutralBackground3Pressed,
color: tokens.colorNeutralForeground2Pressed,
},
},
filledRoundedSelected: {
backgroundColor: tokens.colorBrandBackground,
color: tokens.colorNeutralForegroundOnBrand,
':enabled:hover': {
backgroundColor: tokens.colorBrandBackgroundHover,
color: tokens.colorNeutralForegroundOnBrand,
},
':enabled:active': {
backgroundColor: tokens.colorBrandBackgroundPressed,
color: tokens.colorNeutralForegroundOnBrand,
},
},
filledRoundedDisabled: {
backgroundColor: tokens.colorNeutralBackgroundDisabled,
border: `solid ${tokens.strokeWidthThin} ${tokens.colorTransparentStroke}`,
color: tokens.colorNeutralForegroundDisabled,
},
filledRoundedDisabledSelected: {
border: `solid ${tokens.strokeWidthThin} ${tokens.colorNeutralStrokeDisabled}`,
},
});

/**
Expand Down Expand Up @@ -291,20 +370,20 @@ const useActiveIndicatorStyles = makeStyles({
'::after': {
backgroundColor: tokens.colorCompoundBrandStroke,
},
':hover::after': {
':enabled:hover::after': {
backgroundColor: tokens.colorCompoundBrandStrokeHover,
},
':active::after': {
':enabled:active::after': {
backgroundColor: tokens.colorCompoundBrandStrokePressed,
},
'@media (forced-colors: active)': {
'::after': {
backgroundColor: 'ButtonText',
},
':hover::after': {
':enabled:hover::after': {
backgroundColor: 'ButtonText',
},
':active::after': {
':enabled:active::after': {
backgroundColor: 'ButtonText',
},
},
Expand Down Expand Up @@ -472,35 +551,36 @@ export const useTabIndicatorStyles_unstable = (state: TabState): TabState => {
const pendingIndicatorStyles = usePendingIndicatorStyles();
const activeIndicatorStyles = useActiveIndicatorStyles();

const { disabled, selected, size, vertical } = state;

state.root.className = mergeClasses(
tabClassNames.root,
rootStyles.root,

// pending indicator (before pseudo element)
pendingIndicatorStyles.base,
size === 'small' && (vertical ? pendingIndicatorStyles.smallVertical : pendingIndicatorStyles.smallHorizontal),
size === 'medium' && (vertical ? pendingIndicatorStyles.mediumVertical : pendingIndicatorStyles.mediumHorizontal),
size === 'large' && (vertical ? pendingIndicatorStyles.largeVertical : pendingIndicatorStyles.largeHorizontal),
disabled && pendingIndicatorStyles.disabled,

// active indicator (after pseudo element)
selected && activeIndicatorStyles.base,
selected && !disabled && activeIndicatorStyles.selected,
selected &&
size === 'small' &&
(vertical ? activeIndicatorStyles.smallVertical : activeIndicatorStyles.smallHorizontal),
selected &&
size === 'medium' &&
(vertical ? activeIndicatorStyles.mediumVertical : activeIndicatorStyles.mediumHorizontal),
selected &&
size === 'large' &&
(vertical ? activeIndicatorStyles.largeVertical : activeIndicatorStyles.largeHorizontal),
selected && disabled && activeIndicatorStyles.disabled,

state.root.className,
);
const { appearance, disabled, selected, size, vertical } = state;

const classes: Parameters<typeof mergeClasses> = [tabClassNames.root, rootStyles.root];

if (appearance !== 'subtle-rounded' && appearance !== 'filled-rounded') {
classes.push(
// pending indicator (before pseudo element)
pendingIndicatorStyles.base,
size === 'small' && (vertical ? pendingIndicatorStyles.smallVertical : pendingIndicatorStyles.smallHorizontal),
size === 'medium' && (vertical ? pendingIndicatorStyles.mediumVertical : pendingIndicatorStyles.mediumHorizontal),
size === 'large' && (vertical ? pendingIndicatorStyles.largeVertical : pendingIndicatorStyles.largeHorizontal),
disabled && pendingIndicatorStyles.disabled,

// active indicator (after pseudo element)
selected && activeIndicatorStyles.base,
selected && !disabled && activeIndicatorStyles.selected,
selected &&
size === 'small' &&
(vertical ? activeIndicatorStyles.smallVertical : activeIndicatorStyles.smallHorizontal),
selected &&
size === 'medium' &&
(vertical ? activeIndicatorStyles.mediumVertical : activeIndicatorStyles.mediumHorizontal),
selected &&
size === 'large' &&
(vertical ? activeIndicatorStyles.largeVertical : activeIndicatorStyles.largeHorizontal),
selected && disabled && activeIndicatorStyles.disabled,
);
}

state.root.className = mergeClasses(...classes, state.root.className);

useTabAnimatedIndicatorStyles_unstable(state);

Expand All @@ -525,16 +605,36 @@ export const useTabButtonStyles_unstable = (state: TabState, slot: TabState['roo

const { appearance, disabled, selected, size, vertical } = state;

const isSubtleRounded = appearance === 'subtle-rounded';
const isFilledRounded = appearance === 'filled-rounded';
const isRounded = isSubtleRounded || isFilledRounded;

const roundedAppearance = [
rootStyles.rounded,
// subtle-rounded appearance
isSubtleRounded && rootStyles.subtleRounded,
selected && isSubtleRounded && rootStyles.subtleRoundedSelected,
disabled && isSubtleRounded && rootStyles.subtleRoundedDisabled,
selected && disabled && isSubtleRounded && rootStyles.subtleRoundedDisabledSelected,
// filled-rounded appearance
isFilledRounded && rootStyles.filledRounded,
selected && isFilledRounded && rootStyles.filledRoundedSelected,
disabled && isFilledRounded && rootStyles.filledRoundedDisabled,
selected && disabled && isFilledRounded && rootStyles.filledRoundedDisabledSelected,
];

slot.className = mergeClasses(
rootStyles.button,
// orientation
vertical ? rootStyles.vertical : rootStyles.horizontal,
// size
size === 'small' && (vertical ? rootStyles.smallVertical : rootStyles.smallHorizontal),
size === 'medium' && (vertical ? rootStyles.mediumVertical : rootStyles.mediumHorizontal),
size === 'large' && (vertical ? rootStyles.largeVertical : rootStyles.largeHorizontal),
focusStyles.base,
!disabled && appearance === 'subtle' && rootStyles.subtle,
!disabled && appearance === 'transparent' && rootStyles.transparent,
!disabled && selected && rootStyles.selected,
...(isRounded ? roundedAppearance : [!disabled && selected && rootStyles.selected]),
disabled && rootStyles.disabled,

slot.className,
Expand Down
Loading
Loading