@ulu/frontend 0.1.0-beta.3 → 0.1.0-beta.31
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/CHANGELOG.md +210 -1
- package/dist/ulu-frontend.min.css +1 -1
- package/dist/ulu-frontend.min.js +19 -18
- package/docs-dev/assets/main.js +832 -421
- package/docs-dev/assets/placeholder/icon-calendar.svg +1 -0
- package/docs-dev/assets/placeholder/icon-check.svg +1 -0
- package/docs-dev/assets/style.css +629 -233
- package/docs-dev/changelog/index.html +5660 -0
- package/docs-dev/changelog/updates-and-changes/index.html +5109 -0
- package/docs-dev/demos/accordion/index.html +758 -295
- package/docs-dev/demos/basic-hero/index.html +111 -0
- package/docs-dev/demos/button/index.html +758 -295
- package/docs-dev/demos/button-verbose/index.html +5118 -0
- package/docs-dev/demos/callout/index.html +783 -307
- package/docs-dev/demos/captioned-figure/index.html +758 -295
- package/docs-dev/demos/card/index.html +819 -719
- package/docs-dev/demos/card-grid/index.html +5241 -0
- package/docs-dev/demos/card-new/index.html +5088 -0
- package/docs-dev/demos/card-old/index.html +5223 -0
- package/docs-dev/demos/card.1/index.html +5223 -0
- package/docs-dev/demos/card.TRASH/index.html +5541 -0
- package/docs-dev/demos/css-icons/index.html +758 -295
- package/docs-dev/demos/data-grid/index.html +866 -483
- package/docs-dev/demos/data-table/index.html +783 -320
- package/docs-dev/demos/details-group/index.html +5114 -0
- package/docs-dev/demos/file-save/index.html +758 -295
- package/docs-dev/demos/flipcard/index.html +758 -295
- package/docs-dev/demos/form-theme/index.html +776 -326
- package/docs-dev/demos/hero/index.html +12 -4
- package/docs-dev/demos/image-grid/index.html +12 -4
- package/docs-dev/demos/index.html +758 -295
- package/docs-dev/demos/list-inline/index.html +5100 -0
- package/docs-dev/demos/list-inline.1/index.html +4727 -0
- package/docs-dev/demos/list-lines/index.html +5090 -0
- package/docs-dev/demos/menu-stack/index.html +777 -314
- package/docs-dev/demos/modals/index.html +758 -295
- package/docs-dev/demos/nav-strip/index.html +778 -351
- package/docs-dev/demos/overlay-section/index.html +758 -295
- package/docs-dev/demos/popovers/index.html +860 -299
- package/docs-dev/demos/print/index.html +758 -295
- package/docs-dev/demos/pull-quote/index.html +758 -295
- package/docs-dev/demos/rule/index.html +758 -295
- package/docs-dev/demos/scroll-slider/index.html +72 -106
- package/docs-dev/demos/scrollpoints/index.html +758 -295
- package/docs-dev/demos/slider/index.html +12 -4
- package/docs-dev/demos/spoke-spinner/index.html +758 -295
- package/docs-dev/demos/sticky-list/index.html +5103 -0
- package/docs-dev/demos/tabs/index.html +758 -295
- package/docs-dev/demos/tag/index.html +758 -295
- package/docs-dev/demos/theme-toggle/index.html +5159 -0
- package/docs-dev/demos/tile-grid-overlay/index.html +12 -4
- package/docs-dev/demos/tiles/index.html +758 -295
- package/docs-dev/demos/tooltip/index.html +758 -295
- package/docs-dev/guide/building-stylesheet/index.html +758 -295
- package/docs-dev/guide/developing-ulu-scss-module/index.html +758 -295
- package/docs-dev/guide/index.html +758 -295
- package/docs-dev/guide/updates-and-changes/index.html +5033 -0
- package/docs-dev/index.html +758 -295
- package/docs-dev/javascript/events/index.html +755 -294
- package/docs-dev/javascript/index.html +758 -295
- package/docs-dev/javascript/settings/index.html +5214 -0
- package/docs-dev/javascript/ui-breakpoints/index.html +755 -294
- package/docs-dev/javascript/ui-collapsible/index.html +755 -294
- package/docs-dev/javascript/ui-details-group/index.html +5214 -0
- package/docs-dev/javascript/ui-dialog/index.html +755 -294
- package/docs-dev/javascript/ui-flipcard/index.html +755 -294
- package/docs-dev/javascript/ui-grid/index.html +755 -294
- package/docs-dev/javascript/ui-modal-builder/index.html +755 -294
- package/docs-dev/javascript/ui-overflow-scroller/index.html +755 -294
- package/docs-dev/javascript/ui-overflow-scroller-pager/index.html +755 -294
- package/docs-dev/javascript/ui-page/index.html +755 -294
- package/docs-dev/javascript/ui-popover/index.html +755 -294
- package/docs-dev/javascript/ui-print/index.html +755 -294
- package/docs-dev/javascript/ui-print-details/index.html +755 -294
- package/docs-dev/javascript/ui-programmatic-modal/index.html +755 -294
- package/docs-dev/javascript/ui-proxy-click/index.html +755 -294
- package/docs-dev/javascript/ui-resizer/index.html +755 -294
- package/docs-dev/javascript/ui-scroll-slider/index.html +755 -294
- package/docs-dev/javascript/ui-scrollpoint/index.html +755 -294
- package/docs-dev/javascript/ui-slider/index.html +755 -294
- package/docs-dev/javascript/ui-tabs/index.html +755 -294
- package/docs-dev/javascript/ui-theme-toggle/index.html +5298 -0
- package/docs-dev/javascript/ui-tooltip/index.html +755 -294
- package/docs-dev/javascript/utils-class-logger/index.html +755 -294
- package/docs-dev/javascript/utils-dom/index.html +819 -298
- package/docs-dev/javascript/utils-file-save/index.html +755 -294
- package/docs-dev/javascript/utils-floating-ui/index.html +755 -294
- package/docs-dev/javascript/utils-id/index.html +755 -294
- package/docs-dev/javascript/utils-pause-youtube-video/index.html +755 -294
- package/docs-dev/sass/base/color/index.html +755 -294
- package/docs-dev/sass/base/elements/index.html +755 -294
- package/docs-dev/sass/base/index/index.html +755 -294
- package/docs-dev/sass/base/index.html +758 -295
- package/docs-dev/sass/base/keyframes/index.html +755 -294
- package/docs-dev/sass/base/layout/index.html +755 -294
- package/docs-dev/sass/base/normalize/index.html +755 -294
- package/docs-dev/sass/base/print/index.html +755 -294
- package/docs-dev/sass/base/root/index.html +755 -294
- package/docs-dev/sass/base/typography/index.html +755 -294
- package/docs-dev/sass/components/accordion/index.html +761 -300
- package/docs-dev/sass/components/adaptive-spacing/index.html +755 -294
- package/docs-dev/sass/components/badge/index.html +763 -302
- package/docs-dev/sass/components/basic-hero/index.html +5265 -0
- package/docs-dev/sass/components/button/index.html +755 -294
- package/docs-dev/sass/components/button-verbose/index.html +813 -303
- package/docs-dev/sass/components/callout/index.html +780 -355
- package/docs-dev/sass/components/captioned-figure/index.html +878 -302
- package/docs-dev/sass/components/card/index.html +817 -313
- package/docs-dev/sass/components/card-grid/index.html +755 -294
- package/docs-dev/sass/components/css-icon/index.html +772 -304
- package/docs-dev/sass/components/data-grid/index.html +755 -294
- package/docs-dev/sass/components/data-table/index.html +951 -305
- package/docs-dev/sass/components/fill-context/index.html +755 -294
- package/docs-dev/sass/components/flipcard/index.html +791 -299
- package/docs-dev/sass/components/flipcard-grid/index.html +755 -294
- package/docs-dev/sass/components/form-theme/index.html +965 -402
- package/docs-dev/sass/components/hero/index.html +811 -302
- package/docs-dev/sass/components/horizontal-rule/index.html +755 -294
- package/docs-dev/sass/components/image-grid/index.html +755 -294
- package/docs-dev/sass/components/index/index.html +768 -304
- package/docs-dev/sass/components/index.html +758 -295
- package/docs-dev/sass/components/links/index.html +755 -294
- package/docs-dev/sass/components/list-inline/index.html +5279 -0
- package/docs-dev/sass/components/list-lines/index.html +787 -330
- package/docs-dev/sass/components/list-ordered/index.html +757 -296
- package/docs-dev/sass/components/list-unordered/index.html +755 -294
- package/docs-dev/sass/components/menu-stack/index.html +789 -315
- package/docs-dev/sass/components/modal/index.html +776 -308
- package/docs-dev/sass/components/nav-strip/index.html +767 -306
- package/docs-dev/sass/components/overlay-section/index.html +763 -302
- package/docs-dev/sass/components/pager/index.html +755 -294
- package/docs-dev/sass/components/placeholder-block/index.html +755 -294
- package/docs-dev/sass/components/popover/index.html +812 -315
- package/docs-dev/sass/components/pull-quote/index.html +767 -306
- package/docs-dev/sass/components/ratio-box/index.html +755 -294
- package/docs-dev/sass/components/rule/index.html +763 -302
- package/docs-dev/sass/components/scroll-slider/index.html +755 -294
- package/docs-dev/sass/components/skip-link/index.html +763 -302
- package/docs-dev/sass/components/slider/index.html +762 -301
- package/docs-dev/sass/components/spoke-spinner/index.html +755 -294
- package/docs-dev/sass/components/sticky-list/index.html +5483 -0
- package/docs-dev/sass/components/tabs/index.html +764 -303
- package/docs-dev/sass/components/tag/index.html +755 -294
- package/docs-dev/sass/components/tile-button/index.html +755 -294
- package/docs-dev/sass/components/tile-grid/index.html +755 -294
- package/docs-dev/sass/components/tile-grid-overlay/index.html +755 -294
- package/docs-dev/sass/components/vignette/index.html +769 -302
- package/docs-dev/sass/components/wysiwyg/index.html +755 -294
- package/docs-dev/sass/core/breakpoint/index.html +755 -294
- package/docs-dev/sass/core/button/index.html +755 -294
- package/docs-dev/sass/core/color/index.html +793 -325
- package/docs-dev/sass/core/cssvar/index.html +755 -294
- package/docs-dev/sass/core/element/index.html +755 -294
- package/docs-dev/sass/core/index.html +755 -294
- package/docs-dev/sass/core/layout/index.html +762 -301
- package/docs-dev/sass/core/path/index.html +755 -294
- package/docs-dev/sass/core/selector/index.html +755 -294
- package/docs-dev/sass/core/typography/index.html +755 -294
- package/docs-dev/sass/core/units/index.html +755 -294
- package/docs-dev/sass/core/utils/index.html +1477 -382
- package/docs-dev/sass/helpers/color/index.html +755 -294
- package/docs-dev/sass/helpers/display/index.html +755 -294
- package/docs-dev/sass/helpers/index/index.html +755 -294
- package/docs-dev/sass/helpers/index.html +758 -295
- package/docs-dev/sass/helpers/print/index.html +755 -294
- package/docs-dev/sass/helpers/typography/index.html +755 -294
- package/docs-dev/sass/helpers/units/index.html +755 -294
- package/docs-dev/sass/helpers/utilities/index.html +755 -294
- package/docs-dev/sass/index.html +758 -295
- package/js/index.js +1 -0
- package/js/settings.js +78 -0
- package/js/ui/details-group.js +121 -0
- package/js/ui/index.js +1 -0
- package/js/ui/modal-builder.js +3 -2
- package/js/ui/overflow-scroller.js +5 -4
- package/js/ui/popover.js +1 -0
- package/js/ui/programmatic-modal.js +9 -3
- package/js/ui/slider.js +7 -6
- package/js/ui/theme-toggle.js +330 -89
- package/js/utils/dom.js +43 -1
- package/js/utils/font-awesome.js +18 -0
- package/js/utils/index.js +2 -1
- package/package.json +9 -6
- package/scss/_color.scss +9 -2
- package/scss/_layout.scss +1 -4
- package/scss/_utils.scss +187 -11
- package/scss/components/README.todos +14 -0
- package/scss/components/_accordion.scss +17 -18
- package/scss/components/_badge.scss +3 -2
- package/scss/components/_basic-hero.scss +112 -0
- package/scss/components/_button-verbose.scss +66 -12
- package/scss/components/_callout.scss +43 -54
- package/scss/components/_captioned-figure.scss +23 -5
- package/scss/components/_card-grid.scss +1 -1
- package/scss/components/_card.scss +190 -70
- package/scss/components/_css-icon.scss +16 -11
- package/scss/components/_data-table.scss +41 -4
- package/scss/components/_flipcard.scss +20 -14
- package/scss/components/_form-theme.scss +135 -123
- package/scss/components/_hero.scss +9 -0
- package/scss/components/_index.scss +18 -0
- package/scss/components/_list-inline.scss +80 -0
- package/scss/components/_list-lines.scss +44 -33
- package/scss/components/_list-ordered.scss +0 -1
- package/scss/components/_menu-stack.scss +42 -26
- package/scss/components/_modal.scss +23 -19
- package/scss/components/_nav-strip.scss +25 -16
- package/scss/components/_overlay-section.scss +2 -1
- package/scss/components/_pager.scss +6 -6
- package/scss/components/_placeholder-block.scss +4 -4
- package/scss/components/_popover.scss +174 -73
- package/scss/components/_pull-quote.scss +12 -12
- package/scss/components/_rule.scss +0 -1
- package/scss/components/_scroll-slider.scss +1 -1
- package/scss/components/_skip-link.scss +2 -1
- package/scss/components/_slider.scss +17 -38
- package/scss/components/_sticky-list.scss +206 -0
- package/scss/components/_tabs.scss +5 -2
- package/scss/components/_tag.scss +1 -1
- package/scss/components/_vignette.scss +1 -0
- package/types/index.d.ts +1 -0
- package/types/settings.d.ts +38 -0
- package/types/settings.d.ts.map +1 -0
- package/types/ui/details-group.d.ts +43 -0
- package/types/ui/details-group.d.ts.map +1 -0
- package/types/ui/index.d.ts +1 -0
- package/types/ui/modal-builder.d.ts +2 -2
- package/types/ui/modal-builder.d.ts.map +1 -1
- package/types/ui/overflow-scroller.d.ts +2 -2
- package/types/ui/overflow-scroller.d.ts.map +1 -1
- package/types/ui/popover.d.ts.map +1 -1
- package/types/ui/programmatic-modal.d.ts.map +1 -1
- package/types/ui/slider.d.ts +2 -2
- package/types/ui/slider.d.ts.map +1 -1
- package/types/ui/tabs.d.ts.map +1 -1
- package/types/ui/theme-toggle.d.ts +58 -7
- package/types/ui/theme-toggle.d.ts.map +1 -1
- package/types/utils/dom.d.ts +19 -1
- package/types/utils/dom.d.ts.map +1 -1
- package/types/utils/font-awesome.d.ts +5 -0
- package/types/utils/font-awesome.d.ts.map +1 -0
- package/types/utils/index.d.ts +1 -0
package/js/ui/theme-toggle.js
CHANGED
|
@@ -1,129 +1,370 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @module ui/theme-toggle
|
|
3
|
+
*/
|
|
2
4
|
|
|
3
|
-
// import { getName } from "@ulu/frontend/js/events/index.js";
|
|
4
5
|
import { getName } from "../events/index.js";
|
|
6
|
+
import { getDatasetJson, getElements, resolveClasses } from "../utils/dom.js";
|
|
7
|
+
import { hasRequiredProps } from "@ulu/utils/object.js";
|
|
5
8
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Default data attributes
|
|
11
|
+
*/
|
|
12
|
+
export const attrs = {
|
|
13
|
+
init: "data-ulu-theme-toggle-init",
|
|
14
|
+
toggle: "data-ulu-theme-toggle",
|
|
15
|
+
toggleIcon: "data-ulu-theme-toggle-icon",
|
|
16
|
+
toggleLabel: "data-ulu-theme-toggle-label",
|
|
17
|
+
toggleRemote: "data-ulu-theme-toggle-remote",
|
|
18
|
+
state: "data-ulu-theme-toggle-state",
|
|
10
19
|
};
|
|
11
20
|
|
|
21
|
+
// Utils for selecting things based on attributes
|
|
12
22
|
const attrSelector = key => `[${ attrs[key] }]`;
|
|
13
23
|
const attrSelectorInitial = key => `${ attrSelector(key) }:not([${ attrs.init }])`;
|
|
24
|
+
const queryAllInitial = key => document.querySelectorAll(attrSelectorInitial(key));
|
|
25
|
+
const queryRemotes = group => document.querySelectorAll(
|
|
26
|
+
`[${ attrs.toggleRemote }="${ group }"]`
|
|
27
|
+
);
|
|
28
|
+
const queryRemotesInitial = group => document.querySelectorAll(
|
|
29
|
+
`[${ attrs.toggleRemote }="${ group }"]:not([${ attrs.init }])`
|
|
30
|
+
);
|
|
31
|
+
const debugLog = (...msgs) => console.log("Theme Toggle:", ...msgs);
|
|
32
|
+
const requiredToggleProps = ["target"];
|
|
33
|
+
const checkToggleProps = hasRequiredProps(requiredToggleProps);
|
|
34
|
+
const when = (cond, fn) => cond ? fn() : null; // Consider adding as util
|
|
14
35
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Default Options
|
|
38
|
+
* - Can be overridden using data-attributes
|
|
39
|
+
*/
|
|
40
|
+
export const defaults = {
|
|
41
|
+
/**
|
|
42
|
+
* Object of each theme that should be toggle/cycled through
|
|
43
|
+
*/
|
|
44
|
+
themes: {
|
|
45
|
+
light: {
|
|
46
|
+
label: "Light",
|
|
47
|
+
value: "light",
|
|
48
|
+
iconClass: "fas fa-moon",
|
|
49
|
+
targetClass: "theme-light",
|
|
50
|
+
mediaQuery: "(prefers-color-scheme: light)"
|
|
51
|
+
},
|
|
52
|
+
dark: {
|
|
53
|
+
label: "Dark",
|
|
54
|
+
iconClass: "fas fa-sun",
|
|
55
|
+
targetClass: "theme-dark",
|
|
56
|
+
mediaQuery: "(prefers-color-scheme: dark)"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* Required this is the element(s) that should be changed by a specific toggle
|
|
61
|
+
* - The element should have data-ulu-theme-toggle-target="SOME_IDENTIFIER"
|
|
62
|
+
*/
|
|
63
|
+
target: "body",
|
|
64
|
+
/**
|
|
65
|
+
* Optional group to link remote toggles (toggles that follow the main one and can toggle too)
|
|
66
|
+
*/
|
|
67
|
+
group: null,
|
|
68
|
+
/**
|
|
69
|
+
* Optional callback to do something when the state changes
|
|
70
|
+
*/
|
|
71
|
+
onChange(_ctx) {},
|
|
72
|
+
/**
|
|
73
|
+
* The initial state for this component
|
|
74
|
+
* - May be overridden by saved preference or media query if options are enabled
|
|
75
|
+
*/
|
|
76
|
+
initialState: "light",
|
|
77
|
+
/**
|
|
78
|
+
* Check the OS systems user preference via 'preferenceQuery' option
|
|
79
|
+
*/
|
|
80
|
+
checkMediaQuery: false,
|
|
81
|
+
/**
|
|
82
|
+
* Will store the preference in local storage so it persists between page loads
|
|
83
|
+
*/
|
|
84
|
+
savePreference: false,
|
|
85
|
+
/**
|
|
86
|
+
* The key that will be used to store the preference in local storage
|
|
87
|
+
* - This will be used as prefix in combination with group if defined
|
|
88
|
+
*/
|
|
89
|
+
storagePrefix: "ulu-theme-",
|
|
90
|
+
/**
|
|
91
|
+
* Output information to console for debugging
|
|
92
|
+
*/
|
|
93
|
+
debug: false
|
|
23
94
|
};
|
|
24
95
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
96
|
+
|
|
97
|
+
// Current default objects (user can override these)
|
|
98
|
+
let currentDefaults = { ...defaults };
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {Object} options Change options used as default for dialogs, can then be overridden by data attribute settings on element
|
|
102
|
+
*/
|
|
103
|
+
export function setDefaults(options) {
|
|
104
|
+
currentDefaults = Object.assign({}, currentDefaults, options);
|
|
105
|
+
}
|
|
29
106
|
|
|
30
107
|
/**
|
|
31
108
|
* Initialize everything in document
|
|
32
109
|
* - This will only initialize elements once, it is safe to call on page changes
|
|
33
110
|
*/
|
|
34
111
|
export function init() {
|
|
35
|
-
|
|
36
|
-
document.addEventListener(getName("beforePrint"), () => printSetup());
|
|
37
|
-
// switch back to original theme after printing
|
|
38
|
-
document.addEventListener(getName("afterPrint"), () => printTearDown());
|
|
39
|
-
// document.addEventListener(getName("pageModified"), () => setup());
|
|
112
|
+
document.addEventListener(getName("pageModified"), setup);
|
|
40
113
|
setup();
|
|
41
114
|
}
|
|
42
115
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Query and setup all
|
|
118
|
+
*/
|
|
119
|
+
export function setup() {
|
|
120
|
+
queryAllInitial("toggle").forEach(setupToggle);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sets up a single toggle
|
|
125
|
+
* @param {HTMLElement} toggle A toggle to be setup
|
|
126
|
+
*/
|
|
127
|
+
export function setupToggle(toggle, passedOptions) {
|
|
128
|
+
const elementOptions = getDatasetJson(toggle, "uluThemeToggle");
|
|
129
|
+
const options = Object.assign({}, defaults, passedOptions, elementOptions);
|
|
130
|
+
|
|
131
|
+
if (!checkToggleProps(options)) {
|
|
132
|
+
console.error(`Missing a required option: ${ requiredToggleProps.join(", ") }`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const group = options.group;
|
|
137
|
+
const ctx = { toggle, options };
|
|
138
|
+
const initialKey = resolveInitial(options);
|
|
139
|
+
|
|
140
|
+
if (!initialKey) {
|
|
141
|
+
console.error("Unable to resolve initial key");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setState(initialKey, ctx);
|
|
146
|
+
|
|
147
|
+
toggle.addEventListener("click", onToggleClick);
|
|
148
|
+
toggle.setAttribute(attrs.init, "");
|
|
149
|
+
|
|
150
|
+
// Remotes listeners are attached initially and then we also
|
|
151
|
+
// update them vs toggles which would be updated by the main pageModified
|
|
152
|
+
// event in init
|
|
153
|
+
attachRemotes();
|
|
154
|
+
document.addEventListener(getName("pageModified"), attachRemotes);
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Instance function to get the next theme in cycle
|
|
158
|
+
*/
|
|
159
|
+
function toggleState(event) {
|
|
160
|
+
const targets = getElements(options.target);
|
|
161
|
+
const lastKey = targets[0].dataset.uluThemeToggleState;
|
|
162
|
+
const key = getNextThemeKey(lastKey, options);
|
|
163
|
+
if (!key) {
|
|
164
|
+
console.error("Issue getting next theme key");
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
setState(key, { ...ctx, event });
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Handler for click for both toggle and remote toggles
|
|
172
|
+
*/
|
|
173
|
+
function onToggleClick(event) {
|
|
174
|
+
toggleState(event);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Utility to attach remote handlers
|
|
179
|
+
* - Used initially and when page is modified
|
|
180
|
+
*/
|
|
181
|
+
function attachRemotes() {
|
|
182
|
+
if (!group) return;
|
|
183
|
+
const remotes = queryRemotesInitial(group);
|
|
184
|
+
remotes.forEach(remote => {
|
|
185
|
+
remote.addEventListener("click", onToggleClick);
|
|
186
|
+
remote.setAttribute(attrs.init, "");
|
|
54
187
|
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* This only cleans up remotes that are still in DOM
|
|
192
|
+
* - For ones that have been removed we don't store any references to them
|
|
193
|
+
*/
|
|
194
|
+
function cleanupRemotes() {
|
|
195
|
+
if (!group) return;
|
|
196
|
+
const remotes = queryRemotesInitial(group);
|
|
197
|
+
remotes.forEach(remote => {
|
|
198
|
+
remote.removeEventListener("click", onToggleClick);
|
|
199
|
+
remote.removeAttribute(attrs.init, "");
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Function to cleanup listeners and remove init attributes
|
|
205
|
+
*/
|
|
206
|
+
function destroy() {
|
|
207
|
+
toggle.removeEventListener("click", onToggleClick);
|
|
208
|
+
toggle.removeAttribute(attrs.init, "");
|
|
209
|
+
cleanupRemotes();
|
|
210
|
+
document.removeEventListener(getName("pageModified"), attachRemotes);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
destroy,
|
|
215
|
+
toggle,
|
|
216
|
+
options,
|
|
217
|
+
toggleState,
|
|
218
|
+
setState(themeKey) {
|
|
219
|
+
setState(themeKey, ctx);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
58
222
|
}
|
|
59
223
|
|
|
224
|
+
|
|
225
|
+
|
|
60
226
|
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {Element} body Sets up initial theme on load based on user preference.
|
|
227
|
+
* Change the state of target/toggle
|
|
63
228
|
*/
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
229
|
+
function setState(key, ctx) {
|
|
230
|
+
if (!key) {
|
|
231
|
+
console.error("Missing key");
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const { toggle, options } = ctx;
|
|
236
|
+
const { themes, group } = options;
|
|
237
|
+
const elements = {
|
|
238
|
+
targets: getElements(options.target),
|
|
239
|
+
toggles: [toggle, ...(group ? queryRemotes(group) : [])]
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
if (!elements.targets.length || !elements.toggles.length) {
|
|
243
|
+
console.error("Issue setting state, couldn't find needed elements", elements);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const theme = themes[key];
|
|
248
|
+
const otherThemes = getOtherThemes(key, themes);
|
|
249
|
+
const stateCtx = {
|
|
250
|
+
...ctx,
|
|
251
|
+
key,
|
|
252
|
+
elements,
|
|
253
|
+
theme,
|
|
254
|
+
otherThemes
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
if (options.debug) {
|
|
258
|
+
debugLog("set state context", stateCtx);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Prepare classes to remove
|
|
262
|
+
const otherTargetClasses = concatThemeClasses(otherThemes, "targetClass");
|
|
263
|
+
const otherIconClasses = concatThemeClasses(otherThemes, "iconClass");
|
|
264
|
+
|
|
265
|
+
// Update all targets
|
|
266
|
+
elements.targets.forEach(element => {
|
|
267
|
+
element.setAttribute(attrs.state, key);
|
|
268
|
+
element.classList.remove(...otherTargetClasses);
|
|
269
|
+
element.classList.add(...resolveClasses(theme.targetClass));
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// Update all toggles and inner children
|
|
273
|
+
elements.toggles.forEach(element => {
|
|
274
|
+
const label = element.querySelector(attrSelector("toggleLabel"));
|
|
275
|
+
const icon = element.querySelector(attrSelector("toggleIcon"));
|
|
276
|
+
if (label) {
|
|
277
|
+
label.textContent = theme.label;
|
|
278
|
+
}
|
|
279
|
+
if (icon) {
|
|
280
|
+
icon.classList.remove(...otherIconClasses);
|
|
281
|
+
icon.classList.add(...resolveClasses(theme.iconClass));
|
|
282
|
+
}
|
|
283
|
+
element.setAttribute(attrs.state, key);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
// Optional callback if user want to set other things (ie. data-theme or something)
|
|
287
|
+
if (options.onChange) {
|
|
288
|
+
options.onChange(stateCtx);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (options.savePreference) {
|
|
292
|
+
localStorage.setItem(getStorageKey(options), key);
|
|
293
|
+
}
|
|
74
294
|
}
|
|
75
295
|
|
|
76
296
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
297
|
+
* Function determines what the initial state is
|
|
298
|
+
* - Check OS preference, saved preference, or initialState depending on options
|
|
299
|
+
* @return {String} The resolved initial theme's key
|
|
79
300
|
*/
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
301
|
+
function resolveInitial(options) {
|
|
302
|
+
const { savePreference, checkMediaQuery, themes, initialState } = options;
|
|
303
|
+
const storageKey = getStorageKey(options);
|
|
304
|
+
const saved = when(savePreference, () => localStorage.getItem(storageKey));
|
|
305
|
+
const mediaQueryPreference = when(checkMediaQuery, () => getMatchingThemeQuery(themes));
|
|
306
|
+
const resolved = saved || mediaQueryPreference || initialState;
|
|
307
|
+
|
|
308
|
+
if (options.debug) {
|
|
309
|
+
debugLog("Preference Saved:", saved);
|
|
310
|
+
debugLog("Media Query Preference:", mediaQueryPreference);
|
|
311
|
+
debugLog("Initial State:", initialState);
|
|
89
312
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
313
|
+
|
|
314
|
+
if (!resolved) {
|
|
315
|
+
console.error("Failed to resolve initial theme (pass 'initialState' to options)");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return resolved;
|
|
95
319
|
}
|
|
96
320
|
|
|
97
321
|
/**
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
100
|
-
* @param {Element} context Used to find the icons.
|
|
322
|
+
* Check each theme for a matching media query
|
|
323
|
+
* @return {String} Matching theme key
|
|
101
324
|
*/
|
|
102
|
-
function
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
icon.classList = options.darkIcon;
|
|
107
|
-
} else {
|
|
108
|
-
icon.classList = options.lightIcon;
|
|
325
|
+
function getMatchingThemeQuery(themes) {
|
|
326
|
+
const found = Object.entries(themes).find(([_key, theme]) => {
|
|
327
|
+
if (theme.mediaQuery) {
|
|
328
|
+
return window.matchMedia(theme.mediaQuery).matches;
|
|
109
329
|
}
|
|
110
330
|
});
|
|
331
|
+
// Return just the key
|
|
332
|
+
return found ? found[0] : null;
|
|
111
333
|
}
|
|
112
334
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
335
|
+
/**
|
|
336
|
+
* Get the next key in the themes based on the currentKey
|
|
337
|
+
*/
|
|
338
|
+
function getNextThemeKey(activeKey, options) {
|
|
339
|
+
const { themes } = options;
|
|
340
|
+
const keys = Object.keys(themes);
|
|
341
|
+
const index = keys.findIndex(theme => theme === activeKey);
|
|
342
|
+
// If not found return first, else calculate next index (wrapping)
|
|
343
|
+
const nextIndex = index === -1 ? 0 : (index + 1) % keys.length;
|
|
344
|
+
return keys[nextIndex];
|
|
120
345
|
}
|
|
121
346
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
347
|
+
/**
|
|
348
|
+
* Get all other theme object except the current
|
|
349
|
+
*/
|
|
350
|
+
function getOtherThemes(currentKey, themes) {
|
|
351
|
+
const all = Object.entries(themes);
|
|
352
|
+
return all.filter(([key]) => key !== currentKey).map(([_key, value]) => value);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Concatenates multiple class properties into one array
|
|
357
|
+
*/
|
|
358
|
+
function concatThemeClasses(themes, property) {
|
|
359
|
+
return themes.reduce((acc, theme) => {
|
|
360
|
+
return acc.concat(resolveClasses(theme[property]));
|
|
361
|
+
}, []);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Creates the storage key (either prefix or prefix with group name)
|
|
366
|
+
*/
|
|
367
|
+
function getStorageKey(options) {
|
|
368
|
+
const { storagePrefix, group } = options;
|
|
369
|
+
return group ? `${ storagePrefix }${ group }` : storagePrefix;
|
|
129
370
|
}
|
package/js/utils/dom.js
CHANGED
|
@@ -98,6 +98,7 @@ export function setPositionClasses(parent, classes = {
|
|
|
98
98
|
* Resolve a target to Element
|
|
99
99
|
* @param {String|Node} target The selector or node/element
|
|
100
100
|
* @param {Object} context [document] The context to query possible selectors from
|
|
101
|
+
* @return {HTMLElement} The element or null if not found
|
|
101
102
|
*/
|
|
102
103
|
export function getElement(target, context = document) {
|
|
103
104
|
if (typeof target === "string") {
|
|
@@ -105,11 +106,52 @@ export function getElement(target, context = document) {
|
|
|
105
106
|
} else if (target instanceof Element) {
|
|
106
107
|
return target;
|
|
107
108
|
} else {
|
|
108
|
-
console.warn("
|
|
109
|
+
console.warn("getElement: Invalid target type (expected String/Node)", target);
|
|
109
110
|
return null;
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Resolve a target to Elements
|
|
116
|
+
* @param {String|Node} target The selector or node/element
|
|
117
|
+
* @param {Object} context [document] The context to query possible selectors from
|
|
118
|
+
* @return {Array} The elements or null if not found
|
|
119
|
+
*/
|
|
120
|
+
export function getElements(target, context = document) {
|
|
121
|
+
if (typeof target === "string") {
|
|
122
|
+
return [...context.querySelectorAll(target)];
|
|
123
|
+
} else if (target instanceof Element) {
|
|
124
|
+
return [target];
|
|
125
|
+
} else if (Array.isArray(target) || target instanceof NodeList) {
|
|
126
|
+
return [...target];
|
|
127
|
+
} else {
|
|
128
|
+
console.warn("getElement: Invalid target type (expected String/Node/Array/Node List)", target);
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Resolves a class input (string or array) into a consistent array of class names.
|
|
135
|
+
* @param {string|string[]} input - The class input, which can be a string, an array of strings, or any other value.
|
|
136
|
+
* @returns {string[]} An array of class names. Returns an empty array for invalid or falsy input.
|
|
137
|
+
* @example
|
|
138
|
+
* resolveClassArray("fas fa-check my-class"); // Returns ["fas", "fa-check", "my-class"]
|
|
139
|
+
* resolveClassArray(["another-class", "yet-another-class"]); // Returns ["another-class", "yet-another-class"]
|
|
140
|
+
* resolveClassArray("single-class"); // Returns ["single-class"]
|
|
141
|
+
*/
|
|
142
|
+
export function resolveClasses(classes) {
|
|
143
|
+
if (typeof classes === "string") {
|
|
144
|
+
return classes.split(" ").filter(c => c !== ""); // Split and remove empty strings
|
|
145
|
+
} else if (Array.isArray(classes)) {
|
|
146
|
+
return classes;
|
|
147
|
+
} else if (!classes) {
|
|
148
|
+
return [];
|
|
149
|
+
} else {
|
|
150
|
+
console.warn("resolveClassArray: Invalid class input type.", classes);
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
113
155
|
/**
|
|
114
156
|
* Sets a CSS custom property equal to the scrollbar width
|
|
115
157
|
* @param {Node} element The element that is the child of a scrollabel container
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module settings
|
|
3
|
+
* @description Utility module for setting up Font Awesome
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { updateSettings } from "../settings.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sets icon settings to Font Awesome icons
|
|
10
|
+
*/
|
|
11
|
+
export function configureIcons() {
|
|
12
|
+
updateSettings({
|
|
13
|
+
iconClassClose: "fas fa-xmark",
|
|
14
|
+
iconClassDragX: "fas fa-solid fa-grip-lines-vertical",
|
|
15
|
+
iconClassPrevious: "fas fa-solid fa-chevron-left",
|
|
16
|
+
iconClassNext: "fas fa-solid fa-chevron-right"
|
|
17
|
+
});
|
|
18
|
+
}
|
package/js/utils/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export * as floatingUi from "./floating-ui.js";
|
|
|
4
4
|
export * as id from "./id.js";
|
|
5
5
|
export * as index from "./index.js";
|
|
6
6
|
export * as pauseYoutubeVideo from "./pause-youtube-video.js";
|
|
7
|
-
export * as fileSave from "./file-save.js";
|
|
7
|
+
export * as fileSave from "./file-save.js";
|
|
8
|
+
export * as fontAwesome from "./font-awesome.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ulu/frontend",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.31",
|
|
4
4
|
"description": "Modular Sass Theming Library",
|
|
5
5
|
"browser": "js/index.js",
|
|
6
6
|
"main": "index.js",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"docs:build:prod": "IS_PRODUCTION=true npx @11ty/eleventy --config=docs.eleventy.js",
|
|
31
31
|
"docs:assets": "vite --config docs.vite.config.js --force",
|
|
32
32
|
"docs:assets:build": "vite build --config docs.vite.config.js",
|
|
33
|
-
"docs:assets:build:prod": "IS_PRODUCTION=true vite build --config docs.vite.config.js"
|
|
33
|
+
"docs:assets:build:prod": "IS_PRODUCTION=true vite build --config docs.vite.config.js",
|
|
34
|
+
"deploy": "npm run build && npm run types && npm run docs:build:prod && npm run docs:assets:build:prod",
|
|
35
|
+
"deploy:docs": "npm run docs:build:prod && npm run docs:assets:build:prod"
|
|
34
36
|
},
|
|
35
37
|
"repository": {
|
|
36
38
|
"type": "git",
|
|
@@ -66,6 +68,7 @@
|
|
|
66
68
|
"@ulu/vitepress-auto-menus": "^0.0.3",
|
|
67
69
|
"@ulu/vitepress-sassdoc": "^0.0.9",
|
|
68
70
|
"algoliasearch": "^4.23.3",
|
|
71
|
+
"autoprefixer": "^10.4.16",
|
|
69
72
|
"chokidar": "^3.6.0",
|
|
70
73
|
"eleventy-plugin-nesting-toc": "^1.3.0",
|
|
71
74
|
"fs-extra": "^11.2.0",
|
|
@@ -78,14 +81,14 @@
|
|
|
78
81
|
"sass-embedded": "^1.81.0",
|
|
79
82
|
"sharp": "^0.33.4",
|
|
80
83
|
"svgo": "^3.3.2",
|
|
84
|
+
"twig": "^1.17.1",
|
|
81
85
|
"typescript": "^5.3.3",
|
|
82
|
-
"autoprefixer": "^10.4.16",
|
|
83
86
|
"vite": "^5.4.11"
|
|
84
87
|
},
|
|
85
88
|
"dependencies": {
|
|
86
|
-
"@
|
|
89
|
+
"@floating-ui/dom": "^1.6.5",
|
|
90
|
+
"@ulu/utils": "^0.0.20",
|
|
87
91
|
"ally.js": "^1.4.1",
|
|
88
|
-
"aria-tablist": "^1.2.2"
|
|
89
|
-
"@floating-ui/dom": "^1.6.5"
|
|
92
|
+
"aria-tablist": "^1.2.2"
|
|
90
93
|
}
|
|
91
94
|
}
|
package/scss/_color.scss
CHANGED
|
@@ -23,10 +23,17 @@ $palette: (
|
|
|
23
23
|
"type-tertiary" : rgb(157, 157, 157),
|
|
24
24
|
"headline" : inherit,
|
|
25
25
|
"background" : white,
|
|
26
|
+
"background-gray" : #F7F8F7,
|
|
26
27
|
"focus" : blue,
|
|
27
|
-
"error" : red,
|
|
28
|
-
"warning" : orange,
|
|
29
28
|
"accent" : orange,
|
|
29
|
+
"info" : #00bde3,
|
|
30
|
+
"success" : #00a91c,
|
|
31
|
+
"warning" : #ffbe2e,
|
|
32
|
+
"danger" : #d54309,
|
|
33
|
+
"info-background" : #e7f6f8,
|
|
34
|
+
"success-background" : #ecf3ec,
|
|
35
|
+
"warning-background" : #faf3d1,
|
|
36
|
+
"danger-background" : #f4e3db,
|
|
30
37
|
"selected" : green,
|
|
31
38
|
"box-shadow" : rgba(0, 0, 0, 0.349),
|
|
32
39
|
"box-shadow-hover" : rgba(0, 0, 0, 0.5),
|
package/scss/_layout.scss
CHANGED
|
@@ -215,10 +215,7 @@ $containers: (
|
|
|
215
215
|
$breakpoints: map.get($container, "breakpoints");
|
|
216
216
|
|
|
217
217
|
$width: map.get($container, "width");
|
|
218
|
-
|
|
219
|
-
// @if $specific-breakpoint {
|
|
220
|
-
// @debug $container;
|
|
221
|
-
// }
|
|
218
|
+
|
|
222
219
|
@if ($width == null) {
|
|
223
220
|
$width: 100%;
|
|
224
221
|
}
|