From d70f44991f10e4495ad802ca1139b510bff8d9bf Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sat, 1 Jul 2023 12:08:55 +0800 Subject: [PATCH] Extract actions out of react-refractor Use actions externally. --- .../src/packages/react-refractor/index.tsx | 22 ++------------- .../src/pages/examples/blog-post/index.tsx | 28 +++++++++++-------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/packages/web-kitchensink-reactnext/src/packages/react-refractor/index.tsx b/packages/web-kitchensink-reactnext/src/packages/react-refractor/index.tsx index 7d2d3de..282cccc 100644 --- a/packages/web-kitchensink-reactnext/src/packages/react-refractor/index.tsx +++ b/packages/web-kitchensink-reactnext/src/packages/react-refractor/index.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import RefractorCore from 'react-refractor/all'; import styles from './style.module.css'; -import {getFormValues} from '@theoryofnekomata/formxtra'; import {Marker} from 'react-refractor'; type PrismDerivedElement = HTMLDivElement; @@ -30,20 +29,6 @@ export const Refractor = React.forwardRef(({ markers = [], ...etcProps }, forwardedRef) => { - const handleAction: React.FormEventHandler = React.useCallback((e) => { - e.preventDefault(); - const { currentTarget, nativeEvent } = e; - const { submitter } = nativeEvent as unknown as { submitter: HTMLButtonElement }; - const { action } = getFormValues(currentTarget, { submitter }); - switch (action) { - case 'copyContents': - console.log('copy contents'); - break; - default: - break; - } - }, []); - const code = codeRaw.trim(); return ( @@ -58,11 +43,8 @@ export const Refractor = React.forwardRef(({
{language}
-
- {actions} -
+ {actions} + )}
{ + const handleAction: React.FormEventHandler = React.useCallback((e) => { + e.preventDefault(); + const { currentTarget, nativeEvent } = e; + const { submitter } = nativeEvent as unknown as { submitter: HTMLButtonElement }; + const { action } = getFormValues(currentTarget, { submitter }); + switch (action) { + case 'copyContents': + console.log('copy contents'); + break; + default: + break; + } + }, []); + return ( <>
@@ -13,7 +28,7 @@ const BlogPostPage: NextPage = () => { Use @modal-soft/react-refractor as follows on your page:

-
+
{ language="tsx" scroll actions={ - <> - - + <> } code={`import {Refractor} from '@modal-soft/react-refractor'; import {NextPage} from 'next';