@trackunit/react-components 1.0.7 → 1.0.8
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/index.cjs.js +123 -6
- package/index.esm.js +123 -6
- package/package.json +1 -1
- package/src/components/Popover/Popover.d.ts +7 -4
- package/src/components/Popover/PopoverSizing.d.ts +44 -0
- package/src/components/Popover/PopoverTypes.d.ts +20 -3
- package/src/components/Popover/usePopover.d.ts +2 -2
package/index.cjs.js
CHANGED
|
@@ -3314,6 +3314,98 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
|
|
|
3314
3314
|
return (jsxRuntime.jsx("a", { className: cvaExternalLink({ className }), "data-testid": dataTestId, href: href, onClick: onClick, rel: rel, target: target, title: title, children: children }));
|
|
3315
3315
|
};
|
|
3316
3316
|
|
|
3317
|
+
const PADDING$1 = 16;
|
|
3318
|
+
/**
|
|
3319
|
+
* Converts a width size value into a CSS dimension value for max constraints
|
|
3320
|
+
*
|
|
3321
|
+
* @param params - The parameters object
|
|
3322
|
+
* @param params.value - The size value: number for pixels, "trigger-width" to match trigger, "none" for no constraint
|
|
3323
|
+
* @param params.referenceWidth - The width of the trigger element in pixels
|
|
3324
|
+
* @param params.availableWidth - The available width in the viewport
|
|
3325
|
+
*/
|
|
3326
|
+
const getMaxWidthValue = ({ value, referenceWidth, availableWidth }) => {
|
|
3327
|
+
switch (value) {
|
|
3328
|
+
case "trigger-width": {
|
|
3329
|
+
return `${referenceWidth}px`;
|
|
3330
|
+
}
|
|
3331
|
+
case undefined:
|
|
3332
|
+
case "none": {
|
|
3333
|
+
return `${availableWidth - PADDING$1 * 2}px`;
|
|
3334
|
+
}
|
|
3335
|
+
default: {
|
|
3336
|
+
if (typeof value === "number") {
|
|
3337
|
+
return `${value}px`;
|
|
3338
|
+
}
|
|
3339
|
+
throw new Error(`${value} is not known`);
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
};
|
|
3343
|
+
/**
|
|
3344
|
+
* Converts a width size value into a CSS dimension value for min constraints
|
|
3345
|
+
*
|
|
3346
|
+
* @param params - The parameters object
|
|
3347
|
+
* @param params.value - The size value: number for pixels, "trigger-width" to match trigger, "none" for no constraint
|
|
3348
|
+
* @param params.referenceWidth - The width of the trigger element in pixels
|
|
3349
|
+
*/
|
|
3350
|
+
const getMinWidthValue = ({ value, referenceWidth, }) => {
|
|
3351
|
+
switch (value) {
|
|
3352
|
+
case "trigger-width": {
|
|
3353
|
+
return `${referenceWidth}px`;
|
|
3354
|
+
}
|
|
3355
|
+
case undefined:
|
|
3356
|
+
case "none": {
|
|
3357
|
+
return undefined;
|
|
3358
|
+
}
|
|
3359
|
+
default: {
|
|
3360
|
+
if (typeof value === "number") {
|
|
3361
|
+
return `${value}px`;
|
|
3362
|
+
}
|
|
3363
|
+
throw new Error(`${value} is not known`);
|
|
3364
|
+
}
|
|
3365
|
+
}
|
|
3366
|
+
};
|
|
3367
|
+
/**
|
|
3368
|
+
* Converts a height size value into a CSS dimension value for max constraints
|
|
3369
|
+
*
|
|
3370
|
+
* @param params - The parameters object
|
|
3371
|
+
* @param params.value - The size value: number for pixels, "none" for no constraint
|
|
3372
|
+
* @param params.availableHeight - The available height in the viewport
|
|
3373
|
+
*/
|
|
3374
|
+
const getMaxHeightValue = ({ value, availableHeight }) => {
|
|
3375
|
+
switch (value) {
|
|
3376
|
+
case undefined:
|
|
3377
|
+
case "none": {
|
|
3378
|
+
return `${availableHeight - PADDING$1 * 2}px`;
|
|
3379
|
+
}
|
|
3380
|
+
default: {
|
|
3381
|
+
if (typeof value === "number") {
|
|
3382
|
+
return `${value}px`;
|
|
3383
|
+
}
|
|
3384
|
+
throw new Error(`${value} is not known`);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
};
|
|
3388
|
+
/**
|
|
3389
|
+
* Converts a height size value into a CSS dimension value for min constraints
|
|
3390
|
+
*
|
|
3391
|
+
* @param params - The parameters object
|
|
3392
|
+
* @param params.value - The size value: number for pixels, "none" for no constraint
|
|
3393
|
+
*/
|
|
3394
|
+
const getMinHeightValue = ({ value }) => {
|
|
3395
|
+
switch (value) {
|
|
3396
|
+
case undefined:
|
|
3397
|
+
case "none": {
|
|
3398
|
+
return undefined;
|
|
3399
|
+
}
|
|
3400
|
+
default: {
|
|
3401
|
+
if (typeof value === "number") {
|
|
3402
|
+
return `${value}px`;
|
|
3403
|
+
}
|
|
3404
|
+
throw new Error(`${value} is not known`);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
};
|
|
3408
|
+
|
|
3317
3409
|
const DEFAULT_ACTIVATION = { click: true, hover: false, keyboardHandlers: true };
|
|
3318
3410
|
const PADDING = 16;
|
|
3319
3411
|
const DEFAULT_DISMISSAL = {
|
|
@@ -3321,14 +3413,20 @@ const DEFAULT_DISMISSAL = {
|
|
|
3321
3413
|
outsidePress: true,
|
|
3322
3414
|
ancestorScroll: false,
|
|
3323
3415
|
};
|
|
3416
|
+
const DEFAULT_SIZING = {
|
|
3417
|
+
minWidth: "none",
|
|
3418
|
+
maxWidth: "none",
|
|
3419
|
+
minHeight: "none",
|
|
3420
|
+
maxHeight: "none",
|
|
3421
|
+
};
|
|
3324
3422
|
/**
|
|
3325
3423
|
* The hook that powers the Popover component.
|
|
3326
3424
|
* It should not be used directly, but rather through the Popover component.
|
|
3327
3425
|
*
|
|
3328
3426
|
* @param {PopoverProps} options The options for the popover
|
|
3329
|
-
* @returns {
|
|
3427
|
+
* @returns {UsePopoverType} The data for the popover
|
|
3330
3428
|
*/
|
|
3331
|
-
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, onOpenStateChange, ...restOptions }) => {
|
|
3429
|
+
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, sizing = DEFAULT_SIZING, onOpenStateChange, ...restOptions }) => {
|
|
3332
3430
|
const [uncontrolledIsOpen, setUncontrolledIsOpen] = React.useState(initialOpen);
|
|
3333
3431
|
const [labelId, setLabelId] = React.useState();
|
|
3334
3432
|
const [descriptionId, setDescriptionId] = React.useState();
|
|
@@ -3347,9 +3445,26 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
3347
3445
|
react.shift({ padding: PADDING }),
|
|
3348
3446
|
react.size({
|
|
3349
3447
|
apply({ availableWidth, availableHeight, elements }) {
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3448
|
+
const { floating, reference } = elements;
|
|
3449
|
+
const resolvedSizing = typeof sizing === "function" ? sizing(DEFAULT_SIZING) : sizing;
|
|
3450
|
+
const refRect = reference.getBoundingClientRect();
|
|
3451
|
+
Object.assign(floating.style, {
|
|
3452
|
+
maxWidth: getMaxWidthValue({
|
|
3453
|
+
value: resolvedSizing.maxWidth,
|
|
3454
|
+
referenceWidth: refRect.width,
|
|
3455
|
+
availableWidth,
|
|
3456
|
+
}),
|
|
3457
|
+
minWidth: getMinWidthValue({
|
|
3458
|
+
value: resolvedSizing.minWidth,
|
|
3459
|
+
referenceWidth: refRect.width,
|
|
3460
|
+
}),
|
|
3461
|
+
maxHeight: getMaxHeightValue({
|
|
3462
|
+
value: resolvedSizing.maxHeight,
|
|
3463
|
+
availableHeight,
|
|
3464
|
+
}),
|
|
3465
|
+
minHeight: getMinHeightValue({
|
|
3466
|
+
value: resolvedSizing.minHeight,
|
|
3467
|
+
}),
|
|
3353
3468
|
});
|
|
3354
3469
|
},
|
|
3355
3470
|
}),
|
|
@@ -3422,7 +3537,9 @@ const usePopoverContext = () => {
|
|
|
3422
3537
|
*/
|
|
3423
3538
|
const Popover = ({ children, isModal = false, ...restOptions }) => {
|
|
3424
3539
|
const popover = usePopover({ isModal, ...restOptions });
|
|
3425
|
-
return (jsxRuntime.jsx(PopoverContext.Provider, { value: popover, children: typeof children === "function"
|
|
3540
|
+
return (jsxRuntime.jsx(PopoverContext.Provider, { value: popover, children: typeof children === "function"
|
|
3541
|
+
? children({ isOpen: popover.isOpen, setIsOpen: popover.setIsOpen, placement: popover.placement })
|
|
3542
|
+
: children }));
|
|
3426
3543
|
};
|
|
3427
3544
|
|
|
3428
3545
|
/** @internal */
|
package/index.esm.js
CHANGED
|
@@ -3294,6 +3294,98 @@ const ExternalLink = ({ rel = "noreferrer", target = "_blank", href, className,
|
|
|
3294
3294
|
return (jsx("a", { className: cvaExternalLink({ className }), "data-testid": dataTestId, href: href, onClick: onClick, rel: rel, target: target, title: title, children: children }));
|
|
3295
3295
|
};
|
|
3296
3296
|
|
|
3297
|
+
const PADDING$1 = 16;
|
|
3298
|
+
/**
|
|
3299
|
+
* Converts a width size value into a CSS dimension value for max constraints
|
|
3300
|
+
*
|
|
3301
|
+
* @param params - The parameters object
|
|
3302
|
+
* @param params.value - The size value: number for pixels, "trigger-width" to match trigger, "none" for no constraint
|
|
3303
|
+
* @param params.referenceWidth - The width of the trigger element in pixels
|
|
3304
|
+
* @param params.availableWidth - The available width in the viewport
|
|
3305
|
+
*/
|
|
3306
|
+
const getMaxWidthValue = ({ value, referenceWidth, availableWidth }) => {
|
|
3307
|
+
switch (value) {
|
|
3308
|
+
case "trigger-width": {
|
|
3309
|
+
return `${referenceWidth}px`;
|
|
3310
|
+
}
|
|
3311
|
+
case undefined:
|
|
3312
|
+
case "none": {
|
|
3313
|
+
return `${availableWidth - PADDING$1 * 2}px`;
|
|
3314
|
+
}
|
|
3315
|
+
default: {
|
|
3316
|
+
if (typeof value === "number") {
|
|
3317
|
+
return `${value}px`;
|
|
3318
|
+
}
|
|
3319
|
+
throw new Error(`${value} is not known`);
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
};
|
|
3323
|
+
/**
|
|
3324
|
+
* Converts a width size value into a CSS dimension value for min constraints
|
|
3325
|
+
*
|
|
3326
|
+
* @param params - The parameters object
|
|
3327
|
+
* @param params.value - The size value: number for pixels, "trigger-width" to match trigger, "none" for no constraint
|
|
3328
|
+
* @param params.referenceWidth - The width of the trigger element in pixels
|
|
3329
|
+
*/
|
|
3330
|
+
const getMinWidthValue = ({ value, referenceWidth, }) => {
|
|
3331
|
+
switch (value) {
|
|
3332
|
+
case "trigger-width": {
|
|
3333
|
+
return `${referenceWidth}px`;
|
|
3334
|
+
}
|
|
3335
|
+
case undefined:
|
|
3336
|
+
case "none": {
|
|
3337
|
+
return undefined;
|
|
3338
|
+
}
|
|
3339
|
+
default: {
|
|
3340
|
+
if (typeof value === "number") {
|
|
3341
|
+
return `${value}px`;
|
|
3342
|
+
}
|
|
3343
|
+
throw new Error(`${value} is not known`);
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
};
|
|
3347
|
+
/**
|
|
3348
|
+
* Converts a height size value into a CSS dimension value for max constraints
|
|
3349
|
+
*
|
|
3350
|
+
* @param params - The parameters object
|
|
3351
|
+
* @param params.value - The size value: number for pixels, "none" for no constraint
|
|
3352
|
+
* @param params.availableHeight - The available height in the viewport
|
|
3353
|
+
*/
|
|
3354
|
+
const getMaxHeightValue = ({ value, availableHeight }) => {
|
|
3355
|
+
switch (value) {
|
|
3356
|
+
case undefined:
|
|
3357
|
+
case "none": {
|
|
3358
|
+
return `${availableHeight - PADDING$1 * 2}px`;
|
|
3359
|
+
}
|
|
3360
|
+
default: {
|
|
3361
|
+
if (typeof value === "number") {
|
|
3362
|
+
return `${value}px`;
|
|
3363
|
+
}
|
|
3364
|
+
throw new Error(`${value} is not known`);
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
};
|
|
3368
|
+
/**
|
|
3369
|
+
* Converts a height size value into a CSS dimension value for min constraints
|
|
3370
|
+
*
|
|
3371
|
+
* @param params - The parameters object
|
|
3372
|
+
* @param params.value - The size value: number for pixels, "none" for no constraint
|
|
3373
|
+
*/
|
|
3374
|
+
const getMinHeightValue = ({ value }) => {
|
|
3375
|
+
switch (value) {
|
|
3376
|
+
case undefined:
|
|
3377
|
+
case "none": {
|
|
3378
|
+
return undefined;
|
|
3379
|
+
}
|
|
3380
|
+
default: {
|
|
3381
|
+
if (typeof value === "number") {
|
|
3382
|
+
return `${value}px`;
|
|
3383
|
+
}
|
|
3384
|
+
throw new Error(`${value} is not known`);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
};
|
|
3388
|
+
|
|
3297
3389
|
const DEFAULT_ACTIVATION = { click: true, hover: false, keyboardHandlers: true };
|
|
3298
3390
|
const PADDING = 16;
|
|
3299
3391
|
const DEFAULT_DISMISSAL = {
|
|
@@ -3301,14 +3393,20 @@ const DEFAULT_DISMISSAL = {
|
|
|
3301
3393
|
outsidePress: true,
|
|
3302
3394
|
ancestorScroll: false,
|
|
3303
3395
|
};
|
|
3396
|
+
const DEFAULT_SIZING = {
|
|
3397
|
+
minWidth: "none",
|
|
3398
|
+
maxWidth: "none",
|
|
3399
|
+
minHeight: "none",
|
|
3400
|
+
maxHeight: "none",
|
|
3401
|
+
};
|
|
3304
3402
|
/**
|
|
3305
3403
|
* The hook that powers the Popover component.
|
|
3306
3404
|
* It should not be used directly, but rather through the Popover component.
|
|
3307
3405
|
*
|
|
3308
3406
|
* @param {PopoverProps} options The options for the popover
|
|
3309
|
-
* @returns {
|
|
3407
|
+
* @returns {UsePopoverType} The data for the popover
|
|
3310
3408
|
*/
|
|
3311
|
-
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, onOpenStateChange, ...restOptions }) => {
|
|
3409
|
+
const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen: controlledIsOpen, activation = DEFAULT_ACTIVATION, dismissal = DEFAULT_DISMISSAL, sizing = DEFAULT_SIZING, onOpenStateChange, ...restOptions }) => {
|
|
3312
3410
|
const [uncontrolledIsOpen, setUncontrolledIsOpen] = useState(initialOpen);
|
|
3313
3411
|
const [labelId, setLabelId] = useState();
|
|
3314
3412
|
const [descriptionId, setDescriptionId] = useState();
|
|
@@ -3327,9 +3425,26 @@ const usePopover = ({ initialOpen = false, placement = "bottom", isModal, isOpen
|
|
|
3327
3425
|
shift({ padding: PADDING }),
|
|
3328
3426
|
size({
|
|
3329
3427
|
apply({ availableWidth, availableHeight, elements }) {
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3428
|
+
const { floating, reference } = elements;
|
|
3429
|
+
const resolvedSizing = typeof sizing === "function" ? sizing(DEFAULT_SIZING) : sizing;
|
|
3430
|
+
const refRect = reference.getBoundingClientRect();
|
|
3431
|
+
Object.assign(floating.style, {
|
|
3432
|
+
maxWidth: getMaxWidthValue({
|
|
3433
|
+
value: resolvedSizing.maxWidth,
|
|
3434
|
+
referenceWidth: refRect.width,
|
|
3435
|
+
availableWidth,
|
|
3436
|
+
}),
|
|
3437
|
+
minWidth: getMinWidthValue({
|
|
3438
|
+
value: resolvedSizing.minWidth,
|
|
3439
|
+
referenceWidth: refRect.width,
|
|
3440
|
+
}),
|
|
3441
|
+
maxHeight: getMaxHeightValue({
|
|
3442
|
+
value: resolvedSizing.maxHeight,
|
|
3443
|
+
availableHeight,
|
|
3444
|
+
}),
|
|
3445
|
+
minHeight: getMinHeightValue({
|
|
3446
|
+
value: resolvedSizing.minHeight,
|
|
3447
|
+
}),
|
|
3333
3448
|
});
|
|
3334
3449
|
},
|
|
3335
3450
|
}),
|
|
@@ -3402,7 +3517,9 @@ const usePopoverContext = () => {
|
|
|
3402
3517
|
*/
|
|
3403
3518
|
const Popover = ({ children, isModal = false, ...restOptions }) => {
|
|
3404
3519
|
const popover = usePopover({ isModal, ...restOptions });
|
|
3405
|
-
return (jsx(PopoverContext.Provider, { value: popover, children: typeof children === "function"
|
|
3520
|
+
return (jsx(PopoverContext.Provider, { value: popover, children: typeof children === "function"
|
|
3521
|
+
? children({ isOpen: popover.isOpen, setIsOpen: popover.setIsOpen, placement: popover.placement })
|
|
3522
|
+
: children }));
|
|
3406
3523
|
};
|
|
3407
3524
|
|
|
3408
3525
|
/** @internal */
|
package/package.json
CHANGED
|
@@ -7,6 +7,11 @@ export type ContextType = UsePopoverType | null;
|
|
|
7
7
|
* @returns {ContextType} The popover context
|
|
8
8
|
*/
|
|
9
9
|
export declare const usePopoverContext: () => UsePopoverType;
|
|
10
|
+
type ModalCallback = {
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
setIsOpen: (isOpen: boolean) => void;
|
|
13
|
+
placement: PopoverPlacement;
|
|
14
|
+
};
|
|
10
15
|
/**
|
|
11
16
|
* The popover component.
|
|
12
17
|
* - This component should wrap all the popover components.
|
|
@@ -21,8 +26,6 @@ export declare const usePopoverContext: () => UsePopoverType;
|
|
|
21
26
|
* @returns {JSX.Element} A Popover Context Provider containing the children
|
|
22
27
|
*/
|
|
23
28
|
export declare const Popover: ({ children, isModal, ...restOptions }: {
|
|
24
|
-
children: React.ReactNode | ((
|
|
25
|
-
isOpen: boolean;
|
|
26
|
-
placement: PopoverPlacement;
|
|
27
|
-
}) => React.ReactNode);
|
|
29
|
+
children: React.ReactNode | ((modal: ModalCallback) => React.ReactNode);
|
|
28
30
|
} & PopoverProps) => import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { HeightSizeLimit, WidthSizeLimit } from "./PopoverTypes";
|
|
2
|
+
export declare const PADDING = 16;
|
|
3
|
+
type WidthValueParams = {
|
|
4
|
+
value: WidthSizeLimit | undefined;
|
|
5
|
+
referenceWidth: number;
|
|
6
|
+
availableWidth: number;
|
|
7
|
+
};
|
|
8
|
+
type HeightValueParams = {
|
|
9
|
+
value: HeightSizeLimit | undefined;
|
|
10
|
+
availableHeight: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Converts a width size value into a CSS dimension value for max constraints
|
|
14
|
+
*
|
|
15
|
+
* @param params - The parameters object
|
|
16
|
+
* @param params.value - The size value: number for pixels, "trigger-width" to match trigger, "none" for no constraint
|
|
17
|
+
* @param params.referenceWidth - The width of the trigger element in pixels
|
|
18
|
+
* @param params.availableWidth - The available width in the viewport
|
|
19
|
+
*/
|
|
20
|
+
export declare const getMaxWidthValue: ({ value, referenceWidth, availableWidth }: WidthValueParams) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Converts a width size value into a CSS dimension value for min constraints
|
|
23
|
+
*
|
|
24
|
+
* @param params - The parameters object
|
|
25
|
+
* @param params.value - The size value: number for pixels, "trigger-width" to match trigger, "none" for no constraint
|
|
26
|
+
* @param params.referenceWidth - The width of the trigger element in pixels
|
|
27
|
+
*/
|
|
28
|
+
export declare const getMinWidthValue: ({ value, referenceWidth, }: Omit<WidthValueParams, "availableWidth">) => string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a height size value into a CSS dimension value for max constraints
|
|
31
|
+
*
|
|
32
|
+
* @param params - The parameters object
|
|
33
|
+
* @param params.value - The size value: number for pixels, "none" for no constraint
|
|
34
|
+
* @param params.availableHeight - The available height in the viewport
|
|
35
|
+
*/
|
|
36
|
+
export declare const getMaxHeightValue: ({ value, availableHeight }: HeightValueParams) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Converts a height size value into a CSS dimension value for min constraints
|
|
39
|
+
*
|
|
40
|
+
* @param params - The parameters object
|
|
41
|
+
* @param params.value - The size value: number for pixels, "none" for no constraint
|
|
42
|
+
*/
|
|
43
|
+
export declare const getMinHeightValue: ({ value }: Pick<HeightValueParams, "value">) => string | undefined;
|
|
44
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ExtendedRefs, ReferenceType, UseDismissProps, UseFloatingReturn } from "@floating-ui/react";
|
|
2
|
+
import { Dispatch, SetStateAction } from "react";
|
|
2
3
|
import { CommonProps } from "../../common";
|
|
3
4
|
export type PopoverActivation = {
|
|
4
5
|
click?: boolean;
|
|
@@ -8,7 +9,23 @@ export type PopoverActivation = {
|
|
|
8
9
|
export type PopoverDismissal = Pick<UseDismissProps, "ancestorScroll" | "enabled" | "outsidePress">;
|
|
9
10
|
export type PopoverPlacement = "top" | "right" | "bottom" | "left" | "top-start" | "top-end" | "right-start" | "right-end" | "bottom-start" | "bottom-end" | "left-start" | "left-end";
|
|
10
11
|
export type Strategy = "absolute" | "fixed";
|
|
12
|
+
export type HeightSizeLimit = number | "none";
|
|
13
|
+
export type WidthSizeLimit = number | "trigger-width" | "none";
|
|
14
|
+
export type PopoverSizing = {
|
|
15
|
+
minWidth?: WidthSizeLimit;
|
|
16
|
+
maxWidth?: WidthSizeLimit;
|
|
17
|
+
minHeight?: HeightSizeLimit;
|
|
18
|
+
maxHeight?: HeightSizeLimit;
|
|
19
|
+
};
|
|
11
20
|
export interface PopoverProps extends CommonProps {
|
|
21
|
+
/**
|
|
22
|
+
* Size constraints for the popover
|
|
23
|
+
* For each dimension:
|
|
24
|
+
* - number: explicit size in pixels
|
|
25
|
+
* - "trigger-width": match the trigger element's width
|
|
26
|
+
* - "none": let content determine size (default)
|
|
27
|
+
*/
|
|
28
|
+
sizing?: PopoverSizing | ((defaultSizing: PopoverSizing) => PopoverSizing);
|
|
12
29
|
/**
|
|
13
30
|
* Whether the popover should be open on initial render
|
|
14
31
|
*/
|
|
@@ -18,7 +35,7 @@ export interface PopoverProps extends CommonProps {
|
|
|
18
35
|
*/
|
|
19
36
|
placement?: PopoverPlacement;
|
|
20
37
|
/**
|
|
21
|
-
* Determines if focus is
|
|
38
|
+
* Determines if focus is "modal", meaning focus is fully trapped inside the floating element and outside content cannot be accessed. This includes screen reader virtual cursors.
|
|
22
39
|
*/
|
|
23
40
|
isModal?: boolean;
|
|
24
41
|
/**
|
|
@@ -38,7 +55,7 @@ export interface PopoverProps extends CommonProps {
|
|
|
38
55
|
*/
|
|
39
56
|
onOpenStateChange?: (open: boolean) => void;
|
|
40
57
|
/**
|
|
41
|
-
*
|
|
58
|
+
* The id of the html element
|
|
42
59
|
*/
|
|
43
60
|
id?: string;
|
|
44
61
|
}
|
|
@@ -46,7 +63,7 @@ export type FloatingType = Omit<UseFloatingReturn, "middlewareData" | "floatingS
|
|
|
46
63
|
export type ExtendedRefsType = ExtendedRefs<ReferenceType>;
|
|
47
64
|
export type UsePopoverType = {
|
|
48
65
|
isOpen: boolean;
|
|
49
|
-
setIsOpen:
|
|
66
|
+
setIsOpen: Dispatch<SetStateAction<boolean>>;
|
|
50
67
|
isModal: boolean | undefined;
|
|
51
68
|
labelId?: string;
|
|
52
69
|
descriptionId?: string;
|
|
@@ -4,6 +4,6 @@ import { PopoverProps, UsePopoverType } from "./PopoverTypes";
|
|
|
4
4
|
* It should not be used directly, but rather through the Popover component.
|
|
5
5
|
*
|
|
6
6
|
* @param {PopoverProps} options The options for the popover
|
|
7
|
-
* @returns {
|
|
7
|
+
* @returns {UsePopoverType} The data for the popover
|
|
8
8
|
*/
|
|
9
|
-
export declare const usePopover: ({ initialOpen, placement, isModal, isOpen: controlledIsOpen, activation, dismissal, onOpenStateChange, ...restOptions }: PopoverProps) => UsePopoverType;
|
|
9
|
+
export declare const usePopover: ({ initialOpen, placement, isModal, isOpen: controlledIsOpen, activation, dismissal, sizing, onOpenStateChange, ...restOptions }: PopoverProps) => UsePopoverType;
|