Skip to content

Commit 5858229

Browse files
committed
feat: enhance GenericDescription component with improved toolbar and styling
1 parent 67538f4 commit 5858229

2 files changed

Lines changed: 89 additions & 26 deletions

File tree

src/Common/GenericDescription/GenericDescription.tsx

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { useMemo, useState } from 'react'
18-
import MDEditor, { commands } from '@uiw/react-md-editor'
18+
import MDEditor, { commands, MDEditorProps } from '@uiw/react-md-editor'
1919

2020
import { ReactComponent as BoldIcon } from '@Icons/ic-bold.svg'
2121
import { ReactComponent as CheckedListIcon } from '@Icons/ic-checked-list.svg'
@@ -31,18 +31,16 @@ import { ReactComponent as StrikethroughIcon } from '@Icons/ic-strikethrough.svg
3131
import { ReactComponent as UnorderedListIcon } from '@Icons/ic-unordered-list.svg'
3232

3333
import {
34-
AppThemeType,
3534
Button,
3635
ButtonStyleType,
3736
ButtonVariantType,
3837
ComponentSizeType,
3938
Icon,
4039
ToastManager,
4140
ToastVariantType,
42-
useTheme,
4341
} from '../../Shared'
4442
import Markdown from '../Markdown/MarkDown'
45-
import { showError } from '..'
43+
import { showError, Tooltip } from '..'
4644
import { DESCRIPTION_EMPTY_ERROR_MSG, DESCRIPTION_UNSAVED_CHANGES_MSG } from './constant'
4745
import { GenericDescriptionProps } from './types'
4846
import { getParsedUpdatedOnDate } from './utils'
@@ -94,14 +92,6 @@ const extraCommands = [
9492
...commands.checkedListCommand,
9593
icon: <CheckedListIcon className="icon-dim-16 flex" />,
9694
},
97-
{
98-
...commands.help,
99-
icon: (
100-
<div className="flex dc__no-shrink">
101-
<Icon name="ic-help-outline" color="N700" size={16} />
102-
</div>
103-
),
104-
},
10595
]
10696

10797
const GenericDescription = ({
@@ -118,23 +108,21 @@ const GenericDescription = ({
118108

119109
const [editorViewState, setEditorViewState] = useState<'write' | 'preview'>('write')
120110

121-
const { appTheme } = useTheme()
122-
123111
const _date = getParsedUpdatedOnDate(updatedOn)
124112

125113
const myCommands = useMemo(
126114
() => [
127115
{
128116
...commands.codeEdit,
129-
icon: <span className="fs-13 fw-6 lh-20">Write</span>,
117+
icon: <span className="fs-13 fw-4 lh-20">Write</span>,
130118
execute: (...props) => {
131119
setEditorViewState('write')
132120
return commands.codeEdit.execute(...props)
133121
},
134122
} satisfies typeof commands.codeEdit,
135123
{
136124
...commands.codePreview,
137-
icon: <span className="fs-13 fw-6 lh-20">Preview</span>,
125+
icon: <span className="fs-13 fw-4 lh-20">Preview</span>,
138126
execute: (...props) => {
139127
setEditorViewState('preview')
140128
return commands.codePreview.execute(...props)
@@ -207,9 +195,47 @@ const GenericDescription = ({
207195
}
208196

209197
const renderMarkdown = (source: string) => (
210-
<Markdown markdown={source} breaks disableEscapedText className="mh-150 pt-8" />
198+
<Markdown markdown={source} breaks disableEscapedText className="mh-150 pt-8 fs-14 fw-4 cn-9" />
211199
)
212200

201+
const renderToolbar: MDEditorProps['components']['toolbar'] = (
202+
command,
203+
disabled,
204+
executeCommand: (command, name) => void,
205+
index: number,
206+
) => {
207+
if (command.name === 'edit' || command.name === 'preview') {
208+
return (
209+
<button
210+
key={index}
211+
type="button"
212+
className="markdown-editor__tab-button flex dc__transparent p-4"
213+
onClick={() => executeCommand(command, command.name)}
214+
disabled={disabled}
215+
>
216+
{command.icon}
217+
</button>
218+
)
219+
}
220+
return (
221+
<Tooltip
222+
key={index}
223+
alwaysShowTippyOnHover={!!command.buttonProps?.title}
224+
content={command.buttonProps?.title}
225+
placement="top"
226+
>
227+
<button
228+
type="button"
229+
className="flex dc__transparent p-4 mr-4"
230+
onClick={() => executeCommand(command, command.name)}
231+
disabled={disabled}
232+
>
233+
{command.icon}
234+
</button>
235+
</Tooltip>
236+
)
237+
}
238+
213239
return (
214240
<div
215241
data-testid="generic-description-wrapper"
@@ -246,16 +272,16 @@ const GenericDescription = ({
246272
<MDEditor
247273
value={modifiedValue}
248274
onChange={setModifiedValue}
249-
data-color-mode={appTheme === AppThemeType.dark ? 'dark' : 'light'}
250275
commands={myCommands}
251276
extraCommands={extraCommands}
252277
preview={editorViewState === 'preview' ? 'preview' : 'edit'}
253278
components={{
254279
preview: renderMarkdown,
280+
toolbar: renderToolbar,
255281
}}
256282
/>
257283

258-
<div className="flexbox dc__content-end pt-12 pb-12 dc__contain--paint">
284+
<div className="flexbox dc__content-end pt-12 pb-12 dc__contain--paint border__primary--top">
259285
<div className="form__buttons dc__gap-16 px-16">
260286
<Button
261287
dataTestId="description-edit-cancel-button"

src/Common/GenericDescription/genericDescription.scss

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,48 @@
3131
}
3232

3333
.w-md-editor {
34+
background-color: transparent;
35+
box-shadow: none;
36+
3437
&-toolbar {
3538
border-bottom: 1px solid var(--border-primary);
3639
background-color: transparent;
3740
padding-inline: 16px;
38-
padding-block: 8px;
41+
padding-block: 0px;
3942
height: auto;
4043

41-
button {
42-
color: var(--N700);
43-
}
44+
li {
45+
.markdown-editor__tab-button {
46+
margin-block: 8px;
47+
background-color: var(--bg-primary);
48+
font-size: 13px;
49+
line-height: 20px;
50+
text-align: center;
51+
color: var(--N700);
52+
margin-right: 8px;
53+
}
54+
55+
&.active {
56+
position: relative;
57+
58+
.markdown-editor__tab-button {
59+
font-size: 13px;
60+
line-height: 20px;
61+
text-align: center;
62+
margin-right: 8px;
63+
color: var(--B500);
64+
}
65+
}
4466

45-
.active {
46-
&:hover,button {
47-
color: var(--B500);
67+
&.active::after {
68+
content: '';
69+
position: absolute;
70+
display: block;
71+
width: 100%;
72+
height: 2px;
73+
background-color: var(--B500);
74+
border-radius: 4px;
75+
bottom: 0px;
4876
}
4977
}
5078
}
@@ -66,6 +94,15 @@
6694
margin: 0px;
6795
padding: 8px 0px;
6896
}
97+
98+
.w-md-editor-input {
99+
display: flex;
100+
flex-direction: column;
101+
102+
.w-md-editor-text {
103+
flex-grow: 1;
104+
}
105+
}
69106
}
70107
}
71108
}

0 commit comments

Comments
 (0)