Skip to content

Commit

Permalink
Merge pull request #52 from oslabs-beta/corsodr-patch-1
Browse files Browse the repository at this point in the history
format button.tsx code
  • Loading branch information
alecjessen authored Jul 16, 2024
2 parents 11bc4fb + ff0c72e commit c35f848
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { ReactElement, useState, useRef } from 'react'
import { RoundedBox, Text } from "@react-three/drei"
import { useSpring, animated, config } from '@react-spring/three'
import React from 'react';

type ButtonProps = {
scale?: number;
color?: string;
Expand All @@ -16,9 +16,7 @@ type ButtonProps = {
}

export default function Button(props: ButtonProps): ReactElement {

const buttonRef = useRef() as any;

const [hover, setHover] = useState(false);

const position = props.position || [0,0,0];
Expand Down Expand Up @@ -46,33 +44,32 @@ export default function Button(props: ButtonProps): ReactElement {
buttonRef.current.position.z = position[2];
}


return <>
<group ref={buttonRef} >
<ambientLight intensity={1}/>
<animated.group
scale={scale}
onPointerDown={() => setHover(true)}
onPointerUp={() => setHover(false)}
onClick={handleClick}
rotation-y={rotationY}
rotation-x={rotationX}
>
<mesh >
<RoundedBox args={[buttonWidth, buttonHeight, .5]} radius={.2}>
<meshStandardMaterial color={hover ? activeColor : color}/>
</RoundedBox>
</mesh>
<Text
font={font}
fontSize={fontSize}
color={fontColor}
position-z={.3}
return (
<group ref={buttonRef} >
<ambientLight intensity={1}/>
<animated.group
scale={scale}
onPointerDown={() => setHover(true)}
onPointerUp={() => setHover(false)}
onClick={handleClick}
rotation-y={rotationY}
rotation-x={rotationX}
>
<meshBasicMaterial toneMapped={false}/>
{text}
</Text>
</animated.group>
<mesh >
<RoundedBox args={[buttonWidth, buttonHeight, .5]} radius={.2}>
<meshStandardMaterial color={hover ? activeColor : color}/>
</RoundedBox>
</mesh>
<Text
font={font}
fontSize={fontSize}
color={fontColor}
position-z={.3}
>
<meshBasicMaterial toneMapped={false}/>
{text}
</Text>
</animated.group>
</group>
</>
}
)
}

0 comments on commit c35f848

Please sign in to comment.