@enonic/ui 0.10.0 → 0.11.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/enonic-ui.cjs +7 -7
- package/dist/enonic-ui.es.js +231 -40
- package/dist/styles/preset.css +1 -1
- package/dist/styles/style.css +1 -1
- package/dist/styles/tokens.css +1 -1
- package/dist/styles/utilities.css +1 -1
- package/dist/types/components/button/button.d.ts +6 -3
- package/dist/types/components/button/index.d.ts +1 -1
- package/dist/types/components/dialog/dialog.d.ts +107 -0
- package/dist/types/components/dialog/index.d.ts +3 -0
- package/dist/types/components/icon-button/icon-button.d.ts +2 -2
- package/dist/types/components/index.d.ts +1 -0
- package/dist/types/components/list-item/list-item.d.ts +10 -10
- package/dist/types/components/listbox/index.d.ts +1 -0
- package/dist/types/components/listbox/listbox.d.ts +33 -0
- package/dist/types/components/selectable-list-item/selectable-list-item.d.ts +2 -2
- package/dist/types/components/separator/index.d.ts +2 -0
- package/dist/types/components/separator/separator.d.ts +10 -0
- package/dist/types/components/tooltip/tooltip.d.ts +2 -2
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/use-scroll-lock.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/providers/dialog-provider.d.ts +14 -0
- package/dist/types/providers/{id-provider/id-provider.d.ts → id-provider.d.ts} +2 -2
- package/dist/types/providers/index.d.ts +1 -0
- package/package.json +32 -27
- package/dist/types/providers/id-provider/index.d.ts +0 -1
package/dist/enonic-ui.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { options, Fragment } from "preact";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { forwardRef, createContext, useId, useContext, createElement, useState, isValidElement, Children, useRef, useEffect, useCallback, createPortal } from "react";
|
|
3
|
+
import { forwardRef, createContext, useId, useContext, createElement, useState, isValidElement, Children, useRef, useEffect, useCallback, createPortal, useMemo } from "react";
|
|
4
4
|
import "preact/compat";
|
|
5
5
|
import { useState as useState$1 } from "preact/hooks";
|
|
6
6
|
var f = 0;
|
|
@@ -3028,18 +3028,18 @@ const cva = (base, config) => (props) => {
|
|
|
3028
3028
|
const buttonVariants = cva(
|
|
3029
3029
|
[
|
|
3030
3030
|
"inline-flex items-center justify-center",
|
|
3031
|
-
"text-main
|
|
3031
|
+
"text-main font-medium",
|
|
3032
3032
|
"box-border rounded-sm transition-highlight",
|
|
3033
3033
|
"focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-offset-0",
|
|
3034
|
-
"disabled:pointer-events-none disabled:opacity-30",
|
|
3035
|
-
"cursor-pointer"
|
|
3034
|
+
"disabled:select-none disabled:pointer-events-none disabled:opacity-30",
|
|
3035
|
+
"overflow-hidden text-ellipsis whitespace-nowrap cursor-pointer"
|
|
3036
3036
|
],
|
|
3037
3037
|
{
|
|
3038
3038
|
variants: {
|
|
3039
3039
|
variant: {
|
|
3040
3040
|
text: "bg-btn-primary hover:bg-btn-primary-hover active:bg-btn-active active:text-rev dark:active:text-main",
|
|
3041
3041
|
filled: "bg-btn-secondary hover:bg-btn-secondary-hover active:bg-btn-active active:text-rev dark:active:text-main",
|
|
3042
|
-
solid: "bg-btn-tertiary text-
|
|
3042
|
+
solid: "bg-btn-tertiary text-alt hover:bg-btn-tertiary-hover active:bg-btn-active dark:active:text-main",
|
|
3043
3043
|
outline: "bg-btn-primary hover:bg-btn-primary-hover active:bg-btn-active active:text-rev dark:active:text-main border border-bdr-strong"
|
|
3044
3044
|
},
|
|
3045
3045
|
size: {
|
|
@@ -3065,7 +3065,19 @@ const getIconSize = (size) => {
|
|
|
3065
3065
|
}
|
|
3066
3066
|
};
|
|
3067
3067
|
const Button = forwardRef(
|
|
3068
|
-
({
|
|
3068
|
+
({
|
|
3069
|
+
className,
|
|
3070
|
+
variant = "text",
|
|
3071
|
+
size = "md",
|
|
3072
|
+
iconSize,
|
|
3073
|
+
iconStrokeWidth = 1.5,
|
|
3074
|
+
startIcon,
|
|
3075
|
+
label,
|
|
3076
|
+
endIcon,
|
|
3077
|
+
title,
|
|
3078
|
+
children,
|
|
3079
|
+
...props
|
|
3080
|
+
}, ref) => {
|
|
3069
3081
|
const StartIcon = startIcon;
|
|
3070
3082
|
const EndIcon = endIcon;
|
|
3071
3083
|
const iconSizeValue = iconSize ?? getIconSize(size ?? "md");
|
|
@@ -3080,10 +3092,10 @@ const Button = forwardRef(
|
|
|
3080
3092
|
"aria-disabled": props.disabled,
|
|
3081
3093
|
...props,
|
|
3082
3094
|
children: [
|
|
3083
|
-
StartIcon && /* @__PURE__ */ u(StartIcon, { size: iconSizeValue, strokeWidth:
|
|
3095
|
+
StartIcon && /* @__PURE__ */ u(StartIcon, { size: iconSizeValue, strokeWidth: iconStrokeWidth }),
|
|
3084
3096
|
children,
|
|
3085
3097
|
label,
|
|
3086
|
-
EndIcon && /* @__PURE__ */ u(EndIcon, { size: iconSizeValue, strokeWidth:
|
|
3098
|
+
EndIcon && /* @__PURE__ */ u(EndIcon, { size: iconSizeValue, strokeWidth: iconStrokeWidth })
|
|
3087
3099
|
]
|
|
3088
3100
|
}
|
|
3089
3101
|
);
|
|
@@ -3105,7 +3117,7 @@ const usePrefixedId = (providedId) => {
|
|
|
3105
3117
|
return id;
|
|
3106
3118
|
};
|
|
3107
3119
|
/**
|
|
3108
|
-
* @license lucide-react v0.
|
|
3120
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3109
3121
|
*
|
|
3110
3122
|
* This source code is licensed under the ISC license.
|
|
3111
3123
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3130,7 +3142,7 @@ const hasA11yProp = (props) => {
|
|
|
3130
3142
|
}
|
|
3131
3143
|
};
|
|
3132
3144
|
/**
|
|
3133
|
-
* @license lucide-react v0.
|
|
3145
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3134
3146
|
*
|
|
3135
3147
|
* This source code is licensed under the ISC license.
|
|
3136
3148
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3147,7 +3159,7 @@ var defaultAttributes = {
|
|
|
3147
3159
|
strokeLinejoin: "round"
|
|
3148
3160
|
};
|
|
3149
3161
|
/**
|
|
3150
|
-
* @license lucide-react v0.
|
|
3162
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3151
3163
|
*
|
|
3152
3164
|
* This source code is licensed under the ISC license.
|
|
3153
3165
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3182,7 +3194,7 @@ const Icon = forwardRef(
|
|
|
3182
3194
|
)
|
|
3183
3195
|
);
|
|
3184
3196
|
/**
|
|
3185
|
-
* @license lucide-react v0.
|
|
3197
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3186
3198
|
*
|
|
3187
3199
|
* This source code is licensed under the ISC license.
|
|
3188
3200
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3204,7 +3216,7 @@ const createLucideIcon = (iconName, iconNode) => {
|
|
|
3204
3216
|
return Component;
|
|
3205
3217
|
};
|
|
3206
3218
|
/**
|
|
3207
|
-
* @license lucide-react v0.
|
|
3219
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3208
3220
|
*
|
|
3209
3221
|
* This source code is licensed under the ISC license.
|
|
3210
3222
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3215,7 +3227,7 @@ const __iconNode$7 = [
|
|
|
3215
3227
|
];
|
|
3216
3228
|
const ArrowRight = createLucideIcon("arrow-right", __iconNode$7);
|
|
3217
3229
|
/**
|
|
3218
|
-
* @license lucide-react v0.
|
|
3230
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3219
3231
|
*
|
|
3220
3232
|
* This source code is licensed under the ISC license.
|
|
3221
3233
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3223,7 +3235,7 @@ const ArrowRight = createLucideIcon("arrow-right", __iconNode$7);
|
|
|
3223
3235
|
const __iconNode$6 = [["path", { d: "M20 6 9 17l-5-5", key: "1gmf2c" }]];
|
|
3224
3236
|
const Check = createLucideIcon("check", __iconNode$6);
|
|
3225
3237
|
/**
|
|
3226
|
-
* @license lucide-react v0.
|
|
3238
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3227
3239
|
*
|
|
3228
3240
|
* This source code is licensed under the ISC license.
|
|
3229
3241
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3235,7 +3247,7 @@ const __iconNode$5 = [
|
|
|
3235
3247
|
];
|
|
3236
3248
|
const ExternalLink = createLucideIcon("external-link", __iconNode$5);
|
|
3237
3249
|
/**
|
|
3238
|
-
* @license lucide-react v0.
|
|
3250
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3239
3251
|
*
|
|
3240
3252
|
* This source code is licensed under the ISC license.
|
|
3241
3253
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3247,7 +3259,7 @@ const __iconNode$4 = [
|
|
|
3247
3259
|
];
|
|
3248
3260
|
const LockKeyhole = createLucideIcon("lock-keyhole", __iconNode$4);
|
|
3249
3261
|
/**
|
|
3250
|
-
* @license lucide-react v0.
|
|
3262
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3251
3263
|
*
|
|
3252
3264
|
* This source code is licensed under the ISC license.
|
|
3253
3265
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3255,7 +3267,7 @@ const LockKeyhole = createLucideIcon("lock-keyhole", __iconNode$4);
|
|
|
3255
3267
|
const __iconNode$3 = [["path", { d: "M5 12h14", key: "1ays0h" }]];
|
|
3256
3268
|
const Minus = createLucideIcon("minus", __iconNode$3);
|
|
3257
3269
|
/**
|
|
3258
|
-
* @license lucide-react v0.
|
|
3270
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3259
3271
|
*
|
|
3260
3272
|
* This source code is licensed under the ISC license.
|
|
3261
3273
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3273,7 +3285,7 @@ const __iconNode$2 = [
|
|
|
3273
3285
|
];
|
|
3274
3286
|
const OctagonAlert = createLucideIcon("octagon-alert", __iconNode$2);
|
|
3275
3287
|
/**
|
|
3276
|
-
* @license lucide-react v0.
|
|
3288
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3277
3289
|
*
|
|
3278
3290
|
* This source code is licensed under the ISC license.
|
|
3279
3291
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3284,7 +3296,7 @@ const __iconNode$1 = [
|
|
|
3284
3296
|
];
|
|
3285
3297
|
const Search = createLucideIcon("search", __iconNode$1);
|
|
3286
3298
|
/**
|
|
3287
|
-
* @license lucide-react v0.
|
|
3299
|
+
* @license lucide-react v0.545.0 - ISC
|
|
3288
3300
|
*
|
|
3289
3301
|
* This source code is licensed under the ISC license.
|
|
3290
3302
|
* See the LICENSE file in the root directory of this source tree.
|
|
@@ -3306,7 +3318,10 @@ const checkboxBoxVariants = cva(
|
|
|
3306
3318
|
{
|
|
3307
3319
|
variants: {
|
|
3308
3320
|
editable: {
|
|
3309
|
-
true:
|
|
3321
|
+
true: [
|
|
3322
|
+
"peer-focus-visible:outline-none peer-focus-visible:ring-3 peer-focus-visible:ring-ring/50 peer-focus-visible:ring-offset-0",
|
|
3323
|
+
"peer-hover:outline-none peer-hover:ring-3 peer-hover:ring-ring/50 peer-hover:ring-offset-0"
|
|
3324
|
+
],
|
|
3310
3325
|
false: "opacity-30"
|
|
3311
3326
|
},
|
|
3312
3327
|
state: {
|
|
@@ -3477,7 +3492,8 @@ const inputContainerVariants = cva(
|
|
|
3477
3492
|
[
|
|
3478
3493
|
"relative flex rounded-sm overflow-hidden",
|
|
3479
3494
|
"h-12 border focus-within:border-bdr-solid",
|
|
3480
|
-
"focus-within:focus-ring
|
|
3495
|
+
"focus-within:outline-none focus-within:ring-3 focus-within:ring-ring/50 focus-within:ring-offset-0",
|
|
3496
|
+
"transition-highlight"
|
|
3481
3497
|
],
|
|
3482
3498
|
{
|
|
3483
3499
|
variants: {
|
|
@@ -3486,7 +3502,7 @@ const inputContainerVariants = cva(
|
|
|
3486
3502
|
error: "border-error focus-within:border-error focus-within:ring-error/50"
|
|
3487
3503
|
},
|
|
3488
3504
|
disabled: {
|
|
3489
|
-
true: "
|
|
3505
|
+
true: "select-none"
|
|
3490
3506
|
}
|
|
3491
3507
|
},
|
|
3492
3508
|
defaultVariants: {
|
|
@@ -3539,7 +3555,7 @@ const Input = forwardRef(
|
|
|
3539
3555
|
"flex-1 w-full px-4.5 text-base",
|
|
3540
3556
|
"text-main bg-surface-neutral placeholder:text-subtle",
|
|
3541
3557
|
"border-0 focus:outline-none",
|
|
3542
|
-
"disabled:
|
|
3558
|
+
"disabled:select-none read-only:bg-surface-primary",
|
|
3543
3559
|
startAddon && "rounded-l-none",
|
|
3544
3560
|
endAddon && "rounded-r-none"
|
|
3545
3561
|
),
|
|
@@ -3610,11 +3626,7 @@ function isOfType(node, Comp) {
|
|
|
3610
3626
|
function findComponentByType(children, Comp) {
|
|
3611
3627
|
return Children.toArray(children).find((child) => isOfType(child, Comp));
|
|
3612
3628
|
}
|
|
3613
|
-
const ListItemLeft = ({
|
|
3614
|
-
children,
|
|
3615
|
-
className,
|
|
3616
|
-
...props
|
|
3617
|
-
}) => /* @__PURE__ */ u("div", { className: cn("flex items-center gap-2.5 flex-shrink-0", className), ...props, children });
|
|
3629
|
+
const ListItemLeft = ({ children, className, ...props }) => /* @__PURE__ */ u("div", { className: cn("flex items-center gap-2.5 flex-shrink-0", className), ...props, children });
|
|
3618
3630
|
const ListItemContent = ({
|
|
3619
3631
|
className,
|
|
3620
3632
|
children,
|
|
@@ -3645,12 +3657,7 @@ const ListItemRight = ({
|
|
|
3645
3657
|
...props
|
|
3646
3658
|
}) => /* @__PURE__ */ u("div", { className: cn("flex items-center gap-5 flex-shrink-0", className), ...props, children });
|
|
3647
3659
|
ListItemRight.displayName = "ListItem.Right";
|
|
3648
|
-
const ListItemRoot = ({
|
|
3649
|
-
children,
|
|
3650
|
-
className,
|
|
3651
|
-
selected,
|
|
3652
|
-
...props
|
|
3653
|
-
}) => {
|
|
3660
|
+
const ListItemRoot = ({ children, className, selected, ...props }) => {
|
|
3654
3661
|
const left = findComponentByType(children, ListItemLeft);
|
|
3655
3662
|
const content = findComponentByType(children, ListItemContent) ?? findComponentByType(children, ListItemDefaultContent);
|
|
3656
3663
|
const right = findComponentByType(children, ListItemRight);
|
|
@@ -3942,7 +3949,7 @@ function TooltipContent({
|
|
|
3942
3949
|
{
|
|
3943
3950
|
ref: tooltipRef,
|
|
3944
3951
|
role: "tooltip",
|
|
3945
|
-
className: cn("fixed z-50 pointer-events-none", !position.transformOrigin && "opacity-0"),
|
|
3952
|
+
className: cn("fixed z-50 pointer-events-none select-none", !position.transformOrigin && "opacity-0"),
|
|
3946
3953
|
style: {
|
|
3947
3954
|
top: `${position.top}px`,
|
|
3948
3955
|
left: `${position.left}px`,
|
|
@@ -4047,6 +4054,18 @@ function Tooltip({
|
|
|
4047
4054
|
)
|
|
4048
4055
|
] });
|
|
4049
4056
|
}
|
|
4057
|
+
const DialogContext = createContext(void 0);
|
|
4058
|
+
const DialogProvider = ({ value, children }) => {
|
|
4059
|
+
return /* @__PURE__ */ u(DialogContext.Provider, { value, children });
|
|
4060
|
+
};
|
|
4061
|
+
DialogProvider.displayName = "DialogProvider";
|
|
4062
|
+
const useDialog = () => {
|
|
4063
|
+
const context = useContext(DialogContext);
|
|
4064
|
+
if (!context) {
|
|
4065
|
+
throw new Error("useDialog must be used within a DialogProvider");
|
|
4066
|
+
}
|
|
4067
|
+
return context;
|
|
4068
|
+
};
|
|
4050
4069
|
function setRef(ref, value) {
|
|
4051
4070
|
if (!ref) return;
|
|
4052
4071
|
if (typeof ref === "function") {
|
|
@@ -4104,8 +4123,9 @@ const SearchInput = forwardRef(
|
|
|
4104
4123
|
className: cn(
|
|
4105
4124
|
"relative flex rounded-sm overflow-hidden",
|
|
4106
4125
|
"h-12 border border-bdr-subtle focus-within:border-bdr-strong",
|
|
4107
|
-
"focus-within:focus-ring
|
|
4108
|
-
|
|
4126
|
+
"focus-within:outline-none focus-within:ring-3 focus-within:ring-ring/50 focus-within:ring-offset-0",
|
|
4127
|
+
"transition-highlight",
|
|
4128
|
+
disabled && "pointer-events-none select-none opacity-30",
|
|
4109
4129
|
className
|
|
4110
4130
|
),
|
|
4111
4131
|
children: [
|
|
@@ -4127,7 +4147,6 @@ const SearchInput = forwardRef(
|
|
|
4127
4147
|
"text-main bg-surface-neutral",
|
|
4128
4148
|
"placeholder:text-subtle",
|
|
4129
4149
|
"focus:outline-none",
|
|
4130
|
-
"disabled:pointer-events-none",
|
|
4131
4150
|
"read-only:bg-surface-primary"
|
|
4132
4151
|
),
|
|
4133
4152
|
value: inputValue,
|
|
@@ -4157,18 +4176,190 @@ const SearchInput = forwardRef(
|
|
|
4157
4176
|
}
|
|
4158
4177
|
);
|
|
4159
4178
|
SearchInput.displayName = "SearchInput";
|
|
4179
|
+
function ListboxImpl({
|
|
4180
|
+
className,
|
|
4181
|
+
selection: controlledSelection,
|
|
4182
|
+
selectionMode = "single",
|
|
4183
|
+
disabled = false,
|
|
4184
|
+
defaultSelection = /* @__PURE__ */ new Set(),
|
|
4185
|
+
setSelection,
|
|
4186
|
+
active: controlledActive,
|
|
4187
|
+
defaultActive,
|
|
4188
|
+
onActiveChange,
|
|
4189
|
+
items,
|
|
4190
|
+
renderItem,
|
|
4191
|
+
getValue,
|
|
4192
|
+
...props
|
|
4193
|
+
}, ref) {
|
|
4194
|
+
const listboxId = usePrefixedId();
|
|
4195
|
+
const innerRef = useRef(null);
|
|
4196
|
+
const [uncontrolledSelection, setUncontrolledSelection] = useState(defaultSelection);
|
|
4197
|
+
const isSelectionControlled = controlledSelection !== void 0;
|
|
4198
|
+
const selection = isSelectionControlled ? controlledSelection : uncontrolledSelection;
|
|
4199
|
+
const [uncontrolledActive, setUncontrolledActive] = useState(
|
|
4200
|
+
defaultActive ?? (items[0] ? getValue(items[0]) : void 0)
|
|
4201
|
+
);
|
|
4202
|
+
const isActiveControlled = controlledActive !== void 0;
|
|
4203
|
+
const active = isActiveControlled ? controlledActive : uncontrolledActive;
|
|
4204
|
+
const valueToIndexMap = useMemo(() => {
|
|
4205
|
+
return new Map(items.map((item, idx) => [getValue(item), idx]));
|
|
4206
|
+
}, [items, getValue]);
|
|
4207
|
+
const updateActive = useCallback(
|
|
4208
|
+
(newActive) => {
|
|
4209
|
+
if (!isActiveControlled) {
|
|
4210
|
+
setUncontrolledActive(newActive);
|
|
4211
|
+
}
|
|
4212
|
+
onActiveChange?.(newActive);
|
|
4213
|
+
},
|
|
4214
|
+
[isActiveControlled, onActiveChange]
|
|
4215
|
+
);
|
|
4216
|
+
useEffect(() => {
|
|
4217
|
+
if (!active || !items.some((item) => getValue(item) === active)) {
|
|
4218
|
+
updateActive(items[0] ? getValue(items[0]) : void 0);
|
|
4219
|
+
}
|
|
4220
|
+
}, [items, getValue, active, updateActive]);
|
|
4221
|
+
useEffect(() => {
|
|
4222
|
+
if (!active || !innerRef.current) return;
|
|
4223
|
+
const el = innerRef.current.querySelector(`#${listboxId}-option-${active}`);
|
|
4224
|
+
el?.scrollIntoView({ block: "nearest", behavior: "auto" });
|
|
4225
|
+
}, [active, listboxId]);
|
|
4226
|
+
const handleToggleValue = (value) => {
|
|
4227
|
+
const isAlreadySelected = selection.has(value);
|
|
4228
|
+
let newSelection;
|
|
4229
|
+
if (selectionMode === "single") {
|
|
4230
|
+
newSelection = isAlreadySelected ? /* @__PURE__ */ new Set() : /* @__PURE__ */ new Set([value]);
|
|
4231
|
+
} else {
|
|
4232
|
+
newSelection = new Set(selection);
|
|
4233
|
+
if (isAlreadySelected) {
|
|
4234
|
+
newSelection.delete(value);
|
|
4235
|
+
} else {
|
|
4236
|
+
newSelection.add(value);
|
|
4237
|
+
}
|
|
4238
|
+
}
|
|
4239
|
+
if (!isSelectionControlled) {
|
|
4240
|
+
setUncontrolledSelection(newSelection);
|
|
4241
|
+
}
|
|
4242
|
+
setSelection?.(newSelection);
|
|
4243
|
+
updateActive(value);
|
|
4244
|
+
};
|
|
4245
|
+
const handleClickItem = ({ target }) => {
|
|
4246
|
+
const li = target instanceof Element ? target.closest("li") : null;
|
|
4247
|
+
const value = li?.getAttribute("data-value");
|
|
4248
|
+
if (value) {
|
|
4249
|
+
handleToggleValue(value);
|
|
4250
|
+
}
|
|
4251
|
+
};
|
|
4252
|
+
const moveActive = (delta) => {
|
|
4253
|
+
const activeIndex = active ? valueToIndexMap.get(active) ?? 0 : 0;
|
|
4254
|
+
const newIndex = Math.max(0, Math.min(items.length - 1, activeIndex + delta));
|
|
4255
|
+
updateActive(getValue(items[newIndex]));
|
|
4256
|
+
};
|
|
4257
|
+
const handleKeyDown = (e) => {
|
|
4258
|
+
if (disabled) {
|
|
4259
|
+
return;
|
|
4260
|
+
}
|
|
4261
|
+
if (e.key === "ArrowDown") {
|
|
4262
|
+
e.preventDefault();
|
|
4263
|
+
moveActive(1);
|
|
4264
|
+
} else if (e.key === "ArrowUp") {
|
|
4265
|
+
e.preventDefault();
|
|
4266
|
+
moveActive(-1);
|
|
4267
|
+
} else if (e.key === "Home") {
|
|
4268
|
+
e.preventDefault();
|
|
4269
|
+
const firstItem = items[0];
|
|
4270
|
+
updateActive(firstItem && getValue(firstItem));
|
|
4271
|
+
} else if (e.key === "End") {
|
|
4272
|
+
e.preventDefault();
|
|
4273
|
+
const lastItem = items.at(-1);
|
|
4274
|
+
updateActive(lastItem && getValue(lastItem));
|
|
4275
|
+
} else if (e.key === " " || e.key === "Enter") {
|
|
4276
|
+
e.preventDefault();
|
|
4277
|
+
if (active) {
|
|
4278
|
+
handleToggleValue(active);
|
|
4279
|
+
}
|
|
4280
|
+
}
|
|
4281
|
+
};
|
|
4282
|
+
return /* @__PURE__ */ u(
|
|
4283
|
+
"ul",
|
|
4284
|
+
{
|
|
4285
|
+
id: listboxId,
|
|
4286
|
+
ref: useComposedRefs(ref, innerRef),
|
|
4287
|
+
tabIndex: disabled ? -1 : 0,
|
|
4288
|
+
className: cn(
|
|
4289
|
+
"flex flex-col items-start grow-1 shrink-0 basis-0",
|
|
4290
|
+
"max-h-100 px-0 overflow-y-auto",
|
|
4291
|
+
"focus-within:border-bdr-solid focus-within:outline-none focus-within:ring-3 focus-within:ring-ring/50 focus-within:ring-offset-0",
|
|
4292
|
+
"focus-within:[&>li[data-active=true]]:bg-surface-primary-hover",
|
|
4293
|
+
"focus-within:[&>li[data-active=true][aria-selected=true]]:bg-surface-primary-selected-hover",
|
|
4294
|
+
"transition-highlight",
|
|
4295
|
+
disabled && "pointer-events-none select-none opacity-30",
|
|
4296
|
+
className
|
|
4297
|
+
),
|
|
4298
|
+
role: "listbox",
|
|
4299
|
+
"aria-activedescendant": active ? `${listboxId}-option-${active}` : void 0,
|
|
4300
|
+
"aria-disabled": disabled,
|
|
4301
|
+
"aria-multiselectable": selectionMode === "multiple",
|
|
4302
|
+
"aria-label": props.label ?? void 0,
|
|
4303
|
+
"aria-orientation": "vertical",
|
|
4304
|
+
onKeyDown: handleKeyDown,
|
|
4305
|
+
onClick: handleClickItem,
|
|
4306
|
+
children: items.map((item) => {
|
|
4307
|
+
const value = getValue(item);
|
|
4308
|
+
const selected = selection.has(value);
|
|
4309
|
+
const isActive = value === active;
|
|
4310
|
+
return /* @__PURE__ */ u(
|
|
4311
|
+
"li",
|
|
4312
|
+
{
|
|
4313
|
+
id: `${listboxId}-option-${value}`,
|
|
4314
|
+
"data-value": value,
|
|
4315
|
+
"data-active": isActive ? "true" : "false",
|
|
4316
|
+
tabIndex: -1,
|
|
4317
|
+
className: cn(
|
|
4318
|
+
"flex items-center w-full px-4.5 py-1 gap-x-2.5",
|
|
4319
|
+
!disabled && "cursor-pointer",
|
|
4320
|
+
selected ? "bg-surface-primary-selected text-alt hover:bg-surface-primary-selected-hover" : "hover:bg-surface-primary-hover"
|
|
4321
|
+
),
|
|
4322
|
+
role: "option",
|
|
4323
|
+
"aria-selected": selected,
|
|
4324
|
+
children: renderItem(item, selected, isActive)
|
|
4325
|
+
},
|
|
4326
|
+
value
|
|
4327
|
+
);
|
|
4328
|
+
})
|
|
4329
|
+
}
|
|
4330
|
+
);
|
|
4331
|
+
}
|
|
4332
|
+
const Listbox = forwardRef(ListboxImpl);
|
|
4333
|
+
Listbox.displayName = "Listbox";
|
|
4334
|
+
const useScrollLock = (lock, element) => {
|
|
4335
|
+
useEffect(() => {
|
|
4336
|
+
if (!lock) {
|
|
4337
|
+
return;
|
|
4338
|
+
}
|
|
4339
|
+
const target = element ?? document.body;
|
|
4340
|
+
const originalOverflow = target.style.overflow;
|
|
4341
|
+
target.style.overflow = "hidden";
|
|
4342
|
+
return () => {
|
|
4343
|
+
target.style.overflow = originalOverflow;
|
|
4344
|
+
};
|
|
4345
|
+
}, [lock, element]);
|
|
4346
|
+
};
|
|
4160
4347
|
export {
|
|
4161
4348
|
Button,
|
|
4162
4349
|
Checkbox,
|
|
4350
|
+
DialogProvider,
|
|
4163
4351
|
IconButton,
|
|
4164
4352
|
IdProvider,
|
|
4165
4353
|
Input,
|
|
4166
4354
|
Link,
|
|
4167
4355
|
ListItem,
|
|
4356
|
+
Listbox,
|
|
4168
4357
|
SearchInput,
|
|
4169
4358
|
SelectableListItem,
|
|
4170
4359
|
Tooltip,
|
|
4171
4360
|
cn,
|
|
4172
4361
|
unwrap,
|
|
4173
|
-
|
|
4362
|
+
useDialog,
|
|
4363
|
+
usePrefixedId,
|
|
4364
|
+
useScrollLock
|
|
4174
4365
|
};
|
package/dist/styles/preset.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
@layer base{:root{--color-black: #000000;--color-grey-950: #242829;--color-grey-900: #3d4142;--color-grey-800: #5b5f60;--color-grey-700: #797d7e;--color-grey-600: #8d9192;--color-grey-500: #b2b2b2;--color-grey-400: #b5b9ba;--color-grey-300: #d3d7d8;--color-grey-200: #dde1e2;--color-grey-100: #e7ebeb;--color-grey-50: #f1f5f6;--color-white: #ffffff;--color-fbk-info: #0270a0;--color-fbk-info-subtle: #208ebe;--color-fbk-info-surface: #d7f3ff;--color-fbk-warn: #cb9126;--color-fbk-warn-subtle: #e9af44;--color-fbk-warn-surface: #f7e5c4;--color-fbk-success: #499349;--color-fbk-success-subtle: #67b167;--color-fbk-success-surface: #cee2ce;--color-fbk-danger: #d33030;--color-fbk-danger-subtle: #f56262;--color-fbk-danger-surface: #f6d7d7;--color-purple: #800080;--color-purple-subtle: #e46ee4;--color-juke: #9747ff}}@layer base{:root{--color-main: var(--color-black);--color-main-hover: var(--color-grey-800);--color-subtle: var(--color-grey-800);--color-alt: var(--color-white);--color-rev: var(--color-white);--color-alt-rev: var(--color-black);--color-info: var(--color-fbk-info);--color-warn: var(--color-fbk-warn);--color-success: var(--color-fbk-success);--color-error: var(--color-fbk-danger);--color-surface-neutral: var(--color-white);--color-surface-primary: var(--color-grey-50);--color-surface-primary-hover: var(--color-grey-50);--color-surface-primary-selected: var(--color-grey-800);--color-surface-primary-selected-hover: var(--color-grey-900);--color-bdr-subtle: var(--color-grey-500);--color-bdr-soft: var(--color-grey-200);--color-bdr-strong: var(--color-black);--color-ring: var(--color-grey-500);--color-btn-primary: var(--color-white);--color-btn-primary-hover: var(--color-grey-50);--color-btn-secondary: var(--color-grey-50);--color-btn-secondary-hover: var(--color-grey-100);--color-btn-tertiary: var(--color-black);--color-btn-tertiary-hover: var(--color-grey-900);--color-btn-active: var(--color-grey-800);--color-input-disabled: var(--color-grey-100);--color-link-visited: var(--color-purple);--color-tooltip: var(--color-black);--color-tooltip-foreground: var(--color-white);--color-overlay: oklch(0 0 0 / .4);--color-docs: var(--color-juke)}}@layer base{.dark{--color-main: var(--color-white);--color-main-hover: var(--color-grey-200);--color-subtle: var(--color-grey-400);--color-alt: var(--color-white);--color-rev: var(--color-black);--color-alt-rev: var(--color-black);--color-info: var(--color-fbk-info-subtle);--color-warn: var(--color-fbk-warn-subtle);--color-success: var(--color-fbk-success-subtle);--color-error: var(--color-fbk-danger-subtle);--color-surface-neutral: var(--color-grey-950);--color-surface-primary: var(--color-grey-900);--color-surface-primary-hover: var(--color-grey-900);--color-surface-primary-selected: var(--color-grey-800);--color-surface-primary-selected-hover: var(--color-grey-900);--color-bdr-subtle: var(--color-grey-500);--color-bdr-soft: var(--color-grey-800);--color-bdr-strong: var(--color-white);--color-ring: var(--color-grey-500);--color-btn-primary: var(--color-grey-950);--color-btn-primary-hover: var(--color-grey-900);--color-btn-secondary: var(--color-grey-900);--color-btn-secondary-hover: var(--color-grey-800);--color-btn-tertiary: var(--color-grey-600);--color-btn-tertiary-hover: var(--color-grey-700);--color-btn-active: var(--color-grey-800);--color-input-disabled: var(--color-grey-800);--color-link-visited: var(--color-purple-subtle);--color-tooltip: var(--color-grey-600);--color-tooltip-foreground: var(--color-white);--color-overlay: oklch(0 0 0 / .6);--color-docs: var(--color-juke)}}@custom-variant dark (&:where(.dark,.dark *));@theme{ --color-main: var(--color-main); --color-main-hover: var(--color-main-hover); --color-subtle: var(--color-subtle); --color-alt: var(--color-alt); --color-rev: var(--color-rev); --color-alt-rev: var(--color-alt-rev); --color-info: var(--color-fbk-info); --color-warn: var(--color-fbk-warn); --color-success: var(--color-fbk-success); --color-error: var(--color-fbk-danger); --color-surface-neutral: var(--color-surface-neutral); --color-surface-primary: var(--color-surface-primary); --color-surface-primary-hover: var(--color-surface-primary-hover); --color-surface-primary-selected: var(--color-surface-primary-selected); --color-surface-primary-selected-hover: var(--color-surface-primary-selected-hover); --color-surface-info: var(--color-fbk-info-surface); --color-surface-warn: var(--color-fbk-warn-surface); --color-surface-success: var(--color-fbk-success-surface); --color-surface-error: var(--color-fbk-danger-surface); --color-bdr-subtle: var(--color-bdr-subtle); --color-bdr-soft: var(--color-bdr-soft); --color-bdr-strong: var(--color-bdr-strong); --color-ring: var(--color-ring); --color-btn-primary: var(--color-btn-primary); --color-btn-primary-hover: var(--color-btn-primary-hover); --color-btn-secondary: var(--color-btn-secondary); --color-btn-secondary-hover: var(--color-btn-secondary-hover); --color-btn-tertiary: var(--color-btn-tertiary); --color-btn-tertiary-hover: var(--color-btn-tertiary-hover); --color-btn-active: var(--color-btn-active); --color-input-disabled: var(--color-input-disabled); --color-link-visited: var(--color-link-visited); --color-tooltip: var(--color-tooltip); --color-tooltip-foreground: var(--color-tooltip-foreground); --color-overlay: var(--color-overlay); --color-docs: var(--color-docs); --sizing-11\.5: calc(var(--spacing) * 11.5); }@layer base{:root{font-size:16px;color:var(--color-main);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}}@utility transition-highlight{transition-property: color,box-shadow; transition-duration: .1s;}
|