Skip to content

Commit

Permalink
add none to sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
severinlandolt committed May 19, 2024
1 parent 45bdefe commit 1646770
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 8 additions & 8 deletions src/components/BarList/BarList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Tremor Raw BarList [v0.0.1]
// Tremor Raw BarList [v0.1.0]

import React from "react"

Expand All @@ -18,7 +18,7 @@ interface BarListProps<T = unknown>
valueFormatter?: (value: number) => string
showAnimation?: boolean
onValueChange?: (payload: Bar<T>) => void
sortOrder?: "ascending" | "descending"
sortOrder?: "ascending" | "descending" | "none"
}

function BarListInner<T>(
Expand All @@ -35,12 +35,12 @@ function BarListInner<T>(
) {
const Component = onValueChange ? "button" : "div"
const sortedData = React.useMemo(() => {
if (sortOrder) {
return [...data].sort((a, b) => {
return sortOrder === "ascending" ? a.value - b.value : b.value - a.value
})
if (sortOrder === "none") {
return data
}
return data
return [...data].sort((a, b) => {
return sortOrder === "ascending" ? a.value - b.value : b.value - a.value
})
}, [data, sortOrder])

const widths = React.useMemo(() => {
Expand Down Expand Up @@ -98,7 +98,7 @@ function BarListInner<T>(
)}
style={{ width: `${widths[index]}%` }}
>
<div className={cx("absolute left-2 flex pr-2 max-w-full")}>
<div className={cx("absolute left-2 flex max-w-full pr-2")}>
{item.href ? (
<a
href={item.href}
Expand Down
7 changes: 7 additions & 0 deletions src/components/BarList/barlist.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export const WithSortOrderAscending: Story = {
},
}

export const WithSortOrderNone: Story = {
args: {
data: data,
sortOrder: "none",
},
}

export const WithOnValueChange: Story = {
args: {
data: data,
Expand Down
10 changes: 8 additions & 2 deletions src/components/BarList/changelog.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# Tremor Raw BarList Changelog

## 0.1.0

### Changes

- Added sortOrder: `none` option

## 0.0.1

### Changes

* Improve spacing when bar is a button.
* Improve padding for long labels.
- Improve spacing when bar is a button.
- Improve padding for long labels.

0 comments on commit 1646770

Please sign in to comment.