Skip to content

Commit

Permalink
fix: legend scroll distance (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt committed Jun 23, 2024
1 parent 918209b commit 7c30471
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/components/AreaChart/AreaChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tremor Raw AreaChart [v0.2.1]
// Tremor Raw AreaChart [v0.2.2]

"use client"

Expand Down Expand Up @@ -167,6 +167,7 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
...other
} = props
const scrollableRef = React.useRef<HTMLInputElement>(null)
const scrollButtonsRef = React.useRef<HTMLDivElement>(null)
const [hasScroll, setHasScroll] = React.useState<HasScrollProps | null>(null)
const [isKeyDowned, setIsKeyDowned] = React.useState<string | null>(null)
const intervalRef = React.useRef<NodeJS.Timeout | null>(null)
Expand All @@ -185,14 +186,16 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
const scrollToTest = React.useCallback(
(direction: "left" | "right") => {
const element = scrollableRef?.current
const scrollButtons = scrollButtonsRef?.current
const scrollButtonsWith = scrollButtons?.clientWidth ?? 0
const width = element?.clientWidth ?? 0

if (element && enableLegendSlider) {
element.scrollTo({
left:
direction === "left"
? element.scrollLeft - width
: element.scrollLeft + width,
? element.scrollLeft - width + scrollButtonsWith
: element.scrollLeft + width - scrollButtonsWith,
behavior: "smooth",
})
setTimeout(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/AreaChart/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Tremor Raw AreaChart Changelog

## 0.2.2

### Changes

- Fix: Legend scroll distance

## 0.2.1

### Changes
Expand Down
9 changes: 6 additions & 3 deletions src/components/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tremor Raw BarChart [v0.1.0]
// Tremor Raw BarChart [v0.1.1]

"use client"

Expand Down Expand Up @@ -222,6 +222,7 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
...other
} = props
const scrollableRef = React.useRef<HTMLInputElement>(null)
const scrollButtonsRef = React.useRef<HTMLDivElement>(null)
const [hasScroll, setHasScroll] = React.useState<HasScrollProps | null>(null)
const [isKeyDowned, setIsKeyDowned] = React.useState<string | null>(null)
const intervalRef = React.useRef<NodeJS.Timeout | null>(null)
Expand All @@ -240,14 +241,16 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
const scrollToTest = React.useCallback(
(direction: "left" | "right") => {
const element = scrollableRef?.current
const scrollButtons = scrollButtonsRef?.current
const scrollButtonsWith = scrollButtons?.clientWidth ?? 0
const width = element?.clientWidth ?? 0

if (element && enableLegendSlider) {
element.scrollTo({
left:
direction === "left"
? element.scrollLeft - width
: element.scrollLeft + width,
? element.scrollLeft - width + scrollButtonsWith
: element.scrollLeft + width - scrollButtonsWith,
behavior: "smooth",
})
setTimeout(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/BarChart/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Tremor Raw BarChart Changelog

## 0.1.1

### Changes

- Fix: Legend scroll distance

## 0.1.0

### Changes
Expand Down
9 changes: 6 additions & 3 deletions src/components/LineChart/LineChart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tremor Raw LineChart [v0.2.0]
// Tremor Raw LineChart [v0.2.1]

"use client"

Expand Down Expand Up @@ -166,6 +166,7 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
...other
} = props
const scrollableRef = React.useRef<HTMLInputElement>(null)
const scrollButtonsRef = React.useRef<HTMLDivElement>(null)
const [hasScroll, setHasScroll] = React.useState<HasScrollProps | null>(null)
const [isKeyDowned, setIsKeyDowned] = React.useState<string | null>(null)
const intervalRef = React.useRef<NodeJS.Timeout | null>(null)
Expand All @@ -184,14 +185,16 @@ const Legend = React.forwardRef<HTMLOListElement, LegendProps>((props, ref) => {
const scrollToTest = React.useCallback(
(direction: "left" | "right") => {
const element = scrollableRef?.current
const scrollButtons = scrollButtonsRef?.current
const scrollButtonsWith = scrollButtons?.clientWidth ?? 0
const width = element?.clientWidth ?? 0

if (element && enableLegendSlider) {
element.scrollTo({
left:
direction === "left"
? element.scrollLeft - width
: element.scrollLeft + width,
? element.scrollLeft - width + scrollButtonsWith
: element.scrollLeft + width - scrollButtonsWith,
behavior: "smooth",
})
setTimeout(() => {
Expand Down
6 changes: 6 additions & 0 deletions src/components/LineChart/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Tremor Raw LineChart Changelog

## 0.2.1

### Changes

- Fix: Legend scroll distance

## 0.2.0

### Changes
Expand Down

0 comments on commit 7c30471

Please sign in to comment.