@syscore/ui-library 2.0.0-beta-publish-workflow-beta.16 → 2.0.0-beta-publish-workflow-beta.17
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/client/components/icons/IconUtility.tsx +353 -0
- package/client/components/icons/X.tsx +4 -3
- package/client/components/ui/alert-v02.tsx +2 -6
- package/client/components/ui/button-v01.tsx +2 -12
- package/client/components/ui/button.tsx +39 -3
- package/client/components/ui/dropdown.tsx +2 -12
- package/client/components/ui/navigation.tsx +25 -4
- package/client/components/ui/radio-v01.tsx +84 -0
- package/client/components/ui/search-field-v01.tsx +10 -28
- package/client/components/ui/section-heading.tsx +1 -1
- package/client/components/ui/sign-in-field-v01.tsx +150 -0
- package/client/global.css +354 -73
- package/client/lib/system-icons.ts +1583 -0
- package/client/lib/utility-icons.ts +121 -0
- package/client/ui/Button.stories.tsx +63 -0
- package/client/ui/Colors.stories.tsx +34 -31
- package/client/ui/Icons.stories.tsx +179 -0
- package/client/ui/RadioGroup/RadioGroup.stories.tsx +1 -1
- package/client/ui/RadioV01/RadioV01.stories.tsx +136 -0
- package/client/ui/SearchField/SearchField.stories.tsx +4 -1
- package/client/ui/TextAreaV01/TextAreaV01.stories.tsx +23 -2
- package/client/ui/TextFieldV01/PasswordFieldV01.stories.tsx +25 -11
- package/client/ui/TextFieldV01/SignInFieldV01.stories.tsx +196 -0
- package/dist/client/assets/alert/icon-clear.svg.js +4 -0
- package/dist/client/assets/alert/icon-done.svg.js +4 -0
- package/dist/client/assets/avatar-identity/placeholder-icon.svg.js +4 -0
- package/dist/client/assets/breadcrumb/icon-ellipsis.svg.js +4 -0
- package/dist/client/assets/breadcrumb/icon-home.svg.js +4 -0
- package/dist/client/assets/breadcrumb/icon-separator.svg.js +4 -0
- package/dist/client/assets/button-v01/icon-back.svg.js +4 -0
- package/dist/client/assets/button-v01/icon-check.svg.js +4 -0
- package/dist/client/assets/button-v01/icon-close.svg.js +4 -0
- package/dist/client/assets/button-v01/icon-delete.svg.js +4 -0
- package/dist/client/assets/button-v01/icon-device.svg.js +4 -0
- package/dist/client/assets/dropdown/icon-carrot-contract.svg.js +4 -0
- package/dist/client/assets/dropdown/icon-carrot-expand.svg.js +4 -0
- package/dist/client/assets/dropdown/icon-clear.svg.js +4 -0
- package/dist/client/assets/dropdown/icon-enter.svg.js +4 -0
- package/dist/client/components/icons/AlphaIcon.js +129 -0
- package/dist/client/components/icons/ConceptIcons.js +905 -0
- package/dist/client/components/icons/IconUtility.js +410 -0
- package/dist/client/components/icons/NavAccount.js +37 -0
- package/dist/client/components/icons/NavBullet.js +17 -0
- package/dist/client/components/icons/NavLogo.js +48 -0
- package/dist/client/components/icons/StandardLogo.js +93 -0
- package/dist/client/components/icons/UtilityAccordion.js +27 -0
- package/dist/client/components/icons/UtilityChangeType.js +26 -0
- package/dist/client/components/icons/UtilityCheck.js +28 -0
- package/dist/client/components/icons/UtilityChevronDown.js +39 -0
- package/dist/client/components/icons/UtilityClassification.js +53 -0
- package/dist/client/components/icons/UtilityClearRegular.js +51 -0
- package/dist/client/components/icons/UtilityClose.js +49 -0
- package/dist/client/components/icons/UtilityCompare.js +91 -0
- package/dist/client/components/icons/UtilityDrag.js +89 -0
- package/dist/client/components/icons/UtilityEdit.js +50 -0
- package/dist/client/components/icons/UtilityFeedback.js +38 -0
- package/dist/client/components/icons/UtilityHome.js +34 -0
- package/dist/client/components/icons/UtilityMessage.js +41 -0
- package/dist/client/components/icons/UtilityOptions.js +53 -0
- package/dist/client/components/icons/UtilityPortfolio.js +116 -0
- package/dist/client/components/icons/UtilityReset.js +49 -0
- package/dist/client/components/icons/UtilityRevisionsHide.js +76 -0
- package/dist/client/components/icons/UtilityRevisionsShow.js +56 -0
- package/dist/client/components/icons/UtilitySave.js +38 -0
- package/dist/client/components/icons/UtilityScopeLarge.js +123 -0
- package/dist/client/components/icons/UtilityScoring.js +51 -0
- package/dist/client/components/icons/UtilitySearch.js +46 -0
- package/dist/client/components/icons/UtilityShow.js +49 -0
- package/dist/client/components/icons/UtilitySort.js +63 -0
- package/dist/client/components/icons/UtilityTarget.js +29 -0
- package/dist/client/components/icons/UtilityTargetActive.js +48 -0
- package/dist/client/components/icons/UtilityText.js +59 -0
- package/dist/client/components/icons/UtilityTrash.js +66 -0
- package/dist/client/components/icons/UtilityTriangleInfo.js +38 -0
- package/dist/client/components/icons/X.js +40 -0
- package/dist/client/components/icons/achievement-badges/BadgeCertificationBronze.js +144 -0
- package/dist/client/components/icons/achievement-badges/BadgeCertificationGold.js +144 -0
- package/dist/client/components/icons/achievement-badges/BadgeCertificationPlatinum.js +144 -0
- package/dist/client/components/icons/achievement-badges/BadgeCertificationSilver.js +144 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingCoworking.js +91 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingDesign.js +91 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingEquity.js +91 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingHealthySafety.js +93 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingOperations.js +93 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingPerformance.js +93 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingRealEstate.js +93 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingResidential.js +93 -0
- package/dist/client/components/icons/achievement-badges/BadgeRatingWorkforce.js +91 -0
- package/dist/client/components/icons/imperative-badges/BadgeImperativePrimary.js +58 -0
- package/dist/client/components/icons/imperative-badges/BadgeImperativeSecondary.js +69 -0
- package/dist/client/components/icons/provider-badges/BadgeEnterpriseProvider.js +117 -0
- package/dist/client/components/icons/provider-badges/BadgePerformanceTestingProvider.js +124 -0
- package/dist/client/components/icons/provider-badges/BadgeProductProvider.js +117 -0
- package/dist/client/components/icons/provider-badges/BadgeSurveyProvider.js +117 -0
- package/dist/client/components/icons/provider-seals/SealEnterpriseProvider.js +100 -0
- package/dist/client/components/icons/provider-seals/SealPerformanceTestingProvider.js +100 -0
- package/dist/client/components/icons/provider-seals/SealProductProvider.js +98 -0
- package/dist/client/components/icons/provider-seals/SealProviders.js +98 -0
- package/dist/client/components/icons/provider-seals/SealSurveyProvider.js +98 -0
- package/dist/client/components/icons/seals/IWBILogo.js +301 -0
- package/dist/client/components/icons/seals/SealCertification.js +206 -0
- package/dist/client/components/icons/seals/SealCertificationBronze.js +140 -0
- package/dist/client/components/icons/seals/SealCertificationGold.js +140 -0
- package/dist/client/components/icons/seals/SealCertificationPlatinum.js +140 -0
- package/dist/client/components/icons/seals/SealCertificationSilver.js +140 -0
- package/dist/client/components/icons/seals/SealIwbiMember.js +134 -0
- package/dist/client/components/icons/seals/SealRating.js +157 -0
- package/dist/client/components/icons/seals/SealRatingCoworking.js +89 -0
- package/dist/client/components/icons/seals/SealRatingDesign.js +89 -0
- package/dist/client/components/icons/seals/SealRatingEquity.js +89 -0
- package/dist/client/components/icons/seals/SealRatingHealthSafety.js +91 -0
- package/dist/client/components/icons/seals/SealRatingOperations.js +89 -0
- package/dist/client/components/icons/seals/SealRatingPerformance.js +91 -0
- package/dist/client/components/icons/seals/SealRatingRealEstate.js +89 -0
- package/dist/client/components/icons/seals/SealRatingWorkforce.js +89 -0
- package/dist/client/components/icons/seals/SealWell.js +132 -0
- package/dist/client/components/icons/seals/SealWellCertification.js +225 -0
- package/dist/client/components/icons/seals/SealWellCommunity.js +197 -0
- package/dist/client/components/icons/seals/SealWellResidence.js +197 -0
- package/dist/client/components/icons/seals/SealWorksWithWell.js +227 -0
- package/dist/client/components/icons/seals/WaterMarkWWWProducts.js +27 -0
- package/dist/client/components/icons/seals/WaterMarkWellProjects.js +36 -0
- package/dist/client/components/icons/seals/WatermarkMemberOrg.js +24 -0
- package/dist/client/components/ui/accordion.js +326 -0
- package/dist/client/components/ui/alert-dialog-panel.js +156 -0
- package/dist/client/components/ui/alert-dialog.js +103 -0
- package/dist/client/components/ui/alert-v02.js +157 -0
- package/dist/client/components/ui/alert.js +55 -0
- package/dist/client/components/ui/app-bar.js +203 -0
- package/dist/client/components/ui/aspect-ratio.js +5 -0
- package/dist/client/components/ui/avatar-identity.js +93 -0
- package/dist/client/components/ui/avatar.js +56 -0
- package/dist/client/components/ui/back-link.js +27 -0
- package/dist/client/components/ui/banner.js +75 -0
- package/dist/client/components/ui/bottom-navigation.js +127 -0
- package/dist/client/components/ui/breadcrumb-trail.js +137 -0
- package/dist/client/components/ui/breadcrumb.js +91 -0
- package/dist/client/components/ui/button-v01.js +173 -0
- package/dist/client/components/ui/button.js +99 -0
- package/dist/client/components/ui/calendar.js +62 -0
- package/dist/client/components/ui/card.js +177 -0
- package/dist/client/components/ui/carousel.js +198 -0
- package/dist/client/components/ui/centered-page.js +10 -0
- package/dist/client/components/ui/chart.js +239 -0
- package/dist/client/components/ui/checkbox-field.js +39 -0
- package/dist/client/components/ui/checkbox.js +18 -0
- package/dist/client/components/ui/code-badge.js +29 -0
- package/dist/client/components/ui/collapsible.js +9 -0
- package/dist/client/components/ui/command.js +79 -0
- package/dist/client/components/ui/context-menu.js +138 -0
- package/dist/client/components/ui/copy.js +39 -0
- package/dist/client/components/ui/credit-card-preview.js +74 -0
- package/dist/client/components/ui/data-grid.js +156 -0
- package/dist/client/components/ui/date-picker.js +142 -0
- package/dist/client/components/ui/dialog.js +179 -0
- package/dist/client/components/ui/drawer.js +95 -0
- package/dist/client/components/ui/drop-zone.js +87 -0
- package/dist/client/components/ui/dropdown-menu.js +139 -0
- package/dist/client/components/ui/dropdown.js +339 -0
- package/dist/client/components/ui/empty-state.js +76 -0
- package/dist/client/components/ui/field-group.js +32 -0
- package/dist/client/components/ui/file-upload-trigger.js +70 -0
- package/dist/client/components/ui/file-upload.js +171 -0
- package/dist/client/components/ui/footer.js +97 -0
- package/dist/client/components/ui/form.js +109 -0
- package/dist/client/components/ui/height-container.js +41 -0
- package/dist/client/components/ui/hero-section.js +44 -0
- package/dist/client/components/ui/hero-split-image.js +45 -0
- package/dist/client/components/ui/hover-card.js +22 -0
- package/dist/client/components/ui/icon-button.js +30 -0
- package/dist/client/components/ui/inline-notice.js +19 -0
- package/dist/client/components/ui/input-otp.js +46 -0
- package/dist/client/components/ui/input.js +37 -0
- package/dist/client/components/ui/label.js +31 -0
- package/dist/client/components/ui/labeled-divider.js +23 -0
- package/dist/client/components/ui/layout.js +724 -0
- package/dist/client/components/ui/menubar.js +157 -0
- package/dist/client/components/ui/meta-row.js +19 -0
- package/dist/client/components/ui/mobile-nav.js +230 -0
- package/dist/client/components/ui/modal-panel.js +116 -0
- package/dist/client/components/ui/navigation-menu.js +89 -0
- package/dist/client/components/ui/navigation.js +452 -0
- package/dist/client/components/ui/outline-node.js +57 -0
- package/dist/client/components/ui/page-header.js +79 -0
- package/dist/client/components/ui/pagination-v01.js +124 -0
- package/dist/client/components/ui/pagination.js +105 -0
- package/dist/client/components/ui/password-field-v01.js +46 -0
- package/dist/client/components/ui/pill-button.js +34 -0
- package/dist/client/components/ui/popover.js +22 -0
- package/dist/client/components/ui/price-tag.js +20 -0
- package/dist/client/components/ui/profile-avatar.js +92 -0
- package/dist/client/components/ui/progress.js +23 -0
- package/dist/client/components/ui/radio-card.js +30 -0
- package/dist/client/components/ui/radio-group.js +32 -0
- package/dist/client/components/ui/radio-v01.js +58 -0
- package/dist/client/components/ui/resizable.js +32 -0
- package/dist/client/components/ui/resource-thumbnail.js +24 -0
- package/dist/client/components/ui/scroll-area.js +37 -0
- package/dist/client/components/ui/search-field-v01.js +111 -0
- package/dist/client/components/ui/search.js +109 -0
- package/dist/client/components/ui/section-badge.js +22 -0
- package/dist/client/components/ui/section-heading.js +21 -0
- package/dist/client/components/ui/select.js +96 -0
- package/dist/client/components/ui/separator.js +24 -0
- package/dist/client/components/ui/sheet.js +106 -0
- package/dist/client/components/ui/side-nav.js +173 -0
- package/dist/client/components/ui/sidebar.js +580 -0
- package/dist/client/components/ui/sign-in-field-v01.js +107 -0
- package/dist/client/components/ui/skeleton.js +17 -0
- package/dist/client/components/ui/slider.js +20 -0
- package/dist/client/components/ui/social-button.js +34 -0
- package/dist/client/components/ui/standard-navigation.js +454 -0
- package/dist/client/components/ui/status-pill.js +42 -0
- package/dist/client/components/ui/stepper.js +111 -0
- package/dist/client/components/ui/switch-v01.js +39 -0
- package/dist/client/components/ui/switch.js +17 -0
- package/dist/client/components/ui/system-bar.js +76 -0
- package/dist/client/components/ui/table.js +107 -0
- package/dist/client/components/ui/tabs-v01.js +74 -0
- package/dist/client/components/ui/tabs.js +253 -0
- package/dist/client/components/ui/tag-v02.js +85 -0
- package/dist/client/components/ui/tag.js +73 -0
- package/dist/client/components/ui/text-area-v01.js +26 -0
- package/dist/client/components/ui/text-field-v01.js +78 -0
- package/dist/client/components/ui/text-link.js +23 -0
- package/dist/client/components/ui/textarea.js +19 -0
- package/dist/client/components/ui/timeline.js +87 -0
- package/dist/client/components/ui/toast-v01.js +155 -0
- package/dist/client/components/ui/toast.js +88 -0
- package/dist/client/components/ui/toaster.js +22 -0
- package/dist/client/components/ui/toggle.js +56 -0
- package/dist/client/components/ui/tooltip.js +328 -0
- package/dist/client/components/ui/typography.js +119 -0
- package/dist/client/hooks/use-mobile.js +20 -0
- package/dist/client/hooks/use-segmented-control.js +32 -0
- package/dist/client/hooks/use-tabs.js +22 -0
- package/dist/client/hooks/use-toast.js +122 -0
- package/dist/client/lib/concept-colors.js +74 -0
- package/dist/client/lib/concept-icons.js +32 -0
- package/dist/client/lib/utility-icons.js +73 -0
- package/dist/client/lib/utils.js +13 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +156 -0
- package/dist/ui/index.js +774 -0
- package/package.json +9 -6
- package/dist/index.cjs.js +0 -1
- package/dist/index.es.js +0 -18989
- /package/{dist → client}/fonts/FT-Made/FTMade-Regular.otf +0 -0
- /package/{dist → client}/fonts/FT-Made/FTMade-Regular.ttf +0 -0
- /package/{dist → client}/fonts/FT-Made/FTMade-Regular.woff +0 -0
- /package/{dist → client}/fonts/FT-Made/FTMade-Regular.woff2 +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-black.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-blackitalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-bold.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-bolditalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-extrabold.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-extrabolditalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-extralight.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-extralightitalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-italic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-light.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-lightitalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-medium.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-mediumitalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-regular.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-semibold.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-semibolditalic.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-thin.otf +0 -0
- /package/{dist → client}/fonts/Mazzard-M/mazzardsoftm-thinitalic.otf +0 -0
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
import iconCarrotExpand from "../../assets/dropdown/icon-carrot-expand.svg.js";
|
|
5
|
+
import iconCarrotContract from "../../assets/dropdown/icon-carrot-contract.svg.js";
|
|
6
|
+
import iconEnter from "../../assets/dropdown/icon-enter.svg.js";
|
|
7
|
+
import iconClear from "../../assets/dropdown/icon-clear.svg.js";
|
|
8
|
+
import { UtilityChangeType } from "../icons/UtilityChangeType.js";
|
|
9
|
+
function ChangeTypeIcon({ kind }) {
|
|
10
|
+
return /* @__PURE__ */ jsx(
|
|
11
|
+
UtilityChangeType,
|
|
12
|
+
{
|
|
13
|
+
className: `dropdown-tag-change dropdown-tag-change--${kind}`
|
|
14
|
+
}
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function MaskIcon$2({ src, className }) {
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
"span",
|
|
20
|
+
{
|
|
21
|
+
className: cn("dropdown-mask-icon", className),
|
|
22
|
+
style: {
|
|
23
|
+
WebkitMaskImage: `url("${src}")`,
|
|
24
|
+
maskImage: `url("${src}")`
|
|
25
|
+
},
|
|
26
|
+
"aria-hidden": true
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
function matchPrefix(query, label) {
|
|
31
|
+
if (!query) return null;
|
|
32
|
+
if (label.toLowerCase().startsWith(query.toLowerCase())) {
|
|
33
|
+
return {
|
|
34
|
+
matched: label.slice(0, query.length),
|
|
35
|
+
rest: label.slice(query.length)
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const Dropdown = React.forwardRef(
|
|
41
|
+
({
|
|
42
|
+
className,
|
|
43
|
+
label = "Label",
|
|
44
|
+
required = false,
|
|
45
|
+
placeholder = "Placeholder",
|
|
46
|
+
options = [],
|
|
47
|
+
value: valueProp,
|
|
48
|
+
defaultValue,
|
|
49
|
+
onValueChange,
|
|
50
|
+
error = false,
|
|
51
|
+
errorMessage = "Choose an option",
|
|
52
|
+
disabled = false,
|
|
53
|
+
open: openProp,
|
|
54
|
+
defaultOpen = false,
|
|
55
|
+
onOpenChange,
|
|
56
|
+
defaultInputValue,
|
|
57
|
+
tags,
|
|
58
|
+
onTagRemove,
|
|
59
|
+
onClearTags,
|
|
60
|
+
name,
|
|
61
|
+
id,
|
|
62
|
+
...props
|
|
63
|
+
}, ref) => {
|
|
64
|
+
const listId = React.useId();
|
|
65
|
+
const inputId = id ?? listId;
|
|
66
|
+
const rootRef = React.useRef(null);
|
|
67
|
+
const inputRef = React.useRef(null);
|
|
68
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);
|
|
69
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState(
|
|
70
|
+
defaultValue ?? ""
|
|
71
|
+
);
|
|
72
|
+
const [query, setQuery] = React.useState(defaultInputValue ?? "");
|
|
73
|
+
const [highlighted, setHighlighted] = React.useState(-1);
|
|
74
|
+
const [typing, setTyping] = React.useState(Boolean(defaultInputValue));
|
|
75
|
+
const isOpen = openProp ?? uncontrolledOpen;
|
|
76
|
+
const selectedValue = valueProp ?? uncontrolledValue;
|
|
77
|
+
const selected = options.find((option) => option.value === selectedValue);
|
|
78
|
+
const setOpen = (next) => {
|
|
79
|
+
if (openProp === void 0) setUncontrolledOpen(next);
|
|
80
|
+
onOpenChange == null ? void 0 : onOpenChange(next);
|
|
81
|
+
if (!next) {
|
|
82
|
+
setTyping(false);
|
|
83
|
+
setQuery("");
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const setValue = (next) => {
|
|
87
|
+
if (valueProp === void 0) setUncontrolledValue(next);
|
|
88
|
+
onValueChange == null ? void 0 : onValueChange(next);
|
|
89
|
+
};
|
|
90
|
+
const filtered = React.useMemo(() => {
|
|
91
|
+
if (!query) return options;
|
|
92
|
+
const needle = query.toLowerCase();
|
|
93
|
+
return options.filter(
|
|
94
|
+
(option) => {
|
|
95
|
+
var _a;
|
|
96
|
+
return option.label.toLowerCase().includes(needle) || ((_a = option.secondary) == null ? void 0 : _a.toLowerCase().includes(needle));
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}, [options, query]);
|
|
100
|
+
const ghost = React.useMemo(() => {
|
|
101
|
+
if (!query || !isOpen) return "";
|
|
102
|
+
const hit = filtered.find(
|
|
103
|
+
(option) => option.label.toLowerCase().startsWith(query.toLowerCase()) && option.label.length > query.length
|
|
104
|
+
);
|
|
105
|
+
if (!hit) return "";
|
|
106
|
+
return hit.label.slice(query.length);
|
|
107
|
+
}, [filtered, isOpen, query]);
|
|
108
|
+
React.useEffect(() => {
|
|
109
|
+
setHighlighted(query ? 0 : -1);
|
|
110
|
+
}, [query, isOpen]);
|
|
111
|
+
React.useEffect(() => {
|
|
112
|
+
const onPointerDown = (event) => {
|
|
113
|
+
var _a;
|
|
114
|
+
if (!((_a = rootRef.current) == null ? void 0 : _a.contains(event.target))) {
|
|
115
|
+
if (openProp === void 0) setUncontrolledOpen(false);
|
|
116
|
+
onOpenChange == null ? void 0 : onOpenChange(false);
|
|
117
|
+
setTyping(Boolean(defaultInputValue));
|
|
118
|
+
setQuery(defaultInputValue ?? "");
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
document.addEventListener("pointerdown", onPointerDown);
|
|
122
|
+
return () => document.removeEventListener("pointerdown", onPointerDown);
|
|
123
|
+
}, [defaultInputValue, onOpenChange, openProp]);
|
|
124
|
+
const selectOption = (option) => {
|
|
125
|
+
setValue(option.value);
|
|
126
|
+
setQuery("");
|
|
127
|
+
setTyping(false);
|
|
128
|
+
setOpen(false);
|
|
129
|
+
};
|
|
130
|
+
const clearValue = (event) => {
|
|
131
|
+
var _a;
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
event.stopPropagation();
|
|
134
|
+
setValue("");
|
|
135
|
+
setQuery("");
|
|
136
|
+
setTyping(false);
|
|
137
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
138
|
+
setOpen(true);
|
|
139
|
+
};
|
|
140
|
+
const onKeyDown = (event) => {
|
|
141
|
+
var _a;
|
|
142
|
+
if (event.key === "ArrowDown") {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
if (!isOpen) setOpen(true);
|
|
145
|
+
setHighlighted(
|
|
146
|
+
(index) => Math.min(index + 1, Math.max(filtered.length - 1, 0))
|
|
147
|
+
);
|
|
148
|
+
} else if (event.key === "ArrowUp") {
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
setHighlighted((index) => Math.max(index - 1, 0));
|
|
151
|
+
} else if (event.key === "Enter") {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
const option = filtered[highlighted];
|
|
154
|
+
if (option) selectOption(option);
|
|
155
|
+
} else if (event.key === "Escape") {
|
|
156
|
+
setOpen(false);
|
|
157
|
+
(_a = inputRef.current) == null ? void 0 : _a.blur();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const displayValue = isOpen ? query : (selected == null ? void 0 : selected.label) ?? query;
|
|
161
|
+
const showPlaceholder = !displayValue && !ghost;
|
|
162
|
+
const isRich = filtered.some(
|
|
163
|
+
(option) => option.secondary || option.actionLabel
|
|
164
|
+
);
|
|
165
|
+
const trailingIcon = error ? "expand" : isOpen && (typing || query) ? "enter" : isOpen ? "contract" : selected ? "clear" : "expand";
|
|
166
|
+
return /* @__PURE__ */ jsxs(
|
|
167
|
+
"div",
|
|
168
|
+
{
|
|
169
|
+
ref: (node) => {
|
|
170
|
+
rootRef.current = node;
|
|
171
|
+
if (typeof ref === "function") ref(node);
|
|
172
|
+
else if (ref) ref.current = node;
|
|
173
|
+
},
|
|
174
|
+
className: cn("dropdown font-mazzardSoft", className),
|
|
175
|
+
"data-open": isOpen || void 0,
|
|
176
|
+
"data-filled": !showPlaceholder && !isOpen || void 0,
|
|
177
|
+
"data-error": error || void 0,
|
|
178
|
+
"data-disabled": disabled || void 0,
|
|
179
|
+
...props,
|
|
180
|
+
children: [
|
|
181
|
+
label ? /* @__PURE__ */ jsxs("div", { className: "dropdown-label-row", children: [
|
|
182
|
+
/* @__PURE__ */ jsxs("label", { className: "dropdown-label overline-medium", htmlFor: inputId, children: [
|
|
183
|
+
label,
|
|
184
|
+
required ? /* @__PURE__ */ jsxs("span", { className: "label__required-mark", "aria-hidden": "true", children: [
|
|
185
|
+
" ",
|
|
186
|
+
"*"
|
|
187
|
+
] }) : null
|
|
188
|
+
] }),
|
|
189
|
+
onClearTags ? /* @__PURE__ */ jsx("span", { className: "dropdown-label-actions", children: /* @__PURE__ */ jsx(
|
|
190
|
+
"button",
|
|
191
|
+
{
|
|
192
|
+
type: "button",
|
|
193
|
+
className: "dropdown-label-clear",
|
|
194
|
+
"aria-label": "Clear all",
|
|
195
|
+
onClick: onClearTags,
|
|
196
|
+
children: /* @__PURE__ */ jsx(
|
|
197
|
+
MaskIcon$2,
|
|
198
|
+
{
|
|
199
|
+
src: iconClear,
|
|
200
|
+
className: "dropdown-label-clear-icon"
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
) }) : null
|
|
205
|
+
] }) : null,
|
|
206
|
+
tags && tags.length > 0 ? /* @__PURE__ */ jsx("ul", { className: "dropdown-tags", children: tags.map((tag) => /* @__PURE__ */ jsxs("li", { className: "dropdown-tag", children: [
|
|
207
|
+
/* @__PURE__ */ jsx("span", { className: "dropdown-tag-label", children: tag.label }),
|
|
208
|
+
tag.dot ? /* @__PURE__ */ jsx("span", { className: "dropdown-tag-dot", "aria-hidden": true }) : null,
|
|
209
|
+
tag.changeType ? /* @__PURE__ */ jsx(ChangeTypeIcon, { kind: tag.changeType }) : null,
|
|
210
|
+
onTagRemove ? /* @__PURE__ */ jsx(
|
|
211
|
+
"button",
|
|
212
|
+
{
|
|
213
|
+
type: "button",
|
|
214
|
+
className: "dropdown-tag-remove",
|
|
215
|
+
"aria-label": `Remove ${tag.label}`,
|
|
216
|
+
onClick: () => onTagRemove(tag.id),
|
|
217
|
+
children: /* @__PURE__ */ jsx(
|
|
218
|
+
MaskIcon$2,
|
|
219
|
+
{
|
|
220
|
+
src: iconClear,
|
|
221
|
+
className: "dropdown-tag-remove-icon"
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
) : null
|
|
226
|
+
] }, tag.id)) }) : null,
|
|
227
|
+
/* @__PURE__ */ jsxs("div", { className: "dropdown-field", children: [
|
|
228
|
+
/* @__PURE__ */ jsxs(
|
|
229
|
+
"div",
|
|
230
|
+
{
|
|
231
|
+
className: "dropdown-input",
|
|
232
|
+
onClick: () => {
|
|
233
|
+
var _a;
|
|
234
|
+
if (disabled) return;
|
|
235
|
+
(_a = inputRef.current) == null ? void 0 : _a.focus();
|
|
236
|
+
setOpen(true);
|
|
237
|
+
},
|
|
238
|
+
children: [
|
|
239
|
+
/* @__PURE__ */ jsx("div", { className: "dropdown-input-value", children: showPlaceholder ? /* @__PURE__ */ jsx("span", { className: "dropdown-placeholder", children: placeholder }) : /* @__PURE__ */ jsxs("span", { className: "dropdown-entry", children: [
|
|
240
|
+
displayValue,
|
|
241
|
+
ghost ? /* @__PURE__ */ jsx("span", { className: "dropdown-ghost", children: ghost }) : null
|
|
242
|
+
] }) }),
|
|
243
|
+
/* @__PURE__ */ jsx(
|
|
244
|
+
"input",
|
|
245
|
+
{
|
|
246
|
+
ref: inputRef,
|
|
247
|
+
id: inputId,
|
|
248
|
+
name,
|
|
249
|
+
className: "dropdown-native",
|
|
250
|
+
value: displayValue,
|
|
251
|
+
disabled,
|
|
252
|
+
autoComplete: "off",
|
|
253
|
+
role: "combobox",
|
|
254
|
+
"aria-expanded": isOpen,
|
|
255
|
+
"aria-controls": listId,
|
|
256
|
+
"aria-invalid": error || void 0,
|
|
257
|
+
"aria-autocomplete": "list",
|
|
258
|
+
placeholder: "",
|
|
259
|
+
onFocus: () => {
|
|
260
|
+
if (disabled) return;
|
|
261
|
+
setOpen(true);
|
|
262
|
+
if (selected && !query) setQuery(selected.label);
|
|
263
|
+
},
|
|
264
|
+
onChange: (event) => {
|
|
265
|
+
setTyping(true);
|
|
266
|
+
setQuery(event.target.value);
|
|
267
|
+
if (!isOpen) setOpen(true);
|
|
268
|
+
if (selected && event.target.value !== selected.label) {
|
|
269
|
+
setValue("");
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
onKeyDown
|
|
273
|
+
}
|
|
274
|
+
),
|
|
275
|
+
/* @__PURE__ */ jsx("div", { className: "dropdown-actions", children: trailingIcon === "clear" ? /* @__PURE__ */ jsx(
|
|
276
|
+
"button",
|
|
277
|
+
{
|
|
278
|
+
type: "button",
|
|
279
|
+
className: "dropdown-icon-button",
|
|
280
|
+
"aria-label": "Clear",
|
|
281
|
+
onClick: clearValue,
|
|
282
|
+
children: /* @__PURE__ */ jsx(MaskIcon$2, { src: iconClear, className: "dropdown-icon-clear" })
|
|
283
|
+
}
|
|
284
|
+
) : /* @__PURE__ */ jsx(
|
|
285
|
+
MaskIcon$2,
|
|
286
|
+
{
|
|
287
|
+
src: trailingIcon === "enter" ? iconEnter : trailingIcon === "contract" ? iconCarrotContract : iconCarrotExpand,
|
|
288
|
+
className: trailingIcon === "enter" ? "dropdown-icon-enter" : "dropdown-icon-carrot"
|
|
289
|
+
}
|
|
290
|
+
) })
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
),
|
|
294
|
+
isOpen && !error ? /* @__PURE__ */ jsx(
|
|
295
|
+
"ul",
|
|
296
|
+
{
|
|
297
|
+
id: listId,
|
|
298
|
+
role: "listbox",
|
|
299
|
+
className: cn("dropdown-menu", isRich && "dropdown-menu--rich"),
|
|
300
|
+
children: filtered.map((option, index) => {
|
|
301
|
+
const prefix = query ? matchPrefix(query, option.label) : null;
|
|
302
|
+
const isHighlighted = index === highlighted;
|
|
303
|
+
return /* @__PURE__ */ jsx("li", { role: "presentation", children: /* @__PURE__ */ jsxs(
|
|
304
|
+
"button",
|
|
305
|
+
{
|
|
306
|
+
type: "button",
|
|
307
|
+
role: "option",
|
|
308
|
+
"aria-selected": option.value === selectedValue,
|
|
309
|
+
className: cn(
|
|
310
|
+
"dropdown-item",
|
|
311
|
+
(option.secondary || option.actionLabel) && "dropdown-item--rich"
|
|
312
|
+
),
|
|
313
|
+
"data-highlighted": isHighlighted || void 0,
|
|
314
|
+
onMouseEnter: () => setHighlighted(index),
|
|
315
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
316
|
+
onClick: () => selectOption(option),
|
|
317
|
+
children: [
|
|
318
|
+
/* @__PURE__ */ jsx("span", { className: "dropdown-item-primary", children: prefix ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
319
|
+
/* @__PURE__ */ jsx("span", { className: "dropdown-item-match", children: prefix.matched }),
|
|
320
|
+
/* @__PURE__ */ jsx("span", { className: "dropdown-item-rest", children: prefix.rest })
|
|
321
|
+
] }) : option.label }),
|
|
322
|
+
option.actionLabel ? /* @__PURE__ */ jsx("span", { className: "dropdown-item-action", children: option.actionLabel }) : option.secondary ? /* @__PURE__ */ jsx("span", { className: "dropdown-item-secondary", children: option.secondary }) : null
|
|
323
|
+
]
|
|
324
|
+
}
|
|
325
|
+
) }, option.value);
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
) : null
|
|
329
|
+
] }),
|
|
330
|
+
error ? /* @__PURE__ */ jsx("p", { className: "dropdown-error", children: errorMessage }) : null
|
|
331
|
+
]
|
|
332
|
+
}
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
);
|
|
336
|
+
Dropdown.displayName = "Dropdown";
|
|
337
|
+
export {
|
|
338
|
+
Dropdown
|
|
339
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
const EmptyState = React.forwardRef(
|
|
5
|
+
({
|
|
6
|
+
className,
|
|
7
|
+
children,
|
|
8
|
+
headline,
|
|
9
|
+
title,
|
|
10
|
+
subtitle,
|
|
11
|
+
text,
|
|
12
|
+
image,
|
|
13
|
+
imageAlt = "",
|
|
14
|
+
icon,
|
|
15
|
+
actionText,
|
|
16
|
+
onClickAction,
|
|
17
|
+
mediaSlot,
|
|
18
|
+
headlineSlot,
|
|
19
|
+
titleSlot,
|
|
20
|
+
subtitleSlot,
|
|
21
|
+
textSlot,
|
|
22
|
+
actionsSlot,
|
|
23
|
+
...props
|
|
24
|
+
}, ref) => {
|
|
25
|
+
const hasMedia = mediaSlot || image || icon;
|
|
26
|
+
const hasHeadline = headlineSlot || headline;
|
|
27
|
+
const hasTitle = titleSlot || title;
|
|
28
|
+
const hasSubtitle = subtitleSlot || subtitle;
|
|
29
|
+
const hasText = textSlot || text;
|
|
30
|
+
const hasActions = actionsSlot || actionText;
|
|
31
|
+
return /* @__PURE__ */ jsxs(
|
|
32
|
+
"div",
|
|
33
|
+
{
|
|
34
|
+
ref,
|
|
35
|
+
className: cn("empty-state", className),
|
|
36
|
+
...props,
|
|
37
|
+
children: [
|
|
38
|
+
hasMedia && /* @__PURE__ */ jsx("div", { className: "empty-state-media", children: mediaSlot ?? (image ? /* @__PURE__ */ jsx(
|
|
39
|
+
"img",
|
|
40
|
+
{
|
|
41
|
+
src: image,
|
|
42
|
+
alt: imageAlt,
|
|
43
|
+
className: "empty-state-image"
|
|
44
|
+
}
|
|
45
|
+
) : /* @__PURE__ */ jsx("span", { className: "empty-state-icon", children: icon })) }),
|
|
46
|
+
hasHeadline && /* @__PURE__ */ jsx("div", { className: "empty-state-headline", children: headlineSlot ?? headline }),
|
|
47
|
+
hasTitle && /* @__PURE__ */ jsx("div", { className: "empty-state-title", children: titleSlot ?? title }),
|
|
48
|
+
hasSubtitle && /* @__PURE__ */ jsx("div", { className: "empty-state-subtitle", children: subtitleSlot ?? subtitle }),
|
|
49
|
+
hasText && /* @__PURE__ */ jsx("div", { className: "empty-state-text", children: textSlot ?? text }),
|
|
50
|
+
children && /* @__PURE__ */ jsx("div", { className: "empty-state-default", children }),
|
|
51
|
+
hasActions && /* @__PURE__ */ jsx("div", { className: "empty-state-actions", children: actionsSlot ?? /* @__PURE__ */ jsx(EmptyStateAction, { onClick: onClickAction, children: actionText }) })
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
EmptyState.displayName = "EmptyState";
|
|
58
|
+
const EmptyStateAction = React.forwardRef(({ className, variant = "default", ...props }, ref) => /* @__PURE__ */ jsx(
|
|
59
|
+
"button",
|
|
60
|
+
{
|
|
61
|
+
ref,
|
|
62
|
+
type: "button",
|
|
63
|
+
className: cn(
|
|
64
|
+
"empty-state-action-btn",
|
|
65
|
+
variant === "primary" && "empty-state-action-btn--primary",
|
|
66
|
+
variant === "outline" && "empty-state-action-btn--outline",
|
|
67
|
+
className
|
|
68
|
+
),
|
|
69
|
+
...props
|
|
70
|
+
}
|
|
71
|
+
));
|
|
72
|
+
EmptyStateAction.displayName = "EmptyStateAction";
|
|
73
|
+
export {
|
|
74
|
+
EmptyState,
|
|
75
|
+
EmptyStateAction
|
|
76
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
const FieldGroup = React.forwardRef(
|
|
5
|
+
({ as: Component = "div", className, ...props }, ref) => /* @__PURE__ */ jsx(Component, { ref, className: cn("field-group", className), ...props })
|
|
6
|
+
);
|
|
7
|
+
FieldGroup.displayName = "FieldGroup";
|
|
8
|
+
const Field = React.forwardRef(
|
|
9
|
+
({ actions, staticValue, staticTone = "value", state = "default", className, ...props }, ref) => /* @__PURE__ */ jsxs(
|
|
10
|
+
"div",
|
|
11
|
+
{
|
|
12
|
+
className: cn("field", state === "invalid" && "field--invalid", className),
|
|
13
|
+
children: [
|
|
14
|
+
staticValue !== void 0 ? /* @__PURE__ */ jsx("span", { className: cn("field-static", `field-static--${staticTone}`), children: staticValue }) : /* @__PURE__ */ jsx("input", { ref, className: "field-input", ...props }),
|
|
15
|
+
actions ? /* @__PURE__ */ jsx("span", { className: "field-actions", children: actions }) : null
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
Field.displayName = "Field";
|
|
21
|
+
const FieldAction = React.forwardRef(
|
|
22
|
+
({ static: isStatic, tone = "default", className, children, type = "button", ...props }, ref) => {
|
|
23
|
+
const classes = cn("field-action", `field-action--${tone}`, className);
|
|
24
|
+
return isStatic ? /* @__PURE__ */ jsx("span", { className: classes, "aria-hidden": "true", children }) : /* @__PURE__ */ jsx("button", { ref, type, className: classes, ...props, children });
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
FieldAction.displayName = "FieldAction";
|
|
28
|
+
export {
|
|
29
|
+
Field,
|
|
30
|
+
FieldAction,
|
|
31
|
+
FieldGroup
|
|
32
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
const BUTTON_VARIANT_CLASS = {
|
|
5
|
+
clear: "button--clear",
|
|
6
|
+
default: "button--default",
|
|
7
|
+
"primary-gradient": "button--primary-gradient",
|
|
8
|
+
"primary-dark": "button--primary-dark",
|
|
9
|
+
"secondary-light": "button--secondary-light",
|
|
10
|
+
"tertiary-light": "button--tertiary-light"
|
|
11
|
+
};
|
|
12
|
+
const BUTTON_SIZE_CLASS = {
|
|
13
|
+
large: "button--large",
|
|
14
|
+
utility: "button--utility"
|
|
15
|
+
};
|
|
16
|
+
const FileUploadTrigger = React.forwardRef(
|
|
17
|
+
({
|
|
18
|
+
onFiles,
|
|
19
|
+
accept,
|
|
20
|
+
multiple = false,
|
|
21
|
+
variant = "secondary-light",
|
|
22
|
+
size = "large",
|
|
23
|
+
children,
|
|
24
|
+
className,
|
|
25
|
+
type = "button",
|
|
26
|
+
onClick,
|
|
27
|
+
disabled,
|
|
28
|
+
...props
|
|
29
|
+
}, ref) => {
|
|
30
|
+
const inputRef = React.useRef(null);
|
|
31
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
32
|
+
/* @__PURE__ */ jsx(
|
|
33
|
+
"button",
|
|
34
|
+
{
|
|
35
|
+
ref,
|
|
36
|
+
type,
|
|
37
|
+
disabled,
|
|
38
|
+
className: cn("button", BUTTON_VARIANT_CLASS[variant], BUTTON_SIZE_CLASS[size], className),
|
|
39
|
+
onClick: (event) => {
|
|
40
|
+
var _a;
|
|
41
|
+
onClick == null ? void 0 : onClick(event);
|
|
42
|
+
if (!event.defaultPrevented) (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
43
|
+
},
|
|
44
|
+
...props,
|
|
45
|
+
children: /* @__PURE__ */ jsx("span", { className: "button-text body-base", children })
|
|
46
|
+
}
|
|
47
|
+
),
|
|
48
|
+
/* @__PURE__ */ jsx(
|
|
49
|
+
"input",
|
|
50
|
+
{
|
|
51
|
+
ref: inputRef,
|
|
52
|
+
type: "file",
|
|
53
|
+
hidden: true,
|
|
54
|
+
accept,
|
|
55
|
+
multiple,
|
|
56
|
+
tabIndex: -1,
|
|
57
|
+
onChange: (event) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if ((_a = event.target.files) == null ? void 0 : _a.length) onFiles == null ? void 0 : onFiles(event.target.files);
|
|
60
|
+
event.target.value = "";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
] });
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
FileUploadTrigger.displayName = "FileUploadTrigger";
|
|
68
|
+
export {
|
|
69
|
+
FileUploadTrigger
|
|
70
|
+
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
function formatBytes(bytes) {
|
|
5
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
6
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
7
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
8
|
+
}
|
|
9
|
+
function getFileIcon(type) {
|
|
10
|
+
if (type.startsWith("image/")) return "🖼";
|
|
11
|
+
if (type === "application/pdf") return "📄";
|
|
12
|
+
if (type.includes("spreadsheet") || type.includes("excel") || type.includes("csv")) return "📊";
|
|
13
|
+
if (type.includes("word") || type.includes("document")) return "📝";
|
|
14
|
+
if (type.includes("zip") || type.includes("compressed")) return "🗜";
|
|
15
|
+
return "📎";
|
|
16
|
+
}
|
|
17
|
+
const FileUpload = React.forwardRef(
|
|
18
|
+
({
|
|
19
|
+
accept,
|
|
20
|
+
multiple = false,
|
|
21
|
+
maxSize,
|
|
22
|
+
maxFiles,
|
|
23
|
+
disabled = false,
|
|
24
|
+
variant = "default",
|
|
25
|
+
onFilesChange,
|
|
26
|
+
className
|
|
27
|
+
}, ref) => {
|
|
28
|
+
const [files, setFiles] = React.useState([]);
|
|
29
|
+
const [isDragging, setIsDragging] = React.useState(false);
|
|
30
|
+
const inputRef = React.useRef(null);
|
|
31
|
+
const validateFile = (file) => {
|
|
32
|
+
if (maxSize && file.size > maxSize) {
|
|
33
|
+
return `File exceeds ${formatBytes(maxSize)} limit`;
|
|
34
|
+
}
|
|
35
|
+
return void 0;
|
|
36
|
+
};
|
|
37
|
+
const addFiles = (incoming) => {
|
|
38
|
+
const incomingArray = Array.from(incoming);
|
|
39
|
+
const next = multiple ? [...files] : [];
|
|
40
|
+
for (const file of incomingArray) {
|
|
41
|
+
if (maxFiles && next.filter((f) => !f.error).length >= maxFiles) break;
|
|
42
|
+
const error = validateFile(file);
|
|
43
|
+
next.push({ file, id: `${file.name}-${Date.now()}-${Math.random()}`, error });
|
|
44
|
+
}
|
|
45
|
+
setFiles(next);
|
|
46
|
+
onFilesChange == null ? void 0 : onFilesChange(next.filter((f) => !f.error).map((f) => f.file));
|
|
47
|
+
};
|
|
48
|
+
const removeFile = (id) => {
|
|
49
|
+
const next = files.filter((f) => f.id !== id);
|
|
50
|
+
setFiles(next);
|
|
51
|
+
onFilesChange == null ? void 0 : onFilesChange(next.filter((f) => !f.error).map((f) => f.file));
|
|
52
|
+
};
|
|
53
|
+
const onDragOver = (e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
if (!disabled) setIsDragging(true);
|
|
56
|
+
};
|
|
57
|
+
const onDragLeave = (e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
setIsDragging(false);
|
|
60
|
+
};
|
|
61
|
+
const onDrop = (e) => {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
setIsDragging(false);
|
|
64
|
+
if (disabled) return;
|
|
65
|
+
if (e.dataTransfer.files.length > 0) addFiles(e.dataTransfer.files);
|
|
66
|
+
};
|
|
67
|
+
const onInputChange = (e) => {
|
|
68
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
69
|
+
addFiles(e.target.files);
|
|
70
|
+
e.target.value = "";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const openPicker = () => {
|
|
74
|
+
var _a;
|
|
75
|
+
if (!disabled) (_a = inputRef.current) == null ? void 0 : _a.click();
|
|
76
|
+
};
|
|
77
|
+
return /* @__PURE__ */ jsxs("div", { ref, className: cn("file-upload", className), children: [
|
|
78
|
+
/* @__PURE__ */ jsxs(
|
|
79
|
+
"div",
|
|
80
|
+
{
|
|
81
|
+
role: "button",
|
|
82
|
+
tabIndex: disabled ? -1 : 0,
|
|
83
|
+
"aria-label": "Upload files",
|
|
84
|
+
onClick: openPicker,
|
|
85
|
+
onKeyDown: (e) => e.key === "Enter" && openPicker(),
|
|
86
|
+
onDragOver,
|
|
87
|
+
onDragLeave,
|
|
88
|
+
onDrop,
|
|
89
|
+
className: cn(
|
|
90
|
+
"file-upload-zone",
|
|
91
|
+
variant === "compact" && "file-upload-zone--compact",
|
|
92
|
+
isDragging && "file-upload-zone--dragging",
|
|
93
|
+
disabled && "file-upload-zone--disabled"
|
|
94
|
+
),
|
|
95
|
+
children: [
|
|
96
|
+
/* @__PURE__ */ jsx(
|
|
97
|
+
"input",
|
|
98
|
+
{
|
|
99
|
+
ref: inputRef,
|
|
100
|
+
type: "file",
|
|
101
|
+
accept,
|
|
102
|
+
multiple,
|
|
103
|
+
disabled,
|
|
104
|
+
onChange: onInputChange,
|
|
105
|
+
className: "file-upload-input",
|
|
106
|
+
tabIndex: -1
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
variant === "compact" ? /* @__PURE__ */ jsxs("div", { className: "file-upload-compact-inner", children: [
|
|
110
|
+
/* @__PURE__ */ jsx("span", { className: "file-upload-icon", children: "↑" }),
|
|
111
|
+
/* @__PURE__ */ jsxs("span", { className: "file-upload-zone-text", children: [
|
|
112
|
+
/* @__PURE__ */ jsx("span", { className: "file-upload-zone-link", children: "Click to upload" }),
|
|
113
|
+
" ",
|
|
114
|
+
"or drag and drop"
|
|
115
|
+
] }),
|
|
116
|
+
accept && /* @__PURE__ */ jsx("span", { className: "file-upload-hint", children: accept.split(",").join(", ") }),
|
|
117
|
+
maxSize && /* @__PURE__ */ jsxs("span", { className: "file-upload-hint", children: [
|
|
118
|
+
"Max ",
|
|
119
|
+
formatBytes(maxSize)
|
|
120
|
+
] })
|
|
121
|
+
] }) : /* @__PURE__ */ jsxs("div", { className: "file-upload-default-inner", children: [
|
|
122
|
+
/* @__PURE__ */ jsx("div", { className: "file-upload-icon-circle", children: /* @__PURE__ */ jsx("span", { className: "file-upload-icon", children: "↑" }) }),
|
|
123
|
+
/* @__PURE__ */ jsxs("div", { className: "file-upload-zone-body", children: [
|
|
124
|
+
/* @__PURE__ */ jsxs("span", { className: "file-upload-zone-text", children: [
|
|
125
|
+
/* @__PURE__ */ jsx("span", { className: "file-upload-zone-link", children: "Click to upload" }),
|
|
126
|
+
" ",
|
|
127
|
+
"or drag and drop"
|
|
128
|
+
] }),
|
|
129
|
+
(accept || maxSize) && /* @__PURE__ */ jsx("span", { className: "file-upload-hint", children: [
|
|
130
|
+
accept && accept.split(",").join(", "),
|
|
131
|
+
maxSize && `Max ${formatBytes(maxSize)}`
|
|
132
|
+
].filter(Boolean).join(" · ") })
|
|
133
|
+
] })
|
|
134
|
+
] })
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
),
|
|
138
|
+
files.length > 0 && /* @__PURE__ */ jsx("ul", { className: "file-upload-list", children: files.map(({ file, id, error }) => /* @__PURE__ */ jsxs(
|
|
139
|
+
"li",
|
|
140
|
+
{
|
|
141
|
+
className: cn("file-upload-item", error && "file-upload-item--error"),
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsx("span", { className: "file-upload-item-icon", children: getFileIcon(file.type) }),
|
|
144
|
+
/* @__PURE__ */ jsxs("div", { className: "file-upload-item-info", children: [
|
|
145
|
+
/* @__PURE__ */ jsx("span", { className: "file-upload-item-name", children: file.name }),
|
|
146
|
+
error ? /* @__PURE__ */ jsx("span", { className: "file-upload-item-error", children: error }) : /* @__PURE__ */ jsx("span", { className: "file-upload-item-size", children: formatBytes(file.size) })
|
|
147
|
+
] }),
|
|
148
|
+
/* @__PURE__ */ jsx(
|
|
149
|
+
"button",
|
|
150
|
+
{
|
|
151
|
+
type: "button",
|
|
152
|
+
"aria-label": `Remove ${file.name}`,
|
|
153
|
+
onClick: (e) => {
|
|
154
|
+
e.stopPropagation();
|
|
155
|
+
removeFile(id);
|
|
156
|
+
},
|
|
157
|
+
className: "file-upload-item-remove",
|
|
158
|
+
children: "✕"
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
id
|
|
164
|
+
)) })
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
FileUpload.displayName = "FileUpload";
|
|
169
|
+
export {
|
|
170
|
+
FileUpload
|
|
171
|
+
};
|