Skip to content

Commit

Permalink
fix: rename ExpandableTableRowCell for a better defined use area
Browse files Browse the repository at this point in the history
affects: @fremtind/jkl-table-react
  • Loading branch information
Jo Emil Holen committed Feb 2, 2022
1 parent 7cbf0d9 commit 4858b05
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
10 changes: 7 additions & 3 deletions packages/table-react/documentation/ExpandableTableExample.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { VFC } from "react";
import { ExampleComponentProps } from "../../../doc-utils";
import { Table, TableCaption, TableHead, TableRow, TableHeader, TableBody, TableCell } from "../src";
import { ExpandableTableRowCell, ExpandableTableRow } from "../src/";
import { ExpandableTableRowController, ExpandableTableRow } from "../src/";

const headings = ["Kravnr", "Kravtype", "Status", "Årsakskode", "Meldt dato"];

Expand Down Expand Up @@ -59,7 +59,11 @@ const ExpandableTableExample: VFC<ExampleComponentProps> = ({ boolValues, choice
{cell}
</TableCell>
))}
<ExpandableTableRowCell data-th="Mer informasjon" verticalAlign="center" compact={compact} />
<ExpandableTableRowController
data-th="Mer informasjon"
verticalAlign="center"
compact={compact}
/>
</ExpandableTableRow>
))}
</TableBody>
Expand Down Expand Up @@ -109,7 +113,7 @@ export const expandableTableExampleCode = ({ choiceValues }: ExampleComponentPro
{cell}
</TableCell>
))}
<ExpandableTableRowCell data-th="Mer informasjon" verticalAlign="center" />
<ExpandableTableRowController data-th="Mer informasjon" verticalAlign="center" />
</ExpandableTableRow>
))}
</TableBody>
Expand Down
4 changes: 2 additions & 2 deletions packages/table-react/src/ExpandableTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { FC, useState } from "react";
import cx from "classnames";
import { useAnimatedHeight } from "@fremtind/jkl-react-hooks";
import { ExpandableTableRowCell } from "./ExpandableTableRowCell";
import { ExpandableTableRowController } from "./ExpandableTableRowController";
import { TableRowProps, TableRow } from "./TableRow";

export interface ExpandableTableRowProps extends TableRowProps {
Expand Down Expand Up @@ -43,7 +43,7 @@ export const ExpandableTableRow: FC<ExpandableTableRowProps> = ({
{...rest}
>
{React.Children.map(children, (child) => {
if (React.isValidElement(child) && child.type == ExpandableTableRowCell) {
if (React.isValidElement(child) && child.type == ExpandableTableRowController) {
return React.cloneElement(child, {
isOpen,
onClick: () => setIsOpen(!isOpen),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import cx from "classnames";
import { ExpandButton } from "@fremtind/jkl-expand-button-react";
import { TableCell, TableCellProps } from ".";

export interface ExpandableTableRowCellProps extends TableCellProps {
export interface ExpandableTableRowControllerProps extends TableCellProps {
/** Settes automatisk av ExpandableTableRow */
isOpen?: boolean;
onClick?: () => void;
compact?: boolean;
}

export const ExpandableTableRowCell: React.FC<ExpandableTableRowCellProps> = ({
export const ExpandableTableRowController: React.FC<ExpandableTableRowControllerProps> = ({
isOpen,
onClick,
children,
Expand All @@ -19,7 +19,7 @@ export const ExpandableTableRowCell: React.FC<ExpandableTableRowCellProps> = ({
...rest
}) => {
if (isOpen === undefined || typeof onClick !== "function") {
throw new Error("ExpandableTableRowCell must have ExpandableTableRow as parent");
throw new Error("ExpandableTableRowController must have ExpandableTableRow as parent");
}

return (
Expand Down
4 changes: 2 additions & 2 deletions packages/table-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export { TableHead } from "./TableHead";
export { TableHeader } from "./TableHeader";
export { TableRow } from "./TableRow";
export { ExpandableTableRow } from "./ExpandableTableRow";
export { ExpandableTableRowCell } from "./ExpandableTableRowCell";
export { ExpandableTableRowController } from "./ExpandableTableRowController";

export type { DataTableProps } from "./DataTable";
export type { TableProps } from "./Table";
Expand All @@ -28,4 +28,4 @@ export type { TableHeadProps } from "./TableHead";
export type { TableHeaderProps } from "./TableHeader";
export type { TableRowProps } from "./TableRow";
export type { ExpandableTableRowProps } from "./ExpandableTableRow";
export type { ExpandableTableRowCellProps } from "./ExpandableTableRowCell";
export type { ExpandableTableRowControllerProps } from "./ExpandableTableRowController";

0 comments on commit 4858b05

Please sign in to comment.