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(tab):generic id type added to TabItem #223

Merged
merged 3 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 15 additions & 15 deletions src/tab/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import classNames from "classnames";
import TabHeaderItem from "./header/item/TabHeaderItem";
import List from "../list/List";

export type TabItem = {
id: string;
export type TabItem<ID = string | number> = {
tatata96 marked this conversation as resolved.
Show resolved Hide resolved
id: ID;
content: React.ReactNode;
icon?: React.ReactNode;
isDisabled?: boolean;
};

interface UncontrolledTabProps {
items: TabItem[];
interface UncontrolledTabProps<ID> {
items: TabItem<ID>[];
tatata96 marked this conversation as resolved.
Show resolved Hide resolved
children: React.ReactNode[];
testid?: string;
initialActiveTabIndex?: number;
Expand All @@ -26,16 +26,16 @@ interface UncontrolledTabProps {
// and initialActiveTabIndex should be undefined
type ControlledTabProps =
| {
activeTabIndex: number;
onTabChange: (index: number) => void;
initialActiveTabIndex?: number;
}
activeTabIndex: number;
onTabChange: (index: number) => void;
initialActiveTabIndex?: number;
}
| {
activeTabIndex?: number;
onTabChange?: (index: number) => void;
};
activeTabIndex?: number;
onTabChange?: (index: number) => void;
};

export type TabProps = ControlledTabProps & UncontrolledTabProps;
export type TabProps = ControlledTabProps & UncontrolledTabProps<string | number>;
tatata96 marked this conversation as resolved.
Show resolved Hide resolved

function Tab({
testid,
Expand Down Expand Up @@ -70,9 +70,9 @@ function Tab({
<div className={"tab__body"} data-testid={`${testid}.body`}>
{
children[
activeTabIndexFromProps === undefined
? activeTabIndex
: activeTabIndexFromProps
activeTabIndexFromProps === undefined
? activeTabIndex
: activeTabIndexFromProps
]
}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/tab/header/item/TabHeaderItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {TabItem} from "../../Tab";
import ListItem from "../../../list/item/ListItem";

type TabHeaderItemProps = {
tab: TabItem;
tab: TabItem<string | number>;
tatata96 marked this conversation as resolved.
Show resolved Hide resolved
onClick: (index: number) => void;
isActive: boolean;
index: number;
Expand Down