mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-24 06:48:42 +03:00
Expandable list remove anchor (#5559)
Deprecate anchorElement on ExpandableList to avoid props drilling. The anchorElement should be the ExpandableList container itself
This commit is contained in:
parent
7f7ea59b51
commit
82ec30c957
@ -104,12 +104,7 @@ export const CalendarEventParticipantsResponseStatusField = ({
|
|||||||
</StyledLabelAndIconContainer>
|
</StyledLabelAndIconContainer>
|
||||||
<StyledDiv ref={participantsContainerRef}>
|
<StyledDiv ref={participantsContainerRef}>
|
||||||
{isRightDrawerAnimationCompleted && (
|
{isRightDrawerAnimationCompleted && (
|
||||||
<ExpandableList
|
<ExpandableList isChipCountDisplayed>{styledChips}</ExpandableList>
|
||||||
anchorElement={participantsContainerRef.current || undefined}
|
|
||||||
isChipCountDisplayed
|
|
||||||
>
|
|
||||||
{styledChips}
|
|
||||||
</ExpandableList>
|
|
||||||
)}
|
)}
|
||||||
</StyledDiv>
|
</StyledDiv>
|
||||||
</StyledInlineCellBaseContainer>
|
</StyledInlineCellBaseContainer>
|
||||||
|
@ -6,7 +6,6 @@ import { ExpandableList } from '@/ui/layout/expandable-list/components/Expandabl
|
|||||||
|
|
||||||
type ActivityTargetChipsProps = {
|
type ActivityTargetChipsProps = {
|
||||||
activityTargetObjectRecords: ActivityTargetWithTargetRecord[];
|
activityTargetObjectRecords: ActivityTargetWithTargetRecord[];
|
||||||
anchorElement?: HTMLElement;
|
|
||||||
maxWidth?: number;
|
maxWidth?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -19,12 +18,11 @@ const StyledContainer = styled.div<{ maxWidth?: number }>`
|
|||||||
|
|
||||||
export const ActivityTargetChips = ({
|
export const ActivityTargetChips = ({
|
||||||
activityTargetObjectRecords,
|
activityTargetObjectRecords,
|
||||||
anchorElement,
|
|
||||||
maxWidth,
|
maxWidth,
|
||||||
}: ActivityTargetChipsProps) => {
|
}: ActivityTargetChipsProps) => {
|
||||||
return (
|
return (
|
||||||
<StyledContainer maxWidth={maxWidth}>
|
<StyledContainer maxWidth={maxWidth}>
|
||||||
<ExpandableList anchorElement={anchorElement} isChipCountDisplayed>
|
<ExpandableList isChipCountDisplayed>
|
||||||
{activityTargetObjectRecords.map(
|
{activityTargetObjectRecords.map(
|
||||||
(activityTargetObjectRecord, index) => (
|
(activityTargetObjectRecord, index) => (
|
||||||
<RecordChip
|
<RecordChip
|
||||||
|
@ -53,9 +53,8 @@ export const ActivityTargetsInlineCell = ({
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label="Relations"
|
label="Relations"
|
||||||
displayModeContent={({ cellElement }) => (
|
displayModeContent={() => (
|
||||||
<ActivityTargetChips
|
<ActivityTargetChips
|
||||||
anchorElement={cellElement}
|
|
||||||
activityTargetObjectRecords={activityTargetObjectRecords}
|
activityTargetObjectRecords={activityTargetObjectRecords}
|
||||||
maxWidth={maxWidth}
|
maxWidth={maxWidth}
|
||||||
/>
|
/>
|
||||||
|
@ -80,7 +80,6 @@ export const FieldDisplay = ({
|
|||||||
) : isFieldLinks(fieldDefinition) ? (
|
) : isFieldLinks(fieldDefinition) ? (
|
||||||
<LinksFieldDisplay
|
<LinksFieldDisplay
|
||||||
isCellSoftFocused={isCellSoftFocused}
|
isCellSoftFocused={isCellSoftFocused}
|
||||||
cellElement={cellElement}
|
|
||||||
fromTableCell={fromTableCell}
|
fromTableCell={fromTableCell}
|
||||||
/>
|
/>
|
||||||
) : isFieldCurrency(fieldDefinition) ? (
|
) : isFieldCurrency(fieldDefinition) ? (
|
||||||
|
@ -3,13 +3,11 @@ import { LinksDisplay } from '@/ui/field/display/components/LinksDisplay';
|
|||||||
|
|
||||||
type LinksFieldDisplayProps = {
|
type LinksFieldDisplayProps = {
|
||||||
isCellSoftFocused?: boolean;
|
isCellSoftFocused?: boolean;
|
||||||
cellElement?: HTMLElement;
|
|
||||||
fromTableCell?: boolean;
|
fromTableCell?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LinksFieldDisplay = ({
|
export const LinksFieldDisplay = ({
|
||||||
isCellSoftFocused,
|
isCellSoftFocused,
|
||||||
cellElement,
|
|
||||||
fromTableCell,
|
fromTableCell,
|
||||||
}: LinksFieldDisplayProps) => {
|
}: LinksFieldDisplayProps) => {
|
||||||
const { fieldValue } = useLinksField();
|
const { fieldValue } = useLinksField();
|
||||||
@ -17,7 +15,6 @@ export const LinksFieldDisplay = ({
|
|||||||
return (
|
return (
|
||||||
<LinksDisplay
|
<LinksDisplay
|
||||||
value={fieldValue}
|
value={fieldValue}
|
||||||
anchorElement={cellElement}
|
|
||||||
isChipCountDisplayed={isCellSoftFocused}
|
isChipCountDisplayed={isCellSoftFocused}
|
||||||
withExpandedListBorder={fromTableCell}
|
withExpandedListBorder={fromTableCell}
|
||||||
/>
|
/>
|
||||||
|
@ -11,7 +11,6 @@ type MultiSelectFieldDisplayProps = {
|
|||||||
|
|
||||||
export const MultiSelectFieldDisplay = ({
|
export const MultiSelectFieldDisplay = ({
|
||||||
isCellSoftFocused,
|
isCellSoftFocused,
|
||||||
cellElement,
|
|
||||||
fromTableCell,
|
fromTableCell,
|
||||||
}: MultiSelectFieldDisplayProps) => {
|
}: MultiSelectFieldDisplayProps) => {
|
||||||
const { fieldValues, fieldDefinition } = useMultiSelectField();
|
const { fieldValues, fieldDefinition } = useMultiSelectField();
|
||||||
@ -26,7 +25,6 @@ export const MultiSelectFieldDisplay = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ExpandableList
|
<ExpandableList
|
||||||
anchorElement={cellElement}
|
|
||||||
isChipCountDisplayed={isCellSoftFocused}
|
isChipCountDisplayed={isCellSoftFocused}
|
||||||
withExpandedListBorder={fromTableCell}
|
withExpandedListBorder={fromTableCell}
|
||||||
>
|
>
|
||||||
|
@ -17,13 +17,12 @@ import { getUrlHostName } from '~/utils/url/getUrlHostName';
|
|||||||
|
|
||||||
type LinksDisplayProps = Pick<
|
type LinksDisplayProps = Pick<
|
||||||
ExpandableListProps,
|
ExpandableListProps,
|
||||||
'anchorElement' | 'isChipCountDisplayed' | 'withExpandedListBorder'
|
'isChipCountDisplayed' | 'withExpandedListBorder'
|
||||||
> & {
|
> & {
|
||||||
value?: FieldLinksValue;
|
value?: FieldLinksValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LinksDisplay = ({
|
export const LinksDisplay = ({
|
||||||
anchorElement,
|
|
||||||
isChipCountDisplayed,
|
isChipCountDisplayed,
|
||||||
withExpandedListBorder,
|
withExpandedListBorder,
|
||||||
value,
|
value,
|
||||||
@ -55,7 +54,6 @@ export const LinksDisplay = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ExpandableList
|
<ExpandableList
|
||||||
anchorElement={anchorElement}
|
|
||||||
isChipCountDisplayed={isChipCountDisplayed}
|
isChipCountDisplayed={isChipCountDisplayed}
|
||||||
withExpandedListBorder={withExpandedListBorder}
|
withExpandedListBorder={withExpandedListBorder}
|
||||||
>
|
>
|
||||||
|
@ -41,7 +41,6 @@ const StyledChipCount = styled(Chip)`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export type ExpandableListProps = {
|
export type ExpandableListProps = {
|
||||||
anchorElement?: HTMLElement;
|
|
||||||
isChipCountDisplayed?: boolean;
|
isChipCountDisplayed?: boolean;
|
||||||
withExpandedListBorder?: boolean;
|
withExpandedListBorder?: boolean;
|
||||||
};
|
};
|
||||||
@ -53,7 +52,6 @@ export type ChildrenProperty = {
|
|||||||
|
|
||||||
export const ExpandableList = ({
|
export const ExpandableList = ({
|
||||||
children,
|
children,
|
||||||
anchorElement,
|
|
||||||
isChipCountDisplayed: isChipCountDisplayedFromProps,
|
isChipCountDisplayed: isChipCountDisplayedFromProps,
|
||||||
withExpandedListBorder = false,
|
withExpandedListBorder = false,
|
||||||
}: {
|
}: {
|
||||||
@ -75,10 +73,10 @@ export const ExpandableList = ({
|
|||||||
// @see https://floating-ui.com/docs/useFloating#elements
|
// @see https://floating-ui.com/docs/useFloating#elements
|
||||||
const [childrenContainerElement, setChildrenContainerElement] =
|
const [childrenContainerElement, setChildrenContainerElement] =
|
||||||
useState<HTMLDivElement | null>(null);
|
useState<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const [previousChildrenContainerWidth, setPreviousChildrenContainerWidth] =
|
const [previousChildrenContainerWidth, setPreviousChildrenContainerWidth] =
|
||||||
useState(childrenContainerElement?.clientWidth ?? 0);
|
useState(childrenContainerElement?.clientWidth ?? 0);
|
||||||
|
|
||||||
// Used with useListenClickOutside.
|
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const [firstHiddenChildIndex, setFirstHiddenChildIndex] = useState(
|
const [firstHiddenChildIndex, setFirstHiddenChildIndex] = useState(
|
||||||
@ -165,7 +163,7 @@ export const ExpandableList = ({
|
|||||||
)}
|
)}
|
||||||
{isListExpanded && (
|
{isListExpanded && (
|
||||||
<ExpandedListDropdown
|
<ExpandedListDropdown
|
||||||
anchorElement={anchorElement ?? childrenContainerElement ?? undefined}
|
anchorElement={containerRef.current ?? undefined}
|
||||||
onClickOutside={() => {
|
onClickOutside={() => {
|
||||||
resetFirstHiddenChildIndex();
|
resetFirstHiddenChildIndex();
|
||||||
setIsListExpanded(false);
|
setIsListExpanded(false);
|
||||||
|
@ -42,7 +42,7 @@ export const ExpandedListDropdown = ({
|
|||||||
const { refs, floatingStyles } = useFloating({
|
const { refs, floatingStyles } = useFloating({
|
||||||
// @ts-expect-error placement accepts 'start' as value even if the typing does not permit it
|
// @ts-expect-error placement accepts 'start' as value even if the typing does not permit it
|
||||||
placement: 'start',
|
placement: 'start',
|
||||||
middleware: [offset({ mainAxis: -1, crossAxis: -1 })],
|
middleware: [offset({ mainAxis: -9, crossAxis: -7 })],
|
||||||
elements: { reference: anchorElement },
|
elements: { reference: anchorElement },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ const meta: Meta<typeof ExpandableList> = {
|
|||||||
},
|
},
|
||||||
argTypes: {
|
argTypes: {
|
||||||
children: { control: false },
|
children: { control: false },
|
||||||
anchorElement: { control: false },
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user