@dataloop-ai/components 0.13.0

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.
Files changed (294) hide show
  1. package/.eslintrc.js +154 -0
  2. package/.prettierrc.json +7 -0
  3. package/Dockerfile +12 -0
  4. package/LICENSE +201 -0
  5. package/README.md +43 -0
  6. package/favicon.ico +0 -0
  7. package/index.html +13 -0
  8. package/index.ts +1 -0
  9. package/jest.config.js +16 -0
  10. package/jest.setup.js +59 -0
  11. package/models.ts +1 -0
  12. package/package.json +109 -0
  13. package/src/App.vue +201 -0
  14. package/src/assets/globals.scss +253 -0
  15. package/src/assets/globalsKeys.ts +28 -0
  16. package/src/components/DlAccordion/AccordionHeader.vue +148 -0
  17. package/src/components/DlAccordion/DlAccordion.vue +108 -0
  18. package/src/components/DlAccordion/index.ts +2 -0
  19. package/src/components/DlAlert.vue +227 -0
  20. package/src/components/DlAvatar.vue +99 -0
  21. package/src/components/DlBadge.vue +127 -0
  22. package/src/components/DlButton/DlButton.vue +370 -0
  23. package/src/components/DlButton/index.ts +4 -0
  24. package/src/components/DlButton/utils.ts +169 -0
  25. package/src/components/DlButtonGroup.vue +122 -0
  26. package/src/components/DlCheckbox.vue +298 -0
  27. package/src/components/DlChip/DlChip.vue +244 -0
  28. package/src/components/DlChip/index.ts +4 -0
  29. package/src/components/DlChip/utils.ts +100 -0
  30. package/src/components/DlColorPicker/DlAlpha.vue +142 -0
  31. package/src/components/DlColorPicker/DlBox.vue +75 -0
  32. package/src/components/DlColorPicker/DlColorPicker.vue +306 -0
  33. package/src/components/DlColorPicker/DlColors.vue +139 -0
  34. package/src/components/DlColorPicker/DlHue.vue +135 -0
  35. package/src/components/DlColorPicker/DlPreview.vue +61 -0
  36. package/src/components/DlColorPicker/DlSaturation.vue +152 -0
  37. package/src/components/DlColorPicker/constants.ts +16 -0
  38. package/src/components/DlColorPicker/index.ts +20 -0
  39. package/src/components/DlColorPicker/types.ts +11 -0
  40. package/src/components/DlColorPicker/utils.ts +128 -0
  41. package/src/components/DlCounters.vue +173 -0
  42. package/src/components/DlDatePicker/DlCalendar.vue +332 -0
  43. package/src/components/DlDatePicker/DlDatePicker.vue +315 -0
  44. package/src/components/DlDatePicker/DlMonthCalendar.vue +282 -0
  45. package/src/components/DlDatePicker/classes/Calendar.ts +110 -0
  46. package/src/components/DlDatePicker/classes/CalendarDate.ts +12 -0
  47. package/src/components/DlDatePicker/classes/CustomDate.ts +218 -0
  48. package/src/components/DlDatePicker/index.ts +3 -0
  49. package/src/components/DlDatePicker/isInRange.ts +44 -0
  50. package/src/components/DlDatePicker/types.ts +4 -0
  51. package/src/components/DlDatePicker/utils.ts +39 -0
  52. package/src/components/DlDateTimeRange/DlCardSidebar.vue +109 -0
  53. package/src/components/DlDateTimeRange/DlDateInput.vue +105 -0
  54. package/src/components/DlDateTimeRange/DlDateTimeRange.vue +468 -0
  55. package/src/components/DlDateTimeRange/index.ts +3 -0
  56. package/src/components/DlDateTimeRange/types.ts +42 -0
  57. package/src/components/DlDialogBox/DlDialogBox.vue +196 -0
  58. package/src/components/DlDialogBox/DlDialogBoxFooter.vue +22 -0
  59. package/src/components/DlDialogBox/DlDialogBoxHeader.vue +75 -0
  60. package/src/components/DlDialogBox/index.ts +5 -0
  61. package/src/components/DlDropdownButton.vue +463 -0
  62. package/src/components/DlIcon.vue +147 -0
  63. package/src/components/DlInfoErrorMessage.vue +91 -0
  64. package/src/components/DlItem/DlItem.vue +35 -0
  65. package/src/components/DlItem/index.ts +2 -0
  66. package/src/components/DlItemSection.vue +88 -0
  67. package/src/components/DlLink/DlLink.vue +76 -0
  68. package/src/components/DlLink/index.ts +4 -0
  69. package/src/components/DlLink/utils.ts +4 -0
  70. package/src/components/DlList.vue +61 -0
  71. package/src/components/DlListItem/DlListItem.vue +205 -0
  72. package/src/components/DlListItem/index.ts +3 -0
  73. package/src/components/DlListItem/utils.ts +14 -0
  74. package/src/components/DlMenu/DlMenu.vue +438 -0
  75. package/src/components/DlMenu/index.ts +3 -0
  76. package/src/components/DlMenu/utils.ts +138 -0
  77. package/src/components/DlOptionGroup/DlOptionGroup.vue +201 -0
  78. package/src/components/DlOptionGroup/MenuItemWrapper.vue +48 -0
  79. package/src/components/DlOptionGroup/OptionGroup.types.ts +36 -0
  80. package/src/components/DlOptionGroup/SimpleWrapper.vue +28 -0
  81. package/src/components/DlOptionGroup/index.ts +4 -0
  82. package/src/components/DlOptionGroup/utils.ts +40 -0
  83. package/src/components/DlPagination/DlPagination.vue +184 -0
  84. package/src/components/DlPagination/PageNavigation.vue +350 -0
  85. package/src/components/DlPagination/PaginationLegend.vue +41 -0
  86. package/src/components/DlPagination/QuickNavigation.vue +146 -0
  87. package/src/components/DlPagination/RowsSelector.vue +74 -0
  88. package/src/components/DlPagination/index.ts +3 -0
  89. package/src/components/DlPanelContainer/DlPanel.vue +213 -0
  90. package/src/components/DlPanelContainer/DlPanelContainer.vue +527 -0
  91. package/src/components/DlPanelContainer/index.ts +4 -0
  92. package/src/components/DlPopup/DlPopup.vue +478 -0
  93. package/src/components/DlPopup/DraggableUpper.vue +64 -0
  94. package/src/components/DlPopup/PopupHeader.vue +129 -0
  95. package/src/components/DlPopup/index.ts +1 -0
  96. package/src/components/DlProgressBar.vue +159 -0
  97. package/src/components/DlProgressChart.vue +299 -0
  98. package/src/components/DlRadio.vue +218 -0
  99. package/src/components/DlRange/DlRange.vue +439 -0
  100. package/src/components/DlRange/utils.ts +209 -0
  101. package/src/components/DlSearch.vue +155 -0
  102. package/src/components/DlSelect/DlSelect.vue +992 -0
  103. package/src/components/DlSelect/SelectOption.vue +261 -0
  104. package/src/components/DlSelect/index.ts +4 -0
  105. package/src/components/DlSelect/utils.ts +43 -0
  106. package/src/components/DlSkeleton.vue +72 -0
  107. package/src/components/DlSlider/DlSlider.vue +243 -0
  108. package/src/components/DlSlider/components/DlSliderBase.vue +380 -0
  109. package/src/components/DlSlider/components/DlSliderInput.vue +123 -0
  110. package/src/components/DlSlider/components/index.ts +4 -0
  111. package/src/components/DlSlider/index.ts +3 -0
  112. package/src/components/DlSlider/sliderStyles.scss +109 -0
  113. package/src/components/DlSlider/useSlider.ts +277 -0
  114. package/src/components/DlSlider/utils.ts +7 -0
  115. package/src/components/DlSmartSearch/DlJsonEditor.vue +309 -0
  116. package/src/components/DlSmartSearch/DlSmartSearch.vue +333 -0
  117. package/src/components/DlSmartSearch/DlSmartSearchInput.vue +741 -0
  118. package/src/components/DlSmartSearch/DlSuggestionsDropdown.vue +73 -0
  119. package/src/components/DlSmartSearch/highlightSyntax.ts +169 -0
  120. package/src/components/DlSmartSearch/index.ts +4 -0
  121. package/src/components/DlSmartSearch/types.ts +36 -0
  122. package/src/components/DlSmartSearch/utils.ts +45 -0
  123. package/src/components/DlStepper/DlStepper.vue +196 -0
  124. package/src/components/DlStepper/DlStepperContainer.vue +55 -0
  125. package/src/components/DlStepper/DlStepperContent.vue +101 -0
  126. package/src/components/DlStepper/DlStepperFooter.vue +133 -0
  127. package/src/components/DlStepper/DlStepperHeader.vue +49 -0
  128. package/src/components/DlStepper/DlStepperSidebar.vue +167 -0
  129. package/src/components/DlStepper/Step.ts +101 -0
  130. package/src/components/DlStepper/Stepper.ts +107 -0
  131. package/src/components/DlStepper/index.ts +7 -0
  132. package/src/components/DlStepper/interfaces.ts +11 -0
  133. package/src/components/DlSwitch.vue +280 -0
  134. package/src/components/DlTabPanels/DlTabPanel.vue +22 -0
  135. package/src/components/DlTabPanels/DlTabPanels.vue +41 -0
  136. package/src/components/DlTabPanels/index.ts +4 -0
  137. package/src/components/DlTabPanels/utils.ts +19 -0
  138. package/src/components/DlTable/DlTable.vue +1264 -0
  139. package/src/components/DlTable/DlTd.vue +109 -0
  140. package/src/components/DlTable/DlTh.vue +126 -0
  141. package/src/components/DlTable/DlTr.vue +44 -0
  142. package/src/components/DlTable/ResizableManager.ts +233 -0
  143. package/src/components/DlTable/dl-table-styles.scss +466 -0
  144. package/src/components/DlTable/hooks/tableActions.ts +64 -0
  145. package/src/components/DlTable/hooks/tableColumnSelection.ts +112 -0
  146. package/src/components/DlTable/hooks/tableFilter.ts +42 -0
  147. package/src/components/DlTable/hooks/tablePagination.ts +197 -0
  148. package/src/components/DlTable/hooks/tableRowExpand.ts +55 -0
  149. package/src/components/DlTable/hooks/tableRowSelection.ts +106 -0
  150. package/src/components/DlTable/hooks/tableSort.ts +125 -0
  151. package/src/components/DlTable/index.ts +6 -0
  152. package/src/components/DlTable/types.ts +96 -0
  153. package/src/components/DlTabs/DlTab.vue +146 -0
  154. package/src/components/DlTabs/DlTabs.vue +192 -0
  155. package/src/components/DlTabs/TabsWrapper.vue +104 -0
  156. package/src/components/DlTabs/index.ts +4 -0
  157. package/src/components/DlTabs/types.ts +8 -0
  158. package/src/components/DlTextArea.vue +151 -0
  159. package/src/components/DlTextHolder.vue +65 -0
  160. package/src/components/DlTextInput.vue +753 -0
  161. package/src/components/DlThemeProvider.vue +41 -0
  162. package/src/components/DlTimePicker/DlTimeCounter.vue +81 -0
  163. package/src/components/DlTimePicker/DlTimePicker.vue +151 -0
  164. package/src/components/DlTimePicker/DlTimePickerInput.vue +311 -0
  165. package/src/components/DlTimePicker/index.ts +3 -0
  166. package/src/components/DlTimePicker/types.ts +4 -0
  167. package/src/components/DlTooltip.vue +456 -0
  168. package/src/components/DlTrend.vue +97 -0
  169. package/src/components/DlTypography.vue +87 -0
  170. package/src/components/DlVirtualScroll/DlVirtualScroll.vue +290 -0
  171. package/src/components/DlVirtualScroll/index.ts +3 -0
  172. package/src/components/DlVirtualScroll/useVirtualScroll.ts +833 -0
  173. package/src/components/DlWidget/DlWidget.vue +50 -0
  174. package/src/components/DlWidget/DlWidgetGrid.vue +360 -0
  175. package/src/components/DlWidget/index.ts +4 -0
  176. package/src/components/DlWidget/types.ts +6 -0
  177. package/src/components/DlWidget/utils.ts +30 -0
  178. package/src/components/index.ts +118 -0
  179. package/src/demo/DlAccordionDemo.vue +60 -0
  180. package/src/demo/DlAlertDemo.vue +54 -0
  181. package/src/demo/DlAvatarDemo.vue +43 -0
  182. package/src/demo/DlBadgeDemo.vue +65 -0
  183. package/src/demo/DlButtonDemo.vue +266 -0
  184. package/src/demo/DlCheckboxDemo.vue +50 -0
  185. package/src/demo/DlChipDemo.vue +181 -0
  186. package/src/demo/DlColorPickerDemo.vue +43 -0
  187. package/src/demo/DlCounterDemo.vue +53 -0
  188. package/src/demo/DlDateTimeRangeDemo.vue +217 -0
  189. package/src/demo/DlDialogBoxDemo.vue +175 -0
  190. package/src/demo/DlDropdownButtonDemo.vue +260 -0
  191. package/src/demo/DlIconDemo.vue +47 -0
  192. package/src/demo/DlLinkDemo.vue +23 -0
  193. package/src/demo/DlListDemo.vue +177 -0
  194. package/src/demo/DlMenuDemo.vue +524 -0
  195. package/src/demo/DlOptionGroupDemo.vue +79 -0
  196. package/src/demo/DlPaginationDemo.vue +44 -0
  197. package/src/demo/DlPanelContainerDemo.vue +221 -0
  198. package/src/demo/DlPopupDemo.vue +58 -0
  199. package/src/demo/DlProgressBarDemo.vue +22 -0
  200. package/src/demo/DlProgressChartDemo.vue +71 -0
  201. package/src/demo/DlRadioDemo.vue +35 -0
  202. package/src/demo/DlRangeDemo.vue +44 -0
  203. package/src/demo/DlSearchDemo.vue +27 -0
  204. package/src/demo/DlSelectDemo.vue +355 -0
  205. package/src/demo/DlSkeletonDemo.vue +20 -0
  206. package/src/demo/DlSliderDemo.vue +47 -0
  207. package/src/demo/DlStepperDemo/CenteredStepperInDialogBox.vue +260 -0
  208. package/src/demo/DlStepperDemo/SimpleStepper.vue +202 -0
  209. package/src/demo/DlStepperDemo/StepperInDialogBox.vue +261 -0
  210. package/src/demo/DlStepperDemo/index.ts +5 -0
  211. package/src/demo/DlStepperDemo/steps/AssignmentsStep.vue +97 -0
  212. package/src/demo/DlStepperDemo/steps/DataStep.vue +158 -0
  213. package/src/demo/DlStepperDemo/steps/GeneralStep.vue +106 -0
  214. package/src/demo/DlStepperDemo/steps/InstructionStep.vue +176 -0
  215. package/src/demo/DlStepperDemo/steps/QualityStep.vue +65 -0
  216. package/src/demo/DlSwitchDemo.vue +49 -0
  217. package/src/demo/DlTableDemo.vue +475 -0
  218. package/src/demo/DlTabsDemo.vue +67 -0
  219. package/src/demo/DlTdDemo.vue +19 -0
  220. package/src/demo/DlTextAreaDemo.vue +37 -0
  221. package/src/demo/DlTextHolderDemo.vue +42 -0
  222. package/src/demo/DlTextInputDemo.vue +89 -0
  223. package/src/demo/DlThDemo.vue +32 -0
  224. package/src/demo/DlTooltipDemo.vue +60 -0
  225. package/src/demo/DlTrDemo.vue +18 -0
  226. package/src/demo/DlTrendDemo.vue +25 -0
  227. package/src/demo/DlTypographyDemo.vue +93 -0
  228. package/src/demo/DlWidgetDemo.vue +157 -0
  229. package/src/demo/SmartSearchDemo/DlSmartSearchDemo.vue +202 -0
  230. package/src/demo/SmartSearchDemo/schema.ts +44 -0
  231. package/src/demo/index.ts +141 -0
  232. package/src/directives/TouchPan.ts +525 -0
  233. package/src/env.d.ts +8 -0
  234. package/src/hooks/use-anchor.ts +223 -0
  235. package/src/hooks/use-model-toggle.ts +181 -0
  236. package/src/hooks/use-portal.ts +104 -0
  237. package/src/hooks/use-scroll-target.ts +53 -0
  238. package/src/hooks/use-size-observer.ts +24 -0
  239. package/src/hooks/use-suggestions.ts +355 -0
  240. package/src/hooks/use-tick.ts +32 -0
  241. package/src/hooks/use-timeout.ts +20 -0
  242. package/src/hooks/use-transition.ts +32 -0
  243. package/src/hooks/use-window-size.ts +25 -0
  244. package/src/hooks/useForm.ts +12 -0
  245. package/src/index.ts +7 -0
  246. package/src/main.ts +4 -0
  247. package/src/models.ts +4 -0
  248. package/src/types.ts +6 -0
  249. package/src/utils/calcs.ts +18 -0
  250. package/src/utils/click-outside.ts +108 -0
  251. package/src/utils/component-name-parser.ts +1 -0
  252. package/src/utils/css-color-names.ts +150 -0
  253. package/src/utils/dom.ts +55 -0
  254. package/src/utils/draggable-table.ts +416 -0
  255. package/src/utils/escape-key.ts +54 -0
  256. package/src/utils/events.ts +67 -0
  257. package/src/utils/focus-manager.ts +33 -0
  258. package/src/utils/focusout.ts +29 -0
  259. package/src/utils/format.ts +3 -0
  260. package/src/utils/getColor.ts +17 -0
  261. package/src/utils/getLighterGradient.ts +36 -0
  262. package/src/utils/getRootStyles.ts +52 -0
  263. package/src/utils/global-config.ts +6 -0
  264. package/src/utils/global-nodes.ts +42 -0
  265. package/src/utils/includes.ts +3 -0
  266. package/src/utils/index.ts +29 -0
  267. package/src/utils/inject-object-prop.ts +21 -0
  268. package/src/utils/input-sizes.ts +7 -0
  269. package/src/utils/is-ellipsis-active.ts +3 -0
  270. package/src/utils/is-in-viewport.ts +13 -0
  271. package/src/utils/is.ts +15 -0
  272. package/src/utils/key-composition.ts +17 -0
  273. package/src/utils/keyCodes.ts +12 -0
  274. package/src/utils/logger/ConsoleLogger.ts +65 -0
  275. package/src/utils/logger/ILogger.ts +8 -0
  276. package/src/utils/logger/index.ts +8 -0
  277. package/src/utils/nav-keys-constants.ts +1 -0
  278. package/src/utils/portal.ts +55 -0
  279. package/src/utils/position-engine.ts +381 -0
  280. package/src/utils/render.ts +36 -0
  281. package/src/utils/ripple.ts +7 -0
  282. package/src/utils/scroll.ts +73 -0
  283. package/src/utils/selection.ts +15 -0
  284. package/src/utils/sort.ts +7 -0
  285. package/src/utils/splitByQuotes.ts +32 -0
  286. package/src/utils/string.ts +6 -0
  287. package/src/utils/teleport.ts +14 -0
  288. package/src/utils/theme.ts +2 -0
  289. package/src/utils/vm.ts +16 -0
  290. package/storybook.js +8 -0
  291. package/tsconfig.json +44 -0
  292. package/tsconfig.node.json +8 -0
  293. package/types.ts +1 -0
  294. package/vite.config.ts +13 -0
@@ -0,0 +1,280 @@
1
+ <template>
2
+ <div
3
+ :id="uuid"
4
+ class="dl-switch-wrapper"
5
+ :style="`height: ${size}px; margin: ${margin}`"
6
+ >
7
+ <label
8
+ v-if="!!leftLabel"
9
+ class="left dl-switch-label"
10
+ :for="computedId"
11
+ :style="cssLabelVars"
12
+ >
13
+ {{ leftLabel }}
14
+ </label>
15
+ <span
16
+ class="dl-switch-container"
17
+ :style="`max-height: ${size}px;`"
18
+ >
19
+ <input
20
+ :id="computedId"
21
+ ref="input"
22
+ :disabled="disabled"
23
+ type="checkbox"
24
+ :checked="isTrue"
25
+ class="dl-switch-checkbox"
26
+ :style="cssVars"
27
+ @change="handleChange"
28
+ >
29
+ <label
30
+ :for="computedId"
31
+ class="dl-switch"
32
+ :style="[cssSwitchVars, cssLabelVars]"
33
+ />
34
+ </span>
35
+ <label
36
+ v-if="!!rightLabel"
37
+ class="right dl-switch-label"
38
+ :for="computedId"
39
+ :style="cssLabelVars"
40
+ >
41
+ {{ rightLabel }}
42
+ </label>
43
+ </div>
44
+ </template>
45
+
46
+ <script lang="ts">
47
+ import { defineComponent, PropType, toRaw, nextTick } from 'vue-demi'
48
+ import { debounce } from 'lodash'
49
+ import { getColor } from '../utils'
50
+ import { v4 } from 'uuid'
51
+ import {
52
+ calculateBorderRadius,
53
+ calculateCircleRadius,
54
+ calculateMargin,
55
+ calculateActiveMarginLeft,
56
+ calculateWidth,
57
+ stopAndPrevent
58
+ } from '../utils'
59
+
60
+ const Any = [Array, Boolean, String, Number, Object]
61
+
62
+ export default defineComponent({
63
+ name: 'DlSwitch',
64
+ model: {
65
+ prop: 'modelValue',
66
+ event: 'update:model-value'
67
+ },
68
+ props: {
69
+ color: {
70
+ type: String,
71
+ default: 'dl-color-secondary'
72
+ },
73
+ disabled: {
74
+ type: Boolean,
75
+ default: false
76
+ },
77
+ id: { type: [String, Number], default: null },
78
+ margin: {
79
+ type: String,
80
+ default: '0'
81
+ },
82
+ modelValue: { type: Any, required: true },
83
+ labelProps: {
84
+ type: Object as PropType<{ fontSize: number; color: string }>,
85
+ default: () => ({
86
+ fontSize: 12,
87
+ color: 'dl-color-darker'
88
+ })
89
+ },
90
+ leftLabel: {
91
+ default: null,
92
+ type: String
93
+ },
94
+ rightLabel: {
95
+ default: null,
96
+ type: String
97
+ },
98
+ size: {
99
+ type: Number,
100
+ default: 12
101
+ },
102
+ value: { type: Any, default: null },
103
+ falseValue: { type: Any, default: false },
104
+ trueValue: { type: Any, default: true },
105
+ tabindex: { type: String, default: '0' }
106
+ },
107
+ emits: ['update:model-value', 'toggle', 'click', 'change'],
108
+ data() {
109
+ return {
110
+ uuid: `dl-switch-${v4()}`
111
+ }
112
+ },
113
+ computed: {
114
+ identifierClass(): string {
115
+ return `dl-switch-${
116
+ this.leftLabel ?? this.rightLabel ?? ''
117
+ }`.replaceAll(' ', '-')
118
+ },
119
+ computedId(): string {
120
+ return `${this.id || v4()}`
121
+ },
122
+ modelIsArray(): boolean {
123
+ return this.value !== null && Array.isArray(this.modelValue)
124
+ },
125
+ index(): number {
126
+ const value = toRaw(this.value)
127
+ return this.modelIsArray
128
+ ? (this.modelValue as any[]).findIndex(
129
+ (opt) => toRaw(opt) === value
130
+ )
131
+ : -1
132
+ },
133
+ isTrue(): boolean {
134
+ return this.modelIsArray
135
+ ? this.index > -1
136
+ : toRaw(this.modelValue) === toRaw(this.trueValue)
137
+ },
138
+ isFalse(): boolean {
139
+ return this.modelIsArray
140
+ ? this.index === -1
141
+ : toRaw(this.modelValue) === toRaw(this.falseValue)
142
+ },
143
+ cssVars(): Record<string, string> {
144
+ return {
145
+ '--dl-checkbox-height': `${this.size}px`,
146
+ '--dl-checkbox-width': `${calculateWidth(this.size)}px`
147
+ }
148
+ },
149
+ cssLabelVars(): Record<string, string> {
150
+ return {
151
+ '--dl-color-label': getColor(this.labelProps.color),
152
+ '--dl-label-font-size': `${this.labelProps.fontSize || 12}px`,
153
+ '--dl-checkbox-bg': getColor(this.color),
154
+ '--dl-checked-after': `${calculateActiveMarginLeft(
155
+ this.size
156
+ )}px`
157
+ }
158
+ },
159
+ cssSwitchVars(): Record<string, string> {
160
+ return {
161
+ '--dl-switch-width': `${calculateWidth(this.size)}px`,
162
+ '--dl-switch-height': `${this.size}px`,
163
+ '--dl-switch-border-radius': `${calculateBorderRadius(
164
+ this.size
165
+ )}px`,
166
+ '--dl-switch-margin': `${calculateMargin(this.size)}px`,
167
+ '--dl-switch-after-height': `${calculateCircleRadius(
168
+ this.size
169
+ )}px`,
170
+ '--dl-switch-after-width': `${calculateCircleRadius(
171
+ this.size
172
+ )}px`
173
+ }
174
+ }
175
+ },
176
+ watch: {
177
+ isTrue() {
178
+ debounce(() => {
179
+ nextTick(() => {
180
+ (this.$refs.input as HTMLInputElement).checked =
181
+ this.isTrue
182
+ })
183
+ }, 100)
184
+ }
185
+ },
186
+ methods: {
187
+ handleChange(e: Event) {
188
+ if (e) {
189
+ stopAndPrevent(e)
190
+ }
191
+
192
+ (e.target as HTMLInputElement).checked = this.isTrue
193
+
194
+ if (!this.disabled) {
195
+ let newValue: any | any[]
196
+ if (Array.isArray(this.modelValue)) {
197
+ newValue = this.isFalse
198
+ ? [...this.modelValue, this.value]
199
+ : this.modelValue.filter(
200
+ (element) => element !== this.value
201
+ )
202
+ } else {
203
+ newValue = this.modelValue
204
+ if (this.isTrue) {
205
+ newValue = this.falseValue
206
+ }
207
+ if (this.isFalse) {
208
+ newValue = this.trueValue
209
+ }
210
+ }
211
+
212
+ this.$emit('update:model-value', newValue, e)
213
+ this.$emit('toggle', newValue)
214
+ this.$emit('click', newValue)
215
+ this.$emit('change', newValue)
216
+ }
217
+ }
218
+ }
219
+ })
220
+ </script>
221
+
222
+ <style scoped lang="scss">
223
+ .dl-switch-wrapper {
224
+ display: flex;
225
+ align-items: center;
226
+ }
227
+ .dl-switch-container {
228
+ position: relative;
229
+ }
230
+ .dl-switch-checkbox {
231
+ appearance: none;
232
+ width: var(--dl-checkbox-width);
233
+ height: var(--dl-checkbox-height);
234
+ margin: 0;
235
+ &:disabled + label {
236
+ opacity: 0.6;
237
+ cursor: not-allowed;
238
+ }
239
+ &:checked + label {
240
+ background-color: var(--dl-checkbox-bg);
241
+ &::after {
242
+ margin-left: var(--dl-checked-after);
243
+ }
244
+ }
245
+ }
246
+
247
+ .dl-switch {
248
+ position: absolute;
249
+ top: 0;
250
+ left: 0;
251
+ width: var(--dl-switch-width);
252
+ height: var(--dl-switch-height);
253
+ border-radius: var(--dl-switch-border-radius);
254
+ background-color: #b3b3b3;
255
+ transition: background-color 0.2s;
256
+ cursor: pointer;
257
+ &::after {
258
+ content: '';
259
+ display: block;
260
+ border-radius: 50%;
261
+ width: var(--dl-switch-after-width);
262
+ height: var(--dl-switch-after-height);
263
+ margin: var(--dl-switch-margin);
264
+ background-color: rgba(255, 255, 255, 0.5);
265
+ transition: 0.2s;
266
+ }
267
+ }
268
+ .dl-switch-label {
269
+ font-size: var(--dl-label-font-size);
270
+ color: var(--dl-color-label);
271
+ line-height: 1;
272
+ }
273
+ .right {
274
+ padding-left: 10px;
275
+ }
276
+
277
+ .left {
278
+ padding-right: 10px;
279
+ }
280
+ </style>
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <div :id="uuid">
3
+ <slot />
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts">
8
+ import { v4 } from 'uuid'
9
+ import { defineComponent } from 'vue-demi'
10
+
11
+ export default defineComponent({
12
+ name: 'DlTabPanels',
13
+ props: {
14
+ name: { type: String, required: true }
15
+ },
16
+ data() {
17
+ return {
18
+ uuid: `dl-tab-panel-${v4()}`
19
+ }
20
+ }
21
+ })
22
+ </script>
@@ -0,0 +1,41 @@
1
+ <template>
2
+ <div :id="uuid">
3
+ <component :is="activeTab" />
4
+ </div>
5
+ </template>
6
+ <script lang="ts">
7
+ import { v4 } from 'uuid'
8
+ import { defineComponent, VNode, isVue2 } from 'vue-demi'
9
+ import { textSlot } from '../../utils/render'
10
+
11
+ export default defineComponent({
12
+ name: 'DlTabPanels',
13
+ model: {
14
+ prop: 'modelValue'
15
+ },
16
+ props: {
17
+ modelValue: { type: String, required: true }
18
+ },
19
+ data() {
20
+ return {
21
+ uuid: `dl-tab-panels-${v4()}`
22
+ }
23
+ },
24
+ computed: {
25
+ panels(): any[] {
26
+ return textSlot(this.$slots)
27
+ },
28
+ activeTab(): VNode | undefined {
29
+ if (isVue2) {
30
+ const tabIndex = this.panels.findIndex(
31
+ (item) => item?.data?.key === this.modelValue
32
+ )
33
+ return [this.panels[tabIndex]] as any
34
+ }
35
+ return (this.panels as any[])[0].children.find(
36
+ (panel: any) => panel.key === this.modelValue
37
+ )
38
+ }
39
+ }
40
+ })
41
+ </script>
@@ -0,0 +1,4 @@
1
+ import DlTabPanel from './DlTabPanel.vue'
2
+ import DlTabPanels from './DlTabPanels.vue'
3
+
4
+ export { DlTabPanel, DlTabPanels }
@@ -0,0 +1,19 @@
1
+ import { isVue2, VNode } from 'vue-demi'
2
+
3
+ export const getSlot = (isVue2: boolean, slot: any) => {
4
+ if (isVue2) {
5
+ return slot
6
+ }
7
+ return slot()
8
+ }
9
+
10
+ export const getChildrenFromSlot = (slot?: any): VNode[] => {
11
+ if (typeof slot !== 'undefined') {
12
+ const newSlot = getSlot(isVue2, slot)
13
+ if (isVue2) {
14
+ return newSlot
15
+ }
16
+ return Array.from(newSlot[0].children as VNode[])
17
+ }
18
+ return []
19
+ }