@youngonesworks/ui 1.0.11 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -55,6 +55,8 @@ export { Textarea } from './components/textArea';
55
55
  export { TextInput } from './components/textInput';
56
56
  export { ThemeIcon } from './components/themeIcon';
57
57
  export { TimeInput } from './components/timeInput';
58
+ export type { IToast, TToastType } from './components/toast';
59
+ export { ToastProvider, useToast } from './components/toast';
58
60
  export { Toggle } from './components/toggle';
59
61
  export { Tooltip } from './components/tooltip';
60
62
  export { TruncatedText } from './components/truncatedText';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import * as React$1 from "react";
3
- import React, { Fragment, cloneElement, createRef, forwardRef, isValidElement, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
3
+ import React, { Fragment, cloneElement, createContext, createRef, forwardRef, isValidElement, useCallback, useContext, useEffect, useImperativeHandle, useMemo, useReducer, useRef, useState } from "react";
4
4
  import { IconAlertCircle, IconAlertTriangle, IconArrowNarrowLeft, IconBold, IconCalendar, IconCheck, IconChevronDown, IconChevronLeft, IconChevronRight, IconChevronUp, IconCircleCheck, IconClearFormatting, IconDotsVertical, IconEyeCheck, IconEyeOff, IconFilter, IconHeart, IconHeartFilled, IconItalic, IconList, IconListNumbers, IconMessageDots, IconSearch, IconSelector, IconUnderline, IconX } from "@tabler/icons-react";
5
5
  import clsx from "clsx";
6
6
  import { twMerge } from "tailwind-merge";
@@ -251,34 +251,35 @@ function formatIcon(icon, defaultFormatAttributes) {
251
251
  }
252
252
  //#endregion
253
253
  //#region src/components/actionIcon/index.tsx
254
- const ActionIcon = ({ ref, title, disabled = false, styleVariant = "default", icon, type = "button", "data-testid": testId, iconSize = 20, strokeWidth = 1, onClick, className, ...props }) => {
254
+ const ActionIcon = ({ ref, title, disabled = false, styleVariant = "default", icon, type = "button", tooltipTitle, "data-testid": testId, iconSize = 20, strokeWidth = 1, onClick, className, ...props }) => {
255
255
  const variantClassNames = clsx({
256
256
  "active:translate-y-[1px] content-center flex items-center justify-center rounded-[4px] border border-gray-200 hover:border-black text-black child:p-10 w-[36px] h-[36px] disabled:text-gray-500": styleVariant === ACTION_ICON_STYLE_VARIANT.DEFAULT,
257
257
  "active:translate-y-[1px] border-none content-center flex items-center justify-center rounded-[4px] border text-black child:p-10 w-[36px] h-[36px] disabled:text-gray-500": styleVariant === ACTION_ICON_STYLE_VARIANT.TRANSPARENT,
258
258
  "active:translate-y-[1px] content-center flex items-center justify-center rounded-[4px] child:p-10 w-[37px] h-[37px] text-black rounded-full bg-primary hover:bg-turquoise-700 disabled:turquoise-50 disabled:text-gray-800": styleVariant === ACTION_ICON_STYLE_VARIANT.ROUND,
259
259
  "w-7 h-7 active:translate-y-[1px] content-center flex items-center justify-center rounded-[4px] border border-gray-200 hover:border-black text-black hover:bg-ultra-light-blue-gray disabled:text-gray-500": styleVariant === ACTION_ICON_STYLE_VARIANT.SMALL
260
260
  });
261
- return /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(Tooltip, {
261
+ const renderButton = () => /* @__PURE__ */ jsx("button", {
262
+ title,
263
+ type,
264
+ disabled,
265
+ "data-testid": testId,
266
+ "data-component": "ActionIcon",
267
+ className: cn(variantClassNames, { "hover:bg-transparant cursor-not-allowed hover:border-gray-200": disabled }, className),
268
+ onClick,
269
+ ref,
270
+ "data-tooltip-id": tooltipTitle,
271
+ "data-tooltip-content": tooltipTitle,
272
+ ...props,
273
+ children: icon ? formatIcon(icon, {
274
+ stroke: strokeWidth,
275
+ size: iconSize
276
+ }) : props.children
277
+ });
278
+ return tooltipTitle ? /* @__PURE__ */ jsx(Tooltip, {
262
279
  size: "sm",
263
- content: title,
264
- children: /* @__PURE__ */ jsx("button", {
265
- title,
266
- type,
267
- disabled,
268
- "data-testid": testId,
269
- "data-component": "ActionIcon",
270
- className: cn(variantClassNames, { "hover:bg-transparant cursor-not-allowed hover:border-gray-200": disabled }, className),
271
- onClick,
272
- ref,
273
- "data-tooltip-id": title,
274
- "data-tooltip-content": title,
275
- ...props,
276
- children: icon ? formatIcon(icon, {
277
- stroke: strokeWidth,
278
- size: iconSize
279
- }) : props.children
280
- })
281
- }) });
280
+ content: tooltipTitle,
281
+ children: renderButton()
282
+ }) : renderButton();
282
283
  };
283
284
  ActionIcon.displayName = "ActionIcon";
284
285
  //#endregion
@@ -1219,6 +1220,7 @@ const Divider = ({ className, ...props }) => /* @__PURE__ */ jsx("div", {
1219
1220
  const FavouriteButton = forwardRef((props, ref) => {
1220
1221
  const { onClick, favourite, iconFilled, iconOutline, favouriteTitle, iconColorSelected = "text-secondary", iconColor = "text-gray-800", iconSize, className = "", styleVariant = "transparent", children, ...rest } = props;
1221
1222
  return /* @__PURE__ */ jsx(ActionIcon, {
1223
+ tooltipTitle: favouriteTitle || "Favorite",
1222
1224
  onClick,
1223
1225
  "data-component": "favouriteButton",
1224
1226
  title: favouriteTitle || "Favorite",
@@ -1788,12 +1790,12 @@ const Modal = ({ title, children, withCloseButton = true, opened, additionalClas
1788
1790
  /* @__PURE__ */ jsx("div", {
1789
1791
  className: "relative z-10 w-full",
1790
1792
  children: withCloseButton && /* @__PURE__ */ jsx(ActionIcon, {
1793
+ title: "Close modal",
1791
1794
  onClick: handleClose,
1792
- "aria-label": "close modal",
1795
+ "aria-label": "Close modal",
1793
1796
  className: "absolute top-0 right-0",
1794
1797
  "data-testid": "close-modal",
1795
- icon: /* @__PURE__ */ jsx(IconX, {}),
1796
- title: "Close modal"
1798
+ icon: /* @__PURE__ */ jsx(IconX, {})
1797
1799
  })
1798
1800
  }),
1799
1801
  title && /* @__PURE__ */ jsx("div", {
@@ -2885,6 +2887,132 @@ const TimeInput = forwardRef(({ label, error, withSeconds, className = "", ...pr
2885
2887
  });
2886
2888
  });
2887
2889
  //#endregion
2890
+ //#region src/components/toast/Toast.tsx
2891
+ const Toast = ({ toast, onClose }) => {
2892
+ const icon = useMemo(() => {
2893
+ switch (toast.type) {
2894
+ case "success": return /* @__PURE__ */ jsx(IconCircleCheck, {
2895
+ className: "text-navy-blue",
2896
+ stroke: 2,
2897
+ size: 26
2898
+ });
2899
+ case "warning": return /* @__PURE__ */ jsx(IconAlertCircle, {
2900
+ className: "text-warning",
2901
+ size: 26
2902
+ });
2903
+ case "error": return /* @__PURE__ */ jsx(IconAlertCircle, {
2904
+ className: "text-red-500",
2905
+ size: 26
2906
+ });
2907
+ default: return null;
2908
+ }
2909
+ }, [toast.type]);
2910
+ return /* @__PURE__ */ jsx("div", {
2911
+ "data-testid": `toast-${toast.type || "default"}`,
2912
+ className: "bg-gradient-blue-turquoise mb-4 w-full max-w-[1400px] rounded p-px drop-shadow-sm",
2913
+ children: /* @__PURE__ */ jsxs("div", {
2914
+ "data-testid": "toast-content",
2915
+ className: cn("flex w-full max-w-[1400px] min-w-[350px] items-center justify-between", "gap-6 rounded-[0.20rem] bg-white p-5 md:gap-12"),
2916
+ children: [/* @__PURE__ */ jsxs("div", {
2917
+ className: "flex items-center gap-6",
2918
+ children: [icon && /* @__PURE__ */ jsx("div", {
2919
+ "data-testid": "toast-icon",
2920
+ children: icon
2921
+ }), /* @__PURE__ */ jsx("p", {
2922
+ "data-testid": "toast-message",
2923
+ className: "yo-text-body m-0 text-black",
2924
+ children: toast.message
2925
+ })]
2926
+ }), /* @__PURE__ */ jsx(ActionIcon, {
2927
+ styleVariant: "transparent",
2928
+ onClick: onClose,
2929
+ title: "",
2930
+ "aria-label": "Close",
2931
+ className: "text-inherit",
2932
+ "data-testid": "closeToast",
2933
+ icon: /* @__PURE__ */ jsx(IconX, { size: 20 })
2934
+ })]
2935
+ })
2936
+ }, toast.id);
2937
+ };
2938
+ Toast.displayName = "Toast";
2939
+ //#endregion
2940
+ //#region src/components/toast/ToastContext.tsx
2941
+ const ToastStateContext = createContext([]);
2942
+ const ToastDispatchContext = createContext(void 0);
2943
+ const useToastDispatchContext = () => useContext(ToastDispatchContext);
2944
+ //#endregion
2945
+ //#region src/components/toast/ToastProvider.tsx
2946
+ const toastReducer = (state, action) => {
2947
+ switch (action.type) {
2948
+ case "ADD": return [action.toast, ...state];
2949
+ case "DELETE": return state.filter((t) => t.id !== action.toast.id);
2950
+ }
2951
+ };
2952
+ const toastTimers = /* @__PURE__ */ new Map();
2953
+ const ToastProvider = ({ children, autoDelete = true, dismissTime = 5e3 }) => {
2954
+ const [toasts, dispatch] = useReducer(toastReducer, []);
2955
+ useEffect(() => {
2956
+ if (!autoDelete) return;
2957
+ for (const toast of toasts) if (toast.timeout !== false && !toastTimers.has(toast.id)) {
2958
+ const timer = setTimeout(() => {
2959
+ dispatch({
2960
+ type: "DELETE",
2961
+ toast: { id: toast.id }
2962
+ });
2963
+ toastTimers.delete(toast.id);
2964
+ }, toast.timeout ?? dismissTime);
2965
+ toastTimers.set(toast.id, timer);
2966
+ }
2967
+ }, [
2968
+ autoDelete,
2969
+ dismissTime,
2970
+ toasts
2971
+ ]);
2972
+ return /* @__PURE__ */ jsx(ToastStateContext.Provider, {
2973
+ value: toasts,
2974
+ children: /* @__PURE__ */ jsxs(ToastDispatchContext.Provider, {
2975
+ value: dispatch,
2976
+ children: [children, toasts.length > 0 && /* @__PURE__ */ jsx("div", {
2977
+ "data-component": "ToastContainer",
2978
+ className: "fixed top-8 left-1/2 z-1000 -translate-x-1/2",
2979
+ children: toasts.map((toast) => /* @__PURE__ */ jsx(Toast, {
2980
+ toast,
2981
+ onClose: () => dispatch({
2982
+ type: "DELETE",
2983
+ toast: { id: toast.id }
2984
+ })
2985
+ }, toast.id))
2986
+ })]
2987
+ })
2988
+ });
2989
+ };
2990
+ ToastProvider.displayName = "ToastProvider";
2991
+ //#endregion
2992
+ //#region src/components/toast/useToast.tsx
2993
+ const useToast = () => {
2994
+ const dispatch = useToastDispatchContext();
2995
+ return {
2996
+ addToast: useCallback(({ message, type, timeout }) => {
2997
+ dispatch?.({
2998
+ type: "ADD",
2999
+ toast: {
3000
+ id: crypto.randomUUID(),
3001
+ message,
3002
+ type,
3003
+ timeout
3004
+ }
3005
+ });
3006
+ }, [dispatch]),
3007
+ deleteToast: useCallback((id) => {
3008
+ dispatch?.({
3009
+ type: "DELETE",
3010
+ toast: { id }
3011
+ });
3012
+ }, [dispatch])
3013
+ };
3014
+ };
3015
+ //#endregion
2888
3016
  //#region src/components/toggle/index.tsx
2889
3017
  const Toggle = ({ onClick, value, disabled = false }) => {
2890
3018
  const handleToggle = (e) => {
@@ -3460,6 +3588,6 @@ const WysiwygEditor = forwardRef(({ id, content, className, placeholder, onChang
3460
3588
  })] });
3461
3589
  });
3462
3590
  //#endregion
3463
- export { AccordionItem, AccordionWrapper, ActionIcon, Alert, AppleAppButtonIcon, AutoCompleteInput, Avatar, AvatarIndicator, Badge, BigBadge, BreadCrumb, Button, Checkbox, DatePickerInput, Divider, FavouriteButton, Filters, GoogleAppButtonIcon, HR, HamburgerMenuButton, Island, KebabMenu, Label, Loader, LogoBlack, Modal, NavButtons, NumberField, NumberedStepper, PageUnavailable, PasswordInput, PhoneInput, Popover, ProfileMenu, ProgressBar, RadioButton, Rating, RegionSelector, Reviews, ScrollToTop, SearchInput, Select, SettingsCard, Skeleton, SkillPill, Stepper, StickyMobileButtonWrapper, Table, TableCell, TableHeader, TableHeaderItem, TableHeaderRow, TableRow, TabsBadge, TabsWrapper, TextInput, Textarea, ThemeIcon, TimeInput, Toggle, Tooltip, TruncatedText, UnorderedList, UnorderedListItem, UnstyledButton, WysiwygEditor, buttonVariants };
3591
+ export { AccordionItem, AccordionWrapper, ActionIcon, Alert, AppleAppButtonIcon, AutoCompleteInput, Avatar, AvatarIndicator, Badge, BigBadge, BreadCrumb, Button, Checkbox, DatePickerInput, Divider, FavouriteButton, Filters, GoogleAppButtonIcon, HR, HamburgerMenuButton, Island, KebabMenu, Label, Loader, LogoBlack, Modal, NavButtons, NumberField, NumberedStepper, PageUnavailable, PasswordInput, PhoneInput, Popover, ProfileMenu, ProgressBar, RadioButton, Rating, RegionSelector, Reviews, ScrollToTop, SearchInput, Select, SettingsCard, Skeleton, SkillPill, Stepper, StickyMobileButtonWrapper, Table, TableCell, TableHeader, TableHeaderItem, TableHeaderRow, TableRow, TabsBadge, TabsWrapper, TextInput, Textarea, ThemeIcon, TimeInput, ToastProvider, Toggle, Tooltip, TruncatedText, UnorderedList, UnorderedListItem, UnstyledButton, WysiwygEditor, buttonVariants, useToast };
3464
3592
 
3465
3593
  //# sourceMappingURL=index.js.map