-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow grouping bookmark color to be selected
- Loading branch information
Showing
12 changed files
with
200 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
/* eslint-disable no-undef */ | ||
|
||
exports.up = knex => | ||
knex.raw(/*sql*/ ` | ||
ALTER TABLE expense_groupings ADD COLUMN color TEXT; | ||
`); | ||
|
||
exports.down = knex => | ||
knex.raw(/*sql*/ ` | ||
ALTER TABLE expense_groupings DROP COLUMN color; | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import styled from '@emotion/styled'; | ||
import { colors, IconButton } from '@mui/material'; | ||
import * as React from 'react'; | ||
|
||
import { typedKeys } from 'shared/util'; | ||
|
||
import { colorScheme } from '../Colors'; | ||
import { useToggle } from '../hooks/useToggle'; | ||
import { Icons } from '../icons/Icons'; | ||
import { FlexColumn, FlexRow } from './BasicElements'; | ||
import { TextEdit } from './TextEdit'; | ||
|
||
interface ColorPickerProps { | ||
value: string; | ||
onChange: (color: string) => void; | ||
} | ||
|
||
const allColors = typedKeys(colors); | ||
const colorPalette = typedKeys(colors.amber); | ||
|
||
const defaultPaletteIdx = 4; | ||
|
||
export const ColorPicker: React.FC<ColorPickerProps> = ({ value, onChange }) => { | ||
const [open, toggle] = useToggle(); | ||
const [palette, setPalette] = React.useState<number>(defaultPaletteIdx); | ||
return ( | ||
<> | ||
<FlexRow className="vcenter"> | ||
<ColorBall color={value} onClick={toggle} title={value} className="example" /> | ||
{open ? <TextEdit value={value} onChange={onChange} /> : value} | ||
</FlexRow> | ||
{open ? ( | ||
<FlexRow className="vcenter"> | ||
<FlexColumn> | ||
<IconButton | ||
size="small" | ||
onClick={() => setPalette(palette > 0 ? palette - 1 : palette)} | ||
> | ||
<Icons.SortUp fontSize="small" /> | ||
</IconButton> | ||
<IconButton | ||
size="small" | ||
onClick={() => setPalette(palette < colorPalette.length - 1 ? palette + 1 : palette)} | ||
> | ||
<Icons.SortDown fontSize="small" /> | ||
</IconButton> | ||
</FlexColumn> | ||
<ColorOptions> | ||
{allColors.map(c => { | ||
const col = (colors as any)[c][colorPalette[palette]]; | ||
return <ColorBall color={col} key={c} onClick={() => onChange(col)} />; | ||
})} | ||
</ColorOptions> | ||
</FlexRow> | ||
) : null} | ||
</> | ||
); | ||
}; | ||
|
||
const ColorBall = styled('div')` | ||
display: inline-flex; | ||
border: 1px solid ${colorScheme.gray.standard}; | ||
border-radius: 50%; | ||
width: 24px; | ||
height: 24px; | ||
&.example { | ||
width: 32px; | ||
height: 32px; | ||
margin-right: 8px; | ||
} | ||
${({ color }: { color: string }) => ` | ||
background-color: ${color}; | ||
`}; | ||
`; | ||
|
||
const ColorOptions = styled('div')` | ||
display: inline-grid; | ||
flex: 1; | ||
grid-template-columns: repeat(auto-fill, 28px); | ||
row-gap: 4px; | ||
column-gap: 4px; | ||
margin: 16px 0; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import styled from '@emotion/styled'; | ||
import { colors } from '@mui/material'; | ||
import * as React from 'react'; | ||
|
||
import { ExpenseGroupingRef } from 'shared/types'; | ||
|
||
import { colorScheme } from '../Colors'; | ||
import { Bookmark } from '../icons/Bookmark'; | ||
|
||
type GroupedExpenseIconProps = { | ||
size?: number; | ||
grouping: ExpenseGroupingRef; | ||
onClick?: () => void; | ||
className?: string; | ||
}; | ||
export const GroupedExpenseIcon: React.FC<GroupedExpenseIconProps> = ({ | ||
size, | ||
grouping, | ||
onClick, | ||
className, | ||
}) => ( | ||
<IconContainer title={grouping.title} onClick={onClick} className={className}> | ||
<Bookmark size={size || 24} title={grouping.title} color={grouping.color ?? colors.blue[300]} /> | ||
{grouping.title ? <GroupedExpenseIconText>{grouping.title[0]}</GroupedExpenseIconText> : null} | ||
</IconContainer> | ||
); | ||
|
||
const IconContainer = styled('div')` | ||
cursor: pointer; | ||
position: relative; | ||
display: inline-block; | ||
`; | ||
|
||
const GroupedExpenseIconText = styled('div')` | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
top: 3px; | ||
display: inline-flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
font-weight: bold; | ||
color: ${colorScheme.primary.light}; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.