@uxf/core-react 11.60.1 → 11.67.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
CHANGED
|
@@ -1,11 +1,50 @@
|
|
|
1
1
|
# UXF Core-React
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Components
|
|
4
|
+
---
|
|
4
5
|
|
|
6
|
+
### Hide
|
|
7
|
+
|
|
8
|
+
Conditionally hide some jsx content.
|
|
5
9
|
```tsx
|
|
6
|
-
|
|
10
|
+
const { Hide } from "@uxf/core-react/components/hide";
|
|
7
11
|
|
|
8
|
-
<
|
|
12
|
+
<Hide when={SOME_CONDITION}>
|
|
13
|
+
...some content
|
|
14
|
+
</Hide>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Show
|
|
18
|
+
|
|
19
|
+
Conditionally show some jsx content.
|
|
20
|
+
```tsx
|
|
21
|
+
const { Show } from "@uxf/core-react/components/show";
|
|
22
|
+
|
|
23
|
+
<Show when={SOME_CONDITION}>
|
|
24
|
+
...some content
|
|
25
|
+
</Show>
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### ViewportHeightPolyfill
|
|
29
|
+
|
|
30
|
+
Polyfill for custom css variable `--viewport-height` to mimic functionality of browser's [dynamic viewport height](https://web.dev/blog/viewport-units).
|
|
31
|
+
|
|
32
|
+
Add component to react app root (eg. `_app.tsx`).
|
|
33
|
+
```tsx
|
|
34
|
+
const { ViewportHeightPolyfill } from "@uxf/core-react/components/viewport-height-polyfill";
|
|
35
|
+
|
|
36
|
+
<ViewportHeightPolyfill />
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Add css variable declaration with fallback to app global styles (eg. `base.css`) if already not there.
|
|
40
|
+
```css
|
|
41
|
+
:root {
|
|
42
|
+
--viewport-height: 100vh;
|
|
43
|
+
|
|
44
|
+
@supports (height: 100dvh) {
|
|
45
|
+
--viewport-height: 100dvh;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
9
48
|
```
|
|
10
49
|
|
|
11
50
|
## Hooks
|
|
@@ -338,3 +377,20 @@ import { useDebounce } from "@uxf/core-react/hooks/use-debounce";
|
|
|
338
377
|
|
|
339
378
|
const debouncedValue = useDebounce<string>("some value", 300);
|
|
340
379
|
```
|
|
380
|
+
|
|
381
|
+
## String helpers
|
|
382
|
+
|
|
383
|
+
```tsx
|
|
384
|
+
import { nl2br } from "@uxf/core-react/string/nl2br";
|
|
385
|
+
|
|
386
|
+
<div>{nl2br("Hello\nWorld")}</div>
|
|
387
|
+
```
|
|
388
|
+
---
|
|
389
|
+
### useMediaQuery
|
|
390
|
+
Returns if the media query is matched.
|
|
391
|
+
```tsx
|
|
392
|
+
import { useMediaQuery } from "@uxf/core-react/hooks/use-media-query";
|
|
393
|
+
import { twScreens } from "@generated/tw-tokens/tw-screens";
|
|
394
|
+
|
|
395
|
+
const isDesktop = useMediaQuery(`(min-width: ${twScreens.sm})`);
|
|
396
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.ViewportHeightPolyfill = ViewportHeightPolyfill;
|
|
28
|
+
const use_is_mounted_1 = require("@uxf/core-react/hooks/use-is-mounted");
|
|
29
|
+
const use_on_mount_1 = require("@uxf/core-react/hooks/use-on-mount");
|
|
30
|
+
const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
|
|
31
|
+
const with_unit_1 = require("@uxf/styles/units/with-unit");
|
|
32
|
+
const react_1 = __importStar(require("react"));
|
|
33
|
+
function ViewportHeightPolyfill() {
|
|
34
|
+
const isMounted = (0, use_is_mounted_1.useIsMounted)();
|
|
35
|
+
const [viewportHeight, setViewportHeight] = (0, react_1.useState)();
|
|
36
|
+
(0, use_on_mount_1.useOnMount)(() => {
|
|
37
|
+
if (!CSS.supports("height: 100dvh")) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const updateViewportHeight = () => setViewportHeight(window.innerHeight);
|
|
41
|
+
updateViewportHeight();
|
|
42
|
+
window.addEventListener("resize", updateViewportHeight);
|
|
43
|
+
return () => window.removeEventListener("resize", updateViewportHeight);
|
|
44
|
+
});
|
|
45
|
+
if (isMounted && (0, is_not_nil_1.isNotNil)(viewportHeight)) {
|
|
46
|
+
return react_1.default.createElement("style", null, `:root { --viewport-height: ${(0, with_unit_1.withUnit)(viewportHeight, "px")}; }`);
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useMediaQuery(mediaQueryString: string): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.useMediaQuery = useMediaQuery;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
function useMediaQuery(mediaQueryString) {
|
|
7
|
+
const [isMatched, setIsMatched] = (0, react_1.useState)(false);
|
|
8
|
+
(0, react_1.useEffect)(() => {
|
|
9
|
+
const observer = new ResizeObserver(() => {
|
|
10
|
+
setIsMatched(window.matchMedia(mediaQueryString).matches);
|
|
11
|
+
});
|
|
12
|
+
observer.observe(document.body);
|
|
13
|
+
return () => {
|
|
14
|
+
observer.unobserve(document.body);
|
|
15
|
+
};
|
|
16
|
+
}, [mediaQueryString]);
|
|
17
|
+
return isMatched;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uxf/core-react",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.67.0",
|
|
4
4
|
"description": "UXF Core",
|
|
5
5
|
"author": "UX Fans s.r.o",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@uxf/core": "11.
|
|
15
|
+
"@uxf/core": "11.67.0"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
18
|
"react": ">=18.2.0"
|