@olenbetong/synergi-react 0.6.46 → 0.7.0
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/dist/esm/ob.react.js +1 -17
- package/dist/esm/ob.react.min.css.map +1 -1
- package/dist/esm/ob.react.min.js +1 -1
- package/dist/esm/ob.react.min.js.map +4 -4
- package/dist/iife/ob.react.js +1 -14
- package/dist/iife/ob.react.min.css.map +1 -1
- package/dist/iife/ob.react.min.js +1 -1
- package/dist/iife/ob.react.min.js.map +4 -4
- package/dist/styles/styles.css.map +1 -1
- package/es/DateNavigator/index.js +2 -2
- package/es/Portal/index.js +1 -1
- package/es/index.d.ts +0 -1
- package/es/index.js +0 -1
- package/package.json +3 -4
- package/src/Checkbox/index.scss +78 -78
- package/src/Checkbox/index.tsx +62 -62
- package/src/ColorCard/index.scss +135 -135
- package/src/ColorCard/index.tsx +38 -38
- package/src/DateNavigator/index.scss +33 -33
- package/src/DateNavigator/index.tsx +66 -66
- package/src/LinkedCardList/index.scss +49 -49
- package/src/LinkedCardList/index.tsx +24 -24
- package/src/PageBanner/index.scss +71 -71
- package/src/PageBanner/index.tsx +41 -41
- package/src/Portal/index.tsx +24 -24
- package/src/ProgressBar/index.scss +76 -76
- package/src/ProgressBar/index.tsx +3 -3
- package/src/Sidebar/index.scss +41 -41
- package/src/Sidebar/index.tsx +107 -107
- package/src/Spinner/index.scss +45 -45
- package/src/Spinner/index.tsx +11 -11
- package/src/SplitContainer/index.scss +23 -23
- package/src/SplitContainer/index.tsx +222 -222
- package/src/ValueToggle/index.scss +37 -37
- package/src/ValueToggle/index.tsx +54 -54
- package/src/global.d.ts +1 -1
- package/src/index.ts +10 -11
- package/src/styles/_mixins.scss +16 -16
- package/src/useTranslation/index.ts +58 -58
|
@@ -5,71 +5,71 @@ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
|
5
5
|
let valueToggleId = 0;
|
|
6
6
|
|
|
7
7
|
export type ValueToggleProps = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
className?: string;
|
|
9
|
+
onChange?: (value: string | number) => void;
|
|
10
|
+
value?: string | number;
|
|
11
|
+
defaultValue?: string | number;
|
|
12
|
+
id?: string;
|
|
13
|
+
options: Array<string | { value: string | number; label?: string }>;
|
|
14
|
+
style?: React.CSSProperties;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
function ValueToggleInner(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
{ className, onChange, defaultValue, options, value, ...other }: ValueToggleProps,
|
|
19
|
+
ref: React.ForwardedRef<{
|
|
20
|
+
focus: () => void;
|
|
21
|
+
blur: () => void;
|
|
22
|
+
value: string | number;
|
|
23
|
+
}>
|
|
24
24
|
) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
26
|
+
const [toggleName] = useState("obet-value-toggle-" + String(++valueToggleId));
|
|
27
|
+
const isControlled = value !== undefined;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
useImperativeHandle(ref, () => {
|
|
30
|
+
const e = wrapperRef.current?.querySelector("input");
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
return {
|
|
33
|
+
focus: () => e?.focus(),
|
|
34
|
+
blur: () => e?.blur(),
|
|
35
|
+
value: (e?.querySelector("input:checked") as HTMLInputElement).value,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
return (
|
|
40
|
+
<fieldset className={className} {...other}>
|
|
41
|
+
<div className="ObValueToggle-root" ref={wrapperRef}>
|
|
42
|
+
{options.map((option) => {
|
|
43
|
+
const isObj = typeof option === "object";
|
|
44
|
+
const optValue = isObj ? option.value : option;
|
|
45
|
+
const props: React.HTMLProps<HTMLInputElement> = {
|
|
46
|
+
value: optValue,
|
|
47
|
+
};
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
if (isControlled) {
|
|
50
|
+
props.checked = value === optValue;
|
|
51
|
+
} else {
|
|
52
|
+
props.defaultChecked = defaultValue === optValue;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
if (typeof onChange === "function") {
|
|
56
|
+
props.onChange = () => onChange(optValue);
|
|
57
|
+
}
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
if (isObj) {
|
|
60
|
+
Object.assign(props, option);
|
|
61
|
+
}
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
return (
|
|
64
|
+
<label key={optValue} className="ObValueToggle-option">
|
|
65
|
+
<input type="radio" className="ObValueToggle-input" name={toggleName} {...props} />
|
|
66
|
+
<span className="ObValueToggle-label">{isObj ? option.label || optValue : optValue}</span>
|
|
67
|
+
</label>
|
|
68
|
+
);
|
|
69
|
+
})}
|
|
70
|
+
</div>
|
|
71
|
+
</fieldset>
|
|
72
|
+
);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
export const ValueToggle = forwardRef(ValueToggleInner);
|
package/src/global.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/// <reference path="@olenbetong/appframe-core" />
|
|
2
|
-
/// <reference path="@olenbetong/appframe-data" />
|
|
2
|
+
/// <reference path="@olenbetong/appframe-data" />
|
package/src/index.ts
CHANGED
|
@@ -3,16 +3,16 @@ export { ColorCard, CardColumn, CardDetail, CardLabel } from "./ColorCard/index.
|
|
|
3
3
|
export { DateNavigator } from "./DateNavigator/index.js";
|
|
4
4
|
export { Card, List as LinkedList, ListItem as LinkedListItem } from "./LinkedCardList/index.js";
|
|
5
5
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
BannerImage as PageBannerImage,
|
|
7
|
+
BannerImageProps,
|
|
8
|
+
PageBanner,
|
|
9
|
+
PageBannerProps,
|
|
10
|
+
Tab as PageBannerTab,
|
|
11
|
+
TabProps as PageBannerTabProps,
|
|
12
|
+
TabList as PageBannerTabList,
|
|
13
|
+
TabListProps as PageBannerTabListProps,
|
|
14
|
+
Title as PageBannerTitle,
|
|
15
|
+
TitleProps as PageBannerTitleProps,
|
|
16
16
|
} from "./PageBanner/index.js";
|
|
17
17
|
export { Portal } from "./Portal/index.js";
|
|
18
18
|
export { ProgressBar } from "./ProgressBar/index.js";
|
|
@@ -22,4 +22,3 @@ export { SplitContainer, SplitContainerProps } from "./SplitContainer/index.js";
|
|
|
22
22
|
|
|
23
23
|
export { useTranslation } from "./useTranslation/index.js";
|
|
24
24
|
export { ValueToggle, ValueToggleProps } from "./ValueToggle/index.js";
|
|
25
|
-
export { useDebounce, usePersistedSetting, useSearchParamState } from "@olenbetong/appframe-react";
|
package/src/styles/_mixins.scss
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
@mixin btn-reset {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
background: none;
|
|
3
|
+
border: 0;
|
|
4
|
+
color: inherit;
|
|
5
|
+
/* cursor: default; */
|
|
6
|
+
font: inherit;
|
|
7
|
+
line-height: normal;
|
|
8
|
+
overflow: visible;
|
|
9
|
+
padding: 0;
|
|
10
|
+
-webkit-appearance: button; /* for input */
|
|
11
|
+
-webkit-user-select: none; /* for button */
|
|
12
|
+
-moz-user-select: none;
|
|
13
|
+
-ms-user-select: none;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
&::-moz-focus-inner {
|
|
16
|
+
border: 0;
|
|
17
|
+
padding: 0;
|
|
18
|
+
}
|
|
19
19
|
}
|
|
@@ -1,74 +1,74 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
|
2
2
|
|
|
3
3
|
async function translateText(text: string, target: string, apiKey: string) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
let url = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;
|
|
5
|
+
let body = JSON.stringify({
|
|
6
|
+
q: text,
|
|
7
|
+
target,
|
|
8
|
+
});
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
let options = {
|
|
11
|
+
body,
|
|
12
|
+
method: "POST",
|
|
13
|
+
};
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let result = await fetch(url, options);
|
|
16
|
+
let json = await result.json();
|
|
17
|
+
let { data } = json;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (data && data.translations) {
|
|
20
|
+
let [translation] = data.translations;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
return {
|
|
23
|
+
from: translation.detectedSourceLanguage,
|
|
24
|
+
translation: translation.translatedText,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
return false;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export function useTranslation(text: string, targetLanguage: string, apiKey: string) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
let [translation, setTranslation] = useState("");
|
|
33
|
+
let [error, setError] = useState<string | null>(null);
|
|
34
|
+
let [from, setSourceLang] = useState<string | null>(null);
|
|
35
|
+
let [isTranslating, setIsTranslating] = useState(false);
|
|
36
|
+
let textRef = useRef(text);
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
textRef.current = text;
|
|
40
|
+
return () => {
|
|
41
|
+
setTranslation("");
|
|
42
|
+
setError(null);
|
|
43
|
+
setSourceLang(null);
|
|
44
|
+
setIsTranslating(false);
|
|
45
|
+
};
|
|
46
|
+
}, [apiKey, targetLanguage, text]);
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
async function translate() {
|
|
49
|
+
setIsTranslating(true);
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
try {
|
|
52
|
+
let result = await translateText(text, targetLanguage, apiKey);
|
|
53
|
+
if (result && textRef.current === text) {
|
|
54
|
+
let { from, translation } = result;
|
|
55
|
+
setSourceLang(from);
|
|
56
|
+
setTranslation(translation);
|
|
57
|
+
setIsTranslating(false);
|
|
58
|
+
}
|
|
59
|
+
} catch (error) {
|
|
60
|
+
if (textRef.current === text) {
|
|
61
|
+
setError((error as Error).message);
|
|
62
|
+
setIsTranslating(false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
return {
|
|
68
|
+
error,
|
|
69
|
+
from,
|
|
70
|
+
isTranslating,
|
|
71
|
+
translation,
|
|
72
|
+
translate,
|
|
73
|
+
};
|
|
74
74
|
}
|