-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1123e95
commit d8d20ee
Showing
18 changed files
with
243 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React from 'react' | ||
import { Input } from 'dracula-ui' | ||
|
||
type Type = | ||
| 'button' | ||
| 'checkbox' | ||
| 'color' | ||
| 'date' | ||
| 'datetime-local' | ||
| 'email' | ||
| 'file' | ||
| 'hidden' | ||
| 'image' | ||
| 'month' | ||
| 'number' | ||
| 'password' | ||
| 'radio' | ||
| 'range' | ||
| 'reset' | ||
| 'search' | ||
| 'submit' | ||
| 'tel' | ||
| 'text' | ||
| 'time' | ||
| 'url' | ||
| 'week' | ||
|
||
interface Props { | ||
value: number | string | ||
type?: Type | ||
step?: number | string | undefined | ||
enforceStep?: boolean | undefined | ||
[key: string]: any | ||
} | ||
|
||
export const Field = ({ id, value, onChange, type, step, enforceStep, ...props }: Props) => { | ||
const onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') e.currentTarget.blur() | ||
} | ||
|
||
if (type === 'number') { | ||
// Rounding after a comma or dot is added. | ||
if (enforceStep && step === '1' && value !== '' && typeof value === 'number') { | ||
value = Math.round(value).toString() | ||
} | ||
} | ||
|
||
return ( | ||
<Input | ||
lang="en-150" | ||
size="sm" | ||
borderSize="sm" | ||
onKeyDown={onKeyDown} | ||
onChange={onChange} | ||
{...props} | ||
id={id} | ||
type={type} | ||
step={step} | ||
value={value} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
104 changes: 104 additions & 0 deletions
104
src/components/sidebars/default-properties/DefaultPropertiesSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import React from 'react' | ||
import Section from '../../layout/Section' | ||
import { Box, Heading } from 'dracula-ui' | ||
import FormRow from '../../atoms/FormRow' | ||
import { Field } from '../../atoms/Field' | ||
import { defaultPropertiesState } from '../../../state/AssetsState' | ||
import { useRecoilState } from 'recoil' | ||
import { cloneDeep, set } from 'lodash' | ||
|
||
interface Props {} | ||
|
||
const DefaultPropertiesSection = ({}: Props): JSX.Element => { | ||
const [defaultProps, setDefaultProps] = useRecoilState(defaultPropertiesState) | ||
|
||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const { id, value } = e.target | ||
console.log(id, value) | ||
setDefaultProps((data) => set(cloneDeep(data), id, value)) | ||
} | ||
|
||
return ( | ||
<Section title="Default properties" color="yellow"> | ||
<Heading size="xs">Layer</Heading> | ||
<FormRow> | ||
<label htmlFor="position.z">Z</label> | ||
<Field | ||
style={{ width: '6em' }} | ||
color="green" | ||
type="number" | ||
step="1" | ||
min="-1" | ||
max="1000" | ||
id="position.z" | ||
value={defaultProps.position.z} | ||
onChange={onChange} | ||
/> | ||
</FormRow> | ||
|
||
<Heading size="xs">Scale</Heading> | ||
<FormRow> | ||
<label htmlFor="scale.x">X</label> | ||
<Field | ||
color="green" | ||
type="number" | ||
step="0.1" | ||
max="100" | ||
id="scale.x" | ||
value={defaultProps.scale.x} | ||
onChange={onChange} | ||
/> | ||
<label htmlFor="scale.y">Y</label> | ||
<Field | ||
color="green" | ||
type="number" | ||
step="0.1" | ||
max="100" | ||
id="scale.y" | ||
value={defaultProps.scale.y} | ||
onChange={onChange} | ||
/> | ||
</FormRow> | ||
|
||
<Box pt="sm"> | ||
<Heading size="xs" color="yellow" as="h3"> | ||
Other settings | ||
</Heading> | ||
</Box> | ||
|
||
<Heading size="xs">Rotation</Heading> | ||
<FormRow> | ||
<Field | ||
style={{ width: '6em' }} | ||
color="green" | ||
type="number" | ||
step="1" | ||
min="-179" | ||
max="180" | ||
id="rotation" | ||
value={defaultProps.rotation} | ||
onChange={onChange} | ||
/> | ||
<label htmlFor="rotation">Angle</label> | ||
</FormRow> | ||
|
||
<Heading size="xs">Opacity</Heading> | ||
<FormRow> | ||
<Field | ||
style={{ width: '6em' }} | ||
color="green" | ||
type="number" | ||
step="0.1" | ||
max="1" | ||
min="0" | ||
id="opacity" | ||
value={defaultProps.opacity} | ||
onChange={onChange} | ||
/> | ||
<label htmlFor="opacity">Opacity</label> | ||
</FormRow> | ||
</Section> | ||
) | ||
} | ||
|
||
export default DefaultPropertiesSection |
Oops, something went wrong.