plass-ui 1.3.0 → 1.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/CHANGELOG.md +590 -0
- package/README.md +1 -1
- package/dist/components/alert/PlAlert.js +1 -1
- package/dist/components/anchor/PlAnchor.d.ts +72 -0
- package/dist/components/anchor/PlAnchor.js +1 -0
- package/dist/components/anchor/index.d.ts +2 -0
- package/dist/components/anchor/index.js +1 -0
- package/dist/components/animate-appear/PlAnimateAppear.d.ts +10 -0
- package/dist/components/animate-appear/PlAnimateAppear.js +1 -1
- package/dist/components/animate-blink/PlAnimateBlink.d.ts +2 -2
- package/dist/components/animate-blink/PlAnimateBlink.js +1 -1
- package/dist/components/animate-counter/PlAnimateCounter.d.ts +83 -0
- package/dist/components/animate-counter/PlAnimateCounter.js +1 -0
- package/dist/components/animate-counter/index.d.ts +2 -0
- package/dist/components/animate-counter/index.js +1 -0
- package/dist/components/animate-fade/PlAnimateFade.d.ts +2 -2
- package/dist/components/animate-fade/PlAnimateFade.js +1 -1
- package/dist/components/animate-float/PlAnimateFloat.d.ts +51 -0
- package/dist/components/animate-float/PlAnimateFloat.js +1 -0
- package/dist/components/animate-float/index.d.ts +2 -0
- package/dist/components/animate-float/index.js +1 -0
- package/dist/components/animate-grow/PlAnimateGrow.d.ts +2 -2
- package/dist/components/animate-grow/PlAnimateGrow.js +1 -1
- package/dist/components/animate-reveal/PlAnimateReveal.d.ts +51 -0
- package/dist/components/animate-reveal/PlAnimateReveal.js +1 -0
- package/dist/components/animate-reveal/index.d.ts +2 -0
- package/dist/components/animate-reveal/index.js +1 -0
- package/dist/components/animate-rotate/PlAnimateRotate.d.ts +2 -2
- package/dist/components/animate-rotate/PlAnimateRotate.js +1 -1
- package/dist/components/animate-scramble/PlAnimateScramble.d.ts +75 -0
- package/dist/components/animate-scramble/PlAnimateScramble.js +1 -0
- package/dist/components/animate-scramble/index.d.ts +2 -0
- package/dist/components/animate-scramble/index.js +1 -0
- package/dist/components/animate-shake/PlAnimateShake.d.ts +57 -0
- package/dist/components/animate-shake/PlAnimateShake.js +1 -0
- package/dist/components/animate-shake/index.d.ts +2 -0
- package/dist/components/animate-shake/index.js +1 -0
- package/dist/components/animate-slide/PlAnimateSlide.d.ts +2 -2
- package/dist/components/animate-slide/PlAnimateSlide.js +1 -1
- package/dist/components/animate-split/PlAnimateSplit.d.ts +54 -0
- package/dist/components/animate-split/PlAnimateSplit.js +1 -0
- package/dist/components/animate-split/index.d.ts +2 -0
- package/dist/components/animate-split/index.js +1 -0
- package/dist/components/animate-zoom/PlAnimateZoom.d.ts +2 -2
- package/dist/components/animate-zoom/PlAnimateZoom.js +1 -1
- package/dist/components/app-logo/PlAppLogo.d.ts +78 -0
- package/dist/components/app-logo/PlAppLogo.js +1 -0
- package/dist/components/app-logo/index.d.ts +2 -0
- package/dist/components/app-logo/index.js +1 -0
- package/dist/components/area-chart/PlAreaChart.d.ts +54 -0
- package/dist/components/area-chart/PlAreaChart.js +1 -0
- package/dist/components/area-chart/index.d.ts +2 -0
- package/dist/components/area-chart/index.js +1 -0
- package/dist/components/avatar/PlAvatar.js +1 -1
- package/dist/components/back-top/PlBackTop.js +1 -1
- package/dist/components/bar-chart/PlBarChart.d.ts +63 -0
- package/dist/components/bar-chart/PlBarChart.js +1 -0
- package/dist/components/bar-chart/index.d.ts +2 -0
- package/dist/components/bar-chart/index.js +1 -0
- package/dist/components/breadcrumb/PlBreadcrumb.js +1 -1
- package/dist/components/button-group/PlButtonGroup.js +1 -1
- package/dist/components/carousel/PlCarousel.js +1 -1
- package/dist/components/chat-bubble/PlChatBubble.js +1 -1
- package/dist/components/checkbox/PlCheckbox.js +1 -1
- package/dist/components/chip/PlChip.js +1 -1
- package/dist/components/code-block/PlCodeBlock.d.ts +175 -0
- package/dist/components/code-block/PlCodeBlock.js +1 -0
- package/dist/components/code-block/index.d.ts +2 -0
- package/dist/components/code-block/index.js +1 -0
- package/dist/components/combobox/PlCombobox.d.ts +1 -1
- package/dist/components/combobox/PlCombobox.js +1 -1
- package/dist/components/command-palette/PlCommandPalette.d.ts +1 -1
- package/dist/components/command-palette/PlCommandPalette.js +1 -1
- package/dist/components/container/PlContainer.d.ts +22 -6
- package/dist/components/container/PlContainer.js +1 -1
- package/dist/components/data-list/PlDataList.d.ts +74 -0
- package/dist/components/data-list/PlDataList.js +1 -0
- package/dist/components/data-list/index.d.ts +2 -0
- package/dist/components/data-list/index.js +1 -0
- package/dist/components/data-table/PlDataTable.d.ts +202 -0
- package/dist/components/data-table/PlDataTable.js +1 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +1 -0
- package/dist/components/drawer/PlDrawer.d.ts +1 -1
- package/dist/components/drawer/PlDrawer.js +1 -1
- package/dist/components/flex/PlFlex.d.ts +83 -0
- package/dist/components/flex/PlFlex.js +1 -0
- package/dist/components/flex/index.d.ts +2 -0
- package/dist/components/flex/index.js +1 -0
- package/dist/components/floating-action-button/PlFloatingActionButton.d.ts +81 -0
- package/dist/components/floating-action-button/PlFloatingActionButton.js +1 -0
- package/dist/components/floating-action-button/index.d.ts +2 -0
- package/dist/components/floating-action-button/index.js +1 -0
- package/dist/components/footer/PlFooter.d.ts +4 -3
- package/dist/components/footer/PlFooter.js +1 -1
- package/dist/components/gallery/PlGallery.d.ts +154 -0
- package/dist/components/gallery/PlGallery.js +1 -0
- package/dist/components/gallery/PlGalleryViewer.d.ts +31 -0
- package/dist/components/gallery/PlGalleryViewer.js +1 -0
- package/dist/components/gallery/index.d.ts +2 -0
- package/dist/components/gallery/index.js +1 -0
- package/dist/components/gauge-chart/PlGaugeChart.d.ts +64 -0
- package/dist/components/gauge-chart/PlGaugeChart.js +1 -0
- package/dist/components/gauge-chart/index.d.ts +2 -0
- package/dist/components/gauge-chart/index.js +1 -0
- package/dist/components/grid/PlGrid.js +1 -1
- package/dist/components/grid/PlGridItem.js +1 -1
- package/dist/components/header/PlHeader.d.ts +4 -3
- package/dist/components/header/PlHeader.js +1 -1
- package/dist/components/heatmap-chart/PlHeatmapChart.d.ts +69 -0
- package/dist/components/heatmap-chart/PlHeatmapChart.js +1 -0
- package/dist/components/heatmap-chart/index.d.ts +2 -0
- package/dist/components/heatmap-chart/index.js +1 -0
- package/dist/components/hover-card/PlHoverCard.d.ts +94 -0
- package/dist/components/hover-card/PlHoverCard.js +1 -0
- package/dist/components/hover-card/index.d.ts +2 -0
- package/dist/components/hover-card/index.js +1 -0
- package/dist/components/how-to-steps/PlHowToSteps.d.ts +87 -0
- package/dist/components/how-to-steps/PlHowToSteps.js +1 -0
- package/dist/components/how-to-steps/index.d.ts +2 -0
- package/dist/components/how-to-steps/index.js +1 -0
- package/dist/components/image/PlImage.js +1 -1
- package/dist/components/line-chart/PlLineChart.d.ts +74 -0
- package/dist/components/line-chart/PlLineChart.js +1 -0
- package/dist/components/line-chart/index.d.ts +2 -0
- package/dist/components/line-chart/index.js +1 -0
- package/dist/components/meter/PlMeter.d.ts +83 -0
- package/dist/components/meter/PlMeter.js +1 -0
- package/dist/components/meter/index.d.ts +2 -0
- package/dist/components/meter/index.js +1 -0
- package/dist/components/mockup/PlMockup.d.ts +146 -0
- package/dist/components/mockup/PlMockup.js +1 -0
- package/dist/components/mockup/index.d.ts +2 -0
- package/dist/components/mockup/index.js +1 -0
- package/dist/components/modal/PlModal.d.ts +1 -1
- package/dist/components/modal/PlModal.js +1 -1
- package/dist/components/number-field/PlNumberField.d.ts +1 -1
- package/dist/components/number-field/PlNumberField.js +1 -1
- package/dist/components/overlay/PlOverlay.d.ts +1 -1
- package/dist/components/overlay/PlOverlay.js +1 -1
- package/dist/components/page-layout/PlPageLayout.js +1 -1
- package/dist/components/pagination/PlPagination.js +1 -1
- package/dist/components/panes/PlPanes.d.ts +2 -2
- package/dist/components/panes/PlPanes.js +1 -1
- package/dist/components/pie-chart/PlPieChart.d.ts +58 -0
- package/dist/components/pie-chart/PlPieChart.js +1 -0
- package/dist/components/pie-chart/index.d.ts +2 -0
- package/dist/components/pie-chart/index.js +1 -0
- package/dist/components/popconfirm/PlPopconfirm.d.ts +1 -1
- package/dist/components/popconfirm/PlPopconfirm.js +1 -1
- package/dist/components/popover/PlPopover.d.ts +1 -1
- package/dist/components/popover/PlPopover.js +1 -1
- package/dist/components/portal/PlPortal.d.ts +78 -0
- package/dist/components/portal/PlPortal.js +1 -0
- package/dist/components/portal/index.d.ts +2 -0
- package/dist/components/portal/index.js +1 -0
- package/dist/components/radio-group/PlRadioGroup.js +1 -1
- package/dist/components/rating/PlRating.js +1 -1
- package/dist/components/scatter-chart/PlScatterChart.d.ts +46 -0
- package/dist/components/scatter-chart/PlScatterChart.js +1 -0
- package/dist/components/scatter-chart/index.d.ts +2 -0
- package/dist/components/scatter-chart/index.js +1 -0
- package/dist/components/scroll-area/PlScrollArea.d.ts +98 -0
- package/dist/components/scroll-area/PlScrollArea.js +1 -0
- package/dist/components/scroll-area/index.d.ts +2 -0
- package/dist/components/scroll-area/index.js +1 -0
- package/dist/components/scroll-zone/PlScrollZone.d.ts +9 -5
- package/dist/components/scroll-zone/PlScrollZone.js +1 -1
- package/dist/components/select/PlSelect.js +1 -1
- package/dist/components/show/PlShow.d.ts +60 -0
- package/dist/components/show/PlShow.js +1 -0
- package/dist/components/show/index.d.ts +2 -0
- package/dist/components/show/index.js +1 -0
- package/dist/components/sidebar/PlSidebar.js +1 -1
- package/dist/components/slider/PlSlider.js +1 -1
- package/dist/components/sparkline/PlSparkline.d.ts +68 -0
- package/dist/components/sparkline/PlSparkline.js +1 -0
- package/dist/components/sparkline/index.d.ts +2 -0
- package/dist/components/sparkline/index.js +1 -0
- package/dist/components/spoiler/PlSpoiler.d.ts +8 -0
- package/dist/components/spoiler/PlSpoiler.js +1 -1
- package/dist/components/stack/PlStack.d.ts +114 -0
- package/dist/components/stack/PlStack.js +1 -0
- package/dist/components/stack/index.d.ts +2 -0
- package/dist/components/stack/index.js +1 -0
- package/dist/components/stepper/PlStepper.d.ts +2 -2
- package/dist/components/stepper/PlStepper.js +1 -1
- package/dist/components/table/PlTable.js +1 -1
- package/dist/components/tabs/PlTabs.d.ts +2 -2
- package/dist/components/tabs/PlTabs.js +1 -1
- package/dist/components/text-link/PlTextLink.js +1 -1
- package/dist/components/timeline/PlTimeline.d.ts +2 -2
- package/dist/components/timeline/PlTimeline.js +1 -1
- package/dist/components/timeline-chart/PlTimelineChart.d.ts +44 -0
- package/dist/components/timeline-chart/PlTimelineChart.js +1 -0
- package/dist/components/timeline-chart/index.d.ts +2 -0
- package/dist/components/timeline-chart/index.js +1 -0
- package/dist/components/toast/PlToast.d.ts +1 -1
- package/dist/components/toast/PlToast.js +1 -1
- package/dist/components/toggle/PlToggle.js +1 -1
- package/dist/components/toggle/PlToggleGroup.js +1 -1
- package/dist/components/tour/PlTour.d.ts +134 -0
- package/dist/components/tour/PlTour.js +1 -0
- package/dist/components/tour/index.d.ts +2 -0
- package/dist/components/tour/index.js +1 -0
- package/dist/components/transfer/PlTransfer.js +1 -1
- package/dist/components/tree/PlTree.js +1 -1
- package/dist/components/tree-select/PlTreeSelect.d.ts +99 -0
- package/dist/components/tree-select/PlTreeSelect.js +1 -0
- package/dist/components/tree-select/index.d.ts +2 -0
- package/dist/components/tree-select/index.js +1 -0
- package/dist/components/window-pane/PlWindowPane.d.ts +179 -0
- package/dist/components/window-pane/PlWindowPane.js +1 -0
- package/dist/components/window-pane/index.d.ts +2 -0
- package/dist/components/window-pane/index.js +1 -0
- package/dist/css/anchor.css +2 -0
- package/dist/css/animate-counter.css +2 -0
- package/dist/css/animate-float.css +2 -0
- package/dist/css/animate-reveal.css +2 -0
- package/dist/css/animate-scramble.css +2 -0
- package/dist/css/animate-shake.css +2 -0
- package/dist/css/animate-split.css +2 -0
- package/dist/css/app-logo.css +2 -0
- package/dist/css/area-chart.css +2 -0
- package/dist/css/bar-chart.css +2 -0
- package/dist/css/code-block.css +2 -0
- package/dist/css/data-list.css +2 -0
- package/dist/css/data-table.css +2 -0
- package/dist/css/flex.css +2 -0
- package/dist/css/floating-action-button.css +2 -0
- package/dist/css/gallery.css +2 -0
- package/dist/css/gauge-chart.css +2 -0
- package/dist/css/heatmap-chart.css +2 -0
- package/dist/css/hover-card.css +2 -0
- package/dist/css/how-to-steps.css +2 -0
- package/dist/css/line-chart.css +2 -0
- package/dist/css/meter.css +2 -0
- package/dist/css/mockup.css +2 -0
- package/dist/css/pie-chart.css +2 -0
- package/dist/css/portal.css +2 -0
- package/dist/css/scatter-chart.css +2 -0
- package/dist/css/scroll-area.css +2 -0
- package/dist/css/show.css +2 -0
- package/dist/css/sparkline.css +2 -0
- package/dist/css/stack.css +2 -0
- package/dist/css/timeline-chart.css +2 -0
- package/dist/css/tour.css +2 -0
- package/dist/css/tree-select.css +2 -0
- package/dist/css/window-pane.css +2 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/usePlBreakpoint.d.ts +3 -0
- package/dist/hooks/usePlBreakpoint.js +1 -1
- package/dist/hooks/usePlDisclosure.d.ts +44 -0
- package/dist/hooks/usePlDisclosure.js +1 -0
- package/dist/hooks/usePlElementSize.d.ts +31 -0
- package/dist/hooks/usePlElementSize.js +1 -0
- package/dist/hooks/usePlOnScreen.d.ts +50 -0
- package/dist/hooks/usePlOnScreen.js +1 -0
- package/dist/index.d.ts +34 -1
- package/dist/index.js +1 -1
- package/dist/internal/animate.d.ts +91 -5
- package/dist/internal/animate.js +1 -1
- package/dist/internal/breakpoints.d.ts +31 -0
- package/dist/internal/breakpoints.js +1 -0
- package/dist/internal/button-group.d.ts +29 -2
- package/dist/internal/button-group.js +2 -2
- package/dist/internal/calendar.d.ts +11 -36
- package/dist/internal/calendar.js +1 -1
- package/dist/internal/chart-frame.d.ts +458 -0
- package/dist/internal/chart-frame.js +1 -0
- package/dist/internal/chart-line.d.ts +44 -0
- package/dist/internal/chart-line.js +1 -0
- package/dist/internal/chart.d.ts +473 -0
- package/dist/internal/chart.js +1 -0
- package/dist/internal/data-table.d.ts +69 -0
- package/dist/internal/data-table.js +1 -0
- package/dist/internal/defaults.d.ts +8 -3
- package/dist/internal/drag.d.ts +49 -0
- package/dist/internal/drag.js +1 -0
- package/dist/internal/format.d.ts +2 -0
- package/dist/internal/format.js +1 -1
- package/dist/internal/gallery.d.ts +34 -0
- package/dist/internal/gallery.js +1 -0
- package/dist/internal/grid.d.ts +6 -27
- package/dist/internal/grid.js +1 -1
- package/dist/internal/highlight.d.ts +98 -0
- package/dist/internal/highlight.js +1 -0
- package/dist/internal/icons.d.ts +10 -0
- package/dist/internal/icons.js +1 -1
- package/dist/internal/labels.d.ts +138 -0
- package/dist/internal/labels.js +1 -0
- package/dist/internal/mockup.d.ts +193 -0
- package/dist/internal/mockup.js +1 -0
- package/dist/internal/page-layout.js +1 -1
- package/dist/internal/progress.d.ts +6 -0
- package/dist/internal/responsive.d.ts +108 -0
- package/dist/internal/responsive.js +1 -0
- package/dist/internal/scramble.d.ts +31 -0
- package/dist/internal/scramble.js +1 -0
- package/dist/internal/styles.d.ts +15 -0
- package/dist/internal/styles.js +1 -1
- package/dist/internal/table.d.ts +86 -0
- package/dist/internal/table.js +1 -0
- package/dist/internal/threshold.d.ts +19 -0
- package/dist/internal/threshold.js +1 -0
- package/dist/internal/tour.d.ts +42 -0
- package/dist/internal/tour.js +1 -0
- package/dist/internal/window.d.ts +201 -0
- package/dist/internal/window.js +1 -0
- package/dist/locales/de.d.ts +3 -0
- package/dist/locales/de.js +1 -0
- package/dist/locales/en.d.ts +2 -0
- package/dist/locales/en.js +1 -0
- package/dist/locales/es.d.ts +3 -0
- package/dist/locales/es.js +1 -0
- package/dist/locales/fr.d.ts +3 -0
- package/dist/locales/fr.js +1 -0
- package/dist/locales/index.d.ts +33 -0
- package/dist/locales/index.js +1 -0
- package/dist/locales/ja.d.ts +3 -0
- package/dist/locales/ja.js +1 -0
- package/dist/locales/ko.d.ts +3 -0
- package/dist/locales/ko.js +1 -0
- package/dist/locales/zh-Hans.d.ts +3 -0
- package/dist/locales/zh-Hans.js +1 -0
- package/dist/provider/index.d.ts +1 -0
- package/dist/provider/index.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/tailwind.css +1104 -19
- package/dist/tokens.css +1104 -19
- package/dist/types.d.ts +381 -2
- package/package.json +14 -4
- package/dist/components/avatar-group/PlAvatarGroup.d.ts +0 -47
- package/dist/components/avatar-group/PlAvatarGroup.js +0 -1
- package/dist/components/avatar-group/index.d.ts +0 -2
- package/dist/components/avatar-group/index.js +0 -1
- package/dist/css/avatar-group.css +0 -2
- package/dist/internal/avatar-group.d.ts +0 -25
- package/dist/internal/avatar-group.js +0 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
+
import type { PlWindowControl, PlWindowOffset, PlWindowOs } from '../../internal/window.js';
|
|
4
|
+
import type { PlassColor, PlassElevation, PlassSize } from '../../types.js';
|
|
5
|
+
export type { PlWindowControl, PlWindowOffset, PlWindowOs } from '../../internal/window.js';
|
|
6
|
+
/** The three CSS positions a window can be laid out with. */
|
|
7
|
+
export type PlWindowPanePosition = 'static' | 'absolute' | 'fixed';
|
|
8
|
+
/** What a resize reports: the window's size in pixels. */
|
|
9
|
+
export interface PlWindowPaneSize {
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
}
|
|
13
|
+
export interface PlWindowPaneProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'color' | 'title' | 'onResize'> {
|
|
14
|
+
/**
|
|
15
|
+
* Whose window this is a picture of. Decides where the controls sit, how they
|
|
16
|
+
* are drawn, how tall the title bar is and how its corners are cut.
|
|
17
|
+
* @default 'macos'
|
|
18
|
+
*/
|
|
19
|
+
os?: PlWindowOs;
|
|
20
|
+
/** The window's name, in the title bar. Also what names the window itself. */
|
|
21
|
+
title?: React.ReactNode;
|
|
22
|
+
/** A glyph beside the title — the app's mark. */
|
|
23
|
+
icon?: React.ReactNode;
|
|
24
|
+
/** Anything else the title bar carries, set beside the controls. */
|
|
25
|
+
actions?: React.ReactNode;
|
|
26
|
+
/**
|
|
27
|
+
* Which of the three buttons the title bar has. `true` is all of them,
|
|
28
|
+
* `false` is none, and an array is exactly the ones named — a window that can
|
|
29
|
+
* be closed but not minimized is `['close']`.
|
|
30
|
+
*
|
|
31
|
+
* The order is the system's rather than the array's: macOS puts close first
|
|
32
|
+
* and Windows puts it last, and that is not something a caller should have to
|
|
33
|
+
* remember.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
controls?: boolean | readonly PlWindowControl[];
|
|
37
|
+
/**
|
|
38
|
+
* The scale of the chrome — the title bar's height, its buttons and its type.
|
|
39
|
+
* It does not touch the content, which is the caller's and is laid out at its
|
|
40
|
+
* own scale, exactly as it would be on a desktop where the title bar does not
|
|
41
|
+
* grow with the document.
|
|
42
|
+
* @default 'md'
|
|
43
|
+
*/
|
|
44
|
+
size?: PlassSize;
|
|
45
|
+
/** The colour family the focus rings and an `accent` title bar take. @default 'primary' */
|
|
46
|
+
color?: PlassColor;
|
|
47
|
+
/**
|
|
48
|
+
* Dyes the title bar with the colour family, the way Windows offers to. Off,
|
|
49
|
+
* the bar is the neutral shade the system draws by default.
|
|
50
|
+
* @default false
|
|
51
|
+
*/
|
|
52
|
+
accent?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* How much of what is behind the window shows through its chrome, from `0` to
|
|
55
|
+
* `1`. It applies to the title bar, the body's own fill and the border —
|
|
56
|
+
* never to the content on it, which stays exactly as legible as it was.
|
|
57
|
+
*
|
|
58
|
+
* Anything above `0` also turns the acrylic on, so the page underneath is
|
|
59
|
+
* blurred rather than merely visible. `1` is a window that is nothing but its
|
|
60
|
+
* edge and its chrome.
|
|
61
|
+
* @default 0
|
|
62
|
+
*/
|
|
63
|
+
transparency?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Whether this is the window in front.
|
|
66
|
+
*
|
|
67
|
+
* Left out, the window works it out for itself: it is in front until another
|
|
68
|
+
* `PlWindowPane` on the page is pressed or takes the focus, exactly as windows on
|
|
69
|
+
* a desktop behave. A click on the page *around* the windows changes nothing
|
|
70
|
+
* — a paragraph is not a desktop.
|
|
71
|
+
*
|
|
72
|
+
* Pass it to drive that yourself, which is what a caller keeping its own
|
|
73
|
+
* z-order wants.
|
|
74
|
+
*
|
|
75
|
+
* What being in front looks like is the system's: coloured traffic lights on
|
|
76
|
+
* macOS against grey ones, an accent title bar and an accent border on
|
|
77
|
+
* Windows 10, a tinted header bar on GNOME — and, on all four, a window one
|
|
78
|
+
* step further off the page than the ones behind it.
|
|
79
|
+
*/
|
|
80
|
+
active?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The shadow around the window. `2` here, against the `0` everything else
|
|
83
|
+
* defaults to, for the reason `PlPill`'s is `2`: a window is by definition not
|
|
84
|
+
* part of the page it is on.
|
|
85
|
+
* @default 2
|
|
86
|
+
*/
|
|
87
|
+
elevation?: PlassElevation;
|
|
88
|
+
/**
|
|
89
|
+
* How the window is laid out. `static` leaves it in the flow (as a
|
|
90
|
+
* relatively positioned box, so `offset` can move it without disturbing
|
|
91
|
+
* anything around it); `absolute` pins it inside the nearest positioned
|
|
92
|
+
* ancestor, which is what a desktop full of windows wants; `fixed` pins it to
|
|
93
|
+
* the viewport.
|
|
94
|
+
* @default 'static'
|
|
95
|
+
*/
|
|
96
|
+
position?: PlWindowPanePosition;
|
|
97
|
+
/** Lets the title bar be dragged. @default false */
|
|
98
|
+
draggable?: boolean;
|
|
99
|
+
/** Lets the edges and corners be dragged. @default false */
|
|
100
|
+
resizable?: boolean;
|
|
101
|
+
/** The window's width — a number in pixels or any CSS length. */
|
|
102
|
+
width?: number | string;
|
|
103
|
+
/** And its height. Left out, the window is as tall as what is in it. */
|
|
104
|
+
height?: number | string;
|
|
105
|
+
/** How small it may be dragged, in pixels. @default 180 */
|
|
106
|
+
minWidth?: number;
|
|
107
|
+
/** The same downward. Defaults to the title bar's own height. */
|
|
108
|
+
minHeight?: number;
|
|
109
|
+
/** How far it has been dragged from where the layout put it. */
|
|
110
|
+
offset?: PlWindowOffset;
|
|
111
|
+
/** Where an uncontrolled window starts. @default { x: 0, y: 0 } */
|
|
112
|
+
defaultOffset?: PlWindowOffset;
|
|
113
|
+
onOffsetChange?: (offset: PlWindowOffset) => void;
|
|
114
|
+
/** Fires with the window's size, in pixels, while an edge is dragged. */
|
|
115
|
+
onResize?: (size: PlWindowPaneSize) => void;
|
|
116
|
+
/** Whether the window is on screen at all. Closing it renders nothing. */
|
|
117
|
+
open?: boolean;
|
|
118
|
+
/** @default true */
|
|
119
|
+
defaultOpen?: boolean;
|
|
120
|
+
onOpenChange?: (open: boolean) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Whether the window is rolled up to its title bar. This is what minimizing
|
|
123
|
+
* means for a window that is part of a page rather than of a desktop: there
|
|
124
|
+
* is no dock for it to go to, so it stays where it is with nothing under the
|
|
125
|
+
* bar.
|
|
126
|
+
*/
|
|
127
|
+
minimized?: boolean;
|
|
128
|
+
/** @default false */
|
|
129
|
+
defaultMinimized?: boolean;
|
|
130
|
+
onMinimizedChange?: (minimized: boolean) => void;
|
|
131
|
+
/**
|
|
132
|
+
* Whether the window fills whatever is holding it. Its corners go square
|
|
133
|
+
* while it does, as they do on every system.
|
|
134
|
+
*/
|
|
135
|
+
maximized?: boolean;
|
|
136
|
+
/** @default false */
|
|
137
|
+
defaultMaximized?: boolean;
|
|
138
|
+
onMaximizedChange?: (maximized: boolean) => void;
|
|
139
|
+
/** Whether content taller than the window scrolls. @default true */
|
|
140
|
+
scroll?: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Overrides the buttons' own names.
|
|
143
|
+
*
|
|
144
|
+
* There is no `locale` here: the words come from `PlassProvider`'s `labels`,
|
|
145
|
+
* which is where every other component in the library gets its own, and these
|
|
146
|
+
* four are the narrower override for one window.
|
|
147
|
+
*/
|
|
148
|
+
minimizeLabel?: string;
|
|
149
|
+
maximizeLabel?: string;
|
|
150
|
+
restoreLabel?: string;
|
|
151
|
+
closeLabel?: string;
|
|
152
|
+
resizeLabel?: string;
|
|
153
|
+
/** Renders something other than a `<div>`: `render={<section />}`. */
|
|
154
|
+
render?: useRender.RenderProp;
|
|
155
|
+
/** What is in the window. */
|
|
156
|
+
children?: React.ReactNode;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* A window, drawn the way one of four systems draws it, with anything at all
|
|
160
|
+
* inside it.
|
|
161
|
+
*
|
|
162
|
+
* It is not a real window and does not pretend to be one: there is no desktop,
|
|
163
|
+
* no z-order and no dock. What it is is a *frame that behaves* — the title bar
|
|
164
|
+
* drags, the corners resize, the three buttons are real buttons with real names
|
|
165
|
+
* — so a screenshot of an app, a demo of a feature or a piece of a landing page
|
|
166
|
+
* can be shown as the thing it will be rather than as a picture of it.
|
|
167
|
+
*
|
|
168
|
+
* Nothing here is transformed. A dragged window moves on `left` and `top` and a
|
|
169
|
+
* resized one changes `width` and `height`, which is what keeps the text inside
|
|
170
|
+
* it at whole pixels through both gestures — a `translate()` would resample
|
|
171
|
+
* every glyph in the window for the length of the drag, which is exactly what
|
|
172
|
+
* the house rule against transforming a surface exists to prevent.
|
|
173
|
+
*
|
|
174
|
+
* `minimize` rolls the window up to its title bar rather than sending it
|
|
175
|
+
* anywhere, because a page has nowhere to send it to. `maximize` fills whatever
|
|
176
|
+
* is holding the window, which is the container for `position="absolute"` and
|
|
177
|
+
* the viewport for `fixed`.
|
|
178
|
+
*/
|
|
179
|
+
export declare const PlWindowPane: React.ForwardRefExoticComponent<PlWindowPaneProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as i from"react";import{useRender as o}from"@base-ui/react/use-render";import{beginPointerDrag as r}from"../../internal/drag.js";import{useLabels as s}from"../../internal/labels.js";import{cx as a,glassClasses as l,hasContent as d,iconClasses as c}from"../../internal/styles.js";import{PlWindowControls as u,orderControls as m,windowChrome as h,windowMetrics as g,windowSlots as f}from"../../internal/window.js";import{useDefaults as w}from"../../internal/defaults.js";function useLatched(e,t,n){const[o,r]=i.useState(t),s=void 0!==e;return[s?e:o,i.useCallback(e=>{s||r(e),n?.(e)},[s,n])]}const p=[{edge:"n",className:"inset-x-3 top-0 h-1.5 cursor-ns-resize"},{edge:"s",className:"inset-x-3 bottom-0 h-1.5 cursor-ns-resize"},{edge:"w",className:"inset-y-3 left-0 w-1.5 cursor-ew-resize"},{edge:"e",className:"inset-y-3 right-0 w-1.5 cursor-ew-resize"},{edge:"nw",className:"top-0 left-0 size-3 cursor-nwse-resize"},{edge:"ne",className:"top-0 right-0 size-3 cursor-nesw-resize"},{edge:"sw",className:"bottom-0 left-0 size-3 cursor-nesw-resize"},{edge:"se",className:"right-0 bottom-0 size-3 cursor-nwse-resize"}];export const PlWindowPane=/* @__PURE__ */i.forwardRef(function PlWindowPane(b,v){const{os:x="macos",title:z,icon:y,actions:N,controls:M=!0,size:C,color:E,accent:L=!1,transparency:S=0,active:k,elevation:R=2,position:j="static",draggable:I=!1,resizable:T=!1,width:D,height:P,minWidth:B=180,minHeight:W,offset:A,defaultOffset:H,onOffsetChange:O,onResize:X,open:$,defaultOpen:G=!0,onOpenChange:F,minimized:U,defaultMinimized:Y=!1,onMinimizedChange:_,maximized:q,defaultMaximized:K=!1,onMaximizedChange:J,scroll:Q=!0,minimizeLabel:V,maximizeLabel:Z,restoreLabel:ee,closeLabel:te,resizeLabel:ne,render:ie,className:oe,style:re,children:se,...ae}=b,le=w(),de=C??le.size??"md",ce=E??le.color??"primary",ue=s(),me=h(x),he=g(x,de),ge=i.useId(),[fe,we]=useLatched($,G,F),[pe,be]=useLatched(U,Y,_),[ve,xe]=useLatched(q,K,J),[ze,ye]=useLatched(A,H??{x:0,y:0},O),[Ne,Me]=i.useState(null),[Ce,Ee]=i.useState(!0),Le=k??Ce,[Se,ke]=i.useState(null),[Re,je]=i.useState(null),[Ie,Te]=i.useState(!1),[De,Pe]=i.useState(!1),[Be,We]=i.useState(fe);Be!==fe&&(We(fe),Pe(!fe)),i.useEffect(()=>{if(!De)return;const e=window.setTimeout(()=>Pe(!1),260);return()=>window.clearTimeout(e)},[De]);const Ae=i.useRef(null),He=i.useCallback(e=>{Ae.current=e,"function"==typeof v?v(e):v&&(v.current=e)},[v]);i.useEffect(()=>{if(void 0!==k)return;const e=Ae.current;if(!e)return;const notice=t=>{const n=t.target;if(!(n instanceof Node))return;if(e.contains(n))return void Ee(!0);const i=n instanceof Element?n:n.parentElement;i?.closest(".plass-window")&&Ee(!1)};return document.addEventListener("pointerdown",notice,!0),document.addEventListener("focusin",notice,!0),()=>{document.removeEventListener("pointerdown",notice,!0),document.removeEventListener("focusin",notice,!0)}},[k]);const Oe=i.useRef(null);function beginGesture(e,t){if(0!==e.button)return;Oe.current?.();const n=e.currentTarget,i=e.clientX,o=e.clientY;Te(!0);const finish=()=>{Oe.current=null,Te(!1)},s=r({target:n,pointerId:e.pointerId,onMove:e=>t(e.clientX-i,e.clientY-o),onEnd:finish});Oe.current=()=>{s(),finish()}}i.useEffect(()=>()=>Oe.current?.(),[]);const Xe={width:Math.max(0,B),height:Math.max(he.bar,W??he.bar)};function resizeTo(e){Me(e),X?.(e)}const $e=m(x,!0===M?["minimize","maximize","close"]:!1===M?[]:M),Ge=$e.includes("maximize");i.useEffect(()=>{if(pe||null===Re)return;const e=window.setTimeout(()=>je(null),400);return()=>window.clearTimeout(e)},[pe,Re]);const Fe={minimize:V??ue.minimize,maximize:Z??ue.maximize,restore:ee??ue.restore,close:te??ue.close},Ue=e(u,{os:x,metrics:he,controls:$e,maximized:ve,active:Le,labels:Fe,onCommand:function command(e){"close"===e?we(!1):"minimize"===e?function rollUp(e){const t=Ae.current,n=t?.firstElementChild;if(t&&n instanceof HTMLElement&&ke(n.offsetHeight+(t.offsetHeight-t.clientHeight)),e&&void 0===(Ne?.height??P)&&t)return je(t.getBoundingClientRect().height),void requestAnimationFrame(()=>be(!0));be(e)}(!pe):xe(!ve)}}),Ye=d(z)?e("span",{id:ge,className:"min-w-0 truncate",children:z}):null,_e=d(y)?e("span",{className:"flex shrink-0 items-center",children:y}):null,qe=t("div",{className:a("relative flex shrink-0 items-center select-none",c,I&&!ve?"cursor-grab active:cursor-grabbing":""),style:{height:he.bar,textShadow:"var(--p-window-bar-shadow)",fontWeight:he.weight,paddingInlineStart:he.padX,paddingInlineEnd:he.padEnd,gap:Math.round(.7*he.title),fontSize:he.title,backgroundColor:"var(--p-window-bar)",backgroundImage:"var(--p-window-bar-image)",color:"var(--p-window-bar-fg)",borderBlockEnd:me.rule?"1px solid var(--p-window-line)":void 0},onPointerDown:function beginDrag(e){if(!I||ve)return;const t={...ze};beginGesture(e,(e,n)=>ye({x:t.x+e,y:t.y+n}))},onDoubleClick:Ge?()=>xe(!ve):void 0,children:["start"===me.controlsSide?Ue:null,"center"===me.titleAlign?e("span",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 flex items-center justify-center",style:{paddingInline:he.controlsWidth($e.length)+2*he.padX},children:t("span",{className:"flex min-w-0 items-center",style:{gap:Math.round(.5*he.title)},children:[_e,Ye]})}):t(n,{children:[_e,Ye]}),e("span",{className:"flex-1"}),d(N)?e("span",{className:"flex shrink-0 items-center",style:{gap:Math.round(.5*he.title)},onPointerDown:e=>e.stopPropagation(),children:N}):null,"end"===me.controlsSide?Ue:null]}),Ke=ve?{left:0,top:0,width:"100%",height:"100%"}:{left:ze.x,top:ze.y,width:Ne?.width??D,height:pe?Se??he.bar:Ne?.height??P??Re??void 0},Je=o({render:ie,ref:He,props:{role:"group","aria-labelledby":Ye?ge:void 0,className:a("plass-window relative flex min-w-0 flex-col overflow-hidden",S>0?l:"",me.glass&&0===S?"[backdrop-filter:var(--plass-blur)]":"","[transition-property:left,top,width,height,opacity,box-shadow,background-color,border-color,border-radius]","[transition-duration:var(--plass-duration-slow)]","[transition-timing-function:var(--plass-ease)]","motion-reduce:[transition-duration:0ms]","data-[gesture]:[transition-property:none]",oe),"data-gesture":Ie?"":void 0,inert:!fe||void 0,style:{opacity:fe?void 0:0,...f({os:x,color:ce,accent:L,transparency:S,active:Le,elevation:R}),position:"static"===j?"relative":j,...Ke,borderRadius:ve?0:`${he.radius}px ${he.radius}px ${he.radiusBottom}px ${he.radiusBottom}px`,borderStyle:"solid",borderWidth:he.frame,borderColor:"var(--p-window-line)",backgroundColor:"var(--p-window-band)",boxShadow:"var(--p-window-shadow), var(--plass-gloss-glass)",...re},children:t(n,{children:[qe,e("div",{className:a("min-h-0 flex-1",Q?"overflow-auto":"overflow-hidden"),style:{backgroundColor:"var(--p-window-body)",marginInline:he.band.side,marginBottom:he.band.bottom,boxShadow:he.band.side>0?"inset 0 0 0 1px rgb(0 0 0 / 0.12)":void 0},inert:pe,children:se}),!T||ve||pe?null:p.map(t=>{const n="se"===t.edge;return e("div",{role:n?"button":void 0,tabIndex:n?0:void 0,"aria-label":n?ne??ue.resizeWindow:void 0,"aria-hidden":n?void 0:"true",className:a("absolute z-10 touch-none",t.className,n?"focus-visible:[outline:2px_solid_var(--p-ring)] focus-visible:[outline-offset:-2px]":""),onPointerDown:e=>function beginResize(e,t){const n=Ae.current;if(!n||ve)return;const i=n.getBoundingClientRect(),o={width:i.width,height:i.height,x:ze.x,y:ze.y},r=e.includes("e"),s=e.includes("w"),a=e.includes("n"),l=e.includes("s");beginGesture(t,(e,t)=>{let{width:n,height:i}=o,{x:d,y:c}=o;r&&(n=Math.max(Xe.width,o.width+e)),l&&(i=Math.max(Xe.height,o.height+t)),s&&(n=Math.max(Xe.width,o.width-e),d=o.x+(o.width-n)),a&&(i=Math.max(Xe.height,o.height-t),c=o.y+(o.height-i)),resizeTo({width:n,height:i}),(s||a)&&ye({x:d,y:c})})}(t.edge,e),onKeyDown:n?e=>{const t={ArrowRight:[16,0],ArrowLeft:[-16,0],ArrowDown:[0,16],ArrowUp:[0,-16]}[e.key];t&&(e.preventDefault(),function nudge(e,t){const n=Ae.current;if(!n)return;const i=n.getBoundingClientRect();resizeTo({width:Math.max(Xe.width,i.width+e),height:Math.max(Xe.height,i.height+t)})}(t[0],t[1]))}:void 0},t.edge)})]}),...ae}});return fe||De?Je:null});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{PlWindowPane}from"./PlWindowPane.js";
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export { usePlBreakpoint, usePlBreakpointValue } from './usePlBreakpoint.js';
|
|
2
2
|
export { usePlColorScheme } from './usePlColorScheme.js';
|
|
3
3
|
export type { PlColorScheme, PlColorSchemeOptions, PlColorSchemeResult, PlResolvedColorScheme } from './usePlColorScheme.js';
|
|
4
|
+
export { usePlDisclosure } from './usePlDisclosure.js';
|
|
5
|
+
export type { PlDisclosureResult } from './usePlDisclosure.js';
|
|
6
|
+
export { usePlElementSize } from './usePlElementSize.js';
|
|
7
|
+
export type { PlElementSize } from './usePlElementSize.js';
|
|
4
8
|
export { usePlHotKeys } from './usePlHotKeys.js';
|
|
5
9
|
export type { PlHotKeysOptions, PlHotKeysTarget } from './usePlHotKeys.js';
|
|
6
10
|
export { usePlMediaQuery } from './usePlMediaQuery.js';
|
|
11
|
+
export { usePlOnScreen } from './usePlOnScreen.js';
|
|
12
|
+
export type { PlOnScreenOptions } from './usePlOnScreen.js';
|
|
7
13
|
export { usePlReducedMotion } from './usePlReducedMotion.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{usePlBreakpoint,usePlBreakpointValue}from"./usePlBreakpoint.js";export{usePlColorScheme}from"./usePlColorScheme.js";export{usePlHotKeys}from"./usePlHotKeys.js";export{usePlMediaQuery}from"./usePlMediaQuery.js";export{usePlReducedMotion}from"./usePlReducedMotion.js";
|
|
1
|
+
export{usePlBreakpoint,usePlBreakpointValue}from"./usePlBreakpoint.js";export{usePlColorScheme}from"./usePlColorScheme.js";export{usePlDisclosure}from"./usePlDisclosure.js";export{usePlElementSize}from"./usePlElementSize.js";export{usePlHotKeys}from"./usePlHotKeys.js";export{usePlMediaQuery}from"./usePlMediaQuery.js";export{usePlOnScreen}from"./usePlOnScreen.js";export{usePlReducedMotion}from"./usePlReducedMotion.js";
|
|
@@ -9,6 +9,9 @@ import type { PlassBreakpoint, PlassResponsive } from '../types.js';
|
|
|
9
9
|
* `md` here switches with the `md:` utilities beside it rather than a few
|
|
10
10
|
* pixels away from them.
|
|
11
11
|
*
|
|
12
|
+
* The widths come off the document — see `internal/breakpoints.ts` — so a
|
|
13
|
+
* project that moves a breakpoint in its Tailwind theme moves this too.
|
|
14
|
+
*
|
|
12
15
|
* **`xs` is the server's answer**, and the first one a browser renders. See
|
|
13
16
|
* `usePlMediaQuery` for what follows from that.
|
|
14
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{
|
|
1
|
+
"use client";import{fromQuery as e}from"../internal/breakpoints.js";import{resolveAt as r}from"../internal/responsive.js";import{useMediaQuery as n}from"../internal/media.js";export function usePlBreakpoint(){const r=n(e("sm")),t=n(e("md")),o=n(e("lg"));return n(e("xl"))?"xl":o?"lg":t?"md":r?"sm":"xs"}export function usePlBreakpointValue(e){return r(e,usePlBreakpoint())}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** What a caller gets back: the answer, and the four ways to change it. */
|
|
2
|
+
export interface PlDisclosureResult {
|
|
3
|
+
/** Whether the thing is open. */
|
|
4
|
+
open: boolean;
|
|
5
|
+
/** Opens it. */
|
|
6
|
+
onOpen: () => void;
|
|
7
|
+
/** Closes it. */
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
/** Turns it round. */
|
|
10
|
+
onToggle: () => void;
|
|
11
|
+
/** Sets it to a value, for the caller who already has one. */
|
|
12
|
+
setOpen: (open: boolean) => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* One boolean and the four callbacks that change it.
|
|
16
|
+
*
|
|
17
|
+
* The smallest hook in the library and the one that saves the most typing: a
|
|
18
|
+
* dialog, a drawer, a popover and a menu each need exactly this, and written by
|
|
19
|
+
* hand it is a `useState` plus three arrow functions **that are new on every
|
|
20
|
+
* render**. That last part is the reason it is worth a hook rather than a
|
|
21
|
+
* snippet — an inline `() => setOpen(false)` handed to a memoised trigger
|
|
22
|
+
* defeats the memo, and every one of the callbacks here is stable for the life
|
|
23
|
+
* of the component.
|
|
24
|
+
*
|
|
25
|
+
* The names are the props they are handed to. `onOpenChange` is the one shape
|
|
26
|
+
* every openable component in this library takes, and `setOpen` fits it
|
|
27
|
+
* exactly, so the ordinary use is a spread:
|
|
28
|
+
*
|
|
29
|
+
* ```tsx
|
|
30
|
+
* const dialog = usePlDisclosure();
|
|
31
|
+
*
|
|
32
|
+
* <PlButton onClick={dialog.onOpen}>Delete</PlButton>
|
|
33
|
+
* <PlModal open={dialog.open} onOpenChange={dialog.setOpen} title="Delete this?">
|
|
34
|
+
* <PlButton onClick={dialog.onClose}>Cancel</PlButton>
|
|
35
|
+
* </PlModal>
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* It holds no DOM, watches nothing and has no effect in it, so it costs the
|
|
39
|
+
* same on a server as it does in a browser.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* const drawer = usePlDisclosure(true);
|
|
43
|
+
*/
|
|
44
|
+
export declare function usePlDisclosure(initial?: boolean): PlDisclosureResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import*as e from"react";export function usePlDisclosure(o=!1){const[s,l]=e.useState(o),n=e.useCallback(()=>l(!0),[]),t=e.useCallback(()=>l(!1),[]),u=e.useCallback(()=>l(e=>!e),[]);return e.useMemo(()=>({open:s,onOpen:n,onClose:t,onToggle:u,setOpen:l}),[s,n,t,u])}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/** The box an element is laid out at, in pixels. */
|
|
3
|
+
export interface PlElementSize {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* How big an element is, kept up to date as it changes.
|
|
9
|
+
*
|
|
10
|
+
* A `ResizeObserver` and the two things a hook has to add. The first is
|
|
11
|
+
* **when**: the size is read in a layout effect as well as from the observer,
|
|
12
|
+
* because an observer's first callback arrives after a frame has been painted
|
|
13
|
+
* and a component that laid itself out from `0 × 0` for one frame flashes.
|
|
14
|
+
*
|
|
15
|
+
* The second is what it reports: the **content box**, the room actually left
|
|
16
|
+
* inside the element once its own padding has been taken off. A hand-written
|
|
17
|
+
* version nearly always reports `getBoundingClientRect` or `borderBoxSize`
|
|
18
|
+
* instead, which is a different number — and the wrong one for the question
|
|
19
|
+
* that made somebody measure the element.
|
|
20
|
+
*
|
|
21
|
+
* `null` until there is an element to measure, which is the honest answer on a
|
|
22
|
+
* server and on the first render: guessing `0` there would let a caller divide
|
|
23
|
+
* by it.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const box = React.useRef<HTMLDivElement>(null);
|
|
27
|
+
* const size = usePlElementSize(box);
|
|
28
|
+
*
|
|
29
|
+
* <div ref={box}>{size ? `${Math.round(size.width)}px` : null}</div>
|
|
30
|
+
*/
|
|
31
|
+
export declare function usePlElementSize(target: React.RefObject<HTMLElement | null>): PlElementSize | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import*as t from"react";export function usePlElementSize(e){const[n,i]=t.useState(null);return t.useLayoutEffect(()=>{const t=e.current;if(!t)return;const read=()=>{const e=function contentBoxOf(t){const e=getComputedStyle(t),n=parseFloat(e.paddingInlineStart)+parseFloat(e.paddingInlineEnd),i=parseFloat(e.paddingBlockStart)+parseFloat(e.paddingBlockEnd);return{width:Math.max(0,t.clientWidth-n),height:Math.max(0,t.clientHeight-i)}}(t);i(t=>t?.width===e.width&&t.height===e.height?t:e)};if(read(),"undefined"==typeof ResizeObserver)return;const n=new ResizeObserver(read);return n.observe(t),()=>n.disconnect()},[e]),n}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface PlOnScreenOptions {
|
|
3
|
+
/**
|
|
4
|
+
* How much of the element has to be showing before it counts, from `0` to
|
|
5
|
+
* `1`.
|
|
6
|
+
* @default 0
|
|
7
|
+
*/
|
|
8
|
+
threshold?: number;
|
|
9
|
+
/**
|
|
10
|
+
* How far outside the viewport still counts, as a CSS margin — `'200px'`
|
|
11
|
+
* starts a fetch a screen early.
|
|
12
|
+
*/
|
|
13
|
+
rootMargin?: string;
|
|
14
|
+
/**
|
|
15
|
+
* What it is measured against. The viewport when it is not given; a scrolling
|
|
16
|
+
* panel otherwise.
|
|
17
|
+
*/
|
|
18
|
+
root?: React.RefObject<Element | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Stops watching the first time it appears.
|
|
21
|
+
*
|
|
22
|
+
* On by default, because the question a caller almost always has is "has this
|
|
23
|
+
* been seen yet" rather than "is it on screen right now" — a lazily loaded
|
|
24
|
+
* picture, a section that animates once, a page that fetches the next batch.
|
|
25
|
+
* Turn it off for the answer that keeps changing.
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
once?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether an element is on screen.
|
|
32
|
+
*
|
|
33
|
+
* An `IntersectionObserver` with the three things a hook has to decide, and
|
|
34
|
+
* the interesting one is `once`. It is **on** by default: the question a caller
|
|
35
|
+
* almost always has is "has this been seen yet", not "is it on screen right
|
|
36
|
+
* now", and a hook that kept answering the second one would re-render a page of
|
|
37
|
+
* lazily loaded pictures every time the reader scrolled past any of them.
|
|
38
|
+
*
|
|
39
|
+
* `false` on a server and on the first render, which is the safe answer for
|
|
40
|
+
* both of the things this is used for: nothing is fetched that did not need to
|
|
41
|
+
* be, and nothing is played before a reader could see it.
|
|
42
|
+
*
|
|
43
|
+
* A browser with no observer is told **yes** rather than no. There is no way to
|
|
44
|
+
* find out, and a picture that never loads is worse than one that loads early.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const section = React.useRef<HTMLDivElement>(null);
|
|
48
|
+
* const seen = usePlOnScreen(section, { rootMargin: '200px' });
|
|
49
|
+
*/
|
|
50
|
+
export declare function usePlOnScreen(target: React.RefObject<Element | null>, { threshold, rootMargin, root, once }?: PlOnScreenOptions): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import*as e from"react";export function usePlOnScreen(r,{threshold:t=0,rootMargin:n,root:o,once:s=!0}={}){const[c,i]=e.useState(!1);return e.useEffect(()=>{const e=r.current;if(!e)return;if("undefined"==typeof IntersectionObserver)return void i(!0);const c=new IntersectionObserver(([e])=>{e.isIntersecting?(i(!0),s&&c.disconnect()):s||i(!1)},{threshold:t,rootMargin:n,root:o?.current??null});return c.observe(e),()=>c.disconnect()},[r,t,n,o,s]),c}
|