Skip to content

Commit

Permalink
Fix type error and add children prop to ArrayContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
wduckitt committed May 7, 2024
1 parent 1054183 commit 7b9e534
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions ReactApp/src/components/CompoundComponents/ArrayContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function ArrayContainer({
const [items, setItems] = useState([]);

let maxItems = 100;
let numVisibleItems = 10;
let numVisibleItems:number = 10;
if (registers !== undefined && Array.isArray(registers)) {
numVisibleItems = registers.length;
maxItems = registers.length;
Expand All @@ -63,7 +63,7 @@ function ArrayContainer({
}

useEffect(() => {
let newItems = [];
let newItems:any = [];
for (let i = 0; i < numVisibleItems; i++) {
newItems.push({
index: i,
Expand All @@ -75,7 +75,7 @@ function ArrayContainer({
}, [numVisibleItems]);

const updateItems = (newStartIdx) => {
let newItems = [...items];
let newItems:any = [...items];
if (newStartIdx < startIdx) {
let newItem = {
index: newStartIdx,
Expand Down Expand Up @@ -132,22 +132,22 @@ function ArrayContainer({
display: direction === "horizontal" ? "inline-block" : undefined,
width:
direction === "horizontal"
? Math.max(
parseFloat(100 / numVisibleItems).toFixed(2),
? `${Math.max(
parseFloat((100 / numVisibleItems).toFixed(2)),
itemMinWidth
) + "%"
)} %`
: undefined,
}}
>
{Children.map(props.children, (child) =>
{Children.map(props.children, (child:any) =>
cloneElement(child, additionalProps)
)}
</div>
);
};

let visibleItems = [];
items.forEach((item) => {
let visibleItems:any[] = [];
items.forEach((item:any) => {
if (item.index >= startIdx && item.index < startIdx + numVisibleItems) {
visibleItems.push(item.component);
}
Expand Down Expand Up @@ -233,6 +233,10 @@ interface ArrayContainerProps {
* Must be a non negative integer.
*/
spacing?: number;
/**
* The children of the ArrayContainer must be BaseComponents.
*/
children: React.ReactNode;
}

export default ArrayContainer;
Expand Down

0 comments on commit 7b9e534

Please sign in to comment.