@strato-admin/cloudscape 0.1.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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/Admin.d.ts +17 -0
- package/dist/Admin.js +69 -0
- package/dist/RecordLink.d.ts +9 -0
- package/dist/RecordLink.js +43 -0
- package/dist/__mocks__/strato-core.js +50 -0
- package/dist/__mocks__to__delete/strato-core.js +50 -0
- package/dist/button/BulkDeleteButton.d.ts +7 -0
- package/dist/button/BulkDeleteButton.js +17 -0
- package/dist/button/Button.d.ts +6 -0
- package/dist/button/Button.js +6 -0
- package/dist/button/CreateButton.d.ts +6 -0
- package/dist/button/CreateButton.js +24 -0
- package/dist/button/EditButton.d.ts +8 -0
- package/dist/button/EditButton.js +24 -0
- package/dist/button/SaveButton.d.ts +6 -0
- package/dist/button/SaveButton.js +8 -0
- package/dist/button/index.d.ts +5 -0
- package/dist/button/index.js +5 -0
- package/dist/collection-hooks/index.d.ts +2 -0
- package/dist/collection-hooks/index.js +2 -0
- package/dist/collection-hooks/interfaces.d.ts +93 -0
- package/dist/collection-hooks/interfaces.js +1 -0
- package/dist/collection-hooks/useCollection.d.ts +3 -0
- package/dist/collection-hooks/useCollection.js +102 -0
- package/dist/create/Create.d.ts +40 -0
- package/dist/create/Create.js +34 -0
- package/dist/create/CreateHeader.d.ts +7 -0
- package/dist/create/CreateHeader.js +18 -0
- package/dist/create/index.d.ts +2 -0
- package/dist/create/index.js +2 -0
- package/dist/detail/KeyValuePairs.d.ts +36 -0
- package/dist/detail/KeyValuePairs.js +58 -0
- package/dist/detail/Show.d.ts +39 -0
- package/dist/detail/Show.js +40 -0
- package/dist/detail/ShowHeader.d.ts +7 -0
- package/dist/detail/ShowHeader.js +19 -0
- package/dist/detail/index.d.ts +3 -0
- package/dist/detail/index.js +3 -0
- package/dist/edit/Edit.d.ts +42 -0
- package/dist/edit/Edit.js +38 -0
- package/dist/edit/EditHeader.d.ts +7 -0
- package/dist/edit/EditHeader.js +18 -0
- package/dist/edit/index.d.ts +2 -0
- package/dist/edit/index.js +2 -0
- package/dist/field/ArrayField.d.ts +29 -0
- package/dist/field/ArrayField.js +30 -0
- package/dist/field/BadgeField.d.ts +12 -0
- package/dist/field/BadgeField.js +15 -0
- package/dist/field/BooleanField.d.ts +18 -0
- package/dist/field/BooleanField.js +14 -0
- package/dist/field/CurrencyField.d.ts +19 -0
- package/dist/field/CurrencyField.js +23 -0
- package/dist/field/DateField.d.ts +14 -0
- package/dist/field/DateField.js +17 -0
- package/dist/field/IdField.d.ts +17 -0
- package/dist/field/IdField.js +21 -0
- package/dist/field/NumberField.d.ts +14 -0
- package/dist/field/NumberField.js +18 -0
- package/dist/field/ReferenceField.d.ts +16 -0
- package/dist/field/ReferenceField.js +23 -0
- package/dist/field/ReferenceManyField.d.ts +55 -0
- package/dist/field/ReferenceManyField.js +19 -0
- package/dist/field/StatusIndicatorField.d.ts +56 -0
- package/dist/field/StatusIndicatorField.js +48 -0
- package/dist/field/TextField.d.ts +5 -0
- package/dist/field/TextField.js +11 -0
- package/dist/field/index.d.ts +23 -0
- package/dist/field/index.js +23 -0
- package/dist/field/types.d.ts +56 -0
- package/dist/field/types.js +1 -0
- package/dist/form/Form.d.ts +13 -0
- package/dist/form/Form.js +33 -0
- package/dist/form/index.d.ts +2 -0
- package/dist/form/index.js +2 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/input/AttributeEditor.d.ts +25 -0
- package/dist/input/AttributeEditor.js +80 -0
- package/dist/input/AutocompleteInput.d.ts +10 -0
- package/dist/input/AutocompleteInput.js +67 -0
- package/dist/input/FieldTitle.d.ts +8 -0
- package/dist/input/FieldTitle.js +29 -0
- package/dist/input/FormField.d.ts +7 -0
- package/dist/input/FormField.js +35 -0
- package/dist/input/FormFieldContext.d.ts +6 -0
- package/dist/input/FormFieldContext.js +3 -0
- package/dist/input/NumberInput.d.ts +7 -0
- package/dist/input/NumberInput.js +27 -0
- package/dist/input/ReferenceInput.d.ts +3 -0
- package/dist/input/ReferenceInput.js +25 -0
- package/dist/input/SelectInput.d.ts +15 -0
- package/dist/input/SelectInput.js +47 -0
- package/dist/input/SliderInput.d.ts +6 -0
- package/dist/input/SliderInput.js +25 -0
- package/dist/input/TextAreaInput.d.ts +6 -0
- package/dist/input/TextAreaInput.js +23 -0
- package/dist/input/TextInput.d.ts +7 -0
- package/dist/input/TextInput.js +23 -0
- package/dist/input/index.d.ts +11 -0
- package/dist/input/index.js +11 -0
- package/dist/input/types.d.ts +6 -0
- package/dist/input/types.js +1 -0
- package/dist/layout/AppLayout.d.ts +8 -0
- package/dist/layout/AppLayout.js +38 -0
- package/dist/layout/TopNavigation.d.ts +6 -0
- package/dist/layout/TopNavigation.js +53 -0
- package/dist/layout/index.d.ts +2 -0
- package/dist/layout/index.js +2 -0
- package/dist/list/Cards.d.ts +11 -0
- package/dist/list/Cards.js +27 -0
- package/dist/list/List.d.ts +43 -0
- package/dist/list/List.js +28 -0
- package/dist/list/Table.d.ts +112 -0
- package/dist/list/Table.examples.d.ts +1 -0
- package/dist/list/Table.examples.js +3 -0
- package/dist/list/Table.js +218 -0
- package/dist/list/TableHeader.d.ts +7 -0
- package/dist/list/TableHeader.js +22 -0
- package/dist/list/index.d.ts +4 -0
- package/dist/list/index.js +4 -0
- package/dist/preferences/index.d.ts +0 -0
- package/dist/preferences/index.js +1 -0
- package/dist/theme/ThemeManager.d.ts +2 -0
- package/dist/theme/ThemeManager.js +11 -0
- package/dist/theme/index.d.ts +2 -0
- package/dist/theme/index.js +2 -0
- package/package.json +73 -0
- package/src/Admin.test.tsx +32 -0
- package/src/Admin.tsx +123 -0
- package/src/RecordLink.stories.tsx +56 -0
- package/src/RecordLink.tsx +67 -0
- package/src/__mocks__/strato-core.tsx +52 -0
- package/src/button/BulkDeleteButton.stories.tsx +59 -0
- package/src/button/BulkDeleteButton.test.tsx +64 -0
- package/src/button/BulkDeleteButton.tsx +41 -0
- package/src/button/Button.stories.tsx +31 -0
- package/src/button/Button.tsx +12 -0
- package/src/button/CreateButton.stories.tsx +42 -0
- package/src/button/CreateButton.tsx +38 -0
- package/src/button/EditButton.stories.tsx +29 -0
- package/src/button/EditButton.tsx +38 -0
- package/src/button/SaveButton.stories.tsx +35 -0
- package/src/button/SaveButton.tsx +19 -0
- package/src/button/index.ts +5 -0
- package/src/collection-hooks/index.ts +2 -0
- package/src/collection-hooks/interfaces.ts +80 -0
- package/src/collection-hooks/useCollection.test.ts +413 -0
- package/src/collection-hooks/useCollection.ts +125 -0
- package/src/create/Create.test.tsx +63 -0
- package/src/create/Create.tsx +93 -0
- package/src/create/CreateHeader.tsx +34 -0
- package/src/create/index.ts +2 -0
- package/src/detail/KeyValuePairs.test.tsx +98 -0
- package/src/detail/KeyValuePairs.tsx +107 -0
- package/src/detail/Show.test.tsx +96 -0
- package/src/detail/Show.tsx +104 -0
- package/src/detail/ShowHeader.test.tsx +80 -0
- package/src/detail/ShowHeader.tsx +35 -0
- package/src/detail/index.ts +3 -0
- package/src/edit/Edit.test.tsx +91 -0
- package/src/edit/Edit.tsx +102 -0
- package/src/edit/EditHeader.tsx +34 -0
- package/src/edit/index.ts +2 -0
- package/src/field/ArrayField.tsx +51 -0
- package/src/field/BadgeField.tsx +33 -0
- package/src/field/BooleanField.stories.tsx +56 -0
- package/src/field/BooleanField.test.tsx +63 -0
- package/src/field/BooleanField.tsx +42 -0
- package/src/field/CurrencyField.stories.tsx +67 -0
- package/src/field/CurrencyField.tsx +45 -0
- package/src/field/DateField.stories.tsx +67 -0
- package/src/field/DateField.tsx +33 -0
- package/src/field/IdField.test.tsx +88 -0
- package/src/field/IdField.tsx +40 -0
- package/src/field/NumberField.stories.tsx +75 -0
- package/src/field/NumberField.tsx +35 -0
- package/src/field/ReferenceField.test.tsx +88 -0
- package/src/field/ReferenceField.tsx +64 -0
- package/src/field/ReferenceManyField.test.tsx +41 -0
- package/src/field/ReferenceManyField.tsx +73 -0
- package/src/field/StatusIndicatorField.stories.tsx +93 -0
- package/src/field/StatusIndicatorField.test.tsx +143 -0
- package/src/field/StatusIndicatorField.tsx +119 -0
- package/src/field/TextField.stories.tsx +45 -0
- package/src/field/TextField.tsx +17 -0
- package/src/field/index.ts +23 -0
- package/src/field/types.ts +58 -0
- package/src/form/Form.test.tsx +55 -0
- package/src/form/Form.tsx +66 -0
- package/src/form/index.ts +2 -0
- package/src/index.ts +25 -0
- package/src/input/AttributeEditor.test.tsx +147 -0
- package/src/input/AttributeEditor.tsx +185 -0
- package/src/input/AutocompleteInput.test.tsx +178 -0
- package/src/input/AutocompleteInput.tsx +116 -0
- package/src/input/FieldTitle.tsx +53 -0
- package/src/input/FormField.tsx +87 -0
- package/src/input/FormFieldContext.ts +9 -0
- package/src/input/NumberInput.tsx +56 -0
- package/src/input/ReferenceInput.test.tsx +35 -0
- package/src/input/ReferenceInput.tsx +36 -0
- package/src/input/SelectInput.tsx +91 -0
- package/src/input/SliderInput.test.tsx +103 -0
- package/src/input/SliderInput.tsx +49 -0
- package/src/input/TextAreaInput.tsx +48 -0
- package/src/input/TextInput.test.tsx +91 -0
- package/src/input/TextInput.tsx +51 -0
- package/src/input/index.ts +11 -0
- package/src/input/types.ts +14 -0
- package/src/layout/AppLayout.test.tsx +87 -0
- package/src/layout/AppLayout.tsx +60 -0
- package/src/layout/TopNavigation.test.tsx +78 -0
- package/src/layout/TopNavigation.tsx +84 -0
- package/src/layout/index.ts +2 -0
- package/src/list/Cards.tsx +58 -0
- package/src/list/List.tsx +76 -0
- package/src/list/Table.examples.tsx +11 -0
- package/src/list/Table.stories.tsx +73 -0
- package/src/list/Table.test.tsx +255 -0
- package/src/list/Table.tsx +438 -0
- package/src/list/TableHeader.test.tsx +114 -0
- package/src/list/TableHeader.tsx +44 -0
- package/src/list/index.ts +4 -0
- package/src/preferences/index.ts +0 -0
- package/src/stories/Button.stories.ts +54 -0
- package/src/stories/Button.tsx +31 -0
- package/src/stories/Configure.mdx +369 -0
- package/src/stories/Header.stories.ts +34 -0
- package/src/stories/Header.tsx +47 -0
- package/src/stories/Page.stories.ts +33 -0
- package/src/stories/Page.tsx +71 -0
- package/src/stories/RaStoryDecorator.tsx +38 -0
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +1 -0
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +1 -0
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +1 -0
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +1 -0
- package/src/stories/assets/youtube.svg +1 -0
- package/src/stories/button.css +30 -0
- package/src/stories/header.css +32 -0
- package/src/stories/page.css +68 -0
- package/src/theme/ThemeManager.tsx +15 -0
- package/src/theme/index.ts +2 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
3
|
+
export interface CreateProps<RecordType extends RaRecord = RaRecord> {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
inputSchema?: React.ReactNode;
|
|
6
|
+
title?: React.ReactNode;
|
|
7
|
+
actions?: React.ReactNode;
|
|
8
|
+
resource?: string;
|
|
9
|
+
record?: Partial<RecordType>;
|
|
10
|
+
redirect?: any;
|
|
11
|
+
transform?: any;
|
|
12
|
+
mutationOptions?: any;
|
|
13
|
+
include?: string[];
|
|
14
|
+
exclude?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A Create component that provides record context and a Cloudscape Container.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* <Create>
|
|
21
|
+
* <Form>
|
|
22
|
+
* <TextInput source="name" />
|
|
23
|
+
* </Form>
|
|
24
|
+
* </Create>
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using InputSchema from context
|
|
28
|
+
* <Create include={['name', 'price']} />
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Passing a custom input schema
|
|
32
|
+
* <Create inputSchema={<InputSchema>...</InputSchema>}>
|
|
33
|
+
* <Form />
|
|
34
|
+
* </Create>
|
|
35
|
+
*/
|
|
36
|
+
export declare const Create: {
|
|
37
|
+
<RecordType extends RaRecord = RaRecord<import("@strato-admin/ra-core").Identifier>>({ children, inputSchema, title, actions, include, exclude, ...props }: CreateProps<RecordType>): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
Header: ({ title, actions, ...props }: import("./CreateHeader").CreateHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
39
|
+
};
|
|
40
|
+
export default Create;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CreateBase, ResourceSchemaProvider } from '@strato-admin/core';
|
|
3
|
+
import Container from '@cloudscape-design/components/container';
|
|
4
|
+
import { CreateHeader } from './CreateHeader';
|
|
5
|
+
import Form from '../form/Form';
|
|
6
|
+
const CreateUI = ({ children, resource, inputSchema, title, actions, include, exclude, }) => {
|
|
7
|
+
const finalChildren = children || _jsx(Form, { include: include, exclude: exclude });
|
|
8
|
+
return (_jsx(ResourceSchemaProvider, { resource: resource, inputSchema: inputSchema, children: _jsx(Container, { header: _jsx(CreateHeader, { title: title, actions: actions }), children: finalChildren }) }));
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A Create component that provides record context and a Cloudscape Container.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <Create>
|
|
15
|
+
* <Form>
|
|
16
|
+
* <TextInput source="name" />
|
|
17
|
+
* </Form>
|
|
18
|
+
* </Create>
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Using InputSchema from context
|
|
22
|
+
* <Create include={['name', 'price']} />
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Passing a custom input schema
|
|
26
|
+
* <Create inputSchema={<InputSchema>...</InputSchema>}>
|
|
27
|
+
* <Form />
|
|
28
|
+
* </Create>
|
|
29
|
+
*/
|
|
30
|
+
export const Create = ({ children, inputSchema, title, actions, include, exclude, ...props }) => {
|
|
31
|
+
return (_jsx(CreateBase, { ...props, children: _jsx(CreateUI, { resource: props.resource, title: title, actions: actions, include: include, exclude: exclude, inputSchema: inputSchema, children: children }) }));
|
|
32
|
+
};
|
|
33
|
+
Create.Header = CreateHeader;
|
|
34
|
+
export default Create;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HeaderProps } from '@cloudscape-design/components/header';
|
|
3
|
+
export interface CreateHeaderProps extends Omit<HeaderProps, 'children'> {
|
|
4
|
+
title?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const CreateHeader: ({ title, actions, ...props }: CreateHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default CreateHeader;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Header from '@cloudscape-design/components/header';
|
|
4
|
+
import SpaceBetween from '@cloudscape-design/components/space-between';
|
|
5
|
+
import { useCreateContext, useTranslate } from '@strato-admin/core';
|
|
6
|
+
export const CreateHeader = ({ title, actions, ...props }) => {
|
|
7
|
+
const translate = useTranslate();
|
|
8
|
+
const { defaultTitle } = useCreateContext();
|
|
9
|
+
const headerTitle = React.useMemo(() => {
|
|
10
|
+
if (title !== undefined) {
|
|
11
|
+
return typeof title === 'string' ? translate(title, { _: title }) : title;
|
|
12
|
+
}
|
|
13
|
+
return defaultTitle;
|
|
14
|
+
}, [title, defaultTitle, translate]);
|
|
15
|
+
const headerActions = actions || (_jsx(SpaceBetween, { direction: "horizontal", size: "xs" }));
|
|
16
|
+
return (_jsx(Header, { variant: "h2", ...props, actions: headerActions, children: headerTitle }));
|
|
17
|
+
};
|
|
18
|
+
export default CreateHeader;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type KeyValuePairsProps as CloudscapeKeyValuePairsProps } from '@cloudscape-design/components/key-value-pairs';
|
|
3
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
4
|
+
export interface KeyValuePairsProps extends Partial<Omit<CloudscapeKeyValuePairsProps, 'items'>> {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
include?: string[];
|
|
7
|
+
exclude?: string[];
|
|
8
|
+
columns?: number;
|
|
9
|
+
minColumnWidth?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface KeyValueFieldProps {
|
|
12
|
+
source?: string;
|
|
13
|
+
label?: string;
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
field?: React.ComponentType<any>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* KeyValuePairs.Field is a helper component to define a field in a KeyValuePairs component.
|
|
19
|
+
* It mirrors the DataTable.Col pattern.
|
|
20
|
+
*/
|
|
21
|
+
export declare const KeyValueField: ({ children, source, field: FieldComponent }: KeyValueFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
/**
|
|
23
|
+
* A KeyValuePairs component that mirrors the Cloudscape KeyValuePairs component
|
|
24
|
+
* but automatically handles labels and record context for its children.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* <KeyValuePairs columns={2}>
|
|
28
|
+
* <TextField source="name" label="Full Name" />
|
|
29
|
+
* <KeyValuePairs.Field source="age" label="Age" />
|
|
30
|
+
* </KeyValuePairs>
|
|
31
|
+
*/
|
|
32
|
+
export declare const KeyValuePairs: {
|
|
33
|
+
<RecordType extends RaRecord = RaRecord<import("@strato-admin/ra-core").Identifier>>({ children, include, exclude, columns, minColumnWidth, ...props }: KeyValuePairsProps): import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
Field: ({ children, source, field: FieldComponent }: KeyValueFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
};
|
|
36
|
+
export default KeyValuePairs;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import CloudscapeKeyValuePairs from '@cloudscape-design/components/key-value-pairs';
|
|
4
|
+
import { useResourceContext, useRecordContext, FieldTitle, RecordContextProvider, useFieldSchema, } from '@strato-admin/core';
|
|
5
|
+
import TextField from '../field/TextField';
|
|
6
|
+
/**
|
|
7
|
+
* KeyValuePairs.Field is a helper component to define a field in a KeyValuePairs component.
|
|
8
|
+
* It mirrors the DataTable.Col pattern.
|
|
9
|
+
*/
|
|
10
|
+
export const KeyValueField = ({ children, source, field: FieldComponent }) => {
|
|
11
|
+
if (children) {
|
|
12
|
+
return (_jsx(_Fragment, { children: React.Children.map(children, (child) => React.isValidElement(child) ? React.cloneElement(child, { source }) : child) }));
|
|
13
|
+
}
|
|
14
|
+
if (FieldComponent) {
|
|
15
|
+
return _jsx(FieldComponent, { source: source });
|
|
16
|
+
}
|
|
17
|
+
return _jsx(TextField, { source: source });
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A KeyValuePairs component that mirrors the Cloudscape KeyValuePairs component
|
|
21
|
+
* but automatically handles labels and record context for its children.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <KeyValuePairs columns={2}>
|
|
25
|
+
* <TextField source="name" label="Full Name" />
|
|
26
|
+
* <KeyValuePairs.Field source="age" label="Age" />
|
|
27
|
+
* </KeyValuePairs>
|
|
28
|
+
*/
|
|
29
|
+
export const KeyValuePairs = ({ children, include, exclude, columns = 3, // Default to 3 columns if not specified
|
|
30
|
+
minColumnWidth, ...props }) => {
|
|
31
|
+
const resource = useResourceContext();
|
|
32
|
+
const record = useRecordContext();
|
|
33
|
+
const schemaChildren = useFieldSchema();
|
|
34
|
+
const finalChildren = React.useMemo(() => {
|
|
35
|
+
const baseChildren = children || schemaChildren;
|
|
36
|
+
let result = React.Children.toArray(baseChildren);
|
|
37
|
+
if (include) {
|
|
38
|
+
result = result.filter((child) => React.isValidElement(child) && include.includes(child.props.source));
|
|
39
|
+
}
|
|
40
|
+
else if (exclude) {
|
|
41
|
+
result = result.filter((child) => React.isValidElement(child) && !exclude.includes(child.props.source));
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}, [children, schemaChildren, include, exclude]);
|
|
45
|
+
const items = React.Children.map(finalChildren, (child) => {
|
|
46
|
+
if (!React.isValidElement(child)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const { source, label } = child.props;
|
|
50
|
+
return {
|
|
51
|
+
label: _jsx(FieldTitle, { source: source, resource: resource, label: label }),
|
|
52
|
+
value: _jsx(RecordContextProvider, { value: record, children: child }),
|
|
53
|
+
};
|
|
54
|
+
})?.filter((item) => item !== null) || [];
|
|
55
|
+
return _jsx(CloudscapeKeyValuePairs, { ...props, items: items, columns: columns, minColumnWidth: minColumnWidth });
|
|
56
|
+
};
|
|
57
|
+
KeyValuePairs.Field = KeyValueField;
|
|
58
|
+
export default KeyValuePairs;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
3
|
+
export interface ShowProps<_RecordType extends RaRecord = RaRecord> {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
fieldSchema?: React.ReactNode;
|
|
6
|
+
title?: React.ReactNode;
|
|
7
|
+
actions?: React.ReactNode;
|
|
8
|
+
resource?: string;
|
|
9
|
+
id?: any;
|
|
10
|
+
queryOptions?: any;
|
|
11
|
+
include?: string[];
|
|
12
|
+
exclude?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A Show component that provides record context and a Cloudscape Container.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* <Show>
|
|
19
|
+
* <KeyValuePairs>
|
|
20
|
+
* <TextField source="name" />
|
|
21
|
+
* <NumberField source="price" />
|
|
22
|
+
* </KeyValuePairs>
|
|
23
|
+
* </Show>
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Using FieldSchema from context
|
|
27
|
+
* <Show include={['name', 'price']} />
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Passing a custom field schema
|
|
31
|
+
* <Show fieldSchema={<FieldSchema>...</FieldSchema>}>
|
|
32
|
+
* <KeyValuePairs />
|
|
33
|
+
* </Show>
|
|
34
|
+
*/
|
|
35
|
+
export declare const Show: {
|
|
36
|
+
<RecordType extends RaRecord = RaRecord<import("@strato-admin/ra-core").Identifier>>({ children, fieldSchema, title, actions, include, exclude, ...props }: ShowProps<RecordType>): import("react/jsx-runtime").JSX.Element;
|
|
37
|
+
Header: ({ title, actions, ...props }: import("./ShowHeader").ShowHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
};
|
|
39
|
+
export default Show;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ShowBase, useShowContext, ResourceSchemaProvider } from '@strato-admin/core';
|
|
3
|
+
import Container from '@cloudscape-design/components/container';
|
|
4
|
+
import SpaceBetween from '@cloudscape-design/components/space-between';
|
|
5
|
+
import { ShowHeader } from './ShowHeader';
|
|
6
|
+
import KeyValuePairs from './KeyValuePairs';
|
|
7
|
+
const ShowUI = ({ children, resource, fieldSchema, title, actions, include, exclude, }) => {
|
|
8
|
+
const { record, isLoading } = useShowContext();
|
|
9
|
+
if (isLoading || !record) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const finalChildren = children || _jsx(KeyValuePairs, { include: include, exclude: exclude });
|
|
13
|
+
return (_jsx(ResourceSchemaProvider, { resource: resource, fieldSchema: fieldSchema, children: _jsx(Container, { header: _jsx(ShowHeader, { title: title, actions: actions }), children: _jsx(SpaceBetween, { direction: "vertical", size: "l", children: finalChildren }) }) }));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A Show component that provides record context and a Cloudscape Container.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <Show>
|
|
20
|
+
* <KeyValuePairs>
|
|
21
|
+
* <TextField source="name" />
|
|
22
|
+
* <NumberField source="price" />
|
|
23
|
+
* </KeyValuePairs>
|
|
24
|
+
* </Show>
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* // Using FieldSchema from context
|
|
28
|
+
* <Show include={['name', 'price']} />
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Passing a custom field schema
|
|
32
|
+
* <Show fieldSchema={<FieldSchema>...</FieldSchema>}>
|
|
33
|
+
* <KeyValuePairs />
|
|
34
|
+
* </Show>
|
|
35
|
+
*/
|
|
36
|
+
export const Show = ({ children, fieldSchema, title, actions, include, exclude, ...props }) => {
|
|
37
|
+
return (_jsx(ShowBase, { ...props, children: _jsx(ShowUI, { resource: props.resource, title: title, actions: actions, include: include, exclude: exclude, fieldSchema: fieldSchema, children: children }) }));
|
|
38
|
+
};
|
|
39
|
+
Show.Header = ShowHeader;
|
|
40
|
+
export default Show;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HeaderProps } from '@cloudscape-design/components/header';
|
|
3
|
+
export interface ShowHeaderProps extends Omit<HeaderProps, 'children'> {
|
|
4
|
+
title?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const ShowHeader: ({ title, actions, ...props }: ShowHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default ShowHeader;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Header from '@cloudscape-design/components/header';
|
|
4
|
+
import SpaceBetween from '@cloudscape-design/components/space-between';
|
|
5
|
+
import { useShowContext, useTranslate } from '@strato-admin/core';
|
|
6
|
+
import { EditButton } from '../button/EditButton';
|
|
7
|
+
export const ShowHeader = ({ title, actions, ...props }) => {
|
|
8
|
+
const translate = useTranslate();
|
|
9
|
+
const { record, defaultTitle } = useShowContext();
|
|
10
|
+
const headerTitle = React.useMemo(() => {
|
|
11
|
+
if (title !== undefined) {
|
|
12
|
+
return typeof title === 'string' ? translate(title, { _: title }) : title;
|
|
13
|
+
}
|
|
14
|
+
return defaultTitle;
|
|
15
|
+
}, [title, defaultTitle, translate]);
|
|
16
|
+
const headerActions = actions || (_jsx(SpaceBetween, { direction: "horizontal", size: "xs", children: _jsx(EditButton, { record: record }) }));
|
|
17
|
+
return (_jsx(Header, { variant: "h2", ...props, actions: headerActions, children: headerTitle }));
|
|
18
|
+
};
|
|
19
|
+
export default ShowHeader;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
3
|
+
export interface EditProps<_RecordType extends RaRecord = RaRecord> {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
inputSchema?: React.ReactNode;
|
|
6
|
+
title?: React.ReactNode;
|
|
7
|
+
actions?: React.ReactNode;
|
|
8
|
+
resource?: string;
|
|
9
|
+
id?: any;
|
|
10
|
+
mutationMode?: 'pessimistic' | 'optimistic' | 'undoable';
|
|
11
|
+
mutationOptions?: any;
|
|
12
|
+
queryOptions?: any;
|
|
13
|
+
redirect?: any;
|
|
14
|
+
transform?: any;
|
|
15
|
+
include?: string[];
|
|
16
|
+
exclude?: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* An Edit component that provides record context and a Cloudscape Container.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* <Edit>
|
|
23
|
+
* <Form>
|
|
24
|
+
* <TextInput source="name" />
|
|
25
|
+
* </Form>
|
|
26
|
+
* </Edit>
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Using InputSchema from context
|
|
30
|
+
* <Edit include={['name', 'price']} />
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* // Passing a custom input schema
|
|
34
|
+
* <Edit inputSchema={<InputSchema>...</InputSchema>}>
|
|
35
|
+
* <Form />
|
|
36
|
+
* </Edit>
|
|
37
|
+
*/
|
|
38
|
+
export declare const Edit: {
|
|
39
|
+
<RecordType extends RaRecord = any>({ children, inputSchema, title, actions, include, exclude, ...props }: EditProps<RecordType>): import("react/jsx-runtime").JSX.Element;
|
|
40
|
+
Header: ({ title, actions, ...props }: import("./EditHeader").EditHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
};
|
|
42
|
+
export default Edit;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { EditBase, useEditContext, ResourceSchemaProvider } from '@strato-admin/core';
|
|
3
|
+
import Container from '@cloudscape-design/components/container';
|
|
4
|
+
import { EditHeader } from './EditHeader';
|
|
5
|
+
import Form from '../form/Form';
|
|
6
|
+
const EditUI = ({ children, resource, inputSchema, title, actions, include, exclude, }) => {
|
|
7
|
+
const { record, isLoading } = useEditContext();
|
|
8
|
+
if (isLoading || !record) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const finalChildren = children || _jsx(Form, { include: include, exclude: exclude });
|
|
12
|
+
return (_jsx(ResourceSchemaProvider, { resource: resource, inputSchema: inputSchema, children: _jsx(Container, { header: _jsx(EditHeader, { title: title, actions: actions }), children: finalChildren }) }));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* An Edit component that provides record context and a Cloudscape Container.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* <Edit>
|
|
19
|
+
* <Form>
|
|
20
|
+
* <TextInput source="name" />
|
|
21
|
+
* </Form>
|
|
22
|
+
* </Edit>
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Using InputSchema from context
|
|
26
|
+
* <Edit include={['name', 'price']} />
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Passing a custom input schema
|
|
30
|
+
* <Edit inputSchema={<InputSchema>...</InputSchema>}>
|
|
31
|
+
* <Form />
|
|
32
|
+
* </Edit>
|
|
33
|
+
*/
|
|
34
|
+
export const Edit = ({ children, inputSchema, title, actions, include, exclude, ...props }) => {
|
|
35
|
+
return (_jsx(EditBase, { ...props, children: _jsx(EditUI, { resource: props.resource, title: title, actions: actions, include: include, exclude: exclude, inputSchema: inputSchema, children: children }) }));
|
|
36
|
+
};
|
|
37
|
+
Edit.Header = EditHeader;
|
|
38
|
+
export default Edit;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HeaderProps } from '@cloudscape-design/components/header';
|
|
3
|
+
export interface EditHeaderProps extends Omit<HeaderProps, 'children'> {
|
|
4
|
+
title?: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const EditHeader: ({ title, actions, ...props }: EditHeaderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export default EditHeader;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import Header from '@cloudscape-design/components/header';
|
|
4
|
+
import SpaceBetween from '@cloudscape-design/components/space-between';
|
|
5
|
+
import { useEditContext, useTranslate } from '@strato-admin/core';
|
|
6
|
+
export const EditHeader = ({ title, actions, ...props }) => {
|
|
7
|
+
const translate = useTranslate();
|
|
8
|
+
const { defaultTitle } = useEditContext();
|
|
9
|
+
const headerTitle = React.useMemo(() => {
|
|
10
|
+
if (title !== undefined) {
|
|
11
|
+
return typeof title === 'string' ? translate(title, { _: title }) : title;
|
|
12
|
+
}
|
|
13
|
+
return defaultTitle;
|
|
14
|
+
}, [title, defaultTitle, translate]);
|
|
15
|
+
const headerActions = actions || (_jsx(SpaceBetween, { direction: "horizontal", size: "xs" }));
|
|
16
|
+
return (_jsx(Header, { variant: "h2", ...props, actions: headerActions, children: headerTitle }));
|
|
17
|
+
};
|
|
18
|
+
export default EditHeader;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
2
|
+
import { type FieldProps } from './types';
|
|
3
|
+
export interface ArrayFieldProps<RecordType extends RaRecord = RaRecord> extends FieldProps<RecordType> {
|
|
4
|
+
/**
|
|
5
|
+
* Thecomponents to render for each item in the array.
|
|
6
|
+
*/
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
/**
|
|
9
|
+
* Number of items per page if pagination is used within the field.
|
|
10
|
+
*/
|
|
11
|
+
perPage?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* ArrayField component that wraps its children with a ListContextProvider
|
|
15
|
+
* and ResourceContextProvider initialized with the array data and resource name.
|
|
16
|
+
*
|
|
17
|
+
* This allows using components that expect a ListContext or ResourceContext
|
|
18
|
+
* (like DataTable) to display nested arrays within a record.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <ArrayField source="products" resource="products">
|
|
22
|
+
* <DataTable variant="embedded">
|
|
23
|
+
* <DataTable.Col source="title" label="Title" />
|
|
24
|
+
* <DataTable.NumberCol source="price" label="Price" />
|
|
25
|
+
* </DataTable>
|
|
26
|
+
* </ArrayField>
|
|
27
|
+
*/
|
|
28
|
+
export declare const ArrayField: <RecordType extends RaRecord = any>(props: ArrayFieldProps<RecordType>) => import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
export default ArrayField;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRecordContext, useList, ListContextProvider, ResourceContextProvider } from '@strato-admin/core';
|
|
3
|
+
/**
|
|
4
|
+
* ArrayField component that wraps its children with a ListContextProvider
|
|
5
|
+
* and ResourceContextProvider initialized with the array data and resource name.
|
|
6
|
+
*
|
|
7
|
+
* This allows using components that expect a ListContext or ResourceContext
|
|
8
|
+
* (like DataTable) to display nested arrays within a record.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* <ArrayField source="products" resource="products">
|
|
12
|
+
* <DataTable variant="embedded">
|
|
13
|
+
* <DataTable.Col source="title" label="Title" />
|
|
14
|
+
* <DataTable.NumberCol source="price" label="Price" />
|
|
15
|
+
* </DataTable>
|
|
16
|
+
* </ArrayField>
|
|
17
|
+
*/
|
|
18
|
+
export const ArrayField = (props) => {
|
|
19
|
+
const { source, resource, children, perPage = 10 } = props;
|
|
20
|
+
const record = useRecordContext();
|
|
21
|
+
const data = (source && record?.[source]) || [];
|
|
22
|
+
const targetResource = resource || source || '';
|
|
23
|
+
const listContext = useList({
|
|
24
|
+
data,
|
|
25
|
+
resource: targetResource,
|
|
26
|
+
perPage,
|
|
27
|
+
});
|
|
28
|
+
return (_jsx(ResourceContextProvider, { value: targetResource, children: _jsx(ListContextProvider, { value: listContext, children: children }) }));
|
|
29
|
+
};
|
|
30
|
+
export default ArrayField;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type BadgeProps } from '@cloudscape-design/components/badge';
|
|
2
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
3
|
+
import { type FieldProps } from './types';
|
|
4
|
+
export interface BadgeFieldProps<RecordType extends RaRecord = RaRecord> extends FieldProps<RecordType> {
|
|
5
|
+
/**
|
|
6
|
+
* The color of the badge.
|
|
7
|
+
* @default "grey"
|
|
8
|
+
*/
|
|
9
|
+
color?: BadgeProps['color'];
|
|
10
|
+
}
|
|
11
|
+
declare const BadgeField: <RecordType extends RaRecord = RaRecord>(props: BadgeFieldProps<RecordType>) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default BadgeField;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Badge from '@cloudscape-design/components/badge';
|
|
3
|
+
import { useFieldValue, useRecordContext } from '@strato-admin/core';
|
|
4
|
+
import RecordLink from '../RecordLink';
|
|
5
|
+
const BadgeField = (props) => {
|
|
6
|
+
const { source, record: recordProp, emptyText, link, color = 'grey' } = props;
|
|
7
|
+
const record = useRecordContext({ record: recordProp });
|
|
8
|
+
const value = useFieldValue({ source: source, record });
|
|
9
|
+
const hasValue = value !== null && value !== undefined && value !== '';
|
|
10
|
+
if (!hasValue) {
|
|
11
|
+
return _jsx(_Fragment, { children: emptyText ?? null });
|
|
12
|
+
}
|
|
13
|
+
return (_jsx(RecordLink, { link: link, children: _jsx(Badge, { color: color, children: String(value) }) }));
|
|
14
|
+
};
|
|
15
|
+
export default BadgeField;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RaRecord } from '@strato-admin/core';
|
|
2
|
+
import { type FieldProps } from './types';
|
|
3
|
+
export type BooleanFieldProps<RecordType extends RaRecord = RaRecord> = FieldProps<RecordType> & {
|
|
4
|
+
/**
|
|
5
|
+
* The label to display when the value is true. Defaults to "Yes".
|
|
6
|
+
*/
|
|
7
|
+
trueLabel?: string;
|
|
8
|
+
/**
|
|
9
|
+
* The label to display when the value is false. Defaults to "No".
|
|
10
|
+
*/
|
|
11
|
+
falseLabel?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to show the text label alongside the icon.
|
|
14
|
+
*/
|
|
15
|
+
showLabel?: boolean;
|
|
16
|
+
};
|
|
17
|
+
declare const BooleanField: <RecordType extends RaRecord = RaRecord>(props: BooleanFieldProps<RecordType>) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export default BooleanField;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import StatusIndicator from '@cloudscape-design/components/status-indicator';
|
|
3
|
+
import { useFieldValue, useRecordContext, useTranslate } from '@strato-admin/core';
|
|
4
|
+
import RecordLink from '../RecordLink';
|
|
5
|
+
const BooleanField = (props) => {
|
|
6
|
+
const { source, record: recordProp, trueLabel, falseLabel, showLabel = false, link } = props;
|
|
7
|
+
const record = useRecordContext({ record: recordProp });
|
|
8
|
+
const value = useFieldValue({ source: source, record });
|
|
9
|
+
const translate = useTranslate();
|
|
10
|
+
const isTrue = !!value;
|
|
11
|
+
const content = isTrue ? (_jsx(StatusIndicator, { type: "success", colorOverride: "green", children: showLabel ? (trueLabel ?? translate('ra.boolean.true', { _: 'Yes' })) : null })) : (_jsx(StatusIndicator, { type: "not-started", children: showLabel ? (falseLabel ?? translate('ra.boolean.false', { _: 'No' })) : null }));
|
|
12
|
+
return _jsx(RecordLink, { link: link, children: content });
|
|
13
|
+
};
|
|
14
|
+
export default BooleanField;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
2
|
+
import { type FieldProps } from './types';
|
|
3
|
+
export type CurrencyFieldProps<RecordType extends RaRecord = RaRecord> = FieldProps<RecordType> & {
|
|
4
|
+
/**
|
|
5
|
+
* Options for Intl.NumberFormat.
|
|
6
|
+
*/
|
|
7
|
+
options?: Intl.NumberFormatOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Locale(s) to use for formatting. Defaults to the current app locale.
|
|
10
|
+
*/
|
|
11
|
+
locales?: string | string[];
|
|
12
|
+
/**
|
|
13
|
+
* The currency to use in currency formatting.
|
|
14
|
+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#currency_2
|
|
15
|
+
*/
|
|
16
|
+
currency: string;
|
|
17
|
+
};
|
|
18
|
+
declare const CurrencyField: <RecordType extends RaRecord = RaRecord>(props: CurrencyFieldProps<RecordType>) => import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export default CurrencyField;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useFieldValue, useRecordContext, useLocale } from '@strato-admin/core';
|
|
3
|
+
import RecordLink from '../RecordLink';
|
|
4
|
+
const CurrencyField = (props) => {
|
|
5
|
+
const { source, record: recordProp, emptyText, options, locales, link, currency } = props;
|
|
6
|
+
const record = useRecordContext({ record: recordProp });
|
|
7
|
+
const value = useFieldValue({ source: source, record });
|
|
8
|
+
const currentLocale = useLocale();
|
|
9
|
+
const hasValue = value !== null && value !== undefined && value !== '';
|
|
10
|
+
if (!hasValue) {
|
|
11
|
+
return _jsx(_Fragment, { children: emptyText ?? null });
|
|
12
|
+
}
|
|
13
|
+
const numberValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
14
|
+
const formatOptions = {
|
|
15
|
+
style: 'currency',
|
|
16
|
+
currency,
|
|
17
|
+
...options,
|
|
18
|
+
};
|
|
19
|
+
const formattedValue = new Intl.NumberFormat(locales || currentLocale, formatOptions).format(numberValue);
|
|
20
|
+
return _jsx(RecordLink, { link: link, children: formattedValue });
|
|
21
|
+
};
|
|
22
|
+
CurrencyField.isNumberColumn = true;
|
|
23
|
+
export default CurrencyField;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type RaRecord } from '@strato-admin/core';
|
|
2
|
+
import { type FieldProps } from './types';
|
|
3
|
+
export type DateFieldProps<RecordType extends RaRecord = RaRecord> = FieldProps<RecordType> & {
|
|
4
|
+
/**
|
|
5
|
+
* Options for Intl.DateTimeFormat.
|
|
6
|
+
*/
|
|
7
|
+
options?: Intl.DateTimeFormatOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Locale(s) to use for formatting. Defaults to the current app locale.
|
|
10
|
+
*/
|
|
11
|
+
locales?: string | string[];
|
|
12
|
+
};
|
|
13
|
+
declare const DateField: <RecordType extends RaRecord = RaRecord>(props: DateFieldProps<RecordType>) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export default DateField;
|