@versini/ui-responsive-text 1.0.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/LICENSE +21 -0
- package/README.md +115 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +66 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Arno Versini
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# @versini/ui-responsive-text
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@versini/ui-responsive-text)
|
|
4
|
+
>)
|
|
5
|
+
|
|
6
|
+
> A semantic and accessible React responsive text component built with TypeScript and TailwindCSS.
|
|
7
|
+
|
|
8
|
+
The ResponsiveText component displays different text content based on screen or container size, allowing for flexible and adaptive UI text. It supports both viewport-based and container-query-based breakpoints.
|
|
9
|
+
|
|
10
|
+
## Table of Contents
|
|
11
|
+
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [API](#api)
|
|
16
|
+
|
|
17
|
+
## Features
|
|
18
|
+
|
|
19
|
+
- **🎯 Adaptive Text**: Show different content at different breakpoints
|
|
20
|
+
- **📦 Container Queries**: Supports both viewport and container-query modes
|
|
21
|
+
- **♿ Accessible**: Renders semantic inline spans
|
|
22
|
+
- **🌲 Tree-shakeable**: Lightweight and optimized for bundle size
|
|
23
|
+
- **🔧 TypeScript**: Fully typed with comprehensive prop definitions
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install @versini/ui-responsive-text
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
> **Note**: This component requires TailwindCSS and the `@versini/ui-styles` plugin for proper styling. See the [installation documentation](https://versini-org.github.io/ui-components/?path=/docs/getting-started-installation--docs) for complete setup instructions.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Basic Example
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
import { ResponsiveText } from "@versini/ui-responsive-text";
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
return (
|
|
42
|
+
<ResponsiveText
|
|
43
|
+
short="Hi"
|
|
44
|
+
long="Hello, World!"
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
On small screens, "Hi" is displayed. Above the `sm` breakpoint, "Hello, World!" is shown instead.
|
|
51
|
+
|
|
52
|
+
### Custom Breakpoint
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
import { ResponsiveText } from "@versini/ui-responsive-text";
|
|
56
|
+
|
|
57
|
+
function App() {
|
|
58
|
+
return (
|
|
59
|
+
<ResponsiveText
|
|
60
|
+
short="Menu"
|
|
61
|
+
long="Navigation Menu"
|
|
62
|
+
breakpoint="md"
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Container Query Mode
|
|
69
|
+
|
|
70
|
+
When your layout depends on a container's width rather than the viewport, use `mode="container"`. The parent element must have the `@container` class (from `@tailwindcss/container-queries`).
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { ResponsiveText } from "@versini/ui-responsive-text";
|
|
74
|
+
|
|
75
|
+
function App() {
|
|
76
|
+
return (
|
|
77
|
+
<div className="@container">
|
|
78
|
+
<ResponsiveText
|
|
79
|
+
short="$99"
|
|
80
|
+
long="$99.00 per month"
|
|
81
|
+
mode="container"
|
|
82
|
+
breakpoint="sm"
|
|
83
|
+
/>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### With JSX Content
|
|
90
|
+
|
|
91
|
+
Both `short` and `long` accept `React.ReactNode`, so you can pass rich content:
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { ResponsiveText } from "@versini/ui-responsive-text";
|
|
95
|
+
|
|
96
|
+
function App() {
|
|
97
|
+
return (
|
|
98
|
+
<ResponsiveText
|
|
99
|
+
short={<strong>Save</strong>}
|
|
100
|
+
long={<span><strong>Save</strong> to favorites</span>}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## API
|
|
107
|
+
|
|
108
|
+
### ResponsiveText Props
|
|
109
|
+
|
|
110
|
+
| Prop | Type | Default | Description |
|
|
111
|
+
| ---------- | ---------------------------- | ------------ | ------------------------------------------------------- |
|
|
112
|
+
| short | `React.ReactNode` | **required** | Content displayed below the breakpoint |
|
|
113
|
+
| long | `React.ReactNode` | **required** | Content displayed at or above the breakpoint |
|
|
114
|
+
| breakpoint | `"sm" \| "md" \| "lg" \| "xl"` | `"sm"` | The TailwindCSS breakpoint at which to switch content |
|
|
115
|
+
| mode | `"viewport" \| "container"` | `"viewport"` | Whether to use viewport media queries or container queries |
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
|
|
3
|
+
declare type Breakpoint = "sm" | "md" | "lg" | "xl";
|
|
4
|
+
|
|
5
|
+
declare type QueryMode = "viewport" | "container";
|
|
6
|
+
|
|
7
|
+
export declare const ResponsiveText: ({ short, long, breakpoint, mode, }: ResponsiveTextProps) => JSX.Element;
|
|
8
|
+
|
|
9
|
+
declare type ResponsiveTextProps = {
|
|
10
|
+
short: React.ReactNode;
|
|
11
|
+
long: React.ReactNode;
|
|
12
|
+
breakpoint?: Breakpoint;
|
|
13
|
+
mode?: QueryMode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
@versini/ui-responsive-text v1.0.0
|
|
3
|
+
© 2026 gizmette.com
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
// Static class maps to keep Tailwind's JIT scanner happy
|
|
11
|
+
const viewportClasses = {
|
|
12
|
+
sm: {
|
|
13
|
+
long: "hidden sm:inline",
|
|
14
|
+
short: "inline sm:hidden"
|
|
15
|
+
},
|
|
16
|
+
md: {
|
|
17
|
+
long: "hidden md:inline",
|
|
18
|
+
short: "inline md:hidden"
|
|
19
|
+
},
|
|
20
|
+
lg: {
|
|
21
|
+
long: "hidden lg:inline",
|
|
22
|
+
short: "inline lg:hidden"
|
|
23
|
+
},
|
|
24
|
+
xl: {
|
|
25
|
+
long: "hidden xl:inline",
|
|
26
|
+
short: "inline xl:hidden"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
// Uses @tailwindcss/container-queries prefix "@"
|
|
30
|
+
const containerClasses = {
|
|
31
|
+
sm: {
|
|
32
|
+
long: "hidden @sm:inline",
|
|
33
|
+
short: "inline @sm:hidden"
|
|
34
|
+
},
|
|
35
|
+
md: {
|
|
36
|
+
long: "hidden @md:inline",
|
|
37
|
+
short: "inline @md:hidden"
|
|
38
|
+
},
|
|
39
|
+
lg: {
|
|
40
|
+
long: "hidden @lg:inline",
|
|
41
|
+
short: "inline @lg:hidden"
|
|
42
|
+
},
|
|
43
|
+
xl: {
|
|
44
|
+
long: "hidden @xl:inline",
|
|
45
|
+
short: "inline @xl:hidden"
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const ResponsiveText = ({ short, long, breakpoint = "sm", mode = "viewport" })=>{
|
|
49
|
+
const classes = mode === "container" ? containerClasses[breakpoint] : viewportClasses[breakpoint];
|
|
50
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ jsx("span", {
|
|
53
|
+
className: classes.long,
|
|
54
|
+
children: long
|
|
55
|
+
}),
|
|
56
|
+
/*#__PURE__*/ jsx("span", {
|
|
57
|
+
className: classes.short,
|
|
58
|
+
children: short
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export { ResponsiveText };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@versini/ui-responsive-text",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Arno Versini",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://www.npmjs.com/package/@versini/ui-responsive-text",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git@github.com:aversini/ui-components.git"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build:check": "tsc",
|
|
23
|
+
"build:js": "rslib build",
|
|
24
|
+
"build:types": "echo 'Types now built with rslib'",
|
|
25
|
+
"build": "npm-run-all --serial clean build:check build:js",
|
|
26
|
+
"clean": "rimraf dist tmp coverage",
|
|
27
|
+
"dev:js": "rslib build --watch",
|
|
28
|
+
"dev:types": "echo 'Types now watched with rslib'",
|
|
29
|
+
"dev": "rslib build --watch",
|
|
30
|
+
"lint": "biome lint src",
|
|
31
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
32
|
+
"prettier": "biome check --write --no-errors-on-unmatched",
|
|
33
|
+
"start": "static-server dist --port 5173",
|
|
34
|
+
"test:coverage:ui": "vitest --coverage --ui",
|
|
35
|
+
"test:coverage": "vitest run --coverage",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test": "vitest run"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@versini/ui-types": "8.3.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"tailwindcss": "4.2.1"
|
|
44
|
+
},
|
|
45
|
+
"sideEffects": [
|
|
46
|
+
"**/*.css"
|
|
47
|
+
],
|
|
48
|
+
"gitHead": "51ad61b8366b0220e699ccde69f2235ab1d1c54a"
|
|
49
|
+
}
|