@olenbetong/synergi-react 1.0.5 → 2.0.1
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.css +216 -146
- package/dist/esm/ob.react.js +227 -131
- package/dist/esm/ob.react.min.css +1 -1
- package/dist/esm/ob.react.min.css.map +3 -3
- package/dist/esm/ob.react.min.js +1 -1
- package/dist/esm/ob.react.min.js.map +4 -4
- package/dist/iife/ob.react.css +216 -146
- package/dist/iife/ob.react.js +230 -134
- package/dist/iife/ob.react.min.css +1 -1
- package/dist/iife/ob.react.min.css.map +3 -3
- package/dist/iife/ob.react.min.js +1 -1
- package/dist/iife/ob.react.min.js.map +4 -4
- package/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/Checkbox/index.css +1 -1
- package/es/Checkbox/index.d.ts +11 -0
- package/es/Checkbox/index.js +8 -5
- package/es/ColorCard/index.d.ts +5 -2
- package/es/ColorCard/index.js +6 -0
- package/es/DateNavigator/index.css +1 -1
- package/es/DateNavigator/index.d.ts +3 -1
- package/es/DateNavigator/index.js +82 -28
- package/es/LinkedCardList/index.css +1 -1
- package/es/LinkedCardList/index.d.ts +2 -2
- package/es/LinkedCardList/index.js +2 -2
- package/es/PageBanner/index.js +2 -1
- package/es/Portal/index.js +5 -7
- package/es/ProgressBar/index.css +1 -1
- package/es/Sidebar/index.js +1 -0
- package/es/Spinner/index.d.ts +1 -1
- package/es/SplitContainer/index.d.ts +4 -2
- package/es/SplitContainer/index.js +45 -13
- package/es/ValueToggleGroup/index.d.ts +18 -0
- package/es/ValueToggleGroup/index.js +12 -0
- package/es/index.css +1 -1
- package/es/index.d.ts +8 -8
- package/es/index.js +3 -3
- package/es/useTranslation/index.js +2 -1
- package/package.json +88 -90
- package/src/Checkbox/index.scss +12 -5
- package/src/Checkbox/index.tsx +25 -7
- package/src/ColorCard/{index.scss → index.css} +50 -59
- package/src/ColorCard/index.tsx +21 -9
- package/src/DateNavigator/index.scss +66 -33
- package/src/DateNavigator/index.tsx +98 -33
- package/src/LinkedCardList/index.scss +8 -1
- package/src/LinkedCardList/index.tsx +2 -2
- package/src/PageBanner/index.tsx +2 -1
- package/src/Portal/index.tsx +8 -7
- package/src/ProgressBar/index.scss +2 -2
- package/src/Sidebar/index.tsx +1 -0
- package/src/Spinner/{index.scss → index.css} +13 -10
- package/src/Spinner/index.tsx +2 -2
- package/src/SplitContainer/index.tsx +75 -17
- package/src/ValueToggleGroup/index.css +79 -0
- package/src/ValueToggleGroup/index.tsx +52 -0
- package/src/index.scss +3 -2
- package/src/index.ts +12 -12
- package/src/useTranslation/index.ts +2 -1
- package/LICENSE +0 -21
- package/es/ColorCard/index.css +0 -1
- package/es/Spinner/index.css +0 -1
- package/es/ValueToggle/index.css +0 -1
- package/es/ValueToggle/index.d.ts +0 -18
- package/es/ValueToggle/index.js +0 -38
- package/src/ValueToggle/index.scss +0 -50
- package/src/ValueToggle/index.tsx +0 -75
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
.ObValueToggleGroup {
|
|
2
|
+
padding: 0.25rem;
|
|
3
|
+
border: 2px solid rgb(0 0 0 / 0.2);
|
|
4
|
+
border-radius: 4px;
|
|
5
|
+
|
|
6
|
+
display: flex;
|
|
7
|
+
gap: 0.25rem;
|
|
8
|
+
flex-wrap: wrap;
|
|
9
|
+
|
|
10
|
+
&.vertical {
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
align-items: center;
|
|
13
|
+
|
|
14
|
+
& .ObValueToggleOption {
|
|
15
|
+
width: 100%;
|
|
16
|
+
|
|
17
|
+
& .ObValueToggleLabel {
|
|
18
|
+
width: 100%;
|
|
19
|
+
text-align: center;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&:focus-within {
|
|
25
|
+
border-color: rgb(0 0 0 / 0.8);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.ObValueToggleOption {
|
|
30
|
+
display: flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
margin: 0;
|
|
33
|
+
position: relative;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.ObValueToggleOption input {
|
|
37
|
+
position: absolute;
|
|
38
|
+
width: 1px;
|
|
39
|
+
height: 1px;
|
|
40
|
+
padding: 0;
|
|
41
|
+
margin: -1px;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
clip: rect(0, 0, 0, 0);
|
|
44
|
+
border: 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.ObValueToggleLabel {
|
|
48
|
+
font-size: 0.8em;
|
|
49
|
+
margin: 0 0.2em;
|
|
50
|
+
padding: 0.3em 0.5em;
|
|
51
|
+
text-transform: uppercase;
|
|
52
|
+
transition: background 0.2s ease, color 0.2s ease;
|
|
53
|
+
border-radius: 4px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.ObValueToggleOption:hover input:not(:disabled) + .ObValueToggleLabel {
|
|
57
|
+
cursor: pointer;
|
|
58
|
+
background: #ccc;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.ObValueToggleOption input:checked + .ObValueToggleLabel {
|
|
62
|
+
--color-bg: var(--brand-dark);
|
|
63
|
+
background-color: var(--color-bg);
|
|
64
|
+
color: white;
|
|
65
|
+
cursor: default;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.ObValueToggleOption input:disabled + .ObValueToggleLabel {
|
|
69
|
+
color: rgb(0 0 0 / 0.5);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.ObValueToggleOption input:checked:focus-visible + .ObValueToggleLabel {
|
|
73
|
+
--color-bg: var(--brand-light);
|
|
74
|
+
outline: 2px solid var(--brand-light);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.ObValueToggleOption input:checked:hover + .ObValueToggleLabel {
|
|
78
|
+
background-color: var(--color-bg);
|
|
79
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import "./index.css";
|
|
2
|
+
|
|
3
|
+
import { forwardRef, useId } from "react";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
|
|
6
|
+
export type ValueToggleOption = {
|
|
7
|
+
value: string | number;
|
|
8
|
+
label?: React.ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type ValueToggleGroupProps = {
|
|
13
|
+
options: ValueToggleOption[];
|
|
14
|
+
value?: string | number;
|
|
15
|
+
defaultValue?: string | number;
|
|
16
|
+
onChange?: (value: string | number) => void;
|
|
17
|
+
className?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
id?: string;
|
|
20
|
+
style?: React.CSSProperties;
|
|
21
|
+
orientation?: "horizontal" | "vertical";
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const ValueToggleGroup = forwardRef<HTMLFieldSetElement, ValueToggleGroupProps>(function ValueToggleGroup(
|
|
25
|
+
{ options, value, defaultValue, onChange, className, name, id, style, orientation = "horizontal" },
|
|
26
|
+
ref,
|
|
27
|
+
) {
|
|
28
|
+
let randomId = useId();
|
|
29
|
+
let groupName = name || `toggle-${id ?? randomId}`;
|
|
30
|
+
let isControlled = value !== undefined;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<fieldset className={clsx("ObValueToggleGroup", orientation, className)} role="radiogroup" ref={ref} style={style}>
|
|
34
|
+
{options.map((opt) => {
|
|
35
|
+
return (
|
|
36
|
+
<label key={opt.value} className={clsx("ObValueToggleOption", { disabled: opt.disabled })}>
|
|
37
|
+
<input
|
|
38
|
+
type="radio"
|
|
39
|
+
name={groupName}
|
|
40
|
+
value={opt.value}
|
|
41
|
+
checked={isControlled ? value === opt.value : undefined}
|
|
42
|
+
defaultChecked={!isControlled ? defaultValue === opt.value : undefined}
|
|
43
|
+
onChange={() => onChange?.(opt.value)}
|
|
44
|
+
disabled={opt.disabled}
|
|
45
|
+
/>
|
|
46
|
+
<span className="ObValueToggleLabel">{opt.label ?? opt.value}</span>
|
|
47
|
+
</label>
|
|
48
|
+
);
|
|
49
|
+
})}
|
|
50
|
+
</fieldset>
|
|
51
|
+
);
|
|
52
|
+
});
|
package/src/index.scss
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
@use "Checkbox/index.scss";
|
|
2
|
-
@use "ColorCard/index.
|
|
2
|
+
@use "ColorCard/index.css" as index2;
|
|
3
3
|
@use "DateNavigator/index.scss" as index3;
|
|
4
4
|
@use "LinkedCardList/index.scss" as index4;
|
|
5
5
|
@use "PageBanner/index.scss" as index5;
|
|
6
6
|
@use "ProgressBar/index.scss" as index6;
|
|
7
7
|
@use "Sidebar/index.scss" as index7;
|
|
8
|
+
@use "Spinner/index.css" as index1;
|
|
8
9
|
@use "SplitContainer/index.scss" as index8;
|
|
9
|
-
@use "
|
|
10
|
+
@use "ValueToggleGroup/index.css" as index9;
|
package/src/index.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export { Checkbox, CheckboxProps } from "./Checkbox/index.js";
|
|
2
|
-
export { ColorCard, CardColumn, CardDetail, CardLabel } from "./ColorCard/index.js";
|
|
1
|
+
export { Checkbox, type CheckboxProps } from "./Checkbox/index.js";
|
|
2
|
+
export { ColorCard, CardColumn, CardDetail, CardLabel, CardStep, CardStepList } from "./ColorCard/index.js";
|
|
3
3
|
export { DateNavigator } from "./DateNavigator/index.js";
|
|
4
|
-
export { Card,
|
|
4
|
+
export { Card, LinkedList, LinkedListItem } from "./LinkedCardList/index.js";
|
|
5
5
|
export {
|
|
6
6
|
BannerImage as PageBannerImage,
|
|
7
|
-
BannerImageProps,
|
|
7
|
+
type BannerImageProps,
|
|
8
8
|
PageBanner,
|
|
9
|
-
PageBannerProps,
|
|
9
|
+
type PageBannerProps,
|
|
10
10
|
Tab as PageBannerTab,
|
|
11
|
-
TabProps as PageBannerTabProps,
|
|
11
|
+
type TabProps as PageBannerTabProps,
|
|
12
12
|
TabList as PageBannerTabList,
|
|
13
|
-
TabListProps as PageBannerTabListProps,
|
|
13
|
+
type TabListProps as PageBannerTabListProps,
|
|
14
14
|
Title as PageBannerTitle,
|
|
15
|
-
TitleProps as PageBannerTitleProps,
|
|
15
|
+
type 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";
|
|
19
|
-
export { Sidebar, SidebarProps } from "./Sidebar/index.js";
|
|
20
|
-
export { Spinner, SpinnerProps } from "./Spinner/index.js";
|
|
21
|
-
export { SplitContainer, SplitContainerProps } from "./SplitContainer/index.js";
|
|
19
|
+
export { Sidebar, type SidebarProps } from "./Sidebar/index.js";
|
|
20
|
+
export { Spinner, type SpinnerProps } from "./Spinner/index.js";
|
|
21
|
+
export { SplitContainer, type SplitContainerProps } from "./SplitContainer/index.js";
|
|
22
22
|
|
|
23
23
|
export { useTranslation } from "./useTranslation/index.js";
|
|
24
|
-
export {
|
|
24
|
+
export { ValueToggleGroup, type ValueToggleGroupProps } from "./ValueToggleGroup/index.js";
|
|
@@ -16,7 +16,7 @@ async function translateText(text: string, target: string, apiKey: string) {
|
|
|
16
16
|
let json = await result.json();
|
|
17
17
|
let { data } = json;
|
|
18
18
|
|
|
19
|
-
if (data
|
|
19
|
+
if (data?.translations) {
|
|
20
20
|
let [translation] = data.translations;
|
|
21
21
|
|
|
22
22
|
return {
|
|
@@ -35,6 +35,7 @@ export function useTranslation(text: string, targetLanguage: string, apiKey: str
|
|
|
35
35
|
let [isTranslating, setIsTranslating] = useState(false);
|
|
36
36
|
let textRef = useRef(text);
|
|
37
37
|
|
|
38
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: this is a way of resetting the state so we don't show outdated translations when the text changes
|
|
38
39
|
useEffect(() => {
|
|
39
40
|
textRef.current = text;
|
|
40
41
|
return () => {
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) Ølen Betong
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/es/ColorCard/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.ObColorCard-root{--bg-color-border: black;--bg-color-main: white;--bg-size: 0.75rem;--card-color: rgb(0, 0, 0);align-items:stretch;background-image:linear-gradient(to right, hsl(186, 72%, 24%), hsl(186, 72%, 24%) 0.75rem, white 0.75rem, white);background-image:linear-gradient(to right, var(--bg-color-border), var(--bg-color-border) var(--bg-size), var(--bg-color-main) var(--bg-size), var(--bg-color-main));border-radius:.25rem;box-shadow:0 1px 12px rgba(0,0,0,.15),0 1px 6px rgba(0,0,0,.25);color:#666;cursor:pointer;display:flex;font-family:"Variable Bahnschrift","Bahnschrift","Open Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:1rem;min-height:10rem;overflow:hidden;transition:all ease-in-out 300ms}.ObColorCard-root:nth-of-type(5n + 1){--bg-color-border: rgb(178, 108, 190)}.ObColorCard-root:nth-of-type(5n + 2){--bg-color-border: rgb(79, 164, 61)}.ObColorCard-root:nth-of-type(5n + 3){--bg-color-border: rgb(246, 170, 23)}.ObColorCard-root:nth-of-type(5n + 4){--bg-color-border: rgb(218, 93, 83)}.ObColorCard-root:nth-of-type(5n + 5){--bg-color-border: rgb(23, 162, 184)}.ObColorCard-root:hover,.ObColorCard-root:focus{--bg-color-main: #f5f5f5;box-shadow:0 3px 18px rgba(0,0,0,.15),0 3px 12px rgba(0,0,0,.25);color:#666;text-decoration:none}@media screen and (min-width: 48rem){.ObColorCard-root{font-size:1.2rem}}.ObColorCard-column{display:flex;flex:1 1 100%;flex-direction:column;justify-content:space-between;margin:1rem 0;overflow:hidden;padding:.5rem 1.5rem .5rem 1rem;text-overflow:ellipsis}.ObColorCard-column:first-child{margin-left:.75rem;margin-left:var(--bg-size)}.ObColorCard-column.ObColorCard-minor{border-right:1px solid #e3e3e3;flex:0 0 4rem;transition:margin ease-in-out 300ms}@media screen and (min-width: 48rem){.ObColorCard-column.ObColorCard-minor{flex:0 0 8rem}}.ObColorCard-detailLabel{color:#ccc;font-size:.8rem;text-transform:uppercase}.ObColorCard-detail:not(:last-child){margin-right:1.5rem}.ObColorCard-detail.ObColorCard-primary,.ObColorCard-detail.ObColorCard-primary .ObColorCard-detailValue{font-size:1.25rem;font-weight:300}.ObColorCard-detail.ObColorCard-primary .ObColorCard-detailValue{color:unset}@media screen and (min-width: 48rem){.ObColorCard-detail{font-size:1rem}}.ObColorCard-detailValue{color:#999}.ObColorCard-label{position:relative;padding-left:1.5rem}.ObColorCard-label:not(:last-child){margin-bottom:1rem}.ObColorCard-label:not(:last-child)::after{content:"";position:absolute;width:.2rem;height:calc(100% + 1rem);border-left:.2rem dotted #666;left:.25rem;top:.5rem;z-index:0}.ObColorCard-label::before{background:#fff;border:.2rem solid hsl(186,72%,24%);border:.2rem solid var(--bg-color-border);border-radius:50%;content:"";display:block;height:.75rem;left:0;position:absolute;top:.3rem;width:.75rem;z-index:1}
|
package/es/Spinner/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.ObSpinner-root{display:inline-block}.ObSpinner-fullPage{display:flex;align-items:center;justify-content:center;height:100vh;width:100vw}.ObSpinner-spinner{display:inline-block;height:.75em;position:relative;width:2.5em}.ObSpinner-bullet{animation-timing-function:cubic-bezier(0, 1, 1, 0);background:#666;border-radius:50%;height:.5em;position:absolute;top:.2rem;width:.5em}.ObSpinner-bullet:nth-child(1){animation:scaleAnimation .6s infinite ease-in-out;left:.25em}.ObSpinner-bullet:nth-child(2){animation:translateAnimation .6s infinite ease-in-out;left:.25em}.ObSpinner-bullet:nth-child(3){animation:translateAnimation .6s infinite ease-in-out;left:1.2em}.ObSpinner-bullet:nth-child(4){animation:scaleAnimation .6s infinite ease-in-out reverse;left:2em}@keyframes scaleAnimation{from{transform:scale(0)}to{transform:scale(1)}}@keyframes translateAnimation{from{transform:translate(0, 0)}to{transform:translate(0.825em, 0)}}
|
package/es/ValueToggle/index.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.ObValueToggle-root{display:flex;align-items:center}.ObValueToggle-option{margin-bottom:0}.ObValueToggle-label{cursor:pointer;font-size:.8em;margin:0 .2em;padding:.3em .5em;text-transform:uppercase}.ObValueToggle-label:hover{background:#ccc}.ObValueToggle-input:checked+.ObValueToggle-label{--color-bg: var(--brand-dark);background-color:#666;background-color:var(--color-bg);cursor:default;color:#fff}.ObValueToggle-input:checked:focus-within+.ObValueToggle-label{--color-bg: var(--brand-light)}.ObValueToggle-input:checked:hover+.ObValueToggle-label{background-color:#666;background-color:var(--color-bg)}.ObValueToggle-input{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);border:0}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import "./index.css";
|
|
2
|
-
export type ValueToggleProps = {
|
|
3
|
-
className?: string;
|
|
4
|
-
onChange?: (value: string | number) => void;
|
|
5
|
-
value?: string | number;
|
|
6
|
-
defaultValue?: string | number;
|
|
7
|
-
id?: string;
|
|
8
|
-
options: Array<string | {
|
|
9
|
-
value: string | number;
|
|
10
|
-
label?: string;
|
|
11
|
-
}>;
|
|
12
|
-
style?: React.CSSProperties;
|
|
13
|
-
};
|
|
14
|
-
export declare const ValueToggle: import("react").ForwardRefExoticComponent<ValueToggleProps & import("react").RefAttributes<{
|
|
15
|
-
focus: () => void;
|
|
16
|
-
blur: () => void;
|
|
17
|
-
value: string | number;
|
|
18
|
-
}>>;
|
package/es/ValueToggle/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import "./index.css";
|
|
3
|
-
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
-
let valueToggleId = 0;
|
|
5
|
-
function ValueToggleInner({ className, onChange, defaultValue, options, value, ...other }, ref) {
|
|
6
|
-
const wrapperRef = useRef(null);
|
|
7
|
-
const [toggleName] = useState("obet-value-toggle-" + String(++valueToggleId));
|
|
8
|
-
const isControlled = value !== undefined;
|
|
9
|
-
useImperativeHandle(ref, () => {
|
|
10
|
-
const e = wrapperRef.current?.querySelector("input");
|
|
11
|
-
return {
|
|
12
|
-
focus: () => e?.focus(),
|
|
13
|
-
blur: () => e?.blur(),
|
|
14
|
-
value: (e?.querySelector("input:checked")).value,
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
return (_jsx("fieldset", { className: className, ...other, children: _jsx("div", { className: "ObValueToggle-root", ref: wrapperRef, children: options.map((option) => {
|
|
18
|
-
const isObj = typeof option === "object";
|
|
19
|
-
const optValue = isObj ? option.value : option;
|
|
20
|
-
const props = {
|
|
21
|
-
value: optValue,
|
|
22
|
-
};
|
|
23
|
-
if (isControlled) {
|
|
24
|
-
props.checked = value === optValue;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
props.defaultChecked = defaultValue === optValue;
|
|
28
|
-
}
|
|
29
|
-
if (typeof onChange === "function") {
|
|
30
|
-
props.onChange = () => onChange(optValue);
|
|
31
|
-
}
|
|
32
|
-
if (isObj) {
|
|
33
|
-
Object.assign(props, option);
|
|
34
|
-
}
|
|
35
|
-
return (_jsxs("label", { className: "ObValueToggle-option", children: [_jsx("input", { type: "radio", className: "ObValueToggle-input", name: toggleName, ...props }), _jsx("span", { className: "ObValueToggle-label", children: isObj ? option.label || optValue : optValue })] }, optValue));
|
|
36
|
-
}) }) }));
|
|
37
|
-
}
|
|
38
|
-
export const ValueToggle = forwardRef(ValueToggleInner);
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
@use "../styles/variables";
|
|
2
|
-
|
|
3
|
-
.ObValueToggle-root {
|
|
4
|
-
display: flex;
|
|
5
|
-
align-items: center;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.ObValueToggle-option {
|
|
9
|
-
margin-bottom: 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.ObValueToggle-label {
|
|
13
|
-
cursor: pointer;
|
|
14
|
-
font-size: 0.8em;
|
|
15
|
-
margin: 0 0.2em;
|
|
16
|
-
padding: 0.3em 0.5em;
|
|
17
|
-
text-transform: uppercase;
|
|
18
|
-
|
|
19
|
-
&:hover {
|
|
20
|
-
background: #ccc;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.ObValueToggle-input:checked + & {
|
|
24
|
-
--color-bg: var(--brand-dark);
|
|
25
|
-
background-color: #666;
|
|
26
|
-
background-color: var(--color-bg);
|
|
27
|
-
cursor: default;
|
|
28
|
-
color: white;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.ObValueToggle-input:checked:focus-within + & {
|
|
32
|
-
--color-bg: var(--brand-light);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.ObValueToggle-input:checked:hover + & {
|
|
36
|
-
background-color: #666;
|
|
37
|
-
background-color: var(--color-bg);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.ObValueToggle-input {
|
|
42
|
-
position: absolute;
|
|
43
|
-
width: 1px;
|
|
44
|
-
height: 1px;
|
|
45
|
-
padding: 0;
|
|
46
|
-
margin: -1px;
|
|
47
|
-
overflow: hidden;
|
|
48
|
-
clip: rect(0, 0, 0, 0);
|
|
49
|
-
border: 0;
|
|
50
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import "./index.scss";
|
|
2
|
-
|
|
3
|
-
import { forwardRef, useImperativeHandle, useRef, useState } from "react";
|
|
4
|
-
|
|
5
|
-
let valueToggleId = 0;
|
|
6
|
-
|
|
7
|
-
export type ValueToggleProps = {
|
|
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
|
-
};
|
|
16
|
-
|
|
17
|
-
function ValueToggleInner(
|
|
18
|
-
{ className, onChange, defaultValue, options, value, ...other }: ValueToggleProps,
|
|
19
|
-
ref: React.ForwardedRef<{
|
|
20
|
-
focus: () => void;
|
|
21
|
-
blur: () => void;
|
|
22
|
-
value: string | number;
|
|
23
|
-
}>,
|
|
24
|
-
) {
|
|
25
|
-
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
26
|
-
const [toggleName] = useState("obet-value-toggle-" + String(++valueToggleId));
|
|
27
|
-
const isControlled = value !== undefined;
|
|
28
|
-
|
|
29
|
-
useImperativeHandle(ref, () => {
|
|
30
|
-
const e = wrapperRef.current?.querySelector("input");
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
focus: () => e?.focus(),
|
|
34
|
-
blur: () => e?.blur(),
|
|
35
|
-
value: (e?.querySelector("input:checked") as HTMLInputElement).value,
|
|
36
|
-
};
|
|
37
|
-
});
|
|
38
|
-
|
|
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
|
-
|
|
49
|
-
if (isControlled) {
|
|
50
|
-
props.checked = value === optValue;
|
|
51
|
-
} else {
|
|
52
|
-
props.defaultChecked = defaultValue === optValue;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (typeof onChange === "function") {
|
|
56
|
-
props.onChange = () => onChange(optValue);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (isObj) {
|
|
60
|
-
Object.assign(props, option);
|
|
61
|
-
}
|
|
62
|
-
|
|
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
|
-
}
|
|
74
|
-
|
|
75
|
-
export const ValueToggle = forwardRef(ValueToggleInner);
|