siam-ui-utils 2.2.15 → 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/eslint.config.mjs +45 -45
- package/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/App.jsx +7 -0
- package/src/index.js +1 -0
- package/src/timer/index.jsx +59 -0
- package/src/timer/styles.scss +54 -0
package/eslint.config.mjs
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import js from '@eslint/js';
|
|
2
|
-
import globals from 'globals';
|
|
3
|
-
import pluginReact from 'eslint-plugin-react';
|
|
4
|
-
import pluginReactHooks from 'eslint-plugin-react-hooks';
|
|
5
|
-
import pluginReactRefresh from 'eslint-plugin-react-refresh';
|
|
6
|
-
import { defineConfig } from 'eslint/config';
|
|
7
|
-
|
|
8
|
-
export default defineConfig([
|
|
9
|
-
{ ignores: ['build', '**/*.d.ts'] },
|
|
10
|
-
{
|
|
11
|
-
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
12
|
-
languageOptions: {
|
|
13
|
-
ecmaVersion: 'latest',
|
|
14
|
-
sourceType: 'module',
|
|
15
|
-
globals: globals.browser,
|
|
16
|
-
parserOptions: {
|
|
17
|
-
ecmaFeatures: { jsx: true },
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
parser: '@typescript-eslint/parser',
|
|
21
|
-
parserOptions: {
|
|
22
|
-
ecmaVersion: 'latest',
|
|
23
|
-
},
|
|
24
|
-
plugins: {
|
|
25
|
-
react: pluginReact,
|
|
26
|
-
'react-hooks': pluginReactHooks,
|
|
27
|
-
'react-refresh': pluginReactRefresh,
|
|
28
|
-
},
|
|
29
|
-
rules: {
|
|
30
|
-
...js.configs.recommended.rules,
|
|
31
|
-
...pluginReact.configs.recommended.rules,
|
|
32
|
-
...pluginReact.configs['jsx-runtime'].rules,
|
|
33
|
-
...pluginReactHooks.configs.recommended.rules,
|
|
34
|
-
'react/jsx-no-target-blank': 'off',
|
|
35
|
-
'react-refresh/only-export-components': [
|
|
36
|
-
'off',
|
|
37
|
-
{ allowConstantExport: true },
|
|
38
|
-
],
|
|
39
|
-
'react/prop-types': 'off',
|
|
40
|
-
'@/no-default-export': 'off',
|
|
41
|
-
'no-unused-vars': 'warn',
|
|
42
|
-
},
|
|
43
|
-
settings: { react: { version: 'detect' } },
|
|
44
|
-
},
|
|
45
|
-
]);
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
import pluginReact from 'eslint-plugin-react';
|
|
4
|
+
import pluginReactHooks from 'eslint-plugin-react-hooks';
|
|
5
|
+
import pluginReactRefresh from 'eslint-plugin-react-refresh';
|
|
6
|
+
import { defineConfig } from 'eslint/config';
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
{ ignores: ['build', '**/*.d.ts'] },
|
|
10
|
+
{
|
|
11
|
+
files: ['**/*.{js,jsx,ts,tsx}'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
ecmaVersion: 'latest',
|
|
14
|
+
sourceType: 'module',
|
|
15
|
+
globals: globals.browser,
|
|
16
|
+
parserOptions: {
|
|
17
|
+
ecmaFeatures: { jsx: true },
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
parser: '@typescript-eslint/parser',
|
|
21
|
+
parserOptions: {
|
|
22
|
+
ecmaVersion: 'latest',
|
|
23
|
+
},
|
|
24
|
+
plugins: {
|
|
25
|
+
react: pluginReact,
|
|
26
|
+
'react-hooks': pluginReactHooks,
|
|
27
|
+
'react-refresh': pluginReactRefresh,
|
|
28
|
+
},
|
|
29
|
+
rules: {
|
|
30
|
+
...js.configs.recommended.rules,
|
|
31
|
+
...pluginReact.configs.recommended.rules,
|
|
32
|
+
...pluginReact.configs['jsx-runtime'].rules,
|
|
33
|
+
...pluginReactHooks.configs.recommended.rules,
|
|
34
|
+
'react/jsx-no-target-blank': 'off',
|
|
35
|
+
'react-refresh/only-export-components': [
|
|
36
|
+
'off',
|
|
37
|
+
{ allowConstantExport: true },
|
|
38
|
+
],
|
|
39
|
+
'react/prop-types': 'off',
|
|
40
|
+
'@/no-default-export': 'off',
|
|
41
|
+
'no-unused-vars': 'warn',
|
|
42
|
+
},
|
|
43
|
+
settings: { react: { version: 'detect' } },
|
|
44
|
+
},
|
|
45
|
+
]);
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
package/src/App.jsx
CHANGED
|
@@ -13,6 +13,7 @@ import './assets/css/vendor/bootstrap.min.css';
|
|
|
13
13
|
import { WhereByRoom } from './where-by-room';
|
|
14
14
|
import { ViewLayout } from './view-layout';
|
|
15
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
|
@@ -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
|
+
}
|