Guest User

Custom accordion Yoopta example

a guest
Sep 29th, 2024
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 1.91 KB | Source Code | 0 0
  1. const CustomAccordionRender = ({editorData, children, saveEditor}: CustomAccordionProps) => {
  2.     return (
  3.         <Accordion type={"single"} className={"w-full"} collapsible>
  4.             <AccordionItem value={"item-1"} className={"border border-t rounded"}>
  5.                 <AccordionTrigger>{children}</AccordionTrigger>
  6.                 <AccordionContent className={"pt-4 w-full"}>
  7.                         <YooptaEditor className={"!w-full p-2"} editor={editor} plugins={plugins} marks={MARKS} tools={TOOLS}/>
  8.                 </AccordionContent>
  9.             </AccordionItem>
  10.         </Accordion>
  11.     )
  12. }
  13.  
  14. export const CustomAccordion = new YooptaPlugin({
  15.     type: 'Accordion',
  16.     elements: {
  17.         bigtext: {
  18.             // @ts-ignore
  19.             render: CustomAccordionRender,
  20.             props: {
  21.                 nodeType: 'block',
  22.                 children: {
  23.                     text: "",
  24.                 },
  25.                 editorData: getEditorInitialValue(false),
  26.                 saveEditor: () => {},
  27.             },
  28.         }
  29.     },
  30.     options: {
  31.         shortcuts: ['accordion', 'acc', 'ac'],
  32.         description: 'Accordion with editor',
  33.         icon: <TfiLayoutAccordionMerged />,
  34.         display: {
  35.             title: 'Accordion',
  36.             description: 'Accordion with editor',
  37.             icon: <TfiLayoutAccordionMerged />,
  38.         }
  39.     }
  40. })
  41.  
  42. in editorData we receive and empty (or with some text in) paragraph - a something like that:
  43.  
  44. [uniqueBlockId]: {
  45.           "id": uniqueBlockId,
  46.           "value": [
  47.             {
  48.               "id": "bc5adfd0-d697-4aee-ba10-5209a9901207",
  49.               "type": "paragraph",
  50.               "children": [
  51.                 {
  52.                   "text": ""
  53.                 }
  54.               ]
  55.             }
  56.           ],
  57.           "type": "Paragraph",
  58.           "meta": {
  59.             "order": 0,
  60.             "depth": 0
  61.           }
  62.         }
Advertisement
Add Comment
Please, Sign In to add comment