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

fix(examples): Hide edit button outside editor #30657

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions examples/nextjs/src/components/shared/contentlets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import React from 'react';
import { useMemo } from 'react';
import Image from 'next/image';
import { editContentlet } from '@dotcms/client';
import { editContentlet, isInsideEditor } from '@dotcms/client';

const dateFormatOptions = {
year: 'numeric',
Expand All @@ -10,27 +10,31 @@ const dateFormatOptions = {
};

function Contentlets({ contentlets }) {
const insideEditor = useMemo(isInsideEditor, []);

return (
<ul className="flex flex-col gap-7">
{contentlets.map((contentlet) => (
<li className="flex gap-7 min-h-16 relative" key={contentlet.identifier}>
<button
onClick={() => editContentlet(contentlet)}
style={{
color: 'black',
border: '1px solid black',
position: 'absolute',
bottom: 0,
right: 0,
width: '40px',
height: '20px',
zIndex: 1000,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
}}>
Edit
</button>
{insideEditor && (
<button
onClick={() => editContentlet(contentlet)}
style={{
color: 'black',
border: '1px solid black',
position: 'absolute',
bottom: 0,
right: 0,
width: '40px',
height: '20px',
zIndex: 1000,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
}}>
Edit
</button>
)}
<a className="relative min-w-32" href={contentlet.urlMap || contentlet.url}>
{contentlet.image && (
<Image
Expand Down