Skip to content

Commit 78af0a6

Browse files
committed
feat(CodeEditor): add comprehensive download functionality for editor content
- Introduced a `downloadContent` method to the CodeEditor ref for programmatic file downloads, supporting various file extensions based on the editor's language. - Integrated a download button in the Panel's secondary menu for direct content downloads, with proper filename handling. - Enhanced context support for child components via `CodeEditorContext`, allowing custom UI implementations for downloads. - Implemented content validation to prevent downloads of empty or whitespace-only content, providing user-friendly warnings. - Updated TypeScript definitions and added extensive tests to ensure robust functionality and user experience.
1 parent 26785ac commit 78af0a6

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

.changeset/honest-clocks-join.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@leafygreen-ui/code-editor': minor
3+
---
4+
5+
**Feature**: Add download functionality to CodeEditor component
6+
7+
- **Imperative API**: Added `downloadContent(filename?)` method to CodeEditor ref handle for programmatic file downloads
8+
- **Smart file extensions**: Automatic file extension mapping based on editor language (`.js`, `.ts`, `.py`, `.css`, etc.) with fallback to `.txt`
9+
- **Panel integration**: Download button in Panel secondary menu now performs actual file downloads with proper filename handling
10+
- **Context support**: Download function available to child components via `CodeEditorContext` for custom UI implementations
11+
- **Content validation**: Prevents downloads of empty or whitespace-only content with user-friendly warnings
12+
- **Enhanced TypeScript**: Complete `downloadContent` method documentation in `CodeEditorHandle` interface
13+
- **Comprehensive testing**: Behavior-focused tests that verify actual download triggers rather than implementation details
14+
- **Language support**: Built-in extension mapping for 16+ languages including JavaScript, TypeScript, Python, Java, Go, Rust, and more
15+
16+
**Technical implementation**: Uses browser-native Blob API and temporary anchor elements for downloads. Maintains full backward compatibility while adding new download capabilities. Language extension mapping ensures downloaded files have appropriate extensions for syntax highlighting in external editors.

0 commit comments

Comments
 (0)