@sentry/scraps 0.2.0 → 0.4.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/layout/styles.d.ts +1 -1
- package/dist/menu/controlContext.d.ts +32 -0
- package/dist/menu/controlContext.js +7 -0
- package/dist/menu/dropdownButton.d.ts +18 -0
- package/dist/menu/dropdownButton.js +66 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.js +3 -0
- package/dist/menu/menu.d.ts +159 -0
- package/dist/menu/menu.js +464 -0
- package/dist/menu/selectTypes.d.ts +96 -0
- package/dist/menu/selectTypes.js +0 -0
- package/dist/menu/selectValue.d.ts +13 -0
- package/dist/menu/selectValue.js +0 -0
- package/dist/overlayPositioning.d.ts +10 -1
- package/dist/overlayPositioning.js +15 -2
- package/dist/overlayTrigger.d.ts +22 -0
- package/dist/overlayTrigger.js +30 -0
- package/dist/slot/knownContexts.d.ts +1 -1
- package/dist/spinner/index.d.ts +1 -0
- package/dist/spinner/index.js +1 -0
- package/dist/spinner/spinner.d.ts +14 -0
- package/dist/spinner/spinner.js +126 -0
- package/dist/splitPanel/index.d.ts +1 -0
- package/dist/splitPanel/index.js +1 -0
- package/dist/splitPanel/splitPanel.d.ts +36 -0
- package/dist/splitPanel/splitPanel.js +144 -0
- 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/toast/index.d.ts +5 -0
- package/dist/toast/index.js +4 -0
- package/dist/toast/toast.d.ts +10 -0
- package/dist/toast/toast.js +182 -0
- package/dist/toast/toastApi.d.ts +10 -0
- package/dist/toast/toastApi.js +53 -0
- package/dist/toast/toaster.d.ts +4 -0
- package/dist/toast/toaster.js +42 -0
- package/dist/toast/types.d.ts +17 -0
- package/dist/toast/types.js +2 -0
- package/dist/toggleCard/index.d.ts +1 -0
- package/dist/toggleCard/index.js +1 -0
- package/dist/toggleCard/toggleCard.d.ts +32 -0
- package/dist/toggleCard/toggleCard.js +301 -0
- package/dist/useDimensions.d.ts +12 -0
- package/dist/useDimensions.js +31 -0
- package/dist/useOverlay.js +2 -1
- package/dist/useResizableDrawer.d.ts +72 -0
- package/dist/useResizableDrawer.js +136 -0
- package/package.json +60 -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 };
|
package/dist/layout/styles.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ export declare function useActiveBreakpoint(): BreakpointSize;
|
|
|
77
77
|
* CSS-only responsive props don't need this — they resolve natively via
|
|
78
78
|
* `@container` queries. This context exists purely for the JS resolution path.
|
|
79
79
|
*/
|
|
80
|
-
export declare const ContainerQueryContext: import("react").Context<"
|
|
80
|
+
export declare const ContainerQueryContext: import("react").Context<"2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "zero" | "3xs" | "5xl" | null>;
|
|
81
81
|
/**
|
|
82
82
|
* The JS equivalent of a CSS container query: returns the active breakpoint of
|
|
83
83
|
* the nearest ancestor query container (read from `ContainerQueryContext`),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { OverlayTriggerState } from '@react-stately/overlays';
|
|
2
|
+
import type { FormSize } from '../theme/index.js';
|
|
3
|
+
import type { SearchMatchResult, SelectKey, SelectOptionWithKey } from './selectTypes.js';
|
|
4
|
+
interface ControlContextValue {
|
|
5
|
+
overlayIsOpen: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Search string to determine whether an option should be rendered in the select list.
|
|
8
|
+
*/
|
|
9
|
+
search: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether the select has a search input field.
|
|
12
|
+
*/
|
|
13
|
+
searchable: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the matched substring of each option's label should be highlighted
|
|
17
|
+
* as the user types.
|
|
18
|
+
*/
|
|
19
|
+
highlightSearch?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The control's overlay state. Useful for opening/closing the menu from inside the
|
|
22
|
+
* selector.
|
|
23
|
+
*/
|
|
24
|
+
overlayState?: OverlayTriggerState;
|
|
25
|
+
/**
|
|
26
|
+
* Custom function to determine whether an option matches the search query.
|
|
27
|
+
*/
|
|
28
|
+
searchMatcher?: (option: SelectOptionWithKey<SelectKey>, search: string) => SearchMatchResult;
|
|
29
|
+
size?: FormSize;
|
|
30
|
+
}
|
|
31
|
+
export declare const ControlContext: import("react").Context<ControlContextValue>;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { DistributedOmit } from 'type-fest';
|
|
3
|
+
import type { ButtonProps } from '../button/index.js';
|
|
4
|
+
export type DropdownButtonProps = DistributedOmit<ButtonProps, 'type' | 'prefix'> & {
|
|
5
|
+
/**
|
|
6
|
+
* Whether or not the button should render as open
|
|
7
|
+
*/
|
|
8
|
+
isOpen?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The fixed prefix text to show in the button eg: 'Sort By'
|
|
11
|
+
*/
|
|
12
|
+
prefix?: React.ReactNode;
|
|
13
|
+
/**
|
|
14
|
+
* Should a chevron icon be shown?
|
|
15
|
+
*/
|
|
16
|
+
showChevron?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function DropdownButton({ children, prefix, size: explicitSize, isOpen, showChevron, disabled, ref, onClick, ...props }: DropdownButtonProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { css } from "@emotion/react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { IconChevron } from "@sentry/icons/chevron";
|
|
5
|
+
import { Button } from "../button/index.js";
|
|
6
|
+
import { useResponsivePropValue } from "../layout/index.js";
|
|
7
|
+
import { useSizeContext } from "../sizeContext.js";
|
|
8
|
+
function DropdownButton({ children, prefix, size: explicitSize, isOpen = false, showChevron = true, disabled = false, ref, onClick, ...props }) {
|
|
9
|
+
const contextSize = useSizeContext();
|
|
10
|
+
const size = useResponsivePropValue(explicitSize ?? contextSize ?? 'md');
|
|
11
|
+
return /*#__PURE__*/ jsxs(StyledButton, {
|
|
12
|
+
"aria-haspopup": "true",
|
|
13
|
+
"aria-expanded": isOpen,
|
|
14
|
+
hasPrefix: !!prefix,
|
|
15
|
+
disabled: disabled,
|
|
16
|
+
isOpen: isOpen,
|
|
17
|
+
size: size,
|
|
18
|
+
ref: ref,
|
|
19
|
+
...props,
|
|
20
|
+
onClick: (event)=>{
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
onClick?.(event);
|
|
24
|
+
},
|
|
25
|
+
children: [
|
|
26
|
+
prefix && /*#__PURE__*/ jsx(LabelText, {
|
|
27
|
+
children: prefix
|
|
28
|
+
}),
|
|
29
|
+
children,
|
|
30
|
+
showChevron && /*#__PURE__*/ jsx(ChevronWrap, {
|
|
31
|
+
children: /*#__PURE__*/ jsx(IconChevron, {
|
|
32
|
+
variant: (props.variant ?? 'secondary') === 'secondary' ? 'muted' : void 0,
|
|
33
|
+
direction: isOpen ? 'up' : 'down',
|
|
34
|
+
size: 'zero' === size || 'xs' === size ? 'xs' : 'sm'
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const ChevronWrap = styled('div')`
|
|
41
|
+
display: flex;
|
|
42
|
+
align-items: center;
|
|
43
|
+
margin-left: auto;
|
|
44
|
+
padding-left: ${(p)=>p.theme.space.xs};
|
|
45
|
+
flex-shrink: 0;
|
|
46
|
+
`;
|
|
47
|
+
const StyledButton = styled(Button)`
|
|
48
|
+
position: relative;
|
|
49
|
+
max-width: 100%;
|
|
50
|
+
|
|
51
|
+
${(p)=>(p.isOpen || p.disabled) && css`
|
|
52
|
+
box-shadow: none;
|
|
53
|
+
`}
|
|
54
|
+
${(p)=>p.hasPrefix && css`
|
|
55
|
+
font-weight: ${p.theme.font.weight.sans.regular};
|
|
56
|
+
`}
|
|
57
|
+
`;
|
|
58
|
+
const LabelText = styled('span')`
|
|
59
|
+
&:after {
|
|
60
|
+
content: ':';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
font-weight: ${(p)=>p.theme.font.weight.sans.medium};
|
|
64
|
+
padding-right: ${(p)=>p.theme.space.sm};
|
|
65
|
+
`;
|
|
66
|
+
export { DropdownButton };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Shared presentation; consumers own state, keyboard behavior, and ARIA roles. */
|
|
2
|
+
export { calculateMenuMinHeight, MenuFooterLayout as Footer, MenuHeaderLayout as Header, MenuHeading as Title, MenuSectionLabel as SectionLabel, MenuSectionHeader as SectionHeader, MenuSectionGroup as SectionGroup, MenuSectionList as SectionList, MenuListItem as ListItem, ReserveLeadingSlot, MenuSectionSeparator as SectionSeparator, SearchInput as Search, useReserveLeadingSlot, } from './menu.js';
|
|
3
|
+
export type { ListItemProps, MenuItemTrailingAction } from './menu.js';
|
|
4
|
+
export { ControlContext } from './controlContext.js';
|
|
5
|
+
export { DropdownButton, type DropdownButtonProps } from './dropdownButton.js';
|
|
6
|
+
export type { SelectValue } from './selectValue.js';
|
|
7
|
+
export type * from './selectTypes.js';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { MenuFooterLayout as Footer, MenuHeaderLayout as Header, MenuHeading as Title, MenuListItem as ListItem, MenuSectionGroup as SectionGroup, MenuSectionHeader as SectionHeader, MenuSectionLabel as SectionLabel, MenuSectionList as SectionList, MenuSectionSeparator as SectionSeparator, ReserveLeadingSlot, SearchInput as Search, calculateMenuMinHeight, useReserveLeadingSlot } from "./menu.js";
|
|
2
|
+
export { ControlContext } from "./controlContext.js";
|
|
3
|
+
export { DropdownButton } from "./dropdownButton.js";
|