Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: legend scroll distance #45

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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