opentui-responsive 0.2.8 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -12
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +3 -3
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Create the responsive provider in your layout, then use its hook directly in chi
|
|
|
41
41
|
import { createResponsiveTui } from "opentui-responsive/solid";
|
|
42
42
|
import type { ParentProps } from "solid-js";
|
|
43
43
|
|
|
44
|
-
export const { ResponsiveTUI,
|
|
44
|
+
export const { ResponsiveTUI, useBreakpoint } = createResponsiveTui({
|
|
45
45
|
// Required: each axis must include a 0 threshold.
|
|
46
46
|
width: { narrow: 0, medium: 60, wide: 100 },
|
|
47
47
|
height: { short: 0, medium: 16, tall: 28 },
|
|
@@ -55,10 +55,10 @@ export function Layout(props: ParentProps) {
|
|
|
55
55
|
`src/content.tsx`
|
|
56
56
|
|
|
57
57
|
```tsx
|
|
58
|
-
import {
|
|
58
|
+
import { useBreakpoint } from "./layout.tsx";
|
|
59
59
|
|
|
60
60
|
export function Content() {
|
|
61
|
-
const breakpoint =
|
|
61
|
+
const breakpoint = useBreakpoint();
|
|
62
62
|
// You can use it to directly check [width, height] breakpoint
|
|
63
63
|
const isWideAndTall = breakpoint(["wide", "tall"]);
|
|
64
64
|
|
|
@@ -87,7 +87,7 @@ export function App() {
|
|
|
87
87
|
}
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
`
|
|
90
|
+
`useBreakpoint()` updates when the terminal crosses a configured threshold. Its accessor returns the current width and height names, or accepts an exact `[width, height]` pair and returns whether both axes match.
|
|
91
91
|
|
|
92
92
|
Run `bun run demo` from the package directory to try the Solid example. Resize the terminal to see its layout respond.
|
|
93
93
|
|
|
@@ -97,14 +97,14 @@ The React adapter has the same factory, provider, hook, and inferred breakpoint
|
|
|
97
97
|
|
|
98
98
|
### `opentui-responsive/solid` and `opentui-responsive/react`
|
|
99
99
|
|
|
100
|
-
| API | Description
|
|
101
|
-
| --------------------------------- |
|
|
102
|
-
| `createResponsiveTui(scales)` | Validates the scales and creates a `ResponsiveTUI` provider and `
|
|
103
|
-
| `ResponsiveTUI` | Tracks terminal dimensions and provides the current breakpoint accessor.
|
|
104
|
-
| `
|
|
105
|
-
| `ResponsiveBreakpointAccessor` | Reads the current match or tests an exact breakpoint pair.
|
|
106
|
-
| `ResponsiveTuiConfigurationError` | Thrown when the supplied breakpoint scales are invalid.
|
|
107
|
-
| `ResponsiveTuiProviderError` | Thrown when the generated hook is called outside its provider.
|
|
100
|
+
| API | Description |
|
|
101
|
+
| --------------------------------- | ------------------------------------------------------------------------------------- |
|
|
102
|
+
| `createResponsiveTui(scales)` | Validates the scales and creates a `ResponsiveTUI` provider and `useBreakpoint` hook. |
|
|
103
|
+
| `ResponsiveTUI` | Tracks terminal dimensions and provides the current breakpoint accessor. |
|
|
104
|
+
| `useBreakpoint()` | Reads the accessor from the nearest generated provider. |
|
|
105
|
+
| `ResponsiveBreakpointAccessor` | Reads the current match or tests an exact breakpoint pair. |
|
|
106
|
+
| `ResponsiveTuiConfigurationError` | Thrown when the supplied breakpoint scales are invalid. |
|
|
107
|
+
| `ResponsiveTuiProviderError` | Thrown when the generated hook is called outside its provider. |
|
|
108
108
|
|
|
109
109
|
### `opentui-responsive/core`
|
|
110
110
|
|
package/dist/react/index.d.ts
CHANGED
|
@@ -14,5 +14,5 @@ export declare class ResponsiveTuiProviderError extends Error {
|
|
|
14
14
|
/** Creates a React provider and hook bound to one breakpoint definition. */
|
|
15
15
|
export declare const createResponsiveTui: <const Scales extends BreakpointScales>(scales: Parameters<typeof createBreakpointDefinition<Scales>>[0]) => {
|
|
16
16
|
ResponsiveTUI: (props: PropsWithChildren) => import("react").FunctionComponentElement<import("react").ProviderProps<ResponsiveBreakpointAccessor<Scales> | undefined>>;
|
|
17
|
-
|
|
17
|
+
useBreakpoint: () => ResponsiveBreakpointAccessor<Scales>;
|
|
18
18
|
};
|
package/dist/react/index.js
CHANGED
|
@@ -82,7 +82,7 @@ var isThreshold = (value) => typeof value === "number" && Number.isFinite(value)
|
|
|
82
82
|
class ResponsiveTuiProviderError extends Error {
|
|
83
83
|
_tag = "ResponsiveTuiProviderError";
|
|
84
84
|
constructor() {
|
|
85
|
-
super("
|
|
85
|
+
super("useBreakpoint must be used within a ResponsiveTUI");
|
|
86
86
|
this.name = this._tag;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -94,14 +94,14 @@ var createResponsiveTui = (scales) => {
|
|
|
94
94
|
const breakpoint = (pair) => pair ? breakpoints.matches(dimensions, pair) : breakpoints.match(dimensions);
|
|
95
95
|
return createElement(ResponsiveTuiContext.Provider, { value: breakpoint }, props.children);
|
|
96
96
|
};
|
|
97
|
-
const
|
|
97
|
+
const useBreakpoint = () => {
|
|
98
98
|
const breakpoint = useContext(ResponsiveTuiContext);
|
|
99
99
|
if (!breakpoint) {
|
|
100
100
|
throw new ResponsiveTuiProviderError;
|
|
101
101
|
}
|
|
102
102
|
return breakpoint;
|
|
103
103
|
};
|
|
104
|
-
return { ResponsiveTUI,
|
|
104
|
+
return { ResponsiveTUI, useBreakpoint };
|
|
105
105
|
};
|
|
106
106
|
export {
|
|
107
107
|
ResponsiveTuiConfigurationError,
|
package/dist/solid/index.d.ts
CHANGED
|
@@ -14,5 +14,5 @@ export declare class ResponsiveTuiProviderError extends Error {
|
|
|
14
14
|
/** Creates a Solid provider and hook bound to one breakpoint definition. */
|
|
15
15
|
export declare const createResponsiveTui: <const Scales extends BreakpointScales>(scales: Parameters<typeof createBreakpointDefinition<Scales>>[0]) => {
|
|
16
16
|
ResponsiveTUI: (props: ParentProps) => any;
|
|
17
|
-
|
|
17
|
+
useBreakpoint: () => ResponsiveBreakpointAccessor<Scales>;
|
|
18
18
|
};
|
package/dist/solid/index.js
CHANGED
|
@@ -82,7 +82,7 @@ var isThreshold = (value) => typeof value === "number" && Number.isFinite(value)
|
|
|
82
82
|
class ResponsiveTuiProviderError extends Error {
|
|
83
83
|
_tag = "ResponsiveTuiProviderError";
|
|
84
84
|
constructor() {
|
|
85
|
-
super("
|
|
85
|
+
super("useBreakpoint must be used within a ResponsiveTUI");
|
|
86
86
|
this.name = this._tag;
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -100,14 +100,14 @@ var createResponsiveTui = (scales) => {
|
|
|
100
100
|
value: breakpoint
|
|
101
101
|
});
|
|
102
102
|
};
|
|
103
|
-
const
|
|
103
|
+
const useBreakpoint = () => {
|
|
104
104
|
const breakpoint = useContext(ResponsiveTuiContext);
|
|
105
105
|
if (!breakpoint) {
|
|
106
106
|
throw new ResponsiveTuiProviderError;
|
|
107
107
|
}
|
|
108
108
|
return breakpoint;
|
|
109
109
|
};
|
|
110
|
-
return { ResponsiveTUI,
|
|
110
|
+
return { ResponsiveTUI, useBreakpoint };
|
|
111
111
|
};
|
|
112
112
|
export {
|
|
113
113
|
ResponsiveTuiConfigurationError,
|