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

add a preview button for MarkDown when edit mode + add markdown in ch… #183

Merged
merged 2 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
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
66 changes: 43 additions & 23 deletions packages/react-app/src/components/field-input/text-field-input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TextInput, Markdown } from '@1hive/1hive-ui';
import { TextInput, Markdown, Button } from '@1hive/1hive-ui';
import { noop } from 'lodash-es';
import React, { ReactNode } from 'react';
import React, { ReactNode, useEffect, useState } from 'react';
import { CollapsableBlock } from 'src/collapsable-block';
import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';
Expand All @@ -21,6 +21,10 @@ const MaxLineStyled = styled.div`
}
`;

const BlockStyled = styled.div`
${({ wide }: any) => wide && 'width: 100%;'}
`;

// #endregion

type Props = {
Expand Down Expand Up @@ -63,6 +67,16 @@ export default function TextFieldInput({
tooltipDetail,
tooltip,
}: Props) {
const [isEditState, setIsEdit] = useState(isEdit);

useEffect(() => {
setIsEdit(isEdit);
}, [isEdit]);

const handlePreview = () => {
setIsEdit(!isEditState);
};

const readOnlyContent = (
<>
{isMarkDown ? (
Expand Down Expand Up @@ -114,28 +128,34 @@ export default function TextFieldInput({
)}
</>
);
const loadableContent = isEdit ? (
<TextInput
id={id}
value={value ?? ''}
wide={wide}
onChange={onChange}
placeHolder={placeHolder}
multiline={multiline}
style={css}
rows={rows}
/>
const loadableContent = isEditState ? (
<BlockStyled wide={wide}>
<TextInput
id={id}
value={value ?? ''}
wide={wide}
onChange={onChange}
placeHolder={placeHolder}
multiline={multiline}
style={css}
rows={rows}
/>
{isMarkDown && isEdit && <Button size="mini" label="Preview" onClick={handlePreview} />}
</BlockStyled>
) : (
<div style={{ ...css, fontSize }}>
{maxLine ? (
<div>
<MaxLineStyled maxLine={maxLine}>{readOnlyContent}</MaxLineStyled>
{ellipsis}
</div>
) : (
readOnlyContent
)}
</div>
<BlockStyled>
<div style={{ ...css, fontSize }}>
{maxLine ? (
<div>
<MaxLineStyled maxLine={maxLine}>{readOnlyContent}</MaxLineStyled>
{ellipsis}
</div>
) : (
readOnlyContent
)}
</div>
{isMarkDown && isEdit && <Button size="mini" label="Edit" onClick={handlePreview} />}
</BlockStyled>
);
return (
<FieldInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export default function ChallengeModal({ claim, challengeDeposit, onClose = noop
onChange={handleChange}
multiline
wide
isMarkDown
/>
</Outset>
</FormStyled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export default function ScheduleClaimModal({
wide
rows={5}
compact
isMarkDown
/>
<LineStyled>
<Outset horizontal>
Expand Down