Skip to content

Commit 8b25c8b

Browse files
Add copy to clipboard button for position/rotation/scale properties (#65) (#852)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 26c5cf2 commit 8b25c8b

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

src/components/components/PropertyRow.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import clsx from 'clsx';
55
import { faRotateLeft } from '@fortawesome/free-solid-svg-icons';
66

77
import { AwesomeIcon } from '../AwesomeIcon';
8+
import CopyToClipboardButton from '../CopyToClipboardButton';
89
import BooleanWidget from '../widgets/BooleanWidget';
910
import ColorWidget from '../widgets/ColorWidget';
1011
import InputWidget from '../widgets/InputWidget';
@@ -16,6 +17,9 @@ import Vec3Widget from '../widgets/Vec3Widget';
1617
import Vec2Widget from '../widgets/Vec2Widget';
1718
import { updateEntity } from '../../lib/entity';
1819
import { equal } from '../../lib/utils';
20+
import { getComponentClipboardRepresentation } from '../../lib/entity';
21+
22+
const COPYABLE_COMPONENTS = ['position', 'rotation', 'scale'];
1923

2024
export default class PropertyRow extends React.Component {
2125
static propTypes = {
@@ -212,10 +216,28 @@ export default class PropertyRow extends React.Component {
212216
{props.name}
213217
</label>
214218
{this.getWidget()}
215-
{isPropertyExplicitlySet && type !== 'map' && (
219+
<div className="propertyRow-actions">
220+
{type === 'vec3' &&
221+
COPYABLE_COMPONENTS.includes(props.componentname) && (
222+
<CopyToClipboardButton
223+
title="Copy to clipboard"
224+
message="Copied to clipboard"
225+
text={() =>
226+
getComponentClipboardRepresentation(
227+
props.entity,
228+
props.componentname
229+
)
230+
}
231+
/>
232+
)}
216233
<button
217234
className="reset-button"
218235
title="Reset"
236+
style={
237+
!(isPropertyExplicitlySet && type !== 'map')
238+
? { visibility: 'hidden' }
239+
: null
240+
}
219241
onClick={() => {
220242
updateEntity(
221243
props.entity,
@@ -227,7 +249,7 @@ export default class PropertyRow extends React.Component {
227249
>
228250
<AwesomeIcon icon={faRotateLeft} />
229251
</button>
230-
)}
252+
</div>
231253
</div>
232254
);
233255
}

src/style/components.styl

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
input.string
118118
box-sizing border-box
119119
padding-left 8px
120-
width 150px
120+
width 142px
121121

122122
input[type="text"]:focus,
123123
input.string:focus
@@ -131,6 +131,12 @@
131131
margin 0 0 0 5px
132132
width 68px
133133

134+
.commonComponents .propertyRow
135+
padding-right 45px
136+
137+
.text
138+
width 90px
139+
134140
.propertyRowDefined .text
135141
color var(--color-property-defined)
136142
font-weight 600
@@ -139,20 +145,26 @@
139145
font-style italic
140146
font-weight 600
141147

148+
.propertyRow .propertyRow-actions
149+
align-items baseline
150+
display flex
151+
gap 4px
152+
position absolute
153+
right 8px
154+
155+
.propertyRow .propertyRow-actions a.button
156+
font-size 13px
157+
line-height 1
158+
142159
.propertyRow .reset-button
143160
background none
144161
border none
145162
color var(--color-base-content)
146163
cursor pointer
147-
opacity 0.6
148164
padding 2px
149-
position absolute
150-
right 8px
151-
top 50%
152-
transform translateY(-50%)
153165

154166
&:hover
155-
opacity 1
167+
color var(--color-primary)
156168

157169
#addComponentContainer
158170
align-items center

0 commit comments

Comments
 (0)