@g4rcez/components 3.0.0 → 3.0.1

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 (176) hide show
  1. package/dist/ai/SKILL.md +266 -0
  2. package/dist/ai/docs/Alert.md +167 -0
  3. package/dist/ai/docs/AnimatedList.md +205 -0
  4. package/dist/ai/docs/Autocomplete.md +225 -0
  5. package/dist/ai/docs/Button.md +182 -0
  6. package/dist/ai/docs/Calendar.md +219 -0
  7. package/dist/ai/docs/Card.md +174 -0
  8. package/dist/ai/docs/Checkbox.md +199 -0
  9. package/dist/ai/docs/CommandPalette.md +293 -0
  10. package/dist/ai/docs/DatePicker.md +171 -0
  11. package/dist/ai/docs/Dropdown.md +223 -0
  12. package/dist/ai/docs/Empty.md +163 -0
  13. package/dist/ai/docs/Expand.md +143 -0
  14. package/dist/ai/docs/FileUpload.md +225 -0
  15. package/dist/ai/docs/Form.md +107 -0
  16. package/dist/ai/docs/FormReset.md +117 -0
  17. package/dist/ai/docs/Heading.md +88 -0
  18. package/dist/ai/docs/Input.md +237 -0
  19. package/dist/ai/docs/InputField.md +170 -0
  20. package/dist/ai/docs/List.md +205 -0
  21. package/dist/ai/docs/Menu.md +166 -0
  22. package/dist/ai/docs/Modal.md +280 -0
  23. package/dist/ai/docs/MultiSelect.md +196 -0
  24. package/dist/ai/docs/Notifications.md +231 -0
  25. package/dist/ai/docs/PageCalendar.md +271 -0
  26. package/dist/ai/docs/Polymorph.md +159 -0
  27. package/dist/ai/docs/Progress.md +145 -0
  28. package/dist/ai/docs/Radiobox.md +128 -0
  29. package/dist/ai/docs/RenderOnView.md +138 -0
  30. package/dist/ai/docs/Resizable.md +159 -0
  31. package/dist/ai/docs/Select.md +284 -0
  32. package/dist/ai/docs/Shortcut.md +105 -0
  33. package/dist/ai/docs/Skeleton.md +166 -0
  34. package/dist/ai/docs/Slider.md +144 -0
  35. package/dist/ai/docs/Slot.md +173 -0
  36. package/dist/ai/docs/Spinner.md +118 -0
  37. package/dist/ai/docs/Stats.md +137 -0
  38. package/dist/ai/docs/Step.md +159 -0
  39. package/dist/ai/docs/Switch.md +167 -0
  40. package/dist/ai/docs/Table.md +298 -0
  41. package/dist/ai/docs/Tabs.md +191 -0
  42. package/dist/ai/docs/Tag.md +224 -0
  43. package/dist/ai/docs/TaskList.md +144 -0
  44. package/dist/ai/docs/Textarea.md +167 -0
  45. package/dist/ai/docs/Timeline.md +210 -0
  46. package/dist/ai/docs/Toolbar.md +132 -0
  47. package/dist/ai/docs/Tooltip.md +231 -0
  48. package/dist/ai/docs/TransferList.md +142 -0
  49. package/dist/ai/docs/Typography.md +187 -0
  50. package/dist/ai/docs/Wizard.md +213 -0
  51. package/dist/ai/docs/index.md +183 -0
  52. package/dist/components/core/tag.d.ts +1 -1
  53. package/dist/components/core/tag.d.ts.map +1 -1
  54. package/dist/components/display/list.d.ts.map +1 -1
  55. package/dist/components/floating/dropdown.d.ts +1 -0
  56. package/dist/components/floating/dropdown.d.ts.map +1 -1
  57. package/dist/components/floating/menu.d.ts.map +1 -1
  58. package/dist/config/default-translations.d.ts +4 -4
  59. package/dist/hooks/use-translations.d.ts +4 -4
  60. package/dist/hooks/use-translations.d.ts.map +1 -1
  61. package/dist/index.css +1 -1
  62. package/dist/index.js +28 -20
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +2463 -2458
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/index.umd.js +12 -12
  67. package/dist/index.umd.js.map +1 -1
  68. package/package.json +4 -4
  69. package/dist/components/core/button.jsx +0 -79
  70. package/dist/components/core/heading.jsx +0 -4
  71. package/dist/components/core/polymorph.jsx +0 -5
  72. package/dist/components/core/render-on-view.jsx +0 -31
  73. package/dist/components/core/resizable.jsx +0 -51
  74. package/dist/components/core/slot.jsx +0 -156
  75. package/dist/components/core/tag.jsx +0 -51
  76. package/dist/components/core/typography.jsx +0 -22
  77. package/dist/components/display/alert.jsx +0 -58
  78. package/dist/components/display/calendar.jsx +0 -299
  79. package/dist/components/display/card.jsx +0 -43
  80. package/dist/components/display/empty.jsx +0 -11
  81. package/dist/components/display/list.jsx +0 -81
  82. package/dist/components/display/notifications.jsx +0 -126
  83. package/dist/components/display/progress.jsx +0 -11
  84. package/dist/components/display/shortcut.jsx +0 -23
  85. package/dist/components/display/skeleton.jsx +0 -12
  86. package/dist/components/display/spinner.jsx +0 -7
  87. package/dist/components/display/stats.jsx +0 -20
  88. package/dist/components/display/step.jsx +0 -131
  89. package/dist/components/display/tabs.jsx +0 -98
  90. package/dist/components/display/timeline.jsx +0 -25
  91. package/dist/components/floating/command-palette.jsx +0 -194
  92. package/dist/components/floating/dropdown.jsx +0 -53
  93. package/dist/components/floating/expand.jsx +0 -44
  94. package/dist/components/floating/menu.jsx +0 -147
  95. package/dist/components/floating/modal.jsx +0 -299
  96. package/dist/components/floating/toolbar.jsx +0 -5
  97. package/dist/components/floating/tooltip.jsx +0 -58
  98. package/dist/components/floating/wizard.jsx +0 -161
  99. package/dist/components/form/autocomplete.jsx +0 -279
  100. package/dist/components/form/checkbox.jsx +0 -12
  101. package/dist/components/form/date-picker.jsx +0 -115
  102. package/dist/components/form/file-upload.jsx +0 -133
  103. package/dist/components/form/form.jsx +0 -10
  104. package/dist/components/form/formReset.jsx +0 -17
  105. package/dist/components/form/free-text.jsx +0 -41
  106. package/dist/components/form/input-field.jsx +0 -56
  107. package/dist/components/form/input.jsx +0 -36
  108. package/dist/components/form/multi-select.jsx +0 -328
  109. package/dist/components/form/radiobox.jsx +0 -6
  110. package/dist/components/form/select.jsx +0 -42
  111. package/dist/components/form/slider.jsx +0 -45
  112. package/dist/components/form/switch.jsx +0 -46
  113. package/dist/components/form/task-list.jsx +0 -26
  114. package/dist/components/form/textarea.jsx +0 -12
  115. package/dist/components/form/transfer-list.jsx +0 -39
  116. package/dist/components/index.js +0 -45
  117. package/dist/components/page-calendar/calendar-header.jsx +0 -81
  118. package/dist/components/page-calendar/day-view.jsx +0 -87
  119. package/dist/components/page-calendar/event-pill.jsx +0 -25
  120. package/dist/components/page-calendar/index.js +0 -2
  121. package/dist/components/page-calendar/month-view.jsx +0 -47
  122. package/dist/components/page-calendar/page-calendar.jsx +0 -41
  123. package/dist/components/page-calendar/page-calendar.types.js +0 -1
  124. package/dist/components/page-calendar/page-calendar.utils.js +0 -71
  125. package/dist/components/page-calendar/week-view.jsx +0 -64
  126. package/dist/components/table/filter.jsx +0 -141
  127. package/dist/components/table/group.jsx +0 -68
  128. package/dist/components/table/index.jsx +0 -60
  129. package/dist/components/table/inner-table.jsx +0 -104
  130. package/dist/components/table/metadata.jsx +0 -36
  131. package/dist/components/table/pagination.jsx +0 -73
  132. package/dist/components/table/row.jsx +0 -58
  133. package/dist/components/table/sort.jsx +0 -105
  134. package/dist/components/table/table-lib.js +0 -83
  135. package/dist/components/table/table.context.jsx +0 -4
  136. package/dist/components/table/thead.jsx +0 -103
  137. package/dist/config/context.js +0 -12
  138. package/dist/config/default-translations.jsx +0 -83
  139. package/dist/config/default-tweaks.js +0 -4
  140. package/dist/constants.js +0 -2
  141. package/dist/hooks/use-click-outside.js +0 -17
  142. package/dist/hooks/use-color-parser.js +0 -9
  143. package/dist/hooks/use-components-provider.jsx +0 -19
  144. package/dist/hooks/use-debounce.js +0 -12
  145. package/dist/hooks/use-floating-ref.js +0 -6
  146. package/dist/hooks/use-form.js +0 -550
  147. package/dist/hooks/use-hover.js +0 -18
  148. package/dist/hooks/use-input-id.js +0 -5
  149. package/dist/hooks/use-is-coarse-device.js +0 -12
  150. package/dist/hooks/use-locale.js +0 -10
  151. package/dist/hooks/use-media-query.js +0 -25
  152. package/dist/hooks/use-on-event.js +0 -7
  153. package/dist/hooks/use-parent.js +0 -21
  154. package/dist/hooks/use-preferences.js +0 -23
  155. package/dist/hooks/use-previous.js +0 -9
  156. package/dist/hooks/use-reactive.js +0 -9
  157. package/dist/hooks/use-remove-scroll.js +0 -61
  158. package/dist/hooks/use-resize-observer.js +0 -17
  159. package/dist/hooks/use-stable-ref.js +0 -9
  160. package/dist/hooks/use-swipe.js +0 -17
  161. package/dist/hooks/use-translations.js +0 -9
  162. package/dist/hooks/use-tweaks.js +0 -9
  163. package/dist/hooks/use-window-size.js +0 -14
  164. package/dist/lib/combi-keys.js +0 -60
  165. package/dist/lib/dict.js +0 -39
  166. package/dist/lib/dom.js +0 -62
  167. package/dist/lib/fns.js +0 -46
  168. package/dist/lib/fzf.js +0 -117
  169. package/dist/lib/keyboard-area.js +0 -14
  170. package/dist/styles/common.js +0 -29
  171. package/dist/styles/dark.js +0 -214
  172. package/dist/styles/design-tokens.js +0 -69
  173. package/dist/styles/light.js +0 -214
  174. package/dist/styles/theme.js +0 -4
  175. package/dist/styles/theme.types.js +0 -1
  176. package/dist/types.js +0 -1
@@ -1,133 +0,0 @@
1
- "use client";
2
- import { AudioLinesIcon, FileIcon, FileJsonIcon, FileTextIcon, FileVideo2, FolderIcon, FolderOpenIcon, SheetIcon, XIcon, } from "lucide-react";
3
- import prettyBytes from "pretty-bytes";
4
- import React, { createContext, Fragment, useContext, useEffect, useState } from "react";
5
- import { useDropzone } from "react-dropzone";
6
- import { useTranslations } from "../../hooks/use-translations";
7
- import { Modal } from "../floating/modal";
8
- const Context = createContext([null, () => { }]);
9
- const useFileManager = () => useContext(Context);
10
- const getMimeType = (file) => {
11
- if (file.type.startsWith("image/"))
12
- return "img";
13
- if (file.type.startsWith("audio/"))
14
- return "audio";
15
- if (file.type.startsWith("video/"))
16
- return "video";
17
- return file.type;
18
- };
19
- const extensionMap = {
20
- csv: SheetIcon,
21
- xls: SheetIcon,
22
- mov: FileVideo2,
23
- mp4: FileVideo2,
24
- xlsx: SheetIcon,
25
- pdf: FileTextIcon,
26
- txt: FileTextIcon,
27
- json: FileJsonIcon,
28
- mp3: AudioLinesIcon,
29
- };
30
- const ItemViewer = (props) => {
31
- const [, setManager] = useFileManager();
32
- const [info, setInfo] = useState({ url: "", type: "", size: "" });
33
- useEffect(() => {
34
- const file = props.file;
35
- const url = URL.createObjectURL(file);
36
- setInfo({ url, type: getMimeType(file), size: prettyBytes(file.size) });
37
- return () => URL.revokeObjectURL(url);
38
- }, [props.file]);
39
- const onViewFile = (e) => {
40
- e.stopPropagation();
41
- e.preventDefault();
42
- setManager({ ...info, file: props.file });
43
- };
44
- const onDeleteFile = (e) => {
45
- e.preventDefault();
46
- e.stopPropagation();
47
- props.onDeleteFile?.(props.file);
48
- };
49
- const Icon = extensionMap[props.file.name.split(".").at(-1)] ?? FileIcon;
50
- const Element = info.type === "img" ? (<img src={info.url} className="w-full object-contain" alt={props.file.name}/>) : (<Icon strokeWidth={2} absoluteStrokeWidth size={48}/>);
51
- return (<li className="flex w-full flex-row justify-between gap-4 border-b border-card-border last:border-b-transparent">
52
- <div className="flex flex-col gap-4">
53
- <div className="flex flex-row items-center gap-4">
54
- <button type="button" onClick={onViewFile} className="m-2 flex size-16 max-w-16 items-center justify-center overflow-hidden">
55
- {Element}
56
- </button>
57
- <div className="flex flex-col items-start justify-start text-left">
58
- <span>{props.file.name}</span>
59
- <span className="text-sm italic">{info.size}</span>
60
- </div>
61
- </div>
62
- {props.File ? (<div className="min-w-full flex-1">
63
- <props.File file={props.file}/>
64
- </div>) : null}
65
- </div>
66
- <div className="align-start flex justify-start py-4 transition-colors duration-300 ease-linear hover:text-danger-hover">
67
- <button onClick={onDeleteFile} type="button" className="flex size-6 items-center justify-center">
68
- <XIcon size={16}/>
69
- </button>
70
- </div>
71
- </li>);
72
- };
73
- const FilesList = (props) => (<ul className="w-full space-y-8">
74
- {props.files.map((file) => {
75
- return <ItemViewer File={props.File} onDeleteFile={props.onDeleteFile} key={file.name} file={file}/>;
76
- })}
77
- </ul>);
78
- const Idle = (props) => {
79
- const t = useTranslations();
80
- const Icon = props.dragging ? FolderOpenIcon : FolderIcon;
81
- return (<div className="flex flex-col items-center justify-center">
82
- <div className="flex flex-col items-center justify-center gap-2">
83
- <Icon className="text-primary" size={80}/>
84
- </div>
85
- <div className="my-4 flex flex-col items-center gap-1">
86
- <p>{t.uploadIdle}</p>
87
- <button className="text-primary underline" type="button">
88
- {t.uploadIdleButton}
89
- </button>
90
- </div>
91
- </div>);
92
- };
93
- const InteractiveArea = (props) => {
94
- if (props.isDragActive)
95
- return <Idle files={props.files} dragging/>;
96
- if (props.files.length > 0) {
97
- return <FilesList File={props.File} onDeleteFile={props.onDeleteFile} files={props.files}/>;
98
- }
99
- return <Fragment>{props.idle}</Fragment>;
100
- };
101
- const DefaultIdle = <Idle dragging={false}/>;
102
- const FileViewer = (props) => {
103
- const file = props.item.file;
104
- const type = props.item.type;
105
- return (<div className="flex flex-col gap-4">
106
- <p className="text-lg font-medium">{props.item.file.name}</p>
107
- <p className="text-base">{props.item.size}</p>
108
- {type === "img" ? (<img className="container inline-block w-full max-w-96" src={props.item.url} alt={file.name}/>) : type === "video" ? (<video className="container block w-full max-w-96" src={props.item.url} controls muted/>) : type === "audio" ? (<figure>
109
- <audio controls src={props.item.url}></audio>
110
- </figure>) : null}
111
- </div>);
112
- };
113
- export const FileUpload = ({ idle = DefaultIdle, onDeleteFile, File, onDrop, ...props }) => {
114
- const t = useTranslations();
115
- const state = useState(null);
116
- const [files, setFiles] = useState([]);
117
- const items = props.files ?? files;
118
- const close = () => state[1](null);
119
- const drop = (x) => {
120
- onDrop?.(x);
121
- setFiles((prev) => prev.concat(x));
122
- };
123
- const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop: drop });
124
- return (<Context.Provider value={state}>
125
- <Modal overlayClickClose title={t.uploadDialogTitle} ariaTitle={t.uploadDialogTitle} open={state[0] !== null} onChange={close}>
126
- {state[0] ? <FileViewer item={state[0]}/> : null}
127
- </Modal>
128
- <div {...getRootProps()} data-active={items ? items.length > 0 : false} className="flex flex-col items-center justify-center rounded-lg border border-card-border p-6 text-foreground data-[active=true]:border-solid data-[active=false]:border-dashed data-[active=true]:border-transparent data-[active=true]:bg-card-background">
129
- <input {...getInputProps(props)} name={props.name} id={props.name}/>
130
- <InteractiveArea File={File} onDeleteFile={onDeleteFile} isDragActive={isDragActive} idle={idle} files={items}/>
131
- </div>
132
- </Context.Provider>);
133
- };
@@ -1,10 +0,0 @@
1
- "use client";
2
- import React from "react";
3
- export const Form = (props) => {
4
- const onSubmit = (e) => {
5
- e.persist();
6
- e.preventDefault();
7
- props.onSubmit?.(e);
8
- };
9
- return <form {...props} onSubmit={onSubmit}/>;
10
- };
@@ -1,17 +0,0 @@
1
- const inputFields = ["INPUT", "SELECT"];
2
- export const formReset = (form) => {
3
- if (!form)
4
- return;
5
- const elements = Array.from(form.elements);
6
- elements.forEach((field) => {
7
- if (!inputFields.includes(field.tagName))
8
- return;
9
- if (field.tagName === "INPUT") {
10
- field.value = field.defaultValue;
11
- }
12
- if (field.tagName === "SELECT") {
13
- field.value = "";
14
- }
15
- field.setAttribute("data-initialized", "false");
16
- });
17
- };
@@ -1,41 +0,0 @@
1
- "use client";
2
- import React, { forwardRef, useEffect, useRef } from "react";
3
- import { css, initializeInputDataset, mergeRefs } from "../../lib/dom";
4
- import { InputField } from "./input-field";
5
- export const createFreeText = (Element, elementName, defaultProps, register) => {
6
- const FreeText = forwardRef(({ info, left, next, error, right, container, rightLabel, interactive, optionalText, type = "text", labelClassName, feedback = null, hideLeft = false, loading, hiddenLabel, ...props }, ref) => {
7
- const Render = Element;
8
- const id = props.id ?? props.name;
9
- const inputRef = useRef(null);
10
- useEffect(() => {
11
- if (inputRef.current === null)
12
- return;
13
- const input = inputRef.current;
14
- const focus = initializeInputDataset(inputRef.current);
15
- const registered = register?.(input);
16
- const goNextInputImpl = (e) => {
17
- const event = e;
18
- if (event.key === "Enter" && input.enterKeyHint === "next") {
19
- const focusNext = input.getAttribute("data-next");
20
- if (focusNext) {
21
- const el = document.getElementById(focusNext);
22
- if (el) {
23
- el.focus();
24
- return void event.preventDefault();
25
- }
26
- }
27
- }
28
- };
29
- input.addEventListener("keydown", goNextInputImpl);
30
- return () => {
31
- registered?.();
32
- focus();
33
- input.removeEventListener("keydown", goNextInputImpl);
34
- };
35
- }, []);
36
- return (<InputField {...defaultProps} info={info} left={left} error={error} right={right} form={props.form} loading={loading} name={props.name} feedback={feedback} hideLeft={hideLeft} title={props.title} rightLabel={rightLabel} disabled={props.disabled} hiddenLabel={hiddenLabel} interactive={interactive} required={props.required} componentName={elementName} id={props.name || props.id} optionalText={optionalText} labelClassName={labelClassName} placeholder={props.placeholder} container={css(container, defaultProps.container)}>
37
- <Render {...defaultProps} {...props} id={id} name={id} type={type} data-next={next} aria-busy={props.disabled} aria-disabled={props.disabled} aria-readonly={props.readOnly} ref={mergeRefs(ref, inputRef)} className={css("input placeholder-input-mask group h-input-height w-full flex-1", "rounded-md bg-transparent px-input-x py-input-y text-base text-foreground", "outline-none transition-colors focus:ring-2 focus:ring-inset focus:ring-primary", "group-error:text-danger group-error:placeholder-input-mask-error", "resize-y group-focus-within:border-primary group-hover:border-primary", "disabled:cursor-not-allowed disabled:text-disabled", props.className)}/>
38
- </InputField>);
39
- });
40
- return FreeText;
41
- };
@@ -1,56 +0,0 @@
1
- "use client";
2
- import { CheckCircle, InfoIcon, XCircle } from "lucide-react";
3
- import React, { forwardRef, Fragment } from "react";
4
- import { useTranslations } from "../../hooks/use-translations";
5
- import { useTweaks } from "../../hooks/use-tweaks";
6
- import { css } from "../../lib/dom";
7
- import { Tooltip } from "../floating/tooltip";
8
- export const InputFeedback = ({ reportStatus, id, hideLeft = false, className, info, children, title }) => (<span className={css("w-full justify-between", hideLeft && children === null ? "hidden" : "flex", className)}>
9
- {hideLeft ? null : (<span className="flex items-center gap-1 transition-colors group-focus-within:text-primary group-hover:text-primary group-disabled:text-disabled group-error:text-danger">
10
- {title}
11
- {reportStatus || info ? (<span className="flex items-center justify-center gap-1">
12
- {info ? (<Tooltip as="button" type="button" aria-label={typeof info === "string" ? info : undefined} aria-describedby={typeof info === "string" ? undefined : id ? `tooltip-info-content-${id}` : undefined} title={<span className="cursor-help">
13
- <InfoIcon className="aspect-square size-3" aria-hidden="true" size={16} strokeWidth={1} absoluteStrokeWidth/>
14
- </span>}>
15
- <div id={id ? `tooltip-info-content-${id}` : undefined} className="w-full max-w-48 whitespace-break-spaces break-words">
16
- {info}
17
- </div>
18
- </Tooltip>) : null}
19
- {reportStatus ? (<span className="flex h-3 min-w-6 items-center">
20
- <CheckCircle className="hidden aspect-square size-3 opacity-0 transition-opacity group-assert:block group-assert:text-success group-assert:opacity-100" aria-hidden="true" size={16} strokeWidth={1} absoluteStrokeWidth/>
21
- <XCircle className="hidden aspect-square size-3 opacity-0 transition-opacity group-error:block group-error:opacity-100" aria-hidden="true" size={16} strokeWidth={1} absoluteStrokeWidth/>
22
- </span>) : null}
23
- </span>) : null}
24
- </span>)}
25
- {children}
26
- </span>);
27
- export const InputField = forwardRef(({ optionalText: _optionalText, left, rightLabel, container, feedback, interactive, right, info, children, error, form, id, labelClassName = "", name, title, componentName, placeholder, hideLeft = false, required, disabled, reportStatus, hiddenLabel, }, ref) => {
28
- const tweaks = useTweaks();
29
- const reportStatusDefault = reportStatus !== undefined ? reportStatus : tweaks.input.iconFeedback;
30
- const ID = id ?? name;
31
- const translation = useTranslations();
32
- const optionalText = _optionalText ?? translation.inputOptionalLabel;
33
- return (<fieldset ref={ref} form={form} disabled={disabled} data-error={!!error} aria-disabled={disabled} data-component={componentName} data-interactive={!!interactive} className={css("group flex min-h-0 min-w-0 max-w-full flex-col items-start", container)}>
34
- <label form={form} htmlFor={ID} className="relative inline-flex w-full max-w-full cursor-text flex-row flex-wrap justify-between gap-1 text-field-label text-sm transition-colors empty:hidden group-disabled:cursor-not-allowed group-error:text-danger">
35
- {hiddenLabel ? null : (<InputFeedback info={info} hideLeft={hideLeft} reportStatus={reportStatusDefault} title={title} placeholder={placeholder}>
36
- {optionalText || rightLabel ? (<Fragment>
37
- {!required ? (<span aria-disabled={disabled} className="text-opacity-70 transition-colors group-focus-within:text-primary group-hover:text-primary aria-disabled:text-disabled">
38
- {optionalText}
39
- </span>) : null}
40
- {rightLabel ? <Fragment>{rightLabel}</Fragment> : null}
41
- </Fragment>) : null}
42
- </InputFeedback>)}
43
- <div className={`group relative flex w-full flex-row flex-nowrap items-center gap-x-2 gap-y-1 rounded-md border border-input-border bg-transparent transition-colors group-hover:border-primary group-disabled:border-disabled group-error:border-danger ${labelClassName}`}>
44
- {left ? <span className="flex flex-nowrap gap-1 whitespace-nowrap pl-2">{left}</span> : null}
45
- {children}
46
- {right ? <span className="flex flex-nowrap gap-2 whitespace-nowrap pr-2">{right}</span> : null}
47
- </div>
48
- </label>
49
- <p className="mt-input-gap hidden whitespace-pre-wrap text-wrap text-xs empty:mt-0 empty:hidden group-has-[input:not(:focus):invalid[data-initialized=true]]:flex group-error:flex group-error:text-danger">
50
- {error}
51
- </p>
52
- <p className="mt-input-gap text-xs empty:mt-0 empty:hidden group-has-[input:not(:focus):valid[data-initialized=true]]:block group-assert:block group-error:hidden">
53
- {feedback}
54
- </p>
55
- </fieldset>);
56
- });
@@ -1,36 +0,0 @@
1
- "use client";
2
- import MaskInput from "the-mask-input";
3
- import { createFreeText } from "./free-text";
4
- /**
5
- * A text input component with advanced masking capabilities.
6
- *
7
- * Supports various input masks including:
8
- * - Currency formatting with locale support
9
- * - Percentage inputs
10
- * - Custom regex patterns
11
- * - Phone numbers, dates, and other formatted inputs
12
- *
13
- * @example
14
- * ```tsx
15
- * // Basic input
16
- * <Input placeholder="Enter text..." />
17
- *
18
- * // Phone number mask
19
- * <Input mask="(99) 99999-9999" placeholder="Phone" />
20
- *
21
- * // Currency input
22
- * <Input mask="currency" currency="USD" locale="en-US" />
23
- *
24
- * // Percentage input
25
- * <Input mask="percentage" />
26
- *
27
- * // Custom mask
28
- * <Input mask={["999.999.999-99"]} placeholder="CPF" />
29
- * ```
30
- *
31
- * @param props - Input props including mask, validation, and styling options
32
- * @returns A masked input component with form integration
33
- */
34
- export const Input = createFreeText(MaskInput, "input", {
35
- type: "text",
36
- });
@@ -1,328 +0,0 @@
1
- "use client";
2
- import { autoUpdate, FloatingFocusManager, FloatingOverlay, FloatingPortal, offset, size, useDismiss, useFloating, useInteractions, useListNavigation, useRole, useTransitionStyles, } from "@floating-ui/react";
3
- import { ChevronDown, XIcon } from "lucide-react";
4
- import { AnimatePresence, motion } from "motion/react";
5
- import React, { forwardRef, Fragment, useEffect, useMemo, useRef, useState } from "react";
6
- import { flushSync } from "react-dom";
7
- import { Virtuoso } from "react-virtuoso";
8
- import { useRemoveScroll } from "../../hooks/use-remove-scroll";
9
- import { useTranslations } from "../../hooks/use-translations";
10
- import { Dict } from "../../lib/dict";
11
- import { css, getRemainingSize, initializeInputDataset } from "../../lib/dom";
12
- import { noop } from "../../lib/fns";
13
- import { fzf } from "../../lib/fzf";
14
- import { Tag } from "../core/tag";
15
- import { Checkbox } from "./checkbox";
16
- import { InputField } from "./input-field";
17
- const MIN_SIZE = 40;
18
- const Frag = (props) => <Fragment>{props.children}</Fragment>;
19
- const transitionStyles = {
20
- duration: 300,
21
- initial: { transform: "scaleY(0)", opacity: 0.2 },
22
- open: { transform: "scaleY(1)", opacity: 1 },
23
- close: { transform: "scaleY(0)", opacity: 0 },
24
- };
25
- const emptyRef = [];
26
- const List = forwardRef(function VirtualList(props, ref) {
27
- return (<motion.ul {...props} role="listbox" ref={ref} className="w-full rounded-b-lg border-b border-tooltip-border last:border-transparent">
28
- <AnimatePresence>{props.children}</AnimatePresence>
29
- </motion.ul>);
30
- });
31
- const Item = forwardRef(function VirtualItem({ item, context, ...props }, ref) {
32
- return <motion.li {...props} ref={ref} className="last:rounded-t-lg"/>;
33
- });
34
- const components = { List, Item };
35
- const OverflowControl = (props) => {
36
- const translate = useTranslations();
37
- const ref = useRef(null);
38
- const countable = React.Children.count(props.children);
39
- const [normalView, setNormalView] = useState(false);
40
- useEffect(() => {
41
- if (ref.current === null)
42
- return;
43
- const parent = ref.current.parentElement.getBoundingClientRect();
44
- const items = Array.from(ref.current.querySelectorAll("[data-component='tag']"));
45
- const child = items.reduce((acc, el) => acc + el.getBoundingClientRect().width, 0);
46
- const hasOnlyCounter = ref.current.querySelectorAll("[data-multicounter]").length;
47
- if (hasOnlyCounter && countable <= 3)
48
- return setNormalView(false);
49
- if (child > parent.width)
50
- return setNormalView(true);
51
- }, [countable]);
52
- return (<span ref={ref} className="flex flex-nowrap gap-x-2">
53
- {!normalView ? (props.children) : (<Tag size="small" data-multicounter="true">
54
- {countable} {translate.multiSelectSelectedLabel}
55
- </Tag>)}
56
- </span>);
57
- };
58
- export const MultiSelect = forwardRef(({ left, error, right, options, container, rightLabel, interactive, emptyMessage, optionalText, selectedLabel, labelClassName, feedback = null, hideLeft = false, required = false, dynamicOption = false, onChangeOptions, ...props }, externalRef) => {
59
- const map = useMemo(() => new Dict(options.map((x) => [x.value, x])), [options]);
60
- const fieldset = useRef(null);
61
- const virtuoso = useRef(null);
62
- const defaults = props.value ?? props.defaultValue ?? emptyRef;
63
- const translation = useTranslations();
64
- const [h, setH] = useState(0);
65
- const [open, setOpen] = useState(false);
66
- const [shadow, setShadow] = useState("");
67
- const [value, setValue] = useState(() => {
68
- const d = new Dict();
69
- defaults.forEach((x) => {
70
- const result = map.get(x);
71
- return result ? d.set(x, result) : undefined;
72
- });
73
- return d;
74
- });
75
- const values = useMemo(() => Array.from(value.keys()), [value]);
76
- const [label, setLabel] = useState(() => {
77
- const d = new Set(defaults);
78
- return options.reduce((acc, x) => (d.has(x.value) ? [...acc, x.label ?? x.value] : acc), []) ?? defaults;
79
- });
80
- const [index, setIndex] = useState(null);
81
- const listRef = useRef(emptyRef);
82
- const innerOptions = dynamicOption && shadow !== ""
83
- ? [
84
- {
85
- value: shadow,
86
- label: shadow,
87
- "data-dynamic": "true",
88
- },
89
- ...options,
90
- ]
91
- : options;
92
- const list = shadow.length === 0
93
- ? innerOptions
94
- : fzf(innerOptions, "value", [
95
- { key: "value", value: shadow },
96
- { key: "label", value: shadow },
97
- ]);
98
- const removeScrollRef = useRemoveScroll(open, "block-only");
99
- const displayList = list.filter((x) => x.hidden !== true);
100
- const isEmpty = displayList.length === 0;
101
- const { x, y, strategy, refs, context } = useFloating({
102
- open,
103
- transform: true,
104
- placement: "bottom-start",
105
- strategy: "absolute",
106
- onOpenChange: setOpen,
107
- whileElementsMounted: autoUpdate,
108
- middleware: [
109
- offset(4),
110
- size({
111
- padding: 10,
112
- elementContext: "reference",
113
- apply(args) {
114
- const ul = args.elements.floating.querySelector("ul");
115
- const fullSize = ul?.getBoundingClientRect().height || 0;
116
- const DEFAULT_SIZE = getRemainingSize(refs.reference.current, window.innerHeight);
117
- const maxH = Math.min(fullSize < MIN_SIZE ? DEFAULT_SIZE : fullSize, DEFAULT_SIZE, args.availableHeight);
118
- const size = displayList.length === 0 ? MIN_SIZE : Math.min(maxH, DEFAULT_SIZE, fullSize);
119
- const mw = `${fieldset.current.getBoundingClientRect().width}px`;
120
- Object.assign(args.elements.floating.style, { width: mw, maxWidth: mw, height: size });
121
- },
122
- }),
123
- ],
124
- });
125
- const transitions = useTransitionStyles(context, transitionStyles);
126
- const { getReferenceProps, getFloatingProps, getItemProps } = useInteractions([
127
- useRole(context, { role: "listbox" }),
128
- useDismiss(context),
129
- useListNavigation(context, {
130
- cols: 0,
131
- listRef,
132
- loop: true,
133
- virtual: true,
134
- allowEscape: true,
135
- activeIndex: index,
136
- selectedIndex: index,
137
- focusItemOnOpen: "auto",
138
- openOnArrowKeyDown: true,
139
- scrollItemIntoView: true,
140
- onNavigate: (n) => setIndex((prev) => n ?? prev),
141
- }),
142
- ]);
143
- useEffect(() => {
144
- if (!open)
145
- return setH(0);
146
- const inputRef = refs.reference;
147
- if (inputRef.current === null)
148
- return;
149
- const s = getRemainingSize(inputRef.current, window.innerHeight);
150
- setTimeout(() => setH(Math.min(s, displayList.length * 40)), 100);
151
- }, [shadow, open, refs.reference]);
152
- useEffect(() => {
153
- if (props.value) {
154
- setValue(new Dict(props.value.map((x) => [x, map.get(x)])));
155
- }
156
- }, [props.value, map]);
157
- useEffect(() => {
158
- const input = refs.reference.current;
159
- if (!input)
160
- return;
161
- return initializeInputDataset(input);
162
- }, []);
163
- const onSelect = (opt, i) => {
164
- const clone = value.clone((c) => {
165
- if (c.has(opt.value))
166
- return c.remove(opt.value);
167
- return c.set(opt.value, opt);
168
- });
169
- setValue(clone);
170
- const input = refs.reference.current;
171
- if (!input)
172
- return;
173
- const options = clone.map((x) => x.value);
174
- input?.setAttribute("data-value", JSON.stringify(options));
175
- if (onChangeOptions)
176
- onChangeOptions(options);
177
- setLabel((prev) => prev.concat(opt.label ?? ""));
178
- setShadow("");
179
- setIndex(i);
180
- };
181
- const onChange = (event) => {
182
- const value = event.target.value;
183
- setShadow(value);
184
- if (!open && value === "")
185
- return setOpen(true);
186
- event.target.name = props.name || "";
187
- return value ? setOpen(true) : undefined;
188
- };
189
- const onCaretDownClick = () => {
190
- setOpen(true);
191
- setShadow("");
192
- refs.reference.current?.focus();
193
- };
194
- const onFocus = () => {
195
- setOpen(true);
196
- setShadow("");
197
- };
198
- const onClose = () => {
199
- refs.reference.current?.setAttribute("data-value", "[]");
200
- setShadow("");
201
- setOpen(false);
202
- setValue(new Dict());
203
- onChangeOptions?.([]);
204
- };
205
- const id = props.id || props.name;
206
- const tags = value.map((x, i) => (<Tag size="small" key={`MultiSelect-${x.value}-x`} icon={<button type="button" className="text-current hover:text-danger focus:text-danger" onClick={(e) => {
207
- e.preventDefault();
208
- e.stopPropagation();
209
- onSelect(x, i);
210
- }}>
211
- <XIcon size={14}/>
212
- </button>}>
213
- {x.label ?? x.value}
214
- </Tag>));
215
- const scrollableContainerStyle = { height: isEmpty ? "0" : value.size === 0 ? h - 49 : h - 86 };
216
- return (<InputField {...props} left={left} error={error} ref={fieldset} form={props.form} name={props.name} feedback={feedback} hideLeft={hideLeft} required={required} title={props.title} container={container} rightLabel={rightLabel} interactive={interactive} id={props.name || props.id} optionalText={optionalText} componentName="autocomplete" labelClassName={labelClassName} placeholder={props.placeholder} right={<span className="flex items-center gap-0.5">
217
- {right}
218
- <button type="button" className="transition-colors link:text-primary" onClick={onCaretDownClick}>
219
- <ChevronDown size={20}/>
220
- <span className="sr-only">{translation.inputCaretDown}</span>
221
- </button>
222
- {value ? (<button type="button" onClick={onClose} className="transition-colors link:text-danger">
223
- <svg width="15" height="15" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
224
- <path d="M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z" fill="currentColor" fillRule="evenodd" clipRule="evenodd"/>
225
- </svg>
226
- </button>) : null}
227
- </span>}>
228
- <ul {...getReferenceProps({
229
- ...props,
230
- onFocus,
231
- id: `${id}-shadow`,
232
- name: `${id}-shadow`,
233
- ref: refs.setReference,
234
- })} tabIndex={0} role="button" data-name={id} data-target={id} data-shadow="true" data-error={!!error} aria-autocomplete="list" data-value={values.join(",")} className={css("input placeholder-input-mask group h-input-height w-full text-base", "rounded-md bg-transparent px-input-x py-input-y text-foreground", "outline-none transition-colors focus:ring-2 focus:ring-inset focus:ring-primary", "group-error:text-danger group-error:placeholder-input-mask-error", "group-focus-within:border-primary group-hover:border-primary", "flex flex-row items-center gap-2 whitespace-nowrap text-left", "max-w-full overflow-x-auto truncate overflow-ellipsis", props.className)}>
235
- {values.length > 0 ? null : <li className="text-input-placeholder">{props.placeholder}</li>}
236
- <OverflowControl label={selectedLabel}>{tags}</OverflowControl>
237
- </ul>
238
- <input id={id} name={id} type="hidden" data-origin={id} ref={externalRef} required={required} defaultValue={props.value || values || undefined}/>
239
- <FloatingPortal preserveTabOrder>
240
- {open ? (<FloatingOverlay lockScroll>
241
- <FloatingFocusManager modal guards returnFocus={false} context={context} initialFocus={-1} visuallyHiddenDismiss>
242
- <div {...getFloatingProps({
243
- ref: refs.setFloating,
244
- style: {
245
- ...transitions.styles,
246
- top: y ?? 0,
247
- position: strategy,
248
- left: x,
249
- height: h - (values.length === 0 ? 65 : 30),
250
- },
251
- })} data-floating="true" className="shadow-floating isolate z-floating m-0 max-h-96 w-full origin-[top_center] list-none overscroll-contain rounded-b-lg rounded-t-lg border border-floating-border bg-floating-background p-0 text-foreground">
252
- <input autoFocus value={shadow} onChange={onChange} title={props.title} placeholder={translation.multiSelectInnerPlaceholder} className="input placeholder-input-mask group mb-1 h-10 w-full flex-1 rounded border-b border-input-border bg-transparent px-input-x py-input-y outline-none transition-colors focus:ring-2 focus:ring-inset focus:ring-primary" onKeyDown={(event) => {
253
- if (event.key === "ArrowDown") {
254
- let next = index + 1;
255
- if (next > displayList.length - 1)
256
- next = 0;
257
- virtuoso.current?.scrollIntoView({ index: next });
258
- return setIndex(next);
259
- }
260
- if (event.key === "ArrowUp") {
261
- let next = index - 1;
262
- if (next < 0)
263
- next = displayList.length - 1;
264
- virtuoso.current?.scrollIntoView({ index: next });
265
- return setIndex(next);
266
- }
267
- if (event.key === "Escape") {
268
- event.currentTarget.blur();
269
- return setOpen(false);
270
- }
271
- if (event.key === "Enter") {
272
- if (index !== null && displayList[index]) {
273
- event.preventDefault();
274
- return onSelect(displayList[index], index);
275
- }
276
- if (displayList.length === 1) {
277
- event.preventDefault();
278
- return onSelect(displayList[0], 0);
279
- }
280
- }
281
- }}/>
282
- {isEmpty ? (<li role="option" className="w-full border-b border-tooltip-border last:border-transparent">
283
- <span className="flex w-full justify-between p-2 text-left text-disabled">
284
- {emptyMessage || translation.autocompleteEmpty}
285
- </span>
286
- </li>) : null}
287
- {isEmpty ? null : (<motion.div initial={false} data-floating="true" ref={removeScrollRef} animate={{ height: isEmpty ? "auto" : h }} style={scrollableContainerStyle} className="max-h-72 w-full overscroll-contain" onAnimationComplete={() => {
288
- if (!open)
289
- return setH(0);
290
- const ul = refs.floating.current;
291
- const li = ul.querySelectorAll("li").item(0);
292
- const sum = (li ? li.getBoundingClientRect().height : 40) * displayList.length;
293
- return flushSync(() => setH(sum + 2));
294
- }}>
295
- <Virtuoso ref={virtuoso} hidden={isEmpty} data={displayList} components={components} style={scrollableContainerStyle} className="max-h-72 border-floating-border bg-floating-background p-0 text-foreground" itemContent={(i, option) => {
296
- const Label = option.Render ?? Frag;
297
- const active = value.has(option.value) || value.has(option.label ?? "");
298
- const selected = index === i;
299
- const children = option.label ?? option.value;
300
- return (<button data-value={option.value} {...getItemProps({
301
- ref: (node) => void (listRef.current[i] = node),
302
- role: "option",
303
- type: "button",
304
- "aria-checked": active,
305
- "aria-current": active,
306
- "aria-selected": active,
307
- "aria-busy": option.disabled,
308
- onClick: () => onSelect(option, i),
309
- })} className={`flex w-full max-w-full cursor-pointer items-center justify-start p-2 text-left hover:bg-floating-hover focus:bg-floating-hover ${active || selected ? "bg-floating-hover text-floating-foreground" : ""}`}>
310
- <Checkbox onChange={noop} checked={active} aria-checked={active} onClick={(e) => {
311
- e.stopPropagation();
312
- onSelect(option, i);
313
- }}/>
314
- <Label {...props} label={option.label} value={option.value} children={children}/>
315
- </button>);
316
- }}/>
317
- </motion.div>)}
318
- <div className="sticky bottom-0 flex w-full flex-nowrap items-center gap-2 overflow-x-auto rounded-b-lg bg-floating-background p-2">
319
- {value.size === 0 ? (<Tag theme="muted" size="small">
320
- {translation.autocompleteEmpty}
321
- </Tag>) : (tags)}
322
- </div>
323
- </div>
324
- </FloatingFocusManager>
325
- </FloatingOverlay>) : null}
326
- </FloatingPortal>
327
- </InputField>);
328
- });
@@ -1,6 +0,0 @@
1
- import React from "react";
2
- import { css } from "../../lib/dom";
3
- export const Radiobox = ({ children, className = "", size, ...props }) => (<label data-component="radiobox" data-disabled={props.disabled} aria-disabled={props.disabled} className="group flex items-center gap-2 font-normal data-[disabled=true]:cursor-not-allowed">
4
- <input {...props} type="radio" className={css("app form-radio inline-block h-4 w-4 appearance-none rounded-full border-card-border bg-origin-border text-primary focus:ring-primary disabled:opacity-70 group-aria-disabled:cursor-not-allowed", className)} {...props}/>
5
- {children}
6
- </label>);