Add chevron for collapsing detail rows (#383)

* Add chevron for collapsing detail rows

* Move collapse icon to the right of the label

* Fix ugliness

* Fix ugly
This commit is contained in:
Andrew Prifer 2023-01-22 20:44:22 +01:00 committed by GitHub
parent 415ec76942
commit aec79bd8c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -22,13 +22,12 @@ import {useEditingToolsForCompoundProp} from '@theatre/studio/propEditors/useEdi
import type {PropHighlighted} from '@theatre/studio/panels/SequenceEditorPanel/whatPropIsHighlighted' import type {PropHighlighted} from '@theatre/studio/panels/SequenceEditorPanel/whatPropIsHighlighted'
import {whatPropIsHighlighted} from '@theatre/studio/panels/SequenceEditorPanel/whatPropIsHighlighted' import {whatPropIsHighlighted} from '@theatre/studio/panels/SequenceEditorPanel/whatPropIsHighlighted'
import {deriver} from '@theatre/studio/utils/derive-utils' import {deriver} from '@theatre/studio/utils/derive-utils'
import {getDetailRowHighlightBackground} from './getDetailRowHighlightBackground'
import NumberPropEditor from '@theatre/studio/propEditors/simpleEditors/NumberPropEditor' import NumberPropEditor from '@theatre/studio/propEditors/simpleEditors/NumberPropEditor'
import type {IDetailSimplePropEditorProps} from './DetailSimplePropEditor' import type {IDetailSimplePropEditorProps} from './DetailSimplePropEditor'
import {useEditingToolsForSimplePropInDetailsPanel} from '@theatre/studio/propEditors/useEditingToolsForSimpleProp' import {useEditingToolsForSimplePropInDetailsPanel} from '@theatre/studio/propEditors/useEditingToolsForSimpleProp'
import {EllipsisFill} from '@theatre/studio/uiComponents/icons'
import {usePrism} from '@theatre/react' import {usePrism} from '@theatre/react'
import {val} from '@theatre/dataverse' import {val} from '@theatre/dataverse'
import {HiOutlineChevronRight} from 'react-icons/all'
const Container = styled.div` const Container = styled.div`
--step: 15px; --step: 15px;
@ -37,19 +36,24 @@ const Container = styled.div`
--right-width: 60%; --right-width: 60%;
` `
const Header = deriver(styled.div<{isHighlighted: PropHighlighted}>` const Header = styled.div<{isHighlighted: PropHighlighted}>`
height: 30px; height: 30px;
display: flex; display: flex;
align-items: stretch; align-items: stretch;
position: relative; position: relative;
`
/* background-color: ${getDetailRowHighlightBackground}; */ const Padding = styled.div<{isVectorProp: boolean}>`
`)
const Padding = styled.div`
padding-left: ${rowIndentationFormulaCSS}; padding-left: ${rowIndentationFormulaCSS};
display: flex; display: flex;
align-items: center; align-items: center;
overflow: hidden;
${({isVectorProp}) =>
isVectorProp ? 'width: calc(100% - var(--right-width))' : ''};
`
const ControlIndicators = styled.div`
flexshrink: 0;
` `
const PropName = deriver(styled.div<{isHighlighted: PropHighlighted}>` const PropName = deriver(styled.div<{isHighlighted: PropHighlighted}>`
@ -63,10 +67,34 @@ const PropName = deriver(styled.div<{isHighlighted: PropHighlighted}>`
&:hover { &:hover {
color: white; color: white;
} }
overflow: hidden;
${() => propNameTextCSS}; ${() => propNameTextCSS};
`) `)
const CollapseIcon = styled.span<{isCollapsed: boolean}>`
width: 28px;
height: 28px;
font-size: 9px;
display: flex;
align-items: center;
justify-content: center;
transition: transform 0.05s ease-out, color 0.1s ease-out;
transform: rotateZ(${(props) => (props.isCollapsed ? 0 : 90)}deg);
color: #66686a;
visibility: hidden;
${Header}:hover & {
visibility: visible;
}
&:hover {
transform: rotateZ(${(props) => (props.isCollapsed ? 15 : 75)}deg);
color: #c0c4c9;
}
`
const color = transparentize(0.05, `#282b2f`) const color = transparentize(0.05, `#282b2f`)
const SubProps = styled.div<{depth: number; lastSubIsComposite: boolean}>` const SubProps = styled.div<{depth: number; lastSubIsComposite: boolean}>`
@ -190,30 +218,26 @@ function DetailCompoundPropEditor<
<Container> <Container>
{contextMenu} {contextMenu}
<Header <Header
isHighlighted={isPropHighlightedD}
// @ts-ignore // @ts-ignore
style={{'--depth': visualIndentation - 1}} style={{'--depth': visualIndentation - 1}}
> >
<Padding> <Padding isVectorProp={isVectorProp(propConfig)}>
{tools.controlIndicators} <ControlIndicators>{tools.controlIndicators}</ControlIndicators>
<PropName <PropName
isHighlighted={isPropHighlightedD} isHighlighted={isPropHighlightedD}
ref={propNameContainerRef} ref={propNameContainerRef}
>
<span>{propName || 'Props'}</span>
</PropName>
<CollapseIcon
isCollapsed={isCollapsed}
onClick={() => { onClick={() => {
box?.set(!box.get()) box?.set(!box.get())
}} }}
> >
<span>{propName || 'Props'}</span> <HiOutlineChevronRight />
{!isVectorProp(propConfig) && isCollapsed && ( </CollapseIcon>
<EllipsisFill
width={24}
height={24}
style={{
transform: 'translateY(2px)',
}}
/>
)}
</PropName>
</Padding> </Padding>
{isVectorProp(propConfig) && isCollapsed && ( {isVectorProp(propConfig) && isCollapsed && (
<InputContainer> <InputContainer>