Skip to content
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

fix: component props bug #29

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions src/components/as.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ElementType, forwardRef, ReactElement } from "react";
import { ComponentProps, AsProp, RefOfType } from "./types";
import { AsInProps, AsOutProps, RefOfType } from "./types";

export const as = <T extends ElementType, ExtraProps = unknown>(
export const as = <DefaultType extends ElementType, ExtraProps = object>(
fc: (
props: Omit<ComponentProps<T>, keyof ExtraProps | keyof AsProp<T>> & AsProp<T> & ExtraProps,
ref: RefOfType<T>
) => ReactElement
props: AsInProps<DefaultType, ExtraProps>,
ref: RefOfType<DefaultType>
) => ReactElement | null
) =>
forwardRef(fc) as unknown as <E extends ElementType = T>(
props: Omit<ComponentProps<E>, keyof ExtraProps | keyof AsProp<E>> & AsProp<E> & ExtraProps
) => ReactElement;
forwardRef(fc) as unknown as <T extends ElementType = DefaultType>(
props: AsOutProps<T, ExtraProps>
) => ReturnType<typeof fc>;
5 changes: 4 additions & 1 deletion src/components/checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import React, { AllHTMLAttributes, forwardRef } from "react";
import { Icon, Icons } from "../icon";
import * as css from "./Checkbox.css";

type CheckboxProps = Omit<AllHTMLAttributes<HTMLInputElement>, "children" | "onChange" | "type"> &
type CheckboxProps = Omit<
AllHTMLAttributes<HTMLInputElement>,
"children" | "onChange" | "type" | "size"
> &
css.CheckboxVariants & {
defaultChecked?: boolean;
checked?: boolean;
Expand Down
13 changes: 9 additions & 4 deletions src/components/scroll/Scroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
useLayoutEffect(() => {
if (scrollLocalRef.current) {
const $scroll = scrollLocalRef.current;
const xScrollbarWidth = $scroll.offsetHeight - $scroll.clientHeight;
const yScrollbarWidth = $scroll.offsetWidth - $scroll.clientWidth;
if (size === "0") {
$scroll.setAttribute("data-x-scrollbar-width", "0");
$scroll.setAttribute("data-y-scrollbar-width", "0");
} else {
const xScrollbarWidth = $scroll.offsetHeight - $scroll.clientHeight;
const yScrollbarWidth = $scroll.offsetWidth - $scroll.clientWidth;

$scroll.setAttribute("data-x-scrollbar-width", `${xScrollbarWidth}`);
$scroll.setAttribute("data-y-scrollbar-width", `${yScrollbarWidth}`);
$scroll.setAttribute("data-x-scrollbar-width", `${xScrollbarWidth}`);
$scroll.setAttribute("data-y-scrollbar-width", `${yScrollbarWidth}`);
}
}
}, [size]);

Expand All @@ -38,7 +43,7 @@
if (r) scrollLocalRef.current = r;
if (ref) {
if ("current" in ref) {
const propRef: any = ref;

Check warning on line 46 in src/components/scroll/Scroll.tsx

View workflow job for this annotation

GitHub Actions / Build pull request

Unexpected any. Specify a different type

Check warning on line 46 in src/components/scroll/Scroll.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
propRef.current = r;
}
if (typeof ref === "function") {
Expand Down
21 changes: 19 additions & 2 deletions src/components/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ComponentPropsWithRef, ElementType, PropsWithChildren } from "react";
import {
ComponentPropsWithoutRef,
ComponentPropsWithRef,
ElementType,
PropsWithChildren,
} from "react";

export type MainColor = "Primary" | "Secondary" | "Success" | "Warning" | "Critical";

Expand All @@ -18,4 +23,16 @@ export type AsProp<E extends ElementType> = {
as?: E;
};

export type ComponentProps<E extends ElementType> = PropsWithChildren<ComponentPropsWithRef<E>>;
export type AsInProps<E extends ElementType, ExtraProps = object> = Omit<
PropsWithChildren<ComponentPropsWithoutRef<E>>,
keyof ExtraProps | keyof AsProp<ElementType>
> &
ExtraProps &
AsProp<E>;

export type AsOutProps<E extends ElementType, ExtraProps = object> = Omit<
PropsWithChildren<ComponentPropsWithRef<E>>,
keyof ExtraProps | keyof AsProp<ElementType>
> &
ExtraProps &
AsProp<E>;
Loading