-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'task-6780' of github.com:makafsal/ibm-products into tas…
…k-6780
- Loading branch information
Showing
12 changed files
with
1,716 additions
and
2,064 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/ibm-products/src/global/js/hooks/useOverflowItems/_storybook-styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Copyright IBM Corp. 2025 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.slider { | ||
/* stylelint-disable-next-line carbon/layout-use */ | ||
margin-block-end: 1rem; | ||
} | ||
|
||
.parent { | ||
overflow: scroll; | ||
max-inline-size: 100%; | ||
scrollbar-width: none; | ||
} | ||
|
||
.child { | ||
white-space: nowrap; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/ibm-products/src/global/js/hooks/useOverflowItems/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/** | ||
* Copyright IBM Corp. 2025 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
export { useOverflowItems } from './useOverflowItems'; |
103 changes: 103 additions & 0 deletions
103
packages/ibm-products/src/global/js/hooks/useOverflowItems/useOverflowItems.stories.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* Copyright IBM Corp. 2025 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, { useRef, useState } from 'react'; | ||
import { useOverflowItems } from './useOverflowItems'; | ||
import { Tag, Slider } from '@carbon/react'; | ||
import { Annotation } from '../../../../../../core/.storybook/Annotation'; | ||
import { FitToWidth } from '@carbon/react/icons'; | ||
import './_storybook-styles.scss'; | ||
|
||
export default { | ||
title: 'Hooks/useOverflowItems', | ||
parameters: { | ||
layout: 'padded', | ||
}, | ||
}; | ||
|
||
const Template = () => { | ||
const [width, setWidth] = useState(500); | ||
const [numberOfTags, setNumberOfTags] = useState(10); | ||
const containerRef = useRef(null); | ||
|
||
const makeTags = (n) => { | ||
return Array(n) | ||
.fill(null) | ||
.map((_, idx) => ({ | ||
id: idx, | ||
label: `Tag ${idx + 1}`, | ||
})); | ||
}; | ||
|
||
const tags = makeTags(numberOfTags); | ||
|
||
const { visibleItems, hiddenItems, itemRefHandler } = useOverflowItems( | ||
tags, | ||
containerRef | ||
); | ||
|
||
const widthHandler = (n) => { | ||
setWidth(n); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<Slider | ||
className="slider" | ||
max={1000} | ||
min={200} | ||
value={width} | ||
onChange={({ value }) => widthHandler(value)} | ||
hideTextInput | ||
labelText="Parent container width" | ||
/> | ||
<Slider | ||
className="slider" | ||
max={50} | ||
min={1} | ||
value={numberOfTags} | ||
onChange={({ value }) => setNumberOfTags(value)} | ||
hideTextInput | ||
labelText="Number of total tags" | ||
/> | ||
<div | ||
className="parent" | ||
style={{ | ||
width: `${width}px`, | ||
}} | ||
> | ||
<Annotation text="Parent container" type="layer" icon={FitToWidth}> | ||
<div className="child" ref={containerRef}> | ||
<p>Visible items:</p> | ||
{visibleItems.map((tag) => ( | ||
<Tag | ||
type="blue" | ||
key={tag.id} | ||
ref={(node) => { | ||
itemRefHandler(tag.id, node); | ||
}} | ||
> | ||
{tag.label} | ||
</Tag> | ||
))} | ||
</div> | ||
<div> | ||
<p>Hidden items:</p> | ||
{hiddenItems.map((tag) => ( | ||
<Tag key={tag.id} type="blue"> | ||
{tag.label} | ||
</Tag> | ||
))} | ||
</div> | ||
</Annotation> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const DefaultUsage = Template.bind({}); | ||
DefaultUsage.args = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.