scrolling fixed for buttons

pull/5370/head
lianahus 2 years ago committed by Aniket
parent c25b9cb37e
commit 9951906fb3
  1. 14
      libs/remix-ui/home-tab/src/lib/components/customButtonGroupAsArrows.tsx
  2. 10
      libs/remix-ui/home-tab/src/lib/components/customNavButtons.tsx
  3. 15
      libs/remix-ui/home-tab/src/lib/components/homeTabFeatured.tsx
  4. 7
      libs/remix-ui/home-tab/src/lib/components/homeTabFeaturedPlugins.tsx
  5. 6
      libs/remix-ui/home-tab/src/lib/components/homeTabGetStarted.tsx
  6. 2
      libs/remix-ui/home-tab/src/lib/components/homeTabTitle.tsx

@ -1,14 +0,0 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react'
function CustomButtonGroupAsArrows ({ next, previous }) {
return (
<div style={{ textAlign: "center" }}>
<h4>These buttons can be positioned anywhere you want on the screen</h4>
<button onClick={previous}>Prev</button>
<button onClick={next}>Next</button>
</div>
)
}
export default CustomButtonGroupAsArrows

@ -1,8 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react' import React from 'react'
const CustomNavButtons = ({ next, previous, goToSlide, ...rest }) => { const CustomNavButtons = ({ parent, next, previous, goToSlide, ...rest }) => {
const { carouselState: { currentSlide, totalItems, itemWidth, containerWidth } } = rest const { carouselState: { currentSlide, totalItems, containerWidth, transform } } = rest
console.log("REST ", rest)
console.log("parent ", parent)
return ( return (
<div className="mt-1 d-flex justify-content-end carousel-button-group"> <div className="mt-1 d-flex justify-content-end carousel-button-group">
<button <button
@ -14,11 +16,11 @@ const CustomNavButtons = ({ next, previous, goToSlide, ...rest }) => {
</button> </button>
<button <button
className={ className={
((totalItems - currentSlide) * itemWidth + 5) < containerWidth ? 'disable py-1 border btn' : 'py-1 border btn'} (Math.abs(transform) >= parent?.current?.containerRef?.current?.scrollWidth - containerWidth) ? 'disable py-1 border btn' : 'py-1 border btn'}
onClick={() => { onClick={() => {
if (currentSlide + 1 < totalItems) goToSlide(currentSlide + 1) if (currentSlide + 1 < totalItems) goToSlide(currentSlide + 1)
}} }}
disabled ={((totalItems - currentSlide) * itemWidth + 5) < containerWidth} disabled ={Math.abs(transform) >= parent?.current?.containerRef?.current?.scrollWidth - containerWidth}
> >
<i className="fas fa-angle-right"></i> <i className="fas fa-angle-right"></i>
</button> </button>

@ -3,7 +3,7 @@ import React, { useEffect, useState, useRef, useContext } from 'react'
import { ThemeContext, themes } from '../themeContext' import { ThemeContext, themes } from '../themeContext'
import Carousel from 'react-multi-carousel' import Carousel from 'react-multi-carousel'
import 'react-multi-carousel/lib/styles.css' import 'react-multi-carousel/lib/styles.css'
import CustomNavButtons from './customNavButtons' import CustomButtonGroupDots from './customButtonGroupDots'
const _paq = window._paq = window._paq || [] // eslint-disable-line const _paq = window._paq = window._paq || [] // eslint-disable-line
function HomeTabFeatured() { function HomeTabFeatured() {
@ -14,6 +14,16 @@ function HomeTabFeatured() {
} }
}, []) }, [])
const ButtonGroup = () => {
return (
<>
<button>One</button>
<button>Two</button>
<button>Three</button>
</>
);
};
return ( return (
<div className="pt-3 pl-2" id="hTFeaturedeSection"> <div className="pt-3 pl-2" id="hTFeaturedeSection">
<label style={{ fontSize: "1.2rem" }}>Featured</label> <label style={{ fontSize: "1.2rem" }}>Featured</label>
@ -21,7 +31,7 @@ function HomeTabFeatured() {
<div className="w-100 d-flex flex-column" style={{ height: "200px" }}> <div className="w-100 d-flex flex-column" style={{ height: "200px" }}>
<ThemeContext.Provider value={themeFilter}> <ThemeContext.Provider value={themeFilter}>
<Carousel <Carousel
customButtonGroup={<CustomNavButtons next={undefined} previous={undefined} goToSlide={undefined} />} customButtonGroup={<CustomButtonGroupDots next={undefined} previous={undefined} goToSlide={undefined} />}
arrows={false} arrows={false}
swipeable={false} swipeable={false}
draggable={true} draggable={true}
@ -31,6 +41,7 @@ function HomeTabFeatured() {
ssr={true} // means to render carousel on server-side. ssr={true} // means to render carousel on server-side.
infinite={true} infinite={true}
centerMode={false} centerMode={false}
partialVisible={false}
autoPlay={true} autoPlay={true}
keyBoardControl={true} keyBoardControl={true}
containerClass="border carousel-container" containerClass="border carousel-container"

@ -20,7 +20,7 @@ interface HomeTabFeaturedPluginsProps {
function HomeTabFeaturedPlugins ({plugin}: HomeTabFeaturedPluginsProps) { function HomeTabFeaturedPlugins ({plugin}: HomeTabFeaturedPluginsProps) {
const themeFilter = useContext(ThemeContext) const themeFilter = useContext(ThemeContext)
const carouselRef = useRef(null) const carouselRef = useRef<any>({})
const carouselRefDiv = useRef(null) const carouselRefDiv = useRef(null)
useEffect(() => { useEffect(() => {
@ -46,8 +46,9 @@ function HomeTabFeaturedPlugins ({plugin}: HomeTabFeaturedPluginsProps) {
e.stopPropagation() e.stopPropagation()
let nextSlide = 0 let nextSlide = 0
if (e.wheelDelta < 0) { if (e.wheelDelta < 0) {
console.log("scroll")
nextSlide = carouselRef.current.state.currentSlide + 1; nextSlide = carouselRef.current.state.currentSlide + 1;
if ((carouselRef.current.state.totalItems - carouselRef.current.state.currentSlide) * carouselRef.current.state.itemWidth + 5 < carouselRef.current.state.containerWidth) return // 5 is approx margins if (Math.abs(carouselRef.current.state.transform) >= carouselRef.current.containerRef.current.scrollWidth - carouselRef.current.state.containerWidth) return
carouselRef.current.goToSlide(nextSlide) carouselRef.current.goToSlide(nextSlide)
} else { } else {
nextSlide = carouselRef.current.state.currentSlide - 1; nextSlide = carouselRef.current.state.currentSlide - 1;
@ -92,7 +93,7 @@ function HomeTabFeaturedPlugins ({plugin}: HomeTabFeaturedPluginsProps) {
ref={carouselRef} ref={carouselRef}
focusOnSelect={true} focusOnSelect={true}
customButtonGroup={ customButtonGroup={
<CustomNavButtons next={undefined} previous={undefined} goToSlide={undefined} /> <CustomNavButtons next={undefined} previous={undefined} goToSlide={undefined} parent={carouselRef} />
} }
arrows={false} arrows={false}
swipeable={false} swipeable={false}

@ -17,7 +17,7 @@ interface HomeTabGetStartedProps {
function HomeTabGetStarted ({plugin}: HomeTabGetStartedProps) { function HomeTabGetStarted ({plugin}: HomeTabGetStartedProps) {
const themeFilter = useContext(ThemeContext) const themeFilter = useContext(ThemeContext)
const carouselRef = useRef(null) const carouselRef = useRef<any>({})
const carouselRefDiv = useRef(null) const carouselRefDiv = useRef(null)
useEffect(() => { useEffect(() => {
@ -44,7 +44,7 @@ function HomeTabGetStarted ({plugin}: HomeTabGetStartedProps) {
let nextSlide = 0 let nextSlide = 0
if (e.wheelDelta < 0) { if (e.wheelDelta < 0) {
nextSlide = carouselRef.current.state.currentSlide + 1; nextSlide = carouselRef.current.state.currentSlide + 1;
if ((carouselRef.current.state.totalItems - carouselRef.current.state.currentSlide) * carouselRef.current.state.itemWidth + 5 < carouselRef.current.state.containerWidth) return // 5 is approx margins if (Math.abs(carouselRef.current.state.transform) >= carouselRef.current.containerRef.current.scrollWidth - carouselRef.current.state.containerWidth) return
carouselRef.current.goToSlide(nextSlide) carouselRef.current.goToSlide(nextSlide)
} else { } else {
nextSlide = carouselRef.current.state.currentSlide - 1; nextSlide = carouselRef.current.state.currentSlide - 1;
@ -77,7 +77,7 @@ function HomeTabGetStarted ({plugin}: HomeTabGetStartedProps) {
ref={carouselRef} ref={carouselRef}
focusOnSelect={true} focusOnSelect={true}
customButtonGroup={ customButtonGroup={
<CustomNavButtons next={undefined} previous={undefined} goToSlide={undefined} /> <CustomNavButtons next={undefined} previous={undefined} goToSlide={undefined} parent={carouselRef} />
} }
arrows={false} arrows={false}
swipeable={false} swipeable={false}

@ -157,7 +157,7 @@ function HomeTabTitle() {
ref={searchInputRef} ref={searchInputRef}
type="text" type="text"
className="border form-control border-right-0" className="border form-control border-right-0"
id="searchInput" id="homeTabSearchInput"
placeholder="Search Documentation" placeholder="Search Documentation"
data-id="terminalInputSearch" data-id="terminalInputSearch"
/> />

Loading…
Cancel
Save