Skip to content

Commit

Permalink
Merge pull request #24 from DiSSCo/MarkdownEditorForDescriptionField
Browse files Browse the repository at this point in the history
Add Markup editor to text field and descriptions to all fields
  • Loading branch information
TomDijkema authored Oct 28, 2024
2 parents e1637d0 + 373e29e commit 0ec2e5b
Show file tree
Hide file tree
Showing 12 changed files with 5,693 additions and 2,037 deletions.
7,666 changes: 5,634 additions & 2,032 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@mdxeditor/editor": "^3.14.0",
"@react-keycloak/web": "^3.4.0",
"@reduxjs/toolkit": "^2.2.2",
"axios": "^1.6.7",
Expand Down
5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,9 @@ p {
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}

/* MDX editor toolbar */
.mdxeditor-toolbar {
z-index: 0 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ const BooleanField = (props: Props) => {
/>
</Col>
</Row>
<Row>
<Col>
<p className="fs-5 tc-grey">
{field.description}
</p>
</Col>
</Row>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const FormBuilder = (props: Props) => {
} case 'text': {
return <TextField field={field}
values={values}
SetFieldValue={(fieldName: string, value: string) => SetFieldValue(fieldName, value)}
/>;
} default: {
return <StringField field={field}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const FormFieldTitle = (props: Props) => {
<p>
{field.title}
</p>
<p className="fs-5 tc-grey">
{field.description}
</p>
</Col>
{(field.required && !isEmpty(values) && !jp.value(values, field.jsonPath)) &&
<Col className="d-flex align-items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const RORField = (props: Props) => {
<p>
{field.title}
</p>
<p className="fs-5 tc-grey">
{field.description}
</p>
</Col>
{(field.required && !isEmpty(values) && isEmpty(jp.value(values, field.jsonPath)?.['schema:identifier'])) &&
<Col className="d-flex align-items-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const SelectField = (props: Props) => {
/>
<Select placeholder="Select an option"
options={selectItems.toSorted((a, b) => a.label > b.label ? 1 : 0)}
className={formFieldClass}
className={`${formFieldClass} mt-1`}
onChange={(dropdownOption) => SetFieldValue(jsonPath, dropdownOption?.value)}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const SoftwareLicenses = (props: Props) => {
<p>
{field.title}{field.required ? <span className="tc-grey"> *</span> : ''}
</p>
<p className="fs-5 tc-grey">
{field.description}
</p>
<Select
placeholder="Select an option"
options={selectItems.toSorted((a, b) => a.label > b.label ? 1 : 0)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const StringArrayField = (props: Props) => {
<p>
{field.title}
</p>
<p className="fs-5 tc-grey">
{field.description}
</p>
</Col>
{(field.required && !isEmpty(values) && !jp.value(values, field.jsonPath)?.find((value: string) => !!value)) &&
<Col className="d-flex align-items-center">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* Import Dependencies */
import {
MDXEditor, UndoRedo, BlockTypeSelect, BoldItalicUnderlineToggles, CreateLink,
linkDialogPlugin, ListsToggle, listsPlugin, headingsPlugin, codeMirrorPlugin, toolbarPlugin
} from '@mdxeditor/editor';
import classNames from 'classnames';
import { Field } from "formik";
import jp from 'jsonpath'
import { isEmpty } from 'lodash';

Expand All @@ -14,18 +17,20 @@ import FormFieldTitle from './FormFieldTitle';
/* Props Type */
type Props = {
field: FormField,
values: Dict
values: Dict,
SetFieldValue: Function
};


/**
* Component that renders an input text field for a free, long text insert
* @param field The provided form field
* @param values The current values in the form state
* @param SetFieldValue Function to set the value of a form field
* @returns JSX Component
*/
const TextField = (props: Props) => {
const { field, values } = props;
const { field, values, SetFieldValue } = props;

/* Class Names */
const formFieldClass = classNames({
Expand All @@ -37,10 +42,32 @@ const TextField = (props: Props) => {
<FormFieldTitle field={field}
values={values}
/>
<Field name={field.jsonPath.replace('$', '')}
{/* <Field name={field.jsonPath.replace('$', '')}
as="textarea"
rows="6"
className={`${formFieldClass} w-100 mt-1 py-1 px-2 br-corner`}
/> */}
<MDXEditor markdown=""
className={`${formFieldClass} b-grey br-corner mt-1 z-0`}
plugins={[
codeMirrorPlugin({ codeBlockLanguages: { js: 'JavaScript', css: 'CSS' } }),
headingsPlugin(),
linkDialogPlugin(),
listsPlugin(),
toolbarPlugin({
toolbarContents: () => (
<>
{' '}
<UndoRedo />
<BlockTypeSelect />
<BoldItalicUnderlineToggles />
<CreateLink />
<ListsToggle />
</>
)
})
]}
onChange={(text: string) => SetFieldValue(field.jsonPath.replace('$', ''), text)}
/>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Provider } from 'react-redux';
import { setupStore } from './app/Store';

/* Import Styles */
import '@mdxeditor/editor/style.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import "react-datepicker/dist/react-datepicker.css";

Expand Down

0 comments on commit 0ec2e5b

Please sign in to comment.