siam-ui-utils 2.2.14 → 2.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -88,4 +88,7 @@ declare module 'siam-ui-utils' {
88
88
 
89
89
  //VIEW LAYOUT
90
90
  export function ViewLayout(props);
91
+
92
+ //TIMER
93
+ export function Timer(props);
91
94
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "siam-ui-utils",
3
- "version": "2.2.14",
3
+ "version": "2.2.16",
4
4
  "keywords": [
5
5
  "ampf-react",
6
6
  "ampf-utils",
package/src/App.jsx CHANGED
@@ -11,8 +11,9 @@ import './index.css';
11
11
  import './App.css';
12
12
  import './assets/css/vendor/bootstrap.min.css';
13
13
  import { WhereByRoom } from './where-by-room';
14
- import ViewLayout from './view-layout';
15
- import CopyLink from './copy-link';
14
+ import { ViewLayout } from './view-layout';
15
+ import { CopyLink } from './copy-link';
16
+ import Timer from './timer';
16
17
 
17
18
  const slots = [
18
19
  {
@@ -141,6 +142,12 @@ const App = () => {
141
142
  <ViewLayout slots={slots} />
142
143
  </AccordionBody>
143
144
  </AccordionItem>
145
+ <AccordionItem>
146
+ <AccordionHeader targetId="8">Timer</AccordionHeader>
147
+ <AccordionBody accordionId="8">
148
+ <Timer initialMinutes={2} active={true} />
149
+ </AccordionBody>
150
+ </AccordionItem>
144
151
  </Accordion>
145
152
  </div>
146
153
  );
package/src/index.js CHANGED
@@ -9,3 +9,4 @@ export * as IntlMessages from './IntlMessages';
9
9
  export * from './where-by-room';
10
10
  export * from './copy-link';
11
11
  export * from './view-layout';
12
+ export * from './timer';
@@ -0,0 +1,59 @@
1
+ import { useEffect, useState, useRef } from 'react';
2
+ import './styles.scss';
3
+
4
+ export const formatTiempo = (ms) => {
5
+ if (ms == null) return '--:--';
6
+ const absMs = Math.abs(ms);
7
+ const totalSec = Math.floor(absMs / 1000);
8
+ const min = Math.floor(totalSec / 60);
9
+ const sec = totalSec % 60;
10
+ const formatted = `${min.toString().padStart(2, '0')}:${sec
11
+ .toString()
12
+ .padStart(2, '0')}`;
13
+ return ms < 0 ? `-${formatted}` : formatted;
14
+ };
15
+
16
+ const getTimerColorClass = (ms, maxTime) => {
17
+ if (!maxTime) return '';
18
+ const percent = ms / maxTime;
19
+ if (percent > 0.33) return 'timer-green';
20
+ if (percent > 0.15) return 'timer-yellow';
21
+ if (percent > 0) return 'timer-red';
22
+ if (ms === 0) return 'timer-out';
23
+ if (ms < 0) return 'timer-over';
24
+ return '';
25
+ };
26
+
27
+ const Timer = ({
28
+ initialMinutes = 0,
29
+ icon = true,
30
+ className = '',
31
+ active = true,
32
+ }) => {
33
+ const initialMs = initialMinutes * 60 * 1000;
34
+ const [ms, setMs] = useState(initialMs);
35
+ const intervalRef = useRef();
36
+
37
+ useEffect(() => {
38
+ if (!active) return;
39
+ intervalRef.current = setInterval(() => {
40
+ setMs((prev) => prev - 1000);
41
+ }, 1000);
42
+ return () => clearInterval(intervalRef.current);
43
+ }, [active]);
44
+
45
+ useEffect(() => {
46
+ setMs(initialMs);
47
+ }, [initialMs]);
48
+
49
+ const timerColorClass = getTimerColorClass(ms, initialMs);
50
+
51
+ return (
52
+ <span className={`av-video-timer timer ${timerColorClass} ${className}`}>
53
+ {icon && <i className="icon-clock timer" />}
54
+ {formatTiempo(ms)}
55
+ </span>
56
+ );
57
+ };
58
+
59
+ export default Timer;
@@ -0,0 +1,54 @@
1
+ .av-video-timer {
2
+ color: inherit;
3
+ margin: 0 12px;
4
+ flex: 1;
5
+ text-align: center;
6
+ display: flex;
7
+ justify-content: center;
8
+ font-weight: bold;
9
+ align-items: center;
10
+ font-size: 1.3em;
11
+ width: 100%;
12
+ margin: 8px 0;
13
+ }
14
+ .timer {
15
+ font-size: clamp(5px, 2vw, 20px);
16
+ margin-right: 4px;
17
+ }
18
+ .timer-green {
19
+ color: #28a745;
20
+ }
21
+ .timer-yellow {
22
+ color: #ffc107;
23
+ }
24
+ .timer-red {
25
+ color: #bd0300;
26
+ }
27
+
28
+ @keyframes vibrate {
29
+ 0% {
30
+ transform: translateX(0);
31
+ }
32
+ 20% {
33
+ transform: translateX(-3px);
34
+ }
35
+ 40% {
36
+ transform: translateX(3px);
37
+ }
38
+ 60% {
39
+ transform: translateX(-3px);
40
+ }
41
+ 80% {
42
+ transform: translateX(3px);
43
+ }
44
+ 100% {
45
+ transform: translateX(0);
46
+ }
47
+ }
48
+ .timer-out {
49
+ color: #000000;
50
+ animation: vibrate 0.3s linear infinite;
51
+ }
52
+ .timer-over {
53
+ color: #c00805;
54
+ }
@@ -4,4 +4,4 @@ export const GRID_SIZES = {
4
4
  lg: { cols: 6, rows: 6 },
5
5
  };
6
6
 
7
- export const VERSION = import.meta?.env?.REACT_APP_VERSION || 'TLBD';
7
+ export const LOCALHOST = ['localhost', '127.0.0.1'];
@@ -2,7 +2,7 @@ import React, { FC, useState } from 'react';
2
2
  import SlotWrapper from './slot-wrapper';
3
3
  import { ItemSlot } from './item-slot';
4
4
  import EditorLayer from './editor-layer.jsx';
5
- import { GRID_SIZES, VERSION } from './constants';
5
+ import { GRID_SIZES, LOCALHOST } from './constants';
6
6
  import ButtonEditor from './button-editor.jsx';
7
7
  import './styles.scss';
8
8
 
@@ -19,15 +19,18 @@ const ViewLayout: FC<LayoutProps> = ({
19
19
  size = 'md',
20
20
  alto = 80,
21
21
  ancho = 90,
22
+ server = window?.location?.hostname,
22
23
  ...props
23
24
  }) => {
24
- const isVersionLetters = /^[A-Za-z]+$/.test(VERSION);
25
+
26
+ const isLocalhost=LOCALHOST.includes(server);
27
+
25
28
  const [isEditorActivo, setEditorActivo] = useState(false);
26
29
  const gridCols = GRID_SIZES[size].cols;
27
30
  const gridRows = GRID_SIZES[size].rows;
28
31
  return (
29
32
  <div className="visualizador-container">
30
- {isVersionLetters && (
33
+ {isLocalhost && (
31
34
  <ButtonEditor
32
35
  activo={isEditorActivo}
33
36
  onClick={() => setEditorActivo((prev) => !prev)}