plass-ui 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +3 -2
|
@@ -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";
|
|
@@ -1,294 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { controlHeightClasses, controlSlots, controlTextClasses, glassClasses, paddingXClasses, radiusClasses, srOnlyClasses, transitionClasses } from '../../internal/styles.js';
|
|
4
|
-
const word = (text) => ({ symbol: text, name: text });
|
|
5
|
-
/**
|
|
6
|
-
* One entry per key that is spelled differently somewhere, keyed by the token
|
|
7
|
-
* with its case and spaces taken off.
|
|
8
|
-
*
|
|
9
|
-
* The aliases are deliberate and not generosity: `Cmd`, `Command` and `Meta` are
|
|
10
|
-
* three names one key already has, and a component that accepted only one of
|
|
11
|
-
* them would be a component every caller has to look up.
|
|
12
|
-
*
|
|
13
|
-
* `Mod` is the entry the rest exist for. It is the only token whose *meaning*
|
|
14
|
-
* changes with the platform rather than just its spelling — the modifier a
|
|
15
|
-
* shortcut is actually built on, which is Command on a Mac and Control
|
|
16
|
-
* everywhere else. Writing `Ctrl` and hoping is what makes a documentation page
|
|
17
|
-
* wrong for half its readers.
|
|
18
|
-
*/
|
|
19
|
-
const keyLabels = {
|
|
20
|
-
mod: {
|
|
21
|
-
mac: { symbol: '⌘', name: 'Command' },
|
|
22
|
-
windows: word('Ctrl'),
|
|
23
|
-
linux: word('Ctrl')
|
|
24
|
-
},
|
|
25
|
-
meta: {
|
|
26
|
-
mac: { symbol: '⌘', name: 'Command' },
|
|
27
|
-
windows: word('Win'),
|
|
28
|
-
linux: word('Super')
|
|
29
|
-
},
|
|
30
|
-
ctrl: {
|
|
31
|
-
mac: { symbol: '⌃', name: 'Control' },
|
|
32
|
-
windows: word('Ctrl'),
|
|
33
|
-
linux: word('Ctrl')
|
|
34
|
-
},
|
|
35
|
-
alt: {
|
|
36
|
-
mac: { symbol: '⌥', name: 'Option' },
|
|
37
|
-
windows: word('Alt'),
|
|
38
|
-
linux: word('Alt')
|
|
39
|
-
},
|
|
40
|
-
shift: {
|
|
41
|
-
mac: { symbol: '⇧', name: 'Shift' },
|
|
42
|
-
windows: word('Shift'),
|
|
43
|
-
linux: word('Shift')
|
|
44
|
-
},
|
|
45
|
-
enter: {
|
|
46
|
-
mac: { symbol: '↩', name: 'Enter' },
|
|
47
|
-
windows: word('Enter'),
|
|
48
|
-
linux: word('Enter')
|
|
49
|
-
},
|
|
50
|
-
tab: {
|
|
51
|
-
mac: { symbol: '⇥', name: 'Tab' },
|
|
52
|
-
windows: word('Tab'),
|
|
53
|
-
linux: word('Tab')
|
|
54
|
-
},
|
|
55
|
-
escape: {
|
|
56
|
-
mac: { symbol: '⎋', name: 'Escape' },
|
|
57
|
-
windows: word('Esc'),
|
|
58
|
-
linux: word('Esc')
|
|
59
|
-
},
|
|
60
|
-
backspace: {
|
|
61
|
-
mac: { symbol: '⌫', name: 'Backspace' },
|
|
62
|
-
windows: word('Backspace'),
|
|
63
|
-
linux: word('Backspace')
|
|
64
|
-
},
|
|
65
|
-
delete: {
|
|
66
|
-
mac: { symbol: '⌦', name: 'Delete' },
|
|
67
|
-
windows: word('Del'),
|
|
68
|
-
linux: word('Del')
|
|
69
|
-
},
|
|
70
|
-
capslock: {
|
|
71
|
-
mac: { symbol: '⇪', name: 'Caps Lock' },
|
|
72
|
-
windows: word('Caps Lock'),
|
|
73
|
-
linux: word('Caps Lock')
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
/** The tokens that name one key by more than one word. */
|
|
77
|
-
const keyAliases = {
|
|
78
|
-
cmdorctrl: 'mod',
|
|
79
|
-
commandorcontrol: 'mod',
|
|
80
|
-
cmd: 'meta',
|
|
81
|
-
command: 'meta',
|
|
82
|
-
super: 'meta',
|
|
83
|
-
win: 'meta',
|
|
84
|
-
windows: 'meta',
|
|
85
|
-
control: 'ctrl',
|
|
86
|
-
option: 'alt',
|
|
87
|
-
opt: 'alt',
|
|
88
|
-
return: 'enter',
|
|
89
|
-
esc: 'escape',
|
|
90
|
-
del: 'delete',
|
|
91
|
-
caps: 'capslock'
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* The keys drawn as arrows on every platform, not just on a Mac. An arrow is not
|
|
95
|
-
* a Mac convention — it is what is printed on the key.
|
|
96
|
-
*/
|
|
97
|
-
const arrowLabels = {
|
|
98
|
-
up: { symbol: '↑', name: 'Arrow up' },
|
|
99
|
-
down: { symbol: '↓', name: 'Arrow down' },
|
|
100
|
-
left: { symbol: '←', name: 'Arrow left' },
|
|
101
|
-
right: { symbol: '→', name: 'Arrow right' },
|
|
102
|
-
arrowup: { symbol: '↑', name: 'Arrow up' },
|
|
103
|
-
arrowdown: { symbol: '↓', name: 'Arrow down' },
|
|
104
|
-
arrowleft: { symbol: '←', name: 'Arrow left' },
|
|
105
|
-
arrowright: { symbol: '→', name: 'Arrow right' }
|
|
106
|
-
};
|
|
107
|
-
/** Resolves one token into what to draw and what to announce. */
|
|
108
|
-
function labelFor(token, os) {
|
|
109
|
-
const normalized = token.toLowerCase().replace(/[\s_-]/g, '');
|
|
110
|
-
const canonical = keyAliases[normalized] ?? normalized;
|
|
111
|
-
const arrow = arrowLabels[canonical];
|
|
112
|
-
if (arrow) {
|
|
113
|
-
return arrow;
|
|
114
|
-
}
|
|
115
|
-
const known = keyLabels[canonical];
|
|
116
|
-
if (known) {
|
|
117
|
-
return known[os];
|
|
118
|
-
}
|
|
119
|
-
// Everything else is printed as it was written, with the one courtesy that a
|
|
120
|
-
// single letter is capitalised: `keys="mod+k"` should draw a K, because that
|
|
121
|
-
// is what is on the key.
|
|
122
|
-
return word(token.length === 1 ? token.toUpperCase() : token);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Splits the string form. Empty segments are what `'Ctrl++'` leaves behind, and
|
|
126
|
-
* dropping them is why the array form exists for that case.
|
|
127
|
-
*/
|
|
128
|
-
function tokenize(keys) {
|
|
129
|
-
if (Array.isArray(keys)) {
|
|
130
|
-
return keys.map((key) => key.trim()).filter(Boolean);
|
|
131
|
-
}
|
|
132
|
-
return keys
|
|
133
|
-
.split('+')
|
|
134
|
-
.map((key) => key.trim())
|
|
135
|
-
.filter(Boolean);
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* What the browser says it is running on.
|
|
139
|
-
*
|
|
140
|
-
* `userAgentData.platform` is the modern spelling and `navigator.platform` the
|
|
141
|
-
* deprecated one that every browser still answers; the user agent string is the
|
|
142
|
-
* last resort. All three are matched at once because the question here is coarse
|
|
143
|
-
* — which of three key caps to print — and getting it slightly wrong is a label,
|
|
144
|
-
* not a bug.
|
|
145
|
-
*/
|
|
146
|
-
function detectOS() {
|
|
147
|
-
if (typeof navigator === 'undefined') {
|
|
148
|
-
return 'windows';
|
|
149
|
-
}
|
|
150
|
-
const data = navigator.userAgentData;
|
|
151
|
-
const haystack = `${data?.platform ?? ''} ${navigator.platform ?? ''} ${navigator.userAgent ?? ''}`;
|
|
152
|
-
if (/mac|iphone|ipad|ipod/i.test(haystack)) {
|
|
153
|
-
return 'mac';
|
|
154
|
-
}
|
|
155
|
-
if (/win/i.test(haystack)) {
|
|
156
|
-
return 'windows';
|
|
157
|
-
}
|
|
158
|
-
return 'linux';
|
|
159
|
-
}
|
|
160
|
-
/** The platform never changes under a running page, so there is nothing to subscribe to. */
|
|
161
|
-
function subscribe() {
|
|
162
|
-
return () => { };
|
|
163
|
-
}
|
|
164
|
-
function serverOS() {
|
|
165
|
-
return 'windows';
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* `useSyncExternalStore` rather than `useEffect` plus state, and rather than
|
|
169
|
-
* reading `navigator` during render.
|
|
170
|
-
*
|
|
171
|
-
* Reading it during render is a hydration mismatch waiting to happen: the server
|
|
172
|
-
* has no `navigator`, so it would render `Ctrl` and the client would render `⌘`
|
|
173
|
-
* into the same markup. This hook is the one API that tells React the two are
|
|
174
|
-
* *meant* to differ — it hydrates with the server's answer and re-renders with
|
|
175
|
-
* the browser's, which is exactly the sequence a Mac reader sees.
|
|
176
|
-
*/
|
|
177
|
-
function useDetectedOS() {
|
|
178
|
-
return React.useSyncExternalStore(subscribe, detectOS, serverOS);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* A key cap sits one step down the control ladder: it is a token inside a line
|
|
182
|
-
* of text, not a control the line lines up against.
|
|
183
|
-
*/
|
|
184
|
-
const keyScale = {
|
|
185
|
-
xs: 'xs',
|
|
186
|
-
sm: 'xs',
|
|
187
|
-
md: 'sm',
|
|
188
|
-
lg: 'md',
|
|
189
|
-
xl: 'lg'
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* The three materials, and the one place in the library where a filled surface
|
|
193
|
-
* gets a hard-edged shadow directly under it.
|
|
194
|
-
*
|
|
195
|
-
* That lip is not the gloss line the design language rules out — a gloss line is
|
|
196
|
-
* a highlight *on* the surface, claiming a lamp. This is a two-pixel offset
|
|
197
|
-
* shadow *under* it, which is the one thing every printed manual has used to
|
|
198
|
-
* mean "this is a key you press". A picture of a key is allowed to look like a
|
|
199
|
-
* key; a control is not allowed to look like a picture of one.
|
|
200
|
-
*
|
|
201
|
-
* `glass` is the default, because a hairline box is what a key cap has looked
|
|
202
|
-
* like in every manual ever printed. Its edge is `--plass-border` rather than
|
|
203
|
-
* the sheet's white hairline, or a cap set on a light card would have no edge.
|
|
204
|
-
*/
|
|
205
|
-
const variantClasses = {
|
|
206
|
-
solid: /* @__PURE__ */ [
|
|
207
|
-
'text-(--p-on-solid) [background-image:var(--p-fill)]',
|
|
208
|
-
'[box-shadow:var(--p-elev),0_2px_0_0_var(--p-tint)]'
|
|
209
|
-
].join(' '),
|
|
210
|
-
glass: /* @__PURE__ */ [
|
|
211
|
-
glassClasses,
|
|
212
|
-
'border text-(--p-accent) bg-(--plass-glass)',
|
|
213
|
-
'[border-color:var(--plass-border)]',
|
|
214
|
-
'[box-shadow:var(--p-elev),0_2px_0_0_var(--plass-shadow-ambient)]'
|
|
215
|
-
].join(' '),
|
|
216
|
-
ghost: 'text-(--p-accent) bg-(--p-soft)'
|
|
217
|
-
};
|
|
218
|
-
/** The width a single-letter cap is held to, so `⌘` and `K` are the same square. */
|
|
219
|
-
const keyMinWidthClasses = {
|
|
220
|
-
xs: 'min-w-6',
|
|
221
|
-
sm: 'min-w-8',
|
|
222
|
-
md: 'min-w-10',
|
|
223
|
-
lg: 'min-w-12',
|
|
224
|
-
xl: 'min-w-14'
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* One key cap.
|
|
228
|
-
*
|
|
229
|
-
* Exported so a caller can compose a layout this component does not draw — a
|
|
230
|
-
* numeric keypad, a row of function keys — out of the same object the shortcut
|
|
231
|
-
* strip is made of.
|
|
232
|
-
*
|
|
233
|
-
* It reads its colour slots from whatever set them, which is the `PlHotKeys`
|
|
234
|
-
* around it in the common case. On its own it falls back to the page's own ink,
|
|
235
|
-
* so a bare `<PlKbd>` still draws.
|
|
236
|
-
*/
|
|
237
|
-
export const PlKbd = /* @__PURE__ */ React.forwardRef(function PlKbd({ variant = 'glass', size = 'md', density = 'compact', className, children, ...props }, ref) {
|
|
238
|
-
const step = keyScale[size];
|
|
239
|
-
return (_jsx("kbd", { ref: ref, className: [
|
|
240
|
-
'inline-flex shrink-0 items-center justify-center',
|
|
241
|
-
'font-mono leading-none font-medium tabular-nums whitespace-nowrap',
|
|
242
|
-
controlHeightClasses[step],
|
|
243
|
-
controlTextClasses[step],
|
|
244
|
-
keyMinWidthClasses[step],
|
|
245
|
-
paddingXClasses[density][step],
|
|
246
|
-
radiusClasses[step],
|
|
247
|
-
variantClasses[variant],
|
|
248
|
-
transitionClasses,
|
|
249
|
-
className ?? ''
|
|
250
|
-
]
|
|
251
|
-
.filter(Boolean)
|
|
252
|
-
.join(' '), ...props, children: children }));
|
|
253
|
-
});
|
|
254
|
-
/**
|
|
255
|
-
* A keyboard key, a combination of them, or the four movement keys as they sit
|
|
256
|
-
* on the keyboard.
|
|
257
|
-
*
|
|
258
|
-
* Two things make this more than a styled `<kbd>`, and both are about the label
|
|
259
|
-
* rather than the box around it.
|
|
260
|
-
*
|
|
261
|
-
* The first is `Mod`. A shortcut written as `Ctrl+K` is wrong for every Mac
|
|
262
|
-
* reader and one written as `⌘K` is wrong for everybody else, so the token that
|
|
263
|
-
* means "the modifier shortcuts are built on" resolves per platform — and `os`
|
|
264
|
-
* is there for the pages that have to name a platform rather than the reader's.
|
|
265
|
-
*
|
|
266
|
-
* The second is that `⌘` is not a word. A screen reader reads it as "place of
|
|
267
|
-
* interest sign", so every key drawn as a glyph carries its name beside it, in
|
|
268
|
-
* the clipped box `srOnlyClasses` describes. What is announced is "Command K",
|
|
269
|
-
* which is what the shortcut is called.
|
|
270
|
-
*
|
|
271
|
-
* The keys are real `<kbd>` elements; the wrapper around them is a `<span>`.
|
|
272
|
-
* Nesting `<kbd>` inside `<kbd>` is allowed and would also be defensible, but a
|
|
273
|
-
* `kbd` wrapper is a second box for a host stylesheet to reach into for no gain
|
|
274
|
-
* — the semantics are carried by the keys themselves either way.
|
|
275
|
-
*/
|
|
276
|
-
export const PlHotKeys = /* @__PURE__ */ React.forwardRef(function PlHotKeys({ variant = 'glass', size = 'md', color = 'secondary', density = 'compact', elevation = 0, keys, cluster, os = 'auto', separator, className, style, ...props }, ref) {
|
|
277
|
-
const detected = useDetectedOS();
|
|
278
|
-
const resolved = os === 'auto' ? detected : os;
|
|
279
|
-
const slots = { ...controlSlots(color, elevation, variant), ...style };
|
|
280
|
-
const capProps = { variant, size, density };
|
|
281
|
-
const gap = size === 'xs' || size === 'sm' ? 'gap-1' : 'gap-1.5';
|
|
282
|
-
if (cluster) {
|
|
283
|
-
return (_jsxs("span", { ref: ref, className: ['inline-flex flex-col items-center align-middle', gap, className ?? '']
|
|
284
|
-
.filter(Boolean)
|
|
285
|
-
.join(' '), style: slots, ...props, children: [_jsx(PlKbd, { ...capProps, children: cluster.up }), _jsxs("span", { className: `inline-flex ${gap}`, children: [_jsx(PlKbd, { ...capProps, children: cluster.left }), _jsx(PlKbd, { ...capProps, children: cluster.down }), _jsx(PlKbd, { ...capProps, children: cluster.right })] })] }));
|
|
286
|
-
}
|
|
287
|
-
const labels = tokenize(keys ?? []).map((token) => labelFor(token, resolved));
|
|
288
|
-
// macOS writes a shortcut as a run of symbols with nothing between them; the
|
|
289
|
-
// other two join theirs with a `+`. A caller who passes one gets theirs.
|
|
290
|
-
const joiner = separator === undefined ? (resolved === 'mac' ? null : '+') : separator;
|
|
291
|
-
return (_jsx("span", { ref: ref, className: ['inline-flex max-w-full items-center gap-1 align-middle', className ?? '']
|
|
292
|
-
.filter(Boolean)
|
|
293
|
-
.join(' '), style: slots, ...props, children: labels.map((label, index) => (_jsxs(React.Fragment, { children: [index > 0 && joiner !== null ? (_jsx("span", { "aria-hidden": "true", className: "text-(--plass-muted-fg)", children: joiner })) : null, _jsx(PlKbd, { ...capProps, children: label.symbol === label.name ? (label.symbol) : (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: label.symbol }), _jsx("span", { className: srOnlyClasses, children: label.name })] })) })] }, index))) }));
|
|
294
|
-
});
|
|
1
|
+
"use client";import{jsx as e,jsxs as n,Fragment as a}from"react/jsx-runtime";import*as o from"react";import{controlHeightClasses as r,controlSlots as s,controlTextClasses as t,glassClasses as l,paddingXClasses as i,radiusClasses as m,srOnlyClasses as c,transitionClasses as d}from"../../internal/styles.js";const word=e=>({symbol:e,name:e}),p={mod:{mac:{symbol:"⌘",name:"Command"},windows:word("Ctrl"),linux:word("Ctrl")},meta:{mac:{symbol:"⌘",name:"Command"},windows:word("Win"),linux:word("Super")},ctrl:{mac:{symbol:"⌃",name:"Control"},windows:word("Ctrl"),linux:word("Ctrl")},alt:{mac:{symbol:"⌥",name:"Option"},windows:word("Alt"),linux:word("Alt")},shift:{mac:{symbol:"⇧",name:"Shift"},windows:word("Shift"),linux:word("Shift")},enter:{mac:{symbol:"↩",name:"Enter"},windows:word("Enter"),linux:word("Enter")},tab:{mac:{symbol:"⇥",name:"Tab"},windows:word("Tab"),linux:word("Tab")},escape:{mac:{symbol:"⎋",name:"Escape"},windows:word("Esc"),linux:word("Esc")},backspace:{mac:{symbol:"⌫",name:"Backspace"},windows:word("Backspace"),linux:word("Backspace")},delete:{mac:{symbol:"⌦",name:"Delete"},windows:word("Del"),linux:word("Del")},capslock:{mac:{symbol:"⇪",name:"Caps Lock"},windows:word("Caps Lock"),linux:word("Caps Lock")}},u={cmdorctrl:"mod",commandorcontrol:"mod",cmd:"meta",command:"meta",super:"meta",win:"meta",windows:"meta",control:"ctrl",option:"alt",opt:"alt",return:"enter",esc:"escape",del:"delete",caps:"capslock"},w={up:{symbol:"↑",name:"Arrow up"},down:{symbol:"↓",name:"Arrow down"},left:{symbol:"←",name:"Arrow left"},right:{symbol:"→",name:"Arrow right"},arrowup:{symbol:"↑",name:"Arrow up"},arrowdown:{symbol:"↓",name:"Arrow down"},arrowleft:{symbol:"←",name:"Arrow left"},arrowright:{symbol:"→",name:"Arrow right"}};function detectOS(){if("undefined"==typeof navigator)return"windows";const e=navigator.userAgentData,n=`${e?.platform??""} ${navigator.platform??""} ${navigator.userAgent??""}`;return/mac|iphone|ipad|ipod/i.test(n)?"mac":/win/i.test(n)?"windows":"linux"}function subscribe(){return()=>{}}function serverOS(){return"windows"}const b={xs:"xs",sm:"xs",md:"sm",lg:"md",xl:"lg"},f={solid:/* @__PURE__ */["text-(--p-on-solid) [background-image:var(--p-fill)]","[box-shadow:var(--p-elev),0_2px_0_0_var(--p-tint)]"].join(" "),glass:/* @__PURE__ */[l,"border text-(--p-accent) bg-(--plass-glass)","[border-color:var(--plass-border)]","[box-shadow:var(--p-elev),0_2px_0_0_var(--plass-shadow-ambient)]"].join(" "),ghost:"text-(--p-accent) bg-(--p-soft)"},x={xs:"min-w-6",sm:"min-w-8",md:"min-w-10",lg:"min-w-12",xl:"min-w-14"};export const PlKbd=/* @__PURE__ */o.forwardRef(function PlKbd({variant:n="glass",size:a="md",density:o="compact",className:s,children:l,...c},p){const u=b[a];return e("kbd",{ref:p,className:["inline-flex shrink-0 items-center justify-center","font-mono leading-none font-medium tabular-nums whitespace-nowrap",r[u],t[u],x[u],i[o][u],m[u],f[n],d,s??""].filter(Boolean).join(" "),...c,children:l})});export const PlHotKeys=/* @__PURE__ */o.forwardRef(function PlHotKeys({variant:r="glass",size:t="md",color:l="secondary",density:i="compact",elevation:m=0,keys:d,cluster:b,os:f="auto",separator:x,className:y,style:g,...h},v){const k=function useDetectedOS(){return o.useSyncExternalStore(subscribe,detectOS,serverOS)}(),A="auto"===f?k:f,C={...s(l,m,r),...g},S={variant:r,size:t,density:i},j="xs"===t||"sm"===t?"gap-1":"gap-1.5";if(b)return n("span",{ref:v,className:["inline-flex flex-col items-center align-middle",j,y??""].filter(Boolean).join(" "),style:C,...h,children:[e(PlKbd,{...S,children:b.up}),n("span",{className:`inline-flex ${j}`,children:[e(PlKbd,{...S,children:b.left}),e(PlKbd,{...S,children:b.down}),e(PlKbd,{...S,children:b.right})]})]});const K=function tokenize(e){return Array.isArray(e)?e.map(e=>e.trim()).filter(Boolean):e.split("+").map(e=>e.trim()).filter(Boolean)}(d??[]).map(e=>function labelFor(e,n){const a=e.toLowerCase().replace(/[\s_-]/g,""),o=u[a]??a,r=w[o];if(r)return r;const s=p[o];return s?s[n]:word(1===e.length?e.toUpperCase():e)}(e,A)),P=void 0===x?"mac"===A?null:"+":x;return e("span",{ref:v,className:["inline-flex max-w-full items-center gap-1 align-middle",y??""].filter(Boolean).join(" "),style:C,...h,children:K.map((r,s)=>n(o.Fragment,{children:[s>0&&null!==P?e("span",{"aria-hidden":"true",className:"text-(--plass-muted-fg)",children:P}):null,e(PlKbd,{...S,children:r.symbol===r.name?r.symbol:n(a,{children:[e("span",{"aria-hidden":"true",children:r.symbol}),e("span",{className:c,children:r.name})]})})]},s))})});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export{PlHotKeys,PlKbd}from"./PlHotKeys.js";
|
|
@@ -1,58 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { iconSizeClasses } from '../../internal/styles.js';
|
|
4
|
-
/**
|
|
5
|
-
* The same five lengths as `iconSizeClasses`, as a font size.
|
|
6
|
-
*
|
|
7
|
-
* Written out rather than inherited: an icon set hands back an `<svg>` sized in
|
|
8
|
-
* `em` about as often as one sized in `px`, and the only way both come out right
|
|
9
|
-
* is for the box's own font size to *be* the box. `text-[length:inherit]` would
|
|
10
|
-
* take the surrounding paragraph's, which is the one size the box deliberately
|
|
11
|
-
* is not.
|
|
12
|
-
*/
|
|
13
|
-
const glyphFontClasses = {
|
|
14
|
-
xs: 'text-[0.875rem]',
|
|
15
|
-
sm: 'text-[1rem]',
|
|
16
|
-
md: 'text-[1.25rem]',
|
|
17
|
-
lg: 'text-[1.5rem]',
|
|
18
|
-
xl: 'text-[1.75rem]'
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* A glyph at a known size, in a known colour.
|
|
22
|
-
*
|
|
23
|
-
* The library draws no icons of its own beyond the handful its components need —
|
|
24
|
-
* an icon set is a decision that belongs to the app, not to the component
|
|
25
|
-
* library it installs. What this does is give whatever icon the app chose the
|
|
26
|
-
* same two axes everything else here has.
|
|
27
|
-
*
|
|
28
|
-
* The box is `inline-flex` with the glyph told to fill it, and `font-size` is
|
|
29
|
-
* set to the same length — so an `<svg>` with its own `width`, an `<svg>` sized
|
|
30
|
-
* in `em`, and a bare character all come out the same size. That is the whole
|
|
31
|
-
* component: a box, a length written twice, and a colour.
|
|
32
|
-
*
|
|
33
|
-
* There is no `variant` and no `elevation`. An icon is not a surface: it is ink,
|
|
34
|
-
* and the only thing the design language has to say about ink is which family it
|
|
35
|
-
* is drawn in.
|
|
36
|
-
*/
|
|
37
|
-
export const PlIcon = /* @__PURE__ */ React.forwardRef(function PlIcon({ icon, size = 'md', color = 'inherit', label, className, style, ...props }, ref) {
|
|
38
|
-
const classNames = [
|
|
39
|
-
'inline-flex shrink-0 items-center justify-center align-middle',
|
|
40
|
-
iconSizeClasses[size],
|
|
41
|
-
// The glyph fills the box however it was authored. `[font-size:100%]` on the
|
|
42
|
-
// box itself would be a no-op; what makes an em-sized drawing come out right
|
|
43
|
-
// is the box being an em, which `size-*` and this pair together arrange.
|
|
44
|
-
'[&>svg]:block [&>svg]:size-full [&>img]:block [&>img]:size-full',
|
|
45
|
-
`leading-none ${glyphFontClasses[size]}`,
|
|
46
|
-
color === 'inherit' ? '' : 'text-(--p-accent)',
|
|
47
|
-
className ?? ''
|
|
48
|
-
]
|
|
49
|
-
.filter(Boolean)
|
|
50
|
-
.join(' ');
|
|
51
|
-
return (_jsx("span", { ref: ref, className: classNames, style: (color === 'inherit'
|
|
52
|
-
? style
|
|
53
|
-
: { '--p-accent': `var(--plass-${color}-accent)`, ...style }),
|
|
54
|
-
// An icon with something to say is an `img` with a name; one without is
|
|
55
|
-
// furniture. There is no third case, and `role="img"` on a decorative glyph
|
|
56
|
-
// is the most common way a screen reader ends up saying "graphic".
|
|
57
|
-
role: label ? 'img' : undefined, "aria-label": label, "aria-hidden": label ? undefined : true, ...props, children: icon }));
|
|
58
|
-
});
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import*as t from"react";import{iconSizeClasses as i}from"../../internal/styles.js";const r={xs:"text-[0.875rem]",sm:"text-[1rem]",md:"text-[1.25rem]",lg:"text-[1.5rem]",xl:"text-[1.75rem]"};export const PlIcon=/* @__PURE__ */t.forwardRef(function PlIcon({icon:t,size:n="md",color:l="inherit",label:s,className:o,style:a,...c},m){const f=["inline-flex shrink-0 items-center justify-center align-middle",i[n],"[&>svg]:block [&>svg]:size-full [&>img]:block [&>img]:size-full",`leading-none ${r[n]}`,"inherit"===l?"":"text-(--p-accent)",o??""].filter(Boolean).join(" ");return e("span",{ref:m,className:f,style:"inherit"===l?a:{"--p-accent":`var(--plass-${l}-accent)`,...a},role:s?"img":void 0,"aria-label":s,"aria-hidden":!s||void 0,...c,children:t})});
|