index.ts 956 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. import FieldSelectInput from '@common/components/form/field/FieldSelect/FieldSelectInput.vue'
  3. import createInput from '@common/form/core/createInput'
  4. import type { FormKitNode } from '@formkit/core'
  5. const hideLabelForSmallSelects = (node: FormKitNode) => {
  6. const { props } = node
  7. const toggleLabel = (isHidden: boolean) => {
  8. props.labelClass = isHidden ? 'hidden' : undefined
  9. }
  10. node.on('created', () => {
  11. toggleLabel(props.size === 'small')
  12. node.on('prop:size', ({ payload }) => {
  13. toggleLabel(payload === 'small')
  14. })
  15. })
  16. }
  17. const fieldDefinition = createInput(
  18. FieldSelectInput,
  19. [
  20. 'autoselect',
  21. 'clearable',
  22. 'multiple',
  23. 'noOptionsLabelTranslation',
  24. 'options',
  25. 'size',
  26. 'sorting',
  27. ],
  28. {
  29. features: [hideLabelForSmallSelects],
  30. },
  31. )
  32. export default {
  33. fieldType: 'select',
  34. definition: fieldDefinition,
  35. }