@customviews-js/customviews 1.1.4 → 1.1.6
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 +362 -362
- package/dist/custom-views.core.cjs.js +1576 -992
- package/dist/custom-views.core.cjs.js.map +1 -1
- package/dist/custom-views.core.esm.js +1576 -992
- package/dist/custom-views.core.esm.js.map +1 -1
- package/dist/custom-views.esm.js +1576 -992
- package/dist/custom-views.esm.js.map +1 -1
- package/dist/custom-views.js +1576 -992
- package/dist/custom-views.js.map +1 -1
- package/dist/custom-views.min.js +2 -2
- package/dist/custom-views.min.js.map +1 -1
- package/dist/types/core/core.d.ts +1 -1
- package/dist/types/core/core.d.ts.map +1 -1
- package/dist/types/core/tab-manager.d.ts +32 -7
- package/dist/types/core/tab-manager.d.ts.map +1 -1
- package/dist/types/core/widget.d.ts.map +1 -1
- package/dist/types/styles/tab-styles.d.ts +1 -1
- package/dist/types/styles/tab-styles.d.ts.map +1 -1
- package/dist/types/styles/widget-styles.d.ts +1 -1
- package/dist/types/styles/widget-styles.d.ts.map +1 -1
- package/dist/types/utils/icons.d.ts +21 -0
- package/dist/types/utils/icons.d.ts.map +1 -0
- package/package.json +61 -61
package/README.md
CHANGED
|
@@ -1,363 +1,363 @@
|
|
|
1
|
-
## Custom Views
|
|
2
|
-
|
|
3
|
-
[npm package link](https://www.npmjs.com/package/@customviews-js/customviews)
|
|
4
|
-
|
|
5
|
-
_Custom Views_ allows developers and designers to define reusable content views that can be toggled, personalized, or adapted dynamically for different users and contexts. It is framework-agnostic, meaning it works with plain HTML, JavaScript, or alongside modern frameworks without imposing additional dependencies.
|
|
6
|
-
|
|
7
|
-
With Custom Views, you can:
|
|
8
|
-
|
|
9
|
-
- Show or hide sections of a page based on user preferences.
|
|
10
|
-
- Persist user-selected content variants (e.g., "CLI view" vs "GUI view").
|
|
11
|
-
- Enhance accessibility and provide tailored experiences without bloating your site.
|
|
12
|
-
|
|
13
|
-
Whether you are building a static site, a dashboard, or a documentation portal, Custom Views gives you the tools to make your content interactive and adaptable while keeping things lightweight and simple.
|
|
14
|
-
|
|
15
|
-
[Documentation and User Guide](https://customviews-js.github.io/customviews)
|
|
16
|
-
|
|
17
|
-
## Components
|
|
18
|
-
|
|
19
|
-
Custom Views provides two main components:
|
|
20
|
-
|
|
21
|
-
- **Toggles**: Show or hide sections of a page based on categories (e.g., platform-specific content).
|
|
22
|
-
- **Tabs**: Create mutually exclusive, synchronized content sections for different views.
|
|
23
|
-
|
|
24
|
-
Both components work out of the box without configuration, but can be enhanced with the widget and config file for better user experience.
|
|
25
|
-
|
|
26
|
-
## Quick Start
|
|
27
|
-
|
|
28
|
-
### Mark content with toggles
|
|
29
|
-
|
|
30
|
-
Use the `data-cv-toggle` attribute or `<cv-toggle>` element to mark content that should be shown only for specific categories (for example `mac`, `linux`, `windows`).
|
|
31
|
-
|
|
32
|
-
```html
|
|
33
|
-
<!-- Mark content with data-cv-toggle attribute -->
|
|
34
|
-
<div data-cv-toggle="mac">
|
|
35
|
-
<p>Mac content here</p>
|
|
36
|
-
</div>
|
|
37
|
-
|
|
38
|
-
<div data-cv-toggle="linux">
|
|
39
|
-
<p>Linux content here</p>
|
|
40
|
-
</div>
|
|
41
|
-
|
|
42
|
-
<div data-cv-toggle="windows">
|
|
43
|
-
<p>Windows content here</p>
|
|
44
|
-
</div>
|
|
45
|
-
|
|
46
|
-
<!-- Or use the cv-toggle element -->
|
|
47
|
-
<cv-toggle category="mac">
|
|
48
|
-
<p>Mac content here</p>
|
|
49
|
-
</cv-toggle>
|
|
50
|
-
|
|
51
|
-
<!-- Dynamic content with ID -->
|
|
52
|
-
<div data-cv-toggle="mac" data-cv-id="mac-picture"></div>
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
You can apply multiple toggles to a single element by separating categories with spaces. This allows content to appear as long as one toggle category is active.
|
|
56
|
-
|
|
57
|
-
```html
|
|
58
|
-
<div data-cv-toggle="mac linux">
|
|
59
|
-
This section appears for both macOS and Linux users.
|
|
60
|
-
</div>
|
|
61
|
-
|
|
62
|
-
<cv-toggle category="mac linux">
|
|
63
|
-
This section appears for both macOS and Linux users.
|
|
64
|
-
</cv-toggle>
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Attributes & Options
|
|
68
|
-
|
|
69
|
-
| Name | Type | Default | Description |
|
|
70
|
-
|------|------|----------|-------------|
|
|
71
|
-
| `data-cv-toggle` | string | **required** for data attribute usage | Defines the category for the element. Example: `data-cv-toggle="mac"`. |
|
|
72
|
-
| `category` | string | **required** for `<cv-toggle>` | Defines the category for the cv-toggle element. Example: `category="mac"`. |
|
|
73
|
-
| `data-cv-id` / `data-customviews-id` | string | - | Marks the element as an asset render target. When visible, matching assets from `assets.json` will be dynamically inserted. |
|
|
74
|
-
|
|
75
|
-
**Configuration Integration**
|
|
76
|
-
To expose toggles in the widget and provide defaults, list them in your config file under `config.allToggles` and set `config.defaultState.toggles`:
|
|
77
|
-
|
|
78
|
-
```json
|
|
79
|
-
{
|
|
80
|
-
"config": {
|
|
81
|
-
"allToggles": ["mac", "linux", "windows"],
|
|
82
|
-
"defaultState": { "toggles": ["mac"] }
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
## Tabs
|
|
89
|
-
|
|
90
|
-
Tabs let you create mutually exclusive, synchronized content sections using the custom elements `<cv-tabgroup>` and `<cv-tab>`. All tab groups on the page that share the same `id` stay in sync — changing a tab in one group updates the others automatically.
|
|
91
|
-
|
|
92
|
-
Basic example with synchronized groups:
|
|
93
|
-
|
|
94
|
-
```html
|
|
95
|
-
<cv-tabgroup id="fruit">
|
|
96
|
-
<cv-tab id="apple" header="Apple">
|
|
97
|
-
|
|
98
|
-
**Apple Information**
|
|
99
|
-
|
|
100
|
-
Apples are crisp, sweet fruits that come in many varieties. They are rich in fiber and vitamin C.
|
|
101
|
-
|
|
102
|
-
</cv-tab>
|
|
103
|
-
<cv-tab id="orange" header="Orange">
|
|
104
|
-
|
|
105
|
-
**Orange Information**
|
|
106
|
-
|
|
107
|
-
Oranges are citrus fruits known for their high vitamin C content and refreshing juice.
|
|
108
|
-
|
|
109
|
-
</cv-tab>
|
|
110
|
-
<cv-tab id="pear" header="Pear">
|
|
111
|
-
|
|
112
|
-
**Pear Information**
|
|
113
|
-
|
|
114
|
-
Pears are sweet, bell-shaped fruits with a soft texture when ripe. They're high in fiber and antioxidants.
|
|
115
|
-
|
|
116
|
-
</cv-tab>
|
|
117
|
-
</cv-tabgroup>
|
|
118
|
-
|
|
119
|
-
<cv-tabgroup id="fruit" nav="auto">
|
|
120
|
-
<cv-tab id="apple" header="Apple Types">
|
|
121
|
-
|
|
122
|
-
Apple types include **Granny Smith** and the **Cosmic Crisp**.
|
|
123
|
-
|
|
124
|
-
</cv-tab>
|
|
125
|
-
<cv-tab id="orange" header="Orange Types">
|
|
126
|
-
|
|
127
|
-
Orange types include the **Blood orange** and **Valencia orange**.
|
|
128
|
-
</cv-tab>
|
|
129
|
-
<cv-tab id="pear" header="Pear">
|
|
130
|
-
|
|
131
|
-
Pear types include the **Asian pear** and the **European pear**
|
|
132
|
-
</cv-tab>
|
|
133
|
-
</cv-tabgroup>
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
* **Synchronized Tab Groups** Multiple tab groups with the same `id` will automatically synchronize. When you switch tabs in one group, all other groups with the same ID will update simultaneously.
|
|
137
|
-
|
|
138
|
-
### Attributes & Options
|
|
139
|
-
|
|
140
|
-
#### `<cv-tabgroup>` Attributes
|
|
141
|
-
|
|
142
|
-
| Name | Type | Default | Description |
|
|
143
|
-
|------|------|---------|-------------|
|
|
144
|
-
| `id` | string | **(required)** | Unique identifier for the tab group. Tab groups with the same ID will synchronize. |
|
|
145
|
-
| `nav` | string | `"auto"` | Navigation display mode. Use `"auto"` to automatically generate navigation, or `"none"` to hide navigation. |
|
|
146
|
-
|
|
147
|
-
#### `<cv-tab>` Attributes
|
|
148
|
-
|
|
149
|
-
| Name | Type | Default | Description |
|
|
150
|
-
|------|------|---------|-------------|
|
|
151
|
-
| `id` | string | **(required)** | Unique identifier for the tab within its group. |
|
|
152
|
-
| `header` | string | Tab ID | Display label for the tab in the navigation bar. Supports text and font-awesome emojis. |
|
|
153
|
-
|
|
154
|
-
**Config integration**:
|
|
155
|
-
If you declare tab groups in `customviews.config.json` under `config.tabGroups`, they will appear in the widget with friendly labels and default selections. Example:
|
|
156
|
-
|
|
157
|
-
```json
|
|
158
|
-
{
|
|
159
|
-
"config": {
|
|
160
|
-
"tabGroups": [
|
|
161
|
-
{
|
|
162
|
-
"id": "fruit",
|
|
163
|
-
"label": "Fruit Selection",
|
|
164
|
-
"default": "apple",
|
|
165
|
-
"tabs": [
|
|
166
|
-
{ "id": "apple", "label": "Apple" },
|
|
167
|
-
{ "id": "orange", "label": "Orange" },
|
|
168
|
-
{ "id": "pear", "label": "Pear" }
|
|
169
|
-
]
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
Resolution order of tabs and toggles is as follows:
|
|
177
|
-
* URL state (if present) → persisted localStorage state → `config.defaultState`.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
### Simple Setup (auto-init)
|
|
181
|
-
|
|
182
|
-
To get started quickly, add the following snippet to your site's `<head>` or right before `</body>`:
|
|
183
|
-
|
|
184
|
-
```html
|
|
185
|
-
<!-- Load from CDN or your hosted bundle -->
|
|
186
|
-
<script src="https://unpkg.com/@customviews-js/customviews/dist/custom-views.min.js"
|
|
187
|
-
data-base-url="/customviews"
|
|
188
|
-
></script>
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
This snippet loads:
|
|
192
|
-
* The CustomViews runtime, a lightweight JavaScript that auto-initializes on page load.
|
|
193
|
-
* The base URL and config path, which tell the runtime where to find your assets and configuration.
|
|
194
|
-
|
|
195
|
-
By default the auto-init script will:
|
|
196
|
-
1. Load configuration (default path `/customviews.config.json`)
|
|
197
|
-
2. Initialize the core library
|
|
198
|
-
3. Create and render the widget if enabled
|
|
199
|
-
|
|
200
|
-
## Configuration
|
|
201
|
-
|
|
202
|
-
The config file uses a flat top-level structure. Key fields:
|
|
203
|
-
|
|
204
|
-
Example `customviews.config.json`:
|
|
205
|
-
|
|
206
|
-
```json
|
|
207
|
-
{
|
|
208
|
-
"config": {
|
|
209
|
-
"allToggles": ["mac", "linux", "windows"],
|
|
210
|
-
"defaultState": {
|
|
211
|
-
"toggles": ["mac", "linux", "windows"],
|
|
212
|
-
"tabs": { "fruit": "apple" }
|
|
213
|
-
},
|
|
214
|
-
"tabGroups": [
|
|
215
|
-
{
|
|
216
|
-
"id": "fruit",
|
|
217
|
-
"label": "Fruit Selection",
|
|
218
|
-
"default": "apple",
|
|
219
|
-
"tabs": [
|
|
220
|
-
{ "id": "apple", "label": "Apple" },
|
|
221
|
-
{ "id": "orange", "label": "Orange" },
|
|
222
|
-
{ "id": "pear", "label": "Pear" }
|
|
223
|
-
]
|
|
224
|
-
}
|
|
225
|
-
]
|
|
226
|
-
},
|
|
227
|
-
"assetsJsonPath": "/assets/assets.json",
|
|
228
|
-
"baseUrl": "/customviews",
|
|
229
|
-
"showUrl": false,
|
|
230
|
-
"widget": {
|
|
231
|
-
"enabled": true,
|
|
232
|
-
"position": "middle-left",
|
|
233
|
-
"showReset": true,
|
|
234
|
-
"title": "Customize your view here",
|
|
235
|
-
"description": "Toggle content sections and switch between different tab views.",
|
|
236
|
-
"showWelcome": true
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
#### Key Fields
|
|
242
|
-
|
|
243
|
-
| Field | Description |
|
|
244
|
-
| ------ | ------------ |
|
|
245
|
-
| `config.allToggles` | List of toggle IDs recognized by CustomViews. |
|
|
246
|
-
| `config.defaultState` | Toggles and tabs per tab group enabled by default on first load. |
|
|
247
|
-
| `assetsJsonPath` | Path to your compiled assets manifest (resolved relative to `baseURL`). |
|
|
248
|
-
| `widget` | Floating widget settings — control position, visibility, and welcome prompt. |
|
|
249
|
-
| `showUrl` | When true, CustomViews encodes the active state into the browser URL for shareable links. |
|
|
250
|
-
|
|
251
|
-
#### Script Attributes
|
|
252
|
-
|
|
253
|
-
The auto-init script supports these data attributes:
|
|
254
|
-
- `data-base-url`: Base URL for all paths (e.g., `/customviews`)
|
|
255
|
-
- `data-config-path`: Custom path to config file (default: `/customviews.config.json`)
|
|
256
|
-
|
|
257
|
-
```html
|
|
258
|
-
<script
|
|
259
|
-
src="https://unpkg.com/@customviews-js/customviews"
|
|
260
|
-
data-base-url="/my-site"
|
|
261
|
-
data-config-path="/configs/customviews.config.json">
|
|
262
|
-
</script>
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
## Widget Features
|
|
267
|
-
|
|
268
|
-
- Floating widget with optional welcome modal and reset
|
|
269
|
-
- Config-driven (enable/disable, position, theme, labels)
|
|
270
|
-
- Shows toggles and tab groups declared in `config` for quick switching
|
|
271
|
-
- Can persist state to URL for sharing
|
|
272
|
-
|
|
273
|
-
Widget configuration options:
|
|
274
|
-
|
|
275
|
-
| Name | Type | Default | Description |
|
|
276
|
-
|------|------|---------|-------------|
|
|
277
|
-
| `enabled` | boolean | true | Whether to show the widget. |
|
|
278
|
-
| `position` | string | 'middle-left' | Position of the widget (e.g., 'middle-left', 'bottom-right'). |
|
|
279
|
-
| `showReset` | boolean | true | Whether to show the reset button. |
|
|
280
|
-
| `showWelcome` | boolean | false | Whether to show a welcome modal on first visit. |
|
|
281
|
-
|
|
282
|
-
```typescript
|
|
283
|
-
{
|
|
284
|
-
core: CustomViewsCore; // Required: core instance
|
|
285
|
-
position?: string; // Default: 'middle-left'
|
|
286
|
-
theme?: 'light' | 'dark'; // Default: 'light'
|
|
287
|
-
showReset?: boolean; // Default: true
|
|
288
|
-
showWelcome?: boolean; // Default: false
|
|
289
|
-
welcomeTitle?: string; // Custom welcome title
|
|
290
|
-
welcomeMessage?: string; // Custom welcome message
|
|
291
|
-
title?: string; // Widget tooltip
|
|
292
|
-
description?: string; // Widget modal description
|
|
293
|
-
}
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
## Assets JSON
|
|
297
|
-
|
|
298
|
-
Assets are still defined in a JSON file referenced by `assetsJsonPath`. Example snippets are unchanged — asset keys map to HTML, text, or images and are rendered into elements that have `data-cv-id` (or legacy `data-customviews-id`).
|
|
299
|
-
|
|
300
|
-
The `assets.json` file defines reusable content that can be dynamically injected into your pages. Each asset is referenced by a unique key and can contain images, HTML, or text.
|
|
301
|
-
* Note that `baseURL` defined during initialization is automatically prepended to all asset `src` paths.
|
|
302
|
-
|
|
303
|
-
### Structure
|
|
304
|
-
|
|
305
|
-
```json
|
|
306
|
-
{
|
|
307
|
-
"htmlContent": {
|
|
308
|
-
"content": "<h2>Dynamic HTML</h2><p>This content is injected dynamically.</p>"
|
|
309
|
-
},
|
|
310
|
-
"textContent": {
|
|
311
|
-
"content": "Plain text content"
|
|
312
|
-
},
|
|
313
|
-
"imageContent": {
|
|
314
|
-
"src": "/assets/mac.png"
|
|
315
|
-
},
|
|
316
|
-
"assetKey": {
|
|
317
|
-
"src": "/path/to/image.png",
|
|
318
|
-
"alt": "Description",
|
|
319
|
-
"className": "custom-class",
|
|
320
|
-
"style": "border-radius: 8px;"
|
|
321
|
-
},
|
|
322
|
-
}
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
### Usage in HTML
|
|
326
|
-
|
|
327
|
-
```html
|
|
328
|
-
<!-- Reference asset by key using data-cv-id (or data-customviews-id for backward compatibility) -->
|
|
329
|
-
<div data-cv-toggle="beginner" data-cv-id="assetKey"></div>
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
When the toggle is active, the asset will be automatically rendered into the element.
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
## Troubleshooting
|
|
336
|
-
|
|
337
|
-
* Toggles not appearing in widget?
|
|
338
|
-
* Check `config.allToggles` includes your toggle IDs.
|
|
339
|
-
|
|
340
|
-
* No effect when toggling?
|
|
341
|
-
* Ensure the element uses `data-cv-toggle` or `<cv-toggle>` with `category`, and matches an active toggle ID.
|
|
342
|
-
|
|
343
|
-
* URL state not persisting in URL bar?
|
|
344
|
-
* Enable `showUrl` in the configuration.
|
|
345
|
-
|
|
346
|
-
* Widget not loading?
|
|
347
|
-
* Verify the script is included and `customviews.config.json` is accessible.
|
|
348
|
-
|
|
349
|
-
* Tab groups not synchronizing?
|
|
350
|
-
* Ensure they share the same `id` attribute.
|
|
351
|
-
|
|
352
|
-
* Assets not rendering?
|
|
353
|
-
* Check `data-cv-id` matches a key in `assets.json`, and the toggle is active.
|
|
354
|
-
|
|
355
|
-
## API & Integration Notes
|
|
356
|
-
|
|
357
|
-
- Public globals: `window.CustomViews`, `window.CustomViewsWidget`, and `window.customViewsInstance` (contains `{ core, widget? }`) when auto-initialized.
|
|
358
|
-
- Important events: `customviews:ready` (auto-init done) and `customviews:tab-change` (dispatched when a tab group selection changes).
|
|
359
|
-
- URL state helpers: `URLStateManager.generateShareableURL` and `URLStateManager.parseURL` (used internally by the widget).
|
|
360
|
-
|
|
361
|
-
## License
|
|
362
|
-
|
|
1
|
+
## Custom Views
|
|
2
|
+
|
|
3
|
+
[npm package link](https://www.npmjs.com/package/@customviews-js/customviews)
|
|
4
|
+
|
|
5
|
+
_Custom Views_ allows developers and designers to define reusable content views that can be toggled, personalized, or adapted dynamically for different users and contexts. It is framework-agnostic, meaning it works with plain HTML, JavaScript, or alongside modern frameworks without imposing additional dependencies.
|
|
6
|
+
|
|
7
|
+
With Custom Views, you can:
|
|
8
|
+
|
|
9
|
+
- Show or hide sections of a page based on user preferences.
|
|
10
|
+
- Persist user-selected content variants (e.g., "CLI view" vs "GUI view").
|
|
11
|
+
- Enhance accessibility and provide tailored experiences without bloating your site.
|
|
12
|
+
|
|
13
|
+
Whether you are building a static site, a dashboard, or a documentation portal, Custom Views gives you the tools to make your content interactive and adaptable while keeping things lightweight and simple.
|
|
14
|
+
|
|
15
|
+
[Documentation and User Guide](https://customviews-js.github.io/customviews)
|
|
16
|
+
|
|
17
|
+
## Components
|
|
18
|
+
|
|
19
|
+
Custom Views provides two main components:
|
|
20
|
+
|
|
21
|
+
- **Toggles**: Show or hide sections of a page based on categories (e.g., platform-specific content).
|
|
22
|
+
- **Tabs**: Create mutually exclusive, synchronized content sections for different views.
|
|
23
|
+
|
|
24
|
+
Both components work out of the box without configuration, but can be enhanced with the widget and config file for better user experience.
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### Mark content with toggles
|
|
29
|
+
|
|
30
|
+
Use the `data-cv-toggle` attribute or `<cv-toggle>` element to mark content that should be shown only for specific categories (for example `mac`, `linux`, `windows`).
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<!-- Mark content with data-cv-toggle attribute -->
|
|
34
|
+
<div data-cv-toggle="mac">
|
|
35
|
+
<p>Mac content here</p>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div data-cv-toggle="linux">
|
|
39
|
+
<p>Linux content here</p>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div data-cv-toggle="windows">
|
|
43
|
+
<p>Windows content here</p>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<!-- Or use the cv-toggle element -->
|
|
47
|
+
<cv-toggle category="mac">
|
|
48
|
+
<p>Mac content here</p>
|
|
49
|
+
</cv-toggle>
|
|
50
|
+
|
|
51
|
+
<!-- Dynamic content with ID -->
|
|
52
|
+
<div data-cv-toggle="mac" data-cv-id="mac-picture"></div>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
You can apply multiple toggles to a single element by separating categories with spaces. This allows content to appear as long as one toggle category is active.
|
|
56
|
+
|
|
57
|
+
```html
|
|
58
|
+
<div data-cv-toggle="mac linux">
|
|
59
|
+
This section appears for both macOS and Linux users.
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
<cv-toggle category="mac linux">
|
|
63
|
+
This section appears for both macOS and Linux users.
|
|
64
|
+
</cv-toggle>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Attributes & Options
|
|
68
|
+
|
|
69
|
+
| Name | Type | Default | Description |
|
|
70
|
+
|------|------|----------|-------------|
|
|
71
|
+
| `data-cv-toggle` | string | **required** for data attribute usage | Defines the category for the element. Example: `data-cv-toggle="mac"`. |
|
|
72
|
+
| `category` | string | **required** for `<cv-toggle>` | Defines the category for the cv-toggle element. Example: `category="mac"`. |
|
|
73
|
+
| `data-cv-id` / `data-customviews-id` | string | - | Marks the element as an asset render target. When visible, matching assets from `assets.json` will be dynamically inserted. |
|
|
74
|
+
|
|
75
|
+
**Configuration Integration**
|
|
76
|
+
To expose toggles in the widget and provide defaults, list them in your config file under `config.allToggles` and set `config.defaultState.toggles`:
|
|
77
|
+
|
|
78
|
+
```json
|
|
79
|
+
{
|
|
80
|
+
"config": {
|
|
81
|
+
"allToggles": ["mac", "linux", "windows"],
|
|
82
|
+
"defaultState": { "toggles": ["mac"] }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
## Tabs
|
|
89
|
+
|
|
90
|
+
Tabs let you create mutually exclusive, synchronized content sections using the custom elements `<cv-tabgroup>` and `<cv-tab>`. All tab groups on the page that share the same `id` stay in sync — changing a tab in one group updates the others automatically.
|
|
91
|
+
|
|
92
|
+
Basic example with synchronized groups:
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<cv-tabgroup id="fruit">
|
|
96
|
+
<cv-tab id="apple" header="Apple">
|
|
97
|
+
|
|
98
|
+
**Apple Information**
|
|
99
|
+
|
|
100
|
+
Apples are crisp, sweet fruits that come in many varieties. They are rich in fiber and vitamin C.
|
|
101
|
+
|
|
102
|
+
</cv-tab>
|
|
103
|
+
<cv-tab id="orange" header="Orange">
|
|
104
|
+
|
|
105
|
+
**Orange Information**
|
|
106
|
+
|
|
107
|
+
Oranges are citrus fruits known for their high vitamin C content and refreshing juice.
|
|
108
|
+
|
|
109
|
+
</cv-tab>
|
|
110
|
+
<cv-tab id="pear" header="Pear">
|
|
111
|
+
|
|
112
|
+
**Pear Information**
|
|
113
|
+
|
|
114
|
+
Pears are sweet, bell-shaped fruits with a soft texture when ripe. They're high in fiber and antioxidants.
|
|
115
|
+
|
|
116
|
+
</cv-tab>
|
|
117
|
+
</cv-tabgroup>
|
|
118
|
+
|
|
119
|
+
<cv-tabgroup id="fruit" nav="auto">
|
|
120
|
+
<cv-tab id="apple" header="Apple Types">
|
|
121
|
+
|
|
122
|
+
Apple types include **Granny Smith** and the **Cosmic Crisp**.
|
|
123
|
+
|
|
124
|
+
</cv-tab>
|
|
125
|
+
<cv-tab id="orange" header="Orange Types">
|
|
126
|
+
|
|
127
|
+
Orange types include the **Blood orange** and **Valencia orange**.
|
|
128
|
+
</cv-tab>
|
|
129
|
+
<cv-tab id="pear" header="Pear">
|
|
130
|
+
|
|
131
|
+
Pear types include the **Asian pear** and the **European pear**
|
|
132
|
+
</cv-tab>
|
|
133
|
+
</cv-tabgroup>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
* **Synchronized Tab Groups** Multiple tab groups with the same `id` will automatically synchronize. When you switch tabs in one group, all other groups with the same ID will update simultaneously.
|
|
137
|
+
|
|
138
|
+
### Attributes & Options
|
|
139
|
+
|
|
140
|
+
#### `<cv-tabgroup>` Attributes
|
|
141
|
+
|
|
142
|
+
| Name | Type | Default | Description |
|
|
143
|
+
|------|------|---------|-------------|
|
|
144
|
+
| `id` | string | **(required)** | Unique identifier for the tab group. Tab groups with the same ID will synchronize. |
|
|
145
|
+
| `nav` | string | `"auto"` | Navigation display mode. Use `"auto"` to automatically generate navigation, or `"none"` to hide navigation. |
|
|
146
|
+
|
|
147
|
+
#### `<cv-tab>` Attributes
|
|
148
|
+
|
|
149
|
+
| Name | Type | Default | Description |
|
|
150
|
+
|------|------|---------|-------------|
|
|
151
|
+
| `id` | string | **(required)** | Unique identifier for the tab within its group. |
|
|
152
|
+
| `header` | string | Tab ID | Display label for the tab in the navigation bar. Supports text and font-awesome emojis. |
|
|
153
|
+
|
|
154
|
+
**Config integration**:
|
|
155
|
+
If you declare tab groups in `customviews.config.json` under `config.tabGroups`, they will appear in the widget with friendly labels and default selections. Example:
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"config": {
|
|
160
|
+
"tabGroups": [
|
|
161
|
+
{
|
|
162
|
+
"id": "fruit",
|
|
163
|
+
"label": "Fruit Selection",
|
|
164
|
+
"default": "apple",
|
|
165
|
+
"tabs": [
|
|
166
|
+
{ "id": "apple", "label": "Apple" },
|
|
167
|
+
{ "id": "orange", "label": "Orange" },
|
|
168
|
+
{ "id": "pear", "label": "Pear" }
|
|
169
|
+
]
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Resolution order of tabs and toggles is as follows:
|
|
177
|
+
* URL state (if present) → persisted localStorage state → `config.defaultState`.
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
### Simple Setup (auto-init)
|
|
181
|
+
|
|
182
|
+
To get started quickly, add the following snippet to your site's `<head>` or right before `</body>`:
|
|
183
|
+
|
|
184
|
+
```html
|
|
185
|
+
<!-- Load from CDN or your hosted bundle -->
|
|
186
|
+
<script src="https://unpkg.com/@customviews-js/customviews/dist/custom-views.min.js"
|
|
187
|
+
data-base-url="/customviews"
|
|
188
|
+
></script>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
This snippet loads:
|
|
192
|
+
* The CustomViews runtime, a lightweight JavaScript that auto-initializes on page load.
|
|
193
|
+
* The base URL and config path, which tell the runtime where to find your assets and configuration.
|
|
194
|
+
|
|
195
|
+
By default the auto-init script will:
|
|
196
|
+
1. Load configuration (default path `/customviews.config.json`)
|
|
197
|
+
2. Initialize the core library
|
|
198
|
+
3. Create and render the widget if enabled
|
|
199
|
+
|
|
200
|
+
## Configuration
|
|
201
|
+
|
|
202
|
+
The config file uses a flat top-level structure. Key fields:
|
|
203
|
+
|
|
204
|
+
Example `customviews.config.json`:
|
|
205
|
+
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"config": {
|
|
209
|
+
"allToggles": ["mac", "linux", "windows"],
|
|
210
|
+
"defaultState": {
|
|
211
|
+
"toggles": ["mac", "linux", "windows"],
|
|
212
|
+
"tabs": { "fruit": "apple" }
|
|
213
|
+
},
|
|
214
|
+
"tabGroups": [
|
|
215
|
+
{
|
|
216
|
+
"id": "fruit",
|
|
217
|
+
"label": "Fruit Selection",
|
|
218
|
+
"default": "apple",
|
|
219
|
+
"tabs": [
|
|
220
|
+
{ "id": "apple", "label": "Apple" },
|
|
221
|
+
{ "id": "orange", "label": "Orange" },
|
|
222
|
+
{ "id": "pear", "label": "Pear" }
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
},
|
|
227
|
+
"assetsJsonPath": "/assets/assets.json",
|
|
228
|
+
"baseUrl": "/customviews",
|
|
229
|
+
"showUrl": false,
|
|
230
|
+
"widget": {
|
|
231
|
+
"enabled": true,
|
|
232
|
+
"position": "middle-left",
|
|
233
|
+
"showReset": true,
|
|
234
|
+
"title": "Customize your view here",
|
|
235
|
+
"description": "Toggle content sections and switch between different tab views.",
|
|
236
|
+
"showWelcome": true
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
#### Key Fields
|
|
242
|
+
|
|
243
|
+
| Field | Description |
|
|
244
|
+
| ------ | ------------ |
|
|
245
|
+
| `config.allToggles` | List of toggle IDs recognized by CustomViews. |
|
|
246
|
+
| `config.defaultState` | Toggles and tabs per tab group enabled by default on first load. |
|
|
247
|
+
| `assetsJsonPath` | Path to your compiled assets manifest (resolved relative to `baseURL`). |
|
|
248
|
+
| `widget` | Floating widget settings — control position, visibility, and welcome prompt. |
|
|
249
|
+
| `showUrl` | When true, CustomViews encodes the active state into the browser URL for shareable links. |
|
|
250
|
+
|
|
251
|
+
#### Script Attributes
|
|
252
|
+
|
|
253
|
+
The auto-init script supports these data attributes:
|
|
254
|
+
- `data-base-url`: Base URL for all paths (e.g., `/customviews`)
|
|
255
|
+
- `data-config-path`: Custom path to config file (default: `/customviews.config.json`)
|
|
256
|
+
|
|
257
|
+
```html
|
|
258
|
+
<script
|
|
259
|
+
src="https://unpkg.com/@customviews-js/customviews"
|
|
260
|
+
data-base-url="/my-site"
|
|
261
|
+
data-config-path="/configs/customviews.config.json">
|
|
262
|
+
</script>
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
## Widget Features
|
|
267
|
+
|
|
268
|
+
- Floating widget with optional welcome modal and reset
|
|
269
|
+
- Config-driven (enable/disable, position, theme, labels)
|
|
270
|
+
- Shows toggles and tab groups declared in `config` for quick switching
|
|
271
|
+
- Can persist state to URL for sharing
|
|
272
|
+
|
|
273
|
+
Widget configuration options:
|
|
274
|
+
|
|
275
|
+
| Name | Type | Default | Description |
|
|
276
|
+
|------|------|---------|-------------|
|
|
277
|
+
| `enabled` | boolean | true | Whether to show the widget. |
|
|
278
|
+
| `position` | string | 'middle-left' | Position of the widget (e.g., 'middle-left', 'bottom-right'). |
|
|
279
|
+
| `showReset` | boolean | true | Whether to show the reset button. |
|
|
280
|
+
| `showWelcome` | boolean | false | Whether to show a welcome modal on first visit. |
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
{
|
|
284
|
+
core: CustomViewsCore; // Required: core instance
|
|
285
|
+
position?: string; // Default: 'middle-left'
|
|
286
|
+
theme?: 'light' | 'dark'; // Default: 'light'
|
|
287
|
+
showReset?: boolean; // Default: true
|
|
288
|
+
showWelcome?: boolean; // Default: false
|
|
289
|
+
welcomeTitle?: string; // Custom welcome title
|
|
290
|
+
welcomeMessage?: string; // Custom welcome message
|
|
291
|
+
title?: string; // Widget tooltip
|
|
292
|
+
description?: string; // Widget modal description
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Assets JSON
|
|
297
|
+
|
|
298
|
+
Assets are still defined in a JSON file referenced by `assetsJsonPath`. Example snippets are unchanged — asset keys map to HTML, text, or images and are rendered into elements that have `data-cv-id` (or legacy `data-customviews-id`).
|
|
299
|
+
|
|
300
|
+
The `assets.json` file defines reusable content that can be dynamically injected into your pages. Each asset is referenced by a unique key and can contain images, HTML, or text.
|
|
301
|
+
* Note that `baseURL` defined during initialization is automatically prepended to all asset `src` paths.
|
|
302
|
+
|
|
303
|
+
### Structure
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"htmlContent": {
|
|
308
|
+
"content": "<h2>Dynamic HTML</h2><p>This content is injected dynamically.</p>"
|
|
309
|
+
},
|
|
310
|
+
"textContent": {
|
|
311
|
+
"content": "Plain text content"
|
|
312
|
+
},
|
|
313
|
+
"imageContent": {
|
|
314
|
+
"src": "/assets/mac.png"
|
|
315
|
+
},
|
|
316
|
+
"assetKey": {
|
|
317
|
+
"src": "/path/to/image.png",
|
|
318
|
+
"alt": "Description",
|
|
319
|
+
"className": "custom-class",
|
|
320
|
+
"style": "border-radius: 8px;"
|
|
321
|
+
},
|
|
322
|
+
}
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Usage in HTML
|
|
326
|
+
|
|
327
|
+
```html
|
|
328
|
+
<!-- Reference asset by key using data-cv-id (or data-customviews-id for backward compatibility) -->
|
|
329
|
+
<div data-cv-toggle="beginner" data-cv-id="assetKey"></div>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
When the toggle is active, the asset will be automatically rendered into the element.
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
## Troubleshooting
|
|
336
|
+
|
|
337
|
+
* Toggles not appearing in widget?
|
|
338
|
+
* Check `config.allToggles` includes your toggle IDs.
|
|
339
|
+
|
|
340
|
+
* No effect when toggling?
|
|
341
|
+
* Ensure the element uses `data-cv-toggle` or `<cv-toggle>` with `category`, and matches an active toggle ID.
|
|
342
|
+
|
|
343
|
+
* URL state not persisting in URL bar?
|
|
344
|
+
* Enable `showUrl` in the configuration.
|
|
345
|
+
|
|
346
|
+
* Widget not loading?
|
|
347
|
+
* Verify the script is included and `customviews.config.json` is accessible.
|
|
348
|
+
|
|
349
|
+
* Tab groups not synchronizing?
|
|
350
|
+
* Ensure they share the same `id` attribute.
|
|
351
|
+
|
|
352
|
+
* Assets not rendering?
|
|
353
|
+
* Check `data-cv-id` matches a key in `assets.json`, and the toggle is active.
|
|
354
|
+
|
|
355
|
+
## API & Integration Notes
|
|
356
|
+
|
|
357
|
+
- Public globals: `window.CustomViews`, `window.CustomViewsWidget`, and `window.customViewsInstance` (contains `{ core, widget? }`) when auto-initialized.
|
|
358
|
+
- Important events: `customviews:ready` (auto-init done) and `customviews:tab-change` (dispatched when a tab group selection changes).
|
|
359
|
+
- URL state helpers: `URLStateManager.generateShareableURL` and `URLStateManager.parseURL` (used internally by the widget).
|
|
360
|
+
|
|
361
|
+
## License
|
|
362
|
+
|
|
363
363
|
MIT
|