@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,24 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
export interface GroupContextValue {
|
|
3
|
+
'aria-invalid': boolean;
|
|
4
|
+
disabled: boolean;
|
|
5
|
+
isChecked: (value: string) => boolean;
|
|
6
|
+
name: string;
|
|
7
|
+
onChange: (value: string, checked: boolean) => void;
|
|
8
|
+
'aria-describedby'?: string;
|
|
9
|
+
onBlur?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function GroupProvider({ children, value, }: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
value: GroupContextValue;
|
|
14
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function useGroupContext(): GroupContextValue | null;
|
|
16
|
+
export declare function useGroupItemContext(value: string): {
|
|
17
|
+
checked: boolean;
|
|
18
|
+
'aria-invalid': boolean;
|
|
19
|
+
disabled: boolean;
|
|
20
|
+
name: string;
|
|
21
|
+
onChange: (value: string, checked: boolean) => void;
|
|
22
|
+
'aria-describedby'?: string;
|
|
23
|
+
onBlur?: () => void;
|
|
24
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const GroupContext = /*#__PURE__*/ createContext(null);
|
|
4
|
+
function GroupProvider({ children, value }) {
|
|
5
|
+
return /*#__PURE__*/ jsx(GroupContext, {
|
|
6
|
+
value: value,
|
|
7
|
+
children: children
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function useGroupContext() {
|
|
11
|
+
return useContext(GroupContext);
|
|
12
|
+
}
|
|
13
|
+
function useGroupItemContext(value) {
|
|
14
|
+
const context = useGroupContext();
|
|
15
|
+
if (!context) throw new Error('Group items must be used within a form field group');
|
|
16
|
+
const { isChecked, ...fieldProps } = context;
|
|
17
|
+
return {
|
|
18
|
+
...fieldProps,
|
|
19
|
+
checked: isChecked(value)
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export { GroupProvider, useGroupContext, useGroupItemContext };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const Spinner: import("@emotion/styled").StyledComponent<{
|
|
2
|
+
theme?: import("@emotion/react").Theme;
|
|
3
|
+
as?: React.ElementType;
|
|
4
|
+
}, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {}>;
|
|
5
|
+
export declare const Checkmark: import("@emotion/styled").StyledComponent<import("@sentry/icons/svgIcon").SVGIconProps & {
|
|
6
|
+
theme?: import("@emotion/react").Theme;
|
|
7
|
+
}, {}, {}>;
|
|
8
|
+
export declare const Warning: import("@emotion/styled").StyledComponent<import("@sentry/icons/svgIcon").SVGIconProps & {
|
|
9
|
+
theme?: import("@emotion/react").Theme;
|
|
10
|
+
}, {}, {}>;
|
|
11
|
+
export declare function RequiredIndicator(): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { keyframes } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
6
|
+
import { IconCheckmark } from "@sentry/icons/checkmark";
|
|
7
|
+
import { IconWarning } from "@sentry/icons/warning";
|
|
8
|
+
const fadeOut = keyframes`
|
|
9
|
+
0% { opacity: 1; }
|
|
10
|
+
100% { opacity: 0; }
|
|
11
|
+
`;
|
|
12
|
+
const pulse = keyframes`
|
|
13
|
+
0%, 100% { transform: scale(1, 1); }
|
|
14
|
+
50% { transform: scale(1.15, 1.15); }
|
|
15
|
+
`;
|
|
16
|
+
const spin = keyframes`
|
|
17
|
+
0% {
|
|
18
|
+
transform: rotate(0deg);
|
|
19
|
+
}
|
|
20
|
+
100% {
|
|
21
|
+
transform: rotate(360deg);
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
const Spinner = styled('div')`
|
|
25
|
+
animation: ${spin} 0.4s linear infinite;
|
|
26
|
+
width: 14px;
|
|
27
|
+
height: 14px;
|
|
28
|
+
border-radius: 50%;
|
|
29
|
+
border: 2px solid ${(p)=>p.theme.tokens.border.transparent.neutral.muted};
|
|
30
|
+
border-left-color: ${(p)=>p.theme.tokens.border.accent.vibrant};
|
|
31
|
+
margin-left: 0;
|
|
32
|
+
`;
|
|
33
|
+
const Checkmark = styled(IconCheckmark)`
|
|
34
|
+
animation: ${fadeOut} 0.3s ease 2s 1 forwards;
|
|
35
|
+
`;
|
|
36
|
+
const Warning = styled(IconWarning)`
|
|
37
|
+
animation: ${pulse} 1s ease infinite;
|
|
38
|
+
`;
|
|
39
|
+
const RequiredIndicatorBase = styled('div')`
|
|
40
|
+
display: inline-block;
|
|
41
|
+
background: ${(p)=>p.theme.colors.red400};
|
|
42
|
+
opacity: 0.6;
|
|
43
|
+
width: 5px;
|
|
44
|
+
height: 5px;
|
|
45
|
+
border-radius: 5px;
|
|
46
|
+
text-indent: -9999em;
|
|
47
|
+
vertical-align: super;
|
|
48
|
+
`;
|
|
49
|
+
function RequiredIndicator() {
|
|
50
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsx(RequiredIndicatorBase, {
|
|
53
|
+
"aria-hidden": true
|
|
54
|
+
}),
|
|
55
|
+
/*#__PURE__*/ jsx(VisuallyHidden, {
|
|
56
|
+
children: "(required)"
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export { Checkmark, RequiredIndicator, Spinner, Warning };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AutoSaveContextProvider, useAutoSaveContext } from './autoSaveContext.js';
|
|
2
|
+
export { DisplayField } from './displayField.js';
|
|
3
|
+
export { useFieldId, useHintTextId, useLabelId } from './fieldIds.js';
|
|
4
|
+
export { GroupProvider, useGroupItemContext, type GroupContextValue } from './groupContext.js';
|
|
5
|
+
export { FieldMeta } from './meta.js';
|
|
6
|
+
export { fieldContext, formContext, useFormContext, useFieldContext, FormElementContext, useIsInsideFormElement, } from './formContext.js';
|
|
7
|
+
export { Checkmark, Spinner } from './icons.js';
|
|
8
|
+
export { FieldLayout } from './fieldLayout.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AutoSaveContextProvider, useAutoSaveContext } from "./autoSaveContext.js";
|
|
2
|
+
export { DisplayField } from "./displayField.js";
|
|
3
|
+
export { useFieldId, useHintTextId, useLabelId } from "./fieldIds.js";
|
|
4
|
+
export { GroupProvider, useGroupItemContext } from "./groupContext.js";
|
|
5
|
+
export { FieldMeta } from "./meta.js";
|
|
6
|
+
export { FormElementContext, fieldContext, formContext, useFieldContext, useFormContext, useIsInsideFormElement } from "./formContext.js";
|
|
7
|
+
export { Checkmark, Spinner } from "./icons.js";
|
|
8
|
+
export { FieldLayout } from "./fieldLayout.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
declare function FieldStatus({ disabled, error }: {
|
|
3
|
+
disabled?: boolean | string;
|
|
4
|
+
error?: string;
|
|
5
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
6
|
+
export declare function FieldMeta(): null;
|
|
7
|
+
export declare namespace FieldMeta {
|
|
8
|
+
var Label: (props: {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
description?: React.ReactNode;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
13
|
+
var HintText: (props: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
16
|
+
var Status: typeof FieldStatus;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
3
|
+
import { DisabledTip, InfoText } from "../info/index.js";
|
|
4
|
+
import { Container, Flex } from "../layout/index.js";
|
|
5
|
+
import { Text } from "../text/index.js";
|
|
6
|
+
import { Tooltip } from "../tooltip/index.js";
|
|
7
|
+
import { useFieldId, useHintTextId, useLabelId } from "./fieldIds.js";
|
|
8
|
+
import { useFieldContext } from "./formContext.js";
|
|
9
|
+
import { useGroupContext } from "./groupContext.js";
|
|
10
|
+
import { RequiredIndicator, Warning } from "./icons.js";
|
|
11
|
+
function HintText(props) {
|
|
12
|
+
const id = useHintTextId();
|
|
13
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
14
|
+
width: "fit-content",
|
|
15
|
+
children: (containerProps)=>/*#__PURE__*/ jsx(Text, {
|
|
16
|
+
...containerProps,
|
|
17
|
+
size: "sm",
|
|
18
|
+
variant: "muted",
|
|
19
|
+
id: id,
|
|
20
|
+
children: props.children
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function Label(props) {
|
|
25
|
+
const fieldId = useFieldId();
|
|
26
|
+
const hintTextId = useHintTextId();
|
|
27
|
+
const labelId = useLabelId();
|
|
28
|
+
const isGroup = useGroupContext();
|
|
29
|
+
const labelContent = props.description ? /*#__PURE__*/ jsx(InfoText, {
|
|
30
|
+
title: props.description,
|
|
31
|
+
children: props.children
|
|
32
|
+
}) : props.children;
|
|
33
|
+
const labelProps = isGroup ? {
|
|
34
|
+
as: 'span',
|
|
35
|
+
cursor: 'default',
|
|
36
|
+
id: labelId
|
|
37
|
+
} : {
|
|
38
|
+
as: 'label',
|
|
39
|
+
htmlFor: fieldId,
|
|
40
|
+
id: labelId
|
|
41
|
+
};
|
|
42
|
+
return /*#__PURE__*/ jsx(Container, {
|
|
43
|
+
width: "fit-content",
|
|
44
|
+
children: (containerProps)=>/*#__PURE__*/ jsxs(Flex, {
|
|
45
|
+
gap: "xs",
|
|
46
|
+
children: [
|
|
47
|
+
/*#__PURE__*/ jsx(Text, {
|
|
48
|
+
...containerProps,
|
|
49
|
+
...labelProps,
|
|
50
|
+
bold: false,
|
|
51
|
+
children: labelContent
|
|
52
|
+
}),
|
|
53
|
+
props.required ? /*#__PURE__*/ jsx(RequiredIndicator, {}) : null,
|
|
54
|
+
props.description ? /*#__PURE__*/ jsx(VisuallyHidden, {
|
|
55
|
+
id: hintTextId,
|
|
56
|
+
children: props.description
|
|
57
|
+
}) : null
|
|
58
|
+
]
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function FieldStatus({ disabled, error }) {
|
|
63
|
+
const field = useFieldContext();
|
|
64
|
+
const errorMessage = error ?? (field.state.meta.isValid ? void 0 : field.state.meta.errors.map((e)=>e?.message).join(','));
|
|
65
|
+
if (errorMessage) return /*#__PURE__*/ jsx(Tooltip, {
|
|
66
|
+
position: "bottom",
|
|
67
|
+
title: errorMessage,
|
|
68
|
+
forceVisible: true,
|
|
69
|
+
skipWrapper: true,
|
|
70
|
+
children: /*#__PURE__*/ jsx(Warning, {
|
|
71
|
+
variant: "danger",
|
|
72
|
+
size: "sm"
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
const disabledReason = 'string' == typeof disabled ? disabled : void 0;
|
|
76
|
+
if (disabledReason) return /*#__PURE__*/ jsx(DisabledTip, {
|
|
77
|
+
title: disabledReason,
|
|
78
|
+
size: "sm"
|
|
79
|
+
});
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
function FieldMeta() {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
FieldMeta.Label = Label;
|
|
86
|
+
FieldMeta.HintText = HintText;
|
|
87
|
+
FieldMeta.Status = FieldStatus;
|
|
88
|
+
export { FieldMeta };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useStackedLayout(): boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { useHasContainerQuery, useResponsivePropValue } from "../layout/index.js";
|
|
2
|
+
function useStackedLayout() {
|
|
3
|
+
const isStackAtBreakpoint = useResponsivePropValue({
|
|
4
|
+
zero: true,
|
|
5
|
+
md: false
|
|
6
|
+
});
|
|
7
|
+
return useHasContainerQuery() && isStackAtBreakpoint;
|
|
8
|
+
}
|
|
9
|
+
export { useStackedLayout };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Input, type InputProps, type InputStylesProps } from './input.js';
|
|
2
|
+
export { InputGroup } from './inputGroup.js';
|
|
3
|
+
/** @public */
|
|
4
|
+
export { NumberDragInput } from './numberDragInput.js';
|
|
5
|
+
export { NumberInput } from './numberInput.js';
|
|
6
|
+
/** @public */
|
|
7
|
+
export { OTPInput, type OTPInputProps } from './otpInput.js';
|
|
8
|
+
export { useAutosizeInput } from './useAutosizeInput.js';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Input } from "./input.js";
|
|
2
|
+
export { InputGroup } from "./inputGroup.js";
|
|
3
|
+
export { NumberDragInput } from "./numberDragInput.js";
|
|
4
|
+
export { NumberInput } from "./numberInput.js";
|
|
5
|
+
export { OTPInput } from "./otpInput.js";
|
|
6
|
+
export { useAutosizeInput } from "./useAutosizeInput.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type InputStylesProps } from './inputStyles.js';
|
|
3
|
+
export { type InputStylesProps } from './inputStyles.js';
|
|
4
|
+
export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'readOnly'>, InputStylesProps {
|
|
5
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Basic input component.
|
|
9
|
+
*
|
|
10
|
+
* Use the `size` prop ('md', 'sm', 'xs') to control the input's height &
|
|
11
|
+
* padding. To use the native size attribute (which controls the number of
|
|
12
|
+
* characters the input should fit), use the `nativeSize` prop instead.
|
|
13
|
+
*
|
|
14
|
+
* To add leading/trailing items (e.g. a search icon on the left side), use
|
|
15
|
+
* InputControl (components/inputControl) instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare const Input: import("@emotion/styled").StyledComponent<InputProps & {
|
|
18
|
+
theme?: import("@emotion/react").Theme;
|
|
19
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { inputStyles } from "./inputStyles.js";
|
|
5
|
+
const Input = styled(({ ref, size: _size, nativeSize, ...props })=>/*#__PURE__*/ jsx("input", {
|
|
6
|
+
...props,
|
|
7
|
+
ref: ref,
|
|
8
|
+
size: nativeSize
|
|
9
|
+
}), {
|
|
10
|
+
shouldForwardProp: (prop)=>'nativeSize' === prop || is_prop_valid(prop)
|
|
11
|
+
})`
|
|
12
|
+
${(p)=>inputStyles(p)};
|
|
13
|
+
`;
|
|
14
|
+
export { Input };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { InputProps } from './index.js';
|
|
3
|
+
import { type TextAreaProps } from '../textarea/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Wrapper for input group. To be used alongisde `Input`, `InputGroup.LeadingItems`,
|
|
6
|
+
* and `InputGroup.TrailingItems`:
|
|
7
|
+
* <InputGroup>
|
|
8
|
+
* <InputGroup.LeadingItems> … </InputGroup.LeadingItems>
|
|
9
|
+
* <Input />
|
|
10
|
+
* <InputGroup.TrailingItems> … </InputGroup.TrailingItems>
|
|
11
|
+
* </InputGroup>
|
|
12
|
+
*/
|
|
13
|
+
export declare function InputGroup({ children, ...props }: React.HTMLAttributes<HTMLDivElement>): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare namespace InputGroup {
|
|
15
|
+
var Input: ({ ref, size, disabled, ...props }: InputProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
16
|
+
var TextArea: ({ ref, size, disabled, ...props }: TextAreaProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
17
|
+
var LeadingItems: ({ children, disablePointerEvents, ...props }: InputItemsProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
18
|
+
var TrailingItems: ({ children, disablePointerEvents, ...props }: InputItemsProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
19
|
+
}
|
|
20
|
+
interface InputItemsProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
21
|
+
/**
|
|
22
|
+
* Whether to disable pointer events on the leading/trailing item wrap. This
|
|
23
|
+
* should be set to true when none of the items inside the wrap are
|
|
24
|
+
* interactive (e.g. a leading search icon). That way, mouse clicks will
|
|
25
|
+
* fall through to the `Input` underneath and trigger a focus event.
|
|
26
|
+
*/
|
|
27
|
+
disablePointerEvents?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useLayoutEffect, useMemo, useState } from "react";
|
|
3
|
+
import { css } from "@emotion/react";
|
|
4
|
+
import styled from "@emotion/styled";
|
|
5
|
+
import { TextArea } from "../textarea/index.js";
|
|
6
|
+
import { Input } from "./input.js";
|
|
7
|
+
const InputItemsWrap = styled('div')`
|
|
8
|
+
display: grid;
|
|
9
|
+
grid-auto-flow: column;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: ${(p)=>p.theme.space.md};
|
|
12
|
+
|
|
13
|
+
/* Do not use transform here to do alignment as it will create a new stacking
|
|
14
|
+
* context, breaking things like dropdown menus */
|
|
15
|
+
position: absolute;
|
|
16
|
+
top: 0;
|
|
17
|
+
bottom: 0;
|
|
18
|
+
`;
|
|
19
|
+
const itemsPadding = {
|
|
20
|
+
md: 8,
|
|
21
|
+
sm: 6,
|
|
22
|
+
xs: 4
|
|
23
|
+
};
|
|
24
|
+
const inputStyles = ({ leadingWidth, trailingWidth, size = 'md', theme })=>({
|
|
25
|
+
...leadingWidth && {
|
|
26
|
+
paddingLeft: `calc(${theme.form[size].paddingLeft}px + ${itemsPadding[size]}px + ${leadingWidth}px)`
|
|
27
|
+
},
|
|
28
|
+
...trailingWidth && {
|
|
29
|
+
paddingRight: `calc(${theme.form[size].paddingRight}px + ${itemsPadding[size]}px + ${trailingWidth}px)`
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const StyledInput = styled(Input)`
|
|
33
|
+
${inputStyles}
|
|
34
|
+
`;
|
|
35
|
+
const StyledTextArea = styled(TextArea)`
|
|
36
|
+
${inputStyles}
|
|
37
|
+
`;
|
|
38
|
+
const StyledLeadingItemsWrap = styled(InputItemsWrap)`
|
|
39
|
+
left: ${(p)=>p.theme.form[p.size].paddingLeft + 1}px;
|
|
40
|
+
${(p)=>p.disablePointerEvents && 'pointer-events: none;'}
|
|
41
|
+
`;
|
|
42
|
+
const StyledTrailingItemsWrap = styled(InputItemsWrap)`
|
|
43
|
+
right: ${(p)=>p.theme.form[p.size].paddingRight + 1}px;
|
|
44
|
+
${(p)=>p.disablePointerEvents && 'pointer-events: none;'}
|
|
45
|
+
`;
|
|
46
|
+
const InputGroupContext = /*#__PURE__*/ createContext({
|
|
47
|
+
inputProps: {}
|
|
48
|
+
});
|
|
49
|
+
function InputGroup({ children, ...props }) {
|
|
50
|
+
const [leadingWidth, setLeadingWidth] = useState();
|
|
51
|
+
const [trailingWidth, setTrailingWidth] = useState();
|
|
52
|
+
const [inputProps, setInputProps] = useState({});
|
|
53
|
+
const contextValue = useMemo(()=>({
|
|
54
|
+
inputProps,
|
|
55
|
+
setInputProps,
|
|
56
|
+
leadingWidth,
|
|
57
|
+
setLeadingWidth,
|
|
58
|
+
trailingWidth,
|
|
59
|
+
setTrailingWidth
|
|
60
|
+
}), [
|
|
61
|
+
inputProps,
|
|
62
|
+
leadingWidth,
|
|
63
|
+
trailingWidth
|
|
64
|
+
]);
|
|
65
|
+
return /*#__PURE__*/ jsx(InputGroupContext, {
|
|
66
|
+
value: contextValue,
|
|
67
|
+
children: /*#__PURE__*/ jsx(InputGroupWrap, {
|
|
68
|
+
disabled: inputProps.disabled,
|
|
69
|
+
...props,
|
|
70
|
+
children: children
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function inputGroup_Input({ ref, size, disabled, ...props }) {
|
|
75
|
+
const { leadingWidth, trailingWidth, setInputProps } = useContext(InputGroupContext);
|
|
76
|
+
useLayoutEffect(()=>{
|
|
77
|
+
setInputProps?.({
|
|
78
|
+
size,
|
|
79
|
+
disabled
|
|
80
|
+
});
|
|
81
|
+
}, [
|
|
82
|
+
size,
|
|
83
|
+
disabled,
|
|
84
|
+
setInputProps
|
|
85
|
+
]);
|
|
86
|
+
return /*#__PURE__*/ jsx(StyledInput, {
|
|
87
|
+
ref: ref,
|
|
88
|
+
leadingWidth: leadingWidth,
|
|
89
|
+
trailingWidth: trailingWidth,
|
|
90
|
+
size: size,
|
|
91
|
+
disabled: disabled,
|
|
92
|
+
...props
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function inputGroup_TextArea({ ref, size, disabled, ...props }) {
|
|
96
|
+
const { leadingWidth, trailingWidth, setInputProps } = useContext(InputGroupContext);
|
|
97
|
+
useLayoutEffect(()=>{
|
|
98
|
+
setInputProps?.({
|
|
99
|
+
size,
|
|
100
|
+
disabled
|
|
101
|
+
});
|
|
102
|
+
}, [
|
|
103
|
+
size,
|
|
104
|
+
disabled,
|
|
105
|
+
setInputProps
|
|
106
|
+
]);
|
|
107
|
+
return /*#__PURE__*/ jsx(StyledTextArea, {
|
|
108
|
+
ref: ref,
|
|
109
|
+
leadingWidth: leadingWidth,
|
|
110
|
+
trailingWidth: trailingWidth,
|
|
111
|
+
size: size,
|
|
112
|
+
disabled: disabled,
|
|
113
|
+
...props
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function useInputItemsWidthRef(setWidth) {
|
|
117
|
+
return useCallback((node)=>{
|
|
118
|
+
if (!node || !setWidth) return;
|
|
119
|
+
const updateWidth = ()=>{
|
|
120
|
+
setWidth(node.offsetWidth);
|
|
121
|
+
};
|
|
122
|
+
updateWidth();
|
|
123
|
+
const observer = new ResizeObserver(updateWidth);
|
|
124
|
+
observer.observe(node);
|
|
125
|
+
return ()=>{
|
|
126
|
+
observer.disconnect();
|
|
127
|
+
setWidth(void 0);
|
|
128
|
+
};
|
|
129
|
+
}, [
|
|
130
|
+
setWidth
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
function LeadingItems({ children, disablePointerEvents, ...props }) {
|
|
134
|
+
const { inputProps: { size = 'md', disabled }, setLeadingWidth } = useContext(InputGroupContext);
|
|
135
|
+
const ref = useInputItemsWidthRef(setLeadingWidth);
|
|
136
|
+
return /*#__PURE__*/ jsx(StyledLeadingItemsWrap, {
|
|
137
|
+
ref: ref,
|
|
138
|
+
size: size,
|
|
139
|
+
disablePointerEvents: disabled || disablePointerEvents,
|
|
140
|
+
"data-test-id": "input-leading-items",
|
|
141
|
+
...props,
|
|
142
|
+
children: children
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function TrailingItems({ children, disablePointerEvents, ...props }) {
|
|
146
|
+
const { inputProps: { size = 'md', disabled }, setTrailingWidth } = useContext(InputGroupContext);
|
|
147
|
+
const ref = useInputItemsWidthRef(setTrailingWidth);
|
|
148
|
+
return /*#__PURE__*/ jsx(StyledTrailingItemsWrap, {
|
|
149
|
+
ref: ref,
|
|
150
|
+
size: size,
|
|
151
|
+
disablePointerEvents: disabled || disablePointerEvents,
|
|
152
|
+
"data-test-id": "input-trailing-items",
|
|
153
|
+
...props,
|
|
154
|
+
children: children
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
InputGroup.Input = inputGroup_Input;
|
|
158
|
+
InputGroup.TextArea = inputGroup_TextArea;
|
|
159
|
+
InputGroup.LeadingItems = LeadingItems;
|
|
160
|
+
InputGroup.TrailingItems = TrailingItems;
|
|
161
|
+
const InputGroupWrap = styled('div')`
|
|
162
|
+
position: relative;
|
|
163
|
+
${(p)=>p.disabled && css`
|
|
164
|
+
color: ${p.theme.tokens.content.disabled};
|
|
165
|
+
`}
|
|
166
|
+
`;
|
|
167
|
+
export { InputGroup };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type Theme } from '@emotion/react';
|
|
3
|
+
import { type FormSize, type StrictCSSObject } from '../theme/index.js';
|
|
4
|
+
export interface InputStylesProps {
|
|
5
|
+
monospace?: boolean;
|
|
6
|
+
nativeSize?: React.InputHTMLAttributes<HTMLInputElement>['size'];
|
|
7
|
+
readOnly?: React.InputHTMLAttributes<HTMLInputElement>['readOnly'];
|
|
8
|
+
size?: FormSize;
|
|
9
|
+
type?: React.HTMLInputTypeAttribute;
|
|
10
|
+
}
|
|
11
|
+
export declare const inputStyles: ({ theme, monospace, readOnly, size, }: InputStylesProps & {
|
|
12
|
+
theme: Theme;
|
|
13
|
+
}) => StrictCSSObject;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const inputStyles = ({ theme, monospace, readOnly, size = 'md' })=>{
|
|
2
|
+
const boxShadow = `0px 1px 0px 0px ${theme.tokens.interactive.chonky.debossed.neutral.chonk} inset`;
|
|
3
|
+
return {
|
|
4
|
+
display: 'block',
|
|
5
|
+
width: '100%',
|
|
6
|
+
color: theme.tokens.content.primary,
|
|
7
|
+
backgroundColor: theme.tokens.interactive.chonky.debossed.neutral.background,
|
|
8
|
+
boxShadow,
|
|
9
|
+
border: `1px solid ${theme.tokens.border.primary}`,
|
|
10
|
+
fontFamily: theme.font.family[monospace ? 'mono' : 'sans'],
|
|
11
|
+
fontWeight: theme.font.weight[monospace ? 'mono' : 'sans'].regular,
|
|
12
|
+
resize: 'vertical',
|
|
13
|
+
transition: `border ${theme.motion.smooth.fast}, box-shadow ${theme.motion.smooth.fast}`,
|
|
14
|
+
...readOnly ? {
|
|
15
|
+
cursor: 'default'
|
|
16
|
+
} : {},
|
|
17
|
+
fontSize: theme.form[size].fontSize,
|
|
18
|
+
height: theme.form[size].height,
|
|
19
|
+
lineHeight: theme.form[size].lineHeight,
|
|
20
|
+
minHeight: theme.form[size].minHeight,
|
|
21
|
+
paddingBottom: theme.form[size].paddingBottom,
|
|
22
|
+
paddingLeft: theme.form[size].paddingLeft,
|
|
23
|
+
paddingRight: theme.form[size].paddingRight,
|
|
24
|
+
paddingTop: theme.form[size].paddingTop,
|
|
25
|
+
borderRadius: theme.form[size].borderRadius,
|
|
26
|
+
'&::placeholder': {
|
|
27
|
+
color: theme.tokens.content.secondary,
|
|
28
|
+
opacity: 1
|
|
29
|
+
},
|
|
30
|
+
"&[disabled], &[aria-disabled='true']": {
|
|
31
|
+
color: theme.tokens.content.disabled,
|
|
32
|
+
cursor: 'not-allowed',
|
|
33
|
+
opacity: '60%',
|
|
34
|
+
'&::placeholder': {
|
|
35
|
+
color: theme.tokens.content.disabled
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
'&:focus, &:focus-visible, :focus-within': {
|
|
39
|
+
...theme.focusRing(boxShadow)
|
|
40
|
+
},
|
|
41
|
+
"&[type='number']": {
|
|
42
|
+
appearance: 'textfield',
|
|
43
|
+
MozAppearance: 'textfield',
|
|
44
|
+
fontVariantNumeric: 'tabular-nums'
|
|
45
|
+
},
|
|
46
|
+
'&::-webkit-outer-spin-button, &::-webkit-inner-spin-button': {
|
|
47
|
+
WebkitAppearance: 'none',
|
|
48
|
+
margin: 0
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export { inputStyles };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { InputProps } from './input.js';
|
|
2
|
+
export interface NumberDragInput extends Omit<InputProps, 'type' | 'onPointerMove'> {
|
|
3
|
+
/**
|
|
4
|
+
* Determines the axis of the drag input. Defaults to `x`
|
|
5
|
+
*/
|
|
6
|
+
axis?: 'x' | 'y';
|
|
7
|
+
/**
|
|
8
|
+
* The maximum value of the input (inclusive)
|
|
9
|
+
*/
|
|
10
|
+
max?: number;
|
|
11
|
+
/**
|
|
12
|
+
* The minimum value of the input (inclusive)
|
|
13
|
+
*/
|
|
14
|
+
min?: number;
|
|
15
|
+
/**
|
|
16
|
+
* The multiplier for the value when the shift key is held down
|
|
17
|
+
*/
|
|
18
|
+
shiftKeyMultiplier?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function NumberDragInput({ axis, shiftKeyMultiplier, ...props }: NumberDragInput): import("@emotion/react/jsx-runtime").JSX.Element;
|