@akinon/pz-basket-gift-pack 1.51.0 → 1.52.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +7 -0
- package/README.md +11 -25
- package/package.json +1 -1
- package/src/index.tsx +89 -59
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
@@ -1,35 +1,21 @@
|
|
1
|
-
# pz-basket-gift-pack
|
1
|
+
# @akinon/pz-basket-gift-pack
|
2
2
|
|
3
3
|
### Install the npm package
|
4
4
|
|
5
5
|
```bash
|
6
6
|
# For latest version
|
7
|
-
yarn add
|
7
|
+
yarn add @akinon/pz-basket-gift-pack
|
8
8
|
|
9
|
-
#
|
10
|
-
|
11
|
-
```
|
12
|
-
|
13
|
-
### Next Config Configuration
|
14
|
-
|
15
|
-
##### apps/web/next.config.js**
|
16
|
-
|
17
|
-
```javascript
|
18
|
-
const withTM = require("next-transpile-modules")(["pz-basket-gift-pack"]);
|
19
|
-
```
|
20
|
-
|
21
|
-
### Example Usage
|
22
|
-
##### File Path: src/views/basket/basket-item.tsx
|
23
|
-
|
24
|
-
|
25
|
-
```javascript
|
26
|
-
import { BasketGiftPackage } from 'pz-basket-gift-pack';
|
27
|
-
|
28
|
-
<BasketGiftPackage basketItem={basketItem}/>
|
9
|
+
# Preferred installation method
|
10
|
+
npx @akinon/projectzero@latest --plugins
|
29
11
|
```
|
30
12
|
|
31
13
|
### Props
|
32
14
|
|
33
|
-
| Properties | Type
|
34
|
-
|
|
35
|
-
| basketItem | `object` | Product information. |
|
15
|
+
| Properties | Type | Description |
|
16
|
+
| --- | --- | --- |
|
17
|
+
| basketItem | `object` | Product information. |
|
18
|
+
| useModal | `boolean` | This prop determines whether the gift pack form will be displayed inside a modal. When set to true, the form will open inside a modal. |
|
19
|
+
| modalClassName | `string` | This prop is used to customize the overall style of the modal. |
|
20
|
+
| modalTitle | `string` | This prop sets the title of the modal. |
|
21
|
+
| modalContentClassName | `string` | This prop is used to customize the style of the modal content. |
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
@@ -8,8 +8,7 @@ import { useForm, SubmitHandler } from 'react-hook-form';
|
|
8
8
|
import { yupResolver } from '@hookform/resolvers/yup';
|
9
9
|
import * as yup from 'yup';
|
10
10
|
import { useEffect, useState } from 'react';
|
11
|
-
import { Button } from '@akinon/next/components
|
12
|
-
import { Icon } from '@akinon/next/components/icon';
|
11
|
+
import { Button, Icon, Modal } from '@akinon/next/components';
|
13
12
|
import { BasketItem as BasketItemType } from '@akinon/next/types';
|
14
13
|
|
15
14
|
interface GiftPackForm {
|
@@ -18,6 +17,10 @@ interface GiftPackForm {
|
|
18
17
|
|
19
18
|
interface Props {
|
20
19
|
basketItem: BasketItemType;
|
20
|
+
useModal?: boolean;
|
21
|
+
modalTitle?: string;
|
22
|
+
modalClassName?: string;
|
23
|
+
modalContentClassName?: string;
|
21
24
|
translations?: {
|
22
25
|
placeholderInput?: string;
|
23
26
|
warningMessage?: string;
|
@@ -38,7 +41,11 @@ interface Props {
|
|
38
41
|
export const BasketGiftPack = ({
|
39
42
|
basketItem,
|
40
43
|
translations,
|
41
|
-
className
|
44
|
+
className,
|
45
|
+
useModal = false,
|
46
|
+
modalTitle = 'Gift Note',
|
47
|
+
modalClassName,
|
48
|
+
modalContentClassName
|
42
49
|
}: Props) => {
|
43
50
|
const defaultTranslations = {
|
44
51
|
placeholderInput:
|
@@ -130,6 +137,61 @@ export const BasketGiftPack = ({
|
|
130
137
|
}
|
131
138
|
};
|
132
139
|
|
140
|
+
const formContent = (
|
141
|
+
<form onSubmit={handleSubmit(onSubmit)}>
|
142
|
+
{!useModal && (
|
143
|
+
<div className="flex justify-between mb-3">
|
144
|
+
<span className="text-[0.75rem] font-bold">
|
145
|
+
{_translations.addGiftNote}
|
146
|
+
</span>
|
147
|
+
<Button
|
148
|
+
appearance="ghost"
|
149
|
+
className="text-[#000000] cursor-pointer border-0 px-0 py-0 text-[0.75rem] select-none underline h-auto hover:bg-transparent hover:text-[#000000]"
|
150
|
+
onClick={(e) => {
|
151
|
+
e.preventDefault();
|
152
|
+
setHasNote((prevstate) => ({ ...prevstate, state: false }));
|
153
|
+
}}
|
154
|
+
>
|
155
|
+
{_translations.close}
|
156
|
+
</Button>
|
157
|
+
</div>
|
158
|
+
)}
|
159
|
+
<textarea
|
160
|
+
className="w-full border border-solid border-[#4a4f53] p-4 placeholder:text-[0.75rem] placeholder:text-[#c8c9c8] outline-none text-[0.75rem]"
|
161
|
+
rows={7}
|
162
|
+
name="message"
|
163
|
+
value={note !== defaultMessage ? note : ' '}
|
164
|
+
placeholder={_translations.placeholderInput}
|
165
|
+
{...register('message')}
|
166
|
+
/>
|
167
|
+
{errors.message && (
|
168
|
+
<span className="text-sm text-[#d72a04]">{errors.message.message}</span>
|
169
|
+
)}
|
170
|
+
<div className="flex justify-between items-center mt-2">
|
171
|
+
<span
|
172
|
+
className={clsx(
|
173
|
+
'text-[0.75rem] ',
|
174
|
+
textAreaCount > 160 ? 'text-[#e85150]' : 'text-[#82a27c]'
|
175
|
+
)}
|
176
|
+
>
|
177
|
+
{textAreaCount}/160 {_translations.charactersLength}
|
178
|
+
</span>
|
179
|
+
<div className="flex items-center gap-3">
|
180
|
+
<Button
|
181
|
+
appearance="ghost"
|
182
|
+
className="text-[#000000] cursor-pointer border-0 px-0 py-0 text-[0.75rem] select-none underline h-auto hover:bg-transparent hover:text-[#000000]"
|
183
|
+
onClick={removeNote}
|
184
|
+
>
|
185
|
+
{_translations.removeNote}
|
186
|
+
</Button>
|
187
|
+
<Button type="submit" className="w-28 h-7 font-medium uppercase">
|
188
|
+
{_translations.save}
|
189
|
+
</Button>
|
190
|
+
</div>
|
191
|
+
</div>
|
192
|
+
</form>
|
193
|
+
);
|
194
|
+
|
133
195
|
useEffect(() => {
|
134
196
|
for (const [key, value] of Object.entries(basketItem.attributes)) {
|
135
197
|
if (value === '') {
|
@@ -220,64 +282,32 @@ export const BasketGiftPack = ({
|
|
220
282
|
{_translations.removeGiftPack}
|
221
283
|
</Button>
|
222
284
|
</div>
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
<span className="text-[0.75rem] font-bold">
|
231
|
-
{_translations.addGiftNote}
|
232
|
-
</span>
|
233
|
-
<Button
|
234
|
-
appearance="ghost"
|
235
|
-
className="text-[#000000] cursor-pointer border-0 px-0 py-0 text-[0.75rem] select-none underline h-auto hover:bg-transparent hover:text-[#000000]"
|
236
|
-
onClick={(e) => {
|
237
|
-
e.preventDefault();
|
238
|
-
setHasNote((prevstate) => ({ ...prevstate, state: false }));
|
239
|
-
}}
|
240
|
-
>
|
241
|
-
{_translations.close}
|
242
|
-
</Button>
|
243
|
-
</div>
|
244
|
-
<textarea
|
245
|
-
className="w-full border border-solid border-[#4a4f53] p-4 placeholder:text-[0.75rem] placeholder:text-[#c8c9c8] outline-none text-[0.75rem]"
|
246
|
-
rows={7}
|
247
|
-
name="message"
|
248
|
-
value={note !== defaultMessage ? note : ' '}
|
249
|
-
placeholder={_translations.placeholderInput}
|
250
|
-
{...register('message')}
|
251
|
-
/>
|
252
|
-
{errors.message && (
|
253
|
-
<span className="text-sm text-[#d72a04]">
|
254
|
-
{errors.message.message}
|
255
|
-
</span>
|
285
|
+
{useModal ? (
|
286
|
+
<Modal
|
287
|
+
portalId="basket-gift-pack-modal"
|
288
|
+
title={modalTitle}
|
289
|
+
className={twMerge(
|
290
|
+
'w-full sm:w-[28rem] max-h-[90vh] overflow-y-auto',
|
291
|
+
modalClassName
|
256
292
|
)}
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
{textAreaCount}/160 {_translations.charactersLength}
|
265
|
-
</span>
|
266
|
-
<div className="flex items-center gap-3">
|
267
|
-
<Button
|
268
|
-
appearance="ghost"
|
269
|
-
className="text-[#000000] cursor-pointer border-0 px-0 py-0 text-[0.75rem] select-none underline h-auto hover:bg-transparent hover:text-[#000000]"
|
270
|
-
onClick={removeNote}
|
271
|
-
>
|
272
|
-
{_translations.removeNote}
|
273
|
-
</Button>
|
274
|
-
<Button type="submit" className="w-28 h-7 font-medium uppercase">
|
275
|
-
{_translations.save}
|
276
|
-
</Button>
|
277
|
-
</div>
|
293
|
+
open={hasNote.state}
|
294
|
+
setOpen={(state) =>
|
295
|
+
setHasNote((prevstate) => ({ ...prevstate, state }))
|
296
|
+
}
|
297
|
+
>
|
298
|
+
<div className={twMerge('px-6 py-4', modalContentClassName)}>
|
299
|
+
{formContent}
|
278
300
|
</div>
|
279
|
-
</
|
280
|
-
|
301
|
+
</Modal>
|
302
|
+
) : (
|
303
|
+
<div
|
304
|
+
className={clsx('mt-4', {
|
305
|
+
hidden: !hasNote.state
|
306
|
+
})}
|
307
|
+
>
|
308
|
+
{formContent}
|
309
|
+
</div>
|
310
|
+
)}
|
281
311
|
</div>
|
282
312
|
);
|
283
313
|
};
|