Merge branch 'feed-carousel-fixes' into 'develop'
Set the ref on the actual carousel div See merge request soapbox-pub/soapbox-fe!1661
This commit is contained in:
commit
2d425f7a26
2 changed files with 10 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import React from 'react';
|
import React, { forwardRef } from 'react';
|
||||||
|
|
||||||
const justifyContentOptions = {
|
const justifyContentOptions = {
|
||||||
between: 'justify-between',
|
between: 'justify-between',
|
||||||
|
@ -32,6 +32,8 @@ interface IHStack {
|
||||||
alignItems?: 'top' | 'bottom' | 'center' | 'start',
|
alignItems?: 'top' | 'bottom' | 'center' | 'start',
|
||||||
/** Extra class names on the <div> element. */
|
/** Extra class names on the <div> element. */
|
||||||
className?: string,
|
className?: string,
|
||||||
|
/** Children */
|
||||||
|
children?: React.ReactNode,
|
||||||
/** Horizontal alignment of children. */
|
/** Horizontal alignment of children. */
|
||||||
justifyContent?: 'between' | 'center' | 'start' | 'end' | 'around',
|
justifyContent?: 'between' | 'center' | 'start' | 'end' | 'around',
|
||||||
/** Size of the gap between elements. */
|
/** Size of the gap between elements. */
|
||||||
|
@ -43,12 +45,13 @@ interface IHStack {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Horizontal row of child elements. */
|
/** Horizontal row of child elements. */
|
||||||
const HStack: React.FC<IHStack> = (props) => {
|
const HStack = forwardRef<HTMLDivElement, IHStack>((props, ref) => {
|
||||||
const { space, alignItems, grow, justifyContent, className, ...filteredProps } = props;
|
const { space, alignItems, grow, justifyContent, className, ...filteredProps } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
{...filteredProps}
|
{...filteredProps}
|
||||||
|
ref={ref}
|
||||||
className={classNames('flex', {
|
className={classNames('flex', {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
[alignItemsOptions[alignItems]]: typeof alignItems !== 'undefined',
|
[alignItemsOptions[alignItems]]: typeof alignItems !== 'undefined',
|
||||||
|
@ -60,6 +63,6 @@ const HStack: React.FC<IHStack> = (props) => {
|
||||||
}, className)}
|
}, className)}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export default HStack;
|
export default HStack;
|
||||||
|
|
|
@ -110,7 +110,7 @@ const FeedCarousel = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card variant='rounded' size='lg' ref={setCardRef} className='relative' data-testid='feed-carousel'>
|
<Card variant='rounded' size='lg' className='relative' data-testid='feed-carousel'>
|
||||||
<div>
|
<div>
|
||||||
{hasPrevPage && (
|
{hasPrevPage && (
|
||||||
<div>
|
<div>
|
||||||
|
@ -118,7 +118,7 @@ const FeedCarousel = () => {
|
||||||
<button
|
<button
|
||||||
data-testid='prev-page'
|
data-testid='prev-page'
|
||||||
onClick={handlePrevPage}
|
onClick={handlePrevPage}
|
||||||
className='bg-white/85 backdrop-blur rounded-full h-8 w-8 flex items-center justify-center'
|
className='bg-white/50 dark:bg-gray-900/50 backdrop-blur rounded-full h-8 w-8 flex items-center justify-center'
|
||||||
>
|
>
|
||||||
<Icon src={require('@tabler/icons/chevron-left.svg')} className='text-black dark:text-white h-6 w-6' />
|
<Icon src={require('@tabler/icons/chevron-left.svg')} className='text-black dark:text-white h-6 w-6' />
|
||||||
</button>
|
</button>
|
||||||
|
@ -131,6 +131,7 @@ const FeedCarousel = () => {
|
||||||
space={8}
|
space={8}
|
||||||
className='z-0 flex transition-all duration-200 ease-linear scroll'
|
className='z-0 flex transition-all duration-200 ease-linear scroll'
|
||||||
style={{ transform: `translateX(-${(currentPage - 1) * 100}%)` }}
|
style={{ transform: `translateX(-${(currentPage - 1) * 100}%)` }}
|
||||||
|
ref={setCardRef}
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
new Array(pageSize).fill(0).map((_, idx) => (
|
new Array(pageSize).fill(0).map((_, idx) => (
|
||||||
|
@ -154,7 +155,7 @@ const FeedCarousel = () => {
|
||||||
<button
|
<button
|
||||||
data-testid='next-page'
|
data-testid='next-page'
|
||||||
onClick={handleNextPage}
|
onClick={handleNextPage}
|
||||||
className='bg-white/85 backdrop-blur rounded-full h-8 w-8 flex items-center justify-center'
|
className='bg-white/50 dark:bg-gray-900/50 backdrop-blur rounded-full h-8 w-8 flex items-center justify-center'
|
||||||
>
|
>
|
||||||
<Icon src={require('@tabler/icons/chevron-right.svg')} className='text-black dark:text-white h-6 w-6' />
|
<Icon src={require('@tabler/icons/chevron-right.svg')} className='text-black dark:text-white h-6 w-6' />
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Reference in a new issue