Skip to content

Commit

Permalink
[menu-bar] Add PlatformColor support for electron
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel committed Feb 6, 2024
1 parent e1082b3 commit 9b55bf8
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 10 deletions.
109 changes: 109 additions & 0 deletions apps/menu-bar/global.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,112 @@
body {
background-color: var(--orbit-window-background);
}

:not(input):not(textarea),
:not(input):not(textarea)::after,
:not(input):not(textarea)::before {
-webkit-user-select: none;
user-select: none;
}

@media (prefers-color-scheme: light) {
/* Platform Color based on macOS Semantic Colors*/
:root {
--label-color: #242424;
--secondary-label-color: #000000;
--tertiary-label-color: #000000;
--quaternary-label-color: #000000;
--link-color: #084fd1;
--placeholder-text-color: #000000;
--window-frame-text-color: #000000;
--selected-menu-item-text-color: #fffefe;
--alternate-selected-control-text-color: #fffefe;
--header-text-color: #000000;
--separator-color: #000000;
--grid-color: #e6e6e6;
--window-background-color: #e7e7e7;
--under-page-background-color: #838383;
--control-background-color: #fffefe;
--selected-content-background: #064ad9;
--unemphasized-selected-content-background-color: #d3d3d3;
--find-highlight-color: #ffff0a;
--alternating-content-background-color: #f1f2f2;
--text-color: #000000;
--text-background-color: #fffefe;
--selected-text-color: #000000;
--selected-text-background-color: #fac99f;
--unemphasized-selected-text-background-color: #d3d3d3;
--unemphasized-selected-text-color: #000000;
--control-color: #ffffff;
--control-text-color: #000000;
--selected-control-color: #fac99f;
--selected-control-text-color: #000000;
--disabled-control-text-color: #000000;
--keyboard-focus-indicator-color: #e45a08;
--control-accent-color: #007bff;
--highlight-color: #fffefe;
--shadow-color: #000000;

--popover-background: #e6e7e7;
--orbit-window-background: #eaecec;
}
}

@media (prefers-color-scheme: dark) {
/* Platform Color based on macOS Semantic Colors*/
:root {
--label-color: #fffefe;
--secondary-label-color: #fffefe;
--tertiary-label-color: #fffefe;
--quaternary-label-color: #fffefe;
--link-color: #3486fe;
--placeholder-text-color: #fffefe;
--window-frame-text-color: #fffefe;
--selected-menu-item-text-color: #fffefe;
--alternate-selected-control-text-color: #fffefe;
--header-text-color: #fffefe;
--separator-color: #fffefe;
--grid-color: #fffefe;
--window-background-color: #252525;
--under-page-background-color: #1d1d1d;
--control-background-color: #161616;
--selected-content-background: #064ad9;
--unemphasized-selected-content-background-color: #363636;
--find-highlight-color: #ffff0a;
--alternating-content-background-color: #fffefe;
--text-color: #fffefe;
--text-background-color: #161616;
--selected-text-color: #ffffff;
--selected-text-background-color: #803c0e;
--unemphasized-selected-text-background-color: #363636;
--unemphasized-selected-text-color: #ffffff;
--control-color: #fffefe;
--control-text-color: #fffefe;
--selected-control-color: #803c0e;
--selected-control-text-color: #fffefe;
--disabled-control-text-color: #fffefe;
--keyboard-focus-indicator-color: #fd9d2e;
--control-accent-color: #007aff;
--highlight-color: #a4a4a4;
--shadow-color: #000000;

--popover-background: #212121;
--orbit-window-background: #252928;
}
}

:root {
--system-red-color: #fb2b2c;
--system-green-color: #30d33a;
--system-blue-color: #106afe;
--system-orange-color: #fc8d0d;
--system-yellow-color: #fecf0e;
--system-brown-color: #9b7b55;
--system-pink-color: #fb194c;
--system-purple-color: #4e45d8;
--system-gray-color: #85858b;
}

/* Fonts */
@font-face {
src: url('src/assets/fonts/Inter/Inter-Regular.otf');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ const AutoResizerRootView = ({
}, [enabled, maxRelativeHeight]);

return (
<div ref={divRef} style={{ height: 'fit-content', ...style }}>
<div
ref={divRef}
style={{
height: 'fit-content',
backgroundColor: 'var(--popover-background)',
...style,
}}>
{children}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/menu-bar/src/components/NativeColorPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const colorsArray = [
'unemphasizedSelectedTextBackgroundColor',
'linkColor',
'separatorColor',
'selectedContentBackgroundColor',
'selectedContentBackground',
'unemphasizedSelectedContentBackgroundColor',
'selectedMenuItemTextColor',
'gridColor',
Expand Down
2 changes: 2 additions & 0 deletions apps/menu-bar/src/components/PathInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TextInput } from './Text';
import { Row } from './View';
import * as FilePicker from '../../modules/file-picker';
import FolderIcon from '../assets/icons/folder.svg';
import { PlatformColor } from '../modules/PlatformColor';
import { addOpacity } from '../utils/theme';
import { useCurrentTheme, useExpoTheme } from '../utils/useExpoTheme';

Expand Down Expand Up @@ -36,6 +37,7 @@ const PathInput = React.forwardRef<NativeTextInput, React.ComponentProps<typeof
shadow="input"
{...props}
style={styles.input}
placeholderTextColor={PlatformColor('placeholderTextColor')}
ref={forwardedRef as any}
editable={editable}
onChangeText={onChangeText}
Expand Down
7 changes: 6 additions & 1 deletion apps/menu-bar/src/components/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { shadows } from '@expo/styleguide-native';
import { Text as RNText, TextInput as RNTextInput } from 'react-native';
import { Platform, Text as RNText, TextInput as RNTextInput } from 'react-native';

import { PlatformColor } from '../modules/PlatformColor';
import { create } from '../utils/create-component-primitive';
Expand All @@ -9,6 +9,11 @@ export const Text = create(RNText, {
base: {
fontSize: 14,
lineHeight: 18,
...Platform.select({
web: {
color: 'var(--text-color)',
},
}),
},

props: {
Expand Down
14 changes: 11 additions & 3 deletions apps/menu-bar/src/modules/PlatformColor/index.web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export const PlatformColor = () => {
// Return black as a temporary placeholder
return '#000000';
const camelToSnakeCase = (str: string) =>
str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);

const bodyStyles = window.getComputedStyle(document.body);

export const PlatformColor = (color: string) => {
const colorValue =
bodyStyles.getPropertyValue(`--${camelToSnakeCase(color)}`) ||
bodyStyles.getPropertyValue(`--${camelToSnakeCase(color)}-color`);

return colorValue || '#000000';
};
40 changes: 36 additions & 4 deletions apps/menu-bar/src/utils/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,16 @@ export const text = {
},

color: {
default: { color: PlatformColor('labelColor') },
default: {
...Platform.select({
native: {
color: PlatformColor('labelColor'),
},
web: {
color: 'var(--label-color)',
},
}),
},
error: { color: lightTheme.text.error },
warning: { color: lightTheme.text.warning },
success: { color: lightTheme.text.success },
Expand All @@ -200,7 +209,16 @@ export const text = {

export const textDark = {
color: {
default: { color: PlatformColor('labelColor') },
default: {
...Platform.select({
native: {
color: PlatformColor('labelColor'),
},
web: {
color: 'var(--label-color)',
},
}),
},
error: { color: darkTheme.text.error },
warning: { color: darkTheme.text.warning },
success: { color: darkTheme.text.success },
Expand Down Expand Up @@ -231,7 +249,14 @@ export const bgDark = {

export const border = {
default: {
borderColor: PlatformColor('gridColor'),
...Platform.select({
native: {
borderColor: PlatformColor('gridColor'),
},
web: {
borderColor: 'var(--grid-color)',
},
}),
borderWidth: 1,
},
light: { borderColor: addOpacity(lightTheme.border.default, 0.2), borderWidth: 1 },
Expand All @@ -244,7 +269,14 @@ export const border = {

export const borderDark = {
default: {
borderColor: PlatformColor('controlColor'),
...Platform.select({
native: {
borderColor: PlatformColor('controlColor'),
},
web: {
borderColor: 'var(--control-color)',
},
}),
borderWidth: 1,
},
warning: { borderColor: darkTheme.border.warning, borderWidth: 1 },
Expand Down

0 comments on commit 9b55bf8

Please sign in to comment.