Implement ToolbarSwitchSelect
This commit is contained in:
parent
20603afd40
commit
ff0f8d557b
7 changed files with 137 additions and 31 deletions
|
@ -2,13 +2,16 @@ import type {VFC} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {useEditorStore} from '../../store'
|
import {useEditorStore} from '../../store'
|
||||||
import shallow from 'zustand/shallow'
|
import shallow from 'zustand/shallow'
|
||||||
import {GiPocketBow, IoCameraOutline} from 'react-icons/all'
|
import {GiPocketBow, IoCameraOutline, RiFocus3Line} from 'react-icons/all'
|
||||||
import {Vector3} from 'three'
|
import {Vector3} from 'three'
|
||||||
import type {$FixMe} from '@theatre/shared/utils/types'
|
import type {$FixMe} from '@theatre/shared/utils/types'
|
||||||
import studio, {ToolbarIconButton} from '@theatre/studio'
|
import studio, {ToolbarIconButton} from '@theatre/studio'
|
||||||
import {getSelected} from '../useSelected'
|
import {getSelected} from '../useSelected'
|
||||||
import {usePrism, useVal} from '@theatre/dataverse-react'
|
import {usePrism, useVal} from '@theatre/dataverse-react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
import TransformControlsModeSelect from './TransformControlsModeSelect'
|
||||||
|
import ViewportShadingSelect from './ViewportShadingSelect'
|
||||||
|
import TransformControlsSpaceSelect from './TransformControlsSpaceSelect'
|
||||||
|
|
||||||
const ToolGroup = styled.div`
|
const ToolGroup = styled.div`
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
|
@ -44,7 +47,7 @@ const Toolbar: VFC = () => {
|
||||||
label="Create snapshot"
|
label="Create snapshot"
|
||||||
/>
|
/>
|
||||||
</ToolGroup>
|
</ToolGroup>
|
||||||
{/* <ToolGroup>
|
<ToolGroup>
|
||||||
<TransformControlsModeSelect
|
<TransformControlsModeSelect
|
||||||
value={transformControlsMode}
|
value={transformControlsMode}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
|
@ -75,7 +78,7 @@ const Toolbar: VFC = () => {
|
||||||
/>
|
/>
|
||||||
</ToolGroup>
|
</ToolGroup>
|
||||||
<ToolGroup>
|
<ToolGroup>
|
||||||
<IconButton
|
<ToolbarIconButton
|
||||||
label="Focus on selected"
|
label="Focus on selected"
|
||||||
icon={<RiFocus3Line />}
|
icon={<RiFocus3Line />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
@ -99,7 +102,7 @@ const Toolbar: VFC = () => {
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ToolGroup> */}
|
</ToolGroup>
|
||||||
<ToolGroup>
|
<ToolGroup>
|
||||||
<ToolbarIconButton
|
<ToolbarIconButton
|
||||||
label="Align object to view"
|
label="Align object to view"
|
||||||
|
|
|
@ -1,39 +1,41 @@
|
||||||
|
import {ToolbarSwitchSelect} from '@theatre/studio'
|
||||||
import type {VFC} from 'react'
|
import type {VFC} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {GiClockwiseRotation, GiMove, GiResize} from 'react-icons/all'
|
import {GiClockwiseRotation, GiMove, GiResize} from 'react-icons/all'
|
||||||
import type {TransformControlsMode} from '../../store'
|
import type {TransformControlsMode} from '../../store'
|
||||||
import CompactModeSelect from './utils/CompactModeSelect'
|
|
||||||
|
|
||||||
export interface TransformControlsModeSelectProps {
|
export interface TransformControlsModeSelectProps {
|
||||||
value: TransformControlsMode
|
value: TransformControlsMode
|
||||||
onChange: (value: TransformControlsMode) => void
|
onChange: (value: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const TransformControlsModeSelect: VFC<TransformControlsModeSelectProps> = ({
|
const TransformControlsModeSelect: VFC<TransformControlsModeSelectProps> = ({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
}) => (
|
}) => {
|
||||||
<CompactModeSelect
|
return (
|
||||||
|
<ToolbarSwitchSelect
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
option: 'translate',
|
value: 'translate',
|
||||||
label: 'Tool: Translate',
|
label: 'Tool: Translate',
|
||||||
icon: <GiMove />,
|
icon: <GiMove />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
option: 'rotate',
|
value: 'rotate',
|
||||||
label: 'Tool: Rotate',
|
label: 'Tool: Rotate',
|
||||||
icon: <GiClockwiseRotation />,
|
icon: <GiClockwiseRotation />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
option: 'scale',
|
value: 'scale',
|
||||||
label: 'Tool: Scale',
|
label: 'Tool: Scale',
|
||||||
icon: <GiResize />,
|
icon: <GiResize />,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default TransformControlsModeSelect
|
export default TransformControlsModeSelect
|
||||||
|
|
|
@ -55,6 +55,8 @@ function OptionButton<Option>({
|
||||||
icon,
|
icon,
|
||||||
onClick,
|
onClick,
|
||||||
}: OptionButtonProps<Option>) {
|
}: OptionButtonProps<Option>) {
|
||||||
|
console.log('deprecate CompactModeSelect')
|
||||||
|
|
||||||
const tooltip = useTooltipState()
|
const tooltip = useTooltipState()
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
@ -6,7 +6,9 @@ import * as globalVariableNames from '@theatre/shared/globalVariableNames'
|
||||||
import type {$FixMe} from '@theatre/shared/utils/types'
|
import type {$FixMe} from '@theatre/shared/utils/types'
|
||||||
import StudioBundle from './StudioBundle'
|
import StudioBundle from './StudioBundle'
|
||||||
import type CoreBundle from '@theatre/core/CoreBundle'
|
import type CoreBundle from '@theatre/core/CoreBundle'
|
||||||
|
export {default as ToolbarSwitchSelect} from './uiComponents/toolbar/ToolbarSwitchSelect'
|
||||||
export {default as ToolbarIconButton} from './uiComponents/toolbar/ToolbarIconButton'
|
export {default as ToolbarIconButton} from './uiComponents/toolbar/ToolbarIconButton'
|
||||||
|
export {default as ToolbarDropdownSelect} from './uiComponents/toolbar/ToolbarDropdownSelect'
|
||||||
|
|
||||||
const studioPrivateAPI = new Studio()
|
const studioPrivateAPI = new Studio()
|
||||||
setStudio(studioPrivateAPI)
|
setStudio(studioPrivateAPI)
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import React from 'react'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
|
||||||
|
const Container = styled.div``
|
||||||
|
|
||||||
|
const ToolbarDropdownSelect: React.FC<{
|
||||||
|
value: string
|
||||||
|
options: Array<{label: string; value: string; icon: React.ReactElement}>
|
||||||
|
onChange: (value: string) => void
|
||||||
|
label: (cur: {label: string; value: string}) => string
|
||||||
|
}> = (props) => {
|
||||||
|
return <Container></Container>
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ToolbarDropdownSelect
|
|
@ -2,12 +2,12 @@ import type {ReactElement} from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import {Tooltip, TooltipReference} from '@theatre/studio/uiComponents/Tooltip'
|
import {Tooltip, TooltipReference} from '@theatre/studio/uiComponents/Tooltip'
|
||||||
import {lighten} from 'polished'
|
import {lighten, darken} from 'polished'
|
||||||
import type {ButtonProps} from 'reakit'
|
import type {ButtonProps} from 'reakit'
|
||||||
import {useTooltipState} from 'reakit'
|
import {useTooltipState} from 'reakit'
|
||||||
import {Button} from 'reakit'
|
import {Button} from 'reakit'
|
||||||
|
|
||||||
const TheButton = styled(TooltipReference)`
|
export const TheButton = styled(TooltipReference)`
|
||||||
pointer-events: auto;
|
pointer-events: auto;
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -24,6 +24,11 @@ const TheButton = styled(TooltipReference)`
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.selected {
|
||||||
|
background-color: ${darken(0.1, '#313131')};
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
color: #c0c0c0;
|
color: #c0c0c0;
|
||||||
background-color: #313131;
|
background-color: #313131;
|
||||||
border: 1px solid #272727;
|
border: 1px solid #272727;
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
import type {ReactElement} from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
import type {IconType} from 'react-icons'
|
||||||
|
import {Group, Button} from 'reakit'
|
||||||
|
import styled from 'styled-components'
|
||||||
|
import {Tooltip, useTooltipState} from '@theatre/studio/uiComponents/Tooltip'
|
||||||
|
import {TheButton as ButtonImpl} from './ToolbarIconButton'
|
||||||
|
|
||||||
|
const Opt = styled(ButtonImpl)``
|
||||||
|
|
||||||
|
function OptionButton<T>({
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
icon,
|
||||||
|
onClick,
|
||||||
|
isSelected,
|
||||||
|
}: {
|
||||||
|
value: T
|
||||||
|
label: string
|
||||||
|
icon: ReactElement<IconType>
|
||||||
|
onClick: () => void
|
||||||
|
isSelected: boolean
|
||||||
|
}) {
|
||||||
|
const tooltip = useTooltipState()
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Opt
|
||||||
|
{...tooltip}
|
||||||
|
forwardedAs={Button}
|
||||||
|
className={isSelected ? 'selected' : undefined}
|
||||||
|
aria-label={label}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
{icon}
|
||||||
|
</Opt>
|
||||||
|
<Tooltip {...tooltip}>{label}</Tooltip>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props<Option> {
|
||||||
|
value: Option
|
||||||
|
onChange: (value: Option) => void
|
||||||
|
options: {
|
||||||
|
value: Option
|
||||||
|
label: string
|
||||||
|
icon: ReactElement<IconType>
|
||||||
|
}[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const Container = styled(Group)`
|
||||||
|
display: flex;
|
||||||
|
gap: 2px;
|
||||||
|
`
|
||||||
|
|
||||||
|
const ToolbarSwitchSelect = <Option extends string | number>({
|
||||||
|
value: valueOfSwitch,
|
||||||
|
onChange,
|
||||||
|
options,
|
||||||
|
}: Props<Option>) => {
|
||||||
|
return (
|
||||||
|
<Container>
|
||||||
|
{options.map(({label, icon, value: optionValue}) => (
|
||||||
|
<OptionButton
|
||||||
|
key={optionValue}
|
||||||
|
value={optionValue}
|
||||||
|
isSelected={valueOfSwitch === optionValue}
|
||||||
|
label={label}
|
||||||
|
icon={icon}
|
||||||
|
onClick={() => onChange(optionValue)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ToolbarSwitchSelect
|
Loading…
Reference in a new issue