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 type id added to tabItem #216

Closed
wants to merge 2 commits into from
Closed
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hipo/react-ui-toolkit",
"version": "1.0.0",
"version": "1.0.1",
"description": "React based UI toolkit.",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {InputProps as InputComponentProps} from "./form/input/util/inputTypes";
import PasswordInput, {
PasswordInputProps as PasswordInputComponentProps
} from "./form/password-input/PasswordInput";
import NumberInput from "./form/input/number/NumberInput";
import {NumberInputProps as NumberInputComponentProps} from "./form/input/number/util/numberInputTypes";
import FileInput, {
FileInputProps as FileInputComponentProps
} from "./form/input/file/FileInput";
Expand Down Expand Up @@ -73,6 +75,7 @@ export {
// Components
FormField,
Input,
NumberInput,
FileInput,
PasswordInput,
CheckboxInput,
Expand Down Expand Up @@ -110,6 +113,7 @@ export {
// Types
export type FormFieldProps = FormFieldComponentProps;
export type InputProps = InputComponentProps;
export type NumberInputProps = NumberInputComponentProps;
export type FileInputProps = FileInputComponentProps;
export type PasswordInputProps = PasswordInputComponentProps;
export type CheckboxInputProps = CheckboxInputComponentProps;
Expand All @@ -132,7 +136,7 @@ export type ButtonProps = ButtonComponentProps;
export type DescriptionTermProps = DescriptionTermComponentProps;
export type FileUploadButtonProps = FileUploadButtonComponentProps;
export type SpinnerProps = SpinnerComponentProps;
export type TabItem = TabComponentItem;
export type TabItem <ID = number|string> = TabComponentItem <ID>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you run prettify formatter to format all the files?

I think we can define the generic type for TabItem in Tab file instead of index.tsx:

export type TabItem<ID = number | string> = {
  id: ID;
  ...
};

export type TabProps = TabComponentProps;
export type ProgressBarProps = ProgressBarComponentProps;
export type TextareaProps = TextareaComponentProps;
Expand Down
12 changes: 7 additions & 5 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> = {
id: ID;
content: React.ReactNode;
icon?: React.ReactNode;
isDisabled?: boolean;
};

interface UncontrolledTabProps {
items: TabItem[];
interface UncontrolledTabProps<ID> {
items: TabItem<ID>[];
children: React.ReactNode[];
testid?: string;
initialActiveTabIndex?: number;
Expand All @@ -35,7 +35,7 @@ type ControlledTabProps =
onTabChange?: (index: number) => void;
};

export type TabProps = ControlledTabProps & UncontrolledTabProps;
export type TabProps = ControlledTabProps & UncontrolledTabProps<string | number>;

function Tab({
testid,
Expand All @@ -49,6 +49,8 @@ function Tab({
const [activeTabIndex, setActiveTabIndex] = useState(initialActiveTabIndex);
const tabClassName = classNames("tab", customClassName);

console.log(items);

Comment on lines +52 to +53
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove this I think

return (
<div className={tabClassName}>
<List testid={`${testid}.header`} customClassName={"tab__header"} items={items}>
Expand Down
6 changes: 3 additions & 3 deletions src/tab/header/item/TabHeaderItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import classNames from "classnames";
import {TabItem} from "../../Tab";
import ListItem from "../../../list/item/ListItem";

type TabHeaderItemProps = {
tab: TabItem;
type TabHeaderItemProps<ID> = {
tab: TabItem<ID>;
onClick: (index: number) => void;
isActive: boolean;
index: number;
testid?: string;
};

function TabHeaderItem({testid, tab, onClick, index, isActive}: TabHeaderItemProps) {
function TabHeaderItem({testid, tab, onClick, index, isActive}: TabHeaderItemProps<number|string>) {
return (
<ListItem
customClassName={classNames("tab-header-item", {
Expand Down
2 changes: 1 addition & 1 deletion src/tab/tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {TabItem, TabProps} from "./Tab";
import {Tab} from "..";
import {testA11y} from "../core/utils/test/testUtils";

const tabItems: TabItem[] = [
const tabItems: TabItem<string>[] = [
{
id: "tab-item-1",
content: <div data-testid={"uncontrolled-tab.content-0"}>{"Tab Item 0"}</div>
Expand Down