Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import React from "react";

import { COLORS } from "../constants";

export interface Period {
start: string | null;
end: string | null;
}

interface CustomShortcuts {
[key: string]: ShortcutsItem;
}

interface DefaultShortcuts {
today?: string;
yesterday?: string;
Expand All @@ -25,7 +22,6 @@ export interface Configs {
apply?: string;
};
}

export interface ShortcutsItem {
text: string;
daysNumber?: number;
Expand All @@ -34,34 +30,25 @@ export interface ShortcutsItem {
end: Date | string;
};
}

export type DateType = string | null | Date;

export type DateRangeType = {
startDate: DateType;
endDate: DateType;
};

export type DateValueType = DateRangeType | null;

export type ClassNamesTypeProp = {
container?: (p?: object | null | undefined) => string | undefined;
input?: (p?: object | null | undefined) => string | undefined;
toggleButton?: (p?: object | null | undefined) => string | undefined;
footer?: (p?: object | null | undefined) => string | undefined;
};

export type PopoverDirectionType = "up" | "down";

export interface DatepickerType {
export interface DatepickerTypeBase {
primaryColor?: ColorKeys;
value: DateValueType;
onChange: (value: DateValueType, e?: HTMLInputElement | null | undefined) => void;
useRange?: boolean;
showFooter?: boolean;
showShortcuts?: boolean;
configs?: Configs;
asSingle?: boolean;
placeholder?: string;
separator?: string;
startFrom?: Date | null;
Expand All @@ -84,10 +71,24 @@ export interface DatepickerType {
popoverDirection?: PopoverDirectionType;
}

export type ColorKeys = (typeof COLORS)[number]; // "blue" | "orange"
export interface DatepickerSingle extends DatepickerTypeBase {
asSingle: true;
value: DateType;
onChange: (value: DateType, e?: HTMLInputElement | null | undefined) => void;
}

export interface DatepickerRange extends DatepickerTypeBase {
asSingle?: false;
value: DateValueType;
onChange: (value: DateValueType, e?: HTMLInputElement | null | undefined) => void;
}

export type DatepickerType = DatepickerSingle | DatepickerRange;

export type ColorKeys = (typeof COLORS)[number];
export interface Colors {
[key: string]: {
[K in ColorKeys]: string;
};
}
export {};
58 changes: 33 additions & 25 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
{
"compilerOptions": {
"target": "esnext",
"lib": ["dom", "esnext"],
"module": "esnext",
"jsx": "preserve",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"baseUrl": "src/",
"declaration": true,
"outDir": "./dist",
"inlineSources": true,
"sourceMap": true,
"rootDir": "src",
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"resolveJsonModule": true,
"isolatedModules": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
"compilerOptions": {
"target": "esnext",
"lib": [
"dom",
"esnext"
],
"module": "esnext",
"jsx": "preserve",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"baseUrl": "src/",
"declaration": true,
"outDir": "./dist",
"inlineSources": true,
"sourceMap": true,
"rootDir": "src",
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"resolveJsonModule": true,
"isolatedModules": true,
"incremental": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}