F: Improve tooltips positioning and text truncation

This commit is contained in:
Ivan 2024-09-02 18:34:18 +03:00
parent 40b799d815
commit 79c2050ed2
8 changed files with 38 additions and 12 deletions

View File

@ -67,6 +67,9 @@ function SelectMulti<Option, Group extends GroupBase<Option> = GroupBase<Option>
}), }),
option: (styles, { isSelected }) => ({ option: (styles, { isSelected }) => ({
...styles, ...styles,
padding: '0.25rem 0.75rem',
fontSize: '0.875rem',
lineHeight: '1.25rem',
backgroundColor: isSelected ? colors.bgSelected : styles.backgroundColor, backgroundColor: isSelected ? colors.bgSelected : styles.backgroundColor,
color: isSelected ? colors.fgSelected : styles.color, color: isSelected ? colors.fgSelected : styles.color,
borderWidth: '1px', borderWidth: '1px',

View File

@ -78,6 +78,9 @@ function SelectSingle<Option, Group extends GroupBase<Option> = GroupBase<Option
}), }),
option: (defaultStyles, { isSelected }) => ({ option: (defaultStyles, { isSelected }) => ({
...defaultStyles, ...defaultStyles,
padding: '0.25rem 0.75rem',
fontSize: '0.875rem',
lineHeight: '1.25rem',
backgroundColor: isSelected ? colors.bgSelected : defaultStyles.backgroundColor, backgroundColor: isSelected ? colors.bgSelected : defaultStyles.backgroundColor,
color: isSelected ? colors.fgSelected : defaultStyles.color, color: isSelected ? colors.fgSelected : defaultStyles.color,
borderWidth: '1px', borderWidth: '1px',

View File

@ -8,16 +8,17 @@ import { CProps } from '../props';
export interface TextContentProps extends CProps.Styling { export interface TextContentProps extends CProps.Styling {
text: string; text: string;
maxLength?: number; maxLength?: number;
noTooltip?: boolean;
} }
function TextContent({ className, text, maxLength, ...restProps }: TextContentProps) { function TextContent({ className, text, maxLength, noTooltip, ...restProps }: TextContentProps) {
const truncated = maxLength ? truncateToLastWord(text, maxLength) : text; const truncated = maxLength ? truncateToLastWord(text, maxLength) : text;
const isTruncated = maxLength && text.length > maxLength; const isTruncated = maxLength && text.length > maxLength;
return ( return (
<div <div
className={clsx('text-xs text-pretty', className)} className={clsx('text-xs text-pretty', className)}
data-tooltip-id={isTruncated ? globals.tooltip : undefined} data-tooltip-id={isTruncated && !noTooltip ? globals.value_tooltip : undefined}
data-tooltip-content={isTruncated ? text : undefined} data-tooltip-html={isTruncated && !noTooltip ? text : undefined}
{...restProps} {...restProps}
> >
{truncated} {truncated}

View File

@ -145,8 +145,15 @@ export const OptionsState = ({ children }: OptionsStateProps) => {
id={`${globals.tooltip}`} id={`${globals.tooltip}`}
layer='z-topmost' layer='z-topmost'
place='right-start' place='right-start'
className={clsx('mt-1 translate-y-1/2', 'max-w-[20rem]')} className={clsx('mt-8', 'max-w-[20rem]')}
/> />
<Tooltip
float
id={`${globals.value_tooltip}`}
layer='z-topmost'
className={clsx('max-w-[calc(min(40rem,100dvw-2rem))]')}
/>
{children} {children}
</> </>
</OptionsContext.Provider> </OptionsContext.Provider>

View File

@ -178,7 +178,7 @@ function DlgEditWordForms({ hideWindow, target, onSave }: DlgEditWordFormsProps)
</div> </div>
<SelectMultiGrammeme <SelectMultiGrammeme
placeholder='Выберите граммемы' placeholder='Выберите граммемы'
className='w-[15rem]' className='min-w-[15rem] h-fit'
value={inputGrams} value={inputGrams}
setValue={setInputGrams} setValue={setInputGrams}
/> />

View File

@ -356,20 +356,27 @@ function EditorTermGraph({ onOpenEdit }: EditorTermGraphProps) {
hideZero hideZero
totalCount={controller.schema?.stats?.count_all ?? 0} totalCount={controller.schema?.stats?.count_all ?? 0}
selectedCount={controller.selected.length} selectedCount={controller.selected.length}
position='top-[4.3rem] sm:top-[0.3rem] left-0' position='top-[4.3rem] sm:top-[2rem] left-0'
/> />
{hoverCst && hoverCstDebounced && hoverCst === hoverCstDebounced ? ( {hoverCst && hoverCstDebounced && hoverCst === hoverCstDebounced ? (
<Overlay <Overlay
layer='z-tooltip' layer='z-tooltip'
position={clsx('top-[1.6rem]', { 'left-[2.6rem]': hoverLeft, 'right-[2.6rem]': !hoverLeft })} position={clsx('top-[1.6rem]', { 'left-[2.6rem]': hoverLeft, 'right-[2.6rem]': !hoverLeft })}
className={clsx('w-[25rem]', 'px-3', 'cc-scroll-y', 'border shadow-md', 'clr-app')} className={clsx(
'w-[25rem] max-h-[calc(100dvh-15rem)]',
'px-3',
'cc-scroll-y',
'border shadow-md',
'clr-input',
'text-sm'
)}
> >
<InfoConstituenta className='pt-1 pb-2' data={hoverCstDebounced} /> <InfoConstituenta className='pt-1 pb-2' data={hoverCstDebounced} />
</Overlay> </Overlay>
) : null} ) : null}
<Overlay position='top-[6.25rem] sm:top-9 left-0' className='flex gap-1'> <Overlay position='top-[6.25rem] sm:top-[4rem] left-0' className='flex gap-1'>
<div className='flex flex-col ml-2 w-[13.5rem]'> <div className='flex flex-col ml-2 w-[13.5rem]'>
{selectors} {selectors}
{viewHidden} {viewHidden}

View File

@ -5,12 +5,15 @@ import { useCallback, useLayoutEffect, useMemo } from 'react';
import BadgeConstituenta from '@/components/info/BadgeConstituenta'; import BadgeConstituenta from '@/components/info/BadgeConstituenta';
import DataTable, { createColumnHelper, IConditionalStyle } from '@/components/ui/DataTable'; import DataTable, { createColumnHelper, IConditionalStyle } from '@/components/ui/DataTable';
import NoData from '@/components/ui/NoData'; import NoData from '@/components/ui/NoData';
import TextContent from '@/components/ui/TextContent';
import { useConceptOptions } from '@/context/ConceptOptionsContext'; import { useConceptOptions } from '@/context/ConceptOptionsContext';
import { ConstituentaID, IConstituenta } from '@/models/rsform'; import { ConstituentaID, IConstituenta } from '@/models/rsform';
import { isMockCst } from '@/models/rsformAPI'; import { isMockCst } from '@/models/rsformAPI';
import { PARAMETER, prefixes } from '@/utils/constants'; import { PARAMETER, prefixes } from '@/utils/constants';
import { describeConstituenta } from '@/utils/labels'; import { describeConstituenta } from '@/utils/labels';
const DESCRIPTION_MAX_SYMBOLS = 280;
interface TableSideConstituentsProps { interface TableSideConstituentsProps {
items: IConstituenta[]; items: IConstituenta[];
activeCst?: IConstituenta; activeCst?: IConstituenta;
@ -76,15 +79,16 @@ function TableSideConstituents({
minSize: 250, minSize: 250,
maxSize: 1000, maxSize: 1000,
cell: props => ( cell: props => (
<div <TextContent
noTooltip
text={props.getValue()}
maxLength={DESCRIPTION_MAX_SYMBOLS}
style={{ style={{
textWrap: 'pretty', textWrap: 'pretty',
fontSize: 12, fontSize: 12,
color: isMockCst(props.row.original) ? colors.fgWarning : undefined color: isMockCst(props.row.original) ? colors.fgWarning : undefined
}} }}
> />
{props.getValue()}
</div>
) )
}) })
], ],

View File

@ -138,6 +138,7 @@ export const storage = {
*/ */
export const globals = { export const globals = {
tooltip: 'global_tooltip', tooltip: 'global_tooltip',
value_tooltip: 'value_tooltip',
password_tooltip: 'password_tooltip', password_tooltip: 'password_tooltip',
email_tooltip: 'email_tooltip', email_tooltip: 'email_tooltip',
main_scroll: 'main_scroll', main_scroll: 'main_scroll',