@mistriwork/ui 1.0.0-rc.36 → 1.0.0-rc.38

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.
@@ -6,14 +6,28 @@
6
6
  */
7
7
  import { type ReactNode, type Ref } from 'react';
8
8
  import { type FieldFrame } from './fieldFrame.js';
9
- export interface FileFieldProps extends FieldFrame {
10
- /** The chosen file; null while there is none. Set it to null to clear the choice. */
11
- value: File | null;
12
- onChange: (file: File | null) => void;
9
+ interface FileFieldBase extends FieldFrame {
13
10
  /** What the picker offers, as the input's `accept`: `.csv`, `text/csv`, `image/*`, separated by commas. */
14
11
  accept?: string;
15
12
  name?: string;
16
13
  disabled?: boolean;
17
14
  inputRef?: Ref<HTMLInputElement>;
18
15
  }
16
+ /**
17
+ * One file by default: `value` is the chosen File (null while there is none) and `onChange` hands up one. With `multiple`
18
+ * the picker takes several at once, `value` is a `File[]` (empty while there is none) and `onChange` hands up the whole
19
+ * choice, in the order the browser gives it; the input itself says how many ("3 files"), so a page need not.
20
+ */
21
+ export type FileFieldProps = FileFieldBase & ({
22
+ multiple?: false;
23
+ /** The chosen file; null while there is none. Set it to null to clear the choice. */
24
+ value: File | null;
25
+ onChange: (file: File | null) => void;
26
+ } | {
27
+ multiple: true;
28
+ /** The chosen files; empty while there are none. Set it to `[]` to clear the choice. */
29
+ value: File[];
30
+ onChange: (files: File[]) => void;
31
+ });
19
32
  export declare function FileField(props: FileFieldProps): ReactNode;
33
+ export {};
package/dist/FileField.js CHANGED
@@ -10,16 +10,23 @@ import { Field } from './Field.js';
10
10
  import { frameOf } from './fieldFrame.js';
11
11
  export function FileField(props) {
12
12
  const own = useRef(null);
13
- // The input keeps its own file, so a page that clears the value (null) has to clear it too.
13
+ // The input keeps its own files, so a page that clears the value (null, or an empty list) has to clear it too.
14
+ const cleared = props.multiple ? props.value.length === 0 : props.value === null;
14
15
  useEffect(() => {
15
- if (props.value === null && own.current && own.current.value !== '')
16
+ if (cleared && own.current && own.current.value !== '')
16
17
  own.current.value = '';
17
- }, [props.value]);
18
+ }, [cleared]);
18
19
  return (_jsx(Field, { ...frameOf(props), children: (control) => (_jsx("input", { ...control, ref: (node) => {
19
20
  own.current = node;
20
21
  if (typeof props.inputRef === 'function')
21
22
  props.inputRef(node);
22
23
  else if (props.inputRef)
23
24
  props.inputRef.current = node;
24
- }, className: "field-control field-file", type: "file", name: props.name, accept: props.accept, disabled: props.disabled, onChange: (e) => props.onChange(e.target.files?.[0] ?? null) })) }));
25
+ }, className: "field-control field-file", type: "file", name: props.name, accept: props.accept, disabled: props.disabled, multiple: props.multiple === true, onChange: (e) => {
26
+ const files = Array.from(e.target.files ?? []);
27
+ if (props.multiple === true)
28
+ props.onChange(files);
29
+ else
30
+ props.onChange(files[0] ?? null);
31
+ } })) }));
25
32
  }
@@ -40,7 +40,8 @@ a.btn.ghost { background: transparent; color: var(--ink-muted); border-color: va
40
40
  .form-field-label-row > :not(.form-field-label-hidden) ~ .help-tip { margin-inline-start: var(--space-2h); }
41
41
  .form-field-label-row > .help-tip { vertical-align: -0.2em; }
42
42
  .form-field.is-required > .form-field-label::after { content: "*" / ""; margin-left: var(--space-1h); color: var(--status-critical); }
43
- .form-field-hint { margin: 0; font-size: var(--text-sm); line-height: 1.45; color: var(--ink-muted); }
43
+ /* A hint reads at a measure: under a field in a wide room it stood as one line of 150 characters. */
44
+ .form-field-hint { margin: 0; max-width: 70ch; font-size: var(--text-sm); line-height: 1.45; color: var(--ink-muted); }
44
45
  .form-field-problem { margin: 0; font-size: var(--text-sm); line-height: 1.45; color: var(--status-critical); overflow-wrap: anywhere; }
45
46
  .form-field-compact { gap: var(--space-2); }
46
47
  /* A field is as wide as its answer (docs/design.md, Forms): a count, an amount, a day and a time are a few characters
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/ui",
3
- "version": "1.0.0-rc.36",
3
+ "version": "1.0.0-rc.38",
4
4
  "description": "The standalone React primitives both shells are drawn with: Modal, DropMenu, Dropdown, Typeahead, Button, Field, Icon and DateField over Base UI, Switch, Tabs, Drawer, Popover, Avatar, Pagination, Carousel, Resizable, ScrollArea and Tooltip, the form controls built on them (text, masked, money and sensitive boxes, listboxes, choices, slider, progress and action bar; Preview), the landing hero's blocks (badge, photo tiles, icon rows; Preview), their tokens and stylesheet, and the zoom-aware ruler their popups are placed by.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {