@sentry/scraps 0.4.0 → 0.6.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 +74 -8
- package/dist/alert/alert.js +0 -3
- package/dist/badge/badge.js +1 -2
- package/dist/badge/tag.js +4 -4
- package/dist/button/button.js +1 -0
- package/dist/button/index.d.ts +0 -1
- package/dist/button/index.js +0 -1
- package/dist/button/linkButton.js +1 -0
- package/dist/button/styles.js +157 -152
- package/dist/clipboard/copyToClipboardButton.d.ts +15 -0
- package/dist/clipboard/copyToClipboardButton.js +32 -0
- package/dist/clipboard/index.d.ts +1 -0
- package/dist/clipboard/index.js +1 -0
- package/dist/code/index.d.ts +1 -0
- package/dist/code/index.js +1 -0
- package/dist/codeBlock/codeBlock.d.ts +68 -0
- package/dist/codeBlock/codeBlock.js +243 -0
- package/dist/codeBlock/index.d.ts +2 -0
- package/dist/codeBlock/index.js +2 -0
- package/dist/codeBlock/prism.d.ts +11 -0
- package/dist/codeBlock/prism.js +101 -0
- package/dist/codeBlock/styles.d.ts +2 -0
- package/dist/codeBlock/styles.js +133 -0
- package/dist/compactSelect/compactSelect.d.ts +21 -0
- package/dist/compactSelect/compactSelect.js +150 -0
- package/dist/compactSelect/composite.d.ts +54 -0
- package/dist/compactSelect/composite.js +101 -0
- package/dist/compactSelect/control.d.ts +112 -0
- package/dist/compactSelect/control.js +355 -0
- package/dist/compactSelect/gridList/index.d.ts +46 -0
- package/dist/compactSelect/gridList/index.js +102 -0
- package/dist/compactSelect/gridList/option.d.ts +15 -0
- package/dist/compactSelect/gridList/option.js +111 -0
- package/dist/compactSelect/gridList/section.d.ts +15 -0
- package/dist/compactSelect/gridList/section.js +58 -0
- package/dist/compactSelect/highlightText.d.ts +6 -0
- package/dist/compactSelect/highlightText.js +33 -0
- package/dist/compactSelect/index.d.ts +9 -0
- package/dist/compactSelect/index.js +8 -0
- package/dist/compactSelect/list.d.ts +94 -0
- package/dist/compactSelect/list.js +167 -0
- package/dist/compactSelect/listBox/index.d.ts +84 -0
- package/dist/compactSelect/listBox/index.js +175 -0
- package/dist/compactSelect/listBox/option.d.ts +19 -0
- package/dist/compactSelect/listBox/option.js +101 -0
- package/dist/compactSelect/listBox/section.d.ts +21 -0
- package/dist/compactSelect/listBox/section.js +58 -0
- package/dist/compactSelect/menuComponents.d.ts +89 -0
- package/dist/compactSelect/menuComponents.js +117 -0
- package/dist/compactSelect/selectFilterContext.d.ts +2 -0
- package/dist/compactSelect/selectFilterContext.js +3 -0
- package/dist/compactSelect/styles.d.ts +39 -0
- package/dist/compactSelect/styles.js +155 -0
- package/dist/compactSelect/types.d.ts +1 -0
- package/dist/compactSelect/types.js +0 -0
- package/dist/compactSelect/useVirtualizedItems.d.ts +52 -0
- package/dist/compactSelect/useVirtualizedItems.js +74 -0
- package/dist/compactSelect/utils.d.ts +80 -0
- package/dist/compactSelect/utils.js +264 -0
- package/dist/confirm/index.d.ts +153 -0
- package/dist/confirm/index.js +132 -0
- package/dist/dateTime/config.d.ts +23 -0
- package/dist/dateTime/config.js +50 -0
- package/dist/dateTime/context.d.ts +18 -0
- package/dist/dateTime/context.js +46 -0
- package/dist/dateTime/dateTime.d.ts +6 -0
- package/dist/dateTime/dateTime.js +30 -0
- package/dist/dateTime/format.d.ts +24 -0
- package/dist/dateTime/format.js +45 -0
- package/dist/dateTime/index.d.ts +6 -0
- package/dist/dateTime/index.js +6 -0
- package/dist/dateTime/intlFormatter.d.ts +9 -0
- package/dist/dateTime/intlFormatter.js +16 -0
- package/dist/dateTime/parseDate.d.ts +3 -0
- package/dist/dateTime/parseDate.js +12 -0
- package/dist/descriptionList/descriptionList.js +4 -3
- package/dist/disclosure/disclosure.js +2 -2
- package/dist/dragHandle/dragHandle.d.ts +3 -1
- package/dist/dragHandle/dragHandle.js +8 -5
- package/dist/drawer/components.d.ts +46 -0
- package/dist/drawer/components.js +265 -0
- package/dist/drawer/globalDrawer.d.ts +106 -0
- package/dist/drawer/globalDrawer.js +173 -0
- package/dist/drawer/index.d.ts +3 -0
- package/dist/drawer/index.js +2 -0
- package/dist/drawer/useDrawerResizing.d.ts +19 -0
- package/dist/drawer/useDrawerResizing.js +111 -0
- package/dist/drawer/useDrawerWidth.d.ts +1 -0
- package/dist/drawer/useDrawerWidth.js +42 -0
- package/dist/dropdownMenu/content.d.ts +1 -0
- package/dist/dropdownMenu/content.js +1 -0
- package/dist/dropdownMenu/context.d.ts +39 -0
- package/dist/dropdownMenu/context.js +3 -0
- package/dist/dropdownMenu/dropdownMenu.d.ts +70 -0
- package/dist/dropdownMenu/dropdownMenu.js +109 -0
- package/dist/dropdownMenu/index.d.ts +2 -0
- package/dist/dropdownMenu/index.js +1 -0
- package/dist/dropdownMenu/item.d.ts +140 -0
- package/dist/dropdownMenu/item.js +142 -0
- package/dist/dropdownMenu/list.d.ts +85 -0
- package/dist/dropdownMenu/list.js +429 -0
- package/dist/dropdownMenu/search.d.ts +16 -0
- package/dist/dropdownMenu/search.js +16 -0
- package/dist/dropdownMenu/section.d.ts +21 -0
- package/dist/dropdownMenu/section.js +40 -0
- package/dist/dropdownMenu/separator.d.ts +7 -0
- package/dist/dropdownMenu/separator.js +15 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.d.ts +24 -0
- package/dist/dropdownMenu/useDropdownMenuKeyboard.js +31 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.d.ts +29 -0
- package/dist/dropdownMenu/useDropdownMenuRowLayout.js +64 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.d.ts +13 -0
- package/dist/dropdownMenu/useDropdownRootMenuState.js +30 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.d.ts +19 -0
- package/dist/dropdownMenu/useDropdownSubmenuState.js +25 -0
- package/dist/dropdownMenu/utils.d.ts +21 -0
- package/dist/dropdownMenu/utils.js +55 -0
- package/dist/duration/formatElapsedDuration.d.ts +4 -0
- package/dist/duration/formatElapsedDuration.js +10 -0
- package/dist/duration/getDuration.d.ts +68 -0
- package/dist/duration/getDuration.js +80 -0
- package/dist/duration/index.d.ts +2 -0
- package/dist/duration/index.js +2 -0
- package/dist/form/FormSearch.d.ts +19 -0
- package/dist/form/FormSearch.js +4 -0
- package/dist/form/autoSaveForm.d.ts +110 -0
- package/dist/form/autoSaveForm.js +100 -0
- package/dist/{formPresentation → form}/displayField.js +2 -2
- package/dist/form/field/baseField.d.ts +23 -0
- package/dist/form/field/baseField.js +116 -0
- package/dist/form/field/checkboxField.d.ts +11 -0
- package/dist/form/field/checkboxField.js +42 -0
- package/dist/form/field/checkboxGroupField.d.ts +16 -0
- package/dist/form/field/checkboxGroupField.js +80 -0
- package/dist/form/field/compactSelectField.d.ts +19 -0
- package/dist/form/field/compactSelectField.js +77 -0
- package/dist/{formPresentation → form/field}/fieldIds.js +1 -1
- package/dist/form/field/inputField.d.ts +19 -0
- package/dist/form/field/inputField.js +31 -0
- package/dist/{formPresentation → form/field}/meta.js +6 -6
- package/dist/form/field/numberField.d.ts +5 -0
- package/dist/form/field/numberField.js +11 -0
- package/dist/form/field/passwordField.d.ts +3 -0
- package/dist/form/field/passwordField.js +27 -0
- package/dist/form/field/radioGroupField.d.ts +16 -0
- package/dist/form/field/radioGroupField.js +92 -0
- package/dist/form/field/rangeField.d.ts +8 -0
- package/dist/form/field/rangeField.js +34 -0
- package/dist/form/field/selectAsyncField.d.ts +31 -0
- package/dist/form/field/selectAsyncField.js +22 -0
- package/dist/form/field/selectField.d.ts +9 -0
- package/dist/form/field/selectField.js +72 -0
- package/dist/form/field/switchField.d.ts +7 -0
- package/dist/form/field/switchField.js +37 -0
- package/dist/form/field/textAreaField.d.ts +7 -0
- package/dist/form/field/textAreaField.js +25 -0
- package/dist/{formPresentation → form}/formContext.js +1 -1
- package/dist/form/formErrorContext/index.d.ts +9 -0
- package/dist/form/formErrorContext/index.js +7 -0
- package/dist/form/index.d.ts +9 -0
- package/dist/form/index.js +8 -0
- package/dist/{formPresentation → form/layout}/base.d.ts +1 -1
- package/dist/{formPresentation → form/layout}/base.js +1 -1
- package/dist/form/layout/fieldGroup.d.ts +6 -0
- package/dist/form/layout/fieldGroup.js +60 -0
- package/dist/{formPresentation/fieldLayout.d.ts → form/layout/index.d.ts} +1 -1
- package/dist/{formPresentation/fieldLayout.js → form/layout/index.js} +3 -3
- package/dist/{formPresentation → form/layout}/useStackedLayout.js +1 -1
- package/dist/form/scrapsForm.d.ts +220 -0
- package/dist/form/scrapsForm.js +126 -0
- package/dist/fzf.d.ts +9 -0
- package/dist/fzf.js +155 -0
- package/dist/hotkey/hotkey.d.ts +9 -8
- package/dist/hotkey/hotkey.js +13 -6
- package/dist/hotkey/index.d.ts +2 -1
- package/dist/hotkey/index.js +2 -1
- package/dist/hotkey/keyMappings.d.ts +1 -15
- package/dist/hotkey/keyMappings.js +29 -174
- package/dist/hotkey/useHotkeys.d.ts +3 -47
- package/dist/hotkey/useHotkeys.js +8 -42
- package/dist/image/image.js +2 -1
- package/dist/info/infoTip.d.ts +1 -1
- package/dist/info/infoTip.js +4 -3
- package/dist/input/index.d.ts +0 -3
- package/dist/input/index.js +0 -2
- package/dist/input/input.d.ts +2 -0
- package/dist/input/input.js +2 -0
- package/dist/input/passwordManagerIgnoreProps.d.ts +11 -0
- package/dist/input/passwordManagerIgnoreProps.js +8 -0
- package/dist/layout/container.d.ts +8 -2
- package/dist/layout/container.js +2 -2
- package/dist/layout/index.d.ts +2 -2
- package/dist/layout/index.js +1 -1
- package/dist/layout/styles.d.ts +2 -1
- package/dist/layout/styles.js +11 -5
- package/dist/legacyDatetime.d.ts +21 -0
- package/dist/legacyDatetime.js +13 -0
- package/dist/link/index.d.ts +1 -1
- package/dist/link/index.js +1 -1
- package/dist/link/link.js +4 -3
- package/dist/link/linkBehaviorContext.d.ts +11 -0
- package/dist/link/linkBehaviorContext.js +48 -11
- package/dist/menu/index.d.ts +1 -1
- package/dist/menu/index.js +1 -1
- package/dist/menu/menu.d.ts +14 -8
- package/dist/menu/menu.js +163 -60
- package/dist/modal/components.d.ts +19 -0
- package/dist/modal/components.js +99 -0
- package/dist/modal/errorBoundary.d.ts +2 -0
- package/dist/modal/errorBoundary.js +35 -0
- package/dist/modal/index.d.ts +33 -0
- package/dist/modal/index.js +260 -0
- package/dist/modal/portal.d.ts +1 -0
- package/dist/modal/portal.js +10 -0
- package/dist/modal/state.d.ts +17 -0
- package/dist/modal/state.js +41 -0
- package/dist/modal/types.d.ts +75 -0
- package/dist/modal/types.js +0 -0
- package/dist/numberInput/index.d.ts +3 -0
- package/dist/numberInput/index.js +2 -0
- package/dist/{input → numberInput}/numberDragInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberDragInput.js +1 -1
- package/dist/{input → numberInput}/numberInput.d.ts +1 -1
- package/dist/{input → numberInput}/numberInput.js +1 -1
- package/dist/overlayContext.d.ts +29 -0
- package/dist/overlayContext.js +7 -0
- package/dist/pagination/index.d.ts +1 -0
- package/dist/pagination/index.js +1 -0
- package/dist/pagination/pagination.d.ts +24 -0
- package/dist/pagination/pagination.js +63 -0
- package/dist/pictureInPicture/index.d.ts +2 -0
- package/dist/pictureInPicture/index.js +2 -0
- package/dist/pictureInPicture/pictureInPicture.d.ts +47 -0
- package/dist/pictureInPicture/pictureInPicture.js +100 -0
- package/dist/pictureInPicture/pictureInPicturePortal.d.ts +16 -0
- package/dist/pictureInPicture/pictureInPicturePortal.js +46 -0
- package/dist/pictureInPicture/portalContext.d.ts +2 -0
- package/dist/pictureInPicture/portalContext.js +3 -0
- package/dist/relativeTime/getRelativeDate.d.ts +14 -0
- package/dist/relativeTime/getRelativeDate.js +107 -0
- package/dist/relativeTime/index.d.ts +3 -0
- package/dist/relativeTime/index.js +3 -0
- package/dist/relativeTime/relativeTime.d.ts +55 -0
- package/dist/relativeTime/relativeTime.js +102 -0
- package/dist/relativeTime/useRelativeTimeFormatter.d.ts +2 -0
- package/dist/relativeTime/useRelativeTimeFormatter.js +10 -0
- package/dist/revealOnHover/revealOnHover.js +1 -1
- package/dist/segmentedControl/segmentedControl.js +1 -1
- package/dist/select/filter.d.ts +4 -0
- package/dist/select/filter.js +12 -0
- package/dist/select/index.d.ts +3 -0
- package/dist/select/index.js +2 -0
- package/dist/select/option.d.ts +16 -0
- package/dist/select/option.js +81 -0
- package/dist/select/reactSelectWrapper.d.ts +8 -0
- package/dist/select/reactSelectWrapper.js +25 -0
- package/dist/select/select.d.ts +79 -0
- package/dist/select/select.js +454 -0
- package/dist/select/styles.d.ts +9 -0
- package/dist/select/styles.js +27 -0
- package/dist/select/types.d.ts +60 -0
- package/dist/select/types.js +0 -0
- package/dist/select/virtualizedMenuList.d.ts +24 -0
- package/dist/select/virtualizedMenuList.js +123 -0
- package/dist/slideOverPanel.d.ts +20 -0
- package/dist/slideOverPanel.js +141 -0
- package/dist/splitPanel/splitPanel.d.ts +3 -1
- package/dist/splitPanel/splitPanel.js +2 -1
- package/dist/table/table.d.ts +1 -1
- package/dist/table/table.js +39 -20
- package/dist/table/useColumnResize.d.ts +6 -5
- package/dist/table/useColumnResize.js +5 -4
- package/dist/tabs/context.d.ts +9 -0
- package/dist/tabs/context.js +9 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +1 -0
- package/dist/tabs/item.d.ts +24 -0
- package/dist/tabs/item.js +4 -0
- package/dist/tabs/tab.d.ts +22 -0
- package/dist/tabs/tab.js +208 -0
- package/dist/tabs/tabList.d.ts +18 -0
- package/dist/tabs/tabList.js +258 -0
- package/dist/tabs/tabPanels.d.ts +13 -0
- package/dist/tabs/tabPanels.js +62 -0
- package/dist/tabs/tabs.d.ts +53 -0
- package/dist/tabs/tabs.js +59 -0
- package/dist/tabs/utils.d.ts +3 -0
- package/dist/tabs/utils.js +6 -0
- package/dist/text/heading.d.ts +1 -1
- package/dist/text/heading.js +1 -1
- package/dist/text/prose.d.ts +2 -2
- package/dist/text/styles.js +1 -1
- package/dist/text/text.d.ts +1 -1
- package/dist/text/text.js +1 -1
- package/dist/theme/dark.js +9 -9
- package/dist/theme/light.js +9 -9
- package/dist/theme/theme.d.ts +34 -34
- package/dist/theme/theme.js +9 -0
- package/dist/theme/types.d.ts +20 -2
- package/dist/tooltip/tooltip.js +2 -5
- package/dist/translation/index.d.ts +1 -0
- package/dist/translation/index.js +1 -0
- package/dist/translation/translate.d.ts +9 -0
- package/dist/translation/translate.js +5 -0
- package/dist/translation/translationContext.d.ts +2 -1
- package/dist/translation/translationContext.js +2 -1
- package/dist/useMedia.d.ts +15 -0
- package/dist/useMedia.js +24 -0
- package/dist/useOnClickOutside.d.ts +2 -0
- package/dist/useOnClickOutside.js +22 -0
- package/dist/useOverlay.d.ts +1 -0
- package/dist/useOverlay.js +1 -0
- package/dist/useVirtualCollection.d.ts +154 -0
- package/dist/useVirtualCollection.js +143 -0
- package/dist/useVirtualRows.d.ts +26 -0
- package/dist/useVirtualRows.js +26 -0
- package/dist/virtualCollectionLayout.d.ts +51 -0
- package/dist/virtualCollectionLayout.js +49 -0
- package/fonts/OFL.txt +94 -0
- package/fonts/roboto-mono-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-cyrillic.woff2 +0 -0
- package/fonts/roboto-mono-variable-greek.woff2 +0 -0
- package/fonts/roboto-mono-variable-latin-ext.woff2 +0 -0
- package/fonts/roboto-mono-variable-vietnamese.woff2 +0 -0
- package/fonts/roboto-mono-variable.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic-ext.woff2 +0 -0
- package/fonts/rubik-variable-cyrillic.woff2 +0 -0
- package/fonts/rubik-variable-latin-ext.woff2 +0 -0
- package/fonts/rubik-variable.woff2 +0 -0
- package/fonts.css +211 -0
- package/package.json +140 -23
- package/dist/datetime.d.ts +0 -39
- package/dist/datetime.js +0 -20
- package/dist/formPresentation/index.d.ts +0 -8
- package/dist/formPresentation/index.js +0 -8
- package/dist/interactionStateLayer/index.d.ts +0 -1
- package/dist/interactionStateLayer/index.js +0 -1
- package/dist/interactionStateLayer/interactionStateLayer.d.ts +0 -23
- package/dist/interactionStateLayer/interactionStateLayer.js +0 -67
- package/dist/unreachable.d.ts +0 -1
- package/dist/unreachable.js +0 -4
- /package/dist/{formPresentation → form}/autoSaveContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/autoSaveContext.js +0 -0
- /package/dist/{formPresentation → form}/displayField.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/fieldIds.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.d.ts +0 -0
- /package/dist/{formPresentation → form/field}/groupContext.js +0 -0
- /package/dist/{formPresentation → form/field}/meta.d.ts +0 -0
- /package/dist/{formPresentation → form}/formContext.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.d.ts +0 -0
- /package/dist/{formPresentation → form}/icons.js +0 -0
- /package/dist/{formPresentation → form/layout}/useStackedLayout.d.ts +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Pagination, PaginationBehaviorContextProvider, type PaginationProps, type PaginationPage, type CursorHandler, } from './pagination.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Pagination, PaginationBehaviorContextProvider } from "./pagination.js";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type ButtonProps } from '../button/index.js';
|
|
3
|
+
export type CursorHandler = (cursor: string | undefined, delta: -1 | 1) => void;
|
|
4
|
+
/** Opaque cursor and availability supplied by the consumer. */
|
|
5
|
+
export interface PaginationPage {
|
|
6
|
+
cursor?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PaginationProps {
|
|
10
|
+
caption?: React.ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
next?: PaginationPage;
|
|
14
|
+
/** Override the configured navigation for this pagination instance. */
|
|
15
|
+
onCursor?: CursorHandler;
|
|
16
|
+
/** Observe page changes without overriding the configured navigation. */
|
|
17
|
+
onPageChange?: CursorHandler;
|
|
18
|
+
previous?: PaginationPage;
|
|
19
|
+
size?: ButtonProps['size'];
|
|
20
|
+
}
|
|
21
|
+
/** Supply default cursor navigation while individual instances can override it. */
|
|
22
|
+
export declare const PaginationBehaviorContextProvider: React.Provider<CursorHandler | undefined>;
|
|
23
|
+
/** Cursor formats and navigation belong to consumers. */
|
|
24
|
+
export declare function Pagination({ className, onCursor, onPageChange, previous, next, size, caption, disabled, }: PaginationProps): import("@emotion/react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { IconChevron } from "@sentry/icons/chevron";
|
|
5
|
+
import { Button, ButtonBar } from "../button/index.js";
|
|
6
|
+
import { Flex } from "../layout/index.js";
|
|
7
|
+
import { useTranslation } from "../translation/useTranslation.js";
|
|
8
|
+
const PaginationBehaviorContext = /*#__PURE__*/ createContext(void 0);
|
|
9
|
+
const PaginationBehaviorContextProvider = PaginationBehaviorContext.Provider;
|
|
10
|
+
function Pagination({ className, onCursor, onPageChange, previous, next, size = 'sm', caption, disabled = false }) {
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
const defaultOnCursor = useContext(PaginationBehaviorContext);
|
|
13
|
+
const handleCursor = onCursor ?? defaultOnCursor;
|
|
14
|
+
if (void 0 === previous && void 0 === next) return null;
|
|
15
|
+
const previousDisabled = disabled || !handleCursor || void 0 === previous || true === previous.disabled;
|
|
16
|
+
const nextDisabled = disabled || !handleCursor || void 0 === next || true === next.disabled;
|
|
17
|
+
return /*#__PURE__*/ jsxs(Flex, {
|
|
18
|
+
justify: "end",
|
|
19
|
+
align: "center",
|
|
20
|
+
margin: "2xl 0 0 0",
|
|
21
|
+
className: className,
|
|
22
|
+
"data-test-id": "pagination",
|
|
23
|
+
children: [
|
|
24
|
+
caption && /*#__PURE__*/ jsx(PaginationCaption, {
|
|
25
|
+
children: caption
|
|
26
|
+
}),
|
|
27
|
+
/*#__PURE__*/ jsxs(ButtonBar, {
|
|
28
|
+
children: [
|
|
29
|
+
/*#__PURE__*/ jsx(Button, {
|
|
30
|
+
icon: /*#__PURE__*/ jsx(IconChevron, {
|
|
31
|
+
direction: "left"
|
|
32
|
+
}),
|
|
33
|
+
"aria-label": t('Previous'),
|
|
34
|
+
size: size,
|
|
35
|
+
disabled: previousDisabled,
|
|
36
|
+
onClick: ()=>{
|
|
37
|
+
handleCursor?.(previous?.cursor, -1);
|
|
38
|
+
onPageChange?.(previous?.cursor, -1);
|
|
39
|
+
}
|
|
40
|
+
}),
|
|
41
|
+
/*#__PURE__*/ jsx(Button, {
|
|
42
|
+
icon: /*#__PURE__*/ jsx(IconChevron, {
|
|
43
|
+
direction: "right"
|
|
44
|
+
}),
|
|
45
|
+
"aria-label": t('Next'),
|
|
46
|
+
size: size,
|
|
47
|
+
disabled: nextDisabled,
|
|
48
|
+
onClick: ()=>{
|
|
49
|
+
handleCursor?.(next?.cursor, 1);
|
|
50
|
+
onPageChange?.(next?.cursor, 1);
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
})
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const PaginationCaption = styled('span')`
|
|
59
|
+
color: ${(p)=>p.theme.tokens.content.secondary};
|
|
60
|
+
font-size: ${(p)=>p.theme.font.size.md};
|
|
61
|
+
margin-right: ${(p)=>p.theme.space.xl};
|
|
62
|
+
`;
|
|
63
|
+
export { Pagination, PaginationBehaviorContextProvider };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { PictureInPictureProvider, usePictureInPicture, type PictureInPictureProviderProps, type PictureInPictureContextValue, type RequestPipWindowOptions, } from './pictureInPicture.js';
|
|
2
|
+
export { PictureInPicturePortal, type PictureInPicturePortalProps, } from './pictureInPicturePortal.js';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface RequestPipWindowOptions {
|
|
3
|
+
height?: number;
|
|
4
|
+
/**
|
|
5
|
+
* Opens at the browser's default placement instead of remembering where the
|
|
6
|
+
* window was last positioned. Useful to avoid the window reappearing far from
|
|
7
|
+
* where it was triggered.
|
|
8
|
+
*/
|
|
9
|
+
preferInitialWindowPlacement?: boolean;
|
|
10
|
+
width?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface PictureInPictureContextValue {
|
|
13
|
+
/**
|
|
14
|
+
* Closes the picture-in-picture window if one is open. Idempotent.
|
|
15
|
+
*/
|
|
16
|
+
closePipWindow: () => void;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the Document Picture-in-Picture API is available in this browser.
|
|
19
|
+
*/
|
|
20
|
+
isSupported: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The currently open picture-in-picture window, or null. Watch this value to
|
|
23
|
+
* react to the window being closed (by the user or programmatically).
|
|
24
|
+
*/
|
|
25
|
+
pipWindow: Window | null;
|
|
26
|
+
/**
|
|
27
|
+
* Opens a picture-in-picture window. Must be called from a user gesture (e.g.
|
|
28
|
+
* a click handler) — the API requires transient activation.
|
|
29
|
+
*/
|
|
30
|
+
requestPipWindow: (options?: RequestPipWindowOptions) => Promise<void>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Owns the single Document Picture-in-Picture window for the tab (the API allows
|
|
34
|
+
* only one PiP window per browser tab). Provides it through context so any
|
|
35
|
+
* component can open, close, or render into it via `usePictureInPicture`.
|
|
36
|
+
*
|
|
37
|
+
* Pair with `PictureInPicturePortal` to render React content into the window.
|
|
38
|
+
*/
|
|
39
|
+
export interface PictureInPictureProviderProps {
|
|
40
|
+
children: ReactNode;
|
|
41
|
+
/** Configure a newly opened window before its content mounts. */
|
|
42
|
+
onWindowOpen?: (pipWindow: Window) => void;
|
|
43
|
+
/** Additional portal content, such as application-wide styles or window effects. */
|
|
44
|
+
renderPortalContent?: (pipWindow: Window) => ReactNode;
|
|
45
|
+
}
|
|
46
|
+
export declare function PictureInPictureProvider({ children, onWindowOpen, renderPortalContent, }: PictureInPictureProviderProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
47
|
+
export declare function usePictureInPicture(): PictureInPictureContextValue;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { PictureInPicturePortalContext } from "./portalContext.js";
|
|
4
|
+
const PictureInPictureContext = /*#__PURE__*/ createContext(null);
|
|
5
|
+
const NON_RELATIVE_URL = /^(?:[a-z][a-z0-9+.-]*:|\/\/|#)/i;
|
|
6
|
+
function resolveCssUrls(cssText, baseHref) {
|
|
7
|
+
return cssText.replace(/url\((['"]?)([^'")]*)\1\)/g, (match, quote, url)=>{
|
|
8
|
+
if (!url || NON_RELATIVE_URL.test(url)) return match;
|
|
9
|
+
try {
|
|
10
|
+
return `url(${quote}${new URL(url, baseHref).href}${quote})`;
|
|
11
|
+
} catch {
|
|
12
|
+
return match;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function copyStyles(source, target) {
|
|
17
|
+
for (const sheet of Array.from(source.styleSheets)){
|
|
18
|
+
const owner = sheet.ownerNode;
|
|
19
|
+
if (!(owner instanceof HTMLStyleElement) || !owner.dataset.emotion) try {
|
|
20
|
+
const cssText = Array.from(sheet.cssRules).map((rule)=>rule.cssText).join('');
|
|
21
|
+
const style = target.document.createElement('style');
|
|
22
|
+
style.textContent = resolveCssUrls(cssText, sheet.href ?? source.baseURI);
|
|
23
|
+
target.document.head.appendChild(style);
|
|
24
|
+
} catch {
|
|
25
|
+
if (owner) target.document.head.appendChild(owner.cloneNode(true));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function PictureInPictureProvider({ children, onWindowOpen, renderPortalContent }) {
|
|
30
|
+
const [pipWindow, setPipWindow] = useState(null);
|
|
31
|
+
const documentPictureInPicture = "u" > typeof window && 'documentPictureInPicture' in window ? window.documentPictureInPicture : null;
|
|
32
|
+
const pipWindowRef = useRef(null);
|
|
33
|
+
const handleClose = useCallback(()=>{
|
|
34
|
+
pipWindowRef.current = null;
|
|
35
|
+
setPipWindow(null);
|
|
36
|
+
}, []);
|
|
37
|
+
const requestPipWindow = useCallback(async ({ width, height, preferInitialWindowPlacement } = {})=>{
|
|
38
|
+
if (!documentPictureInPicture) return;
|
|
39
|
+
if (pipWindowRef.current && !pipWindowRef.current.closed) return;
|
|
40
|
+
const pip = await documentPictureInPicture.requestWindow({
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
preferInitialWindowPlacement
|
|
44
|
+
});
|
|
45
|
+
try {
|
|
46
|
+
copyStyles(document, pip);
|
|
47
|
+
onWindowOpen?.(pip);
|
|
48
|
+
pip.addEventListener('pagehide', handleClose, {
|
|
49
|
+
once: true
|
|
50
|
+
});
|
|
51
|
+
pipWindowRef.current = pip;
|
|
52
|
+
setPipWindow(pip);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
pip.close();
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}, [
|
|
58
|
+
documentPictureInPicture,
|
|
59
|
+
handleClose,
|
|
60
|
+
onWindowOpen
|
|
61
|
+
]);
|
|
62
|
+
const closePipWindow = useCallback(()=>{
|
|
63
|
+
const pip = pipWindowRef.current;
|
|
64
|
+
if (pip && !pip.closed) pip.close();
|
|
65
|
+
}, []);
|
|
66
|
+
useEffect(()=>()=>{
|
|
67
|
+
const pip = pipWindowRef.current;
|
|
68
|
+
if (pip && !pip.closed) {
|
|
69
|
+
pip.removeEventListener('pagehide', handleClose);
|
|
70
|
+
pip.close();
|
|
71
|
+
}
|
|
72
|
+
pipWindowRef.current = null;
|
|
73
|
+
}, [
|
|
74
|
+
handleClose
|
|
75
|
+
]);
|
|
76
|
+
const value = useMemo(()=>({
|
|
77
|
+
pipWindow,
|
|
78
|
+
isSupported: !!documentPictureInPicture,
|
|
79
|
+
requestPipWindow,
|
|
80
|
+
closePipWindow
|
|
81
|
+
}), [
|
|
82
|
+
pipWindow,
|
|
83
|
+
documentPictureInPicture,
|
|
84
|
+
requestPipWindow,
|
|
85
|
+
closePipWindow
|
|
86
|
+
]);
|
|
87
|
+
return /*#__PURE__*/ jsx(PictureInPictureContext.Provider, {
|
|
88
|
+
value: value,
|
|
89
|
+
children: /*#__PURE__*/ jsx(PictureInPicturePortalContext, {
|
|
90
|
+
value: renderPortalContent,
|
|
91
|
+
children: children
|
|
92
|
+
})
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function usePictureInPicture() {
|
|
96
|
+
const context = useContext(PictureInPictureContext);
|
|
97
|
+
if (!context) throw new Error('usePictureInPicture must be used within a PictureInPictureProvider');
|
|
98
|
+
return context;
|
|
99
|
+
}
|
|
100
|
+
export { PictureInPictureProvider, usePictureInPicture };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
export interface PictureInPicturePortalProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
/**
|
|
5
|
+
* The picture-in-picture window to render into. Obtain one via
|
|
6
|
+
* `usePictureInPicture`.
|
|
7
|
+
*/
|
|
8
|
+
pipWindow: Window;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Renders children into a Document Picture-in-Picture window with the full
|
|
12
|
+
* styling context wired up: a PiP-scoped emotion cache, the theme,
|
|
13
|
+
* and a tooltip container override so overlays render in the PiP window
|
|
14
|
+
* rather than the main one.
|
|
15
|
+
*/
|
|
16
|
+
export declare function PictureInPicturePortal({ children, pipWindow, }: PictureInPicturePortalProps): React.ReactPortal;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { useContext, useEffect, useMemo } from "react";
|
|
3
|
+
import { createPortal } from "react-dom";
|
|
4
|
+
import _emotion_cache from "@emotion/cache";
|
|
5
|
+
import { CacheProvider, ThemeProvider, useTheme } from "@emotion/react";
|
|
6
|
+
import { TooltipContext } from "../tooltip/index.js";
|
|
7
|
+
import { PictureInPicturePortalContext } from "./portalContext.js";
|
|
8
|
+
function PictureInPicturePortal({ children, pipWindow }) {
|
|
9
|
+
const theme = useTheme();
|
|
10
|
+
const renderPortalContent = useContext(PictureInPicturePortalContext);
|
|
11
|
+
const cache = useMemo(()=>{
|
|
12
|
+
const pipCache = _emotion_cache({
|
|
13
|
+
key: 'scraps-pip',
|
|
14
|
+
container: pipWindow.document.head,
|
|
15
|
+
stylisPlugins: []
|
|
16
|
+
});
|
|
17
|
+
pipCache.compat = true;
|
|
18
|
+
return pipCache;
|
|
19
|
+
}, [
|
|
20
|
+
pipWindow
|
|
21
|
+
]);
|
|
22
|
+
useEffect(()=>{
|
|
23
|
+
const { documentElement, body } = pipWindow.document;
|
|
24
|
+
documentElement.style.height = '100%';
|
|
25
|
+
body.style.height = '100%';
|
|
26
|
+
body.style.margin = '0';
|
|
27
|
+
}, [
|
|
28
|
+
pipWindow
|
|
29
|
+
]);
|
|
30
|
+
return /*#__PURE__*/ createPortal(/*#__PURE__*/ jsx(CacheProvider, {
|
|
31
|
+
value: cache,
|
|
32
|
+
children: /*#__PURE__*/ jsx(ThemeProvider, {
|
|
33
|
+
theme: theme,
|
|
34
|
+
children: /*#__PURE__*/ jsxs(TooltipContext, {
|
|
35
|
+
value: {
|
|
36
|
+
container: pipWindow.document.body
|
|
37
|
+
},
|
|
38
|
+
children: [
|
|
39
|
+
renderPortalContent?.(pipWindow),
|
|
40
|
+
children
|
|
41
|
+
]
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
}), pipWindow.document.body);
|
|
45
|
+
}
|
|
46
|
+
export { PictureInPicturePortal };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DateTimeInput } from '../dateTime/index.js';
|
|
2
|
+
import { type FormattingSnapshot } from '../dateTime/config.js';
|
|
3
|
+
export type RelaxedDateType = DateTimeInput;
|
|
4
|
+
export interface RelativeTimeOptions {
|
|
5
|
+
prefix?: string;
|
|
6
|
+
/** Fuzzy preserves thresholds; English keeps articles, other locales use numeric counts. */
|
|
7
|
+
rounding?: 'fuzzy' | 'unit';
|
|
8
|
+
/** Unit width when rounding is "unit". */
|
|
9
|
+
style?: 'long' | 'short' | 'narrow';
|
|
10
|
+
suffix?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function getDateObj(date: RelaxedDateType): Date;
|
|
13
|
+
export declare function formatRelativeDate(date: DateTimeInput, { suffix, prefix, style, rounding }: RelativeTimeOptions, snapshot: Readonly<FormattingSnapshot>): string;
|
|
14
|
+
export declare function getRelativeDate(date: DateTimeInput, options?: RelativeTimeOptions): string;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { getSnapshot } from "../dateTime/config.js";
|
|
3
|
+
import { getIntlFormatter } from "../dateTime/intlFormatter.js";
|
|
4
|
+
import { parseDate } from "../dateTime/parseDate.js";
|
|
5
|
+
import { getDurationWithMessages } from "../duration/getDuration.js";
|
|
6
|
+
function getDateObj(date) {
|
|
7
|
+
return 'string' == typeof date || 'number' == typeof date ? new Date(date) : date;
|
|
8
|
+
}
|
|
9
|
+
function getFuzzyDuration(value, now) {
|
|
10
|
+
const milliseconds = Math.abs(value.epochMilliseconds - now.epochMilliseconds);
|
|
11
|
+
const seconds = Math.round(milliseconds / 1000);
|
|
12
|
+
if (seconds <= 44) return {
|
|
13
|
+
unit: 'second',
|
|
14
|
+
count: seconds
|
|
15
|
+
};
|
|
16
|
+
for (const { unit, size, limit } of [
|
|
17
|
+
{
|
|
18
|
+
unit: 'minute',
|
|
19
|
+
size: 60000,
|
|
20
|
+
limit: 45
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
unit: 'hour',
|
|
24
|
+
size: 3600000,
|
|
25
|
+
limit: 22
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
unit: 'day',
|
|
29
|
+
size: 86400000,
|
|
30
|
+
limit: 26
|
|
31
|
+
}
|
|
32
|
+
]){
|
|
33
|
+
const count = Math.round(milliseconds / size);
|
|
34
|
+
if (count <= 1) return {
|
|
35
|
+
unit,
|
|
36
|
+
count: 1
|
|
37
|
+
};
|
|
38
|
+
if (count < limit) return {
|
|
39
|
+
unit,
|
|
40
|
+
count
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const earlier = value.epochNanoseconds < now.epochNanoseconds ? value : now;
|
|
44
|
+
const later = earlier === value ? now : value;
|
|
45
|
+
let wholeMonths = (later.year - earlier.year) * 12 + later.month - earlier.month;
|
|
46
|
+
let anchor;
|
|
47
|
+
try {
|
|
48
|
+
anchor = earlier.add({
|
|
49
|
+
months: wholeMonths
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (!(error instanceof RangeError)) throw error;
|
|
53
|
+
anchor = earlier.add({
|
|
54
|
+
months: --wholeMonths
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
if (anchor.epochNanoseconds > later.epochNanoseconds) anchor = earlier.add({
|
|
58
|
+
months: --wholeMonths
|
|
59
|
+
});
|
|
60
|
+
const remainder = later.epochMilliseconds - anchor.epochMilliseconds;
|
|
61
|
+
const months = wholeMonths + remainder / 86400000 * (4800 / 146097);
|
|
62
|
+
const roundedMonths = Math.round(months);
|
|
63
|
+
return roundedMonths < 11 ? {
|
|
64
|
+
unit: 'month',
|
|
65
|
+
count: Math.max(1, roundedMonths)
|
|
66
|
+
} : {
|
|
67
|
+
unit: 'year',
|
|
68
|
+
count: Math.max(1, Math.round(months / 12))
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function englishFuzzyDuration(unit, count) {
|
|
72
|
+
if ('second' === unit) return 'a few seconds';
|
|
73
|
+
if (1 === count) return 'hour' === unit ? 'an hour' : `a ${unit}`;
|
|
74
|
+
return `${count} ${unit}s`;
|
|
75
|
+
}
|
|
76
|
+
function formatRelativeDate(date, { suffix, prefix, style = 'long', rounding = 'fuzzy' }, snapshot) {
|
|
77
|
+
const value = parseDate(date, snapshot.timezone);
|
|
78
|
+
if (!value) return 'Invalid date';
|
|
79
|
+
const now = Temporal.Instant.fromEpochMilliseconds(Date.now()).toZonedDateTimeISO(snapshot.timezone);
|
|
80
|
+
const isFuture = value.epochNanoseconds > now.epochNanoseconds;
|
|
81
|
+
let duration;
|
|
82
|
+
if ('fuzzy' === rounding) {
|
|
83
|
+
const { unit, count } = getFuzzyDuration(value, now);
|
|
84
|
+
const isEnglish = 'en' === snapshot.locale.toLowerCase().split('-')[0];
|
|
85
|
+
if (!isEnglish && (isFuture ? prefix : suffix) === void 0) return getIntlFormatter(Intl.RelativeTimeFormat, snapshot.locale, {
|
|
86
|
+
numeric: 'always'
|
|
87
|
+
}).format(isFuture ? count : -count, unit);
|
|
88
|
+
duration = isEnglish ? englishFuzzyDuration(unit, count) : getIntlFormatter(Intl.NumberFormat, snapshot.locale, {
|
|
89
|
+
style: 'unit',
|
|
90
|
+
unit,
|
|
91
|
+
unitDisplay: 'long'
|
|
92
|
+
}).format(count);
|
|
93
|
+
} else duration = getDurationWithMessages(Math.trunc((now.epochMilliseconds - value.epochMilliseconds) / 1000), {
|
|
94
|
+
style,
|
|
95
|
+
absolute: isFuture
|
|
96
|
+
}, snapshot.messages);
|
|
97
|
+
if (isFuture) {
|
|
98
|
+
if (void 0 === prefix) return `${snapshot.messages.t('in')} ${duration}`;
|
|
99
|
+
return prefix ? `${prefix} ${duration}` : duration;
|
|
100
|
+
}
|
|
101
|
+
if (void 0 === suffix) return snapshot.messages.t('%s ago', duration);
|
|
102
|
+
return suffix ? `${duration} ${suffix}` : duration;
|
|
103
|
+
}
|
|
104
|
+
function getRelativeDate(date, options = {}) {
|
|
105
|
+
return formatRelativeDate(date, options, getSnapshot());
|
|
106
|
+
}
|
|
107
|
+
export { formatRelativeDate, getDateObj, getRelativeDate };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { RelativeTime, RELATIVE_TIME_MAX_WIDTH, type RelativeTimeProps, } from './relativeTime.js';
|
|
2
|
+
export { getDateObj, getRelativeDate, type RelaxedDateType, type RelativeTimeOptions, } from './getRelativeDate.js';
|
|
3
|
+
export { useRelativeTimeFormatter } from './useRelativeTimeFormatter.js';
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import { type RelaxedDateType, type RelativeTimeOptions } from './getRelativeDate.js';
|
|
3
|
+
/** Allow room for offset labels such as GMT+5:45 without wrapping timestamp rows. */
|
|
4
|
+
export declare const RELATIVE_TIME_MAX_WIDTH = 280;
|
|
5
|
+
export interface RelativeTimeProps extends RelativeTimeOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The date value, can be string, number (e.g. timestamp), or instance of Date
|
|
8
|
+
*/
|
|
9
|
+
date: RelaxedDateType;
|
|
10
|
+
/**
|
|
11
|
+
* What the timestamp refers to, e.g. "Last Seen". Rendered in a header
|
|
12
|
+
* alongside the relative time.
|
|
13
|
+
*
|
|
14
|
+
* Optional because most timestamps in the app are already labelled by what
|
|
15
|
+
* they sit next to. Without one there is no header, and the card is the two
|
|
16
|
+
* timezone rows on their own.
|
|
17
|
+
*/
|
|
18
|
+
label?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Prefix before upcoming time (when the date is in the future)
|
|
21
|
+
*
|
|
22
|
+
* @default "in"
|
|
23
|
+
*/
|
|
24
|
+
prefix?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Show seconds on the absolute times. For timestamps precise enough that the
|
|
27
|
+
* minute alone does not identify them, e.g. spans in a trace.
|
|
28
|
+
*/
|
|
29
|
+
showSeconds?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Suffix after elapsed time e.g. "ago" in "5 minutes ago"
|
|
32
|
+
*
|
|
33
|
+
* @default "ago"
|
|
34
|
+
*/
|
|
35
|
+
suffix?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A detail card for a single timestamp, showing the relative time alongside the
|
|
39
|
+
* absolute time in both the viewer's timezone and UTC.
|
|
40
|
+
*
|
|
41
|
+
* This is tooltip content rather than a standalone element. `TimeSince` renders
|
|
42
|
+
* it for you; reach for it directly only when you are building the tooltip
|
|
43
|
+
* yourself. The overlay drops its own padding on seeing the sections this
|
|
44
|
+
* composes, so there is nothing to pass but the card's width:
|
|
45
|
+
*
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <Tooltip
|
|
48
|
+
* maxWidth={RELATIVE_TIME_MAX_WIDTH}
|
|
49
|
+
* title={<RelativeTime date={date} label={t('Last Seen')} />}
|
|
50
|
+
* >
|
|
51
|
+
* {trigger}
|
|
52
|
+
* </Tooltip>
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function RelativeTime({ date, label, prefix, suffix, rounding, style, showSeconds, }: RelativeTimeProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import styled from "@emotion/styled";
|
|
4
|
+
import { Tag } from "../badge/index.js";
|
|
5
|
+
import { DateTime } from "../dateTime/index.js";
|
|
6
|
+
import { DescriptionList } from "../descriptionList/index.js";
|
|
7
|
+
import { Text } from "../text/index.js";
|
|
8
|
+
import { Tooltip } from "../tooltip/index.js";
|
|
9
|
+
import { useFormattingSnapshot } from "../dateTime/context.js";
|
|
10
|
+
import { formatTimezone } from "../dateTime/format.js";
|
|
11
|
+
import { parseDate } from "../dateTime/parseDate.js";
|
|
12
|
+
import { formatRelativeDate } from "./getRelativeDate.js";
|
|
13
|
+
const RELATIVE_TIME_MAX_WIDTH = 280;
|
|
14
|
+
const UTC = 'UTC';
|
|
15
|
+
function RelativeTime({ date, label, prefix, suffix, rounding, style, showSeconds }) {
|
|
16
|
+
const snapshot = useFormattingSnapshot();
|
|
17
|
+
const value = parseDate(date, snapshot.timezone);
|
|
18
|
+
const abbreviation = value ? formatTimezone(value.epochMilliseconds, snapshot.timezone, snapshot) : 'Invalid date';
|
|
19
|
+
const isViewerUtc = abbreviation === UTC;
|
|
20
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
21
|
+
children: [
|
|
22
|
+
null != label && /*#__PURE__*/ jsx(Tooltip.Header, {
|
|
23
|
+
trailingItems: formatRelativeDate(date, {
|
|
24
|
+
suffix,
|
|
25
|
+
prefix,
|
|
26
|
+
rounding,
|
|
27
|
+
style
|
|
28
|
+
}, snapshot),
|
|
29
|
+
children: label
|
|
30
|
+
}),
|
|
31
|
+
/*#__PURE__*/ jsx(Tooltip.Grid, {
|
|
32
|
+
children: /*#__PURE__*/ jsxs(DescriptionList, {
|
|
33
|
+
columns: "max-content 1fr max-content",
|
|
34
|
+
gap: "2xs sm",
|
|
35
|
+
align: "center",
|
|
36
|
+
children: [
|
|
37
|
+
!isViewerUtc && /*#__PURE__*/ jsx(TimestampRow, {
|
|
38
|
+
date: date,
|
|
39
|
+
abbreviation: abbreviation,
|
|
40
|
+
variant: "info",
|
|
41
|
+
showSeconds: showSeconds
|
|
42
|
+
}),
|
|
43
|
+
/*#__PURE__*/ jsx(TimestampRow, {
|
|
44
|
+
date: date,
|
|
45
|
+
abbreviation: UTC,
|
|
46
|
+
variant: "muted",
|
|
47
|
+
showSeconds: showSeconds,
|
|
48
|
+
utc: true
|
|
49
|
+
})
|
|
50
|
+
]
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function TimestampRow({ date, abbreviation, variant, showSeconds, utc }) {
|
|
57
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
58
|
+
children: [
|
|
59
|
+
/*#__PURE__*/ jsx(DescriptionList.Term, {
|
|
60
|
+
children: /*#__PURE__*/ jsx(TimezoneTag, {
|
|
61
|
+
variant: variant,
|
|
62
|
+
children: abbreviation
|
|
63
|
+
})
|
|
64
|
+
}),
|
|
65
|
+
/*#__PURE__*/ jsx(DescriptionList.Details, {
|
|
66
|
+
children: /*#__PURE__*/ jsx(Text, {
|
|
67
|
+
tabular: true,
|
|
68
|
+
wrap: "nowrap",
|
|
69
|
+
children: /*#__PURE__*/ jsx(DateTime, {
|
|
70
|
+
date: date,
|
|
71
|
+
mode: "date",
|
|
72
|
+
year: "always",
|
|
73
|
+
timezone: utc ? 'UTC' : void 0,
|
|
74
|
+
showTimezone: false
|
|
75
|
+
})
|
|
76
|
+
})
|
|
77
|
+
}),
|
|
78
|
+
/*#__PURE__*/ jsx(DescriptionList.Details, {
|
|
79
|
+
children: /*#__PURE__*/ jsx(Text, {
|
|
80
|
+
align: "right",
|
|
81
|
+
tabular: true,
|
|
82
|
+
wrap: "nowrap",
|
|
83
|
+
children: /*#__PURE__*/ jsx(DateTime, {
|
|
84
|
+
date: date,
|
|
85
|
+
mode: "time",
|
|
86
|
+
precision: showSeconds ? 'second' : 'minute',
|
|
87
|
+
timezone: utc ? 'UTC' : void 0,
|
|
88
|
+
showTimezone: false
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const TimezoneTag = styled(Tag)`
|
|
96
|
+
height: 17px;
|
|
97
|
+
min-width: 20px;
|
|
98
|
+
justify-content: center;
|
|
99
|
+
padding: 0 ${(p)=>p.theme.space.xs};
|
|
100
|
+
border-radius: ${(p)=>p.theme.radius['2xs']};
|
|
101
|
+
`;
|
|
102
|
+
export { RELATIVE_TIME_MAX_WIDTH, RelativeTime };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useFormattingSnapshot } from "../dateTime/context.js";
|
|
3
|
+
import { formatRelativeDate } from "./getRelativeDate.js";
|
|
4
|
+
function useRelativeTimeFormatter() {
|
|
5
|
+
const snapshot = useFormattingSnapshot();
|
|
6
|
+
return useCallback((date, options = {})=>formatRelativeDate(date, options, snapshot), [
|
|
7
|
+
snapshot
|
|
8
|
+
]);
|
|
9
|
+
}
|
|
10
|
+
export { useRelativeTimeFormatter };
|
|
@@ -7,7 +7,7 @@ import { Item, useCollection } from "@react-stately/collections";
|
|
|
7
7
|
import { ListCollection } from "@react-stately/list";
|
|
8
8
|
import { useRadioGroupState } from "@react-stately/radio";
|
|
9
9
|
import { LayoutGroup } from "framer-motion";
|
|
10
|
-
import { DO_NOT_USE_getButtonStyles } from "../button/
|
|
10
|
+
import { DO_NOT_USE_getButtonStyles } from "../button/styles.js";
|
|
11
11
|
import { Tooltip } from "../tooltip/index.js";
|
|
12
12
|
const getChildTransforms = (count)=>Array.from({
|
|
13
13
|
length: count
|