@douglasneuroinformatics/libui 2.1.0 → 2.2.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.
@@ -22,6 +22,6 @@ export const BaseRadioField = ({ description, error, label, name, options, orien
22
22
  React.createElement(FieldGroup.Description, { description: description })),
23
23
  React.createElement(RadioGroup, { className: baseRadioFieldVariants({ orientation: optionsCount > 5 ? 'vertical' : orientation }), name: name, value: value ?? '', onValueChange: (value) => setValue(value) }, Object.keys(options).map((option) => (React.createElement("div", { className: "flex items-center gap-2", key: option },
24
24
  React.createElement(RadioGroup.Item, { id: `${name}-${option}`, value: option }),
25
- React.createElement(Label, { className: "font-normal", htmlFor: `${name}-${option}` }, options[option]))))),
25
+ React.createElement(Label, { className: "font-normal text-muted-foreground", htmlFor: `${name}-${option}` }, options[option]))))),
26
26
  React.createElement(FieldGroup.Error, { error: error })));
27
27
  };
@@ -23,9 +23,9 @@ export const BooleanFieldRadio = ({ error, label, name, options, setValue, value
23
23
  React.createElement(RadioGroup, { name: name, value: stringifyBoolean(value), onValueChange: handleValueChange },
24
24
  React.createElement(FieldGroup.Row, null,
25
25
  React.createElement(RadioGroup.Item, { id: `${name}-true`, value: "true" }),
26
- React.createElement(Label, { className: "font-normal", htmlFor: `${name}-true` }, options?.true ?? t('form.radioLabels.true'))),
26
+ React.createElement(Label, { className: "font-normal text-muted-foreground", htmlFor: `${name}-true` }, options?.true ?? t('form.radioLabels.true'))),
27
27
  React.createElement(FieldGroup.Row, null,
28
28
  React.createElement(RadioGroup.Item, { id: `${name}-false`, value: "false" }),
29
- React.createElement(Label, { className: "font-normal", htmlFor: `${name}-false` }, options?.false ?? t('form.radioLabels.false')))),
29
+ React.createElement(Label, { className: "font-normal text-muted-foreground", htmlFor: `${name}-false` }, options?.false ?? t('form.radioLabels.false')))),
30
30
  React.createElement(FieldGroup.Error, { error: error })));
31
31
  };
@@ -1,2 +1,2 @@
1
1
  import React from 'react';
2
- export const FieldGroupRoot = ({ children }) => (React.createElement("div", { className: "flex flex-col gap-2 @container" }, children));
2
+ export const FieldGroupRoot = ({ children }) => (React.createElement("div", { className: "flex flex-col gap-3.5 @container" }, children));
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { FormContent, FormDataType, PartialNullableFormDataType } from '@douglasneuroinformatics/libui-form-types';
3
3
  import { z } from 'zod';
4
- type FormProps<TSchema extends z.ZodType<FormDataType>, TData extends z.infer<TSchema> = z.infer<TSchema>> = {
4
+ type FormProps<TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TSchema> = z.TypeOf<TSchema>> = {
5
5
  [key: `data-${string}`]: unknown;
6
6
  className?: string;
7
7
  content: FormContent<TData>;
@@ -1 +1 @@
1
- {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../../src/components/Form/Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EAGZ,2BAA2B,EAC5B,MAAM,2CAA2C,CAAC;AAInD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAUxB,KAAK,SAAS,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI;IAC3G,CAAC,GAAG,EAAE,QAAQ,MAAM,EAAE,GAAG,OAAO,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,aAAa,CAAC,EAAE,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACnD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;IAC7C,QAAQ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,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;CACpC,CAAC;AAEF,QAAA,MAAM,IAAI,iPAWP,UAAU,OAAO,EAAE,KAAK,CAAC,sBAgG3B,CAAC;AAEF,OAAO,EAAE,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC"}
@@ -12,8 +12,8 @@ export const NumberFieldRadio = ({ description, error, label, name, options, set
12
12
  React.createElement(RadioGroup, { className: cn('flex', optionsCount > 5 ? 'flex-col' : 'flex-col @3xl:flex-row @3xl:items-center @3xl:justify-between'), name: name, value: value?.toString() ?? '', onValueChange: (value) => setValue(parseInt(value)) }, Object.keys(options)
13
13
  .map((val) => parseInt(val))
14
14
  .toSorted((a, b) => a - b)
15
- .map((key) => (React.createElement("div", { className: "flex items-center gap-2", key: key },
16
- React.createElement(RadioGroup.Item, { id: `${name}-${key}`, value: key.toString() }),
17
- React.createElement(Label, { className: "font-normal", htmlFor: `${name}-${key}` }, options[key]))))),
15
+ .map((val) => (React.createElement("div", { className: "flex items-center gap-2", key: val },
16
+ React.createElement(RadioGroup.Item, { id: `${name}-${val}`, value: val.toString() }),
17
+ React.createElement(Label, { className: "font-normal text-muted-foreground", htmlFor: `${name}-${val}` }, `${val} - ${options[val]}`))))),
18
18
  React.createElement(FieldGroup.Error, { error: error })));
19
19
  };
@@ -11,6 +11,6 @@ export const NumberFieldSelect = ({ description, error, label, name, options, se
11
11
  React.createElement(Select, { name: name, value: value?.toString() ?? '', onValueChange: (value) => setValue(parseFloat(value)) },
12
12
  React.createElement(Select.Trigger, { "data-cy": `${name}-select-trigger`, "data-testid": `${name}-select-trigger` },
13
13
  React.createElement(Select.Value, null)),
14
- React.createElement(Select.Content, { "data-cy": `${name}-select-content`, "data-testid": `${name}-select-content` }, Object.keys(options).map((option) => (React.createElement(Select.Item, { key: option, value: option }, options[option]))))),
14
+ React.createElement(Select.Content, { "data-cy": `${name}-select-content`, "data-testid": `${name}-select-content` }, Object.keys(options).map((option) => (React.createElement(Select.Item, { key: option, value: option }, `${option} - ${options[option]}`))))),
15
15
  React.createElement(FieldGroup.Error, { error: error })));
16
16
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SetFieldListbox.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/SetField/SetFieldListbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAC5D,eAAe,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAErB,eAAO,MAAM,eAAe,oGAQzB,qBAAqB,CAAC,CAAC,sBAwBzB,CAAC"}
1
+ {"version":3,"file":"SetFieldListbox.d.ts","sourceRoot":"","sources":["../../../../src/components/Form/SetField/SetFieldListbox.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IAC5D,eAAe,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1D,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAErB,eAAO,MAAM,eAAe,oGAQzB,qBAAqB,CAAC,CAAC,sBA0BzB,CAAC"}
@@ -7,10 +7,10 @@ export const SetFieldListbox = ({ description, error, label, name, onCheckedChan
7
7
  React.createElement(FieldGroup.Row, null,
8
8
  React.createElement(Label, null, label),
9
9
  React.createElement(FieldGroup.Description, { description: description })),
10
- Object.keys(options).map((option) => (React.createElement("div", { className: "flex items-center gap-2", key: option },
10
+ React.createElement("div", { className: "grid gap-2" }, Object.keys(options).map((option) => (React.createElement(FieldGroup.Row, { key: option },
11
11
  React.createElement(Checkbox, { checked: value?.has(option) ?? false, id: `${name}-${option}`, onCheckedChange: (checked) => {
12
12
  onCheckedChange(option, !checked);
13
13
  } }),
14
- React.createElement(Label, { className: "font-normal", htmlFor: `${name}-${option}` }, options[option])))),
14
+ React.createElement(Label, { className: "font-normal text-muted-foreground", htmlFor: `${name}-${option}` }, options[option]))))),
15
15
  React.createElement(FieldGroup.Error, { error: error })));
16
16
  };
@@ -1,13 +1,20 @@
1
1
  import type { Promisable } from 'type-fest';
2
- type DownloadOptions<T extends Blob | string = Blob | string> = T extends Blob ? {
3
- blobType: 'image/png';
4
- } : {
2
+ type DownloadTextOptions = {
5
3
  blobType: 'text/csv' | 'text/plain';
6
4
  };
5
+ type DownloadBlobOptions = {
6
+ blobType: 'application/zip' | 'image/jpeg' | 'image/png' | 'image/webp';
7
+ };
8
+ interface DownloadFunction {
9
+ (filename: string, data: Blob, options: DownloadBlobOptions): Promise<void>;
10
+ (filename: string, data: () => Promisable<Blob>, options: DownloadBlobOptions): Promise<void>;
11
+ (filename: string, data: string, options?: DownloadTextOptions): Promise<void>;
12
+ (filename: string, data: () => Promisable<string>, options?: DownloadTextOptions): Promise<void>;
13
+ }
7
14
  /**
8
15
  * Used to trigger downloads of arbitrary data to the client
9
16
  * @returns A function to invoke the download
10
17
  */
11
- export declare function useDownload(): <T extends string | Blob>(filename: string, fetchData: () => Promisable<T>, options?: DownloadOptions<T>) => Promise<void>;
18
+ export declare function useDownload(): DownloadFunction;
12
19
  export {};
13
20
  //# sourceMappingURL=useDownload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDownload.d.ts","sourceRoot":"","sources":["../../src/hooks/useDownload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAI5C,KAAK,eAAe,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,GA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
22
  setState(null);
23
23
  }
24
24
  }, [state]);
25
- return async (filename, fetchData, options) => {
25
+ return async (filename, _data, options) => {
26
26
  try {
27
- const data = await fetchData();
27
+ const data = typeof _data === 'function' ? await _data() : _data;
28
28
  if (typeof data !== 'string' && !options?.blobType) {
29
29
  throw new Error("argument 'blobType' must be defined when download is called with a Blob object");
30
30
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@douglasneuroinformatics/libui",
3
3
  "type": "module",
4
- "version": "2.1.0",
4
+ "version": "2.2.1",
5
5
  "packageManager": "pnpm@8.15.3",
6
6
  "description": "Generic UI components for DNP projects, built using React and TailwindCSS",
7
7
  "author": {
@@ -56,7 +56,7 @@ export const BaseRadioField = <T extends string>({
56
56
  {Object.keys(options).map((option) => (
57
57
  <div className="flex items-center gap-2" key={option}>
58
58
  <RadioGroup.Item id={`${name}-${option}`} value={option} />
59
- <Label className="font-normal" htmlFor={`${name}-${option}`}>
59
+ <Label className="font-normal text-muted-foreground" htmlFor={`${name}-${option}`}>
60
60
  {options[option as T]}
61
61
  </Label>
62
62
  </div>
@@ -42,13 +42,13 @@ export const BooleanFieldRadio = ({ error, label, name, options, setValue, value
42
42
  <RadioGroup name={name} value={stringifyBoolean(value)} onValueChange={handleValueChange}>
43
43
  <FieldGroup.Row>
44
44
  <RadioGroup.Item id={`${name}-true`} value="true" />
45
- <Label className="font-normal" htmlFor={`${name}-true`}>
45
+ <Label className="font-normal text-muted-foreground" htmlFor={`${name}-true`}>
46
46
  {options?.true ?? t('form.radioLabels.true')}
47
47
  </Label>
48
48
  </FieldGroup.Row>
49
49
  <FieldGroup.Row>
50
50
  <RadioGroup.Item id={`${name}-false`} value="false" />
51
- <Label className="font-normal" htmlFor={`${name}-false`}>
51
+ <Label className="font-normal text-muted-foreground" htmlFor={`${name}-false`}>
52
52
  {options?.false ?? t('form.radioLabels.false')}
53
53
  </Label>
54
54
  </FieldGroup.Row>
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
 
3
3
  export const FieldGroupRoot: React.FC<{ children: React.ReactNode }> = ({ children }) => (
4
- <div className="flex flex-col gap-2 @container">{children}</div>
4
+ <div className="flex flex-col gap-3.5 @container">{children}</div>
5
5
  );
@@ -20,7 +20,7 @@ import { getInitialValues } from './utils.js';
20
20
 
21
21
  import type { FormErrors } from './types.js';
22
22
 
23
- type FormProps<TSchema extends z.ZodType<FormDataType>, TData extends z.infer<TSchema> = z.infer<TSchema>> = {
23
+ type FormProps<TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TSchema> = z.TypeOf<TSchema>> = {
24
24
  [key: `data-${string}`]: unknown;
25
25
  className?: string;
26
26
  content: FormContent<TData>;
@@ -33,7 +33,7 @@ type FormProps<TSchema extends z.ZodType<FormDataType>, TData extends z.infer<TS
33
33
  validationSchema: z.ZodType<TData>;
34
34
  };
35
35
 
36
- const Form = <TSchema extends z.ZodType<FormDataType>, TData extends z.infer<TSchema> = z.infer<TSchema>>({
36
+ const Form = <TSchema extends z.ZodType<FormDataType>, TData extends z.TypeOf<TSchema> = z.TypeOf<TSchema>>({
37
37
  className,
38
38
  content,
39
39
  id,
@@ -43,11 +43,11 @@ export const NumberFieldRadio = ({
43
43
  {Object.keys(options)
44
44
  .map((val) => parseInt(val))
45
45
  .toSorted((a, b) => a - b)
46
- .map((key) => (
47
- <div className="flex items-center gap-2" key={key}>
48
- <RadioGroup.Item id={`${name}-${key}`} value={key.toString()} />
49
- <Label className="font-normal" htmlFor={`${name}-${key}`}>
50
- {options[key]}
46
+ .map((val) => (
47
+ <div className="flex items-center gap-2" key={val}>
48
+ <RadioGroup.Item id={`${name}-${val}`} value={val.toString()} />
49
+ <Label className="font-normal text-muted-foreground" htmlFor={`${name}-${val}`}>
50
+ {`${val} - ${options[val]}`}
51
51
  </Label>
52
52
  </div>
53
53
  ))}
@@ -35,7 +35,7 @@ export const NumberFieldSelect = <T extends number = number>({
35
35
  {Object.keys(options).map((option) => (
36
36
  <Select.Item key={option} value={option}>
37
37
  {/** option needs to be type number, but no sense converting it when it is coerced right back anyways */}
38
- {options[option as any as T]}
38
+ {`${option} - ${options[option as any as T]}`}
39
39
  </Select.Item>
40
40
  ))}
41
41
  </Select.Content>
@@ -25,20 +25,22 @@ export const SetFieldListbox = <T extends string = string>({
25
25
  <Label>{label}</Label>
26
26
  <FieldGroup.Description description={description} />
27
27
  </FieldGroup.Row>
28
- {Object.keys(options).map((option) => (
29
- <div className="flex items-center gap-2" key={option}>
30
- <Checkbox
31
- checked={value?.has(option as T) ?? false}
32
- id={`${name}-${option}`}
33
- onCheckedChange={(checked) => {
34
- onCheckedChange(option as T, !checked);
35
- }}
36
- />
37
- <Label className="font-normal" htmlFor={`${name}-${option}`}>
38
- {options[option as T]}
39
- </Label>
40
- </div>
41
- ))}
28
+ <div className="grid gap-2">
29
+ {Object.keys(options).map((option) => (
30
+ <FieldGroup.Row key={option}>
31
+ <Checkbox
32
+ checked={value?.has(option as T) ?? false}
33
+ id={`${name}-${option}`}
34
+ onCheckedChange={(checked) => {
35
+ onCheckedChange(option as T, !checked);
36
+ }}
37
+ />
38
+ <Label className="font-normal text-muted-foreground" htmlFor={`${name}-${option}`}>
39
+ {options[option as T]}
40
+ </Label>
41
+ </FieldGroup.Row>
42
+ ))}
43
+ </div>
42
44
  <FieldGroup.Error error={error} />
43
45
  </FieldGroup>
44
46
  );
@@ -4,18 +4,30 @@ import type { Promisable } from 'type-fest';
4
4
 
5
5
  import { useNotificationsStore } from './useNotificationsStore.js';
6
6
 
7
- type DownloadOptions<T extends Blob | string = Blob | string> = T extends Blob
8
- ? { blobType: 'image/png' }
9
- : { blobType: 'text/csv' | 'text/plain' };
7
+ type DownloadTextOptions = {
8
+ blobType: 'text/csv' | 'text/plain';
9
+ };
10
+
11
+ type DownloadBlobOptions = {
12
+ blobType: 'application/zip' | 'image/jpeg' | 'image/png' | 'image/webp';
13
+ };
14
+
15
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
16
+ interface DownloadFunction {
17
+ (filename: string, data: Blob, options: DownloadBlobOptions): Promise<void>;
18
+ (filename: string, data: () => Promisable<Blob>, options: DownloadBlobOptions): Promise<void>;
19
+ (filename: string, data: string, options?: DownloadTextOptions): Promise<void>;
20
+ (filename: string, data: () => Promisable<string>, options?: DownloadTextOptions): Promise<void>;
21
+ }
10
22
 
11
23
  /**
12
24
  * Used to trigger downloads of arbitrary data to the client
13
25
  * @returns A function to invoke the download
14
26
  */
15
- export function useDownload() {
27
+ export function useDownload(): DownloadFunction {
16
28
  const notifications = useNotificationsStore();
17
29
  const [state, setState] = useState<{
18
- blobType: DownloadOptions['blobType'];
30
+ blobType: string;
19
31
  data: Blob | string;
20
32
  filename: string;
21
33
  } | null>(null);
@@ -38,13 +50,9 @@ export function useDownload() {
38
50
  }
39
51
  }, [state]);
40
52
 
41
- return async <T extends Blob | string>(
42
- filename: string,
43
- fetchData: () => Promisable<T>,
44
- options?: DownloadOptions<T>
45
- ) => {
53
+ return async (filename, _data, options) => {
46
54
  try {
47
- const data = await fetchData();
55
+ const data = typeof _data === 'function' ? await _data() : _data;
48
56
  if (typeof data !== 'string' && !options?.blobType) {
49
57
  throw new Error("argument 'blobType' must be defined when download is called with a Blob object");
50
58
  }