Skip to content

Commit

Permalink
chore(group): modify markdown editor style
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnsonMao committed Nov 17, 2024
1 parent 3f6bc88 commit be2fc6e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
9 changes: 7 additions & 2 deletions components/Group/GroupList/GroupCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ function GroupCard({
<span>{formatToString(partnerEducationStep, '皆可')}</span>
</StyledText>
</StyledInfo>
<StyledText lineClamp="2" fontSize="14px" style={{ height: '48px' }}>
<MarkdownEditor value={content?.split('\n')[0]} suppressLinkDefaultPrevent readOnly />
<StyledText lineClamp="2" fontSize="14px" style={{ height: '42px' }}>
<MarkdownEditor
value={content?.split('\n')[0]}
disabledProse
suppressLinkDefaultPrevent
readOnly
/>
</StyledText>
<StyledAreas>
<LocationOnOutlinedIcon fontSize="16px" sx={{ color: '#536166' }} />
Expand Down
7 changes: 6 additions & 1 deletion components/Profile/MyGroup/GroupCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ function GroupCard({
<StyledContainer>
<StyledTitle>{title}</StyledTitle>
<StyledText lineClamp="2" style={{ height: '42px' }}>
<MarkdownEditor readOnly value={content?.split('\n')[0]} suppressLinkDefaultPrevent />
<MarkdownEditor
readOnly
value={content?.split('\n')[0]}
disabledProse
suppressLinkDefaultPrevent
/>
</StyledText>
<StyledAreas>
<LocationOnOutlinedIcon fontSize="16px" sx={{ color: '#536166' }} />
Expand Down
12 changes: 10 additions & 2 deletions shared/components/MarkdownEditor/MarkdownEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ function InternalMarkdownEditor(
editorClassName,
onChange,
suppressLinkDefaultPrevent = false,
disabledProse = false,
},
ref
) {
const id = useId();
const checkLinkRef = useRef(null);
const markdown = useRef(value);
const editorSelectors = 'markdown-editor';
const pluginsSettings = useMemo(
() =>
Object.entries(generatePluginsSettings({ diffMarkdown: markdown.current }))
Expand All @@ -87,13 +89,18 @@ function InternalMarkdownEditor(
);

useEffect(() => {
const editor = document.getElementById(id).querySelector('.prose');
const editor = document.getElementById(id).querySelector(`.${editorSelectors}`);

const handleClick = (e) => {
if (suppressLinkDefaultPrevent) {
return;
}

if (!readOnly) {
e.preventDefault();
return;
}

let { target } = e;
while (target.tagName !== 'A') {
if (editor === target) break;
Expand Down Expand Up @@ -121,7 +128,8 @@ function InternalMarkdownEditor(
suppressHtmlProcessing
className={className}
contentEditableClassName={cn(
'prose',
editorSelectors,
disabledProse ? 'disabled-prose' : 'prose',
readOnly && '!p-0',
editorClassName
)}
Expand Down
8 changes: 7 additions & 1 deletion shared/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@
.prose li[role=checkbox] {
@apply indent-1 relative before:translate-y-1 after:absolute after:top-1/2 after:-translate-y-2/3 after:rotate-45;
}
}
.disabled-prose li {
@apply my-0;
}
.disabled-prose a {
@apply text-basic-black;
}
}

0 comments on commit be2fc6e

Please sign in to comment.