@sentry/scraps 0.2.0 → 0.3.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/button/buttonBar.js +7 -1
- package/dist/dragHandle/dragHandle.d.ts +34 -0
- package/dist/dragHandle/dragHandle.js +115 -0
- package/dist/dragHandle/index.d.ts +4 -0
- package/dist/dragHandle/index.js +4 -0
- package/dist/dragHandle/setDocumentDragging.d.ts +9 -0
- package/dist/dragHandle/setDocumentDragging.js +6 -0
- package/dist/dragHandle/useDragMove.d.ts +244 -0
- package/dist/dragHandle/useDragMove.js +66 -0
- package/dist/dragHandle/useDragSeparator.d.ts +256 -0
- package/dist/dragHandle/useDragSeparator.js +36 -0
- package/dist/formPresentation/autoSaveContext.d.ts +23 -0
- package/dist/formPresentation/autoSaveContext.js +13 -0
- package/dist/formPresentation/base.d.ts +11 -0
- package/dist/formPresentation/base.js +37 -0
- package/dist/formPresentation/displayField.d.ts +17 -0
- package/dist/formPresentation/displayField.js +69 -0
- package/dist/formPresentation/fieldIds.d.ts +3 -0
- package/dist/formPresentation/fieldIds.js +14 -0
- package/dist/formPresentation/fieldLayout.d.ts +23 -0
- package/dist/formPresentation/fieldLayout.js +76 -0
- package/dist/formPresentation/formContext.d.ts +4 -0
- package/dist/formPresentation/formContext.js +6 -0
- package/dist/formPresentation/groupContext.d.ts +24 -0
- package/dist/formPresentation/groupContext.js +22 -0
- package/dist/formPresentation/icons.d.ts +11 -0
- package/dist/formPresentation/icons.js +61 -0
- package/dist/formPresentation/index.d.ts +8 -0
- package/dist/formPresentation/index.js +8 -0
- package/dist/formPresentation/meta.d.ts +18 -0
- package/dist/formPresentation/meta.js +88 -0
- package/dist/formPresentation/useStackedLayout.d.ts +1 -0
- package/dist/formPresentation/useStackedLayout.js +9 -0
- package/dist/input/index.d.ts +8 -0
- package/dist/input/index.js +6 -0
- package/dist/input/input.d.ts +19 -0
- package/dist/input/input.js +14 -0
- package/dist/input/inputGroup.d.ts +29 -0
- package/dist/input/inputGroup.js +167 -0
- package/dist/input/inputStyles.d.ts +13 -0
- package/dist/input/inputStyles.js +52 -0
- package/dist/input/numberDragInput.d.ts +20 -0
- package/dist/input/numberDragInput.js +97 -0
- package/dist/input/numberInput.d.ts +10 -0
- package/dist/input/numberInput.js +94 -0
- package/dist/input/otpInput.d.ts +28 -0
- package/dist/input/otpInput.js +81 -0
- package/dist/input/useAutosizeInput.d.ts +17 -0
- package/dist/input/useAutosizeInput.js +56 -0
- package/dist/overlayPositioning.d.ts +10 -1
- package/dist/overlayPositioning.js +15 -2
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.js +3 -0
- package/dist/table/sortableHeaderCell.d.ts +36 -0
- package/dist/table/sortableHeaderCell.js +99 -0
- package/dist/table/styles.d.ts +46 -0
- package/dist/table/styles.js +93 -0
- package/dist/table/table.d.ts +64 -0
- package/dist/table/table.js +228 -0
- package/dist/table/useColumnResize.d.ts +27 -0
- package/dist/table/useColumnResize.js +62 -0
- package/dist/table/useObservedColumnSize.d.ts +12 -0
- package/dist/table/useObservedColumnSize.js +74 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/text.d.ts +7 -0
- package/dist/text/text.js +1 -1
- package/dist/textarea/index.d.ts +1 -0
- package/dist/textarea/index.js +1 -0
- package/dist/textarea/textarea.d.ts +22 -0
- package/dist/textarea/textarea.js +77 -0
- package/dist/useOverlay.js +2 -1
- package/package.json +27 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useCallback, useRef } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { IconArrow } from "@sentry/icons/arrow";
|
|
5
|
+
import { Flex } from "../layout/index.js";
|
|
6
|
+
import { Tooltip } from "../tooltip/index.js";
|
|
7
|
+
import { useTranslation } from "../translation/useTranslation.js";
|
|
8
|
+
import { InputGroup } from "./inputGroup.js";
|
|
9
|
+
function NumberDragInput({ axis = 'x', shiftKeyMultiplier = 10, ...props }) {
|
|
10
|
+
const { tct } = useTranslation();
|
|
11
|
+
const inputRef = useRef(null);
|
|
12
|
+
const onPointerMove = useCallback((event)=>{
|
|
13
|
+
if (0 === event.movementX && 0 === event.movementY || !inputRef.current) return;
|
|
14
|
+
const step = parseFloat(props.step?.toString() ?? '1');
|
|
15
|
+
if (isNaN(step)) throw new TypeError('Step must be of type number, got ' + props.step);
|
|
16
|
+
const pointerDelta = 'x' === axis ? event.movementX : -1 * event.movementY;
|
|
17
|
+
const pointerDeltaOne = pointerDelta > 0 ? Math.ceil(pointerDelta / 100) : Math.floor(pointerDelta / 100);
|
|
18
|
+
const deltaStep = pointerDeltaOne * ((event.shiftKey ? shiftKeyMultiplier : step) ?? 1);
|
|
19
|
+
const min = props.min ?? -1 / 0;
|
|
20
|
+
const max = props.max ?? 1 / 0;
|
|
21
|
+
const value = Math.min(Math.max(Number(inputRef.current.value) + deltaStep, min), max);
|
|
22
|
+
setInputValueAndDispatchChange(inputRef.current, value.toString());
|
|
23
|
+
}, [
|
|
24
|
+
axis,
|
|
25
|
+
props.min,
|
|
26
|
+
props.max,
|
|
27
|
+
props.step,
|
|
28
|
+
shiftKeyMultiplier
|
|
29
|
+
]);
|
|
30
|
+
const onPointerUp = useCallback(()=>{
|
|
31
|
+
document.exitPointerLock();
|
|
32
|
+
document.removeEventListener('pointermove', onPointerMove);
|
|
33
|
+
document.removeEventListener('pointerup', onPointerUp);
|
|
34
|
+
}, [
|
|
35
|
+
onPointerMove
|
|
36
|
+
]);
|
|
37
|
+
const onPointerDown = (event)=>{
|
|
38
|
+
if (0 !== event.button) return;
|
|
39
|
+
event.currentTarget.requestPointerLock();
|
|
40
|
+
document.addEventListener('pointermove', onPointerMove);
|
|
41
|
+
document.addEventListener('pointerup', onPointerUp);
|
|
42
|
+
};
|
|
43
|
+
const onKeyDownProp = props.onKeyDown;
|
|
44
|
+
const onKeyDown = (event)=>{
|
|
45
|
+
onKeyDownProp?.(event);
|
|
46
|
+
if (!inputRef.current || 'ArrowUp' !== event.key && 'ArrowDown' !== event.key) return;
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
const value = parseFloat(inputRef.current.value);
|
|
49
|
+
const step = parseFloat(props.step?.toString() ?? '1');
|
|
50
|
+
const min = props.min ?? -1 / 0;
|
|
51
|
+
const max = props.max ?? 1 / 0;
|
|
52
|
+
const newValue = Math.min(Math.max(value + ('ArrowUp' === event.key ? step : -step), min), max);
|
|
53
|
+
setInputValueAndDispatchChange(inputRef.current, newValue.toString());
|
|
54
|
+
};
|
|
55
|
+
return /*#__PURE__*/ jsxs(InputGroup, {
|
|
56
|
+
children: [
|
|
57
|
+
/*#__PURE__*/ jsx(InputGroup.Input, {
|
|
58
|
+
ref: inputRef,
|
|
59
|
+
type: "text",
|
|
60
|
+
...props,
|
|
61
|
+
onKeyDown: onKeyDown
|
|
62
|
+
}),
|
|
63
|
+
/*#__PURE__*/ jsx(InputGroup.TrailingItems, {
|
|
64
|
+
children: /*#__PURE__*/ jsx(Tooltip, {
|
|
65
|
+
title: tct('Drag to adjust threshold[break]You can hold shift to fine tune', {
|
|
66
|
+
break: /*#__PURE__*/ jsx("br", {})
|
|
67
|
+
}),
|
|
68
|
+
skipWrapper: true,
|
|
69
|
+
children: /*#__PURE__*/ jsxs(Flex, {
|
|
70
|
+
direction: 'x' === axis ? 'row' : 'column',
|
|
71
|
+
gap: "2xs",
|
|
72
|
+
onPointerDown: onPointerDown,
|
|
73
|
+
children: [
|
|
74
|
+
/*#__PURE__*/ jsx(VerySmallIconArrow, {
|
|
75
|
+
direction: 'x' === axis ? 'left' : 'up'
|
|
76
|
+
}),
|
|
77
|
+
/*#__PURE__*/ jsx(VerySmallIconArrow, {
|
|
78
|
+
direction: 'x' === axis ? 'right' : 'down'
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function setInputValueAndDispatchChange(input, value) {
|
|
88
|
+
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set?.call(input, value);
|
|
89
|
+
input.dispatchEvent(new Event('input', {
|
|
90
|
+
bubbles: true
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
const VerySmallIconArrow = styled(IconArrow)`
|
|
94
|
+
width: 8px;
|
|
95
|
+
height: 8px;
|
|
96
|
+
`;
|
|
97
|
+
export { NumberDragInput };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { AriaNumberFieldProps } from '@react-aria/numberfield';
|
|
3
|
+
import type { InputStylesProps } from './input.js';
|
|
4
|
+
interface NumberInputProps extends InputStylesProps, AriaNumberFieldProps, Pick<React.InputHTMLAttributes<HTMLInputElement>, 'name' | 'disabled' | 'readOnly' | 'required' | 'className'> {
|
|
5
|
+
max?: number;
|
|
6
|
+
min?: number;
|
|
7
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
8
|
+
}
|
|
9
|
+
export declare function NumberInput({ ref, disabled, readOnly, monospace, min, max, size, placeholder, nativeSize, className, ...props }: NumberInputProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { useButton } from "@react-aria/button";
|
|
5
|
+
import { useLocale } from "@react-aria/i18n";
|
|
6
|
+
import { useNumberField } from "@react-aria/numberfield";
|
|
7
|
+
import { mergeRefs } from "@react-aria/utils";
|
|
8
|
+
import { useNumberFieldState } from "@react-stately/numberfield";
|
|
9
|
+
import { IconChevron } from "@sentry/icons/chevron";
|
|
10
|
+
import { Button } from "../button/index.js";
|
|
11
|
+
import { useTranslation } from "../translation/useTranslation.js";
|
|
12
|
+
import { InputGroup } from "./inputGroup.js";
|
|
13
|
+
function NumberInput({ ref, disabled, readOnly, monospace, min, max, size, placeholder, nativeSize, className, ...props }) {
|
|
14
|
+
const { t } = useTranslation();
|
|
15
|
+
const localRef = useRef(null);
|
|
16
|
+
const ariaProps = {
|
|
17
|
+
isDisabled: disabled,
|
|
18
|
+
isReadOnly: readOnly,
|
|
19
|
+
minValue: min,
|
|
20
|
+
maxValue: max,
|
|
21
|
+
placeholder,
|
|
22
|
+
...props
|
|
23
|
+
};
|
|
24
|
+
const { locale } = useLocale();
|
|
25
|
+
const state = useNumberFieldState({
|
|
26
|
+
locale,
|
|
27
|
+
...ariaProps
|
|
28
|
+
});
|
|
29
|
+
const { groupProps, inputProps, incrementButtonProps, decrementButtonProps } = useNumberField(ariaProps, state, localRef);
|
|
30
|
+
const incrementButtonRef = useRef(null);
|
|
31
|
+
const { buttonProps: incrementProps } = useButton(incrementButtonProps, incrementButtonRef);
|
|
32
|
+
const decrementButtonRef = useRef(null);
|
|
33
|
+
const { buttonProps: decrementProps } = useButton(decrementButtonProps, decrementButtonRef);
|
|
34
|
+
return /*#__PURE__*/ jsxs(InputGroup, {
|
|
35
|
+
...groupProps,
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ jsx(InputGroup.Input, {
|
|
38
|
+
...inputProps,
|
|
39
|
+
ref: mergeRefs(localRef, ref),
|
|
40
|
+
placeholder: placeholder,
|
|
41
|
+
size: size,
|
|
42
|
+
nativeSize: nativeSize,
|
|
43
|
+
monospace: monospace,
|
|
44
|
+
className: className
|
|
45
|
+
}),
|
|
46
|
+
/*#__PURE__*/ jsx(InputGroup.TrailingItems, {
|
|
47
|
+
children: /*#__PURE__*/ jsxs(StepWrap, {
|
|
48
|
+
size: size,
|
|
49
|
+
children: [
|
|
50
|
+
/*#__PURE__*/ jsx(StepButton, {
|
|
51
|
+
ref: incrementButtonRef,
|
|
52
|
+
size: "zero",
|
|
53
|
+
variant: "transparent",
|
|
54
|
+
...incrementProps,
|
|
55
|
+
"aria-label": incrementProps['aria-label'] ?? t('Increment'),
|
|
56
|
+
icon: /*#__PURE__*/ jsx(StyledIconChevron, {
|
|
57
|
+
direction: "up"
|
|
58
|
+
})
|
|
59
|
+
}),
|
|
60
|
+
/*#__PURE__*/ jsx(StepButton, {
|
|
61
|
+
ref: decrementButtonRef,
|
|
62
|
+
size: "zero",
|
|
63
|
+
variant: "transparent",
|
|
64
|
+
...decrementProps,
|
|
65
|
+
"aria-label": decrementProps['aria-label'] ?? t('Decrement'),
|
|
66
|
+
icon: /*#__PURE__*/ jsx(StyledIconChevron, {
|
|
67
|
+
direction: "down"
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
]
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const StepWrap = styled('div')`
|
|
77
|
+
display: flex;
|
|
78
|
+
flex-direction: column;
|
|
79
|
+
align-items: center;
|
|
80
|
+
width: ${(p)=>p.theme.space.lg};
|
|
81
|
+
height: ${(p)=>'xs' === p.size ? '1rem' : '1.25rem'};
|
|
82
|
+
`;
|
|
83
|
+
const StepButton = styled(Button)`
|
|
84
|
+
display: flex;
|
|
85
|
+
height: 50%;
|
|
86
|
+
padding: 0 ${(p)=>p.theme.space['2xs']};
|
|
87
|
+
min-height: 0;
|
|
88
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
89
|
+
`;
|
|
90
|
+
const StyledIconChevron = styled(IconChevron)`
|
|
91
|
+
width: 0.5rem;
|
|
92
|
+
height: 0.5rem;
|
|
93
|
+
`;
|
|
94
|
+
export { NumberInput };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type FormatToken = '0' | 'A';
|
|
2
|
+
type FormatParserState = 'start' | 'token' | 'separator';
|
|
3
|
+
/**
|
|
4
|
+
* Type-level parsing machinery for OTP formats. It walks the format one character at
|
|
5
|
+
* a time, remembers whether the first input token was `0` or `A`, and rejects formats
|
|
6
|
+
* that mix the two token types. The parser state also prevents leading, trailing, or
|
|
7
|
+
* consecutive separators. This type has no runtime behavior; it exists solely to
|
|
8
|
+
* provide useful TypeScript errors at OTPInput call sites.
|
|
9
|
+
*/
|
|
10
|
+
type IsValidOTPFormat<Format extends string, SelectedToken extends FormatToken | null = null, State extends FormatParserState = 'start'> = Format extends '' ? State extends 'token' ? true : false : Format extends `${infer Character}${infer Rest}` ? Character extends FormatToken ? SelectedToken extends null ? IsValidOTPFormat<Rest, Character, 'token'> : Character extends SelectedToken ? IsValidOTPFormat<Rest, SelectedToken, 'token'> : false : Character extends '-' ? State extends 'token' ? IsValidOTPFormat<Rest, SelectedToken, 'separator'> : false : false : false;
|
|
11
|
+
type OTPFormat<Format extends string> = IsValidOTPFormat<Format> extends true ? Format : never;
|
|
12
|
+
export interface OTPInputProps<Format extends string> {
|
|
13
|
+
/**
|
|
14
|
+
* Describes the accepted characters and visual grouping. Use `0` for numeric
|
|
15
|
+
* inputs, `A` for alphanumeric inputs, and `-` for visual separators. A format
|
|
16
|
+
* must use either `0` or `A` throughout. Separators are not included in the value.
|
|
17
|
+
*/
|
|
18
|
+
format: OTPFormat<Format>;
|
|
19
|
+
onComplete: (value: string) => void;
|
|
20
|
+
'aria-label'?: string;
|
|
21
|
+
defaultValue?: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** Converts alphanumeric input to uppercase as it is entered. */
|
|
24
|
+
uppercase?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** @public */
|
|
27
|
+
export declare function OTPInput<const Format extends string>({ 'aria-label': ariaLabel, format, onComplete, disabled, defaultValue, uppercase, }: OTPInputProps<Format>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment, useState } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { OTPInput, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
|
|
5
|
+
import { Flex } from "../layout/index.js";
|
|
6
|
+
import { Text } from "../text/index.js";
|
|
7
|
+
import { useTranslation } from "../translation/useTranslation.js";
|
|
8
|
+
import { inputStyles } from "./inputStyles.js";
|
|
9
|
+
function otpInput_OTPInput({ 'aria-label': ariaLabel, format, onComplete, disabled = false, defaultValue = '', uppercase = false }) {
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const [value, setValue] = useState(defaultValue);
|
|
12
|
+
const normalizeValue = (newValue)=>uppercase ? newValue.toUpperCase() : newValue;
|
|
13
|
+
const formatCharacters = [
|
|
14
|
+
...format
|
|
15
|
+
];
|
|
16
|
+
const isAlphanumeric = format.includes('A');
|
|
17
|
+
const length = formatCharacters.filter((character)=>'-' !== character).length;
|
|
18
|
+
return /*#__PURE__*/ jsx(OTPInput, {
|
|
19
|
+
"aria-label": ariaLabel ?? t('One-time password'),
|
|
20
|
+
autoComplete: "one-time-code",
|
|
21
|
+
disabled: disabled,
|
|
22
|
+
inputMode: isAlphanumeric ? 'text' : 'numeric',
|
|
23
|
+
maxLength: length,
|
|
24
|
+
onChange: (newValue)=>setValue(normalizeValue(newValue)),
|
|
25
|
+
onComplete: (newValue)=>onComplete(normalizeValue(newValue)),
|
|
26
|
+
onPasteCapture: (event)=>{
|
|
27
|
+
if (!event.clipboardData) {
|
|
28
|
+
event.preventDefault();
|
|
29
|
+
event.stopPropagation();
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
pasteTransformer: (pastedValue)=>pastedValue.replaceAll('-', ''),
|
|
33
|
+
pattern: isAlphanumeric ? REGEXP_ONLY_DIGITS_AND_CHARS : REGEXP_ONLY_DIGITS,
|
|
34
|
+
render: ({ slots })=>/*#__PURE__*/ jsx(Flex, {
|
|
35
|
+
align: "center",
|
|
36
|
+
"aria-hidden": true,
|
|
37
|
+
gap: "xs",
|
|
38
|
+
paddingRight: "md",
|
|
39
|
+
children: formatCharacters.map((character, formatIndex)=>{
|
|
40
|
+
if ('-' === character) return /*#__PURE__*/ jsx(Fragment, {
|
|
41
|
+
children: /*#__PURE__*/ jsx(Flex, {
|
|
42
|
+
align: "center",
|
|
43
|
+
paddingLeft: "xs",
|
|
44
|
+
paddingRight: "xs",
|
|
45
|
+
children: (flexProps)=>/*#__PURE__*/ jsx(Text, {
|
|
46
|
+
...flexProps,
|
|
47
|
+
as: "span",
|
|
48
|
+
size: "lg",
|
|
49
|
+
children: "-"
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
}, formatIndex);
|
|
53
|
+
const slotIndex = formatCharacters.slice(0, formatIndex).filter((formatCharacter)=>'-' !== formatCharacter).length;
|
|
54
|
+
const slot = slots[slotIndex];
|
|
55
|
+
if (!slot) return null;
|
|
56
|
+
return /*#__PURE__*/ jsx(OTPInputSlot, {
|
|
57
|
+
align: "center",
|
|
58
|
+
"aria-hidden": true,
|
|
59
|
+
"aria-disabled": disabled,
|
|
60
|
+
"data-input-otp-slot": true,
|
|
61
|
+
justify: "center",
|
|
62
|
+
$isActive: slot.isActive,
|
|
63
|
+
children: slot.char ?? slot.placeholderChar
|
|
64
|
+
}, formatIndex);
|
|
65
|
+
})
|
|
66
|
+
}),
|
|
67
|
+
value: value
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const OTPInputSlot = styled(Flex)`
|
|
71
|
+
${(p)=>inputStyles({
|
|
72
|
+
theme: p.theme
|
|
73
|
+
})};
|
|
74
|
+
display: flex;
|
|
75
|
+
min-width: ${(p)=>p.theme.form.md.height};
|
|
76
|
+
padding: 0;
|
|
77
|
+
width: ${(p)=>p.theme.form.md.height};
|
|
78
|
+
|
|
79
|
+
${(p)=>p.$isActive && p.theme.focusRing(`0 1px 0 0 ${p.theme.tokens.interactive.chonky.debossed.neutral.chonk} inset`)};
|
|
80
|
+
`;
|
|
81
|
+
export { otpInput_OTPInput as OTPInput };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* This hook is used to automatically resize an input element based on its content.
|
|
4
|
+
* It is useful for creating "growing" inputs that can resize to fit their content.
|
|
5
|
+
*
|
|
6
|
+
* @param options - Options for the autosize input functionality.
|
|
7
|
+
* @param options.value - The value of the input, use when the input is controlled.
|
|
8
|
+
* @param options.placeholder - The placeholder of the input. An empty input is sized
|
|
9
|
+
* to its placeholder, so pass it when the placeholder can change.
|
|
10
|
+
* @returns A ref callback for the input element.
|
|
11
|
+
*/
|
|
12
|
+
interface UseAutosizeInputOptions {
|
|
13
|
+
placeholder?: string | undefined;
|
|
14
|
+
value?: React.InputHTMLAttributes<HTMLInputElement>['value'] | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare function useAutosizeInput(options?: UseAutosizeInputOptions): React.RefCallback<HTMLInputElement>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useCallback, useLayoutEffect, useRef } from "react";
|
|
2
|
+
function createSizingDiv(computedStyles) {
|
|
3
|
+
const sizingDiv = document.createElement('div');
|
|
4
|
+
sizingDiv.style.whiteSpace = 'pre';
|
|
5
|
+
sizingDiv.style.width = 'auto';
|
|
6
|
+
sizingDiv.style.height = '0';
|
|
7
|
+
sizingDiv.style.position = 'fixed';
|
|
8
|
+
sizingDiv.style.pointerEvents = 'none';
|
|
9
|
+
sizingDiv.style.opacity = '0';
|
|
10
|
+
sizingDiv.style.zIndex = '-1';
|
|
11
|
+
sizingDiv.style.fontSize = computedStyles.fontSize;
|
|
12
|
+
sizingDiv.style.fontWeight = computedStyles.fontWeight;
|
|
13
|
+
sizingDiv.style.fontFamily = computedStyles.fontFamily;
|
|
14
|
+
return sizingDiv;
|
|
15
|
+
}
|
|
16
|
+
function useAutosizeInput(options) {
|
|
17
|
+
const sourceRef = useRef(null);
|
|
18
|
+
const sizingDivRef = useRef(null);
|
|
19
|
+
useLayoutEffect(()=>()=>{
|
|
20
|
+
if (sizingDivRef.current?.parentNode) {
|
|
21
|
+
sizingDivRef.current.parentNode.removeChild(sizingDivRef.current);
|
|
22
|
+
sizingDivRef.current = null;
|
|
23
|
+
}
|
|
24
|
+
}, []);
|
|
25
|
+
useLayoutEffect(()=>{
|
|
26
|
+
if (sourceRef.current) resize(sourceRef.current, sizingDivRef);
|
|
27
|
+
}, [
|
|
28
|
+
options?.value,
|
|
29
|
+
options?.placeholder
|
|
30
|
+
]);
|
|
31
|
+
const onInputChange = useCallback((_event)=>{
|
|
32
|
+
if (sourceRef.current) resize(sourceRef.current, sizingDivRef);
|
|
33
|
+
}, []);
|
|
34
|
+
const autosizingCallbackRef = useCallback((element)=>{
|
|
35
|
+
if (element) {
|
|
36
|
+
resize(element, sizingDivRef);
|
|
37
|
+
element.addEventListener('input', onInputChange);
|
|
38
|
+
} else sourceRef.current?.removeEventListener('input', onInputChange);
|
|
39
|
+
sourceRef.current = element;
|
|
40
|
+
}, [
|
|
41
|
+
onInputChange
|
|
42
|
+
]);
|
|
43
|
+
return autosizingCallbackRef;
|
|
44
|
+
}
|
|
45
|
+
function resize(input, sizingDivRef) {
|
|
46
|
+
const computedStyles = getComputedStyle(input);
|
|
47
|
+
if (!sizingDivRef.current) {
|
|
48
|
+
sizingDivRef.current = createSizingDiv(computedStyles);
|
|
49
|
+
document.body.appendChild(sizingDivRef.current);
|
|
50
|
+
}
|
|
51
|
+
const sizingDiv = sizingDivRef.current;
|
|
52
|
+
sizingDiv.innerText = input.value || input.placeholder;
|
|
53
|
+
const newTotalInputSize = sizingDiv.offsetWidth + parseInt(computedStyles.paddingLeft ?? 0, 10) + parseInt(computedStyles.paddingRight ?? 0, 10) + 2 * parseInt(computedStyles.borderWidth ?? 0, 10) + 1;
|
|
54
|
+
input.style.width = `${newTotalInputSize}px`;
|
|
55
|
+
}
|
|
56
|
+
export { useAutosizeInput };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as React from 'react';
|
|
2
|
-
import type { FlipOptions, Middleware, Padding, Placement, ShiftOptions } from '@floating-ui/react-dom';
|
|
2
|
+
import type { FlipOptions, Middleware, Padding, Placement, Platform, ShiftOptions } from '@floating-ui/react-dom';
|
|
3
3
|
/**
|
|
4
4
|
* Where to place an overlay relative to its trigger. The `auto` positions
|
|
5
5
|
* pick whichever side has the most space.
|
|
@@ -59,3 +59,12 @@ export interface ShiftOverlayOptions extends ShiftOptions {
|
|
|
59
59
|
* offset that already places the overlay away from its trigger is kept.
|
|
60
60
|
*/
|
|
61
61
|
export declare function shiftOverlay(options?: ShiftOverlayOptions): Middleware;
|
|
62
|
+
/**
|
|
63
|
+
* Floating UI's platform, except that the default `clippingAncestors` boundary
|
|
64
|
+
* only includes ancestors that contain the overlay's offset parent, as Popper
|
|
65
|
+
* did. Floating UI treats a positioned `display: contents` element as the
|
|
66
|
+
* overlay's containing block, even though it has no box. Overflow ancestors
|
|
67
|
+
* between it and the real containing block then clamp the overlay's size
|
|
68
|
+
* without clipping it, e.g. a `DropdownMenu` inside a `ButtonBar`.
|
|
69
|
+
*/
|
|
70
|
+
export declare const overlayPlatform: Platform;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { arrow, autoPlacement, flip, limitShift, shift } from "@floating-ui/react-dom";
|
|
1
|
+
import { arrow, autoPlacement, flip, getOverflowAncestors, limitShift, platform as react_dom_platform, shift } from "@floating-ui/react-dom";
|
|
2
2
|
function placementMiddleware(position, flipOptions = {}) {
|
|
3
3
|
if ('auto' === position || 'auto-start' === position || 'auto-end' === position) {
|
|
4
4
|
const { mainAxis: _mainAxis, crossAxis: _crossAxis, fallbackPlacements: _fallbackPlacements, fallbackStrategy: _fallbackStrategy, fallbackAxisSideDirection: _fallbackAxisSideDirection, flipAlignment = true, ...detectOverflowOptions } = flipOptions;
|
|
@@ -123,4 +123,17 @@ function tetherLimiter(origin, arrowElement) {
|
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
-
|
|
126
|
+
const overlayPlatform = {
|
|
127
|
+
...react_dom_platform,
|
|
128
|
+
getClippingRect (args) {
|
|
129
|
+
const { element, boundary, strategy } = args;
|
|
130
|
+
const offsetParent = element instanceof HTMLElement && 'absolute' === strategy ? element.offsetParent : null;
|
|
131
|
+
if ('clippingAncestors' !== boundary || !offsetParent) return react_dom_platform.getClippingRect.call(this, args);
|
|
132
|
+
const clippingAncestors = getOverflowAncestors(element, [], false).filter((ancestor)=>ancestor instanceof Element && ancestor !== element.ownerDocument.body && ancestor.contains(offsetParent));
|
|
133
|
+
return react_dom_platform.getClippingRect.call(this, {
|
|
134
|
+
...args,
|
|
135
|
+
boundary: clippingAncestors
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
export { anchorOverlay, anchoredStyles, arrowOverlay, flipOverlay, overlayPlatform, placementMiddleware, shiftOverlay };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { COL_WIDTH_MINIMUM, COL_WIDTH_UNDEFINED, Table, type TableColumnConfig, type TableProps, useTableElement, } from './table.js';
|
|
2
|
+
export { COLUMN_ALIGN_JUSTIFY, getAriaSort, HeaderCellContent, SortableHeaderCell, type ColumnAlign, type SortDirection, } from './sortableHeaderCell.js';
|
|
3
|
+
export { emptyCellStyle, fullWidthCellStyle, statusCellStyle, TableStatusCell, } from './styles.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { COL_WIDTH_MINIMUM, COL_WIDTH_UNDEFINED, Table, useTableElement } from "./table.js";
|
|
2
|
+
export { COLUMN_ALIGN_JUSTIFY, HeaderCellContent, SortableHeaderCell, getAriaSort } from "./sortableHeaderCell.js";
|
|
3
|
+
export { TableStatusCell, emptyCellStyle, fullWidthCellStyle, statusCellStyle } from "./styles.js";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HTMLAttributes, MouseEvent, ReactNode } from 'react';
|
|
2
|
+
import { type LinkProps } from '../link/index.js';
|
|
3
|
+
export type SortDirection = 'asc' | 'desc';
|
|
4
|
+
export declare function getAriaSort(direction: SortDirection | undefined): 'ascending' | 'descending' | undefined;
|
|
5
|
+
export type ColumnAlign = 'left' | 'center' | 'right';
|
|
6
|
+
export declare const COLUMN_ALIGN_JUSTIFY: {
|
|
7
|
+
readonly center: "center";
|
|
8
|
+
readonly left: "start";
|
|
9
|
+
readonly right: "end";
|
|
10
|
+
};
|
|
11
|
+
interface SortableHeaderCellProps extends HTMLAttributes<HTMLDivElement> {
|
|
12
|
+
align?: ColumnAlign;
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
direction?: SortDirection;
|
|
15
|
+
onSort?: (event: MouseEvent) => void;
|
|
16
|
+
overlays?: ReactNode;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `to` should replace the history entry rather than pushing a new one.
|
|
19
|
+
*/
|
|
20
|
+
replace?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Sort destination to navigate to on sort.
|
|
23
|
+
*/
|
|
24
|
+
to?: LinkProps['to'];
|
|
25
|
+
}
|
|
26
|
+
export declare function SortableHeaderCell({ align, children, direction, onSort, overlays, replace, to, ...props }: SortableHeaderCellProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare const HeaderCellContent: import("@emotion/styled").StyledComponent<{
|
|
28
|
+
theme?: import("@emotion/react").Theme;
|
|
29
|
+
as?: React.ElementType;
|
|
30
|
+
} & {
|
|
31
|
+
align?: ColumnAlign;
|
|
32
|
+
replace?: boolean;
|
|
33
|
+
to?: LinkProps["to"];
|
|
34
|
+
type?: "button";
|
|
35
|
+
}, import("react").DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
|
+
import { css } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { IconArrow } from "@sentry/icons/arrow";
|
|
6
|
+
import { FLEX_JUSTIFY_CONTENT } from "../layout/index.js";
|
|
7
|
+
import { Link } from "../link/index.js";
|
|
8
|
+
import { Tooltip } from "../tooltip/index.js";
|
|
9
|
+
function getAriaSort(direction) {
|
|
10
|
+
switch(direction){
|
|
11
|
+
case 'asc':
|
|
12
|
+
return 'ascending';
|
|
13
|
+
case 'desc':
|
|
14
|
+
return 'descending';
|
|
15
|
+
default:
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const COLUMN_ALIGN_JUSTIFY = {
|
|
20
|
+
center: 'center',
|
|
21
|
+
left: 'start',
|
|
22
|
+
right: 'end'
|
|
23
|
+
};
|
|
24
|
+
function SortableHeaderCell({ align, children, direction, onSort, overlays, replace, to, ...props }) {
|
|
25
|
+
return /*#__PURE__*/ jsxs(HeaderCellContent, {
|
|
26
|
+
...props,
|
|
27
|
+
align: align,
|
|
28
|
+
as: to ? Link : onSort ? 'button' : 'div',
|
|
29
|
+
onClick: onSort,
|
|
30
|
+
replace: to ? replace : void 0,
|
|
31
|
+
to: to,
|
|
32
|
+
type: !to && onSort ? 'button' : void 0,
|
|
33
|
+
children: [
|
|
34
|
+
overlays,
|
|
35
|
+
/*#__PURE__*/ jsx(Tooltip, {
|
|
36
|
+
showOnlyOnOverflow: true,
|
|
37
|
+
skipWrapper: true,
|
|
38
|
+
title: children,
|
|
39
|
+
children: /*#__PURE__*/ jsx(Label, {
|
|
40
|
+
align: align,
|
|
41
|
+
grow: !direction,
|
|
42
|
+
children: children
|
|
43
|
+
})
|
|
44
|
+
}),
|
|
45
|
+
direction && /*#__PURE__*/ jsx(IconArrow, {
|
|
46
|
+
"aria-hidden": true,
|
|
47
|
+
direction: 'desc' === direction ? 'down' : 'up',
|
|
48
|
+
size: "xs"
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const Label = styled('div', {
|
|
54
|
+
shouldForwardProp: (prop)=>'align' !== prop && 'grow' !== prop
|
|
55
|
+
})`
|
|
56
|
+
margin: -${(p)=>p.theme.space['2xs']};
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
padding: ${(p)=>p.theme.space['2xs']};
|
|
59
|
+
text-overflow: ellipsis;
|
|
60
|
+
white-space: nowrap;
|
|
61
|
+
|
|
62
|
+
/* Without a sort arrow beside it, the label fills the cell so that content
|
|
63
|
+
aligning itself, such as a right-aligned column label, has room to. */
|
|
64
|
+
${(p)=>p.grow && css`
|
|
65
|
+
flex: 1;
|
|
66
|
+
text-align: ${p.align ?? 'left'};
|
|
67
|
+
`}
|
|
68
|
+
`;
|
|
69
|
+
const HeaderCellContent = styled('div', {
|
|
70
|
+
shouldForwardProp: (prop)=>'align' !== prop && ('to' === prop || 'replace' === prop || is_prop_valid(prop))
|
|
71
|
+
})`
|
|
72
|
+
align-items: center;
|
|
73
|
+
background: none;
|
|
74
|
+
border: 0;
|
|
75
|
+
color: inherit;
|
|
76
|
+
cursor: ${(p)=>p.onClick || p.to ? 'pointer' : 'default'};
|
|
77
|
+
display: flex;
|
|
78
|
+
flex: 1;
|
|
79
|
+
font: inherit;
|
|
80
|
+
gap: ${(p)=>p.theme.space.xs};
|
|
81
|
+
margin: -${(p)=>p.theme.space['2xs']};
|
|
82
|
+
min-width: 0;
|
|
83
|
+
overflow: hidden;
|
|
84
|
+
padding: ${(p)=>p.theme.space['2xs']};
|
|
85
|
+
text-align: inherit;
|
|
86
|
+
text-transform: inherit;
|
|
87
|
+
|
|
88
|
+
${(p)=>p.align && css`
|
|
89
|
+
justify-content: ${FLEX_JUSTIFY_CONTENT[COLUMN_ALIGN_JUSTIFY[p.align]]};
|
|
90
|
+
`}
|
|
91
|
+
|
|
92
|
+
&:hover,
|
|
93
|
+
&:active,
|
|
94
|
+
&:focus,
|
|
95
|
+
&:visited {
|
|
96
|
+
color: inherit;
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
export { COLUMN_ALIGN_JUSTIFY, HeaderCellContent, SortableHeaderCell, getAriaSort };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type Theme } from '@emotion/react';
|
|
2
|
+
import { type FlexProps } from '../layout/index.js';
|
|
3
|
+
interface TableGridProps {
|
|
4
|
+
hiddenColumnIndexes?: number[];
|
|
5
|
+
}
|
|
6
|
+
export declare const TableGrid: import("@emotion/styled").StyledComponent<{
|
|
7
|
+
theme?: Theme;
|
|
8
|
+
as?: React.ElementType;
|
|
9
|
+
} & TableGridProps, import("react").DetailedHTMLProps<import("react").TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, {}>;
|
|
10
|
+
export declare const TableHead: import("@emotion/styled").StyledComponent<{
|
|
11
|
+
theme?: Theme;
|
|
12
|
+
as?: React.ElementType;
|
|
13
|
+
} & {
|
|
14
|
+
sticky?: boolean;
|
|
15
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
|
|
16
|
+
export declare const TableBody: import("@emotion/styled").StyledComponent<{
|
|
17
|
+
theme?: Theme;
|
|
18
|
+
as?: React.ElementType;
|
|
19
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableSectionElement>, HTMLTableSectionElement>, {}>;
|
|
20
|
+
export declare const TableRow: import("@emotion/styled").StyledComponent<{
|
|
21
|
+
theme?: Theme;
|
|
22
|
+
as?: React.ElementType;
|
|
23
|
+
} & {
|
|
24
|
+
divider?: boolean;
|
|
25
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement>, {}>;
|
|
26
|
+
export declare function TableHeadCell(props: FlexProps<'th'>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
27
|
+
export declare const TableCell: import("@emotion/styled").StyledComponent<{
|
|
28
|
+
theme?: Theme;
|
|
29
|
+
as?: React.ElementType;
|
|
30
|
+
}, import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, {}>;
|
|
31
|
+
export declare const TableStatusCell: import("@emotion/styled").StyledComponent<{
|
|
32
|
+
theme?: Theme;
|
|
33
|
+
as?: React.ElementType;
|
|
34
|
+
}, import("react").DetailedHTMLProps<import("react").TdHTMLAttributes<HTMLTableDataCellElement>, HTMLTableDataCellElement>, {}>;
|
|
35
|
+
export declare const fullWidthCellStyle: import("@emotion/react").SerializedStyles;
|
|
36
|
+
export declare const statusCellStyle: (p: {
|
|
37
|
+
theme: Theme;
|
|
38
|
+
}) => import("@emotion/react").SerializedStyles;
|
|
39
|
+
export declare const emptyCellStyle: (p: {
|
|
40
|
+
theme: Theme;
|
|
41
|
+
}) => import("@emotion/react").SerializedStyles;
|
|
42
|
+
export declare const TableResizer: import("@emotion/styled").StyledComponent<{
|
|
43
|
+
theme?: Theme;
|
|
44
|
+
as?: React.ElementType;
|
|
45
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
46
|
+
export {};
|