From 232ffa7836a0d65be1a9b651f913a48a65913b13 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Fri, 16 Jul 2021 11:08:09 +0200 Subject: [PATCH] Range indicator for the number editor --- packages/plugin-r3f/src/store.ts | 5 +- theatre/core/src/propTypes/index.ts | 7 +-- .../propEditors/NumberPropEditor.tsx | 1 + .../uiComponents/form/BasicNumberInput.tsx | 59 ++++++++++++++++++- 4 files changed, 63 insertions(+), 9 deletions(-) diff --git a/packages/plugin-r3f/src/store.ts b/packages/plugin-r3f/src/store.ts index c4d8682..5f8c923 100644 --- a/packages/plugin-r3f/src/store.ts +++ b/packages/plugin-r3f/src/store.ts @@ -295,7 +295,10 @@ const editorSheetObjectConfig = types.compound({ showAxes: types.boolean(true, {label: 'Axes'}), showGrid: types.boolean(true, {label: 'Grid'}), showOverlayIcons: types.boolean(false, {label: 'Overlay Icons'}), - resolution: types.number(1440, {label: 'Resolution'}), + resolution: types.number(1440, { + label: 'Resolution', + range: [0, 1000], + }), shading: types.stringLiteral( 'rendered', { diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index 941da8d..67032dd 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -12,15 +12,12 @@ interface IBasePropType { export interface PropTypeConfig_Number extends IBasePropType { type: 'number' default: number - min?: number - max?: number - step?: number + range?: [min: number, max: number] } export const number = ( defaultValue: number, - opts?: Pick & - PropTypeConfigExtras, + opts?: Pick & PropTypeConfigExtras, ): PropTypeConfig_Number => { return { type: 'number', diff --git a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx index 8e08252..2a013f0 100644 --- a/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx +++ b/theatre/studio/src/panels/ObjectEditorPanel/propEditors/NumberPropEditor.tsx @@ -19,6 +19,7 @@ const NumberPropEditor: React.FC<{ temporarilySetValue={stuff.temporarilySetValue} discardTemporaryValue={stuff.discardTemporaryValue} permenantlySetValue={stuff.permenantlySetValue} + range={propConfig.range} /> ) diff --git a/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx b/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx index a20dba6..01417e0 100644 --- a/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx +++ b/theatre/studio/src/uiComponents/form/BasicNumberInput.tsx @@ -1,5 +1,5 @@ import {theme} from '@theatre/studio/css' -import {isInteger, round} from 'lodash-es' +import {clamp, isInteger, round} from 'lodash-es' import {darken, lighten} from 'polished' import React, {useMemo, useRef, useState} from 'react' import styled from 'styled-components' @@ -10,6 +10,31 @@ type IMode = IState['mode'] const Container = styled.div` height: 100%; width: 100%; + position: relative; + z-index: 0; + box-sizing: border-box; + + &:after { + position: absolute; + inset: 1px 0 2px; + display: block; + content: ' '; + background-color: #2525252b; + border: 1px solid #1c2123; + z-index: -2; + box-sizing: border-box; + border-radius: 1px; + } + + &:hover, + &.dragging, + &.editingViaKeyboard { + &:after { + background-color: #10101042; + /* background-color: ${darken(0.2, theme.panel.bg)}; */ + border-color: #00000059; + } + } ` const Input = styled.input` @@ -25,18 +50,32 @@ const Input = styled.input` height: calc(100% - 4px); border-radius: 2px; - &:hover, + /* &:hover, &:focus, ${Container}.dragging > & { background: ${darken(0.9, theme.panel.bg)}; border: 1px solid ${lighten(0.1, theme.panel.bg)}; - } + } */ &:focus { cursor: text; } ` +const FillIndicator = styled.div` + position: absolute; + inset: 3px 2px 4px; + transform: scale(var(--percentage), 1); + transform-origin: top left; + background-color: #2d5561; + z-index: -1; + border-radius: 2px; + + ${Container}.dragging &, ${Container}.noFocus:hover & { + background-color: #338198; + } +` + function isValueAcceptable(s: string) { const v = parseFloat(s) return !isNaN(v) @@ -66,6 +105,7 @@ const BasicNumberInput: React.FC<{ discardTemporaryValue: () => void permenantlySetValue: (v: number) => void className?: string + range?: [min: number, max: number] }> = (propsA) => { const [stateA, setState] = useState({mode: 'noFocus'}) @@ -238,6 +278,18 @@ const BasicNumberInput: React.FC<{ /> ) + const {range} = propsA + const num = parseFloat(value) + + const fillIndicator = range ? ( + + ) : null + return ( {theInput} + {fillIndicator} ) }