-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/#110-copy-paste-shape
- Loading branch information
Showing
29 changed files
with
504 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
74 changes: 74 additions & 0 deletions
74
src/common/components/front-components/radiobutton-shape.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,74 @@ | ||
import { ShapeSizeRestrictions } from '@/core/model'; | ||
import { forwardRef, useState } from 'react'; | ||
import { Group, Circle, Text } from 'react-konva'; | ||
import { ShapeProps } from './shape.model'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions'; | ||
|
||
const radioButtonShapeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 50, | ||
minHeight: 30, | ||
maxWidth: 200, | ||
maxHeight: 50, | ||
defaultWidth: 120, | ||
defaultHeight: 50, | ||
}; | ||
|
||
export const RadioButtonShape = forwardRef<any, ShapeProps>( | ||
({ x, y, width, height, id, onSelected, ...shapeProps }, ref) => { | ||
const { width: restrictedWidth, height: restrictedHeight } = | ||
fitSizeToShapeSizeRestrictions( | ||
radioButtonShapeRestrictions, | ||
width, | ||
height | ||
); | ||
|
||
const [isOn, setIsOn] = useState(false); | ||
|
||
const handleSwitch = () => { | ||
setIsOn(!isOn); | ||
}; | ||
|
||
const radius = restrictedHeight / 2; | ||
|
||
return ( | ||
<Group | ||
x={x} | ||
y={y} | ||
ref={ref} | ||
width={restrictedWidth} | ||
height={restrictedHeight} | ||
{...shapeProps} | ||
onClick={() => onSelected(id, 'radiobutton')} | ||
> | ||
{/* Círculo exterior del radio button */} | ||
<Circle | ||
x={radius} | ||
y={radius} | ||
radius={radius} | ||
stroke="black" | ||
strokeWidth={2} | ||
/> | ||
|
||
{/* Círculo interior del radio button (checked) */} | ||
<Circle | ||
onClick={handleSwitch} | ||
x={radius} | ||
y={radius} | ||
radius={radius * 0.5} | ||
fill={isOn ? 'black' : 'white'} | ||
/> | ||
|
||
{/* Texto */} | ||
<Text | ||
x={radius * 2 + 10} | ||
y={radius * 0.5 + 5} | ||
text="Select me!" | ||
fontFamily="Comic Sans MS, cursive" | ||
fontSize={20} | ||
fill="none" | ||
verticalAllign="middle" | ||
/> | ||
</Group> | ||
); | ||
} | ||
); |
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
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
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
Oops, something went wrong.