mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Misc cleanup and prep for dark mode CSS
This commit is contained in:
1 parent
f3f497f40f
commit
8e5a35b762
9 files changed
+65
-14
No files matched your search
@@ -1,6 +1,5 @@
|
||||
.ButtonIcon {
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
margin: 0 0.25rem;
|
||||
fill: currentColor;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className={styles.Icon}
|
||||
className={`${styles.Icon} ${className}`}
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
@@ -33,3 +37,8 @@ export default function Icon({ type }: Props) {
|
||||
}
|
||||
|
||||
const PATH_ARROW = 'M8 5v14l11-7z';
|
||||
const PATH_SEARCH = `
|
||||
M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91
|
||||
16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99
|
||||
5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z
|
||||
`;
|
||||
@@ -9,11 +9,15 @@
|
||||
font-size: 1rem;
|
||||
outline: none;
|
||||
border: none;
|
||||
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: left center;
|
||||
background-size: 16px 16px;
|
||||
background-color: var(--color-background);
|
||||
color: var(--color-text-color);
|
||||
padding-left: 1.5rem;
|
||||
margin-left: -1rem;
|
||||
}
|
||||
|
||||
.InputIcon {
|
||||
pointer-events: none;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.IndexLabel {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import React, { useCallback, useContext, useEffect, useRef } from 'react';
|
||||
import { TreeContext } from './TreeContext';
|
||||
import ButtonIcon from './ButtonIcon';
|
||||
import Icon from './Icon';
|
||||
|
||||
import styles from './SearchInput.css';
|
||||
|
||||
@@ -57,6 +58,7 @@ export default function SearchInput(props: Props) {
|
||||
|
||||
return (
|
||||
<div className={styles.SearchInput}>
|
||||
<Icon className={styles.InputIcon} type="search" />
|
||||
<input
|
||||
className={styles.Input}
|
||||
onKeyPress={handleInputKeyPress}
|
||||
|
||||
@@ -98,6 +98,7 @@ type InspectedElementViewProps = {|
|
||||
|
||||
function InspectedElementView({ inspectedElement }: InspectedElementViewProps) {
|
||||
let { context, hooks, owners, props, state } = inspectedElement;
|
||||
const { ownerStack } = useContext(TreeContext);
|
||||
|
||||
return (
|
||||
<div className={styles.InspectedElement}>
|
||||
@@ -106,7 +107,7 @@ function InspectedElementView({ inspectedElement }: InspectedElementViewProps) {
|
||||
<HooksTree hooksTree={hooks} />
|
||||
<InspectedElementTree label="context" data={context} />
|
||||
|
||||
{owners !== null && owners.length > 0 && (
|
||||
{ownerStack.length === 0 && owners !== null && owners.length > 0 && (
|
||||
<div className={styles.Owners}>
|
||||
<div>owner stack</div>
|
||||
{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);
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user