colibri-ui 0.8.86 → 0.8.87

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.
@@ -11,6 +11,14 @@ var React__default = /*#__PURE__*/_interopDefault(React);
11
11
  var clsx__default = /*#__PURE__*/_interopDefault(clsx);
12
12
  var styles__default = /*#__PURE__*/_interopDefault(styles);
13
13
 
14
+ const getSizeClassNames = size => {
15
+ if (!size) return [];
16
+ if (typeof size === "string") return [styles__default.default[`size_${size}`]];
17
+ return Object.entries(size).flatMap(([breakpoint, name]) => {
18
+ if (!name) return [];
19
+ return [styles__default.default[breakpoint === "base" ? `size_${name}` : `size_${breakpoint}_${name}`]];
20
+ });
21
+ };
14
22
  const Typography = _a => {
15
23
  var {
16
24
  tag: Component = "span",
@@ -27,8 +35,7 @@ const Typography = _a => {
27
35
  style: lines ? Object.assign(Object.assign({}, style), {
28
36
  "--typography-lines": lines
29
37
  }) : Object.assign({}, style),
30
- className: clsx__default.default({
31
- [styles__default.default[`size_${size}`]]: Boolean(size),
38
+ className: clsx__default.default(getSizeClassNames(size), {
32
39
  [styles__default.default[`font-weight_${fontWeight}`]]: Boolean(fontWeight),
33
40
  [styles__default.default[`variant_${variant}`]]: Boolean(variant),
34
41
  [styles__default.default.clamp]: Boolean(lines)
@@ -1,7 +1,15 @@
1
1
  import type { CSSProperties } from "react";
2
+ import type { BreakpointName } from "../Theme";
2
3
  export type TypographyVariant = "primary" | "secondary" | "tertiary" | "disabled" | "inverse" | "alert" | "success" | "warning" | "info";
3
4
  export type TypographyFontWeight = "normal" | "regular" | "medium" | "semibold" | "bold";
4
5
  export type TypographySize = "xs" | "s" | "m" | "l" | "text-xs" | "text-sm" | "text-md" | "text-lg" | "heading-sm" | "heading-md" | "heading-lg" | "heading-xl" | "display-sm" | "display-md" | "display-lg" | "display-xl" | "display-s" | "display-m" | "display-l" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
6
+ /**
7
+ * Size per breakpoint, mobile first: `base` applies to every width, each
8
+ * breakpoint from its width up (`BREAKPOINTS` in Theme).
9
+ */
10
+ export type TypographyResponsiveSize = {
11
+ base?: TypographySize;
12
+ } & Partial<Record<BreakpointName, TypographySize>>;
5
13
  export type TypographyTag = "span" | "label" | "legend" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "s";
6
14
  export type TypographyProps = {
7
15
  className?: string;
@@ -10,7 +18,8 @@ export type TypographyProps = {
10
18
  id?: string;
11
19
  tag?: TypographyTag;
12
20
  variant?: TypographyVariant;
13
- size?: TypographySize;
21
+ /** One size, or sizes per breakpoint: `{ base: "xs", sm: "m" }`. */
22
+ size?: TypographySize | TypographyResponsiveSize;
14
23
  fontWeight?: TypographyFontWeight;
15
24
  /** Limits the text to this many lines and ends the last one with an ellipsis. */
16
25
  lines?: number;
@@ -27,17 +27,23 @@ const Drawer = /*#__PURE__*/forwardRef(function DrawerRoot(_a, forwardedRef) {
27
27
  focusAfterRef,
28
28
  portalContainer,
29
29
  onClose,
30
+ onClosed,
30
31
  onEscKeyDown,
31
32
  onOverlayClick,
32
33
  className,
33
34
  style,
34
35
  children
35
36
  } = _a,
36
- rest = __rest(_a, ["opened", "placement", "width", "height", "offset", "zIndex", "asModal", "withBlur", "closeOnEsc", "closeOnOverlayClick", "borderRadius", "customBackgroundColor", "customContentBackgroundColor", "animationInfo", "initialFocusRef", "focusAfterRef", "portalContainer", "onClose", "onEscKeyDown", "onOverlayClick", "className", "style", "children"]);
37
+ rest = __rest(_a, ["opened", "placement", "width", "height", "offset", "zIndex", "asModal", "withBlur", "closeOnEsc", "closeOnOverlayClick", "borderRadius", "customBackgroundColor", "customContentBackgroundColor", "animationInfo", "initialFocusRef", "focusAfterRef", "portalContainer", "onClose", "onClosed", "onEscKeyDown", "onOverlayClick", "className", "style", "children"]);
37
38
  const panelRef = useRef(null);
38
39
  const previousFocus = useRef(null);
39
40
  const [rendered, setRendered] = useState(opened);
40
41
  const [closing, setClosing] = useState(false);
42
+ // The latest callback without restarting the closing timer.
43
+ const onClosedRef = useRef(onClosed);
44
+ useEffect(() => {
45
+ onClosedRef.current = onClosed;
46
+ }, [onClosed]);
41
47
  const setPanelRef = element => {
42
48
  panelRef.current = element;
43
49
  if (typeof forwardedRef === "function") forwardedRef(element);else if (forwardedRef) forwardedRef.current = element;
@@ -51,8 +57,10 @@ const Drawer = /*#__PURE__*/forwardRef(function DrawerRoot(_a, forwardedRef) {
51
57
  if (!rendered) return;
52
58
  setClosing(true);
53
59
  const timeout = window.setTimeout(() => {
60
+ var _a;
54
61
  setRendered(false);
55
62
  setClosing(false);
63
+ (_a = onClosedRef.current) === null || _a === void 0 ? void 0 : _a.call(onClosedRef);
56
64
  }, 200);
57
65
  return () => window.clearTimeout(timeout);
58
66
  }, [opened, rendered]);
@@ -24,6 +24,8 @@ export interface DrawerProps extends Omit<HTMLAttributes<HTMLDivElement>, "onAni
24
24
  focusAfterRef?: RefObject<HTMLElement | null>;
25
25
  portalContainer?: HTMLElement | null;
26
26
  onClose?: () => void;
27
+ /** Called once the closing animation has finished and the drawer is removed. */
28
+ onClosed?: () => void;
27
29
  onEscKeyDown?: (event: KeyboardEvent) => void;
28
30
  onOverlayClick?: MouseEventHandler<HTMLDivElement>;
29
31
  }
@@ -24,6 +24,7 @@ const Sheet = /*#__PURE__*/forwardRef(function SheetComponent(_a, forwardedRef)
24
24
  var {
25
25
  open,
26
26
  onOpenChange,
27
+ onClosed,
27
28
  title,
28
29
  description,
29
30
  header,
@@ -50,7 +51,7 @@ const Sheet = /*#__PURE__*/forwardRef(function SheetComponent(_a, forwardedRef)
50
51
  "aria-labelledby": ariaLabelledBy,
51
52
  "aria-describedby": ariaDescribedBy
52
53
  } = _a,
53
- rest = __rest(_a, ["open", "onOpenChange", "title", "description", "header", "footer", "snapPoints", "snapPoint", "defaultSnapPoint", "onSnapPointChange", "modal", "blurOverlay", "closeOnOverlayClick", "closeOnEscape", "draggable", "showHandle", "lockBodyScroll", "portalContainer", "initialFocusRef", "returnFocusRef", "zIndex", "className", "style", "children", "aria-label", "aria-labelledby", "aria-describedby"]);
54
+ rest = __rest(_a, ["open", "onOpenChange", "onClosed", "title", "description", "header", "footer", "snapPoints", "snapPoint", "defaultSnapPoint", "onSnapPointChange", "modal", "blurOverlay", "closeOnOverlayClick", "closeOnEscape", "draggable", "showHandle", "lockBodyScroll", "portalContainer", "initialFocusRef", "returnFocusRef", "zIndex", "className", "style", "children", "aria-label", "aria-labelledby", "aria-describedby"]);
54
55
  const normalizedPoints = snapPoints.length ? snapPoints : defaultSnapPoints;
55
56
  const controlledSnap = snapPoint !== undefined;
56
57
  const [internalSnap, setInternalSnap] = useState(() => findPoint(normalizedPoints, defaultSnapPoint));
@@ -80,6 +81,11 @@ const Sheet = /*#__PURE__*/forwardRef(function SheetComponent(_a, forwardedRef)
80
81
  if (!controlledSnap) setInternalSnap(next);
81
82
  onSnapPointChange === null || onSnapPointChange === void 0 ? void 0 : onSnapPointChange(next);
82
83
  };
84
+ // The latest callback without restarting the closing timer.
85
+ const onClosedRef = useRef(onClosed);
86
+ useEffect(() => {
87
+ onClosedRef.current = onClosed;
88
+ }, [onClosed]);
83
89
  useEffect(() => {
84
90
  if (open) {
85
91
  setRendered(true);
@@ -90,8 +96,10 @@ const Sheet = /*#__PURE__*/forwardRef(function SheetComponent(_a, forwardedRef)
90
96
  setClosing(true);
91
97
  const duration = panelRef.current ? Number.parseFloat(getComputedStyle(panelRef.current).animationDuration) * 1000 : 220;
92
98
  const timer = window.setTimeout(() => {
99
+ var _a;
93
100
  setRendered(false);
94
101
  setClosing(false);
102
+ (_a = onClosedRef.current) === null || _a === void 0 ? void 0 : _a.call(onClosedRef);
95
103
  }, Number.isFinite(duration) ? duration : 220);
96
104
  return () => window.clearTimeout(timer);
97
105
  }, [open, rendered]);
@@ -4,6 +4,8 @@ export type SheetCloseReason = "overlay" | "escape" | "drag";
4
4
  export interface SheetProps extends Omit<HTMLAttributes<HTMLDivElement>, "title" | "onChange"> {
5
5
  open: boolean;
6
6
  onOpenChange: (open: boolean, reason?: SheetCloseReason) => void;
7
+ /** Called once the closing animation has finished and the sheet is removed. */
8
+ onClosed?: () => void;
7
9
  title?: ReactNode;
8
10
  description?: ReactNode;
9
11
  header?: ReactNode;