@sentry/scraps 0.1.0 → 0.2.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/README.md +13 -21
- package/dist/alert/alert.d.ts +25 -0
- package/dist/alert/alert.js +262 -0
- package/dist/alert/alertLink.d.ts +32 -0
- package/dist/alert/alertLink.js +94 -0
- package/dist/alert/index.d.ts +2 -0
- package/dist/alert/index.js +2 -0
- package/dist/backdrop/backdrop.d.ts +9 -0
- package/dist/backdrop/backdrop.js +28 -0
- package/dist/backdrop/index.d.ts +1 -0
- package/dist/backdrop/index.js +1 -0
- package/dist/badge/badge.d.ts +12 -0
- package/dist/badge/badge.js +80 -0
- package/dist/badge/featureBadge.d.ts +6 -0
- package/dist/badge/featureBadge.js +86 -0
- package/dist/badge/index.d.ts +3 -0
- package/dist/badge/index.js +3 -0
- package/dist/badge/tag.d.ts +15 -0
- package/dist/badge/tag.js +119 -0
- package/dist/boundaryContext.d.ts +2 -0
- package/dist/boundaryContext.js +5 -0
- package/dist/button/button.d.ts +3 -0
- package/dist/button/button.js +83 -0
- package/dist/button/buttonBar.d.ts +10 -0
- package/dist/button/buttonBar.js +135 -0
- package/dist/button/index.d.ts +5 -0
- package/dist/button/index.js +4 -0
- package/dist/button/linkButton.d.ts +3 -0
- package/dist/button/linkButton.js +110 -0
- package/dist/button/styles.d.ts +10 -0
- package/dist/button/styles.js +247 -0
- package/dist/button/types.d.ts +77 -0
- package/dist/button/types.js +0 -0
- package/dist/button/useButtonFunctionality.d.ts +5 -0
- package/dist/button/useButtonFunctionality.js +9 -0
- package/dist/checkbox/checkbox.d.ts +20 -0
- package/dist/checkbox/checkbox.js +193 -0
- package/dist/checkbox/index.d.ts +1 -0
- package/dist/checkbox/index.js +1 -0
- package/dist/chip/chip.d.ts +128 -0
- package/dist/chip/chip.js +364 -0
- package/dist/chip/index.d.ts +1 -0
- package/dist/chip/index.js +1 -0
- package/dist/code/inlineCode.d.ts +1 -0
- package/dist/datetime.d.ts +39 -0
- package/dist/datetime.js +20 -0
- package/dist/descriptionList/descriptionList.d.ts +69 -0
- package/dist/descriptionList/descriptionList.js +76 -0
- package/dist/descriptionList/index.d.ts +1 -0
- package/dist/descriptionList/index.js +1 -0
- package/dist/disclosure/disclosure.d.ts +37 -0
- package/dist/disclosure/disclosure.js +155 -0
- package/dist/disclosure/index.d.ts +1 -0
- package/dist/disclosure/index.js +1 -0
- package/dist/emptyState/emptyState.d.ts +10 -0
- package/dist/emptyState/emptyState.js +81 -0
- package/dist/emptyState/index.d.ts +1 -0
- package/dist/emptyState/index.js +1 -0
- package/dist/hotkey/hotkey.d.ts +22 -0
- package/dist/hotkey/hotkey.js +41 -0
- package/dist/hotkey/index.d.ts +4 -0
- package/dist/hotkey/index.js +3 -0
- package/dist/hotkey/kbd.d.ts +1 -0
- package/dist/hotkey/keyMappings.d.ts +23 -0
- package/dist/hotkey/keyMappings.js +223 -0
- package/dist/hotkey/useHotkeys.d.ts +47 -0
- package/dist/hotkey/useHotkeys.js +44 -0
- package/dist/image/image.d.ts +21 -0
- package/dist/image/image.js +20 -0
- package/dist/image/index.d.ts +1 -0
- package/dist/image/index.js +1 -0
- package/dist/info/index.d.ts +2 -0
- package/dist/info/index.js +2 -0
- package/dist/info/infoText.d.ts +15 -0
- package/dist/info/infoText.js +43 -0
- package/dist/info/infoTip.d.ts +10 -0
- package/dist/info/infoTip.js +54 -0
- package/dist/interactionStateLayer/index.d.ts +1 -0
- package/dist/interactionStateLayer/index.js +1 -0
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +23 -0
- package/dist/interactionStateLayer/interactionStateLayer.js +67 -0
- package/dist/layout/flex.d.ts +1 -0
- package/dist/layout/grid.d.ts +1 -0
- package/dist/layout/index.d.ts +1 -1
- package/dist/layout/index.js +1 -1
- package/dist/layout/stack.d.ts +1 -0
- package/dist/layout/styles.d.ts +1 -1
- package/dist/layout/surface.d.ts +1 -0
- package/dist/link/index.d.ts +2 -0
- package/dist/link/index.js +2 -0
- package/dist/link/link.d.ts +43 -0
- package/dist/link/link.js +71 -0
- package/dist/link/linkBehaviorContext.d.ts +14 -0
- package/dist/link/linkBehaviorContext.js +31 -0
- package/dist/loader/indeterminateLoader.d.ts +1 -0
- package/dist/overlay.d.ts +59 -0
- package/dist/overlay.js +113 -0
- package/dist/overlayArrow.d.ts +9 -0
- package/dist/overlayArrow.js +55 -0
- package/dist/overlayPositioning.d.ts +61 -0
- package/dist/overlayPositioning.js +126 -0
- package/dist/panelProvider.d.ts +8 -0
- package/dist/panelProvider.js +20 -0
- package/dist/quote/quote.js +1 -1
- package/dist/radio/index.d.ts +1 -0
- package/dist/radio/index.js +1 -0
- package/dist/radio/radio.d.ts +9 -0
- package/dist/radio/radio.js +77 -0
- package/dist/renderToString.d.ts +2 -0
- package/dist/renderToString.js +25 -0
- package/dist/revealOnHover/index.d.ts +1 -0
- package/dist/revealOnHover/index.js +1 -0
- package/dist/revealOnHover/revealOnHover.d.ts +20 -0
- package/dist/revealOnHover/revealOnHover.js +62 -0
- package/dist/segmentedControl/index.d.ts +1 -0
- package/dist/segmentedControl/index.js +1 -0
- package/dist/segmentedControl/segmentedControl.d.ts +41 -0
- package/dist/segmentedControl/segmentedControl.js +217 -0
- package/dist/separator/separator.d.ts +4 -3
- package/dist/separator/separator.js +1 -1
- package/dist/sizeContext.d.ts +9 -0
- package/dist/sizeContext.js +13 -0
- package/dist/slider/index.d.ts +1 -0
- package/dist/slider/index.js +1 -0
- package/dist/slider/slider.d.ts +41 -0
- package/dist/slider/slider.js +386 -0
- package/dist/slot/index.d.ts +1 -0
- package/dist/slot/index.js +1 -0
- package/dist/slot/knownContexts.d.ts +1 -0
- package/dist/slot/knownContexts.js +7 -0
- package/dist/slot/slot.d.ts +26 -0
- package/dist/slot/slot.js +274 -0
- package/dist/statusIndicator/index.d.ts +1 -0
- package/dist/statusIndicator/index.js +1 -0
- package/dist/statusIndicator/statusIndicator.d.ts +24 -0
- package/dist/statusIndicator/statusIndicator.js +130 -0
- package/dist/switch/index.d.ts +1 -0
- package/dist/switch/index.js +1 -0
- package/dist/switch/switch.d.ts +6 -0
- package/dist/switch/switch.js +172 -0
- package/dist/text/heading.d.ts +1 -0
- package/dist/text/index.d.ts +1 -0
- package/dist/text/index.js +1 -0
- package/dist/text/prose.d.ts +8 -0
- package/dist/text/prose.js +45 -0
- package/dist/text/text.d.ts +1 -0
- package/dist/theme/dark.d.ts +129 -10
- package/dist/theme/dark.js +41 -13
- package/dist/theme/index.d.ts +3 -12
- package/dist/theme/index.js +2 -2
- package/dist/theme/light.d.ts +129 -10
- package/dist/theme/light.js +42 -14
- package/dist/theme/swatch.d.ts +27 -0
- package/dist/theme/swatch.js +37 -0
- package/dist/theme/theme.d.ts +648 -0
- package/dist/theme/theme.js +780 -0
- package/dist/theme/types.d.ts +1 -0
- package/dist/theme/useInvertedTheme.d.ts +1 -0
- package/dist/theme/useInvertedTheme.js +7 -0
- package/dist/tooltip/index.d.ts +2 -0
- package/dist/tooltip/index.js +2 -0
- package/dist/tooltip/tooltip.d.ts +166 -0
- package/dist/tooltip/tooltip.js +181 -0
- package/dist/tooltip/useDisabledTooltip.d.ts +22 -0
- package/dist/tooltip/useDisabledTooltip.js +24 -0
- package/dist/trackingContext.d.ts +34 -0
- package/dist/trackingContext.js +29 -0
- package/dist/translation/index.d.ts +4 -0
- package/dist/translation/index.js +4 -0
- package/dist/translation/translationContext.d.ts +6 -0
- package/dist/translation/translationContext.js +6 -0
- package/dist/translation/useTranslation.d.ts +1 -0
- package/dist/translation/useTranslation.js +6 -0
- package/dist/unreachable.d.ts +1 -0
- package/dist/unreachable.js +4 -0
- package/dist/useHoverOverlay.d.ts +113 -0
- package/dist/useHoverOverlay.js +370 -0
- package/dist/useIsInsideInteractiveElement.d.ts +6 -0
- package/dist/useIsInsideInteractiveElement.js +31 -0
- package/dist/useOverlay.d.ts +82 -0
- package/dist/useOverlay.js +216 -0
- package/dist/useScrollLock.d.ts +5 -0
- package/dist/useScrollLock.js +100 -0
- package/dist/useStableMergeRef.d.ts +9 -0
- package/dist/useStableMergeRef.js +18 -0
- package/package.json +193 -11
- package/dist/index.d.ts +0 -9
- package/dist/index.js +0 -9
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { mergeProps } from "@react-aria/utils";
|
|
5
|
+
import { IconClose } from "@sentry/icons/close";
|
|
6
|
+
import { Button } from "../button/index.js";
|
|
7
|
+
import { Flex } from "../layout/index.js";
|
|
8
|
+
import { Text } from "../text/index.js";
|
|
9
|
+
import { useTranslation } from "../translation/useTranslation.js";
|
|
10
|
+
const SIZES = {
|
|
11
|
+
xs: {
|
|
12
|
+
height: '20px',
|
|
13
|
+
radius: '2xs',
|
|
14
|
+
pad: 'xs',
|
|
15
|
+
font: 'sm',
|
|
16
|
+
dismiss: '20px'
|
|
17
|
+
},
|
|
18
|
+
sm: {
|
|
19
|
+
height: '24px',
|
|
20
|
+
radius: 'xs',
|
|
21
|
+
pad: 'sm',
|
|
22
|
+
font: 'md',
|
|
23
|
+
dismiss: '20px'
|
|
24
|
+
},
|
|
25
|
+
md: {
|
|
26
|
+
height: '28px',
|
|
27
|
+
radius: 'sm',
|
|
28
|
+
pad: 'md',
|
|
29
|
+
font: 'md',
|
|
30
|
+
dismiss: '24px'
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const SEGMENT_ATTR = 'data-chip-segment';
|
|
34
|
+
const ChipContext = /*#__PURE__*/ createContext(null);
|
|
35
|
+
function useChipContext(component) {
|
|
36
|
+
const context = useContext(ChipContext);
|
|
37
|
+
if (!context) throw new Error(`${component} must be rendered inside <Chip.Root>`);
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
function useRovingController(enabled, rootRef) {
|
|
41
|
+
const idsRef = useRef([]);
|
|
42
|
+
const [activeId, setActiveId] = useState(null);
|
|
43
|
+
const register = useCallback((id)=>{
|
|
44
|
+
if (!idsRef.current.includes(id)) idsRef.current = [
|
|
45
|
+
...idsRef.current,
|
|
46
|
+
id
|
|
47
|
+
];
|
|
48
|
+
setActiveId((current)=>current ?? id);
|
|
49
|
+
return ()=>{
|
|
50
|
+
idsRef.current = idsRef.current.filter((existing)=>existing !== id);
|
|
51
|
+
setActiveId((current)=>current === id ? idsRef.current[0] ?? null : current);
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
const onItemKeyDown = useCallback((event)=>{
|
|
55
|
+
const root = rootRef.current;
|
|
56
|
+
if (!root) return;
|
|
57
|
+
const items = Array.from(root.querySelectorAll(`[${SEGMENT_ATTR}]`));
|
|
58
|
+
const currentIndex = items.indexOf(event.currentTarget);
|
|
59
|
+
if (-1 === currentIndex) return;
|
|
60
|
+
let nextIndex = -1;
|
|
61
|
+
switch(event.key){
|
|
62
|
+
case 'ArrowRight':
|
|
63
|
+
nextIndex = (currentIndex + 1) % items.length;
|
|
64
|
+
break;
|
|
65
|
+
case 'ArrowLeft':
|
|
66
|
+
nextIndex = (currentIndex - 1 + items.length) % items.length;
|
|
67
|
+
break;
|
|
68
|
+
case 'Home':
|
|
69
|
+
nextIndex = 0;
|
|
70
|
+
break;
|
|
71
|
+
case 'End':
|
|
72
|
+
nextIndex = items.length - 1;
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
event.preventDefault();
|
|
78
|
+
items[nextIndex]?.focus();
|
|
79
|
+
}, [
|
|
80
|
+
rootRef
|
|
81
|
+
]);
|
|
82
|
+
const getItemProps = useCallback((id)=>({
|
|
83
|
+
[SEGMENT_ATTR]: '',
|
|
84
|
+
tabIndex: activeId === id ? 0 : -1,
|
|
85
|
+
onFocus: ()=>setActiveId(id),
|
|
86
|
+
onKeyDown: onItemKeyDown
|
|
87
|
+
}), [
|
|
88
|
+
activeId,
|
|
89
|
+
onItemKeyDown
|
|
90
|
+
]);
|
|
91
|
+
return useMemo(()=>({
|
|
92
|
+
enabled,
|
|
93
|
+
activeId,
|
|
94
|
+
register,
|
|
95
|
+
getItemProps
|
|
96
|
+
}), [
|
|
97
|
+
enabled,
|
|
98
|
+
activeId,
|
|
99
|
+
register,
|
|
100
|
+
getItemProps
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
function useChipSegment(interactive) {
|
|
104
|
+
const { roving } = useChipContext('Chip section');
|
|
105
|
+
const { enabled, register, getItemProps } = roving;
|
|
106
|
+
const id = useId();
|
|
107
|
+
const active = interactive && enabled;
|
|
108
|
+
useEffect(()=>{
|
|
109
|
+
if (active) return register(id);
|
|
110
|
+
}, [
|
|
111
|
+
active,
|
|
112
|
+
id,
|
|
113
|
+
register
|
|
114
|
+
]);
|
|
115
|
+
return active ? getItemProps(id) : {};
|
|
116
|
+
}
|
|
117
|
+
function ChipRoot({ size = 'md', readonly = false, children, ...rest }) {
|
|
118
|
+
const rootRef = useRef(null);
|
|
119
|
+
const roving = useRovingController(!readonly, rootRef);
|
|
120
|
+
const context = useMemo(()=>({
|
|
121
|
+
size,
|
|
122
|
+
readonly,
|
|
123
|
+
roving
|
|
124
|
+
}), [
|
|
125
|
+
size,
|
|
126
|
+
readonly,
|
|
127
|
+
roving
|
|
128
|
+
]);
|
|
129
|
+
return /*#__PURE__*/ jsx(ChipContext.Provider, {
|
|
130
|
+
value: context,
|
|
131
|
+
children: /*#__PURE__*/ jsx(ChipRootElement, {
|
|
132
|
+
ref: rootRef,
|
|
133
|
+
chipSize: size,
|
|
134
|
+
...rest,
|
|
135
|
+
children: children
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function resolveTone(tone, readonly) {
|
|
140
|
+
if ('operator' === tone) return 'secondary';
|
|
141
|
+
if ('value' === tone) return readonly ? 'secondary' : 'accent';
|
|
142
|
+
return 'primary';
|
|
143
|
+
}
|
|
144
|
+
function ChipSection({ tone, children, variant, interactive, onClick, ref, ...rest }) {
|
|
145
|
+
const { size, readonly } = useChipContext('Chip section');
|
|
146
|
+
const isInteractive = !readonly && (interactive ?? void 0 !== onClick);
|
|
147
|
+
const segmentProps = useChipSegment(isInteractive);
|
|
148
|
+
const textVariant = variant ?? resolveTone(tone, readonly);
|
|
149
|
+
const textSize = SIZES[size].font;
|
|
150
|
+
const content = /*#__PURE__*/ jsx(Text, {
|
|
151
|
+
size: textSize,
|
|
152
|
+
variant: textVariant,
|
|
153
|
+
wrap: "nowrap",
|
|
154
|
+
children: children
|
|
155
|
+
});
|
|
156
|
+
if (!isInteractive) return /*#__PURE__*/ jsx(Flex, {
|
|
157
|
+
display: "inline-flex",
|
|
158
|
+
align: "center",
|
|
159
|
+
children: content
|
|
160
|
+
});
|
|
161
|
+
return /*#__PURE__*/ jsx(InteractiveSegment, {
|
|
162
|
+
ref: ref,
|
|
163
|
+
type: "button",
|
|
164
|
+
"data-chip-interactive": "",
|
|
165
|
+
...mergeProps(rest, segmentProps, {
|
|
166
|
+
onClick
|
|
167
|
+
}),
|
|
168
|
+
children: content
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
function ChipProperty(props) {
|
|
172
|
+
return /*#__PURE__*/ jsx(ChipSection, {
|
|
173
|
+
tone: "property",
|
|
174
|
+
...props
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function ChipOperator(props) {
|
|
178
|
+
return /*#__PURE__*/ jsx(ChipSection, {
|
|
179
|
+
tone: "operator",
|
|
180
|
+
...props
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function ChipValue(props) {
|
|
184
|
+
return /*#__PURE__*/ jsx(ChipSection, {
|
|
185
|
+
tone: "value",
|
|
186
|
+
...props
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
function ChipDismiss({ onClick, ref, ...rest }) {
|
|
190
|
+
const { t } = useTranslation();
|
|
191
|
+
const { size, readonly } = useChipContext('Chip.Dismiss');
|
|
192
|
+
const segmentProps = useChipSegment(!readonly);
|
|
193
|
+
if (readonly) return null;
|
|
194
|
+
return /*#__PURE__*/ jsx(DismissButton, {
|
|
195
|
+
ref: ref,
|
|
196
|
+
chipSize: size,
|
|
197
|
+
size: "zero",
|
|
198
|
+
variant: "transparent",
|
|
199
|
+
icon: /*#__PURE__*/ jsx(IconClose, {
|
|
200
|
+
size: "xs"
|
|
201
|
+
}),
|
|
202
|
+
"aria-label": t('Remove'),
|
|
203
|
+
"data-chip-dismiss": "",
|
|
204
|
+
...mergeProps(rest, segmentProps, {
|
|
205
|
+
onClick: (event)=>{
|
|
206
|
+
event.stopPropagation();
|
|
207
|
+
onClick?.(event);
|
|
208
|
+
}
|
|
209
|
+
})
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function Chip({ size = 'md', property, operator, readonly = false, value, onDismiss, ...rest }) {
|
|
213
|
+
const { t } = useTranslation();
|
|
214
|
+
const valueVariant = readonly ? 'secondary' : void 0 === property ? 'primary' : 'accent';
|
|
215
|
+
return /*#__PURE__*/ jsxs(ChipRoot, {
|
|
216
|
+
size: size,
|
|
217
|
+
readonly: readonly,
|
|
218
|
+
...rest,
|
|
219
|
+
children: [
|
|
220
|
+
void 0 !== property && /*#__PURE__*/ jsx(ChipProperty, {
|
|
221
|
+
children: property
|
|
222
|
+
}),
|
|
223
|
+
operator ? /*#__PURE__*/ jsx(ChipOperator, {
|
|
224
|
+
children: operator
|
|
225
|
+
}) : null,
|
|
226
|
+
/*#__PURE__*/ jsx(ChipValue, {
|
|
227
|
+
variant: valueVariant,
|
|
228
|
+
children: value
|
|
229
|
+
}),
|
|
230
|
+
!readonly && onDismiss ? /*#__PURE__*/ jsx(ChipDismiss, {
|
|
231
|
+
"aria-label": t('Remove %s', [
|
|
232
|
+
property,
|
|
233
|
+
operator,
|
|
234
|
+
value
|
|
235
|
+
].filter(Boolean).join(' ')),
|
|
236
|
+
onClick: ()=>onDismiss()
|
|
237
|
+
}) : null
|
|
238
|
+
]
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
Chip.Root = ChipRoot;
|
|
242
|
+
Chip.Property = ChipProperty;
|
|
243
|
+
Chip.Operator = ChipOperator;
|
|
244
|
+
Chip.Value = ChipValue;
|
|
245
|
+
Chip.Dismiss = ChipDismiss;
|
|
246
|
+
const ChipRootElement = styled('div')`
|
|
247
|
+
display: inline-flex;
|
|
248
|
+
align-items: stretch;
|
|
249
|
+
box-sizing: border-box;
|
|
250
|
+
height: ${(p)=>SIZES[p.chipSize].height};
|
|
251
|
+
/* Inert layout: generous end padding, tight gap between the value parts. */
|
|
252
|
+
gap: ${(p)=>p.theme.space.xs};
|
|
253
|
+
padding-inline: ${(p)=>p.theme.space[SIZES[p.chipSize].pad]};
|
|
254
|
+
border: 1px solid ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.chonk};
|
|
255
|
+
border-radius: ${(p)=>p.theme.radius[SIZES[p.chipSize].radius]};
|
|
256
|
+
background: ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.background};
|
|
257
|
+
box-shadow: 0 1px 0 0 ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.chonk};
|
|
258
|
+
line-height: 16px;
|
|
259
|
+
|
|
260
|
+
/* Let the trailing dismiss button sit flush against the edge. */
|
|
261
|
+
&:has([data-chip-dismiss]) {
|
|
262
|
+
padding-right: 0;
|
|
263
|
+
}
|
|
264
|
+
/*
|
|
265
|
+
* The dismiss button's own inline padding already supplies the flat gap
|
|
266
|
+
* on this seam (see DismissButton below), so cancel out the inert
|
|
267
|
+
* layout's uniform gap here rather than doubling it. Only applies when
|
|
268
|
+
* there are no interactive segments — that layout redistributes this
|
|
269
|
+
* seam's spacing itself, below.
|
|
270
|
+
*/
|
|
271
|
+
&:not(:has([data-chip-interactive])) > [data-chip-dismiss] {
|
|
272
|
+
margin-inline-start: calc(-1 * ${(p)=>p.theme.space.xs});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/*
|
|
276
|
+
* Interactive layout: segmented buttons abut and fill the chip. Redistribute
|
|
277
|
+
* padding so labels line up exactly with the flat chip — the flat end padding
|
|
278
|
+
* on the outer edges and half the flat gap on each inner seam, so adjacent
|
|
279
|
+
* segments sum to a single gap instead of doubling.
|
|
280
|
+
*/
|
|
281
|
+
&:has([data-chip-interactive]) {
|
|
282
|
+
gap: 0;
|
|
283
|
+
padding-inline: 0;
|
|
284
|
+
}
|
|
285
|
+
&:has([data-chip-interactive]) [data-chip-interactive] {
|
|
286
|
+
padding-inline: calc(${(p)=>p.theme.space.xs} / 2);
|
|
287
|
+
}
|
|
288
|
+
&:has([data-chip-interactive]) > [data-chip-interactive]:first-child {
|
|
289
|
+
padding-inline-start: ${(p)=>p.theme.space[SIZES[p.chipSize].pad]};
|
|
290
|
+
}
|
|
291
|
+
&:has([data-chip-interactive]) > [data-chip-interactive]:last-child {
|
|
292
|
+
padding-inline-end: ${(p)=>p.theme.space[SIZES[p.chipSize].pad]};
|
|
293
|
+
}
|
|
294
|
+
/*
|
|
295
|
+
* A segment flush against the dismiss yields its half of the seam — the
|
|
296
|
+
* dismiss button's own inline padding (see DismissButton below) supplies
|
|
297
|
+
* the single flat gap, same as the inert layout above.
|
|
298
|
+
*/
|
|
299
|
+
&:has([data-chip-interactive]) > [data-chip-interactive]:has(+ [data-chip-dismiss]) {
|
|
300
|
+
padding-inline-end: 0;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/*
|
|
304
|
+
* Overflow stays visible so a segment's focus ring isn't clipped. Round the
|
|
305
|
+
* leading and trailing children instead, so their hover/active backgrounds
|
|
306
|
+
* still follow the chip's corners in the flush interactive layout. The inner
|
|
307
|
+
* radius is the chip radius minus the 1px border so the corners stay
|
|
308
|
+
* concentric with the chip.
|
|
309
|
+
*/
|
|
310
|
+
& > :first-child {
|
|
311
|
+
border-start-start-radius: calc(
|
|
312
|
+
${(p)=>p.theme.radius[SIZES[p.chipSize].radius]} - 1px
|
|
313
|
+
);
|
|
314
|
+
border-end-start-radius: calc(${(p)=>p.theme.radius[SIZES[p.chipSize].radius]} - 1px);
|
|
315
|
+
}
|
|
316
|
+
& > :last-child {
|
|
317
|
+
border-start-end-radius: calc(${(p)=>p.theme.radius[SIZES[p.chipSize].radius]} - 1px);
|
|
318
|
+
border-end-end-radius: calc(${(p)=>p.theme.radius[SIZES[p.chipSize].radius]} - 1px);
|
|
319
|
+
}
|
|
320
|
+
`;
|
|
321
|
+
const InteractiveSegment = styled('button')`
|
|
322
|
+
display: inline-flex;
|
|
323
|
+
align-items: center;
|
|
324
|
+
align-self: stretch;
|
|
325
|
+
margin: 0;
|
|
326
|
+
border: 0;
|
|
327
|
+
background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.rest};
|
|
328
|
+
padding: 0;
|
|
329
|
+
color: inherit;
|
|
330
|
+
cursor: pointer;
|
|
331
|
+
|
|
332
|
+
&:hover {
|
|
333
|
+
background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.hover};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
&:active {
|
|
337
|
+
background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.active};
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
&:focus-visible {
|
|
341
|
+
${(p)=>p.theme.focusRing()};
|
|
342
|
+
z-index: 1;
|
|
343
|
+
}
|
|
344
|
+
`;
|
|
345
|
+
const DismissButton = styled(Button)`
|
|
346
|
+
align-self: stretch;
|
|
347
|
+
width: ${(p)=>SIZES[p.chipSize].dismiss};
|
|
348
|
+
height: auto;
|
|
349
|
+
min-height: 0;
|
|
350
|
+
padding: 0 ${(p)=>p.theme.space.xs};
|
|
351
|
+
border: 0;
|
|
352
|
+
border-radius: 0;
|
|
353
|
+
color: ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.content.secondary};
|
|
354
|
+
|
|
355
|
+
&:hover {
|
|
356
|
+
background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.hover};
|
|
357
|
+
color: ${(p)=>p.theme.tokens.interactive.chonky.embossed.neutral.content.primary};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
&:active {
|
|
361
|
+
background: ${(p)=>p.theme.tokens.interactive.transparent.neutral.background.active};
|
|
362
|
+
}
|
|
363
|
+
`;
|
|
364
|
+
export { Chip };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Chip } from './chip.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Chip } from "./chip.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
1
2
|
import type { Theme } from '../theme/index.js';
|
|
2
3
|
export declare const inlineCodeStyles: (theme: Theme, props?: InlineCodeProps) => import("@emotion/react").SerializedStyles;
|
|
3
4
|
interface InlineCodeProps extends React.HTMLProps<HTMLElementTagNameMap['code']> {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* How an absolute time should be written out for the person reading it.
|
|
4
|
+
*
|
|
5
|
+
* Scraps has no notion of who is viewing, so it cannot resolve either of these
|
|
6
|
+
* on its own. The defaults are the neutral reading of a timestamp before anyone
|
|
7
|
+
* localizes it: UTC, on a 12 hour clock, which is what the unprefixed formats
|
|
8
|
+
* in `getFormat` already produce.
|
|
9
|
+
*
|
|
10
|
+
* Applications provide the viewer's values with <DateTimeProvider>.
|
|
11
|
+
*/
|
|
12
|
+
export interface DateTimeContextValue {
|
|
13
|
+
/**
|
|
14
|
+
* Whether times are written on a 12 or 24 hour clock.
|
|
15
|
+
*/
|
|
16
|
+
clockDisplay: '12' | '24';
|
|
17
|
+
/**
|
|
18
|
+
* IANA timezone name, e.g. "America/New_York".
|
|
19
|
+
*/
|
|
20
|
+
timezone: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Provide the timezone and clock that absolute times should be written in.
|
|
24
|
+
*
|
|
25
|
+
* Takes the whole value rather than separate props so that consumers wire up
|
|
26
|
+
* one thing; memoize it if you are building it inline.
|
|
27
|
+
*/
|
|
28
|
+
export declare function DateTimeProvider({ value, children, }: {
|
|
29
|
+
children: React.ReactNode;
|
|
30
|
+
value: DateTimeContextValue;
|
|
31
|
+
}): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
32
|
+
/**
|
|
33
|
+
* The timezone absolute times should be written in.
|
|
34
|
+
*/
|
|
35
|
+
export declare function useTimezone(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Whether absolute times should be written on a 12 or 24 hour clock.
|
|
38
|
+
*/
|
|
39
|
+
export declare function useClockDisplay(): DateTimeContextValue['clockDisplay'];
|
package/dist/datetime.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
const DEFAULT_DATE_TIME = {
|
|
4
|
+
timezone: 'UTC',
|
|
5
|
+
clockDisplay: '12'
|
|
6
|
+
};
|
|
7
|
+
const DateTimeContext = /*#__PURE__*/ createContext(DEFAULT_DATE_TIME);
|
|
8
|
+
function DateTimeProvider({ value, children }) {
|
|
9
|
+
return /*#__PURE__*/ jsx(DateTimeContext, {
|
|
10
|
+
value: value,
|
|
11
|
+
children: children
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function useTimezone() {
|
|
15
|
+
return useContext(DateTimeContext).timezone;
|
|
16
|
+
}
|
|
17
|
+
function useClockDisplay() {
|
|
18
|
+
return useContext(DateTimeContext).clockDisplay;
|
|
19
|
+
}
|
|
20
|
+
export { DateTimeProvider, useClockDisplay, useTimezone };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { CSS } from '../cssTypes.js';
|
|
3
|
+
import { type Responsive } from '../layout/index.js';
|
|
4
|
+
import type { SpaceSize } from '../theme/index.js';
|
|
5
|
+
export interface DescriptionListProps extends React.HTMLAttributes<HTMLDListElement> {
|
|
6
|
+
/**
|
|
7
|
+
* How a row's term and details line up against each other.
|
|
8
|
+
* @default 'baseline'
|
|
9
|
+
*/
|
|
10
|
+
align?: Responsive<'start' | 'end' | 'center' | 'baseline' | 'stretch'>;
|
|
11
|
+
/**
|
|
12
|
+
* The column tracks the rows are laid out in. A term and its details are two
|
|
13
|
+
* tracks; a term with more than one details cell needs one track each.
|
|
14
|
+
* @default 'max-content minmax(0, 1fr)'
|
|
15
|
+
*/
|
|
16
|
+
columns?: Responsive<CSS['gridTemplateColumns']>;
|
|
17
|
+
/**
|
|
18
|
+
* Row and column gap between terms and their details.
|
|
19
|
+
* @default 'sm md'
|
|
20
|
+
*/
|
|
21
|
+
gap?: Responsive<SpaceSize | `${SpaceSize} ${SpaceSize}`>;
|
|
22
|
+
/**
|
|
23
|
+
* Keep every row on one line and size the list to its own content, rather
|
|
24
|
+
* than wrapping to the width it is given. For a list in an overlay that
|
|
25
|
+
* shrink-to-fits, such as a tooltip, this is what makes the overlay grow to
|
|
26
|
+
* fit the rows instead of breaking timestamps and slugs mid-token.
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
nowrap?: boolean;
|
|
30
|
+
ref?: React.Ref<HTMLDListElement>;
|
|
31
|
+
/**
|
|
32
|
+
* Lay the list out as a full-width table: alternate rows are striped, terms
|
|
33
|
+
* and details split the width evenly, and details sit against the far edge.
|
|
34
|
+
* Each cell stays on one line and truncates. Terms are set in the primary
|
|
35
|
+
* color and details in the secondary color, so `terms` does not apply.
|
|
36
|
+
* @default false
|
|
37
|
+
*/
|
|
38
|
+
striped?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* How terms are set against their details.
|
|
41
|
+
*
|
|
42
|
+
* - `muted` sets them in the secondary color at a regular weight, so the
|
|
43
|
+
* details are what the eye lands on.
|
|
44
|
+
* - `strong` sets them in the primary color and bold, which is what a bare
|
|
45
|
+
* `dt` inherits from the global rule in base.less. Lists that already read
|
|
46
|
+
* that way keep it rather than being restyled.
|
|
47
|
+
*
|
|
48
|
+
* @default 'muted'
|
|
49
|
+
*/
|
|
50
|
+
terms?: 'muted' | 'strong';
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A compact, two-column list of terms and their details, rendered as a
|
|
54
|
+
* semantic `<dl>`. Compose rows with `DescriptionList.Term` and
|
|
55
|
+
* `DescriptionList.Details`.
|
|
56
|
+
*/
|
|
57
|
+
export declare const DescriptionList: import("@emotion/styled").StyledComponent<{
|
|
58
|
+
theme?: import("@emotion/react").Theme;
|
|
59
|
+
as?: React.ElementType;
|
|
60
|
+
} & DescriptionListProps, React.DetailedHTMLProps<React.HTMLAttributes<HTMLDListElement>, HTMLDListElement>, {}> & {
|
|
61
|
+
Term: import("@emotion/styled").StyledComponent<{
|
|
62
|
+
theme?: import("@emotion/react").Theme;
|
|
63
|
+
as?: React.ElementType;
|
|
64
|
+
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, {}>;
|
|
65
|
+
Details: import("@emotion/styled").StyledComponent<{
|
|
66
|
+
theme?: import("@emotion/react").Theme;
|
|
67
|
+
as?: React.ElementType;
|
|
68
|
+
}, React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, {}>;
|
|
69
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import is_prop_valid from "@emotion/is-prop-valid";
|
|
2
|
+
import { css } from "@emotion/react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { getSpacing, rc } from "../layout/index.js";
|
|
5
|
+
const List = styled('dl', {
|
|
6
|
+
shouldForwardProp: (prop)=>'gap' !== prop && 'nowrap' !== prop && 'columns' !== prop && 'align' !== prop && 'terms' !== prop && 'striped' !== prop && is_prop_valid(prop)
|
|
7
|
+
})`
|
|
8
|
+
display: grid;
|
|
9
|
+
${(p)=>rc('grid-template-columns', p.columns ?? (p.striped ? 'minmax(0, 1fr) minmax(0, 1fr)' : 'max-content minmax(0, 1fr)'), p.theme)};
|
|
10
|
+
${(p)=>rc('align-items', p.align ?? (p.striped ? 'stretch' : 'baseline'), p.theme)};
|
|
11
|
+
${(p)=>rc('gap', p.gap ?? (p.striped ? '0' : 'sm md'), p.theme, getSpacing)};
|
|
12
|
+
margin: 0;
|
|
13
|
+
text-align: left;
|
|
14
|
+
${(p)=>p.nowrap && css`
|
|
15
|
+
width: max-content;
|
|
16
|
+
white-space: nowrap;
|
|
17
|
+
`}
|
|
18
|
+
|
|
19
|
+
${(p)=>p.striped && css`
|
|
20
|
+
> dt,
|
|
21
|
+
> dd {
|
|
22
|
+
padding: ${p.theme.space.xs} ${p.theme.space.md};
|
|
23
|
+
font-size: ${p.theme.font.size.md};
|
|
24
|
+
line-height: inherit;
|
|
25
|
+
white-space: nowrap;
|
|
26
|
+
overflow: hidden;
|
|
27
|
+
text-overflow: ellipsis;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
> dt {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: center;
|
|
33
|
+
color: ${p.theme.tokens.content.primary};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
> dd {
|
|
37
|
+
text-align: right;
|
|
38
|
+
color: ${p.theme.tokens.content.secondary};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
> dt:nth-of-type(odd),
|
|
42
|
+
> dd:nth-of-type(odd) {
|
|
43
|
+
background-color: ${p.theme.tokens.background.secondary};
|
|
44
|
+
}
|
|
45
|
+
`}
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
* Selects on the element so it beats Term's own class without every term
|
|
49
|
+
* restating it. 700 is not a scraps weight -- it is what these lists already
|
|
50
|
+
* inherit from the global dt rule in base.less, restated here because Term
|
|
51
|
+
* overrides that with the regular weight.
|
|
52
|
+
*/
|
|
53
|
+
${(p)=>'strong' === p.terms && !p.striped && css`
|
|
54
|
+
> dt {
|
|
55
|
+
color: ${p.theme.tokens.content.primary};
|
|
56
|
+
font-weight: 700;
|
|
57
|
+
}
|
|
58
|
+
`}
|
|
59
|
+
`;
|
|
60
|
+
const Term = styled('dt')`
|
|
61
|
+
min-width: 0;
|
|
62
|
+
margin: 0;
|
|
63
|
+
overflow-wrap: anywhere;
|
|
64
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
65
|
+
font-weight: ${(p)=>p.theme.font.weight.sans.regular};
|
|
66
|
+
`;
|
|
67
|
+
const Details = styled('dd')`
|
|
68
|
+
min-width: 0;
|
|
69
|
+
margin: 0;
|
|
70
|
+
overflow-wrap: anywhere;
|
|
71
|
+
`;
|
|
72
|
+
const DescriptionList = Object.assign(List, {
|
|
73
|
+
Term: Term,
|
|
74
|
+
Details: Details
|
|
75
|
+
});
|
|
76
|
+
export { DescriptionList };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DescriptionList, type DescriptionListProps } from './descriptionList.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DescriptionList } from "./descriptionList.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type AriaDisclosureProps } from '@react-aria/disclosure';
|
|
3
|
+
import { type StackProps } from '../layout/index.js';
|
|
4
|
+
interface DisclosureProps extends Omit<AriaDisclosureProps, 'isDisabled' | 'isExpanded'>, Omit<StackProps, 'as'> {
|
|
5
|
+
children: NonNullable<React.ReactNode>;
|
|
6
|
+
as?: 'section' | 'div';
|
|
7
|
+
expanded?: boolean;
|
|
8
|
+
ref?: React.Ref<HTMLDivElement | null>;
|
|
9
|
+
size?: 'xs' | 'sm' | 'md';
|
|
10
|
+
/**
|
|
11
|
+
* Visual treatment of the disclosure's content panel:
|
|
12
|
+
* - `default`: content is left-indented to align under the title.
|
|
13
|
+
* - `outline`: content is a bordered, rounded card sitting below the title.
|
|
14
|
+
*/
|
|
15
|
+
variant?: 'default' | 'outline';
|
|
16
|
+
}
|
|
17
|
+
declare function DisclosureComponent({ children, size, variant, ref, onExpandedChange, ...props }: DisclosureProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
18
|
+
interface DisclosureTitleProps extends React.HTMLAttributes<HTMLButtonElement> {
|
|
19
|
+
children?: NonNullable<React.ReactNode>;
|
|
20
|
+
/**
|
|
21
|
+
* Content rendered before the toggle (e.g. an avatar or brand mark). When
|
|
22
|
+
* provided, the chevron moves to sit after the title so the leading slot reads
|
|
23
|
+
* as the row's first element.
|
|
24
|
+
*/
|
|
25
|
+
leadingItems?: React.ReactNode;
|
|
26
|
+
trailingItems?: React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
declare function Title({ children, leadingItems, trailingItems, ...rest }: DisclosureTitleProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
29
|
+
interface DisclosureContentProps extends React.HTMLAttributes<HTMLElement> {
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
declare function Content({ children, ...props }: DisclosureContentProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
33
|
+
export declare const Disclosure: typeof DisclosureComponent & {
|
|
34
|
+
Title: typeof Title;
|
|
35
|
+
Content: typeof Content;
|
|
36
|
+
};
|
|
37
|
+
export {};
|