Skip to content

Commit

Permalink
Select color font change (#43)
Browse files Browse the repository at this point in the history
* change the background color of pages

* get bgColor from backend

* add and remove color in form

* change font color to match bgColor
  • Loading branch information
levg34 authored Dec 28, 2023
1 parent da5b771 commit 6ed29c9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pages/src/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ const Page: Component<Props> = (props: Props) => {

const [pageData] = createResource(pageId, getPageData)

function getFontColor() {
const bgColor = pageData()?.bgColor
if (!bgColor) return '#000000'
var color = bgColor.charAt(0) === '#' ? bgColor.substring(1, 7) : bgColor
var r = parseInt(color.substring(0, 2), 16) // Red
var g = parseInt(color.substring(2, 4), 16) // Green
var b = parseInt(color.substring(4, 6), 16) // Blue
return r * 0.299 + g * 0.587 + b * 0.114 > 186 ? '#000000' : '#FFFFFF'
}

return (
<Stack style="background-color: black">
<Carousel controls={false} indicators={false}>
Expand All @@ -47,7 +57,7 @@ const Page: Component<Props> = (props: Props) => {
</div>
</Carousel.Item>
</Carousel>
<Container style={`background-color: ${pageData()?.bgColor ?? 'lightgrey'}`} class="mt-3 pt-2">
<Container style={`background-color: ${pageData()?.bgColor ?? 'lightgrey'}; color: ${getFontColor()}`} class="mt-3 pt-2">
<For each={prepareForDisplay(pageData()?.data ?? [])}>
{(elements) => (
<>
Expand Down

0 comments on commit 6ed29c9

Please sign in to comment.