@phreshos/react-ui 0.1.43 → 0.1.45
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/document-theme.d.ts +12 -0
- package/dist/document-theme.js +29 -0
- package/dist/grid-list.js +15 -18
- package/dist/main.d.ts +1 -0
- package/dist/main.js +1 -0
- package/dist/tabs.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps the document's color scheme on the Theme of the nearest UIProvider,
|
|
3
|
+
* or on the browser's without one. It writes the Theme into the document's
|
|
4
|
+
* `<meta name="color-scheme">`, creating the element when the document has
|
|
5
|
+
* none, before the browser paints, and follows every change. It renders
|
|
6
|
+
* nothing; place it once, where the Theme that owns the page is provided.
|
|
7
|
+
*
|
|
8
|
+
* A page embedded in a frame needs its color scheme to match the frame's, or
|
|
9
|
+
* the browser paints the frame opaque instead of letting what is behind it
|
|
10
|
+
* show.
|
|
11
|
+
*/
|
|
12
|
+
export declare function DocumentTheme(): null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
import { usePreferences } from "./foundation/visual.js";
|
|
3
|
+
/**
|
|
4
|
+
* Keeps the document's color scheme on the Theme of the nearest UIProvider,
|
|
5
|
+
* or on the browser's without one. It writes the Theme into the document's
|
|
6
|
+
* `<meta name="color-scheme">`, creating the element when the document has
|
|
7
|
+
* none, before the browser paints, and follows every change. It renders
|
|
8
|
+
* nothing; place it once, where the Theme that owns the page is provided.
|
|
9
|
+
*
|
|
10
|
+
* A page embedded in a frame needs its color scheme to match the frame's, or
|
|
11
|
+
* the browser paints the frame opaque instead of letting what is behind it
|
|
12
|
+
* show.
|
|
13
|
+
*/
|
|
14
|
+
export function DocumentTheme() {
|
|
15
|
+
const { theme } = usePreferences();
|
|
16
|
+
useLayoutEffect(() => {
|
|
17
|
+
const existing = document.head.querySelector('meta[name="color-scheme" i]');
|
|
18
|
+
const meta = existing ?? document.head.appendChild(Object.assign(document.createElement("meta"), { name: "color-scheme" }));
|
|
19
|
+
const previous = meta.content;
|
|
20
|
+
meta.content = theme;
|
|
21
|
+
return () => {
|
|
22
|
+
if (existing)
|
|
23
|
+
meta.content = previous;
|
|
24
|
+
else
|
|
25
|
+
meta.remove();
|
|
26
|
+
};
|
|
27
|
+
}, [theme]);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
package/dist/grid-list.js
CHANGED
|
@@ -2,7 +2,6 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
2
2
|
import { createContext, forwardRef, useContext, useMemo } from "react";
|
|
3
3
|
import { GridList as AriaGridList, GridListHeader as AriaGridListHeader, GridListItem as AriaGridListItem, GridListSection as AriaGridListSection } from "react-aria-components";
|
|
4
4
|
import { useControlMetrics } from "./control/control.js";
|
|
5
|
-
import { separatorColor } from "./control/field.js";
|
|
6
5
|
import { itemSurface, SelectionMark } from "./control/item.js";
|
|
7
6
|
import { ariaSelection } from "./control/selection.js";
|
|
8
7
|
import { surfaceRender } from "./control/surface-render.js";
|
|
@@ -31,18 +30,24 @@ const GridListRootImplementation = forwardRef(function GridList(properties, ref)
|
|
|
31
30
|
...style
|
|
32
31
|
} }) }) });
|
|
33
32
|
});
|
|
34
|
-
/** One card. It holds whatever it is given, shows
|
|
33
|
+
/** One card. It holds whatever it is given, and shows a check in its corner when selected. */
|
|
35
34
|
const GridListItemImplementation = forwardRef(function GridListItem({ children, className, color, disabled = false, style, textValue, ...properties }, ref) {
|
|
36
35
|
const inherited = useGridListStyle();
|
|
37
36
|
const itemColor = color ?? inherited.color;
|
|
38
37
|
const { metrics } = inherited;
|
|
39
|
-
return _jsx(AriaGridListItem, { ...properties, ref: ref, textValue: textValue ?? (typeof children === "string" ? children : undefined), className: className, isDisabled: disabled, render: surfaceRender("div", state =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
return _jsx(AriaGridListItem, { ...properties, ref: ref, textValue: textValue ?? (typeof children === "string" ? children : undefined), className: className, isDisabled: disabled, render: surfaceRender("div", state => ({
|
|
39
|
+
...itemSurface(metrics.visual, itemColor, {
|
|
40
|
+
selected: state.isSelected,
|
|
41
|
+
hovered: state.isHovered,
|
|
42
|
+
pressed: state.isPressed,
|
|
43
|
+
focusVisible: state.isFocusVisible,
|
|
44
|
+
disabled: state.isDisabled
|
|
45
|
+
}, metrics.radius),
|
|
46
|
+
// Unlike a list row, a card is a whole Surface: flat, in the default color at rest, in its
|
|
47
|
+
// selection color once selected, with the default material in both.
|
|
48
|
+
...(state.isSelected ? {} : { color: "default" }),
|
|
49
|
+
material: undefined
|
|
50
|
+
})), style: {
|
|
46
51
|
position: "relative",
|
|
47
52
|
display: "grid",
|
|
48
53
|
alignContent: "start",
|
|
@@ -54,15 +59,7 @@ const GridListItemImplementation = forwardRef(function GridListItem({ children,
|
|
|
54
59
|
userSelect: "none",
|
|
55
60
|
outlineOffset: -1,
|
|
56
61
|
...style
|
|
57
|
-
}, children: state => _jsxs(_Fragment, { children: [_jsx("span", { "
|
|
58
|
-
position: "absolute",
|
|
59
|
-
inset: 0,
|
|
60
|
-
// The card's own radius: the edge sits inside the grid cell, not directly in the card.
|
|
61
|
-
borderRadius: metrics.radius,
|
|
62
|
-
border: `1px solid ${separatorColor(metrics)}`,
|
|
63
|
-
opacity: state.isSelected ? 0 : 1,
|
|
64
|
-
pointerEvents: "none"
|
|
65
|
-
} }), typeof children === "function" ? children(state) : children, _jsx("span", { style: { position: "absolute", insetBlockStart: metrics.inset, insetInlineEnd: metrics.inset, display: "flex" }, children: _jsx(SelectionMark, { visible: state.isSelected }) })] }) });
|
|
62
|
+
}, children: state => _jsxs(_Fragment, { children: [typeof children === "function" ? children(state) : children, _jsx("span", { style: { position: "absolute", insetBlockStart: metrics.inset, insetInlineEnd: metrics.inset, display: "flex" }, children: _jsx(SelectionMark, { visible: state.isSelected }) })] }) });
|
|
66
63
|
});
|
|
67
64
|
/** A Section spans the whole grid and lays its own Items out in the same columns. */
|
|
68
65
|
const GridListSectionImplementation = forwardRef(function GridListSection({ className, style, ...properties }, ref) {
|
package/dist/main.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { appearanceLimits, defaultAppearance, type Appearance, type AppearanceColor, type AppearanceColors, type AppearanceMaterial, type AppearanceRange, type AppearanceShadow, type AppearanceTransaction, type AppearanceUpdate, type Easing, type ThemedValue } from "./foundation/appearance.js";
|
|
8
8
|
export { UIProvider, type UIProviderProps } from "./foundation/provider.js";
|
|
9
|
+
export { DocumentTheme } from "./document-theme.js";
|
|
9
10
|
export { useAppearance, useBrowserPreferences, usePreferences, useThemedValue } from "./foundation/visual.js";
|
|
10
11
|
export { useDirection, useDocumentDirection, type Direction } from "./foundation/direction.js";
|
|
11
12
|
export type { Preferences, PreferencesUpdate, Theme } from "./foundation/preferences.js";
|
package/dist/main.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { appearanceLimits, defaultAppearance } from "./foundation/appearance.js";
|
|
8
8
|
export { UIProvider } from "./foundation/provider.js";
|
|
9
|
+
export { DocumentTheme } from "./document-theme.js";
|
|
9
10
|
export { useAppearance, useBrowserPreferences, usePreferences, useThemedValue } from "./foundation/visual.js";
|
|
10
11
|
export { useDirection, useDocumentDirection } from "./foundation/direction.js";
|
|
11
12
|
export { Flex } from "./flex.js";
|
package/dist/tabs.js
CHANGED
|
@@ -21,7 +21,6 @@ const TabsRoot = forwardRef(function Tabs({ className, color = "default", defaul
|
|
|
21
21
|
gap: metrics.gap,
|
|
22
22
|
minWidth: 0,
|
|
23
23
|
fontFamily: "inherit",
|
|
24
|
-
fontSize: metrics.fontSize,
|
|
25
24
|
...style
|
|
26
25
|
} }) }) });
|
|
27
26
|
});
|
|
@@ -29,7 +28,8 @@ const TabsRoot = forwardRef(function Tabs({ className, color = "default", defaul
|
|
|
29
28
|
const TabsListImplementation = forwardRef(function TabsList({ className, style, ...properties }, ref) {
|
|
30
29
|
const { color, material, metrics, orientation } = useTabsStyle();
|
|
31
30
|
const selectedKey = useContext(TabListStateContext)?.selectedKey;
|
|
32
|
-
|
|
31
|
+
// Only the Tabs take the Tabs' size: the Panels hold consumer content, which keeps its own.
|
|
32
|
+
return _jsx(SelectionTrack, { metrics: metrics, color: color, material: material, orientation: orientation, selectedKey: selectedKey, className: className, style: { fontSize: metrics.fontSize, ...style }, children: _jsx(AriaTabList, { ...properties, ref: ref, "data-selection-list": "", style: selectionListStyle(orientation) }) });
|
|
33
33
|
});
|
|
34
34
|
const TabsTab = forwardRef(function TabsTab({ children, className, disabled = false, style, ...properties }, ref) {
|
|
35
35
|
const { color, metrics, orientation } = useTabsStyle();
|