focus.mjs 852 B

12345678910111213141516171819202122232425262728293031
  1. // Composables
  2. import { useProxiedModel } from "./proxiedModel.mjs"; // Utilities
  3. import { computed } from 'vue';
  4. import { EventProp, getCurrentInstanceName, propsFactory } from "../util/index.mjs"; // Types
  5. // Composables
  6. export const makeFocusProps = propsFactory({
  7. focused: Boolean,
  8. 'onUpdate:focused': EventProp()
  9. }, 'focus');
  10. export function useFocus(props) {
  11. let name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getCurrentInstanceName();
  12. const isFocused = useProxiedModel(props, 'focused');
  13. const focusClasses = computed(() => {
  14. return {
  15. [`${name}--focused`]: isFocused.value
  16. };
  17. });
  18. function focus() {
  19. isFocused.value = true;
  20. }
  21. function blur() {
  22. isFocused.value = false;
  23. }
  24. return {
  25. focusClasses,
  26. isFocused,
  27. focus,
  28. blur
  29. };
  30. }
  31. //# sourceMappingURL=focus.mjs.map