@haus-storefront-react/order-lines 0.0.1

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/index.css ADDED
@@ -0,0 +1 @@
1
+ ._icon_qkmq5_1{width:var(--icon-width, 24px);height:var(--icon-height, 24px);display:var(--icon-display, inline-flex);align-items:center;flex:0 0 auto}._icon_qkmq5_1._spin_qkmq5_8{animation:_spin_qkmq5_8 1s linear infinite}@keyframes _spin_qkmq5_8{0%{transform:rotate(0)}to{transform:rotate(359deg)}}._button_pv27b_1{box-sizing:content-box;display:var(--button-display, inline-flex);flex-direction:var(--button-flex-direction, row);align-items:var(--button-align-items, center);justify-content:var(--button-justify-content, center);gap:var(--button-gap, var(--ec-spacing-xxs, 4px));width:var(--button-width, fit-content);max-width:var(--button-max-width, calc(100% - 32px) );max-height:var(--button-max-height, inherit);min-width:var(--button-min-width, fit-content);min-height:var(--button-min-height, fit-content);height:var(--button-height, fit-content);padding:var(--button-padding, var(--ec-spacing-xxs, 4px) var(--ec-spacing-sm, 16px));border:var(--button-border, 1px solid var(--button-background-color, #b3d6cd));border-radius:var(--button-border-radius, var(--ec-border-radius-sm, 8px));color:var(--button-color, var(--ec-font-color, #000));font-size:var(--button-font-size, 14px);background-color:var(--button-background-color, var(--ec-primary-color, #b3d6cd));transition:var(--button-transition, var(--ec-transition-ease-in-out));text-decoration:var(--button-text-decoration, none);font-family:var(--button-font-family, inherit);font-weight:var(--button-font-weight, inherit);--spinner-margin: 0}._button_pv27b_1:hover{cursor:pointer;background-color:var(--button-background-color-hover, var(--ec-primary-color-300, #8bbdb2))}._button_pv27b_1:focus:not(:focus-visible){outline:none}._button_pv27b_1:disabled{cursor:not-allowed;opacity:.5}._btnIcon_pv27b_38{width:var(--button-icon-width, 24px);height:var(--button-icon-height, 24px);display:flex;align-items:center;justify-content:center}._btnIcon_pv27b_38 svg{width:100%;height:100%}
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/order-lines';
2
+ export * from './lib/use-order-lines-props';
package/index.mjs ADDED
@@ -0,0 +1,6 @@
1
+ import { O as s, a, u as o } from "./index-Bkhe0b4T.mjs";
2
+ export {
3
+ s as OrderLines,
4
+ a as createOrderLinesScope,
5
+ o as useOrderLinesProps
6
+ };
@@ -0,0 +1,196 @@
1
+ import { OrderLine, CurrencyCode, Price as PriceType, AsChildProps } from '@haus-storefront-react/shared-types';
2
+ import { Scope } from '@haus-storefront-react/common-utils';
3
+ import { ButtonHTMLAttributes, ImgHTMLAttributes } from 'react';
4
+ import { UseOrderLinesResult } from './use-order-lines-props';
5
+ import * as React from 'react';
6
+ type ScopedProps<P> = P & {
7
+ __scopeOrderLines?: Scope;
8
+ };
9
+ declare const createOrderLinesScope: {
10
+ (): (scope: Scope) => {
11
+ [x: string]: {
12
+ [x: string]: React.Context<any>[] | React.Context<React.Context<any>>[];
13
+ };
14
+ };
15
+ scopeName: string;
16
+ };
17
+ type OrderLinesContextValue = UseOrderLinesResult & {
18
+ isAdjustable: boolean;
19
+ isRemovable: boolean;
20
+ };
21
+ interface OrderLinesRootProps {
22
+ children?: (props: OrderLinesContextValue) => React.ReactNode;
23
+ orderCode?: string;
24
+ adjustable?: boolean;
25
+ removable?: boolean;
26
+ }
27
+ interface OrderLineItemProps {
28
+ children?: React.ReactNode;
29
+ orderLine: OrderLine;
30
+ }
31
+ interface OrderLineImageProps extends ImgHTMLAttributes<HTMLImageElement>, AsChildProps {
32
+ alt?: string;
33
+ }
34
+ interface OrderLineRemoveProps extends ButtonHTMLAttributes<HTMLButtonElement>, AsChildProps {
35
+ }
36
+ interface OrderLineQuantityProps extends AsChildProps {
37
+ min?: number;
38
+ max?: number;
39
+ step?: number;
40
+ }
41
+ interface OrderLinesPriceProps {
42
+ children?: (props: {
43
+ price: PriceType;
44
+ priceWithTax: PriceType;
45
+ currencyCode: CurrencyCode;
46
+ isPromotion: boolean;
47
+ isCampaign: boolean;
48
+ isFromPrice: boolean;
49
+ ordinaryPrice?: PriceType;
50
+ }) => React.ReactNode;
51
+ withDiscountPrice?: boolean;
52
+ }
53
+ /**
54
+ * OrderLines is a headless component for managing order lines in a cart or order.
55
+ * It provides functionality for displaying, adjusting quantities, and removing items.
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * <OrderLines.Root>
60
+ * {({ data: orderLines }) => (
61
+ * orderLines?.map((line) => (
62
+ * <OrderLines.Item key={line.id} orderLine={line}>
63
+ * <OrderLines.Image />
64
+ * <OrderLines.Price>
65
+ * {({ price, currencyCode, isFromPrice }) => (
66
+ * <div>
67
+ * {isFromPrice ? 'From ' : ''}
68
+ * <Price price={price} currencyCode={currencyCode} />
69
+ * </div>
70
+ * )}
71
+ * </OrderLines.Price>
72
+ * <OrderLines.Quantity>
73
+ * <OrderLines.Quantity.Decrement>-</OrderLines.Quantity.Decrement>
74
+ * <OrderLines.Quantity.Input />
75
+ * <OrderLines.Quantity.Increment>+</OrderLines.Quantity.Increment>
76
+ * </OrderLines.Quantity>
77
+ * <OrderLines.Remove>Remove</OrderLines.Remove>
78
+ * </OrderLines.Item>
79
+ * ))
80
+ * )}
81
+ * </OrderLines.Root>
82
+ * ```
83
+ */
84
+ export declare const OrderLines: {
85
+ /**
86
+ * Root component for OrderLines. Provides context for all child components.
87
+ *
88
+ * @param props.orderCode - Optional order code for fetching specific order
89
+ * @param props.adjustable - Whether quantities can be adjusted (default: true)
90
+ * @param props.removable - Whether items can be removed (default: true)
91
+ * @param props.children - Render prop that receives order lines data and functions
92
+ */
93
+ Root: {
94
+ ({ children, orderCode, adjustable, removable, __scopeOrderLines, }: ScopedProps<OrderLinesRootProps>): import("react/jsx-runtime").JSX.Element;
95
+ displayName: string;
96
+ };
97
+ /**
98
+ * Item component for a single order line. Must be used within OrderLines.Root.
99
+ *
100
+ * @param props.orderLine - The order line data to display
101
+ */
102
+ Item: {
103
+ ({ children, orderLine, __scopeOrderLines, }: ScopedProps<OrderLineItemProps>): import("react/jsx-runtime").JSX.Element;
104
+ displayName: string;
105
+ };
106
+ /**
107
+ * Image component for displaying the order line's featured asset.
108
+ * Must be used within OrderLines.Item.
109
+ *
110
+ * @param props.alt - Optional alt text for the image
111
+ */
112
+ Image: {
113
+ ({ alt, asChild, __scopeOrderLines, ...props }: ScopedProps<OrderLineImageProps>): import("react/jsx-runtime").JSX.Element | null;
114
+ displayName: string;
115
+ };
116
+ /**
117
+ * Remove button component for removing an order line.
118
+ * Must be used within OrderLines.Item.
119
+ */
120
+ Remove: {
121
+ ({ children, asChild, __scopeOrderLines, ...props }: ScopedProps<OrderLineRemoveProps>): import("react/jsx-runtime").JSX.Element | null;
122
+ displayName: string;
123
+ };
124
+ /**
125
+ * Quantity buttons component for an order line.
126
+ * Must be used within OrderLines.Item.
127
+ *
128
+ * @param props.min - Minimum quantity (default: 1)
129
+ * @param props.max - Maximum quantity
130
+ * @param props.step - Step size for quantity changes (default: 1)
131
+ */
132
+ Quantity: {
133
+ Root: {
134
+ ({ children, min, max, step, __scopeOrderLines, }: ScopedProps<OrderLineQuantityProps>): import("react/jsx-runtime").JSX.Element | null;
135
+ displayName: string;
136
+ };
137
+ Decrement: {
138
+ ({ children, className, asChild, __scopeQuantityButtons, ...props }: import('@haus-storefront-react/common-ui').QuantityButtonsDecrementProps & {
139
+ __scopeQuantityButtons?: Scope;
140
+ }): import("react/jsx-runtime").JSX.Element;
141
+ displayName: string;
142
+ };
143
+ Input: {
144
+ ({ className, asChild, __scopeQuantityButtons, ...props }: import('@haus-storefront-react/common-ui').QuantityButtonsInputProps & {
145
+ __scopeQuantityButtons?: Scope;
146
+ }): import("react/jsx-runtime").JSX.Element;
147
+ displayName: string;
148
+ };
149
+ Increment: {
150
+ ({ children, className, asChild, __scopeQuantityButtons, ...props }: import('@haus-storefront-react/common-ui').QuantityButtonsIncrementProps & {
151
+ __scopeQuantityButtons?: Scope;
152
+ }): import("react/jsx-runtime").JSX.Element;
153
+ displayName: string;
154
+ };
155
+ Remove: ({ children, ...props }: ButtonHTMLAttributes<HTMLButtonElement>) => import("react/jsx-runtime").JSX.Element;
156
+ };
157
+ /**
158
+ * Price component for an order line.
159
+ * Must be used within OrderLines.Item.
160
+ *
161
+ * @example
162
+ * ```tsx
163
+ * <OrderLines.Price>
164
+ * {({ price, currencyCode, isFromPrice, isCampaign, ordinaryPrice }) => (
165
+ * <div>
166
+ * {isCampaign && ordinaryPrice && (
167
+ * <div className="original-price">
168
+ * <span price={ordinaryPrice} currencyCode={currencyCode} />
169
+ * </div>
170
+ * )}
171
+ * <div className="current-price">
172
+ * {isFromPrice ? 'From ' : ''}
173
+ * <span price={price} currencyCode={currencyCode} />
174
+ * </div>
175
+ * </div>
176
+ * )}
177
+ * </OrderLines.Price>
178
+ * ```
179
+ *
180
+ * @param props.withDiscountPrice - Whether to show discounted price
181
+ * @param props.children - Function that receives price information and returns React nodes:
182
+ * - price: The current price
183
+ * - priceWithTax: The current price with tax
184
+ * - currencyCode: The currency code
185
+ * - isPromotion: Whether the price is a promotion
186
+ * - isCampaign: Whether the price is part of a campaign
187
+ * - isFromPrice: Whether the price is a "from" price
188
+ * - ordinaryPrice: The original price before campaign/promotion
189
+ */
190
+ Price: {
191
+ ({ children, withDiscountPrice, __scopeOrderLines, }: ScopedProps<OrderLinesPriceProps>): React.ReactNode;
192
+ displayName: string;
193
+ };
194
+ };
195
+ export { createOrderLinesScope };
196
+ export type { OrderLinesRootProps, OrderLineItemProps, OrderLineImageProps, OrderLineRemoveProps, OrderLineQuantityProps, OrderLinesPriceProps, };
@@ -0,0 +1,26 @@
1
+ import { Maybe, OrderLine } from '@haus-storefront-react/shared-types';
2
+ import { UseQueryResult } from '@tanstack/react-query';
3
+ import { ButtonHTMLAttributes, InputHTMLAttributes } from 'react';
4
+ export type UseOrderLinesResult = UseQueryResult<Maybe<OrderLine[]>, Error> & {
5
+ adjustOrderLine: (orderLineId: string, quantity: number) => Promise<unknown>;
6
+ removeOrderLine: (lineId: string) => Promise<unknown>;
7
+ adjustError: Error | null;
8
+ removeError: Error | null;
9
+ isAdjusting: boolean;
10
+ isRemoving: boolean;
11
+ getRemoveProps: (props?: Partial<ButtonHTMLAttributes<HTMLButtonElement>>) => ButtonHTMLAttributes<HTMLButtonElement>;
12
+ getAdjustProps: (props?: Partial<InputHTMLAttributes<HTMLInputElement>>) => InputHTMLAttributes<HTMLInputElement>;
13
+ getDecrementProps: (props?: Partial<ButtonHTMLAttributes<HTMLButtonElement>>) => ButtonHTMLAttributes<HTMLButtonElement>;
14
+ getIncrementProps: (props?: Partial<ButtonHTMLAttributes<HTMLButtonElement>>) => ButtonHTMLAttributes<HTMLButtonElement>;
15
+ };
16
+ interface UseOrderLinesOptions {
17
+ orderCode?: string;
18
+ adjustable?: boolean;
19
+ removable?: boolean;
20
+ fetchActiveOrder?: boolean;
21
+ min?: number;
22
+ max?: number;
23
+ step?: number;
24
+ }
25
+ export declare const useOrderLinesProps: ({ orderCode, adjustable, removable, fetchActiveOrder, min, max, step, }?: UseOrderLinesOptions) => UseOrderLinesResult;
26
+ export {};
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@haus-storefront-react/order-lines",
3
+ "version": "0.0.1",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "import": "./index.mjs",
10
+ "require": "./index.js"
11
+ }
12
+ },
13
+ "dependencies": {
14
+ "@haus-storefront-react/common-ui": "0.0.1",
15
+ "@haus-storefront-react/common-utils": "0.0.1",
16
+ "@haus-storefront-react/core": "0.0.1",
17
+ "@haus-storefront-react/hooks": "0.0.1",
18
+ "@haus-storefront-react/shared-types": "0.0.1"
19
+ }
20
+ }