Skip to content

Commit

Permalink
color tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ann-kilzer committed Apr 18, 2024
1 parent 48333ee commit 639a980
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
25 changes: 24 additions & 1 deletion src/components/TagChips/TagChips.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
import { FC } from 'react';

import Chip from '@mui/material/Chip'
import {
purple,
blue,
lightBlue,
lightGreen,
green,
pink,
indigo,
teal,
lime,
amber
} from '@mui/material/colors';

interface TagChipsProps {
tags: string[]
}

const colors = [purple, blue, lightGreen, green, pink, indigo, lime, amber, teal, lightBlue]

function mapColor(tag: string) {
let hash = 0
for (let i = 0; i < tag.length; i++) {
hash += tag.charCodeAt(i)
}
const index = hash % colors.length
return colors[index][200]
}

const TagChips: FC<TagChipsProps> = ({ tags }) => {
return tags.map((tag: string) => {
return <Chip
label={tag}
key={tag}
sx={{ mr: 1 }}
sx={{ mr: 1, backgroundColor: mapColor(tag) }}
/>
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Writing/Writing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Writing: FC<WritingProps> = () => {
subtitle="Subtitle"
body="Lorum ipsum dolor sit amet"
date={new Date('2024-04-18')}
tags={['one', 'two', 'three']}
tags={['one', 'two', 'tag three']}
/>
</Container>
}
Expand Down
6 changes: 6 additions & 0 deletions src/theme/customColorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ declare module '@mui/material/Button' {
tertiary: true;
}
}

declare module '@mui/material/Chip' {
interface ChipPropsColorOverrides {
tertiary: true
}
}

0 comments on commit 639a980

Please sign in to comment.