@olenbetong/appframe-ds 0.2.0 → 0.4.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.
Files changed (117) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/es/AfLookup/BoundLookup.d.ts +10 -0
  3. package/es/AfLookup/BoundLookup.js +16 -0
  4. package/es/AfLookup/Combobox.css +78 -0
  5. package/es/AfLookup/Combobox.d.ts +31 -0
  6. package/es/AfLookup/Combobox.js +71 -0
  7. package/es/AfLookup/Lookup.css +125 -0
  8. package/es/AfLookup/Lookup.d.ts +35 -0
  9. package/es/AfLookup/Lookup.js +42 -0
  10. package/es/AfLookup/LookupEdit.d.ts +21 -0
  11. package/es/AfLookup/LookupEdit.js +49 -0
  12. package/es/AfLookup/LookupGrid.css +57 -0
  13. package/es/AfLookup/LookupGrid.d.ts +13 -0
  14. package/es/AfLookup/LookupGrid.js +27 -0
  15. package/es/AfLookup/index.d.ts +5 -0
  16. package/es/AfLookup/index.js +5 -0
  17. package/es/binding/BoundCheckbox.d.ts +9 -0
  18. package/es/binding/BoundCheckbox.js +13 -0
  19. package/es/binding/BoundDatePicker.d.ts +7 -0
  20. package/es/binding/BoundDatePicker.js +12 -0
  21. package/es/binding/BoundDateTimePicker.d.ts +7 -0
  22. package/es/binding/BoundDateTimePicker.js +14 -0
  23. package/es/binding/BoundInput.d.ts +6 -0
  24. package/es/binding/BoundInput.js +12 -0
  25. package/es/binding/BoundNumericTextField.d.ts +20 -0
  26. package/es/binding/BoundNumericTextField.js +58 -0
  27. package/es/binding/BoundSelect.d.ts +9 -0
  28. package/es/binding/BoundSelect.js +13 -0
  29. package/es/binding/BoundSwitch.d.ts +9 -0
  30. package/es/binding/BoundSwitch.js +13 -0
  31. package/es/binding/BoundTextField.d.ts +7 -0
  32. package/es/binding/BoundTextField.js +22 -0
  33. package/es/binding/CancelButton.d.ts +3 -0
  34. package/es/binding/CancelButton.js +14 -0
  35. package/es/binding/CancelIconButton.d.ts +2 -0
  36. package/es/binding/CancelIconButton.js +15 -0
  37. package/es/binding/DataEditToolbar.d.ts +13 -0
  38. package/es/binding/DataEditToolbar.js +28 -0
  39. package/es/binding/DataObjectSelect.d.ts +50 -0
  40. package/es/binding/DataObjectSelect.js +26 -0
  41. package/es/binding/DeleteButton.d.ts +8 -0
  42. package/es/binding/DeleteButton.js +14 -0
  43. package/es/binding/DeleteIconButton.d.ts +10 -0
  44. package/es/binding/DeleteIconButton.js +15 -0
  45. package/es/binding/RefreshButton.d.ts +3 -0
  46. package/es/binding/RefreshButton.js +14 -0
  47. package/es/binding/RefreshIconButton.d.ts +2 -0
  48. package/es/binding/RefreshIconButton.js +16 -0
  49. package/es/binding/RefreshRowIconButton.d.ts +7 -0
  50. package/es/binding/RefreshRowIconButton.js +15 -0
  51. package/es/binding/SaveButton.d.ts +3 -0
  52. package/es/binding/SaveButton.js +14 -0
  53. package/es/binding/SaveIconButton.d.ts +2 -0
  54. package/es/binding/SaveIconButton.js +15 -0
  55. package/es/binding/index.d.ts +19 -0
  56. package/es/binding/index.js +19 -0
  57. package/es/index.d.ts +3 -0
  58. package/es/index.js +3 -0
  59. package/es/layout/AppLayoutDesktop.css +65 -0
  60. package/es/layout/AppLayoutDesktop.d.ts +3 -0
  61. package/es/layout/AppLayoutDesktop.js +19 -0
  62. package/es/layout/AppLayoutMobile.css +75 -0
  63. package/es/layout/AppLayoutMobile.d.ts +3 -0
  64. package/es/layout/AppLayoutMobile.js +18 -0
  65. package/es/layout/AppMenu.css +67 -0
  66. package/es/layout/AppMenu.d.ts +8 -0
  67. package/es/layout/AppMenu.js +36 -0
  68. package/es/layout/AppMenuItem.css +97 -0
  69. package/es/layout/AppMenuItem.d.ts +50 -0
  70. package/es/layout/AppMenuItem.js +14 -0
  71. package/es/layout/AppMenuSubheader.css +18 -0
  72. package/es/layout/AppMenuSubheader.d.ts +4 -0
  73. package/es/layout/AppMenuSubheader.js +6 -0
  74. package/es/layout/ErrorBoundary.css +101 -0
  75. package/es/layout/ErrorBoundary.d.ts +30 -0
  76. package/es/layout/ErrorBoundary.js +81 -0
  77. package/es/layout/PageContainer.css +29 -0
  78. package/es/layout/PageContainer.d.ts +7 -0
  79. package/es/layout/PageContainer.js +6 -0
  80. package/es/layout/PartnerToggle.d.ts +5 -0
  81. package/es/layout/PartnerToggle.js +9 -0
  82. package/es/layout/constants.d.ts +2 -0
  83. package/es/layout/constants.js +2 -0
  84. package/es/layout/index.css +65 -0
  85. package/es/layout/index.d.ts +33 -0
  86. package/es/layout/index.js +31 -0
  87. package/package.json +17 -12
  88. package/src/AfLookup/BoundLookup.tsx +4 -4
  89. package/src/AfLookup/Combobox.css +1 -1
  90. package/src/AfLookup/Combobox.tsx +79 -108
  91. package/src/AfLookup/Lookup.css +21 -0
  92. package/src/AfLookup/Lookup.tsx +25 -157
  93. package/src/AfLookup/LookupEdit.tsx +131 -0
  94. package/src/AfLookup/LookupGrid.css +57 -0
  95. package/src/AfLookup/LookupGrid.tsx +98 -0
  96. package/src/AfLookup/index.ts +2 -0
  97. package/src/binding/DataObjectSelect.tsx +1 -1
  98. package/src/index.ts +1 -0
  99. package/src/layout/AppLayoutDesktop.css +65 -0
  100. package/src/layout/AppLayoutDesktop.tsx +45 -0
  101. package/src/layout/AppLayoutMobile.css +75 -0
  102. package/src/layout/AppLayoutMobile.tsx +50 -0
  103. package/src/layout/AppMenu.css +67 -0
  104. package/src/layout/AppMenu.tsx +75 -0
  105. package/src/layout/AppMenuItem.css +97 -0
  106. package/src/layout/AppMenuItem.tsx +80 -0
  107. package/src/layout/AppMenuSubheader.css +18 -0
  108. package/src/layout/AppMenuSubheader.tsx +14 -0
  109. package/src/layout/ErrorBoundary.css +101 -0
  110. package/src/layout/ErrorBoundary.tsx +162 -0
  111. package/src/layout/PageContainer.css +29 -0
  112. package/src/layout/PageContainer.tsx +19 -0
  113. package/src/layout/PartnerToggle.tsx +23 -0
  114. package/src/layout/constants.ts +2 -0
  115. package/src/layout/index.css +65 -0
  116. package/src/layout/index.tsx +62 -0
  117. package/tsconfig.build.tsbuildinfo +1 -0
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Textfield } from "@digdir/designsystemet-react";
3
+ import { useField } from "@olenbetong/appframe-react";
4
+ import { forwardRef } from "react";
5
+ export const BoundDatePicker = forwardRef(function BoundDatePicker({ field, ...props }, ref) {
6
+ let { error, value, onChange, onKeyDown } = useField(field);
7
+ let inputValue = value;
8
+ if (value instanceof Date) {
9
+ inputValue = value.toISOString().split("T")[0];
10
+ }
11
+ return (_jsx(Textfield, { type: "date", name: field, error: error ?? undefined, ...props, value: inputValue ?? "", onChange: (evt) => onChange(evt), onKeyDown: (evt) => onKeyDown(evt), ref: ref }));
12
+ });
@@ -0,0 +1,7 @@
1
+ import { type TextfieldProps } from "@digdir/designsystemet-react";
2
+ export type BoundDateTimePickerProps = Omit<TextfieldProps, "value" | "onChange" | "onKeyDown" | "type"> & {
3
+ field: string;
4
+ };
5
+ export declare const BoundDateTimePicker: import("react").ForwardRefExoticComponent<Omit<TextfieldProps, "onChange" | "onKeyDown" | "type" | "value"> & {
6
+ field: string;
7
+ } & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Textfield } from "@digdir/designsystemet-react";
3
+ import { useField } from "@olenbetong/appframe-react";
4
+ import { forwardRef } from "react";
5
+ export const BoundDateTimePicker = forwardRef(function BoundDateTimePicker({ field, ...props }, ref) {
6
+ let { error, value, onChange, onKeyDown } = useField(field);
7
+ let inputValue = value;
8
+ if (value instanceof Date) {
9
+ inputValue = value.toISOString().replace("Z", "");
10
+ }
11
+ return (_jsx(Textfield, { type: "datetime-local", name: field, error: error ?? undefined, ...props, value: inputValue ?? "", onChange: (evt) => {
12
+ onChange(evt, evt.target.value ? `${evt.target.value}Z` : null);
13
+ }, onKeyDown: (evt) => onKeyDown(evt), ref: ref }));
14
+ });
@@ -0,0 +1,6 @@
1
+ import { type InputProps } from "@digdir/designsystemet-react";
2
+ export type BoundInputProps = Omit<InputProps, "onChange" | "onKeyDown" | "onBlur"> & {
3
+ field: string;
4
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
5
+ };
6
+ export declare function BoundInput({ field, onChange: onChangeProp, ...props }: BoundInputProps): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Input } from "@digdir/designsystemet-react";
3
+ import { useField } from "@olenbetong/appframe-react";
4
+ export function BoundInput({ field, onChange: onChangeProp, ...props }) {
5
+ let { value, onChange, onKeyDown } = useField(field);
6
+ return (_jsx(Input, { name: field, ...props, value: value ?? "", onChange: (event) => {
7
+ onChangeProp?.(event);
8
+ if (!event.defaultPrevented) {
9
+ onChange(event);
10
+ }
11
+ }, onKeyDown: (evt) => onKeyDown(evt) }));
12
+ }
@@ -0,0 +1,20 @@
1
+ import { type TextfieldProps } from "@digdir/designsystemet-react";
2
+ /**
3
+ * A Designsystemet `Textfield` bound to an Appframe data source field via `useField`.
4
+ *
5
+ * Adds client-side numeric validation: rejects non-numeric characters and enforces
6
+ * optional `precision` (total digits) and `scale` (decimal places) constraints.
7
+ * Validation errors are reported to the parent via the `onError` callback so the
8
+ * parent can track whether any field is in an error state (e.g., to disable Save).
9
+ *
10
+ * On blur the displayed value is normalized to a JS `Number` (comma decimal separators
11
+ * are converted to dots) so the data source always stores a proper numeric value.
12
+ */
13
+ export type BoundNumericTextFieldProps = Omit<TextfieldProps, "onChange" | "onKeyDown" | "onError"> & {
14
+ field: string;
15
+ precision?: number;
16
+ scale?: number;
17
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
18
+ onError?: (error: string | null) => void;
19
+ };
20
+ export declare function BoundNumericTextField({ field, precision, scale, onChange: onChangeProp, onError, ...props }: BoundNumericTextFieldProps): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Textfield } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString, localize } from "@olenbetong/appframe-core";
4
+ import { useField } from "@olenbetong/appframe-react";
5
+ import { useEffect, useState } from "react";
6
+ export function BoundNumericTextField({ field, precision, scale, onChange: onChangeProp, onError, ...props }) {
7
+ let { value, setValue, onChange, onKeyDown } = useField(field);
8
+ let [error, setError] = useState(null);
9
+ function checkNumber(value, precision, scale) {
10
+ if (value[0] === "0") {
11
+ value = value[0].replace("0", "");
12
+ }
13
+ let [integer, decimal] = value.split(",");
14
+ if (value.includes(".")) {
15
+ [integer, decimal] = value.split(".");
16
+ }
17
+ integer = integer.replace("-", "");
18
+ if (integer.length > precision - scale) {
19
+ setError(localize `The amount of whole numbers is too high. Allowed limit is ${precision - scale}`);
20
+ return;
21
+ }
22
+ if (decimal && decimal.length > scale) {
23
+ setError(localize `The amount of decimal places is too high. Allowed limit is ${scale}`);
24
+ return;
25
+ }
26
+ setError(null);
27
+ }
28
+ function checkError(value, precision, scale) {
29
+ let regExp = /[a-zA-Z `!@#$%^&*()_+=[\]{};':"\\|<>/?~]/;
30
+ if (regExp.test(value)) {
31
+ setError(getLocalizedString("Please enter a valid number"));
32
+ }
33
+ else if (value.substring(1).includes("-")) {
34
+ setError(getLocalizedString("Please enter a valid number"));
35
+ }
36
+ else if (precision !== undefined && scale !== undefined) {
37
+ checkNumber(value, precision, scale);
38
+ }
39
+ else {
40
+ setError(null);
41
+ }
42
+ }
43
+ useEffect(() => {
44
+ onError?.(error);
45
+ }, [error, onError]);
46
+ return (_jsx(Textfield, { name: field, error: error ?? undefined, ...props, value: value ?? "", onChange: (event) => {
47
+ onChangeProp?.(event);
48
+ if (!event.defaultPrevented) {
49
+ checkError(event.target.value, precision, scale);
50
+ onChange(event);
51
+ }
52
+ }, onKeyDown: (evt) => onKeyDown(evt), onBlur: (evt) => {
53
+ const raw = evt.target.value;
54
+ if (raw !== "") {
55
+ setValue(Number(raw.replaceAll(",", ".")));
56
+ }
57
+ } }));
58
+ }
@@ -0,0 +1,9 @@
1
+ import { type SelectProps } from "@digdir/designsystemet-react";
2
+ export type BoundSelectProps = Omit<SelectProps, "onChange" | "value"> & {
3
+ field: string;
4
+ onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void;
5
+ };
6
+ export declare const BoundSelect: import("react").ForwardRefExoticComponent<Omit<SelectProps, "onChange" | "value"> & {
7
+ field: string;
8
+ onChange?: (event: React.ChangeEvent<HTMLSelectElement>) => void;
9
+ } & import("react").RefAttributes<HTMLSelectElement>>;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Select } from "@digdir/designsystemet-react";
3
+ import { useField } from "@olenbetong/appframe-react";
4
+ import { forwardRef } from "react";
5
+ export const BoundSelect = forwardRef(function BoundSelect({ field, onChange: onChangeProp, ...props }, ref) {
6
+ let { value, onChange, onKeyDown } = useField(field);
7
+ return (_jsx(Select, { name: field, value: value ?? "", onChange: (evt) => {
8
+ onChangeProp?.(evt);
9
+ if (!evt.defaultPrevented) {
10
+ onChange(evt);
11
+ }
12
+ }, onKeyDown: (evt) => onKeyDown(evt), ...props, ref: ref }));
13
+ });
@@ -0,0 +1,9 @@
1
+ import { type SwitchProps } from "@digdir/designsystemet-react";
2
+ export type BoundSwitchProps = Omit<SwitchProps, "onChange" | "checked"> & {
3
+ field: string;
4
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
5
+ };
6
+ export declare const BoundSwitch: import("react").ForwardRefExoticComponent<Omit<SwitchProps, "checked" | "onChange"> & {
7
+ field: string;
8
+ onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
9
+ } & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Switch } from "@digdir/designsystemet-react";
3
+ import { useField } from "@olenbetong/appframe-react";
4
+ import { forwardRef } from "react";
5
+ export const BoundSwitch = forwardRef(function BoundSwitch({ field, onChange: onChangeProp, ...props }, ref) {
6
+ let { value, setValue } = useField(field);
7
+ return (_jsx(Switch, { name: field, ...props, checked: value ?? false, onChange: (evt) => {
8
+ onChangeProp?.(evt);
9
+ if (!evt.defaultPrevented) {
10
+ setValue(evt.target.checked);
11
+ }
12
+ }, ref: ref }));
13
+ });
@@ -0,0 +1,7 @@
1
+ import { type TextfieldProps } from "@digdir/designsystemet-react";
2
+ export type BoundTextFieldProps = Omit<TextfieldProps, "value" | "onChange" | "onKeyDown"> & {
3
+ field: string;
4
+ };
5
+ export declare const BoundTextField: import("react").ForwardRefExoticComponent<Omit<TextfieldProps, "onChange" | "onKeyDown" | "value"> & {
6
+ field: string;
7
+ } & import("react").RefAttributes<HTMLInputElement & HTMLTextAreaElement>>;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Textfield } from "@digdir/designsystemet-react";
3
+ import { useField } from "@olenbetong/appframe-react";
4
+ import { forwardRef } from "react";
5
+ export const BoundTextField = forwardRef(function BoundTextField({ field, ...props }, ref) {
6
+ let { error, value, onChange, onKeyDown } = useField(field);
7
+ let inputValue = value;
8
+ if (props.type === "date" && value instanceof Date) {
9
+ inputValue = value.toISOString().split("T")[0];
10
+ }
11
+ else if (["datetime", "datetime-local"].includes(props.type ?? "") && value instanceof Date) {
12
+ inputValue = value.toISOString().replace("Z", "");
13
+ }
14
+ return (_jsx(Textfield, { name: field, error: error ?? undefined, ...props, value: inputValue ?? "", onChange: (evt) => {
15
+ if (["datetime", "datetime-local"].includes(props.type ?? "")) {
16
+ onChange(evt, evt.target.value ? `${evt.target.value}Z` : null);
17
+ }
18
+ else {
19
+ onChange(evt);
20
+ }
21
+ }, onKeyDown: (evt) => onKeyDown(evt), ref: ref }));
22
+ });
@@ -0,0 +1,3 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ import { type ForwardRefExoticComponent, type RefAttributes } from "react";
3
+ export declare const CancelButton: ForwardRefExoticComponent<ButtonProps & RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString } from "@olenbetong/appframe-core";
4
+ import { useCancelButton } from "@olenbetong/appframe-react";
5
+ import { forwardRef } from "react";
6
+ export const CancelButton = forwardRef(function CancelButton({ onClick, children, ...props }, ref) {
7
+ let { cancelEdit } = useCancelButton();
8
+ return (_jsx(Button, { onClick: (evt) => {
9
+ onClick?.(evt);
10
+ if (!evt.defaultPrevented) {
11
+ cancelEdit();
12
+ }
13
+ }, variant: "secondary", ...props, ref: ref, children: children ?? getLocalizedString("Cancel") }));
14
+ });
@@ -0,0 +1,2 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ export declare const CancelIconButton: import("react").ForwardRefExoticComponent<Omit<ButtonProps, "icon"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import UndoIcon from "@mui/icons-material/Undo";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
5
+ import { useCancelButton } from "@olenbetong/appframe-react";
6
+ import { forwardRef } from "react";
7
+ export const CancelIconButton = forwardRef(function CancelIconButton({ onClick, children, ...props }, ref) {
8
+ let { cancelEdit } = useCancelButton();
9
+ return (_jsx(Button, { icon: true, "aria-label": getLocalizedString("Revert unsaved changes"), variant: "tertiary", onClick: (evt) => {
10
+ onClick?.(evt);
11
+ if (!evt.defaultPrevented) {
12
+ cancelEdit();
13
+ }
14
+ }, ...props, ref: ref, children: children ?? _jsx(UndoIcon, {}) }));
15
+ });
@@ -0,0 +1,13 @@
1
+ import type { DataObject } from "@olenbetong/appframe-data";
2
+ export type DataEditToolbarProps = React.HTMLAttributes<HTMLDivElement> & {
3
+ /**
4
+ * If different data objects are used for navigation and editing, you can set the data object
5
+ * used for navigation with this property.
6
+ */
7
+ navigationDataObject?: DataObject<any>;
8
+ /**
9
+ * If true, will add buttons to move to the next/previous index in the data object.
10
+ */
11
+ showNavigation?: boolean;
12
+ };
13
+ export declare function DataEditToolbar({ children, navigationDataObject, showNavigation, style, ...props }: DataEditToolbarProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Tooltip } from "@digdir/designsystemet-react";
3
+ import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
4
+ import ChevronRightIcon from "@mui/icons-material/ChevronRight";
5
+ import { getLocalizedString } from "@olenbetong/appframe-core";
6
+ import { useCurrentIndex, useDataLength, useDataObject } from "@olenbetong/appframe-react";
7
+ import { CancelIconButton } from "./CancelIconButton.js";
8
+ import { RefreshRowIconButton } from "./RefreshRowIconButton.js";
9
+ import { SaveIconButton } from "./SaveIconButton.js";
10
+ function IndexNavigator({ dataObject }) {
11
+ let count = useDataLength(dataObject);
12
+ let index = useCurrentIndex(dataObject);
13
+ if (count <= 1) {
14
+ return null;
15
+ }
16
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { icon: true, variant: "tertiary", "aria-label": getLocalizedString("Previous"), onClick: () => dataObject.setCurrentIndex(index - 1), disabled: index <= 0, children: _jsx(ChevronLeftIcon, {}) }), _jsx(Button, { icon: true, variant: "tertiary", "aria-label": getLocalizedString("Next"), onClick: () => dataObject.setCurrentIndex(index + 1), disabled: index >= count - 1, children: _jsx(ChevronRightIcon, {}) })] }));
17
+ }
18
+ export function DataEditToolbar({ children, navigationDataObject, showNavigation, style, ...props }) {
19
+ let dataObject = useDataObject();
20
+ return (_jsxs("div", { style: {
21
+ display: "flex",
22
+ alignItems: "center",
23
+ minHeight: "48px",
24
+ borderBottom: "1px solid rgb(0 0 0 / 0.12)",
25
+ borderTop: "1px solid rgb(0 0 0 / 0.12)",
26
+ ...style,
27
+ }, ...props, children: [_jsx(Tooltip, { content: getLocalizedString("Save changes"), children: _jsx(SaveIconButton, {}) }), _jsx(Tooltip, { content: getLocalizedString("Revert unsaved changes"), children: _jsx(CancelIconButton, {}) }), _jsx(Tooltip, { content: getLocalizedString("Refresh record"), children: _jsx(RefreshRowIconButton, {}) }), children, showNavigation && (_jsx("div", { style: { marginLeft: "auto" }, children: _jsx(IndexNavigator, { dataObject: navigationDataObject ?? dataObject }) }))] }));
28
+ }
@@ -0,0 +1,50 @@
1
+ import type { DataObject } from "@olenbetong/appframe-data";
2
+ export type DataObjectSelectProps<T extends Record<string, unknown>> = React.SelectHTMLAttributes<HTMLSelectElement> & {
3
+ /**
4
+ * Data object to get options from. Only the data handler is used, so the component
5
+ * will not affect the state of the data object.
6
+ */
7
+ dataObject: DataObject<T>;
8
+ /**
9
+ * Filter to use when getting options.
10
+ */
11
+ filter?: string;
12
+ /**
13
+ * The label displayed above the select.
14
+ */
15
+ label?: React.ReactNode;
16
+ /**
17
+ * Whether the user is allowed to clear the value. Will add an empty option at the
18
+ * start of the options list.
19
+ */
20
+ nullable?: boolean;
21
+ /**
22
+ * If nullable is true, this is the label for the empty option. Default is an empty string.
23
+ */
24
+ blankLabel?: string;
25
+ /**
26
+ * The field in the options record to use as the value.
27
+ */
28
+ valueField?: string;
29
+ /**
30
+ * The field in the options record to use as the label.
31
+ */
32
+ labelField?: string;
33
+ /**
34
+ * If the value isn't simply a record field, you can pass a function here to
35
+ * get the value from the record.
36
+ */
37
+ getOptionValue?: (option: T) => string;
38
+ /**
39
+ * If you want to display labels that are not simply a record field, you can
40
+ * pass a function that takes a record and returns a label.
41
+ */
42
+ getOptionLabel?: (item: T) => string;
43
+ };
44
+ export declare function DataObjectSelect<T extends Record<string, unknown>>({ nullable, blankLabel, dataObject, filter, id: idProp, label, name, getOptionLabel, getOptionValue, valueField, labelField, value, defaultValue, ...props }: DataObjectSelectProps<T>): import("react").JSX.Element;
45
+ export declare function BoundDataObjectSelect<T extends Record<string, unknown>>({ field, ...props }: DataObjectSelectProps<T> & {
46
+ /**
47
+ * Field to bind the value of the select component to.
48
+ */
49
+ field: string;
50
+ }): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Field, Label, Select } from "@digdir/designsystemet-react";
3
+ import { useFetchData, useField } from "@olenbetong/appframe-react";
4
+ import { useEffect, useId, useRef } from "react";
5
+ export function DataObjectSelect({ nullable = false, blankLabel = "", dataObject, filter, id: idProp, label, name, getOptionLabel, getOptionValue, valueField = "ID", labelField = "Description", value, defaultValue, ...props }) {
6
+ let { data } = useFetchData(dataObject, filter ?? "");
7
+ let fallbackId = useId();
8
+ let id = idProp ?? fallbackId;
9
+ let inputRef = useRef(null);
10
+ // oxlint-disable-next-line react-hooks/exhaustive-deps -- default value should only affect the initial value
11
+ useEffect(() => {
12
+ let defaultExists = data.find((r) => String(getOptionValue?.(r) ?? r[valueField]) === defaultValue);
13
+ if (inputRef.current && defaultExists) {
14
+ inputRef.current.value = defaultValue;
15
+ }
16
+ }, [data]);
17
+ return (_jsxs(Field, { children: [label && (_jsxs(Label, { htmlFor: id, children: [label, props.required && " *"] })), _jsxs(Select, { id: id, name: name, ...props, value: value === undefined ? undefined : (value ?? ""), ref: inputRef, children: [nullable && _jsx("option", { value: "", children: blankLabel }), data.map((t) => {
18
+ let optionValue = getOptionValue?.(t) ?? t[valueField];
19
+ let optionLabel = getOptionLabel?.(t) ?? t[labelField];
20
+ return (_jsx("option", { value: optionValue, children: optionLabel }, optionValue));
21
+ })] })] }));
22
+ }
23
+ export function BoundDataObjectSelect({ field, ...props }) {
24
+ let { value, setValue } = useField(field);
25
+ return (_jsx(DataObjectSelect, { value: (value ?? ""), onChange: (event) => setValue(event.target.value), ...props }));
26
+ }
@@ -0,0 +1,8 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ import { type DeletePrompt } from "@olenbetong/appframe-react";
3
+ import { type ForwardRefExoticComponent, type RefAttributes } from "react";
4
+ export type DeleteButtonProps = ButtonProps & {
5
+ index?: number;
6
+ prompt?: DeletePrompt;
7
+ };
8
+ export declare const DeleteButton: ForwardRefExoticComponent<DeleteButtonProps & RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString } from "@olenbetong/appframe-core";
4
+ import { useDeleteButton } from "@olenbetong/appframe-react";
5
+ import { forwardRef } from "react";
6
+ export const DeleteButton = forwardRef(function DeleteButton({ prompt, onClick, index, children, ...props }, ref) {
7
+ let { deleting, deleteRow } = useDeleteButton(prompt);
8
+ return (_jsx(Button, { loading: deleting, "data-color": "danger", variant: "secondary", onClick: (evt) => {
9
+ onClick?.(evt);
10
+ if (!evt.defaultPrevented) {
11
+ deleteRow(index);
12
+ }
13
+ }, ...props, ref: ref, children: children ?? getLocalizedString("Delete") }));
14
+ });
@@ -0,0 +1,10 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ import { type DeletePrompt } from "@olenbetong/appframe-react";
3
+ export type DeleteIconButtonProps = Omit<ButtonProps, "icon"> & {
4
+ index?: number;
5
+ prompt?: DeletePrompt;
6
+ };
7
+ export declare const DeleteIconButton: import("react").ForwardRefExoticComponent<Omit<ButtonProps, "icon"> & {
8
+ index?: number;
9
+ prompt?: DeletePrompt;
10
+ } & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import DeleteIcon from "@mui/icons-material/Delete";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
5
+ import { useDeleteButton } from "@olenbetong/appframe-react";
6
+ import { forwardRef } from "react";
7
+ export const DeleteIconButton = forwardRef(function DeleteIconButton({ prompt, onClick, index, children, ...props }, ref) {
8
+ let { isDeleting, deleteRow } = useDeleteButton(prompt);
9
+ return (_jsx(Button, { icon: true, loading: isDeleting, "data-color": "danger", "aria-label": getLocalizedString("Delete"), variant: "tertiary", onClick: (evt) => {
10
+ onClick?.(evt);
11
+ if (!evt.defaultPrevented) {
12
+ deleteRow(index);
13
+ }
14
+ }, ...props, ref: ref, children: children ?? _jsx(DeleteIcon, {}) }));
15
+ });
@@ -0,0 +1,3 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ import { type ForwardRefExoticComponent, type RefAttributes } from "react";
3
+ export declare const RefreshButton: ForwardRefExoticComponent<ButtonProps & RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString } from "@olenbetong/appframe-core";
4
+ import { useRefreshButton } from "@olenbetong/appframe-react";
5
+ import { forwardRef } from "react";
6
+ export const RefreshButton = forwardRef(function RefreshButton({ onClick, children, ...props }, ref) {
7
+ let { loading, refresh } = useRefreshButton();
8
+ return (_jsx(Button, { loading: loading, onClick: (evt) => {
9
+ onClick?.(evt);
10
+ if (!evt.defaultPrevented) {
11
+ refresh();
12
+ }
13
+ }, ...props, ref: ref, children: children ?? getLocalizedString("Refresh") }));
14
+ });
@@ -0,0 +1,2 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ export declare const RefreshIconButton: import("react").ForwardRefExoticComponent<Omit<ButtonProps, "icon"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import RefreshIcon from "@mui/icons-material/Refresh";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
5
+ import { useDataObject, useLoading } from "@olenbetong/appframe-react";
6
+ import { forwardRef } from "react";
7
+ export const RefreshIconButton = forwardRef(function RefreshIconButton({ onClick, children, ...props }, ref) {
8
+ let dataObject = useDataObject();
9
+ let loading = useLoading(dataObject);
10
+ return (_jsx(Button, { icon: true, loading: loading, "aria-label": getLocalizedString("Refresh data"), variant: "tertiary", onClick: (evt) => {
11
+ onClick?.(evt);
12
+ if (!evt.defaultPrevented) {
13
+ dataObject.refreshDataSource();
14
+ }
15
+ }, ...props, ref: ref, children: children ?? _jsx(RefreshIcon, {}) }));
16
+ });
@@ -0,0 +1,7 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ export type RefreshRowIconButtonProps = Omit<ButtonProps, "icon"> & {
3
+ index?: number;
4
+ };
5
+ export declare const RefreshRowIconButton: import("react").ForwardRefExoticComponent<Omit<ButtonProps, "icon"> & {
6
+ index?: number;
7
+ } & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import RefreshIcon from "@mui/icons-material/Refresh";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
5
+ import { useRefreshRowButton } from "@olenbetong/appframe-react";
6
+ import { forwardRef } from "react";
7
+ export const RefreshRowIconButton = forwardRef(function RefreshRowIconButton({ onClick, index, children, ...props }, ref) {
8
+ let { loading, refreshRow } = useRefreshRowButton();
9
+ return (_jsx(Button, { icon: true, loading: loading, "aria-label": getLocalizedString("Refresh current row"), variant: "tertiary", onClick: (evt) => {
10
+ onClick?.(evt);
11
+ if (!evt.defaultPrevented) {
12
+ refreshRow(index);
13
+ }
14
+ }, ...props, ref: ref, children: children ?? _jsx(RefreshIcon, {}) }));
15
+ });
@@ -0,0 +1,3 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ import { type ForwardRefExoticComponent, type RefAttributes } from "react";
3
+ export declare const SaveButton: ForwardRefExoticComponent<ButtonProps & RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import { getLocalizedString } from "@olenbetong/appframe-core";
4
+ import { useSaveButton } from "@olenbetong/appframe-react";
5
+ import { forwardRef } from "react";
6
+ export const SaveButton = forwardRef(function SaveButton({ onClick, children, ...props }, ref) {
7
+ let { saving, save } = useSaveButton();
8
+ return (_jsx(Button, { loading: saving, onClick: (evt) => {
9
+ onClick?.(evt);
10
+ if (!evt.defaultPrevented) {
11
+ save();
12
+ }
13
+ }, ...props, ref: ref, children: children ?? getLocalizedString("Save") }));
14
+ });
@@ -0,0 +1,2 @@
1
+ import { type ButtonProps } from "@digdir/designsystemet-react";
2
+ export declare const SaveIconButton: import("react").ForwardRefExoticComponent<Omit<ButtonProps, "icon"> & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Button } from "@digdir/designsystemet-react";
3
+ import SaveIcon from "@mui/icons-material/Save";
4
+ import { getLocalizedString } from "@olenbetong/appframe-core";
5
+ import { useSaveButton } from "@olenbetong/appframe-react";
6
+ import { forwardRef } from "react";
7
+ export const SaveIconButton = forwardRef(function SaveIconButton({ onClick, children, ...props }, ref) {
8
+ let { saving, save } = useSaveButton();
9
+ return (_jsx(Button, { icon: true, loading: saving, "aria-label": getLocalizedString("Save"), variant: "tertiary", onClick: (evt) => {
10
+ onClick?.(evt);
11
+ if (!evt.defaultPrevented) {
12
+ save();
13
+ }
14
+ }, ...props, ref: ref, children: children ?? _jsx(SaveIcon, {}) }));
15
+ });
@@ -0,0 +1,19 @@
1
+ export * from "./BoundCheckbox.js";
2
+ export * from "./BoundDatePicker.js";
3
+ export * from "./BoundDateTimePicker.js";
4
+ export * from "./BoundInput.js";
5
+ export * from "./BoundNumericTextField.js";
6
+ export * from "./BoundSelect.js";
7
+ export * from "./BoundSwitch.js";
8
+ export * from "./BoundTextField.js";
9
+ export * from "./CancelButton.js";
10
+ export * from "./CancelIconButton.js";
11
+ export * from "./DataEditToolbar.js";
12
+ export * from "./DataObjectSelect.js";
13
+ export * from "./DeleteButton.js";
14
+ export * from "./DeleteIconButton.js";
15
+ export * from "./RefreshButton.js";
16
+ export * from "./RefreshIconButton.js";
17
+ export * from "./RefreshRowIconButton.js";
18
+ export * from "./SaveButton.js";
19
+ export * from "./SaveIconButton.js";
@@ -0,0 +1,19 @@
1
+ export * from "./BoundCheckbox.js";
2
+ export * from "./BoundDatePicker.js";
3
+ export * from "./BoundDateTimePicker.js";
4
+ export * from "./BoundInput.js";
5
+ export * from "./BoundNumericTextField.js";
6
+ export * from "./BoundSelect.js";
7
+ export * from "./BoundSwitch.js";
8
+ export * from "./BoundTextField.js";
9
+ export * from "./CancelButton.js";
10
+ export * from "./CancelIconButton.js";
11
+ export * from "./DataEditToolbar.js";
12
+ export * from "./DataObjectSelect.js";
13
+ export * from "./DeleteButton.js";
14
+ export * from "./DeleteIconButton.js";
15
+ export * from "./RefreshButton.js";
16
+ export * from "./RefreshIconButton.js";
17
+ export * from "./RefreshRowIconButton.js";
18
+ export * from "./SaveButton.js";
19
+ export * from "./SaveIconButton.js";
package/es/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./AfLookup/index.js";
2
+ export * from "./binding/index.js";
3
+ export * from "./layout/index.js";
package/es/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./AfLookup/index.js";
2
+ export * from "./binding/index.js";
3
+ export * from "./layout/index.js";