plass-ui 1.0.0 → 1.0.2
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 +165 -0
- package/dist/components/accordion/PlAccordion.js +1 -131
- package/dist/components/accordion/index.js +1 -1
- package/dist/components/alert/PlAlert.js +1 -109
- package/dist/components/alert/index.js +1 -1
- package/dist/components/animate-appear/PlAnimateAppear.js +1 -71
- package/dist/components/animate-appear/index.js +1 -1
- package/dist/components/animate-blink/PlAnimateBlink.js +1 -47
- package/dist/components/animate-blink/index.js +1 -1
- package/dist/components/animate-fade/PlAnimateFade.js +1 -48
- package/dist/components/animate-fade/index.js +1 -1
- package/dist/components/animate-grow/PlAnimateGrow.js +1 -49
- package/dist/components/animate-grow/index.js +1 -1
- package/dist/components/animate-headline/PlAnimateHeadline.js +1 -120
- package/dist/components/animate-headline/index.js +1 -1
- package/dist/components/animate-lighting/PlAnimateLighting.js +1 -65
- package/dist/components/animate-lighting/index.js +1 -1
- package/dist/components/animate-marquee/PlAnimateMarquee.js +1 -94
- package/dist/components/animate-marquee/index.js +1 -1
- package/dist/components/animate-rotate/PlAnimateRotate.js +1 -50
- package/dist/components/animate-rotate/index.js +1 -1
- package/dist/components/animate-slide/PlAnimateSlide.js +1 -49
- package/dist/components/animate-slide/index.js +1 -1
- package/dist/components/animate-typing/PlAnimateTyping.js +1 -177
- package/dist/components/animate-typing/index.js +1 -1
- package/dist/components/animate-zoom/PlAnimateZoom.js +1 -45
- package/dist/components/animate-zoom/index.js +1 -1
- package/dist/components/aspect-ratio/PlAspectRatio.js +1 -58
- package/dist/components/aspect-ratio/index.js +1 -1
- package/dist/components/avatar/PlAvatar.js +1 -121
- package/dist/components/avatar/index.js +1 -1
- package/dist/components/badge/PlBadge.js +1 -168
- package/dist/components/badge/index.js +1 -1
- package/dist/components/blockquote/PlBlockquote.js +1 -112
- package/dist/components/blockquote/index.js +1 -1
- package/dist/components/bottom-navigation/PlBottomNavigation.js +1 -141
- package/dist/components/bottom-navigation/index.js +1 -1
- package/dist/components/box/PlBox.js +1 -46
- package/dist/components/box/index.js +1 -1
- package/dist/components/breadcrumb/PlBreadcrumb.js +1 -201
- package/dist/components/breadcrumb/index.js +1 -1
- package/dist/components/button/PlButton.js +1 -196
- package/dist/components/button/index.js +1 -1
- package/dist/components/button-group/PlButtonGroup.js +1 -64
- package/dist/components/button-group/index.js +1 -1
- package/dist/components/card/PlCard.js +1 -102
- package/dist/components/card/index.js +1 -1
- package/dist/components/carousel/PlCarousel.js +1 -177
- package/dist/components/carousel/index.js +1 -1
- package/dist/components/chat-bubble/PlChatBubble.js +1 -206
- package/dist/components/chat-bubble/index.js +1 -1
- package/dist/components/checkbox/PlCheckbox.js +1 -100
- package/dist/components/checkbox/index.js +1 -1
- package/dist/components/chip/PlChip.js +1 -144
- package/dist/components/chip/index.js +1 -1
- package/dist/components/collapsible/PlCollapsible.js +1 -65
- package/dist/components/collapsible/index.js +1 -1
- package/dist/components/combobox/PlCombobox.js +1 -199
- package/dist/components/combobox/index.js +1 -1
- package/dist/components/container/PlContainer.js +1 -47
- package/dist/components/container/index.js +1 -1
- package/dist/components/date-picker/PlDatePicker.js +1 -87
- package/dist/components/date-picker/index.js +1 -1
- package/dist/components/date-range-picker/PlDateRangePicker.js +1 -152
- package/dist/components/date-range-picker/index.js +1 -1
- package/dist/components/date-time-picker/PlDateTimePicker.js +1 -106
- package/dist/components/date-time-picker/index.js +1 -1
- package/dist/components/divider/PlDivider.js +1 -107
- package/dist/components/divider/index.js +1 -1
- package/dist/components/drawer/PlDrawer.js +1 -190
- package/dist/components/drawer/index.js +1 -1
- package/dist/components/file-picker/PlFilePicker.js +1 -274
- package/dist/components/file-picker/index.js +1 -1
- package/dist/components/floating-bottom-navigation/PlFloatingBottomNavigation.js +1 -291
- package/dist/components/floating-bottom-navigation/index.js +1 -1
- package/dist/components/grid/PlGrid.js +1 -51
- package/dist/components/grid/PlGridItem.js +1 -34
- package/dist/components/grid/index.js +1 -2
- package/dist/components/highlight/PlHighlight.js +1 -185
- package/dist/components/highlight/index.js +1 -1
- package/dist/components/hot-keys/PlHotKeys.js +1 -294
- package/dist/components/hot-keys/index.js +1 -1
- package/dist/components/icon/PlIcon.js +1 -58
- package/dist/components/icon/index.js +1 -1
- package/dist/components/icon-button/PlIconButton.js +1 -37
- package/dist/components/icon-button/index.js +1 -1
- package/dist/components/list/PlList.js +1 -160
- package/dist/components/list/index.js +1 -1
- package/dist/components/menu/PlMenu.js +1 -209
- package/dist/components/menu/index.js +1 -1
- package/dist/components/modal/PlModal.js +1 -150
- package/dist/components/modal/index.js +1 -1
- package/dist/components/number-field/PlNumberField.js +1 -111
- package/dist/components/number-field/index.js +1 -1
- package/dist/components/otp-field/PlOtpField.js +1 -109
- package/dist/components/otp-field/index.js +1 -1
- package/dist/components/overlay/PlOverlay.js +1 -77
- package/dist/components/overlay/index.js +1 -1
- package/dist/components/pagination/PlPagination.js +1 -159
- package/dist/components/pagination/index.js +1 -1
- package/dist/components/panes/PlPanes.js +1 -324
- package/dist/components/panes/index.js +1 -1
- package/dist/components/pill/PlPill.js +1 -154
- package/dist/components/pill/index.js +1 -1
- package/dist/components/popover/PlPopover.js +1 -113
- package/dist/components/popover/index.js +1 -1
- package/dist/components/progress-box/PlProgressBox.js +1 -34
- package/dist/components/progress-box/index.js +1 -1
- package/dist/components/progress-circular/PlProgressCircular.js +1 -47
- package/dist/components/progress-circular/index.js +1 -1
- package/dist/components/progress-linear/PlProgressLinear.js +1 -40
- package/dist/components/progress-linear/index.js +1 -1
- package/dist/components/radio-group/PlRadioGroup.js +1 -99
- package/dist/components/radio-group/index.js +1 -1
- package/dist/components/rating/PlRating.js +1 -101
- package/dist/components/rating/index.js +1 -1
- package/dist/components/scroll-zone/PlScrollZone.js +1 -411
- package/dist/components/scroll-zone/index.js +1 -1
- package/dist/components/segmented-button/PlSegmentedButton.js +1 -206
- package/dist/components/segmented-button/index.js +1 -1
- package/dist/components/select/PlSelect.js +1 -115
- package/dist/components/select/index.js +1 -1
- package/dist/components/skeleton/PlSkeleton.js +1 -142
- package/dist/components/skeleton/index.js +1 -1
- package/dist/components/slider/PlSlider.js +1 -132
- package/dist/components/slider/index.js +1 -1
- package/dist/components/spoiler/PlSpoiler.js +1 -74
- package/dist/components/spoiler/index.js +1 -1
- package/dist/components/switch/PlSwitch.js +1 -131
- package/dist/components/switch/index.js +1 -1
- package/dist/components/table/PlTable.js +1 -210
- package/dist/components/table/index.js +1 -1
- package/dist/components/tabs/PlTabs.js +1 -182
- package/dist/components/tabs/index.js +1 -1
- package/dist/components/text-field/PlTextField.js +1 -126
- package/dist/components/text-field/index.js +1 -1
- package/dist/components/text-link/PlTextLink.js +1 -136
- package/dist/components/text-link/index.js +1 -1
- package/dist/components/time-picker/PlTimePicker.js +1 -97
- package/dist/components/time-picker/index.js +1 -1
- package/dist/components/timeline/PlTimeline.js +1 -207
- package/dist/components/timeline/index.js +1 -1
- package/dist/components/toast/PlToast.js +1 -174
- package/dist/components/toast/index.js +1 -1
- package/dist/components/toolbar/PlToolbar.js +1 -65
- package/dist/components/toolbar/index.js +1 -1
- package/dist/components/tooltip/PlTooltip.js +1 -117
- package/dist/components/tooltip/index.js +1 -1
- package/dist/components/typography/PlTypography.js +1 -143
- package/dist/components/typography/index.js +1 -1
- package/dist/index.js +1 -75
- package/dist/internal/animate.js +1 -318
- package/dist/internal/button-group.js +2 -19
- package/dist/internal/calendar.js +1 -501
- package/dist/internal/date.js +1 -353
- package/dist/internal/format.js +1 -41
- package/dist/internal/grid.js +1 -143
- package/dist/internal/icons.js +1 -138
- package/dist/internal/menu.js +1 -18
- package/dist/internal/picker.js +1 -139
- package/dist/internal/progress.js +1 -167
- package/dist/internal/sizer.js +1 -35
- package/dist/internal/styles.js +1 -636
- package/dist/types.js +0 -8
- package/package.json +5 -3
|
@@ -1,291 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
4
|
-
import { controlHeightClasses, controlSlots, controlSquareClasses, cx, focusRingClasses, glassClasses, hasContent, iconSizeClasses, srOnlyClasses, transitionClasses } from '../../internal/styles.js';
|
|
5
|
-
const FloatingBarContext = /* @__PURE__ */ React.createContext({
|
|
6
|
-
value: null,
|
|
7
|
-
change: () => { },
|
|
8
|
-
size: 'md',
|
|
9
|
-
disabled: false
|
|
10
|
-
});
|
|
11
|
-
/** How far off the floor the capsule sits, on the size ladder. */
|
|
12
|
-
const floatGapClasses = {
|
|
13
|
-
xs: 'pb-2',
|
|
14
|
-
sm: 'pb-3',
|
|
15
|
-
md: 'pb-4',
|
|
16
|
-
lg: 'pb-5',
|
|
17
|
-
xl: 'pb-6'
|
|
18
|
-
};
|
|
19
|
-
/** The same, with the home indicator added underneath it. */
|
|
20
|
-
const floatGapSafeClasses = {
|
|
21
|
-
xs: 'pb-[calc(env(safe-area-inset-bottom)+0.5rem)]',
|
|
22
|
-
sm: 'pb-[calc(env(safe-area-inset-bottom)+0.75rem)]',
|
|
23
|
-
md: 'pb-[calc(env(safe-area-inset-bottom)+1rem)]',
|
|
24
|
-
lg: 'pb-[calc(env(safe-area-inset-bottom)+1.25rem)]',
|
|
25
|
-
xl: 'pb-[calc(env(safe-area-inset-bottom)+1.5rem)]'
|
|
26
|
-
};
|
|
27
|
-
/** The air inside the capsule, around the discs. */
|
|
28
|
-
const capsulePaddingClasses = {
|
|
29
|
-
default: { xs: 'p-1', sm: 'p-1', md: 'p-1.5', lg: 'p-2', xl: 'p-2.5' },
|
|
30
|
-
compact: { xs: 'p-0.5', sm: 'p-0.5', md: 'p-1', lg: 'p-1', xl: 'p-1.5' }
|
|
31
|
-
};
|
|
32
|
-
/** Between two discs. */
|
|
33
|
-
const discGapClasses = {
|
|
34
|
-
default: { xs: 'gap-1', sm: 'gap-1', md: 'gap-1.5', lg: 'gap-2', xl: 'gap-2.5' },
|
|
35
|
-
compact: { xs: 'gap-0.5', sm: 'gap-0.5', md: 'gap-1', lg: 'gap-1', xl: 'gap-1.5' }
|
|
36
|
-
};
|
|
37
|
-
const positionClasses = {
|
|
38
|
-
static: '',
|
|
39
|
-
sticky: 'sticky bottom-0 z-20',
|
|
40
|
-
fixed: 'fixed inset-x-0 bottom-0 z-30'
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* The capsule.
|
|
44
|
-
*
|
|
45
|
-
* `rounded-full` is one of the very few places the library allows a pill, and it
|
|
46
|
-
* is allowed for the reason a `PlSegmentedButton`'s groove is: this is not a
|
|
47
|
-
* sheet lying on the page, it is an object floating clear of one. The house
|
|
48
|
-
* fillet is about a sheet with its corners cut, and a sheet that is not on
|
|
49
|
-
* anything has no corners to cut.
|
|
50
|
-
*/
|
|
51
|
-
const capsuleClasses = {
|
|
52
|
-
solid: /* @__PURE__ */ [
|
|
53
|
-
glassClasses,
|
|
54
|
-
'bg-(--plass-glass-press)',
|
|
55
|
-
'[box-shadow:var(--p-elev),var(--plass-gloss-glass)]'
|
|
56
|
-
].join(' '),
|
|
57
|
-
glass: /* @__PURE__ */ [
|
|
58
|
-
glassClasses,
|
|
59
|
-
'border bg-(--plass-glass)',
|
|
60
|
-
'[border-color:var(--plass-glass-line)]',
|
|
61
|
-
'[box-shadow:var(--p-elev),var(--plass-gloss-glass)]'
|
|
62
|
-
].join(' '),
|
|
63
|
-
ghost: ''
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* The key that slides.
|
|
67
|
-
*
|
|
68
|
-
* Always the family's own gradient with that family's tinted shadow under it,
|
|
69
|
-
* whatever the capsule is made of — a key of tinted glass riding in a clear
|
|
70
|
-
* sheet is the design language's own sentence, and `variant` is a statement
|
|
71
|
-
* about the *capsule*. A `ghost` bar is a row of discs with no sheet behind
|
|
72
|
-
* them; the one that is current is still the one that is current.
|
|
73
|
-
*
|
|
74
|
-
* `left`, `top`, `width` and `height` rather than a `translate`: the key is
|
|
75
|
-
* measured off the disc it belongs under, and moving it by its own box is what
|
|
76
|
-
* keeps every glyph in the row unresampled while it travels. `left` and not
|
|
77
|
-
* `inset-inline-start`, because `offsetLeft` is a distance from the left edge
|
|
78
|
-
* and stays one under RTL — pairing a physical measurement with a logical
|
|
79
|
-
* property is what would break the direction.
|
|
80
|
-
*
|
|
81
|
-
* `data-quiet` is the current destination being unavailable, which is the one
|
|
82
|
-
* state the key cannot read off its own props: the light goes out on the key
|
|
83
|
-
* the same way it goes out on the disc over it, or a disabled destination is a
|
|
84
|
-
* dimmed glyph on a fully lit gradient.
|
|
85
|
-
*/
|
|
86
|
-
const keyClasses = /* @__PURE__ */ [
|
|
87
|
-
'pointer-events-none absolute rounded-full',
|
|
88
|
-
'top-(--p-disc-y) left-(--p-disc-x) h-(--p-disc-h) w-(--p-disc-w)',
|
|
89
|
-
'[background-image:var(--p-fill)]',
|
|
90
|
-
'[box-shadow:var(--plass-shadow-1),var(--p-lift)]',
|
|
91
|
-
'data-[quiet]:opacity-50 data-[quiet]:saturate-[0.35]',
|
|
92
|
-
'[transition-property:left,top,width,height,opacity,filter]',
|
|
93
|
-
'[transition-timing-function:var(--plass-ease)]',
|
|
94
|
-
// Nothing until the first measurement has landed; the house duration from
|
|
95
|
-
// then on.
|
|
96
|
-
'[transition-duration:0ms] data-[ready]:[transition-duration:var(--plass-duration)]'
|
|
97
|
-
].join(' ');
|
|
98
|
-
/**
|
|
99
|
-
* A row of round destinations floating clear of the bottom edge of the window.
|
|
100
|
-
*
|
|
101
|
-
* The other half of `PlBottomNavigation`, and a different object rather than a
|
|
102
|
-
* variant of one: that bar is **attached** to the edge of the window — full
|
|
103
|
-
* width, a hairline against the content, its sheet running under the home
|
|
104
|
-
* indicator — and this one is **not part of the page at all**. Everything that
|
|
105
|
-
* follows comes from that one difference: the capsule, the gap under it, the
|
|
106
|
-
* shadow it defaults to, and the pill corners it is allowed.
|
|
107
|
-
*
|
|
108
|
-
* Every destination is a disc with a glyph in it and no name drawn, which is
|
|
109
|
-
* what keeps a row of five inside the width of a phone. The name is still
|
|
110
|
-
* required and still read out — a row of glyphs with no accessible names is the
|
|
111
|
-
* defect `PlIconButton`'s `label` exists to make impossible, and it would be
|
|
112
|
-
* exactly as easy to ship here.
|
|
113
|
-
*
|
|
114
|
-
* The current destination is a key of **tinted glass** riding in the clear
|
|
115
|
-
* sheet, which is the design language's own sentence with nothing added to it.
|
|
116
|
-
* The key is **one element that travels**, measured off whichever disc is
|
|
117
|
-
* current and animated the way a `PlSegmentedButton`'s tile is — not a fill
|
|
118
|
-
* that appears on one disc while it disappears from another. Two discs
|
|
119
|
-
* cross-fading is two objects; a bar with a key in it has one, and where it
|
|
120
|
-
* goes is the whole of what the component has to say.
|
|
121
|
-
*
|
|
122
|
-
* Nothing is transformed: the key is an empty box, and no glyph is resampled
|
|
123
|
-
* while it travels. That is what lets the house no-transform rule survive a
|
|
124
|
-
* component whose entire point is that something moves.
|
|
125
|
-
*
|
|
126
|
-
* It reads `controlSlots` and not the `surfaceSlots` every other container
|
|
127
|
-
* takes, which is the one place this bar is not a container: the slots a
|
|
128
|
-
* container is given are deliberately undyed — no `--p-fill`, no `--p-on-solid`
|
|
129
|
-
* and no `--p-lift` — and the key is made of all three. Asking a container's
|
|
130
|
-
* slot set for a control's colours is asking for `var(--p-fill)` to resolve to
|
|
131
|
-
* nothing, which is a `background-image` the browser drops on the floor and a
|
|
132
|
-
* current destination that looks exactly like the four beside it.
|
|
133
|
-
*/
|
|
134
|
-
export const PlFloatingBottomNavigation = /* @__PURE__ */ React.forwardRef(function PlFloatingBottomNavigation({ variant = 'glass', size = 'md', color = 'primary', density = 'default', elevation = 2, value: valueProp, defaultValue = null, onValueChange, position = 'fixed', safeArea = true, disabled = false, label, render, className, style, children, ...props }, ref) {
|
|
135
|
-
const [uncontrolled, setUncontrolled] = React.useState(defaultValue);
|
|
136
|
-
const controlled = valueProp !== undefined;
|
|
137
|
-
const value = controlled ? valueProp : uncontrolled;
|
|
138
|
-
const capsuleRef = React.useRef(null);
|
|
139
|
-
const keyRef = React.useRef(null);
|
|
140
|
-
/**
|
|
141
|
-
* Writes the current disc's box onto the key as four custom properties.
|
|
142
|
-
*
|
|
143
|
-
* Written straight to the element rather than held in state, exactly as
|
|
144
|
-
* `PlSegmentedButton` writes its tile: a `setState` here would re-render
|
|
145
|
-
* every disc on every resize, and nothing in the tree depends on the numbers
|
|
146
|
-
* except four CSS declarations.
|
|
147
|
-
*
|
|
148
|
-
* `animate` is what separates the two callers. A change of destination is the
|
|
149
|
-
* thing this exists to animate; a resize is the capsule moving under a key
|
|
150
|
-
* that was already in the right place, and animating that is a key that lags
|
|
151
|
-
* behind the window being dragged.
|
|
152
|
-
*/
|
|
153
|
-
const measure = React.useCallback((animate) => {
|
|
154
|
-
const capsule = capsuleRef.current;
|
|
155
|
-
const disc = keyRef.current;
|
|
156
|
-
if (!capsule || !disc) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const current = capsule.querySelector('[data-disc][data-current]');
|
|
160
|
-
if (!current) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
// A key that has only just mounted has nowhere to travel *from*, so its
|
|
164
|
-
// first placement is instant however it was asked for — that is what makes
|
|
165
|
-
// the first destination appear under its disc rather than fly in from the
|
|
166
|
-
// left edge of the capsule.
|
|
167
|
-
const instant = !animate || !disc.hasAttribute('data-ready');
|
|
168
|
-
if (instant) {
|
|
169
|
-
disc.removeAttribute('data-ready');
|
|
170
|
-
}
|
|
171
|
-
// `offsetLeft`/`offsetTop` are measured from the offsetParent's padding
|
|
172
|
-
// edge, and `left`/`top` on an absolutely positioned child resolve against
|
|
173
|
-
// the same box — so the capsule's own padding is already accounted for and
|
|
174
|
-
// must not be subtracted again.
|
|
175
|
-
disc.style.setProperty('--p-disc-x', `${current.offsetLeft}px`);
|
|
176
|
-
disc.style.setProperty('--p-disc-y', `${current.offsetTop}px`);
|
|
177
|
-
disc.style.setProperty('--p-disc-w', `${current.offsetWidth}px`);
|
|
178
|
-
disc.style.setProperty('--p-disc-h', `${current.offsetHeight}px`);
|
|
179
|
-
// Read off the disc rather than off a prop, because the bar does not know
|
|
180
|
-
// which of its children is unavailable — the items are `children` and the
|
|
181
|
-
// disabled one is whichever of them said so. The same query that measures
|
|
182
|
-
// the box answers it, so there is no second pass.
|
|
183
|
-
disc.toggleAttribute('data-quiet', current.hasAttribute('data-disabled'));
|
|
184
|
-
if (instant) {
|
|
185
|
-
// Reading a layout property commits the four writes above while the
|
|
186
|
-
// duration is still 0ms, so turning the transition back on cannot
|
|
187
|
-
// animate a move that has already happened.
|
|
188
|
-
void disc.offsetWidth;
|
|
189
|
-
}
|
|
190
|
-
disc.setAttribute('data-ready', '');
|
|
191
|
-
}, []);
|
|
192
|
-
// Before the browser paints, or the key is visibly at nothing for a frame.
|
|
193
|
-
React.useLayoutEffect(() => {
|
|
194
|
-
measure(true);
|
|
195
|
-
}, [measure, value, variant, size, density, disabled, children]);
|
|
196
|
-
React.useEffect(() => {
|
|
197
|
-
const capsule = capsuleRef.current;
|
|
198
|
-
if (!capsule || typeof ResizeObserver === 'undefined') {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const observer = new ResizeObserver(() => measure(false));
|
|
202
|
-
observer.observe(capsule);
|
|
203
|
-
return () => observer.disconnect();
|
|
204
|
-
}, [measure]);
|
|
205
|
-
const change = React.useCallback((next) => {
|
|
206
|
-
if (!controlled) {
|
|
207
|
-
setUncontrolled(next);
|
|
208
|
-
}
|
|
209
|
-
onValueChange?.(next);
|
|
210
|
-
}, [controlled, onValueChange]);
|
|
211
|
-
const context = React.useMemo(() => ({ value: value ?? null, change, size, disabled }), [value, change, size, disabled]);
|
|
212
|
-
const classNames = cx('flex w-full justify-center px-4',
|
|
213
|
-
// The strip the capsule is centred in spans the window, and a transparent
|
|
214
|
-
// band across the bottom of a page that swallowed presses would be a band
|
|
215
|
-
// nobody could scroll through. Only the capsule takes them back.
|
|
216
|
-
position === 'static' ? '' : 'pointer-events-none', safeArea ? floatGapSafeClasses[size] : floatGapClasses[size], positionClasses[position], className);
|
|
217
|
-
return useRender({
|
|
218
|
-
render: render ?? _jsx("nav", {}),
|
|
219
|
-
ref,
|
|
220
|
-
props: {
|
|
221
|
-
'aria-label': label,
|
|
222
|
-
className: classNames,
|
|
223
|
-
// `controlSlots` and not `surfaceSlots`: the capsule is undyed like every
|
|
224
|
-
// other container, but the key riding in it is a control's surface and is
|
|
225
|
-
// made of three slots a container's set does not carry.
|
|
226
|
-
style: { ...controlSlots(color, elevation, 'solid'), ...style },
|
|
227
|
-
children: (_jsx(FloatingBarContext.Provider, { value: context, children: _jsxs("div", { ref: capsuleRef, className: cx(
|
|
228
|
-
// `relative` is load-bearing twice over: it is what makes the
|
|
229
|
-
// capsule the discs' offsetParent, and what the key is positioned
|
|
230
|
-
// in.
|
|
231
|
-
'pointer-events-auto relative inline-flex items-center rounded-full', capsuleClasses[variant], capsulePaddingClasses[density][size], discGapClasses[density][size], transitionClasses), children: [value !== null && value !== undefined ? (_jsx("span", { ref: keyRef, "aria-hidden": "true", className: keyClasses })) : null, children] }) })),
|
|
232
|
-
...props
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
/**
|
|
237
|
-
* One destination, as a disc.
|
|
238
|
-
*
|
|
239
|
-
* It has no `size`, no `color` and no `variant` of its own: all three belong to
|
|
240
|
-
* the bar, which is the only place they can be set once and mean the same thing
|
|
241
|
-
* for every disc.
|
|
242
|
-
*/
|
|
243
|
-
export const PlFloatingBottomNavigationItem = /* @__PURE__ */ React.forwardRef(function PlFloatingBottomNavigationItem({ value, icon, href, disabled: disabledProp = false, className, children, onClick, ...props }, ref) {
|
|
244
|
-
const bar = React.useContext(FloatingBarContext);
|
|
245
|
-
const disabled = disabledProp || bar.disabled;
|
|
246
|
-
const selected = bar.value !== null && bar.value === value;
|
|
247
|
-
const classNames = cx(
|
|
248
|
-
// `z-10` and a stacking context of its own: the key is painted behind the
|
|
249
|
-
// discs, and without this it would cover the glyph it is under.
|
|
250
|
-
'relative z-10 inline-flex shrink-0 items-center justify-center rounded-full', controlHeightClasses[bar.size], controlSquareClasses[bar.size], '[-webkit-tap-highlight-color:transparent] [touch-action:manipulation]', transitionClasses,
|
|
251
|
-
// Offset rather than inset: a disc inside a capsule that is only padding has
|
|
252
|
-
// room around it, and a flush ring on a circle is the circle's own edge
|
|
253
|
-
// thickening — which is the one shape where that reads as a border rather
|
|
254
|
-
// than as focus.
|
|
255
|
-
focusRingClasses, disabled
|
|
256
|
-
? 'cursor-not-allowed opacity-50 saturate-[0.35] text-(--plass-muted-fg)'
|
|
257
|
-
: selected
|
|
258
|
-
? // No surface of its own. What is under the glyph is the key, which
|
|
259
|
-
// belongs to the bar and is the one thing in the row that travels;
|
|
260
|
-
// a disc that drew its own fill would be a second key appearing
|
|
261
|
-
// wherever the first one had just left.
|
|
262
|
-
'cursor-pointer text-(--p-on-solid)'
|
|
263
|
-
: 'cursor-pointer text-(--plass-muted-fg) hover:text-(--plass-fg) hover:bg-(--plass-glass-hover)', className);
|
|
264
|
-
const body = (_jsxs(_Fragment, { children: [hasContent(icon) ? (_jsx("span", { className: cx('flex shrink-0 items-center justify-center', iconSizeClasses[bar.size]), children: icon })) : null, hasContent(children) ? _jsx("span", { className: srOnlyClasses, children: children }) : null] }));
|
|
265
|
-
/**
|
|
266
|
-
* The hooks the key is measured from.
|
|
267
|
-
*
|
|
268
|
-
* Attributes rather than a ref per disc, for the reason a `PlSegment` carries
|
|
269
|
-
* `data-segment`: a ref array would mean keeping it in step with however the
|
|
270
|
-
* caller composed the items — through a `.map()`, through a fragment, through
|
|
271
|
-
* a component of their own — and an attribute is the version of that which
|
|
272
|
-
* cannot fall out of step.
|
|
273
|
-
*/
|
|
274
|
-
const discAttributes = {
|
|
275
|
-
'data-disc': '',
|
|
276
|
-
'data-current': selected ? '' : undefined,
|
|
277
|
-
'data-disabled': disabled ? '' : undefined
|
|
278
|
-
};
|
|
279
|
-
const press = (event) => {
|
|
280
|
-
if (disabled) {
|
|
281
|
-
event.preventDefault();
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
bar.change(value);
|
|
285
|
-
onClick?.(event);
|
|
286
|
-
};
|
|
287
|
-
if (href) {
|
|
288
|
-
return (_jsx("a", { ref: ref, href: disabled ? undefined : href, "aria-current": selected ? 'page' : undefined, "aria-disabled": disabled || undefined, ...discAttributes, className: classNames, onClick: press, ...props, children: body }));
|
|
289
|
-
}
|
|
290
|
-
return (_jsx("button", { ref: ref, type: "button", disabled: disabled, "aria-current": selected ? 'page' : undefined, ...discAttributes, className: classNames, onClick: press, ...props, children: body }));
|
|
291
|
-
});
|
|
1
|
+
"use client";import{jsx as e,jsxs as t,Fragment as a}from"react/jsx-runtime";import*as s from"react";import{useRender as r}from"@base-ui/react/use-render";import{controlHeightClasses as i,controlSlots as l,controlSquareClasses as o,cx as n,focusRingClasses as d,glassClasses as c,hasContent as p,iconSizeClasses as u,srOnlyClasses as f,transitionClasses as m}from"../../internal/styles.js";const g=/* @__PURE__ */s.createContext({value:null,change:()=>{},size:"md",disabled:!1}),v={xs:"pb-2",sm:"pb-3",md:"pb-4",lg:"pb-5",xl:"pb-6"},b={xs:"pb-[calc(env(safe-area-inset-bottom)+0.5rem)]",sm:"pb-[calc(env(safe-area-inset-bottom)+0.75rem)]",md:"pb-[calc(env(safe-area-inset-bottom)+1rem)]",lg:"pb-[calc(env(safe-area-inset-bottom)+1.25rem)]",xl:"pb-[calc(env(safe-area-inset-bottom)+1.5rem)]"},h={default:{xs:"p-1",sm:"p-1",md:"p-1.5",lg:"p-2",xl:"p-2.5"},compact:{xs:"p-0.5",sm:"p-0.5",md:"p-1",lg:"p-1",xl:"p-1.5"}},x={default:{xs:"gap-1",sm:"gap-1",md:"gap-1.5",lg:"gap-2",xl:"gap-2.5"},compact:{xs:"gap-0.5",sm:"gap-0.5",md:"gap-1",lg:"gap-1",xl:"gap-1.5"}},y={static:"",sticky:"sticky bottom-0 z-20",fixed:"fixed inset-x-0 bottom-0 z-30"},w={solid:/* @__PURE__ */[c,"bg-(--plass-glass-press)","[box-shadow:var(--p-elev),var(--plass-gloss-glass)]"].join(" "),glass:/* @__PURE__ */[c,"border bg-(--plass-glass)","[border-color:var(--plass-glass-line)]","[box-shadow:var(--p-elev),var(--plass-gloss-glass)]"].join(" "),ghost:""},N=/* @__PURE__ */["pointer-events-none absolute rounded-full","top-(--p-disc-y) left-(--p-disc-x) h-(--p-disc-h) w-(--p-disc-w)","[background-image:var(--p-fill)]","[box-shadow:var(--plass-shadow-1),var(--p-lift)]","data-[quiet]:opacity-50 data-[quiet]:saturate-[0.35]","[transition-property:left,top,width,height,opacity,filter]","[transition-timing-function:var(--plass-ease)]","[transition-duration:0ms] data-[ready]:[transition-duration:var(--plass-duration)]"].join(" ");export const PlFloatingBottomNavigation=/* @__PURE__ */s.forwardRef(function PlFloatingBottomNavigation({variant:a="glass",size:i="md",color:o="primary",density:d="default",elevation:c=2,value:p,defaultValue:u=null,onValueChange:f,position:k="fixed",safeArea:z=!0,disabled:j=!1,label:P,render:C,className:A,style:R,children:F,...q},B){const[$,E]=s.useState(u),I=void 0!==p,L=I?p:$,O=s.useRef(null),S=s.useRef(null),V=s.useCallback(e=>{const t=O.current,a=S.current;if(!t||!a)return;const s=t.querySelector("[data-disc][data-current]");if(!s)return;const r=!e||!a.hasAttribute("data-ready");r&&a.removeAttribute("data-ready"),a.style.setProperty("--p-disc-x",`${s.offsetLeft}px`),a.style.setProperty("--p-disc-y",`${s.offsetTop}px`),a.style.setProperty("--p-disc-w",`${s.offsetWidth}px`),a.style.setProperty("--p-disc-h",`${s.offsetHeight}px`),a.toggleAttribute("data-quiet",s.hasAttribute("data-disabled")),r&&a.offsetWidth,a.setAttribute("data-ready","")},[]);s.useLayoutEffect(()=>{V(!0)},[V,L,a,i,d,j,F]),s.useEffect(()=>{const e=O.current;if(!e||"undefined"==typeof ResizeObserver)return;const t=new ResizeObserver(()=>V(!1));return t.observe(e),()=>t.disconnect()},[V]);const W=s.useCallback(e=>{I||E(e),f?.(e)},[I,f]),D=s.useMemo(()=>({value:L??null,change:W,size:i,disabled:j}),[L,W,i,j]),H=n("flex w-full justify-center px-4","static"===k?"":"pointer-events-none",z?b[i]:v[i],y[k],A);return r({render:C??e("nav",{}),ref:B,props:{"aria-label":P,className:H,style:{...l(o,c,"solid"),...R},children:e(g.Provider,{value:D,children:t("div",{ref:O,className:n("pointer-events-auto relative inline-flex items-center rounded-full",w[a],h[d][i],x[d][i],m),children:[null!=L?e("span",{ref:S,"aria-hidden":"true",className:N}):null,F]})}),...q}})});export const PlFloatingBottomNavigationItem=/* @__PURE__ */s.forwardRef(function PlFloatingBottomNavigationItem({value:r,icon:l,href:c,disabled:v=!1,className:b,children:h,onClick:x,...y},w){const N=s.useContext(g),k=v||N.disabled,z=null!==N.value&&N.value===r,j=n("relative z-10 inline-flex shrink-0 items-center justify-center rounded-full",i[N.size],o[N.size],"[-webkit-tap-highlight-color:transparent] [touch-action:manipulation]",m,d,k?"cursor-not-allowed opacity-50 saturate-[0.35] text-(--plass-muted-fg)":z?"cursor-pointer text-(--p-on-solid)":"cursor-pointer text-(--plass-muted-fg) hover:text-(--plass-fg) hover:bg-(--plass-glass-hover)",b),P=t(a,{children:[p(l)?e("span",{className:n("flex shrink-0 items-center justify-center",u[N.size]),children:l}):null,p(h)?e("span",{className:f,children:h}):null]}),C={"data-disc":"","data-current":z?"":void 0,"data-disabled":k?"":void 0},press=e=>{k?e.preventDefault():(N.change(r),x?.(e))};return c?e("a",{ref:w,href:k?void 0:c,"aria-current":z?"page":void 0,"aria-disabled":k||void 0,...C,className:j,onClick:press,...y,children:P}):e("button",{ref:w,type:"button",disabled:k,"aria-current":z?"page":void 0,...C,className:j,onClick:press,...y,children:P})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlFloatingBottomNavigation,PlFloatingBottomNavigationItem}from"./PlFloatingBottomNavigation.js";
|
|
@@ -1,51 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { alignContentClasses, alignItemsClasses, columnCount, justifyClasses, responsiveSlots, spacingValue, withBaseline } from '../../internal/grid.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
const DEFAULT_COLUMNS = 12;
|
|
6
|
-
/** Two Tailwind steps, and the reason a bare `PlGrid` already looks like one. */
|
|
7
|
-
const DEFAULT_SPACING = 2;
|
|
8
|
-
/**
|
|
9
|
-
* A twelve-column row, and the parent every `PlGridItem` needs.
|
|
10
|
-
*
|
|
11
|
-
* It owns the three numbers an item cannot know on its own — how many columns
|
|
12
|
-
* there are and how wide the two gutters are — and hands them down as inherited
|
|
13
|
-
* custom properties rather than through a React context. That is not a
|
|
14
|
-
* shortcut: the values are responsive, and a media query can change an inherited
|
|
15
|
-
* custom property without React hearing about it, so the column count an item
|
|
16
|
-
* lays itself out against is always the one that is actually on screen. A
|
|
17
|
-
* context would have to re-render the tree at every breakpoint to say the same
|
|
18
|
-
* thing.
|
|
19
|
-
*
|
|
20
|
-
* It draws nothing, and it takes no `variant`, `color`, `elevation`, `size` or
|
|
21
|
-
* `density`. A grid is not a surface — it is the arrangement of the surfaces
|
|
22
|
-
* inside it — and there is no padding here either: the gutter round a page is a
|
|
23
|
-
* `PlContainer`'s and the padding round content is a `PlCard`'s, and a grid that
|
|
24
|
-
* had a track of its own would be a third one to keep in step. `spacing` is the
|
|
25
|
-
* only measurement it owns, and it is the space *between* items.
|
|
26
|
-
*
|
|
27
|
-
* Nesting is a `PlGrid` inside a `PlGridItem`, not an item that is also a grid:
|
|
28
|
-
* the inner grid re-declares the column count for its own subtree while the item
|
|
29
|
-
* around it keeps the width the outer grid gave it.
|
|
30
|
-
*/
|
|
31
|
-
export const PlGrid = /* @__PURE__ */ React.forwardRef(function PlGrid({ columns, spacing, rowSpacing, columnSpacing, justify, alignItems, alignContent, wrap = true, render, className, style, children, ...props }, ref) {
|
|
32
|
-
const classNames = cx('plass-grid flex', wrap ? 'flex-wrap' : 'flex-nowrap',
|
|
33
|
-
// Both gutters are read from the slots below, which is what lets a media
|
|
34
|
-
// query change them without React re-rendering.
|
|
35
|
-
'gap-x-(--p-gap-x) gap-y-(--p-gap-y)', justify ? justifyClasses[justify] : '', alignItems ? alignItemsClasses[alignItems] : '', alignContent ? alignContentClasses[alignContent] : '', className);
|
|
36
|
-
return useRender({
|
|
37
|
-
render,
|
|
38
|
-
ref,
|
|
39
|
-
props: {
|
|
40
|
-
className: classNames,
|
|
41
|
-
style: {
|
|
42
|
-
...responsiveSlots('cols', withBaseline(columns, DEFAULT_COLUMNS), columnCount),
|
|
43
|
-
...responsiveSlots('gap-x', withBaseline(columnSpacing ?? spacing, DEFAULT_SPACING), spacingValue),
|
|
44
|
-
...responsiveSlots('gap-y', withBaseline(rowSpacing ?? spacing, DEFAULT_SPACING), spacingValue),
|
|
45
|
-
...style
|
|
46
|
-
},
|
|
47
|
-
children,
|
|
48
|
-
...props
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
1
|
+
"use client";import*as r from"react";import{useRender as e}from"@base-ui/react/use-render";import{alignContentClasses as a,alignItemsClasses as n,columnCount as s,justifyClasses as p,responsiveSlots as i,spacingValue as l,withBaseline as t}from"../../internal/grid.js";import{cx as o}from"../../internal/styles.js";export const PlGrid=/* @__PURE__ */r.forwardRef(function PlGrid({columns:r,spacing:c,rowSpacing:g,columnSpacing:m,justify:f,alignItems:d,alignContent:u,wrap:x=!0,render:y,className:w,style:j,children:h,...G},N){const P=o("plass-grid flex",x?"flex-wrap":"flex-nowrap","gap-x-(--p-gap-x) gap-y-(--p-gap-y)",f?p[f]:"",d?n[d]:"",u?a[u]:"",w);return e({render:y,ref:N,props:{className:P,style:{...i("cols",t(r,12),s),...i("gap-x",t(m??c,2),l),...i("gap-y",t(g??c,2),l),...j},children:h,...G}})});
|
|
@@ -1,34 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRender } from '@base-ui/react/use-render';
|
|
3
|
-
import { alignSelfClasses, offsetValue, responsiveSlots, spanValue } from '../../internal/grid.js';
|
|
4
|
-
import { cx } from '../../internal/styles.js';
|
|
5
|
-
/**
|
|
6
|
-
* One cell of a `PlGrid`.
|
|
7
|
-
*
|
|
8
|
-
* It is a width and nothing else — no sheet, no padding, no typography. What
|
|
9
|
-
* goes inside brings its own, which is the whole reason a cell and a `PlCard`
|
|
10
|
-
* are two components: wrapping something in a layout must not change how it
|
|
11
|
-
* looks, and a cell that drew a sheet would make `span` a visual decision.
|
|
12
|
-
*
|
|
13
|
-
* The column count it divides by is inherited from the grid as a custom
|
|
14
|
-
* property, so an item with no `PlGrid` above it falls back to twelve rather
|
|
15
|
-
* than breaking — but it will be a lone width in a plain parent, which is not a
|
|
16
|
-
* layout. Always wrap.
|
|
17
|
-
*/
|
|
18
|
-
export const PlGridItem = /* @__PURE__ */ React.forwardRef(function PlGridItem({ span, offset, alignSelf, render, className, style, children, ...props }, ref) {
|
|
19
|
-
const classNames = cx('plass-grid-item', alignSelf ? alignSelfClasses[alignSelf] : '', className);
|
|
20
|
-
return useRender({
|
|
21
|
-
render,
|
|
22
|
-
ref,
|
|
23
|
-
props: {
|
|
24
|
-
className: classNames,
|
|
25
|
-
style: {
|
|
26
|
-
...responsiveSlots('span', span, spanValue),
|
|
27
|
-
...responsiveSlots('offset', offset, offsetValue),
|
|
28
|
-
...style
|
|
29
|
-
},
|
|
30
|
-
children,
|
|
31
|
-
...props
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
});
|
|
1
|
+
"use client";import*as e from"react";import{useRender as r}from"@base-ui/react/use-render";import{alignSelfClasses as s,offsetValue as t,responsiveSlots as n,spanValue as i}from"../../internal/grid.js";import{cx as o}from"../../internal/styles.js";export const PlGridItem=/* @__PURE__ */e.forwardRef(function PlGridItem({span:e,offset:a,alignSelf:l,render:f,className:m,style:c,children:d,...p},u){const g=o("plass-grid-item",l?s[l]:"",m);return r({render:f,ref:u,props:{className:g,style:{...n("span",e,i),...n("offset",a,t),...c},children:d,...p}})});
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { PlGridItem } from './PlGridItem.js';
|
|
1
|
+
export{PlGrid}from"./PlGrid.js";export{PlGridItem}from"./PlGridItem.js";
|
|
@@ -1,185 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { transitionClasses } from '../../internal/styles.js';
|
|
4
|
-
/**
|
|
5
|
-
* There is no `size` here on purpose, and it is the one prop a reader will look
|
|
6
|
-
* for. A mark sits inside running text and has to be the size of the text it is
|
|
7
|
-
* inside; a `size` prop would only offer ways to be wrong.
|
|
8
|
-
*/
|
|
9
|
-
const variantClasses = {
|
|
10
|
-
solid: '[background-image:var(--p-fill)] text-(--p-on-solid)',
|
|
11
|
-
glass: 'border bg-(--p-soft) text-(--p-accent) [border-color:var(--p-line)]',
|
|
12
|
-
// Both properties are still set. A `<mark>` arrives from the browser's own
|
|
13
|
-
// stylesheet with a yellow background and black ink, and "no surface" has to
|
|
14
|
-
// be said out loud or it turns into the UA's surface.
|
|
15
|
-
ghost: 'bg-transparent text-(--p-accent)'
|
|
16
|
-
};
|
|
17
|
-
const weightClasses = {
|
|
18
|
-
regular: 'font-normal',
|
|
19
|
-
medium: 'font-medium',
|
|
20
|
-
semibold: 'font-semibold',
|
|
21
|
-
bold: 'font-bold'
|
|
22
|
-
};
|
|
23
|
-
/** Letters, digits and underscores in any script — what `wholeWord` counts. */
|
|
24
|
-
const wordCharacter = /[\p{L}\p{N}_]/u;
|
|
25
|
-
/** The characters a regular expression treats as syntax. */
|
|
26
|
-
function escapeRegExp(text) {
|
|
27
|
-
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Turns the `query` prop into one expression, or `null` when there is nothing to
|
|
31
|
-
* look for — an empty search box should leave the text exactly as it was, not
|
|
32
|
-
* mark every character in it.
|
|
33
|
-
*
|
|
34
|
-
* Terms are sorted longest first because alternation in a regular expression is
|
|
35
|
-
* first-match-wins: without it `['data', 'database']` would mark `data` and
|
|
36
|
-
* stop, leaving `base` outside the mark.
|
|
37
|
-
*/
|
|
38
|
-
function buildPattern(query, caseSensitive) {
|
|
39
|
-
if (query instanceof RegExp) {
|
|
40
|
-
// Always a copy, even when the flags are already right. A global regular
|
|
41
|
-
// expression carries a `lastIndex` that `markString` moves, and mutating one
|
|
42
|
-
// the caller is holding — and may be matching with elsewhere — is not this
|
|
43
|
-
// component's to do.
|
|
44
|
-
return new RegExp(query.source, query.global ? query.flags : `${query.flags}g`);
|
|
45
|
-
}
|
|
46
|
-
const terms = (Array.isArray(query) ? query : [query])
|
|
47
|
-
.map((term) => term.trim())
|
|
48
|
-
.filter(Boolean)
|
|
49
|
-
.sort((a, b) => b.length - a.length);
|
|
50
|
-
if (terms.length === 0) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return new RegExp(terms.map(escapeRegExp).join('|'), caseSensitive ? 'gu' : 'giu');
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Whether a match is a whole word.
|
|
57
|
-
*
|
|
58
|
-
* Checked here rather than with a lookbehind in the pattern, because lookbehind
|
|
59
|
-
* is the one regular-expression feature this library would have to think about
|
|
60
|
-
* shipping — Safari only grew it in 16.4. Two character tests cost nothing and
|
|
61
|
-
* work everywhere.
|
|
62
|
-
*/
|
|
63
|
-
function isWholeWord(text, start, end) {
|
|
64
|
-
const before = start > 0 ? text[start - 1] : '';
|
|
65
|
-
const after = end < text.length ? text[end] : '';
|
|
66
|
-
return !wordCharacter.test(before) && !wordCharacter.test(after);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Splits one string into plain runs and marked ones.
|
|
70
|
-
*
|
|
71
|
-
* Returns the string itself when nothing matched, so an unmatched text node
|
|
72
|
-
* stays a text node rather than becoming an array of one.
|
|
73
|
-
*/
|
|
74
|
-
function markString(text, pattern, wholeWord, mark) {
|
|
75
|
-
pattern.lastIndex = 0;
|
|
76
|
-
const parts = [];
|
|
77
|
-
let cursor = 0;
|
|
78
|
-
let match;
|
|
79
|
-
while ((match = pattern.exec(text)) !== null) {
|
|
80
|
-
// A pattern that can match nothing — `/x*/` — would otherwise never advance.
|
|
81
|
-
if (match[0] === '') {
|
|
82
|
-
pattern.lastIndex += 1;
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const start = match.index;
|
|
86
|
-
const end = start + match[0].length;
|
|
87
|
-
if (wholeWord && !isWholeWord(text, start, end)) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
if (start > cursor) {
|
|
91
|
-
parts.push(text.slice(cursor, start));
|
|
92
|
-
}
|
|
93
|
-
parts.push(mark(match[0], `${start}`));
|
|
94
|
-
cursor = end;
|
|
95
|
-
}
|
|
96
|
-
if (parts.length === 0) {
|
|
97
|
-
return text;
|
|
98
|
-
}
|
|
99
|
-
if (cursor < text.length) {
|
|
100
|
-
parts.push(text.slice(cursor));
|
|
101
|
-
}
|
|
102
|
-
return parts;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Walks the tree, marking the text in it and leaving everything else alone.
|
|
106
|
-
*
|
|
107
|
-
* The alternative — requiring `children` to be a string — is what most libraries
|
|
108
|
-
* do, and it fails on the first search result that has a `<strong>` in it. An
|
|
109
|
-
* element is cloned with its children marked, which keeps its type, its props
|
|
110
|
-
* and its key; anything that is not a string, a number, an array or an element
|
|
111
|
-
* with children is returned untouched.
|
|
112
|
-
*/
|
|
113
|
-
function markNode(node, pattern, wholeWord, mark) {
|
|
114
|
-
if (typeof node === 'string') {
|
|
115
|
-
return markString(node, pattern, wholeWord, mark);
|
|
116
|
-
}
|
|
117
|
-
if (typeof node === 'number') {
|
|
118
|
-
return markString(String(node), pattern, wholeWord, mark);
|
|
119
|
-
}
|
|
120
|
-
if (Array.isArray(node)) {
|
|
121
|
-
return React.Children.map(node, (child) => markNode(child, pattern, wholeWord, mark));
|
|
122
|
-
}
|
|
123
|
-
if (React.isValidElement(node)) {
|
|
124
|
-
const children = node.props.children;
|
|
125
|
-
// A component whose children are a render prop, and every void element:
|
|
126
|
-
// there is no text in either, and cloning one with a `children` it never
|
|
127
|
-
// declared is how an `<input>` ends up with a child.
|
|
128
|
-
if (children === undefined || typeof children === 'function') {
|
|
129
|
-
return node;
|
|
130
|
-
}
|
|
131
|
-
return React.cloneElement(node, undefined, markNode(children, pattern, wholeWord, mark));
|
|
132
|
-
}
|
|
133
|
-
return node;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Marks the words a reader is looking for, inside text they were already
|
|
137
|
-
* reading.
|
|
138
|
-
*
|
|
139
|
-
* The component is the search, not just the styling: `query` is what a search
|
|
140
|
-
* box holds, and everything about *how* the matching is done — case, whole
|
|
141
|
-
* words, a regular expression — is a prop rather than something a caller has to
|
|
142
|
-
* pre-compute into a list of offsets.
|
|
143
|
-
*
|
|
144
|
-
* The mark is a real `<mark>`, which is the element for "text of relevance to
|
|
145
|
-
* the reader" and is announced as such. That has one consequence worth knowing:
|
|
146
|
-
* marking eleven words in a paragraph tells a screen reader that eleven things
|
|
147
|
-
* are important, which is a way of saying nothing. A highlight is for a handful
|
|
148
|
-
* of matches.
|
|
149
|
-
*
|
|
150
|
-
* Nothing here is stateful and nothing measures — the whole component is a pure
|
|
151
|
-
* function of `children` and `query`, so it re-marks on its own the moment the
|
|
152
|
-
* search box changes.
|
|
153
|
-
*/
|
|
154
|
-
export const PlHighlight = /* @__PURE__ */ React.forwardRef(function PlHighlight({ query, variant = 'solid', color = 'warning', caseSensitive = false, wholeWord = false, underline = false, weight, className, style, children, ...props }, ref) {
|
|
155
|
-
const pattern = React.useMemo(() => buildPattern(query, caseSensitive), [query, caseSensitive]);
|
|
156
|
-
const markClasses = [
|
|
157
|
-
// A hair of padding so the surface does not sit flush against the letters,
|
|
158
|
-
// and the same hair back out as a negative margin so the marked line is the
|
|
159
|
-
// same length as it was before. A mark must not move the text around it.
|
|
160
|
-
'-mx-0.5 rounded-[0.25rem] px-0.5',
|
|
161
|
-
// A mark that wraps across two lines gets its corners on both fragments
|
|
162
|
-
// rather than one long box with two square ends.
|
|
163
|
-
'box-decoration-clone',
|
|
164
|
-
variantClasses[variant],
|
|
165
|
-
// `decoration-2` and the offset so the rule sits under the descenders rather
|
|
166
|
-
// than through them, which is the whole difference between an underline and
|
|
167
|
-
// a strikethrough that missed.
|
|
168
|
-
underline ? 'underline decoration-2 underline-offset-2' : '',
|
|
169
|
-
weight ? weightClasses[weight] : '',
|
|
170
|
-
transitionClasses
|
|
171
|
-
]
|
|
172
|
-
.filter(Boolean)
|
|
173
|
-
.join(' ');
|
|
174
|
-
const marked = pattern
|
|
175
|
-
? markNode(children, pattern, wholeWord, (matched, key) => (_jsx("mark", { className: markClasses, children: matched }, key)))
|
|
176
|
-
: children;
|
|
177
|
-
return (_jsx("span", { ref: ref, className: className, style: {
|
|
178
|
-
'--p-fill': `var(--plass-${color}-fill)`,
|
|
179
|
-
'--p-on-solid': `var(--plass-${color}-on-solid)`,
|
|
180
|
-
'--p-accent': `var(--plass-${color}-accent)`,
|
|
181
|
-
'--p-soft': `var(--plass-${color}-soft)`,
|
|
182
|
-
'--p-line': `var(--plass-${color}-line)`,
|
|
183
|
-
...style
|
|
184
|
-
}, ...props, children: marked }));
|
|
185
|
-
});
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import*as n from"react";import{transitionClasses as r}from"../../internal/styles.js";const t={solid:"[background-image:var(--p-fill)] text-(--p-on-solid)",glass:"border bg-(--p-soft) text-(--p-accent) [border-color:var(--p-line)]",ghost:"bg-transparent text-(--p-accent)"},o={regular:"font-normal",medium:"font-medium",semibold:"font-semibold",bold:"font-bold"},l=/[\p{L}\p{N}_]/u;function escapeRegExp(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function isWholeWord(e,n,r){const t=n>0?e[n-1]:"",o=r<e.length?e[r]:"";return!l.test(t)&&!l.test(o)}function markString(e,n,r,t){n.lastIndex=0;const o=[];let l,i=0;for(;null!==(l=n.exec(e));){if(""===l[0]){n.lastIndex+=1;continue}const s=l.index,a=s+l[0].length;r&&!isWholeWord(e,s,a)||(s>i&&o.push(e.slice(i,s)),o.push(t(l[0],`${s}`)),i=a)}return 0===o.length?e:(i<e.length&&o.push(e.slice(i)),o)}function markNode(e,r,t,o){if("string"==typeof e)return markString(e,r,t,o);if("number"==typeof e)return markString(String(e),r,t,o);if(Array.isArray(e))return n.Children.map(e,e=>markNode(e,r,t,o));if(n.isValidElement(e)){const l=e.props.children;return void 0===l||"function"==typeof l?e:n.cloneElement(e,void 0,markNode(l,r,t,o))}return e}export const PlHighlight=/* @__PURE__ */n.forwardRef(function PlHighlight({query:l,variant:i="solid",color:s="warning",caseSensitive:a=!1,wholeWord:c=!1,underline:p=!1,weight:u,className:d,style:f,children:g,...m},h){const x=n.useMemo(()=>function buildPattern(e,n){if(e instanceof RegExp)return new RegExp(e.source,e.global?e.flags:`${e.flags}g`);const r=(Array.isArray(e)?e:[e]).map(e=>e.trim()).filter(Boolean).sort((e,n)=>n.length-e.length);return 0===r.length?null:new RegExp(r.map(escapeRegExp).join("|"),n?"gu":"giu")}(l,a),[l,a]),b=["-mx-0.5 rounded-[0.25rem] px-0.5","box-decoration-clone",t[i],p?"underline decoration-2 underline-offset-2":"",u?o[u]:"",r].filter(Boolean).join(" "),v=x?markNode(g,x,c,(n,r)=>e("mark",{className:b,children:n},r)):g;return e("span",{ref:h,className:d,style:{"--p-fill":`var(--plass-${s}-fill)`,"--p-on-solid":`var(--plass-${s}-on-solid)`,"--p-accent":`var(--plass-${s}-accent)`,"--p-soft":`var(--plass-${s}-soft)`,"--p-line":`var(--plass-${s}-line)`,...f},...m,children:v})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlHighlight}from"./PlHighlight.js";
|