NotionX / react-notion-x

Fast and accurate React renderer for Notion. TS batteries included. ⚡️
https://react-notion-x-demo.transitivebullsh.it
MIT License
4.87k stars 570 forks source link

Export default components so that they can be overriden easily #402

Open utkuturunc opened 2 years ago

utkuturunc commented 2 years ago

Description

I'd like to be able to use custom components only for certain cases such as:

more examples could be found.

The idea

const components = useMemo(() => {
   Embed: (props) => {
       if (props.smt === 'criteria') { return <div>something</div> }
       return <defaultComponents.Embed {...props} />
   }
}, [...]);

Notion Test Page ID

N/A

transitive-bullshit commented 2 years ago

This is a great idea.

Some of the blocks already support this, and some don't. The challenge is just to create a common typed format and go through and replace all block usage with this type of pattern.

bmitchinson commented 1 year ago

For those looking for a shortcut to alter the attributes of <video> elements, you can use patch-package

Before:

// node_modules/react-notion-x/build/index.js
createElement("video", {
        playsInline: true,
        controls: true,
        preload: "metadata",
        style: assetStyle,
        src: source,
        title: block.type
      });

Example After:

// node_modules/react-notion-x/build/index.js
createElement("video", {
        autoPlay: true,
        playsInline: true,
        loop: true,
        muted: true,
        controls: false,
        preload: "metadata",
        style: assetStyle,
        src: source,
        title: block.type,
      });
AntoineDuComptoirDesPharmacies commented 11 months ago

Same request here but extended to every component block (Text, Heading, ...). Indeed, it will allow to instantiate a Notion page according to the design of the hosting website (with its components from storybook) without having to override/repeat all the CSS by hand.

BougaCaillou commented 6 months ago

Searching for a way to provide my own components for various types of blocks like previously mentioned (Text, Heading, ...), I found my way here, and looking at open PRs it seems like this one is promising.

I tested it in my projet and with very little tinkering was able to make this work for my workflow. At this time I use this as a drop-in replacement over react-notion-x (will see when/if this gets approved). It looks like it didn't quit pass some checks regarding the minimal demo project, I wanted to look into it but was unable to (vercel causing me some trouble), although it might be a minimal issue.