@licklist/design 0.78.12 → 0.78.15
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/bitbucket-pipelines.yml +1 -1
- package/dist/CustomDatePicker/CustomDatePicker.d.ts +10 -0
- package/dist/CustomDatePicker/CustomDatePicker.d.ts.map +1 -0
- package/dist/customRadioButton/RadioButton.d.ts +11 -0
- package/dist/customRadioButton/RadioButton.d.ts.map +1 -0
- package/dist/customRadioButton/RadioButton.js +93 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/sales/guest-profile/profile/Profile.d.ts.map +1 -1
- package/dist/sales/guest-profile/profile/Profile.js +2 -1
- package/package.json +1 -1
- package/src/CustomDatePicker/CustomDatePicker.tsx +258 -0
- package/src/customRadioButton/RadioButton.tsx +84 -0
- package/src/index.ts +1 -0
- package/src/sales/guest-profile/profile/Profile.tsx +2 -5
- package/dist/CustomAlertTypes/AlertBox.d.ts +0 -22
- package/dist/CustomAlertTypes/AlertBox.d.ts.map +0 -1
- package/dist/CustomAlertTypes/AlertRender.d.ts +0 -21
- package/dist/CustomAlertTypes/AlertRender.d.ts.map +0 -1
- package/dist/CustomAlertTypes/alertThemes.d.ts +0 -41
- package/dist/CustomAlertTypes/alertThemes.d.ts.map +0 -1
- package/dist/CustomAlertTypes/utils/textWrapperUtils.d.ts +0 -8
- package/dist/CustomAlertTypes/utils/textWrapperUtils.d.ts.map +0 -1
- package/src/CustomAlertTypes/AlertBox.tsx +0 -87
- package/src/CustomAlertTypes/AlertRender.ts +0 -283
- package/src/CustomAlertTypes/alertThemes.ts +0 -72
- package/src/CustomAlertTypes/utils/textWrapperUtils.ts +0 -26
- package/yarn.lock +0 -22280
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { createRoot } from "react-dom/client";
|
|
2
|
-
import { AlertRenderer } from './AlertRender';
|
|
3
|
-
import { alertThemes } from "./alertThemes";
|
|
4
|
-
|
|
5
|
-
export interface AlertConfig {
|
|
6
|
-
type: keyof typeof alertThemes;
|
|
7
|
-
title?: string;
|
|
8
|
-
subTitle?: string;
|
|
9
|
-
message?: string | string[];
|
|
10
|
-
description?: string;
|
|
11
|
-
actionText?: string;
|
|
12
|
-
secondaryActionText?: string;
|
|
13
|
-
onAction?: (() => void) | null;
|
|
14
|
-
onSecondaryAction?: (() => void) | null;
|
|
15
|
-
timeout?: number;
|
|
16
|
-
closable?: boolean;
|
|
17
|
-
titleColor?: string;
|
|
18
|
-
subTitleColor?: string;
|
|
19
|
-
showArrow?: boolean;
|
|
20
|
-
showSecondaryArrow?: boolean;
|
|
21
|
-
alignActionsRight?: boolean;
|
|
22
|
-
mount?: "container" | "global";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let container: HTMLDivElement | null = null;
|
|
26
|
-
let root: any = null;
|
|
27
|
-
|
|
28
|
-
function createContainer(mount: "container" | "global" = "global") {
|
|
29
|
-
if (container) return container;
|
|
30
|
-
container = document.createElement("div");
|
|
31
|
-
root = createRoot(container);
|
|
32
|
-
|
|
33
|
-
if (mount === "container") {
|
|
34
|
-
const containerFluid = document.querySelector(
|
|
35
|
-
".container-fluid"
|
|
36
|
-
) as HTMLDivElement | null;
|
|
37
|
-
|
|
38
|
-
if (containerFluid) {
|
|
39
|
-
container.style.cssText = `
|
|
40
|
-
width: 100%;
|
|
41
|
-
margin-bottom: 1rem;
|
|
42
|
-
pointer-events: auto;
|
|
43
|
-
`;
|
|
44
|
-
containerFluid.insertBefore(container, containerFluid.firstChild);
|
|
45
|
-
} else {
|
|
46
|
-
document.body.appendChild(container);
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
container.style.cssText = `
|
|
50
|
-
position: fixed;
|
|
51
|
-
top: 0;
|
|
52
|
-
left: 0;
|
|
53
|
-
right: 0;
|
|
54
|
-
z-index: 9999;
|
|
55
|
-
pointer-events: none;
|
|
56
|
-
`;
|
|
57
|
-
document.body.appendChild(container);
|
|
58
|
-
}
|
|
59
|
-
injectShrinkBarAnimation();
|
|
60
|
-
return container;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function injectShrinkBarAnimation() {
|
|
64
|
-
if (document.getElementById('shrinkBar-style')) return;
|
|
65
|
-
const style = document.createElement('style');
|
|
66
|
-
style.id = 'shrinkBar-style';
|
|
67
|
-
style.textContent = `
|
|
68
|
-
@keyframes shrinkBar {
|
|
69
|
-
from { width: 100%; }
|
|
70
|
-
to { width: 0%; }
|
|
71
|
-
}
|
|
72
|
-
`;
|
|
73
|
-
document.head.appendChild(style);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function showAlert(config: AlertConfig) {
|
|
77
|
-
createContainer(config.mount || "global");
|
|
78
|
-
const removeAlert = () => {
|
|
79
|
-
if (root) root.render(null);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
if (config.timeout && config.timeout > 0) {
|
|
83
|
-
setTimeout(removeAlert, config.timeout);
|
|
84
|
-
}
|
|
85
|
-
const alertBox = AlertRenderer.createAlert(config, removeAlert);
|
|
86
|
-
root.render(alertBox);
|
|
87
|
-
}
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { MdClose, MdArrowForward } from "react-icons/md";
|
|
3
|
-
import { alertThemes, commonStyle } from "./alertThemes";
|
|
4
|
-
import { wrapText } from "./utils/textWrapperUtils";
|
|
5
|
-
import { AlertConfig } from './AlertBox'
|
|
6
|
-
export class AlertRenderer {
|
|
7
|
-
static createAlert(config: AlertConfig, onClose: () => void) {
|
|
8
|
-
const theme = alertThemes[config.type];
|
|
9
|
-
|
|
10
|
-
return React.createElement(
|
|
11
|
-
"div",
|
|
12
|
-
{
|
|
13
|
-
style: {
|
|
14
|
-
backgroundColor: theme.bg,
|
|
15
|
-
border: theme.border,
|
|
16
|
-
borderRadius: commonStyle.borderRad,
|
|
17
|
-
padding: "16px 20px 0",
|
|
18
|
-
width: "100%",
|
|
19
|
-
maxWidth: "100%",
|
|
20
|
-
margin: "0 auto",
|
|
21
|
-
pointerEvents: "auto",
|
|
22
|
-
fontFamily: commonStyle.fontFamily,
|
|
23
|
-
position: "relative",
|
|
24
|
-
overflow: "hidden",
|
|
25
|
-
boxSizing: "border-box",
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
// HEADER ROW (icon + title + close button)
|
|
30
|
-
React.createElement(
|
|
31
|
-
"div",
|
|
32
|
-
{
|
|
33
|
-
style: {
|
|
34
|
-
display: "grid",
|
|
35
|
-
gridTemplateColumns: "20px 1fr auto", // icon | title | X
|
|
36
|
-
alignItems: "center",
|
|
37
|
-
columnGap: "12px",
|
|
38
|
-
marginBottom: "4px",
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
// Icon
|
|
43
|
-
React.createElement(theme.IconComponent, {
|
|
44
|
-
size: 20,
|
|
45
|
-
style: {
|
|
46
|
-
color: theme.icon,
|
|
47
|
-
gridColumn: "1 / 2",
|
|
48
|
-
gridRow: "1 / 2",
|
|
49
|
-
},
|
|
50
|
-
}),
|
|
51
|
-
|
|
52
|
-
// Title
|
|
53
|
-
React.createElement(
|
|
54
|
-
"h4",
|
|
55
|
-
{
|
|
56
|
-
style: {
|
|
57
|
-
gridColumn: "2 / 3",
|
|
58
|
-
gridRow: "1 / 2",
|
|
59
|
-
alignSelf: "center",
|
|
60
|
-
fontFamily: commonStyle.fontFamily,
|
|
61
|
-
fontSize: "16px",
|
|
62
|
-
fontWeight: 600,
|
|
63
|
-
lineHeight: "18px",
|
|
64
|
-
color: config.titleColor || commonStyle.fontFamily,
|
|
65
|
-
margin: 0,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
config.title || theme.defaultTitle
|
|
69
|
-
),
|
|
70
|
-
|
|
71
|
-
// Close Button
|
|
72
|
-
config.closable !== true &&
|
|
73
|
-
React.createElement(
|
|
74
|
-
"button",
|
|
75
|
-
{
|
|
76
|
-
style: {
|
|
77
|
-
gridColumn: "3 / 4",
|
|
78
|
-
gridRow: "1 / 2",
|
|
79
|
-
background: "none",
|
|
80
|
-
border: "none",
|
|
81
|
-
color: config.type === "info" ? "#1E3A8A" : theme.icon,
|
|
82
|
-
cursor: "pointer",
|
|
83
|
-
padding: 0,
|
|
84
|
-
lineHeight: 1,
|
|
85
|
-
display: "flex",
|
|
86
|
-
alignItems: "center",
|
|
87
|
-
},
|
|
88
|
-
onClick: onClose,
|
|
89
|
-
},
|
|
90
|
-
React.createElement(MdClose, { size: 20 })
|
|
91
|
-
)
|
|
92
|
-
),
|
|
93
|
-
|
|
94
|
-
// BODY (Subtitle, Message, Description, Actions)
|
|
95
|
-
React.createElement(
|
|
96
|
-
"div",
|
|
97
|
-
{
|
|
98
|
-
style: {
|
|
99
|
-
marginLeft: "32px", // aligns with title, not icon
|
|
100
|
-
marginBottom:
|
|
101
|
-
!config.message && !config.description && !config.actionText
|
|
102
|
-
? "12px"
|
|
103
|
-
: "0",
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
// Subtitle
|
|
108
|
-
config.subTitle &&
|
|
109
|
-
React.createElement(
|
|
110
|
-
"span",
|
|
111
|
-
{
|
|
112
|
-
style: {
|
|
113
|
-
fontFamily: "Geist, system-ui, sans-serif",
|
|
114
|
-
fontSize: "16px",
|
|
115
|
-
fontWeight: 600,
|
|
116
|
-
lineHeight: "18px",
|
|
117
|
-
color: config.subTitleColor || commonStyle.color,
|
|
118
|
-
display: "block",
|
|
119
|
-
marginBottom: "4px",
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
config.subTitle
|
|
123
|
-
),
|
|
124
|
-
|
|
125
|
-
// Message
|
|
126
|
-
config.message &&
|
|
127
|
-
(Array.isArray(config.message)
|
|
128
|
-
? React.createElement(
|
|
129
|
-
"ul",
|
|
130
|
-
{
|
|
131
|
-
style: {
|
|
132
|
-
margin: "0 0 8px 0",
|
|
133
|
-
paddingLeft: "20px",
|
|
134
|
-
fontFamily: commonStyle.fontFamily,
|
|
135
|
-
fontSize: "15px",
|
|
136
|
-
fontWeight: 400,
|
|
137
|
-
lineHeight: "20px",
|
|
138
|
-
color: commonStyle.color,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
config.message.map((line, idx) =>
|
|
142
|
-
React.createElement(
|
|
143
|
-
"li",
|
|
144
|
-
{
|
|
145
|
-
key: idx,
|
|
146
|
-
style: {
|
|
147
|
-
fontSize: "15px",
|
|
148
|
-
fontWeight: 400,
|
|
149
|
-
lineHeight: "20px",
|
|
150
|
-
fontFamily: "Geist, system-ui, sans-serif",
|
|
151
|
-
color: commonStyle.color,
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
line
|
|
155
|
-
)
|
|
156
|
-
)
|
|
157
|
-
)
|
|
158
|
-
: React.createElement(
|
|
159
|
-
"p",
|
|
160
|
-
{
|
|
161
|
-
style: {
|
|
162
|
-
fontFamily: commonStyle.fontFamily,
|
|
163
|
-
fontSize: "15px",
|
|
164
|
-
fontWeight: 400,
|
|
165
|
-
lineHeight: "20px",
|
|
166
|
-
color: commonStyle.color,
|
|
167
|
-
margin: "0 0 8px 0",
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
config.message
|
|
171
|
-
)),
|
|
172
|
-
|
|
173
|
-
// Description
|
|
174
|
-
config.description &&
|
|
175
|
-
React.createElement(
|
|
176
|
-
"p",
|
|
177
|
-
{
|
|
178
|
-
style: {
|
|
179
|
-
fontFamily: commonStyle.fontFamily,
|
|
180
|
-
fontSize: "15px",
|
|
181
|
-
fontWeight: 400,
|
|
182
|
-
lineHeight: "20px",
|
|
183
|
-
color: commonStyle.color,
|
|
184
|
-
margin: "0 0 12px 0",
|
|
185
|
-
whiteSpace: "pre-line",
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
wrapText(config.description, 150)
|
|
189
|
-
),
|
|
190
|
-
|
|
191
|
-
// Actions
|
|
192
|
-
(config.actionText || config.secondaryActionText) &&
|
|
193
|
-
React.createElement(
|
|
194
|
-
"div",
|
|
195
|
-
{
|
|
196
|
-
style: {
|
|
197
|
-
display: "flex",
|
|
198
|
-
flexDirection: "row",
|
|
199
|
-
gap: "16px",
|
|
200
|
-
marginTop: "6px",
|
|
201
|
-
justifyContent: config.alignActionsRight
|
|
202
|
-
? "flex-end"
|
|
203
|
-
: "flex-start",
|
|
204
|
-
marginBottom: "8px",
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
// Primary Action
|
|
209
|
-
config.actionText &&
|
|
210
|
-
React.createElement(
|
|
211
|
-
"button",
|
|
212
|
-
{
|
|
213
|
-
style: {
|
|
214
|
-
fontFamily: commonStyle.fontFamily,
|
|
215
|
-
fontSize: "15px",
|
|
216
|
-
fontWeight: 600,
|
|
217
|
-
lineHeight: "20px",
|
|
218
|
-
color: commonStyle.color,
|
|
219
|
-
background: "none",
|
|
220
|
-
border: "none",
|
|
221
|
-
padding: 0,
|
|
222
|
-
cursor: "pointer",
|
|
223
|
-
display: "flex",
|
|
224
|
-
alignItems: "center",
|
|
225
|
-
gap: "4px",
|
|
226
|
-
},
|
|
227
|
-
onClick: () => {
|
|
228
|
-
if (config.onAction) config.onAction();
|
|
229
|
-
onClose();
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
config.actionText,
|
|
233
|
-
config.showArrow &&
|
|
234
|
-
React.createElement(MdArrowForward, { size: 16 })
|
|
235
|
-
),
|
|
236
|
-
|
|
237
|
-
// Secondary Action
|
|
238
|
-
config.secondaryActionText &&
|
|
239
|
-
React.createElement(
|
|
240
|
-
"button",
|
|
241
|
-
{
|
|
242
|
-
style: {
|
|
243
|
-
fontFamily: commonStyle.fontFamily,
|
|
244
|
-
fontSize: "15px",
|
|
245
|
-
fontWeight: 600,
|
|
246
|
-
lineHeight: "20px",
|
|
247
|
-
color: commonStyle.color,
|
|
248
|
-
background: "none",
|
|
249
|
-
border: "none",
|
|
250
|
-
padding: 0,
|
|
251
|
-
cursor: "pointer",
|
|
252
|
-
display: "flex",
|
|
253
|
-
alignItems: "center",
|
|
254
|
-
gap: "4px",
|
|
255
|
-
},
|
|
256
|
-
onClick: () => {
|
|
257
|
-
if (config.onSecondaryAction) config.onSecondaryAction();
|
|
258
|
-
onClose();
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
config.secondaryActionText,
|
|
262
|
-
config.showSecondaryArrow &&
|
|
263
|
-
React.createElement(MdArrowForward, { size: 16 })
|
|
264
|
-
)
|
|
265
|
-
)
|
|
266
|
-
),
|
|
267
|
-
|
|
268
|
-
// Progress Bar
|
|
269
|
-
config.timeout &&
|
|
270
|
-
React.createElement("div", {
|
|
271
|
-
style: {
|
|
272
|
-
position: "absolute",
|
|
273
|
-
bottom: 0,
|
|
274
|
-
left: 0,
|
|
275
|
-
height: "4px",
|
|
276
|
-
backgroundColor: theme.icon,
|
|
277
|
-
width: "100%",
|
|
278
|
-
animation: `shrinkBar ${config.timeout}ms linear forwards`,
|
|
279
|
-
},
|
|
280
|
-
})
|
|
281
|
-
);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
// Factory for simple SVG icon components
|
|
4
|
-
function createSvgIcon(pathD: string, fillColor: string) {
|
|
5
|
-
return () =>
|
|
6
|
-
React.createElement(
|
|
7
|
-
"svg",
|
|
8
|
-
{
|
|
9
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
10
|
-
width: 32,
|
|
11
|
-
height: 32,
|
|
12
|
-
viewBox: "0 0 32 32",
|
|
13
|
-
},
|
|
14
|
-
React.createElement("path", { d: pathD, fill: fillColor })
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Each icon path (different geometry and colors)
|
|
19
|
-
const iconInfoPath =
|
|
20
|
-
'M16 7C20.9706 7 25 11.0294 25 16C25 20.9706 20.9706 25 16 25C11.0294 25 7 20.9706 7 16C7 11.0294 11.0294 7 16 7ZM16 14C15.4477 14 15 14.4477 15 15V20C15 20.5523 15.4477 21 16 21C16.5523 21 17 20.5523 17 20V15C17 14.4477 16.5523 14 16 14ZM16 11C15.4477 11 15 11.4477 15 12C15 12.5523 15.4477 13 16 13C16.5523 13 17 12.5523 17 12C17 11.4477 16.5523 11 16 11Z';
|
|
21
|
-
|
|
22
|
-
const warningIconPath =
|
|
23
|
-
'M15.3496 8.46973C15.7414 7.84329 16.6543 7.84314 17.0459 8.46973L25.2412 21.583C25.6574 22.249 25.1788 23.113 24.3936 23.1133H8.00195C7.21654 23.1133 6.73711 22.249 7.15332 21.583L15.3496 8.46973ZM16.1973 19.1133C15.6451 19.1134 15.1973 19.5611 15.1973 20.1133C15.1973 20.6654 15.6451 21.1132 16.1973 21.1133C16.7495 21.1133 17.1972 20.6655 17.1973 20.1133C17.1973 19.561 16.7496 19.1133 16.1973 19.1133ZM15.1973 18.1133H17.1973V13.1133H15.1973V18.1133Z';
|
|
24
|
-
|
|
25
|
-
const errorIconPath =
|
|
26
|
-
'M16.1975 7C21.1681 7 25.1975 11.0294 25.1975 16C25.1975 20.9706 21.1681 25 16.1975 25C11.2269 25 7.19751 20.9706 7.19751 16C7.19751 11.0294 11.2269 7 16.1975 7ZM16.1975 14.5859L13.3694 11.7578L11.9553 13.1719L14.7834 16L11.9553 18.8281L13.3694 20.2422L16.1975 17.4141L19.0256 20.2422L20.4397 18.8281L17.6116 16L20.4397 13.1719L19.0256 11.7578L16.1975 14.5859Z';
|
|
27
|
-
|
|
28
|
-
const successIconPath =
|
|
29
|
-
'M16 7C20.9706 7 25 11.0294 25 16C25 20.9706 20.9706 25 16 25C11.0294 25 7 20.9706 7 16C7 11.0294 11.0294 7 16 7ZM14.4463 17.6055L12.7217 15.8076L11.2783 17.1924L14.3525 20.3945L21.6729 13.7402L20.3271 12.2598L14.4463 17.6055Z';
|
|
30
|
-
// Specific icons with unique fills
|
|
31
|
-
export const ErrorIcon = createSvgIcon(errorIconPath, "#E0423A"); // red
|
|
32
|
-
export const SuccessIcon = createSvgIcon(successIconPath, "#52C22B"); // green
|
|
33
|
-
export const InfoIcon = createSvgIcon(iconInfoPath, "#0E8CE2"); // blue
|
|
34
|
-
export const WarningIcon = createSvgIcon(warningIconPath, "#E2A50C"); // yellow
|
|
35
|
-
|
|
36
|
-
export const commonStyle = {
|
|
37
|
-
fontFamily: 'Geist, system-ui, sans-serif',
|
|
38
|
-
color: '#14215A',
|
|
39
|
-
borderRad: '8px',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export const alertThemes = {
|
|
44
|
-
error: {
|
|
45
|
-
bg: "#FCECEB",
|
|
46
|
-
border: "2px solid #F5C4C2",
|
|
47
|
-
icon: "#E0423A",
|
|
48
|
-
IconComponent: ErrorIcon,
|
|
49
|
-
defaultTitle: "Error!",
|
|
50
|
-
},
|
|
51
|
-
success: {
|
|
52
|
-
bg: "#EEF9EA",
|
|
53
|
-
border: "2px solid #C9ECBD",
|
|
54
|
-
icon: "#52C22B",
|
|
55
|
-
IconComponent: SuccessIcon,
|
|
56
|
-
defaultTitle: "Success!",
|
|
57
|
-
},
|
|
58
|
-
warning: {
|
|
59
|
-
bg: "#FCF6E7",
|
|
60
|
-
border: "2px solid #F2D68F",
|
|
61
|
-
icon: "#E2A50C",
|
|
62
|
-
IconComponent: WarningIcon,
|
|
63
|
-
defaultTitle: "Warning!",
|
|
64
|
-
},
|
|
65
|
-
info: {
|
|
66
|
-
bg: "#E7F4FC",
|
|
67
|
-
border: "2px solid #B4DBF6",
|
|
68
|
-
icon: "#0E8CE2",
|
|
69
|
-
IconComponent: InfoIcon,
|
|
70
|
-
defaultTitle: "Info",
|
|
71
|
-
},
|
|
72
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps text into multiple lines by word count limit.
|
|
3
|
-
* @param text - The input string
|
|
4
|
-
* @param limit - Max characters per line
|
|
5
|
-
* @returns Wrapped text as a single string with newlines
|
|
6
|
-
*/
|
|
7
|
-
export function wrapText(text: string, limit: number): string {
|
|
8
|
-
const words = text.split(' ');
|
|
9
|
-
let lines: string[] = [];
|
|
10
|
-
let currentLine = '';
|
|
11
|
-
|
|
12
|
-
words.forEach((word) => {
|
|
13
|
-
if ((currentLine + word).length >= limit) {
|
|
14
|
-
lines.push(currentLine.trim());
|
|
15
|
-
currentLine = word + ' ';
|
|
16
|
-
} else {
|
|
17
|
-
currentLine += word + ' ';
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
if (currentLine.trim() !== '') {
|
|
22
|
-
lines.push(currentLine.trim());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return lines.join('\n');
|
|
26
|
-
}
|