Skip to content

fix(useResponsiveContentPadding - TypeScript): adjust types #5039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/base/src/hooks/useResponsiveContentPadding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ const useStyles = createUseStyles<Range>(
{ name: 'StdExtPadding' }
);

export function useResponsiveContentPadding(element: HTMLElement, returnRangeString?: boolean): string;
export function useResponsiveContentPadding(element: HTMLElement, returnRangeString: true): [string, Range];
export function useResponsiveContentPadding(
element: HTMLElement | undefined | null,
returnRangeString?: boolean
): string;

export function useResponsiveContentPadding(
element: HTMLElement | undefined | null,
returnRangeString: true
): [string, Range];

/**
* Hook for creating a style class, which sets `padding-left` and `padding-right` depending on the width of the element.
Expand All @@ -26,7 +33,7 @@ export function useResponsiveContentPadding(element: HTMLElement, returnRangeStr
* @param {boolean} [returnRangeString=false] If set to `true`, returns a tuple with the class name and range.
* @returns {(string|Array)} If `returnRangeString` is `true`, the hook returns a tuple with the class name on first and the range string on second position. Otherwise, only the class name string is returned.
*/
export function useResponsiveContentPadding(element: HTMLElement, returnRangeString = false) {
export function useResponsiveContentPadding(element: HTMLElement | undefined | null, returnRangeString = false) {
const [currentRange, setCurrentRange] = useState(() => getCurrentRange()?.name ?? 'Desktop');
const classes = useStyles();
const requestAnimationFrameRef = useRef<number | undefined>();
Expand Down