@superleapai/flow-ui 1.0.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/CHANGELOG.md +65 -0
- package/LICENSE +21 -0
- package/README.md +451 -0
- package/components/alert.js +282 -0
- package/components/avatar.js +195 -0
- package/components/badge.js +135 -0
- package/components/button.js +201 -0
- package/components/checkbox.js +254 -0
- package/components/currency.js +227 -0
- package/components/date-time-picker/date-time-picker-utils.js +253 -0
- package/components/date-time-picker/date-time-picker.js +532 -0
- package/components/duration/duration-constants.js +46 -0
- package/components/duration/duration-utils.js +164 -0
- package/components/duration/duration.js +448 -0
- package/components/enum-multiselect.js +869 -0
- package/components/enum-select.js +831 -0
- package/components/enumeration.js +213 -0
- package/components/file-input.js +533 -0
- package/components/icon.js +200 -0
- package/components/input.js +259 -0
- package/components/label.js +111 -0
- package/components/multiselect.js +351 -0
- package/components/phone-input/phone-input.js +392 -0
- package/components/phone-input/phone-utils.js +157 -0
- package/components/popover.js +240 -0
- package/components/radio-group.js +435 -0
- package/components/record-multiselect.js +956 -0
- package/components/record-select.js +930 -0
- package/components/select.js +544 -0
- package/components/spinner.js +136 -0
- package/components/table.js +335 -0
- package/components/textarea.js +114 -0
- package/components/time-picker.js +357 -0
- package/components/toast.js +343 -0
- package/core/flow.js +1729 -0
- package/core/superleapClient.js +146 -0
- package/dist/output.css +2 -0
- package/index.d.ts +458 -0
- package/index.js +253 -0
- package/package.json +70 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration Component (vanilla JS)
|
|
3
|
+
* Design-system enumeration: N clickable items that toggle between enabled/disabled icon by count.
|
|
4
|
+
* Ref: React Enumeration with cva variants (default, error, warning, success, borderless, inline).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
(function (global) {
|
|
8
|
+
"use strict";
|
|
9
|
+
|
|
10
|
+
var BASE_CLASS =
|
|
11
|
+
"flex items-center border rounded-4 text-typography-primary-text gap-4 !text-reg-13";
|
|
12
|
+
|
|
13
|
+
var VARIANTS = {
|
|
14
|
+
default:
|
|
15
|
+
"border-border-primary bg-fill-quarternary-fill-white hover:border-primary-base focus-within:border-primary-base",
|
|
16
|
+
error:
|
|
17
|
+
"border-error-base bg-fill-quarternary-fill-white hover:border-error-base focus-within:border-error-base",
|
|
18
|
+
warning:
|
|
19
|
+
"border-warning-base bg-fill-quarternary-fill-white hover:border-warning-base focus-within:border-warning-base",
|
|
20
|
+
success:
|
|
21
|
+
"border-success-base bg-fill-quarternary-fill-white hover:border-success-base focus-within:border-success-base",
|
|
22
|
+
borderless:
|
|
23
|
+
"border-none shadow-none rounded-0 bg-fill-quarternary-fill-white",
|
|
24
|
+
inline:
|
|
25
|
+
"border-none shadow-none rounded-0 bg-fill-quarternary-fill-white",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
var SIZES = {
|
|
29
|
+
default: "px-12 py-6",
|
|
30
|
+
large: "px-12 py-8",
|
|
31
|
+
small: "px-12 py-4",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
var DISABLED_CLASS =
|
|
35
|
+
"pointer-events-none !cursor-not-allowed opacity-50";
|
|
36
|
+
var READONLY_CLASS = "pointer-events-none";
|
|
37
|
+
|
|
38
|
+
var ITEM_BASE_CLASS =
|
|
39
|
+
"flex items-center justify-center text-primary-base hover:cursor-pointer";
|
|
40
|
+
|
|
41
|
+
var ITEM_ICON_SIZES = {
|
|
42
|
+
default: "size-16",
|
|
43
|
+
large: "size-20",
|
|
44
|
+
small: "size-12",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** Default icons when user does not pass enabledIcon/disabledIcon (e.g. star rating) */
|
|
48
|
+
var DEFAULT_ENABLED_ICON = '<span class="text-primary-base">★</span>';
|
|
49
|
+
var DEFAULT_DISABLED_ICON = '<span class="text-typography-quaternary-text">☆</span>';
|
|
50
|
+
|
|
51
|
+
function join() {
|
|
52
|
+
return Array.prototype.filter.call(arguments, Boolean).join(" ");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function setContent(el, content) {
|
|
56
|
+
if (content == null) return;
|
|
57
|
+
el.innerHTML = "";
|
|
58
|
+
if (typeof content === "string") {
|
|
59
|
+
el.insertAdjacentHTML("beforeend", content);
|
|
60
|
+
} else if (content instanceof HTMLElement) {
|
|
61
|
+
el.appendChild(content);
|
|
62
|
+
} else if (content instanceof Node) {
|
|
63
|
+
el.appendChild(content.cloneNode(true));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Create an enumeration component
|
|
69
|
+
* @param {Object} config
|
|
70
|
+
* @param {number} config.totalElements - Number of items (1..totalElements)
|
|
71
|
+
* @param {string|HTMLElement} config.enabledIcon - Icon shown when item index <= count
|
|
72
|
+
* @param {string|HTMLElement} config.disabledIcon - Icon shown when item index > count
|
|
73
|
+
* @param {string} [config.variant] - 'default' | 'error' | 'warning' | 'success' | 'borderless' | 'inline'
|
|
74
|
+
* @param {string} [config.size] - 'default' | 'large' | 'small'
|
|
75
|
+
* @param {string} [config.iconSize] - 'default' | 'large' | 'small' (per-item icon size)
|
|
76
|
+
* @param {number} [config.defaultValue] - Initial count (0 to totalElements)
|
|
77
|
+
* @param {boolean} [config.disabled]
|
|
78
|
+
* @param {boolean} [config.readOnly]
|
|
79
|
+
* @param {string} [config.className] - extra Tailwind/classes on container
|
|
80
|
+
* @param {Function} [config.onValueChange] - (count: number) => void
|
|
81
|
+
* @param {HTMLElement|string} [config.children] - optional content after items (node or HTML string)
|
|
82
|
+
* @returns {HTMLDivElement}
|
|
83
|
+
*/
|
|
84
|
+
function create(config) {
|
|
85
|
+
var opts = config || {};
|
|
86
|
+
var totalElements = Math.max(0, parseInt(opts.totalElements, 10) || 0);
|
|
87
|
+
var enabledIcon = opts.enabledIcon != null ? opts.enabledIcon : DEFAULT_ENABLED_ICON;
|
|
88
|
+
var disabledIcon = opts.disabledIcon != null ? opts.disabledIcon : DEFAULT_DISABLED_ICON;
|
|
89
|
+
var variant = opts.variant || "default";
|
|
90
|
+
var size = opts.size || "default";
|
|
91
|
+
var iconSize = opts.iconSize || "default";
|
|
92
|
+
var defaultValue = opts.defaultValue;
|
|
93
|
+
var disabled = opts.disabled === true;
|
|
94
|
+
var readOnly = opts.readOnly === true;
|
|
95
|
+
var className = opts.className || "";
|
|
96
|
+
var onValueChange = opts.onValueChange;
|
|
97
|
+
var children = opts.children;
|
|
98
|
+
|
|
99
|
+
var wrapper = document.createElement("div");
|
|
100
|
+
wrapper.className = join(
|
|
101
|
+
BASE_CLASS,
|
|
102
|
+
VARIANTS[variant] != null ? VARIANTS[variant] : VARIANTS.default,
|
|
103
|
+
SIZES[size] != null ? SIZES[size] : SIZES.default,
|
|
104
|
+
disabled ? DISABLED_CLASS : "",
|
|
105
|
+
readOnly ? READONLY_CLASS : "",
|
|
106
|
+
className
|
|
107
|
+
);
|
|
108
|
+
wrapper.setAttribute("data-enumeration-variant", variant);
|
|
109
|
+
|
|
110
|
+
var count =
|
|
111
|
+
defaultValue != null
|
|
112
|
+
? Math.min(totalElements, Math.max(0, parseInt(defaultValue, 10) || 0))
|
|
113
|
+
: 0;
|
|
114
|
+
|
|
115
|
+
var itemIconClass = join(
|
|
116
|
+
ITEM_BASE_CLASS,
|
|
117
|
+
ITEM_ICON_SIZES[iconSize] != null
|
|
118
|
+
? ITEM_ICON_SIZES[iconSize]
|
|
119
|
+
: ITEM_ICON_SIZES.default
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
var itemElements = [];
|
|
123
|
+
|
|
124
|
+
function updateItems() {
|
|
125
|
+
for (var i = 0; i < itemElements.length; i++) {
|
|
126
|
+
var itemEl = itemElements[i];
|
|
127
|
+
var value = i + 1;
|
|
128
|
+
var active = value <= count;
|
|
129
|
+
setContent(itemEl, active ? enabledIcon : disabledIcon);
|
|
130
|
+
itemEl.setAttribute("aria-pressed", active ? "true" : "false");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
for (var i = 0; i < totalElements; i++) {
|
|
135
|
+
var value = i + 1;
|
|
136
|
+
var item = document.createElement("div");
|
|
137
|
+
item.className = itemIconClass;
|
|
138
|
+
item.setAttribute("role", "button");
|
|
139
|
+
item.setAttribute("tabindex", disabled || readOnly ? "-1" : "0");
|
|
140
|
+
item.setAttribute("aria-pressed", value <= count ? "true" : "false");
|
|
141
|
+
item.setAttribute("aria-label", "Set value to " + value);
|
|
142
|
+
setContent(item, value <= count ? enabledIcon : disabledIcon);
|
|
143
|
+
itemElements.push(item);
|
|
144
|
+
|
|
145
|
+
if (!disabled && !readOnly) {
|
|
146
|
+
(function (val) {
|
|
147
|
+
item.addEventListener("click", function () {
|
|
148
|
+
var newCount = count === val ? 0 : val;
|
|
149
|
+
count = newCount;
|
|
150
|
+
updateItems();
|
|
151
|
+
if (typeof onValueChange === "function") {
|
|
152
|
+
onValueChange(newCount);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
item.addEventListener("keydown", function (e) {
|
|
156
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
item.click();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
})(value);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
wrapper.appendChild(item);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (children != null) {
|
|
168
|
+
if (typeof children === "string") {
|
|
169
|
+
var childWrap = document.createElement("span");
|
|
170
|
+
childWrap.innerHTML = children;
|
|
171
|
+
wrapper.appendChild(childWrap);
|
|
172
|
+
} else if (children instanceof HTMLElement || children instanceof Node) {
|
|
173
|
+
wrapper.appendChild(children);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return wrapper;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Get Tailwind class string for enumeration container (for use with custom elements)
|
|
182
|
+
* @param {Object} options - { variant, size, disabled, readOnly }
|
|
183
|
+
* @returns {string}
|
|
184
|
+
*/
|
|
185
|
+
function getEnumerationClasses(options) {
|
|
186
|
+
var o = options || {};
|
|
187
|
+
var variant = o.variant || "default";
|
|
188
|
+
var size = o.size || "default";
|
|
189
|
+
var disabled = o.disabled === true;
|
|
190
|
+
var readOnly = o.readOnly === true;
|
|
191
|
+
return join(
|
|
192
|
+
BASE_CLASS,
|
|
193
|
+
VARIANTS[variant] != null ? VARIANTS[variant] : VARIANTS.default,
|
|
194
|
+
SIZES[size] != null ? SIZES[size] : SIZES.default,
|
|
195
|
+
disabled ? DISABLED_CLASS : "",
|
|
196
|
+
readOnly ? READONLY_CLASS : ""
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
var Enumeration = {
|
|
201
|
+
create: create,
|
|
202
|
+
getEnumerationClasses: getEnumerationClasses,
|
|
203
|
+
VARIANTS: VARIANTS,
|
|
204
|
+
SIZES: SIZES,
|
|
205
|
+
ITEM_ICON_SIZES: ITEM_ICON_SIZES,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
209
|
+
module.exports = Enumeration;
|
|
210
|
+
} else {
|
|
211
|
+
global.Enumeration = Enumeration;
|
|
212
|
+
}
|
|
213
|
+
})(typeof window !== "undefined" ? window : this);
|