Advertisement
kauffman12

q-control-label

Jan 16th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 2.51 KB | Source Code | 0 0
  1. import { type DirectiveBinding } from 'vue';
  2. import { nextTick } from 'vue';
  3.  
  4. // src/directives/log.js
  5. export default {
  6.   mounted(el: HTMLElement, binding: DirectiveBinding) {
  7.     console.log('Directive bound to:', el);
  8.     const labelElement = el.querySelector('.q-field__label');
  9.     console.log('Label text:', labelElement?.textContent);
  10.     const labelText = labelElement?.textContent ?? 'Bleh';
  11.    
  12.     if (binding.value) {
  13.       console.log('test')
  14.     }
  15.    
  16.     const control = el.querySelector('.q-field__control');
  17.     if (!control) {
  18.       return;
  19.     }
  20.    
  21.     const wrapper = document.createElement('div');
  22.     wrapper.id = 'test';
  23.     wrapper.style.display = 'flex';
  24.     wrapper.style.position = 'absolute';
  25.     wrapper.style.height = '100%';
  26.     wrapper.style.width = '100%';
  27.  
  28.     const leftDiv = document.createElement('div');
  29.     const middleDiv = document.createElement('div');
  30.     const rightDiv = document.createElement('div');
  31.  
  32.     leftDiv.style.display = 'flex';
  33.     leftDiv.style.height = '100%';
  34.     leftDiv.style.width = '12px';
  35.     leftDiv.style.borderLeft = '1px solid black';
  36.     leftDiv.style.borderTop = '1px solid black';
  37.     leftDiv.style.borderBottom = '1px solid black';
  38.     leftDiv.style.borderRadius = '3px 0px 0px 3px';
  39.    
  40.     middleDiv.style.height = '100%';
  41.     middleDiv.style.width = '100%';
  42.     middleDiv.style.borderBottom = '1px solid black';
  43.  
  44.     rightDiv.style.display = 'flex';
  45.     rightDiv.style.flex = '1';
  46.     rightDiv.style.height = '100%';
  47.     rightDiv.style.borderRight = '1px solid black';
  48.     rightDiv.style.borderTop = '1px solid black';
  49.     rightDiv.style.borderBottom = '1px solid black';
  50.     rightDiv.style.borderRadius = '0px 3px 3px 0px';
  51.  
  52.     // Insert a hidden label into the middle div
  53.     const hiddenLabel = document.createElement('span');
  54.     hiddenLabel.textContent = labelText;
  55.     hiddenLabel.style.visibility = 'hidden';
  56.     hiddenLabel.style.whiteSpace = 'nowrap'; // Ensure it doesn't wrap
  57.     hiddenLabel.style.position = 'absolute'; // Remove it from layout flow
  58.     hiddenLabel.style.overflow = 'hidden';
  59.     hiddenLabel.style.textOverflow = 'ellipsis';
  60.     middleDiv.appendChild(hiddenLabel);
  61.  
  62.     // Add all parts to the wrapper
  63.     wrapper.appendChild(leftDiv);
  64.     wrapper.appendChild(middleDiv);
  65.     wrapper.appendChild(rightDiv);
  66.     // Insert the wrapper into the DOM
  67.     control.appendChild(wrapper);
  68.    
  69.     void nextTick(() => {
  70.       middleDiv.style.flex = `0 0 ${hiddenLabel.offsetWidth}px`;
  71.     });
  72.   },
  73. };
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement