@invopop/popui 0.0.104 → 0.1.1

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 (248) hide show
  1. package/dist/AlertDialog.svelte +84 -59
  2. package/dist/AlertDialog.svelte.d.ts +5 -29
  3. package/dist/BaseButton.svelte +106 -101
  4. package/dist/BaseButton.svelte.d.ts +4 -34
  5. package/dist/BaseCard.svelte +20 -12
  6. package/dist/BaseCard.svelte.d.ts +4 -26
  7. package/dist/BaseCounter.svelte +13 -9
  8. package/dist/BaseCounter.svelte.d.ts +4 -17
  9. package/dist/BaseDropdown.svelte +54 -38
  10. package/dist/BaseDropdown.svelte.d.ts +6 -26
  11. package/dist/BaseFlag.svelte +6 -4
  12. package/dist/BaseFlag.svelte.d.ts +4 -17
  13. package/dist/BaseTable.svelte +226 -188
  14. package/dist/BaseTable.svelte.d.ts +4 -39
  15. package/dist/BaseTableActions.svelte +43 -33
  16. package/dist/BaseTableActions.svelte.d.ts +6 -21
  17. package/dist/BaseTableCellContent.svelte +19 -13
  18. package/dist/BaseTableCellContent.svelte.d.ts +4 -24
  19. package/dist/BaseTableCheckbox.svelte +19 -12
  20. package/dist/BaseTableCheckbox.svelte.d.ts +4 -21
  21. package/dist/BaseTableHeaderContent.svelte +30 -22
  22. package/dist/BaseTableHeaderContent.svelte.d.ts +4 -21
  23. package/dist/BaseTableHeaderOrderBy.svelte +24 -0
  24. package/dist/BaseTableHeaderOrderBy.svelte.d.ts +4 -0
  25. package/dist/BaseTableRow.svelte +78 -60
  26. package/dist/BaseTableRow.svelte.d.ts +4 -32
  27. package/dist/Breadcrumbs.svelte +14 -10
  28. package/dist/Breadcrumbs.svelte.d.ts +4 -19
  29. package/dist/ButtonFile.svelte +40 -29
  30. package/dist/ButtonFile.svelte.d.ts +4 -26
  31. package/dist/ButtonUuidCopy.svelte +27 -20
  32. package/dist/ButtonUuidCopy.svelte.d.ts +4 -22
  33. package/dist/CardCheckbox.svelte +28 -19
  34. package/dist/CardCheckbox.svelte.d.ts +4 -28
  35. package/dist/CardRelation.svelte +9 -8
  36. package/dist/CardRelation.svelte.d.ts +4 -22
  37. package/dist/CompanySelector.svelte +49 -43
  38. package/dist/CompanySelector.svelte.d.ts +4 -22
  39. package/dist/CounterWorkflow.svelte +12 -8
  40. package/dist/CounterWorkflow.svelte.d.ts +4 -17
  41. package/dist/DataListItem.svelte +24 -14
  42. package/dist/DataListItem.svelte.d.ts +4 -22
  43. package/dist/DatePicker.svelte +186 -386
  44. package/dist/DatePicker.svelte.d.ts +4 -22
  45. package/dist/DrawerContext.svelte +33 -22
  46. package/dist/DrawerContext.svelte.d.ts +4 -24
  47. package/dist/DrawerContextItem.svelte +70 -57
  48. package/dist/DrawerContextItem.svelte.d.ts +4 -23
  49. package/dist/DrawerContextSeparator.svelte +1 -1
  50. package/dist/DrawerContextSeparator.svelte.d.ts +22 -19
  51. package/dist/DrawerContextWorkspace.svelte +31 -32
  52. package/dist/DrawerContextWorkspace.svelte.d.ts +4 -20
  53. package/dist/DropdownSelect.svelte +93 -81
  54. package/dist/DropdownSelect.svelte.d.ts +4 -27
  55. package/dist/EmptyStateIcon.svelte +13 -7
  56. package/dist/EmptyStateIcon.svelte.d.ts +4 -22
  57. package/dist/EmptyStateIllustration.svelte +41 -33
  58. package/dist/EmptyStateIllustration.svelte.d.ts +4 -21
  59. package/dist/FeedEvents.svelte +5 -2
  60. package/dist/FeedEvents.svelte.d.ts +4 -17
  61. package/dist/FeedIconEvent.svelte +5 -3
  62. package/dist/FeedIconEvent.svelte.d.ts +4 -19
  63. package/dist/FeedIconStatus.svelte +23 -18
  64. package/dist/FeedIconStatus.svelte.d.ts +4 -17
  65. package/dist/FeedItem.svelte +33 -28
  66. package/dist/FeedItem.svelte.d.ts +4 -30
  67. package/dist/FeedItemDetail.svelte +21 -13
  68. package/dist/FeedItemDetail.svelte.d.ts +4 -23
  69. package/dist/FeedViewer.svelte +6 -13
  70. package/dist/FeedViewer.svelte.d.ts +4 -21
  71. package/dist/FormLayoutModal.svelte +9 -3
  72. package/dist/FormLayoutModal.svelte.d.ts +4 -29
  73. package/dist/GlobalSearch.svelte +38 -31
  74. package/dist/GlobalSearch.svelte.d.ts +4 -18
  75. package/dist/InputCheckbox.svelte +23 -14
  76. package/dist/InputCheckbox.svelte.d.ts +4 -23
  77. package/dist/InputError.svelte +4 -1
  78. package/dist/InputError.svelte.d.ts +4 -16
  79. package/dist/InputLabel.svelte +5 -3
  80. package/dist/InputLabel.svelte.d.ts +4 -18
  81. package/dist/InputRadio.svelte +25 -19
  82. package/dist/InputRadio.svelte.d.ts +4 -21
  83. package/dist/InputSearch.svelte +66 -46
  84. package/dist/InputSearch.svelte.d.ts +9 -33
  85. package/dist/InputSelect.svelte +36 -33
  86. package/dist/InputSelect.svelte.d.ts +4 -31
  87. package/dist/InputText.svelte +64 -48
  88. package/dist/InputText.svelte.d.ts +4 -28
  89. package/dist/InputTextarea.svelte +38 -29
  90. package/dist/InputTextarea.svelte.d.ts +4 -25
  91. package/dist/InputToggle.svelte +29 -22
  92. package/dist/InputToggle.svelte.d.ts +4 -20
  93. package/dist/MenuItem.svelte +99 -87
  94. package/dist/MenuItem.svelte.d.ts +5 -29
  95. package/dist/MenuItemCollapsible.svelte +26 -18
  96. package/dist/MenuItemCollapsible.svelte.d.ts +4 -24
  97. package/dist/Notification.svelte +35 -31
  98. package/dist/Notification.svelte.d.ts +4 -20
  99. package/dist/ProfileAvatar.svelte +26 -19
  100. package/dist/ProfileAvatar.svelte.d.ts +4 -21
  101. package/dist/ProfileSelector.svelte +25 -17
  102. package/dist/ProfileSelector.svelte.d.ts +4 -22
  103. package/dist/SectionLayout.svelte +6 -3
  104. package/dist/SectionLayout.svelte.d.ts +4 -18
  105. package/dist/SeparatorHorizontal.svelte +1 -1
  106. package/dist/SeparatorHorizontal.svelte.d.ts +22 -19
  107. package/dist/ShortcutWrapper.svelte +7 -1
  108. package/dist/ShortcutWrapper.svelte.d.ts +4 -27
  109. package/dist/StatusLabel.svelte +16 -12
  110. package/dist/StatusLabel.svelte.d.ts +4 -18
  111. package/dist/StepIconList.svelte +44 -41
  112. package/dist/StepIconList.svelte.d.ts +4 -17
  113. package/dist/TagBeta.svelte.d.ts +22 -19
  114. package/dist/TagSearch.svelte +19 -20
  115. package/dist/TagSearch.svelte.d.ts +4 -22
  116. package/dist/TagStatus.svelte +42 -37
  117. package/dist/TagStatus.svelte.d.ts +4 -19
  118. package/dist/TitleMain.svelte +9 -2
  119. package/dist/TitleMain.svelte.d.ts +4 -18
  120. package/dist/TitleSection.svelte +9 -2
  121. package/dist/TitleSection.svelte.d.ts +4 -18
  122. package/dist/UuidCopy.svelte +61 -48
  123. package/dist/UuidCopy.svelte.d.ts +4 -26
  124. package/dist/alert-dialog/alert-dialog-action.svelte +15 -15
  125. package/dist/alert-dialog/alert-dialog-action.svelte.d.ts +5 -26
  126. package/dist/alert-dialog/alert-dialog-cancel.svelte +13 -10
  127. package/dist/alert-dialog/alert-dialog-cancel.svelte.d.ts +3 -22
  128. package/dist/alert-dialog/alert-dialog-content.svelte +19 -15
  129. package/dist/alert-dialog/alert-dialog-content.svelte.d.ts +6 -15
  130. package/dist/alert-dialog/alert-dialog-description.svelte +11 -6
  131. package/dist/alert-dialog/alert-dialog-description.svelte.d.ts +3 -16
  132. package/dist/alert-dialog/alert-dialog-footer.svelte +11 -5
  133. package/dist/alert-dialog/alert-dialog-footer.svelte.d.ts +4 -16
  134. package/dist/alert-dialog/alert-dialog-header.svelte +14 -5
  135. package/dist/alert-dialog/alert-dialog-header.svelte.d.ts +4 -16
  136. package/dist/alert-dialog/alert-dialog-overlay.svelte +10 -13
  137. package/dist/alert-dialog/alert-dialog-overlay.svelte.d.ts +3 -14
  138. package/dist/alert-dialog/alert-dialog-title.svelte +11 -8
  139. package/dist/alert-dialog/alert-dialog-title.svelte.d.ts +3 -16
  140. package/dist/alert-dialog/alert-dialog-trigger.svelte +6 -0
  141. package/dist/alert-dialog/alert-dialog-trigger.svelte.d.ts +4 -0
  142. package/dist/alert-dialog/index.d.ts +3 -4
  143. package/dist/alert-dialog/index.js +2 -2
  144. package/dist/button/button.svelte +76 -18
  145. package/dist/button/button.svelte.d.ts +62 -14
  146. package/dist/button/index.d.ts +2 -60
  147. package/dist/button/index.js +1 -26
  148. package/dist/helpers.d.ts +4 -1
  149. package/dist/helpers.js +35 -0
  150. package/dist/index.d.ts +1 -3
  151. package/dist/index.js +0 -4
  152. package/dist/range-calendar/index.d.ts +20 -0
  153. package/dist/range-calendar/index.js +22 -0
  154. package/dist/range-calendar/range-calendar-caption.svelte +71 -0
  155. package/dist/range-calendar/range-calendar-caption.svelte.d.ts +19 -0
  156. package/dist/range-calendar/range-calendar-cell.svelte +18 -0
  157. package/dist/range-calendar/range-calendar-cell.svelte.d.ts +4 -0
  158. package/dist/range-calendar/range-calendar-day.svelte +41 -0
  159. package/dist/range-calendar/range-calendar-day.svelte.d.ts +4 -0
  160. package/dist/range-calendar/range-calendar-grid-row.svelte +11 -0
  161. package/dist/range-calendar/range-calendar-grid-row.svelte.d.ts +4 -0
  162. package/dist/range-calendar/range-calendar-grid.svelte +15 -0
  163. package/dist/range-calendar/range-calendar-grid.svelte.d.ts +4 -0
  164. package/dist/range-calendar/range-calendar-head-cell.svelte +18 -0
  165. package/dist/range-calendar/range-calendar-head-cell.svelte.d.ts +4 -0
  166. package/dist/range-calendar/range-calendar-header.svelte +18 -0
  167. package/dist/range-calendar/range-calendar-header.svelte.d.ts +4 -0
  168. package/dist/range-calendar/range-calendar-heading.svelte +15 -0
  169. package/dist/range-calendar/range-calendar-heading.svelte.d.ts +4 -0
  170. package/dist/range-calendar/range-calendar-month-select.svelte +44 -0
  171. package/dist/range-calendar/range-calendar-month-select.svelte.d.ts +4 -0
  172. package/dist/range-calendar/range-calendar-month.svelte +14 -0
  173. package/dist/range-calendar/range-calendar-month.svelte.d.ts +5 -0
  174. package/dist/range-calendar/range-calendar-months.svelte +18 -0
  175. package/dist/range-calendar/range-calendar-months.svelte.d.ts +5 -0
  176. package/dist/range-calendar/range-calendar-nav.svelte +18 -0
  177. package/dist/range-calendar/range-calendar-nav.svelte.d.ts +5 -0
  178. package/dist/range-calendar/range-calendar-next-button.svelte +30 -0
  179. package/dist/range-calendar/range-calendar-next-button.svelte.d.ts +8 -0
  180. package/dist/range-calendar/range-calendar-prev-button.svelte +30 -0
  181. package/dist/range-calendar/range-calendar-prev-button.svelte.d.ts +8 -0
  182. package/dist/range-calendar/range-calendar-year-select.svelte +43 -0
  183. package/dist/range-calendar/range-calendar-year-select.svelte.d.ts +4 -0
  184. package/dist/range-calendar/range-calendar.svelte +109 -0
  185. package/dist/range-calendar/range-calendar.svelte.d.ts +21 -0
  186. package/dist/svg/BgPattern.svelte.d.ts +22 -19
  187. package/dist/svg/IconContact.svelte +6 -1
  188. package/dist/svg/IconContact.svelte.d.ts +5 -15
  189. package/dist/svg/IconEmpty.svelte.d.ts +22 -19
  190. package/dist/svg/IconFile.svelte +6 -1
  191. package/dist/svg/IconFile.svelte.d.ts +5 -15
  192. package/dist/svg/IconInvoice.svelte +6 -1
  193. package/dist/svg/IconInvoice.svelte.d.ts +5 -15
  194. package/dist/svg/IconNoResults.svelte +6 -1
  195. package/dist/svg/IconNoResults.svelte.d.ts +5 -15
  196. package/dist/svg/IconPdf.svelte +6 -1
  197. package/dist/svg/IconPdf.svelte.d.ts +5 -15
  198. package/dist/svg/IconProduct.svelte +6 -1
  199. package/dist/svg/IconProduct.svelte.d.ts +5 -15
  200. package/dist/table/table-body.svelte +10 -5
  201. package/dist/table/table-body.svelte.d.ts +4 -16
  202. package/dist/table/table-caption.svelte +14 -5
  203. package/dist/table/table-caption.svelte.d.ts +4 -16
  204. package/dist/table/table-cell.svelte +16 -7
  205. package/dist/table/table-cell.svelte.d.ts +4 -19
  206. package/dist/table/table-footer.svelte +14 -5
  207. package/dist/table/table-footer.svelte.d.ts +4 -16
  208. package/dist/table/table-head.svelte +11 -5
  209. package/dist/table/table-head.svelte.d.ts +4 -16
  210. package/dist/table/table-header.svelte +17 -8
  211. package/dist/table/table-header.svelte.d.ts +4 -19
  212. package/dist/table/table-row.svelte +22 -8
  213. package/dist/table/table-row.svelte.d.ts +4 -22
  214. package/dist/table/table.svelte +11 -6
  215. package/dist/table/table.svelte.d.ts +4 -16
  216. package/dist/tabs/tabs-content.svelte +13 -8
  217. package/dist/tabs/tabs-content.svelte.d.ts +3 -16
  218. package/dist/tabs/tabs-list.svelte +7 -6
  219. package/dist/tabs/tabs-list.svelte.d.ts +3 -16
  220. package/dist/tabs/tabs-trigger.svelte +13 -9
  221. package/dist/tabs/tabs-trigger.svelte.d.ts +3 -14
  222. package/dist/tabs/tabs.svelte +12 -7
  223. package/dist/tabs/tabs.svelte.d.ts +3 -16
  224. package/dist/tooltip/index.d.ts +5 -3
  225. package/dist/tooltip/index.js +5 -3
  226. package/dist/tooltip/tooltip-content.svelte +42 -23
  227. package/dist/tooltip/tooltip-content.svelte.d.ts +5 -15
  228. package/dist/tooltip/tooltip-trigger.svelte +8 -0
  229. package/dist/tooltip/tooltip-trigger.svelte.d.ts +4 -0
  230. package/dist/tw.theme.d.ts +2 -9
  231. package/dist/tw.theme.js +0 -5
  232. package/dist/types.d.ts +484 -25
  233. package/dist/utils.d.ts +10 -1
  234. package/package.json +30 -39
  235. package/README.md +0 -234
  236. package/dist/BaseTableHeaderSortBy.svelte +0 -22
  237. package/dist/BaseTableHeaderSortBy.svelte.d.ts +0 -20
  238. package/dist/ComboBox.svelte +0 -12
  239. package/dist/ComboBox.svelte.d.ts +0 -21
  240. package/dist/ComboBoxContent.svelte +0 -33
  241. package/dist/ComboBoxContent.svelte.d.ts +0 -20
  242. package/dist/ProgressBar.svelte +0 -6
  243. package/dist/ProgressBar.svelte.d.ts +0 -16
  244. package/dist/alert-dialog/alert-dialog-portal.svelte +0 -6
  245. package/dist/alert-dialog/alert-dialog-portal.svelte.d.ts +0 -17
  246. package/dist/popui.css +0 -1
  247. package/dist/wcdispatch.d.ts +0 -1
  248. package/dist/wcdispatch.js +0 -9
@@ -1,194 +1,193 @@
1
- <script>import Transition from "svelte-transition";
2
- import flatpickr from "flatpickr";
3
- import "flatpickr/dist/flatpickr.min.css";
4
- import { createEventDispatcher, onMount } from "svelte";
5
- import BaseButton from "./BaseButton.svelte";
6
- import {
7
- startOfWeek,
8
- endOfWeek,
9
- subWeeks,
10
- endOfMonth,
11
- startOfMonth,
12
- subMonths,
13
- startOfQuarter,
14
- endOfQuarter,
15
- subQuarters
16
- } from "date-fns";
17
- import { Icon } from "@steeze-ui/svelte-icon";
18
- import { Calendar } from "@invopop/ui-icons";
19
- import clsx from "clsx";
20
- import { clickOutside } from "./clickOutside.js";
21
- const dispatch = createEventDispatcher();
22
- export let label = "Date";
23
- export let position = "left";
24
- export let from = "";
25
- export let to = "";
26
- $:
27
- if (datepicker) {
28
- setDates(from, to);
29
- }
30
- $:
31
- styles = clsx({
32
- "border-workspace-accent focus:border-workspace-accent shadow-active": isOpen,
33
- "border-neutral-200 hover:border-neutral-300": !isOpen
34
- });
35
- let datePickerEl;
36
- let selectedLabel = label;
37
- let datepicker;
38
- let selectedDates = { from: { value: "", display: "" }, to: { value: "", display: "" } };
39
- let isOpen = false;
40
- let selectedPeriod = "custom";
41
- const today = /* @__PURE__ */ new Date();
42
- const startOfThisWeek = startOfWeek(today, { weekStartsOn: 1 });
43
- const endOfThisWeek = endOfWeek(today, { weekStartsOn: 1 });
44
- const startOfLastWeek = subWeeks(startOfThisWeek, 1);
45
- const endOfLastWeek = endOfWeek(startOfLastWeek, { weekStartsOn: 1 });
46
- const startOfThisMonth = startOfMonth(today);
47
- const endOfThisMonth = endOfMonth(today);
48
- const startOfLastMonth = subMonths(startOfThisMonth, 1);
49
- const endOfLastMonth = endOfMonth(startOfLastMonth);
50
- const startOfThisQuarter = startOfQuarter(today);
51
- const endOfThisQuarter = endOfQuarter(today);
52
- const startOfLastQuarter = subQuarters(startOfThisQuarter, 1);
53
- const endOfLastQuarter = endOfQuarter(startOfLastQuarter);
54
- const periods = [
55
- {
56
- slug: "this-week",
57
- label: "This Week",
58
- action: () => {
59
- selectedPeriod = "this-week";
60
- datepicker.setDate([startOfThisWeek, endOfThisWeek], true);
61
- datepicker.jumpToDate(startOfThisWeek);
62
- }
63
- },
64
- {
65
- slug: "last-week",
66
- label: "Last Week",
67
- action: () => {
68
- selectedPeriod = "last-week";
69
- datepicker.setDate([startOfLastWeek, endOfLastWeek], true);
70
- datepicker.jumpToDate(startOfLastWeek);
71
- }
72
- },
73
- {
74
- slug: "this-month",
75
- label: "This month",
76
- action: () => {
77
- selectedPeriod = "this-month";
78
- datepicker.setDate([startOfThisMonth, endOfThisMonth], true);
79
- datepicker.jumpToDate(startOfThisMonth);
80
- }
81
- },
82
- {
83
- slug: "last-month",
84
- label: "Last month",
85
- action: () => {
86
- selectedPeriod = "last-month";
87
- datepicker.setDate([startOfLastMonth, endOfLastMonth], true);
88
- datepicker.jumpToDate(startOfLastMonth);
89
- }
90
- },
91
- {
92
- slug: "this-quarter",
93
- label: "This quarter",
94
- action: () => {
95
- selectedPeriod = "this-quarter";
96
- datepicker.setDate([startOfThisQuarter, endOfThisQuarter], true);
97
- datepicker.jumpToDate(startOfThisQuarter);
98
- }
99
- },
100
- {
101
- slug: "last-quarter",
102
- label: "Last quarter",
103
- action: () => {
104
- selectedPeriod = "last-quarter";
105
- datepicker.setDate([startOfLastQuarter, endOfLastQuarter], true);
106
- datepicker.jumpToDate(startOfLastQuarter);
107
- }
108
- },
109
- {
110
- slug: "custom",
111
- label: "Custom",
112
- action: () => {
113
- datepicker.clear();
114
- selectedPeriod = "custom";
115
- }
116
- }
117
- ];
118
- onMount(() => {
119
- datepicker = flatpickr(datePickerEl, {
120
- onChange: function(dates) {
121
- if (dates.length === 0) {
122
- selectedLabel = label;
123
- return;
1
+ <script lang="ts">
2
+ import clsx from 'clsx'
3
+ import RangeCalendar from './range-calendar/range-calendar.svelte'
4
+ import { parseDate, type DateValue } from '@internationalized/date'
5
+ import type { DateRange } from 'bits-ui'
6
+ import { Icon } from '@steeze-ui/svelte-icon'
7
+ import { Calendar } from '@invopop/ui-icons'
8
+ import Transition from 'svelte-transition'
9
+ import type { DatePickerProps } from './types'
10
+ import { clickOutside } from './clickOutside'
11
+ import BaseButton from './BaseButton.svelte'
12
+ import { datesFromToday, toCalendarDate } from './helpers'
13
+
14
+ const {
15
+ startOfThisWeek,
16
+ endOfThisWeek,
17
+ startOfLastWeek,
18
+ endOfLastWeek,
19
+ startOfThisMonth,
20
+ endOfThisMonth,
21
+ startOfLastMonth,
22
+ endOfLastMonth,
23
+ startOfThisQuarter,
24
+ endOfThisQuarter,
25
+ startOfLastQuarter,
26
+ endOfLastQuarter,
27
+ today
28
+ } = datesFromToday()
29
+
30
+ const periods = [
31
+ {
32
+ slug: 'this-week',
33
+ label: 'This Week',
34
+ action: () => {
35
+ value = {
36
+ start: toCalendarDate(startOfThisWeek),
37
+ end: toCalendarDate(endOfThisWeek)
38
+ }
39
+ selectedPeriod = 'this-week'
124
40
  }
125
- if (dates.length === 1) {
126
- selectedPeriod = "custom";
127
- return;
41
+ },
42
+ {
43
+ slug: 'last-week',
44
+ label: 'Last Week',
45
+ action: () => {
46
+ value = {
47
+ start: toCalendarDate(startOfLastWeek),
48
+ end: toCalendarDate(endOfLastWeek)
49
+ }
50
+ selectedPeriod = 'last-week'
128
51
  }
129
- const from2 = getDate(dates[0]);
130
- const to2 = getDate(dates[1]);
131
- selectedDates = { from: from2, to: to2 };
132
52
  },
133
- locale: {
134
- firstDayOfWeek: 1,
135
- weekdays: {
136
- shorthand: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
137
- longhand: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
53
+ {
54
+ slug: 'this-month',
55
+ label: 'This month',
56
+ action: () => {
57
+ value = {
58
+ start: toCalendarDate(startOfThisMonth),
59
+ end: toCalendarDate(endOfThisMonth)
60
+ }
61
+ selectedPeriod = 'this-month'
138
62
  }
139
63
  },
140
- inline: true,
141
- mode: "range",
142
- dateFormat: "Y-m-d",
143
- showMonths: 2
144
- });
145
- });
146
- function getDate(date) {
147
- const year = date.getFullYear();
148
- const month = ("0" + (date.getMonth() + 1)).slice(-2);
149
- const day = ("0" + date.getDate()).slice(-2);
150
- return { value: `${year}-${month}-${day}`, display: `${day}/${month}/${year}` };
151
- }
152
- function cancel() {
153
- isOpen = false;
154
- datepicker.clear();
155
- dispatch("selected", { from: "", to: "" });
156
- }
157
- function confirm() {
158
- isOpen = false;
159
- selectedLabel = getLabel();
160
- dispatch("selected", { from: selectedDates.from.value, to: selectedDates.to.value });
161
- }
162
- function getLabel() {
163
- if (!selectedDates.from.value)
164
- return label;
165
- if (selectedDates.from.value === selectedDates.to.value)
166
- return selectedDates.from.display;
167
- return `${selectedDates.from.display} \u2192 ${selectedDates.to.display}`;
168
- }
169
- function setDates(from2, to2) {
170
- datepicker.setDate([from2, to2]);
171
- selectedDates = {
172
- from: { value: from2, display: getDisplayFromValue(from2) },
173
- to: { value: to2, display: getDisplayFromValue(to2) }
174
- };
175
- selectedLabel = getLabel();
176
- }
177
- function getDisplayFromValue(value) {
178
- if (!value)
179
- return "";
180
- const parts = value.split("-");
181
- return `${parts[2]}/${parts[1]}/${parts[0]}`;
182
- }
64
+ {
65
+ slug: 'last-month',
66
+ label: 'Last month',
67
+ action: () => {
68
+ value = {
69
+ start: toCalendarDate(startOfLastMonth),
70
+ end: toCalendarDate(endOfLastMonth)
71
+ }
72
+ selectedPeriod = 'last-month'
73
+ }
74
+ },
75
+ {
76
+ slug: 'this-quarter',
77
+ label: 'This quarter',
78
+ action: () => {
79
+ value = {
80
+ start: toCalendarDate(startOfThisQuarter),
81
+ end: toCalendarDate(endOfThisQuarter)
82
+ }
83
+ selectedPeriod = 'this-quarter'
84
+ }
85
+ },
86
+ {
87
+ slug: 'last-quarter',
88
+ label: 'Last quarter',
89
+ action: () => {
90
+ value = {
91
+ start: toCalendarDate(startOfLastQuarter),
92
+ end: toCalendarDate(endOfLastQuarter)
93
+ }
94
+ selectedPeriod = 'last-quarter'
95
+ }
96
+ },
97
+ {
98
+ slug: 'custom',
99
+ label: 'Custom',
100
+ action: () => {
101
+ value = {
102
+ start: toCalendarDate(today),
103
+ end: undefined
104
+ }
105
+ selectedPeriod = 'custom'
106
+ }
107
+ }
108
+ ]
109
+
110
+ let {
111
+ label = 'Date',
112
+ position = 'left',
113
+ from = '',
114
+ to = '',
115
+ onSelect
116
+ }: DatePickerProps = $props()
117
+
118
+ let selectedPeriod = $state('this-week')
119
+ let value = $state<DateRange>({
120
+ start: undefined,
121
+ end: undefined
122
+ })
123
+ let isOpen = $state(false)
124
+ let styles = $derived(
125
+ clsx({
126
+ 'border-workspace-accent focus:border-workspace-accent shadow-active': isOpen,
127
+ 'border-neutral-200 hover:border-neutral-300': !isOpen
128
+ })
129
+ )
130
+ let selectedLabel = $state(label)
131
+
132
+ $effect(() => {
133
+ if (!value.end) {
134
+ selectedPeriod = 'custom'
135
+ }
136
+ })
137
+
138
+ $effect(() => {
139
+ if (from) {
140
+ value = {
141
+ start: parseDate(from),
142
+ end: to ? parseDate(to) : undefined
143
+ }
144
+ return
145
+ }
146
+ value = {
147
+ start: toCalendarDate(startOfThisWeek),
148
+ end: toCalendarDate(endOfThisWeek)
149
+ }
150
+ selectedPeriod = 'this-week'
151
+ })
152
+
153
+ function cancel() {
154
+ isOpen = false
155
+ onSelect?.({ from: '', to: '' })
156
+ }
157
+
158
+ function getDisplayFromValue(value: DateValue | undefined) {
159
+ if (!value) return ''
160
+
161
+ const date = value.toString()
162
+
163
+ const parts = date.split('-')
164
+
165
+ return `${parts[2]}/${parts[1]}/${parts[0]}`
166
+ }
167
+
168
+ function getLabel() {
169
+ if (!value.start) return label
170
+
171
+ if (value.start === value.end) return getDisplayFromValue(value.start)
172
+
173
+ return `${getDisplayFromValue(value.start)} → ${getDisplayFromValue(value.end)}`
174
+ }
175
+
176
+ function confirm() {
177
+ isOpen = false
178
+ selectedLabel = getLabel()
179
+
180
+ onSelect?.({ from: value.start?.toString() || '', to: value.end?.toString() || '' })
181
+ }
183
182
  </script>
184
183
 
185
184
  <div>
186
185
  <div class="relative">
187
186
  <button
188
- on:click={() => {
187
+ onclick={() => {
189
188
  isOpen = !isOpen
190
189
  }}
191
- class="{styles} datepicker-trigger w-full py-1.25 pl-7 pr-8 border rounded-md text-neutral-800 placeholder-neutral-800 text-base"
190
+ class="{styles} datepicker-trigger w-full py-1.25 pl-7 pr-8 border rounded-md text-neutral-800 placeholder-neutral-800 text-base cursor-pointer"
192
191
  >
193
192
  {selectedLabel}
194
193
  </button>
@@ -211,230 +210,31 @@ function getDisplayFromValue(value) {
211
210
  class:right-0={position === 'right'}
212
211
  class="bg-white inline-flex flex-col shadow rounded-lg absolute right-0 top-2 z-40"
213
212
  use:clickOutside
214
- on:click_outside={() => {
213
+ onclick_outside={() => {
215
214
  if (!isOpen) return
216
215
  cancel()
217
216
  }}
218
217
  >
219
- <div class="flex border-b border-neutral-100 h-[300px]">
218
+ <div class="flex border-b border-neutral-100 min-h-[300px] rounded-lg shadow-calendar">
220
219
  <div class="flex flex-col space-y-2 items-start p-3 border-r border-neutral-100">
221
220
  {#each periods as period}
222
221
  <button
223
- on:click={period.action}
222
+ onclick={period.action}
224
223
  class="{selectedPeriod === period.slug
225
- ? 'selected-period text-workspace-accent border-workspace-accent-200 bg-workspace-accent-50'
226
- : 'text-neutral-500 border-transparent'} whitespace-nowrap text-base px-2 py-1 tracking-normal border rounded"
224
+ ? 'selected-period text-workspace-accent-600 bg-workspace-accent-100'
225
+ : 'text-neutral-500'} whitespace-nowrap text-base px-2 py-1 tracking-normal rounded cursor-pointer"
227
226
  >
228
227
  {period.label}
229
228
  </button>
230
229
  {/each}
231
230
  </div>
232
- <div bind:this={datePickerEl} />
231
+ <RangeCalendar bind:value numberOfMonths={2} />
233
232
  </div>
234
233
  <div class="p-3 flex justify-end items-center space-x-3">
235
- <BaseButton variant="secondary" on:click={cancel}>Cancel</BaseButton>
236
- <BaseButton variant="primary" on:click={confirm} disabled={!selectedDates.to.value}>
237
- Confirm
238
- </BaseButton>
234
+ <BaseButton variant="secondary" onclick={cancel}>Cancel</BaseButton>
235
+ <BaseButton variant="primary" onclick={confirm} disabled={!value.end}>Confirm</BaseButton>
239
236
  </div>
240
237
  </div>
241
238
  </Transition>
242
239
  </div>
243
240
  </div>
244
-
245
- <style>
246
- :global(.flatpickr-calendar) {
247
- width: 508px !important;
248
- padding-left: 12px;
249
- padding-right: 12px;
250
- padding-top: 4px;
251
- padding-bottom: 8px;
252
- font-family: 'Inter' !important;
253
- top: 0 !important;
254
- border-radius: 0;
255
- box-shadow: none;
256
- }
257
- :global(.flatpickr-weekdaycontainer:nth-child(2)) {
258
- margin-left: 28px;
259
- }
260
- :global(.dayContainer:nth-child(1)) {
261
- margin-right: 28px;
262
- }
263
- :global(.flatpickr-months) {
264
- padding-top: 8px;
265
- padding-bottom: 12px;
266
- }
267
- :global(.flatpickr-current-month) {
268
- padding-top: 0px;
269
- display: flex;
270
- align-items: center;
271
- justify-content: center;
272
- font-size: 14px;
273
- height: 24px !important;
274
- letter-spacing: -0.07px;
275
- }
276
- :global(.flatpickr-monthDropdown-months) {
277
- font-weight: 500 !important;
278
- height: 22px !important;
279
- color: #09101c !important;
280
- }
281
- :global(.cur-month:hover) {
282
- background-color: transparent !important;
283
- }
284
- :global(.numInputWrapper:hover) {
285
- background-color: #fafbfb !important;
286
- border: 1px solid #f3f5f5 !important;
287
- }
288
- :global(.numInputWrapper span.arrowUp) {
289
- right: -4px;
290
- border: 0;
291
- background-color: transparent;
292
- }
293
- :global(.numInputWrapper span.arrowDown) {
294
- right: -4px;
295
- border: 0;
296
- background-color: transparent;
297
- }
298
- :global(.cur-year, .cur-month) {
299
- font-weight: 600 !important;
300
- color: #09101c !important;
301
- }
302
- :global(.numInputWrapper) {
303
- display: flex !important;
304
- align-items: center;
305
- justify-content: center;
306
- height: 22px;
307
- }
308
- :global(.flatpickr-next-month) {
309
- display: flex;
310
- align-items: center;
311
- justify-content: center;
312
- height: 24px !important;
313
- width: 24px !important;
314
- border: 1px solid #e9ebeb;
315
- right: 12px !important;
316
- top: 12px !important;
317
- padding: 0 !important;
318
- border-radius: 4px;
319
- }
320
- :global(.flatpickr-prev-month) {
321
- display: flex;
322
- align-items: center;
323
- justify-content: center;
324
- height: 24px !important;
325
- width: 24px !important;
326
- border: 1px solid #e9ebeb;
327
- left: 12px !important;
328
- top: 12px !important;
329
- padding: 0 !important;
330
- border-radius: 4px;
331
- }
332
- :global(.flatpickr-weekdays) {
333
- height: 32px;
334
- }
335
- :global(.flatpickr-day.selected, .flatpickr-day.startRange, .flatpickr-day.endRange) {
336
- background-color: var(--workspace-accent-color, #169958) !important;
337
- border: 0;
338
- border-radius: 4px !important;
339
- box-shadow: 0px 0px 0px 2px
340
- color-mix(in lab, transparent 88%, var(--workspace-accent-color, #169958)) !important;
341
- }
342
- :global(
343
- .flatpickr-day.selected:hover,
344
- .flatpickr-day.startRange:hover,
345
- .flatpickr-day.endRange:hover
346
- ) {
347
- border: 0;
348
- }
349
- :global(.flatpickr-day.inRange) {
350
- background-color: #f4f5f5;
351
- border: 1px solid #f4f5f5;
352
- box-shadow: none !important;
353
- }
354
- :global(.prevMonthDay, .nextMonthDay) {
355
- color: #cccece !important;
356
- font-weight: 500;
357
- font-size: 13px;
358
- }
359
- :global(.prevMonthDay.inRange, .nextMonthDay.inRange) {
360
- background-color: #f4f5f5 !important;
361
- border: 1px solid #f4f5f5 !important;
362
- }
363
- :global(.flatpickr-weekday) {
364
- width: 32px;
365
- height: 32px;
366
- display: flex !important;
367
- align-items: center;
368
- justify-content: center;
369
- font-weight: 400 !important;
370
- color: #9ca3af !important;
371
- font-size: 12px !important;
372
- }
373
- :global(.flatpickr-weekdaycontainer) {
374
- flex: 0 !important;
375
- border-bottom: 1px solid #f3f5f5 !important;
376
- }
377
- :global(.flatpickr-prev-month svg) {
378
- fill: #0a0a0a;
379
- height: 10px !important;
380
- width: 10px !important;
381
- }
382
- :global(.flatpickr-next-month svg) {
383
- fill: #0a0a0a;
384
- height: 10px !important;
385
- width: 10px !important;
386
- }
387
- :global(.flatpickr-prev-month:hover svg, .flatpickr-next-month:hover svg) {
388
- fill: #0a0a0a !important;
389
- }
390
- :global(.flatpickr-days) {
391
- width: 496px !important;
392
- }
393
- :global(.dayContainer) {
394
- width: 224px;
395
- min-width: 224px;
396
- max-width: 224px;
397
- justify-content: start;
398
- box-shadow: none !important;
399
- }
400
- :global(.flatpickr-day) {
401
- margin-top: 2px !important;
402
- border-radius: 4px;
403
- width: 32px;
404
- max-width: 32px;
405
- height: 32px;
406
- line-height: 32px;
407
- display: flex !important;
408
- font-weight: 500 !important;
409
- align-items: center;
410
- justify-content: center;
411
- color: #0a0a0a;
412
- }
413
- :global(.flatpickr-day.today) {
414
- border: 0;
415
- border-bottom: 1px solid var(--workspace-accent-color, #169958);
416
- border-radius: 0;
417
- }
418
- :global(.flatpickr-day.today:hover) {
419
- background-color: #fafbfb !important;
420
- border: 1px solid #f3f5f5 !important;
421
- color: #0a0a0a;
422
- border-radius: 4px;
423
- }
424
- :global(.flatpickr-day:hover) {
425
- background-color: #fafbfb;
426
- border: 1px solid #f3f5f5;
427
- }
428
- :global(.prevMonthDay:hover, .nextMonthDay:hover) {
429
- background-color: #fafbfb !important;
430
- border: 1px solid #f3f5f5 !important;
431
- }
432
- .datepicker-trigger {
433
- appearance: none;
434
- -webkit-appearance: none;
435
- -moz-appearance: none;
436
- background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3QgeD0iMiIgeT0iMiIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiByeD0iNCIgZmlsbD0iI0YzRjRGNiIvPgo8cGF0aCBkPSJNNi41IDguMjUwMDRMMTAgMTEuNzVMMTMuNSA4LjI1IiBzdHJva2U9IiMwMzA3MTIiIHN0cm9rZS13aWR0aD0iMS4xIi8+Cjwvc3ZnPg==');
437
- background-repeat: no-repeat;
438
- background-position: center right 8px;
439
- }
440
- </style>
@@ -1,22 +1,4 @@
1
- import { SvelteComponent } from "svelte";
2
- import 'flatpickr/dist/flatpickr.min.css';
3
- declare const __propDef: {
4
- props: {
5
- label?: string | undefined;
6
- position?: "right" | "left" | undefined;
7
- from?: string | undefined;
8
- to?: string | undefined;
9
- };
10
- events: {
11
- selected: CustomEvent<any>;
12
- } & {
13
- [evt: string]: CustomEvent<any>;
14
- };
15
- slots: {};
16
- };
17
- export type DatePickerProps = typeof __propDef.props;
18
- export type DatePickerEvents = typeof __propDef.events;
19
- export type DatePickerSlots = typeof __propDef.slots;
20
- export default class DatePicker extends SvelteComponent<DatePickerProps, DatePickerEvents, DatePickerSlots> {
21
- }
22
- export {};
1
+ import type { DatePickerProps } from './types';
2
+ declare const DatePicker: import("svelte").Component<DatePickerProps, {}, "">;
3
+ type DatePicker = ReturnType<typeof DatePicker>;
4
+ export default DatePicker;