Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bold inputs when value changes #420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const AddImage = styled.div`
background-size: 5px 5px;
`

const InputLabel = styled.label<{empty: boolean}>`
const InputLabel = styled.label<{empty: boolean; changed: boolean}>`
position: relative;
cursor: default;
box-sizing: border-box;
Expand All @@ -43,6 +43,7 @@ const InputLabel = styled.label<{empty: boolean}>`
justify-content: center;
align-items: center;
font-size: 16px;
font-weight: ${(props) => (props.changed ? 'bold' : 'normal')};

overflow: hidden;
color: #ccc;
Expand Down Expand Up @@ -138,6 +139,7 @@ function ImagePropEditor({
<Container empty={empty}>
<InputLabel
empty={empty}
changed={value !== propConfig.default}
title={
empty ? 'Upload image' : `"${value.id}" (Click to upload new image)`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function NumberPropEditor({
temporarilySetValue={editingTools.temporarilySetValue}
discardTemporaryValue={editingTools.discardTemporaryValue}
permanentlySetValue={editingTools.permanentlySetValue}
defaultValue={propConfig.default}
range={propConfig.range}
nudge={nudge}
autoFocus={autoFocus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ColorPreviewPuck = styled.div.attrs<ColorPreviewPuckProps>((props) => ({
border-radius: 99999px;
`

const HexInput = styled(BasicStringInput)`
const HexInput = styled(BasicStringInput)<{defaultValue: string}>`
flex: 1;
`

Expand All @@ -61,6 +61,7 @@ const RgbaPopover = styled.div`
`

function RgbaPropEditor({
propConfig,
editingTools,
value,
autoFocus,
Expand Down Expand Up @@ -109,6 +110,9 @@ function RgbaPropEditor({
/>
<HexInput
value={rgba2hex(value, {removeAlphaIfOpaque: true})}
defaultValue={rgba2hex(propConfig.default, {
removeAlphaIfOpaque: true,
})}
temporarilySetValue={noop}
discardTemporaryValue={noop}
permanentlySetValue={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ function StringLiteralPropEditor<TLiteralOptions extends string>({
return propConfig.as === 'menu' ? (
<BasicSelect
value={value}
defaultValue={propConfig.default}
onChange={onChange}
options={propConfig.valuesAndLabels}
autoFocus={autoFocus}
/>
) : (
<BasicSwitch
value={value}
defaultValue={propConfig.default}
onChange={onChange}
options={propConfig.valuesAndLabels}
autoFocus={autoFocus}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import BasicStringInput from '@theatre/studio/uiComponents/form/BasicStringInput
import type {ISimplePropEditorReactProps} from './ISimplePropEditorReactProps'

function StringPropEditor({
propConfig,
editingTools,
value,
autoFocus,
Expand All @@ -14,6 +15,7 @@ function StringPropEditor({
temporarilySetValue={editingTools.temporarilySetValue}
discardTemporaryValue={editingTools.discardTemporaryValue}
permanentlySetValue={editingTools.permanentlySetValue}
defaultValue={propConfig.default}
autoFocus={autoFocus}
/>
)
Expand Down
6 changes: 5 additions & 1 deletion theatre/studio/src/uiComponents/form/BasicNumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Container = styled.div`
}
`

const Input = styled.input`
const Input = styled.input<{defaultValue: number}>`
background: transparent;
border: 1px solid transparent;
color: rgba(255, 255, 255, 0.9);
Expand All @@ -52,6 +52,8 @@ const Input = styled.input`
width: 100%;
height: calc(100% - 4px);
border-radius: 2px;
font-weight: ${(props) =>
props.value === props.defaultValue ? 'normal' : 'bold'};

&:focus {
cursor: text;
Expand Down Expand Up @@ -107,6 +109,7 @@ const BasicNumberInput: React.FC<{
discardTemporaryValue: () => void
permanentlySetValue: (v: number) => void
className?: string
defaultValue: number
range?: [min: number, max: number]
isValid?: (v: number) => boolean
inputRef?: MutableRefObject<HTMLInputElement | null>
Expand Down Expand Up @@ -308,6 +311,7 @@ const BasicNumberInput: React.FC<{
type="text"
onChange={callbacks.inputChange}
value={value}
defaultValue={propsA.defaultValue}
onBlur={callbacks.onBlur}
onKeyDown={callbacks.onInputKeyDown}
onClick={callbacks.onClick}
Expand Down
7 changes: 6 additions & 1 deletion theatre/studio/src/uiComponents/form/BasicSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const IconContainer = styled.div`
pointer-events: none;
`

const Select = styled.select`
const Select = styled.select<{defaultValue: string}>`
appearance: none;
background-color: transparent;
box-sizing: border-box;
Expand All @@ -37,6 +37,8 @@ const Select = styled.select`
So we're hard-coding the height to 26px, unlike all other inputs that use a relative height.
*/
height: 26px /* calc(100% - 4px); */;
font-weight: ${(props) =>
props.value === props.defaultValue ? 'normal' : 'bold'};

@supports (-moz-appearance: none) {
/* Ugly hack to remove the extra left padding that shows up only in Firefox */
Expand All @@ -52,12 +54,14 @@ const Select = styled.select`

function BasicSelect<TLiteralOptions extends string>({
value,
defaultValue,
onChange,
options,
className,
autoFocus,
}: {
value: TLiteralOptions
defaultValue: TLiteralOptions
onChange: (val: TLiteralOptions) => void
options: Record<TLiteralOptions, string>
className?: string
Expand All @@ -75,6 +79,7 @@ function BasicSelect<TLiteralOptions extends string>({
<Select
className={className}
value={value}
defaultValue={defaultValue}
onChange={_onChange}
autoFocus={autoFocus}
>
Expand Down
10 changes: 7 additions & 3 deletions theatre/studio/src/uiComponents/form/BasicStringInput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import styled from 'styled-components'
import type {MutableRefObject} from 'react';
import { useEffect} from 'react'
import type {MutableRefObject} from 'react'
import {useEffect} from 'react'
import React, {useMemo, useRef} from 'react'
import mergeRefs from 'react-merge-refs'
import useRefAndState from '@theatre/studio/utils/useRefAndState'
import useOnClickOutside from '@theatre/studio/uiComponents/useOnClickOutside'

const Input = styled.input.attrs({type: 'text'})`
const Input = styled.input.attrs({type: 'text'})<{defaultValue: string}>`
background: transparent;
border: 1px solid transparent;
color: rgba(255, 255, 255, 0.9);
Expand All @@ -20,6 +20,8 @@ const Input = styled.input.attrs({type: 'text'})`
border-radius: 2px;
border: 1px solid transparent;
box-sizing: border-box;
font-weight: ${(props) =>
props.value === props.defaultValue ? 'normal' : 'bold'};

&:hover {
background-color: #10101042;
Expand Down Expand Up @@ -54,6 +56,7 @@ const alwaysValid = (v: string) => true

const BasicStringInput: React.FC<{
value: string
defaultValue: string
temporarilySetValue: (v: string) => void
discardTemporaryValue: () => void
permanentlySetValue: (v: string) => void
Expand Down Expand Up @@ -192,6 +195,7 @@ const BasicStringInput: React.FC<{
className={`${props.className ?? ''} ${!isValid(value) ? 'invalid' : ''}`}
onChange={callbacks.inputChange}
value={value}
defaultValue={props.defaultValue}
onBlur={callbacks.onBlur}
onKeyDown={callbacks.onInputKeyDown}
onClick={callbacks.onClick}
Expand Down
7 changes: 6 additions & 1 deletion theatre/studio/src/uiComponents/form/BasicSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,25 @@ const Label = styled.label`
}
`

const Input = styled.input`
const Input = styled.input<{defaultValue: string}>`
position: absolute;
opacity: 0;
pointer-events: none;
width: 0;
height: 0;
font-weight: ${(props) =>
props.value === props.defaultValue ? 'normal' : 'bold'};
`

function BasicSwitch<TLiteralOptions extends string>({
value,
defaultValue,
onChange,
options,
autoFocus,
}: {
value: TLiteralOptions
defaultValue: TLiteralOptions
onChange: (val: TLiteralOptions) => void
options: Record<TLiteralOptions, string>
autoFocus?: boolean
Expand All @@ -78,6 +82,7 @@ function BasicSwitch<TLiteralOptions extends string>({
type="radio"
checked={value === key}
value={key}
defaultValue={defaultValue}
onChange={_onChange}
name="switchbox"
autoFocus={autoFocus}
Expand Down
Loading