fix: update dropdown width (#2181)
* fix: update dropdown width * fix conflict * refactor dropdown width state
This commit is contained in:
@ -14,6 +14,7 @@ import { FilterDropdownNumberSearchInput } from './FilterDropdownNumberSearchInp
|
|||||||
import { FilterDropdownOperandButton } from './FilterDropdownOperandButton';
|
import { FilterDropdownOperandButton } from './FilterDropdownOperandButton';
|
||||||
import { FilterDropdownOperandSelect } from './FilterDropdownOperandSelect';
|
import { FilterDropdownOperandSelect } from './FilterDropdownOperandSelect';
|
||||||
import { FilterDropdownTextSearchInput } from './FilterDropdownTextSearchInput';
|
import { FilterDropdownTextSearchInput } from './FilterDropdownTextSearchInput';
|
||||||
|
import { MultipleFiltersDropdownFilterOnFilterChangedEffect } from './MultipleFiltersDropdownFilterOnFilterChangedEffect';
|
||||||
|
|
||||||
export const MultipleFiltersDropdownContent = () => {
|
export const MultipleFiltersDropdownContent = () => {
|
||||||
const { ViewBarRecoilScopeContext } = useViewBarContext();
|
const { ViewBarRecoilScopeContext } = useViewBarContext();
|
||||||
@ -62,6 +63,11 @@ export const MultipleFiltersDropdownContent = () => {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
)}
|
)}
|
||||||
|
<MultipleFiltersDropdownFilterOnFilterChangedEffect
|
||||||
|
filterDefinitionUsedInDropdownType={
|
||||||
|
filterDefinitionUsedInDropdown?.type
|
||||||
|
}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,23 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
||||||
|
|
||||||
|
export const MultipleFiltersDropdownFilterOnFilterChangedEffect = ({
|
||||||
|
filterDefinitionUsedInDropdownType,
|
||||||
|
}: {
|
||||||
|
filterDefinitionUsedInDropdownType: string | undefined;
|
||||||
|
}) => {
|
||||||
|
const { setDropdownWidth } = useDropdown();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
switch (filterDefinitionUsedInDropdownType) {
|
||||||
|
case 'date':
|
||||||
|
setDropdownWidth(280);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setDropdownWidth(160);
|
||||||
|
}
|
||||||
|
}, [filterDefinitionUsedInDropdownType, setDropdownWidth]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
@ -1,6 +1,12 @@
|
|||||||
import { useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import { Keys } from 'react-hotkeys-hook';
|
import { Keys } from 'react-hotkeys-hook';
|
||||||
import { flip, offset, Placement, useFloating } from '@floating-ui/react';
|
import {
|
||||||
|
autoUpdate,
|
||||||
|
flip,
|
||||||
|
offset,
|
||||||
|
Placement,
|
||||||
|
useFloating,
|
||||||
|
} from '@floating-ui/react';
|
||||||
import { Key } from 'ts-key-enum';
|
import { Key } from 'ts-key-enum';
|
||||||
|
|
||||||
import { HotkeyEffect } from '@/ui/utilities/hotkey/components/HotkeyEffect';
|
import { HotkeyEffect } from '@/ui/utilities/hotkey/components/HotkeyEffect';
|
||||||
@ -12,7 +18,7 @@ import { useDropdown } from '../hooks/useDropdown';
|
|||||||
import { useInternalHotkeyScopeManagement } from '../hooks/useInternalHotkeyScopeManagement';
|
import { useInternalHotkeyScopeManagement } from '../hooks/useInternalHotkeyScopeManagement';
|
||||||
|
|
||||||
import { DropdownMenu } from './DropdownMenu';
|
import { DropdownMenu } from './DropdownMenu';
|
||||||
import { DropdownToggleEffect } from './DropdownToggleEffect';
|
import { DropdownOnToggleEffect } from './DropdownOnToggleEffect';
|
||||||
|
|
||||||
type DropdownProps = {
|
type DropdownProps = {
|
||||||
clickableComponent?: JSX.Element | JSX.Element[];
|
clickableComponent?: JSX.Element | JSX.Element[];
|
||||||
@ -33,7 +39,7 @@ type DropdownProps = {
|
|||||||
export const Dropdown = ({
|
export const Dropdown = ({
|
||||||
clickableComponent,
|
clickableComponent,
|
||||||
dropdownComponents,
|
dropdownComponents,
|
||||||
dropdownMenuWidth = 160,
|
dropdownMenuWidth,
|
||||||
hotkey,
|
hotkey,
|
||||||
dropdownHotkeyScope,
|
dropdownHotkeyScope,
|
||||||
dropdownPlacement = 'bottom-end',
|
dropdownPlacement = 'bottom-end',
|
||||||
@ -44,8 +50,10 @@ export const Dropdown = ({
|
|||||||
}: DropdownProps) => {
|
}: DropdownProps) => {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const { isDropdownOpen, toggleDropdown, closeDropdown } = useDropdown();
|
const { isDropdownOpen, toggleDropdown, closeDropdown, dropdownWidth } =
|
||||||
|
useDropdown();
|
||||||
|
|
||||||
|
const dropdownWidthState = dropdownMenuWidth ?? dropdownWidth;
|
||||||
const offsetMiddlewares = [];
|
const offsetMiddlewares = [];
|
||||||
if (dropdownOffset.x) {
|
if (dropdownOffset.x) {
|
||||||
offsetMiddlewares.push(offset({ crossAxis: dropdownOffset.x }));
|
offsetMiddlewares.push(offset({ crossAxis: dropdownOffset.x }));
|
||||||
@ -58,6 +66,7 @@ export const Dropdown = ({
|
|||||||
const { refs, floatingStyles } = useFloating({
|
const { refs, floatingStyles } = useFloating({
|
||||||
placement: dropdownPlacement,
|
placement: dropdownPlacement,
|
||||||
middleware: [flip(), ...offsetMiddlewares],
|
middleware: [flip(), ...offsetMiddlewares],
|
||||||
|
whileElementsMounted: autoUpdate,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleHotkeyTriggered = () => {
|
const handleHotkeyTriggered = () => {
|
||||||
@ -103,7 +112,7 @@ export const Dropdown = ({
|
|||||||
)}
|
)}
|
||||||
{isDropdownOpen && (
|
{isDropdownOpen && (
|
||||||
<DropdownMenu
|
<DropdownMenu
|
||||||
width={dropdownMenuWidth}
|
width={dropdownWidthState}
|
||||||
data-select-disable
|
data-select-disable
|
||||||
ref={refs.setFloating}
|
ref={refs.setFloating}
|
||||||
style={floatingStyles}
|
style={floatingStyles}
|
||||||
@ -111,7 +120,10 @@ export const Dropdown = ({
|
|||||||
{dropdownComponents}
|
{dropdownComponents}
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
)}
|
)}
|
||||||
<DropdownToggleEffect onDropdownClose={onClose} onDropdownOpen={onOpen} />
|
<DropdownOnToggleEffect
|
||||||
|
onDropdownClose={onClose}
|
||||||
|
onDropdownOpen={onOpen}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { useEffect } from 'react';
|
|||||||
|
|
||||||
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
|
||||||
|
|
||||||
export const DropdownToggleEffect = ({
|
export const DropdownOnToggleEffect = ({
|
||||||
onDropdownClose,
|
onDropdownClose,
|
||||||
onDropdownOpen,
|
onDropdownOpen,
|
||||||
}: {
|
}: {
|
||||||
@ -25,6 +25,8 @@ export const useDropdown = (props?: UseDropdownProps) => {
|
|||||||
setDropdownHotkeyScope,
|
setDropdownHotkeyScope,
|
||||||
isDropdownOpen,
|
isDropdownOpen,
|
||||||
setIsDropdownOpen,
|
setIsDropdownOpen,
|
||||||
|
dropdownWidth,
|
||||||
|
setDropdownWidth,
|
||||||
} = useDropdownStates({
|
} = useDropdownStates({
|
||||||
scopeId,
|
scopeId,
|
||||||
});
|
});
|
||||||
@ -61,5 +63,7 @@ export const useDropdown = (props?: UseDropdownProps) => {
|
|||||||
scopeId,
|
scopeId,
|
||||||
dropdownHotkeyScope,
|
dropdownHotkeyScope,
|
||||||
setDropdownHotkeyScope,
|
setDropdownHotkeyScope,
|
||||||
|
dropdownWidth,
|
||||||
|
setDropdownWidth,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useRecoilScopedStateV2 } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedStateV2';
|
import { useRecoilScopedStateV2 } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedStateV2';
|
||||||
|
|
||||||
import { dropdownHotkeyScopeScopedState } from '../states/dropdownHotkeyScopeScopedState';
|
import { dropdownHotkeyScopeScopedState } from '../states/dropdownHotkeyScopeScopedState';
|
||||||
|
import { dropdownWidthScopedState } from '../states/dropdownWidthScopedState';
|
||||||
import { isDropdownOpenScopedState } from '../states/isDropdownOpenScopedState';
|
import { isDropdownOpenScopedState } from '../states/isDropdownOpenScopedState';
|
||||||
|
|
||||||
export const useDropdownStates = ({ scopeId }: { scopeId: string }) => {
|
export const useDropdownStates = ({ scopeId }: { scopeId: string }) => {
|
||||||
@ -14,10 +15,17 @@ export const useDropdownStates = ({ scopeId }: { scopeId: string }) => {
|
|||||||
scopeId,
|
scopeId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const [dropdownWidth, setDropdownWidth] = useRecoilScopedStateV2(
|
||||||
|
dropdownWidthScopedState,
|
||||||
|
scopeId,
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDropdownOpen,
|
isDropdownOpen,
|
||||||
setIsDropdownOpen,
|
setIsDropdownOpen,
|
||||||
dropdownHotkeyScope,
|
dropdownHotkeyScope,
|
||||||
setDropdownHotkeyScope,
|
setDropdownHotkeyScope,
|
||||||
|
dropdownWidth,
|
||||||
|
setDropdownWidth,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
import { createScopedState } from '@/ui/utilities/recoil-scope/utils/createScopedState';
|
||||||
|
|
||||||
|
export const dropdownWidthScopedState = createScopedState<number | undefined>({
|
||||||
|
key: 'dropdownWidthScopedState',
|
||||||
|
defaultValue: 160,
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user