@commercelayer/app-elements 1.1.0 → 1.2.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 (24) hide show
  1. package/dist/{InputDateComponent-42ce4751.js → InputDateComponent-a16635b1.js} +1 -1
  2. package/dist/{main-6e2634ae.js → main-7df8201b.js} +7338 -7194
  3. package/dist/main.d.ts +1 -1
  4. package/dist/main.js +127 -126
  5. package/dist/style.css +1 -1
  6. package/dist/ui/forms/InputCheckboxGroup/HookedInputCheckboxGroup.d.ts +13 -0
  7. package/dist/ui/forms/InputCheckboxGroup/InputCheckboxGroup.d.ts +31 -0
  8. package/dist/ui/forms/InputCheckboxGroup/InputCheckboxGroupItem.d.ts +55 -0
  9. package/dist/ui/forms/InputCheckboxGroup/index.d.ts +2 -0
  10. package/dist/ui/forms/InputCheckboxGroup/reducer.d.ts +25 -0
  11. package/dist/ui/forms/InputResourceGroup/utils.d.ts +16 -0
  12. package/dist/ui/resources/ResourceLineItems/ResourceLineItems.d.ts +7 -24
  13. package/dist/ui/resources/ResourceLineItems/ResourceLineItems.mocks.d.ts +43 -5
  14. package/dist/ui/resources/ResourceOrderSummary/AddCouponOverlay.d.ts +6 -0
  15. package/dist/ui/resources/ResourceOrderSummary/AdjustTotalOverlay.d.ts +6 -0
  16. package/dist/ui/resources/ResourceOrderSummary/DeleteCouponButton.d.ts +6 -0
  17. package/dist/ui/resources/{ResourceOrderSummary.d.ts → ResourceOrderSummary/ResourceOrderSummary.d.ts} +5 -4
  18. package/dist/ui/resources/ResourceOrderSummary/index.d.ts +1 -0
  19. package/dist/ui/resources/ResourceOrderSummary/utils.d.ts +23 -0
  20. package/package.json +1 -1
  21. package/dist/ui/forms/InputCheckboxGroup.d.ts +0 -56
  22. package/dist/ui/forms/InputResourceGroup/Checkbox.d.ts +0 -22
  23. /package/dist/ui/forms/{InputCheckboxGroup.test.d.ts → InputCheckboxGroup/InputCheckboxGroup.test.d.ts} +0 -0
  24. /package/dist/ui/resources/{ResourceOrderSummary.test.d.ts → ResourceOrderSummary/ResourceOrderSummary.test.d.ts} +0 -0
@@ -0,0 +1,55 @@
1
+ import { type InputCheckboxProps } from '../../forms/InputCheckbox';
2
+ import { type ComponentProps } from 'react';
3
+ export interface InputCheckboxGroupOption extends Pick<InputCheckboxProps, 'icon' | 'checked'> {
4
+ /**
5
+ * Input name, will be used to set the html name for checkbox and the quantity inputs.
6
+ * If not provided, the value will be used instead.
7
+ */
8
+ name?: string;
9
+ /**
10
+ * Item identifier, must be unique and will be used for the onChange callback.
11
+ */
12
+ value: string;
13
+ /**
14
+ * Item content to be displayed in the central section of the row.
15
+ */
16
+ content: React.ReactNode;
17
+ /**
18
+ * Quantity range to be used in the InputSpinner.
19
+ * If not provided the quantity input spinner will not be displayed.
20
+ */
21
+ quantity?: {
22
+ min: number;
23
+ max: number;
24
+ };
25
+ }
26
+ export interface Props extends InputCheckboxGroupOption {
27
+ /**
28
+ * Callback triggered when the user checks/unchecks an option or changes the quantity.
29
+ * New quantity is returned only if `quantity` is part of the option (`InputCheckboxGroupOption`).
30
+ */
31
+ onChange: (value: string, newQuantity?: number) => void;
32
+ /**
33
+ * Quantity to be used as default value for the InputSpinner.
34
+ */
35
+ defaultQuantity?: number;
36
+ }
37
+ /**
38
+ * Internal component to render the single item of the InputCheckboxGroup.
39
+ */
40
+ export declare const InputCheckboxGroupItem: import('../../atoms/SkeletonTemplate').SkeletonTemplateComponent<{
41
+ onChange: (value: string, newQuantity?: number) => void;
42
+ defaultQuantity?: number | undefined;
43
+ name?: string | undefined;
44
+ value: string;
45
+ content: React.ReactNode;
46
+ quantity?: {
47
+ min: number;
48
+ max: number;
49
+ } | undefined;
50
+ icon?: JSX.Element | undefined;
51
+ checked?: boolean | undefined;
52
+ delayMs?: number | undefined;
53
+ isLoading?: boolean | undefined;
54
+ }>;
55
+ export type InputCheckboxGroupItemProps = ComponentProps<typeof InputCheckboxGroupItem>;
@@ -0,0 +1,2 @@
1
+ export { HookedInputCheckboxGroup, type HookedInputCheckboxGroupProps } from './HookedInputCheckboxGroup';
2
+ export { InputCheckboxGroup, type InputCheckboxGroupProps } from './InputCheckboxGroup';
@@ -0,0 +1,25 @@
1
+ import { type SelectedItem } from './InputCheckboxGroup';
2
+ import { type InputCheckboxGroupOption } from './InputCheckboxGroupItem';
3
+ export type InternalState = Array<{
4
+ value: string;
5
+ quantity?: number;
6
+ isSelected: boolean;
7
+ }>;
8
+ type Action = {
9
+ type: 'updateQuantity';
10
+ payload: {
11
+ value: string;
12
+ quantity: number;
13
+ };
14
+ } | {
15
+ type: 'toggleSelection';
16
+ payload: {
17
+ value: string;
18
+ };
19
+ };
20
+ export declare const reducer: (state: InternalState, action: Action) => InternalState;
21
+ export declare function makeInitialState({ options, defaultValues }: {
22
+ options: InputCheckboxGroupOption[];
23
+ defaultValues: SelectedItem[];
24
+ }): InternalState;
25
+ export {};
@@ -1,3 +1,5 @@
1
+ import { type CommerceLayerClient } from '@commercelayer/sdk';
2
+ import { type ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
1
3
  export declare function useToggleCheckboxValues(defaultValues: string[]): {
2
4
  values: string[];
3
5
  toggleValue: (value: string) => void;
@@ -18,3 +20,17 @@ export declare function computeLabelWithSelected({ label, selectedCount, totalCo
18
20
  selectedCount: number;
19
21
  totalCount?: number;
20
22
  }): string;
23
+ type Resource = Awaited<ReturnType<CommerceLayerClient[ListableResourceType]['list']>>[number];
24
+ /**
25
+ * Helper to prepare the options for the checkbox group or mocked info to be used for skeleton.
26
+ */
27
+ export declare function prepareCheckboxItemOrMock({ resource, isLoading, fieldForLabel, fieldForValue }: {
28
+ resource?: Resource;
29
+ isLoading?: boolean;
30
+ fieldForValue: string;
31
+ fieldForLabel: string;
32
+ }): {
33
+ value: string;
34
+ label: string;
35
+ };
36
+ export {};
@@ -1,35 +1,18 @@
1
- /// <reference types="react" />
2
1
  import type { LineItem, ParcelLineItem, ReturnLineItem, StockLineItem } from '@commercelayer/sdk';
2
+ import { type ComponentProps } from 'react';
3
3
  type Item = LineItem | ParcelLineItem | StockLineItem | ReturnLineItem;
4
- export interface ResourceLineItemsProps {
5
- /**
6
- * Array of supported line items to be rendered.
7
- */
8
- items: Item[];
9
- /**
10
- * Optional size of rendered items structure. This setting is going to change font size, spacings, icon size in a proportional way.
11
- */
12
- size?: 'small' | 'normal';
13
- /**
14
- * Optional footer slot to add bottom elements / actions.
15
- */
16
- footer?: React.ReactNode;
17
- /**
18
- * Optional setting to define the visibility of line item Edit link.
19
- */
20
- editable?: boolean;
21
- /**
22
- * Optional onChange function to define line item Edit callback.
23
- */
24
- onChange?: () => void;
25
- }
4
+ export type ResourceLineItemsProps = ComponentProps<typeof ResourceLineItems>;
26
5
  /**
27
6
  * This component renders a list of line items taking care of showing the right informations and structure depending of provided line item type.
28
7
  */
29
8
  export declare const ResourceLineItems: import('../../atoms/SkeletonTemplate').SkeletonTemplateComponent<{
30
9
  items: Item[];
31
10
  size?: "small" | "normal" | undefined;
32
- footer?: React.ReactNode;
11
+ footer?: {
12
+ key: string;
13
+ element: React.ReactNode;
14
+ fullWidth?: boolean | undefined;
15
+ }[] | undefined;
33
16
  editable?: boolean | undefined;
34
17
  onChange?: (() => void) | undefined;
35
18
  delayMs?: number | undefined;
@@ -338,10 +338,11 @@ export declare const presetLineItems: {
338
338
  reference_origin: null;
339
339
  metadata: {};
340
340
  };
341
- percentageDiscountPromotionSkuList: {
341
+ percentageDiscountPromotionCoupon: {
342
342
  type: "line_items";
343
343
  id: string;
344
344
  sku_code: null;
345
+ coupon_code: string;
345
346
  bundle_code: null;
346
347
  quantity: number;
347
348
  currency_code: string;
@@ -373,7 +374,7 @@ export declare const presetLineItems: {
373
374
  reference_origin: null;
374
375
  metadata: {};
375
376
  };
376
- percentageDiscountPromotionCoupon: {
377
+ freeShippingPromotion: {
377
378
  type: "line_items";
378
379
  id: string;
379
380
  sku_code: null;
@@ -400,7 +401,7 @@ export declare const presetLineItems: {
400
401
  discount_breakdown: {};
401
402
  tax_rate: number;
402
403
  tax_breakdown: {};
403
- item_type: "percentage_discount_promotions";
404
+ item_type: "free_shipping_promotions";
404
405
  frequency: null;
405
406
  created_at: string;
406
407
  updated_at: string;
@@ -408,7 +409,7 @@ export declare const presetLineItems: {
408
409
  reference_origin: null;
409
410
  metadata: {};
410
411
  };
411
- freeShippingPromotion: {
412
+ paymentMethod: {
412
413
  type: "line_items";
413
414
  id: string;
414
415
  sku_code: null;
@@ -435,8 +436,45 @@ export declare const presetLineItems: {
435
436
  discount_breakdown: {};
436
437
  tax_rate: number;
437
438
  tax_breakdown: {};
438
- item_type: "free_shipping_promotions";
439
+ item_type: "payment_methods";
440
+ frequency: null;
441
+ coupon_code: null;
442
+ created_at: string;
443
+ updated_at: string;
444
+ reference: null;
445
+ reference_origin: null;
446
+ metadata: {};
447
+ };
448
+ shipment: {
449
+ type: "line_items";
450
+ id: string;
451
+ sku_code: null;
452
+ bundle_code: null;
453
+ quantity: number;
454
+ currency_code: string;
455
+ unit_amount_cents: number;
456
+ unit_amount_float: number;
457
+ formatted_unit_amount: string;
458
+ options_amount_cents: number;
459
+ options_amount_float: number;
460
+ formatted_options_amount: string;
461
+ discount_cents: number;
462
+ discount_float: number;
463
+ formatted_discount: string;
464
+ total_amount_cents: number;
465
+ total_amount_float: number;
466
+ formatted_total_amount: string;
467
+ tax_amount_cents: number;
468
+ tax_amount_float: number;
469
+ formatted_tax_amount: string;
470
+ name: string;
471
+ image_url: null;
472
+ discount_breakdown: {};
473
+ tax_rate: number;
474
+ tax_breakdown: {};
475
+ item_type: "shipments";
439
476
  frequency: null;
477
+ coupon_code: null;
440
478
  created_at: string;
441
479
  updated_at: string;
442
480
  reference: null;
@@ -0,0 +1,6 @@
1
+ import type { Order } from '@commercelayer/sdk';
2
+ export declare function useAddCouponOverlay(order: Order, onChange?: () => void): {
3
+ close: () => void;
4
+ open: () => void;
5
+ Overlay: () => import("react/jsx-runtime").JSX.Element;
6
+ };
@@ -0,0 +1,6 @@
1
+ import type { Order } from '@commercelayer/sdk';
2
+ export declare function useAdjustTotalOverlay(order: Order, onChange?: () => void): {
3
+ close: () => void;
4
+ open: () => void;
5
+ Overlay: () => import("react/jsx-runtime").JSX.Element;
6
+ };
@@ -0,0 +1,6 @@
1
+ export declare const DeleteCouponButton: import('../../atoms/SkeletonTemplate').SkeletonTemplateComponent<{
2
+ order: import("@commercelayer/sdk/lib/cjs/resources/orders").Order;
3
+ onChange?: (() => void) | undefined;
4
+ delayMs?: number | undefined;
5
+ isLoading?: boolean | undefined;
6
+ }>;
@@ -1,13 +1,14 @@
1
- /// <reference types="react" />
2
- import { type ActionButtonsProps } from '../composite/ActionButtons';
1
+ import { type ActionButtonsProps } from '../../composite/ActionButtons';
3
2
  import type { Order } from '@commercelayer/sdk';
4
- export interface ResourceOrderSummaryProps {
3
+ import { type ComponentProps } from 'react';
4
+ export interface Props {
5
5
  editable?: boolean;
6
6
  onChange?: () => void;
7
7
  footerActions?: ActionButtonsProps['actions'];
8
8
  order: Order;
9
9
  }
10
- export declare const ResourceOrderSummary: import('../atoms/SkeletonTemplate').SkeletonTemplateComponent<{
10
+ export type ResourceOrderSummaryProps = ComponentProps<typeof ResourceOrderSummary>;
11
+ export declare const ResourceOrderSummary: import('../../atoms/SkeletonTemplate').SkeletonTemplateComponent<{
11
12
  editable?: boolean | undefined;
12
13
  onChange?: (() => void) | undefined;
13
14
  footerActions?: {
@@ -0,0 +1 @@
1
+ export { ResourceOrderSummary, type ResourceOrderSummaryProps } from './ResourceOrderSummary';
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ import type { Order } from '@commercelayer/sdk';
3
+ interface TotalRowProps {
4
+ /** Displayed label */
5
+ label: string;
6
+ /** Formatted amount */
7
+ formattedAmount: string | undefined | null;
8
+ /** Set font-weight to bold */
9
+ bold?: boolean;
10
+ /**
11
+ * When `true` the row will be always printed.
12
+ * @default false
13
+ */
14
+ force?: boolean;
15
+ }
16
+ export declare function renderTotalRow({ label, value, bold }: {
17
+ label: string;
18
+ value: React.ReactNode;
19
+ bold?: boolean;
20
+ }): JSX.Element;
21
+ export declare function renderTotalRowAmount({ label, formattedAmount, force, bold }: TotalRowProps): JSX.Element | null;
22
+ export declare function renderDiscounts(order: Order): JSX.Element | null;
23
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercelayer/app-elements",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -1,56 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- interface OptionItem {
3
- /**
4
- * Input name, will be used to set the html name for checkbox and the quantity inputs
5
- * If not provided, the value will be used instead
6
- */
7
- name?: string;
8
- /**
9
- * Item identifier, must be unique and will be used for the onChange callback
10
- */
11
- value: string;
12
- /**
13
- * Item content to be displayed in the central section of the row
14
- */
15
- content: ReactNode;
16
- /**
17
- * Quantity range to be used in the InputSpinner
18
- */
19
- quantity: {
20
- min: number;
21
- max: number;
22
- };
23
- }
24
- interface SelectedItem {
25
- /**
26
- * Item identifier, should be one of the options
27
- */
28
- value: string;
29
- /**
30
- * Selected quantity for the checked item
31
- */
32
- quantity: number;
33
- }
34
- export interface InputCheckboxGroupProps {
35
- /**
36
- * Text to be displayed on top of the list
37
- */
38
- title?: string;
39
- /**
40
- * list of options to render as checkboxes with quantity input
41
- */
42
- options: OptionItem[];
43
- /**
44
- * pre-selected options
45
- */
46
- defaultValues?: SelectedItem[];
47
- /**
48
- * Callback triggered when the user checks/unchecks an option or changes the quantity
49
- */
50
- onChange: (selected: SelectedItem[]) => void;
51
- }
52
- export declare function InputCheckboxGroup({ options, defaultValues, onChange, title, ...rest }: InputCheckboxGroupProps): JSX.Element;
53
- export declare namespace InputCheckboxGroup {
54
- var displayName: string;
55
- }
56
- export {};
@@ -1,22 +0,0 @@
1
- /// <reference types="react" />
2
- import { type InputCheckboxProps } from '../../forms/InputCheckbox/InputCheckbox';
3
- import { type CommerceLayerClient } from '@commercelayer/sdk';
4
- import { type ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
5
- export interface CheckboxItem {
6
- value: string;
7
- label: string;
8
- }
9
- interface CheckboxProps extends Pick<InputCheckboxProps, 'checked' | 'onChange'> {
10
- item: CheckboxItem;
11
- showIcon?: boolean;
12
- hasBottomMargin?: boolean;
13
- }
14
- export declare function Checkbox({ item, showIcon, checked, onChange }: CheckboxProps): JSX.Element;
15
- type Resource = Awaited<ReturnType<CommerceLayerClient[ListableResourceType]['list']>>[number];
16
- export declare function prepareCheckboxItemOrMock({ resource, isLoading, fieldForLabel, fieldForValue }: {
17
- resource?: Resource;
18
- isLoading?: boolean;
19
- fieldForValue: string;
20
- fieldForLabel: string;
21
- }): CheckboxItem;
22
- export {};