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

Open
wants to merge 34 commits into
base: r/overflow-container
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1787868
Brought back OverflowContainer and usages
r100-stack Jul 18, 2024
8937b87
Modified components to work with old useOverflow
r100-stack Jul 18, 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
e9b3053
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Aug 6, 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
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
eaab58b
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Aug 30, 2024
83ded22
Merge remote-tracking branch 'origin/r/unit-tests-to-e2e' into r/over…
r100-stack Sep 23, 2024
58acfaa
Merge remote-tracking branch 'origin/r/unit-tests-to-e2e' into r/over…
r100-stack Sep 26, 2024
94dc4fc
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 26, 2024
e012341
Merge remote-tracking branch 'origin/r/unit-tests-to-e2e' into r/over…
r100-stack Sep 30, 2024
5c60090
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 30, 2024
6dedd71
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 30, 2024
d615fd0
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Sep 30, 2024
807e0f0
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Oct 1, 2024
5b3e65c
Merge branch 'r/unit-tests-to-e2e' into r/overflow-container-without-…
r100-stack Oct 1, 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
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
94 changes: 47 additions & 47 deletions packages/itwinui-react/src/core/Breadcrumbs/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import * as React from 'react';
import cx from 'classnames';
import {
useMergedRefs,
useOverflow,
SvgChevronRight,
Box,
createWarningLogger,
} from '../../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
import { Button } from '../Buttons/Button.js';
import { Anchor } from '../Typography/Anchor.js';
import { OverflowContainer } from '../../utils/components/OverflowContainer.js';

const logWarning = createWarningLogger();

Expand Down Expand Up @@ -124,62 +123,63 @@ const BreadcrumbsComponent = React.forwardRef((props, ref) => {
...rest
} = props;

const [overflowRef, visibleCount] = useOverflow(items);
const refs = useMergedRefs(overflowRef, ref);

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 && (
<OverflowContainer as='ol' className='iui-breadcrumbs-list' items={items}>
{(visibleCount) => (
<>
<Box as='li' className='iui-breadcrumbs-item'>
{overflowButton ? (
overflowButton(visibleCount)
) : (
<Box as='span' className='iui-breadcrumbs-content'>
{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>
)}
</Box>
<Separator separator={separator} />
<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>
);
})}
</>
)}
{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>
</Box>
);
}) as PolymorphicForwardRefComponent<'nav', BreadcrumbsProps>;
Expand Down
53 changes: 20 additions & 33 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 } from '../../utils/index.js';
import type {
AnyString,
PolymorphicForwardRefComponent,
Expand All @@ -14,6 +14,7 @@ import {
CompositeItem,
FloatingDelayGroup,
} from '@floating-ui/react';
import { OverflowContainer } from '../../utils/components/OverflowContainer.js';

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

Expand Down Expand Up @@ -172,6 +173,7 @@ const BaseGroup = React.forwardRef((props, forwardedRef) => {

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

/** Note: If `overflowButton == null`, it behaves like a `BaseGroup`. */
mayank99 marked this conversation as resolved.
Show resolved Hide resolved
const OverflowGroup = React.forwardRef((props, forwardedRef) => {
const {
children: childrenProp,
Expand All @@ -186,14 +188,12 @@ const OverflowGroup = React.forwardRef((props, forwardedRef) => {
[childrenProp],
);

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

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

const overflowStart =
ref={forwardedRef}
overflowTag={(visibleCount) => {
const firstOverflowingIndex =
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)}
</>
);
})()}
return overflowButton(firstOverflowingIndex);
}}
>
{items}
</OverflowContainer>
) : (
<BaseGroup orientation={orientation} ref={forwardedRef} {...rest}>
{childrenProp}
</BaseGroup>
);
}) as PolymorphicForwardRefComponent<
Expand Down
22 changes: 9 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/components/OverflowContainer.js';

type SelectTagContainerProps = {
/**
Expand All @@ -20,21 +20,17 @@ type SelectTagContainerProps = {
export const SelectTagContainer = React.forwardRef((props, ref) => {
const { tags, className, ...rest } = props;

const [containerRef, visibleCount] = useOverflow(tags);
const refs = useMergedRefs(ref, containerRef);

return (
<Box
<OverflowContainer
items={tags}
overflowTag={(visibleCount) => (
<SelectTag label={`+${tags.length - (visibleCount - 1)} item(s)`} /> // -1 to account for the overflowTag
)}
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>
{tags}
</OverflowContainer>
);
}) as PolymorphicForwardRefComponent<'div', SelectTagContainerProps>;
Loading
Loading