@syscore/ui-library 2.0.0-beta-publish-workflow-beta.15 → 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 +10 -12
- package/client/components/ui/form.tsx +1 -1
- package/client/components/ui/label.tsx +21 -4
- 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 +358 -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 +159 -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 -18973
- /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,328 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { cn } from "../../lib/utils.js";
|
|
6
|
+
import { Button } from "./button.js";
|
|
7
|
+
const tooltipContentVariants = cva("tooltip-content font-mazzardSoft", {
|
|
8
|
+
variants: {
|
|
9
|
+
tone: {
|
|
10
|
+
dark: "tooltip-content--dark",
|
|
11
|
+
light: "tooltip-content--light"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
defaultVariants: {
|
|
15
|
+
tone: "dark"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const MARKER_INSET = { inline: 54, block: 53 };
|
|
19
|
+
const MARKER_HALF = 5;
|
|
20
|
+
const directionToSide = {
|
|
21
|
+
top: "bottom",
|
|
22
|
+
bottom: "top",
|
|
23
|
+
left: "right",
|
|
24
|
+
right: "left"
|
|
25
|
+
};
|
|
26
|
+
const TooltipContext = React.createContext({
|
|
27
|
+
trigger: "hover",
|
|
28
|
+
toggle: () => {
|
|
29
|
+
},
|
|
30
|
+
close: () => {
|
|
31
|
+
},
|
|
32
|
+
triggerRef: { current: null },
|
|
33
|
+
anchorSize: { width: 0, height: 0 },
|
|
34
|
+
setAnchorSize: () => {
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
function TooltipProvider({
|
|
38
|
+
delayDuration = 0,
|
|
39
|
+
...props
|
|
40
|
+
}) {
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
TooltipPrimitive.Provider,
|
|
43
|
+
{
|
|
44
|
+
"data-slot": "tooltip-provider",
|
|
45
|
+
delayDuration,
|
|
46
|
+
...props
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function Tooltip({
|
|
51
|
+
trigger = "click",
|
|
52
|
+
open: controlledOpen,
|
|
53
|
+
onOpenChange,
|
|
54
|
+
children,
|
|
55
|
+
...props
|
|
56
|
+
}) {
|
|
57
|
+
const [uncontrolledOpen, setUncontrolledOpen] = React.useState(false);
|
|
58
|
+
const triggerRef = React.useRef(null);
|
|
59
|
+
const [anchorSize, setAnchorSize] = React.useState({
|
|
60
|
+
width: 0,
|
|
61
|
+
height: 0
|
|
62
|
+
});
|
|
63
|
+
const isControlled = controlledOpen !== void 0;
|
|
64
|
+
const isOpen = isControlled ? controlledOpen : uncontrolledOpen;
|
|
65
|
+
const handleOpenChange = React.useCallback(
|
|
66
|
+
(newOpen) => {
|
|
67
|
+
if (trigger === "click") return;
|
|
68
|
+
if (!isControlled) {
|
|
69
|
+
setUncontrolledOpen(newOpen);
|
|
70
|
+
}
|
|
71
|
+
onOpenChange == null ? void 0 : onOpenChange(newOpen);
|
|
72
|
+
},
|
|
73
|
+
[isControlled, onOpenChange, trigger]
|
|
74
|
+
);
|
|
75
|
+
const close = React.useCallback(() => {
|
|
76
|
+
if (!isControlled) {
|
|
77
|
+
setUncontrolledOpen(false);
|
|
78
|
+
}
|
|
79
|
+
onOpenChange == null ? void 0 : onOpenChange(false);
|
|
80
|
+
}, [isControlled, onOpenChange]);
|
|
81
|
+
const toggle = React.useCallback(() => {
|
|
82
|
+
const newOpen = !isOpen;
|
|
83
|
+
if (!isControlled) {
|
|
84
|
+
setUncontrolledOpen(newOpen);
|
|
85
|
+
}
|
|
86
|
+
onOpenChange == null ? void 0 : onOpenChange(newOpen);
|
|
87
|
+
}, [isOpen, isControlled, onOpenChange]);
|
|
88
|
+
const tooltipProps = trigger === "click" ? {
|
|
89
|
+
open: isOpen,
|
|
90
|
+
onOpenChange: handleOpenChange
|
|
91
|
+
} : {
|
|
92
|
+
open: isControlled ? controlledOpen : void 0,
|
|
93
|
+
onOpenChange
|
|
94
|
+
};
|
|
95
|
+
return /* @__PURE__ */ jsx(
|
|
96
|
+
TooltipContext.Provider,
|
|
97
|
+
{
|
|
98
|
+
value: { trigger, toggle, close, triggerRef, anchorSize, setAnchorSize },
|
|
99
|
+
children: /* @__PURE__ */ jsx(TooltipProvider, { delayDuration: trigger === "click" ? 1e5 : 0, children: /* @__PURE__ */ jsx(TooltipPrimitive.Root, { "data-slot": "tooltip", ...tooltipProps, ...props, children }) })
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
function TooltipTrigger({
|
|
104
|
+
onClick,
|
|
105
|
+
...props
|
|
106
|
+
}) {
|
|
107
|
+
const { trigger, toggle, triggerRef, setAnchorSize } = React.useContext(TooltipContext);
|
|
108
|
+
React.useLayoutEffect(() => {
|
|
109
|
+
const el = triggerRef.current;
|
|
110
|
+
if (!el) return;
|
|
111
|
+
const measure = () => {
|
|
112
|
+
const { width, height } = el.getBoundingClientRect();
|
|
113
|
+
setAnchorSize({ width, height });
|
|
114
|
+
};
|
|
115
|
+
measure();
|
|
116
|
+
const observer = new ResizeObserver(measure);
|
|
117
|
+
observer.observe(el);
|
|
118
|
+
return () => observer.disconnect();
|
|
119
|
+
}, [triggerRef, setAnchorSize]);
|
|
120
|
+
const handleClick = React.useCallback(
|
|
121
|
+
(e) => {
|
|
122
|
+
if (trigger === "click") {
|
|
123
|
+
e.preventDefault();
|
|
124
|
+
e.stopPropagation();
|
|
125
|
+
toggle();
|
|
126
|
+
}
|
|
127
|
+
onClick == null ? void 0 : onClick(e);
|
|
128
|
+
},
|
|
129
|
+
[trigger, toggle, onClick]
|
|
130
|
+
);
|
|
131
|
+
return /* @__PURE__ */ jsx(
|
|
132
|
+
TooltipPrimitive.Trigger,
|
|
133
|
+
{
|
|
134
|
+
ref: triggerRef,
|
|
135
|
+
"data-slot": "tooltip-trigger",
|
|
136
|
+
onClick: handleClick,
|
|
137
|
+
...props
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
function TooltipMarker() {
|
|
142
|
+
return /* @__PURE__ */ jsx(
|
|
143
|
+
"svg",
|
|
144
|
+
{
|
|
145
|
+
className: "tooltip-marker",
|
|
146
|
+
"data-slot": "tooltip-marker",
|
|
147
|
+
width: "10",
|
|
148
|
+
height: "5",
|
|
149
|
+
viewBox: "0 0 10 5",
|
|
150
|
+
fill: "none",
|
|
151
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
152
|
+
"aria-hidden": true,
|
|
153
|
+
children: /* @__PURE__ */ jsx(
|
|
154
|
+
"path",
|
|
155
|
+
{
|
|
156
|
+
d: "M10 0L0 0C0 2.76142 2.23858 5 5 5C7.76142 5 10 2.76142 10 0Z",
|
|
157
|
+
fill: "currentColor"
|
|
158
|
+
}
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
function textOf(node) {
|
|
164
|
+
if (node == null || typeof node === "boolean") return "";
|
|
165
|
+
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
166
|
+
if (Array.isArray(node)) return node.map(textOf).filter(Boolean).join(" ");
|
|
167
|
+
if (React.isValidElement(node)) {
|
|
168
|
+
return textOf(node.props.children);
|
|
169
|
+
}
|
|
170
|
+
return "";
|
|
171
|
+
}
|
|
172
|
+
const TooltipPanel = React.forwardRef(
|
|
173
|
+
({
|
|
174
|
+
className,
|
|
175
|
+
tone = "dark",
|
|
176
|
+
direction = "top",
|
|
177
|
+
heading,
|
|
178
|
+
body,
|
|
179
|
+
conditionalText,
|
|
180
|
+
primaryLabel,
|
|
181
|
+
secondaryLabel,
|
|
182
|
+
onPrimaryAction,
|
|
183
|
+
onSecondaryAction,
|
|
184
|
+
children,
|
|
185
|
+
...props
|
|
186
|
+
}, ref) => {
|
|
187
|
+
const showHeader = heading != null || body != null;
|
|
188
|
+
const showActions = primaryLabel != null || secondaryLabel != null;
|
|
189
|
+
return /* @__PURE__ */ jsxs(
|
|
190
|
+
"div",
|
|
191
|
+
{
|
|
192
|
+
ref,
|
|
193
|
+
"data-slot": "tooltip-content",
|
|
194
|
+
"data-direction": direction,
|
|
195
|
+
className: cn(tooltipContentVariants({ tone }), className),
|
|
196
|
+
...props,
|
|
197
|
+
children: [
|
|
198
|
+
/* @__PURE__ */ jsx(TooltipMarker, {}),
|
|
199
|
+
showHeader && /* @__PURE__ */ jsxs("div", { className: "tooltip-header", "data-slot": "tooltip-header", children: [
|
|
200
|
+
heading != null && /* @__PURE__ */ jsx("p", { className: "tooltip-heading", "data-slot": "tooltip-heading", children: heading }),
|
|
201
|
+
body != null && /* @__PURE__ */ jsx("p", { className: "tooltip-body", "data-slot": "tooltip-body", children: body })
|
|
202
|
+
] }),
|
|
203
|
+
conditionalText != null && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
204
|
+
/* @__PURE__ */ jsx(
|
|
205
|
+
"span",
|
|
206
|
+
{
|
|
207
|
+
className: "tooltip-separator",
|
|
208
|
+
"data-slot": "tooltip-separator",
|
|
209
|
+
"aria-hidden": true
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
/* @__PURE__ */ jsx("p", { className: "tooltip-body", "data-slot": "tooltip-conditional-text", children: conditionalText })
|
|
213
|
+
] }),
|
|
214
|
+
children,
|
|
215
|
+
showActions && /* @__PURE__ */ jsxs("div", { className: "tooltip-actions", "data-slot": "tooltip-actions", children: [
|
|
216
|
+
primaryLabel != null && /* @__PURE__ */ jsx(
|
|
217
|
+
Button,
|
|
218
|
+
{
|
|
219
|
+
type: "button",
|
|
220
|
+
size: "utility",
|
|
221
|
+
variant: tone === "light" ? "tooltip-primary-light" : "tooltip-primary",
|
|
222
|
+
onClick: onPrimaryAction,
|
|
223
|
+
children: primaryLabel
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
secondaryLabel != null && /* @__PURE__ */ jsx(
|
|
227
|
+
Button,
|
|
228
|
+
{
|
|
229
|
+
type: "button",
|
|
230
|
+
size: "utility",
|
|
231
|
+
variant: tone === "light" ? "tooltip-secondary-light" : "tooltip-secondary",
|
|
232
|
+
onClick: onSecondaryAction,
|
|
233
|
+
children: secondaryLabel
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
] })
|
|
237
|
+
]
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
);
|
|
242
|
+
TooltipPanel.displayName = "TooltipPanel";
|
|
243
|
+
function TooltipContent({
|
|
244
|
+
className,
|
|
245
|
+
tone = "dark",
|
|
246
|
+
sideOffset = 12,
|
|
247
|
+
direction = "top",
|
|
248
|
+
align = "start",
|
|
249
|
+
alignOffset,
|
|
250
|
+
heading,
|
|
251
|
+
body,
|
|
252
|
+
conditionalText,
|
|
253
|
+
primaryLabel,
|
|
254
|
+
secondaryLabel,
|
|
255
|
+
onPrimaryAction,
|
|
256
|
+
onSecondaryAction,
|
|
257
|
+
"aria-label": ariaLabel,
|
|
258
|
+
children,
|
|
259
|
+
...props
|
|
260
|
+
}) {
|
|
261
|
+
const { trigger, close, triggerRef, anchorSize } = React.useContext(TooltipContext);
|
|
262
|
+
const contentRef = React.useRef(null);
|
|
263
|
+
React.useEffect(() => {
|
|
264
|
+
if (trigger !== "click") return;
|
|
265
|
+
const handleKeyDown = (event) => {
|
|
266
|
+
if (event.key === "Escape") close();
|
|
267
|
+
};
|
|
268
|
+
const handleClickOutside = (event) => {
|
|
269
|
+
const target = event.target;
|
|
270
|
+
const isOutsideContent = contentRef.current && !contentRef.current.contains(target);
|
|
271
|
+
const isOutsideTrigger = triggerRef.current && !triggerRef.current.contains(target);
|
|
272
|
+
if (isOutsideContent && isOutsideTrigger) {
|
|
273
|
+
close();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
const timeoutId = setTimeout(() => {
|
|
277
|
+
document.addEventListener("click", handleClickOutside);
|
|
278
|
+
}, 0);
|
|
279
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
280
|
+
return () => {
|
|
281
|
+
clearTimeout(timeoutId);
|
|
282
|
+
document.removeEventListener("click", handleClickOutside);
|
|
283
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
284
|
+
};
|
|
285
|
+
}, [trigger, close, triggerRef]);
|
|
286
|
+
const isVertical = direction === "top" || direction === "bottom";
|
|
287
|
+
const markerCentre = (isVertical ? MARKER_INSET.inline : MARKER_INSET.block) + MARKER_HALF;
|
|
288
|
+
const anchorExtent = isVertical ? anchorSize.width : anchorSize.height;
|
|
289
|
+
const resolvedAlignOffset = alignOffset ?? (anchorExtent > 0 ? anchorExtent / 2 - markerCentre : 0);
|
|
290
|
+
const derivedLabel = [heading, body, conditionalText].map(textOf).filter(Boolean).join(". ");
|
|
291
|
+
return /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
292
|
+
TooltipPrimitive.Content,
|
|
293
|
+
{
|
|
294
|
+
asChild: true,
|
|
295
|
+
ref: contentRef,
|
|
296
|
+
sideOffset,
|
|
297
|
+
alignOffset: resolvedAlignOffset,
|
|
298
|
+
side: directionToSide[direction],
|
|
299
|
+
align,
|
|
300
|
+
"aria-label": ariaLabel ?? (derivedLabel || void 0),
|
|
301
|
+
...props,
|
|
302
|
+
children: /* @__PURE__ */ jsx(
|
|
303
|
+
TooltipPanel,
|
|
304
|
+
{
|
|
305
|
+
tone,
|
|
306
|
+
direction,
|
|
307
|
+
className,
|
|
308
|
+
heading,
|
|
309
|
+
body,
|
|
310
|
+
conditionalText,
|
|
311
|
+
primaryLabel,
|
|
312
|
+
secondaryLabel,
|
|
313
|
+
onPrimaryAction,
|
|
314
|
+
onSecondaryAction,
|
|
315
|
+
children
|
|
316
|
+
}
|
|
317
|
+
)
|
|
318
|
+
}
|
|
319
|
+
) });
|
|
320
|
+
}
|
|
321
|
+
export {
|
|
322
|
+
Tooltip,
|
|
323
|
+
TooltipContent,
|
|
324
|
+
TooltipPanel,
|
|
325
|
+
TooltipProvider,
|
|
326
|
+
TooltipTrigger,
|
|
327
|
+
tooltipContentVariants
|
|
328
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { cva } from "class-variance-authority";
|
|
4
|
+
import { cn } from "../../lib/utils.js";
|
|
5
|
+
const typographyVariants = cva("", {
|
|
6
|
+
variants: {
|
|
7
|
+
variant: {
|
|
8
|
+
"heading-xlarge": "heading-xlarge",
|
|
9
|
+
"heading-large": "heading-large",
|
|
10
|
+
"heading-medium": "heading-medium",
|
|
11
|
+
"heading-small": "heading-small",
|
|
12
|
+
"heading-xsmall": "heading-xsmall",
|
|
13
|
+
"heading-xxsmall": "heading-xxsmall",
|
|
14
|
+
"body-large": "body-large",
|
|
15
|
+
"body-base": "body-base",
|
|
16
|
+
"body-small": "body-small",
|
|
17
|
+
"overline-large": "overline-large",
|
|
18
|
+
"overline-medium": "overline-medium",
|
|
19
|
+
"overline-small": "overline-small",
|
|
20
|
+
"number-large": "number-large",
|
|
21
|
+
"number-base": "number-base"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
defaultVariants: {
|
|
25
|
+
variant: "body-base"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const defaultElementMap = {
|
|
29
|
+
"heading-xlarge": "h1",
|
|
30
|
+
"heading-large": "h1",
|
|
31
|
+
"heading-medium": "h2",
|
|
32
|
+
"heading-small": "h3",
|
|
33
|
+
"heading-xsmall": "h4",
|
|
34
|
+
"heading-xxsmall": "h5",
|
|
35
|
+
"body-large": "p",
|
|
36
|
+
"body-base": "p",
|
|
37
|
+
"body-small": "p",
|
|
38
|
+
"overline-large": "span",
|
|
39
|
+
"overline-medium": "span",
|
|
40
|
+
"overline-small": "span",
|
|
41
|
+
"number-large": "span",
|
|
42
|
+
"number-base": "span"
|
|
43
|
+
};
|
|
44
|
+
const Text = React.forwardRef(
|
|
45
|
+
({
|
|
46
|
+
className,
|
|
47
|
+
variant = "body-base",
|
|
48
|
+
as,
|
|
49
|
+
loose = false,
|
|
50
|
+
tone = "default",
|
|
51
|
+
strong = false,
|
|
52
|
+
align,
|
|
53
|
+
leading = "default",
|
|
54
|
+
family = "default",
|
|
55
|
+
...props
|
|
56
|
+
}, ref) => {
|
|
57
|
+
const Component = as || defaultElementMap[variant];
|
|
58
|
+
return /* @__PURE__ */ jsx(
|
|
59
|
+
Component,
|
|
60
|
+
{
|
|
61
|
+
ref,
|
|
62
|
+
className: cn(
|
|
63
|
+
typographyVariants({ variant }),
|
|
64
|
+
loose && "typography--loose",
|
|
65
|
+
tone === "muted" && "typo--muted",
|
|
66
|
+
strong && "typo--strong",
|
|
67
|
+
align === "center" && "typo--center",
|
|
68
|
+
leading === "relaxed" && "typo--relaxed",
|
|
69
|
+
family === "sans" && "typo--sans",
|
|
70
|
+
className
|
|
71
|
+
),
|
|
72
|
+
...props
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
Text.displayName = "Text";
|
|
78
|
+
const List = React.forwardRef(
|
|
79
|
+
({ className, ...props }, ref) => {
|
|
80
|
+
return /* @__PURE__ */ jsx("ul", { ref, className: cn("typography-list", className), ...props });
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
List.displayName = "List";
|
|
84
|
+
const ListItem = React.forwardRef(
|
|
85
|
+
({ className, variant = "body-base", children, ...props }, ref) => {
|
|
86
|
+
return /* @__PURE__ */ jsxs(
|
|
87
|
+
"li",
|
|
88
|
+
{
|
|
89
|
+
ref,
|
|
90
|
+
className: cn("typography-list-item", className),
|
|
91
|
+
...props,
|
|
92
|
+
children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
"svg",
|
|
95
|
+
{
|
|
96
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
97
|
+
width: "4",
|
|
98
|
+
height: "4",
|
|
99
|
+
viewBox: "0 0 4 4",
|
|
100
|
+
fill: "none",
|
|
101
|
+
className: "typography-list-bullet",
|
|
102
|
+
"aria-hidden": "true",
|
|
103
|
+
children: /* @__PURE__ */ jsx("circle", { cx: "2", cy: "2", r: "2", fill: "#71747D" })
|
|
104
|
+
}
|
|
105
|
+
),
|
|
106
|
+
/* @__PURE__ */ jsx("span", { className: cn(typographyVariants({ variant })), children })
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
ListItem.displayName = "ListItem";
|
|
113
|
+
export {
|
|
114
|
+
List,
|
|
115
|
+
ListItem,
|
|
116
|
+
Text,
|
|
117
|
+
defaultElementMap,
|
|
118
|
+
typographyVariants
|
|
119
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const MOBILE_BREAKPOINT = 768;
|
|
3
|
+
function useIsMobile() {
|
|
4
|
+
const [isMobile, setIsMobile] = React.useState(
|
|
5
|
+
void 0
|
|
6
|
+
);
|
|
7
|
+
React.useEffect(() => {
|
|
8
|
+
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
|
|
9
|
+
const onChange = () => {
|
|
10
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
11
|
+
};
|
|
12
|
+
mql.addEventListener("change", onChange);
|
|
13
|
+
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
|
|
14
|
+
return () => mql.removeEventListener("change", onChange);
|
|
15
|
+
}, []);
|
|
16
|
+
return !!isMobile;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
useIsMobile
|
|
20
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback } from "react";
|
|
2
|
+
function useSegmentedControl({
|
|
3
|
+
value,
|
|
4
|
+
defaultValue,
|
|
5
|
+
onValueChange
|
|
6
|
+
}) {
|
|
7
|
+
const [internalValue, setInternalValue] = useState(
|
|
8
|
+
value ?? defaultValue
|
|
9
|
+
);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (value !== void 0) {
|
|
12
|
+
setInternalValue(value);
|
|
13
|
+
}
|
|
14
|
+
}, [value]);
|
|
15
|
+
const handleValueChange = useCallback(
|
|
16
|
+
(newValue) => {
|
|
17
|
+
if (value === void 0) {
|
|
18
|
+
setInternalValue(newValue);
|
|
19
|
+
}
|
|
20
|
+
onValueChange == null ? void 0 : onValueChange(newValue);
|
|
21
|
+
},
|
|
22
|
+
[value, onValueChange]
|
|
23
|
+
);
|
|
24
|
+
const currentValue = value ?? internalValue;
|
|
25
|
+
return {
|
|
26
|
+
value: currentValue,
|
|
27
|
+
onValueChange: handleValueChange
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
useSegmentedControl
|
|
32
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useState, useCallback } from "react";
|
|
2
|
+
function useTabs({ tabs, initialTabId }) {
|
|
3
|
+
const initialIndex = tabs.findIndex((tab) => tab.value === initialTabId);
|
|
4
|
+
const [selectedTabIndex, setSelectedTabIndex] = useState(
|
|
5
|
+
initialIndex >= 0 ? initialIndex : 0
|
|
6
|
+
);
|
|
7
|
+
const setSelectedTab = useCallback(([index, direction]) => {
|
|
8
|
+
setSelectedTabIndex(index);
|
|
9
|
+
}, []);
|
|
10
|
+
const selectedTab = tabs[selectedTabIndex] || tabs[0];
|
|
11
|
+
return {
|
|
12
|
+
tabProps: {
|
|
13
|
+
tabs,
|
|
14
|
+
selectedTabIndex,
|
|
15
|
+
setSelectedTab
|
|
16
|
+
},
|
|
17
|
+
selectedTab
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
useTabs
|
|
22
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const TOAST_LIMIT = 1;
|
|
3
|
+
const TOAST_REMOVE_DELAY = 1e6;
|
|
4
|
+
let count = 0;
|
|
5
|
+
function genId() {
|
|
6
|
+
count = (count + 1) % Number.MAX_SAFE_INTEGER;
|
|
7
|
+
return count.toString();
|
|
8
|
+
}
|
|
9
|
+
const toastTimeouts = /* @__PURE__ */ new Map();
|
|
10
|
+
const addToRemoveQueue = (toastId) => {
|
|
11
|
+
if (toastTimeouts.has(toastId)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const timeout = setTimeout(() => {
|
|
15
|
+
toastTimeouts.delete(toastId);
|
|
16
|
+
dispatch({
|
|
17
|
+
type: "REMOVE_TOAST",
|
|
18
|
+
toastId
|
|
19
|
+
});
|
|
20
|
+
}, TOAST_REMOVE_DELAY);
|
|
21
|
+
toastTimeouts.set(toastId, timeout);
|
|
22
|
+
};
|
|
23
|
+
const reducer = (state, action) => {
|
|
24
|
+
switch (action.type) {
|
|
25
|
+
case "ADD_TOAST":
|
|
26
|
+
return {
|
|
27
|
+
...state,
|
|
28
|
+
toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT)
|
|
29
|
+
};
|
|
30
|
+
case "UPDATE_TOAST":
|
|
31
|
+
return {
|
|
32
|
+
...state,
|
|
33
|
+
toasts: state.toasts.map(
|
|
34
|
+
(t) => t.id === action.toast.id ? { ...t, ...action.toast } : t
|
|
35
|
+
)
|
|
36
|
+
};
|
|
37
|
+
case "DISMISS_TOAST": {
|
|
38
|
+
const { toastId } = action;
|
|
39
|
+
if (toastId) {
|
|
40
|
+
addToRemoveQueue(toastId);
|
|
41
|
+
} else {
|
|
42
|
+
state.toasts.forEach((toast2) => {
|
|
43
|
+
addToRemoveQueue(toast2.id);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...state,
|
|
48
|
+
toasts: state.toasts.map(
|
|
49
|
+
(t) => t.id === toastId || toastId === void 0 ? {
|
|
50
|
+
...t,
|
|
51
|
+
open: false
|
|
52
|
+
} : t
|
|
53
|
+
)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
case "REMOVE_TOAST":
|
|
57
|
+
if (action.toastId === void 0) {
|
|
58
|
+
return {
|
|
59
|
+
...state,
|
|
60
|
+
toasts: []
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...state,
|
|
65
|
+
toasts: state.toasts.filter((t) => t.id !== action.toastId)
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const listeners = [];
|
|
70
|
+
let memoryState = { toasts: [] };
|
|
71
|
+
function dispatch(action) {
|
|
72
|
+
memoryState = reducer(memoryState, action);
|
|
73
|
+
listeners.forEach((listener) => {
|
|
74
|
+
listener(memoryState);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function toast({ ...props }) {
|
|
78
|
+
const id = genId();
|
|
79
|
+
const update = (props2) => dispatch({
|
|
80
|
+
type: "UPDATE_TOAST",
|
|
81
|
+
toast: { ...props2, id }
|
|
82
|
+
});
|
|
83
|
+
const dismiss = () => dispatch({ type: "DISMISS_TOAST", toastId: id });
|
|
84
|
+
dispatch({
|
|
85
|
+
type: "ADD_TOAST",
|
|
86
|
+
toast: {
|
|
87
|
+
...props,
|
|
88
|
+
id,
|
|
89
|
+
open: true,
|
|
90
|
+
onOpenChange: (open) => {
|
|
91
|
+
if (!open) dismiss();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
id,
|
|
97
|
+
dismiss,
|
|
98
|
+
update
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function useToast() {
|
|
102
|
+
const [state, setState] = React.useState(memoryState);
|
|
103
|
+
React.useEffect(() => {
|
|
104
|
+
listeners.push(setState);
|
|
105
|
+
return () => {
|
|
106
|
+
const index = listeners.indexOf(setState);
|
|
107
|
+
if (index > -1) {
|
|
108
|
+
listeners.splice(index, 1);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}, [state]);
|
|
112
|
+
return {
|
|
113
|
+
...state,
|
|
114
|
+
toast,
|
|
115
|
+
dismiss: (toastId) => dispatch({ type: "DISMISS_TOAST", toastId })
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
reducer,
|
|
120
|
+
toast,
|
|
121
|
+
useToast
|
|
122
|
+
};
|