Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a badge component to be placed under Rich Components #213

Open
brauliodiez opened this issue Aug 18, 2024 · 0 comments · May be fixed by #374
Open

Create a badge component to be placed under Rich Components #213

brauliodiez opened this issue Aug 18, 2024 · 0 comments · May be fixed by #374
Assignees

Comments

@brauliodiez
Copy link
Member

image

Svg example

<svg width="150" height="50" xmlns="http://www.w3.org/2000/svg">
  <!-- Fondo del chip/badge -->
  <rect x="10" y="10" width="130" height="30" rx="15" ry="15" style="fill:lightgray;stroke:gray;stroke-width:2"/>

  <!-- Texto del chip/badge -->
  <text x="30" y="30" font-family="Arial" font-size="16" fill="black">Badge Label</text>
</svg>

React Konva (just take this as a starting point):

import React, { forwardRef } from 'react';
import { Group, Rect, Text } from 'react-konva';
import { ShapeConfig } from 'konva/lib/Shape';

interface ChipProps extends ShapeConfig {
  id: string;
  x: number;
  y: number;
  width: number;
  height: number;
  label: string;
  fillColor?: string;
  textColor?: string;
}

export const Chip = forwardRef<any, ChipProps>(
  ({ x, y, width, height, label, fillColor = 'lightgray', textColor = 'black', id, ...shapeProps }, ref) => {
    const padding = 10;

    return (
      <Group x={x} y={y} ref={ref} {...shapeProps}>
        {/* Fondo del chip/badge */}
        <Rect
          x={0}
          y={0}
          width={width}
          height={height}
          fill={fillColor}
          stroke="gray"
          strokeWidth={2}
          cornerRadius={height / 2}  // Para hacer las esquinas redondeadas
        />

        {/* Texto del chip/badge */}
        <Text
          x={padding}
          y={height / 2 - 8}  // Centrar verticalmente
          text={label}
          fontFamily="Arial"
          fontSize={16}
          fill={textColor}
        />
      </Group>
    );
  }
);

export default Chip;
@brauliodiez brauliodiez moved this to Backlog in QuickMock Aug 18, 2024
IonutGabi pushed a commit that referenced this issue Sep 16, 2024
IonutGabi pushed a commit that referenced this issue Sep 16, 2024
IonutGabi pushed a commit that referenced this issue Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging a pull request may close this issue.

2 participants