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(tabs): add new tabs components #2002

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/src/components/Stories @DarkGenius
/src/components/Switch @zamkovskaya
/src/components/Table @Raubzeug
/src/components/Tabs @sofiushko
/src/components/tabs @sofiushko
/src/components/Text @IsaevAlexandr
/src/components/TreeList @IsaevAlexandr
/src/components/TreeSelect @IsaevAlexandr
Expand Down
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export * from './Spin';
export * from './Switch';
export * from './Table';
export * from './TableColumnSetup';
export * from './Tabs';
export * from './tabs';
export * from './Text';
export * from './Toaster';
export * from './Toc';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--/GITHUB_BLOCK-->

```tsx
import {Tabs} from '@gravity-ui/uikit';
import {Tabs} from '@gravity-ui/uikit/legacy';
```

Компонент `Tabs` используется организации контента и навигации по нему, а также для переключения между различными представлениями.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--/GITHUB_BLOCK-->

```tsx
import {Tabs} from '@gravity-ui/uikit';
import {Tabs} from '@gravity-ui/uikit/legacy';
```

The `Tabs` component is used to explore and organize content, as well as to switch across various views.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use '../variables';
@use '../../../styles/mixins';
@use '../../variables';
@use '../../../../styles/mixins';

$block: '.#{variables.$ns}tabs';
$block: '.#{variables.$ns}tabs-legacy';

#{$block} {
--_--vertical-item-padding: var(--g-tabs-vertical-item-padding, 6px 20px);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import * as React from 'react';

import type {AriaLabelingProps, QAProps} from '../types';
import {block} from '../utils/cn';
import {filterDOMProps} from '../utils/filterDOMProps';
import type {AriaLabelingProps, QAProps} from '../../types';
import {block} from '../../utils/cn';
import {filterDOMProps} from '../../utils/filterDOMProps';

import {TabsContext} from './TabsContext';
import {TabsItem} from './TabsItem';
import type {TabsItemProps as TabsItemInternalProps} from './TabsItem';

import './Tabs.scss';

const b = block('tabs');
const b = block('tabs-legacy');

export enum TabsDirection {
Horizontal = 'horizontal',
Expand Down Expand Up @@ -66,6 +66,9 @@ const getActiveTabId = (

const emptyTabsList: TabsItemProps[] = [];

/**
* @deprecated
*/
const TabsComponent = React.forwardRef<HTMLDivElement, TabsProps>(
(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import * as React from 'react';

import {Label} from '../Label';
import type {LabelProps} from '../Label';
import type {QAProps} from '../types';
import {block} from '../utils/cn';
import {Label} from '../../Label';
import type {LabelProps} from '../../Label';
import type {QAProps} from '../../types';
import {block} from '../../utils/cn';

import {TabsContext} from './TabsContext';

const b = block('tabs');
const b = block('tabs-legacy');

type ExtraProps = Omit<
React.HTMLProps<HTMLDivElement>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {getTabsMock} from './getTabsMock';
import type {StoryParams} from './types';

const meta: Meta<typeof Tabs> = {
title: 'Components/Navigation/Tabs',
title: 'Legacy/Tabs',
component: Tabs,
args: {
direction: TabsDirection.Horizontal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type * as React from 'react';

import userEvent from '@testing-library/user-event';

import {render, screen} from '../../../../test-utils/utils';
import {render, screen} from '../../../../../test-utils/utils';
import {Tabs, TabsDirection} from '../Tabs';
import type {TabsItemProps, TabsSize} from '../Tabs';

Expand All @@ -21,8 +21,8 @@ test('should render tabs by default', () => {
const component = screen.getByRole('tablist');

expect(component).toBeVisible();
expect(component).toHaveClass('g-tabs_size_m');
expect(component).toHaveClass('g-tabs_direction_horizontal');
expect(component).toHaveClass('g-tabs-legacy_size_m');
expect(component).toHaveClass('g-tabs-legacy_direction_horizontal');
});

test('should not render tabs if no items', () => {
Expand All @@ -38,7 +38,7 @@ test.each(new Array<TabsSize>('m', 'l', 'xl'))('should render with given "%s" si
render(<Tabs items={[]} size={size} qa={qaId} />);
const component = screen.getByTestId(qaId);

expect(component).toHaveClass(`g-tabs_size_${size}`);
expect(component).toHaveClass(`g-tabs-legacy_size_${size}`);
});

test.each(new Array<TabsDirection>(TabsDirection.Horizontal, TabsDirection.Vertical))(
Expand All @@ -47,7 +47,7 @@ test.each(new Array<TabsDirection>(TabsDirection.Horizontal, TabsDirection.Verti
render(<Tabs items={[]} direction={direction} qa={qaId} />);
const component = screen.getByTestId(qaId);

expect(component).toHaveClass(`g-tabs_direction_${direction}`);
expect(component).toHaveClass(`g-tabs-legacy_direction_${direction}`);
},
);

Expand All @@ -65,10 +65,10 @@ test('should not select tab if allow not selected', () => {
const tabComponent1 = screen.getByTitle(tabTitle1);
const tabComponent2 = screen.getByTitle(tabTitle2);

expect(tabComponent1).not.toHaveClass('g-tabs__item_active');
expect(tabComponent1).not.toHaveClass('g-tabs-legacy__item_active');
expect(tabComponent1).toHaveAttribute('aria-selected', 'false');

expect(tabComponent2).not.toHaveClass('g-tabs__item_active');
expect(tabComponent2).not.toHaveClass('g-tabs-legacy__item_active');
expect(tabComponent2).toHaveAttribute('aria-selected', 'false');
});

Expand All @@ -77,10 +77,10 @@ test('should select first tab as active', () => {
const tabComponent1 = screen.getByTitle(tabTitle1);
const tabComponent2 = screen.getByTitle(tabTitle2);

expect(tabComponent1).toHaveClass('g-tabs__item_active');
expect(tabComponent1).toHaveClass('g-tabs-legacy__item_active');
expect(tabComponent1).toHaveAttribute('aria-selected', 'true');

expect(tabComponent2).not.toHaveClass('g-tabs__item_active');
expect(tabComponent2).not.toHaveClass('g-tabs-legacy__item_active');
expect(tabComponent2).toHaveAttribute('aria-selected', 'false');
});

Expand All @@ -89,10 +89,10 @@ test('should passed active tab', () => {
const tabComponent1 = screen.getByTitle(tabTitle1);
const tabComponent2 = screen.getByTitle(tabTitle2);

expect(tabComponent1).not.toHaveClass('g-tabs__item_active');
expect(tabComponent1).not.toHaveClass('g-tabs-legacy__item_active');
expect(tabComponent1).toHaveAttribute('aria-selected', 'false');

expect(tabComponent2).toHaveClass('g-tabs__item_active');
expect(tabComponent2).toHaveClass('g-tabs-legacy__item_active');
expect(tabComponent2).toHaveAttribute('aria-selected', 'true');
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {smokeTest, test} from '~playwright/core';

import {createSmokeScenarios} from '../../../stories/tests-factory/create-smoke-scenarios';
import {createSmokeScenarios} from '../../../../stories/tests-factory/create-smoke-scenarios';
import type {TabsProps} from '../Tabs';

import {directionCases, sizeCases} from './cases';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Flame} from '@gravity-ui/icons';
import userEvent from '@testing-library/user-event';

import {render, screen} from '../../../../test-utils/utils';
import {render, screen} from '../../../../../test-utils/utils';
import {TabsItem} from '../TabsItem';

const tabId = 'tab-id';
Expand All @@ -12,7 +12,7 @@ test('should render tab item by default', () => {
const component = screen.getByRole('tab');

expect(component).toBeVisible();
expect(component).not.toHaveClass('g-tabs__item_active');
expect(component).not.toHaveClass('g-tabs-legacy__item_active');
expect(component).toHaveAttribute('aria-selected', 'false');
expect(component).toHaveAttribute('aria-disabled', 'false');
});
Expand All @@ -22,7 +22,7 @@ test('should render active tab item', () => {
const component = screen.getByRole('tab');

expect(component).toBeVisible();
expect(component).toHaveClass('g-tabs__item_active');
expect(component).toHaveClass('g-tabs-legacy__item_active');
expect(component).toHaveAttribute('aria-selected', 'true');
});

Expand Down Expand Up @@ -70,7 +70,7 @@ test('should render id if title is empty', () => {
const titleComponent = screen.getByText(tabId);

expect(component).toContainElement(titleComponent);
expect(titleComponent).toHaveClass('g-tabs__item-title');
expect(titleComponent).toHaveClass('g-tabs-legacy__item-title');
});

test('should render counter', () => {
Expand All @@ -82,7 +82,7 @@ test('should render counter', () => {
const counterComponent = screen.getByText(counter);

expect(counterComponent).toBeVisible();
expect(counterComponent).toHaveClass('g-tabs__item-counter');
expect(counterComponent).toHaveClass('g-tabs-legacy__item-counter');
expect(component).toContainElement(counterComponent);
});

Expand Down Expand Up @@ -126,7 +126,7 @@ test('should render meta', () => {
const metaComponent = screen.getByText(meta);

expect(metaComponent).toBeVisible();
expect(metaComponent).toHaveClass('g-tabs__item-meta');
expect(metaComponent).toHaveClass('g-tabs-legacy__item-meta');
expect(component).toContainElement(metaComponent);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Cases} from '../../../stories/tests-factory/models';
import type {Cases} from '../../../../stories/tests-factory/models';
import type {TabsProps} from '../Tabs';
import {TabsDirection} from '../Tabs';

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/components/legacy/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Popover';
export * from './Tabs';
Loading
Loading