1.1.1 • Published 5 months ago

segmentslibrary v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

Documentación del Componente Segments

Link del repositorio Link de la libreria

Licencia

MIT License

Copyright (c) 2025

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Descripción

El componente Segments permite mostrar un display de segmentos al estilo de relojes digitales o pantallas de calculadoras. Es altamente configurable y admite distintos tamaños, colores y estilos de segmentos.

Instalación

Para usar este componente en tu proyecto, primero instala la librería:

npm install segmentslibrary

Luego, impórtalo en tu código:

import Segments from "segmentslibrary";

Props del Componente

PropiedadTipoDescripción
idStringIdentificador único del display (por defecto "1").
patternStringPatrón del display (ej. "#####", "##:##:##").
textopredefinidoStringTexto inicial que se mostrará en el display.
widthNumberAncho del canvas (px).
heightNumberAlto del canvas (px).
colorOnStringColor de los segmentos activos.
colorOffStringColor de los segmentos inactivos.
cantidadSegmentosNumberCantidad de segmentos (7, 14 o 16).
altoDisplayNumberAltura de los dígitos.
anchoDisplayNumberAncho de los dígitos.
distanciaEntreDigitosNumberEspacio entre los dígitos.
anchoSegmentoNumberAncho de los segmentos.
distanciaSegmentoNumberDistancia entre los segmentos.
tipoBordeNumberTipo de borde (0, 1, 2 o 3).
anguloDisplayNumberÁngulo de inclinación del display.

Ejemplo: Crear un Reloj Digital

Para mostrar un reloj en tiempo real con este componente:

import React, { useState, useEffect } from 'react';
import Segments from 'segmentslibrary';  // Ajusta la ruta según tu estructura de archivos

const DigitalClock = () => {
  const [time, setTime] = useState('');

  useEffect(() => {
    const formatTime = (date) => {
      const hours = date.getHours().toString().padStart(2, '0');
      const minutes = date.getMinutes().toString().padStart(2, '0');
      const seconds = date.getSeconds().toString().padStart(2, '0');
      return `${hours}:${minutes}:${seconds}`;
    };

    setTime(formatTime(new Date()));

    const intervalId = setInterval(() => {
      setTime(formatTime(new Date()));
    }, 1000);

    return () => clearInterval(intervalId);
  }, []);

  return (
    <div className="digital-clock">
      <Segments
        id="reloj"
        textopredefinido={time}
        pattern="##:##:##"
        width={400}
        height={200}
        colorOn="#ff5555"
        colorOff="#33333330"
        altoDisplay={30}
        anchoDisplay={18}
        distanciaEntreDigitos={3}
        anchoSegmento={3.5}
        cantidadSegmentos={7}
        anguloDisplay={7}
      />
    </div>
  );
};

export default DigitalClock;

Ejemplo: Animación de Palabra Letra por Letra

Para animar una palabra letra por letra con parpadeo:

import React, { useState, useEffect } from 'react'; 
import Segments from 'segmentslibrary';  // Ajusta la ruta según tu estructura de archivos

const AnimatedSegments = ({
  text = "TUTEC",
  animationSpeed = 500,
  blinkCount = 2,
  id = "animated"
}) => {
  const [displayText, setDisplayText] = useState('');
  const [index, setIndex] = useState(0);
  const [blinkPhase, setBlinkPhase] = useState(0);

  useEffect(() => {
    const animate = () => {
      if (index <= text.length) {
        setDisplayText(text.substring(0, index));
        setIndex(prev => prev + 1);
      } else if (blinkPhase < blinkCount * 2) {
        if (blinkPhase % 2 === 0) {
          setDisplayText('     ');
        } else {
          setDisplayText(text);
        }
        setBlinkPhase(prev => prev + 1);
      } else {
        setIndex(0);
        setBlinkPhase(0);
      }
    };

    const intervalId = setInterval(animate, animationSpeed);
    return () => clearInterval(intervalId);
  }, [text, animationSpeed, blinkCount, index, blinkPhase]);

  return (
    <Segments
      id={id}
      textopredefinido={displayText}
      pattern="#####"
      width={300}
      height={180}
      colorOn="#4d91cd"
      colorOff="#53595e45"
      cantidadSegmentos={14}
      altoDisplay={23.5}
      anchoDisplay={14.5}
      distanciaEntreDigitos={2.5}
      anchoSegmento={3}
      distanciaSegmento={0.3}
      tipoBorde={3}
      anguloDisplay={6}
    />
  );
};

export default AnimatedSegments;

Ejemplo de Manejo de Errores

Si se proporciona un valor incorrecto en cantidadSegmentos, el componente lo corregirá automáticamente a 7, 14 o 16.

<Segments cantidadSegmentos={10} />  // Se corregirá a 7

Este componente es ideal para paneles de control, relojes digitales, y más. 🚀

1.1.1

5 months ago

1.1.0

5 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.0

5 months ago