Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 6af7844

Browse files
RXminuSBill Caplan
andauthored
[Backport 5.3.9104] Notices: Add customization for background color, text color, and text position. (#61915)
Notices: Add customization for background color, text color, and text position. (#61338) Closes #59751 Co-authored-by: Bill Caplan <[email protected]>
1 parent fd30e59 commit 6af7844

File tree

8 files changed

+138
-5
lines changed

8 files changed

+138
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ All notable changes to Sourcegraph are documented in this file.
3131
- GitHub apps installation records will only be deleted from the database if the GitHub App has been uninstalled or if the GitHub app has been deleted. [#60460](https://github.com/sourcegraph/sourcegraph/pull/60460)
3232
- The Anthropic provider for Cody has been updated to use the messages API which includes support for Claude 3 models. This is applicable to both BYOK and Cody Gateway users. The messages API does not support model identifiers which only set a major model version such as: `claude-2`, `claude-instant-v1` and `claude-instant-1`. Default values have been updated to `claude-2.0` and `claude-instant-1.2`, any legacy models identifiers in the site config will be set to the corresponding default previously mentioned. [#60953](https://github.com/sourcegraph/sourcegraph/pull/60953) [#61324](https://github.com/sourcegraph/sourcegraph/pull/61324)
3333
- The AWS Bedrock provider for Cody has been updated to use Anthropic's Messages API, bringing support for Claude 3 models. [#61347](https://github.com/sourcegraph/sourcegraph/pull/61347)
34+
- Notices configured in the site config now allow for specifying a style or color. [#61338](https://github.com/sourcegraph/sourcegraph/pull/61338)
3435

3536
### Fixed
3637

client/web/src/components/DismissibleAlert/DismissibleAlert.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const DismissibleAlert: React.FunctionComponent<React.PropsWithChildren<D
2828
testId,
2929
children,
3030
variant,
31+
styleOverrides,
3132
}) => {
3233
const [dismissed, setDismissed] = React.useState<boolean>(
3334
partialStorageKey ? isAlertDismissed(partialStorageKey) : false
@@ -45,8 +46,19 @@ export const DismissibleAlert: React.FunctionComponent<React.PropsWithChildren<D
4546
}
4647

4748
return (
48-
<Alert data-testid={testId} className={classNames(styles.container, className)} variant={variant}>
49-
<div className={styles.content}>{children}</div>
49+
<Alert
50+
data-testid={testId}
51+
className={classNames(styles.container, className)}
52+
variant={variant}
53+
styleOverrides={styleOverrides}
54+
>
55+
<div
56+
className={classNames(styles.content, {
57+
'justify-content-center': styleOverrides?.textCentered,
58+
})}
59+
>
60+
{children}
61+
</div>
5062
<Button aria-label="Dismiss alert" variant="icon" className={styles.closeButton} onClick={onDismiss}>
5163
<Icon aria-hidden={true} svgPath={mdiClose} />
5264
</Button>

client/web/src/global/Notices.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ describe('Notices', () => {
1818
{ message: 'a', location: 'home' },
1919
{ message: 'a', location: 'home', dismissible: true },
2020
{ message: 'b', location: 'top' },
21+
{ message: 'a message with a variant', location: 'top', variant: 'note' },
22+
{
23+
message: 'a message with style overrides',
24+
location: 'top',
25+
variant: 'success',
26+
styleOverrides: {
27+
backgroundColor: '#00f0ff',
28+
textCentered: true,
29+
},
30+
},
2131
],
2232
},
2333
}}
2434
>
2535
<Notices location="home" telemetryRecorder={noOpTelemetryRecorder} />
36+
<Notices location="top" telemetryRecorder={noOpTelemetryRecorder} />
2637
</SettingsProvider>
2738
).asFragment()
2839
).toMatchSnapshot())

client/web/src/global/Notices.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ const NoticeAlert: React.FunctionComponent<React.PropsWithChildren<NoticeAlertPr
3030
}) => {
3131
const content = <Markdown dangerousInnerHTML={renderMarkdown(notice.message)} />
3232

33-
const sharedProps = {
33+
const sharedProps: AlertProps & { 'data-testid': typeof testId } = {
3434
'data-testid': testId,
35-
variant: getAlertVariant(notice.location),
35+
variant: notice.variant || getAlertVariant(notice.location),
3636
className: classNames(notice.location !== 'top' && 'bg transparent border p-2', className),
37+
styleOverrides: notice.styleOverrides,
3738
}
3839

3940
return notice.dismissible ? (

client/web/src/global/__snapshots__/Notices.test.tsx.snap

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/wildcard/src/components/Alert/Alert.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ export interface AlertProps extends React.HTMLAttributes<HTMLDivElement> {
2020
* be default.
2121
*/
2222
withIcon?: boolean
23+
24+
styleOverrides?: {
25+
backgroundColor?: string
26+
textColor?: string
27+
textCentered?: boolean
28+
}
2329
}
2430

2531
const userShouldBeImmediatelyNotified = (variant?: AlertVariant): boolean =>
@@ -33,7 +39,17 @@ const userShouldBeImmediatelyNotified = (variant?: AlertVariant): boolean =>
3339
* Further details: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/alert_role
3440
*/
3541
export const Alert = React.forwardRef(function Alert(
36-
{ children, withIcon = true, as: Component = 'div', variant, className, role = 'alert', ...attributes },
42+
{
43+
children,
44+
withIcon = true,
45+
as: Component = 'div',
46+
variant,
47+
className,
48+
role = 'alert',
49+
styleOverrides,
50+
style,
51+
...attributes
52+
},
3753
reference
3854
) {
3955
const { isBranded } = useWildcardTheme()
@@ -46,12 +62,22 @@ export const Alert = React.forwardRef(function Alert(
4662
*/
4763
const alertAssertiveness = userShouldBeImmediatelyNotified(variant) ? 'assertive' : 'polite'
4864

65+
// Merge styles with overrides
66+
const { backgroundColor, textColor, textCentered } = styleOverrides || {}
67+
const mergedStyles: React.CSSProperties = {
68+
...style,
69+
...(!!backgroundColor && { backgroundColor }),
70+
...(!!textColor && { color: textColor }),
71+
...(!!textCentered && { textAlign: 'center' }),
72+
}
73+
4974
return (
5075
<Component
5176
ref={reference}
5277
className={classNames(brandedClassName, className, { [styles.alertWithNoIcon]: !withIcon })}
5378
role={role}
5479
aria-live={alertAssertiveness}
80+
style={mergedStyles}
5581
{...attributes}
5682
>
5783
{children}

schema/schema.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/settings.schema.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,10 +484,32 @@
484484
"type": "string",
485485
"enum": ["top", "home"]
486486
},
487+
"variant": {
488+
"type": "string",
489+
"enum": ["primary", "secondary", "success", "danger", "warning", "info", "note"]
490+
},
487491
"dismissible": {
488492
"description": "Whether this notice can be dismissed (closed) by the user.",
489493
"type": "boolean",
490494
"default": false
495+
},
496+
"styleOverrides": {
497+
"description": "Overrides for the notice's default style. You probably want to use notice 'variant' setting instead.",
498+
"type": "object",
499+
"properties": {
500+
"backgroundColor": {
501+
"description": "The hex code of the background color for this notice.",
502+
"type": "string"
503+
},
504+
"textColor": {
505+
"description": "The hex code of the text color for this notice.",
506+
"type": "string"
507+
},
508+
"textCentered": {
509+
"description": "Whether the notice text should be centered.",
510+
"type": "boolean"
511+
}
512+
}
491513
}
492514
}
493515
}

0 commit comments

Comments
 (0)