Skip to content

Commit

Permalink
fix(Button): better exports (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
aversini authored Sep 16, 2024
1 parent 58808cd commit 2abb463
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/ui-button/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import { BaseButton } from "../private/BaseButton";
import { BaseButton_private as BaseButton } from "../private/BaseButton";
import type { ButtonProps } from "./ButtonTypes";
import { TYPE_BUTTON, getButtonClasses } from "./utilities";

Expand Down
2 changes: 1 addition & 1 deletion packages/ui-button/src/components/Button/ButtonIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import clsx from "clsx";
import React from "react";

import { BaseButton } from "../private/BaseButton";
import { BaseButton_private as BaseButton } from "../private/BaseButton";
import type { ButtonIconProps } from "./ButtonTypes";
import { TYPE_ICON, getButtonClasses } from "./utilities";

Expand Down
7 changes: 3 additions & 4 deletions packages/ui-button/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "../common/constants";

export * from "./Button/Button";
export * from "./Button/ButtonIcon";
export * from "./Button/ButtonLink";
export * from "../common/constants";

import { ButtonSort as ButtonSort_private } from "./private/ButtonSort";
export { ButtonSort_private };
export * from "./private/ButtonSort";
31 changes: 16 additions & 15 deletions packages/ui-button/src/components/private/BaseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ const internalClick = (
};
/* c8 ignore end */

export const BaseButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
(buttonProps: any, ref) => {
const { onClick, noInternalClick = false, ...otherProps } = buttonProps;
return (
<button
ref={ref}
onClick={(e) => {
internalClick(e, noInternalClick, onClick);
}}
{...otherProps}
/>
);
},
);
export const BaseButton_private = React.forwardRef<
HTMLButtonElement,
ButtonProps
>((buttonProps: any, ref) => {
const { onClick, noInternalClick = false, ...otherProps } = buttonProps;
return (
<button
ref={ref}
onClick={(e) => {
internalClick(e, noInternalClick, onClick);
}}
{...otherProps}
/>
);
});

BaseButton.displayName = "BaseButton";
BaseButton_private.displayName = "BaseButton";
9 changes: 6 additions & 3 deletions packages/ui-button/src/components/private/ButtonSort.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import clsx from "clsx";
import React from "react";

import { TYPE_ICON, getButtonClasses } from "../Button/utilities";
import { BaseButton } from "./BaseButton";
import { BaseButton_private as BaseButton } from "./BaseButton";
import type { ButtonSortProps } from "./ButtonSortTypes";

export const ButtonSort = React.forwardRef<HTMLButtonElement, ButtonSortProps>(
export const ButtonSort_private = React.forwardRef<
HTMLButtonElement,
ButtonSortProps
>(
(
{
children,
Expand Down Expand Up @@ -95,4 +98,4 @@ export const ButtonSort = React.forwardRef<HTMLButtonElement, ButtonSortProps>(
},
);

ButtonSort.displayName = "ButtonSort";
ButtonSort_private.displayName = "ButtonSort";
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconSettings } from "@versini/ui-icons";

import { expectToHaveClasses } from "../../../../../../configuration/tests-helpers";
import { BUTTON_CLASSNAME } from "../../../common/constants";
import { ButtonSort } from "../ButtonSort";
import { ButtonSort_private as ButtonSort } from "../ButtonSort";

describe("ButtonSort (exceptions)", () => {
it("should be able to require/import from root", () => {
Expand Down

0 comments on commit 2abb463

Please sign in to comment.