@luxfi/ui 7.4.11 → 7.4.13
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/alert.cjs +68 -46
- package/dist/alert.js +69 -46
- package/dist/avatar.cjs +49 -47
- package/dist/avatar.js +52 -49
- package/dist/badge.cjs +82 -49
- package/dist/badge.js +83 -50
- package/dist/checkbox.cjs +42 -75
- package/dist/checkbox.js +43 -76
- package/dist/chrome.cjs +3 -7
- package/dist/chrome.js +3 -7
- package/dist/close-button.cjs +3 -7
- package/dist/close-button.js +3 -7
- package/dist/dialog.cjs +3 -7
- package/dist/dialog.js +3 -7
- package/dist/drawer.cjs +3 -7
- package/dist/drawer.js +3 -7
- package/dist/empty-state.cjs +13 -13
- package/dist/empty-state.js +13 -13
- package/dist/expiration-selector.cjs +58 -63
- package/dist/expiration-selector.js +58 -63
- package/dist/greeks-display.cjs +48 -39
- package/dist/greeks-display.js +48 -39
- package/dist/index.cjs +1053 -888
- package/dist/index.js +1054 -889
- package/dist/input-group.cjs +36 -19
- package/dist/input-group.js +37 -19
- package/dist/option-chain.cjs +89 -67
- package/dist/option-chain.js +89 -67
- package/dist/option-position.cjs +88 -85
- package/dist/option-position.js +88 -85
- package/dist/pin-input.cjs +30 -29
- package/dist/pin-input.js +30 -29
- package/dist/pnl-diagram.cjs +20 -20
- package/dist/pnl-diagram.js +20 -20
- package/dist/popover.cjs +3 -7
- package/dist/popover.js +3 -7
- package/dist/progress-circle.cjs +40 -22
- package/dist/progress-circle.d.cts +5 -5
- package/dist/progress-circle.d.ts +5 -5
- package/dist/progress-circle.js +41 -22
- package/dist/progress.cjs +15 -22
- package/dist/progress.d.cts +6 -6
- package/dist/progress.d.ts +6 -6
- package/dist/progress.js +15 -22
- package/dist/radio.cjs +35 -68
- package/dist/radio.d.cts +18 -18
- package/dist/radio.d.ts +18 -18
- package/dist/radio.js +36 -69
- package/dist/rating.cjs +15 -17
- package/dist/rating.js +15 -17
- package/dist/slider.cjs +33 -50
- package/dist/slider.js +34 -51
- package/dist/strategy-builder.cjs +194 -115
- package/dist/strategy-builder.js +194 -115
- package/dist/switch.cjs +48 -55
- package/dist/switch.js +49 -56
- package/dist/tag.cjs +115 -69
- package/dist/tag.js +116 -69
- package/dist/tooltip.cjs +28 -17
- package/dist/tooltip.js +30 -18
- package/package.json +1 -1
- package/src/alert.tsx +78 -45
- package/src/avatar.tsx +54 -38
- package/src/badge.tsx +65 -44
- package/src/checkbox.tsx +70 -89
- package/src/close-button.tsx +3 -8
- package/src/empty-state.tsx +21 -17
- package/src/expiration-selector.tsx +84 -66
- package/src/greeks-display.tsx +59 -51
- package/src/input-group.tsx +38 -24
- package/src/option-chain.tsx +154 -104
- package/src/option-position.tsx +143 -114
- package/src/pin-input.tsx +37 -29
- package/src/pnl-diagram.tsx +36 -28
- package/src/progress-circle.tsx +52 -28
- package/src/progress.tsx +17 -21
- package/src/radio.tsx +56 -76
- package/src/rating.tsx +22 -20
- package/src/slider.tsx +43 -45
- package/src/strategy-builder.tsx +260 -162
- package/src/switch.tsx +63 -64
- package/src/tag.tsx +89 -51
- package/src/tooltip.tsx +21 -13
- package/tokens.css +18 -0
package/dist/strategy-builder.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { YStack, XStack, Text, View } from '@hanzo/gui';
|
|
2
3
|
import * as React from 'react';
|
|
3
|
-
import { clsx } from 'clsx';
|
|
4
|
-
import { twMerge } from 'tailwind-merge';
|
|
5
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
6
5
|
|
|
7
|
-
function cn(...inputs) {
|
|
8
|
-
return twMerge(clsx(inputs));
|
|
9
|
-
}
|
|
10
6
|
function findATM(strikes, spot) {
|
|
11
7
|
if (strikes.length === 0) return spot;
|
|
12
8
|
return strikes.reduce(
|
|
@@ -115,84 +111,145 @@ var STRATEGY_PRESETS = [
|
|
|
115
111
|
]
|
|
116
112
|
}
|
|
117
113
|
];
|
|
114
|
+
var MONO = "monospace";
|
|
115
|
+
var CONTROL_BOX = {
|
|
116
|
+
backgroundColor: "var(--color-input-bg)",
|
|
117
|
+
borderWidth: 1,
|
|
118
|
+
borderColor: "var(--color-input-border)",
|
|
119
|
+
outlineWidth: 0,
|
|
120
|
+
focusStyle: { borderColor: "var(--color-input-border-focus)" }
|
|
121
|
+
};
|
|
122
|
+
var CONTROL_INK = { color: "var(--color-input-fg)" };
|
|
118
123
|
function LegRow({ leg, index, strikes, expirations, removable, onChange, onRemove }) {
|
|
119
124
|
const update = (patch) => {
|
|
120
125
|
onChange(index, { ...leg, ...patch });
|
|
121
126
|
};
|
|
122
|
-
return /* @__PURE__ */ jsxs(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
return /* @__PURE__ */ jsxs(
|
|
128
|
+
XStack,
|
|
129
|
+
{
|
|
130
|
+
alignItems: "center",
|
|
131
|
+
gap: 8,
|
|
132
|
+
borderRadius: 6,
|
|
133
|
+
backgroundColor: "var(--color-tag-subtle-bg)",
|
|
134
|
+
paddingHorizontal: 8,
|
|
135
|
+
paddingVertical: 6,
|
|
136
|
+
children: [
|
|
137
|
+
/* @__PURE__ */ jsx(Text, { fontSize: 10, style: { fontFamily: MONO }, flexShrink: 0, width: 16, color: "var(--color-text-secondary)", children: index + 1 }),
|
|
138
|
+
/* @__PURE__ */ jsx(
|
|
139
|
+
XStack,
|
|
140
|
+
{
|
|
141
|
+
unstyled: true,
|
|
142
|
+
render: /* @__PURE__ */ jsx("button", { type: "button" }),
|
|
143
|
+
onClick: () => update({ action: leg.action === "buy" ? "sell" : "buy" }),
|
|
144
|
+
paddingHorizontal: 8,
|
|
145
|
+
paddingVertical: 2,
|
|
146
|
+
borderRadius: 4,
|
|
147
|
+
borderWidth: 0,
|
|
148
|
+
cursor: "pointer",
|
|
149
|
+
transition: "quick",
|
|
150
|
+
backgroundColor: leg.action === "buy" ? "color-mix(in srgb, var(--color-status-good) 20%, transparent)" : "color-mix(in srgb, var(--color-status-bad) 20%, transparent)",
|
|
151
|
+
children: /* @__PURE__ */ jsx(Text, { fontSize: 12, fontWeight: "600", color: leg.action === "buy" ? "var(--color-status-good)" : "var(--color-status-bad)", children: leg.action === "buy" ? "BUY" : "SELL" })
|
|
152
|
+
}
|
|
131
153
|
),
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
/* @__PURE__ */ jsx(
|
|
155
|
+
XStack,
|
|
156
|
+
{
|
|
157
|
+
unstyled: true,
|
|
158
|
+
render: /* @__PURE__ */ jsx("button", { type: "button" }),
|
|
159
|
+
onClick: () => update({ type: leg.type === "call" ? "put" : "call" }),
|
|
160
|
+
paddingHorizontal: 8,
|
|
161
|
+
paddingVertical: 2,
|
|
162
|
+
borderRadius: 4,
|
|
163
|
+
borderWidth: 0,
|
|
164
|
+
cursor: "pointer",
|
|
165
|
+
transition: "quick",
|
|
166
|
+
backgroundColor: leg.type === "call" ? "var(--secondary)" : "var(--muted)",
|
|
167
|
+
children: /* @__PURE__ */ jsx(Text, { fontSize: 12, fontWeight: "500", color: leg.type === "call" ? "var(--foreground)" : "var(--muted-foreground)", children: leg.type === "call" ? "CALL" : "PUT" })
|
|
168
|
+
}
|
|
144
169
|
),
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
170
|
+
/* @__PURE__ */ jsx(
|
|
171
|
+
View,
|
|
172
|
+
{
|
|
173
|
+
unstyled: true,
|
|
174
|
+
render: /* @__PURE__ */ jsx("select", { value: leg.strike, onChange: (e) => update({ strike: Number(e.target.value) }) }),
|
|
175
|
+
...CONTROL_BOX,
|
|
176
|
+
borderRadius: 4,
|
|
177
|
+
paddingHorizontal: 6,
|
|
178
|
+
paddingVertical: 2,
|
|
179
|
+
minWidth: 72,
|
|
180
|
+
style: { ...CONTROL_INK, fontFamily: MONO, fontSize: 12 },
|
|
181
|
+
children: strikes.map((s) => /* @__PURE__ */ jsx("option", { value: s, children: s.toFixed(2) }, s))
|
|
182
|
+
}
|
|
183
|
+
),
|
|
184
|
+
/* @__PURE__ */ jsx(
|
|
185
|
+
View,
|
|
186
|
+
{
|
|
187
|
+
unstyled: true,
|
|
188
|
+
render: /* @__PURE__ */ jsx("select", { value: leg.expiration, onChange: (e) => update({ expiration: e.target.value }) }),
|
|
189
|
+
...CONTROL_BOX,
|
|
190
|
+
borderRadius: 4,
|
|
191
|
+
paddingHorizontal: 6,
|
|
192
|
+
paddingVertical: 2,
|
|
193
|
+
minWidth: 80,
|
|
194
|
+
style: { ...CONTROL_INK, fontSize: 12 },
|
|
195
|
+
children: expirations.map((exp) => /* @__PURE__ */ jsx("option", { value: exp, children: exp }, exp))
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ jsx(
|
|
199
|
+
View,
|
|
200
|
+
{
|
|
201
|
+
unstyled: true,
|
|
202
|
+
render: /* @__PURE__ */ jsx(
|
|
203
|
+
"input",
|
|
204
|
+
{
|
|
205
|
+
type: "number",
|
|
206
|
+
min: 1,
|
|
207
|
+
max: 999,
|
|
208
|
+
value: leg.quantity,
|
|
209
|
+
onChange: (e) => update({ quantity: Math.max(1, parseInt(e.target.value, 10) || 1) })
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
...CONTROL_BOX,
|
|
213
|
+
borderRadius: 4,
|
|
214
|
+
paddingHorizontal: 6,
|
|
215
|
+
paddingVertical: 2,
|
|
216
|
+
width: 48,
|
|
217
|
+
style: { ...CONTROL_INK, fontFamily: MONO, fontSize: 12, textAlign: "center" }
|
|
218
|
+
}
|
|
219
|
+
),
|
|
220
|
+
leg.premium !== void 0 && /* @__PURE__ */ jsxs(
|
|
221
|
+
Text,
|
|
222
|
+
{
|
|
223
|
+
fontSize: 12,
|
|
224
|
+
style: { fontFamily: MONO },
|
|
225
|
+
fontVariant: ["tabular-nums"],
|
|
226
|
+
marginLeft: "auto",
|
|
227
|
+
color: leg.premium >= 0 ? "var(--color-status-good)" : "var(--color-status-bad)",
|
|
228
|
+
children: [
|
|
229
|
+
leg.premium >= 0 ? "+" : "",
|
|
230
|
+
leg.premium.toFixed(2)
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
),
|
|
234
|
+
removable && /* @__PURE__ */ jsx(
|
|
235
|
+
XStack,
|
|
236
|
+
{
|
|
237
|
+
unstyled: true,
|
|
238
|
+
render: /* @__PURE__ */ jsx("button", { type: "button", "aria-label": "Remove leg" }),
|
|
239
|
+
onClick: () => onRemove(index),
|
|
240
|
+
marginLeft: "auto",
|
|
241
|
+
padding: 2,
|
|
242
|
+
borderWidth: 0,
|
|
243
|
+
cursor: "pointer",
|
|
244
|
+
transition: "quick",
|
|
245
|
+
style: { color: "var(--color-text-secondary)" },
|
|
246
|
+
hoverStyle: { opacity: 0.7 },
|
|
247
|
+
children: /* @__PURE__ */ jsx("svg", { width: 14, height: 14, viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) })
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
]
|
|
251
|
+
}
|
|
252
|
+
);
|
|
196
253
|
}
|
|
197
254
|
var StrategyBuilder = React.forwardRef(
|
|
198
255
|
function StrategyBuilder2(props, ref) {
|
|
@@ -262,37 +319,46 @@ var StrategyBuilder = React.forwardRef(
|
|
|
262
319
|
});
|
|
263
320
|
}, [onSubmit, strategyType, legs, netPremium]);
|
|
264
321
|
const currentPreset = STRATEGY_PRESETS.find((p) => p.value === strategyType);
|
|
322
|
+
const netColor = netPremium > 0 ? "var(--color-status-good)" : netPremium < 0 ? "var(--color-status-bad)" : "var(--color-text-secondary)";
|
|
265
323
|
return /* @__PURE__ */ jsxs(
|
|
266
|
-
|
|
324
|
+
YStack,
|
|
267
325
|
{
|
|
268
326
|
ref,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
),
|
|
327
|
+
gap: 12,
|
|
328
|
+
borderRadius: 8,
|
|
329
|
+
borderWidth: 1,
|
|
330
|
+
borderColor: "var(--color-border-divider)",
|
|
331
|
+
backgroundColor: "var(--card)",
|
|
332
|
+
padding: 12,
|
|
333
|
+
className,
|
|
273
334
|
...rest,
|
|
274
335
|
children: [
|
|
275
|
-
/* @__PURE__ */ jsxs(
|
|
276
|
-
/* @__PURE__ */ jsxs(
|
|
277
|
-
/* @__PURE__ */ jsx(
|
|
278
|
-
/* @__PURE__ */ jsx(
|
|
336
|
+
/* @__PURE__ */ jsxs(XStack, { alignItems: "center", justifyContent: "space-between", gap: 12, children: [
|
|
337
|
+
/* @__PURE__ */ jsxs(XStack, { alignItems: "center", gap: 8, children: [
|
|
338
|
+
/* @__PURE__ */ jsx(Text, { fontSize: 12, fontWeight: "600", textTransform: "uppercase", letterSpacing: 0.6, color: "var(--color-text-secondary)", children: "Strategy" }),
|
|
339
|
+
/* @__PURE__ */ jsx(Text, { fontSize: 14, fontWeight: "500", color: "var(--color-text-primary)", children: underlying })
|
|
279
340
|
] }),
|
|
280
|
-
/* @__PURE__ */ jsxs(
|
|
341
|
+
/* @__PURE__ */ jsxs(Text, { fontSize: 10, color: "var(--color-text-secondary)", children: [
|
|
281
342
|
"Spot: ",
|
|
282
|
-
/* @__PURE__ */ jsx(
|
|
343
|
+
/* @__PURE__ */ jsx(Text, { style: { fontFamily: MONO }, fontVariant: ["tabular-nums"], color: "var(--color-text-primary)", children: spotPrice.toFixed(2) })
|
|
283
344
|
] })
|
|
284
345
|
] }),
|
|
285
|
-
/* @__PURE__ */ jsx(
|
|
286
|
-
|
|
346
|
+
/* @__PURE__ */ jsx(XStack, { alignItems: "center", gap: 8, children: /* @__PURE__ */ jsx(
|
|
347
|
+
View,
|
|
287
348
|
{
|
|
288
|
-
|
|
289
|
-
onChange: handleStrategyChange,
|
|
290
|
-
|
|
349
|
+
unstyled: true,
|
|
350
|
+
render: /* @__PURE__ */ jsx("select", { value: strategyType, onChange: handleStrategyChange }),
|
|
351
|
+
flex: 1,
|
|
352
|
+
...CONTROL_BOX,
|
|
353
|
+
borderRadius: 6,
|
|
354
|
+
paddingHorizontal: 10,
|
|
355
|
+
paddingVertical: 6,
|
|
356
|
+
style: { ...CONTROL_INK, fontSize: 14 },
|
|
291
357
|
children: STRATEGY_PRESETS.map((preset) => /* @__PURE__ */ jsx("option", { value: preset.value, children: preset.label }, preset.value))
|
|
292
358
|
}
|
|
293
359
|
) }),
|
|
294
|
-
currentPreset && /* @__PURE__ */ jsx(
|
|
295
|
-
/* @__PURE__ */ jsx(
|
|
360
|
+
currentPreset && /* @__PURE__ */ jsx(Text, { fontSize: 11, marginTop: -4, color: "var(--color-text-secondary)", children: currentPreset.description }),
|
|
361
|
+
/* @__PURE__ */ jsx(YStack, { gap: 6, children: legs.map((leg, i) => /* @__PURE__ */ jsx(
|
|
296
362
|
LegRow,
|
|
297
363
|
{
|
|
298
364
|
leg,
|
|
@@ -306,40 +372,53 @@ var StrategyBuilder = React.forwardRef(
|
|
|
306
372
|
i
|
|
307
373
|
)) }),
|
|
308
374
|
strategyType === "custom" && legs.length < 4 && /* @__PURE__ */ jsxs(
|
|
309
|
-
|
|
375
|
+
XStack,
|
|
310
376
|
{
|
|
311
|
-
|
|
377
|
+
unstyled: true,
|
|
378
|
+
render: /* @__PURE__ */ jsx("button", { type: "button" }),
|
|
312
379
|
onClick: handleAddLeg,
|
|
313
|
-
|
|
380
|
+
alignItems: "center",
|
|
381
|
+
justifyContent: "center",
|
|
382
|
+
gap: 4,
|
|
383
|
+
borderRadius: 6,
|
|
384
|
+
borderWidth: 1,
|
|
385
|
+
paddingVertical: 4,
|
|
386
|
+
cursor: "pointer",
|
|
387
|
+
transition: "quick",
|
|
388
|
+
borderColor: "var(--color-border-divider)",
|
|
389
|
+
hoverStyle: { borderColor: "var(--color-hover)" },
|
|
390
|
+
style: { color: "var(--color-text-secondary)", borderStyle: "dashed" },
|
|
314
391
|
children: [
|
|
315
|
-
/* @__PURE__ */ jsx("svg", {
|
|
316
|
-
"Add Leg"
|
|
392
|
+
/* @__PURE__ */ jsx("svg", { width: 12, height: 12, viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M12 5v14M5 12h14", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }),
|
|
393
|
+
/* @__PURE__ */ jsx(Text, { fontSize: 12, color: "var(--color-text-secondary)", children: "Add Leg" })
|
|
317
394
|
]
|
|
318
395
|
}
|
|
319
396
|
),
|
|
320
|
-
/* @__PURE__ */ jsxs(
|
|
321
|
-
/* @__PURE__ */ jsxs(
|
|
322
|
-
/* @__PURE__ */ jsx(
|
|
323
|
-
/* @__PURE__ */ jsxs("
|
|
324
|
-
"font-mono tabular-nums text-sm font-semibold",
|
|
325
|
-
netPremium > 0 ? "text-emerald-400" : netPremium < 0 ? "text-red-400" : "text-zinc-400"
|
|
326
|
-
), children: [
|
|
397
|
+
/* @__PURE__ */ jsxs(XStack, { alignItems: "center", justifyContent: "space-between", paddingTop: 4, borderTopWidth: 1, borderColor: "var(--color-border-divider)", children: [
|
|
398
|
+
/* @__PURE__ */ jsxs(XStack, { alignItems: "center", gap: 8, children: [
|
|
399
|
+
/* @__PURE__ */ jsx(Text, { fontSize: 12, color: "var(--color-text-secondary)", children: "Net:" }),
|
|
400
|
+
/* @__PURE__ */ jsxs(Text, { fontSize: 14, fontWeight: "600", style: { fontFamily: MONO }, fontVariant: ["tabular-nums"], color: netColor, children: [
|
|
327
401
|
netPremium > 0 ? "Credit " : netPremium < 0 ? "Debit " : "",
|
|
328
402
|
netPremium !== 0 ? `$${Math.abs(netPremium).toFixed(2)}` : "-"
|
|
329
403
|
] })
|
|
330
404
|
] }),
|
|
331
405
|
/* @__PURE__ */ jsx(
|
|
332
|
-
|
|
406
|
+
XStack,
|
|
333
407
|
{
|
|
334
|
-
|
|
408
|
+
unstyled: true,
|
|
409
|
+
render: /* @__PURE__ */ jsx("button", { type: "button" }),
|
|
335
410
|
onClick: handleSubmit,
|
|
336
411
|
disabled: legs.length === 0,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
412
|
+
paddingHorizontal: 16,
|
|
413
|
+
paddingVertical: 6,
|
|
414
|
+
borderRadius: 6,
|
|
415
|
+
borderWidth: 0,
|
|
416
|
+
cursor: "pointer",
|
|
417
|
+
transition: "quick",
|
|
418
|
+
backgroundColor: "var(--color-button-solid-bg)",
|
|
419
|
+
hoverStyle: { backgroundColor: "var(--color-hover)" },
|
|
420
|
+
disabledStyle: { opacity: 0.4, cursor: "not-allowed" },
|
|
421
|
+
children: /* @__PURE__ */ jsx(Text, { fontSize: 12, fontWeight: "600", color: "var(--color-button-solid-text)", children: "Review Order" })
|
|
343
422
|
}
|
|
344
423
|
)
|
|
345
424
|
] })
|
package/dist/switch.cjs
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
var gui = require('@hanzo/gui');
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var clsx = require('clsx');
|
|
7
|
-
var tailwindMerge = require('tailwind-merge');
|
|
8
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
7
|
|
|
10
8
|
function _interopNamespace(e) {
|
|
@@ -28,28 +26,17 @@ function _interopNamespace(e) {
|
|
|
28
26
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
27
|
|
|
30
28
|
// src/switch.tsx
|
|
31
|
-
function cn(...inputs) {
|
|
32
|
-
return tailwindMerge.twMerge(clsx.clsx(inputs));
|
|
33
|
-
}
|
|
34
29
|
var NOOP = () => {
|
|
35
30
|
};
|
|
36
|
-
var
|
|
37
|
-
sm: {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
label: "text-xs"
|
|
41
|
-
},
|
|
42
|
-
md: {
|
|
43
|
-
root: "h-5 w-9",
|
|
44
|
-
thumb: "h-4 w-4",
|
|
45
|
-
label: "text-sm"
|
|
46
|
-
},
|
|
47
|
-
lg: {
|
|
48
|
-
root: "h-6 w-11",
|
|
49
|
-
thumb: "h-5 w-5",
|
|
50
|
-
label: "text-base"
|
|
51
|
-
}
|
|
31
|
+
var SIZE = {
|
|
32
|
+
sm: { width: 28, height: 16, thumb: 12, label: 12 },
|
|
33
|
+
md: { width: 36, height: 20, thumb: 16, label: 14 },
|
|
34
|
+
lg: { width: 44, height: 24, thumb: 20, label: 16 }
|
|
52
35
|
};
|
|
36
|
+
var TRACK_ON = "var(--color-text-primary)";
|
|
37
|
+
var TRACK_OFF = "var(--color-switch-bg)";
|
|
38
|
+
var OUTLINE = "var(--color-gray-500)";
|
|
39
|
+
var WHITE = "var(--color-white)";
|
|
53
40
|
var SwitchBase = React__namespace.forwardRef(
|
|
54
41
|
function Switch(props, ref) {
|
|
55
42
|
const {
|
|
@@ -66,7 +53,6 @@ var SwitchBase = React__namespace.forwardRef(
|
|
|
66
53
|
disabled = false,
|
|
67
54
|
size = "md",
|
|
68
55
|
direction,
|
|
69
|
-
className,
|
|
70
56
|
...rest
|
|
71
57
|
} = props;
|
|
72
58
|
const [internalChecked, setInternalChecked] = React__namespace.useState(defaultChecked ?? false);
|
|
@@ -81,18 +67,19 @@ var SwitchBase = React__namespace.forwardRef(
|
|
|
81
67
|
},
|
|
82
68
|
[isControlled, onCheckedChange]
|
|
83
69
|
);
|
|
84
|
-
const
|
|
70
|
+
const s = SIZE[size];
|
|
85
71
|
const isRtl = direction === "rtl";
|
|
86
72
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
87
|
-
|
|
73
|
+
gui.Label,
|
|
88
74
|
{
|
|
89
75
|
ref: rootRef,
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
76
|
+
unstyled: true,
|
|
77
|
+
flexDirection: isRtl ? "row-reverse" : "row",
|
|
78
|
+
alignItems: "center",
|
|
79
|
+
gap: 8,
|
|
80
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
81
|
+
userSelect: "none",
|
|
82
|
+
opacity: disabled ? 0.5 : 1,
|
|
96
83
|
onChange,
|
|
97
84
|
"data-disabled": disabled || void 0,
|
|
98
85
|
...rest,
|
|
@@ -104,38 +91,51 @@ var SwitchBase = React__namespace.forwardRef(
|
|
|
104
91
|
checked: checkedState,
|
|
105
92
|
onCheckedChange: handleCheckedChange,
|
|
106
93
|
disabled,
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
94
|
+
position: "relative",
|
|
95
|
+
flexShrink: 0,
|
|
96
|
+
alignItems: "center",
|
|
97
|
+
width: s.width,
|
|
98
|
+
height: s.height,
|
|
99
|
+
borderRadius: 9999,
|
|
100
|
+
backgroundColor: checkedState ? TRACK_ON : TRACK_OFF,
|
|
101
|
+
transition: "quick",
|
|
102
|
+
focusStyle: { outlineWidth: 2, outlineStyle: "solid", outlineColor: OUTLINE, outlineOffset: 2 },
|
|
115
103
|
children: [
|
|
116
|
-
trackLabel && /* @__PURE__ */ jsxRuntime.jsx(
|
|
104
|
+
trackLabel && /* @__PURE__ */ jsxRuntime.jsx(
|
|
105
|
+
gui.Text,
|
|
106
|
+
{
|
|
107
|
+
position: "absolute",
|
|
108
|
+
width: "100%",
|
|
109
|
+
textAlign: "center",
|
|
110
|
+
fontSize: 8,
|
|
111
|
+
fontWeight: "700",
|
|
112
|
+
color: WHITE,
|
|
113
|
+
pointerEvents: "none",
|
|
114
|
+
children: checkedState ? trackLabel.on : trackLabel.off
|
|
115
|
+
}
|
|
116
|
+
),
|
|
117
117
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
118
118
|
gui.Switch.Thumb,
|
|
119
119
|
{
|
|
120
120
|
unstyled: true,
|
|
121
121
|
"data-thumb": true,
|
|
122
122
|
transition: "quicker",
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
width: s.thumb,
|
|
124
|
+
height: s.thumb,
|
|
125
|
+
borderRadius: 9999,
|
|
126
|
+
backgroundColor: WHITE,
|
|
127
|
+
boxShadow: "0 1px 2px 0 rgba(0,0,0,0.05)",
|
|
128
|
+
children: thumbLabel && /* @__PURE__ */ jsxRuntime.jsx(gui.Text, { width: "100%", height: "100%", textAlign: "center", fontSize: 8, children: checkedState ? thumbLabel.on : thumbLabel.off })
|
|
128
129
|
}
|
|
129
130
|
)
|
|
130
131
|
]
|
|
131
132
|
}
|
|
132
133
|
),
|
|
133
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
134
|
+
/* @__PURE__ */ jsxRuntime.jsx(gui.VisuallyHidden, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
134
135
|
"input",
|
|
135
136
|
{
|
|
136
137
|
ref,
|
|
137
138
|
type: "checkbox",
|
|
138
|
-
className: "sr-only",
|
|
139
139
|
checked: checkedState,
|
|
140
140
|
disabled,
|
|
141
141
|
tabIndex: -1,
|
|
@@ -143,15 +143,8 @@ var SwitchBase = React__namespace.forwardRef(
|
|
|
143
143
|
onChange: NOOP,
|
|
144
144
|
...inputProps
|
|
145
145
|
}
|
|
146
|
-
),
|
|
147
|
-
children != null && /* @__PURE__ */ jsxRuntime.jsx(
|
|
148
|
-
"span",
|
|
149
|
-
{
|
|
150
|
-
...labelProps,
|
|
151
|
-
className: cn(sizeClasses.label, labelProps?.className),
|
|
152
|
-
children
|
|
153
|
-
}
|
|
154
|
-
)
|
|
146
|
+
) }),
|
|
147
|
+
children != null && /* @__PURE__ */ jsxRuntime.jsx(gui.Text, { ...labelProps, fontSize: s.label, children })
|
|
155
148
|
]
|
|
156
149
|
}
|
|
157
150
|
);
|