Skip to content

Commit

Permalink
feat: updated type FileUploaderModes
Browse files Browse the repository at this point in the history
  • Loading branch information
egordidenko committed Nov 4, 2024
1 parent d0df7a2 commit 388386c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@uploadcare/file-uploader/web/uc-file-uploader-inline.min.css";
import { customElementToReactComponent } from "@uploadcare/react-adapter";
import { AdapterConfig } from "../core/AdapterConfig";
import { AdapterUploadCtxProvider } from "../core/AdapterUploadCtxProvider";
import type { FileUploaderModes, TProps } from "../types";
import type { TProps } from "../types";
import { getCalcPropertyOfProps } from "../../utils/getCalcPropertyOfProps";
import { getUserAgentIntegration } from "../../utils/getUserAgentIntegration";
import {
Expand All @@ -20,7 +20,7 @@ const AdapterFileUploaderInline = customElementToReactComponent({
elClass: UC.FileUploaderMinimal,
});

export const FileUploaderInline: FC<TProps<FileUploaderModes.Inline>> = ({
export const FileUploaderInline: FC<TProps<"Inline">> = ({
ctxName,
className,
classNameUploader,
Expand All @@ -31,7 +31,7 @@ export const FileUploaderInline: FC<TProps<FileUploaderModes.Inline>> = ({
const CTX_NAME = useMemo(() => ctxName ?? UC.UID.generate(), [ctxName]);

const { eventHandlers, config } = useMemo(
() => getCalcPropertyOfProps<FileUploaderModes.Inline>(props),
() => getCalcPropertyOfProps<"Inline">(props),
[props],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@uploadcare/file-uploader/web/uc-file-uploader-minimal.min.css";
import { customElementToReactComponent } from "@uploadcare/react-adapter";
import { AdapterConfig } from "../core/AdapterConfig";
import { AdapterUploadCtxProvider } from "../core/AdapterUploadCtxProvider";
import type { FileUploaderModes, TProps } from "../types";
import type { TProps } from "../types";
import { getCalcPropertyOfProps } from "../../utils/getCalcPropertyOfProps";
import { getUserAgentIntegration } from "../../utils/getUserAgentIntegration";
import {
Expand All @@ -20,7 +20,7 @@ const AdapterFileUploaderMinimal = customElementToReactComponent({
elClass: UC.FileUploaderMinimal,
});

export const FileUploaderMinimal: FC<TProps<FileUploaderModes.Minimal>> = ({
export const FileUploaderMinimal: FC<TProps<"Minimal">> = ({
ctxName,
className,
classNameUploader,
Expand All @@ -31,7 +31,7 @@ export const FileUploaderMinimal: FC<TProps<FileUploaderModes.Minimal>> = ({
const CTX_NAME = useMemo(() => ctxName ?? UC.UID.generate(), [ctxName]);

const { eventHandlers, config } = useMemo(
() => getCalcPropertyOfProps<FileUploaderModes.Minimal>(props),
() => getCalcPropertyOfProps<"Minimal">(props),
[props],
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@uploadcare/file-uploader/web/uc-file-uploader-regular.min.css";
import { customElementToReactComponent } from "@uploadcare/react-adapter";
import { AdapterConfig } from "../core/AdapterConfig";
import { AdapterUploadCtxProvider } from "../core/AdapterUploadCtxProvider";
import type { FileUploaderModes, TProps } from "../types";
import type { TProps } from "../types";

import { getCalcPropertyOfProps } from "../../utils/getCalcPropertyOfProps";
import { getUserAgentIntegration } from "../../utils/getUserAgentIntegration";
Expand All @@ -21,7 +21,7 @@ const AdapterFileUploaderRegular = customElementToReactComponent({
elClass: UC.FileUploaderRegular,
});

export const FileUploaderRegular: FC<TProps<FileUploaderModes.Regular>> = ({
export const FileUploaderRegular: FC<TProps<"Regular">> = ({
ctxName,
className,
classNameUploader,
Expand All @@ -32,7 +32,7 @@ export const FileUploaderRegular: FC<TProps<FileUploaderModes.Regular>> = ({
const CTX_NAME = useMemo(() => ctxName ?? UC.UID.generate(), [ctxName]);

const { eventHandlers, config, uploader } = useMemo(
() => getCalcPropertyOfProps<FileUploaderModes.Regular>(props),
() => getCalcPropertyOfProps<"Regular">(props),
[props],
);

Expand Down
9 changes: 2 additions & 7 deletions packages/react-uploader/src/Uploader/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ type TExtraPrefixOn<S extends string> = `on${Capitalize<S>}`;

type TPrefixOnAndCamelCase<S extends string> = TExtraPrefixOn<TToCamelCase<S>>;

export enum FileUploaderModes {
Regular = "Regular",
Minimal = "Minimal",
Inline = "Inline"
}

export type FileUploaderModesKeys = keyof typeof FileUploaderModes;
export type FileUploaderModes = 'Regular' | 'Minimal' | 'Inline'

type CommonProps = {
/**
Expand Down Expand Up @@ -60,7 +55,7 @@ export type ConfigProps = Partial<Omit<ConfigType, "pubkey">> & {
pubkey: ConfigType["pubkey"];
};

export type TProps<T extends FileUploaderModesKeys> = CommonProps &
export type TProps<T extends FileUploaderModes> = CommonProps &
ConfigProps &
EventProps &
UploadCtxPropviderProps &
Expand Down
4 changes: 2 additions & 2 deletions packages/react-uploader/src/utils/getCalcPropertyOfProps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FileUploaderModesKeys, TProps } from "../Uploader/types";
import type { FileUploaderModes, TProps } from "../Uploader/types";

export const getCalcPropertyOfProps = <T extends FileUploaderModesKeys>(props: TProps<T>) => {
export const getCalcPropertyOfProps = <T extends FileUploaderModes>(props: TProps<T>) => {
const eventHandlers: Record<string, unknown> = {};
const config: Record<string, unknown> = {};
const uploader: Record<string, unknown> = {};
Expand Down

0 comments on commit 388386c

Please sign in to comment.