@onereach/ui-components-common 19.3.0-beta.5083.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 (157) hide show
  1. package/dist/assets/index.d.ts +2 -0
  2. package/dist/assets.js +5 -0
  3. package/dist/directives/dropdown-close.d.ts +4 -0
  4. package/dist/directives/dropdown-open.d.ts +4 -0
  5. package/dist/directives/index.d.ts +2 -0
  6. package/dist/directives.js +5 -0
  7. package/dist/dom-CwV-xS38.js +95 -0
  8. package/dist/dropdown-open-k6cFnrqA.js +20 -0
  9. package/dist/extractCssVarName-IHa2pGlF.js +160 -0
  10. package/dist/helpers/getItemByValue.d.ts +2 -0
  11. package/dist/helpers/getItemsByValue.d.ts +2 -0
  12. package/dist/helpers/index.d.ts +3 -0
  13. package/dist/helpers/searchItemsByLabel.d.ts +2 -0
  14. package/dist/helpers.js +6 -0
  15. package/dist/hooks/index.d.ts +15 -0
  16. package/dist/hooks/useControlAttributes.d.ts +7 -0
  17. package/dist/hooks/useDateFormat.d.ts +4 -0
  18. package/dist/hooks/useDateMask.d.ts +4 -0
  19. package/dist/hooks/useElevation.d.ts +3 -0
  20. package/dist/hooks/useIdAttribute.d.ts +3 -0
  21. package/dist/hooks/useLocale.d.ts +4 -0
  22. package/dist/hooks/useOverflow.d.ts +11 -0
  23. package/dist/hooks/usePopoverState.d.ts +12 -0
  24. package/dist/hooks/useProxyModelValue.d.ts +8 -0
  25. package/dist/hooks/useResponsive/index.d.ts +1 -0
  26. package/dist/hooks/useResponsive/useResponsive.d.ts +6 -0
  27. package/dist/hooks/useTheme.d.ts +3 -0
  28. package/dist/hooks/useTimeFormat.d.ts +4 -0
  29. package/dist/hooks/useTimeMask.d.ts +4 -0
  30. package/dist/hooks/useToggle.d.ts +8 -0
  31. package/dist/hooks/useValidationAttributes.d.ts +11 -0
  32. package/dist/hooks.js +18 -0
  33. package/dist/index.d.ts +6 -0
  34. package/dist/index.js +138 -0
  35. package/dist/isUndefined-B5qXrATz.js +4 -0
  36. package/dist/isVisible-BuGrjvTY.js +4 -0
  37. package/dist/searchItemsByLabel-BhinsABA.js +13 -0
  38. package/dist/tokens/DATE_FORMAT.d.ts +3 -0
  39. package/dist/tokens/LOCALE.d.ts +3 -0
  40. package/dist/tokens/TIME_FORMAT.d.ts +3 -0
  41. package/dist/tokens/index.d.ts +3 -0
  42. package/dist/types/DataModel.d.ts +6 -0
  43. package/dist/types/DateFormat.d.ts +5 -0
  44. package/dist/types/FilterFunction.d.ts +1 -0
  45. package/dist/types/FormatFunction.d.ts +2 -0
  46. package/dist/types/Group.d.ts +5 -0
  47. package/dist/types/GroupFunction.d.ts +1 -0
  48. package/dist/types/Id.d.ts +1 -0
  49. package/dist/types/Item.d.ts +5 -0
  50. package/dist/types/Locale.d.ts +1 -0
  51. package/dist/types/ModelValue.d.ts +1 -0
  52. package/dist/types/SearchFunction.d.ts +1 -0
  53. package/dist/types/TimeFormat.d.ts +5 -0
  54. package/dist/types/index.d.ts +12 -0
  55. package/dist/types.js +5 -0
  56. package/dist/useValidationAttributes-DxhcSj_h.js +217 -0
  57. package/dist/utils/constants/color.d.ts +14 -0
  58. package/dist/utils/constants/key-codes.d.ts +14 -0
  59. package/dist/utils/constants/poper.d.ts +8 -0
  60. package/dist/utils/constants/regex.d.ts +42 -0
  61. package/dist/utils/exclude.d.ts +4 -0
  62. package/dist/utils/extractCssVarName.d.ts +1 -0
  63. package/dist/utils/functions/color.d.ts +23 -0
  64. package/dist/utils/functions/dom.d.ts +30 -0
  65. package/dist/utils/functions/flattenDeep.d.ts +2 -0
  66. package/dist/utils/functions/hash.d.ts +2 -0
  67. package/dist/utils/functions/px-to-rem.d.ts +1 -0
  68. package/dist/utils/functions/text.d.ts +1 -0
  69. package/dist/utils/include.d.ts +4 -0
  70. package/dist/utils/index.d.ts +26 -0
  71. package/dist/utils/isAncestor.d.ts +4 -0
  72. package/dist/utils/isArray.d.ts +4 -0
  73. package/dist/utils/isDescendant.d.ts +4 -0
  74. package/dist/utils/isEmpty.d.ts +4 -0
  75. package/dist/utils/isEqual.d.ts +4 -0
  76. package/dist/utils/isNil.d.ts +4 -0
  77. package/dist/utils/isNull.d.ts +4 -0
  78. package/dist/utils/isNumber.d.ts +4 -0
  79. package/dist/utils/isObject.d.ts +4 -0
  80. package/dist/utils/isString.d.ts +4 -0
  81. package/dist/utils/isUndefined.d.ts +4 -0
  82. package/dist/utils/isVisible.d.ts +1 -0
  83. package/dist/utils/toArray.d.ts +4 -0
  84. package/dist/utils.js +109 -0
  85. package/package.json +77 -0
  86. package/src/assets/error.png +0 -0
  87. package/src/assets/index.ts +2 -0
  88. package/src/assets/success.png +0 -0
  89. package/src/directives/dropdown-close.ts +14 -0
  90. package/src/directives/dropdown-open.ts +21 -0
  91. package/src/directives/index.ts +2 -0
  92. package/src/helpers/getItemByValue.ts +12 -0
  93. package/src/helpers/getItemsByValue.ts +6 -0
  94. package/src/helpers/index.ts +3 -0
  95. package/src/helpers/searchItemsByLabel.ts +5 -0
  96. package/src/hooks/index.ts +15 -0
  97. package/src/hooks/useControlAttributes.ts +19 -0
  98. package/src/hooks/useDateFormat.ts +13 -0
  99. package/src/hooks/useDateMask.ts +54 -0
  100. package/src/hooks/useElevation.ts +32 -0
  101. package/src/hooks/useIdAttribute.ts +11 -0
  102. package/src/hooks/useLocale.ts +13 -0
  103. package/src/hooks/useOverflow.ts +83 -0
  104. package/src/hooks/usePopoverState.ts +67 -0
  105. package/src/hooks/useProxyModelValue.ts +50 -0
  106. package/src/hooks/useResponsive/index.ts +1 -0
  107. package/src/hooks/useResponsive/useResponsive.ts +58 -0
  108. package/src/hooks/useTheme.ts +8 -0
  109. package/src/hooks/useTimeFormat.ts +13 -0
  110. package/src/hooks/useTimeMask.ts +41 -0
  111. package/src/hooks/useToggle.ts +32 -0
  112. package/src/hooks/useValidationAttributes.ts +25 -0
  113. package/src/index.ts +6 -0
  114. package/src/tokens/DATE_FORMAT.ts +4 -0
  115. package/src/tokens/LOCALE.ts +4 -0
  116. package/src/tokens/TIME_FORMAT.ts +4 -0
  117. package/src/tokens/index.ts +3 -0
  118. package/src/types/DataModel.ts +3 -0
  119. package/src/types/DateFormat.ts +5 -0
  120. package/src/types/FilterFunction.ts +1 -0
  121. package/src/types/FormatFunction.ts +3 -0
  122. package/src/types/Group.ts +6 -0
  123. package/src/types/GroupFunction.ts +1 -0
  124. package/src/types/Id.ts +1 -0
  125. package/src/types/Item.ts +5 -0
  126. package/src/types/Locale.ts +1 -0
  127. package/src/types/ModelValue.ts +1 -0
  128. package/src/types/SearchFunction.ts +1 -0
  129. package/src/types/TimeFormat.ts +5 -0
  130. package/src/types/index.ts +12 -0
  131. package/src/utils/constants/color.ts +14 -0
  132. package/src/utils/constants/key-codes.ts +14 -0
  133. package/src/utils/constants/poper.ts +8 -0
  134. package/src/utils/constants/regex.ts +57 -0
  135. package/src/utils/exclude.ts +6 -0
  136. package/src/utils/extractCssVarName.ts +5 -0
  137. package/src/utils/functions/color.ts +55 -0
  138. package/src/utils/functions/dom.ts +206 -0
  139. package/src/utils/functions/flattenDeep.ts +5 -0
  140. package/src/utils/functions/hash.ts +10 -0
  141. package/src/utils/functions/px-to-rem.ts +2 -0
  142. package/src/utils/functions/text.ts +8 -0
  143. package/src/utils/include.ts +6 -0
  144. package/src/utils/index.ts +28 -0
  145. package/src/utils/isAncestor.ts +16 -0
  146. package/src/utils/isArray.ts +6 -0
  147. package/src/utils/isDescendant.ts +16 -0
  148. package/src/utils/isEmpty.ts +24 -0
  149. package/src/utils/isEqual.ts +23 -0
  150. package/src/utils/isNil.ts +8 -0
  151. package/src/utils/isNull.ts +6 -0
  152. package/src/utils/isNumber.ts +6 -0
  153. package/src/utils/isObject.ts +6 -0
  154. package/src/utils/isString.ts +6 -0
  155. package/src/utils/isUndefined.ts +6 -0
  156. package/src/utils/isVisible.ts +3 -0
  157. package/src/utils/toArray.ts +16 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Returns a copy of the `items` array, including the `value`.
3
+ */
4
+ export declare const include: <T>(value: T, items: T[]) => T[];
@@ -0,0 +1,26 @@
1
+ export * from './constants/color';
2
+ export * from './constants/key-codes';
3
+ export * from './constants/poper';
4
+ export * from './constants/regex';
5
+ export * from './exclude';
6
+ export * from './functions/color';
7
+ export * from './functions/dom';
8
+ export * from './functions/flattenDeep';
9
+ export * from './functions/hash';
10
+ export * from './functions/px-to-rem';
11
+ export * from './functions/text';
12
+ export * from './include';
13
+ export * from './isAncestor';
14
+ export * from './isArray';
15
+ export * from './isDescendant';
16
+ export * from './isEmpty';
17
+ export * from './isEqual';
18
+ export * from './isNil';
19
+ export * from './isNull';
20
+ export * from './isNumber';
21
+ export * from './isObject';
22
+ export * from './isString';
23
+ export * from './isUndefined';
24
+ export * from './isVisible';
25
+ export * from './toArray';
26
+ export * from './extractCssVarName';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the element `a` is an ancestor of the element `b`.
3
+ */
4
+ export declare const isAncestor: (a: Element, b: Element) => boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is an array literal.
3
+ */
4
+ export declare const isArray: (value: unknown) => value is unknown[];
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the element `a` is a descendant of the element `b`.
3
+ */
4
+ export declare const isDescendant: (a: Element, b: Element) => boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is an empty object, an empty array, a zero-length string, `null`, or `undefined`.
3
+ */
4
+ export declare const isEmpty: (value: unknown) => boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether `a` and `b` are the same value (makes shallow comparison of arrays and objects).
3
+ */
4
+ export declare const isEqual: (a: unknown, b: unknown) => boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is `null` or `undefined`.
3
+ */
4
+ export declare const isNil: (value: unknown) => value is null | undefined;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is `null`.
3
+ */
4
+ export declare const isNull: (value: unknown) => value is null;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is a number.
3
+ */
4
+ export declare const isNumber: (value: unknown) => value is number;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is an object literal.
3
+ */
4
+ export declare const isObject: (value: unknown) => value is Record<PropertyKey, unknown>;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is a string.
3
+ */
4
+ export declare const isString: (value: unknown) => value is string;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determines whether the `value` is `undefined`.
3
+ */
4
+ export declare const isUndefined: (value: unknown) => value is undefined;
@@ -0,0 +1 @@
1
+ export declare const isVisible: (element: Element) => boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Converts the `value` to an array literal.
3
+ */
4
+ export declare const toArray: <T>(value: T | T[]) => T[];
package/dist/utils.js ADDED
@@ -0,0 +1,109 @@
1
+ import { C as E, a as _, b as R, c as e, d as T, e as t, f as A, g as C, h as O, i as r, j as S, k as o, l as N, m as i, H as D, p as X, o as P, t as l, s as L, r as n, q as M, n as I, P as g, Q as H, R as m, u as c, S as d, T as f, v as B, W as x, X as F, w as G, x as b, y as p, V as U, z as u, A as h, _ as y, B as v, D as V, E as W, Y as j, F as q, Z as K, G as Y, I as k, J as w, K as z, U as Q, L as Z, M as J, N as $, O as aa, $ as sa, am as Ea, a5 as _a, a4 as Ra, a2 as ea, a9 as Ta, a6 as ta, a0 as Aa, a3 as Ca, aa as Oa, ab as ra, ac as Sa, ad as oa, ae as Na, af as ia, ag as Da, ah as Xa, ai as Pa, aj as la, ak as La, a7 as na, a8 as Ma, a1 as Ia, al as ga } from "./extractCssVarName-IHa2pGlF.js";
2
+ import { M as ma, f as ca, c as da, e as fa, l as Ba, q as xa, g as Fa, t as Ga, w as ba, p as pa, m as Ua, i as ua, u as ha, v as ya, b as va, k as Va, h as Wa, a as ja, o as qa, r as Ka, d as Ya, s as ka, j as wa, n as za } from "./dom-CwV-xS38.js";
3
+ import { i as Za } from "./isUndefined-B5qXrATz.js";
4
+ import { i as $a } from "./isVisible-BuGrjvTY.js";
5
+ export {
6
+ E as CODE_BACKSPACE,
7
+ _ as CODE_BREAK,
8
+ R as CODE_DELETE,
9
+ e as CODE_DOWN,
10
+ T as CODE_END,
11
+ t as CODE_ENTER,
12
+ A as CODE_ESC,
13
+ C as CODE_HOME,
14
+ O as CODE_LEFT,
15
+ r as CODE_PAGEDOWN,
16
+ S as CODE_PAGEUP,
17
+ o as CODE_RIGHT,
18
+ N as CODE_SPACE,
19
+ i as CODE_UP,
20
+ D as HSL_LIMITS,
21
+ ma as MutationObs,
22
+ X as PLACEMENT_BOTTOM_END,
23
+ P as PLACEMENT_BOTTOM_START,
24
+ l as PLACEMENT_LEFT_END,
25
+ L as PLACEMENT_LEFT_START,
26
+ n as PLACEMENT_RIGHT_END,
27
+ M as PLACEMENT_RIGHT_START,
28
+ I as PLACEMENT_TOP_END,
29
+ g as PLACEMENT_TOP_START,
30
+ H as RX_ABBREVIATION_FROM_STRING,
31
+ m as RX_ARRAY_NOTATION,
32
+ c as RX_BV_PREFIX,
33
+ d as RX_DATE,
34
+ f as RX_DATE_SPLIT,
35
+ B as RX_DIGITS,
36
+ x as RX_ENCODED_COMMA,
37
+ F as RX_ENCODE_REVERSE,
38
+ G as RX_EXTENSION,
39
+ b as RX_HASH,
40
+ p as RX_HASH_ID,
41
+ U as RX_HREF,
42
+ u as RX_HTML_TAGS,
43
+ h as RX_HYPHENATE,
44
+ y as RX_LONG_COLOR,
45
+ v as RX_LOWER_UPPER,
46
+ V as RX_NUMBER,
47
+ W as RX_PLUS,
48
+ j as RX_QUERY_START,
49
+ q as RX_REGEXP_REPLACE,
50
+ K as RX_SHORT_COLOR,
51
+ Y as RX_SPACES,
52
+ k as RX_SPACE_SPLIT,
53
+ w as RX_STAR,
54
+ z as RX_START_SPACE_WORD,
55
+ Q as RX_TIME,
56
+ Z as RX_TRIM_LEFT,
57
+ J as RX_TRIM_RIGHT,
58
+ $ as RX_UNDERSCORE,
59
+ aa as RX_UN_KEBAB,
60
+ ca as addClass,
61
+ da as cancelAF,
62
+ fa as contains,
63
+ sa as exclude,
64
+ Ea as extractCssVarName,
65
+ _a as flattenDeep,
66
+ Ra as generateColorFromString,
67
+ ea as generateHslFromString,
68
+ Ta as getAbbreviation,
69
+ Ba as getAttr,
70
+ xa as getBCR,
71
+ Fa as getById,
72
+ Ga as getCS,
73
+ ta as getHashOfString,
74
+ ba as getMaxZIndex,
75
+ pa as getStyle,
76
+ Ua as hasAttr,
77
+ ua as hasClass,
78
+ Aa as hexToRgb,
79
+ Ca as hslToColorString,
80
+ Oa as include,
81
+ ra as isAncestor,
82
+ Sa as isArray,
83
+ oa as isDescendant,
84
+ Na as isEmpty,
85
+ ia as isEqual,
86
+ Da as isNil,
87
+ Xa as isNull,
88
+ Pa as isNumber,
89
+ la as isObject,
90
+ La as isString,
91
+ Za as isUndefined,
92
+ $a as isVisible,
93
+ na as normalize,
94
+ ha as offset,
95
+ ya as position,
96
+ Ma as pxToRem,
97
+ va as reflow,
98
+ Va as removeAttr,
99
+ Wa as removeClass,
100
+ ja as removeNode,
101
+ qa as removeStyle,
102
+ Ka as requestAF,
103
+ Ia as rgbToHex,
104
+ Ya as select,
105
+ ka as selectAll,
106
+ wa as setAttr,
107
+ za as setStyle,
108
+ ga as toArray
109
+ };
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@onereach/ui-components-common",
3
+ "version": "19.3.0-beta.5083.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./src/": "./src/",
12
+ "./utils": {
13
+ "types": "./dist/utils/index.d.ts",
14
+ "import": "./dist/utils.js",
15
+ "default": "./dist/utils.js"
16
+ },
17
+ "./types": {
18
+ "types": "./dist/types/index.d.ts",
19
+ "import": "./dist/types.js",
20
+ "default": "./dist/types.js"
21
+ },
22
+ "./hooks": {
23
+ "types": "./dist/hooks/index.d.ts",
24
+ "import": "./dist/hooks.js",
25
+ "default": "./dist/hooks.js"
26
+ },
27
+ "./helpers": {
28
+ "types": "./dist/helpers/index.d.ts",
29
+ "import": "./dist/helpers.js",
30
+ "default": "./dist/helpers.js"
31
+ },
32
+ "./directives": {
33
+ "types": "./dist/directives/index.d.ts",
34
+ "import": "./dist/directives.js",
35
+ "default": "./dist/directives.js"
36
+ },
37
+ "./tokens": {
38
+ "types": "./dist/tokens/index.d.ts",
39
+ "import": "./dist/tokens.js",
40
+ "default": "./dist/tokens.js"
41
+ },
42
+ "./assets": {
43
+ "types": "./dist/assets/index.d.ts",
44
+ "import": "./dist/assets.js",
45
+ "default": "./dist/assets.js"
46
+ }
47
+ },
48
+ "main": "./dist/index.js",
49
+ "typings": "./dist/index.d.ts",
50
+ "files": [
51
+ "dist",
52
+ "src",
53
+ "./shims.d.ts",
54
+ "./tsconfig.components.json"
55
+ ],
56
+ "scripts": {
57
+ "build": "vite build",
58
+ "dev": "vite"
59
+ },
60
+ "dependencies": {
61
+ "@onereach/styles": "19.1.2",
62
+ "@vueuse/core": "9.13.0",
63
+ "lodash": "^4.17.21"
64
+ },
65
+ "devDependencies": {
66
+ "@types/lodash": "^4.17.0",
67
+ "rollup-plugin-node-externals": "6.1.2",
68
+ "vite": "^5.2.3",
69
+ "vite-plugin-dts": "3.7.3"
70
+ },
71
+ "peerDependencies": {
72
+ "vue": "^3.0.5 || 2.6.14"
73
+ },
74
+ "publishConfig": {
75
+ "access": "restricted"
76
+ }
77
+ }
Binary file
@@ -0,0 +1,2 @@
1
+ export { default as success } from './success.png';
2
+ export { default as error } from './error.png';
Binary file
@@ -0,0 +1,14 @@
1
+ import { DirectiveBinding, DirectiveHook } from 'vue';
2
+ import { isVue3 } from '@/constants';
3
+
4
+ const created: DirectiveHook = (element: HTMLElement, binding: DirectiveBinding<(event: Event) => void>) => {
5
+ element.addEventListener('keydown', (event) => {
6
+ if (['Escape'].includes(event.key)) {
7
+ binding.value(event);
8
+ }
9
+ });
10
+ };
11
+
12
+ export const DropdownClose = {
13
+ [isVue3 ? 'created' : 'bind']: created,
14
+ };
@@ -0,0 +1,21 @@
1
+ import { DirectiveBinding, DirectiveHook } from 'vue';
2
+ import { isVue3 } from '@/constants';
3
+
4
+ const created: DirectiveHook = (element: HTMLElement, binding: DirectiveBinding<(event: Event) => void>) => {
5
+ element.addEventListener('keydown', (event) => {
6
+ if (['Enter', ' '].includes(event.key)) {
7
+ binding.value(event);
8
+ }
9
+ });
10
+
11
+ element.addEventListener('click', (event) => {
12
+ event.stopPropagation();
13
+ event.preventDefault();
14
+
15
+ binding.value(event);
16
+ });
17
+ };
18
+
19
+ export const DropdownOpen = {
20
+ [isVue3 ? 'created' : 'bind']: created,
21
+ };
@@ -0,0 +1,2 @@
1
+ export * from './dropdown-close';
2
+ export * from './dropdown-open';
@@ -0,0 +1,12 @@
1
+ import { Item } from '../types';
2
+ import { isUndefined } from '../utils';
3
+
4
+ export const getItemByValue = <T, E extends Item<T>>(value: T, items: E[]): E => {
5
+ const item = items.find((item) => value === item.value);
6
+
7
+ if (isUndefined(item)) {
8
+ throw new Error('[getItemByValue]: Item not found.');
9
+ }
10
+
11
+ return item;
12
+ };
@@ -0,0 +1,6 @@
1
+ import { getItemByValue } from '.';
2
+ import { Item } from '../types';
3
+
4
+ export const getItemsByValue = <T, E extends Item<T>>(value: T[], items: E[]): E[] => {
5
+ return value.map((value) => getItemByValue(value, items));
6
+ };
@@ -0,0 +1,3 @@
1
+ export * from './getItemByValue';
2
+ export * from './getItemsByValue';
3
+ export * from './searchItemsByLabel';
@@ -0,0 +1,5 @@
1
+ import { Item } from '../types';
2
+
3
+ export const searchItemsByLabel = async <T, E extends Item<T>>(value: string, items: E[]): Promise<E[]> => {
4
+ return items.filter((item) => new RegExp(value, 'i').test(item.label));
5
+ };
@@ -0,0 +1,15 @@
1
+ export * from './useControlAttributes';
2
+ export * from './useDateFormat';
3
+ export * from './useDateMask';
4
+ export * from './useElevation';
5
+ export * from './useIdAttribute';
6
+ export * from './useLocale';
7
+ export * from './useOverflow';
8
+ export * from './usePopoverState';
9
+ export * from './useProxyModelValue';
10
+ export * from './useResponsive';
11
+ export * from './useTheme';
12
+ export * from './useTimeFormat';
13
+ export * from './useTimeMask';
14
+ export { default as useToggle } from './useToggle';
15
+ export * from './useValidationAttributes';
@@ -0,0 +1,19 @@
1
+ import { computed, ComputedRef, useAttrs } from 'vue';
2
+
3
+ export type UseControlAttributesReturn = {
4
+ readonly: ComputedRef<boolean | undefined>;
5
+ disabled: ComputedRef<boolean | undefined>;
6
+
7
+ 'force-state': ComputedRef<string | undefined>;
8
+ };
9
+
10
+ export const useControlAttributes = (): UseControlAttributesReturn => {
11
+ const attributes = useAttrs();
12
+
13
+ return {
14
+ readonly: computed(() => attributes['readonly'] as boolean | undefined),
15
+ disabled: computed(() => attributes['disabled'] as boolean | undefined),
16
+
17
+ 'force-state': computed(() => attributes['force-state'] as string | undefined),
18
+ };
19
+ };
@@ -0,0 +1,13 @@
1
+ import { ComputedRef, Ref, computed, inject } from 'vue';
2
+ import { DATE_FORMAT } from '../tokens';
3
+ import { DateFormat, FormatFunction, ModelValue } from '../types';
4
+
5
+ export type UseDateFormatReturn = ComputedRef<`${DateFormat}` | FormatFunction<ModelValue<Date>>>;
6
+
7
+ export const useDateFormat = (
8
+ format: Ref<`${DateFormat}` | FormatFunction<ModelValue<Date>> | undefined>
9
+ ): UseDateFormatReturn => {
10
+ return computed(() => {
11
+ return format.value ?? inject(DATE_FORMAT, DateFormat.Short);
12
+ });
13
+ };
@@ -0,0 +1,54 @@
1
+ import { ComputedRef, Ref, computed } from 'vue';
2
+ import { DateFormat, FormatFunction, Locale, ModelValue } from '../types';
3
+
4
+ export type UseDateMaskReturn = ComputedRef<string>;
5
+
6
+ export const useDateMask = (
7
+ format: Ref<`${DateFormat}` | FormatFunction<ModelValue<Date>>>,
8
+ locale: Ref<`${Locale}`>
9
+ ): UseDateMaskReturn => {
10
+ return computed(() => {
11
+ if (typeof format.value !== 'function') {
12
+ const formatter = new Intl.DateTimeFormat(locale.value, {
13
+ dateStyle: format.value,
14
+ timeZone: 'UTC',
15
+ });
16
+
17
+ return formatter.formatToParts(Date.UTC(1, 0, 1, 1, 1)).reduce((mask, part) => {
18
+ switch (part.type) {
19
+ case 'year':
20
+ return mask + part.value
21
+ .replace(/^\d{2}$/, 'YY')
22
+ .replace(/^\d{4}$/, 'YYYY');
23
+
24
+ case 'month':
25
+ switch (format.value) {
26
+ case 'short':
27
+ return mask + part.value
28
+ .replace(/^\d{1}$/, 'M')
29
+ .replace(/^\d{2}$/, 'MM');
30
+
31
+ case 'medium':
32
+ return mask + 'MMM';
33
+
34
+ case 'long':
35
+ return mask + 'MMMM';
36
+
37
+ default:
38
+ throw new Error('[useDateMask]: `format` has an invalid value.');
39
+ }
40
+
41
+ case 'day':
42
+ return mask + part.value
43
+ .replace(/^\d{1}$/, 'D')
44
+ .replace(/^\d{2}$/, 'DD');
45
+
46
+ default:
47
+ return mask + part.value;
48
+ }
49
+ }, '');
50
+ }
51
+
52
+ return format.value(undefined, locale.value);
53
+ });
54
+ };
@@ -0,0 +1,32 @@
1
+ import { MaybeElementRef } from '@vueuse/core';
2
+ import { isRef, Ref, ref, watch } from 'vue';
3
+ import { isVisible } from '../utils';
4
+
5
+ export const useElevation = (
6
+ element: MaybeElementRef<HTMLElement | undefined>,
7
+ trigger?: Ref<unknown>
8
+ ): void => {
9
+ const elementRef = isRef(element) ? element : ref(element);
10
+ const triggerRef = isRef(trigger) ? trigger : ref();
11
+
12
+ // Functions
13
+ function getPageElevations(currentElement: HTMLElement): number[] {
14
+ return ([...document.body.querySelectorAll('*')] as HTMLElement[])
15
+ .filter(isVisible)
16
+ .filter(element => !element.isEqualNode(currentElement))
17
+ .map((element) => getComputedStyle(element))
18
+ .map((style) => Number(style.zIndex))
19
+ .filter((zIndex) => !isNaN(zIndex));
20
+ }
21
+
22
+ function setElementElevation(element: HTMLElement): void {
23
+ element.style.zIndex = String(Math.max(0, ...getPageElevations(element)) + 1);
24
+ }
25
+
26
+ // Effects
27
+ watch([elementRef, triggerRef], ([element]) => {
28
+ if (element) {
29
+ setElementElevation(element as HTMLElement);
30
+ }
31
+ }, { immediate: true });
32
+ };
@@ -0,0 +1,11 @@
1
+ import { computed, ComputedRef, getCurrentInstance, useAttrs } from 'vue';
2
+
3
+ export type UseIdAttributeReturn = ComputedRef<string | undefined>;
4
+
5
+ export const useIdAttribute = (): UseIdAttributeReturn => {
6
+ const attributes = useAttrs(), component = getCurrentInstance();
7
+
8
+ return computed(() => {
9
+ return attributes['id'] as string | undefined ?? component?.uid.toString();
10
+ });
11
+ };
@@ -0,0 +1,13 @@
1
+ import { ComputedRef, Ref, computed, inject } from 'vue';
2
+ import { LOCALE } from '../tokens';
3
+ import { Locale } from '../types';
4
+
5
+ export type UseLocaleReturn = ComputedRef<`${Locale}`>;
6
+
7
+ export const useLocale = (
8
+ locale: Ref<`${Locale}` | undefined>
9
+ ): UseLocaleReturn => {
10
+ return computed(() => {
11
+ return locale.value ?? inject(LOCALE, navigator.language);
12
+ });
13
+ };
@@ -0,0 +1,83 @@
1
+ import { MaybeElementRef, useMutationObserver, useResizeObserver } from '@vueuse/core';
2
+ import { Ref, UnwrapRef, isRef, ref, watch } from 'vue';
3
+ import { requestAF } from '../utils';
4
+
5
+ export type UseOverflowReturn = {
6
+ innerItems: Ref<HTMLElement[]>;
7
+ outerItems: Ref<HTMLElement[]>;
8
+ };
9
+
10
+ export interface UseOverflowOptions {
11
+ hide?: boolean;
12
+ threshold?: number;
13
+ }
14
+ export const useOverflow = (
15
+ container: MaybeElementRef<HTMLElement | undefined>,
16
+ options: UseOverflowOptions = {},
17
+ ): UseOverflowReturn => {
18
+ const { hide = true, threshold = 0 } = options;
19
+ const containerRef = isRef(container) ? container : ref(container);
20
+
21
+ // State
22
+ const innerItemsRef = ref<HTMLElement[]>([]);
23
+ const outerItemsRef = ref<HTMLElement[]>([]);
24
+
25
+ // Functions
26
+ function updateState(): void {
27
+ const container = containerRef.value;
28
+
29
+ if (container) {
30
+ const update = [...container.children].reduce(({ innerItems, outerItems }, child) => {
31
+ const item = child as HTMLElement;
32
+
33
+ const { x: itemOffset, width: itemWidth } = item.getBoundingClientRect();
34
+ const { x: containerOffset, width: containerWidth } = container.getBoundingClientRect();
35
+
36
+ if (itemOffset + itemWidth > containerOffset + containerWidth + threshold) {
37
+ if (hide) {
38
+ item.style.setProperty('visibility', 'hidden');
39
+ }
40
+
41
+ return {
42
+ innerItems,
43
+ outerItems: [...outerItems, item],
44
+ };
45
+ } else {
46
+ if (hide) {
47
+ item.style.removeProperty('visibility');
48
+ }
49
+
50
+ return {
51
+ innerItems: [...innerItems, item],
52
+ outerItems,
53
+ };
54
+ }
55
+ }, {
56
+ innerItems: [],
57
+ outerItems: [],
58
+ } as UnwrapRef<UseOverflowReturn>);
59
+
60
+ innerItemsRef.value = update.innerItems;
61
+ outerItemsRef.value = update.outerItems;
62
+ } else {
63
+ innerItemsRef.value = [];
64
+ outerItemsRef.value = [];
65
+ }
66
+ }
67
+
68
+ // Effects
69
+ watch(containerRef, updateState, {
70
+ immediate: true,
71
+ });
72
+
73
+ useMutationObserver(containerRef as Ref, updateState, {
74
+ childList: true,
75
+ });
76
+
77
+ useResizeObserver(containerRef as Ref, () => requestAF(updateState));
78
+
79
+ return {
80
+ innerItems: innerItemsRef as Ref<HTMLElement[]>,
81
+ outerItems: outerItemsRef as Ref<HTMLElement[]>,
82
+ };
83
+ };