@techsio/ui-kit 0.41.2 → 0.42.0

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 (40) hide show
  1. package/dist/internal/molecules/drawer.context.js +133 -0
  2. package/dist/internal/molecules/drawer.styles.js +107 -0
  3. package/dist/internal/organisms/sidebar.context.js +223 -0
  4. package/dist/internal/organisms/sidebar.focus.js +169 -0
  5. package/dist/internal/organisms/sidebar.styles.js +146 -0
  6. package/dist/molecules/drawer.js +262 -0
  7. package/dist/organisms/sidebar.js +448 -0
  8. package/dist/src/internal/molecules/drawer.context.d.ts +53 -0
  9. package/dist/src/internal/molecules/drawer.context.d.ts.map +1 -0
  10. package/dist/src/internal/molecules/drawer.styles.d.ts +115 -0
  11. package/dist/src/internal/molecules/drawer.styles.d.ts.map +1 -0
  12. package/dist/src/internal/organisms/sidebar.context.d.ts +83 -0
  13. package/dist/src/internal/organisms/sidebar.context.d.ts.map +1 -0
  14. package/dist/src/internal/organisms/sidebar.focus.d.ts +16 -0
  15. package/dist/src/internal/organisms/sidebar.focus.d.ts.map +1 -0
  16. package/dist/src/internal/organisms/sidebar.styles.d.ts +149 -0
  17. package/dist/src/internal/organisms/sidebar.styles.d.ts.map +1 -0
  18. package/dist/src/molecules/drawer.d.ts +112 -0
  19. package/dist/src/molecules/drawer.d.ts.map +1 -0
  20. package/dist/src/molecules/switch.d.ts +3 -3
  21. package/dist/src/molecules/toast.d.ts +6 -6
  22. package/dist/src/organisms/sidebar.d.ts +93 -0
  23. package/dist/src/organisms/sidebar.d.ts.map +1 -0
  24. package/dist/src/types/zag.d.ts +1 -0
  25. package/dist/src/types/zag.d.ts.map +1 -1
  26. package/dist/stories/changelog/changelog.stories.d.ts.map +1 -1
  27. package/dist/stories/molecules/drawer.stories.d.ts +158 -0
  28. package/dist/stories/molecules/drawer.stories.d.ts.map +1 -0
  29. package/dist/stories/organisms/sidebar.stories.d.ts +66 -0
  30. package/dist/stories/organisms/sidebar.stories.d.ts.map +1 -0
  31. package/dist/test/drawer.behavior.spec.d.ts +2 -0
  32. package/dist/test/drawer.behavior.spec.d.ts.map +1 -0
  33. package/dist/test/sidebar.behavior.spec.d.ts +2 -0
  34. package/dist/test/sidebar.behavior.spec.d.ts.map +1 -0
  35. package/dist/test/sidebar.ssr.bun.d.ts +2 -0
  36. package/dist/test/sidebar.ssr.bun.d.ts.map +1 -0
  37. package/package.json +25 -22
  38. package/src/tokens/components/components.css +2 -0
  39. package/src/tokens/components/molecules/_drawer.css +369 -0
  40. package/src/tokens/components/organisms/_sidebar.css +93 -0
@@ -0,0 +1,146 @@
1
+ import { tv } from "../../utils.js";
2
+ const sidebarVariants = tv({
3
+ slots: {
4
+ root: [
5
+ "relative flex min-h-sidebar-viewport w-full min-w-0",
6
+ "bg-sidebar-root-bg text-sidebar-root-fg"
7
+ ],
8
+ breakpoint: "pointer-events-none invisible absolute sidebar-desktop:block hidden size-0",
9
+ desktopPanel: [
10
+ "group/sidebar-panel sticky top-sidebar-offset hidden h-sidebar-viewport shrink-0 flex-col overflow-hidden",
11
+ "sidebar-desktop:flex bg-sidebar-panel-bg text-sidebar-panel-fg",
12
+ "border-sidebar-panel-border transition-all duration-(--duration-sidebar) motion-reduce:transition-none",
13
+ "focus-visible:sidebar-focus-ring",
14
+ "data-[side=start]:border-e-(length:--border-width-sidebar)",
15
+ "data-[side=end]:border-s-(length:--border-width-sidebar)"
16
+ ],
17
+ mobilePanel: [
18
+ "w-full max-w-sidebar-mobile bg-sidebar-panel-bg p-0 text-sidebar-panel-fg",
19
+ "data-[swipe-direction=left]:rounded-none data-[swipe-direction=right]:rounded-none"
20
+ ],
21
+ mobileAside: "focus-visible:sidebar-focus-ring flex size-full min-h-0 flex-col overflow-hidden",
22
+ trigger: [
23
+ "bg-sidebar-trigger-bg text-sidebar-trigger-fg",
24
+ "hover:bg-sidebar-trigger-bg-hover active:bg-sidebar-trigger-bg-active"
25
+ ],
26
+ inset: [
27
+ "relative min-h-sidebar-viewport min-w-0 flex-1",
28
+ "bg-sidebar-inset-bg text-sidebar-inset-fg"
29
+ ],
30
+ header: [
31
+ "flex shrink-0 flex-col gap-sidebar-section p-sidebar-section",
32
+ "border-b-(length:--border-width-sidebar) border-sidebar-panel-border",
33
+ "group-data-[state=collapsed]/sidebar-panel:p-sidebar-section-compact",
34
+ "group-data-[size=rail]/sidebar-pane:p-sidebar-section-compact"
35
+ ],
36
+ content: [
37
+ "flex min-h-0 flex-1 flex-col gap-sidebar-content overflow-y-auto overflow-x-hidden",
38
+ "p-sidebar-content",
39
+ "group-data-[state=collapsed]/sidebar-panel:p-sidebar-content-compact",
40
+ "group-data-[size=rail]/sidebar-pane:p-sidebar-content-compact"
41
+ ],
42
+ footer: [
43
+ "flex shrink-0 flex-col gap-sidebar-section p-sidebar-section",
44
+ "border-t-(length:--border-width-sidebar) border-sidebar-panel-border",
45
+ "group-data-[state=collapsed]/sidebar-panel:p-sidebar-section-compact",
46
+ "group-data-[size=rail]/sidebar-pane:p-sidebar-section-compact"
47
+ ],
48
+ group: "flex min-w-0 flex-col gap-sidebar-group",
49
+ groupLabel: [
50
+ "sidebar-group-label-typography truncate px-sidebar-group-label",
51
+ "font-sidebar-group-label text-sidebar-group-label-fg"
52
+ ],
53
+ groupContent: "flex min-w-0 flex-col gap-sidebar-group-content",
54
+ menu: "flex min-w-0 list-none flex-col gap-sidebar-menu",
55
+ item: "relative min-w-0",
56
+ separator: [
57
+ "h-sidebar-separator w-full shrink-0 border-0",
58
+ "bg-sidebar-separator-bg"
59
+ ],
60
+ expanded: "min-w-0",
61
+ label: "min-w-0 truncate whitespace-nowrap",
62
+ paneGroup: "flex min-h-0 min-w-0 flex-1 overflow-hidden",
63
+ pane: "group/sidebar-pane flex min-h-0 min-w-0 flex-col",
64
+ rail: [
65
+ "sidebar-rail-layer absolute inset-y-sidebar-rail hidden w-sidebar-rail cursor-col-resize items-center justify-center",
66
+ "sidebar-desktop:flex text-sidebar-rail-fg hover:bg-sidebar-rail-bg-hover",
67
+ "focus-visible:sidebar-focus-ring",
68
+ "data-[side=end]:start-0 data-[side=start]:end-0",
69
+ "after:h-sidebar-rail-indicator after:w-sidebar-rail-indicator after:rounded-sidebar-rail after:bg-sidebar-rail-indicator-bg"
70
+ ]
71
+ },
72
+ variants: {
73
+ collapsible: {
74
+ icon: {},
75
+ offcanvas: {},
76
+ none: {}
77
+ },
78
+ expanded: {
79
+ true: {},
80
+ false: {}
81
+ },
82
+ paneSize: {
83
+ rail: {
84
+ pane: "w-sidebar-icon shrink-0"
85
+ },
86
+ content: {
87
+ pane: [
88
+ "border-s-(length:--border-width-sidebar) flex-1",
89
+ "border-sidebar-pane-border"
90
+ ]
91
+ },
92
+ auto: {
93
+ pane: "flex-1"
94
+ }
95
+ },
96
+ collapsed: {
97
+ true: {
98
+ label: "sr-only"
99
+ },
100
+ false: {}
101
+ }
102
+ },
103
+ compoundVariants: [
104
+ {
105
+ collapsible: "icon",
106
+ expanded: true,
107
+ class: {
108
+ desktopPanel: "w-sidebar-expanded"
109
+ }
110
+ },
111
+ {
112
+ collapsible: "icon",
113
+ expanded: false,
114
+ class: {
115
+ desktopPanel: "w-sidebar-icon"
116
+ }
117
+ },
118
+ {
119
+ collapsible: "offcanvas",
120
+ expanded: true,
121
+ class: {
122
+ desktopPanel: "w-sidebar-expanded"
123
+ }
124
+ },
125
+ {
126
+ collapsible: "offcanvas",
127
+ expanded: false,
128
+ class: {
129
+ desktopPanel: "w-0 border-transparent"
130
+ }
131
+ },
132
+ {
133
+ collapsible: "none",
134
+ class: {
135
+ desktopPanel: "w-sidebar-expanded"
136
+ }
137
+ }
138
+ ],
139
+ defaultVariants: {
140
+ collapsible: "icon",
141
+ expanded: true,
142
+ paneSize: "auto",
143
+ collapsed: false
144
+ }
145
+ });
146
+ export { sidebarVariants };
@@ -0,0 +1,262 @@
1
+ "use client";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { Portal, mergeProps } from "@zag-js/react";
4
+ import { ActionIcon } from "../atoms/action-icon.js";
5
+ import { Button } from "../atoms/button.js";
6
+ import { DrawerProvider, DrawerStackProvider, getDrawerPresenceProps, useComposedRefs, useDrawer, useDrawerContext, useDrawerPresence, useDrawerStackContext } from "../internal/molecules/drawer.context.js";
7
+ import { drawerVariants } from "../internal/molecules/drawer.styles.js";
8
+ const drawer_useDrawer = useDrawer;
9
+ const swipeDirectionByPlacement = {
10
+ bottom: "down",
11
+ end: "end",
12
+ start: "start",
13
+ top: "up"
14
+ };
15
+ function Drawer({ children, immediate, lazyMount = true, onEnterComplete, onExitComplete, placement = "end", size, skipAnimationOnMount = false, unmountOnExit = true, ...machineProps }) {
16
+ const api = drawer_useDrawer({
17
+ ...machineProps,
18
+ swipeDirection: swipeDirectionByPlacement[placement]
19
+ });
20
+ return /*#__PURE__*/ jsx(DrawerProvider, {
21
+ api: api,
22
+ immediate: immediate,
23
+ lazyMount: lazyMount,
24
+ onEnterComplete: onEnterComplete,
25
+ onExitComplete: onExitComplete,
26
+ size: size,
27
+ skipAnimationOnMount: skipAnimationOnMount,
28
+ unmountOnExit: unmountOnExit,
29
+ children: children
30
+ });
31
+ }
32
+ Drawer.Root = Drawer;
33
+ Drawer.RootProvider = function({ children, immediate, lazyMount = true, onEnterComplete, onExitComplete, size, skipAnimationOnMount = false, unmountOnExit = true, value }) {
34
+ return /*#__PURE__*/ jsx(DrawerProvider, {
35
+ api: value,
36
+ immediate: immediate,
37
+ lazyMount: lazyMount,
38
+ onEnterComplete: onEnterComplete,
39
+ onExitComplete: onExitComplete,
40
+ size: size,
41
+ skipAnimationOnMount: skipAnimationOnMount,
42
+ unmountOnExit: unmountOnExit,
43
+ children: children
44
+ });
45
+ };
46
+ Drawer.Trigger = function({ className, ref, value, ...props }) {
47
+ const { api, styles } = useDrawerContext();
48
+ const mergedProps = mergeProps(api.getTriggerProps({
49
+ value
50
+ }), props);
51
+ return /*#__PURE__*/ jsx(Button, {
52
+ ...mergedProps,
53
+ className: styles.trigger({
54
+ className
55
+ }),
56
+ ref: ref
57
+ });
58
+ };
59
+ Drawer.Portal = function(props) {
60
+ return /*#__PURE__*/ jsx(Portal, {
61
+ ...props
62
+ });
63
+ };
64
+ Drawer.Backdrop = function({ className, ref, ...props }) {
65
+ const { api, presenceOptions, styles } = useDrawerContext();
66
+ const presence = useDrawerPresence({
67
+ ...presenceOptions,
68
+ present: api.open
69
+ });
70
+ const composedRef = useComposedRefs(presence.ref, ref);
71
+ if (presence.unmounted) return null;
72
+ const mergedProps = mergeProps(api.getBackdropProps(), getDrawerPresenceProps(api.open, presence), props);
73
+ return /*#__PURE__*/ jsx("div", {
74
+ ...mergedProps,
75
+ className: styles.backdrop({
76
+ className
77
+ }),
78
+ ref: composedRef
79
+ });
80
+ };
81
+ Drawer.Positioner = function({ className, ref, ...props }) {
82
+ const { api, presence, styles } = useDrawerContext();
83
+ if (presence.unmounted) return null;
84
+ const mergedProps = mergeProps(api.getPositionerProps(), getDrawerPresenceProps(api.open, presence), props);
85
+ return /*#__PURE__*/ jsx("div", {
86
+ ...mergedProps,
87
+ className: styles.positioner({
88
+ className
89
+ }),
90
+ ref: ref
91
+ });
92
+ };
93
+ Drawer.Content = function({ className, draggable = true, ref, ...props }) {
94
+ const { api, presence, styles } = useDrawerContext();
95
+ const composedRef = useComposedRefs(presence.ref, ref);
96
+ if (presence.unmounted) return null;
97
+ const mergedProps = mergeProps(api.getContentProps({
98
+ draggable
99
+ }), getDrawerPresenceProps(api.open, presence), props);
100
+ return /*#__PURE__*/ jsx("div", {
101
+ ...mergedProps,
102
+ className: styles.content({
103
+ className
104
+ }),
105
+ ref: composedRef
106
+ });
107
+ };
108
+ Drawer.Header = function({ className, ref, ...props }) {
109
+ const { styles } = useDrawerContext();
110
+ return /*#__PURE__*/ jsx("div", {
111
+ className: styles.header({
112
+ className
113
+ }),
114
+ ref: ref,
115
+ ...props
116
+ });
117
+ };
118
+ Drawer.Body = function({ className, ref, ...props }) {
119
+ const { styles } = useDrawerContext();
120
+ return /*#__PURE__*/ jsx("div", {
121
+ className: styles.body({
122
+ className
123
+ }),
124
+ ref: ref,
125
+ ...props
126
+ });
127
+ };
128
+ Drawer.Footer = function({ className, ref, ...props }) {
129
+ const { styles } = useDrawerContext();
130
+ return /*#__PURE__*/ jsx("div", {
131
+ className: styles.footer({
132
+ className
133
+ }),
134
+ ref: ref,
135
+ ...props
136
+ });
137
+ };
138
+ Drawer.Title = function({ className, ref, ...props }) {
139
+ const { api, styles } = useDrawerContext();
140
+ return /*#__PURE__*/ jsx("h2", {
141
+ ...mergeProps(api.getTitleProps(), props),
142
+ className: styles.title({
143
+ className
144
+ }),
145
+ ref: ref
146
+ });
147
+ };
148
+ Drawer.Description = function({ className, ref, ...props }) {
149
+ const { api, styles } = useDrawerContext();
150
+ return /*#__PURE__*/ jsx("p", {
151
+ ...mergeProps(api.getDescriptionProps(), props),
152
+ className: styles.description({
153
+ className
154
+ }),
155
+ ref: ref
156
+ });
157
+ };
158
+ Drawer.CloseTrigger = function(props) {
159
+ const { api, styles } = useDrawerContext();
160
+ const { onClick: onMachineClick, ...machineProps } = api.getCloseTriggerProps();
161
+ if (null == props.children) {
162
+ const { children: _children, className: iconClassName, icon: iconName = "token-icon-drawer-close", onClick: onIconClick, ref: iconRef, size: iconSize = "md", tone = "neutral", type: iconType = "button", ...iconProps } = props;
163
+ const mergedProps = mergeProps(iconProps, machineProps);
164
+ return /*#__PURE__*/ jsx(ActionIcon, {
165
+ ...mergedProps,
166
+ "aria-label": mergedProps["aria-label"] ?? "Close drawer",
167
+ className: styles.closeTrigger({
168
+ className: iconClassName
169
+ }),
170
+ icon: iconName,
171
+ onClick: (event)=>{
172
+ onIconClick?.(event);
173
+ if (!event.defaultPrevented) onMachineClick?.(event);
174
+ },
175
+ ref: iconRef,
176
+ size: iconSize,
177
+ tone: tone,
178
+ type: iconType
179
+ });
180
+ }
181
+ const { children, className, icon, onClick, ref, size = "current", theme = "unstyled", type = "button", ...buttonProps } = props;
182
+ const mergedProps = mergeProps(buttonProps, machineProps);
183
+ return /*#__PURE__*/ jsx(Button, {
184
+ ...mergedProps,
185
+ className: styles.closeTrigger({
186
+ className
187
+ }),
188
+ icon: icon,
189
+ onClick: (event)=>{
190
+ onClick?.(event);
191
+ if (!event.defaultPrevented) onMachineClick?.(event);
192
+ },
193
+ ref: ref,
194
+ size: size,
195
+ theme: theme,
196
+ type: type,
197
+ children: children
198
+ });
199
+ };
200
+ Drawer.Grabber = function({ className, ref, ...props }) {
201
+ const { api, styles } = useDrawerContext();
202
+ const mergedProps = mergeProps(api.getGrabberProps(), props);
203
+ return /*#__PURE__*/ jsx("div", {
204
+ ...mergedProps,
205
+ className: styles.grabber({
206
+ className
207
+ }),
208
+ "data-swipe-direction": api.swipeDirection,
209
+ ref: ref
210
+ });
211
+ };
212
+ Drawer.GrabberIndicator = function({ className, ref, ...props }) {
213
+ const { api, styles } = useDrawerContext();
214
+ return /*#__PURE__*/ jsx("div", {
215
+ ...mergeProps(api.getGrabberIndicatorProps(), props),
216
+ className: styles.grabberIndicator({
217
+ className
218
+ }),
219
+ ref: ref
220
+ });
221
+ };
222
+ Drawer.SwipeArea = function({ className, disabled, ref, swipeDirection, ...props }) {
223
+ const { api, styles } = useDrawerContext();
224
+ return /*#__PURE__*/ jsx("div", {
225
+ ...mergeProps(api.getSwipeAreaProps({
226
+ disabled,
227
+ swipeDirection
228
+ }), props),
229
+ className: styles.swipeArea({
230
+ className
231
+ }),
232
+ ref: ref
233
+ });
234
+ };
235
+ Drawer.Context = function({ children }) {
236
+ return children(useDrawerContext().api);
237
+ };
238
+ Drawer.Stack = DrawerStackProvider;
239
+ Drawer.Indent = function({ className, ref, ...props }) {
240
+ const api = useDrawerStackContext();
241
+ const { indent } = drawerVariants();
242
+ return /*#__PURE__*/ jsx("div", {
243
+ ...mergeProps(api.getIndentProps(), props),
244
+ className: indent({
245
+ className
246
+ }),
247
+ ref: ref
248
+ });
249
+ };
250
+ Drawer.IndentBackground = function({ className, ref, ...props }) {
251
+ const api = useDrawerStackContext();
252
+ const { indentBackground } = drawerVariants();
253
+ return /*#__PURE__*/ jsx("div", {
254
+ ...mergeProps(api.getIndentBackgroundProps(), props),
255
+ className: indentBackground({
256
+ className
257
+ }),
258
+ ref: ref
259
+ });
260
+ };
261
+ Drawer.displayName = "Drawer";
262
+ export { Drawer, drawer_useDrawer as useDrawer };