Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New OverflowContainer wrapper around useOverflow #2152

Merged
merged 86 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
71a3611
Brought back e2e tests from combined PR
r100-stack Jul 18, 2024
ad14635
Small edits for tests to pass with old useOverflow
r100-stack Jul 18, 2024
24de931
Try to increase await duration
r100-stack Jul 18, 2024
3da2c29
Try not awaiting inside expect.
r100-stack Jul 18, 2024
df16014
Undo build.yml changes
r100-stack Jul 18, 2024
1787868
Brought back OverflowContainer and usages
r100-stack Jul 18, 2024
8937b87
Modified components to work with old useOverflow
r100-stack Jul 18, 2024
1d4e7bf
Remove nested components
r100-stack Jul 18, 2024
c524246
Added `await`
r100-stack Jul 18, 2024
1cc98a1
Remove nested describe blocks
r100-stack Jul 18, 2024
46e7d99
nit/optional comments
r100-stack Jul 18, 2024
057a5a0
Lenient test selectors; unchanged old tests.
r100-stack Jul 19, 2024
44adeac
Trying review suggestions
r100-stack Jul 19, 2024
a97ff78
Lenient MiddleTextTruncation text comparison
r100-stack Jul 19, 2024
7c90aef
Fixed var undefined error. Old test unchanged.
r100-stack Jul 19, 2024
8de316a
Add missing await
r100-stack Jul 19, 2024
4575008
Un-nest components in Table
r100-stack Jul 19, 2024
24fe514
Deconstruct config variables
r100-stack Jul 19, 2024
a9a7614
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Jul 19, 2024
c3d2221
iui-breadcrumbs-list stretches to iui-breadcrumbs
r100-stack Jul 19, 2024
722385f
nit
r100-stack Jul 19, 2024
e2b47a0
Fixed indexes and JSDocs explanation
r100-stack Jul 19, 2024
0d50c68
Review comments:
r100-stack Jul 19, 2024
2758496
Try to memoize as much as possible
r100-stack Jul 19, 2024
d180b6f
Created OverflowContainer.OverflowNode only in ButtonGroup for now.
r100-stack Jul 19, 2024
abd6485
OverflowContainer.OverflowNode for other components
r100-stack Jul 22, 2024
de81633
Import from utils root and not from inner paths.
r100-stack Jul 22, 2024
219e2ed
Memoize context value
r100-stack Jul 22, 2024
cd1a18a
Remove redundant OverflowGroup checks
r100-stack Jul 22, 2024
08f8b9f
Merge remote-tracking branch 'origin/main' into r/overflow-container-…
r100-stack Aug 6, 2024
bf4ff5c
Merged imports
r100-stack Aug 6, 2024
bdfaf1b
Use React.Children.toArray
r100-stack Aug 6, 2024
262ba5d
Merge remote-tracking branch 'origin/main' into r/unit-tests-to-e2e
r100-stack Aug 6, 2024
e9b3053
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Aug 6, 2024
a77da3f
Merge remote-tracking branch 'origin/main' into r/unit-tests-to-e2e
r100-stack Aug 29, 2024
f9f146e
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Aug 29, 2024
a05e8d4
`useOverflowContainerContext`
r100-stack Aug 29, 2024
77c8afe
Merge remote-tracking branch 'origin/main' into r/unit-tests-to-e2e
r100-stack Aug 29, 2024
f67b378
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Aug 29, 2024
99e3536
General improvements
r100-stack Aug 29, 2024
48e7fc7
Bug fixes
r100-stack Aug 30, 2024
42bc280
Fix test failures
r100-stack Aug 30, 2024
eaab58b
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Aug 30, 2024
0ddb674
Merge branch 'main' into r/unit-tests-to-e2e
r100-stack Sep 23, 2024
83ded22
Merge remote-tracking branch 'origin/r/unit-tests-to-e2e' into r/over…
r100-stack Sep 23, 2024
9fca3bc
Merge branch 'main' into r/unit-tests-to-e2e
r100-stack Sep 26, 2024
58acfaa
Merge remote-tracking branch 'origin/r/unit-tests-to-e2e' into r/over…
r100-stack Sep 26, 2024
1651f27
Fixed e2e test
r100-stack Sep 26, 2024
94dc4fc
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 26, 2024
fe9ccb9
Merge branch 'main' into r/unit-tests-to-e2e
r100-stack Sep 26, 2024
9fe39a3
Merge branch 'main' into r/unit-tests-to-e2e
r100-stack Sep 30, 2024
e012341
Merge remote-tracking branch 'origin/r/unit-tests-to-e2e' into r/over…
r100-stack Sep 30, 2024
f55d709
Improvements
r100-stack Sep 30, 2024
5c60090
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 30, 2024
b7c05ae
Simplicity
r100-stack Sep 30, 2024
6dedd71
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 30, 2024
3e82ea5
Improvements
r100-stack Sep 30, 2024
d615fd0
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 30, 2024
aa8b849
Remove unrelated test
r100-stack Oct 1, 2024
807e0f0
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Oct 1, 2024
314aac7
Reduce diff
r100-stack Oct 1, 2024
5b3e65c
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Oct 1, 2024
c23cffb
Changes
r100-stack Oct 1, 2024
2902ba0
Fix unit tests
r100-stack Oct 2, 2024
c67f2ff
Update outdated test
r100-stack Oct 2, 2024
e5bab06
Merge branch 'main' into r/unit-tests-to-e2e
r100-stack Oct 2, 2024
3c3588e
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container
r100-stack Oct 2, 2024
557e096
Fix test
r100-stack Oct 2, 2024
67ddecb
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container
r100-stack Oct 2, 2024
11af876
Fix test
r100-stack Oct 2, 2024
5321eab
Merge branch 'r/overflow-container' into r/overflow-container-without…
r100-stack Oct 2, 2024
192964d
`items` → `itemsCount`
r100-stack Oct 2, 2024
eb1cd2e
Comments on components
r100-stack Oct 8, 2024
7bfb92e
OverflowContainer comments
r100-stack Oct 8, 2024
33a02d6
Comment suggestion patch
r100-stack Oct 11, 2024
4ff8d97
Merge remote-tracking branch 'origin/main' into r/overflow-container-…
r100-stack Oct 14, 2024
fb18559
Fix focusedIndex out of sync with currentPage
r100-stack Oct 14, 2024
4fed729
🔧
r100-stack Oct 14, 2024
27fbb21
Merge branch 'r/table-paginator-arrow-keys-bug' into r/overflow-conta…
r100-stack Oct 14, 2024
863f69e
Fix e2e tests
r100-stack Oct 14, 2024
3c0e25f
Merge branch 'main' into r/overflow-container-without-new-algorithm
r100-stack Oct 15, 2024
c1bb020
nits
r100-stack Oct 15, 2024
1bec970
Merge branch 'main' into r/overflow-container-without-new-algorithm
r100-stack Oct 16, 2024
a9ca651
Fix e2e tests
r100-stack Oct 16, 2024
6ef0cc4
Merge branch 'main' into r/overflow-container-without-new-algorithm
r100-stack Oct 17, 2024
6f85103
Fix tests
r100-stack Oct 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/light-poems-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-css': patch
---

`iui-breadcrumbs-list` now stretches to the width of `iui-breadcrumbs`.
1 change: 1 addition & 0 deletions packages/itwinui-css/src/breadcrumbs/breadcrumbs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
list-style-type: none;
user-select: none;
block-size: 100%;
inline-size: 100%;
}

.iui-breadcrumbs-item {
Expand Down
125 changes: 73 additions & 52 deletions packages/itwinui-react/src/core/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import * as React from 'react';
import cx from 'classnames';
import {
useMergedRefs,
useOverflow,
SvgChevronRight,
Box,
OverflowContainer,
useWarningLogger,
} from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
Expand Down Expand Up @@ -114,70 +113,40 @@ type BreadcrumbsProps = {
*/
const BreadcrumbsComponent = React.forwardRef((props, ref) => {
const {
children: items,
currentIndex = items.length - 1,
children: childrenProp,
currentIndex = React.Children.count(childrenProp) - 1,
separator,
overflowButton,
className,
...rest
} = props;

const [overflowRef, visibleCount] = useOverflow(items.length);
const refs = useMergedRefs(overflowRef, ref);
const items = React.useMemo(
() => React.Children.toArray(childrenProp),
[childrenProp],
);

return (
<Box
as='nav'
className={cx('iui-breadcrumbs', className)}
ref={refs}
ref={ref}
aria-label='Breadcrumb'
{...rest}
>
<Box as='ol' className='iui-breadcrumbs-list'>
{visibleCount > 1 && (
<>
<ListItem item={items[0]} isActive={currentIndex === 0} />
<Separator separator={separator} />
</>
)}
{items.length - visibleCount > 0 && (
<>
<Box as='li' className='iui-breadcrumbs-item'>
{overflowButton ? (
overflowButton(visibleCount)
) : (
<Box as='span' className='iui-breadcrumbs-content'>
</Box>
)}
</Box>
<Separator separator={separator} />
</>
)}
{items
.slice(
visibleCount > 1
? items.length - visibleCount + 1
: items.length - 1,
)
.map((_, _index) => {
const index =
visibleCount > 1
? 1 + (items.length - visibleCount) + _index
: items.length - 1;
return (
<React.Fragment key={index}>
<ListItem
item={items[index]}
isActive={currentIndex === index}
/>
{index < items.length - 1 && (
<Separator separator={separator} />
)}
</React.Fragment>
);
})}
</Box>
<OverflowContainer
as='ol'
itemsCount={items.length}
className='iui-breadcrumbs-list'
>
<BreadcrumbContent
currentIndex={currentIndex}
overflowButton={overflowButton}
separator={separator}
>
{items}
</BreadcrumbContent>
</OverflowContainer>
</Box>
);
}) as PolymorphicForwardRefComponent<'nav', BreadcrumbsProps>;
Expand All @@ -187,6 +156,58 @@ if (process.env.NODE_ENV === 'development') {

// ----------------------------------------------------------------------------

type BreadcrumbContentProps = Omit<BreadcrumbsProps, 'currentIndex'> & {
currentIndex: NonNullable<BreadcrumbsProps['currentIndex']>;
};

const BreadcrumbContent = (props: BreadcrumbContentProps) => {
const { children: items, currentIndex, overflowButton, separator } = props;
const { visibleCount } = OverflowContainer.useContext();

return (
<>
{visibleCount > 1 && (
<>
<ListItem item={items[0]} isActive={currentIndex === 0} />
<Separator separator={separator} />
</>
)}
{items.length - visibleCount > 0 && (
<>
<Box as='li' className='iui-breadcrumbs-item'>
{overflowButton ? (
overflowButton(visibleCount)
) : (
<Box as='span' className='iui-breadcrumbs-content'>
</Box>
)}
</Box>
<Separator separator={separator} />
</>
)}
{items
.slice(
visibleCount > 1 ? items.length - visibleCount + 1 : items.length - 1,
)
.map((_, _index) => {
const index =
visibleCount > 1
? 1 + (items.length - visibleCount) + _index
: items.length - 1;
return (
<React.Fragment key={index}>
<ListItem item={items[index]} isActive={currentIndex === index} />
{index < items.length - 1 && <Separator separator={separator} />}
</React.Fragment>
);
})}
</>
);
};

// ----------------------------------------------------------------------------

const ListItem = ({
item,
isActive,
Expand Down
101 changes: 58 additions & 43 deletions packages/itwinui-react/src/core/ButtonGroup/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import cx from 'classnames';
import { useOverflow, useMergedRefs, Box } from '../../utils/index.js';
import { Box, OverflowContainer } from '../../utils/index.js';
import type {
AnyString,
PolymorphicForwardRefComponent,
Expand Down Expand Up @@ -172,6 +172,12 @@ const BaseGroup = React.forwardRef((props, forwardedRef) => {

// ----------------------------------------------------------------------------

type OverflowGroupProps = Pick<
ButtonGroupProps,
'children' | 'orientation' | 'overflowPlacement'
> &
Required<Pick<ButtonGroupProps, 'overflowButton'>>;

const OverflowGroup = React.forwardRef((props, forwardedRef) => {
const {
children: childrenProp,
Expand All @@ -186,14 +192,11 @@ const OverflowGroup = React.forwardRef((props, forwardedRef) => {
[childrenProp],
);

const [overflowRef, visibleCount] = useOverflow(
items.length,
!overflowButton,
orientation,
);

return (
<BaseGroup
<OverflowContainer
as={BaseGroup}
itemsCount={items.length}
overflowOrientation={orientation}
orientation={orientation}
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
{...rest}
className={cx(
Expand All @@ -203,40 +206,52 @@ const OverflowGroup = React.forwardRef((props, forwardedRef) => {
},
props.className,
)}
ref={useMergedRefs(forwardedRef, overflowRef)}
ref={forwardedRef}
>
{(() => {
if (!(visibleCount < items.length)) {
return items;
}

const overflowStart =
overflowPlacement === 'start'
? items.length - visibleCount
: visibleCount - 1;

return (
<>
{overflowButton &&
overflowPlacement === 'start' &&
overflowButton(overflowStart)}

{overflowPlacement === 'start'
? items.slice(overflowStart + 1)
: items.slice(0, Math.max(0, overflowStart))}

{overflowButton &&
overflowPlacement === 'end' &&
overflowButton(overflowStart)}
</>
);
})()}
</BaseGroup>
<OverflowGroupContent
overflowButton={overflowButton}
overflowPlacement={overflowPlacement}
items={items}
/>
</OverflowContainer>
);
}) as PolymorphicForwardRefComponent<
'div',
Pick<
ButtonGroupProps,
'children' | 'orientation' | 'overflowButton' | 'overflowPlacement'
>
>;
}) as PolymorphicForwardRefComponent<'div', OverflowGroupProps>;

// ----------------------------------------------------------------------------

type OverflowGroupContentProps = Pick<
OverflowGroupProps,
'overflowButton' | 'overflowPlacement'
> & {
items: ReturnType<typeof React.Children.toArray>;
};

const OverflowGroupContent = (props: OverflowGroupContentProps) => {
const { overflowButton, overflowPlacement, items } = props;
const { visibleCount } = OverflowContainer.useContext();

const overflowStart =
overflowPlacement === 'start'
? items.length - visibleCount
: visibleCount - 1;

if (!(visibleCount < items.length)) {
return items;
}

return (
<>
{overflowButton &&
overflowPlacement === 'start' &&
overflowButton(overflowStart)}

{overflowPlacement === 'start'
? items.slice(overflowStart + 1)
: items.slice(0, Math.max(0, overflowStart))}

{overflowButton &&
overflowPlacement === 'end' &&
overflowButton(overflowStart)}
</>
);
};
45 changes: 32 additions & 13 deletions packages/itwinui-react/src/core/Select/SelectTagContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*--------------------------------------------------------------------------------------------*/
import * as React from 'react';
import cx from 'classnames';
import { useOverflow, useMergedRefs, Box } from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import { SelectTag } from './SelectTag.js';
import { OverflowContainer } from '../../utils/index.js';

type SelectTagContainerProps = {
/**
Expand All @@ -18,23 +18,42 @@ type SelectTagContainerProps = {
/**
*/
export const SelectTagContainer = React.forwardRef((props, ref) => {
const { tags, className, ...rest } = props;
const { tags: tagsProp, className, ...rest } = props;

const [containerRef, visibleCount] = useOverflow(tags.length);
const refs = useMergedRefs(ref, containerRef);
const tags = React.useMemo(
() => React.Children.toArray(tagsProp),
[tagsProp],
);

return (
<Box
<OverflowContainer
itemsCount={tags.length}
className={cx('iui-select-tag-container', className)}
ref={refs}
ref={ref}
{...rest}
>
<>
{visibleCount < tags.length ? tags.slice(0, visibleCount - 1) : tags}
{visibleCount < tags.length && (
<SelectTag label={`+${tags.length - visibleCount + 1} item(s)`} />
)}
</>
</Box>
<SelectTagContainerContent {...props} tags={tags} />
</OverflowContainer>
);
}) as PolymorphicForwardRefComponent<'div', SelectTagContainerProps>;

// ----------------------------------------------------------------------------

type SelectTagContainerContentProps = {
tags: ReturnType<typeof React.Children.toArray>;
};

const SelectTagContainerContent = (props: SelectTagContainerContentProps) => {
const { tags } = props;
const { visibleCount } = OverflowContainer.useContext();

return (
<>
{visibleCount < tags.length ? tags.slice(0, visibleCount - 1) : tags}

<OverflowContainer.OverflowNode>
<SelectTag label={`+${tags.length - visibleCount + 1} item(s)`} />
</OverflowContainer.OverflowNode>
</>
);
};
Loading
Loading