@commercelayer/app-elements 0.0.36 → 0.0.38

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.
@@ -0,0 +1,57 @@
1
+ import { type ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
2
+ export interface SortBy {
3
+ attribute: string;
4
+ direction: 'asc' | 'desc';
5
+ }
6
+ export interface FullListProps {
7
+ /**
8
+ * Default values to be shown as selected
9
+ */
10
+ defaultValues: string[];
11
+ /**
12
+ * Resource name from core API to be fetched.
13
+ * Example: `markets`
14
+ */
15
+ resource: ListableResourceType;
16
+ /**
17
+ * Attribute from the resource to be used as label for the checkbox
18
+ * Example: name, sku_code or email
19
+ */
20
+ fieldForLabel: string;
21
+ /**
22
+ * Attribute from the resource to be used as value for the checkbox
23
+ * Example: id
24
+ */
25
+ fieldForValue: string;
26
+ /**
27
+ * Callback invoked on change, it returns the new list of selected values
28
+ */
29
+ onChange: (values: string[]) => void;
30
+ /**
31
+ * Value to be used as search predicate when SearchBar is used.
32
+ * If missing the search bar will not be shown.
33
+ * It must match the format described in the Core APIs documentation.
34
+ * {@link https://docs.commercelayer.io/core/filtering-data}
35
+ * Example: name_cont
36
+ */
37
+ searchBy?: string;
38
+ /**
39
+ * Sorting options
40
+ *
41
+ * Example:
42
+ * ```{ attribute: 'name', direction: 'asc'}```
43
+ * or
44
+ * ```{ attribute: 'created_at', direction: 'desc'}```
45
+ */
46
+ sortBy: SortBy;
47
+ /**
48
+ * Title to be shown as main label.
49
+ * It will be automatically computed with the number of selected items.
50
+ */
51
+ title: string;
52
+ /**
53
+ * Total count of pre-fetched items.
54
+ */
55
+ totalCount?: number;
56
+ }
57
+ export declare function FullList({ defaultValues, fieldForLabel, fieldForValue, onChange, resource, searchBy, sortBy, title, totalCount }: FullListProps): JSX.Element;
@@ -0,0 +1,13 @@
1
+ import { type FullListProps } from './FullList';
2
+ export interface RelationshipSelectorProps extends Omit<FullListProps, 'totalCount'> {
3
+ /**
4
+ * Number of item to be shown in the preview list
5
+ * @default 5
6
+ */
7
+ previewLimit?: number;
8
+ }
9
+ declare function RelationshipSelector({ defaultValues, fieldForLabel, fieldForValue, previewLimit, onChange, resource, searchBy, sortBy, title }: RelationshipSelectorProps): JSX.Element;
10
+ declare namespace RelationshipSelector {
11
+ var displayName: string;
12
+ }
13
+ export { RelationshipSelector };
@@ -0,0 +1,20 @@
1
+ export declare function useToggleCheckboxValues(defaultValues: string[]): {
2
+ values: string[];
3
+ toggleValue: (value: string) => void;
4
+ setValues: (values: string[]) => void;
5
+ };
6
+ /**
7
+ * Simple helper to add the counter for selected options to a label
8
+ * or just the total of available options when nothing is selected
9
+ * @param options
10
+ * @returns string
11
+ *
12
+ * @example
13
+ * "Markets · 2 of 4"
14
+ * "Markets · 4"
15
+ */
16
+ export declare function computeLabelWithSelected({ label, selectedCount, totalCount }: {
17
+ label: string;
18
+ selectedCount: number;
19
+ totalCount?: number;
20
+ }): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/app-elements",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -56,13 +56,15 @@
56
56
  "polished": "^4.2.2",
57
57
  "postcss": "^8.4.21",
58
58
  "tailwindcss": "^3.3.1",
59
- "typescript": "^5.0.3",
59
+ "typescript": "^5.1.3",
60
60
  "vite": "^4.2.1",
61
61
  "vite-plugin-dts": "^2.2.0",
62
- "vitest": "^0.29.8"
62
+ "vitest": "^0.29.8",
63
+ "wouter": "^2.11.0"
63
64
  },
64
65
  "peerDependencies": {
65
- "@commercelayer/sdk": "^5.x"
66
+ "@commercelayer/sdk": "^5.x",
67
+ "wouter": "^2.x"
66
68
  },
67
69
  "scripts": {
68
70
  "build": "tsc && vite build",