Skip to content

Commit

Permalink
Merge pull request #156 from sasza2/feat/export-types-and-ref-change
Browse files Browse the repository at this point in the history
feat: export types and ref changes
  • Loading branch information
sasza2 authored Apr 26, 2024
2 parents c3f7e4c + 62c2dda commit 9da3cdd
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-deers-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sasza/react-panzoom": minor
---

export types and ref changes
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"exports": {
".": {
"import": "./dist/main.js",
"require": "./dist/main.umd.cjs"
"require": "./dist/main.umd.cjs",
"types": "./types/index.d.ts"
}
},
"keywords": [
Expand Down
7 changes: 4 additions & 3 deletions src/PanZoom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {
forwardRef, MutableRefObject, useLayoutEffect,
forwardRef, Ref, useLayoutEffect,
} from 'react';
import initPanZoom, { getAllowedProps } from 'panzoom-core';

Expand All @@ -8,7 +8,7 @@ import usePanZoom from './usePanZoom';

const panZoomAllowedProps = getAllowedProps();

const PanZoom: React.FC<PanZoomProps & { apiRef?: MutableRefObject<PanZoomApi> }> = ({
const PanZoom: React.FC<PanZoomProps & { apiRef?: Ref<PanZoomApi> }> = ({
apiRef,
children,
...props
Expand All @@ -27,14 +27,15 @@ const PanZoom: React.FC<PanZoomProps & { apiRef?: MutableRefObject<PanZoomApi> }
...props,
className: props.className || 'react-panzoom',
});
panZoomRef.current.setOptions(props)
setInitialized(true);
return panZoomRef.current.destroy;
}, []);

return render;
};

const PanZoomRef = forwardRef((props: PanZoomProps, ref: MutableRefObject<PanZoomApi>) => (
const PanZoomRef = forwardRef((props: PanZoomProps, ref: Ref<PanZoomApi>) => (
<PanZoom {...props} apiRef={ref} />
)) as React.FC<PanZoomPropsRef>;

Expand Down
5 changes: 3 additions & 2 deletions src/usePanZoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const usePanZoom = <T extends keyof PanZoomOptions, >({
props,
}: React.PropsWithChildren<{
allowedProps: Array<T>,
apiRef: React.MutableRefObject<PanZoomApi>,
apiRef: React.Ref<PanZoomApi>,
props: PanZoomOptions,
}>): PanZoomReturn => {
const childRef = useRef<HTMLDivElement>();
Expand All @@ -36,8 +36,9 @@ const usePanZoom = <T extends keyof PanZoomOptions, >({
}, deps);

useImperativeHandle(
apiRef,
initialized ? apiRef : undefined,
() => panZoomRef.current,
[initialized],
);

const value = useMemo(() => ({
Expand Down
4 changes: 2 additions & 2 deletions types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export type PanZoomOptions = {

export type PanZoomProps = React.PropsWithChildren<PanZoomOptions>

export type PanZoomPropsRef = PanZoomProps & { ref?: React.MutableRefObject<API> }
export type PanZoomPropsRef = PanZoomProps & { ref?: React.Ref<API> }

export type PanZoomWithCoverOmit = Omit<PanZoomOptions, 'boundary'>

Expand All @@ -102,7 +102,7 @@ export type PanZoomWithCoverProps = React.PropsWithChildren<{
} & PanZoomWithCoverOmit>

export type PanZoomWithCoverPropsRef = PanZoomWithCoverProps & {
ref?: React.MutableRefObject<API>
ref?: React.Ref<API>
}

export type PanZoomApi = {
Expand Down

0 comments on commit 9da3cdd

Please sign in to comment.