Skip to content

Commit

Permalink
P20-119: Add colors prop to Notification component
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-vavilov committed May 9, 2024
1 parent 854da70 commit 8567fc1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions apps/src/templates/Notification.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import firehoseClient from '@cdo/apps/lib/util/firehose';
import fontConstants from '@cdo/apps/fontConstants';

export const NotificationType = {
default: 'default',
information: 'information',
success: 'success',
failure: 'failure',
Expand Down Expand Up @@ -47,7 +48,7 @@ const Notification = ({
type,
tooltipText,
width,
color,
colors,
}) => {
const [open, setOpen] = useState(true);

Expand Down Expand Up @@ -125,9 +126,7 @@ const Notification = ({
return null;
}

const colorStyles = color
? {backgroundColor: color, borderColor: color}
: styles.colors[type];
const colorStyles = {...styles.colors[type], ...colors};

const tooltipId = _.uniqueId();

Expand Down Expand Up @@ -215,7 +214,7 @@ const Notification = ({
};

Notification.propTypes = {
type: PropTypes.oneOf(Object.keys(NotificationType)),
type: PropTypes.oneOf(Object.keys(NotificationType)).isRequired,
notice: PropTypes.string.isRequired,
details: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired,
detailsLinkText: PropTypes.string,
Expand Down Expand Up @@ -259,7 +258,16 @@ Notification.propTypes = {
// Can be specified to override default width
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

color: PropTypes.string,
colors: PropTypes.shape({
backgroundColor: PropTypes.string,
borderColor: PropTypes.string,
color: PropTypes.string,
}),
};

Notification.defaultProps = {
type: NotificationType.default,
colors: {},
};

const styles = {
Expand Down Expand Up @@ -335,6 +343,10 @@ const styles = {
marginBottom: 18,
},
colors: {
[NotificationType.default]: {
borderColor: color.teal,
backgroundColor: color.teal,
},
[NotificationType.information]: {
borderColor: color.teal,
color: color.teal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const ParentalPermissionBanner: React.FC<ParentalPermissionBannerProps> = ({
/>

<Notification
color={color.orange}
colors={{backgroundColor: color.orange, borderColor: color.orange}}
notice={i18n.policyCompliance_parentalPermissionBanner_title()}
details={i18n.policyCompliance_parentalPermissionBanner_desc({
lockoutDate: formattedLockoutDate,
Expand Down

0 comments on commit 8567fc1

Please sign in to comment.