Skip to content

Commit

Permalink
fix: export CustomTooltipProps and fix button transition (#930)
Browse files Browse the repository at this point in the history
* fix: findDOMNode is deprecated in StrictMode (#907) (#924)

* Add react-transition-state library

* replace `react-transition-group` with `react-transition-state`

* fix: reconfigure CustomTooltipProps

* fix: add theme tokens to legend slider (#929)

---------

Co-authored-by: Touha Zohair <[email protected]>
Co-authored-by: christopherkindl <[email protected]>
  • Loading branch information
3 people authored Jan 23, 2024
1 parent 0fa9bef commit 7e857c5
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 121 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@headlessui/tailwindcss": "^0.2.0",
"date-fns": "^2.30.0",
"react-day-picker": "^8.9.1",
"react-transition-group": "^4.4.5",
"react-transition-state": "^2.1.1",
"recharts": "^2.10.3",
"tailwind-merge": "^1.14.0"
},
Expand Down Expand Up @@ -64,7 +64,6 @@
"@types/jest": "^27.5.2",
"@types/node": "^20.10.2",
"@types/react": "^18.2.41",
"@types/react-transition-group": "^4.4.9",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"autoprefixer": "^10.4.16",
Expand Down
35 changes: 8 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/components/chart-elements/DonutChart/DonutChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { DonutChartTooltip } from "./DonutChartTooltip";
import { parseData, parseLabelInput } from "./inputParser";

import type { EventProps } from "components/chart-elements/common";
import { CustomTooltipType } from "components/chart-elements/common/CustomTooltipProps";
import { CustomTooltipProps } from "components/chart-elements/common/CustomTooltipProps";
import type BaseAnimationTimingProps from "../common/BaseAnimationTimingProps";

type DonutChartVariant = "donut" | "pie";
Expand All @@ -35,7 +35,7 @@ export interface DonutChartProps extends BaseAnimationTimingProps {
noDataText?: string;
className?: string;
onValueChange?: (value: EventProps) => void;
customTooltip?: React.ComponentType<CustomTooltipType>;
customTooltip?: React.ComponentType<CustomTooltipProps>;
}

const renderInactiveShape = (props: any) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/chart-elements/ScatterChart/ScatterChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
getYAxisDomain,
} from "../common/utils";

import { CustomTooltipType } from "components/chart-elements/common/CustomTooltipProps";
import { CustomTooltipProps } from "components/chart-elements/common/CustomTooltipProps";
import {
BaseColors,
colorPalette,
Expand Down Expand Up @@ -73,7 +73,7 @@ export interface ScatterChartProps
noDataText?: string;
enableLegendSlider?: boolean;
onValueChange?: (value: EventProps) => void;
customTooltip?: React.ComponentType<CustomTooltipType>;
customTooltip?: React.ComponentType<CustomTooltipProps>;
rotateLabelX?: {
angle: number;
verticalShift: number;
Expand Down
4 changes: 2 additions & 2 deletions src/components/chart-elements/common/BaseChartProps.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Color, ValueFormatter, IntervalType } from "../../../lib";
import type BaseAnimationTimingProps from "./BaseAnimationTimingProps";
import { CustomTooltipType } from "./CustomTooltipProps";
import { CustomTooltipProps } from "./CustomTooltipProps";

type FixedProps = {
eventType: "dot" | "category" | "bar" | "slice" | "bubble";
Expand Down Expand Up @@ -34,7 +34,7 @@ interface BaseChartProps extends BaseAnimationTimingProps, React.HTMLAttributes<
noDataText?: string;
onValueChange?: (value: EventProps) => void;
enableLegendSlider?: boolean;
customTooltip?: React.ComponentType<CustomTooltipType>;
customTooltip?: React.ComponentType<CustomTooltipProps>;
rotateLabelX?: {
angle: number;
verticalShift?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NameType, Payload } from "recharts/types/component/DefaultTooltipContent";

export type CustomTooltipType = {
export type CustomTooltipProps = {
payload: Payload<string | number | (string | number)[], string | number>[] | undefined;
active: boolean | undefined;
label: NameType | undefined;
Expand Down
1 change: 1 addition & 0 deletions src/components/chart-elements/common/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export type { EventProps } from "./BaseChartProps";
export type { CustomTooltipProps } from "./CustomTooltipProps";
1 change: 1 addition & 0 deletions src/components/chart-elements/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from "./AreaChart";
export * from "./BarChart";
export { EventProps } from "./common/BaseChartProps";
export { CustomTooltipProps } from "./common/CustomTooltipProps";
export * from "./DonutChart";
export * from "./LineChart";
export * from "./ScatterChart";
134 changes: 68 additions & 66 deletions src/components/input-elements/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";
import Tooltip, { useTooltip } from "components/util-elements/Tooltip/Tooltip";
import React from "react";
import { Transition } from "react-transition-group";
import React, { useEffect } from "react";
import { useTransition, type TransitionStatus } from "react-transition-state";

import { HorizontalPositions, makeClassName, mergeRefs, Sizes, tremorTwMerge } from "lib";

Expand All @@ -17,7 +17,7 @@ export interface ButtonIconOrSpinnerProps {
iconPosition: string;
Icon: React.ElementType | undefined;
needMargin: boolean;
transitionState: string;
transitionStatus: TransitionStatus;
}

export const ButtonIconOrSpinner = ({
Expand All @@ -26,7 +26,7 @@ export const ButtonIconOrSpinner = ({
iconPosition,
Icon,
needMargin,
transitionState,
transitionStatus,
}: ButtonIconOrSpinnerProps) => {
Icon = Icon!;

Expand All @@ -52,7 +52,7 @@ export const ButtonIconOrSpinner = ({
"animate-spin shrink-0",
margin,
spinnerSize.default,
spinnerSize[transitionState],
spinnerSize[transitionStatus],
)}
style={{ transition: `width 150ms` }}
/>
Expand Down Expand Up @@ -113,71 +113,73 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =>
const delay = 300;
const { tooltipProps, getReferenceProps } = useTooltip(delay);

const [transitionState, toggleTransition] = useTransition({ timeout: 50 });

useEffect(() => {
toggleTransition(loading);
}, [loading]);

return (
<Transition in={loading} timeout={50}>
{(state) => (
// eslint-disable-next-line react/button-has-type
<button
ref={mergeRefs([ref, tooltipProps.refs.setReference])}
// eslint-disable-next-line react/button-has-type
<button
ref={mergeRefs([ref, tooltipProps.refs.setReference])}
className={tremorTwMerge(
makeButtonClassName("root"),
// common
"flex-shrink-0 inline-flex justify-center items-center group font-medium outline-none",
buttonShapeStyles,
buttonProportionStyles.paddingX,
buttonProportionStyles.paddingY,
buttonProportionStyles.fontSize,
buttonColorStyles.textColor,
buttonColorStyles.bgColor,
buttonColorStyles.borderColor,
buttonColorStyles.hoverBorderColor,
!isDisabled
? tremorTwMerge(
getButtonColors(variant, color).hoverTextColor,
getButtonColors(variant, color).hoverBgColor,
getButtonColors(variant, color).hoverBorderColor,
)
: "opacity-50 cursor-not-allowed",
className,
)}
disabled={isDisabled}
{...getReferenceProps}
{...other}
>
<Tooltip text={tooltip} {...tooltipProps} />
{showButtonIconOrSpinner && iconPosition !== HorizontalPositions.Right ? (
<ButtonIconOrSpinner
loading={loading}
iconSize={iconSize}
iconPosition={iconPosition}
Icon={Icon}
transitionStatus={transitionState.status}
needMargin={needIconMargin}
/>
) : null}
{showLoadingText || children ? (
<span
className={tremorTwMerge(
makeButtonClassName("root"),
// common
"flex-shrink-0 inline-flex justify-center items-center group font-medium outline-none",
buttonShapeStyles,
buttonProportionStyles.paddingX,
buttonProportionStyles.paddingY,
buttonProportionStyles.fontSize,
buttonColorStyles.textColor,
buttonColorStyles.bgColor,
buttonColorStyles.borderColor,
buttonColorStyles.hoverBorderColor,
!isDisabled
? tremorTwMerge(
getButtonColors(variant, color).hoverTextColor,
getButtonColors(variant, color).hoverBgColor,
getButtonColors(variant, color).hoverBorderColor,
)
: "opacity-50 cursor-not-allowed",
className,
makeButtonClassName("text"),
"text-tremor-default whitespace-nowrap",
)}
disabled={isDisabled}
{...getReferenceProps}
{...other}
>
<Tooltip text={tooltip} {...tooltipProps} />
{showButtonIconOrSpinner && iconPosition !== HorizontalPositions.Right ? (
<ButtonIconOrSpinner
loading={loading}
iconSize={iconSize}
iconPosition={iconPosition}
Icon={Icon}
transitionState={state}
needMargin={needIconMargin}
/>
) : null}
{showLoadingText || children ? (
<span
className={tremorTwMerge(
makeButtonClassName("text"),
"text-tremor-default whitespace-nowrap",
)}
>
{showLoadingText ? loadingText : children}
</span>
) : null}
{showButtonIconOrSpinner && iconPosition === HorizontalPositions.Right ? (
<ButtonIconOrSpinner
loading={loading}
iconSize={iconSize}
iconPosition={iconPosition}
Icon={Icon}
transitionState={state}
needMargin={needIconMargin}
/>
) : null}
</button>
)}
</Transition>
{showLoadingText ? loadingText : children}
</span>
) : null}
{showButtonIconOrSpinner && iconPosition === HorizontalPositions.Right ? (
<ButtonIconOrSpinner
loading={loading}
iconSize={iconSize}
iconPosition={iconPosition}
Icon={Icon}
transitionStatus={transitionState.status}
needMargin={needIconMargin}
/>
) : null}
</button>
);
});

Expand Down
21 changes: 18 additions & 3 deletions src/components/text-elements/Legend/Legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,32 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
<>
<div
className={tremorTwMerge(
"absolute top-0 bottom-0 left-0 w-4 bg-gradient-to-r from-white to-transparent pointer-events-none",
// light mode
"from-tremor-background",
// dark mode
"dark:from-dark-tremor-background",
// common
"absolute top-0 bottom-0 left-0 w-4 bg-gradient-to-r to-transparent pointer-events-none",
)}
/>
<div
className={tremorTwMerge(
"absolute top-0 bottom-0 right-10 w-4 bg-gradient-to-r from-transparent to-white pointer-events-none",
// light mode
"to-tremor-background",
// dark mode
"dark:to-dark-tremor-background",
// common
"absolute top-0 bottom-0 right-10 w-4 bg-gradient-to-r from-transparent pointer-events-none",
)}
/>
<div
className={tremorTwMerge(
"absolute flex top-0 pr-1 bottom-0 right-0 items-center justify-center h-full bg-tremor-background",
// light mode
"bg-tremor-background",
// dark mode
"dark:bg-dark-tremor-background",
// common
"absolute flex top-0 pr-1 bottom-0 right-0 items-center justify-center h-full",
)}
>
<ScrollButton
Expand Down
Loading

0 comments on commit 7e857c5

Please sign in to comment.