ndcloud-storybook 1.2.1 → 1.2.2-beta.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.
- package/dist/index.cjs +465 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -1
- package/dist/index.d.ts +102 -1
- package/dist/index.js +452 -62
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import { keyframes, css } from '@emotion/react';
|
|
2
|
-
import
|
|
2
|
+
import styled16 from '@emotion/styled';
|
|
3
3
|
import { jsx, jsxs, Fragment } from '@emotion/react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
// src/atoms/Button/Button.tsx
|
|
6
|
-
var spin = keyframes`
|
|
7
|
-
from { transform: rotate(0deg); }
|
|
8
|
-
to { transform: rotate(360deg); }
|
|
9
|
-
`;
|
|
10
|
-
var Wrapper = styled.div`
|
|
11
|
-
display: inline-flex;
|
|
12
|
-
align-items: center;
|
|
13
|
-
justify-content: center;
|
|
14
|
-
|
|
15
|
-
svg {
|
|
16
|
-
width: ${({ size = 20 }) => size}px;
|
|
17
|
-
height: ${({ size = 20 }) => size}px;
|
|
18
|
-
animation: ${spin} ${({ speed = "0.75s" }) => speed} linear infinite;
|
|
19
|
-
transform-origin: center;
|
|
20
|
-
}
|
|
21
|
-
`;
|
|
22
6
|
var Spinner = ({
|
|
23
7
|
size = 20,
|
|
24
8
|
speed = "0.75s",
|
|
@@ -47,6 +31,22 @@ var Spinner = ({
|
|
|
47
31
|
}
|
|
48
32
|
) });
|
|
49
33
|
var Spinner_default = Spinner;
|
|
34
|
+
var spin = keyframes`
|
|
35
|
+
from { transform: rotate(0deg); }
|
|
36
|
+
to { transform: rotate(360deg); }
|
|
37
|
+
`;
|
|
38
|
+
var Wrapper = styled16.div`
|
|
39
|
+
display: inline-flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
|
|
43
|
+
svg {
|
|
44
|
+
width: ${({ size = 20 }) => size}px;
|
|
45
|
+
height: ${({ size = 20 }) => size}px;
|
|
46
|
+
animation: ${spin} ${({ speed = "0.75s" }) => speed} linear infinite;
|
|
47
|
+
transform-origin: center;
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
50
|
|
|
51
51
|
// src/tokens/colors.ts
|
|
52
52
|
var colors = {
|
|
@@ -55,6 +55,7 @@ var colors = {
|
|
|
55
55
|
// Brand
|
|
56
56
|
primaryGreen: "#7EE896",
|
|
57
57
|
primaryPurple: "#6D65DA",
|
|
58
|
+
primaryBlue: "#55A3BD",
|
|
58
59
|
// Palette
|
|
59
60
|
darkBlue1: "#12131B",
|
|
60
61
|
darkBlue2: "#2A2B33",
|
|
@@ -130,6 +131,17 @@ var FONT_SIZE_KEYS = {
|
|
|
130
131
|
xl: "xl",
|
|
131
132
|
"2xl": "2xl"
|
|
132
133
|
};
|
|
134
|
+
|
|
135
|
+
// src/utils/colorHelpers.ts
|
|
136
|
+
function getOpacity(hexColor, opacity) {
|
|
137
|
+
const hex = hexColor.trim().replace(/^#/, "");
|
|
138
|
+
if (!/^[\da-fA-F]{6}$/.test(hex)) {
|
|
139
|
+
throw new Error(`Invalid hex color: ${hexColor}`);
|
|
140
|
+
}
|
|
141
|
+
const opacityFraction = Math.round(opacity / 100 * 255);
|
|
142
|
+
const alphaHex = opacityFraction.toString(16).padStart(2, "0");
|
|
143
|
+
return `#${hex}${alphaHex}`;
|
|
144
|
+
}
|
|
133
145
|
var Variant = /* @__PURE__ */ ((Variant2) => {
|
|
134
146
|
Variant2["Primary"] = "primary";
|
|
135
147
|
Variant2["Secondary"] = "secondary";
|
|
@@ -147,11 +159,35 @@ var VARIANTS = {
|
|
|
147
159
|
},
|
|
148
160
|
outline: {
|
|
149
161
|
background: colors.backgrounds.transparent,
|
|
150
|
-
border:
|
|
151
|
-
color:
|
|
162
|
+
border: `1px solid ${getOpacity(colors.baseColors.grey2, 10)}`,
|
|
163
|
+
color: getOpacity(colors.baseColors.darkBlue3, 85)
|
|
152
164
|
}
|
|
153
165
|
};
|
|
154
|
-
var
|
|
166
|
+
var Button = ({
|
|
167
|
+
label,
|
|
168
|
+
icon,
|
|
169
|
+
loading,
|
|
170
|
+
disabled,
|
|
171
|
+
className,
|
|
172
|
+
variant = "primary",
|
|
173
|
+
selected,
|
|
174
|
+
...rest
|
|
175
|
+
}) => /* @__PURE__ */ jsx(
|
|
176
|
+
StyledButton,
|
|
177
|
+
{
|
|
178
|
+
variant,
|
|
179
|
+
disabled: disabled || loading,
|
|
180
|
+
selected,
|
|
181
|
+
className,
|
|
182
|
+
...rest,
|
|
183
|
+
children: loading ? /* @__PURE__ */ jsx(Spinner_default, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
184
|
+
icon && /* @__PURE__ */ jsx("span", { children: icon }),
|
|
185
|
+
label
|
|
186
|
+
] })
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
var Button_default = Button;
|
|
190
|
+
var StyledButton = styled16.button`
|
|
155
191
|
display: flex;
|
|
156
192
|
align-items: center;
|
|
157
193
|
justify-content: center;
|
|
@@ -181,46 +217,12 @@ var StyledButton = styled.button`
|
|
|
181
217
|
pointer-events: ${disabled ? "none" : "auto"};
|
|
182
218
|
|
|
183
219
|
&:focus-visible {
|
|
184
|
-
outline: 2px solid
|
|
220
|
+
outline: 2px solid ${colors.baseColors.primaryBlue};
|
|
185
221
|
outline-offset: 2px;
|
|
186
222
|
}
|
|
187
223
|
`;
|
|
188
224
|
}}
|
|
189
225
|
`;
|
|
190
|
-
var Button = ({
|
|
191
|
-
label,
|
|
192
|
-
icon,
|
|
193
|
-
loading,
|
|
194
|
-
disabled,
|
|
195
|
-
className,
|
|
196
|
-
...rest
|
|
197
|
-
}) => /* @__PURE__ */ jsx(
|
|
198
|
-
StyledButton,
|
|
199
|
-
{
|
|
200
|
-
label: "",
|
|
201
|
-
disabled: disabled || loading,
|
|
202
|
-
className,
|
|
203
|
-
...rest,
|
|
204
|
-
children: loading ? /* @__PURE__ */ jsx(Spinner_default, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
205
|
-
icon && /* @__PURE__ */ jsx("span", { children: icon }),
|
|
206
|
-
label
|
|
207
|
-
] })
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
var Button_default = Button;
|
|
211
|
-
|
|
212
|
-
// src/utils/colorHelpers.ts
|
|
213
|
-
function getOpacity(hexColor, opacity) {
|
|
214
|
-
const hex = hexColor.trim().replace(/^#/, "");
|
|
215
|
-
if (!/^[\da-fA-F]{6}$/.test(hex)) {
|
|
216
|
-
throw new Error(`Invalid hex color: ${hexColor}`);
|
|
217
|
-
}
|
|
218
|
-
const opacityFraction = Math.round(opacity / 100 * 255);
|
|
219
|
-
const alphaHex = opacityFraction.toString(16).padStart(2, "0");
|
|
220
|
-
return `#${hex}${alphaHex}`;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// src/atoms/shared/inputStyles.ts
|
|
224
226
|
var defaultPadding = "9px 17px";
|
|
225
227
|
var focusedPadding = "8px 16px";
|
|
226
228
|
var baseInputStyles = css`
|
|
@@ -280,7 +282,7 @@ var Input = ({ className, error, warning, ...rest }) => {
|
|
|
280
282
|
return /* @__PURE__ */ jsx(StyledInput, { className, error, warning, ...rest });
|
|
281
283
|
};
|
|
282
284
|
var Input_default = Input;
|
|
283
|
-
var StyledInput =
|
|
285
|
+
var StyledInput = styled16.input`
|
|
284
286
|
${baseInputStyles}
|
|
285
287
|
|
|
286
288
|
${({ error }) => error && errorStyles}
|
|
@@ -294,7 +296,7 @@ var Textarea = ({ className, error, warning, ...rest }) => {
|
|
|
294
296
|
return /* @__PURE__ */ jsx(StyledTextarea, { className, error, warning, ...rest });
|
|
295
297
|
};
|
|
296
298
|
var Textarea_default = Textarea;
|
|
297
|
-
var StyledTextarea =
|
|
299
|
+
var StyledTextarea = styled16.textarea`
|
|
298
300
|
${baseInputStyles}
|
|
299
301
|
resize: vertical;
|
|
300
302
|
min-height: 80px;
|
|
@@ -322,7 +324,7 @@ var Tab = ({
|
|
|
322
324
|
);
|
|
323
325
|
};
|
|
324
326
|
var Tab_default = Tab;
|
|
325
|
-
var StyledTab =
|
|
327
|
+
var StyledTab = styled16.div`
|
|
326
328
|
display: inline-block;
|
|
327
329
|
padding: 8px 16px;
|
|
328
330
|
user-select: none;
|
|
@@ -343,7 +345,7 @@ var StyledTab = styled.div`
|
|
|
343
345
|
}
|
|
344
346
|
`}
|
|
345
347
|
`;
|
|
346
|
-
var HelperText =
|
|
348
|
+
var HelperText = styled16.div`
|
|
347
349
|
margin-top: 4px;
|
|
348
350
|
font-size: ${typography.fontSize.xs}px;
|
|
349
351
|
color: ${({ error, warning }) => {
|
|
@@ -352,6 +354,94 @@ var HelperText = styled.div`
|
|
|
352
354
|
return colors.baseColors.grey3;
|
|
353
355
|
}};
|
|
354
356
|
`;
|
|
357
|
+
var USER_ROLES = {
|
|
358
|
+
OWNER: "owner",
|
|
359
|
+
EDITOR: "editor",
|
|
360
|
+
VIEWER: "viewer",
|
|
361
|
+
AUDITOR: "auditor"
|
|
362
|
+
};
|
|
363
|
+
var USER_STATUS = {
|
|
364
|
+
INVITED: "invited"
|
|
365
|
+
};
|
|
366
|
+
var getBadgeColor = (role, status) => {
|
|
367
|
+
if (status?.toLowerCase() === USER_STATUS.INVITED) {
|
|
368
|
+
return colors.accents.warning;
|
|
369
|
+
}
|
|
370
|
+
const roleLower = role.toLowerCase();
|
|
371
|
+
switch (roleLower) {
|
|
372
|
+
case USER_ROLES.OWNER:
|
|
373
|
+
return colors.baseColors.primaryGreen;
|
|
374
|
+
case USER_ROLES.EDITOR:
|
|
375
|
+
return colors.baseColors.primaryBlue;
|
|
376
|
+
case USER_ROLES.VIEWER:
|
|
377
|
+
case USER_ROLES.AUDITOR:
|
|
378
|
+
return colors.baseColors.primaryPurple;
|
|
379
|
+
default:
|
|
380
|
+
return colors.baseColors.primaryGreen;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
function GroupBadge({ role, status, children }) {
|
|
384
|
+
const badgeColor = getBadgeColor(role, status);
|
|
385
|
+
const displayText = status?.toLowerCase() === USER_STATUS.INVITED ? "Invited" : children;
|
|
386
|
+
return /* @__PURE__ */ jsx(Badge, { badgeColor, children: displayText });
|
|
387
|
+
}
|
|
388
|
+
var Badge = styled16.div`
|
|
389
|
+
display: inline-flex;
|
|
390
|
+
padding: 8px 28px;
|
|
391
|
+
border-radius: 100px;
|
|
392
|
+
background-color: ${({ badgeColor }) => getOpacity(badgeColor, 20)};
|
|
393
|
+
border: 1px solid ${({ badgeColor }) => badgeColor};
|
|
394
|
+
color: ${({ badgeColor }) => badgeColor};
|
|
395
|
+
font-size: ${FONT_SIZES.s}px;
|
|
396
|
+
font-weight: ${FONT_WEIGHTS.bold};
|
|
397
|
+
text-transform: capitalize;
|
|
398
|
+
`;
|
|
399
|
+
var Badge_default = GroupBadge;
|
|
400
|
+
function UserAvatar({
|
|
401
|
+
initials,
|
|
402
|
+
badgeColor,
|
|
403
|
+
onClick,
|
|
404
|
+
size = 56
|
|
405
|
+
}) {
|
|
406
|
+
if (!initials || !initials.trim()) {
|
|
407
|
+
return null;
|
|
408
|
+
}
|
|
409
|
+
if (onClick) {
|
|
410
|
+
return /* @__PURE__ */ jsx(
|
|
411
|
+
ProfileAvatar,
|
|
412
|
+
{
|
|
413
|
+
badgeColor,
|
|
414
|
+
size,
|
|
415
|
+
onClick,
|
|
416
|
+
children: initials
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
return /* @__PURE__ */ jsx(ColourAvatar, { badgeColor, size, children: initials });
|
|
421
|
+
}
|
|
422
|
+
var UserAvatar_default = UserAvatar;
|
|
423
|
+
var ColourAvatar = styled16.div`
|
|
424
|
+
width: ${({ size }) => typeof size === "number" ? `${size}px` : size === "large" ? "56px" : "40px"};
|
|
425
|
+
height: ${({ size }) => typeof size === "number" ? `${size}px` : size === "large" ? "56px" : "40px"};
|
|
426
|
+
border-radius: 50%;
|
|
427
|
+
background: ${({ badgeColor }) => badgeColor ? getOpacity(badgeColor, 20) : "linear-gradient(90deg, #6d65da 0.08%, #55a3bd 68.44%)"};
|
|
428
|
+
border: ${({ badgeColor }) => badgeColor ? `2px solid ${badgeColor}` : "none"};
|
|
429
|
+
display: flex;
|
|
430
|
+
align-items: center;
|
|
431
|
+
justify-content: center;
|
|
432
|
+
color: ${colors.baseColors.darkBlue1};
|
|
433
|
+
font-size: ${({ size }) => typeof size === "number" ? `${size * 0.325}px` : size === "large" ? `${FONT_SIZES.xs}px` : `${FONT_SIZES.s}px`};
|
|
434
|
+
font-weight: ${FONT_WEIGHTS.normal};
|
|
435
|
+
flex-shrink: 0;
|
|
436
|
+
`;
|
|
437
|
+
var ProfileAvatar = styled16(ColourAvatar)`
|
|
438
|
+
color: #fff;
|
|
439
|
+
background: ${colors.gradients.gradient1};
|
|
440
|
+
border: none;
|
|
441
|
+
border-radius: 999px;
|
|
442
|
+
line-height: 138%;
|
|
443
|
+
margin-bottom: 12px;
|
|
444
|
+
`;
|
|
355
445
|
var FormField = ({
|
|
356
446
|
id,
|
|
357
447
|
label,
|
|
@@ -389,7 +479,7 @@ var FormField = ({
|
|
|
389
479
|
displayText && /* @__PURE__ */ jsx(HelperText, { error: hasError, warning: hasWarning, children: displayText })
|
|
390
480
|
] });
|
|
391
481
|
};
|
|
392
|
-
var FormFieldWrapper =
|
|
482
|
+
var FormFieldWrapper = styled16.div`
|
|
393
483
|
display: flex;
|
|
394
484
|
flex-direction: column;
|
|
395
485
|
|
|
@@ -437,7 +527,7 @@ var FormFieldTextarea = ({
|
|
|
437
527
|
displayText && /* @__PURE__ */ jsx(HelperText, { error: hasError, warning: hasWarning, children: displayText })
|
|
438
528
|
] });
|
|
439
529
|
};
|
|
440
|
-
var FormFieldWrapper2 =
|
|
530
|
+
var FormFieldWrapper2 = styled16.div`
|
|
441
531
|
display: flex;
|
|
442
532
|
flex-direction: column;
|
|
443
533
|
|
|
@@ -448,7 +538,307 @@ var FormFieldWrapper2 = styled.div`
|
|
|
448
538
|
}
|
|
449
539
|
`;
|
|
450
540
|
var FormFieldTextarea_default = FormFieldTextarea;
|
|
541
|
+
var SearchContainer = styled16.div`
|
|
542
|
+
width: ${({ width }) => typeof width === "number" ? `${width}px` : width || "208px"};
|
|
543
|
+
`;
|
|
544
|
+
var InputWrapper = styled16.div`
|
|
545
|
+
position: relative;
|
|
546
|
+
width: 100%;
|
|
547
|
+
display: flex;
|
|
548
|
+
align-items: center;
|
|
549
|
+
`;
|
|
550
|
+
var IconWrapper = styled16.div`
|
|
551
|
+
position: absolute;
|
|
552
|
+
left: 17px;
|
|
553
|
+
top: 50%;
|
|
554
|
+
transform: translateY(-50%);
|
|
555
|
+
display: flex;
|
|
556
|
+
align-items: center;
|
|
557
|
+
justify-content: center;
|
|
558
|
+
color: ${colors.baseColors.grey3};
|
|
559
|
+
pointer-events: none;
|
|
560
|
+
z-index: 2;
|
|
561
|
+
`;
|
|
562
|
+
var StyledInput2 = styled16(Input_default)`
|
|
563
|
+
width: 100%;
|
|
564
|
+
padding-right: ${({ hasClearButton }) => hasClearButton ? "32px" : "17px"};
|
|
565
|
+
padding-left: ${({ hasIcon }) => hasIcon ? "44px" : "17px"};
|
|
566
|
+
font-size: ${({ fontSize = "s" }) => `${typography.fontSize[fontSize]}px`};
|
|
567
|
+
position: relative;
|
|
568
|
+
z-index: 1;
|
|
569
|
+
|
|
570
|
+
&:focus {
|
|
571
|
+
padding-left: ${({ hasIcon }) => hasIcon ? "43px" : "16px"};
|
|
572
|
+
}
|
|
573
|
+
`;
|
|
574
|
+
var ClearButton = styled16.button`
|
|
575
|
+
position: absolute;
|
|
576
|
+
right: 8px;
|
|
577
|
+
top: 50%;
|
|
578
|
+
transform: translateY(-50%);
|
|
579
|
+
background: none;
|
|
580
|
+
border: none;
|
|
581
|
+
cursor: pointer;
|
|
582
|
+
padding: 4px;
|
|
583
|
+
display: flex;
|
|
584
|
+
align-items: center;
|
|
585
|
+
justify-content: center;
|
|
586
|
+
color: ${colors.baseColors.grey3};
|
|
587
|
+
transition: color 0.2s ease;
|
|
588
|
+
z-index: 3;
|
|
589
|
+
|
|
590
|
+
&:hover {
|
|
591
|
+
color: ${colors.baseColors.grey1};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
&:focus {
|
|
595
|
+
outline: 2px solid ${colors.baseColors.primaryPurple};
|
|
596
|
+
outline-offset: 2px;
|
|
597
|
+
border-radius: 4px;
|
|
598
|
+
}
|
|
599
|
+
`;
|
|
600
|
+
var ClearIcon = styled16.svg`
|
|
601
|
+
width: 16px;
|
|
602
|
+
height: 16px;
|
|
603
|
+
stroke-width: 2;
|
|
604
|
+
stroke-linecap: round;
|
|
605
|
+
stroke-linejoin: round;
|
|
606
|
+
`;
|
|
607
|
+
function SearchInput({
|
|
608
|
+
value,
|
|
609
|
+
onChange,
|
|
610
|
+
placeholder = "Search...",
|
|
611
|
+
showClearButton = false,
|
|
612
|
+
icon,
|
|
613
|
+
width = "208px",
|
|
614
|
+
fontSize = "s"
|
|
615
|
+
}) {
|
|
616
|
+
const handleChange = (e) => {
|
|
617
|
+
onChange(e.target.value);
|
|
618
|
+
};
|
|
619
|
+
const handleClear = () => {
|
|
620
|
+
onChange("");
|
|
621
|
+
};
|
|
622
|
+
const hasClearButton = showClearButton && !!value;
|
|
623
|
+
const hasIcon = !!icon;
|
|
624
|
+
return /* @__PURE__ */ jsx(SearchContainer, { width, children: /* @__PURE__ */ jsxs(InputWrapper, { children: [
|
|
625
|
+
hasIcon && /* @__PURE__ */ jsx(IconWrapper, { children: icon }),
|
|
626
|
+
/* @__PURE__ */ jsx(
|
|
627
|
+
StyledInput2,
|
|
628
|
+
{
|
|
629
|
+
type: "text",
|
|
630
|
+
placeholder,
|
|
631
|
+
value,
|
|
632
|
+
onChange: handleChange,
|
|
633
|
+
autoComplete: "off",
|
|
634
|
+
hasClearButton,
|
|
635
|
+
hasIcon,
|
|
636
|
+
fontSize
|
|
637
|
+
}
|
|
638
|
+
),
|
|
639
|
+
hasClearButton && /* @__PURE__ */ jsx(ClearButton, { onClick: handleClear, type: "button", "aria-label": "Clear search", children: /* @__PURE__ */ jsxs(ClearIcon, { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", children: [
|
|
640
|
+
/* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
641
|
+
/* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
642
|
+
] }) })
|
|
643
|
+
] }) });
|
|
644
|
+
}
|
|
645
|
+
var SearchInput_default = SearchInput;
|
|
646
|
+
function TableElement({ children, ...rest }) {
|
|
647
|
+
return /* @__PURE__ */ jsx(StyledTable, { ...rest, children });
|
|
648
|
+
}
|
|
649
|
+
var Table_default = TableElement;
|
|
650
|
+
var StyledTable = styled16.table`
|
|
651
|
+
width: 100%;
|
|
652
|
+
border-collapse: separate;
|
|
653
|
+
border-spacing: 0 4px;
|
|
654
|
+
`;
|
|
655
|
+
function TableHeader({ alignRight, children, ...rest }) {
|
|
656
|
+
return /* @__PURE__ */ jsx(StyledTableHeader, { alignRight, ...rest, children });
|
|
657
|
+
}
|
|
658
|
+
var TableHeader_default = TableHeader;
|
|
659
|
+
var StyledTableHeader = styled16.th`
|
|
660
|
+
padding-bottom: 12px;
|
|
661
|
+
text-align: ${({ alignRight }) => alignRight ? "right" : "left"};
|
|
662
|
+
font-size: ${FONT_SIZES.xs}px;
|
|
663
|
+
font-weight: ${FONT_WEIGHTS.bold};
|
|
664
|
+
padding-left: ${({ alignRight }) => alignRight ? "0" : "24px"};
|
|
665
|
+
padding-right: ${({ alignRight }) => alignRight ? "60px" : "0"};
|
|
666
|
+
`;
|
|
667
|
+
function TableCell({ children, colSpan, ...rest }) {
|
|
668
|
+
return /* @__PURE__ */ jsx(StyledTableCell, { colSpan, ...rest, children });
|
|
669
|
+
}
|
|
670
|
+
var TableCell_default = TableCell;
|
|
671
|
+
var StyledTableCell = styled16.td`
|
|
672
|
+
|
|
673
|
+
`;
|
|
674
|
+
function TableRow({ children, ...rest }) {
|
|
675
|
+
return /* @__PURE__ */ jsx(StyledTableRow, { ...rest, children });
|
|
676
|
+
}
|
|
677
|
+
var TableRow_default = TableRow;
|
|
678
|
+
var StyledTableRow = styled16.tr`
|
|
679
|
+
/* Base row styling */
|
|
680
|
+
`;
|
|
681
|
+
var TableRowWrapper = styled16.div`
|
|
682
|
+
border-radius: 6px;
|
|
683
|
+
border: 1px solid ${colors.baseColors.grey7};
|
|
684
|
+
display: flex;
|
|
685
|
+
align-items: center;
|
|
686
|
+
justify-content: space-between;
|
|
687
|
+
padding: 12px 24px;
|
|
688
|
+
`;
|
|
689
|
+
var CheckboxWrapper = styled16.div`
|
|
690
|
+
display: flex;
|
|
691
|
+
align-items: center;
|
|
692
|
+
`;
|
|
693
|
+
var ActionsWrapper = styled16.div`
|
|
694
|
+
display: flex;
|
|
695
|
+
align-items: center;
|
|
696
|
+
justify-content: flex-end;
|
|
697
|
+
`;
|
|
698
|
+
var AlignedTableCell = styled16(TableCell_default)`
|
|
699
|
+
padding-top: 12px;
|
|
700
|
+
padding-bottom: 12px;
|
|
701
|
+
padding-left: ${({ alignRight }) => alignRight ? "0" : "24px"};
|
|
702
|
+
padding-right: ${({ alignRight }) => alignRight ? "60px" : "0"};
|
|
703
|
+
text-align: ${({ alignRight }) => alignRight ? "right" : "left"};
|
|
704
|
+
border: 1px solid ${colors.baseColors.grey7};
|
|
705
|
+
border-right: ${({ isLast }) => isLast ? `1px solid ${colors.baseColors.grey7}` : "none"};
|
|
706
|
+
border-left: ${({ isFirst }) => isFirst ? `1px solid ${colors.baseColors.grey7}` : "none"};
|
|
707
|
+
${({ isFirst }) => isFirst && `border-top-left-radius: 6px; border-bottom-left-radius: 6px;`}
|
|
708
|
+
${({ isLast }) => isLast && `border-top-right-radius: 6px; border-bottom-right-radius: 6px;`}
|
|
709
|
+
`;
|
|
710
|
+
var CellContent = styled16.div`
|
|
711
|
+
display: flex;
|
|
712
|
+
align-items: center;
|
|
713
|
+
justify-content: ${({ alignRight }) => alignRight ? "flex-end" : "flex-start"};
|
|
714
|
+
flex: ${({ alignRight }) => alignRight ? "0 0 auto" : "1"};
|
|
715
|
+
min-width: 0;
|
|
716
|
+
`;
|
|
717
|
+
var TableWrapper = styled16.div`
|
|
718
|
+
margin-top: 32px;
|
|
719
|
+
`;
|
|
720
|
+
var EmptyState = styled16.div`
|
|
721
|
+
padding: 24px;
|
|
722
|
+
text-align: center;
|
|
723
|
+
display: flex;
|
|
724
|
+
flex-direction: column;
|
|
725
|
+
gap: 8px;
|
|
726
|
+
`;
|
|
727
|
+
var EmptyHeader = styled16.div`
|
|
728
|
+
font-size: 26px;
|
|
729
|
+
font-weight: 700;
|
|
730
|
+
color: ${colors.baseColors.darkBlue1};
|
|
731
|
+
`;
|
|
732
|
+
var EmptySubheader = styled16.div`
|
|
733
|
+
font-size: 12px;
|
|
734
|
+
font-weight: 500;
|
|
735
|
+
color: ${colors.baseColors.grey3};
|
|
736
|
+
`;
|
|
737
|
+
function getCellContent(column, row, rowIndex) {
|
|
738
|
+
if (column.renderCell) {
|
|
739
|
+
return column.renderCell(row, rowIndex);
|
|
740
|
+
}
|
|
741
|
+
if (column.accessor) {
|
|
742
|
+
if (typeof column.accessor === "function") {
|
|
743
|
+
return column.accessor(row);
|
|
744
|
+
}
|
|
745
|
+
return String(row[column.accessor] ?? "");
|
|
746
|
+
}
|
|
747
|
+
return null;
|
|
748
|
+
}
|
|
749
|
+
function getTotalColumns(columns, showCheckboxes, renderActions) {
|
|
750
|
+
return columns.length + (showCheckboxes ? 1 : 0) + (renderActions ? 1 : 0);
|
|
751
|
+
}
|
|
752
|
+
function Table({
|
|
753
|
+
data,
|
|
754
|
+
columns,
|
|
755
|
+
getRowKey,
|
|
756
|
+
emptyMessage,
|
|
757
|
+
emptyHeader,
|
|
758
|
+
emptySubheader,
|
|
759
|
+
showCheckboxes = false,
|
|
760
|
+
onSelectAll,
|
|
761
|
+
onSelectRow,
|
|
762
|
+
selectedRows = /* @__PURE__ */ new Set(),
|
|
763
|
+
renderActions,
|
|
764
|
+
rowLayout = "aligned"
|
|
765
|
+
}) {
|
|
766
|
+
const getKey = getRowKey || ((row, index) => index);
|
|
767
|
+
const allSelected = data.length > 0 && data.every((row, idx) => selectedRows.has(getKey(row, idx)));
|
|
768
|
+
const someSelected = data.some((row, idx) => selectedRows.has(getKey(row, idx)));
|
|
769
|
+
const totalColumns = getTotalColumns(columns, showCheckboxes, renderActions);
|
|
770
|
+
const handleSelectAll = (e) => {
|
|
771
|
+
onSelectAll?.(e.target.checked);
|
|
772
|
+
};
|
|
773
|
+
const handleSelectRow = (row, e) => {
|
|
774
|
+
onSelectRow?.(row, e.target.checked);
|
|
775
|
+
};
|
|
776
|
+
return /* @__PURE__ */ jsx(TableWrapper, { children: /* @__PURE__ */ jsxs(Table_default, { children: [
|
|
777
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs(TableRow_default, { children: [
|
|
778
|
+
showCheckboxes && /* @__PURE__ */ jsx(TableHeader_default, { children: /* @__PURE__ */ jsx(
|
|
779
|
+
"input",
|
|
780
|
+
{
|
|
781
|
+
type: "checkbox",
|
|
782
|
+
checked: allSelected,
|
|
783
|
+
ref: (input) => {
|
|
784
|
+
if (input) input.indeterminate = someSelected && !allSelected;
|
|
785
|
+
},
|
|
786
|
+
onChange: handleSelectAll,
|
|
787
|
+
"aria-label": "Select all rows"
|
|
788
|
+
}
|
|
789
|
+
) }),
|
|
790
|
+
columns.map((column, index) => /* @__PURE__ */ jsx(TableHeader_default, { alignRight: column.alignRight, children: column.label }, index)),
|
|
791
|
+
renderActions && /* @__PURE__ */ jsx(TableHeader_default, { alignRight: true, children: " " })
|
|
792
|
+
] }) }),
|
|
793
|
+
/* @__PURE__ */ jsx("tbody", { children: data.length === 0 ? /* @__PURE__ */ jsx(TableRow_default, { children: /* @__PURE__ */ jsx(TableCell_default, { colSpan: totalColumns, children: /* @__PURE__ */ jsx(EmptyState, { children: emptyHeader ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
794
|
+
/* @__PURE__ */ jsx(EmptyHeader, { children: emptyHeader }),
|
|
795
|
+
emptySubheader && /* @__PURE__ */ jsx(EmptySubheader, { children: emptySubheader })
|
|
796
|
+
] }) : /* @__PURE__ */ jsx("div", { children: emptyMessage || "No data found" }) }) }) }) : data.map((row, rowIndex) => {
|
|
797
|
+
const rowKey = getKey(row, rowIndex);
|
|
798
|
+
const isSelected = selectedRows.has(rowKey);
|
|
799
|
+
if (rowLayout === "spaced") {
|
|
800
|
+
return /* @__PURE__ */ jsx(TableRow_default, { children: /* @__PURE__ */ jsx(TableCell_default, { colSpan: totalColumns, children: /* @__PURE__ */ jsxs(TableRowWrapper, { children: [
|
|
801
|
+
showCheckboxes && /* @__PURE__ */ jsx(CheckboxWrapper, { children: /* @__PURE__ */ jsx(
|
|
802
|
+
"input",
|
|
803
|
+
{
|
|
804
|
+
type: "checkbox",
|
|
805
|
+
checked: isSelected,
|
|
806
|
+
onChange: (e) => handleSelectRow(row, e),
|
|
807
|
+
"aria-label": `Select row ${rowIndex + 1}`
|
|
808
|
+
}
|
|
809
|
+
) }),
|
|
810
|
+
columns.map((column, colIndex) => {
|
|
811
|
+
const cellContent = getCellContent(column, row, rowIndex);
|
|
812
|
+
const isLast = colIndex === columns.length - 1 && !renderActions;
|
|
813
|
+
return /* @__PURE__ */ jsx(CellContent, { alignRight: column.alignRight, isLast, children: cellContent }, colIndex);
|
|
814
|
+
}),
|
|
815
|
+
renderActions && /* @__PURE__ */ jsx(ActionsWrapper, { children: renderActions(row, rowIndex) })
|
|
816
|
+
] }) }) }, rowKey);
|
|
817
|
+
} else {
|
|
818
|
+
return /* @__PURE__ */ jsxs(TableRow_default, { children: [
|
|
819
|
+
showCheckboxes && /* @__PURE__ */ jsx(AlignedTableCell, { isFirst: true, isLast: totalColumns === 1, children: /* @__PURE__ */ jsx(
|
|
820
|
+
"input",
|
|
821
|
+
{
|
|
822
|
+
type: "checkbox",
|
|
823
|
+
checked: isSelected,
|
|
824
|
+
onChange: (e) => handleSelectRow(row, e),
|
|
825
|
+
"aria-label": `Select row ${rowIndex + 1}`
|
|
826
|
+
}
|
|
827
|
+
) }),
|
|
828
|
+
columns.map((column, colIndex) => {
|
|
829
|
+
const cellContent = getCellContent(column, row, rowIndex);
|
|
830
|
+
const isFirst = !showCheckboxes && colIndex === 0;
|
|
831
|
+
const isLast = !renderActions && colIndex === columns.length - 1;
|
|
832
|
+
return /* @__PURE__ */ jsx(AlignedTableCell, { alignRight: column.alignRight, isFirst, isLast, children: cellContent }, colIndex);
|
|
833
|
+
}),
|
|
834
|
+
renderActions && /* @__PURE__ */ jsx(AlignedTableCell, { alignRight: true, isLast: true, children: renderActions(row, rowIndex) })
|
|
835
|
+
] }, rowKey);
|
|
836
|
+
}
|
|
837
|
+
}) })
|
|
838
|
+
] }) });
|
|
839
|
+
}
|
|
840
|
+
var DataTable_default = Table;
|
|
451
841
|
|
|
452
|
-
export { Button_default as Button, FONT_SIZES, FONT_SIZE_KEYS, FONT_WEIGHTS, FormField_default as FormField, FormFieldTextarea_default as FormFieldTextarea, HelperText, Input_default as Input, Label_default as Label, Tab_default as Tab, Textarea_default as Textarea, Variant, colors, getOpacity, typography };
|
|
842
|
+
export { Badge_default as Badge, Button_default as Button, FONT_SIZES, FONT_SIZE_KEYS, FONT_WEIGHTS, FormField_default as FormField, FormFieldTextarea_default as FormFieldTextarea, GroupBadge, HelperText, Input_default as Input, Label_default as Label, SearchInput_default as SearchInput, Tab_default as Tab, DataTable_default as Table, TableCell_default as TableCell, Table_default as TableElement, TableHeader_default as TableHeader, TableRow_default as TableRow, TableRowWrapper, Textarea_default as Textarea, USER_ROLES, USER_STATUS, UserAvatar_default as UserAvatar, Variant, colors, getBadgeColor, getOpacity, typography };
|
|
453
843
|
//# sourceMappingURL=index.js.map
|
|
454
844
|
//# sourceMappingURL=index.js.map
|