Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

groupable.ts 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Mixins
  2. import { Registrable, inject as RegistrableInject } from './registrable'
  3. // Utilities
  4. import { ExtractVue } from '../util/mixins'
  5. import { PropValidator } from 'vue/types/options'
  6. import { VueConstructor } from 'vue'
  7. /* eslint-disable-next-line no-use-before-define */
  8. export type Groupable<T extends string> = VueConstructor<ExtractVue<Registrable<T>> & {
  9. activeClass: string
  10. isActive: boolean
  11. groupClasses: object
  12. toggle (): void
  13. }>
  14. export function factory<T extends string> (
  15. namespace: T,
  16. child?: string,
  17. parent?: string
  18. ): Groupable<T> {
  19. return RegistrableInject(namespace, child, parent).extend({
  20. name: 'groupable',
  21. props: {
  22. activeClass: {
  23. type: String,
  24. default (): string | undefined {
  25. if (!this[namespace]) return undefined
  26. return this[namespace].activeClass
  27. }
  28. } as any as PropValidator<string>,
  29. disabled: Boolean
  30. },
  31. data () {
  32. return {
  33. isActive: false
  34. }
  35. },
  36. computed: {
  37. groupClasses (): object {
  38. if (!this.activeClass) return {}
  39. return {
  40. [this.activeClass]: this.isActive
  41. }
  42. }
  43. },
  44. created () {
  45. this[namespace] && (this[namespace] as any).register(this)
  46. },
  47. beforeDestroy () {
  48. this[namespace] && (this[namespace] as any).unregister(this)
  49. },
  50. methods: {
  51. toggle () {
  52. this.$emit('change')
  53. }
  54. }
  55. })
  56. }
  57. /* eslint-disable-next-line no-redeclare */
  58. const Groupable = factory('itemGroup')
  59. export default Groupable