fix: Fixed issue where checklist item text in Super notes wasn't aligned correctly (#2656)

This commit is contained in:
Aman Harwara
2023-11-27 19:54:38 +05:30
committed by GitHub
parent c6b952ef23
commit 8ff0d20858
4 changed files with 50 additions and 35 deletions

View File

@@ -6,3 +6,13 @@ export enum EditorLineHeight {
Relaxed = 'Relaxed', Relaxed = 'Relaxed',
Loose = 'Loose', Loose = 'Loose',
} }
// https://tailwindcss.com/docs/line-height
export const EditorLineHeightValues: { [key in EditorLineHeight]: number } = {
None: 1,
Tight: 1.25,
Snug: 1.375,
Normal: 1.5,
Relaxed: 1.625,
Loose: 2,
}

View File

@@ -52,8 +52,8 @@
.Lexical__listItemChecked, .Lexical__listItemChecked,
.Lexical__listItemUnchecked { .Lexical__listItemUnchecked {
position: relative; position: relative;
padding-left: 24px; padding-left: calc(var(--font-size) + 0.5rem);
padding-right: 24px; padding-right: calc(var(--font-size) + 0.5rem);
list-style-type: none; list-style-type: none;
outline: none; outline: none;
vertical-align: middle; vertical-align: middle;
@@ -65,10 +65,12 @@
.Lexical__listItemUnchecked:before, .Lexical__listItemUnchecked:before,
.Lexical__listItemChecked:before { .Lexical__listItemChecked:before {
content: ''; content: '';
width: 16px; --size: 16px;
height: 16px; width: var(--size);
height: var(--size);
left: 0; left: 0;
top: 7px; top: calc(var(--line-height, 1) * var(--font-size) / 2);
transform: translateY(-50%);
cursor: pointer; cursor: pointer;
background-size: cover; background-size: cover;
position: absolute; position: absolute;
@@ -100,11 +102,12 @@
border-style: solid; border-style: solid;
position: absolute; position: absolute;
display: block; display: block;
top: 9px;
width: 5px; width: 5px;
left: 6px; height: 11px;
height: 10px; --top: calc(var(--line-height, 1) * var(--font-size) / 2);
transform: rotate(45deg); top: calc(var(--top) - 1px);
left: 5px;
transform: translateY(-50%) rotate(45deg);
border-width: 0 2px 2px 0; border-width: 0 2px 2px 0;
} }
.Lexical__nestedListItem { .Lexical__nestedListItem {

View File

@@ -10,8 +10,9 @@ import {
NativeFeatureIdentifier, NativeFeatureIdentifier,
FeatureStatus, FeatureStatus,
GetSuperNoteFeature, GetSuperNoteFeature,
EditorLineHeightValues,
} from '@standardnotes/snjs' } from '@standardnotes/snjs'
import { FunctionComponent, useCallback, useEffect, useRef, useState } from 'react' import { CSSProperties, FunctionComponent, useCallback, useEffect, useRef, useState } from 'react'
import { BlocksEditor } from './BlocksEditor' import { BlocksEditor } from './BlocksEditor'
import { BlocksEditorComposer } from './BlocksEditorComposer' import { BlocksEditorComposer } from './BlocksEditorComposer'
import { ItemSelectionPlugin } from './Plugins/ItemSelectionPlugin/ItemSelectionPlugin' import { ItemSelectionPlugin } from './Plugins/ItemSelectionPlugin/ItemSelectionPlugin'
@@ -165,7 +166,7 @@ export const SuperEditor: FunctionComponent<Props> = ({
const [fontSize, setFontSize] = useState<EditorFontSize>(() => const [fontSize, setFontSize] = useState<EditorFontSize>(() =>
application.getPreference(PrefKey.EditorFontSize, PrefDefaults[PrefKey.EditorFontSize]), application.getPreference(PrefKey.EditorFontSize, PrefDefaults[PrefKey.EditorFontSize]),
) )
const responsiveFontSize = useResponsiveEditorFontSize(fontSize) const responsiveFontSize = useResponsiveEditorFontSize(fontSize, false)
const reloadPreferences = useCallback(() => { const reloadPreferences = useCallback(() => {
const lineHeight = application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight]) const lineHeight = application.getPreference(PrefKey.EditorLineHeight, PrefDefaults[PrefKey.EditorLineHeight])
@@ -211,11 +212,13 @@ export const SuperEditor: FunctionComponent<Props> = ({
return ( return (
<div <div
className={classNames( className="font-editor relative flex h-full w-full flex-col"
'font-editor relative flex h-full w-full flex-col', style={
lineHeight && `leading-${lineHeight.toLowerCase()}`, {
responsiveFontSize, '--line-height': EditorLineHeightValues[lineHeight],
)} '--font-size': responsiveFontSize,
} as CSSProperties
}
ref={ref} ref={ref}
> >
{featureStatus !== FeatureStatus.Entitled && ( {featureStatus !== FeatureStatus.Entitled && (
@@ -228,9 +231,8 @@ export const SuperEditor: FunctionComponent<Props> = ({
<BlocksEditor <BlocksEditor
onChange={handleChange} onChange={handleChange}
className={classNames( className={classNames(
'blocks-editor relative h-full resize-none px-4 py-4 focus:shadow-none focus:outline-none', 'blocks-editor relative h-full resize-none px-4 py-4 text-[length:--font-size] focus:shadow-none focus:outline-none',
lineHeight && `leading-${lineHeight.toLowerCase()}`, lineHeight && 'leading-[--line-height]',
responsiveFontSize,
)} )}
previewLength={SuperNotePreviewCharLimit} previewLength={SuperNotePreviewCharLimit}
spellcheck={spellcheck} spellcheck={spellcheck}

View File

@@ -1,29 +1,29 @@
import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery' import { MutuallyExclusiveMediaQueryBreakpoints, useMediaQuery } from '@/Hooks/useMediaQuery'
import { EditorFontSize } from '@standardnotes/snjs' import { EditorFontSize } from '@standardnotes/snjs'
export const useResponsiveEditorFontSize = (key: EditorFontSize): string => { export const useResponsiveEditorFontSize = (key: EditorFontSize, useTailwindClasses = true): string => {
const desktopMapping: Record<EditorFontSize, string> = { const desktopMapping: Record<EditorFontSize, string> = {
ExtraSmall: 'text-xs', ExtraSmall: useTailwindClasses ? 'text-xs' : '0.75rem',
Small: 'text-sm', Small: useTailwindClasses ? 'text-sm' : '0.875rem',
Normal: 'text-editor', Normal: useTailwindClasses ? 'text-editor' : 'var(--sn-stylekit-font-size-editor)',
Medium: 'text-lg', Medium: useTailwindClasses ? 'text-lg' : '1.125rem',
Large: 'text-xl', Large: useTailwindClasses ? 'text-xl' : '1.25rem',
} }
const mobileMapping: Record<EditorFontSize, string> = { const mobileMapping: Record<EditorFontSize, string> = {
ExtraSmall: 'text-sm', ExtraSmall: useTailwindClasses ? 'text-sm' : '0.875rem',
Small: 'text-editor', Small: useTailwindClasses ? 'text-editor' : 'var(--sn-stylekit-font-size-editor)',
Normal: 'text-lg', Normal: useTailwindClasses ? 'text-lg' : '1.125rem',
Medium: 'text-xl', Medium: useTailwindClasses ? 'text-xl' : '1.25rem',
Large: 'text-2xl', Large: useTailwindClasses ? 'text-2xl' : '1.5rem',
} }
const tabletMapping: Record<EditorFontSize, string> = { const tabletMapping: Record<EditorFontSize, string> = {
ExtraSmall: 'text-sm', ExtraSmall: useTailwindClasses ? 'text-sm' : '0.875rem',
Small: 'text-editor', Small: useTailwindClasses ? 'text-editor' : 'var(--sn-stylekit-font-size-editor)',
Normal: 'text-base', Normal: useTailwindClasses ? 'text-base' : '1rem',
Medium: 'text-xl', Medium: useTailwindClasses ? 'text-xl' : '1.25rem',
Large: 'text-2xl', Large: useTailwindClasses ? 'text-2xl' : '1.5rem',
} }
const isTabletScreen = useMediaQuery(MutuallyExclusiveMediaQueryBreakpoints.md) const isTabletScreen = useMediaQuery(MutuallyExclusiveMediaQueryBreakpoints.md)