Skip to content

Commit 2a36723

Browse files
committed
Better colours and filters
1 parent dedc478 commit 2a36723

File tree

5 files changed

+76
-25
lines changed

5 files changed

+76
-25
lines changed

app/models/category.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
class Category < ApplicationRecord
22
include Deletable
33

4-
COLORS = %w(gray red orange yellow green teal blue cyan purple pink)
4+
COLORS = %w(
5+
gray
6+
red
7+
orange
8+
yellow
9+
green
10+
teal
11+
blue
12+
cyan
13+
purple
14+
pink
15+
indigo
16+
fuchsia
17+
amber
18+
lime
19+
emerald
20+
sky
21+
violet
22+
rose
23+
)
524
ICONS = YAML.load_file(Rails.root.join('config', 'data', 'icons.yml'))['icons']
625

726
has_many :category_budgets

web/src/components/categories/CategoryForm.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,21 @@ const CategoryForm: Component<{
6767
{ value: "gray", content: <ColorOptionContent value="gray" /> },
6868
{ value: "red", content: <ColorOptionContent value="red" /> },
6969
{ value: "orange", content: <ColorOptionContent value="orange" /> },
70+
{ value: "amber", content: <ColorOptionContent value="amber" /> },
7071
{ value: "yellow", content: <ColorOptionContent value="yellow" /> },
72+
{ value: "lime", content: <ColorOptionContent value="lime" /> },
7173
{ value: "green", content: <ColorOptionContent value="green" /> },
74+
{ value: "emerald", content: <ColorOptionContent value="emerald" /> },
7275
{ value: "teal", content: <ColorOptionContent value="teal" /> },
73-
{ value: "blue", content: <ColorOptionContent value="blue" /> },
7476
{ value: "cyan", content: <ColorOptionContent value="cyan" /> },
77+
{ value: "sky", content: <ColorOptionContent value="sky" /> },
78+
{ value: "blue", content: <ColorOptionContent value="blue" /> },
79+
{ value: "indigo", content: <ColorOptionContent value="indigo" /> },
80+
{ value: "violet", content: <ColorOptionContent value="violet" /> },
7581
{ value: "purple", content: <ColorOptionContent value="purple" /> },
82+
{ value: "fuchsia", content: <ColorOptionContent value="fuchsia" /> },
7683
{ value: "pink", content: <ColorOptionContent value="pink" /> },
77-
{ value: "indigo", content: <ColorOptionContent value="indigo" /> },
78-
{ value: "fuchsia", content: <ColorOptionContent value="fuchsia" /> }
84+
{ value: "rose", content: <ColorOptionContent value="rose" /> }
7985
] satisfies Array<{ value: CategoryColor; content: JSX.Element }>
8086
}
8187
/>

web/src/components/transactions/TransactionFilters.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Form, FormStore, getValue } from "@modular-forms/solid"
22
import { noop } from "lodash"
3-
import { IconFilter } from "@tabler/icons-solidjs"
3+
import { IconFilter, IconX } from "@tabler/icons-solidjs"
44
import { Component, JSX, Show } from "solid-js"
55
import { useCategoriesQuery } from "../../graphql/queries/categoriesQuery"
66
import { namedIcons } from "../../utils/namedIcons"
77
import CategoryIndicator from "../CategoryIndicator"
88
import FormInput from "../forms/FormInput"
99
import FormOptionButtons from "../forms/FormOptionButtons"
1010
import { stripTime } from "../../utils/date"
11+
import { Button } from "../base/Button"
1112

1213
export type TransactionFilterValues = {
1314
dateFrom?: string
@@ -21,11 +22,13 @@ export type TransactionFilterValues = {
2122

2223
export const TransactionFilters: Component<{
2324
form: FormStore<TransactionFilterValues, undefined>
25+
clearFilters: () => void
26+
hasFilterValues: boolean
2427
}> = (props) => {
2528
const data = useCategoriesQuery(() => ({ archived: false, today: stripTime(new Date()) }))
2629

2730
return (
28-
<div class="mb-4 bg-white p-4 shadow-xs lg:rounded-sm" data-testid="filters-container">
31+
<div class="shadow-xs mb-4 bg-white p-4 lg:rounded-sm" data-testid="filters-container">
2932
<Form of={props.form} onSubmit={noop}>
3033
<FormInput
3134
of={props.form}
@@ -100,6 +103,16 @@ export const TransactionFilters: Component<{
100103
]}
101104
/>
102105
</Form>
106+
107+
<Button
108+
variant="ghost"
109+
size="sm"
110+
class="gap-2"
111+
onClick={props.clearFilters}
112+
disabled={!props.hasFilterValues}
113+
>
114+
<IconX /> Clear filters
115+
</Button>
103116
</div>
104117
)
105118
}

web/src/pages/transactions/TransactionsListPage.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Title } from "@solidjs/meta"
22
import { useNavigate, useRouteData } from "@solidjs/router"
3-
import { IconCalendarEvent, IconFilter, IconPlus, IconX } from "@tabler/icons-solidjs"
3+
import { IconCalendarEvent, IconFilter, IconPlus } from "@tabler/icons-solidjs"
44
import { Component, Show, createSignal, onMount } from "solid-js"
55
import { Cell } from "../../components/Cell"
66
import { Button } from "../../components/base/Button"
@@ -37,7 +37,7 @@ const TransactionsListPage: Component = () => {
3737
const [isFiltering, setFiltering] = createSignal(false)
3838
const [creatingTransaction, setCreatingTransaction] = createSignal(false)
3939

40-
const { form, hasFilterValues, filterCount, clearFilters, setFilterValue } =
40+
const { form, filterCount, hasFilterValues, clearFilters, setFilterValue } =
4141
usePageFilter<TransactionFilterValues>({
4242
basePath: "/transactions/list",
4343
paramName: "filter",
@@ -75,24 +75,15 @@ const TransactionsListPage: Component = () => {
7575
<IconPlus size="1.25em" class="-ml-1 mr-2" />
7676
Add
7777
</button>
78-
<Button
79-
class="mr-2"
80-
classList={{ hidden: !hasFilterValues() }}
81-
size="sm"
82-
colorScheme="primary"
83-
onClick={clearFilters}
84-
>
85-
{filterCount()} {filterCount() === 1 ? "filter" : "filters"}
86-
<IconX class="ml-2" />
87-
</Button>
8878
<Button
8979
colorScheme={isFiltering() ? "primary" : "neutral"}
9080
variant={isFiltering() ? "solid" : "ghost"}
91-
size="square"
81+
size={hasFilterValues() ? "md" : "square"}
9282
aria-label="Filter"
9383
onClick={() => setFiltering((isFiltering) => !isFiltering)}
9484
>
9585
<IconFilter size="1.25em" />
86+
{hasFilterValues() && `(${filterCount()})`}
9687
</Button>
9788
<Button
9889
class="ml-2"
@@ -111,7 +102,11 @@ const TransactionsListPage: Component = () => {
111102
</Show>
112103

113104
<div classList={{ block: isFiltering(), hidden: !isFiltering() }}>
114-
<TransactionFilters form={form} />
105+
<TransactionFilters
106+
form={form}
107+
clearFilters={clearFilters}
108+
hasFilterValues={hasFilterValues()}
109+
/>
115110
</div>
116111

117112
<Cell

web/src/utils/categoryColors.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,53 @@ export type CategoryColor =
1111
| "pink"
1212
| "indigo"
1313
| "fuchsia"
14+
| "amber"
15+
| "lime"
16+
| "emerald"
17+
| "sky"
18+
| "violet"
19+
| "rose"
1420

1521
export const CATEGORY_BACKGROUND_COLORS: { [key in CategoryColor]: string } = {
1622
gray: "bg-gray-500",
1723
red: "bg-red-500",
1824
orange: "bg-orange-500",
25+
amber: "bg-amber-500",
1926
yellow: "bg-yellow-500",
27+
lime: "bg-lime-500",
2028
green: "bg-green-500",
29+
emerald: "bg-emerald-500",
2130
teal: "bg-teal-500",
22-
blue: "bg-blue-500",
2331
cyan: "bg-cyan-500",
32+
sky: "bg-sky-500",
33+
blue: "bg-blue-500",
34+
indigo: "bg-indigo-500",
35+
violet: "bg-violet-500",
2436
purple: "bg-purple-500",
37+
fuchsia: "bg-fuchsia-500",
2538
pink: "bg-pink-500",
26-
indigo: "bg-indigo-500",
27-
fuchsia: "bg-fuchsia-500"
39+
rose: "bg-rose-500"
2840
}
2941

3042
export const CATEGORY_PALE_BACKGROUND_COLORS: { [key in CategoryColor]: string } = {
3143
gray: "bg-gray-200",
3244
red: "bg-red-200",
3345
orange: "bg-orange-200",
46+
amber: "bg-amber-200",
3447
yellow: "bg-yellow-200",
48+
lime: "bg-lime-200",
49+
emerald: "bg-emerald-200",
3550
green: "bg-green-200",
3651
teal: "bg-teal-200",
3752
blue: "bg-blue-200",
3853
cyan: "bg-cyan-200",
54+
sky: "bg-sky-200",
55+
violet: "bg-violet-200",
3956
purple: "bg-purple-200",
40-
pink: "bg-pink-200",
4157
indigo: "bg-indigo-200",
42-
fuchsia: "bg-fuchsia-200"
58+
fuchsia: "bg-fuchsia-200",
59+
pink: "bg-pink-200",
60+
rose: "bg-rose-200"
4361
}
4462

4563
export const CATEGORY_COLORS = Object.keys(CATEGORY_BACKGROUND_COLORS)

0 commit comments

Comments
 (0)