Skip to content

Commit

Permalink
feat: support custom background color (#3814)
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen authored Sep 27, 2024
1 parent 7b3485b commit 22cfe58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type ColumnConfig = DefaultWidgetColumnConfig | PluginWidgetColumnConfig;

export type PageLayoutConfig = {
title?: ?string,
backgroundColor?: ?string,
leftColumn: ?Array<ColumnConfig>,
rightColumn: ?Array<ColumnConfig>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DefaultPageTitle, EnrollmentPageKeys } from './DefaultEnrollmentLayout.

const getEnrollmentPageStyles = () => ({
container: {
minHeight: '90vh',
padding: '16px 24px 16px 24px',
},
contentContainer: {
Expand Down Expand Up @@ -44,6 +45,9 @@ const getEnrollmentPageStyles = () => ({
},
});

// Function to validate hex color
const isValidHex = (color: string) => /^#[0-9A-F]{6}$/i.test(color);

const getTitle = (inputTitle, page) => {
const title = inputTitle || i18n.t('Enrollment');
const titles = {
Expand Down Expand Up @@ -83,8 +87,13 @@ const EnrollmentPageLayoutPlain = ({
props: allProps,
});

const containerStyle = useMemo(() => {
if (!pageLayout.backgroundColor || !isValidHex(pageLayout.backgroundColor)) return undefined;
return { backgroundColor: pageLayout.backgroundColor };
}, [pageLayout.backgroundColor]);

return (
<div className={classes.container}>
<div className={classes.container} style={containerStyle}>
<AddRelationshipRefWrapper setRelationshipRef={setAddRelationshipContainerElement} />
<div
className={classes.contentContainer}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// @flow
import React, { useState, useEffect, useRef, type ComponentType } from 'react';
import React, { type ComponentType, useEffect, useRef, useState } from 'react';
import { withStyles } from '@material-ui/core';
import cx from 'classnames';
import { colors, spacersNum, IconChevronUp24 } from '@dhis2/ui';
import { colors, IconChevronUp24, spacersNum } from '@dhis2/ui';
import { IconButton } from 'capture-ui';
import type { WidgetCollapsibleProps, WidgetCollapsiblePropsPlain } from './widgetCollapsible.types';

Expand Down Expand Up @@ -127,7 +127,7 @@ const WidgetCollapsiblePlain = ({
}, [open, animationsReady]);

return (
<div style={{ backgroundColor: color }}>
<div style={{ backgroundColor: color, borderRadius: 3 }}>
<div
className={cx(classes.headerContainer, {
childrenVisible,
Expand Down

0 comments on commit 22cfe58

Please sign in to comment.