@konstructio/ui 0.1.5 → 0.1.7

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.
@@ -0,0 +1,94 @@
1
+ "use client";
2
+ import { t as C } from "../../../../utils-DnIJruo0.js";
3
+ import { useEffect as O, useLayoutEffect as L, useRef as c } from "react";
4
+ import { jsx as j } from "react/jsx-runtime";
5
+ import { animate as y, motion as G, useMotionValue as M } from "motion/react";
6
+ var h = "100%", u = {
7
+ type: "spring",
8
+ stiffness: 380,
9
+ damping: 38
10
+ }, E = { duration: 0 }, V = 0.05, l = (t) => typeof t == "number" ? t : t.direction, P = "-30%", W = {
11
+ enter: (t) => l(t) > 0 ? {
12
+ x: h,
13
+ opacity: 1,
14
+ zIndex: 1
15
+ } : {
16
+ x: P,
17
+ opacity: 1,
18
+ zIndex: 0
19
+ },
20
+ center: (t) => ({
21
+ x: 0,
22
+ opacity: 1,
23
+ zIndex: l(t) > 0 ? 1 : 0
24
+ }),
25
+ exit: (t) => typeof t == "object" && t.instant ? {
26
+ opacity: 0,
27
+ transition: E
28
+ } : l(t) > 0 ? {
29
+ x: P,
30
+ opacity: 1,
31
+ zIndex: 0
32
+ } : {
33
+ x: h,
34
+ opacity: 1,
35
+ zIndex: 1
36
+ }
37
+ }, D = ({ step: t, direction: R, animated: s, canSwipeBack: r, onMount: I, commitSignal: f, isArmed: S, onBackStart: m, onBackMove: A, onBackEnd: T, onBackCommit: g, onBackCancel: N, children: _ }) => {
38
+ const n = M(0), a = c(null), o = c(!1), d = c(f);
39
+ L(() => {
40
+ I(a.current?.getBoundingClientRect().height ?? 0);
41
+ }, []);
42
+ const x = () => {
43
+ const i = n.get();
44
+ if (typeof i == "string") {
45
+ const e = a.current?.offsetWidth ?? 0;
46
+ n.set(parseFloat(i) / 100 * e || 0);
47
+ }
48
+ }, p = () => {
49
+ n.stop(), x(), y(n, a.current?.offsetWidth ?? 0, {
50
+ ...u,
51
+ onComplete: g
52
+ });
53
+ };
54
+ O(() => {
55
+ d.current !== f && (d.current = f, p());
56
+ }, [f]);
57
+ const b = (i, e) => {
58
+ o.current = r && S(e), o.current && (n.stop(), x(), m());
59
+ }, z = (i, e) => {
60
+ if (!o.current) return;
61
+ const v = e.offset.x >= 0 ? e.offset.x : e.offset.x * V;
62
+ n.set(v), A(Math.max(v, 0));
63
+ }, F = (i, e) => {
64
+ if (o.current) {
65
+ if (o.current = !1, T(e) === "back") {
66
+ p();
67
+ return;
68
+ }
69
+ y(n, 0, {
70
+ ...u,
71
+ onComplete: N
72
+ });
73
+ }
74
+ };
75
+ return /* @__PURE__ */ j(G.div, {
76
+ ref: a,
77
+ custom: R,
78
+ className: C("relative flex w-full flex-col bg-white dark:bg-metal-800", r && "touch-pan-y"),
79
+ style: { x: n },
80
+ variants: s ? W : void 0,
81
+ initial: s ? "enter" : !1,
82
+ animate: "center",
83
+ exit: s ? "exit" : void 0,
84
+ transition: s ? u : E,
85
+ onPanStart: r ? b : void 0,
86
+ onPan: r ? z : void 0,
87
+ onPanEnd: r ? F : void 0,
88
+ children: _
89
+ }, t);
90
+ };
91
+ D.displayName = "KonstructSheetStep";
92
+ export {
93
+ D as SheetStep
94
+ };
@@ -0,0 +1,4 @@
1
+ import { SheetStep as t } from "./SheetStep/SheetStep.js";
2
+ export {
3
+ t as SheetStep
4
+ };
@@ -1,10 +1,37 @@
1
- var I = 0.25, i = 500;
2
- function c({ offset: e, velocity: n, panelHeight: o, position: S }) {
3
- const s = S === "bottom" ? 1 : -1, t = e * s, r = n * s;
4
- return t <= 0 ? !1 : t > o * 0.25 || r > 500;
1
+ var c = 0.25, f = 500;
2
+ function r({ offset: n, velocity: e, position: t }) {
3
+ const s = t === "bottom" ? 1 : -1;
4
+ return {
5
+ distance: n * s,
6
+ speed: e * s
7
+ };
8
+ }
9
+ function i(n, e, t) {
10
+ return n > t * 0.25 || e > 500;
11
+ }
12
+ function u(n) {
13
+ const { distance: e, speed: t } = r(n);
14
+ return e <= 0 ? !1 : i(e, t, n.panelHeight);
15
+ }
16
+ function d(n) {
17
+ const { distance: e, speed: t } = r(n);
18
+ return e >= 0 ? !1 : i(-e, -t, n.panelHeight);
19
+ }
20
+ function l({ offset: n, velocity: e, panelWidth: t }) {
21
+ return n <= 0 ? !1 : i(n, e, t);
22
+ }
23
+ function p({ expandable: n, isExpanded: e, restHeight: t = 0, ...s }) {
24
+ if (n && !e && d(s)) return "expand";
25
+ if (!u(s)) return "rest";
26
+ if (!e) return "dismiss";
27
+ const { distance: o } = r(s), a = o - (s.panelHeight - t) > t * c;
28
+ return t > 0 && a ? "dismiss" : "collapse";
5
29
  }
6
30
  export {
7
- I as DISMISS_DISTANCE_RATIO,
8
- i as DISMISS_VELOCITY,
9
- c as shouldDismissSheet
31
+ c as DISMISS_DISTANCE_RATIO,
32
+ f as DISMISS_VELOCITY,
33
+ p as resolveSheetGesture,
34
+ u as shouldDismissSheet,
35
+ d as shouldExpandSheet,
36
+ l as shouldSwipeBack
10
37
  };
@@ -1,11 +1,11 @@
1
1
  import { t } from "../../dist-B9GE4SXf.js";
2
- var e = t([""], {
2
+ var r = t([""], {
3
3
  variants: { variant: {
4
4
  horizontal: "",
5
5
  vertical: "flex gap-6"
6
6
  } },
7
7
  defaultVariants: { variant: "horizontal" }
8
- }), r = t([""], {
8
+ }), e = t([""], {
9
9
  variants: { variant: { default: "" } },
10
10
  defaultVariants: { variant: "default" }
11
11
  }), i = t(["flex"], {
@@ -17,9 +17,6 @@ var e = t([""], {
17
17
  defaultVariants: { variant: "default" }
18
18
  }), f = t([
19
19
  "cursor-pointer",
20
- "relative",
21
- "tap-target",
22
- "touch-hit-area",
23
20
  "h-[27px]",
24
21
  "w-fit",
25
22
  "block",
@@ -66,8 +63,8 @@ var e = t([""], {
66
63
  defaultVariants: { variant: "default" }
67
64
  });
68
65
  export {
69
- r as contentVariants,
66
+ e as contentVariants,
70
67
  i as listVariants,
71
- e as rootVariants,
68
+ r as rootVariants,
72
69
  f as triggerVariants
73
70
  };
@@ -1,19 +1,19 @@
1
- import { i as t } from "../../../dist-DeWnSzlM.js";
1
+ import { i as o } from "../../../dist-DeWnSzlM.js";
2
2
  import { Typography as s } from "../../Typography/Typography.js";
3
3
  import { t as n } from "../../../utils-DnIJruo0.js";
4
4
  import { triggerVariants as u } from "../Tabs.variants.js";
5
5
  import { jsx as i } from "react/jsx-runtime";
6
- var l = (r) => r === void 0 ? "auto" : r ? "active" : "inactive", m = ({ tab: r, label: o, isActive: a, className: e }) => /* @__PURE__ */ i(t, {
6
+ var l = (r) => r === void 0 ? "auto" : r ? "active" : "inactive", m = ({ tab: r, label: a, isActive: t, className: e }) => /* @__PURE__ */ i(o, {
7
7
  value: r,
8
- className: "group/tab rounded-xs outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-aurora-500 kubefirst:focus-visible:outline-kubefirst-primary",
8
+ className: "group/tab relative tap-target touch-hit-area rounded-xs outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-aurora-500 kubefirst:focus-visible:outline-kubefirst-primary",
9
9
  children: /* @__PURE__ */ i(s, {
10
10
  variant: "body2",
11
11
  component: "span",
12
12
  className: n(u({
13
- variant: l(a),
13
+ variant: l(t),
14
14
  className: e
15
15
  })),
16
- children: o
16
+ children: a
17
17
  })
18
18
  });
19
19
  m.displayName = "KonstructTabsTrigger";
@@ -36,7 +36,7 @@ var j = {
36
36
  return /* @__PURE__ */ r("th", {
37
37
  scope: "col",
38
38
  ref: b ? D(e.id) : void 0,
39
- className: t("kvt-header-cell", "px-4", "py-3", "text-left", "text-xs", !o && !a && "first:rounded-tl-lg", !o && !a && "last:rounded-tr-lg", !o && a && k(d, g, H), "border-transparent", "dark:border-t", "dark:border-metal-700", !a && "dark:first:border-l", !a && "dark:last:border-r", a && k(d, g, L), b && "bg-slate-100 dark:bg-metal-800", h.className, f && O[f], _),
39
+ className: t("kvt-header-cell", "px-4", "py-3", "text-left", "text-xs", !o && !a && "first:rounded-tl-lg", !o && !a && "last:rounded-tr-lg", !o && a && k(d, g, H), "border-transparent", "dark:border-t", "dark:border-metal-700", !a && "dark:first:border-l", !a && "dark:last:border-r", a && k(d, g, L), b && "z-1 bg-slate-100 dark:bg-metal-800", h.className, f && O[f], _),
40
40
  style: h.style,
41
41
  "aria-sort": x ? j[i || "none"] : void 0,
42
42
  children: x ? /* @__PURE__ */ c("button", {
@@ -19,6 +19,8 @@ export interface Props extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'di
19
19
  asChild?: boolean;
20
20
  /** Whether the button is disabled */
21
21
  disabled?: boolean;
22
+ /** Sink the button while pressed on touch screens (default: true) */
23
+ pressEffect?: boolean;
22
24
  /** Theme override for this component */
23
25
  theme?: Theme;
24
26
  }
@@ -1,4 +1,5 @@
1
1
  export declare const buttonVariants: (props?: ({
2
+ pressEffect?: boolean | null | undefined;
2
3
  variant?: "link" | "danger" | "primary" | "secondary" | "tertiary" | null | undefined;
3
4
  shape?: "circle" | "pill" | null | undefined;
4
5
  version?: "default" | "alternate" | null | undefined;
@@ -9,11 +9,17 @@ import { Props } from './Sheet.types';
9
9
  *
10
10
  * Multi-step sheets pass a `step`: when it changes the content slides across
11
11
  * (forward for a higher step, back for a lower one) and the panel height
12
- * animates to the new content.
12
+ * animates to the new content. With `onBack`, swiping the content towards the
13
+ * right on a later step goes back the way the iOS back gesture does: the
14
+ * previous step follows the finger in from the left while the panel grows or
15
+ * shrinks to its height, and the swipe commits or springs back on release.
13
16
  *
14
- * On touch screens the panel can be dragged by its grab handle or header
15
- * towards the edge it docks to: it closes past a quarter of its height or on a
16
- * quick flick, and springs back otherwise.
17
+ * On touch screens the panel follows a finger on its grab handle or header.
18
+ * Towards the edge it docks to it closes past a quarter of its height or on a
19
+ * quick flick, and springs back otherwise. An `expandable` sheet grows with
20
+ * the finger when pulled away from that edge and, once released, springs the
21
+ * rest of the way to the full viewport (or back to its natural height); from
22
+ * there a pull towards the edge shrinks it again, and a long one closes it.
17
23
  *
18
24
  * @example
19
25
  * ```tsx
@@ -16,6 +16,12 @@ export type Props = PropsWithChildren<{
16
16
  isOpen: boolean;
17
17
  /** Called when the sheet asks to close: scrim tap, Escape, or `closeOnSelect` */
18
18
  onClose: () => void;
19
+ /**
20
+ * Goes back one step. On a step above the first the header (chevron and
21
+ * title) becomes the back control in place of `leading`, and swiping the
22
+ * content towards the right goes back too.
23
+ */
24
+ onBack?: () => void;
19
25
  /** Heading of the sheet; also its accessible name */
20
26
  title: ReactNode;
21
27
  /** Keep the title for assistive technology only */
@@ -24,6 +30,12 @@ export type Props = PropsWithChildren<{
24
30
  leading?: ReactNode;
25
31
  /** Screen edge the sheet docks to (default: 'bottom') */
26
32
  position?: SheetPosition;
33
+ /**
34
+ * Let a swipe away from the docked edge grow the panel to the full viewport.
35
+ * A swipe back towards the edge restores its natural height first and only
36
+ * a further swipe closes it.
37
+ */
38
+ expandable?: boolean;
27
39
  /**
28
40
  * Index of the step the content shows. Changing it slides the content across
29
41
  * (forward for a higher index, back for a lower one) and animates the panel
@@ -0,0 +1,8 @@
1
+ import { FC } from 'react';
2
+ import { Props } from './SheetStep.types';
3
+ /**
4
+ * One step of a sheet's content. It owns its horizontal offset so a step that
5
+ * was swiped away keeps that offset while it unmounts and the next step mounts
6
+ * in place.
7
+ */
8
+ export declare const SheetStep: FC<Props>;
@@ -0,0 +1,32 @@
1
+ import { PanInfo } from 'motion/react';
2
+ import { PropsWithChildren } from 'react';
3
+ export type BackOutcome = 'back' | 'stay';
4
+ /**
5
+ * What AnimatePresence hands an exiting step: the direction of travel and
6
+ * whether the step has already been moved out by a gesture.
7
+ */
8
+ export type StepExitCustom = {
9
+ direction: number;
10
+ instant: boolean;
11
+ };
12
+ export type Props = PropsWithChildren<{
13
+ step: number;
14
+ direction: number;
15
+ /** Slide the content across on mount and unmount */
16
+ animated: boolean;
17
+ /** The content follows a swipe towards the right and reports its progress */
18
+ canSwipeBack: boolean;
19
+ /** Whether the pan that just started is a horizontal one on swipeable content */
20
+ isArmed: (info: PanInfo) => boolean;
21
+ onBackStart: () => void;
22
+ onBackMove: (offset: number) => void;
23
+ onBackEnd: (info: PanInfo) => BackOutcome;
24
+ /** Reports the step's own height once it is laid out */
25
+ onMount: (height: number) => void;
26
+ /** Bumped to slide the content out as if swiped, e.g. from the back button */
27
+ commitSignal: number;
28
+ /** The content has finished sliding out after a completed swipe */
29
+ onBackCommit: () => void;
30
+ /** The content has settled back in place after an abandoned swipe */
31
+ onBackCancel: () => void;
32
+ }>;
@@ -0,0 +1,2 @@
1
+ export { SheetStep } from './SheetStep/SheetStep';
2
+ export type { BackOutcome } from './SheetStep/SheetStep.types';
@@ -1,11 +1,26 @@
1
1
  import { SheetPosition } from '../Sheet.types';
2
2
  export declare const DISMISS_DISTANCE_RATIO = 0.25;
3
3
  export declare const DISMISS_VELOCITY = 500;
4
- type DismissGesture = {
4
+ type Gesture = {
5
5
  offset: number;
6
6
  velocity: number;
7
7
  panelHeight: number;
8
8
  position: SheetPosition;
9
9
  };
10
- export declare function shouldDismissSheet({ offset, velocity, panelHeight, position, }: DismissGesture): boolean;
10
+ type SheetGesture = Gesture & {
11
+ expandable: boolean;
12
+ isExpanded: boolean;
13
+ /** Height the panel had before it expanded; the collapse target */
14
+ restHeight?: number;
15
+ };
16
+ export type SheetGestureOutcome = 'dismiss' | 'expand' | 'collapse' | 'rest';
17
+ export declare function shouldDismissSheet(gesture: Gesture): boolean;
18
+ export declare function shouldExpandSheet(gesture: Gesture): boolean;
19
+ type BackGesture = {
20
+ offset: number;
21
+ velocity: number;
22
+ panelWidth: number;
23
+ };
24
+ export declare function shouldSwipeBack({ offset, velocity, panelWidth, }: BackGesture): boolean;
25
+ export declare function resolveSheetGesture({ expandable, isExpanded, restHeight, ...gesture }: SheetGesture): SheetGestureOutcome;
11
26
  export {};
package/dist/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.1.4",
5
+ "version": "0.1.6",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
@@ -102,7 +102,7 @@
102
102
  "google-libphonenumber": "^3.2.48",
103
103
  "i18n-iso-countries": "^7.14.0",
104
104
  "js-cookie": "^3.0.8",
105
- "lucide-react": "^1.67.0",
105
+ "lucide-react": "^1.68.0",
106
106
  "react-chartjs-2": "^5.3.1",
107
107
  "react-day-picker": "^10.0.2",
108
108
  "react-feather": "^2.0.10",
@@ -176,7 +176,7 @@
176
176
  "jest-axe": "^11.0.0",
177
177
  "jsdom": "^30.1.3",
178
178
  "lodash": "^4.18.1",
179
- "motion": "^14.9.0",
179
+ "motion": "^14.9.1",
180
180
  "postcss": "^8.5.32",
181
181
  "prettier": "^3.9.10",
182
182
  "rimraf": "^6.1.4",