@appius-fr/apx 2.6.2 → 2.7.1

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.
Files changed (36) hide show
  1. package/APX.mjs +2 -0
  2. package/README.md +226 -203
  3. package/dist/2ab50e700c8fbddb45e0.svg +10 -0
  4. package/dist/2e967d8dd752e0bed703.svg +10 -0
  5. package/dist/5ddaeefe5dfbc8e09652.svg +7 -0
  6. package/dist/6dc2907ba3bbb232601d.svg +10 -0
  7. package/dist/6e1e61dfca176a885b8d.svg +3 -0
  8. package/dist/6f3a0a27a260bb2c221b.svg +9 -0
  9. package/dist/8b07a8bf719a38262b7d.svg +10 -0
  10. package/dist/APX.dev.mjs +1167 -227
  11. package/dist/APX.mjs +1 -1
  12. package/dist/APX.prod.mjs +1 -1
  13. package/dist/APX.standalone.js +1119 -75
  14. package/dist/APX.standalone.js.map +1 -1
  15. package/dist/bdfa755a1cdb872368c7.svg +3 -0
  16. package/dist/c9da177f7663f9fcd023.svg +10 -0
  17. package/dist/ce9ef5fceb78e17e68c9.svg +8 -0
  18. package/dist/ed5af5163957b04bc6cc.svg +7 -0
  19. package/modules/listen/README.md +242 -235
  20. package/modules/listen/listen.mjs +1 -3
  21. package/modules/scrollableTable/CHANGELOG.md +37 -0
  22. package/modules/scrollableTable/README.md +108 -0
  23. package/modules/scrollableTable/css/scrollableTable.css +67 -0
  24. package/modules/scrollableTable/scrollableTable.mjs +577 -0
  25. package/modules/toast/README.md +186 -153
  26. package/modules/tristate/CHANGELOG.md +34 -0
  27. package/modules/tristate/README.md +157 -94
  28. package/modules/tristate/assets/tristate-checked.svg +3 -0
  29. package/modules/tristate/assets/tristate-cross.svg +10 -0
  30. package/modules/tristate/assets/tristate-crossed.svg +3 -0
  31. package/modules/tristate/assets/tristate-indeterminate-dash.svg +9 -0
  32. package/modules/tristate/assets/tristate-tick.svg +10 -0
  33. package/modules/tristate/assets/tristate-unchecked.svg +7 -0
  34. package/modules/tristate/css/tristate.css +91 -24
  35. package/modules/tristate/tristate.mjs +292 -171
  36. package/package.json +5 -1
@@ -1,153 +1,186 @@
1
- # APX Toast
2
-
3
- A tiny, framework‑agnostic toast library for APX. Minimal CSS, ESM‑first, no globals. DOM is only touched when you actually show a toast (SSR‑safe to import).
4
-
5
- ## Install / Import
6
-
7
- Just import `APX` — the toast CSS is automatically loaded by `modules/toast/toast.mjs`.
8
-
9
- ```html
10
- <script type="module">
11
- import APX from './APX.mjs';
12
- // CSS is auto‑imported; no <link> tag required.
13
- // ...
14
- APX.toast.success('Ready!');
15
- </script>
16
- ```
17
-
18
- ## Quick start
19
-
20
- ```js
21
- // Default manager (lazy)
22
- APX.toast.success('Saved!');
23
- APX.toast.warning('Heads up', { durationMs: 4000 });
24
- APX.toast.danger('Something failed', { durationMs: 0 }); // sticky
25
-
26
- // Custom toast
27
- const ref = APX.toast.show({ message: 'Processing…', type: 'info', durationMs: 0 });
28
- // Callable shorthand for show:
29
- APX.toast({ message: 'Hello', type: 'success' });
30
- ref.update({ message: 'Done', type: 'success', durationMs: 1800 });
31
- ref.whenClosed().then(() => console.log('closed'));
32
-
33
- // Configure defaults at runtime
34
- APX.toast.configure({ position: 'top-right', maxToasts: 4, dedupe: true });
35
- ```
36
-
37
- ### Named managers (profiles)
38
-
39
- ```js
40
- // Register a named manager
41
- APX.toast.create('admin', { position: 'bottom-left', ariaLive: 'polite' });
42
-
43
- // Use it later
44
- APX.toast.use('admin').info('Admin ready');
45
- APX.toast.use('admin').closeAll();
46
- ```
47
-
48
- ## API overview
49
-
50
- - Top‑level (default manager):
51
- - `APX.toast.show(opts)`
52
- - `APX.toast.info|success|warning|danger(message, opts?)`
53
- - `APX.toast.configure(config)`
54
- - `APX.toast.closeAll(reason?)`
55
- - `APX.toast.create(name, config)` registers named manager
56
- - `APX.toast.use(name)` returns named manager
57
-
58
- - Named manager instance (same surface):
59
- - `.show(opts)`, `.info|success|warning|danger(message, opts?)`
60
- - `.configure(config)`, `.closeAll(reason?)`
61
-
62
- ## Options and types
63
-
64
- ```js
65
- // ToastConfig (global/manager defaults)
66
- {
67
- position: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left', // default 'bottom-right'
68
- maxToasts: number, // default 5
69
- defaultDurationMs: number, // default 5000
70
- zIndex: number, // default 11000
71
- ariaLive: 'polite'|'assertive'|'off', // default 'polite'
72
- gap: number, // default 8
73
- dedupe: boolean, // default false
74
- containerClass: string, // extra class on container
75
- offset: number, // px offset from screen edges
76
- progress: false | true | { enable, position?, pauseButton? } // default false; pauseButton default false (v2.6.1)
77
- }
78
-
79
- // ToastOptions (per toast)
80
- {
81
- message: string | Node,
82
- type: 'info'|'success'|'warning'|'danger', // default 'info'
83
- durationMs: number, // default from config; 0 = sticky
84
- dismissible: boolean, // default true
85
- id: string, // stable id for dedupe updates
86
- className: string, // extra classes on the toast element
87
- progress: true | { enable: boolean, position?: 'top'|'bottom', pauseButton?: boolean }, // v2.6.1; pauseButton default false
88
- onClick: (ref, ev) => void,
89
- onClose: (ref, reason) => void // reason: 'timeout'|'close'|'api'|'overflow'
90
- }
91
- ```
92
-
93
- ## Theming (minimal CSS)
94
-
95
- Override CSS variables to theme without touching markup:
96
-
97
- ```css
98
- :root {
99
- --apx-toast-gap: 10px;
100
- --apx-toast-min-width: 280px;
101
- --apx-toast-radius: 8px;
102
- --apx-toast-success-bg: #16a34a;
103
- --apx-toast-success-fg: #fff;
104
- }
105
- ```
106
-
107
- Class structure (BEM‑like):
108
- - Container: `APX-toast-container APX-toast-container--{corner}`
109
- - Toast: `APX-toast APX-toast--{type}`
110
- - Children: `APX-toast__content`, optional `APX-toast__close`
111
- - Progress (v2.6.1): `APX-toast__progress`, `APX-toast__progress-track`, `APX-toast__progress-bar`, optional `APX-toast__progress-pause`
112
- - Animations: `APX-toast--enter/--enter-active`, `APX-toast--exit/--exit-active`
113
-
114
- ## Progress bar (v2.6.1)
115
-
116
- Optional visual countdown for toasts with a duration. Bar shows time remaining (100% → 0%); sync with timer and hover pause.
117
-
118
- ```js
119
- // Bar on top (default), no pause button by default
120
- APX.toast.show({ message: 'Saving…', type: 'info', progress: true });
121
-
122
- // Bar with pause/resume button
123
- APX.toast.show({ message: 'Pausable', type: 'info', progress: { enable: true, position: 'top', pauseButton: true } });
124
-
125
- // Bar at bottom
126
- APX.toast.show({ message: 'Done', type: 'success', progress: { enable: true, position: 'bottom' } });
127
-
128
- // Default progress for all toasts from a manager
129
- APX.toast.configure({ progress: true });
130
- ```
131
-
132
- - `progress: true` → bar at top, no pause button.
133
- - `progress: { enable, position: 'top'|'bottom', pauseButton?: boolean }` — `pauseButton` defaults to `false`; set `pauseButton: true` to show the round pause/resume button on the toast corner.
134
- - No bar if `durationMs === 0` (sticky). Extra spacing is applied when the button is present so stacked toasts do not overlap.
135
-
136
- ## Behavior
137
-
138
- - Lazy container creation (first `show`).
139
- - `maxToasts` enforced; oldest removed with reason `'overflow'`.
140
- - Hover pauses timer; resumes on mouse leave (unless user clicked pause).
141
- - `durationMs = 0` makes the toast sticky (no progress bar).
142
- - If `dedupe: true` and `id` matches an open toast, it updates instead of creating a new one.
143
- - With `progress`, a bar and optional pause/resume button show; button toggles pause (same as hover).
144
-
145
- ## Accessibility & SSR
146
-
147
- - Container uses `aria-live` (configurable).
148
- - Each toast has `role="status"`.
149
- - ESM only; no DOM access at import time. Safe to import in SSR; DOM is touched only when showing toasts in the browser.
150
-
151
- ## License
152
-
153
- Copyright Appius.
1
+ # APX Toast
2
+
3
+ A tiny, framework‑agnostic toast library for APX. Minimal CSS, ESM‑first, no globals. DOM is only touched when you actually show a toast (SSR‑safe to import).
4
+
5
+ ## Install / Import
6
+
7
+ Just import `APX` — the toast CSS is automatically loaded by `modules/toast/toast.mjs`.
8
+
9
+ ```html
10
+ <script type="module">
11
+ import APX from './APX.mjs';
12
+ // CSS is auto‑imported; no <link> tag required.
13
+ // ...
14
+ APX.toast.success('Ready!');
15
+ </script>
16
+ ```
17
+
18
+ ## Quick start
19
+
20
+ ```js
21
+ // Default manager (lazy)
22
+ APX.toast.success('Saved!');
23
+ APX.toast.warning('Heads up', { durationMs: 4000 });
24
+ APX.toast.danger('Something failed', { durationMs: 0 }); // sticky
25
+
26
+ // Custom toast
27
+ const ref = APX.toast.show({ message: 'Processing…', type: 'info', durationMs: 0 });
28
+ // Callable shorthand for show:
29
+ APX.toast({ message: 'Hello', type: 'success' });
30
+ ref.update({ message: 'Done', type: 'success', durationMs: 1800 });
31
+ ref.whenClosed().then(() => console.log('closed'));
32
+
33
+ // Configure defaults at runtime
34
+ APX.toast.configure({ position: 'top-right', maxToasts: 4, dedupe: true });
35
+ ```
36
+
37
+ ### Named managers (profiles)
38
+
39
+ ```js
40
+ // Register a named manager
41
+ APX.toast.create('admin', { position: 'bottom-left', ariaLive: 'polite' });
42
+
43
+ // Use it later
44
+ APX.toast.use('admin').info('Admin ready');
45
+ APX.toast.use('admin').closeAll();
46
+ ```
47
+
48
+ ## API overview
49
+
50
+ - Top‑level (default manager):
51
+ - `APX.toast(opts)` — callable shorthand for `show(opts)`
52
+ - `APX.toast.show(opts)`
53
+ - `APX.toast.info|success|warning|danger(message, opts?)`
54
+ - `APX.toast.configure(config)`
55
+ - `APX.toast.closeAll(reason?)` `reason`: `'api'` | `'overflow'`
56
+ - `APX.toast.getOpenToasts()` returns `ToastRef[]`
57
+ - `APX.toast.create(name, config)` — register named manager; or `create(config)` to get a new manager without registering
58
+ - `APX.toast.use(name)` — returns named manager or `null`
59
+
60
+ - Named manager instance (same surface):
61
+ - `.show(opts)`, `.info|success|warning|danger(message, opts?)`
62
+ - `.configure(config)`, `.closeAll(reason?)`, `.getOpenToasts()`
63
+
64
+ - **ToastRef** (returned by `show` / helpers):
65
+ - `ref.id`, `ref.el` (HTMLElement)
66
+ - `ref.close(reason?)` — `reason`: `'api'` | `'close'`
67
+ - `ref.update(partial)` merge options (message, type, durationMs, progress, className, etc.)
68
+ - `ref.whenClosed()` `Promise<void>` when toast is removed
69
+ - `ref.on('close'|'click', handler)` — returns unsubscribe function
70
+ - `ref.off('close'|'click', handler)`
71
+
72
+ ## Options and types
73
+
74
+ ```js
75
+ // ToastConfig (global/manager defaults)
76
+ {
77
+ position: Position, // default 'bottom-right' (string or object, see Position below)
78
+ flow: 'up'|'down'|'auto', // stacking direction; 'auto' from position (default 'auto')
79
+ maxToasts: number, // default 5
80
+ defaultDurationMs: number, // default 5000
81
+ zIndex: number, // default 11000
82
+ ariaLive: 'polite'|'assertive'|'off', // default 'polite'
83
+ gap: number, // default 8
84
+ dedupe: boolean, // default false
85
+ containerClass: string, // extra class on container
86
+ offset: number, // px offset from screen edges (string positions only)
87
+ id: string, // default id for toasts when not provided per-call
88
+ progress: false | true | { enable, position?, pauseButton? } // default false; pauseButton default false
89
+ }
90
+
91
+ // Position — string or object
92
+ // String: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
93
+ // Object:
94
+ // - type 'sticky': fixed viewport, use x / y (e.g. '10px', '-20px' = from right/bottom)
95
+ // - type 'relative': relative to element; x, y offset; requires element
96
+ // - type 'anchored': outside element; placement 'top'|'right'|'bottom'|'left' (or 'above'|'below'|'before'|'after'); gap; requires element
97
+ // - useNativeCSS: true — for relative/anchored, render container inside the element with CSS (no fixed overlay)
98
+
99
+ // ToastOptions (per toast)
100
+ {
101
+ message: string | Node,
102
+ type: 'info'|'success'|'warning'|'danger', // default 'info'
103
+ durationMs: number, // default from config; 0 = sticky
104
+ dismissible: boolean, // default true
105
+ id: string, // stable id for dedupe updates
106
+ className: string, // extra classes on the toast element
107
+ position: Position, // override container position for this toast
108
+ flow: 'up'|'down'|'auto', // override stacking direction for this toast
109
+ progress: true | { enable: boolean, position?: 'top'|'bottom', pauseButton?: boolean }, // pauseButton default false
110
+ onClick: (ref, ev) => void,
111
+ onClose: (ref, reason) => void // reason: 'timeout'|'close'|'api'|'overflow'
112
+ }
113
+ ```
114
+
115
+ ## Position (advanced)
116
+
117
+ Besides the four corners (`'bottom-right'`, `'bottom-left'`, `'top-right'`, `'top-left'`), position can be an object:
118
+
119
+ - **sticky** (or omit type and set `x`/`y`): fixed in viewport. Use `x`, `y` as CSS values; prefix with `-` for right/bottom (e.g. `y: '-20px'`).
120
+ - **relative**: fixed overlay positioned relative to an element. Requires `element` (HTMLElement); `x`, `y` are offsets (px/em). Container follows scroll/resize.
121
+ - **anchored**: container placed outside the element. Requires `element` and `placement` (`'top'|'right'|'bottom'|'left'` or synonyms `'above'|'below'|'before'|'after'`). Optional `gap` (e.g. `'1em'`).
122
+ - **useNativeCSS**: when `true` with relative/anchored, the toast container is rendered inside the target element with `position: absolute` (no fixed overlay). The target gets `position: relative` while toasts exist.
123
+
124
+ `flow` (`'up'|'down'|'auto'`) controls stacking: `'auto'` is derived from position (e.g. top → up, bottom → down).
125
+
126
+ ## Theming (minimal CSS)
127
+
128
+ Override CSS variables to theme without touching markup:
129
+
130
+ ```css
131
+ :root {
132
+ --apx-toast-gap: 10px;
133
+ --apx-toast-min-width: 280px;
134
+ --apx-toast-radius: 8px;
135
+ --apx-toast-success-bg: #16a34a;
136
+ --apx-toast-success-fg: #fff;
137
+ }
138
+ ```
139
+
140
+ Class structure (BEM‑like):
141
+ - Container: `APX-toast-container APX-toast-container--{corner}`
142
+ - Toast: `APX-toast APX-toast--{type}`
143
+ - Children: `APX-toast__content`, optional `APX-toast__close`
144
+ - Progress (v2.6.1): `APX-toast__progress`, `APX-toast__progress-track`, `APX-toast__progress-bar`, optional `APX-toast__progress-pause`
145
+ - Animations: `APX-toast--enter/--enter-active`, `APX-toast--exit/--exit-active`
146
+
147
+ ## Progress bar (v2.6.1)
148
+
149
+ Optional visual countdown for toasts with a duration. Bar shows time remaining (100% 0%); sync with timer and hover pause.
150
+
151
+ ```js
152
+ // Bar on top (default), no pause button by default
153
+ APX.toast.show({ message: 'Saving…', type: 'info', progress: true });
154
+
155
+ // Bar with pause/resume button
156
+ APX.toast.show({ message: 'Pausable', type: 'info', progress: { enable: true, position: 'top', pauseButton: true } });
157
+
158
+ // Bar at bottom
159
+ APX.toast.show({ message: 'Done', type: 'success', progress: { enable: true, position: 'bottom' } });
160
+
161
+ // Default progress for all toasts from a manager
162
+ APX.toast.configure({ progress: true });
163
+ ```
164
+
165
+ - `progress: true` → bar at top, no pause button.
166
+ - `progress: { enable, position: 'top'|'bottom', pauseButton?: boolean }` — `pauseButton` defaults to `false`; set `pauseButton: true` to show the round pause/resume button on the toast corner.
167
+ - No bar if `durationMs === 0` (sticky). Extra spacing is applied when the button is present so stacked toasts do not overlap.
168
+
169
+ ## Behavior
170
+
171
+ - Lazy container creation (first `show`).
172
+ - `maxToasts` enforced; oldest removed with reason `'overflow'`.
173
+ - Hover pauses timer; resumes on mouse leave (unless user clicked pause).
174
+ - `durationMs = 0` makes the toast sticky (no progress bar).
175
+ - If `dedupe: true` and `id` matches an open toast, it updates instead of creating a new one.
176
+ - With `progress`, a bar and optional pause/resume button show; button toggles pause (same as hover).
177
+
178
+ ## Accessibility & SSR
179
+
180
+ - Container uses `aria-live` (configurable).
181
+ - Each toast has `role="status"`.
182
+ - ESM only; no DOM access at import time. Safe to import in SSR; DOM is touched only when showing toasts in the browser.
183
+
184
+ ## License
185
+
186
+ Copyright Appius.
@@ -0,0 +1,34 @@
1
+ # Tristate Module Changelog
2
+
3
+ This changelog tracks updates for `modules/tristate` between APX releases.
4
+
5
+ ## TBA (next release)
6
+
7
+ ### Added
8
+ - **Chainable API**: `tristate(options)` now returns an object with `setChildren(childrenApx)`. Use it to link a parent tristate to its child checkboxes.
9
+ - **Parent + sub-checkboxes**: `setChildren(childrenApx)` wires one parent (first in the selection) to all child checkboxes. Parent reflects children (all checked → parent checked, all crossed → parent crossed, all unchecked → parent empty, **mixed → parent shows indeterminate dash**). Clicking the parent applies its new state to all children. Children are initialized as tristates with the same options as the parent.
10
+ - **Automatic indeterminate (dash)**: When `setChildren()` is used, the parent automatically gets the indeterminate (dash) appearance **only when children are mixed**. When all children are unchecked the parent shows an empty frame. Indeterminate is no longer a manual option; it is derived from child states.
11
+ - New `colors` option: an object grouping color targets.
12
+ - `colors.tick`: checked/crossed symbol color (default: `transparent`).
13
+ - `colors.checked`: checked state background (default: `#0654ba`).
14
+ - `colors.crossed`: crossed state background (default: `#f00`).
15
+ - Flat options `tickColor`, `checkedColor`, `crossedColor` remain supported for backward compatibility; `colors` takes precedence when both are set.
16
+ - CSS class `apx-tristate--mixed`: when the parent has indeterminate-dash and `--mixed`, the dash is shown; when not `--mixed` (e.g. all children unchecked), the parent shows an empty unchecked frame. Used internally by `setChildren()`.
17
+
18
+ ### Changed
19
+ - `size.width` and `size.height` accept numbers (treated as pixels) or strings (used as CSS length, e.g. `'1.25rem'`, `'20px'`). Invalid types throw `TypeError`.
20
+ - Tristate symbols (check and cross) are rendered with `mask-image` and data URIs over themeable backgrounds. Unchecked and indeterminate-dash assets are inlined as data URIs in CSS so the demo works from `file://` without CORS.
21
+ - Unchecked icon uses a rounded inset (`4px`). Indeterminate (dash) uses checked background + tick-colored dash; indeterminate (filled check) uses checked background only with `border-radius: inherit`.
22
+ - **State classes**: Only one of `unchecked` / `checked` / `crossed` is ever set on the tristate DOM (fixes parent with `setChildren` incorrectly showing indeterminate when state was `crossed`). `setDefaultState` and `toggleTriStateCheckboxState` now clear all three before adding the active one.
23
+ - Asset `tristate-indeterminate.svg` renamed to `tristate-indeterminate-dash.svg`.
24
+
25
+ ### Removed
26
+ - **Breaking**: Options `uncheckedAppearance` and `indeterminateDisplay` have been removed. Indeterminate (dash) is no longer configurable manually; it is applied automatically on parents that use `setChildren()` when their children are in a mixed state.
27
+
28
+ ### Docs & Demo
29
+ - Demo `demo/modules/tristate/index.html`: Parameters (size + colors), Live preview, States preview, Interactive cycle, **Parent + sub-checkboxes** real-world section using `APX('#policyParent').tristate(opts).setChildren(APX('#policyEmail, #policySms, #policyPush'))`. Removed manual uncheckedAppearance/indeterminateDisplay controls and the separate “Unchecked appearance” preview section.
30
+ - README: documented `setChildren(childrenApx)`, automatic indeterminate when mixed, and removed `uncheckedAppearance` / `indeterminateDisplay` from the options list.
31
+
32
+ ## 2.6.2 (current)
33
+
34
+ Baseline for this changelog. Tristate visuals and options prior to the theming improvements above.
@@ -1,95 +1,158 @@
1
- # APX Tri-State Checkbox Module
2
-
3
- The APX Tri-State Checkbox module provides an augmentation to the `APX` object. This functionality allows you to easily transform standard checkboxes within an `APX` object into tri-state checkboxes.
4
-
5
- ## Installation
6
-
7
- Ensure you have the core `APX` object integrated into your project.
8
-
9
- Next, to use this augmentation, make sure you've imported and added the `tristate` module to your project:
10
-
11
- ```javascript
12
- import APX from 'path-to-APX';
13
- // Assuming tristate is part of APX's module structure
14
- ```
15
-
16
- Also, link the required CSS:
17
-
18
- ```html
19
- <link rel="stylesheet" href="path-to-css/tristate.css">
20
- ```
21
-
22
- ## Usage
23
-
24
- To transform a group of checkboxes into tri-state checkboxes using the `APX` object, first create an `APX` object containing the checkboxes you wish to transform, then simply call the `tristate` method:
25
-
26
- ```javascript
27
- const myApxCheckboxes = APX('.my-checkbox-class');
28
- myApxCheckboxes.tristate();
29
- ```
30
-
31
- ### Parameters
32
-
33
- The `tristate` method accepts an `options` parameter which can have the following properties:
34
-
35
- - `size`: An object that defines the `width` and `height` of the tri-state checkbox.
36
- - `width`: Width of the checkbox in pixels (e.g., `50` for 50px width).
37
- - `height`: Height of the checkbox in pixels.
38
-
39
- - `classes`: A string or an array of strings representing classes to be added to the custom checkbox. The string can contain class names separated by spaces or commas.
40
-
41
- - `defaultState`: A string that defines the default state of the tri-state checkbox. Possible values are 'checked', 'unchecked', and 'crossed'.
42
-
43
- - `callbacks`: An object that contains callback functions.
44
- - `after`: A function that is called after the tri-state checkbox is created.
45
- - `change`: A function that is called when the tri-state checkbox state changes.
46
-
47
- - `bubbleEvents`: A boolean that determines whether events (`click`, `keyup`, `change`) on the custom checkbox should bubble up to the original checkbox.
48
-
49
- Example:
50
-
51
- ```javascript
52
- const options = {
53
- size: {
54
- width: 50,
55
- height: 30
56
- },
57
- classes: 'myClass1 myClass2',
58
- defaultState: 'checked',
59
- callbacks: {
60
- after: function(originalCheckbox, tristateDom, hiddenInput) {
61
- console.log("Checkbox created!");
62
- },
63
- change: function(originalCheckbox, tristateDom, hiddenInput) {
64
- console.log("Checkbox state changed!");
65
- }
66
- },
67
- bubbleEvents: true
68
- };
69
-
70
- const myApxCheckboxes = APX('.my-checkbox-class');
71
- myApxCheckboxes.tristate(options);
72
- ```
73
-
74
- ## Features
75
-
76
- ### Tri-State Logic
77
-
78
- The checkbox will cycle through three states:
79
-
80
- 1. Checked (represented by a tick)
81
- 2. Crossed (represented by a cross)
82
- 3. Unchecked (default checkbox state)
83
-
84
- ### Accessibility
85
-
86
- The tri-state checkbox retains the `tabIndex` property of the original checkbox, ensuring the accessibility of the control.
87
-
88
- ### Event Bubbling
89
-
90
- Any `click`, `keyup`, or `change` events attached to the original checkbox will be bubbled up from the custom checkbox if the `bubbleEvents` option is set to true. This ensures that your existing event listeners will still work as expected and that custom callbacks can also be executed.
91
-
92
-
93
- ## License
94
-
1
+ # APX Tri-State Checkbox Module
2
+
3
+ The APX Tri-State Checkbox module provides an augmentation to the `APX` object. This functionality allows you to easily transform standard checkboxes within an `APX` object into tri-state checkboxes.
4
+
5
+ ### When to use this module
6
+
7
+ This module is designed for **whitelist/blacklist** and **inheritance-based policy** UIs: permissions, feature flags, or rule matrices where each row can be explicitly allowed, explicitly denied, or left unspecified (inherit/default). Three distinct states avoid forcing a binary choice and keep policy intent clear both in the UI and when submitting to the backend.
8
+
9
+ ## Installation
10
+
11
+ Ensure you have the core `APX` object integrated into your project.
12
+
13
+ Next, to use this augmentation, make sure you've imported and added the `tristate` module to your project:
14
+
15
+ ```javascript
16
+ import APX from 'path-to-APX';
17
+ // Assuming tristate is part of APX's module structure
18
+ ```
19
+
20
+ Also, link the required CSS:
21
+
22
+ ```html
23
+ <link rel="stylesheet" href="path-to-css/tristate.css">
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ To transform a group of checkboxes into tri-state checkboxes using the `APX` object, first create an `APX` object containing the checkboxes you wish to transform, then simply call the `tristate` method:
29
+
30
+ ```javascript
31
+ const myApxCheckboxes = APX('.my-checkbox-class');
32
+ myApxCheckboxes.tristate();
33
+ ```
34
+
35
+ **Example: policy row (whitelist/blacklist)** one checkbox per permission, submitted as allow/deny/inherit:
36
+
37
+ ```html
38
+ <form>
39
+ <label>Can edit <input type="checkbox" name="perm_edit" class="policy-cb"></label>
40
+ <label>Can delete <input type="checkbox" name="perm_delete" class="policy-cb"></label>
41
+ </form>
42
+ <script>
43
+ APX('.policy-cb').tristate({
44
+ defaultState: 'unchecked',
45
+ colors: { tick: '#fff' },
46
+ callbacks: { change: (_, el, hidden) => console.log(hidden.name, hidden.value || 'inherit'); }
47
+ });
48
+ </script>
49
+ ```
50
+
51
+ ### Parameters
52
+
53
+ The `tristate` method accepts an `options` parameter which can have the following properties:
54
+
55
+ - `size`: An object that defines the `width` and `height` of the tri-state checkbox.
56
+ - `width`: Numeric value is treated as pixels (e.g. `50` → `50px`); string values are used as-is (e.g. `'1.25rem'`, `'20px'`).
57
+ - `height`: Same as `width` (number = px, string = any CSS length).
58
+
59
+ - `classes`: A string or an array of strings representing classes to be added to the custom checkbox. The string can contain class names separated by spaces or commas.
60
+
61
+ - `defaultState`: A string that defines the default state of the tri-state checkbox. Possible values are 'checked', 'unchecked', and 'crossed'.
62
+
63
+ - `colors`: An object grouping color targets (recommended). Omitted keys keep CSS defaults.
64
+ - `tick`: CSS color for the check/cross symbol. Default is `transparent`.
65
+ - `checked`: CSS color for the checked state background. Default is `#0654ba`.
66
+ - `crossed`: CSS color for the crossed state background. Default is `#f00`.
67
+ - For backward compatibility, the flat options `tickColor`, `checkedColor`, and `crossedColor` are still supported; they are overridden by `colors` when both are present.
68
+
69
+ - `callbacks`: An object that contains callback functions.
70
+ - `after`: A function that is called after the tri-state checkbox is created.
71
+ - `change`: A function that is called when the tri-state checkbox state changes.
72
+
73
+ - `bubbleEvents`: A boolean that determines whether events (`click`, `keyup`, `change`) on the custom checkbox should bubble up to the original checkbox.
74
+
75
+ ### Parent + sub-checkboxes: `setChildren(childrenApx)`
76
+
77
+ `tristate()` returns a chainable object with a `setChildren` method. Use it to link one parent tristate to its child checkboxes. The parent then reflects the children (all checked → parent checked, all crossed → parent crossed, all unchecked → parent empty, **mixed children → parent shows indeterminate dash**). Clicking the parent applies its new state to all children.
78
+
79
+ The indeterminate (dash) appearance is **automatically** applied to the parent when `setChildren` is used: the dash is shown only when the children are in a mixed state; when all are unchecked the parent shows an empty frame.
80
+
81
+ ```javascript
82
+ APX('#policyParent').tristate({ size: { width: 28, height: 28 }, colors: { tick: '#fff' }, defaultState: 'unchecked' })
83
+ .setChildren(APX('#policyEmail, #policySms, #policyPush'));
84
+ ```
85
+
86
+ - Only the **first** parent in the APX selection is linked to **all** children in the given APX. For multiple parent/child groups, call `tristate().setChildren()` per parent.
87
+ - Children are initialized as tristates with the same options as the parent (plus internal change callbacks). If they are already tristates, they are just linked.
88
+
89
+ Example:
90
+
91
+ ```javascript
92
+ const options = {
93
+ size: {
94
+ width: 50,
95
+ height: 30
96
+ },
97
+ classes: 'myClass1 myClass2',
98
+ defaultState: 'checked',
99
+ callbacks: {
100
+ after: function(originalCheckbox, tristateDom, hiddenInput) {
101
+ console.log("Checkbox created!");
102
+ },
103
+ change: function(originalCheckbox, tristateDom, hiddenInput) {
104
+ console.log("Checkbox state changed!");
105
+ }
106
+ },
107
+ colors: {
108
+ tick: '#ffffff',
109
+ checked: '#0654ba',
110
+ crossed: '#ff0000'
111
+ },
112
+ bubbleEvents: true
113
+ };
114
+
115
+ const myApxCheckboxes = APX('.my-checkbox-class');
116
+ myApxCheckboxes.tristate(options);
117
+ ```
118
+
119
+ ## Features
120
+
121
+ ### Tri-State Logic
122
+
123
+ The checkbox will cycle through three states:
124
+
125
+ 1. Checked (represented by a tick)
126
+ 2. Crossed (represented by a cross)
127
+ 3. Unchecked (default checkbox state)
128
+
129
+ ### Whitelist/Blacklist semantics
130
+
131
+ For policy UIs, map the three states as follows:
132
+
133
+ | State | Visual | Typical meaning | Backend value (via hidden input) |
134
+ |-----------|--------|-------------------------|----------------------------------|
135
+ | Checked | Tick | Allow / whitelist | `true` (or your chosen value) |
136
+ | Crossed | Cross | Deny / blacklist | `false` (or your chosen value) |
137
+ | Unchecked | Empty | Inherit / default / N/A | Not submitted (no value) |
138
+
139
+ This gives you an explicit **deny vs not-set** distinction: users can leave a row unspecified instead of being forced to choose allow or deny.
140
+
141
+ ### Benefits
142
+
143
+ - **Explicit allow/deny vs inherit** — Unchecked means “no override”; checked and crossed mean explicit policy decisions.
144
+ - **Cleaner inheritance** — Hierarchical rules (e.g. org → team → user) can override only where needed; other levels inherit.
145
+ - **Auditability** — It is clear in the UI and in submitted data whether a rule was explicitly denied or simply not set.
146
+
147
+ ### Accessibility
148
+
149
+ The tri-state checkbox retains the `tabIndex` property of the original checkbox, ensuring the accessibility of the control.
150
+
151
+ ### Event Bubbling
152
+
153
+ Any `click`, `keyup`, or `change` events attached to the original checkbox will be bubbled up from the custom checkbox if the `bubbleEvents` option is set to true. This ensures that your existing event listeners will still work as expected and that custom callbacks can also be executed.
154
+
155
+
156
+ ## License
157
+
95
158
  Copyright Appius SARL
@@ -0,0 +1,3 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2
+ <rect width="32" height="32" fill="#0654ba" />
3
+ </svg>