kmaterialize 2.3.3-1.0.11 → 2.3.3-1.0.12

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.
@@ -0,0 +1,176 @@
1
+ @use '../../sass/variables' as *;
2
+
3
+ // @implement /Users/kzarshenas/Sites/RodeoFx/rodeo_toolkit_2/app/Front/style/scss/partial/_planning_toolbar.scss
4
+ // A rounded "pill" action bar: a full-width flex row split into groups
5
+ // (buttons, a segmented "track" control, an expandable search field) laid
6
+ // out with space-between, sitting inline above the content it controls -
7
+ // not fixed/sticky, just a normal flex row like the source component.
8
+ //
9
+ // :not(.fixed-action-btn) - "toolbar" is already a FAB display mode
10
+ // (.fixed-action-btn.toolbar, see components/button/_buttons.scss); this
11
+ // guards against also painting pill styles onto that unrelated element.
12
+ .toolbar:not(.fixed-action-btn) {
13
+ display: flex;
14
+ align-items: center;
15
+ justify-content: space-between;
16
+ width: 100%;
17
+ gap: 8px;
18
+ padding: 5px 8px;
19
+ margin: $element-top-margin 0 $element-bottom-margin 0;
20
+ border-radius: 27px;
21
+ background-color: var(--md-sys-color-surface-variant);
22
+ }
23
+
24
+ // A cluster of controls inside the toolbar (buttons, a track, a search
25
+ // field, ...) kept together and spaced from the next group.
26
+ .toolbar-group {
27
+ display: flex;
28
+ align-items: center;
29
+ gap: 5px;
30
+ }
31
+
32
+ /// Track (segmented control)
33
+ ///////////////////////////////////////////////////////
34
+ ///
35
+
36
+ // A pill-shaped segmented control - e.g. "Today / Previous / Next" or a
37
+ // "Week / Month / Year" range picker - with a sliding highlight behind
38
+ // whichever item is active.
39
+ .toolbar-track {
40
+ position: relative;
41
+ display: inline-flex;
42
+ align-items: center;
43
+ height: 34px;
44
+ padding: 3px;
45
+ border-radius: 999px;
46
+ background-color: var(--md-sys-color-surface);
47
+ border: 1px solid var(--md-sys-color-outline-variant);
48
+ }
49
+
50
+ // A track with no background/border of its own - just for spacing a group
51
+ // of items that don't need the pill-within-a-pill look.
52
+ .toolbar-track.toolbar-track-bare {
53
+ padding: 3px 0;
54
+ background-color: transparent;
55
+ border-color: transparent;
56
+ }
57
+
58
+ // Positioned/sized by Toolbar's JS (offsetLeft/offsetWidth of the active
59
+ // .toolbar-track-item), not by CSS - the transition below is what makes
60
+ // that JS-driven move/resize animate instead of jumping.
61
+ .toolbar-track-indicator {
62
+ position: absolute;
63
+ top: 3px;
64
+ bottom: 3px;
65
+ left: 0;
66
+ z-index: 0;
67
+ width: 0;
68
+ border-radius: 999px;
69
+ background-color: var(--md-sys-color-primary);
70
+ opacity: 0;
71
+ pointer-events: none;
72
+ transition: transform .22s cubic-bezier(.2, .7, .3, 1), width .22s cubic-bezier(.2, .7, .3, 1), opacity .14s ease;
73
+
74
+ // Only fade in once Toolbar's JS has measured and placed it for the
75
+ // first time - otherwise it flashes at 0 width in the top-left corner
76
+ // for a frame before the first real position is set.
77
+ .toolbar-track.is-armed & {
78
+ opacity: 1;
79
+ }
80
+ }
81
+
82
+ .toolbar-track-item {
83
+ position: relative;
84
+ z-index: 1;
85
+ display: inline-flex;
86
+ align-items: center;
87
+ height: 28px;
88
+ padding: 0 13px;
89
+ border: 0;
90
+ border-radius: 999px;
91
+ background-color: transparent;
92
+ color: var(--md-sys-color-on-surface-variant);
93
+ font-size: 12.5px;
94
+ line-height: 1;
95
+ white-space: nowrap;
96
+ cursor: pointer;
97
+ transition: color .16s ease;
98
+
99
+ &:hover {
100
+ color: var(--md-sys-color-on-surface);
101
+ }
102
+ &.is-active {
103
+ font-weight: 600;
104
+ color: var(--md-sys-color-on-primary);
105
+ }
106
+ &:focus-visible {
107
+ outline: 2px solid var(--md-sys-color-primary);
108
+ outline-offset: 2px;
109
+ }
110
+ }
111
+
112
+ /// Expandable search
113
+ ///////////////////////////////////////////////////////
114
+ ///
115
+
116
+ // A search field that starts as just an icon button and expands into a
117
+ // full text input once focused (or once it has a value) - Toolbar's JS
118
+ // toggles the .is-expanded class.
119
+ .toolbar-search {
120
+ display: inline-flex;
121
+ align-items: center;
122
+ width: 34px;
123
+ height: 34px;
124
+ padding: 2px;
125
+ overflow: hidden;
126
+ border-radius: 999px;
127
+ background-color: var(--md-sys-color-surface);
128
+ border: 1px solid var(--md-sys-color-outline-variant);
129
+ transition: width .2s cubic-bezier(.2, .7, .3, 1);
130
+
131
+ &.is-expanded {
132
+ width: 190px;
133
+ }
134
+
135
+ .toolbar-search-toggle {
136
+ display: inline-flex;
137
+ flex: 0 0 28px;
138
+ align-items: center;
139
+ justify-content: center;
140
+ width: 28px;
141
+ height: 28px;
142
+ padding: 0;
143
+ border: 0;
144
+ border-radius: 50%;
145
+ background-color: transparent;
146
+ color: var(--md-sys-color-on-surface-variant);
147
+ cursor: pointer;
148
+ }
149
+
150
+ .toolbar-search-input {
151
+ width: 0;
152
+ min-width: 0;
153
+ height: 28px;
154
+ margin: 0;
155
+ padding: 0;
156
+ border: 0;
157
+ outline: 0;
158
+ background-color: transparent;
159
+ color: var(--md-sys-color-on-surface);
160
+ font-size: 12px;
161
+ opacity: 0;
162
+ transition: opacity .12s ease;
163
+ }
164
+
165
+ &.is-expanded .toolbar-search-input {
166
+ width: 150px;
167
+ padding-right: 5px;
168
+ opacity: 1;
169
+ }
170
+ }
171
+
172
+ @media (prefers-reduced-motion: reduce) {
173
+ .toolbar-track-indicator {
174
+ transition: opacity .14s ease;
175
+ }
176
+ }
@@ -0,0 +1,137 @@
1
+ import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
2
+
3
+ export interface ToolbarOptions extends BaseOptions {}
4
+
5
+ const _defaults: ToolbarOptions = {};
6
+
7
+ // @implement /Users/kzarshenas/Sites/RodeoFx/rodeo_toolkit_2/app/Environment/Partials/PlanningToolbar.ts
8
+ // Generic version of that file's track-indicator sliding and expandable
9
+ // search behavior, decoupled from the page-specific filter/state-binding
10
+ // system (UtilityFilter) the source used - here it's just plain DOM state.
11
+ export class Toolbar extends Component<ToolbarOptions> {
12
+ _tracks: HTMLElement[];
13
+
14
+ constructor(el: HTMLElement, options: Partial<ToolbarOptions>) {
15
+ super(el, options, Toolbar);
16
+ (this.el as any).M_Toolbar = this;
17
+
18
+ this.options = {
19
+ ...Toolbar.defaults,
20
+ ...options
21
+ };
22
+
23
+ this._tracks = Array.from(this.el.querySelectorAll<HTMLElement>('.toolbar-track'));
24
+ this._setupEventHandlers();
25
+ this._tracks.forEach((track) => this._moveIndicator(track, false));
26
+ }
27
+
28
+ static get defaults(): ToolbarOptions {
29
+ return _defaults;
30
+ }
31
+
32
+ static init(el: HTMLElement, options?: Partial<ToolbarOptions>): Toolbar;
33
+ static init(els: InitElements<MElement>, options?: Partial<ToolbarOptions>): Toolbar[];
34
+ static init(
35
+ els: HTMLElement | InitElements<MElement>,
36
+ options: Partial<ToolbarOptions> = {}
37
+ ): Toolbar | Toolbar[] {
38
+ return super.init(els, options, Toolbar);
39
+ }
40
+
41
+ static getInstance(el: HTMLElement): Toolbar {
42
+ return (el as any).M_Toolbar;
43
+ }
44
+
45
+ destroy() {
46
+ this._removeEventHandlers();
47
+ (this.el as any).M_Toolbar = undefined;
48
+ }
49
+
50
+ /**
51
+ * Re-measure and reposition every track's sliding indicator - call this
52
+ * after changing which .toolbar-track-item is active from your own code,
53
+ * or after anything that could have changed the toolbar's layout/width.
54
+ */
55
+ updateIndicators() {
56
+ this._tracks.forEach((track) => this._moveIndicator(track, true));
57
+ }
58
+
59
+ _setupEventHandlers() {
60
+ this.el.addEventListener('click', this._handleTrackClick);
61
+ this.el.addEventListener('focusin', this._handleSearchFocusIn);
62
+ this.el.addEventListener('focusout', this._handleSearchFocusOut);
63
+ this.el.addEventListener('input', this._handleSearchInput);
64
+ this.el.addEventListener('keydown', this._handleSearchKeydown);
65
+ window.addEventListener('resize', this._handleWindowResize);
66
+ }
67
+
68
+ _removeEventHandlers() {
69
+ this.el.removeEventListener('click', this._handleTrackClick);
70
+ this.el.removeEventListener('focusin', this._handleSearchFocusIn);
71
+ this.el.removeEventListener('focusout', this._handleSearchFocusOut);
72
+ this.el.removeEventListener('input', this._handleSearchInput);
73
+ this.el.removeEventListener('keydown', this._handleSearchKeydown);
74
+ window.removeEventListener('resize', this._handleWindowResize);
75
+ }
76
+
77
+ _handleTrackClick = (e: MouseEvent) => {
78
+ const item = (e.target as HTMLElement).closest('.toolbar-track-item') as HTMLElement;
79
+ if (!item) return;
80
+ const track = item.closest('.toolbar-track') as HTMLElement;
81
+ if (!track || !this._tracks.includes(track)) return;
82
+
83
+ track.querySelectorAll('.toolbar-track-item.is-active').forEach((el) => el.classList.remove('is-active'));
84
+ item.classList.add('is-active');
85
+ this._moveIndicator(track, true);
86
+ };
87
+
88
+ _handleSearchFocusIn = (e: FocusEvent) => {
89
+ const search = (e.target as HTMLElement).closest('.toolbar-search');
90
+ if (search) search.classList.add('is-expanded');
91
+ };
92
+
93
+ _handleSearchFocusOut = (e: FocusEvent) => {
94
+ const search = (e.target as HTMLElement).closest('.toolbar-search');
95
+ if (!search) return;
96
+ const input = search.querySelector<HTMLInputElement>('.toolbar-search-input');
97
+ if (input && input.value === '') search.classList.remove('is-expanded');
98
+ };
99
+
100
+ _handleSearchInput = (e: Event) => {
101
+ const input = e.target as HTMLInputElement;
102
+ if (!input.classList.contains('toolbar-search-input')) return;
103
+ const search = input.closest('.toolbar-search');
104
+ if (search) search.classList.toggle('is-expanded', input.value !== '' || document.activeElement === input);
105
+ };
106
+
107
+ _handleSearchKeydown = (e: KeyboardEvent) => {
108
+ if (e.key !== 'Escape') return;
109
+ const input = (e.target as HTMLElement).closest('.toolbar-search')?.querySelector<HTMLInputElement>('.toolbar-search-input');
110
+ if (!input) return;
111
+ input.value = '';
112
+ input.blur();
113
+ };
114
+
115
+ _handleWindowResize = () => {
116
+ this._tracks.forEach((track) => this._moveIndicator(track, false));
117
+ };
118
+
119
+ _moveIndicator(track: HTMLElement, animate: boolean) {
120
+ const indicator = track.querySelector<HTMLElement>('.toolbar-track-indicator');
121
+ const active = track.querySelector<HTMLElement>('.toolbar-track-item.is-active');
122
+ if (!indicator || !active) return;
123
+
124
+ if (!animate) indicator.style.transition = 'none';
125
+ indicator.style.transform = `translateX(${active.offsetLeft - track.clientLeft}px)`;
126
+ indicator.style.width = `${active.offsetWidth}px`;
127
+ track.classList.add('is-armed');
128
+ if (!animate) {
129
+ // Force layout so the transition-less move above actually applies
130
+ // before re-enabling transitions on the next frame.
131
+ void indicator.offsetWidth;
132
+ requestAnimationFrame(() => {
133
+ indicator.style.transition = '';
134
+ });
135
+ }
136
+ }
137
+ }