Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paolostyle committed Feb 18, 2024
1 parent 7ac5d96 commit 8101893
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/visx-responsive/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const MySuperCoolVisxChart = ({ myProp, screenWidth, screenHeight }: Props) => {

const ChartToRender = withScreenSize(MySuperCoolVisxChart);

const chartToRender = <ChartToRender />;
const chartToRender = <ChartToRender myProp="string" />;

// ... Render the chartToRender somewhere
```
Expand Down Expand Up @@ -80,7 +80,7 @@ const MySuperCoolVisxChart = ({ myProp, parentWidth, parentHeight }: Props) => {

const ChartWithParentSize = withParentSize(MySuperCoolVisxChart);

const chartToRender = <ChartWithParentSize initialWidth={400} />;
const chartToRender = <ChartWithParentSize myProp="string" initialWidth={400} />;

// ... Render the chartToRender somewhere
```
Expand Down
9 changes: 9 additions & 0 deletions packages/visx-responsive/src/enhancers/withParentSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ interface PrivateWindow {
ResizeObserver: ResizeObserverPolyfill;
}

/**
* @deprecated
* @TODO remove in the next major version - exported for backwards compatibility
*/
export type WithParentSizeProps = Pick<
WithParentSizeConfig,
'debounceTime' | 'enableDebounceLeadingCall'
>;

type WithParentSizeConfig = {
debounceTime?: number;
enableDebounceLeadingCall?: boolean;
Expand Down
6 changes: 6 additions & 0 deletions packages/visx-responsive/src/enhancers/withScreenSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ type WithScreenSizeConfig = {
enableDebounceLeadingCall?: boolean;
};

/**
* @deprecated
* @TODO remove in the next major version - exported for backwards compatibility
*/
export type WithParentSizeProps = WithScreenSizeConfig;

type WithScreenSizeState = {
screenWidth?: number;
screenHeight?: number;
Expand Down
10 changes: 8 additions & 2 deletions packages/visx-responsive/test/withParentSize.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ describe('withParentSize', () => {
});

test('it should pass parentWidth and parentHeight props to its child', () => {
const HOC = withParentSize(Component, ResizeObserver);
const { getByTestId } = render(<HOC role="img" initialWidth={200} initialHeight={200} />);
const WrappedComponent = withParentSize(Component, ResizeObserver);

// @ts-expect-error ensure unknown types still error
render(<WrappedComponent unknown="prop" />);

const { getByTestId } = render(
<WrappedComponent role="img" initialWidth={200} initialHeight={200} />,
);

const RenderedComponent = getByTestId('Component');
expect(RenderedComponent).toHaveStyle('width: 200px; height: 200px');
Expand Down

0 comments on commit 8101893

Please sign in to comment.