@telia/teddy 0.4.4 → 0.4.5

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.
Files changed (76) hide show
  1. package/dist/components/card/card-illustration.d.ts +1 -1
  2. package/dist/components/channel-button/channel-button-root.d.ts +3 -3
  3. package/dist/components/channel-button/index.d.ts +3 -3
  4. package/dist/components/checkbox/checkbox-group.d.ts +1 -1
  5. package/dist/components/checkbox/index.d.ts +1 -1
  6. package/dist/components/chip/chip-indicator.d.ts +2 -2
  7. package/dist/components/chip/index.d.ts +2 -2
  8. package/dist/components/color-dot/index.d.ts +1 -1
  9. package/dist/components/expandable-card/expandable-card-button.d.ts +2 -2
  10. package/dist/components/expandable-card/index.d.ts +3 -3
  11. package/dist/components/flip-card/flip-card-back.cjs +39 -0
  12. package/dist/components/flip-card/flip-card-back.d.ts +27 -0
  13. package/dist/components/flip-card/flip-card-back.js +39 -0
  14. package/dist/components/flip-card/flip-card-footer.cjs +22 -0
  15. package/dist/components/flip-card/flip-card-footer.d.ts +14 -0
  16. package/dist/components/flip-card/flip-card-footer.js +22 -0
  17. package/dist/components/flip-card/flip-card-front.cjs +29 -0
  18. package/dist/components/flip-card/flip-card-front.d.ts +21 -0
  19. package/dist/components/flip-card/flip-card-front.js +29 -0
  20. package/dist/components/flip-card/flip-card-root.cjs +132 -0
  21. package/dist/components/flip-card/flip-card-root.d.ts +60 -0
  22. package/dist/components/flip-card/flip-card-root.js +132 -0
  23. package/dist/components/flip-card/flip-card-trigger.cjs +36 -0
  24. package/dist/components/flip-card/flip-card-trigger.d.ts +63 -0
  25. package/dist/components/flip-card/flip-card-trigger.js +36 -0
  26. package/dist/components/flip-card/index.cjs +18 -0
  27. package/dist/components/flip-card/index.d.ts +154 -0
  28. package/dist/components/flip-card/index.js +18 -0
  29. package/dist/components/icon/utils.d.ts +1 -1
  30. package/dist/components/index.cjs +2 -0
  31. package/dist/components/index.d.ts +1 -0
  32. package/dist/components/index.js +2 -0
  33. package/dist/components/modal/modal-close.cjs +1 -0
  34. package/dist/components/modal/modal-close.js +1 -0
  35. package/dist/components/navigation-menu/navigation-menu.cjs +1 -0
  36. package/dist/components/navigation-menu/navigation-menu.js +1 -0
  37. package/dist/components/notabene/notabene-icon.d.ts +2 -2
  38. package/dist/components/notification/index.d.ts +1 -1
  39. package/dist/components/notification/notification-icon.d.ts +2 -2
  40. package/dist/components/notification/notification-root.d.ts +1 -1
  41. package/dist/components/radio-card-group/radio-card-group-content.cjs +1 -0
  42. package/dist/components/radio-card-group/radio-card-group-content.js +1 -0
  43. package/dist/components/radio-card-group/radio-card-group-item-title.cjs +1 -0
  44. package/dist/components/radio-card-group/radio-card-group-item-title.js +1 -0
  45. package/dist/components/radio-card-group/radio-card-group-item.cjs +1 -0
  46. package/dist/components/radio-card-group/radio-card-group-item.js +1 -0
  47. package/dist/components/scroll-area/index.cjs +4 -3
  48. package/dist/components/scroll-area/index.d.ts +6 -3
  49. package/dist/components/scroll-area/index.js +3 -2
  50. package/dist/components/scroll-area/scroll-area-bar.cjs +6 -250
  51. package/dist/components/scroll-area/scroll-area-bar.js +6 -233
  52. package/dist/components/scroll-area/scroll-area-button.cjs +2 -2
  53. package/dist/components/scroll-area/scroll-area-button.d.ts +2 -2
  54. package/dist/components/scroll-area/scroll-area-button.js +1 -1
  55. package/dist/components/scroll-area/scroll-area-corner.cjs +2 -2
  56. package/dist/components/scroll-area/scroll-area-corner.js +1 -1
  57. package/dist/components/scroll-area/scroll-area-item.cjs +3 -3
  58. package/dist/components/scroll-area/scroll-area-item.js +1 -1
  59. package/dist/components/scroll-area/scroll-area-root.cjs +4 -5
  60. package/dist/components/scroll-area/scroll-area-root.d.ts +19 -3
  61. package/dist/components/scroll-area/scroll-area-root.js +1 -2
  62. package/dist/components/scroll-area/scroll-area-thumb.cjs +251 -6
  63. package/dist/components/scroll-area/scroll-area-thumb.js +234 -6
  64. package/dist/components/tabs/index.d.ts +5 -3
  65. package/dist/components/tabs/tabs-scroll-button.d.ts +2 -2
  66. package/dist/components/tabs/tabs-scroll.d.ts +3 -1
  67. package/dist/components/text-field/index.d.ts +2 -2
  68. package/dist/components/text-field/text-field-button.d.ts +2 -2
  69. package/dist/components/toggle/toggle.d.ts +2 -2
  70. package/dist/main.cjs +2 -0
  71. package/dist/main.js +2 -0
  72. package/dist/style.css +3373 -3307
  73. package/dist/utils/generate-styling/grid.d.ts +24 -24
  74. package/dist/utils/generate-styling/index.d.ts +16 -16
  75. package/dist/utils/generate-styling/util.d.ts +2 -2
  76. package/package.json +1 -1
@@ -1,8 +1,253 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("react/jsx-runtime");
4
- require("react");
5
- require("clsx");
6
- require("@radix-ui/react-scroll-area");
7
- const components_scrollArea_scrollAreaBar = require("./scroll-area-bar.cjs");
8
- exports.Thumb = components_scrollArea_scrollAreaBar.Thumb;
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const React = require("react");
5
+ const clsx = require("clsx");
6
+ const ScrollAreaPrimitive = require("@radix-ui/react-scroll-area");
7
+ const components_button_button = require("../button/button.cjs");
8
+ const utils_composeEventHandlers = require("../../utils/composeEventHandlers.cjs");
9
+ require("../../assets/sprite.1321fab0-teddy.svg");
10
+ const components_icon_icon = require("../icon/icon.cjs");
11
+ function _interopNamespaceDefault(e) {
12
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
13
+ if (e) {
14
+ for (const k in e) {
15
+ if (k !== "default") {
16
+ const d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: () => e[k]
20
+ });
21
+ }
22
+ }
23
+ }
24
+ n.default = e;
25
+ return Object.freeze(n);
26
+ }
27
+ const ScrollAreaPrimitive__namespace = /* @__PURE__ */ _interopNamespaceDefault(ScrollAreaPrimitive);
28
+ const styles = {
29
+ "teddy-scroll-area": "_teddy-scroll-area_1r6mf_1",
30
+ "teddy-scroll-area__viewport": "_teddy-scroll-area__viewport_1r6mf_5",
31
+ "teddy-scroll-area__scrollbar": "_teddy-scroll-area__scrollbar_1r6mf_11",
32
+ "teddy-scroll-area__scrollbar--hidden": "_teddy-scroll-area__scrollbar--hidden_1r6mf_32",
33
+ "teddy-scroll-area__thumb": "_teddy-scroll-area__thumb_1r6mf_45",
34
+ "teddy-scroll-area__corner": "_teddy-scroll-area__corner_1r6mf_62",
35
+ "teddy-scroll-area__button": "_teddy-scroll-area__button_1r6mf_65",
36
+ "teddy-scroll-area__button--hidden": "_teddy-scroll-area__button--hidden_1r6mf_93"
37
+ };
38
+ const Thumb = React.forwardRef(
39
+ ({ className, ...props }, forwardRef) => {
40
+ const classes = clsx([styles[`${rootClassName}__thumb`]], className);
41
+ return /* @__PURE__ */ jsxRuntime.jsx(ScrollAreaPrimitive__namespace.ScrollAreaThumb, { ...props, ref: forwardRef, className: classes });
42
+ }
43
+ );
44
+ Thumb.displayName = "Thumb";
45
+ const Scrollbar = React.forwardRef(
46
+ ({ className, ...props }, forwardRef) => {
47
+ const context = React.useContext(RootContext);
48
+ const classes = clsx(
49
+ [styles[`${rootClassName}__scrollbar`]],
50
+ {
51
+ [styles[`${rootClassName}__scrollbar--hidden`]]: (context == null ? void 0 : context.variant) === "button"
52
+ },
53
+ className
54
+ );
55
+ return /* @__PURE__ */ jsxRuntime.jsx(ScrollAreaPrimitive__namespace.ScrollAreaScrollbar, { ...props, ref: forwardRef, className: classes, children: /* @__PURE__ */ jsxRuntime.jsx(Thumb, {}) });
56
+ }
57
+ );
58
+ Scrollbar.displayName = "Scrollbar";
59
+ const Corner = React.forwardRef(
60
+ ({ className, ...props }, forwardRef) => {
61
+ const classes = clsx([styles[`${rootClassName}__corner`]], className);
62
+ return /* @__PURE__ */ jsxRuntime.jsx(ScrollAreaPrimitive__namespace.Corner, { ...props, ref: forwardRef, className: classes });
63
+ }
64
+ );
65
+ Corner.displayName = "Corner";
66
+ const directionToAriaLabel = {
67
+ up: "Scroll opp",
68
+ down: "Scroll ned",
69
+ left: "Scroll til venstre",
70
+ right: "Scroll til høyre"
71
+ };
72
+ const directionToIconName = {
73
+ up: "chevron-up",
74
+ down: "chevron-down",
75
+ left: "chevron-left",
76
+ right: "chevron-right"
77
+ };
78
+ const Button = React.forwardRef(
79
+ ({ className, hidden, direction = "right", children, ...props }, forwardRef) => {
80
+ const scrollAreaContext = React.useContext(RootContext);
81
+ const shouldBeHidden = hidden ?? (direction === "up" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollTop) || direction === "down" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollBottom) || direction === "left" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollLeft) || direction === "right" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollRight));
82
+ const buttonClasses = clsx(
83
+ styles[`${rootClassName}__button`],
84
+ {
85
+ [styles[`${rootClassName}__button--hidden`]]: shouldBeHidden
86
+ },
87
+ className
88
+ );
89
+ const handleButtonClick = utils_composeEventHandlers.composeEventHandlers(props.onClick, (event) => {
90
+ if (event.defaultPrevented)
91
+ return;
92
+ const scrollAreaElement = scrollAreaContext == null ? void 0 : scrollAreaContext.scrollRef;
93
+ if (!scrollAreaElement)
94
+ return;
95
+ const scrollableItems = Array.from(scrollAreaElement.querySelectorAll("[data-in-view]"));
96
+ const isHorizontalScroll = direction === "left" || direction === "right";
97
+ const scrollProperty = isHorizontalScroll ? "left" : "top";
98
+ const isScrollingBackward = direction === "left" || direction === "up";
99
+ const currentScrollPosition = isHorizontalScroll ? scrollAreaElement.scrollLeft : scrollAreaElement.scrollTop;
100
+ const viewportSize = isHorizontalScroll ? scrollAreaElement.clientWidth : scrollAreaElement.clientHeight;
101
+ const scrollButtonSize = isHorizontalScroll ? event.currentTarget.offsetWidth : event.currentTarget.offsetHeight;
102
+ const visibleAreaStart = currentScrollPosition + (isScrollingBackward ? scrollButtonSize : 0);
103
+ const visibleAreaEnd = currentScrollPosition + viewportSize - (!isScrollingBackward ? scrollButtonSize : 0);
104
+ const getItemBounds = (item) => {
105
+ const itemStart = isHorizontalScroll ? item.offsetLeft : item.offsetTop;
106
+ const itemEnd = itemStart + (isHorizontalScroll ? item.offsetWidth : item.offsetHeight);
107
+ return { itemStart, itemEnd };
108
+ };
109
+ const isItemFullyVisible = (item) => {
110
+ const { itemStart, itemEnd } = getItemBounds(item);
111
+ return itemStart >= visibleAreaStart && itemEnd <= visibleAreaEnd;
112
+ };
113
+ const fullyVisibleItemIndices = scrollableItems.map((item, index) => {
114
+ const isInView = item.getAttribute("data-in-view") === "true";
115
+ const isFullyVisible = isItemFullyVisible(item);
116
+ return isInView && isFullyVisible ? index : -1;
117
+ }).filter((index) => index !== -1);
118
+ const userPrefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
119
+ const scrollBehavior = userPrefersReducedMotion ? "auto" : (scrollAreaContext == null ? void 0 : scrollAreaContext.scrollBehavior) ?? "smooth";
120
+ function calculateScrollAmount() {
121
+ if (fullyVisibleItemIndices.length <= 0) {
122
+ const defaultScrollAmount = viewportSize - scrollButtonSize * 2;
123
+ return isScrollingBackward ? currentScrollPosition - defaultScrollAmount : currentScrollPosition + defaultScrollAmount;
124
+ }
125
+ const isRightToLeft = scrollAreaContext == null ? void 0 : scrollAreaContext.isRtl;
126
+ const effectiveBackwardDirection = isRightToLeft ? !isScrollingBackward : isScrollingBackward;
127
+ const referenceItemIndex = effectiveBackwardDirection ? fullyVisibleItemIndices[0] : fullyVisibleItemIndices[fullyVisibleItemIndices.length - 1];
128
+ const targetItemIndex = effectiveBackwardDirection ? referenceItemIndex > 0 ? referenceItemIndex - 1 : referenceItemIndex : referenceItemIndex < scrollableItems.length - 1 ? referenceItemIndex + 1 : referenceItemIndex;
129
+ const targetItem = scrollableItems[targetItemIndex];
130
+ const { itemStart, itemEnd } = getItemBounds(targetItem);
131
+ const targetItemSize = itemEnd - itemStart;
132
+ return isScrollingBackward ? itemStart + targetItemSize - viewportSize + scrollButtonSize : itemStart - scrollButtonSize;
133
+ }
134
+ const newScrollPosition = calculateScrollAmount();
135
+ scrollAreaElement.scrollTo({
136
+ [scrollProperty]: newScrollPosition,
137
+ behavior: scrollBehavior
138
+ });
139
+ });
140
+ return /* @__PURE__ */ jsxRuntime.jsx(
141
+ components_button_button.Button,
142
+ {
143
+ iconOnly: true,
144
+ variant: "primary",
145
+ "aria-label": directionToAriaLabel[direction],
146
+ "data-direction": direction,
147
+ tabIndex: shouldBeHidden ? -1 : void 0,
148
+ ...props,
149
+ onClick: handleButtonClick,
150
+ ref: forwardRef,
151
+ className: buttonClasses,
152
+ children: children || /* @__PURE__ */ jsxRuntime.jsx(components_icon_icon.Icon, { name: directionToIconName[direction] })
153
+ }
154
+ );
155
+ }
156
+ );
157
+ Button.displayName = "Button";
158
+ const rootClassName = "teddy-scroll-area";
159
+ const RootContext = React.createContext(void 0);
160
+ function isScrollable(element) {
161
+ if (!element)
162
+ return null;
163
+ const buffer = 1;
164
+ const scrollLeft = element.scrollLeft;
165
+ const scrollWidth = element.scrollWidth;
166
+ const offsetWidth = element.offsetWidth;
167
+ const maxScrollLeft = scrollWidth - offsetWidth;
168
+ const isRtl = getComputedStyle(element).direction === "rtl";
169
+ let left;
170
+ let right;
171
+ if (isRtl) {
172
+ const normalizedScrollLeft = Math.abs(scrollLeft);
173
+ left = normalizedScrollLeft < maxScrollLeft - buffer;
174
+ right = normalizedScrollLeft > buffer;
175
+ } else {
176
+ left = scrollLeft > buffer;
177
+ right = scrollLeft < maxScrollLeft - buffer;
178
+ }
179
+ const scrollTop = element.scrollTop;
180
+ const maxScrollTop = element.scrollHeight - element.offsetHeight;
181
+ const top = scrollTop > buffer;
182
+ const bottom = scrollTop < maxScrollTop - buffer;
183
+ return {
184
+ left,
185
+ right,
186
+ top,
187
+ bottom
188
+ };
189
+ }
190
+ const Root = React.forwardRef(
191
+ ({ className, variant, scrollBehavior = "smooth", viewPortClassName, barClassName, children, ...props }, forwardRef) => {
192
+ const [scrollRef, setScrollRef] = React.useState(null);
193
+ const [hasScroll, setHasScroll] = React.useState(null);
194
+ const initialScrollable = isScrollable(scrollRef);
195
+ const hasScrollLeft = hasScroll ? hasScroll.left : initialScrollable == null ? void 0 : initialScrollable.left;
196
+ const hasScrollRight = hasScroll ? hasScroll.right : initialScrollable == null ? void 0 : initialScrollable.right;
197
+ const hasScrollTop = hasScroll ? hasScroll.top : initialScrollable == null ? void 0 : initialScrollable.top;
198
+ const hasScrollBottom = hasScroll ? hasScroll.bottom : initialScrollable == null ? void 0 : initialScrollable.bottom;
199
+ const hasScrollHorizontal = hasScrollLeft || hasScrollRight;
200
+ const hasScrollVertical = hasScrollTop || hasScrollBottom;
201
+ function handleScroll(e) {
202
+ const target = e.currentTarget;
203
+ setHasScroll(isScrollable(target));
204
+ }
205
+ const classes = clsx([styles[`${rootClassName}`]], className);
206
+ return /* @__PURE__ */ jsxRuntime.jsx(
207
+ RootContext.Provider,
208
+ {
209
+ value: {
210
+ scrollRef,
211
+ variant,
212
+ hasScrollTop,
213
+ hasScrollBottom,
214
+ hasScrollLeft,
215
+ hasScrollRight,
216
+ scrollBehavior,
217
+ isRtl: props.dir === "rtl"
218
+ },
219
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ScrollAreaPrimitive__namespace.Root, { ...props, ref: forwardRef, className: classes, children: [
220
+ /* @__PURE__ */ jsxRuntime.jsx(
221
+ ScrollAreaPrimitive__namespace.Viewport,
222
+ {
223
+ onScroll: handleScroll,
224
+ ref: setScrollRef,
225
+ className: clsx([styles[`${rootClassName}__viewport`]], viewPortClassName),
226
+ children
227
+ }
228
+ ),
229
+ variant !== "hidden" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
230
+ /* @__PURE__ */ jsxRuntime.jsx(Scrollbar, { orientation: "vertical", className: barClassName }),
231
+ /* @__PURE__ */ jsxRuntime.jsx(Scrollbar, { orientation: "horizontal", className: barClassName })
232
+ ] }),
233
+ /* @__PURE__ */ jsxRuntime.jsx(Corner, {}),
234
+ variant === "button" && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
235
+ hasScrollVertical && /* @__PURE__ */ jsxRuntime.jsx(Button, { direction: "up", hidden: !hasScrollTop }),
236
+ hasScrollVertical && /* @__PURE__ */ jsxRuntime.jsx(Button, { direction: "down", hidden: !hasScrollBottom }),
237
+ hasScrollHorizontal && /* @__PURE__ */ jsxRuntime.jsx(Button, { direction: "left", hidden: !hasScrollLeft }),
238
+ hasScrollHorizontal && /* @__PURE__ */ jsxRuntime.jsx(Button, { direction: "right", hidden: !hasScrollRight })
239
+ ] })
240
+ ] })
241
+ }
242
+ );
243
+ }
244
+ );
245
+ Root.displayName = "Root";
246
+ exports.Button = Button;
247
+ exports.Corner = Corner;
248
+ exports.Root = Root;
249
+ exports.RootContext = RootContext;
250
+ exports.Scrollbar = Scrollbar;
251
+ exports.Thumb = Thumb;
252
+ exports.rootClassName = rootClassName;
253
+ exports.styles = styles;
@@ -1,8 +1,236 @@
1
- import "react/jsx-runtime";
2
- import "react";
3
- import "clsx";
4
- import "@radix-ui/react-scroll-area";
5
- import { T } from "./scroll-area-bar.js";
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import React__default from "react";
3
+ import clsx from "clsx";
4
+ import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
5
+ import { Button as Button$1 } from "../button/button.js";
6
+ import { composeEventHandlers } from "../../utils/composeEventHandlers.js";
7
+ import "../../assets/sprite.1321fab0-teddy.svg";
8
+ import { Icon } from "../icon/icon.js";
9
+ const styles = {
10
+ "teddy-scroll-area": "_teddy-scroll-area_1r6mf_1",
11
+ "teddy-scroll-area__viewport": "_teddy-scroll-area__viewport_1r6mf_5",
12
+ "teddy-scroll-area__scrollbar": "_teddy-scroll-area__scrollbar_1r6mf_11",
13
+ "teddy-scroll-area__scrollbar--hidden": "_teddy-scroll-area__scrollbar--hidden_1r6mf_32",
14
+ "teddy-scroll-area__thumb": "_teddy-scroll-area__thumb_1r6mf_45",
15
+ "teddy-scroll-area__corner": "_teddy-scroll-area__corner_1r6mf_62",
16
+ "teddy-scroll-area__button": "_teddy-scroll-area__button_1r6mf_65",
17
+ "teddy-scroll-area__button--hidden": "_teddy-scroll-area__button--hidden_1r6mf_93"
18
+ };
19
+ const Thumb = React__default.forwardRef(
20
+ ({ className, ...props }, forwardRef) => {
21
+ const classes = clsx([styles[`${rootClassName}__thumb`]], className);
22
+ return /* @__PURE__ */ jsx(ScrollAreaPrimitive.ScrollAreaThumb, { ...props, ref: forwardRef, className: classes });
23
+ }
24
+ );
25
+ Thumb.displayName = "Thumb";
26
+ const Scrollbar = React__default.forwardRef(
27
+ ({ className, ...props }, forwardRef) => {
28
+ const context = React__default.useContext(RootContext);
29
+ const classes = clsx(
30
+ [styles[`${rootClassName}__scrollbar`]],
31
+ {
32
+ [styles[`${rootClassName}__scrollbar--hidden`]]: (context == null ? void 0 : context.variant) === "button"
33
+ },
34
+ className
35
+ );
36
+ return /* @__PURE__ */ jsx(ScrollAreaPrimitive.ScrollAreaScrollbar, { ...props, ref: forwardRef, className: classes, children: /* @__PURE__ */ jsx(Thumb, {}) });
37
+ }
38
+ );
39
+ Scrollbar.displayName = "Scrollbar";
40
+ const Corner = React__default.forwardRef(
41
+ ({ className, ...props }, forwardRef) => {
42
+ const classes = clsx([styles[`${rootClassName}__corner`]], className);
43
+ return /* @__PURE__ */ jsx(ScrollAreaPrimitive.Corner, { ...props, ref: forwardRef, className: classes });
44
+ }
45
+ );
46
+ Corner.displayName = "Corner";
47
+ const directionToAriaLabel = {
48
+ up: "Scroll opp",
49
+ down: "Scroll ned",
50
+ left: "Scroll til venstre",
51
+ right: "Scroll til høyre"
52
+ };
53
+ const directionToIconName = {
54
+ up: "chevron-up",
55
+ down: "chevron-down",
56
+ left: "chevron-left",
57
+ right: "chevron-right"
58
+ };
59
+ const Button = React__default.forwardRef(
60
+ ({ className, hidden, direction = "right", children, ...props }, forwardRef) => {
61
+ const scrollAreaContext = React__default.useContext(RootContext);
62
+ const shouldBeHidden = hidden ?? (direction === "up" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollTop) || direction === "down" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollBottom) || direction === "left" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollLeft) || direction === "right" && !(scrollAreaContext == null ? void 0 : scrollAreaContext.hasScrollRight));
63
+ const buttonClasses = clsx(
64
+ styles[`${rootClassName}__button`],
65
+ {
66
+ [styles[`${rootClassName}__button--hidden`]]: shouldBeHidden
67
+ },
68
+ className
69
+ );
70
+ const handleButtonClick = composeEventHandlers(props.onClick, (event) => {
71
+ if (event.defaultPrevented)
72
+ return;
73
+ const scrollAreaElement = scrollAreaContext == null ? void 0 : scrollAreaContext.scrollRef;
74
+ if (!scrollAreaElement)
75
+ return;
76
+ const scrollableItems = Array.from(scrollAreaElement.querySelectorAll("[data-in-view]"));
77
+ const isHorizontalScroll = direction === "left" || direction === "right";
78
+ const scrollProperty = isHorizontalScroll ? "left" : "top";
79
+ const isScrollingBackward = direction === "left" || direction === "up";
80
+ const currentScrollPosition = isHorizontalScroll ? scrollAreaElement.scrollLeft : scrollAreaElement.scrollTop;
81
+ const viewportSize = isHorizontalScroll ? scrollAreaElement.clientWidth : scrollAreaElement.clientHeight;
82
+ const scrollButtonSize = isHorizontalScroll ? event.currentTarget.offsetWidth : event.currentTarget.offsetHeight;
83
+ const visibleAreaStart = currentScrollPosition + (isScrollingBackward ? scrollButtonSize : 0);
84
+ const visibleAreaEnd = currentScrollPosition + viewportSize - (!isScrollingBackward ? scrollButtonSize : 0);
85
+ const getItemBounds = (item) => {
86
+ const itemStart = isHorizontalScroll ? item.offsetLeft : item.offsetTop;
87
+ const itemEnd = itemStart + (isHorizontalScroll ? item.offsetWidth : item.offsetHeight);
88
+ return { itemStart, itemEnd };
89
+ };
90
+ const isItemFullyVisible = (item) => {
91
+ const { itemStart, itemEnd } = getItemBounds(item);
92
+ return itemStart >= visibleAreaStart && itemEnd <= visibleAreaEnd;
93
+ };
94
+ const fullyVisibleItemIndices = scrollableItems.map((item, index) => {
95
+ const isInView = item.getAttribute("data-in-view") === "true";
96
+ const isFullyVisible = isItemFullyVisible(item);
97
+ return isInView && isFullyVisible ? index : -1;
98
+ }).filter((index) => index !== -1);
99
+ const userPrefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
100
+ const scrollBehavior = userPrefersReducedMotion ? "auto" : (scrollAreaContext == null ? void 0 : scrollAreaContext.scrollBehavior) ?? "smooth";
101
+ function calculateScrollAmount() {
102
+ if (fullyVisibleItemIndices.length <= 0) {
103
+ const defaultScrollAmount = viewportSize - scrollButtonSize * 2;
104
+ return isScrollingBackward ? currentScrollPosition - defaultScrollAmount : currentScrollPosition + defaultScrollAmount;
105
+ }
106
+ const isRightToLeft = scrollAreaContext == null ? void 0 : scrollAreaContext.isRtl;
107
+ const effectiveBackwardDirection = isRightToLeft ? !isScrollingBackward : isScrollingBackward;
108
+ const referenceItemIndex = effectiveBackwardDirection ? fullyVisibleItemIndices[0] : fullyVisibleItemIndices[fullyVisibleItemIndices.length - 1];
109
+ const targetItemIndex = effectiveBackwardDirection ? referenceItemIndex > 0 ? referenceItemIndex - 1 : referenceItemIndex : referenceItemIndex < scrollableItems.length - 1 ? referenceItemIndex + 1 : referenceItemIndex;
110
+ const targetItem = scrollableItems[targetItemIndex];
111
+ const { itemStart, itemEnd } = getItemBounds(targetItem);
112
+ const targetItemSize = itemEnd - itemStart;
113
+ return isScrollingBackward ? itemStart + targetItemSize - viewportSize + scrollButtonSize : itemStart - scrollButtonSize;
114
+ }
115
+ const newScrollPosition = calculateScrollAmount();
116
+ scrollAreaElement.scrollTo({
117
+ [scrollProperty]: newScrollPosition,
118
+ behavior: scrollBehavior
119
+ });
120
+ });
121
+ return /* @__PURE__ */ jsx(
122
+ Button$1,
123
+ {
124
+ iconOnly: true,
125
+ variant: "primary",
126
+ "aria-label": directionToAriaLabel[direction],
127
+ "data-direction": direction,
128
+ tabIndex: shouldBeHidden ? -1 : void 0,
129
+ ...props,
130
+ onClick: handleButtonClick,
131
+ ref: forwardRef,
132
+ className: buttonClasses,
133
+ children: children || /* @__PURE__ */ jsx(Icon, { name: directionToIconName[direction] })
134
+ }
135
+ );
136
+ }
137
+ );
138
+ Button.displayName = "Button";
139
+ const rootClassName = "teddy-scroll-area";
140
+ const RootContext = React__default.createContext(void 0);
141
+ function isScrollable(element) {
142
+ if (!element)
143
+ return null;
144
+ const buffer = 1;
145
+ const scrollLeft = element.scrollLeft;
146
+ const scrollWidth = element.scrollWidth;
147
+ const offsetWidth = element.offsetWidth;
148
+ const maxScrollLeft = scrollWidth - offsetWidth;
149
+ const isRtl = getComputedStyle(element).direction === "rtl";
150
+ let left;
151
+ let right;
152
+ if (isRtl) {
153
+ const normalizedScrollLeft = Math.abs(scrollLeft);
154
+ left = normalizedScrollLeft < maxScrollLeft - buffer;
155
+ right = normalizedScrollLeft > buffer;
156
+ } else {
157
+ left = scrollLeft > buffer;
158
+ right = scrollLeft < maxScrollLeft - buffer;
159
+ }
160
+ const scrollTop = element.scrollTop;
161
+ const maxScrollTop = element.scrollHeight - element.offsetHeight;
162
+ const top = scrollTop > buffer;
163
+ const bottom = scrollTop < maxScrollTop - buffer;
164
+ return {
165
+ left,
166
+ right,
167
+ top,
168
+ bottom
169
+ };
170
+ }
171
+ const Root = React__default.forwardRef(
172
+ ({ className, variant, scrollBehavior = "smooth", viewPortClassName, barClassName, children, ...props }, forwardRef) => {
173
+ const [scrollRef, setScrollRef] = React__default.useState(null);
174
+ const [hasScroll, setHasScroll] = React__default.useState(null);
175
+ const initialScrollable = isScrollable(scrollRef);
176
+ const hasScrollLeft = hasScroll ? hasScroll.left : initialScrollable == null ? void 0 : initialScrollable.left;
177
+ const hasScrollRight = hasScroll ? hasScroll.right : initialScrollable == null ? void 0 : initialScrollable.right;
178
+ const hasScrollTop = hasScroll ? hasScroll.top : initialScrollable == null ? void 0 : initialScrollable.top;
179
+ const hasScrollBottom = hasScroll ? hasScroll.bottom : initialScrollable == null ? void 0 : initialScrollable.bottom;
180
+ const hasScrollHorizontal = hasScrollLeft || hasScrollRight;
181
+ const hasScrollVertical = hasScrollTop || hasScrollBottom;
182
+ function handleScroll(e) {
183
+ const target = e.currentTarget;
184
+ setHasScroll(isScrollable(target));
185
+ }
186
+ const classes = clsx([styles[`${rootClassName}`]], className);
187
+ return /* @__PURE__ */ jsx(
188
+ RootContext.Provider,
189
+ {
190
+ value: {
191
+ scrollRef,
192
+ variant,
193
+ hasScrollTop,
194
+ hasScrollBottom,
195
+ hasScrollLeft,
196
+ hasScrollRight,
197
+ scrollBehavior,
198
+ isRtl: props.dir === "rtl"
199
+ },
200
+ children: /* @__PURE__ */ jsxs(ScrollAreaPrimitive.Root, { ...props, ref: forwardRef, className: classes, children: [
201
+ /* @__PURE__ */ jsx(
202
+ ScrollAreaPrimitive.Viewport,
203
+ {
204
+ onScroll: handleScroll,
205
+ ref: setScrollRef,
206
+ className: clsx([styles[`${rootClassName}__viewport`]], viewPortClassName),
207
+ children
208
+ }
209
+ ),
210
+ variant !== "hidden" && /* @__PURE__ */ jsxs(Fragment, { children: [
211
+ /* @__PURE__ */ jsx(Scrollbar, { orientation: "vertical", className: barClassName }),
212
+ /* @__PURE__ */ jsx(Scrollbar, { orientation: "horizontal", className: barClassName })
213
+ ] }),
214
+ /* @__PURE__ */ jsx(Corner, {}),
215
+ variant === "button" && /* @__PURE__ */ jsxs(Fragment, { children: [
216
+ hasScrollVertical && /* @__PURE__ */ jsx(Button, { direction: "up", hidden: !hasScrollTop }),
217
+ hasScrollVertical && /* @__PURE__ */ jsx(Button, { direction: "down", hidden: !hasScrollBottom }),
218
+ hasScrollHorizontal && /* @__PURE__ */ jsx(Button, { direction: "left", hidden: !hasScrollLeft }),
219
+ hasScrollHorizontal && /* @__PURE__ */ jsx(Button, { direction: "right", hidden: !hasScrollRight })
220
+ ] })
221
+ ] })
222
+ }
223
+ );
224
+ }
225
+ );
226
+ Root.displayName = "Root";
6
227
  export {
7
- T as Thumb
228
+ Button as B,
229
+ Corner as C,
230
+ Root as R,
231
+ Scrollbar as S,
232
+ Thumb,
233
+ RootContext as a,
234
+ rootClassName as r,
235
+ styles as s
8
236
  };
@@ -24,8 +24,10 @@ export declare const Tabs: import('react').ForwardRefExoticComponent<Omit<Omit<i
24
24
  value: string;
25
25
  } & import('react').RefAttributes<HTMLDivElement>>;
26
26
  Scroll: import('react').ForwardRefExoticComponent<Omit<Omit<import('@radix-ui/react-scroll-area').ScrollAreaProps & import('react').RefAttributes<HTMLDivElement>, "ref"> & {
27
- variant?: ("button" | "scrollbar") | undefined;
27
+ variant?: ("button" | "hidden" | "scrollbar") | undefined;
28
28
  scrollBehavior?: "auto" | "smooth" | undefined;
29
+ viewPortClassName?: string | undefined;
30
+ barClassName?: string | undefined;
29
31
  } & import('react').RefAttributes<HTMLDivElement>, "ref"> & import('react').RefAttributes<HTMLDivElement>>;
30
32
  ScrollButton: import('react').ForwardRefExoticComponent<Omit<Omit<Omit<Omit<import('react').ButtonHTMLAttributes<HTMLButtonElement>, "aria-label"> & import('../../utils/generate-styling/flex').FlexChildren & import('../../utils/generate-styling/grid').GridChildren & import('../../utils/generate-styling/position').PositionProps & import('../../utils/generate-styling/inset').InsetProps & import('../../utils/generate-styling/radius').RadiusProps & import('../../utils/generate-styling/margin').MarginProps & import('../../utils/generate-styling/padding').PaddingProps & import('../../utils/generate-styling/width').WidthProps & import('../../utils/generate-styling/height').HeightProps & import('../../utils/generate-styling/color').ColorProps & {
31
33
  display?: import('../../utils/generate-styling').DisplayChildren | undefined;
@@ -34,7 +36,7 @@ export declare const Tabs: import('react').ForwardRefExoticComponent<Omit<Omit<i
34
36
  loading?: boolean | undefined;
35
37
  fullWidth?: boolean | undefined;
36
38
  size?: "sm" | "md" | "lg" | undefined;
37
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
39
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
38
40
  borderStyle?: ("default" | "dashed") | undefined;
39
41
  } & {
40
42
  iconOnly: true;
@@ -46,7 +48,7 @@ export declare const Tabs: import('react').ForwardRefExoticComponent<Omit<Omit<i
46
48
  loading?: boolean | undefined;
47
49
  fullWidth?: boolean | undefined;
48
50
  size?: "sm" | "md" | "lg" | undefined;
49
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
51
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
50
52
  borderStyle?: ("default" | "dashed") | undefined;
51
53
  } & {
52
54
  iconOnly?: false | undefined;
@@ -10,7 +10,7 @@ export declare const ScrollButton: React.ForwardRefExoticComponent<Omit<Omit<Omi
10
10
  loading?: boolean | undefined;
11
11
  fullWidth?: boolean | undefined;
12
12
  size?: "sm" | "md" | "lg" | undefined;
13
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
13
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
14
14
  borderStyle?: ("default" | "dashed") | undefined;
15
15
  } & {
16
16
  iconOnly: true;
@@ -22,7 +22,7 @@ export declare const ScrollButton: React.ForwardRefExoticComponent<Omit<Omit<Omi
22
22
  loading?: boolean | undefined;
23
23
  fullWidth?: boolean | undefined;
24
24
  size?: "sm" | "md" | "lg" | undefined;
25
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
25
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
26
26
  borderStyle?: ("default" | "dashed") | undefined;
27
27
  } & {
28
28
  iconOnly?: false | undefined;
@@ -5,6 +5,8 @@ export type ScrollProps = React.ComponentPropsWithoutRef<typeof ScrollArea>;
5
5
  export declare const ScrollContext: React.Context<boolean>;
6
6
  /** */
7
7
  export declare const Scroll: React.ForwardRefExoticComponent<Omit<Omit<import('@radix-ui/react-scroll-area').ScrollAreaProps & React.RefAttributes<HTMLDivElement>, "ref"> & {
8
- variant?: ("button" | "scrollbar") | undefined;
8
+ variant?: ("button" | "hidden" | "scrollbar") | undefined;
9
9
  scrollBehavior?: "auto" | "smooth" | undefined;
10
+ viewPortClassName?: string | undefined;
11
+ barClassName?: string | undefined;
10
12
  } & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -35,7 +35,7 @@ export declare const TextField: import('react').ForwardRefExoticComponent<Omit<i
35
35
  loading?: boolean | undefined;
36
36
  fullWidth?: boolean | undefined;
37
37
  size?: "sm" | "md" | "lg" | undefined;
38
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
38
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
39
39
  borderStyle?: ("default" | "dashed") | undefined;
40
40
  } & {
41
41
  iconOnly: true;
@@ -47,7 +47,7 @@ export declare const TextField: import('react').ForwardRefExoticComponent<Omit<i
47
47
  loading?: boolean | undefined;
48
48
  fullWidth?: boolean | undefined;
49
49
  size?: "sm" | "md" | "lg" | undefined;
50
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
50
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
51
51
  borderStyle?: ("default" | "dashed") | undefined;
52
52
  } & {
53
53
  iconOnly?: false | undefined;
@@ -11,7 +11,7 @@ export declare const Button: React.ForwardRefExoticComponent<Omit<Omit<Omit<Reac
11
11
  loading?: boolean | undefined;
12
12
  fullWidth?: boolean | undefined;
13
13
  size?: "sm" | "md" | "lg" | undefined;
14
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
14
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
15
15
  borderStyle?: ("default" | "dashed") | undefined;
16
16
  } & {
17
17
  iconOnly: true;
@@ -23,7 +23,7 @@ export declare const Button: React.ForwardRefExoticComponent<Omit<Omit<Omit<Reac
23
23
  loading?: boolean | undefined;
24
24
  fullWidth?: boolean | undefined;
25
25
  size?: "sm" | "md" | "lg" | undefined;
26
- variant?: "primary" | "text" | "list-item" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
26
+ variant?: "text" | "list-item" | "primary" | "secondary" | "destructive" | "tertiary-purple" | "expressive" | "primary-negative" | "secondary-negative" | "destructive-negative" | "tertiary-purple-negative" | "text-negative" | "expressive-negative" | undefined;
27
27
  borderStyle?: ("default" | "dashed") | undefined;
28
28
  } & {
29
29
  iconOnly?: false | undefined;