@sentry/scraps 0.4.0 → 0.6.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/README.md +74 -8
- package/dist/alert/alert.js +0 -3
- package/dist/badge/badge.js +1 -2
- package/dist/badge/tag.js +4 -4
- package/dist/button/button.js +1 -0
- package/dist/button/index.d.ts +0 -1
- package/dist/button/index.js +0 -1
- package/dist/button/linkButton.js +1 -0
- package/dist/button/styles.js +157 -152
- package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
- package/dist/clipboard/copyToClipboardButton.js +32 -0
- package/dist/clipboard/index.d.ts +1 -0
- package/dist/clipboard/index.js +1 -0
- package/dist/code/index.d.ts +1 -0
- package/dist/code/index.js +1 -0
- package/dist/codeBlock/codeBlock.d.ts +68 -0
- package/dist/codeBlock/codeBlock.js +243 -0
- package/dist/codeBlock/index.d.ts +2 -0
- package/dist/codeBlock/index.js +2 -0
- package/dist/codeBlock/prism.d.ts +11 -0
- package/dist/codeBlock/prism.js +101 -0
- package/dist/codeBlock/styles.d.ts +2 -0
- package/dist/codeBlock/styles.js +133 -0
- package/dist/compactSelect/compactSelect.d.ts +21 -0
- package/dist/compactSelect/compactSelect.js +150 -0
- package/dist/compactSelect/composite.d.ts +54 -0
- package/dist/compactSelect/composite.js +101 -0
- package/dist/compactSelect/control.d.ts +112 -0
- package/dist/compactSelect/control.js +355 -0
- package/dist/compactSelect/gridList/index.d.ts +46 -0
- package/dist/compactSelect/gridList/index.js +102 -0
- package/dist/compactSelect/gridList/option.d.ts +15 -0
- package/dist/compactSelect/gridList/option.js +111 -0
- package/dist/compactSelect/gridList/section.d.ts +15 -0
- package/dist/compactSelect/gridList/section.js +58 -0
- package/dist/compactSelect/highlightText.d.ts +6 -0
- package/dist/compactSelect/highlightText.js +33 -0
- package/dist/compactSelect/index.d.ts +9 -0
- package/dist/compactSelect/index.js +8 -0
- package/dist/compactSelect/list.d.ts +94 -0
- package/dist/compactSelect/list.js +167 -0
- package/dist/compactSelect/listBox/index.d.ts +84 -0
- package/dist/compactSelect/listBox/index.js +175 -0
- package/dist/compactSelect/listBox/option.d.ts +19 -0
- package/dist/compactSelect/listBox/option.js +101 -0
- package/dist/compactSelect/listBox/section.d.ts +21 -0
- package/dist/compactSelect/listBox/section.js +58 -0
- package/dist/compactSelect/menuComponents.d.ts +89 -0
- package/dist/compactSelect/menuComponents.js +117 -0
- package/dist/compactSelect/selectFilterContext.d.ts +2 -0
- package/dist/compactSelect/selectFilterContext.js +3 -0
- package/dist/compactSelect/styles.d.ts +39 -0
- package/dist/compactSelect/styles.js +155 -0
- package/dist/compactSelect/types.d.ts +1 -0
- package/dist/compactSelect/types.js +0 -0
- package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
- package/dist/compactSelect/useVirtualizedItems.js +74 -0
- package/dist/compactSelect/utils.d.ts +80 -0
- package/dist/compactSelect/utils.js +264 -0
- package/dist/confirm/index.d.ts +153 -0
- package/dist/confirm/index.js +132 -0
- package/dist/dateTime/config.d.ts +23 -0
- package/dist/dateTime/config.js +50 -0
- package/dist/dateTime/context.d.ts +18 -0
- package/dist/dateTime/context.js +46 -0
- package/dist/dateTime/dateTime.d.ts +6 -0
- package/dist/dateTime/dateTime.js +30 -0
- package/dist/dateTime/format.d.ts +24 -0
- package/dist/dateTime/format.js +45 -0
- package/dist/dateTime/index.d.ts +6 -0
- package/dist/dateTime/index.js +6 -0
- package/dist/dateTime/intlFormatter.d.ts +9 -0
- package/dist/dateTime/intlFormatter.js +16 -0
- package/dist/dateTime/parseDate.d.ts +3 -0
- package/dist/dateTime/parseDate.js +12 -0
- package/dist/descriptionList/descriptionList.js +4 -3
- package/dist/disclosure/disclosure.js +2 -2
- package/dist/dragHandle/dragHandle.d.ts +3 -1
- package/dist/dragHandle/dragHandle.js +8 -5
- package/dist/drawer/components.d.ts +46 -0
- package/dist/drawer/components.js +265 -0
- package/dist/drawer/globalDrawer.d.ts +106 -0
- package/dist/drawer/globalDrawer.js +173 -0
- package/dist/drawer/index.d.ts +3 -0
- package/dist/drawer/index.js +2 -0
- package/dist/drawer/useDrawerResizing.d.ts +19 -0
- package/dist/drawer/useDrawerResizing.js +111 -0
- package/dist/drawer/useDrawerWidth.d.ts +1 -0
- package/dist/drawer/useDrawerWidth.js +42 -0
- package/dist/dropdownMenu/content.d.ts +1 -0
- package/dist/dropdownMenu/content.js +1 -0
- package/dist/dropdownMenu/context.d.ts +39 -0
- package/dist/dropdownMenu/context.js +3 -0
- package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
- package/dist/dropdownMenu/dropdownMenu.js +109 -0
- package/dist/dropdownMenu/index.d.ts +2 -0
- package/dist/dropdownMenu/index.js +1 -0
- package/dist/dropdownMenu/item.d.ts +140 -0
- package/dist/dropdownMenu/item.js +142 -0
- package/dist/dropdownMenu/list.d.ts +85 -0
- package/dist/dropdownMenu/list.js +429 -0
- package/dist/dropdownMenu/search.d.ts +16 -0
- package/dist/dropdownMenu/search.js +16 -0
- package/dist/dropdownMenu/section.d.ts +21 -0
- package/dist/dropdownMenu/section.js +40 -0
- package/dist/dropdownMenu/separator.d.ts +7 -0
- package/dist/dropdownMenu/separator.js +15 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +24 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +31 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.d.ts +13 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.js +30 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.d.ts +19 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.js +25 -0
- package/dist/dropdownMenu/utils.d.ts +21 -0
- package/dist/dropdownMenu/utils.js +55 -0
- package/dist/duration/formatElapsedDuration.d.ts +4 -0
- package/dist/duration/formatElapsedDuration.js +10 -0
- package/dist/duration/getDuration.d.ts +68 -0
- package/dist/duration/getDuration.js +80 -0
- package/dist/duration/index.d.ts +2 -0
- package/dist/duration/index.js +2 -0
- package/dist/form/FormSearch.d.ts +19 -0
- package/dist/form/FormSearch.js +4 -0
- package/dist/form/autoSaveForm.d.ts +110 -0
- package/dist/form/autoSaveForm.js +100 -0
- package/dist/{formPresentation → form}/displayField.js +2 -2
- package/dist/form/field/baseField.d.ts +23 -0
- package/dist/form/field/baseField.js +116 -0
- package/dist/form/field/checkboxField.d.ts +11 -0
- package/dist/form/field/checkboxField.js +42 -0
- package/dist/form/field/checkboxGroupField.d.ts +16 -0
- package/dist/form/field/checkboxGroupField.js +80 -0
- package/dist/form/field/compactSelectField.d.ts +19 -0
- package/dist/form/field/compactSelectField.js +77 -0
- package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
- package/dist/form/field/inputField.d.ts +19 -0
- package/dist/form/field/inputField.js +31 -0
- package/dist/{formPresentation → form/field}/meta.js +6 -6
- package/dist/form/field/numberField.d.ts +5 -0
- package/dist/form/field/numberField.js +11 -0
- package/dist/form/field/passwordField.d.ts +3 -0
- package/dist/form/field/passwordField.js +27 -0
- package/dist/form/field/radioGroupField.d.ts +16 -0
- package/dist/form/field/radioGroupField.js +92 -0
- package/dist/form/field/rangeField.d.ts +8 -0
- package/dist/form/field/rangeField.js +34 -0
- package/dist/form/field/selectAsyncField.d.ts +31 -0
- package/dist/form/field/selectAsyncField.js +22 -0
- package/dist/form/field/selectField.d.ts +9 -0
- package/dist/form/field/selectField.js +72 -0
- package/dist/form/field/switchField.d.ts +7 -0
- package/dist/form/field/switchField.js +37 -0
- package/dist/form/field/textAreaField.d.ts +7 -0
- package/dist/form/field/textAreaField.js +25 -0
- package/dist/{formPresentation → form}/formContext.js +1 -1
- package/dist/form/formErrorContext/index.d.ts +9 -0
- package/dist/form/formErrorContext/index.js +7 -0
- package/dist/form/index.d.ts +9 -0
- package/dist/form/index.js +8 -0
- package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
- package/dist/{formPresentation → form/layout}/base.js +1 -1
- package/dist/form/layout/fieldGroup.d.ts +6 -0
- package/dist/form/layout/fieldGroup.js +60 -0
- package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
- package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
- package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
- package/dist/form/scrapsForm.d.ts +220 -0
- package/dist/form/scrapsForm.js +126 -0
- package/dist/fzf.d.ts +9 -0
- package/dist/fzf.js +155 -0
- package/dist/hotkey/hotkey.d.ts +9 -8
- package/dist/hotkey/hotkey.js +13 -6
- package/dist/hotkey/index.d.ts +2 -1
- package/dist/hotkey/index.js +2 -1
- package/dist/hotkey/keyMappings.d.ts +1 -15
- package/dist/hotkey/keyMappings.js +29 -174
- package/dist/hotkey/useHotkeys.d.ts +3 -47
- package/dist/hotkey/useHotkeys.js +8 -42
- package/dist/image/image.js +2 -1
- package/dist/info/infoTip.d.ts +1 -1
- package/dist/info/infoTip.js +4 -3
- package/dist/input/index.d.ts +0 -3
- package/dist/input/index.js +0 -2
- package/dist/input/input.d.ts +2 -0
- package/dist/input/input.js +2 -0
- package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
- package/dist/input/passwordManagerIgnoreProps.js +8 -0
- package/dist/layout/container.d.ts +8 -2
- package/dist/layout/container.js +2 -2
- package/dist/layout/index.d.ts +2 -2
- package/dist/layout/index.js +1 -1
- package/dist/layout/styles.d.ts +2 -1
- package/dist/layout/styles.js +11 -5
- package/dist/legacyDatetime.d.ts +21 -0
- package/dist/legacyDatetime.js +13 -0
- package/dist/link/index.d.ts +1 -1
- package/dist/link/index.js +1 -1
- package/dist/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +11 -0
- package/dist/link/linkBehaviorContext.js +48 -11
- package/dist/menu/index.d.ts +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/menu.d.ts +14 -8
- package/dist/menu/menu.js +163 -60
- package/dist/modal/components.d.ts +19 -0
- package/dist/modal/components.js +99 -0
- package/dist/modal/errorBoundary.d.ts +2 -0
- package/dist/modal/errorBoundary.js +35 -0
- package/dist/modal/index.d.ts +33 -0
- package/dist/modal/index.js +260 -0
- package/dist/modal/portal.d.ts +1 -0
- package/dist/modal/portal.js +10 -0
- package/dist/modal/state.d.ts +17 -0
- package/dist/modal/state.js +41 -0
- package/dist/modal/types.d.ts +75 -0
- package/dist/modal/types.js +0 -0
- package/dist/numberInput/index.d.ts +3 -0
- package/dist/numberInput/index.js +2 -0
- package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberDragInput.js +1 -1
- package/dist/{input → numberInput}/numberInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberInput.js +1 -1
- package/dist/overlayContext.d.ts +29 -0
- package/dist/overlayContext.js +7 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/pagination.d.ts +24 -0
- package/dist/pagination/pagination.js +63 -0
- package/dist/pictureInPicture/index.d.ts +2 -0
- package/dist/pictureInPicture/index.js +2 -0
- package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
- package/dist/pictureInPicture/pictureInPicture.js +100 -0
- package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
- package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
- package/dist/pictureInPicture/portalContext.d.ts +2 -0
- package/dist/pictureInPicture/portalContext.js +3 -0
- package/dist/relativeTime/getRelativeDate.d.ts +14 -0
- package/dist/relativeTime/getRelativeDate.js +107 -0
- package/dist/relativeTime/index.d.ts +3 -0
- package/dist/relativeTime/index.js +3 -0
- package/dist/relativeTime/relativeTime.d.ts +55 -0
- package/dist/relativeTime/relativeTime.js +102 -0
- package/dist/relativeTime/useRelativeTimeFormatter.d.ts +2 -0
- package/dist/relativeTime/useRelativeTimeFormatter.js +10 -0
- package/dist/revealOnHover/revealOnHover.js +1 -1
- package/dist/segmentedControl/segmentedControl.js +1 -1
- package/dist/select/filter.d.ts +4 -0
- package/dist/select/filter.js +12 -0
- package/dist/select/index.d.ts +3 -0
- package/dist/select/index.js +2 -0
- package/dist/select/option.d.ts +16 -0
- package/dist/select/option.js +81 -0
- package/dist/select/reactSelectWrapper.d.ts +8 -0
- package/dist/select/reactSelectWrapper.js +25 -0
- package/dist/select/select.d.ts +79 -0
- package/dist/select/select.js +454 -0
- package/dist/select/styles.d.ts +9 -0
- package/dist/select/styles.js +27 -0
- package/dist/select/types.d.ts +60 -0
- package/dist/select/types.js +0 -0
- package/dist/select/virtualizedMenuList.d.ts +24 -0
- package/dist/select/virtualizedMenuList.js +123 -0
- package/dist/slideOverPanel.d.ts +20 -0
- package/dist/slideOverPanel.js +141 -0
- package/dist/splitPanel/splitPanel.d.ts +3 -1
- package/dist/splitPanel/splitPanel.js +2 -1
- package/dist/table/table.d.ts +1 -1
- package/dist/table/table.js +39 -20
- package/dist/table/useColumnResize.d.ts +6 -5
- package/dist/table/useColumnResize.js +5 -4
- package/dist/tabs/context.d.ts +9 -0
- package/dist/tabs/context.js +9 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +1 -0
- package/dist/tabs/item.d.ts +24 -0
- package/dist/tabs/item.js +4 -0
- package/dist/tabs/tab.d.ts +22 -0
- package/dist/tabs/tab.js +208 -0
- package/dist/tabs/tabList.d.ts +18 -0
- package/dist/tabs/tabList.js +258 -0
- package/dist/tabs/tabPanels.d.ts +13 -0
- package/dist/tabs/tabPanels.js +62 -0
- package/dist/tabs/tabs.d.ts +53 -0
- package/dist/tabs/tabs.js +59 -0
- package/dist/tabs/utils.d.ts +3 -0
- package/dist/tabs/utils.js +6 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/heading.js +1 -1
- package/dist/text/prose.d.ts +2 -2
- package/dist/text/styles.js +1 -1
- package/dist/text/text.d.ts +1 -1
- package/dist/text/text.js +1 -1
- package/dist/theme/dark.js +9 -9
- package/dist/theme/light.js +9 -9
- package/dist/theme/theme.d.ts +34 -34
- package/dist/theme/theme.js +9 -0
- package/dist/theme/types.d.ts +20 -2
- package/dist/tooltip/tooltip.js +2 -5
- package/dist/translation/index.d.ts +1 -0
- package/dist/translation/index.js +1 -0
- package/dist/translation/translate.d.ts +9 -0
- package/dist/translation/translate.js +5 -0
- package/dist/translation/translationContext.d.ts +2 -1
- package/dist/translation/translationContext.js +2 -1
- package/dist/useMedia.d.ts +15 -0
- package/dist/useMedia.js +24 -0
- package/dist/useOnClickOutside.d.ts +2 -0
- package/dist/useOnClickOutside.js +22 -0
- package/dist/useOverlay.d.ts +1 -0
- package/dist/useOverlay.js +1 -0
- package/dist/useVirtualCollection.d.ts +154 -0
- package/dist/useVirtualCollection.js +143 -0
- package/dist/useVirtualRows.d.ts +26 -0
- package/dist/useVirtualRows.js +26 -0
- package/dist/virtualCollectionLayout.d.ts +51 -0
- package/dist/virtualCollectionLayout.js +49 -0
- package/fonts/OFL.txt +94 -0
- package/fonts/roboto-mono-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-cyrillic.woff2 +0 -0
- package/fonts/roboto-mono-variable-greek.woff2 +0 -0
- package/fonts/roboto-mono-variable-latin-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-vietnamese.woff2 +0 -0
- package/fonts/roboto-mono-variable.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic.woff2 +0 -0
- package/fonts/rubik-variable-latin-ext.woff2 +0 -0
- package/fonts/rubik-variable.woff2 +0 -0
- package/fonts.css +211 -0
- package/package.json +140 -23
- package/dist/datetime.d.ts +0 -39
- package/dist/datetime.js +0 -20
- package/dist/formPresentation/index.d.ts +0 -8
- package/dist/formPresentation/index.js +0 -8
- package/dist/interactionStateLayer/index.d.ts +0 -1
- package/dist/interactionStateLayer/index.js +0 -1
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
- package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
- package/dist/unreachable.d.ts +0 -1
- package/dist/unreachable.js +0 -4
- /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
- /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
- /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
- /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.js +0 -0
- /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type Ref } from 'react';
|
|
3
|
+
export type BaseFieldProps<T extends HTMLElement> = {
|
|
4
|
+
disabled?: boolean | string;
|
|
5
|
+
ref?: Ref<T>;
|
|
6
|
+
};
|
|
7
|
+
type FieldChildrenProps<T extends HTMLElement> = {
|
|
8
|
+
'aria-describedby': string;
|
|
9
|
+
'aria-invalid': boolean;
|
|
10
|
+
disabled: boolean;
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
onBlur: () => void;
|
|
14
|
+
ref: Ref<T>;
|
|
15
|
+
};
|
|
16
|
+
export declare const useAutoSaveIndicator: () => import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
17
|
+
type FieldState = {
|
|
18
|
+
indicator: React.ReactNode;
|
|
19
|
+
};
|
|
20
|
+
export declare function BaseField<T extends HTMLElement>({ children, disabled, ref: refProp, }: BaseFieldProps<T> & {
|
|
21
|
+
children: (props: FieldChildrenProps<T>, state: FieldState) => React.ReactNode;
|
|
22
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { mergeRefs } from "@react-aria/utils";
|
|
4
|
+
import { useAutoSaveContext } from "../autoSaveContext.js";
|
|
5
|
+
import { useFieldId, useHintTextId } from "./fieldIds.js";
|
|
6
|
+
import { FieldMeta } from "./meta.js";
|
|
7
|
+
import { useFieldContext } from "../formContext.js";
|
|
8
|
+
import { Checkmark, Spinner } from "../icons.js";
|
|
9
|
+
import { Flex } from "../../layout/index.js";
|
|
10
|
+
import { useOverlayContext } from "../../overlayContext.js";
|
|
11
|
+
const useAutoSaveIndicator = ()=>{
|
|
12
|
+
const field = useFieldContext();
|
|
13
|
+
const status = useAutoSaveContext()?.status;
|
|
14
|
+
if ('pending' === status) return /*#__PURE__*/ jsx(Spinner, {
|
|
15
|
+
role: "status",
|
|
16
|
+
"aria-label": `Saving ${field.name}`,
|
|
17
|
+
"aria-live": "polite"
|
|
18
|
+
});
|
|
19
|
+
if ('success' === status) return /*#__PURE__*/ jsx(Checkmark, {
|
|
20
|
+
variant: "success",
|
|
21
|
+
size: "sm"
|
|
22
|
+
});
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
function useScrollToHash(fieldName, ref) {
|
|
26
|
+
const locationHash = useOverlayContext().location?.hash ?? '';
|
|
27
|
+
useEffect(()=>{
|
|
28
|
+
let hash;
|
|
29
|
+
try {
|
|
30
|
+
hash = decodeURIComponent(locationHash.slice(1));
|
|
31
|
+
} catch {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (hash !== fieldName) return;
|
|
35
|
+
ref.current?.scrollIntoView({
|
|
36
|
+
block: 'center',
|
|
37
|
+
behavior: 'smooth'
|
|
38
|
+
});
|
|
39
|
+
ref.current?.focus({
|
|
40
|
+
focusVisible: true
|
|
41
|
+
});
|
|
42
|
+
animateRowHighlight(fieldName, ref.current);
|
|
43
|
+
}, [
|
|
44
|
+
fieldName,
|
|
45
|
+
ref,
|
|
46
|
+
locationHash
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
function useFocusRestore(ref) {
|
|
50
|
+
const autoSaveContext = useAutoSaveContext();
|
|
51
|
+
const focusRestoreTargetRef = useRef(null);
|
|
52
|
+
const isDisabledByAutoSave = autoSaveContext?.status === 'pending';
|
|
53
|
+
useEffect(()=>{
|
|
54
|
+
const el = ref.current;
|
|
55
|
+
if (!el) return;
|
|
56
|
+
function onBlur(event) {
|
|
57
|
+
const target = event.target;
|
|
58
|
+
if (target instanceof HTMLElement && target.hasAttribute('disabled')) focusRestoreTargetRef.current = target;
|
|
59
|
+
}
|
|
60
|
+
el.addEventListener('blur', onBlur, true);
|
|
61
|
+
return ()=>el.removeEventListener('blur', onBlur, true);
|
|
62
|
+
}, [
|
|
63
|
+
ref
|
|
64
|
+
]);
|
|
65
|
+
useEffect(()=>{
|
|
66
|
+
if (!isDisabledByAutoSave && focusRestoreTargetRef.current) {
|
|
67
|
+
const target = focusRestoreTargetRef.current;
|
|
68
|
+
focusRestoreTargetRef.current = null;
|
|
69
|
+
if (target.isConnected && document.activeElement === document.body) target.focus();
|
|
70
|
+
}
|
|
71
|
+
}, [
|
|
72
|
+
isDisabledByAutoSave
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
function BaseField({ children, disabled, ref: refProp }) {
|
|
76
|
+
const autoSaveContext = useAutoSaveContext();
|
|
77
|
+
const indicator = useAutoSaveIndicator();
|
|
78
|
+
const field = useFieldContext();
|
|
79
|
+
const ref = useRef(null);
|
|
80
|
+
const fieldId = useFieldId();
|
|
81
|
+
const hintTextId = useHintTextId();
|
|
82
|
+
useScrollToHash(field.name, ref);
|
|
83
|
+
useFocusRestore(ref);
|
|
84
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
85
|
+
gap: "sm",
|
|
86
|
+
align: "center",
|
|
87
|
+
children: [
|
|
88
|
+
children({
|
|
89
|
+
ref: mergeRefs(ref, refProp),
|
|
90
|
+
disabled: !!disabled || autoSaveContext?.status === 'pending',
|
|
91
|
+
'aria-invalid': !field.state.meta.isValid,
|
|
92
|
+
'aria-describedby': hintTextId,
|
|
93
|
+
onBlur: field.handleBlur,
|
|
94
|
+
name: field.name,
|
|
95
|
+
id: fieldId
|
|
96
|
+
}, {
|
|
97
|
+
indicator
|
|
98
|
+
}),
|
|
99
|
+
/*#__PURE__*/ jsx(FieldMeta.Status, {
|
|
100
|
+
disabled: disabled
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function animateRowHighlight(fieldName, node) {
|
|
106
|
+
if (!node) return;
|
|
107
|
+
const selector = `#${CSS.escape(fieldName)}`;
|
|
108
|
+
const fieldRow = node.closest(selector) ?? node.querySelector(selector);
|
|
109
|
+
if (fieldRow) {
|
|
110
|
+
fieldRow.dataset.highlight = '';
|
|
111
|
+
fieldRow.addEventListener('animationend', ()=>delete fieldRow.dataset.highlight, {
|
|
112
|
+
once: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export { BaseField, useAutoSaveIndicator };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type CheckboxProps } from '../../checkbox/index.js';
|
|
3
|
+
import { type BaseFieldProps } from './baseField.js';
|
|
4
|
+
type Props = BaseFieldProps<HTMLInputElement> & Omit<CheckboxProps, 'checked' | 'onChange' | 'onBlur' | 'disabled' | 'id' | 'ref'> & {
|
|
5
|
+
checked: boolean;
|
|
6
|
+
label: React.ReactNode;
|
|
7
|
+
onChange: (checked: boolean) => void;
|
|
8
|
+
hintText?: React.ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare function CheckboxField({ checked, disabled, hintText, label, onChange, ref, ...props }: Props): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Checkbox } from "../../checkbox/index.js";
|
|
3
|
+
import { FieldMeta } from "./meta.js";
|
|
4
|
+
import { Container, Flex, Grid } from "../../layout/index.js";
|
|
5
|
+
import { BaseField } from "./baseField.js";
|
|
6
|
+
function CheckboxField({ checked, disabled, hintText, label, onChange, ref, ...props }) {
|
|
7
|
+
return /*#__PURE__*/ jsx(BaseField, {
|
|
8
|
+
disabled: disabled,
|
|
9
|
+
ref: ref,
|
|
10
|
+
children: (fieldProps, { indicator })=>/*#__PURE__*/ jsxs(Grid, {
|
|
11
|
+
columns: "max-content minmax(0, 1fr)",
|
|
12
|
+
gap: "xs sm",
|
|
13
|
+
align: "center",
|
|
14
|
+
flexGrow: 1,
|
|
15
|
+
children: [
|
|
16
|
+
/*#__PURE__*/ jsx(Checkbox, {
|
|
17
|
+
...fieldProps,
|
|
18
|
+
...props,
|
|
19
|
+
checked: checked,
|
|
20
|
+
onChange: (event)=>onChange(event.target.checked)
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ jsxs(Flex, {
|
|
23
|
+
align: "center",
|
|
24
|
+
gap: "sm",
|
|
25
|
+
children: [
|
|
26
|
+
/*#__PURE__*/ jsx(FieldMeta.Label, {
|
|
27
|
+
children: label
|
|
28
|
+
}),
|
|
29
|
+
indicator
|
|
30
|
+
]
|
|
31
|
+
}),
|
|
32
|
+
hintText && /*#__PURE__*/ jsx(Container, {
|
|
33
|
+
column: 2,
|
|
34
|
+
children: /*#__PURE__*/ jsx(FieldMeta.HintText, {
|
|
35
|
+
children: hintText
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
]
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
export { CheckboxField };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type BaseFieldProps } from './baseField.js';
|
|
3
|
+
export interface CheckboxGroupProps<T extends string> extends BaseFieldProps<HTMLDivElement> {
|
|
4
|
+
children: (components: {
|
|
5
|
+
Item: (props: CheckboxGroupItemProps<NoInfer<T>>) => React.JSX.Element;
|
|
6
|
+
}) => React.ReactNode;
|
|
7
|
+
onChange: (value: Array<NoInfer<T>>) => void;
|
|
8
|
+
value: T[];
|
|
9
|
+
}
|
|
10
|
+
interface CheckboxGroupItemProps<T extends string> {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
value: T;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const CheckboxGroupField: <T extends string>(props: CheckboxGroupProps<T>) => React.JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { Checkbox } from "../../checkbox/index.js";
|
|
4
|
+
import { useAutoSaveContext } from "../autoSaveContext.js";
|
|
5
|
+
import { useLabelId } from "./fieldIds.js";
|
|
6
|
+
import { GroupProvider, useGroupItemContext } from "./groupContext.js";
|
|
7
|
+
import { useFieldContext } from "../formContext.js";
|
|
8
|
+
import { Flex, Stack } from "../../layout/index.js";
|
|
9
|
+
import { Text } from "../../text/index.js";
|
|
10
|
+
import { BaseField } from "./baseField.js";
|
|
11
|
+
function CheckboxGroup({ children, value, onChange, disabled, ref }) {
|
|
12
|
+
const field = useFieldContext();
|
|
13
|
+
const labelId = useLabelId();
|
|
14
|
+
const autoSaveContext = useAutoSaveContext();
|
|
15
|
+
return /*#__PURE__*/ jsx(BaseField, {
|
|
16
|
+
disabled: disabled,
|
|
17
|
+
ref: ref,
|
|
18
|
+
children: ({ disabled: isDisabled, name, ...baseProps }, { indicator })=>/*#__PURE__*/ jsxs(GroupProvider, {
|
|
19
|
+
value: {
|
|
20
|
+
'aria-describedby': baseProps['aria-describedby'],
|
|
21
|
+
'aria-invalid': baseProps['aria-invalid'],
|
|
22
|
+
disabled: isDisabled,
|
|
23
|
+
name,
|
|
24
|
+
isChecked: (itemValue)=>value.includes(itemValue),
|
|
25
|
+
onChange: (itemValue, checked)=>{
|
|
26
|
+
onChange(checked ? [
|
|
27
|
+
...value,
|
|
28
|
+
itemValue
|
|
29
|
+
] : value.filter((item)=>item !== itemValue));
|
|
30
|
+
if (autoSaveContext) {
|
|
31
|
+
autoSaveContext.resetOnErrorRef.current = true;
|
|
32
|
+
field.handleBlur();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ jsx(Stack, {
|
|
38
|
+
...baseProps,
|
|
39
|
+
role: "group",
|
|
40
|
+
"aria-labelledby": labelId,
|
|
41
|
+
"aria-disabled": isDisabled,
|
|
42
|
+
flexGrow: 1,
|
|
43
|
+
tabIndex: -1,
|
|
44
|
+
onFocus: (event)=>{
|
|
45
|
+
if (event.target === event.currentTarget) event.currentTarget.querySelector('input[type="checkbox"]:enabled')?.focus();
|
|
46
|
+
},
|
|
47
|
+
children: children(checkboxGroupComponents)
|
|
48
|
+
}),
|
|
49
|
+
indicator
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function CheckboxGroupItem({ children, value: itemValue, disabled }) {
|
|
55
|
+
const { checked, onChange, disabled: groupDisabled, ...fieldProps } = useGroupItemContext(itemValue);
|
|
56
|
+
const id = useId();
|
|
57
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
58
|
+
as: "label",
|
|
59
|
+
gap: "sm",
|
|
60
|
+
align: "center",
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ jsx(Checkbox, {
|
|
63
|
+
...fieldProps,
|
|
64
|
+
id: id,
|
|
65
|
+
value: itemValue,
|
|
66
|
+
checked: checked,
|
|
67
|
+
disabled: groupDisabled || disabled,
|
|
68
|
+
onChange: (event)=>onChange(itemValue, event.target.checked)
|
|
69
|
+
}),
|
|
70
|
+
/*#__PURE__*/ jsx(Text, {
|
|
71
|
+
children: children
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const checkboxGroupComponents = {
|
|
77
|
+
Item: CheckboxGroupItem
|
|
78
|
+
};
|
|
79
|
+
const CheckboxGroupField = CheckboxGroup;
|
|
80
|
+
export { CheckboxGroupField };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type MultipleSelectProps, type SelectKey, type SingleSelectProps } from '../../compactSelect/index.js';
|
|
2
|
+
import { type BaseFieldProps } from './baseField.js';
|
|
3
|
+
type FieldOverrides = 'value' | 'onChange' | 'disabled' | 'onBlur' | 'id';
|
|
4
|
+
type CompactSelectFieldProps<TValue extends SelectKey> = BaseFieldProps<HTMLButtonElement> & ((Omit<MultipleSelectProps<TValue>, FieldOverrides> & {
|
|
5
|
+
onChange: (value: TValue[]) => void;
|
|
6
|
+
value: TValue[];
|
|
7
|
+
}) | (Omit<Extract<SingleSelectProps<TValue>, {
|
|
8
|
+
clearable: true;
|
|
9
|
+
}>, FieldOverrides> & {
|
|
10
|
+
onChange: (value: TValue | null) => void;
|
|
11
|
+
value: TValue | null;
|
|
12
|
+
}) | (Omit<Extract<SingleSelectProps<TValue>, {
|
|
13
|
+
clearable?: false;
|
|
14
|
+
}>, FieldOverrides> & {
|
|
15
|
+
onChange: (value: TValue) => void;
|
|
16
|
+
value: TValue | null;
|
|
17
|
+
}));
|
|
18
|
+
export declare function CompactSelectField<TValue extends SelectKey>({ disabled, ref, trigger, ...props }: CompactSelectFieldProps<TValue>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { mergeProps, mergeRefs } from "@react-aria/utils";
|
|
4
|
+
import { CompactSelect } from "../../compactSelect/index.js";
|
|
5
|
+
import { useAutoSaveContext } from "../autoSaveContext.js";
|
|
6
|
+
import { useFieldContext } from "../formContext.js";
|
|
7
|
+
import { Container } from "../../layout/index.js";
|
|
8
|
+
import { OverlayTrigger } from "../../overlayTrigger.js";
|
|
9
|
+
import { BaseField } from "./baseField.js";
|
|
10
|
+
function CompactSelectField({ disabled, ref, trigger, ...props }) {
|
|
11
|
+
const autoSaveContext = useAutoSaveContext();
|
|
12
|
+
const field = useFieldContext();
|
|
13
|
+
const selectProps = props.multiple ? {
|
|
14
|
+
...props,
|
|
15
|
+
onChange: (options)=>{
|
|
16
|
+
props.onChange(options.map((option)=>option.value));
|
|
17
|
+
}
|
|
18
|
+
} : props.clearable ? {
|
|
19
|
+
...props,
|
|
20
|
+
value: props.value ?? void 0,
|
|
21
|
+
onChange: (option)=>{
|
|
22
|
+
props.onChange(option?.value ?? null);
|
|
23
|
+
if (autoSaveContext) field.handleBlur();
|
|
24
|
+
}
|
|
25
|
+
} : {
|
|
26
|
+
...props,
|
|
27
|
+
value: props.value ?? void 0,
|
|
28
|
+
onChange: (option)=>{
|
|
29
|
+
props.onChange(option.value);
|
|
30
|
+
if (autoSaveContext) field.handleBlur();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return /*#__PURE__*/ jsx(BaseField, {
|
|
34
|
+
disabled: disabled ?? 0 === props.options.length,
|
|
35
|
+
ref: ref,
|
|
36
|
+
children: (fieldProps, { indicator })=>/*#__PURE__*/ jsxs(Fragment, {
|
|
37
|
+
children: [
|
|
38
|
+
/*#__PURE__*/ jsx(Container, {
|
|
39
|
+
flex: 1,
|
|
40
|
+
minWidth: 0,
|
|
41
|
+
children: /*#__PURE__*/ jsx(CompactSelect, {
|
|
42
|
+
...selectProps,
|
|
43
|
+
style: {
|
|
44
|
+
width: '100%',
|
|
45
|
+
...props.style
|
|
46
|
+
},
|
|
47
|
+
triggerId: fieldProps.id,
|
|
48
|
+
disabled: fieldProps.disabled,
|
|
49
|
+
onClose: ()=>{
|
|
50
|
+
props.onClose?.();
|
|
51
|
+
if (!autoSaveContext || props.multiple) field.handleBlur();
|
|
52
|
+
},
|
|
53
|
+
trigger: (triggerProps, isOpen)=>{
|
|
54
|
+
const mergedProps = mergeProps({
|
|
55
|
+
style: {
|
|
56
|
+
width: '100%'
|
|
57
|
+
}
|
|
58
|
+
}, triggerProps, {
|
|
59
|
+
...fieldProps,
|
|
60
|
+
onBlur: ()=>{
|
|
61
|
+
if (!isOpen) fieldProps.onBlur();
|
|
62
|
+
}
|
|
63
|
+
}, {
|
|
64
|
+
ref: mergeRefs(triggerProps.ref, fieldProps.ref)
|
|
65
|
+
});
|
|
66
|
+
return trigger ? trigger(mergedProps, isOpen) : /*#__PURE__*/ jsx(OverlayTrigger.Button, {
|
|
67
|
+
...mergedProps
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}),
|
|
72
|
+
indicator
|
|
73
|
+
]
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export { CompactSelectField };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type InputProps } from '../../input/index.js';
|
|
3
|
+
import { type BaseFieldProps } from './baseField.js';
|
|
4
|
+
interface SharedInputFieldProps extends BaseFieldProps<HTMLInputElement>, Omit<InputProps, 'value' | 'onChange' | 'onBlur' | 'disabled' | 'id' | 'type' | 'readOnly'> {
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean | string;
|
|
7
|
+
leadingItems?: React.ReactNode;
|
|
8
|
+
trailingItems?: React.ReactNode;
|
|
9
|
+
type?: 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week';
|
|
10
|
+
}
|
|
11
|
+
export type InputFieldProps = SharedInputFieldProps & ({
|
|
12
|
+
readOnly: true;
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
|
+
} | {
|
|
15
|
+
onChange: (value: string) => void;
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
});
|
|
18
|
+
export declare function InputField({ onChange, disabled, leadingItems, trailingItems, ref, ...props }: InputFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { InputGroup } from "../../input/index.js";
|
|
3
|
+
import { BaseField } from "./baseField.js";
|
|
4
|
+
function InputField({ onChange, disabled, leadingItems, trailingItems, ref, ...props }) {
|
|
5
|
+
return /*#__PURE__*/ jsx(BaseField, {
|
|
6
|
+
disabled: disabled,
|
|
7
|
+
ref: ref,
|
|
8
|
+
children: (fieldProps, { indicator })=>/*#__PURE__*/ jsxs(InputGroup, {
|
|
9
|
+
style: {
|
|
10
|
+
flex: 1
|
|
11
|
+
},
|
|
12
|
+
children: [
|
|
13
|
+
leadingItems && /*#__PURE__*/ jsx(InputGroup.LeadingItems, {
|
|
14
|
+
children: leadingItems
|
|
15
|
+
}),
|
|
16
|
+
/*#__PURE__*/ jsx(InputGroup.Input, {
|
|
17
|
+
...fieldProps,
|
|
18
|
+
...props,
|
|
19
|
+
onChange: onChange ? (e)=>onChange(e.target.value) : void 0
|
|
20
|
+
}),
|
|
21
|
+
/*#__PURE__*/ jsxs(InputGroup.TrailingItems, {
|
|
22
|
+
children: [
|
|
23
|
+
trailingItems,
|
|
24
|
+
indicator
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
]
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
export { InputField };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import { useFieldContext } from "../formContext.js";
|
|
4
|
+
import { RequiredIndicator, Warning } from "../icons.js";
|
|
5
|
+
import { DisabledTip, InfoText } from "../../info/index.js";
|
|
6
|
+
import { Container, Flex } from "../../layout/index.js";
|
|
7
|
+
import { Text } from "../../text/index.js";
|
|
8
|
+
import { Tooltip } from "../../tooltip/index.js";
|
|
7
9
|
import { useFieldId, useHintTextId, useLabelId } from "./fieldIds.js";
|
|
8
|
-
import { useFieldContext } from "./formContext.js";
|
|
9
10
|
import { useGroupContext } from "./groupContext.js";
|
|
10
|
-
import { RequiredIndicator, Warning } from "./icons.js";
|
|
11
11
|
function HintText(props) {
|
|
12
12
|
const id = useHintTextId();
|
|
13
13
|
return /*#__PURE__*/ jsx(Container, {
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { InputFieldProps } from './inputField.js';
|
|
2
|
+
export declare function NumberField(props: Omit<InputFieldProps, 'type' | 'value' | 'onChange'> & {
|
|
3
|
+
onChange: (value: number | null) => void;
|
|
4
|
+
value: number | null;
|
|
5
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { InputField } from "./inputField.js";
|
|
3
|
+
function NumberField(props) {
|
|
4
|
+
return /*#__PURE__*/ jsx(InputField, {
|
|
5
|
+
...props,
|
|
6
|
+
value: null === props.value ? '' : String(props.value),
|
|
7
|
+
onChange: (value)=>props.onChange('' === value ? null : Number(value)),
|
|
8
|
+
type: "number"
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export { NumberField };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { IconHide } from "@sentry/icons/hide";
|
|
4
|
+
import { IconShow } from "@sentry/icons/show";
|
|
5
|
+
import { Button } from "../../button/index.js";
|
|
6
|
+
import { InputField } from "./inputField.js";
|
|
7
|
+
import { useTranslation } from "../../translation/useTranslation.js";
|
|
8
|
+
function PasswordField(props) {
|
|
9
|
+
const [isFieldVisible, setisFieldVisible] = useState(false);
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
return /*#__PURE__*/ jsx(InputField, {
|
|
12
|
+
...props,
|
|
13
|
+
type: isFieldVisible ? 'text' : 'password',
|
|
14
|
+
trailingItems: /*#__PURE__*/ jsx(Button, {
|
|
15
|
+
size: "xs",
|
|
16
|
+
variant: "transparent",
|
|
17
|
+
icon: isFieldVisible ? /*#__PURE__*/ jsx(IconShow, {
|
|
18
|
+
size: "xs"
|
|
19
|
+
}) : /*#__PURE__*/ jsx(IconHide, {
|
|
20
|
+
size: "xs"
|
|
21
|
+
}),
|
|
22
|
+
"aria-label": isFieldVisible ? t('Hide password') : t('Show password'),
|
|
23
|
+
onClick: ()=>setisFieldVisible((v)=>!v)
|
|
24
|
+
})
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export { PasswordField };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
export interface RadioGroupProps<T extends string> {
|
|
3
|
+
children: (components: {
|
|
4
|
+
Item: (props: RadioItemProps<NoInfer<T>>) => React.JSX.Element;
|
|
5
|
+
}) => React.ReactNode;
|
|
6
|
+
onChange: (value: NoInfer<T>) => void;
|
|
7
|
+
value: T;
|
|
8
|
+
disabled?: boolean | string;
|
|
9
|
+
}
|
|
10
|
+
interface RadioItemProps<T extends string> {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
value: T;
|
|
13
|
+
description?: React.ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare const RadioGroupField: <T extends string>(props: RadioGroupProps<T>) => React.JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { useAutoSaveContext } from "../autoSaveContext.js";
|
|
4
|
+
import { useLabelId } from "./fieldIds.js";
|
|
5
|
+
import { GroupProvider, useGroupItemContext } from "./groupContext.js";
|
|
6
|
+
import { FieldMeta } from "./meta.js";
|
|
7
|
+
import { useFieldContext } from "../formContext.js";
|
|
8
|
+
import { Flex, Stack } from "../../layout/index.js";
|
|
9
|
+
import { Radio } from "../../radio/index.js";
|
|
10
|
+
import { Text } from "../../text/index.js";
|
|
11
|
+
import { useAutoSaveIndicator } from "./baseField.js";
|
|
12
|
+
function RadioGroup({ children, value, onChange, disabled }) {
|
|
13
|
+
const field = useFieldContext();
|
|
14
|
+
const labelId = useLabelId();
|
|
15
|
+
const autoSaveContext = useAutoSaveContext();
|
|
16
|
+
const indicator = useAutoSaveIndicator();
|
|
17
|
+
const isDisabled = !!disabled || autoSaveContext?.status === 'pending';
|
|
18
|
+
const contextValue = {
|
|
19
|
+
name: field.name,
|
|
20
|
+
isChecked: (itemValue)=>itemValue === value,
|
|
21
|
+
onChange: (newValue)=>{
|
|
22
|
+
onChange(newValue);
|
|
23
|
+
if (autoSaveContext) {
|
|
24
|
+
autoSaveContext.resetOnErrorRef.current = true;
|
|
25
|
+
field.handleBlur();
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
onBlur: field.handleBlur,
|
|
29
|
+
disabled: isDisabled,
|
|
30
|
+
'aria-invalid': !field.state.meta.isValid
|
|
31
|
+
};
|
|
32
|
+
return /*#__PURE__*/ jsx(GroupProvider, {
|
|
33
|
+
value: contextValue,
|
|
34
|
+
children: /*#__PURE__*/ jsxs(Flex, {
|
|
35
|
+
role: "radiogroup",
|
|
36
|
+
"aria-labelledby": labelId,
|
|
37
|
+
gap: "sm",
|
|
38
|
+
align: "center",
|
|
39
|
+
children: [
|
|
40
|
+
children(radioGroupComponents),
|
|
41
|
+
indicator ?? (autoSaveContext ? /*#__PURE__*/ jsx(Flex, {
|
|
42
|
+
width: "14px",
|
|
43
|
+
flexShrink: 0
|
|
44
|
+
}) : null),
|
|
45
|
+
/*#__PURE__*/ jsx(FieldMeta.Status, {
|
|
46
|
+
disabled: disabled
|
|
47
|
+
})
|
|
48
|
+
]
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function RadioItem({ children, value, description }) {
|
|
53
|
+
const { checked, onChange, ...fieldProps } = useGroupItemContext(value);
|
|
54
|
+
const descriptionId = useId();
|
|
55
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
56
|
+
as: "label",
|
|
57
|
+
gap: "sm",
|
|
58
|
+
align: "start",
|
|
59
|
+
margin: "0",
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ jsx(Radio, {
|
|
62
|
+
...fieldProps,
|
|
63
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
64
|
+
value: value,
|
|
65
|
+
checked: checked,
|
|
66
|
+
onChange: ()=>onChange(value, true)
|
|
67
|
+
}),
|
|
68
|
+
/*#__PURE__*/ jsxs(Stack, {
|
|
69
|
+
gap: "xs",
|
|
70
|
+
paddingTop: "xs",
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ jsx(Text, {
|
|
73
|
+
bold: false,
|
|
74
|
+
children: children
|
|
75
|
+
}),
|
|
76
|
+
description && /*#__PURE__*/ jsx(Text, {
|
|
77
|
+
bold: false,
|
|
78
|
+
size: "sm",
|
|
79
|
+
variant: "muted",
|
|
80
|
+
id: descriptionId,
|
|
81
|
+
children: description
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
})
|
|
85
|
+
]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const radioGroupComponents = {
|
|
89
|
+
Item: RadioItem
|
|
90
|
+
};
|
|
91
|
+
const RadioGroupField = RadioGroup;
|
|
92
|
+
export { RadioGroupField };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DistributedOmit } from 'type-fest';
|
|
2
|
+
import { type SliderProps } from '../../slider/index.js';
|
|
3
|
+
import { type BaseFieldProps } from './baseField.js';
|
|
4
|
+
export declare function RangeField({ onChange, disabled, value, ref, ...props }: BaseFieldProps<HTMLInputElement> & DistributedOmit<SliderProps, 'value' | 'onChange' | 'onBlur' | 'disabled' | 'id'> & {
|
|
5
|
+
onChange: (value: number) => void;
|
|
6
|
+
value: number;
|
|
7
|
+
disabled?: boolean | string;
|
|
8
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|