@techsio/ui-kit 0.41.2 → 0.43.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.
- package/dist/internal/molecules/drawer.context.js +133 -0
- package/dist/internal/molecules/drawer.styles.js +107 -0
- package/dist/internal/organisms/sidebar.context.js +223 -0
- package/dist/internal/organisms/sidebar.focus.js +169 -0
- package/dist/internal/organisms/sidebar.styles.js +146 -0
- package/dist/molecules/drawer.js +262 -0
- package/dist/molecules/file-upload.js +369 -0
- package/dist/organisms/sidebar.js +448 -0
- package/dist/src/internal/molecules/drawer.context.d.ts +53 -0
- package/dist/src/internal/molecules/drawer.context.d.ts.map +1 -0
- package/dist/src/internal/molecules/drawer.styles.d.ts +115 -0
- package/dist/src/internal/molecules/drawer.styles.d.ts.map +1 -0
- package/dist/src/internal/organisms/sidebar.context.d.ts +83 -0
- package/dist/src/internal/organisms/sidebar.context.d.ts.map +1 -0
- package/dist/src/internal/organisms/sidebar.focus.d.ts +16 -0
- package/dist/src/internal/organisms/sidebar.focus.d.ts.map +1 -0
- package/dist/src/internal/organisms/sidebar.styles.d.ts +149 -0
- package/dist/src/internal/organisms/sidebar.styles.d.ts.map +1 -0
- package/dist/src/molecules/drawer.d.ts +112 -0
- package/dist/src/molecules/drawer.d.ts.map +1 -0
- package/dist/src/molecules/file-upload.d.ts +84 -0
- package/dist/src/molecules/file-upload.d.ts.map +1 -0
- package/dist/src/molecules/switch.d.ts +3 -3
- package/dist/src/molecules/toast.d.ts +6 -6
- package/dist/src/organisms/sidebar.d.ts +93 -0
- package/dist/src/organisms/sidebar.d.ts.map +1 -0
- package/dist/src/types/zag.d.ts +2 -0
- package/dist/src/types/zag.d.ts.map +1 -1
- package/dist/stories/changelog/changelog.stories.d.ts.map +1 -1
- package/dist/stories/molecules/drawer.stories.d.ts +158 -0
- package/dist/stories/molecules/drawer.stories.d.ts.map +1 -0
- package/dist/stories/molecules/file-upload.stories.d.ts +105 -0
- package/dist/stories/molecules/file-upload.stories.d.ts.map +1 -0
- package/dist/stories/organisms/sidebar.stories.d.ts +66 -0
- package/dist/stories/organisms/sidebar.stories.d.ts.map +1 -0
- package/dist/test/drawer.behavior.spec.d.ts +2 -0
- package/dist/test/drawer.behavior.spec.d.ts.map +1 -0
- package/dist/test/sidebar.behavior.spec.d.ts +2 -0
- package/dist/test/sidebar.behavior.spec.d.ts.map +1 -0
- package/dist/test/sidebar.ssr.bun.d.ts +2 -0
- package/dist/test/sidebar.ssr.bun.d.ts.map +1 -0
- package/package.json +26 -22
- package/src/tokens/components/components.css +3 -0
- package/src/tokens/components/molecules/_drawer.css +369 -0
- package/src/tokens/components/molecules/_file-upload.css +128 -0
- package/src/tokens/components/organisms/_sidebar.css +93 -0
- package/src/tokens/figma/brand-overrides.css +2 -2
- package/src/tokens/figma/business/variables.css +3 -2
- package/src/tokens/figma/dark/variables.css +1 -0
- package/src/tokens/figma/light/variables.css +3 -2
- package/src/tokens/figma/neo/variables.css +3 -2
- package/src/tokens/figma/neo-dark/variables.css +1 -0
- package/src/tokens/figma/variables.css +3 -2
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { connect, machine } from "@zag-js/file-upload";
|
|
3
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
4
|
+
import { createContext, useContext, useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { ActionIcon } from "../atoms/action-icon.js";
|
|
6
|
+
import { Button } from "../atoms/button.js";
|
|
7
|
+
import { Icon } from "../atoms/icon.js";
|
|
8
|
+
import { Image } from "../atoms/image.js";
|
|
9
|
+
import { Label } from "../atoms/label.js";
|
|
10
|
+
import { tv } from "../utils.js";
|
|
11
|
+
const fileUploadStyles = tv({
|
|
12
|
+
slots: {
|
|
13
|
+
root: "flex w-full flex-col items-start gap-file-upload-root",
|
|
14
|
+
label: [
|
|
15
|
+
"font-file-upload-label text-file-upload-label text-file-upload-label-fg",
|
|
16
|
+
"data-disabled:text-file-upload-label-disabled-fg"
|
|
17
|
+
],
|
|
18
|
+
dropzone: [
|
|
19
|
+
"flex min-h-file-upload-dropzone-min-height w-full cursor-pointer flex-col items-center justify-center gap-file-upload-dropzone",
|
|
20
|
+
"file-upload-dropzone-border-dashed file-upload-dropzone-border-width rounded-file-upload-dropzone border-file-upload-dropzone-border bg-file-upload-dropzone-bg p-file-upload-dropzone",
|
|
21
|
+
"transition-colors hover:bg-file-upload-dropzone-hover-bg motion-reduce:transition-none",
|
|
22
|
+
"focus-visible:file-upload-focus",
|
|
23
|
+
"data-dragging:file-upload-dropzone-border-solid data-dragging:border-file-upload-dropzone-dragging-border data-dragging:bg-file-upload-dropzone-dragging-bg",
|
|
24
|
+
"data-invalid:border-file-upload-dropzone-invalid-border",
|
|
25
|
+
"data-disabled:cursor-not-allowed data-disabled:border-file-upload-dropzone-disabled-border data-disabled:bg-file-upload-dropzone-disabled-bg",
|
|
26
|
+
"data-readonly:cursor-default"
|
|
27
|
+
],
|
|
28
|
+
trigger: "",
|
|
29
|
+
itemGroup: "flex w-full flex-col gap-file-upload-item-group empty:hidden",
|
|
30
|
+
item: [
|
|
31
|
+
"flex w-full items-center gap-file-upload-item",
|
|
32
|
+
"file-upload-item-border-width rounded-file-upload-item border-file-upload-item-border bg-file-upload-item-bg p-file-upload-item text-file-upload-item",
|
|
33
|
+
"data-[type=rejected]:border-file-upload-item-rejected-border data-[type=rejected]:bg-file-upload-item-rejected-bg",
|
|
34
|
+
"data-disabled:text-file-upload-item-disabled-fg"
|
|
35
|
+
],
|
|
36
|
+
itemPreview: [
|
|
37
|
+
"flex size-file-upload-item-preview shrink-0 items-center justify-center overflow-hidden rounded-file-upload-item-preview text-file-upload-item-preview-fg",
|
|
38
|
+
"data-disabled:text-file-upload-item-disabled-fg"
|
|
39
|
+
],
|
|
40
|
+
itemPreviewImage: "size-full object-cover",
|
|
41
|
+
itemName: [
|
|
42
|
+
"min-w-0 flex-1 truncate font-file-upload-item-name text-file-upload-item-name-fg",
|
|
43
|
+
"data-disabled:text-file-upload-item-disabled-fg"
|
|
44
|
+
],
|
|
45
|
+
itemSizeText: [
|
|
46
|
+
"text-file-upload-item-size text-file-upload-item-size-fg",
|
|
47
|
+
"data-disabled:text-file-upload-item-disabled-fg"
|
|
48
|
+
],
|
|
49
|
+
itemDeleteTrigger: "",
|
|
50
|
+
clearTrigger: ""
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
const FileUploadContext = /*#__PURE__*/ createContext(null);
|
|
54
|
+
function useFileUploadContext() {
|
|
55
|
+
const context = useContext(FileUploadContext);
|
|
56
|
+
if (!context) throw new Error("FileUpload components must be used within FileUpload.Root");
|
|
57
|
+
return context;
|
|
58
|
+
}
|
|
59
|
+
const FileUploadItemGroupContext = /*#__PURE__*/ createContext(null);
|
|
60
|
+
function useFileUploadItemGroupContext() {
|
|
61
|
+
const context = useContext(FileUploadItemGroupContext);
|
|
62
|
+
if (!context) throw new Error("FileUpload.Item must be used within FileUpload.ItemGroup");
|
|
63
|
+
return context;
|
|
64
|
+
}
|
|
65
|
+
const FileUploadItemContext = /*#__PURE__*/ createContext(null);
|
|
66
|
+
function useFileUploadItemContext() {
|
|
67
|
+
const context = useContext(FileUploadItemContext);
|
|
68
|
+
if (!context) throw new Error("FileUpload item components must be used within FileUpload.Item");
|
|
69
|
+
return context;
|
|
70
|
+
}
|
|
71
|
+
function FileUpload({ accept, acceptedFiles, allowDrop, capture, children, className, defaultAcceptedFiles, dir = "ltr", directory, disabled, getRootNode, id, ids, invalid, locale, maxFileSize, maxFiles, minFileSize, name, onFileAccept, onFileChange, onFileReject, preventDocumentDrop, readOnly, ref, required, transformFiles, translations, validate, ...props }) {
|
|
72
|
+
const generatedId = useId();
|
|
73
|
+
const service = useMachine(machine, {
|
|
74
|
+
accept,
|
|
75
|
+
acceptedFiles,
|
|
76
|
+
allowDrop,
|
|
77
|
+
capture,
|
|
78
|
+
defaultAcceptedFiles,
|
|
79
|
+
dir,
|
|
80
|
+
directory,
|
|
81
|
+
disabled,
|
|
82
|
+
getRootNode,
|
|
83
|
+
id: id ?? generatedId,
|
|
84
|
+
ids,
|
|
85
|
+
invalid,
|
|
86
|
+
locale,
|
|
87
|
+
maxFileSize,
|
|
88
|
+
maxFiles,
|
|
89
|
+
minFileSize,
|
|
90
|
+
name,
|
|
91
|
+
onFileAccept,
|
|
92
|
+
onFileChange,
|
|
93
|
+
onFileReject,
|
|
94
|
+
preventDocumentDrop,
|
|
95
|
+
readOnly,
|
|
96
|
+
required,
|
|
97
|
+
transformFiles,
|
|
98
|
+
translations,
|
|
99
|
+
validate
|
|
100
|
+
});
|
|
101
|
+
const api = connect(service, normalizeProps);
|
|
102
|
+
const styles = fileUploadStyles();
|
|
103
|
+
const rootProps = mergeProps(props, api.getRootProps());
|
|
104
|
+
return /*#__PURE__*/ jsx(FileUploadContext.Provider, {
|
|
105
|
+
value: {
|
|
106
|
+
api,
|
|
107
|
+
required,
|
|
108
|
+
styles
|
|
109
|
+
},
|
|
110
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
111
|
+
className: styles.root({
|
|
112
|
+
className
|
|
113
|
+
}),
|
|
114
|
+
ref: ref,
|
|
115
|
+
...rootProps,
|
|
116
|
+
children: children
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
FileUpload.Context = function({ children }) {
|
|
121
|
+
const { api } = useFileUploadContext();
|
|
122
|
+
return children(api);
|
|
123
|
+
};
|
|
124
|
+
FileUpload.Label = function({ children, className, ref, ...props }) {
|
|
125
|
+
const { api, required, styles } = useFileUploadContext();
|
|
126
|
+
const labelProps = mergeProps({
|
|
127
|
+
ref
|
|
128
|
+
}, props, api.getLabelProps());
|
|
129
|
+
return /*#__PURE__*/ jsx(Label, {
|
|
130
|
+
className: styles.label({
|
|
131
|
+
className
|
|
132
|
+
}),
|
|
133
|
+
required: required,
|
|
134
|
+
size: "current",
|
|
135
|
+
...labelProps,
|
|
136
|
+
children: children
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
FileUpload.Dropzone = function({ children, className, disableClick, onClick, onKeyDown, ref, ...props }) {
|
|
140
|
+
const { api, styles } = useFileUploadContext();
|
|
141
|
+
const { onClick: onMachineClick, onKeyDown: onMachineKeyDown, ...machineDropzoneProps } = api.getDropzoneProps({
|
|
142
|
+
disableClick
|
|
143
|
+
});
|
|
144
|
+
const dropzoneProps = mergeProps(props, machineDropzoneProps, {
|
|
145
|
+
onClick (event) {
|
|
146
|
+
onClick?.(event);
|
|
147
|
+
if (!event.defaultPrevented) onMachineClick?.(event);
|
|
148
|
+
},
|
|
149
|
+
onKeyDown (event) {
|
|
150
|
+
onKeyDown?.(event);
|
|
151
|
+
if (!event.defaultPrevented) onMachineKeyDown?.(event);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return /*#__PURE__*/ jsx("div", {
|
|
155
|
+
className: styles.dropzone({
|
|
156
|
+
className
|
|
157
|
+
}),
|
|
158
|
+
ref: ref,
|
|
159
|
+
...dropzoneProps,
|
|
160
|
+
children: children
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
FileUpload.HiddenInput = function({ ref, ...props }) {
|
|
164
|
+
const { api } = useFileUploadContext();
|
|
165
|
+
const inputProps = mergeProps(props, api.getHiddenInputProps());
|
|
166
|
+
return /*#__PURE__*/ jsx("input", {
|
|
167
|
+
ref: ref,
|
|
168
|
+
...inputProps
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
FileUpload.Trigger = function({ children, className, disabled, icon = "token-icon-file-upload-trigger", onClick, ref, ...props }) {
|
|
172
|
+
const { api, styles } = useFileUploadContext();
|
|
173
|
+
const { disabled: machineDisabled, onClick: onMachineClick, ...machineTriggerProps } = api.getTriggerProps();
|
|
174
|
+
const triggerProps = mergeProps(props, machineTriggerProps);
|
|
175
|
+
const isDisabled = Boolean(disabled || machineDisabled);
|
|
176
|
+
return /*#__PURE__*/ jsx(Button, {
|
|
177
|
+
className: styles.trigger({
|
|
178
|
+
className
|
|
179
|
+
}),
|
|
180
|
+
disabled: isDisabled,
|
|
181
|
+
icon: icon,
|
|
182
|
+
onClick: (event)=>{
|
|
183
|
+
onClick?.(event);
|
|
184
|
+
if (!event.defaultPrevented) onMachineClick?.(event);
|
|
185
|
+
},
|
|
186
|
+
ref: ref,
|
|
187
|
+
size: "md",
|
|
188
|
+
theme: "outlined",
|
|
189
|
+
type: "button",
|
|
190
|
+
variant: "primary",
|
|
191
|
+
...triggerProps,
|
|
192
|
+
children: children
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
FileUpload.ItemGroup = function({ children, className, ref, type = "accepted", ...props }) {
|
|
196
|
+
const { api, styles } = useFileUploadContext();
|
|
197
|
+
const itemGroupProps = mergeProps(props, api.getItemGroupProps({
|
|
198
|
+
type
|
|
199
|
+
}));
|
|
200
|
+
return /*#__PURE__*/ jsx(FileUploadItemGroupContext.Provider, {
|
|
201
|
+
value: {
|
|
202
|
+
type
|
|
203
|
+
},
|
|
204
|
+
children: /*#__PURE__*/ jsx("ul", {
|
|
205
|
+
className: styles.itemGroup({
|
|
206
|
+
className
|
|
207
|
+
}),
|
|
208
|
+
ref: ref,
|
|
209
|
+
...itemGroupProps,
|
|
210
|
+
children: children
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
};
|
|
214
|
+
FileUpload.Item = function({ children, className, file, ref, ...props }) {
|
|
215
|
+
const { api, styles } = useFileUploadContext();
|
|
216
|
+
const { type } = useFileUploadItemGroupContext();
|
|
217
|
+
const itemProps = mergeProps(props, api.getItemProps({
|
|
218
|
+
file,
|
|
219
|
+
type
|
|
220
|
+
}));
|
|
221
|
+
return /*#__PURE__*/ jsx(FileUploadItemContext.Provider, {
|
|
222
|
+
value: {
|
|
223
|
+
file,
|
|
224
|
+
type
|
|
225
|
+
},
|
|
226
|
+
children: /*#__PURE__*/ jsx("li", {
|
|
227
|
+
className: styles.item({
|
|
228
|
+
className
|
|
229
|
+
}),
|
|
230
|
+
ref: ref,
|
|
231
|
+
...itemProps,
|
|
232
|
+
children: children
|
|
233
|
+
})
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
FileUpload.ItemPreview = function({ children, className, ref, ...props }) {
|
|
237
|
+
const { api, styles } = useFileUploadContext();
|
|
238
|
+
const { file, type } = useFileUploadItemContext();
|
|
239
|
+
const previewProps = mergeProps(props, api.getItemPreviewProps({
|
|
240
|
+
file,
|
|
241
|
+
type
|
|
242
|
+
}));
|
|
243
|
+
return /*#__PURE__*/ jsx("div", {
|
|
244
|
+
className: styles.itemPreview({
|
|
245
|
+
className
|
|
246
|
+
}),
|
|
247
|
+
ref: ref,
|
|
248
|
+
...previewProps,
|
|
249
|
+
children: children ?? /*#__PURE__*/ jsx(Icon, {
|
|
250
|
+
icon: "token-icon-file-upload-preview",
|
|
251
|
+
size: "lg"
|
|
252
|
+
})
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
FileUpload.ItemPreviewImage = function({ className, ref, ...props }) {
|
|
256
|
+
const { api, styles } = useFileUploadContext();
|
|
257
|
+
const { file, type } = useFileUploadItemContext();
|
|
258
|
+
const apiRef = useRef(api);
|
|
259
|
+
const [url, setUrl] = useState();
|
|
260
|
+
apiRef.current = api;
|
|
261
|
+
useEffect(()=>{
|
|
262
|
+
setUrl(void 0);
|
|
263
|
+
return apiRef.current.createFileUrl(file, setUrl);
|
|
264
|
+
}, [
|
|
265
|
+
file
|
|
266
|
+
]);
|
|
267
|
+
if (!url) return null;
|
|
268
|
+
const imageProps = mergeProps({
|
|
269
|
+
ref
|
|
270
|
+
}, props, api.getItemPreviewImageProps({
|
|
271
|
+
file,
|
|
272
|
+
type,
|
|
273
|
+
url
|
|
274
|
+
}));
|
|
275
|
+
const { alt, src, ...imageElementProps } = imageProps;
|
|
276
|
+
return /*#__PURE__*/ jsx(Image, {
|
|
277
|
+
alt: alt ?? file.name,
|
|
278
|
+
className: styles.itemPreviewImage({
|
|
279
|
+
className
|
|
280
|
+
}),
|
|
281
|
+
size: "custom",
|
|
282
|
+
src: src ?? url,
|
|
283
|
+
...imageElementProps
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
FileUpload.ItemName = function({ children, className, ref, ...props }) {
|
|
287
|
+
const { api, styles } = useFileUploadContext();
|
|
288
|
+
const { file, type } = useFileUploadItemContext();
|
|
289
|
+
const nameProps = mergeProps(props, api.getItemNameProps({
|
|
290
|
+
file,
|
|
291
|
+
type
|
|
292
|
+
}));
|
|
293
|
+
return /*#__PURE__*/ jsx("span", {
|
|
294
|
+
className: styles.itemName({
|
|
295
|
+
className
|
|
296
|
+
}),
|
|
297
|
+
ref: ref,
|
|
298
|
+
...nameProps,
|
|
299
|
+
children: children ?? file.name
|
|
300
|
+
});
|
|
301
|
+
};
|
|
302
|
+
FileUpload.ItemSizeText = function({ children, className, ref, ...props }) {
|
|
303
|
+
const { api, styles } = useFileUploadContext();
|
|
304
|
+
const { file, type } = useFileUploadItemContext();
|
|
305
|
+
const sizeTextProps = mergeProps(props, api.getItemSizeTextProps({
|
|
306
|
+
file,
|
|
307
|
+
type
|
|
308
|
+
}));
|
|
309
|
+
return /*#__PURE__*/ jsx("span", {
|
|
310
|
+
className: styles.itemSizeText({
|
|
311
|
+
className
|
|
312
|
+
}),
|
|
313
|
+
ref: ref,
|
|
314
|
+
...sizeTextProps,
|
|
315
|
+
children: children ?? api.getFileSize(file)
|
|
316
|
+
});
|
|
317
|
+
};
|
|
318
|
+
FileUpload.ItemDeleteTrigger = function({ className, disabled, icon = "token-icon-file-upload-delete", onClick, ref, ...props }) {
|
|
319
|
+
const { api, styles } = useFileUploadContext();
|
|
320
|
+
const { file, type } = useFileUploadItemContext();
|
|
321
|
+
const { disabled: machineDisabled, onClick: onMachineClick, ...machineDeleteProps } = api.getItemDeleteTriggerProps({
|
|
322
|
+
file,
|
|
323
|
+
type
|
|
324
|
+
});
|
|
325
|
+
const deleteProps = mergeProps(props, machineDeleteProps);
|
|
326
|
+
const isDisabled = Boolean(disabled || machineDisabled);
|
|
327
|
+
return /*#__PURE__*/ jsx(ActionIcon, {
|
|
328
|
+
className: styles.itemDeleteTrigger({
|
|
329
|
+
className
|
|
330
|
+
}),
|
|
331
|
+
disabled: isDisabled,
|
|
332
|
+
icon: icon,
|
|
333
|
+
onClick: (event)=>{
|
|
334
|
+
onClick?.(event);
|
|
335
|
+
if (!event.defaultPrevented) onMachineClick?.(event);
|
|
336
|
+
},
|
|
337
|
+
ref: ref,
|
|
338
|
+
size: "md",
|
|
339
|
+
tone: "neutral",
|
|
340
|
+
type: "button",
|
|
341
|
+
...deleteProps
|
|
342
|
+
});
|
|
343
|
+
};
|
|
344
|
+
FileUpload.ClearTrigger = function({ "aria-label": ariaLabel = "Clear files", className, disabled, icon = "token-icon-file-upload-clear", onClick, ref, ...props }) {
|
|
345
|
+
const { api, styles } = useFileUploadContext();
|
|
346
|
+
const { disabled: machineDisabled, onClick: onMachineClick, ...machineClearProps } = api.getClearTriggerProps();
|
|
347
|
+
const clearProps = mergeProps(props, machineClearProps);
|
|
348
|
+
const isDisabled = Boolean(disabled || machineDisabled);
|
|
349
|
+
return /*#__PURE__*/ jsx(ActionIcon, {
|
|
350
|
+
"aria-label": ariaLabel,
|
|
351
|
+
className: styles.clearTrigger({
|
|
352
|
+
className
|
|
353
|
+
}),
|
|
354
|
+
disabled: isDisabled,
|
|
355
|
+
icon: icon,
|
|
356
|
+
onClick: (event)=>{
|
|
357
|
+
onClick?.(event);
|
|
358
|
+
if (!event.defaultPrevented) onMachineClick?.(event);
|
|
359
|
+
},
|
|
360
|
+
ref: ref,
|
|
361
|
+
size: "md",
|
|
362
|
+
tone: "neutral",
|
|
363
|
+
type: "button",
|
|
364
|
+
...clearProps
|
|
365
|
+
});
|
|
366
|
+
};
|
|
367
|
+
FileUpload.Root = FileUpload;
|
|
368
|
+
FileUpload.displayName = "FileUpload";
|
|
369
|
+
export { FileUpload };
|