mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(ui): add ellipsis direction to IAICustomSelect
This commit is contained in:
parent
fa285883ad
commit
4f7820719b
@ -18,7 +18,7 @@ import { autoUpdate, offset, shift, useFloating } from '@floating-ui/react-dom';
|
|||||||
import { useSelect } from 'downshift';
|
import { useSelect } from 'downshift';
|
||||||
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
|
import { OverlayScrollbarsComponent } from 'overlayscrollbars-react';
|
||||||
|
|
||||||
import { memo } from 'react';
|
import { memo, useMemo } from 'react';
|
||||||
import { getInputOutlineStyles } from 'theme/util/getInputOutlineStyles';
|
import { getInputOutlineStyles } from 'theme/util/getInputOutlineStyles';
|
||||||
|
|
||||||
export type ItemTooltips = { [key: string]: string };
|
export type ItemTooltips = { [key: string]: string };
|
||||||
@ -34,6 +34,7 @@ type IAICustomSelectProps = {
|
|||||||
buttonProps?: FlexProps;
|
buttonProps?: FlexProps;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
tooltipProps?: Omit<TooltipProps, 'children'>;
|
tooltipProps?: Omit<TooltipProps, 'children'>;
|
||||||
|
ellipsisPosition?: 'start' | 'end';
|
||||||
};
|
};
|
||||||
|
|
||||||
const IAICustomSelect = (props: IAICustomSelectProps) => {
|
const IAICustomSelect = (props: IAICustomSelectProps) => {
|
||||||
@ -48,6 +49,7 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
|
|||||||
tooltip,
|
tooltip,
|
||||||
buttonProps,
|
buttonProps,
|
||||||
tooltipProps,
|
tooltipProps,
|
||||||
|
ellipsisPosition = 'end',
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -69,6 +71,14 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
|
|||||||
middleware: [offset(4), shift({ crossAxis: true, padding: 8 })],
|
middleware: [offset(4), shift({ crossAxis: true, padding: 8 })],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const labelTextDirection = useMemo(() => {
|
||||||
|
if (ellipsisPosition === 'start') {
|
||||||
|
return document.dir === 'rtl' ? 'ltr' : 'rtl';
|
||||||
|
}
|
||||||
|
|
||||||
|
return document.dir;
|
||||||
|
}, [ellipsisPosition]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormControl sx={{ w: 'full' }} {...formControlProps}>
|
<FormControl sx={{ w: 'full' }} {...formControlProps}>
|
||||||
{label && (
|
{label && (
|
||||||
@ -106,6 +116,7 @@ const IAICustomSelect = (props: IAICustomSelectProps) => {
|
|||||||
whiteSpace: 'nowrap',
|
whiteSpace: 'nowrap',
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
|
direction: labelTextDirection,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{selectedItem}
|
{selectedItem}
|
||||||
|
Loading…
Reference in New Issue
Block a user