@dloizides/ui-forms 1.25.1 → 1.27.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.27.0
4
+
5
+ DATE-INPUT-1 "Every date or date-time field uses the shared input".
6
+
7
+ - New `DateField` (`YYYY-MM-DD`) and `DateTimeField` (`YYYY-MM-DDTHH:mm`), rendered through `Field`; a real `<input type>` on web.
8
+
9
+ ## 1.26.0
10
+
11
+ INVOICE-3 "Invoice interface over a user-chosen folder": owner picks.
12
+
13
+ - `SelectControl` trigger fills with `surfaceElevated`, like an editable field, so it differs from read-only.
14
+ - Read-only `useThemedInput` draws the rest border, so the box shows on a form of the same fill.
15
+ - Placeholder is solid `textSecondary`: 0.6 alpha measured 2.38 against the 4.5 AA floor.
16
+ - `FormField` gains `inputRef`.
17
+
3
18
  ## 1.25.0
4
19
 
5
20
  INVOICE-3 "Invoice interface over a user-chosen folder": extracted from invoice-web.
package/dist/index.d.mts CHANGED
@@ -438,8 +438,10 @@ interface FormFieldProps extends Omit<TextInputProps, 'style'> {
438
438
  recentKey?: string;
439
439
  /** Cap on remembered values when {@link recentKey} is set (most-recent-first). Default 10. */
440
440
  recentMax?: number;
441
+ /** Reaches the input, for focusing it without scrolling the page. Not forwarded when `recentKey` is set. */
442
+ inputRef?: React.Ref<TextInput>;
441
443
  }
442
- declare const FormField: ({ label, labelHidden, required, error, containerStyle, recentKey, recentMax, ...textInputProps }: FormFieldProps) => React.ReactElement;
444
+ declare const FormField: ({ label, labelHidden, required, error, containerStyle, recentKey, recentMax, inputRef, ...textInputProps }: FormFieldProps) => React.ReactElement;
443
445
 
444
446
  /**
445
447
  * `ThemedTextInput` — the shared, readable + lively text-input primitive. A thin `<TextInput>`
@@ -869,6 +871,31 @@ interface DateRangeControlProps {
869
871
  }
870
872
  declare function DateRangeControl({ value, onChange, onSubmit, fromLabel, toLabel, fromPlaceholder, toPlaceholder, accessibilityHint, style, testID, }: DateRangeControlProps): React.ReactElement;
871
873
 
874
+ interface DateFieldProps {
875
+ /** PRE-LOCALIZED label; also the accessible name. */
876
+ label: string;
877
+ /** `YYYY-MM-DD` for `DateField`, `YYYY-MM-DDTHH:mm` for `DateTimeField`; empty is `''`. */
878
+ value: string;
879
+ onChange: (value: string) => void;
880
+ /** Runs on Enter. */
881
+ onSubmit?: () => void;
882
+ accessibilityHint: string;
883
+ testID: string;
884
+ required?: boolean;
885
+ hint?: string;
886
+ error?: string;
887
+ disabled?: boolean;
888
+ min?: string;
889
+ max?: string;
890
+ }
891
+ type DateTimeFieldProps = DateFieldProps;
892
+
893
+ /** A labelled calendar date: takes and emits `YYYY-MM-DD`, empty is `''`. */
894
+ declare function DateField(props: DateFieldProps): React.ReactElement;
895
+
896
+ /** A labelled local date and time: takes and emits `YYYY-MM-DDTHH:mm`, empty is `''`. */
897
+ declare function DateTimeField(props: DateTimeFieldProps): React.ReactElement;
898
+
872
899
  /**
873
900
  * `AnchoredMenu` — the floating option list shared by `SelectControl` and `TypeaheadControl`.
874
901
  *
@@ -1183,4 +1210,4 @@ interface UploadWithLinkFieldProps {
1183
1210
  /** An image field: preview, an upload control, and a link input revealed on request. */
1184
1211
  declare const UploadWithLinkField: ({ value, onChange, labels, uploadControl, testID, disabled, previewSize, }: UploadWithLinkFieldProps) => React.ReactElement;
1185
1212
 
1186
- export { AlignToControl, type AlignToControlProps, AnchoredMenu, type AnchoredMenuColors, type AnchoredMenuListbox, type AnchoredMenuProps, type ChipOption, ChipSelector, type ChipSelectorProps, type ChipSingleSelectRole, type ChipVariant, type ControlOption, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateRangeControl, type DateRangeControlProps, type DateRangeValue, Field, type FieldChildContext, type FieldChildren, type FieldLabelVariant, type FieldMarker, type FieldProps, type FieldSpacing, type Focusable, type FocusableRefs, FormActions, type FormActionsProps, FormCell, type FormCellProps, FormCheckbox, type FormCheckboxProps, FormField, type FormFieldProps, FormGrid, type FormGridProps, FormSection, type FormSectionProps, FormStatusLine, type FormStatusLineProps, FormSwitch, type FormSwitchProps, type GroupSelection, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, type InlineFieldRowLayout, type InlineFieldRowProps, type RecentValues, SelectControl, type SelectControlProps, SelectField, type SelectFieldProps, type StepNeighbours, StepperNav, type StepperNavLabels, type StepperNavProps, type StepperStep, StepperTabs, type StepperTabsProps, type ThemedInput, ThemedTextInput, type ThemedTextInputProps, TypeaheadControl, type TypeaheadControlProps, type TypeaheadSearch, type TypeaheadSearchProps, UploadWithLinkField, type UploadWithLinkFieldProps, type UploadWithLinkLabels, type UseThemedInputOptions, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
1213
+ export { AlignToControl, type AlignToControlProps, AnchoredMenu, type AnchoredMenuColors, type AnchoredMenuListbox, type AnchoredMenuProps, type ChipOption, ChipSelector, type ChipSelectorProps, type ChipSingleSelectRole, type ChipVariant, type ControlOption, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, type DateFieldProps, DateRangeControl, type DateRangeControlProps, type DateRangeValue, DateTimeField, type DateTimeFieldProps, Field, type FieldChildContext, type FieldChildren, type FieldLabelVariant, type FieldMarker, type FieldProps, type FieldSpacing, type Focusable, type FocusableRefs, FormActions, type FormActionsProps, FormCell, type FormCellProps, FormCheckbox, type FormCheckboxProps, FormField, type FormFieldProps, FormGrid, type FormGridProps, FormSection, type FormSectionProps, FormStatusLine, type FormStatusLineProps, FormSwitch, type FormSwitchProps, type GroupSelection, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, type InlineFieldRowLayout, type InlineFieldRowProps, type RecentValues, SelectControl, type SelectControlProps, SelectField, type SelectFieldProps, type StepNeighbours, StepperNav, type StepperNavLabels, type StepperNavProps, type StepperStep, StepperTabs, type StepperTabsProps, type ThemedInput, ThemedTextInput, type ThemedTextInputProps, TypeaheadControl, type TypeaheadControlProps, type TypeaheadSearch, type TypeaheadSearchProps, UploadWithLinkField, type UploadWithLinkFieldProps, type UploadWithLinkLabels, type UseThemedInputOptions, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
package/dist/index.d.ts CHANGED
@@ -438,8 +438,10 @@ interface FormFieldProps extends Omit<TextInputProps, 'style'> {
438
438
  recentKey?: string;
439
439
  /** Cap on remembered values when {@link recentKey} is set (most-recent-first). Default 10. */
440
440
  recentMax?: number;
441
+ /** Reaches the input, for focusing it without scrolling the page. Not forwarded when `recentKey` is set. */
442
+ inputRef?: React.Ref<TextInput>;
441
443
  }
442
- declare const FormField: ({ label, labelHidden, required, error, containerStyle, recentKey, recentMax, ...textInputProps }: FormFieldProps) => React.ReactElement;
444
+ declare const FormField: ({ label, labelHidden, required, error, containerStyle, recentKey, recentMax, inputRef, ...textInputProps }: FormFieldProps) => React.ReactElement;
443
445
 
444
446
  /**
445
447
  * `ThemedTextInput` — the shared, readable + lively text-input primitive. A thin `<TextInput>`
@@ -869,6 +871,31 @@ interface DateRangeControlProps {
869
871
  }
870
872
  declare function DateRangeControl({ value, onChange, onSubmit, fromLabel, toLabel, fromPlaceholder, toPlaceholder, accessibilityHint, style, testID, }: DateRangeControlProps): React.ReactElement;
871
873
 
874
+ interface DateFieldProps {
875
+ /** PRE-LOCALIZED label; also the accessible name. */
876
+ label: string;
877
+ /** `YYYY-MM-DD` for `DateField`, `YYYY-MM-DDTHH:mm` for `DateTimeField`; empty is `''`. */
878
+ value: string;
879
+ onChange: (value: string) => void;
880
+ /** Runs on Enter. */
881
+ onSubmit?: () => void;
882
+ accessibilityHint: string;
883
+ testID: string;
884
+ required?: boolean;
885
+ hint?: string;
886
+ error?: string;
887
+ disabled?: boolean;
888
+ min?: string;
889
+ max?: string;
890
+ }
891
+ type DateTimeFieldProps = DateFieldProps;
892
+
893
+ /** A labelled calendar date: takes and emits `YYYY-MM-DD`, empty is `''`. */
894
+ declare function DateField(props: DateFieldProps): React.ReactElement;
895
+
896
+ /** A labelled local date and time: takes and emits `YYYY-MM-DDTHH:mm`, empty is `''`. */
897
+ declare function DateTimeField(props: DateTimeFieldProps): React.ReactElement;
898
+
872
899
  /**
873
900
  * `AnchoredMenu` — the floating option list shared by `SelectControl` and `TypeaheadControl`.
874
901
  *
@@ -1183,4 +1210,4 @@ interface UploadWithLinkFieldProps {
1183
1210
  /** An image field: preview, an upload control, and a link input revealed on request. */
1184
1211
  declare const UploadWithLinkField: ({ value, onChange, labels, uploadControl, testID, disabled, previewSize, }: UploadWithLinkFieldProps) => React.ReactElement;
1185
1212
 
1186
- export { AlignToControl, type AlignToControlProps, AnchoredMenu, type AnchoredMenuColors, type AnchoredMenuListbox, type AnchoredMenuProps, type ChipOption, ChipSelector, type ChipSelectorProps, type ChipSingleSelectRole, type ChipVariant, type ControlOption, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateRangeControl, type DateRangeControlProps, type DateRangeValue, Field, type FieldChildContext, type FieldChildren, type FieldLabelVariant, type FieldMarker, type FieldProps, type FieldSpacing, type Focusable, type FocusableRefs, FormActions, type FormActionsProps, FormCell, type FormCellProps, FormCheckbox, type FormCheckboxProps, FormField, type FormFieldProps, FormGrid, type FormGridProps, FormSection, type FormSectionProps, FormStatusLine, type FormStatusLineProps, FormSwitch, type FormSwitchProps, type GroupSelection, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, type InlineFieldRowLayout, type InlineFieldRowProps, type RecentValues, SelectControl, type SelectControlProps, SelectField, type SelectFieldProps, type StepNeighbours, StepperNav, type StepperNavLabels, type StepperNavProps, type StepperStep, StepperTabs, type StepperTabsProps, type ThemedInput, ThemedTextInput, type ThemedTextInputProps, TypeaheadControl, type TypeaheadControlProps, type TypeaheadSearch, type TypeaheadSearchProps, UploadWithLinkField, type UploadWithLinkFieldProps, type UploadWithLinkLabels, type UseThemedInputOptions, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
1213
+ export { AlignToControl, type AlignToControlProps, AnchoredMenu, type AnchoredMenuColors, type AnchoredMenuListbox, type AnchoredMenuProps, type ChipOption, ChipSelector, type ChipSelectorProps, type ChipSingleSelectRole, type ChipVariant, type ControlOption, DEFAULT_MAX_RECENTS, DEFAULT_OPTIONAL_LABEL, DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS, DEFAULT_TYPEAHEAD_MIN_CHARS, DateField, type DateFieldProps, DateRangeControl, type DateRangeControlProps, type DateRangeValue, DateTimeField, type DateTimeFieldProps, Field, type FieldChildContext, type FieldChildren, type FieldLabelVariant, type FieldMarker, type FieldProps, type FieldSpacing, type Focusable, type FocusableRefs, FormActions, type FormActionsProps, FormCell, type FormCellProps, FormCheckbox, type FormCheckboxProps, FormField, type FormFieldProps, FormGrid, type FormGridProps, FormSection, type FormSectionProps, FormStatusLine, type FormStatusLineProps, FormSwitch, type FormSwitchProps, type GroupSelection, INLINE_FIELD_ROW_MIN_WIDTH, InlineFieldRow, type InlineFieldRowLayout, type InlineFieldRowProps, type RecentValues, SelectControl, type SelectControlProps, SelectField, type SelectFieldProps, type StepNeighbours, StepperNav, type StepperNavLabels, type StepperNavProps, type StepperStep, StepperTabs, type StepperTabsProps, type ThemedInput, ThemedTextInput, type ThemedTextInputProps, TypeaheadControl, type TypeaheadControlProps, type TypeaheadSearch, type TypeaheadSearchProps, UploadWithLinkField, type UploadWithLinkFieldProps, type UploadWithLinkLabels, type UseThemedInputOptions, controlStyles, groupAriaChecked, inlineFieldRowLayout, isUnmatched, resolveGroupSelection, resolveStepNeighbours, suggestOptions, toggleGroupSelection, useFocusFirstInvalid, useKeepInView, useRecentValues, useThemedInput };
package/dist/index.js CHANGED
@@ -813,7 +813,6 @@ var TRANSITION_DURATION = "0.14s";
813
813
  var TRANSITION_TIMING = "ease";
814
814
  var NO_RING = { outlineWidth: 0 };
815
815
  var HOVER_BORDER_ALPHA = 0.22;
816
- var PLACEHOLDER_ALPHA = 0.6;
817
816
  var HEX_RADIX = 16;
818
817
  var HEX_SHORT_LENGTH = 4;
819
818
  var HEX_FULL_LENGTH = 7;
@@ -863,8 +862,7 @@ function useThemedInput(options = {}) {
863
862
  const restBorder = hasError ? errorColor : colors.border;
864
863
  const focusBorder = hasError ? errorColor : primary;
865
864
  const editableBorder = isFocused ? focusBorder : isHovered ? withAlpha(colors.text, HOVER_BORDER_ALPHA) : restBorder;
866
- const readOnlyBorder = hasError ? errorColor : colors.surface;
867
- const borderColor = editable ? editableBorder : readOnlyBorder;
865
+ const borderColor = editable ? editableBorder : restBorder;
868
866
  const editableFill = isFocused ? colors.surface : colors.surfaceElevated;
869
867
  const backgroundColor = editable ? editableFill : colors.surface;
870
868
  const base = { color: editable ? colors.text : colors.textSecondary, borderColor, backgroundColor };
@@ -901,7 +899,7 @@ function useThemedInput(options = {}) {
901
899
  );
902
900
  return {
903
901
  style,
904
- placeholderTextColor: withAlpha(colors.textSecondary, PLACEHOLDER_ALPHA),
902
+ placeholderTextColor: colors.textSecondary,
905
903
  isFocused,
906
904
  isHovered,
907
905
  focusBind,
@@ -1144,6 +1142,7 @@ var FormField = ({
1144
1142
  containerStyle,
1145
1143
  recentKey,
1146
1144
  recentMax,
1145
+ inputRef,
1147
1146
  ...textInputProps
1148
1147
  }) => /* @__PURE__ */ jsxRuntime.jsx(
1149
1148
  Field,
@@ -1163,7 +1162,7 @@ var FormField = ({
1163
1162
  testID: "form-field-input",
1164
1163
  ...textInputProps
1165
1164
  };
1166
- return recentKey !== void 0 && recentKey !== "" ? /* @__PURE__ */ jsxRuntime.jsx(RecentInputField, { label, recentKey, recentMax, ...inputProps }) : /* @__PURE__ */ jsxRuntime.jsx(ThemedTextInput, { ...inputProps });
1165
+ return recentKey !== void 0 && recentKey !== "" ? /* @__PURE__ */ jsxRuntime.jsx(RecentInputField, { label, recentKey, recentMax, ...inputProps }) : /* @__PURE__ */ jsxRuntime.jsx(ThemedTextInput, { ref: inputRef, ...inputProps });
1167
1166
  }
1168
1167
  }
1169
1168
  );
@@ -1744,7 +1743,7 @@ function SelectControl({
1744
1743
  "aria-expanded": isOpen,
1745
1744
  "aria-labelledby": labelledById,
1746
1745
  onPress: toggle,
1747
- style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surface }],
1746
+ style: [controlStyles.selectTrigger, { borderColor: colors.border, backgroundColor: colors.surfaceElevated }],
1748
1747
  testID: `${testID}-trigger`,
1749
1748
  children: [
1750
1749
  /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { numberOfLines: 1, style: [controlStyles.selectTriggerText, { color: value === "" ? colors.textSecondary : colors.text }], children: selectedLabel }),
@@ -2117,6 +2116,86 @@ function DateRangeControl({
2117
2116
  )
2118
2117
  ] });
2119
2118
  }
2119
+ var NATIVE_INPUT_BOX = {
2120
+ borderStyle: "solid",
2121
+ boxSizing: "border-box",
2122
+ fontFamily: "inherit",
2123
+ width: "100%"
2124
+ };
2125
+ function buildNativeInputStyle(themed) {
2126
+ const { paddingHorizontal, paddingVertical, ...box } = reactNative.StyleSheet.flatten(controlStyles.input);
2127
+ return {
2128
+ ...box,
2129
+ ...themed,
2130
+ ...NATIVE_INPUT_BOX,
2131
+ paddingBlock: paddingVertical,
2132
+ paddingInline: paddingHorizontal
2133
+ };
2134
+ }
2135
+ function WebDateInput({ fieldProps, context, webInputType }) {
2136
+ const { label, value, onChange, onSubmit, accessibilityHint, testID, required, disabled = false, min, max } = fieldProps;
2137
+ const { style, focusBind, hoverBind } = useThemedInput({ hasError: context.hasError, editable: !disabled });
2138
+ const webA11y = webFieldA11y({
2139
+ describedById: context.describedById,
2140
+ hasError: context.hasError,
2141
+ required
2142
+ });
2143
+ const handleChange = (event) => onChange(event.target.value);
2144
+ const handleKeyDown = (event) => {
2145
+ if (event.key !== "Enter" || onSubmit === void 0) return;
2146
+ event.preventDefault();
2147
+ onSubmit();
2148
+ };
2149
+ return /* @__PURE__ */ jsxRuntime.jsx(
2150
+ "input",
2151
+ {
2152
+ ...webA11y,
2153
+ ...hoverBind,
2154
+ ...focusBind,
2155
+ "aria-label": label,
2156
+ "data-testid": testID,
2157
+ disabled,
2158
+ id: context.controlId,
2159
+ max,
2160
+ min,
2161
+ style: buildNativeInputStyle(style),
2162
+ title: accessibilityHint,
2163
+ type: webInputType,
2164
+ value,
2165
+ onChange: handleChange,
2166
+ onKeyDown: handleKeyDown
2167
+ }
2168
+ );
2169
+ }
2170
+ var IS_WEB7 = reactNative.Platform.OS === "web";
2171
+ function renderNativeInput(fieldProps, context) {
2172
+ return /* @__PURE__ */ jsxRuntime.jsx(
2173
+ ThemedTextInput,
2174
+ {
2175
+ accessibilityHint: fieldProps.accessibilityHint,
2176
+ accessibilityLabel: fieldProps.label,
2177
+ describedById: context.describedById,
2178
+ editable: fieldProps.disabled !== true,
2179
+ hasError: context.hasError,
2180
+ id: context.controlId,
2181
+ requiredField: fieldProps.required,
2182
+ testID: fieldProps.testID,
2183
+ value: fieldProps.value,
2184
+ onChangeText: fieldProps.onChange,
2185
+ onSubmitEditing: fieldProps.onSubmit
2186
+ }
2187
+ );
2188
+ }
2189
+ function TemporalField({ fieldProps, webInputType }) {
2190
+ const { label, required, hint, error } = fieldProps;
2191
+ return /* @__PURE__ */ jsxRuntime.jsx(Field, { error, hint, label, required, children: (context) => IS_WEB7 ? /* @__PURE__ */ jsxRuntime.jsx(WebDateInput, { context, fieldProps, webInputType }) : renderNativeInput(fieldProps, context) });
2192
+ }
2193
+ function DateField(props) {
2194
+ return /* @__PURE__ */ jsxRuntime.jsx(TemporalField, { fieldProps: props, webInputType: "date" });
2195
+ }
2196
+ function DateTimeField(props) {
2197
+ return /* @__PURE__ */ jsxRuntime.jsx(TemporalField, { fieldProps: props, webInputType: "datetime-local" });
2198
+ }
2120
2199
 
2121
2200
  // src/groupSelection/groupSelection.ts
2122
2201
  var NONE = 0;
@@ -2364,7 +2443,9 @@ exports.DEFAULT_MAX_RECENTS = DEFAULT_MAX_RECENTS;
2364
2443
  exports.DEFAULT_OPTIONAL_LABEL = DEFAULT_OPTIONAL_LABEL;
2365
2444
  exports.DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS = DEFAULT_TYPEAHEAD_MAX_SUGGESTIONS;
2366
2445
  exports.DEFAULT_TYPEAHEAD_MIN_CHARS = DEFAULT_TYPEAHEAD_MIN_CHARS;
2446
+ exports.DateField = DateField;
2367
2447
  exports.DateRangeControl = DateRangeControl;
2448
+ exports.DateTimeField = DateTimeField;
2368
2449
  exports.Field = Field;
2369
2450
  exports.FormActions = FormActions;
2370
2451
  exports.FormCell = FormCell;