From b147df9d32e63094031da0ccb96e216f9e3e2c54 Mon Sep 17 00:00:00 2001 From: simonguo Date: Fri, 4 Jul 2025 11:28:41 +0800 Subject: [PATCH] feat(types): add support for data-* attributes in button props - Extend ButtonHTMLAttributes to support custom data-* attributes - Update type definitions in CodeEditor and Renderer components - Ensure type safety while allowing flexible data attributes --- docs/index.tsx | 1 + src/CodeEditor.tsx | 14 +++++++------- src/CodeView.tsx | 7 ++++++- src/CopyCodeButton.tsx | 21 +++++++++++---------- src/MarkdownRenderer.tsx | 1 + src/Renderer.tsx | 13 ++++++++++--- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/docs/index.tsx b/docs/index.tsx index 5e09579..6072ef9 100644 --- a/docs/index.tsx +++ b/docs/index.tsx @@ -31,6 +31,7 @@ const App = () => { return
Footer
; }} copyButtonProps={{ + 'data-appearence': 'subtle', className: 'rs-btn-icon rs-btn-icon-circle rs-btn rs-btn-subtle rs-btn-xs' }} > diff --git a/src/CodeEditor.tsx b/src/CodeEditor.tsx index f3f7712..8f761f0 100644 --- a/src/CodeEditor.tsx +++ b/src/CodeEditor.tsx @@ -4,7 +4,10 @@ import CopyCodeButton from './CopyCodeButton'; export interface CodeEditorProps extends Omit, 'onChange'> { code?: string; editorConfig?: EditorConfiguration; - copyCodeButtonAs?: React.ElementType; + copyButtonAs?: React.ElementType; + copyButtonProps?: React.HTMLAttributes & { + [key: `data-${string}`]: string; + }; onChange?: (code?: string) => void; onInitialized?: (editor: EditorFromTextArea) => void; } @@ -30,7 +33,8 @@ async function importCodeMirror() { } const CodeEditor = React.forwardRef((props: CodeEditorProps, ref: React.Ref) => { - const { code, editorConfig, copyCodeButtonAs, onChange, onInitialized, ...rest } = props; + const { code, editorConfig, copyButtonAs, copyButtonProps, onChange, onInitialized, ...rest } = + props; const textareaRef = useRef(null); const editor = useRef(null); @@ -68,11 +72,7 @@ const CodeEditor = React.forwardRef((props: CodeEditorProps, ref: React.Ref - + {!initialized &&
Editor initializing ...
}