Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3d0493f
docs: add typescript examples
SergeyKazarinov May 4, 2025
0607bab
Merge branch 'main' into docs/docs-site-ts
SergeyKazarinov May 4, 2025
d128864
refactor: formatting code in docs-site
SergeyKazarinov May 4, 2025
09fa619
feat: Update TypeScript examples from string to actual components by …
balajis-qb Sep 10, 2025
a69680c
feat: integrate esbuild-wasm for TypeScript transpilation in examples
balajis-qb Sep 11, 2025
e585449
feat: add copy-to-clipboard functionality to code examples
balajis-qb Sep 11, 2025
fc984d1
feat: add Toast component for code copy and transpile-error notificat…
balajis-qb Sep 12, 2025
ca8c4f6
refactor: simplify ExampleCustomInputProps by removing unused props
balajis-qb Sep 12, 2025
54bb930
migrate: Change index.jsx to tsx
balajis-qb Sep 12, 2025
db57608
feat: add TypeScript declaration for PNG images
balajis-qb Sep 12, 2025
bde4eac
fix: update script source in index.html from index.jsx to index.tsx
balajis-qb Sep 12, 2025
d06541e
feat: enhance TypeScript support in examples
balajis-qb Sep 12, 2025
c9a3504
refactor: rename state variables in date picker examples for clarity
balajis-qb Sep 15, 2025
a5b953d
restore: Restore the changes made on 7a954283e359e5b0a2055fe34f017c38…
balajis-qb Sep 15, 2025
26b9a07
Merge branch 'main' into enhancement/docs-site-ts
balajis-qb Sep 15, 2025
260bbae
refactor: remove redundant style condition in RenderCustomHeaderTwoMo…
balajis-qb Sep 15, 2025
86e1a41
refactor: rename state variables in date picker examples for consiste…
balajis-qb Sep 15, 2025
e4b27a5
fix: remove the wrong destructure of range from DateFNS
balajis-qb Sep 15, 2025
0d2dc05
chore: remove unused date picker javascript example files that got co…
balajis-qb Sep 15, 2025
47ae74d
Merge branch 'main' into enhancement/docs-site-ts
balajis-qb Sep 15, 2025
41043d5
Merge branch 'main' into enhancement/docs-site-ts
balajis-qb Sep 16, 2025
2b37f40
Restore main repo yarn.lock changes as the branch changes are scopped…
balajis-qb Sep 29, 2025
8b4935e
Merge branch 'main' into enhancement/docs-site-ts
balajis-qb Sep 30, 2025
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
2 changes: 1 addition & 1 deletion docs-site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.jsx"></script>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
11 changes: 9 additions & 2 deletions docs-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"private": true,
"type": "module",
"dependencies": {
"copy-to-clipboard": "^3.3.3",
"date-fns": "^4.1.0",
"esbuild-wasm": "^0.25.9",
"highlight.js": "^11.11.1",
"lodash": "^4.17.21",
"prism-react-renderer": "^2.4.1",
Expand All @@ -16,21 +18,26 @@
},
"scripts": {
"start": "vite",
"build": "vite build",
"build": "tsc && vite build",
"lint": "eslint .",
"preview": "vite preview"
"preview": "vite preview",
"type-check": "tsc --noEmit"
},
"devDependencies": {
"@eslint/js": "^9.35.0",
"@types/lodash": "^4.17.0",
"@types/react": "^19.1.13",
"@types/react-dom": "^19.1.9",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@vitejs/plugin-react": "^5.0.3",
"eslint": "^9.35.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^6.0.0",
"eslint-plugin-react-refresh": "^0.4.20",
"globals": "^16.4.0",
"sass": "^1.92.1",
"typescript": "^5.7.2",
"vite": "^7.1.6"
},
"packageManager": "[email protected]"
Expand Down
61 changes: 61 additions & 0 deletions docs-site/src/components/App/Toast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useState, useEffect, useRef } from "react";
import { createPortal } from "react-dom";

import "./toast.scss";

type ToastType = "success" | "error";

let showToastFn: ((message: string, type: ToastType) => void) | null;

export const toast = {
show: (message: string, type: ToastType) => {
if (showToastFn) {
showToastFn(message, type);
}
},
};

const Toast = (): React.ReactPortal | null => {
const [toastMeta, setToastMeta] = useState<{
message: string;
type?: ToastType;
}>({
message: "",
});
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const clearTimer = () => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
};

const scheduleToastReset = () => {
clearTimer();
timerRef.current = setTimeout(() => {
setToastMeta({ message: "" });
}, 3000);
};

useEffect(() => {
showToastFn = (message: string, type: ToastType) => {
setToastMeta({ message, type });
scheduleToastReset();
};

return () => {
clearTimer();
showToastFn = null;
};
}, []);

const { message, type } = toastMeta;
if (!message?.trim()) return null;

return createPortal(
<div className={`toast toast--${type}`}>{message}</div>,
document.body,
);
};

export default Toast;
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { useEffect, useState } from "react";
import DatePicker from "react-datepicker";
import ExampleComponents from "../Examples";
import Toast from "./Toast";
import { initializeTsxTransformer } from "../tsxTransformer";
import logo from "./logo.png";
import ribbon from "./ribbon.png";

const Example = () => {
const [isOpen, setIsOpen] = useState(true);
const [startDate, setStartDate] = useState(new Date());
const [isScrolled, setIsScrolled] = useState(true);
const Example: React.FC = () => {
const [isOpen, setIsOpen] = useState<boolean>(true);
const [startDate, setStartDate] = useState<Date | null>(new Date());
const [isScrolled, setIsScrolled] = useState<boolean>(true);

useEffect(() => {
const handleScroll = () => setIsScrolled(window.scrollY < 400);
const handleScroll = (): void => setIsScrolled(window.scrollY < 400);
document.addEventListener("scroll", handleScroll);

initializeTsxTransformer();

return () => {
document.removeEventListener("scroll", handleScroll);
};
Expand All @@ -22,7 +26,7 @@ const Example = () => {
<DatePicker
open={isOpen && isScrolled}
selected={startDate}
onChange={(date) => {
onChange={(date: Date | null) => {
setStartDate(date);
setIsOpen(false);
}}
Expand All @@ -31,7 +35,7 @@ const Example = () => {
);
};

const Root = () => (
const Root: React.FC = () => (
<div>
<div className="hero">
<div className="hero__content">
Expand Down Expand Up @@ -107,6 +111,8 @@ const Root = () => (
<a href="https://github.com/Hacker0x01/react-datepicker/">
<img className="github-ribbon" src={ribbon} alt="Fork me on GitHub" />
</a>

<Toast />
</div>
);

Expand Down
27 changes: 27 additions & 0 deletions docs-site/src/components/App/toast.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$toast-success-color: #009688;
$toast-error-color: #ef5350;

.toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);

display: inline-block;
color: #fff;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5);
border-radius: 5px;
padding: 10px 20px;
font-size: 14px;
font-weight: 600;
text-align: center;
z-index: 1000;

&--success {
background-color: $toast-success-color;
}

&--error {
background-color: $toast-error-color;
}
}
3 changes: 3 additions & 0 deletions docs-site/src/components/Example/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 0 additions & 66 deletions docs-site/src/components/Example/index.jsx

This file was deleted.

Loading
Loading