@adobe-commerce/elsie 1.6.0 → 1.7.0-beta2
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/package.json +1 -2
- package/src/components/CartItem/CartItem.css +22 -3
- package/src/components/CartItem/CartItem.stories.tsx +102 -57
- package/src/components/CartItem/CartItem.tsx +10 -0
- package/src/components/CartList/CartList.stories.tsx +66 -3
- package/src/components/Field/Field.css +3 -3
- package/src/components/Field/Field.stories.tsx +45 -3
- package/src/components/Field/Field.tsx +22 -20
- package/src/components/Input/Input.css +3 -3
- package/src/components/Input/Input.stories.tsx +42 -3
- package/src/components/Input/Input.tsx +14 -6
- package/src/components/Picker/Picker.css +3 -3
- package/src/components/Picker/Picker.stories.tsx +74 -3
- package/src/components/Picker/Picker.tsx +8 -7
- package/src/components/RadioButton/RadioButton.css +8 -3
- package/src/components/RadioButton/RadioButton.stories.tsx +37 -3
- package/src/components/RadioButton/RadioButton.tsx +18 -4
- package/src/components/RadioButton/index.ts +3 -3
- package/src/components/TextArea/TextArea.css +4 -4
- package/src/components/TextArea/TextArea.stories.tsx +54 -7
- package/src/components/TextArea/TextArea.tsx +5 -5
- package/src/components/UIProvider/normalize.css +8 -3
- package/src/lib/debounce.ts +5 -1
- package/src/lib/get-price-formatter.ts +1 -1
- package/src/lib/index.ts +1 -0
- package/src/lib/wrap-required-asterisk.tsx +70 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* ADOBE CONFIDENTIAL
|
|
3
|
+
* __________________
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2025 Adobe
|
|
6
|
+
* All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* NOTICE: All information contained herein is, and remains
|
|
9
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
10
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
11
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
12
|
+
* property laws, including trade secret and copyright laws.
|
|
13
|
+
* Dissemination of this information or reproduction of this material
|
|
14
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
15
|
+
* from Adobe.
|
|
16
|
+
*******************************************************************/
|
|
17
|
+
|
|
18
|
+
import { VNode } from 'preact';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Wraps trailing asterisk(s) in a span element for consistent styling.
|
|
22
|
+
* If the text ends with one or more asterisks (preceded by optional space),
|
|
23
|
+
* the asterisk(s) will be wrapped in a <span className="dropin-label-required">.
|
|
24
|
+
* If required is true and no asterisk exists, one will be added automatically.
|
|
25
|
+
*
|
|
26
|
+
* @param text - The label text that may contain asterisk(s)
|
|
27
|
+
* @param required - Whether the field is required
|
|
28
|
+
* @returns A VNode with the text and wrapped asterisk, or the original text
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* wrapRequiredAsterisk('Email *', true) // Returns: <>Email <span className="dropin-label-required">*</span></>
|
|
32
|
+
* wrapRequiredAsterisk('Email', true) // Returns: <>Email <span className="dropin-label-required">*</span></>
|
|
33
|
+
* wrapRequiredAsterisk('Email *', false) // Returns: <>Email <span>*</span></>
|
|
34
|
+
* wrapRequiredAsterisk('Email', false) // Returns: 'Email'
|
|
35
|
+
*/
|
|
36
|
+
export const wrapRequiredAsterisk = (
|
|
37
|
+
text: string | undefined,
|
|
38
|
+
required?: boolean
|
|
39
|
+
): string | VNode | undefined => {
|
|
40
|
+
if (!text) return text;
|
|
41
|
+
|
|
42
|
+
// Match optional space followed by one or more asterisks at the end of the string
|
|
43
|
+
const asteriskPattern = /^(.+?)(\s*)(\*+)$/;
|
|
44
|
+
const match = text.match(asteriskPattern);
|
|
45
|
+
|
|
46
|
+
if (match) {
|
|
47
|
+
const [, textPart, space, asterisks] = match;
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
{textPart}
|
|
51
|
+
{space}
|
|
52
|
+
<span className={required ? 'dropin-label-required' : undefined}>
|
|
53
|
+
{asterisks}
|
|
54
|
+
</span>
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If required is true and no asterisk exists, add it
|
|
60
|
+
if (required) {
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
{text}{' '}
|
|
64
|
+
<span className="dropin-label-required">*</span>
|
|
65
|
+
</>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return text;
|
|
70
|
+
};
|