From 8e5a35b7629bdc7dbd219910f1bf679c922e798c Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Tue, 12 Feb 2019 09:45:00 -0500 Subject: [PATCH] Misc cleanup and prep for dark mode CSS --- src/devtools/views/ButtonIcon.css | 1 - src/devtools/views/Elements.css | 1 + src/devtools/views/Icon.js | 15 ++++++++++++--- src/devtools/views/SearchInput.css | 12 ++++++++---- src/devtools/views/SearchInput.js | 2 ++ src/devtools/views/SelectedElement.js | 7 ++++++- src/devtools/views/Tree.js | 5 ++++- src/devtools/views/TreeContext.js | 10 ++++++++-- src/devtools/views/root.css | 26 ++++++++++++++++++++++++-- 9 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/devtools/views/ButtonIcon.css b/src/devtools/views/ButtonIcon.css index 85c6a98bb7..b21c094828 100644 --- a/src/devtools/views/ButtonIcon.css +++ b/src/devtools/views/ButtonIcon.css @@ -1,6 +1,5 @@ .ButtonIcon { width: 1rem; height: 1rem; - margin: 0 0.25rem; fill: currentColor; } diff --git a/src/devtools/views/Elements.css b/src/devtools/views/Elements.css index b1814179a8..e3fbdd2a6d 100644 --- a/src/devtools/views/Elements.css +++ b/src/devtools/views/Elements.css @@ -4,6 +4,7 @@ display: flex; flex-direction: row; background-color: var(--color-background); + color: var(--color-text-color); font-family: var(--font-family-sans); } diff --git a/src/devtools/views/Icon.js b/src/devtools/views/Icon.js index c58aa0afde..16868464b6 100644 --- a/src/devtools/views/Icon.js +++ b/src/devtools/views/Icon.js @@ -4,15 +4,19 @@ import React from 'react'; import styles from './Icon.css'; type Props = {| - type: 'arrow', + className?: string, + type: 'arrow' | 'search', |}; -export default function Icon({ type }: Props) { +export default function Icon({ className = '', type }: Props) { let pathData = null; switch (type) { case 'arrow': pathData = PATH_ARROW; break; + case 'search': + pathData = PATH_SEARCH; + break; default: console.warn(`Unsupported type "${type}" specified for Icon`); break; @@ -21,7 +25,7 @@ export default function Icon({ type }: Props) { return ( +
owner stack
{owners.map(owner => ( @@ -182,10 +183,14 @@ function useInspectedElement(id: number | null): InspectedElement | null { const onInspectedElement = (inspectedElement: InspectedElement) => { if (inspectedElement && inspectedElement.id !== idRef.current) { + // TODO Is this sufficient? Will this leak? // Ignore bridge updates about previously selected elements. return; } + // TODO I think there's a bug here with stale state or a bad listener. + // "Cannot read property 'inspectElement' of undefined" + if (inspectedElement !== null) { inspectedElement.context = hydrateHelper(inspectedElement.context); inspectedElement.hooks = hydrateHelper(inspectedElement.hooks); diff --git a/src/devtools/views/Tree.js b/src/devtools/views/Tree.js index aaf151e17c..2326415ec7 100644 --- a/src/devtools/views/Tree.js +++ b/src/devtools/views/Tree.js @@ -80,7 +80,10 @@ export default function Tree(props: Props) { ); const itemSize = parseInt( - getComputedStyle(document.body).getPropertyValue('--line-height-data') + getComputedStyle((document.body: any)).getPropertyValue( + '--line-height-data' + ), + 10 ); return ( diff --git a/src/devtools/views/TreeContext.js b/src/devtools/views/TreeContext.js index bc9232552c..c757980e95 100644 --- a/src/devtools/views/TreeContext.js +++ b/src/devtools/views/TreeContext.js @@ -327,6 +327,8 @@ function reduceOwnersState(store: Store, state: State, action: Action): State { _ownerFlatTree, } = state; + let prevSelectedElementIndex = selectedElementIndex; + switch (type) { case 'HANDLE_STORE_MUTATION': if (ownerStack.length > 0) { @@ -351,6 +353,7 @@ function reduceOwnersState(store: Store, state: State, action: Action): State { case 'RESET_OWNER_STACK': ownerStack = []; ownerStackIndex = null; + selectedElementIndex = null; _ownerFlatTree = null; break; case 'SELECT_ELEMENT_AT_INDEX': @@ -383,6 +386,10 @@ function reduceOwnersState(store: Store, state: State, action: Action): State { case 'SELECT_OWNER': ownerStackIndex = ownerStack.indexOf(payload); + // Always force reset selection to be the top of the new owner tree. + selectedElementIndex = 0; + prevSelectedElementIndex = null; + // If this owner is already in the current stack, just select it. // Otherwise, create a new stack. if (ownerStackIndex < 0) { @@ -396,7 +403,6 @@ function reduceOwnersState(store: Store, state: State, action: Action): State { ): any): Element).ownerID; } ownerStackIndex = ownerStack.length - 1; - selectedElementIndex = 0; if (searchText !== '') { searchIndex = null; @@ -435,7 +441,7 @@ function reduceOwnersState(store: Store, state: State, action: Action): State { } // Keep selected item ID and index in sync. - if (selectedElementIndex !== state.selectedElementIndex) { + if (selectedElementIndex !== prevSelectedElementIndex) { if (selectedElementIndex === null) { selectedElementID = null; } else if (_ownerFlatTree !== null) { diff --git a/src/devtools/views/root.css b/src/devtools/views/root.css index 0487da7b47..8e9b4fc974 100644 --- a/src/devtools/views/root.css +++ b/src/devtools/views/root.css @@ -16,11 +16,32 @@ --theme-light-jsx-arrow-brackets: #333333; --theme-light-jsx-arrow-brackets-inverted: rgba(255, 255, 255, 0.7); --theme-light-search-match: yellow; - --theme-light-search-match-current: orange; + --theme-light-search-match-current: #f7923b; + --theme-light-text-color: #000000; --theme-light-tree-node-selected: #0088fa; --theme-light-tree-node-hover: #ebf1fb; - /* TODO Dark theme */ + /* Dark theme */ + --theme-dark-arrow: #777d88; + --theme-dark-arrow-inverted: #23272f; + --theme-dark-attribute-name: #9d87d2; + --theme-dark-attribute-value: #cedae0; + --theme-dark-background: #23272f; + --theme-dark-button: #4dbba6; + --theme-dark-button-hover: #80d4c4; + --theme-dark-color-border: #303846; + --theme-dark-component-name: #4dbba6; + --theme-dark-component-name-inverted: ##23272f; + --theme-dark-dim: #8f949d; + --theme-dark-dimmer: #777d88; + --theme-dark-dimmest: #4f5766; + --theme-dark-jsx-arrow-brackets: #777d88; + --theme-dark-jsx-arrow-brackets-inverted: rgba(255, 255, 255, 0.7); + --theme-dark-search-match: yellow; + --theme-dark-search-match-current: #f7923b; + --theme-dark-text-color: #ffffff; + --theme-dark-tree-node-selected: #31a38d; + --theme-dark-tree-node-hover: #23272f; /* "theme" values referenced by other stylesheets */ --color-arrow: var(--theme-light-arrow); @@ -38,6 +59,7 @@ --color-dimmest: var(--theme-light-dimmest); --color-search-match: var(--theme-light-search-match); --color-search-match-current: var(--theme-light-search-match-current); + --color-text-color: var(--theme-light-text-color); --color-tree-jsx-arrow-brackets: var(--theme-light-jsx-arrow-brackets); --color-tree-jsx-arrow-brackets-inverted: var( --theme-light-jsx-arrow-brackets-inverted