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 text zoom in simplified text #2806

Merged
merged 2 commits into from
Jan 10, 2024
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
16 changes: 15 additions & 1 deletion app/views/EntryEdit/LeftPane/SimplifiedTextView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface Props {
assistedTaggingEnabled: boolean;
projectId: string | undefined;
frameworkDetails?: Framework;
textZoomValue?: number | undefined;
}

function SimplifiedTextView(props: Props) {
Expand All @@ -87,6 +88,7 @@ function SimplifiedTextView(props: Props) {
disableDiscardButton,
disableAddButton,
frameworkDetails,
textZoomValue,
} = props;

const containerRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -328,7 +330,19 @@ function SimplifiedTextView(props: Props) {
disableAddButton && styles.disabled,
)}
>
{children}
<div className={_cs(
styles.simplifiedText,
textZoomValue === 1 && styles.xSmall,
textZoomValue === 2 && styles.small,
textZoomValue === 3 && styles.medium,
textZoomValue === 4 && styles.large,
textZoomValue === 5 && styles.xLarge,
textZoomValue === 6 && styles.xxLarge,
textZoomValue === 7 && styles.xxxLarge,
)}
>
{children}
</div>
{(textFromProps?.length ?? 0) > charactersLoaded && (
<div className={styles.actions}>
<Button
Expand Down
28 changes: 28 additions & 0 deletions app/views/EntryEdit/LeftPane/SimplifiedTextView/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,34 @@
user-select: none;
}

.simplified-text {
line-height: 1.5;
--base-font-size: var(--dui-font-size-medium);
--diff: 2px;

&.x-small{
font-size: var(--base-font-size);
}
&.small{
font-size: calc(var(--base-font-size) + var(--diff));
}
&.medium{
font-size: calc(var(--base-font-size) + 2 * var(--diff));
}
&.large{
font-size: calc(var(--base-font-size) + 3 * var(--diff));
}
&.x-large{
font-size: calc(var(--base-font-size) + 4 * var(--diff));
}
&.xx-large{
font-size: calc(var(--base-font-size) + 5 * var(--diff));
}
&.xxx-large{
font-size: calc(var(--base-font-size) + 6 * var(--diff));
}
}

.entry {
margin: var(--dui-spacing-medium) 0;
}
Expand Down
81 changes: 68 additions & 13 deletions app/views/EntryEdit/LeftPane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
randomString,
} from '@togglecorp/fujs';
import { gql, useQuery } from '@apollo/client';
import {
MdOutlineZoomIn,
MdOutlineZoomOut,
} from 'react-icons/md';
import {
Tabs,
Container,
Expand Down Expand Up @@ -507,6 +511,34 @@ function LeftPane(props: Props) {
</Container>
);

const [
textZoomValue,
setTextZoomValue,
] = useState<number | undefined>(2);
const handleTextZoomOut = useCallback(() => {
setTextZoomValue((prev) => {
if (isNotDefined(prev)) {
return undefined;
}
if (prev <= 1) {
return 1;
}
return (prev - 1);
});
}, []);

const handleTextZoomIn = useCallback(() => {
setTextZoomValue((prev) => {
if (isNotDefined(prev)) {
return undefined;
}
if (prev >= 5) {
return 5;
}
return (prev + 1);
});
}, []);

const assistedTaggingShown = !project?.isPrivate
&& isAssistedTaggingAccessible
&& frameworkDetails?.assistedTaggingEnabled
Expand Down Expand Up @@ -550,19 +582,41 @@ function LeftPane(props: Props) {
retainMount="lazy"
>
<>
<Button
className={styles.autoEntriesButton}
name={undefined}
title={!isAutoExtractionCompatible
? 'Ooops. Looks like this source does not support Auto extraction at the moment. Please try it with a new source.'
: 'Extract entries for this source'}
onClick={showAutoEntriesModal}
variant="nlp-tertiary"
spacing="compact"
disabled={!isAutoExtractionCompatible}
>
NLP Extract and Classify
</Button>
<div className={styles.simplifiedHeader}>
<Button
className={styles.autoEntriesButton}
name={undefined}
title={!isAutoExtractionCompatible
? 'Ooops. Looks like this source does not support Auto extraction at the moment. Please try it with a new source.'
: 'Extract entries for this source'}
onClick={showAutoEntriesModal}
variant="nlp-tertiary"
spacing="compact"
disabled={!isAutoExtractionCompatible}
>
NLP Extract and Classify
</Button>
<div className={styles.actions}>
<QuickActionButton
name={undefined}
className={styles.zoom}
variant="general"
onClick={handleTextZoomOut}
disabled={isNotDefined(textZoomValue) || textZoomValue <= 1}
>
<MdOutlineZoomOut />
</QuickActionButton>
<QuickActionButton
name={undefined}
className={styles.zoom}
variant="general"
onClick={handleTextZoomIn}
disabled={isNotDefined(textZoomValue) || textZoomValue >= 5}
>
<MdOutlineZoomIn />
</QuickActionButton>
</div>
</div>
{(leadPreview?.textExtract?.length ?? 0) > 0 ? (
<SimplifiedTextView
className={styles.simplifiedTextView}
Expand All @@ -583,6 +637,7 @@ function LeftPane(props: Props) {
assistedTaggingEnabled={!!assistedTaggingShown}
frameworkDetails={frameworkDetails}
leadId={leadId}
textZoomValue={textZoomValue}
/>
) : (
<Message
Expand Down
18 changes: 16 additions & 2 deletions app/views/EntryEdit/LeftPane/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,22 @@
overflow: auto;
gap: var(--dui-spacing-medium);

.auto-entries-button {
flex-shrink: 0;
.simplified-header {
display: flex;
justify-content: space-between;
gap: var(--dui-spacing-large);

.auto-entries-button {
flex-shrink: 0;
}
.actions {
display: flex;
gap: var(--dui-spacing-extra-small);

.zoom {
border-radius: unset;
}
}
}

.switch {
Expand Down
Loading