From 47ca0a10f38d4b5bd6219a5bf7e62fe49e270539 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Wed, 7 Jul 2021 16:37:32 +0200 Subject: [PATCH] Changes to prop editors' theme --- theatre/core/src/propTypes/index.ts | 26 +++++- .../propEditors/BooleanPropEditor.tsx | 88 ++++++++++-------- .../propEditors/CompoundPropEditor.tsx | 4 +- .../propEditors/NumberPropEditor.tsx | 76 +++------------- .../propEditors/StringLiteralPropEditor.tsx | 90 ++++--------------- .../DopeSheet/Left/PrimitivePropRow.tsx | 9 +- 6 files changed, 112 insertions(+), 181 deletions(-) diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 8383b6f..d03ab19 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -6,6 +6,7 @@ type S = typeof s interface IBasePropType { valueType: ValueType [s]: 'TheatrePropType' + label: string | undefined } export interface PropTypeConfig_Number extends IBasePropType { @@ -18,7 +19,8 @@ export interface PropTypeConfig_Number extends IBasePropType { export const number = ( defaultValue: number, - opts?: Pick, + opts?: Pick & + PropTypeConfigExtras, ): PropTypeConfig_Number => { return { type: 'number', @@ -26,6 +28,7 @@ export const number = ( default: defaultValue, [s]: 'TheatrePropType', ...(opts ? opts : {}), + label: opts?.label, } } @@ -34,12 +37,20 @@ export interface PropTypeConfig_Boolean extends IBasePropType { default: boolean } -export const boolean = (defaultValue: boolean): PropTypeConfig_Boolean => { +export type PropTypeConfigExtras = { + label?: string +} + +export const boolean = ( + defaultValue: boolean, + extras?: PropTypeConfigExtras, +): PropTypeConfig_Boolean => { return { type: 'boolean', default: defaultValue, valueType: null as $IntentionalAny, [s]: 'TheatrePropType', + label: extras?.label, } } @@ -48,12 +59,16 @@ export interface PropTypeConfig_String extends IBasePropType { default: string } -export const string = (defaultValue: string): PropTypeConfig_String => { +export const string = ( + defaultValue: string, + extras: PropTypeConfigExtras, +): PropTypeConfig_String => { return { type: 'string', default: defaultValue, valueType: null as $IntentionalAny, [s]: 'TheatrePropType', + label: extras.label, } } @@ -68,7 +83,7 @@ export interface PropTypeConfig_StringLiteral export function stringLiteral( defaultValue: Extract, options: Opts, - extras?: {as?: 'menu' | 'switch'}, + extras?: {as?: 'menu' | 'switch'} & PropTypeConfigExtras, ): PropTypeConfig_StringLiteral> { return { type: 'stringLiteral', @@ -77,6 +92,7 @@ export function stringLiteral( [s]: 'TheatrePropType', valueType: null as $IntentionalAny, as: extras?.as ?? 'menu', + label: extras?.label, } } @@ -97,12 +113,14 @@ export interface PropTypeConfig_Compound export const compound = ( props: Props, + extras?: PropTypeConfigExtras, ): PropTypeConfig_Compound => { return { type: 'compound', props, valueType: null as $IntentionalAny, [s]: 'TheatrePropType', + label: extras?.label, } } diff --git a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/BooleanPropEditor.tsx b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/BooleanPropEditor.tsx index 4930475..bcf22cb 100644 --- a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/BooleanPropEditor.tsx +++ b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/BooleanPropEditor.tsx @@ -1,16 +1,30 @@ -import type {PropTypeConfig_Boolean} from '@theatre/core/propTypes' +import type { + PropTypeConfig, + PropTypeConfig_Boolean, +} from '@theatre/core/propTypes' import type SheetObject from '@theatre/core/sheetObjects/SheetObject' import useContextMenu from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu' import useRefAndState from '@theatre/studio/utils/useRefAndState' import {getPointerParts} from '@theatre/dataverse' import {last} from 'lodash-es' import React, {useCallback} from 'react' -import styled from 'styled-components' +import styled, {css} from 'styled-components' import { shadeToColor, useEditingToolsForPrimitiveProp, } from './useEditingToolsForPrimitiveProp' +export const labelText = css` + font-weight: 300; + font-size: 11px; + color: #9a9a9a; + text-shadow: 0.5px 0.5px 2px black; + + &:hover { + color: white; + } +` + const Container = styled.div` display: flex; height: 30px; @@ -18,23 +32,10 @@ const Container = styled.div` align-items: center; ` -export const NumberPropEditor_theme = { - label: { - color: `#787878`, - }, -} - -const Label = styled.div` +const Label = styled.label` margin-right: 4px; - font-weight: 200; - font-size: 12px; - color: ${NumberPropEditor_theme.label.color}; - cursor: default; text-align: right; - - &:hover { - color: white; - } + ${labelText}; ` const Body = styled.label` display: flex; @@ -47,6 +48,38 @@ const Body = styled.label` margin-left: 4px; ` +export const PrimitivePropEditor: React.FC<{ + propConfig: PropTypeConfig + pointerToProp: SheetObject['propsP'] + stuff: ReturnType +}> = ({propConfig, pointerToProp, stuff, children}) => { + const label = propConfig.label ?? last(getPointerParts(pointerToProp).path) + + const [labelRef, labelNode] = useRefAndState(null) + + const [contextMenu] = useContextMenu(labelNode, { + items: stuff.contextMenuItems, + }) + + const color = shadeToColor[stuff.shade] + + return ( + + {contextMenu} + + {stuff.controlIndicators} + {children} + + ) +} + const BooleanPropEditor: React.FC<{ propConfig: PropTypeConfig_Boolean pointerToProp: SheetObject['propsP'] @@ -54,14 +87,6 @@ const BooleanPropEditor: React.FC<{ }> = ({propConfig, pointerToProp, obj}) => { const stuff = useEditingToolsForPrimitiveProp(pointerToProp, obj) - const label = last(getPointerParts(pointerToProp).path) - - const [labelRef, labelNode] = useRefAndState(null) - - const [contextMenu] = useContextMenu(labelNode, { - items: stuff.contextMenuItems, - }) - const onChange = useCallback( (el: React.ChangeEvent) => { stuff.permenantlySetValue(Boolean(el.target.checked)) @@ -69,17 +94,10 @@ const BooleanPropEditor: React.FC<{ [propConfig, pointerToProp, obj], ) - const color = shadeToColor[stuff.shade] - return ( - - {contextMenu} - - {stuff.controlIndicators} - - - - + + + ) } diff --git a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/CompoundPropEditor.tsx b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/CompoundPropEditor.tsx index ed2a91e..eb24622 100644 --- a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/CompoundPropEditor.tsx +++ b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/CompoundPropEditor.tsx @@ -13,6 +13,7 @@ import {GoChevronRight} from 'react-icons/go' import styled from 'styled-components' import DeterminePropEditor from './DeterminePropEditor' import NextPrevKeyframeCursors from './utils/NextPrevKeyframeCursors' +import {labelText} from './BooleanPropEditor' const Container = styled.div<{depth: number}>` --depth: ${(props) => props.depth}; @@ -36,6 +37,7 @@ const IconContainer = styled.div` const PropName = styled.div` margin-right: 4px; cursor: default; + ${labelText} ` const SubProps = styled.div<{depth: number; lastSubIsComposite: boolean}>` @@ -49,7 +51,7 @@ const CompoundPropEditor: React.FC<{ propConfig: PropTypeConfig_Compound<$IntentionalAny> depth: number }> = ({pointerToProp, obj, propConfig, depth}) => { - const propName = last(getPointerParts(pointerToProp).path) + const propName = propConfig.label ?? last(getPointerParts(pointerToProp).path) const allSubs = Object.entries(propConfig.props) const compositeSubs = allSubs.filter(([_, conf]) => diff --git a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx index 1d5cba7..424b6b0 100644 --- a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx +++ b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx @@ -1,50 +1,9 @@ import type {PropTypeConfig_Number} from '@theatre/core/propTypes' import type SheetObject from '@theatre/core/sheetObjects/SheetObject' import BasicNumberEditor from '@theatre/studio/uiComponents/form/BasicNumberEditor' -import useContextMenu from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu' -import useRefAndState from '@theatre/studio/utils/useRefAndState' -import {getPointerParts} from '@theatre/dataverse' -import {last} from 'lodash-es' import React from 'react' -import styled from 'styled-components' -import { - shadeToColor, - useEditingToolsForPrimitiveProp, -} from './useEditingToolsForPrimitiveProp' - -const Container = styled.div` - display: flex; - height: 30px; - justify-content: flex-end; - align-items: center; -` - -export const NumberPropEditor_theme = { - label: { - color: `#787878`, - }, -} - -const Label = styled.div` - margin-right: 4px; - font-weight: 200; - font-size: 12px; - color: ${NumberPropEditor_theme.label.color}; - cursor: default; - text-align: right; - - &:hover { - color: white; - } -` -const Body = styled.div` - cursor: ew-resize; - display: flex; - width: 140px; - height: 100%; - margin-right: 16px; - margin-left: 4px; -` +import {useEditingToolsForPrimitiveProp} from './useEditingToolsForPrimitiveProp' +import {PrimitivePropEditor} from './BooleanPropEditor' const NumberPropEditor: React.FC<{ propConfig: PropTypeConfig_Number @@ -53,30 +12,15 @@ const NumberPropEditor: React.FC<{ }> = ({propConfig, pointerToProp, obj}) => { const stuff = useEditingToolsForPrimitiveProp(pointerToProp, obj) - const label = last(getPointerParts(pointerToProp).path) - - const [labelRef, labelNode] = useRefAndState(null) - - const [contextMenu] = useContextMenu(labelNode, { - items: stuff.contextMenuItems, - }) - - const color = shadeToColor[stuff.shade] - return ( - - {contextMenu} - - {stuff.controlIndicators} - - - - + + + ) } diff --git a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/StringLiteralPropEditor.tsx b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/StringLiteralPropEditor.tsx index 3efdd34..56b9f92 100644 --- a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/StringLiteralPropEditor.tsx +++ b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/StringLiteralPropEditor.tsx @@ -1,52 +1,11 @@ import type {PropTypeConfig_StringLiteral} from '@theatre/core/propTypes' import type SheetObject from '@theatre/core/sheetObjects/SheetObject' -import useContextMenu from '@theatre/studio/uiComponents/simpleContextMenu/useContextMenu' -import useRefAndState from '@theatre/studio/utils/useRefAndState' -import {getPointerParts} from '@theatre/dataverse' -import {last} from 'lodash-es' import React, {useCallback} from 'react' -import styled from 'styled-components' -import { - shadeToColor, - useEditingToolsForPrimitiveProp, -} from './useEditingToolsForPrimitiveProp' +import {useEditingToolsForPrimitiveProp} from './useEditingToolsForPrimitiveProp' import type {$IntentionalAny} from '@theatre/shared/utils/types' import BasicSwitchEditor from '@theatre/studio/uiComponents/form/BasicSwitchEditor' import BasicSelectEditor from '@theatre/studio/uiComponents/form/BasicSelectEditor' - -const Container = styled.div` - display: flex; - height: 30px; - justify-content: flex-end; - align-items: center; -` - -export const NumberPropEditor_theme = { - label: { - color: `#787878`, - }, -} - -const Label = styled.div` - margin-right: 4px; - font-weight: 200; - font-size: 12px; - color: ${NumberPropEditor_theme.label.color}; - cursor: default; - text-align: right; - - &:hover { - color: white; - } -` -const Body = styled.div` - cursor: ew-resize; - display: flex; - width: 140px; - height: 100%; - margin-right: 16px; - margin-left: 4px; -` +import {PrimitivePropEditor} from './BooleanPropEditor' const StringLiteralPropEditor: React.FC<{ propConfig: PropTypeConfig_StringLiteral<$IntentionalAny> @@ -55,14 +14,6 @@ const StringLiteralPropEditor: React.FC<{ }> = ({propConfig, pointerToProp, obj}) => { const stuff = useEditingToolsForPrimitiveProp(pointerToProp, obj) - const label = last(getPointerParts(pointerToProp).path) - - const [labelRef, labelNode] = useRefAndState(null) - - const [contextMenu] = useContextMenu(labelNode, { - items: stuff.contextMenuItems, - }) - const onChange = useCallback( (val: string) => { stuff.permenantlySetValue(val) @@ -70,29 +21,22 @@ const StringLiteralPropEditor: React.FC<{ [propConfig, pointerToProp, obj], ) - const color = shadeToColor[stuff.shade] - return ( - - {contextMenu} - - {stuff.controlIndicators} - - {propConfig.as === 'menu' ? ( - - ) : ( - - )} - - + + {propConfig.as === 'menu' ? ( + + ) : ( + + )} + ) } diff --git a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Left/PrimitivePropRow.tsx b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Left/PrimitivePropRow.tsx index 07be07c..6cfa836 100644 --- a/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Left/PrimitivePropRow.tsx +++ b/theatre/studio/src/panels/SequenceEditorPanel/DopeSheet/Left/PrimitivePropRow.tsx @@ -8,12 +8,17 @@ import type {Pointer} from '@theatre/dataverse' import {val} from '@theatre/dataverse' import React, {useCallback, useRef} from 'react' import styled from 'styled-components' -import {NumberPropEditor_theme} from '@theatre/studio/panels/ObjectEditorPanel/propEditors/NumberPropEditor' import {useEditingToolsForPrimitiveProp} from '@theatre/studio/panels/ObjectEditorPanel/propEditors/useEditingToolsForPrimitiveProp' import {nextPrevCursorsTheme} from '@theatre/studio/panels/ObjectEditorPanel/propEditors/utils/NextPrevKeyframeCursors' import {graphEditorColors} from '@theatre/studio/panels/SequenceEditorPanel/GraphEditor/GraphEditor' import {BaseHeader, Container as BaseContainer} from './AnyCompositeRow' +const theme = { + label: { + color: `#9a9a9a`, + }, +} + const Container = styled(BaseContainer)<{}>`` const Head = styled(BaseHeader)<{ @@ -21,7 +26,7 @@ const Head = styled(BaseHeader)<{ isEven: boolean }>` display: flex; - color: ${NumberPropEditor_theme.label.color}; + color: ${theme.label.color}; padding-right: 12px; align-items: center; justify-content: flex-end;