@douglasneuroinformatics/libui 6.1.1 → 6.1.3
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/components/Form/BaseRadioField.d.ts +1 -2
- package/dist/components/Form/BaseRadioField.d.ts.map +1 -1
- package/dist/components/Form/BaseRadioField.js +2 -15
- package/dist/components/Form/BaseRadioField.js.map +1 -1
- package/dist/components/Form/NumberField/NumberFieldRadio.d.ts.map +1 -1
- package/dist/components/Form/NumberField/NumberFieldRadio.js +20 -4
- package/dist/components/Form/NumberField/NumberFieldRadio.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.d.ts +4 -4
- package/dist/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/components/RadioGroup/RadioGroup.js +4 -4
- package/dist/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/components/RadioGroup/RadioGroupItem.d.ts +2 -2
- package/dist/components/RadioGroup/RadioGroupItem.d.ts.map +1 -1
- package/dist/components/RadioGroup/RadioGroupItem.js +4 -5
- package/dist/components/RadioGroup/RadioGroupItem.js.map +1 -1
- package/dist/i18n/translator.js +1 -1
- package/package.json +1 -1
- package/src/components/Form/BaseRadioField.tsx +1 -22
- package/src/components/Form/NumberField/NumberFieldRadio.tsx +29 -10
- package/src/components/RadioGroup/RadioGroup.tsx +5 -10
- package/src/components/RadioGroup/RadioGroupItem.tsx +7 -13
- package/src/i18n/translator.ts +1 -1
|
@@ -7,7 +7,6 @@ export type BaseRadioFieldProps<T extends string> = Simplify<BaseFieldComponentP
|
|
|
7
7
|
options: {
|
|
8
8
|
[K in T]: string;
|
|
9
9
|
};
|
|
10
|
-
orientation?: 'horizontal' | 'vertical';
|
|
11
10
|
}>;
|
|
12
|
-
export declare const BaseRadioField: <T extends string>({ description, disabled, error, label, name, options,
|
|
11
|
+
export declare const BaseRadioField: <T extends string>({ description, disabled, error, label, name, options, readOnly, setValue, value }: BaseRadioFieldProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
13
12
|
//# sourceMappingURL=BaseRadioField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseRadioField.d.ts","sourceRoot":"","sources":["../../../src/components/Form/BaseRadioField.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseRadioField.d.ts","sourceRoot":"","sources":["../../../src/components/Form/BaseRadioField.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAM1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,CAC1D,uBAAuB,CAAC,CAAC,CAAC,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE;SAAG,CAAC,IAAI,CAAC,GAAG,MAAM;KAAE,CAAC;CAC/B,CACF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,mFAU9C,mBAAmB,CAAC,CAAC,CAAC,4CAwBxB,CAAC"}
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { cva } from 'class-variance-authority';
|
|
3
2
|
import { Label } from "../Label/Label.js";
|
|
4
3
|
import { RadioGroup } from "../RadioGroup/RadioGroup.js";
|
|
5
4
|
import { FieldGroup } from "./FieldGroup/FieldGroup.js";
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
orientation: 'vertical'
|
|
9
|
-
},
|
|
10
|
-
variants: {
|
|
11
|
-
orientation: {
|
|
12
|
-
horizontal: 'flex-col @3xl:flex-row @3xl:items-center @3xl:justify-between',
|
|
13
|
-
vertical: 'flex-col'
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
export const BaseRadioField = ({ description, disabled, error, label, name, options, orientation = 'vertical', readOnly, setValue, value }) => {
|
|
18
|
-
const optionsCount = Object.keys(options).length;
|
|
19
|
-
return (_jsxs(FieldGroup, { name: name, children: [_jsxs(FieldGroup.Row, { children: [_jsx(Label, { children: label }), _jsx(FieldGroup.Description, { description: description })] }), _jsx(RadioGroup, { className: baseRadioFieldVariants({ orientation: optionsCount > 5 ? 'vertical' : orientation }), name: name, value: value ?? '', onValueChange: (value) => setValue(value), children: Object.keys(options).map((option) => (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(RadioGroup.Item, { disabled: disabled || readOnly, id: `${name}-${option}`, value: option }), _jsx(Label, { "aria-disabled": disabled || readOnly, className: "text-muted-foreground font-normal", htmlFor: `${name}-${option}`, children: options[option] })] }, option))) }), _jsx(FieldGroup.Error, { error: error })] }));
|
|
5
|
+
export const BaseRadioField = ({ description, disabled, error, label, name, options, readOnly, setValue, value }) => {
|
|
6
|
+
return (_jsxs(FieldGroup, { name: name, children: [_jsxs(FieldGroup.Row, { children: [_jsx(Label, { children: label }), _jsx(FieldGroup.Description, { description: description })] }), _jsx(RadioGroup, { name: name, value: value ?? '', onValueChange: (value) => setValue(value), children: Object.keys(options).map((option) => (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(RadioGroup.Item, { disabled: disabled || readOnly, id: `${name}-${option}`, value: option }), _jsx(Label, { "aria-disabled": disabled || readOnly, className: "text-muted-foreground font-normal", htmlFor: `${name}-${option}`, children: options[option] })] }, option))) }), _jsx(FieldGroup.Error, { error: error })] }));
|
|
20
7
|
};
|
|
21
8
|
//# sourceMappingURL=BaseRadioField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseRadioField.js","sourceRoot":"","sources":["../../../src/components/Form/BaseRadioField.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"BaseRadioField.js","sourceRoot":"","sources":["../../../src/components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J,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberFieldRadio.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/NumberField/NumberFieldRadio.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NumberFieldRadio.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/NumberField/NumberFieldRadio.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAM1C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,QAAQ,CAC1C,uBAAuB,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,eAAe,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAChF,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,sGAW9B,qBAAqB,4CA0DvB,CAAC"}
|
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
3
|
import { Label, RadioGroup } from '#components';
|
|
3
|
-
import { cn } from '#utils';
|
|
4
4
|
import { FieldGroup } from "../FieldGroup/FieldGroup.js";
|
|
5
5
|
export const NumberFieldRadio = ({ description, disableAutoPrefix, disabled, error, label, name, options, readOnly, setValue, value }) => {
|
|
6
|
+
const radioGroupRef = useRef(null);
|
|
7
|
+
const [isColumnLayout, setIsColumnLayout] = useState(false);
|
|
6
8
|
const optionsCount = Object.keys(options).length;
|
|
7
|
-
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
11
|
+
const { width: rootWidth } = entry.target.getBoundingClientRect();
|
|
12
|
+
const children = Array.from(entry.target.children);
|
|
13
|
+
const totalChildWidth = children.reduce((sum, child) => sum + child.scrollWidth, 0);
|
|
14
|
+
const isOverflowing = totalChildWidth > rootWidth - children.length * 24; // to additional provide spacing between items
|
|
15
|
+
setIsColumnLayout(isOverflowing);
|
|
16
|
+
});
|
|
17
|
+
if (radioGroupRef.current) {
|
|
18
|
+
observer.observe(radioGroupRef.current);
|
|
19
|
+
}
|
|
20
|
+
return () => observer.disconnect();
|
|
21
|
+
}, []);
|
|
22
|
+
return (_jsxs(FieldGroup, { name: name, children: [_jsxs(FieldGroup.Row, { children: [_jsx(Label, { children: label }), _jsx(FieldGroup.Description, { description: description })] }), _jsx(RadioGroup, { className: "grid justify-between", name: name, ref: radioGroupRef, style: {
|
|
23
|
+
gridTemplateColumns: isColumnLayout ? 'repeat(1, 1fr)' : `repeat(${optionsCount}, auto)`
|
|
24
|
+
}, value: value?.toString() ?? '', onValueChange: (value) => setValue(parseInt(value, 10)), children: Object.keys(options)
|
|
8
25
|
.map((val) => parseInt(val))
|
|
9
26
|
.toSorted((a, b) => a - b)
|
|
10
27
|
.map((val) => {
|
|
11
|
-
|
|
12
|
-
return (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(RadioGroup.Item, { disabled: disabled || readOnly, id: `${name}-${val}`, value: val.toString() }), _jsx(Label, { "aria-disabled": disabled || readOnly, className: "text-muted-foreground font-normal", htmlFor: `${name}-${val}`, children: text })] }, val));
|
|
28
|
+
return (_jsxs("div", { className: "flex w-fit items-center gap-2", children: [_jsx(RadioGroup.Item, { disabled: disabled || readOnly, id: `${name}-${val}`, value: val.toString() }), _jsxs(Label, { "aria-disabled": disabled || readOnly, className: "text-muted-foreground flex items-center font-normal", htmlFor: `${name}-${val}`, children: [!disableAutoPrefix && _jsxs("span", { className: "whitespace-nowrap", children: [val, "\u00A0-\u00A0"] }), _jsx("span", { children: options[val] })] })] }, val));
|
|
13
29
|
}) }), _jsx(FieldGroup.Error, { error: error })] }));
|
|
14
30
|
};
|
|
15
31
|
//# sourceMappingURL=NumberFieldRadio.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberFieldRadio.js","sourceRoot":"","sources":["../../../../src/components/Form/NumberField/NumberFieldRadio.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"NumberFieldRadio.js","sourceRoot":"","sources":["../../../../src/components/Form/NumberField/NumberFieldRadio.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAKpD,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA8B,CAAC;AAQ1D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,EAC/B,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,KAAK,EACL,KAAK,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,KAAK,EACiB,EAAE,EAAE;IAC1B,MAAM,aAAa,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACnD,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAErE,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAEjD,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE;YAC9C,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,KAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC;YACnE,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,KAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;YACpD,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,C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AAK,SAAS,EAAC,+BAA+B,aAC5C,KAAC,UAAU,CAAC,IAAI,IAAC,QAAQ,EAAE,QAAQ,IAAI,QAAQ,EAAE,EAAE,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAI,EAChG,MAAC,KAAK,qBACW,QAAQ,IAAI,QAAQ,EACnC,SAAS,EAAC,qDAAqD,EAC/D,OAAO,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,aAExB,CAAC,iBAAiB,IAAI,gBAAM,SAAS,EAAC,mBAAmB,aAAE,GAAG,qBAAqB,EACpF,yBAAO,OAAO,CAAC,GAAG,CAAC,GAAQ,IACrB,KAT0C,GAAG,CAUjD,CACP,CAAC;gBACJ,CAAC,CAAC,GACO,EACb,KAAC,UAAU,CAAC,KAAK,IAAC,KAAK,EAAE,KAAK,GAAI,IACvB,CACd,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import
|
|
3
|
-
type RadioGroupProps = React.
|
|
4
|
-
export declare const RadioGroup: React.
|
|
5
|
-
Item: React.
|
|
2
|
+
import { Root } from '@radix-ui/react-radio-group';
|
|
3
|
+
type RadioGroupProps = React.ComponentProps<typeof Root>;
|
|
4
|
+
export declare const RadioGroup: React.FC<import("@radix-ui/react-radio-group").RadioGroupProps & React.RefAttributes<HTMLDivElement>> & {
|
|
5
|
+
Item: React.FC<import("@radix-ui/react-radio-group").RadioGroupItemProps & React.RefAttributes<HTMLButtonElement>>;
|
|
6
6
|
};
|
|
7
7
|
export type { RadioGroupProps };
|
|
8
8
|
//# sourceMappingURL=RadioGroup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroup.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,
|
|
1
|
+
{"version":3,"file":"RadioGroup.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAMnD,KAAK,eAAe,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,CAAC;AAMzD,eAAO,MAAM,UAAU;;CAErB,CAAC;AAEH,YAAY,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import
|
|
3
|
+
import { Root } from '@radix-ui/react-radio-group';
|
|
4
4
|
import { cn } from '#utils';
|
|
5
5
|
import { RadioGroupItem } from "./RadioGroupItem.js";
|
|
6
|
-
const RadioGroupRoot =
|
|
7
|
-
return
|
|
8
|
-
}
|
|
6
|
+
const RadioGroupRoot = ({ className, ...props }) => {
|
|
7
|
+
return _jsx(Root, { className: cn('grid gap-2', className), "data-testid": "radio-group", ...props });
|
|
8
|
+
};
|
|
9
9
|
export const RadioGroup = Object.assign(RadioGroupRoot, {
|
|
10
10
|
Item: RadioGroupItem
|
|
11
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,
|
|
1
|
+
{"version":3,"file":"RadioGroup.js","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroup.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAsB,CAAC;AAItD,MAAM,cAAc,GAA8B,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IAC5E,OAAO,KAAC,IAAI,IAAC,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC,iBAAc,aAAa,KAAK,KAAK,GAAI,CAAC;AAC/F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE;IACtD,IAAI,EAAE,cAAc;CACrB,CAAC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const RadioGroupItem:
|
|
1
|
+
import { Item } from '@radix-ui/react-radio-group';
|
|
2
|
+
export declare const RadioGroupItem: React.FC<React.ComponentProps<typeof Item>>;
|
|
3
3
|
//# sourceMappingURL=RadioGroupItem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroupItem.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroupItem.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RadioGroupItem.d.ts","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroupItem.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAa,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAK9D,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,CAiBtE,CAAC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
2
|
+
import { Indicator, Item } from '@radix-ui/react-radio-group';
|
|
4
3
|
import { CircleIcon } from 'lucide-react';
|
|
5
4
|
import { cn } from '#utils';
|
|
6
|
-
export const RadioGroupItem =
|
|
7
|
-
return (_jsx(
|
|
8
|
-
}
|
|
5
|
+
export const RadioGroupItem = ({ className, ...props }) => {
|
|
6
|
+
return (_jsx(Item, { className: cn('border-primary text-primary focus-visible:ring-ring flex aspect-square h-4 w-4 items-center justify-center rounded-full border shadow-sm focus:outline-hidden focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50', className), ...props, children: _jsx(Indicator, { asChild: true, children: _jsx(CircleIcon, { className: "fill-current text-current", style: { height: '0.625rem', strokeWidth: '2px', width: '0.625rem' } }) }) }));
|
|
7
|
+
};
|
|
9
8
|
//# sourceMappingURL=RadioGroupItem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RadioGroupItem.js","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroupItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"RadioGroupItem.js","sourceRoot":"","sources":["../../../src/components/RadioGroup/RadioGroupItem.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,cAAc,GAAgD,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE;IACrG,OAAO,CACL,KAAC,IAAI,IACH,SAAS,EAAE,EAAE,CACX,oOAAoO,EACpO,SAAS,CACV,KACG,KAAK,YAET,KAAC,SAAS,IAAC,OAAO,kBAChB,KAAC,UAAU,IACT,SAAS,EAAC,2BAA2B,EACrC,KAAK,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,GACpE,GACQ,GACP,CACR,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/i18n/translator.js
CHANGED
|
@@ -75,7 +75,7 @@ let Translator = (() => {
|
|
|
75
75
|
const globalObj = globalThis;
|
|
76
76
|
globalObj[globalKey] ??= [];
|
|
77
77
|
globalObj[globalKey].push(this);
|
|
78
|
-
if (globalObj[globalKey].length >
|
|
78
|
+
if (globalObj[globalKey].length > 1) {
|
|
79
79
|
console.warn(`WARNING: Multiple Translator instances detected (existing: ${globalObj[globalKey].length})`);
|
|
80
80
|
// Check if prototypes are the same (can occur if multiple library versions are loaded)
|
|
81
81
|
const differentPrototype = globalObj[globalKey].some((inst) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@douglasneuroinformatics/libui",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "6.1.
|
|
4
|
+
"version": "6.1.3",
|
|
5
5
|
"packageManager": "pnpm@10.7.1",
|
|
6
6
|
"description": "Generic UI components for DNP projects, built using React and Tailwind CSS",
|
|
7
7
|
"author": "Joshua Unrau",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { cva } from 'class-variance-authority';
|
|
2
1
|
import type { Simplify } from 'type-fest';
|
|
3
2
|
|
|
4
3
|
import { Label } from '../Label/Label.tsx';
|
|
@@ -7,25 +6,12 @@ import { FieldGroup } from './FieldGroup/FieldGroup.tsx';
|
|
|
7
6
|
|
|
8
7
|
import type { BaseFieldComponentProps } from './types.ts';
|
|
9
8
|
|
|
10
|
-
const baseRadioFieldVariants = cva('flex', {
|
|
11
|
-
defaultVariants: {
|
|
12
|
-
orientation: 'vertical'
|
|
13
|
-
},
|
|
14
|
-
variants: {
|
|
15
|
-
orientation: {
|
|
16
|
-
horizontal: 'flex-col @3xl:flex-row @3xl:items-center @3xl:justify-between',
|
|
17
|
-
vertical: 'flex-col'
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
|
|
22
9
|
export type BaseRadioFieldProps<T extends string> = Simplify<
|
|
23
10
|
BaseFieldComponentProps<T> & {
|
|
24
11
|
description?: string;
|
|
25
12
|
disabled?: boolean;
|
|
26
13
|
label: string;
|
|
27
14
|
options: { [K in T]: string };
|
|
28
|
-
orientation?: 'horizontal' | 'vertical';
|
|
29
15
|
}
|
|
30
16
|
>;
|
|
31
17
|
|
|
@@ -36,24 +22,17 @@ export const BaseRadioField = <T extends string>({
|
|
|
36
22
|
label,
|
|
37
23
|
name,
|
|
38
24
|
options,
|
|
39
|
-
orientation = 'vertical',
|
|
40
25
|
readOnly,
|
|
41
26
|
setValue,
|
|
42
27
|
value
|
|
43
28
|
}: BaseRadioFieldProps<T>) => {
|
|
44
|
-
const optionsCount = Object.keys(options).length;
|
|
45
29
|
return (
|
|
46
30
|
<FieldGroup name={name}>
|
|
47
31
|
<FieldGroup.Row>
|
|
48
32
|
<Label>{label}</Label>
|
|
49
33
|
<FieldGroup.Description description={description} />
|
|
50
34
|
</FieldGroup.Row>
|
|
51
|
-
<RadioGroup
|
|
52
|
-
className={baseRadioFieldVariants({ orientation: optionsCount > 5 ? 'vertical' : orientation })}
|
|
53
|
-
name={name}
|
|
54
|
-
value={value ?? ''}
|
|
55
|
-
onValueChange={(value) => setValue(value as T)}
|
|
56
|
-
>
|
|
35
|
+
<RadioGroup name={name} value={value ?? ''} onValueChange={(value) => setValue(value as T)}>
|
|
57
36
|
{Object.keys(options).map((option) => (
|
|
58
37
|
<div className="flex items-center gap-2" key={option}>
|
|
59
38
|
<RadioGroup.Item disabled={disabled || readOnly} id={`${name}-${option}`} value={option} />
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
|
|
1
3
|
import type { NumberFormField } from '@douglasneuroinformatics/libui-form-types';
|
|
2
4
|
import type { Simplify } from 'type-fest';
|
|
3
5
|
|
|
4
6
|
import { Label, RadioGroup } from '#components';
|
|
5
|
-
import { cn } from '#utils';
|
|
6
7
|
|
|
7
8
|
import { FieldGroup } from '../FieldGroup/FieldGroup.tsx';
|
|
8
9
|
|
|
@@ -24,8 +25,25 @@ export const NumberFieldRadio = ({
|
|
|
24
25
|
setValue,
|
|
25
26
|
value
|
|
26
27
|
}: NumberFieldRadioProps) => {
|
|
28
|
+
const radioGroupRef = useRef<HTMLDivElement>(null);
|
|
29
|
+
const [isColumnLayout, setIsColumnLayout] = useState<boolean>(false);
|
|
30
|
+
|
|
27
31
|
const optionsCount = Object.keys(options).length;
|
|
28
32
|
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
35
|
+
const { width: rootWidth } = entry!.target.getBoundingClientRect();
|
|
36
|
+
const children = Array.from(entry!.target.children);
|
|
37
|
+
const totalChildWidth = children.reduce((sum, child) => sum + child.scrollWidth, 0);
|
|
38
|
+
const isOverflowing = totalChildWidth > rootWidth - children.length * 24; // to additional provide spacing between items
|
|
39
|
+
setIsColumnLayout(isOverflowing);
|
|
40
|
+
});
|
|
41
|
+
if (radioGroupRef.current) {
|
|
42
|
+
observer.observe(radioGroupRef.current);
|
|
43
|
+
}
|
|
44
|
+
return () => observer.disconnect();
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
29
47
|
return (
|
|
30
48
|
<FieldGroup name={name}>
|
|
31
49
|
<FieldGroup.Row>
|
|
@@ -33,28 +51,29 @@ export const NumberFieldRadio = ({
|
|
|
33
51
|
<FieldGroup.Description description={description} />
|
|
34
52
|
</FieldGroup.Row>
|
|
35
53
|
<RadioGroup
|
|
36
|
-
className=
|
|
37
|
-
'flex',
|
|
38
|
-
optionsCount > 5 ? 'flex-col' : 'flex-col @3xl:flex-row @3xl:items-center @3xl:justify-between'
|
|
39
|
-
)}
|
|
54
|
+
className="grid justify-between"
|
|
40
55
|
name={name}
|
|
56
|
+
ref={radioGroupRef}
|
|
57
|
+
style={{
|
|
58
|
+
gridTemplateColumns: isColumnLayout ? 'repeat(1, 1fr)' : `repeat(${optionsCount}, auto)`
|
|
59
|
+
}}
|
|
41
60
|
value={value?.toString() ?? ''}
|
|
42
|
-
onValueChange={(value) => setValue(parseInt(value))}
|
|
61
|
+
onValueChange={(value) => setValue(parseInt(value, 10))}
|
|
43
62
|
>
|
|
44
63
|
{Object.keys(options)
|
|
45
64
|
.map((val) => parseInt(val))
|
|
46
65
|
.toSorted((a, b) => a - b)
|
|
47
66
|
.map((val) => {
|
|
48
|
-
const text = (disableAutoPrefix ? '' : `${val} - `) + options[val];
|
|
49
67
|
return (
|
|
50
|
-
<div className="flex items-center gap-2" key={val}>
|
|
68
|
+
<div className="flex w-fit items-center gap-2" key={val}>
|
|
51
69
|
<RadioGroup.Item disabled={disabled || readOnly} id={`${name}-${val}`} value={val.toString()} />
|
|
52
70
|
<Label
|
|
53
71
|
aria-disabled={disabled || readOnly}
|
|
54
|
-
className="text-muted-foreground font-normal"
|
|
72
|
+
className="text-muted-foreground flex items-center font-normal"
|
|
55
73
|
htmlFor={`${name}-${val}`}
|
|
56
74
|
>
|
|
57
|
-
{
|
|
75
|
+
{!disableAutoPrefix && <span className="whitespace-nowrap">{val} - </span>}
|
|
76
|
+
<span>{options[val]}</span>
|
|
58
77
|
</Label>
|
|
59
78
|
</div>
|
|
60
79
|
);
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { Root } from '@radix-ui/react-radio-group';
|
|
4
4
|
|
|
5
5
|
import { cn } from '#utils';
|
|
6
6
|
|
|
7
7
|
import { RadioGroupItem } from './RadioGroupItem.tsx';
|
|
8
8
|
|
|
9
|
-
type RadioGroupProps = React.
|
|
9
|
+
type RadioGroupProps = React.ComponentProps<typeof Root>;
|
|
10
10
|
|
|
11
|
-
const RadioGroupRoot
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
>(function RadioGroup({ className, ...props }, ref) {
|
|
15
|
-
return (
|
|
16
|
-
<RadioGroupPrimitive.Root className={cn('grid gap-2', className)} data-testid="radio-group" {...props} ref={ref} />
|
|
17
|
-
);
|
|
18
|
-
});
|
|
11
|
+
const RadioGroupRoot: React.FC<RadioGroupProps> = ({ className, ...props }) => {
|
|
12
|
+
return <Root className={cn('grid gap-2', className)} data-testid="radio-group" {...props} />;
|
|
13
|
+
};
|
|
19
14
|
|
|
20
15
|
export const RadioGroup = Object.assign(RadioGroupRoot, {
|
|
21
16
|
Item: RadioGroupItem
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
1
|
+
import { Indicator, Item } from '@radix-ui/react-radio-group';
|
|
4
2
|
import { CircleIcon } from 'lucide-react';
|
|
5
3
|
|
|
6
4
|
import { cn } from '#utils';
|
|
7
5
|
|
|
8
|
-
export const RadioGroupItem =
|
|
9
|
-
React.ElementRef<typeof RadioGroupPrimitive.Item>,
|
|
10
|
-
React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
|
|
11
|
-
>(function RadioGroupItem({ className, ...props }, ref) {
|
|
6
|
+
export const RadioGroupItem: React.FC<React.ComponentProps<typeof Item>> = ({ className, ...props }) => {
|
|
12
7
|
return (
|
|
13
|
-
<
|
|
8
|
+
<Item
|
|
14
9
|
className={cn(
|
|
15
10
|
'border-primary text-primary focus-visible:ring-ring flex aspect-square h-4 w-4 items-center justify-center rounded-full border shadow-sm focus:outline-hidden focus-visible:ring-1 disabled:cursor-not-allowed disabled:opacity-50',
|
|
16
11
|
className
|
|
17
12
|
)}
|
|
18
|
-
ref={ref}
|
|
19
13
|
{...props}
|
|
20
14
|
>
|
|
21
|
-
<
|
|
15
|
+
<Indicator asChild>
|
|
22
16
|
<CircleIcon
|
|
23
17
|
className="fill-current text-current"
|
|
24
18
|
style={{ height: '0.625rem', strokeWidth: '2px', width: '0.625rem' }}
|
|
25
19
|
/>
|
|
26
|
-
</
|
|
27
|
-
</
|
|
20
|
+
</Indicator>
|
|
21
|
+
</Item>
|
|
28
22
|
);
|
|
29
|
-
}
|
|
23
|
+
};
|
package/src/i18n/translator.ts
CHANGED
|
@@ -57,7 +57,7 @@ export class Translator implements TranslatorType<TranslationKey> {
|
|
|
57
57
|
globalObj[globalKey] ??= [];
|
|
58
58
|
globalObj[globalKey].push(this);
|
|
59
59
|
|
|
60
|
-
if (globalObj[globalKey].length >
|
|
60
|
+
if (globalObj[globalKey].length > 1) {
|
|
61
61
|
console.warn(`WARNING: Multiple Translator instances detected (existing: ${globalObj[globalKey].length})`);
|
|
62
62
|
|
|
63
63
|
// Check if prototypes are the same (can occur if multiple library versions are loaded)
|