Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue using a custom preview component with code-input #95

Open
ejmudrak opened this issue Jan 23, 2024 · 0 comments
Open

Issue using a custom preview component with code-input #95

ejmudrak opened this issue Jan 23, 2024 · 0 comments

Comments

@ejmudrak
Copy link

ejmudrak commented Jan 23, 2024

Describe the bug
When inserting code-input blocks into rich text, specifying any ObjectComponents elements for the components property of a field causes the code-input's form inputs to change to a less usable state. The language select becomes a text box, and the code text editor loses syntax highlighting and other options. Perhaps supplying anything for components is overwriting the default functionality?

To Reproduce

Try adding the components property below to a field with type: 'code'.

export default [
  {
    type: 'block',
    of: [
      defineArrayMember({
        type: 'code',
        name: 'code',
        title: 'Code',
        icon: CodeIcon,
        components: {
          preview: () => (
            <div style={{fontSize: '12px', display: 'flex', alignItems: 'center', padding: '3px'}}>
              <CodeIcon />
              <span style={{marginLeft: '5px'}}>Code Snippet</span>
            </div>
          ),
        },
      }),
    ],
  },
]

The custom preview component looks like this, see the <> Code Snippet here:
Screenshot 2024-01-23 at 2 28 37 PM

Expected behavior

What I'm trying to accomplish is to customize the preview component for a code-input, so that the actual code doesn't render in the editor -- this is because the default code-input preview overlaps with other text when adding it inline.

Screenshots

The expected behavior of code-input:
Screenshot 2024-01-22 at 11 43 38 AM

The issue behavior of code-input, when the components property is given:
Screenshot 2024-01-22 at 11 43 47 AM

What the current code-input preview looks like, without trying to customize it:
Screenshot 2024-01-23 at 2 21 44 PM

Which versions of Sanity are you using?

@sanity/cli (global) 3.23.4 (latest: 3.26.0)

What operating system are you using?

MacOS Sonoma 14.1.1

Which versions of Node.js / npm are you running?

Node 17

npm 8.18.0, Node 17.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant