@tfn-design/design-system 0.4.1 → 0.4.2
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/accordion/web/ds-accordion.js +2 -2
- package/dist/button/web/ds-button.js +1 -1
- package/dist/check-option/web/ds-check-option.js +1 -1
- package/dist/data-table/web/data-table-theme.css +32 -7
- package/dist/date-field/web/ds-date-field.d.ts +5 -2
- package/dist/date-field/web/ds-date-field.js +1 -1
- package/dist/date-input/web/ds-date-input.d.ts +6 -3
- package/dist/date-input/web/ds-date-input.js +1 -1
- package/dist/field-rules/field-rules.d.ts +16 -2
- package/dist/field-rules/field-rules.js +8 -2
- package/dist/form-field-group/form-field-group.d.ts +9 -0
- package/dist/form-field-group/form-field-group.js +1 -0
- package/dist/form-field-group/web/ds-form-field-group.js +2 -2
- package/dist/geo/geo.js +14 -1
- package/dist/geofence-editor/geofence-editor.d.ts +25 -0
- package/dist/geofence-editor/geofence-editor.js +14 -0
- package/dist/geofence-editor/web/ds-geofence-editor.d.ts +4 -1
- package/dist/geofence-editor/web/ds-geofence-editor.js +29 -12
- package/dist/index.d.ts +11 -11
- package/dist/index.js +5 -5
- package/dist/input/web/ds-input.js +4 -3
- package/dist/map/web/ds-map-names.d.ts +5 -0
- package/dist/map/web/ds-map-names.js +10 -0
- package/dist/map/web/ds-map.d.ts +4 -1
- package/dist/map/web/ds-map.js +5 -3
- package/dist/map/web/map-provider.d.ts +6 -0
- package/dist/number-field/native/ds-number-field.d.ts +1 -1
- package/dist/number-field/native/ds-number-field.js +10 -6
- package/dist/number-field/number-field.d.ts +28 -6
- package/dist/number-field/number-field.js +5 -2
- package/dist/number-field/web/ds-number-field.d.ts +1 -1
- package/dist/number-field/web/ds-number-field.js +10 -6
- package/dist/phone-field/phone-field.d.ts +9 -1
- package/dist/phone-field/phone-field.js +11 -1
- package/dist/phone-field/web/ds-phone-field.d.ts +2 -2
- package/dist/phone-field/web/ds-phone-field.js +21 -5
- package/dist/sheet/sheet.d.ts +9 -0
- package/dist/sheet/sheet.js +1 -0
- package/dist/sheet/web/ds-sheet.d.ts +9 -2
- package/dist/sheet/web/ds-sheet.js +4 -2
- package/dist/tabs/tabs.d.ts +15 -8
- package/dist/tabs/tabs.js +13 -3
- package/dist/tabs/web/ds-tabs.js +6 -4
- package/dist/web.d.ts +2 -1
- package/dist/web.js +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ export { BUTTON_LABEL_SIZE_RECIPES, BUTTON_LABEL_SIZES, BUTTON_RADII, BUTTON_SHA
|
|
|
3
3
|
export { COMPACT_MIN_HEIGHT_PX, DENSITIES, DENSITY_ATTRIBUTE } from './scale';
|
|
4
4
|
export { CHECKBOX_DISABLED_SPEC, CHECKBOX_INVALID_BORDER, CHECKBOX_SIZE_SPECS, CHECKBOX_SIZES, CHECKBOX_STATE_SPECS, CHECKBOX_STATES, checkboxSpec, checkboxState, } from './checkbox/checkbox';
|
|
5
5
|
export { INPUT_SIZE_SPECS, INPUT_SIZES, INPUT_STATE_SPECS, INPUT_STATES, inputSpec, TEXTAREA_LINE_HEIGHT, TEXTAREA_MIN_HEIGHT_EM, TEXTAREA_PADDING_Y_STEP, TEXTAREA_RESIZE, TEXTAREA_MAX_ROWS, textareaCountNearAt, textareaCountText, textareaCountDescription, textareaCountLeft, textareaCountAnnouncement, TEXTAREA_COPY, } from './input/input';
|
|
6
|
-
export { FIELD_CHECK_SILENT, FIELD_MASK_TOKENS, fieldCheck, fieldCheckIsError, fieldCheckIsSilent, fieldChecksEqual, fieldFormatter, fieldMaskCaretPosition, fieldMaskDisplay, fieldMaskFormatter, fieldMaskIsComplete, fieldMaskLength, fieldMaskParts, fieldMaskValue, fieldShouldCheckOnBlur, fieldShouldCheckOnChange, fieldTold, fieldValueCharsBefore, } from './field-rules/field-rules';
|
|
6
|
+
export { FIELD_CHECK_SILENT, FIELD_MASK_TOKENS, fieldCheck, fieldCheckIsError, fieldCheckIsSilent, fieldChecksEqual, fieldFormatter, fieldMaskCaretPosition, fieldMaskDisplay, fieldMaskFormatter, fieldMaskIsComplete, fieldMaskLength, fieldMaskParts, fieldMaskValue, fieldMovedOn, fieldShouldCheckOnBlur, fieldShouldCheckOnChange, fieldTold, fieldValueCharsBefore, } from './field-rules/field-rules';
|
|
7
7
|
export { MEASURE_CHAR_PX, MEASURE_MAX_CHARS, MEASURE_MAX_PX, MEASURE_MIN_CHARS, MEASURE_MIN_PX, } from './measure';
|
|
8
8
|
export { isTone, TONES, TONE_SPECS, toneSpec } from './tone';
|
|
9
9
|
export { ALERT_DEFAULT_SIZE, ALERT_LIVE, ALERT_RADIUS, ALERT_SIZE_SPECS, ALERT_SIZES, ALERT_TONE_ICONS, ALERT_DOM_PLATFORM, alertAnnouncement, alertSpec, alertSpokenText, TONE_IN_WORDS_GUIDANCE, } from './alert/alert';
|
|
@@ -51,7 +51,7 @@ export { TOAST_DEFAULT_STATE, TOAST_GAP, TOAST_STATES, toastBottom, toastSpec, }
|
|
|
51
51
|
export { METER_SIZES, meterChipPlacement, meterSpec, meterTargetPercent } from './meter/meter';
|
|
52
52
|
export { PROPORTION_BAND_KINDS, PROPORTION_BAND_STOPPED_FILL, proportionBandSpec, visibleProportionBands, } from './proportion-bar/proportion-bar';
|
|
53
53
|
export { METRIC_SIZES, METRIC_SIZE_SPECS, metricSpec } from './metric/metric';
|
|
54
|
-
export { DELTA_MINUS, DELTA_SENTIMENTS, DELTA_SENTIMENT_SPECS, deltaChange, deltaHasBasis, deltaSpec, deltaText, } from './delta/delta';
|
|
54
|
+
export { DELTA_MINUS, DELTA_SENTIMENTS, DELTA_SENTIMENT_SPECS, deltaChange, deltaHasBasis, deltaSpec, deltaText, deltaDirection, } from './delta/delta';
|
|
55
55
|
export { isStatTileFootDelta, statTileSpec } from './stat-tile/stat-tile';
|
|
56
56
|
export { METRIC_CARD_CHART_HEIGHT_PX, METRIC_CARD_STATES, metricCardSpec } from './metric-card/metric-card';
|
|
57
57
|
export { FIGURE_TYPE, figureLabel, figureSpec } from './figure/figure';
|
|
@@ -60,18 +60,18 @@ export { LIST_ROW_ACTION_REVEALS, LIST_ROW_CARD_EDGE, LIST_ROW_CARD_SURFACE, LIS
|
|
|
60
60
|
export { VALUE_ROW_TONES, valueRowLabel, valueRowSpec } from './value-row/value-row';
|
|
61
61
|
export { factSpec } from './fact/fact';
|
|
62
62
|
export { DROPDOWN_MENU_BORDER_ROLES, DROPDOWN_MENU_ITEM_HOVER_SURFACE_ROLES, DROPDOWN_MENU_ITEM_INK_ROLES, DROPDOWN_MENU_ITEM_SPECS, DROPDOWN_MENU_NEEDS_A_NAME, DROPDOWN_MENU_NEEDS_A_RELATIVE_ANCHOR, DROPDOWN_MENU_NEEDS_A_TRIGGER, DROPDOWN_MENU_SURFACE_ROLES, dropdownMenuItemSpec, dropdownMenuSpec, DROPDOWN_MENU_DANGER_SECTION, DROPDOWN_MENU_DISABLED_INK, DROPDOWN_MENU_DISABLED_INK_ROLES, DROPDOWN_MENU_KEY_INTENTS, DROPDOWN_MENU_OPEN_ENDS, dropdownMenuAriaShortcut, dropdownMenuHasSubmenu, dropdownMenuInitialIndex, dropdownMenuIsTypeaheadKey, dropdownMenuTriggerOpenEnd, dropdownMenuItemStateSpec, dropdownMenuItemRole, dropdownMenuItemStaysOpen, dropdownMenuChoiceItems, DROPDOWN_MENU_CHECK_INK, DROPDOWN_MENU_TYPEAHEAD_RESET_MS, dropdownMenuKeyIntent, dropdownMenuMove, dropdownMenuRowIsDestructive, dropdownMenuSections, dropdownMenuTypeahead, dropdownMenuWalk, isDropdownMenuSeparator, } from './dropdown-menu/dropdown-menu';
|
|
63
|
-
export { SHEET_BACKDROP_ROLES, SHEET_BORDER_ROLES, SHEET_CLOSE_INK_ROLES, SHEET_CLOSE_SURFACE_ROLES, SHEET_DIRTY_CLOSE_IGNORED, SHEET_SCRIM_OPACITY, SHEET_SCRIM_SOLID_OPACITY, SHEET_SURFACE_ROLES, SHEET_TITLE_INK_ROLES, sheetSpec, } from './sheet/sheet';
|
|
63
|
+
export { SHEET_BACKDROP_ROLES, SHEET_BORDER_ROLES, SHEET_CLOSE_INK_ROLES, SHEET_CLOSE_SURFACE_ROLES, SHEET_DIRTY_CLOSE_IGNORED, SHEET_SCRIM_OPACITY, SHEET_SCRIM_SOLID_OPACITY, SHEET_SURFACE_ROLES, SHEET_TITLE_INK_ROLES, sheetSpec, SHEET_INITIAL_FOCUS, } from './sheet/sheet';
|
|
64
64
|
export { BOTTOM_NAV_ACTION_RISE, BOTTOM_NAV_ACTION_SIZE, BOTTOM_NAV_CONTAINER_BORDER_ROLES, BOTTOM_NAV_CONTAINER_SURFACE_ROLES, BOTTOM_NAV_COUNT_MAX, BOTTOM_NAV_CURRENT_EDGE_ROLES, BOTTOM_NAV_CURRENT_WASH_ROLES, BOTTOM_NAV_DEFAULT_STATE, BOTTOM_NAV_HEIGHT, BOTTOM_NAV_ICON_SIZE, BOTTOM_NAV_ICON_STROKE, BOTTOM_NAV_ICON_ROLES, BOTTOM_NAV_LABEL_MAX_SCALE, BOTTOM_NAV_STATES, bottomNavClearance, bottomNavCount, bottomNavItemName, bottomNavItemSpec, bottomNavSpec, } from './bottom-nav/bottom-nav';
|
|
65
65
|
export { TASK_SHELL_ASIDE_SIDES, TASK_SHELL_ASIDE_WIDTH_PX, TASK_SHELL_BAR_MIN_HEIGHT_PX, TASK_SHELL_INSET_PX, TASK_SHELL_NEEDS_A_LABEL, TASK_SHELL_SPLIT_WIDTH_PX, TASK_SHELL_CLOSE_LABEL, TASK_SHELL_BACK_LABEL, taskShellSpec, taskShellStepText, taskShellStepFraction, } from './task-shell/task-shell';
|
|
66
66
|
export { APP_SHELL_CONTENT_MAX_WIDTH_PX, APP_SHELL_EDGE, APP_SHELL_EDGE_ROLES, APP_SHELL_GUTTER_PX, APP_SHELL_RAIL_MIN_WIDTH_PX, APP_SHELL_REGIONS, APP_SHELL_SURFACE, APP_SHELL_SURFACE_ROLES, appShellSpec, } from './app-shell/app-shell';
|
|
67
67
|
export { SIDE_NAV_CURRENT_ICON, SIDE_NAV_CURRENT_INK, SIDE_NAV_EDGE, SIDE_NAV_EDGE_ROLES, SIDE_NAV_HEADING_INK, SIDE_NAV_HOVER_SURFACE, SIDE_NAV_ICON_ROLES, SIDE_NAV_ICON_SIZE, SIDE_NAV_INK_ROLES, SIDE_NAV_LOGO_SIZE, SIDE_NAV_RAIL_WIDTH_PX, SIDE_NAV_REST_ICON, SIDE_NAV_REST_INK, SIDE_NAV_ROW_HEIGHT_PX, SIDE_NAV_SECTION_PLACEMENTS, SIDE_NAV_SURFACE, SIDE_NAV_SURFACE_ROLES, SIDE_NAV_WIDTH_PX, SIDE_NAV_WIDTH_STEP_PX, clampSideNavWidth, isSideNavGroup, isSideNavLogo, isSideNavMenuSeparator, sideNavCollapseLabel, sideNavExpandedFor, sideNavFlyoutOpensFromKey, sideNavGroupContains, sideNavGroupIsCurrent, sideNavLinkName, sideNavMenuHasSubmenu, sideNavMenuInitialIndex, sideNavMenuItems, sideNavMenuKeyIntent, sideNavMenuOrder, sideNavMonogram, sideNavMoreLabel, sideNavNotificationsMark, sideNavNotificationsName, sideNavRailMark, sideNavRevealScroll, sideNavRowSpec, sideNavSectionsByPlacement, sideNavShortcutAria, sideNavSpec, sideNavWidthAfterKey, toggleSideNavGroup, toggleSideNavSection, SIDE_NAV_NOTIFICATIONS_MAX, SIDE_NAV_LABEL_DOTS_MAX, sideNavNotificationsBadge, sideNavRowPress, } from './side-nav/side-nav';
|
|
68
68
|
export { selectFilter, selectGroupedOptions, selectInitialActiveIndex, selectIsSearchable, selectMoveIndex, selectSpec, selectTypeaheadIndex, selectTypeaheadSearch, SELECT_LONG_LIST_NEEDS_SEARCH_COPY, SELECT_PLACEHOLDER_IS_NOT_AN_OPTION, SELECT_SEARCH_THRESHOLD, SELECT_TYPEAHEAD_RESET_MS, } from './select/select';
|
|
69
|
-
export { phoneFieldCaretPosition, phoneFieldDigits, phoneFieldFormat, phoneFieldIsComplete, phoneFieldMaxDigits, phoneFieldNationalDigits, phoneFieldSpec, PHONE_FIELD_CODE_SCALE, PHONE_FIELD_CODE_WEIGHT, PHONE_FIELD_FLAG_SCALE, PHONE_FIELD_HAS_NO_VALID_STATE, PHONE_FIELD_PREFIX_IS_DECORATION, } from './phone-field/phone-field';
|
|
69
|
+
export { phoneFieldCaretPosition, phoneFieldDigits, phoneFieldFormat, phoneFieldIsComplete, phoneFieldMaxDigits, phoneFieldNationalDigits, phoneFieldSpec, PHONE_FIELD_CODE_SCALE, PHONE_FIELD_CODE_WEIGHT, PHONE_FIELD_FLAG_SCALE, PHONE_FIELD_HAS_NO_VALID_STATE, PHONE_FIELD_PREFIX_IS_DECORATION, phoneFieldCountryFormat, phoneFieldCountryIsComplete, phoneFieldCountryLabel, phoneFieldCountryOf, phoneFieldCodeIsOpen, } from './phone-field/phone-field';
|
|
70
70
|
export { POPOVER_ANCHOR_GAP_PX, POPOVER_BORDER, POPOVER_FOOTER_BORDER, POPOVER_INK, POPOVER_MAX_HEIGHT_REM, POPOVER_RADIUS_PX, POPOVER_ROLES, POPOVER_SURFACE, POPOVER_VIEWPORT_MARGIN_PX, POPOVER_VIEWPORT_RESERVE_PX, POPOVER_WIDTHS, POPOVER_WIDTH_PX, POPOVER_Z_INDEX, popoverSpec, } from './popover/popover';
|
|
71
71
|
export { assertTooltipCarriesNoTaskRequiredContent, TOOLTIP_BORDER, TOOLTIP_FORBIDS_TASK_REQUIRED_CONTENT, TOOLTIP_GAP_PX, TOOLTIP_INK, TOOLTIP_INTERACTIVE_TAGS, TOOLTIP_IS_WEB_ONLY, TOOLTIP_SC_1_4_13, TOOLTIP_MAX_WIDTH_CH, TOOLTIP_RADIUS_PX, TOOLTIP_ROLES, TOOLTIP_SURFACE, TOOLTIP_Z_INDEX, tooltipSpec, } from './tooltip/tooltip';
|
|
72
72
|
export { DRAWER_AXES, DRAWER_BORDER, DRAWER_CLOSE_INK, DRAWER_CLOSE_SURFACE, DRAWER_COUNT_IS_A_SLOT, DRAWER_DEFAULT_MODAL, DRAWER_DIRECTIONS, DRAWER_EXTENT_PX, DRAWER_FLOATING_GUTTER, DRAWER_MOTION, DRAWER_HEADING_LEVELS, DRAWER_INK, DRAWER_ROLES, DRAWER_SCRIM, DRAWER_SCRIM_OPACITY, DRAWER_SCRIM_SOLID_OPACITY, DRAWER_SCRIM_Z_INDEX, DRAWER_SCROLLS_ITS_BODY, DRAWER_SIZE_EXTENT_PX, DRAWER_SIZES, DRAWER_SUB_INK, DRAWER_SURFACE, DRAWER_TITLE_INK, DRAWER_WIDTH_PX, DRAWER_Z_INDEX, DRAWER_COPY, drawerPeekAnnouncement, drawerSpec, } from './drawer/drawer';
|
|
73
73
|
export { DIALOG_BODY_INK, DIALOG_BORDER, DIALOG_DEFAULT_HEADING_LEVEL, DIALOG_DOCKS_BELOW, DIALOG_FOOTER_IS_A_SLOT, DIALOG_HEADING_LEVELS, DIALOG_INK, DIALOG_RADIUS_PX, DIALOG_ROLES, DIALOG_SCRIM, DIALOG_SCRIM_OPACITY, DIALOG_SCRIM_SOLID_OPACITY, DIALOG_SCRIM_Z_INDEX, DIALOG_SIZES, DIALOG_SURFACE, DIALOG_TITLE_INK, DIALOG_MIN_HEIGHT_PX, DIALOG_VIEWPORT_MARGIN_PX, DIALOG_VIEWPORT_RESERVE_PX, DIALOG_WIDTH_PX, DIALOG_Z_INDEX, dialogSpec, } from './dialog/dialog';
|
|
74
|
-
export { TAB_BORDER, TAB_REST_INK, TAB_CURRENT_INK, TAB_TINT_INK, TAB_CURRENT_TINT_PERCENT, TAB_HOVER_TINT_PERCENT, TAB_APPEARANCES, TAB_SELECTED_WEIGHT, TABS_KEYS, nextTabIndex, tabSpec, } from './tabs/tabs';
|
|
74
|
+
export { TAB_BORDER, TAB_REST_INK, TAB_CURRENT_INK, TAB_CHOSEN_FILL, TAB_CHOSEN_INK, TAB_TINT_INK, TAB_CURRENT_TINT_PERCENT, TAB_HOVER_TINT_PERCENT, TAB_APPEARANCES, TAB_SELECTED_WEIGHT, TABS_KEYS, nextTabIndex, tabSpec, } from './tabs/tabs';
|
|
75
75
|
export { RADIO_HOVER_BORDER_ROLE, RADIO_MARKER_BORDER_WIDTH, RADIO_MARKER_DIAMETER, RADIO_MARKER_DOT_DIAMETER, RADIO_MARKER_FACE_INSET, RADIO_MIN_HEIGHT, radioMarkerSpec, radioSpec, } from './radio/radio';
|
|
76
76
|
export { PAGE_HEAD_DESCRIPTION_INK, PAGE_HEAD_DESCRIPTION_MEASURE, PAGE_HEAD_MAX_ACTIONS, PAGE_HEAD_MAX_PRIMARY_ACTIONS, PAGE_HEAD_TITLE_INK, } from './page-head/page-head';
|
|
77
77
|
export { TOOLBAR_CONTROLS_GAP_PX, TOOLBAR_GAP_PX, TOOLBAR_SEARCH_MAX_WIDTH, TOOLBAR_SEARCH_MIN_WIDTH, } from './toolbar/toolbar';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useLayoutEffect, useRef, useState, } from 'react';
|
|
3
3
|
import { inputSpec, } from '../input';
|
|
4
|
-
import { FIELD_CHECK_SILENT, fieldCheck, fieldChecksEqual, fieldCheckIsError, fieldFormatter, fieldShouldCheckOnBlur, fieldShouldCheckOnChange, fieldTold, fieldValueCharsBefore, } from '../../field-rules/field-rules';
|
|
4
|
+
import { FIELD_CHECK_SILENT, fieldCheck, fieldChecksEqual, fieldCheckIsError, fieldFormatter, fieldMovedOn, fieldShouldCheckOnBlur, fieldShouldCheckOnChange, fieldTold, fieldValueCharsBefore, } from '../../field-rules/field-rules';
|
|
5
5
|
import { SUB_TOUCH_HEIGHTS } from '../../scale';
|
|
6
6
|
import { cn } from '../../lib/cn';
|
|
7
7
|
import { setsTypeRecipe } from '../../lib/sets-type';
|
|
@@ -118,9 +118,10 @@ export function DSInput({ size = 'md', invalid, disabled, className, mask, forma
|
|
|
118
118
|
if (validate === undefined || props.readOnly === true)
|
|
119
119
|
return;
|
|
120
120
|
const current = valueOf(event.target.value);
|
|
121
|
-
|
|
121
|
+
const movedOn = fieldMovedOn(event.target, event.relatedTarget);
|
|
122
|
+
if (!fieldShouldCheckOnBlur(current, told, movedOn))
|
|
122
123
|
return;
|
|
123
|
-
setTold(fieldTold(told, current));
|
|
124
|
+
setTold(fieldTold(told, current) || movedOn);
|
|
124
125
|
report(fieldCheck(current, validate));
|
|
125
126
|
};
|
|
126
127
|
const search = props.type === 'search';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** THE PLACE NAMES, AS A LAYER OF THEIR OWN. The ground is one picture under every layer, so a
|
|
2
|
+
* fence's edge ran through the names on it: Johannesburg and Rosebank were struck out. Put
|
|
3
|
+
* this after the fences and before the pins in a `DSMap` with `namesAbove`. Without an engine
|
|
4
|
+
* the ground has no names to lift and this draws nothing. */
|
|
5
|
+
export declare function DSMapNames(): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMapEngine, useMapView } from './map-provider';
|
|
3
|
+
const nothing = () => undefined;
|
|
4
|
+
export function DSMapNames() {
|
|
5
|
+
const { engine: Engine } = useMapEngine();
|
|
6
|
+
const { projection, viewport, base } = useMapView();
|
|
7
|
+
if (Engine === undefined)
|
|
8
|
+
return null;
|
|
9
|
+
return (_jsx("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 overflow-hidden rounded-card", children: _jsx(Engine, { viewport: viewport, base: base, paint: "names", width: projection.size.width, height: projection.size.height, onReady: nothing, onError: nothing }) }));
|
|
10
|
+
}
|
package/dist/map/web/ds-map.d.ts
CHANGED
|
@@ -35,6 +35,9 @@ export type DSMapProps = Omit<ComponentProps<'section'>, 'children' | 'role' | '
|
|
|
35
35
|
/** The layers drawn over the ground, markers, fences, popups. Each
|
|
36
36
|
* positions itself from the map's projection. */
|
|
37
37
|
children?: ReactNode;
|
|
38
|
+
/** Leaves the place names off the ground: a `DSMapNames` among the children paints them, so
|
|
39
|
+
* they stand over fences. Has no effect without a map engine. */
|
|
40
|
+
namesAbove?: boolean;
|
|
38
41
|
};
|
|
39
42
|
/** A pannable, zoomable map with layers that position themselves on it. */
|
|
40
|
-
export declare function DSMap({ label, viewport, onViewportChange, base, height, minZoom, maxZoom, fitTo, controls, scrollZoom, attribution, onPick, finishable, onRetry, children, className, style, ...props }: DSMapProps): import("react/jsx-runtime").JSX.Element;
|
|
43
|
+
export declare function DSMap({ label, viewport, onViewportChange, base, height, minZoom, maxZoom, fitTo, controls, scrollZoom, attribution, onPick, finishable, onRetry, children, namesAbove, className, style, ...props }: DSMapProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/map/web/ds-map.js
CHANGED
|
@@ -14,7 +14,7 @@ import { DSText } from '../../text/web/ds-text';
|
|
|
14
14
|
const GRATICULE_OPACITY = 0.5;
|
|
15
15
|
const WHEEL_ZOOM_PER_UNIT = 0.01;
|
|
16
16
|
const SHIFT_PAN_FACTOR = 3;
|
|
17
|
-
export function DSMap({ label, viewport, onViewportChange, base = 'standard', height = MAP_DEFAULT_HEIGHT, minZoom = MAP_MIN_ZOOM, maxZoom = MAP_MAX_ZOOM, fitTo, controls = true, scrollZoom = false, attribution, onPick, finishable = false, onRetry, children, className, style, ...props }) {
|
|
17
|
+
export function DSMap({ label, viewport, onViewportChange, base = 'standard', height = MAP_DEFAULT_HEIGHT, minZoom = MAP_MIN_ZOOM, maxZoom = MAP_MAX_ZOOM, fitTo, controls = true, scrollZoom = false, attribution, onPick, finishable = false, onRetry, children, namesAbove = false, className, style, ...props }) {
|
|
18
18
|
const { engine: Engine, tileUrl: tileSource, attribution: engineAttribution } = useMapEngine();
|
|
19
19
|
const tileUrl = mapTileTemplate(tileSource, base);
|
|
20
20
|
const surfaceRef = useRef(null);
|
|
@@ -129,11 +129,13 @@ export function DSMap({ label, viewport, onViewportChange, base = 'standard', he
|
|
|
129
129
|
}, [projection]);
|
|
130
130
|
const view = useMemo(() => ({
|
|
131
131
|
projection,
|
|
132
|
+
viewport,
|
|
133
|
+
base,
|
|
132
134
|
clientToGeo,
|
|
133
135
|
focusSurface: () => {
|
|
134
136
|
surfaceRef.current?.focus();
|
|
135
137
|
},
|
|
136
|
-
}), [projection, clientToGeo]);
|
|
138
|
+
}), [projection, viewport, base, clientToGeo]);
|
|
137
139
|
const drag = useRef(null);
|
|
138
140
|
useEffect(() => {
|
|
139
141
|
const node = surfaceRef.current;
|
|
@@ -284,7 +286,7 @@ export function DSMap({ label, viewport, onViewportChange, base = 'standard', he
|
|
|
284
286
|
const grid = measured && tileUrl === undefined && base === 'standard' ? mapGraticule(projection) : undefined;
|
|
285
287
|
const tiles = measured && tileUrl !== undefined ? mapVisibleTiles(viewport, size) : [];
|
|
286
288
|
const credit = engineAttribution === undefined ? (attribution) : attribution === undefined ? (engineAttribution) : (_jsxs(_Fragment, { children: [engineAttribution, " \u00B7 ", attribution] }));
|
|
287
|
-
return (_jsxs("section", { ...props, "aria-label": label, className: cn('map-frame relative isolate w-full rounded-card border border-border bg-muted', className), style: { ...style, height }, "data-base": base, "data-ground": ground, children: [_jsxs("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 overflow-hidden rounded-card", children: [Engine !== undefined ? (measured && (_jsx(Engine, { viewport: viewport, base: base, width: size.width, height: size.height, onReady: groundReady, onError: groundFailed }, attempt))) : (_jsxs(_Fragment, { children: [tileUrl !== undefined &&
|
|
289
|
+
return (_jsxs("section", { ...props, "aria-label": label, className: cn('map-frame relative isolate w-full rounded-card border border-border bg-muted', className), style: { ...style, height }, "data-base": base, "data-ground": ground, children: [_jsxs("div", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 overflow-hidden rounded-card", children: [Engine !== undefined ? (measured && (_jsx(Engine, { viewport: viewport, base: base, ...(namesAbove ? { paint: 'ground' } : {}), width: size.width, height: size.height, onReady: groundReady, onError: groundFailed }, attempt))) : (_jsxs(_Fragment, { children: [tileUrl !== undefined &&
|
|
288
290
|
tiles.map((tile) => (_jsx("img", { src: mapTileUrl(tileUrl, tile), alt: "", draggable: false, onLoad: groundReady, onError: (event) => {
|
|
289
291
|
event.currentTarget.style.visibility = 'hidden';
|
|
290
292
|
groundFailed();
|
|
@@ -6,6 +6,9 @@ export interface MapEngineProps {
|
|
|
6
6
|
viewport: MapViewport;
|
|
7
7
|
/** The ground style the reader chose, the engine switches its own style to match. */
|
|
8
8
|
base: MapBase;
|
|
9
|
+
/** Which of the ground to paint. `DSMap` asks for `ground` and `DSMapNames` for `names`, so
|
|
10
|
+
* place names can stand over fences and under pins. Left out, paint both as one picture. */
|
|
11
|
+
paint?: 'ground' | 'names' | undefined;
|
|
9
12
|
width: number;
|
|
10
13
|
height: number;
|
|
11
14
|
/** Call once the first frame of the ground is drawn. */
|
|
@@ -35,6 +38,9 @@ export declare function useMapEngine(): MapEngineConfig;
|
|
|
35
38
|
/** What a layer inside a map is given. */
|
|
36
39
|
export interface MapView {
|
|
37
40
|
projection: MapProjection;
|
|
41
|
+
/** The view and ground style this map is painting. */
|
|
42
|
+
viewport: MapViewport;
|
|
43
|
+
base: MapBase;
|
|
38
44
|
/** The point under a pointer, from the event's `clientX` and `clientY`. */
|
|
39
45
|
clientToGeo: (clientX: number, clientY: number) => GeoPoint;
|
|
40
46
|
/** Moves keyboard focus to the map's pannable surface, where it goes when
|
|
@@ -2,4 +2,4 @@ import { type TextInputProps } from 'react-native';
|
|
|
2
2
|
import { type NumberFieldContract } from '../number-field';
|
|
3
3
|
export type DSNumberFieldProps = Omit<TextInputProps, 'value' | 'defaultValue' | 'onChangeText' | 'keyboardType' | 'inputMode' | 'editable' | 'accessibilityLabel' | 'aria-label' | 'accessibilityValue' | 'accessibilityState' | 'aria-disabled' | 'children'> & NumberFieldContract;
|
|
4
4
|
/** A number with its unit, limits and steppers, typed freely and settled on blur. */
|
|
5
|
-
export declare function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size, onRejectedInput, decrementLabel, incrementLabel, onFocus, onBlur, className, ...props }: DSNumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size, outOfRange, onRejectedInput, decrementLabel, incrementLabel, onFocus, onBlur, className, ...props }: DSNumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -25,15 +25,17 @@ const HEIGHT = {
|
|
|
25
25
|
roomy: 'min-h-16',
|
|
26
26
|
};
|
|
27
27
|
const FIELD_METRICS = { includeFontPadding: false };
|
|
28
|
-
export function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size = 'md', onRejectedInput, decrementLabel, incrementLabel, onFocus, onBlur, className, ...props }) {
|
|
28
|
+
export function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size = 'md', outOfRange, onRejectedInput, decrementLabel, incrementLabel, onFocus, onBlur, className, ...props }) {
|
|
29
29
|
const [text, setText] = useState(() => formatNumberInput(value));
|
|
30
30
|
const [refused, setRefused] = useState(false);
|
|
31
31
|
const [seen, setSeen] = useState(value);
|
|
32
|
+
const [heard, setHeard] = useState(value);
|
|
32
33
|
const [focused, setFocused] = useState(false);
|
|
33
34
|
const epoch = useThemeEpoch();
|
|
34
35
|
const large = useLargeText();
|
|
35
36
|
if (!Object.is(seen, value)) {
|
|
36
37
|
setSeen(value);
|
|
38
|
+
setHeard(value);
|
|
37
39
|
const parsed = parseNumberInput(text);
|
|
38
40
|
const says = parsed.kind === 'number' ? parsed.value : undefined;
|
|
39
41
|
if (!Object.is(says, value)) {
|
|
@@ -42,8 +44,10 @@ export function DSNumberField({ label, value, onValueChange, min, max, step, pre
|
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
const report = (next) => {
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
+
if (Object.is(next, heard))
|
|
48
|
+
return;
|
|
49
|
+
setHeard(next);
|
|
50
|
+
onValueChange(next);
|
|
47
51
|
};
|
|
48
52
|
const parsedNow = parseNumberInput(text);
|
|
49
53
|
const now = parsedNow.kind === 'number' ? parsedNow.value : value;
|
|
@@ -73,7 +77,7 @@ export function DSNumberField({ label, value, onValueChange, min, max, step, pre
|
|
|
73
77
|
: null, className: cn('items-center justify-center self-stretch android:ripple-primary', large ? 'min-h-touch flex-1' : 'w-12', (!large || direction > 0) && 'border-s', isDisabled ? 'border-disabled-border' : 'border-input'), children: _jsx(Glyph, { size: 18, className: off ? 'text-disabled-foreground' : 'text-muted-foreground' }) }, `${String(direction)}-${epoch}`));
|
|
74
78
|
};
|
|
75
79
|
const frame = cn('will-change-variable w-full overflow-hidden rounded-card-sm', SURFACE[spec.surface], BORDER[spec.border], isDisabled && 'border-disabled-border bg-disabled', focused && 'outline-solid outline-2 outline-offset-2 outline-ring');
|
|
76
|
-
const entry = (_jsxs(_Fragment, { children: [prefix !== undefined && (_jsx(Text, { importantForAccessibility: "no", "aria-hidden": true, accessibilityElementsHidden: true, className: cn('font-sans pe-1', isDisabled ? 'text-disabled-foreground' : 'text-muted-foreground', TEXT[spec.text]), children: prefix })), _jsx(TextInput, { textAlignVertical: "center", style: FIELD_METRICS, underlineColorAndroid: "transparent", className: cn('min-w-0 flex-1 self-stretch py-0 font-sans font-semibold tabular-nums', isDisabled ? 'text-disabled-foreground' : LABEL[spec.label], TEXT[spec.text]), ...props, value: text, keyboardType: keyboardType, editable: !isDisabled && !isReadOnly, accessibilityLabel: label, accessibilityValue:
|
|
80
|
+
const entry = (_jsxs(_Fragment, { children: [prefix !== undefined && (_jsx(Text, { importantForAccessibility: "no", "aria-hidden": true, accessibilityElementsHidden: true, className: cn('font-sans pe-1', isDisabled ? 'text-disabled-foreground' : 'text-muted-foreground', TEXT[spec.text]), children: prefix })), _jsx(TextInput, { textAlignVertical: "center", style: FIELD_METRICS, underlineColorAndroid: "transparent", className: cn('min-w-0 flex-1 self-stretch py-0 font-sans font-semibold tabular-nums', isDisabled ? 'text-disabled-foreground' : LABEL[spec.label], TEXT[spec.text]), ...props, value: text, keyboardType: keyboardType, editable: !isDisabled && !isReadOnly, accessibilityLabel: label, accessibilityValue: now === undefined ? {} : { text: numberFieldValueText(now, prefix, suffix) ?? '' }, accessibilityState: { disabled: isDisabled }, "aria-disabled": isDisabled, "aria-invalid": (invalid ?? refused) || undefined, onChangeText: (next) => {
|
|
77
81
|
setText(next);
|
|
78
82
|
setRefused(false);
|
|
79
83
|
const parsed = parseNumberInput(next);
|
|
@@ -86,10 +90,10 @@ export function DSNumberField({ label, value, onValueChange, min, max, step, pre
|
|
|
86
90
|
onBlur?.(event);
|
|
87
91
|
if (isReadOnly)
|
|
88
92
|
return;
|
|
89
|
-
const settled = settleNumberInput(text, { min, max });
|
|
93
|
+
const settled = settleNumberInput(text, { min, max, outOfRange });
|
|
90
94
|
setText(settled.text);
|
|
91
95
|
setRefused(settled.invalid);
|
|
92
|
-
if (settled.invalid)
|
|
96
|
+
if (settled.invalid && settled.value === undefined)
|
|
93
97
|
onRejectedInput?.(text);
|
|
94
98
|
report(settled.value);
|
|
95
99
|
} }), suffix !== undefined && (_jsx(Text, { importantForAccessibility: "no", "aria-hidden": true, accessibilityElementsHidden: true, className: cn('font-sans px-2', isDisabled ? 'text-disabled-foreground' : 'text-muted-foreground', TEXT[spec.text]), children: suffix }))] }));
|
|
@@ -43,10 +43,17 @@ export interface NumberFieldSettled {
|
|
|
43
43
|
value: number | undefined;
|
|
44
44
|
invalid: boolean;
|
|
45
45
|
}
|
|
46
|
-
/** What leaving the field does to
|
|
46
|
+
/** What leaving the field does to a number outside `min` and `max`: move it into range, or keep it and refuse it. */
|
|
47
|
+
export type NumberFieldOutOfRange = 'clamp' | 'keep';
|
|
48
|
+
/**
|
|
49
|
+
* What leaving the field does to its text: tidy a number and, by default, clamp
|
|
50
|
+
* it; keep garbage as typed. Under `outOfRange: 'keep'` an out-of-range number
|
|
51
|
+
* is tidied but not moved, and is reported as invalid.
|
|
52
|
+
*/
|
|
47
53
|
export declare function settleNumberInput(text: string, bounds?: {
|
|
48
54
|
min?: number | undefined;
|
|
49
55
|
max?: number | undefined;
|
|
56
|
+
outOfRange?: NumberFieldOutOfRange | undefined;
|
|
50
57
|
}): NumberFieldSettled;
|
|
51
58
|
/** What a screen reader hears as the field's value, `45 litres`, `R500`. */
|
|
52
59
|
export declare function numberFieldValueText(value: number | undefined, prefix?: string, suffix?: string): string | undefined;
|
|
@@ -68,13 +75,20 @@ export declare function numberFieldStepperLabels(label: string, override?: {
|
|
|
68
75
|
export interface NumberFieldContract {
|
|
69
76
|
/** The field's name, read by assistive tech and used to name its stepper buttons. */
|
|
70
77
|
label: string;
|
|
71
|
-
/** The current number, or `undefined` for an empty field.
|
|
78
|
+
/** The current number, or `undefined` for an empty field. An outside reset to the
|
|
79
|
+
* number the field already holds leaves a kept draft on screen; remount with a
|
|
80
|
+
* `key` to clear it. */
|
|
72
81
|
value: number | undefined;
|
|
73
|
-
/** Called with the parsed number
|
|
82
|
+
/** Called with the parsed number, `undefined` when empty or unreadable, whenever it
|
|
83
|
+
* differs from the last number the field reported or was given as `value`. So a
|
|
84
|
+
* caller that refused a number still hears a correction back to the number it
|
|
85
|
+
* holds, whether typed, stepped or clamped on blur. */
|
|
74
86
|
onValueChange: (value: number | undefined) => void;
|
|
75
|
-
/** The smallest allowed value; stepping stops here and blur clamps to it
|
|
87
|
+
/** The smallest allowed value; stepping stops here and blur clamps to it, unless
|
|
88
|
+
* `outOfRange` is `'keep'`. */
|
|
76
89
|
min?: Forwarded<number>;
|
|
77
|
-
/** The largest allowed value; stepping stops here and blur clamps to it
|
|
90
|
+
/** The largest allowed value; stepping stops here and blur clamps to it, unless
|
|
91
|
+
* `outOfRange` is `'keep'`. */
|
|
78
92
|
max?: Forwarded<number>;
|
|
79
93
|
/** How far one stepper press moves the value. */
|
|
80
94
|
step?: Forwarded<number>;
|
|
@@ -88,7 +102,15 @@ export interface NumberFieldContract {
|
|
|
88
102
|
disabled?: Forwarded<boolean>;
|
|
89
103
|
/** The field's height step. */
|
|
90
104
|
size?: Forwarded<InputSize>;
|
|
91
|
-
/**
|
|
105
|
+
/** What leaving the field does to a number outside `min` and `max`. `'clamp'` (the
|
|
106
|
+
* default) moves it into range, visibly, in the box the person is looking at.
|
|
107
|
+
* `'keep'` leaves it as typed (tidied, so "1 284" becomes "1284") and paints the
|
|
108
|
+
* field invalid, for a form that must refuse an out-of-range number rather than
|
|
109
|
+
* correct it, so its own error stays on screen beside what was typed. Stepping
|
|
110
|
+
* stops at the bounds either way. */
|
|
111
|
+
outOfRange?: Forwarded<NumberFieldOutOfRange>;
|
|
112
|
+
/** Called on blur with the text that could not be read as a number. A number outside
|
|
113
|
+
* `min` and `max` is not rejected input, whichever `outOfRange` says. */
|
|
92
114
|
onRejectedInput?: Forwarded<(text: string) => void>;
|
|
93
115
|
/** The decrease stepper's accessible name, for a product in another language.
|
|
94
116
|
* Left out, it is "Decrease {label}". */
|
|
@@ -62,8 +62,11 @@ export function settleNumberInput(text, bounds = {}) {
|
|
|
62
62
|
return { text: '', value: undefined, invalid: false };
|
|
63
63
|
if (parsed.kind === 'invalid')
|
|
64
64
|
return { text, value: undefined, invalid: true };
|
|
65
|
-
const
|
|
66
|
-
|
|
65
|
+
const clamped = clampNumberInput(parsed.value, bounds.min, bounds.max);
|
|
66
|
+
if (bounds.outOfRange === 'keep' && clamped !== parsed.value) {
|
|
67
|
+
return { text: formatNumberInput(parsed.value), value: parsed.value, invalid: true };
|
|
68
|
+
}
|
|
69
|
+
return { text: formatNumberInput(clamped), value: clamped, invalid: false };
|
|
67
70
|
}
|
|
68
71
|
export function numberFieldValueText(value, prefix, suffix) {
|
|
69
72
|
if (value === undefined)
|
|
@@ -2,4 +2,4 @@ import { type ComponentProps } from 'react';
|
|
|
2
2
|
import { type NumberFieldContract } from '../number-field';
|
|
3
3
|
export type DSNumberFieldProps = Omit<ComponentProps<'input'>, 'value' | 'defaultValue' | 'onChange' | 'type' | 'inputMode' | 'role' | 'aria-label' | 'aria-valuenow' | 'aria-valuemin' | 'aria-valuemax' | 'aria-valuetext' | 'min' | 'max' | 'step' | 'size' | 'prefix' | 'disabled' | 'children'> & NumberFieldContract;
|
|
4
4
|
/** A number with its unit, limits and steppers, typed freely and settled on blur. */
|
|
5
|
-
export declare function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size, onRejectedInput, decrementLabel, incrementLabel, 'aria-invalid': ariaInvalid, onBlur, onKeyDown, className, id, ...props }: DSNumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
export declare function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size, outOfRange, onRejectedInput, decrementLabel, incrementLabel, 'aria-invalid': ariaInvalid, onBlur, onKeyDown, className, id, ...props }: DSNumberFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -27,14 +27,16 @@ const HEIGHT = {
|
|
|
27
27
|
roomy: 'min-h-14',
|
|
28
28
|
};
|
|
29
29
|
const BIG_STEP = 10;
|
|
30
|
-
export function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size = 'md', onRejectedInput, decrementLabel, incrementLabel, 'aria-invalid': ariaInvalid, onBlur, onKeyDown, className, id, ...props }) {
|
|
30
|
+
export function DSNumberField({ label, value, onValueChange, min, max, step, prefix, suffix, invalid, disabled, readOnly, size = 'md', outOfRange, onRejectedInput, decrementLabel, incrementLabel, 'aria-invalid': ariaInvalid, onBlur, onKeyDown, className, id, ...props }) {
|
|
31
31
|
const [text, setText] = useState(() => formatNumberInput(value));
|
|
32
32
|
const [refused, setRefused] = useState(false);
|
|
33
33
|
const [seen, setSeen] = useState(value);
|
|
34
|
+
const [heard, setHeard] = useState(value);
|
|
34
35
|
const ownId = useId();
|
|
35
36
|
const inputId = id ?? ownId;
|
|
36
37
|
if (!Object.is(seen, value)) {
|
|
37
38
|
setSeen(value);
|
|
39
|
+
setHeard(value);
|
|
38
40
|
const parsed = parseNumberInput(text);
|
|
39
41
|
const says = parsed.kind === 'number' ? parsed.value : undefined;
|
|
40
42
|
if (!Object.is(says, value)) {
|
|
@@ -43,8 +45,10 @@ export function DSNumberField({ label, value, onValueChange, min, max, step, pre
|
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
const report = (next) => {
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
+
if (Object.is(next, heard))
|
|
49
|
+
return;
|
|
50
|
+
setHeard(next);
|
|
51
|
+
onValueChange(next);
|
|
48
52
|
};
|
|
49
53
|
const current = () => {
|
|
50
54
|
const parsed = parseNumberInput(text);
|
|
@@ -71,10 +75,10 @@ export function DSNumberField({ label, value, onValueChange, min, max, step, pre
|
|
|
71
75
|
onBlur?.(event);
|
|
72
76
|
if (readOnly === true)
|
|
73
77
|
return;
|
|
74
|
-
const settled = settleNumberInput(text, { min, max });
|
|
78
|
+
const settled = settleNumberInput(text, { min, max, outOfRange });
|
|
75
79
|
setText(settled.text);
|
|
76
80
|
setRefused(settled.invalid);
|
|
77
|
-
if (settled.invalid)
|
|
81
|
+
if (settled.invalid && settled.value === undefined)
|
|
78
82
|
onRejectedInput?.(text);
|
|
79
83
|
report(settled.value);
|
|
80
84
|
};
|
|
@@ -128,7 +132,7 @@ export function DSNumberField({ label, value, onValueChange, min, max, step, pre
|
|
|
128
132
|
const stepper = cn('flex w-9 items-center justify-center self-stretch text-muted-foreground state-layer', 'not-aria-disabled:hover:text-foreground', 'aria-disabled:cursor-not-allowed aria-disabled:text-disabled-foreground', COARSE_POINTER_TARGET[spec.minHeight]);
|
|
129
133
|
const downOff = isDisabled || isReadOnly || atMin;
|
|
130
134
|
const upOff = isDisabled || isReadOnly || atMax;
|
|
131
|
-
return (_jsxs("div", { className: cn('group flex w-full items-center overflow-hidden rounded-field transition-control focusable-field-within', SURFACE[spec.surface], LABEL[spec.label], BORDER[spec.border], TEXT[spec.text], !setsTypeRecipe(className) && 'font-normal', HEIGHT[spec.minHeight], COMPACT_HEIGHT[spec.minHeight], PADDING[spec.paddingX], !painted && !isDisabled && 'state-layer-edge', 'hover:has-[input:enabled]:bg-field-hover', 'has-[input:disabled]:cursor-not-allowed has-[input:disabled]:border-disabled-border', 'has-[input:disabled]:bg-disabled has-[input:disabled]:text-disabled-foreground', className), children: [prefix !== undefined && (_jsx("span", { "aria-hidden": true, "aria-disabled": isDisabled || undefined, className: "select-none pe-1 text-muted-foreground group-has-[input:disabled]:text-disabled-foreground", children: prefix })), _jsx("input", { id: inputId, spellCheck: false, className: cn('min-w-0 flex-1 border-0 bg-transparent p-0 tabular-nums outline-none', 'placeholder:text-placeholder-foreground disabled:cursor-not-allowed', 'disabled:placeholder:text-disabled-foreground'), ...props, type: "text", inputMode: "decimal", autoComplete: "off", role: "spinbutton", "aria-label": label, "aria-valuenow":
|
|
135
|
+
return (_jsxs("div", { className: cn('group flex w-full items-center overflow-hidden rounded-field transition-control focusable-field-within', SURFACE[spec.surface], LABEL[spec.label], BORDER[spec.border], TEXT[spec.text], !setsTypeRecipe(className) && 'font-normal', HEIGHT[spec.minHeight], COMPACT_HEIGHT[spec.minHeight], PADDING[spec.paddingX], !painted && !isDisabled && 'state-layer-edge', 'hover:has-[input:enabled]:bg-field-hover', 'has-[input:disabled]:cursor-not-allowed has-[input:disabled]:border-disabled-border', 'has-[input:disabled]:bg-disabled has-[input:disabled]:text-disabled-foreground', className), children: [prefix !== undefined && (_jsx("span", { "aria-hidden": true, "aria-disabled": isDisabled || undefined, className: "select-none pe-1 text-muted-foreground group-has-[input:disabled]:text-disabled-foreground", children: prefix })), _jsx("input", { id: inputId, spellCheck: false, className: cn('min-w-0 flex-1 border-0 bg-transparent p-0 tabular-nums outline-none', 'placeholder:text-placeholder-foreground disabled:cursor-not-allowed', 'disabled:placeholder:text-disabled-foreground'), ...props, type: "text", inputMode: "decimal", autoComplete: "off", role: "spinbutton", "aria-label": label, "aria-valuenow": now, "aria-valuemin": min, "aria-valuemax": max, "aria-valuetext": numberFieldValueText(now, prefix, suffix), "aria-invalid": painted || undefined, disabled: isDisabled, readOnly: isReadOnly, value: text, onChange: handleChange, onBlur: handleBlur, onKeyDown: handleKeyDown }), suffix !== undefined && (_jsx("span", { "aria-hidden": true, "aria-disabled": isDisabled || undefined, className: "select-none whitespace-nowrap px-2 text-muted-foreground group-has-[input:disabled]:text-disabled-foreground", children: suffix })), _jsxs("div", { className: "flex self-stretch border-s border-card group-has-[input:disabled]:border-disabled-border", children: [_jsx("button", { type: "button", tabIndex: -1, "aria-label": names.decrement, "aria-controls": inputId, "aria-disabled": downOff || undefined, onPointerDown: (event) => {
|
|
132
136
|
event.preventDefault();
|
|
133
137
|
}, onClick: () => {
|
|
134
138
|
if (downOff)
|
|
@@ -48,7 +48,7 @@ export interface PhoneFieldContract extends InputContract {
|
|
|
48
48
|
* Why the prefix is not announced, kept as a constant so the reasoning travels
|
|
49
49
|
* with the code rather than living only in a header.
|
|
50
50
|
*/
|
|
51
|
-
export declare const PHONE_FIELD_PREFIX_IS_DECORATION = "The prefix is aria-hidden: the
|
|
51
|
+
export declare const PHONE_FIELD_PREFIX_IS_DECORATION = "The prefix is aria-hidden: the field holds the national number, so the flag and the dialling code are context for the eye, not part of the value. A fixed code asks the browser for autocomplete=\"tel-national\"; a code the person can choose asks for \"tel\", whose own \"+\" code moves the picker.";
|
|
52
52
|
/**
|
|
53
53
|
* The rule that forbids a success state on this field, in the design's own
|
|
54
54
|
* words.
|
|
@@ -123,6 +123,14 @@ export declare function phoneFieldCountryOf(raw: string, countries: readonly Pho
|
|
|
123
123
|
country: PhoneFieldCountry;
|
|
124
124
|
national: string;
|
|
125
125
|
} | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* Whether text that starts with "+" is still part way through a dialling code:
|
|
128
|
+
* the digits after the plus are the start of a longer code the list holds. "+",
|
|
129
|
+
* "+2" and "+26" are open while "+263" is Zimbabwe; "+1" stays open while the
|
|
130
|
+
* list holds "+1268", so a code typed key by key lands where the same text
|
|
131
|
+
* pasted at once lands (`phoneFieldCountryOf`, longest code wins).
|
|
132
|
+
*/
|
|
133
|
+
export declare function phoneFieldCodeIsOpen(raw: string, countries: readonly PhoneFieldCountry[]): boolean;
|
|
126
134
|
/** Whether the national digits are a whole number for that country: the full
|
|
127
135
|
* length of its format, or 8 to 15 digits where it has none. */
|
|
128
136
|
export declare function phoneFieldCountryIsComplete(digits: string, country: PhoneFieldCountry): boolean;
|
|
@@ -10,7 +10,7 @@ export function phoneFieldSpec() {
|
|
|
10
10
|
codeWeight: PHONE_FIELD_CODE_WEIGHT,
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export const PHONE_FIELD_PREFIX_IS_DECORATION = 'The prefix is aria-hidden: the
|
|
13
|
+
export const PHONE_FIELD_PREFIX_IS_DECORATION = 'The prefix is aria-hidden: the field holds the national number, so the flag and the dialling code are context for the eye, not part of the value. A fixed code asks the browser for autocomplete="tel-national"; a code the person can choose asks for "tel", whose own "+" code moves the picker.';
|
|
14
14
|
export const PHONE_FIELD_HAS_NO_VALID_STATE = 'No validity tick: nine digits is a complete number, not a recognised one, so only the server can confirm it.';
|
|
15
15
|
export function phoneFieldDigits(raw) {
|
|
16
16
|
return raw.replace(/\D/g, '');
|
|
@@ -93,6 +93,16 @@ export function phoneFieldCountryOf(raw, countries) {
|
|
|
93
93
|
return undefined;
|
|
94
94
|
return { country: found, national: digits.slice(phoneFieldDigits(found.dialCode).length) };
|
|
95
95
|
}
|
|
96
|
+
export function phoneFieldCodeIsOpen(raw, countries) {
|
|
97
|
+
const text = raw.trim();
|
|
98
|
+
if (!text.startsWith('+'))
|
|
99
|
+
return false;
|
|
100
|
+
const digits = phoneFieldDigits(text);
|
|
101
|
+
return countries.some((country) => {
|
|
102
|
+
const code = phoneFieldDigits(country.dialCode);
|
|
103
|
+
return code.length > digits.length && code.startsWith(digits);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
96
106
|
export function phoneFieldCountryIsComplete(digits, country) {
|
|
97
107
|
if (country.format !== undefined) {
|
|
98
108
|
return phoneFieldNationalDigits(digits, country.format, country.dialCode).length ===
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
2
|
import { type PhoneFieldContract, type PhoneFieldCountry } from '../phone-field';
|
|
3
|
-
export type DSPhoneFieldProps = Omit<ComponentProps<'input'>, 'size' | 'type' | 'inputMode' | '
|
|
3
|
+
export type DSPhoneFieldProps = Omit<ComponentProps<'input'>, 'size' | 'type' | 'inputMode' | 'onChange' | 'value'> & PhoneFieldContract & {
|
|
4
4
|
/** The older handler, kept so every existing caller works: it is told the
|
|
5
5
|
* change event. New code uses `onValueChange`, which is told the number.
|
|
6
6
|
* Not tagged `@deprecated` on purpose: the tag turns every caller outside
|
|
@@ -42,4 +42,4 @@ export type DSPhoneFieldProps = Omit<ComponentProps<'input'>, 'size' | 'type' |
|
|
|
42
42
|
countryEmptyLabel?: undefined;
|
|
43
43
|
});
|
|
44
44
|
/** A telephone field with a dialling-code prefix and optional grouping as the number is typed. */
|
|
45
|
-
export declare function DSPhoneField({ dialCode: fixedDialCode, flag, format: fixedFormat, countries, country, onCountryChange, countryLabel, countrySearchLabel, countryEmptyLabel, size, invalid, disabled, value, onChange, onValueChange, className, 'aria-invalid': ariaInvalid, ref, ...props }: DSPhoneFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
45
|
+
export declare function DSPhoneField({ dialCode: fixedDialCode, flag, format: fixedFormat, countries, country, onCountryChange, countryLabel, countrySearchLabel, countryEmptyLabel, size, invalid, disabled, value, onChange, onValueChange, className, autoComplete, 'aria-invalid': ariaInvalid, ref, ...props }: DSPhoneFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useCallback, useLayoutEffect, useRef, } from 'react';
|
|
3
|
-
import { phoneFieldCaretPosition, phoneFieldCountryFormat, phoneFieldCountryLabel, phoneFieldCountryOf, phoneFieldDigits, phoneFieldFormat, phoneFieldNationalDigits, phoneFieldSpec, } from '../phone-field';
|
|
2
|
+
import { useCallback, useLayoutEffect, useRef, useState, } from 'react';
|
|
3
|
+
import { phoneFieldCaretPosition, phoneFieldCodeIsOpen, phoneFieldCountryFormat, phoneFieldCountryLabel, phoneFieldCountryOf, phoneFieldDigits, phoneFieldFormat, phoneFieldNationalDigits, phoneFieldSpec, } from '../phone-field';
|
|
4
4
|
import { inputSpec, } from '../../input/input';
|
|
5
5
|
import { cn } from '../../lib/cn';
|
|
6
6
|
import { setsTypeRecipe } from '../../lib/sets-type';
|
|
@@ -33,7 +33,7 @@ const HEIGHT = {
|
|
|
33
33
|
roomy: 'min-h-14',
|
|
34
34
|
};
|
|
35
35
|
const HOME_COUNTRY = 'za';
|
|
36
|
-
export function DSPhoneField({ dialCode: fixedDialCode, flag, format: fixedFormat, countries, country, onCountryChange, countryLabel, countrySearchLabel, countryEmptyLabel, size = 'md', invalid, disabled, value, onChange, onValueChange, className, 'aria-invalid': ariaInvalid, ref, ...props }) {
|
|
36
|
+
export function DSPhoneField({ dialCode: fixedDialCode, flag, format: fixedFormat, countries, country, onCountryChange, countryLabel, countrySearchLabel, countryEmptyLabel, size = 'md', invalid, disabled, value, onChange, onValueChange, className, autoComplete, 'aria-invalid': ariaInvalid, ref, ...props }) {
|
|
37
37
|
const spec = phoneFieldSpec();
|
|
38
38
|
const choosable = countries !== undefined && countries.length > 0;
|
|
39
39
|
const chosen = choosable
|
|
@@ -65,14 +65,30 @@ export function DSPhoneField({ dialCode: fixedDialCode, flag, format: fixedForma
|
|
|
65
65
|
}
|
|
66
66
|
catch { }
|
|
67
67
|
});
|
|
68
|
+
const [codeDraft, setCodeDraft] = useState(null);
|
|
68
69
|
const raw = typeof value === 'string' ? value : '';
|
|
69
|
-
const display =
|
|
70
|
+
const display = codeDraft !== null && raw === ''
|
|
71
|
+
? codeDraft
|
|
72
|
+
: format === undefined
|
|
73
|
+
? raw
|
|
74
|
+
: phoneFieldFormat(raw, format, dialCode);
|
|
70
75
|
const handleChange = (event) => {
|
|
71
76
|
if (format === undefined) {
|
|
72
77
|
onChange?.(event);
|
|
73
78
|
onValueChange?.(event.target.value);
|
|
74
79
|
return;
|
|
75
80
|
}
|
|
81
|
+
if (choosable && phoneFieldCodeIsOpen(event.target.value, countries)) {
|
|
82
|
+
const typed = event.target.value;
|
|
83
|
+
const caret = event.target.selectionStart ?? typed.length;
|
|
84
|
+
setCodeDraft(typed);
|
|
85
|
+
event.target.value = '';
|
|
86
|
+
onChange?.(event);
|
|
87
|
+
onValueChange?.('');
|
|
88
|
+
pendingCaret.current = caret;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setCodeDraft(null);
|
|
76
92
|
const named = choosable ? phoneFieldCountryOf(event.target.value, countries) : undefined;
|
|
77
93
|
const nowFormat = named === undefined ? format : phoneFieldCountryFormat(named.country);
|
|
78
94
|
const nowCode = named === undefined ? dialCode : named.country.dialCode;
|
|
@@ -116,5 +132,5 @@ export function DSPhoneField({ dialCode: fixedDialCode, flag, format: fixedForma
|
|
|
116
132
|
label: phoneFieldCountryLabel(c),
|
|
117
133
|
triggerLabel: c.dialCode,
|
|
118
134
|
leading: _jsx(DSFlag, { code: c.code }),
|
|
119
|
-
})) }) })) : (_jsxs("span", { "aria-hidden": "true", className: cn('flex shrink-0 items-center gap-2 border-r pr-3', DIVIDER[spec.divider]), children: [flag !== undefined && _jsx("span", { className: "text-heading-md leading-none", children: flag }), _jsx(DSText, { as: "span", variant: "heading-sm", className: cn(INK[field.label], 'group-has-[:disabled]:text-disabled-foreground'), children: dialCode })] })), _jsx("input", { ref: setInput, ...valueProps, type: "tel", inputMode: "numeric", enterKeyHint: "next", autoComplete:
|
|
135
|
+
})) }) })) : (_jsxs("span", { "aria-hidden": "true", className: cn('flex shrink-0 items-center gap-2 border-r pr-3', DIVIDER[spec.divider]), children: [flag !== undefined && _jsx("span", { className: "text-heading-md leading-none", children: flag }), _jsx(DSText, { as: "span", variant: "heading-sm", className: cn(INK[field.label], 'group-has-[:disabled]:text-disabled-foreground'), children: dialCode })] })), _jsx("input", { ref: setInput, ...valueProps, type: "tel", inputMode: "numeric", enterKeyHint: "next", autoComplete: autoComplete ?? (choosable ? 'tel' : 'tel-national'), "aria-invalid": painted || undefined, disabled: disabled, className: cn('ml-3 min-w-0 flex-1 border-0 bg-transparent outline-none', TEXT[field.text], !setsTypeRecipe(className) && 'font-normal', INK[field.label], PLACEHOLDER[field.placeholder], 'disabled:cursor-not-allowed disabled:text-disabled-foreground'), ...props })] }));
|
|
120
136
|
}
|
package/dist/sheet/sheet.d.ts
CHANGED
|
@@ -50,6 +50,15 @@ export interface SheetContract {
|
|
|
50
50
|
* twice. */
|
|
51
51
|
closeLabel: string;
|
|
52
52
|
}
|
|
53
|
+
/** Where focus lands when the sheet opens.
|
|
54
|
+
*
|
|
55
|
+
* `'first-field'`, the default, is for a sheet that holds a form: the cursor
|
|
56
|
+
* is where the work starts. `'sheet'` puts focus on the panel itself, which a
|
|
57
|
+
* screen reader announces by its title, for a sheet opened to READ a record:
|
|
58
|
+
* on a phone a focused field raises the keyboard over the record the person
|
|
59
|
+
* came to see. Tab goes on from the top of the sheet. */
|
|
60
|
+
export declare const SHEET_INITIAL_FOCUS: readonly ["first-field", "sheet"];
|
|
61
|
+
export type SheetInitialFocus = (typeof SHEET_INITIAL_FOCUS)[number];
|
|
53
62
|
/** The one recipe this concern has, no size/tone/variant axis exists for it,
|
|
54
63
|
* on the same terms `panelSpec()`/`dropdownMenuSpec()` take no arguments for their
|
|
55
64
|
* own axis-free concerns. */
|
package/dist/sheet/sheet.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
-
import { type SheetContract } from '../sheet';
|
|
2
|
+
import { type SheetContract, type SheetInitialFocus } from '../sheet';
|
|
3
3
|
export type DSSheetProps = Omit<ComponentProps<'div'>, 'title' | 'role' | 'aria-modal' | 'aria-labelledby' | 'onKeyDown' | 'tabIndex' | 'ref' | 'onAnimationEnd'> & SheetContract & {
|
|
4
4
|
/** `.focus-sheet__body`, the form (or record) this sheet holds. */
|
|
5
5
|
children: ReactNode;
|
|
@@ -15,6 +15,13 @@ export type DSSheetProps = Omit<ComponentProps<'div'>, 'title' | 'role' | 'aria-
|
|
|
15
15
|
* it and a dirty close does nothing at all, never a silent discard.
|
|
16
16
|
*/
|
|
17
17
|
onDirtyCloseAttempt?: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* Where focus lands when the sheet opens. `'first-field'` (the default) is
|
|
20
|
+
* the first control in the body, for a form. `'sheet'` is the panel itself,
|
|
21
|
+
* announced by its title, for a record opened to read: a focused field on a
|
|
22
|
+
* phone raises the keyboard over it. See `SHEET_INITIAL_FOCUS`.
|
|
23
|
+
*/
|
|
24
|
+
initialFocus?: SheetInitialFocus | undefined;
|
|
18
25
|
};
|
|
19
26
|
/** A modal panel for one focused task, anchored to the right edge of the page. */
|
|
20
|
-
export declare function DSSheet({ open, title, sub, dirty, dirtyClosePending, children, footer, onRequestClose, onDirtyCloseAttempt, closeLabel, className, ...props }: DSSheetProps): import("react").ReactPortal | null;
|
|
27
|
+
export declare function DSSheet({ open, title, sub, dirty, dirtyClosePending, children, footer, onRequestClose, onDirtyCloseAttempt, closeLabel, initialFocus, className, ...props }: DSSheetProps): import("react").ReactPortal | null;
|
|
@@ -26,7 +26,7 @@ const SUB_INK = {
|
|
|
26
26
|
'muted-foreground': 'text-muted-foreground',
|
|
27
27
|
};
|
|
28
28
|
const SHEET_EXIT_FALLBACK_MS = 400;
|
|
29
|
-
export function DSSheet({ open, title, sub, dirty = false, dirtyClosePending = false, children, footer, onRequestClose, onDirtyCloseAttempt, closeLabel, className, ...props }) {
|
|
29
|
+
export function DSSheet({ open, title, sub, dirty = false, dirtyClosePending = false, children, footer, onRequestClose, onDirtyCloseAttempt, closeLabel, initialFocus = 'first-field', className, ...props }) {
|
|
30
30
|
const spec = sheetSpec();
|
|
31
31
|
const titleId = useId();
|
|
32
32
|
const subId = useId();
|
|
@@ -72,7 +72,9 @@ export function DSSheet({ open, title, sub, dirty = false, dirtyClosePending = f
|
|
|
72
72
|
}, [open]);
|
|
73
73
|
useEffect(() => {
|
|
74
74
|
if (open) {
|
|
75
|
-
const first =
|
|
75
|
+
const first = initialFocus === 'sheet'
|
|
76
|
+
? null
|
|
77
|
+
: (bodyRef.current?.querySelector(TABBABLE) ?? null);
|
|
76
78
|
(first ?? sheetRef.current)?.focus({ preventScroll: true });
|
|
77
79
|
}
|
|
78
80
|
else {
|