@krak-stack/registry 0.8.3 → 0.9.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/CHANGELOG.md +10 -5
- package/dist/components/ui/animated-list.js +5 -0
- package/dist/components/ui/app-switcher.d.ts +2 -1
- package/dist/components/ui/app-switcher.js +5 -1
- package/dist/components/ui/async-action-button.d.ts +2 -1
- package/dist/components/ui/async-action-button.js +3 -1
- package/dist/components/ui/bulk-list-input.d.ts +2 -1
- package/dist/components/ui/bulk-list-input.js +6 -1
- package/dist/components/ui/calendar.d.ts +10 -0
- package/dist/components/ui/choice-cards.d.ts +1 -0
- package/dist/components/ui/choice-cards.js +7 -1
- package/dist/components/ui/color-picker.d.ts +2 -1
- package/dist/components/ui/color-picker.js +4 -1
- package/dist/components/ui/cron-expression-editor.d.ts +3 -1
- package/dist/components/ui/cron-expression-editor.js +13 -3
- package/dist/components/ui/danger-confirmation.d.ts +1 -0
- package/dist/components/ui/danger-confirmation.js +5 -1
- package/dist/components/ui/date-picker.d.ts +33 -0
- package/dist/components/ui/date-picker.js +470 -0
- package/dist/components/ui/date-picker.schema.d.ts +9 -0
- package/dist/components/ui/editable-text.js +8 -1
- package/dist/components/ui/form.d.ts +5 -5
- package/dist/components/ui/image-crop-editor.js +10 -1
- package/dist/components/ui/phone-number-input.d.ts +3 -1
- package/dist/components/ui/phone-number-input.js +53 -13
- package/dist/components/ui/phone-number-input.schema.d.ts +7 -0
- package/dist/components/ui/{copy-value.d.ts → secret-value.d.ts} +4 -6
- package/dist/components/ui/secret-value.js +222 -0
- package/dist/components/ui/select-with-custom-input.d.ts +36 -0
- package/dist/components/ui/select-with-custom-input.js +275 -0
- package/dist/components/ui/sidebar-layout.js +1 -0
- package/dist/components/ui/stepper.js +8 -0
- package/dist/components/ui/timezone-select.d.ts +2 -1
- package/dist/components/ui/timezone-select.js +5 -1
- package/dist/components/ui/toast.d.ts +18 -0
- package/dist/components/ui/toast.js +121 -0
- package/dist/components/ui/unsaved-changes-guard.d.ts +2 -1
- package/dist/components/ui/unsaved-changes-guard.js +4 -1
- package/dist/components/ui/upload-attachment.js +3 -0
- package/dist/lib/docs.js +1 -0
- package/package.json +19 -5
- package/dist/components/ui/copy-value.js +0 -319
|
@@ -16,5 +16,7 @@ export type PhoneNumberInputProps = Omit<ComponentProps<typeof Input>, "value" |
|
|
|
16
16
|
locale?: string;
|
|
17
17
|
label?: string;
|
|
18
18
|
withExtension?: boolean;
|
|
19
|
+
containerClassName?: string;
|
|
20
|
+
contentClassName?: string;
|
|
19
21
|
};
|
|
20
|
-
export declare const PhoneNumberInput: ({ value, country, onCountryChange, onValueChange, countries, locale, label, id, onBlur, name, withExtension, onKeyDown, ...props }: PhoneNumberInputProps) => import("react").JSX.Element;
|
|
22
|
+
export declare const PhoneNumberInput: ({ value, country, onCountryChange, onValueChange, countries, locale, label, id, onBlur, name, withExtension, onKeyDown, className, containerClassName, contentClassName, ...props }: PhoneNumberInputProps) => import("react").JSX.Element;
|
|
@@ -3,8 +3,8 @@ import { useId, useLayoutEffect, useRef as useRef2 } from "react";
|
|
|
3
3
|
import {
|
|
4
4
|
getCountries,
|
|
5
5
|
AsYouType,
|
|
6
|
-
getCountryCallingCode,
|
|
7
|
-
parsePhoneNumberFromString
|
|
6
|
+
getCountryCallingCode as getCountryCallingCode2,
|
|
7
|
+
parsePhoneNumberFromString as parsePhoneNumberFromString2
|
|
8
8
|
} from "libphonenumber-js/max";
|
|
9
9
|
|
|
10
10
|
// ../../src/components/ui/input.tsx
|
|
@@ -446,13 +446,36 @@ function VirtualizedCombobox(props) {
|
|
|
446
446
|
|
|
447
447
|
// ../../src/components/ui/phone-number-input.tsx
|
|
448
448
|
import { ChevronsUpDown as ChevronsUpDown2 } from "lucide-react";
|
|
449
|
+
|
|
450
|
+
// ../../src/components/ui/phone-number-input.schema.ts
|
|
451
|
+
import { Schema } from "effect";
|
|
452
|
+
import {
|
|
453
|
+
getCountryCallingCode,
|
|
454
|
+
parsePhoneNumberFromString
|
|
455
|
+
} from "libphonenumber-js/max";
|
|
456
|
+
var E164DigitsSchema = Schema.String.check(Schema.isPattern(/^\d*$/), Schema.isMaxLength(15)).annotate({ identifier: "E164Digits" });
|
|
457
|
+
var getPhoneNumberDigits = (value, country) => {
|
|
458
|
+
if (!value)
|
|
459
|
+
return "";
|
|
460
|
+
const parsed = parsePhoneNumberFromString(value, {
|
|
461
|
+
defaultCountry: country,
|
|
462
|
+
extract: false
|
|
463
|
+
});
|
|
464
|
+
if (parsed)
|
|
465
|
+
return parsed.number.slice(1);
|
|
466
|
+
const digits = value.replace(/(?:ext\.?|x|#|;ext=)\s*\d+\s*$/i, "").replace(/\D/g, "");
|
|
467
|
+
return value.trimStart().startsWith("+") ? digits : `${getCountryCallingCode(country)}${digits}`;
|
|
468
|
+
};
|
|
469
|
+
var fitsE164DigitLimit = (value, country) => Schema.is(E164DigitsSchema)(getPhoneNumberDigits(value, country));
|
|
470
|
+
|
|
471
|
+
// ../../src/components/ui/phone-number-input.tsx
|
|
449
472
|
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
450
473
|
var normalizePhoneNumber = (value, country) => {
|
|
451
|
-
const phone =
|
|
474
|
+
const phone = parsePhoneNumberFromString2(value, {
|
|
452
475
|
defaultCountry: country,
|
|
453
476
|
extract: false
|
|
454
477
|
});
|
|
455
|
-
return phone?.isValid() ? {
|
|
478
|
+
return phone?.isValid() && fitsE164DigitLimit(value, country) ? {
|
|
456
479
|
e164: phone.number,
|
|
457
480
|
extension: phone.ext ?? null,
|
|
458
481
|
country: phone.country ?? null
|
|
@@ -471,6 +494,9 @@ var PhoneNumberInput = ({
|
|
|
471
494
|
name,
|
|
472
495
|
withExtension = false,
|
|
473
496
|
onKeyDown,
|
|
497
|
+
className,
|
|
498
|
+
containerClassName,
|
|
499
|
+
contentClassName,
|
|
474
500
|
...props
|
|
475
501
|
}) => {
|
|
476
502
|
const generatedId = useId();
|
|
@@ -480,11 +506,11 @@ var PhoneNumberInput = ({
|
|
|
480
506
|
const names = new Intl.DisplayNames([language], { type: "region" });
|
|
481
507
|
const options = [...new Set([country, ...countries])].sort((a, b) => (names.of(a) ?? a).localeCompare(names.of(b) ?? b, language));
|
|
482
508
|
const valid = normalizePhoneNumber(value, country);
|
|
483
|
-
const parsed =
|
|
509
|
+
const parsed = parsePhoneNumberFromString2(value, {
|
|
484
510
|
defaultCountry: country,
|
|
485
511
|
extract: false
|
|
486
512
|
});
|
|
487
|
-
const callingCode = value.trim().startsWith("+") ? parsed?.countryCallingCode ??
|
|
513
|
+
const callingCode = value.trim().startsWith("+") ? parsed?.countryCallingCode ?? getCountryCallingCode2(country) : getCountryCallingCode2(country);
|
|
488
514
|
const nationalDraft = value.trim().startsWith(`+${callingCode}`) ? value.trim().slice(callingCode.length + 1).trimStart() : value;
|
|
489
515
|
const extension = parsed?.ext ?? "";
|
|
490
516
|
const nationalDigits = (extension ? nationalDraft.replace(/(?:ext\.?|x|#|;ext=)\s*\d+\s*$/i, "") : nationalDraft).replace(/\D/g, "");
|
|
@@ -508,17 +534,23 @@ var PhoneNumberInput = ({
|
|
|
508
534
|
const emitNational = (draft, nextExtension = extension) => {
|
|
509
535
|
const digits = draft.replace(/\D/g, "");
|
|
510
536
|
const next = digits ? `+${callingCode} ${digits}${nextExtension ? ` ext. ${nextExtension}` : ""}` : "";
|
|
537
|
+
if (!fitsE164DigitLimit(next, country)) {
|
|
538
|
+
pendingCaret.current = null;
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
511
541
|
onValueChange(next, normalizePhoneNumber(next, country));
|
|
512
542
|
};
|
|
513
543
|
const countryLabel = french ? "Pays du numéro" : "Phone country";
|
|
514
544
|
const items = options.map((code) => ({
|
|
515
545
|
value: code,
|
|
516
|
-
label: `${names.of(code)} (${code}) +${
|
|
546
|
+
label: `${names.of(code)} (${code}) +${getCountryCallingCode2(code)}`
|
|
517
547
|
}));
|
|
518
548
|
return /* @__PURE__ */ jsxs2("div", {
|
|
519
|
-
|
|
549
|
+
"data-slot": "phone-number-input",
|
|
550
|
+
className: cn("grid gap-2", containerClassName),
|
|
520
551
|
children: [
|
|
521
552
|
/* @__PURE__ */ jsx5("label", {
|
|
553
|
+
"data-slot": "phone-number-label",
|
|
522
554
|
htmlFor: inputId,
|
|
523
555
|
className: "text-sm font-medium",
|
|
524
556
|
children: label ?? (french ? "Numéro de téléphone" : "Phone number")
|
|
@@ -530,6 +562,7 @@ var PhoneNumberInput = ({
|
|
|
530
562
|
disabled: props.disabled
|
|
531
563
|
}) : null,
|
|
532
564
|
/* @__PURE__ */ jsxs2("div", {
|
|
565
|
+
"data-slot": "phone-number-controls",
|
|
533
566
|
className: "flex min-w-0 gap-2",
|
|
534
567
|
children: [
|
|
535
568
|
/* @__PURE__ */ jsx5(VirtualizedCombobox, {
|
|
@@ -539,7 +572,7 @@ var PhoneNumberInput = ({
|
|
|
539
572
|
value: items.find((item) => item.value === country) ?? null,
|
|
540
573
|
placeholder: country,
|
|
541
574
|
emptyLabel: french ? "Aucun pays correspondant." : "No matching countries.",
|
|
542
|
-
contentClassName: "w-72! max-w-[calc(100vw-2rem)]!",
|
|
575
|
+
contentClassName: cn("w-72! max-w-[calc(100vw-2rem)]!", contentClassName),
|
|
543
576
|
disabled: props.disabled || props.readOnly,
|
|
544
577
|
trigger: /* @__PURE__ */ jsxs2(Button, {
|
|
545
578
|
type: "button",
|
|
@@ -568,25 +601,28 @@ var PhoneNumberInput = ({
|
|
|
568
601
|
const selected = options.find((option) => option === item?.value);
|
|
569
602
|
if (!selected || selected === country)
|
|
570
603
|
return;
|
|
604
|
+
const next = nationalDigits ? `+${getCountryCallingCode2(selected)} ${nationalDigits}${extension ? ` ext. ${extension}` : ""}` : "";
|
|
605
|
+
if (!fitsE164DigitLimit(next, selected))
|
|
606
|
+
return;
|
|
571
607
|
onCountryChange(selected);
|
|
572
|
-
const next = nationalDigits ? `+${getCountryCallingCode(selected)} ${nationalDigits}${extension ? ` ext. ${extension}` : ""}` : "";
|
|
573
608
|
onValueChange(next, normalizePhoneNumber(next, selected));
|
|
574
609
|
}
|
|
575
610
|
}),
|
|
576
611
|
/* @__PURE__ */ jsx5(Input, {
|
|
577
612
|
...props,
|
|
613
|
+
"data-component": "phone-number-national",
|
|
578
614
|
id: inputId,
|
|
579
615
|
type: "tel",
|
|
580
616
|
inputMode: "numeric",
|
|
581
617
|
autoComplete: props.autoComplete ?? "tel-national",
|
|
582
|
-
className: "min-w-0 flex-1",
|
|
618
|
+
className: cn("min-w-0 flex-1", className),
|
|
583
619
|
value: nationalValue,
|
|
584
620
|
"aria-invalid": Boolean(value) && !valid,
|
|
585
621
|
"aria-describedby": `${inputId}-status ${props["aria-describedby"] ?? ""}`,
|
|
586
622
|
onChange: (event) => {
|
|
587
623
|
const draft = event.target.value;
|
|
588
624
|
const international = draft.trimStart().startsWith("+");
|
|
589
|
-
const pasted =
|
|
625
|
+
const pasted = parsePhoneNumberFromString2(draft, {
|
|
590
626
|
defaultCountry: country,
|
|
591
627
|
extract: false
|
|
592
628
|
});
|
|
@@ -600,6 +636,8 @@ var PhoneNumberInput = ({
|
|
|
600
636
|
}
|
|
601
637
|
const digits = draft.replace(/\D/g, "");
|
|
602
638
|
const next = pasted?.isValid() ? `${pasted.number}${pasted.ext ? ` ext. ${pasted.ext}` : ""}` : digits ? `${international ? "+" : `+${callingCode} `}${digits}` : "";
|
|
639
|
+
if (!fitsE164DigitLimit(next, country))
|
|
640
|
+
return;
|
|
603
641
|
const details = normalizePhoneNumber(next, country);
|
|
604
642
|
if (international && details?.country && options.includes(details.country) && details.country !== country)
|
|
605
643
|
onCountryChange(details.country);
|
|
@@ -637,7 +675,7 @@ var PhoneNumberInput = ({
|
|
|
637
675
|
},
|
|
638
676
|
onBlur: (event) => {
|
|
639
677
|
if (!props.readOnly && !props.disabled && valid) {
|
|
640
|
-
const formatted =
|
|
678
|
+
const formatted = parsePhoneNumberFromString2(value, {
|
|
641
679
|
defaultCountry: country,
|
|
642
680
|
extract: false
|
|
643
681
|
})?.formatInternational();
|
|
@@ -650,6 +688,7 @@ var PhoneNumberInput = ({
|
|
|
650
688
|
]
|
|
651
689
|
}),
|
|
652
690
|
withExtension || extension ? /* @__PURE__ */ jsxs2("div", {
|
|
691
|
+
"data-slot": "phone-number-extension",
|
|
653
692
|
className: "grid max-w-32 gap-1.5",
|
|
654
693
|
children: [
|
|
655
694
|
/* @__PURE__ */ jsx5("label", {
|
|
@@ -669,6 +708,7 @@ var PhoneNumberInput = ({
|
|
|
669
708
|
]
|
|
670
709
|
}) : null,
|
|
671
710
|
/* @__PURE__ */ jsx5("p", {
|
|
711
|
+
"data-slot": "phone-number-status",
|
|
672
712
|
id: `${inputId}-status`,
|
|
673
713
|
className: "text-muted-foreground text-xs",
|
|
674
714
|
children: valid ? `${valid.e164}${valid.extension ? ` ext. ${valid.extension}` : ""}` : french ? "Saisissez un numéro complet. La validation ne vérifie pas son propriétaire." : "Enter a complete number. Validation does not verify ownership."
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { type CountryCode } from "libphonenumber-js/max";
|
|
3
|
+
/** ITU-T E.164: up to 15 digits, including the country calling code, excluding extensions. */
|
|
4
|
+
export declare const E164DigitsSchema: Schema.String;
|
|
5
|
+
/** Use the parser’s national-prefix normalization when available, even for incomplete/invalid numbers. */
|
|
6
|
+
export declare const getPhoneNumberDigits: (value: string, country: CountryCode) => string;
|
|
7
|
+
export declare const fitsE164DigitLimit: (value: string, country: CountryCode) => boolean;
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import { type CopyButtonMessageTranslations } from "./copy-button.js";
|
|
2
|
-
export type
|
|
2
|
+
export type SecretValueMessages = {
|
|
3
3
|
show: string;
|
|
4
4
|
hide: string;
|
|
5
5
|
hidden: string;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type SecretValueProps = {
|
|
8
8
|
value: string;
|
|
9
9
|
label: string;
|
|
10
|
-
secret?: boolean;
|
|
11
|
-
variant?: "outline" | "ghost";
|
|
12
10
|
disabled?: boolean;
|
|
13
11
|
copyable?: boolean;
|
|
14
12
|
autoHideDelay?: number;
|
|
15
13
|
className?: string;
|
|
16
14
|
locale?: string;
|
|
17
|
-
messages?: Partial<Record<string, Partial<
|
|
15
|
+
messages?: Partial<Record<string, Partial<SecretValueMessages>>>;
|
|
18
16
|
copyMessages?: CopyButtonMessageTranslations;
|
|
19
17
|
};
|
|
20
18
|
/** Masking is presentation, not a security boundary. Never logs the value. */
|
|
21
|
-
export declare const
|
|
19
|
+
export declare const SecretValue: ({ value, label, disabled, copyable, autoHideDelay, className, locale: override, messages, copyMessages, }: SecretValueProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// ../../src/components/ui/secret-value.tsx
|
|
2
|
+
import { Eye, EyeOff } from "lucide-react";
|
|
3
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
4
|
+
|
|
5
|
+
// ../../src/components/ui/button.tsx
|
|
6
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
7
|
+
import { cva } from "class-variance-authority";
|
|
8
|
+
|
|
9
|
+
// ../../src/lib/utils.ts
|
|
10
|
+
import { cn } from "cn";
|
|
11
|
+
|
|
12
|
+
// ../../src/components/ui/button.tsx
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
|
|
15
|
+
variants: {
|
|
16
|
+
variant: {
|
|
17
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
18
|
+
outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
19
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
20
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
21
|
+
destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
22
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
26
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
27
|
+
sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
|
|
28
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
29
|
+
icon: "size-9",
|
|
30
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
31
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
32
|
+
"icon-lg": "size-10"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
defaultVariants: {
|
|
36
|
+
variant: "default",
|
|
37
|
+
size: "default"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function Button({
|
|
41
|
+
className,
|
|
42
|
+
variant = "default",
|
|
43
|
+
size = "default",
|
|
44
|
+
...props
|
|
45
|
+
}) {
|
|
46
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
47
|
+
"data-slot": "button",
|
|
48
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
49
|
+
...props
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ../../src/components/ui/copy-button.tsx
|
|
54
|
+
import { Check, Copy, TriangleAlert } from "lucide-react";
|
|
55
|
+
import { useEffect, useRef, useState } from "react";
|
|
56
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
57
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
58
|
+
var messages = {
|
|
59
|
+
en: { copy: "Copy", copied: "Copied", copyFailed: "Copy failed" },
|
|
60
|
+
fr: { copy: "Copier", copied: "Copié", copyFailed: "Échec de la copie" }
|
|
61
|
+
};
|
|
62
|
+
var copyButtonMessages = (locale = "en", translations) => ({
|
|
63
|
+
...locale.startsWith("fr") ? messages.fr : messages.en,
|
|
64
|
+
...translations?.[locale.split("-")[0] ?? locale],
|
|
65
|
+
...translations?.[locale]
|
|
66
|
+
});
|
|
67
|
+
function CopyButton({
|
|
68
|
+
value,
|
|
69
|
+
valueDescription,
|
|
70
|
+
copyVariant = "default",
|
|
71
|
+
locale: localeOverride,
|
|
72
|
+
messages,
|
|
73
|
+
onCopied,
|
|
74
|
+
onCopyError,
|
|
75
|
+
resetDelay = 1500,
|
|
76
|
+
disabled,
|
|
77
|
+
size,
|
|
78
|
+
"aria-label": ariaLabel,
|
|
79
|
+
...props
|
|
80
|
+
}) {
|
|
81
|
+
const locale = useKrakstackLocale(localeOverride);
|
|
82
|
+
const [copyState, setCopyState] = useState("idle");
|
|
83
|
+
const copyTimeout = useRef(undefined);
|
|
84
|
+
const labels = copyButtonMessages(locale, messages);
|
|
85
|
+
const accessibleLabel = ariaLabel ?? (valueDescription ? `${labels.copy} ${valueDescription}` : labels.copy);
|
|
86
|
+
const isLarge = copyVariant === "large";
|
|
87
|
+
const defaultSize = copyVariant === "sm" ? "icon-xs" : isLarge ? "sm" : "icon-sm";
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
return () => {
|
|
90
|
+
if (copyTimeout.current)
|
|
91
|
+
clearTimeout(copyTimeout.current);
|
|
92
|
+
};
|
|
93
|
+
}, []);
|
|
94
|
+
const resetCopyState = () => {
|
|
95
|
+
if (copyTimeout.current)
|
|
96
|
+
clearTimeout(copyTimeout.current);
|
|
97
|
+
copyTimeout.current = setTimeout(() => setCopyState("idle"), resetDelay);
|
|
98
|
+
};
|
|
99
|
+
const copy = async () => {
|
|
100
|
+
try {
|
|
101
|
+
await navigator.clipboard.writeText(value);
|
|
102
|
+
setCopyState("copied");
|
|
103
|
+
onCopied?.();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
setCopyState("failed");
|
|
106
|
+
onCopyError?.(error instanceof Error ? error : new Error(labels.copyFailed, { cause: error }));
|
|
107
|
+
}
|
|
108
|
+
resetCopyState();
|
|
109
|
+
};
|
|
110
|
+
const status = copyState === "copied" ? valueDescription ? `${labels.copied}: ${valueDescription}` : labels.copied : copyState === "failed" ? valueDescription ? `${labels.copyFailed}: ${valueDescription}` : labels.copyFailed : "";
|
|
111
|
+
return /* @__PURE__ */ jsxs(Button, {
|
|
112
|
+
"aria-label": accessibleLabel,
|
|
113
|
+
disabled,
|
|
114
|
+
onClick: copy,
|
|
115
|
+
size: size ?? defaultSize,
|
|
116
|
+
...props,
|
|
117
|
+
children: [
|
|
118
|
+
/* @__PURE__ */ jsx2("span", {
|
|
119
|
+
"aria-live": "polite",
|
|
120
|
+
className: "sr-only",
|
|
121
|
+
role: "status",
|
|
122
|
+
children: status
|
|
123
|
+
}),
|
|
124
|
+
copyState === "copied" ? /* @__PURE__ */ jsx2(Check, {
|
|
125
|
+
"aria-hidden": "true"
|
|
126
|
+
}) : null,
|
|
127
|
+
copyState === "failed" ? /* @__PURE__ */ jsx2(TriangleAlert, {
|
|
128
|
+
"aria-hidden": "true"
|
|
129
|
+
}) : null,
|
|
130
|
+
copyState === "idle" ? /* @__PURE__ */ jsx2(Copy, {
|
|
131
|
+
"aria-hidden": "true"
|
|
132
|
+
}) : null,
|
|
133
|
+
isLarge ? /* @__PURE__ */ jsx2("span", {
|
|
134
|
+
children: labels.copy
|
|
135
|
+
}) : null
|
|
136
|
+
]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ../../src/components/ui/secret-value.tsx
|
|
141
|
+
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
142
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
143
|
+
var labels = {
|
|
144
|
+
en: { show: "Show", hide: "Hide", hidden: "Hidden value" },
|
|
145
|
+
fr: { show: "Afficher", hide: "Masquer", hidden: "Valeur masquée" }
|
|
146
|
+
};
|
|
147
|
+
var SecretValue = ({
|
|
148
|
+
value,
|
|
149
|
+
label,
|
|
150
|
+
disabled,
|
|
151
|
+
copyable = true,
|
|
152
|
+
autoHideDelay = 0,
|
|
153
|
+
className,
|
|
154
|
+
locale: override,
|
|
155
|
+
messages,
|
|
156
|
+
copyMessages
|
|
157
|
+
}) => {
|
|
158
|
+
const locale = useKrakstackLocale2(override);
|
|
159
|
+
const copy = {
|
|
160
|
+
...locale.startsWith("fr") ? labels.fr : labels.en,
|
|
161
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
162
|
+
...messages?.[locale]
|
|
163
|
+
};
|
|
164
|
+
const [revealedValue, setRevealedValue] = useState2(null);
|
|
165
|
+
const [previous, setPrevious] = useState2({ value, disabled });
|
|
166
|
+
if (previous.value !== value || previous.disabled !== disabled) {
|
|
167
|
+
setPrevious({ value, disabled });
|
|
168
|
+
setRevealedValue(null);
|
|
169
|
+
}
|
|
170
|
+
const revealed = !disabled && revealedValue === value;
|
|
171
|
+
useEffect2(() => {
|
|
172
|
+
if (!revealed || autoHideDelay <= 0)
|
|
173
|
+
return;
|
|
174
|
+
const timer = setTimeout(() => setRevealedValue(null), autoHideDelay);
|
|
175
|
+
return () => clearTimeout(timer);
|
|
176
|
+
}, [revealed, autoHideDelay, value]);
|
|
177
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
178
|
+
"data-slot": "secret-value",
|
|
179
|
+
"data-state": revealed ? "revealed" : "hidden",
|
|
180
|
+
"data-disabled": disabled || undefined,
|
|
181
|
+
className: cn("flex min-w-0 items-center gap-2", className),
|
|
182
|
+
children: [
|
|
183
|
+
/* @__PURE__ */ jsx3("code", {
|
|
184
|
+
"data-slot": "secret-value-content",
|
|
185
|
+
className: "min-w-0 flex-1 text-sm break-all",
|
|
186
|
+
"aria-label": revealed ? undefined : `${label}: ${copy.hidden}`,
|
|
187
|
+
children: revealed ? value : /* @__PURE__ */ jsx3("span", {
|
|
188
|
+
"aria-hidden": "true",
|
|
189
|
+
children: "••••••••"
|
|
190
|
+
})
|
|
191
|
+
}),
|
|
192
|
+
/* @__PURE__ */ jsx3(Button, {
|
|
193
|
+
"data-component": "secret-value-toggle",
|
|
194
|
+
type: "button",
|
|
195
|
+
size: "icon-sm",
|
|
196
|
+
variant: "ghost",
|
|
197
|
+
disabled,
|
|
198
|
+
"aria-label": `${revealed ? copy.hide : copy.show} ${label}`,
|
|
199
|
+
"aria-pressed": revealed,
|
|
200
|
+
onClick: () => setRevealedValue(revealed ? null : value),
|
|
201
|
+
children: revealed ? /* @__PURE__ */ jsx3(EyeOff, {
|
|
202
|
+
"aria-hidden": "true"
|
|
203
|
+
}) : /* @__PURE__ */ jsx3(Eye, {
|
|
204
|
+
"aria-hidden": "true"
|
|
205
|
+
})
|
|
206
|
+
}),
|
|
207
|
+
copyable ? /* @__PURE__ */ jsx3(CopyButton, {
|
|
208
|
+
"data-component": "secret-value-copy",
|
|
209
|
+
type: "button",
|
|
210
|
+
value,
|
|
211
|
+
valueDescription: label,
|
|
212
|
+
disabled,
|
|
213
|
+
variant: "ghost",
|
|
214
|
+
locale,
|
|
215
|
+
messages: copyMessages
|
|
216
|
+
}) : null
|
|
217
|
+
]
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
export {
|
|
221
|
+
SecretValue
|
|
222
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type SelectWithCustomInputOption = {
|
|
2
|
+
value: string;
|
|
3
|
+
label: string;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
input?: {
|
|
6
|
+
label: string;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
required?: boolean;
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export type SelectWithCustomInputValue = {
|
|
13
|
+
option: string;
|
|
14
|
+
customValue?: string;
|
|
15
|
+
};
|
|
16
|
+
export type SelectWithCustomInputProps = {
|
|
17
|
+
label: string;
|
|
18
|
+
options: readonly SelectWithCustomInputOption[];
|
|
19
|
+
value: SelectWithCustomInputValue | null;
|
|
20
|
+
onValueChange: (value: SelectWithCustomInputValue | null) => void;
|
|
21
|
+
name?: string;
|
|
22
|
+
customName?: string;
|
|
23
|
+
required?: boolean;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
readOnly?: boolean;
|
|
26
|
+
placeholder?: string;
|
|
27
|
+
description?: string;
|
|
28
|
+
error?: string;
|
|
29
|
+
locale?: string;
|
|
30
|
+
className?: string;
|
|
31
|
+
triggerClassName?: string;
|
|
32
|
+
contentClassName?: string;
|
|
33
|
+
inputClassName?: string;
|
|
34
|
+
};
|
|
35
|
+
/** Option identifiers and custom text stay separate; the host owns the option catalog. */
|
|
36
|
+
export declare const SelectWithCustomInput: ({ label, options, value, onValueChange, name, customName, required, disabled, readOnly, placeholder, description, error, locale, className, triggerClassName, contentClassName, inputClassName, }: SelectWithCustomInputProps) => import("react").JSX.Element;
|