Skip to content

Conversation

balajis-qb
Copy link
Contributor

@balajis-qb balajis-qb commented Sep 15, 2025

Description

Migrates docs-site examples from JavaScript to TypeScript, adds in-browser TypeScript transpilation via esbuild-wasm, and improves UX with copy-to-clipboard and toast notifications.

As I added live transpilation support, we don't need to maintain two separate code base of TypeScript and Javascript. I created this branch from an existing PR authored by @SergeyKazarinov. I used the TS configuration setup by him as a base and added all my changes on top of it.

Changes

  • TypeScript migration: Replaces docs-site/src/examples/*.js with docs-site/src/examples/ts/*.tsx variants across all examples. I also noticed in the initial PR, we were maintaining typescript code as a string, but I feel making changes to those examples will be difficult as editor auto-help won't help in that case, so I changed all those examples to tsx
  • Added Globals for react-live scope: Added live-provider-globals.d.ts with the scope imports to avoid type errors in TSX files for the unimported functions. Moved all Date Utils functions to DateFNS & updated all the usage of Date utils to DateFNS.***() to avoid redeclaring all date_utils functions in the typescript global declaration file.
  • Live TS transpilation: Integrates esbuild-wasm and adds tsxTransformer.ts for client-side transpile of example code.
  • Copy UX: Adds copy-to-clipboard on examples and a Toast component for success/error notifications.
  • App bootstrap to TS: Renames index.jsxindex.tsx, updates docs-site/index.html script reference, and converts vite.config.js → vite.config.ts.
  • Types and configs: Adds tsconfig.json, tsconfig.node.json, images.d.ts, and types/ for better typings (It was already configured in the base PR).
  • Refactors/cleanup: Standardizes example state variable names, removes unused props, and tidies styles and components.

Screenshots

image image
React-Datepicker-crafted-by-HackerOne.2.mp4

To reviewers

@martijnrusschen Please take your time to review this PR and let me know if any changes required.

Thank you @SergeyKazarinov, I used your PR as a base to this PR and mostly reused the TS config and examples and added my changes on top of it. If you have time, you also gothrough the changes I made and let me know if any changes required.

Contribution checklist

  • I have followed the contributing guidelines.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

SergeyKazarinov and others added 19 commits May 4, 2025 13:55
…skipping the type check for the files

- Added a custom tsconfig.json to skip the type checking inside examples/
- Made TypeScript tab is the default tab for documentation
- Added `esbuild-wasm` as a dependency to enable TypeScript transpilation.
- Implemented `tsxTransformer` for transforming TSX code to JSX.
- Updated `CodeExampleComponent` to handle TSX code and display transpiled output.
- Enhanced example configuration to support new TSX examples.
- Removed the duplicate javascript code base examples from examples/js/*.js
- Styled loading state for transpilation in examples.
- Integrated `copy-to-clipboard` library to enable copying code snippets.
- Added a copy icon button in the code example component for user interaction.
- Styled action buttons for better user experience in the examples section.
- Introduced a new SVG icon for the copy action.
…ions

- Introduced a new Toast component to display success and error messages.
- Integrated Toast notifications in the CodeExampleComponent for user feedback on actions like code copying and transpilation errors.
- Added corresponding styles for the Toast component in a new SCSS file.
- Removed unnecessary props from ExampleCustomInputProps to streamline the component's interface.
- Improved code clarity and maintainability by focusing on essential properties.
- Introduced a new TypeScript declaration file to support importing PNG images in the project.
- This addition enhances type safety and improves the development experience when working with image assets.
- Updated tsconfig.json for examples to include new compiler options and exclude specific files.
- Introduced a new live-provider-globals.d.ts file to declare global variables and types that we configured for react-live.
- Refactored examples to use globally declared DateFNS methods.
- Add the DATEFNS directly to the react-live scope instead of destructuring it, as it avoid declaring all utilities of date-fns
- Fixed the type related issues in the examples.
- Updated state variable names from `startDate` and `setStartDate` to `selectedDate` and `setSelectedDate` across multiple date picker examples.
- This change enhances code readability and consistency in the examples.
- Clone of the commit 5aa5985
…nths example. Related commit: 7a95428

- Eliminated the visibility style condition for the previous navigation button when customHeaderCount is 1, simplifying the component's logic.
- This change enhances code clarity and reduces unnecessary complexity in the example.
…ncy. Related commit 5aa5985

- Updated state variable names from `selectedDate` to `selectedDateTime` across multiple date picker examples.
- This change improves code clarity and maintains consistency in the examples.
…pied unintentionally during the merge with main branch

- Deleted the customRangeSeparator.js and customWeekClassName.js example files as they are no longer needed.
- This cleanup helps maintain a more streamlined and relevant codebase.
Copy link

codecov bot commented Sep 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.26%. Comparing base (80a0d93) to head (41043d5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5865   +/-   ##
=======================================
  Coverage   97.26%   97.26%           
=======================================
  Files          30       30           
  Lines        3443     3443           
  Branches     1455     1439   -16     
=======================================
  Hits         3349     3349           
  Misses         94       94           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@balajis-qb balajis-qb force-pushed the enhancement/docs-site-ts branch from 6dc06e5 to 0d2dc05 Compare September 15, 2025 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants