Skip to content

Commit

Permalink
Add dark mode for widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Half-Shot committed Dec 22, 2023
1 parent a58febf commit 98d312f
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 29 deletions.
15 changes: 10 additions & 5 deletions web/components/ConnectionCard.module.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.card {
/* Compound/Light/Background */
background: #FFFFFF;

/* Compound/Light/Quinary Content */
border: 1px solid #E3E8F0;
.card {
background: var(--cpd-color-bg-subtle-secondary);
border: 1px solid var(--cpd-color-border-interactive-secondary);
box-sizing: border-box;
border-radius: 8px;

Expand All @@ -15,6 +13,13 @@

cursor: pointer;


@media (prefers-color-scheme: dark) {
img.invert {
filter: invert(100%);
}
}

img {
width: 52px;
height: 52px;
Expand Down
3 changes: 2 additions & 1 deletion web/components/ConnectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import style from "./ConnectionCard.module.scss";

interface IProps {
imageSrc: string;
darkImage?: boolean;
serviceName: string;
description: string;
key: string;
Expand All @@ -10,7 +11,7 @@ interface IProps {

export function ConnectionCard(props: IProps) {
return <div className={style.card} onClick={props.onClick}>
<img alt="" src={props.imageSrc} />
<img alt="" src={props.imageSrc} className={props.darkImage ? style.invert : ''} />
<div>
<span>{props.serviceName}</span>
<p>{props.description}</p>
Expand Down
4 changes: 4 additions & 0 deletions web/components/RoomConfigView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface IConnectionProps {
displayName: string,
description: string,
icon: string,
darkIcon?: true,
component: BridgeConfig,
}

Expand All @@ -51,6 +52,7 @@ const connections: Record<ConnectionType, IConnectionProps> = {
displayName: 'Github',
description: "Connect the room to a GitHub project",
icon: GitHubIcon,
darkIcon: true,
component: GithubRepoConfig,
},
[ConnectionType.Gitlab]: {
Expand All @@ -69,6 +71,7 @@ const connections: Record<ConnectionType, IConnectionProps> = {
displayName: 'Generic Webhook',
description: "Create a webhook which can be used to connect any service to Matrix",
icon: WebhookIcon,
darkIcon: true,
component: GenericWebhookConfig,
},
};
Expand Down Expand Up @@ -97,6 +100,7 @@ export default function RoomConfigView(props: IProps) {
description={connection.description}
key={connectionType}
imageSrc={connection.icon}
darkImage={connection.darkIcon}
onClick={() => setActiveConnectionType(connectionType)}
/>
})}
Expand Down
13 changes: 10 additions & 3 deletions web/components/ServiceCard.module.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
.icon {
width: 48px;
}

.serviceCard {
display: grid !important;
grid-template-columns: 0.6fr 1fr 1fr;
padding: 0.5rem;

img {
width: 48px;
@media (prefers-color-scheme: dark) {
&.invert {
filter: invert(100%);
}
}
}

}
2 changes: 1 addition & 1 deletion web/components/ServiceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import style from "./ServiceCard.module.scss";

export const ServiceCard: FunctionComponent<{serviceName: string, iconUrl: string, onConfigure: () => void}> = ({ serviceName, iconUrl, onConfigure }) => {
return <div className={`card ${style.serviceCard}`}>
<img className={style.icon} src={iconUrl} />
<img className={style.invert} src={iconUrl} />
<div>
<span>{serviceName}</span>
<button onClick={onConfigure}>Configure</button>
Expand Down
7 changes: 2 additions & 5 deletions web/components/elements/Card.module.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
.card {
/* Compound/Light/Background */
background: #FFFFFF;

/* Compound/Light/Quinary Content */
border: 1px solid #E3E8F0;
background: var(--cpd-color-bg-subtle-secondary);
border: 1px solid var(--cpd-color-border-interactive-secondary);
box-sizing: border-box;
border-radius: 8px;

Expand Down
2 changes: 1 addition & 1 deletion web/components/elements/DropdownSearch.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

.value {
font-weight: 400;
color: var(--light-color);
color: var(--cpd-color-text-primary);
}

.hasImg {
Expand Down
14 changes: 7 additions & 7 deletions web/components/elements/InputField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
text-overflow: ellipsis;
max-width: calc(100% - 20px);
padding: 0 2px;
color: var(--light-color);
background: var(--background-color);
color: var(--cpd-color-text-primary);
}

> ul {
Expand All @@ -37,23 +36,24 @@
}

input[type="text"],input[type="search"] {
border: 1px solid #E3E8F0;
border: 1px solid var(--cpd-color-border-interactive-primary);
box-sizing: border-box;
border-radius: 8px;
width: 100%;
font-size: 14px;
padding: 8px 12px;
color: var(--light-color);
color: var(--cpd-color-text-primary);
background: var(--cpd-color-bg-subtle-primary);
}

select {
border: 1px solid #E3E8F0;
border: 1px solid var(--cpd-color-border-interactive-primary);
box-sizing: border-box;
border-radius: 8px;
width: 100%;
font-size: 14px;
background: var(--background-color);
padding: 8px 12px;
color: var(--light-color);
color: var(--cpd-color-text-primary);
background: var(--cpd-color-bg-subtle-primary);
}
}
19 changes: 18 additions & 1 deletion web/components/roomConfig/GenericWebhookConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionComponent, createRef } from "preact";
import { useCallback, useState } from "preact/hooks"
import { useCallback, useEffect, useState } from "preact/hooks"
import CodeMirror from '@uiw/react-codemirror';
import { javascript } from '@codemirror/lang-javascript';
import { BridgeConfig } from "../../BridgeAPI";
Expand Down Expand Up @@ -48,6 +48,21 @@ const ConnectionConfiguration: FunctionComponent<ConnectionConfigurationProps<Se
});
}, [canEdit, onSave, nameRef, transFn, existingConnection, transFnEnabled, waitForComplete]);

const [codeMirrorTheme, setCodeMirrorTheme] = useState<"light"|"dark">("light");
useEffect(() => {
if (!transFnEnabled) {
return;
}
const mm = window.matchMedia('(prefers-color-scheme: dark)');
const fn = (event: MediaQueryListEvent) => {
console.log('media change!');
setCodeMirrorTheme(event.matches ? "dark" : "light");
};
mm.addEventListener('change', fn);
setCodeMirrorTheme(mm.matches ? "dark" : "light");
return () => mm.removeEventListener('change', fn);
}, [transFnEnabled]);

return <form onSubmit={handleSave}>
<InputField visible={!existingConnection} label="Friendly name" noPadding={true}>
<input ref={nameRef} disabled={!canEdit} placeholder="My webhook" type="text" value={existingConnection?.config.name} />
Expand All @@ -69,6 +84,7 @@ const ConnectionConfiguration: FunctionComponent<ConnectionConfigurationProps<Se
<InputField visible={transFnEnabled} noPadding={true}>
<CodeMirror
value={transFn}
theme={codeMirrorTheme}
extensions={CODE_MIRROR_EXTENSIONS}
onChange={setTransFn}
/>
Expand Down Expand Up @@ -98,6 +114,7 @@ const RoomConfigListItemFunc = (c: GenericHookResponseItem) => c.config.name;
export const GenericWebhookConfig: BridgeConfig = ({ api, roomId, showHeader }) => {
return <RoomConfig<ServiceConfig, GenericHookResponseItem, GenericHookConnectionState>
headerImg={WebhookIcon}
darkHeaderImg={true}
showHeader={showHeader}
api={api}
roomId={roomId}
Expand Down
1 change: 1 addition & 0 deletions web/components/roomConfig/GithubRepoConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export const GithubRepoConfig: BridgeConfig = ({ api, roomId, showHeader }) => {

return <RoomConfig<never, GitHubRepoResponseItem, GitHubRepoConnectionState>
headerImg={GitHubIcon}
darkHeaderImg={true}
showHeader={showHeader}
api={api}
roomId={roomId}
Expand Down
6 changes: 6 additions & 0 deletions web/components/roomConfig/RoomConfig.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
height: 52px;
}

@media (prefers-color-scheme: dark) {
img.invert {
filter: invert(100%);
}
}

h1 {
margin-left: 10px;
font-weight: 600;
Expand Down
4 changes: 3 additions & 1 deletion web/components/roomConfig/RoomConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface IRoomConfigProps<SConfig, ConnectionType extends GetConnectionsRespons
type: string;
showAuthPrompt?: boolean;
showHeader: boolean;
darkHeaderImg?: boolean;
headerImg: string;
text: IRoomConfigText;
connectionEventType: string;
Expand All @@ -52,6 +53,7 @@ export const RoomConfig = function<SConfig, ConnectionType extends GetConnection
roomId,
type,
showAuthPrompt = false,
darkHeaderImg,
headerImg,
showHeader,
text,
Expand Down Expand Up @@ -156,7 +158,7 @@ export const RoomConfig = function<SConfig, ConnectionType extends GetConnection
<main>
{ showHeader &&
<header className={style.header}>
<img alt="" src={headerImg} />
<img alt="" className={darkHeaderImg ? style.invert : undefined} src={headerImg} />
<h1>{text.header}</h1>
</header>
}
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>GitHub Bridge Widget</title>
</head>
<body class="cpd-theme-light">
<body>
<main id="root"></main>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script type="module" src="/index.tsx"></script>
Expand Down
7 changes: 4 additions & 3 deletions web/styling.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
:root {
--background-color: #FFFFFF;
--foreground-color: #17191C;
--light-color: #737D8C;
--primary-color: #0DBD8B;
--primary-color-disabled: #0dbd8baf;

Expand Down Expand Up @@ -29,6 +28,8 @@ a:visited {

body {
margin: 0;
height: fit-content;
block-size: fit-content !important;
}


Expand Down Expand Up @@ -56,13 +57,13 @@ button {

.chevron.down::before {
transform: rotate(-225deg);
border-color: var(--light-color);
border-color: var(--cpd-color-text-primary);
float: right;
}


.chevron.up::before {
transform: rotate(-45deg);
border-color: var(--light-color);
border-color: var(--cpd-color-text-primary);
float: right;
}

0 comments on commit 98d312f

Please sign in to comment.