@db-ux/react-core-components 4.9.1 → 4.10.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 (131) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +97 -35
  3. package/dist/components/accordion/accordion.js +102 -86
  4. package/dist/components/accordion/model.js +4 -2
  5. package/dist/components/accordion-item/accordion-item.d.ts +2 -1
  6. package/dist/components/accordion-item/accordion-item.js +89 -56
  7. package/dist/components/accordion-item/model.d.ts +4 -0
  8. package/dist/components/badge/badge.js +72 -32
  9. package/dist/components/badge/model.js +12 -1
  10. package/dist/components/brand/brand.js +60 -13
  11. package/dist/components/button/button.js +75 -21
  12. package/dist/components/button/model.js +13 -2
  13. package/dist/components/card/card.js +65 -15
  14. package/dist/components/card/model.js +8 -2
  15. package/dist/components/checkbox/checkbox.js +163 -157
  16. package/dist/components/custom-button/custom-button.js +65 -10
  17. package/dist/components/custom-select/custom-select.js +509 -727
  18. package/dist/components/custom-select/model.js +8 -1
  19. package/dist/components/custom-select-dropdown/custom-select-dropdown.js +62 -11
  20. package/dist/components/custom-select-dropdown/model.js +8 -1
  21. package/dist/components/custom-select-form-field/custom-select-form-field.js +57 -10
  22. package/dist/components/custom-select-list/custom-select-list.js +60 -11
  23. package/dist/components/custom-select-list-item/custom-select-list-item.js +89 -32
  24. package/dist/components/custom-select-list-item/model.js +4 -1
  25. package/dist/components/divider/divider.js +60 -10
  26. package/dist/components/divider/model.js +4 -2
  27. package/dist/components/drawer/drawer.js +118 -97
  28. package/dist/components/drawer/model.js +14 -4
  29. package/dist/components/header/header.js +143 -65
  30. package/dist/components/icon/icon.js +61 -12
  31. package/dist/components/icon/model.js +11 -1
  32. package/dist/components/infotext/infotext.js +62 -12
  33. package/dist/components/input/input.js +198 -167
  34. package/dist/components/input/model.js +21 -5
  35. package/dist/components/link/link.js +70 -12
  36. package/dist/components/link/model.js +8 -3
  37. package/dist/components/navigation/navigation.js +57 -11
  38. package/dist/components/navigation-item/model.d.ts +4 -0
  39. package/dist/components/navigation-item/navigation-item.js +117 -81
  40. package/dist/components/notification/model.js +12 -3
  41. package/dist/components/notification/notification.js +100 -32
  42. package/dist/components/page/model.js +4 -2
  43. package/dist/components/page/page.js +74 -46
  44. package/dist/components/popover/popover.js +126 -125
  45. package/dist/components/radio/radio.js +124 -85
  46. package/dist/components/section/section.js +59 -10
  47. package/dist/components/select/select.js +188 -191
  48. package/dist/components/stack/model.js +14 -4
  49. package/dist/components/stack/stack.js +63 -10
  50. package/dist/components/switch/switch.js +182 -150
  51. package/dist/components/tab-item/tab-item.js +105 -76
  52. package/dist/components/tab-list/tab-list.js +60 -11
  53. package/dist/components/tab-panel/tab-panel.js +59 -13
  54. package/dist/components/tabs/model.js +4 -2
  55. package/dist/components/tabs/tabs.js +191 -178
  56. package/dist/components/tag/model.js +4 -1
  57. package/dist/components/tag/tag.js +91 -32
  58. package/dist/components/textarea/model.js +13 -2
  59. package/dist/components/textarea/textarea.js +165 -150
  60. package/dist/components/tooltip/model.js +4 -1
  61. package/dist/components/tooltip/tooltip.js +119 -115
  62. package/dist/index.js +64 -81
  63. package/dist/shared/constants.js +32 -94
  64. package/dist/shared/figma.d.ts +12 -6
  65. package/dist/shared/model.js +73 -22
  66. package/dist/utils/document-click-listener.js +26 -29
  67. package/dist/utils/document-scroll-listener.js +30 -38
  68. package/dist/utils/floating-components.js +107 -358
  69. package/dist/utils/form-components.js +34 -60
  70. package/dist/utils/index.js +49 -167
  71. package/dist/utils/navigation.js +68 -135
  72. package/dist/utils/react.js +10 -15
  73. package/package.json +11 -8
  74. package/dist/components/accordion/index.js +0 -1
  75. package/dist/components/accordion-item/index.js +0 -1
  76. package/dist/components/accordion-item/model.js +0 -1
  77. package/dist/components/badge/index.js +0 -1
  78. package/dist/components/brand/index.js +0 -1
  79. package/dist/components/brand/model.js +0 -1
  80. package/dist/components/button/index.js +0 -1
  81. package/dist/components/card/index.js +0 -1
  82. package/dist/components/checkbox/index.js +0 -1
  83. package/dist/components/checkbox/model.js +0 -1
  84. package/dist/components/custom-button/index.js +0 -1
  85. package/dist/components/custom-button/model.js +0 -1
  86. package/dist/components/custom-select/index.js +0 -1
  87. package/dist/components/custom-select-dropdown/index.js +0 -1
  88. package/dist/components/custom-select-form-field/index.js +0 -1
  89. package/dist/components/custom-select-form-field/model.js +0 -1
  90. package/dist/components/custom-select-list/index.js +0 -1
  91. package/dist/components/custom-select-list/model.js +0 -1
  92. package/dist/components/custom-select-list-item/index.js +0 -1
  93. package/dist/components/divider/index.js +0 -1
  94. package/dist/components/drawer/index.js +0 -1
  95. package/dist/components/header/index.js +0 -1
  96. package/dist/components/header/model.js +0 -1
  97. package/dist/components/icon/index.js +0 -1
  98. package/dist/components/infotext/index.js +0 -1
  99. package/dist/components/infotext/model.js +0 -1
  100. package/dist/components/input/index.js +0 -1
  101. package/dist/components/link/index.js +0 -1
  102. package/dist/components/navigation/index.js +0 -1
  103. package/dist/components/navigation/model.js +0 -1
  104. package/dist/components/navigation-item/index.js +0 -1
  105. package/dist/components/navigation-item/model.js +0 -1
  106. package/dist/components/notification/index.js +0 -1
  107. package/dist/components/page/index.js +0 -1
  108. package/dist/components/popover/index.js +0 -1
  109. package/dist/components/popover/model.js +0 -1
  110. package/dist/components/radio/index.js +0 -1
  111. package/dist/components/radio/model.js +0 -1
  112. package/dist/components/section/index.js +0 -1
  113. package/dist/components/section/model.js +0 -1
  114. package/dist/components/select/index.js +0 -1
  115. package/dist/components/select/model.js +0 -1
  116. package/dist/components/stack/index.js +0 -1
  117. package/dist/components/switch/index.js +0 -1
  118. package/dist/components/switch/model.js +0 -1
  119. package/dist/components/tab-item/index.js +0 -1
  120. package/dist/components/tab-item/model.js +0 -1
  121. package/dist/components/tab-list/index.js +0 -1
  122. package/dist/components/tab-list/model.js +0 -1
  123. package/dist/components/tab-panel/index.js +0 -1
  124. package/dist/components/tab-panel/model.js +0 -1
  125. package/dist/components/tabs/index.js +0 -1
  126. package/dist/components/tag/index.js +0 -1
  127. package/dist/components/textarea/index.js +0 -1
  128. package/dist/components/tooltip/index.js +0 -1
  129. package/dist/shared/examples/index.js +0 -4
  130. package/dist/shared/figma.js +0 -1
  131. package/dist/shared/showcase/show-code-link.js +0 -51
@@ -1,152 +1,167 @@
1
1
  "use client";
2
- import * as React from "react";
3
- import { filterPassingProps, getRootProps } from "../../utils/react";
4
- import { useState, useRef, useEffect, forwardRef } from "react";
5
- import { DEFAULT_INVALID_MESSAGE, DEFAULT_INVALID_MESSAGE_ID_SUFFIX, DEFAULT_LABEL, DEFAULT_MESSAGE_ID_SUFFIX, DEFAULT_PLACEHOLDER, DEFAULT_ROWS, DEFAULT_VALID_MESSAGE, DEFAULT_VALID_MESSAGE_ID_SUFFIX, } from "../../shared/constants";
6
- import { cls, delay, getBoolean, getHideProp, getNumber, hasVoiceOver, stringPropVisible, } from "../../utils";
7
- import { addValueResetEventListener, } from "../../utils/form-components";
8
- import DBInfotext from "../infotext/infotext";
9
- import { useId } from "react";
10
- function DBTextareaFn(props, component) {
11
- var _a, _b, _c, _d, _e;
12
- const uuid = useId();
13
- const _ref = component || useRef(component);
14
- const [_id, set_id] = useState(() => undefined);
15
- const [_messageId, set_messageId] = useState(() => undefined);
16
- const [_validMessageId, set_validMessageId] = useState(() => undefined);
17
- const [_invalidMessageId, set_invalidMessageId] = useState(() => undefined);
18
- const [_invalidMessage, set_invalidMessage] = useState(() => undefined);
19
- const [_descByIds, set_descByIds] = useState(() => undefined);
20
- const [_value, set_value] = useState(() => "");
21
- const [_voiceOverFallback, set_voiceOverFallback] = useState(() => "");
22
- const [abortController, setAbortController] = useState(() => undefined);
23
- function hasValidState() {
24
- var _a;
25
- return !!((_a = props.validMessage) !== null && _a !== void 0 ? _a : props.validation === "valid");
26
- }
27
- function handleValidation() {
28
- var _a, _b, _c, _d;
29
- /* For a11y reasons we need to map the correct message with the textarea */
30
- if (!((_a = _ref.current) === null || _a === void 0 ? void 0 : _a.validity.valid) || props.validation === "invalid") {
31
- set_descByIds(_invalidMessageId);
32
- set_invalidMessage(props.invalidMessage ||
33
- ((_b = _ref.current) === null || _b === void 0 ? void 0 : _b.validationMessage) ||
34
- DEFAULT_INVALID_MESSAGE);
35
- if (hasVoiceOver()) {
36
- set_voiceOverFallback(_invalidMessage);
37
- delay(() => set_voiceOverFallback(""), 1000);
38
- }
39
- }
40
- else if (hasValidState() &&
41
- ((_c = _ref.current) === null || _c === void 0 ? void 0 : _c.validity.valid) &&
42
- (props.required || props.minLength || props.maxLength)) {
43
- set_descByIds(_validMessageId);
44
- if (hasVoiceOver()) {
45
- set_voiceOverFallback((_d = props.validMessage) !== null && _d !== void 0 ? _d : DEFAULT_VALID_MESSAGE);
46
- delay(() => set_voiceOverFallback(""), 1000);
47
- }
48
- }
49
- else if (stringPropVisible(props.message, props.showMessage)) {
50
- set_descByIds(_messageId);
51
- }
52
- else {
53
- set_descByIds(undefined);
54
- }
55
- }
56
- function handleInput(event, reset) {
57
- if (props.onInput) {
58
- props.onInput(event);
59
- }
60
- handleValidation();
61
- }
62
- function handleChange(event, reset) {
63
- if (props.onChange) {
64
- props.onChange(event);
65
- }
66
- handleValidation();
67
- }
68
- function handleBlur(event) {
69
- if (props.onBlur) {
70
- props.onBlur(event);
71
- }
72
- }
73
- function handleFocus(event) {
74
- if (props.onFocus) {
75
- props.onFocus(event);
76
- }
77
- }
78
- function resetIds() {
79
- var _a, _b, _c;
80
- const mId = (_c = (_a = props.id) !== null && _a !== void 0 ? _a : (_b = props.propOverrides) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : `textarea-${uuid}`;
81
- set_id(mId);
82
- set_messageId(mId + DEFAULT_MESSAGE_ID_SUFFIX);
83
- set_validMessageId(mId + DEFAULT_VALID_MESSAGE_ID_SUFFIX);
84
- set_invalidMessageId(mId + DEFAULT_INVALID_MESSAGE_ID_SUFFIX);
85
- }
86
- useEffect(() => {
87
- resetIds();
88
- set_invalidMessage(props.invalidMessage || DEFAULT_INVALID_MESSAGE);
89
- }, []);
90
- useEffect(() => {
91
- var _a, _b;
92
- if ((_a = props.id) !== null && _a !== void 0 ? _a : (_b = props.propOverrides) === null || _b === void 0 ? void 0 : _b.id) {
93
- resetIds();
94
- }
95
- }, [props.id, (_a = props.propOverrides) === null || _a === void 0 ? void 0 : _a.id]);
96
- useEffect(() => {
97
- var _a;
98
- set_invalidMessage(props.invalidMessage ||
99
- ((_a = _ref.current) === null || _a === void 0 ? void 0 : _a.validationMessage) ||
100
- DEFAULT_INVALID_MESSAGE);
101
- }, [_ref.current, props.invalidMessage]);
102
- useEffect(() => {
103
- if (_id) {
104
- const messageId = _id + DEFAULT_MESSAGE_ID_SUFFIX;
105
- set_messageId(messageId);
106
- set_validMessageId(_id + DEFAULT_VALID_MESSAGE_ID_SUFFIX);
107
- set_invalidMessageId(_id + DEFAULT_INVALID_MESSAGE_ID_SUFFIX);
108
- if (stringPropVisible(props.message, props.showMessage)) {
109
- set_descByIds(messageId);
110
- }
111
- handleValidation();
112
- }
113
- }, [_id]);
114
- useEffect(() => {
115
- set_value(props.value);
116
- }, [props.value]);
117
- useEffect(() => {
118
- // If angular uses ngModel value and _value are null
119
- // then the value will be set afterward and the _ref will be refreshed
120
- const addResetListener = true;
121
- if (_ref.current && addResetListener) {
122
- const defaultValue = props.defaultValue;
123
- let controller = abortController;
124
- if (!controller) {
125
- controller = new AbortController();
126
- setAbortController(controller);
127
- }
128
- addValueResetEventListener(_ref.current, {
129
- value: props.value,
130
- defaultValue,
131
- }, (event) => {
132
- handleChange(event, true);
133
- handleInput(event, true);
134
- }, controller.signal);
135
- }
136
- }, [_ref.current]);
137
- useEffect(() => {
138
- return () => {
139
- abortController === null || abortController === void 0 ? void 0 : abortController.abort();
140
- };
141
- }, []);
142
- return (React.createElement("div", Object.assign({}, getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), { className: cls("db-textarea", props.className), "data-variant": props.variant, "data-hide-asterisk": getHideProp(props.showRequiredAsterisk), "data-hide-label": getHideProp(props.showLabel) }),
143
- React.createElement("label", { htmlFor: _id }, (_b = props.label) !== null && _b !== void 0 ? _b : DEFAULT_LABEL),
144
- React.createElement("textarea", Object.assign({ "aria-invalid": props.validation === "invalid", "data-custom-validity": props.validation, "data-field-sizing": props.fieldSizing, ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), { id: _id, "data-resize": props.resize, "data-hide-resizer": getHideProp((_c = props.showResizer) !== null && _c !== void 0 ? _c : true), disabled: getBoolean(props.disabled, "disabled"), required: getBoolean(props.required, "required"), readOnly: getBoolean(props.readOnly, "readOnly") ||
145
- getBoolean(props.readonly, "readonly"), form: props.form, maxLength: getNumber(props.maxLength, props.maxlength), minLength: getNumber(props.minLength, props.minlength), name: props.name, wrap: props.wrap, spellCheck: props.spellCheck, autoComplete: props.autocomplete, onInput: (event) => handleInput(event), onChange: (event) => handleChange(event), onBlur: (event) => handleBlur(event), onFocus: (event) => handleFocus(event), value: props.value, "aria-describedby": (_d = props.ariaDescribedBy) !== null && _d !== void 0 ? _d : _descByIds, placeholder: (_e = props.placeholder) !== null && _e !== void 0 ? _e : DEFAULT_PLACEHOLDER, rows: getNumber(props.rows, DEFAULT_ROWS), cols: getNumber(props.cols) })),
146
- stringPropVisible(props.message, props.showMessage) ? (React.createElement(DBInfotext, { size: "small", icon: props.messageIcon, id: _messageId }, props.message)) : null,
147
- hasValidState() ? (React.createElement(DBInfotext, { size: "small", semantic: "successful", id: _validMessageId }, props.validMessage || DEFAULT_VALID_MESSAGE)) : null,
148
- React.createElement(DBInfotext, { size: "small", semantic: "critical", id: _invalidMessageId }, _invalidMessage),
149
- React.createElement("span", { "data-visually-hidden": "true", role: "status" }, _voiceOverFallback)));
2
+ import { filterPassingProps as e, getRootProps as t } from "../../utils/react.js";
3
+ import { cls as n, delay as r, getBoolean as i, getHideProp as a, getNumber as o, hasVoiceOver as s, stringPropVisible as c } from "../../utils/index.js";
4
+ import { DEFAULT_INVALID_MESSAGE_ID_SUFFIX as l, DEFAULT_MESSAGE_ID_SUFFIX as u, DEFAULT_VALID_MESSAGE_ID_SUFFIX as d } from "../../shared/constants.js";
5
+ import { addValueResetEventListener as f } from "../../utils/form-components.js";
6
+ import p from "../infotext/infotext.js";
7
+ import { forwardRef as m, useEffect as h, useId as g, useRef as _, useState as v } from "react";
8
+ import { jsx as y, jsxs as b } from "react/jsx-runtime";
9
+ //#region src/components/textarea/textarea.tsx
10
+ function x(m, x) {
11
+ let S = g(), C = x || _(x), [w, T] = v(() => void 0), [E, D] = v(() => void 0), [O, k] = v(() => void 0), [A, j] = v(() => void 0), [M, N] = v(() => void 0), [P, F] = v(() => void 0), [I, L] = v(() => ""), [R, z] = v(() => ""), [B, V] = v(() => void 0);
12
+ function H() {
13
+ return !!(m.validMessage ?? m.validation === "valid");
14
+ }
15
+ function U() {
16
+ !C.current?.validity.valid || m.validation === "invalid" ? (F(A), N(m.invalidMessage || C.current?.validationMessage || "TODO: Add an invalidMessage"), s() && (z(M), r(() => z(""), 1e3))) : H() && C.current?.validity.valid && (m.required || m.minLength || m.maxLength) ? (F(O), s() && (z(m.validMessage ?? "TODO: Add a validMessage"), r(() => z(""), 1e3))) : c(m.message, m.showMessage) ? F(E) : F(void 0);
17
+ }
18
+ function W(e, t) {
19
+ m.onInput && m.onInput(e), U();
20
+ }
21
+ function G(e, t) {
22
+ m.onChange && m.onChange(e), U();
23
+ }
24
+ function K(e) {
25
+ m.onBlur && m.onBlur(e);
26
+ }
27
+ function q(e) {
28
+ m.onFocus && m.onFocus(e);
29
+ }
30
+ function J() {
31
+ let e = m.id ?? m.propOverrides?.id ?? `textarea-${S}`;
32
+ T(e), D(e + u), k(e + d), j(e + l);
33
+ }
34
+ return h(() => {
35
+ J(), N(m.invalidMessage || "TODO: Add an invalidMessage");
36
+ }, []), h(() => {
37
+ (m.id ?? m.propOverrides?.id) && J();
38
+ }, [m.id, m.propOverrides?.id]), h(() => {
39
+ N(m.invalidMessage || C.current?.validationMessage || "TODO: Add an invalidMessage");
40
+ }, [C.current, m.invalidMessage]), h(() => {
41
+ if (w) {
42
+ let e = w + u;
43
+ D(e), k(w + d), j(w + l), c(m.message, m.showMessage) && F(e), U();
44
+ }
45
+ }, [w]), h(() => {
46
+ L(m.value);
47
+ }, [m.value]), h(() => {
48
+ if (C.current) {
49
+ let e = m.defaultValue, t = B;
50
+ t || (t = new AbortController(), V(t)), f(C.current, {
51
+ value: m.value,
52
+ defaultValue: e
53
+ }, (e) => {
54
+ G(e, !0), W(e, !0);
55
+ }, t.signal);
56
+ }
57
+ }, [C.current]), h(() => () => {
58
+ B?.abort();
59
+ }, []), /* @__PURE__ */ b("div", {
60
+ ...t(m, [
61
+ "data-icon-variant",
62
+ "data-icon-variant-before",
63
+ "data-icon-variant-after",
64
+ "data-icon-weight",
65
+ "data-icon-weight-before",
66
+ "data-icon-weight-after",
67
+ "data-interactive",
68
+ "data-force-mobile",
69
+ "data-color",
70
+ "data-container-color",
71
+ "data-bg-color",
72
+ "data-on-bg-color",
73
+ "data-color-scheme",
74
+ "data-font-size",
75
+ "data-headline-size",
76
+ "data-divider",
77
+ "data-focus",
78
+ "data-font",
79
+ "data-density"
80
+ ]),
81
+ className: n("db-textarea", m.className),
82
+ "data-variant": m.variant,
83
+ "data-hide-asterisk": a(m.showRequiredAsterisk),
84
+ "data-hide-label": a(m.showLabel),
85
+ children: [
86
+ /* @__PURE__ */ y("label", {
87
+ htmlFor: w,
88
+ children: m.label ?? "LABEL SHOULD BE SET"
89
+ }),
90
+ /* @__PURE__ */ y("textarea", {
91
+ "aria-invalid": m.validation === "invalid",
92
+ "data-custom-validity": m.validation,
93
+ "data-field-sizing": m.fieldSizing,
94
+ ref: C,
95
+ ...e(m, [
96
+ "data-icon-variant",
97
+ "data-icon-variant-before",
98
+ "data-icon-variant-after",
99
+ "data-icon-weight",
100
+ "data-icon-weight-before",
101
+ "data-icon-weight-after",
102
+ "data-interactive",
103
+ "data-force-mobile",
104
+ "data-color",
105
+ "data-container-color",
106
+ "data-bg-color",
107
+ "data-on-bg-color",
108
+ "data-color-scheme",
109
+ "data-font-size",
110
+ "data-headline-size",
111
+ "data-divider",
112
+ "data-focus",
113
+ "data-font",
114
+ "data-density"
115
+ ]),
116
+ id: w,
117
+ "data-resize": m.resize,
118
+ "data-hide-resizer": a(m.showResizer ?? !0),
119
+ disabled: i(m.disabled, "disabled"),
120
+ required: i(m.required, "required"),
121
+ readOnly: i(m.readOnly, "readOnly") || i(m.readonly, "readonly"),
122
+ form: m.form,
123
+ maxLength: o(m.maxLength, m.maxlength),
124
+ minLength: o(m.minLength, m.minlength),
125
+ name: m.name,
126
+ wrap: m.wrap,
127
+ spellCheck: m.spellCheck,
128
+ autoComplete: m.autocomplete,
129
+ onInput: (e) => W(e),
130
+ onChange: (e) => G(e),
131
+ onBlur: (e) => K(e),
132
+ onFocus: (e) => q(e),
133
+ value: m.value,
134
+ "aria-describedby": m.ariaDescribedBy ?? P,
135
+ placeholder: m.placeholder ?? " ",
136
+ rows: o(m.rows, 4),
137
+ cols: o(m.cols)
138
+ }),
139
+ c(m.message, m.showMessage) ? /* @__PURE__ */ y(p, {
140
+ size: "small",
141
+ icon: m.messageIcon,
142
+ id: E,
143
+ children: m.message
144
+ }) : null,
145
+ H() ? /* @__PURE__ */ y(p, {
146
+ size: "small",
147
+ semantic: "successful",
148
+ id: O,
149
+ children: m.validMessage || "TODO: Add a validMessage"
150
+ }) : null,
151
+ /* @__PURE__ */ y(p, {
152
+ size: "small",
153
+ semantic: "critical",
154
+ id: A,
155
+ children: M
156
+ }),
157
+ /* @__PURE__ */ y("span", {
158
+ "data-visually-hidden": "true",
159
+ role: "status",
160
+ children: R
161
+ })
162
+ ]
163
+ });
150
164
  }
151
- const DBTextarea = forwardRef(DBTextareaFn);
152
- export default DBTextarea;
165
+ var S = m(x);
166
+ //#endregion
167
+ export { S as default };
@@ -1 +1,4 @@
1
- export const TooltipVariantList = ['description', 'label'];
1
+ //#region src/components/tooltip/model.ts
2
+ var e = ["description", "label"];
3
+ //#endregion
4
+ export { e as TooltipVariantList };
@@ -1,117 +1,121 @@
1
1
  "use client";
2
- import * as React from "react";
3
- import { filterPassingProps, getRootProps } from "../../utils/react";
4
- import { useState, useRef, useEffect, forwardRef } from "react";
5
- import { DEFAULT_ID } from "../../shared/constants";
6
- import { cls, getBooleanAsString, delay as utilsDelay } from "../../utils";
7
- import { DocumentScrollListener } from "../../utils/document-scroll-listener";
8
- import { handleFixedPopover } from "../../utils/floating-components";
9
- import { useId } from "react";
10
- function DBTooltipFn(props, component) {
11
- var _a, _b, _c;
12
- const uuid = useId();
13
- const _ref = component || useRef(component);
14
- const [_id, set_id] = useState(() => DEFAULT_ID);
15
- const [initialized, setInitialized] = useState(() => false);
16
- const [_documentScrollListenerCallbackId, set_documentScrollListenerCallbackId,] = useState(() => undefined);
17
- const [_observer, set_observer] = useState(() => undefined);
18
- function handleClick(event) {
19
- event.stopPropagation();
20
- }
21
- function handleEscape(event) {
22
- if ((!event || event.key === "Escape") &&
23
- _ref.current &&
24
- getComputedStyle(_ref.current).visibility === "visible") {
25
- getParent().blur();
26
- }
27
- }
28
- function getParent() {
29
- let parent = _ref.current.parentElement;
30
- if (parent && parent.localName.includes("tooltip")) {
31
- // Angular workaround
32
- parent = parent.parentElement;
33
- }
34
- return parent;
35
- }
36
- function handleAutoPlacement(parent) {
37
- if (!parent)
38
- return;
39
- if (_ref.current) {
40
- // This is a workaround for angular
41
- void utilsDelay(() => {
42
- var _a;
43
- // Due to race conditions we need to check for _ref again
44
- if (_ref.current) {
45
- handleFixedPopover(_ref.current, parent, (_a = props.placement) !== null && _a !== void 0 ? _a : "bottom");
46
- }
47
- }, 1);
48
- }
49
- }
50
- function handleDocumentScroll(event, parent) {
51
- var _a, _b;
52
- if (((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.contains) && ((_b = event === null || event === void 0 ? void 0 : event.target) === null || _b === void 0 ? void 0 : _b.contains(_ref.current))) {
53
- handleAutoPlacement(parent);
54
- }
55
- }
56
- function handleLeave() {
57
- if (_documentScrollListenerCallbackId) {
58
- new DocumentScrollListener().removeCallback(_documentScrollListenerCallbackId);
59
- }
60
- _observer === null || _observer === void 0 ? void 0 : _observer.unobserve(getParent());
61
- }
62
- function handleEnter(parent) {
63
- set_documentScrollListenerCallbackId(new DocumentScrollListener().addCallback((event) => handleDocumentScroll(event, parent)));
64
- handleAutoPlacement(parent);
65
- _observer === null || _observer === void 0 ? void 0 : _observer.observe(getParent());
66
- }
67
- function resetIds() {
68
- var _a, _b, _c;
69
- set_id((_c = (_a = props.id) !== null && _a !== void 0 ? _a : (_b = props.propOverrides) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : "tooltip-" + uuid);
70
- }
71
- useEffect(() => {
72
- resetIds();
73
- setInitialized(true);
74
- }, []);
75
- useEffect(() => {
76
- var _a, _b;
77
- if ((_a = props.id) !== null && _a !== void 0 ? _a : (_b = props.propOverrides) === null || _b === void 0 ? void 0 : _b.id) {
78
- resetIds();
79
- }
80
- }, [props.id, (_a = props.propOverrides) === null || _a === void 0 ? void 0 : _a.id]);
81
- useEffect(() => {
82
- if (_ref.current && initialized && _id) {
83
- const parent = getParent();
84
- if (parent) {
85
- handleAutoPlacement(parent);
86
- ["mouseenter", "focusin"].forEach((event) => {
87
- parent.addEventListener(event, () => handleEnter(parent));
88
- });
89
- parent.addEventListener("keydown", (event) => handleEscape(event));
90
- ["mouseleave", "focusout"].forEach((event) => {
91
- parent.addEventListener(event, () => handleLeave());
92
- });
93
- parent.dataset["hasTooltip"] = "true";
94
- if (props.variant === "label") {
95
- parent.setAttribute("aria-labelledby", _id);
96
- }
97
- else {
98
- parent.setAttribute("aria-describedby", _id);
99
- }
100
- }
101
- if (typeof window !== "undefined" && "IntersectionObserver" in window) {
102
- set_observer(new IntersectionObserver((payload) => {
103
- const entry = payload.find(({ target }) => target === getParent());
104
- if (entry && !entry.isIntersecting) {
105
- handleEscape(false);
106
- }
107
- }));
108
- }
109
- setInitialized(false);
110
- }
111
- }, [_ref.current, initialized, _id]);
112
- return (React.createElement("i", Object.assign({ role: "tooltip", "aria-hidden": "true", "data-gap": "true", ref: _ref }, filterPassingProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), getRootProps(props, ["data-icon-variant", "data-icon-variant-before", "data-icon-variant-after", "data-icon-weight", "data-icon-weight-before", "data-icon-weight-after", "data-interactive", "data-force-mobile", "data-color", "data-container-color", "data-bg-color", "data-on-bg-color", "data-color-scheme", "data-font-size", "data-headline-size", "data-divider", "data-focus", "data-font", "data-density"]), { className: cls("db-tooltip", props.className), id: _id, "data-emphasis": props.emphasis, "data-wrap": getBooleanAsString(props.wrap), "data-animation": getBooleanAsString((_b = props.animation) !== null && _b !== void 0 ? _b : true), "data-delay": props.delay, "data-width": props.width, "data-show-arrow": getBooleanAsString((_c = props.showArrow) !== null && _c !== void 0 ? _c : true), "data-placement": props.placement, onClick: (event) => handleClick(event) }),
113
- props.text ? React.createElement(React.Fragment, null, props.text) : null,
114
- props.children));
2
+ import { filterPassingProps as e, getRootProps as t } from "../../utils/react.js";
3
+ import { cls as n, delay as r, getBooleanAsString as i } from "../../utils/index.js";
4
+ import { DEFAULT_ID as a } from "../../shared/constants.js";
5
+ import { DocumentScrollListener as o } from "../../utils/document-scroll-listener.js";
6
+ import { handleFixedPopover as s } from "../../utils/floating-components.js";
7
+ import { forwardRef as c, useEffect as l, useId as u, useRef as d, useState as f } from "react";
8
+ import { Fragment as p, jsx as m, jsxs as h } from "react/jsx-runtime";
9
+ //#region src/components/tooltip/tooltip.tsx
10
+ function g(c, g) {
11
+ let _ = u(), v = g || d(g), [y, b] = f(() => a), [x, S] = f(() => !1), [C, w] = f(() => void 0), [T, E] = f(() => void 0);
12
+ function D(e) {
13
+ e.stopPropagation();
14
+ }
15
+ function O(e) {
16
+ (!e || e.key === "Escape") && v.current && getComputedStyle(v.current).visibility === "visible" && k().blur();
17
+ }
18
+ function k() {
19
+ let e = v.current.parentElement;
20
+ return e && e.localName.includes("tooltip") && (e = e.parentElement), e;
21
+ }
22
+ function A(e) {
23
+ e && v.current && r(() => {
24
+ v.current && s(v.current, e, c.placement ?? "bottom");
25
+ }, 1);
26
+ }
27
+ function j(e, t) {
28
+ e?.target?.contains && e?.target?.contains(v.current) && A(t);
29
+ }
30
+ function M() {
31
+ C && new o().removeCallback(C), T?.unobserve(k());
32
+ }
33
+ function N(e) {
34
+ w(new o().addCallback((t) => j(t, e))), A(e), T?.observe(k());
35
+ }
36
+ function P() {
37
+ b(c.id ?? c.propOverrides?.id ?? "tooltip-" + _);
38
+ }
39
+ return l(() => {
40
+ P(), S(!0);
41
+ }, []), l(() => {
42
+ (c.id ?? c.propOverrides?.id) && P();
43
+ }, [c.id, c.propOverrides?.id]), l(() => {
44
+ if (v.current && x && y) {
45
+ let e = k();
46
+ e && (A(e), ["mouseenter", "focusin"].forEach((t) => {
47
+ e.addEventListener(t, () => N(e));
48
+ }), e.addEventListener("keydown", (e) => O(e)), ["mouseleave", "focusout"].forEach((t) => {
49
+ e.addEventListener(t, () => M());
50
+ }), e.dataset.hasTooltip = "true", c.variant === "label" ? e.setAttribute("aria-labelledby", y) : e.setAttribute("aria-describedby", y)), typeof window < "u" && "IntersectionObserver" in window && E(new IntersectionObserver((e) => {
51
+ let t = e.find(({ target: e }) => e === k());
52
+ t && !t.isIntersecting && O(!1);
53
+ })), S(!1);
54
+ }
55
+ }, [
56
+ v.current,
57
+ x,
58
+ y
59
+ ]), /* @__PURE__ */ h("i", {
60
+ role: "tooltip",
61
+ "aria-hidden": "true",
62
+ "data-gap": "true",
63
+ ref: v,
64
+ ...e(c, [
65
+ "data-icon-variant",
66
+ "data-icon-variant-before",
67
+ "data-icon-variant-after",
68
+ "data-icon-weight",
69
+ "data-icon-weight-before",
70
+ "data-icon-weight-after",
71
+ "data-interactive",
72
+ "data-force-mobile",
73
+ "data-color",
74
+ "data-container-color",
75
+ "data-bg-color",
76
+ "data-on-bg-color",
77
+ "data-color-scheme",
78
+ "data-font-size",
79
+ "data-headline-size",
80
+ "data-divider",
81
+ "data-focus",
82
+ "data-font",
83
+ "data-density"
84
+ ]),
85
+ ...t(c, [
86
+ "data-icon-variant",
87
+ "data-icon-variant-before",
88
+ "data-icon-variant-after",
89
+ "data-icon-weight",
90
+ "data-icon-weight-before",
91
+ "data-icon-weight-after",
92
+ "data-interactive",
93
+ "data-force-mobile",
94
+ "data-color",
95
+ "data-container-color",
96
+ "data-bg-color",
97
+ "data-on-bg-color",
98
+ "data-color-scheme",
99
+ "data-font-size",
100
+ "data-headline-size",
101
+ "data-divider",
102
+ "data-focus",
103
+ "data-font",
104
+ "data-density"
105
+ ]),
106
+ className: n("db-tooltip", c.className),
107
+ id: y,
108
+ "data-emphasis": c.emphasis,
109
+ "data-wrap": i(c.wrap),
110
+ "data-animation": i(c.animation ?? !0),
111
+ "data-delay": c.delay,
112
+ "data-width": c.width,
113
+ "data-show-arrow": i(c.showArrow ?? !0),
114
+ "data-placement": c.placement,
115
+ onClick: (e) => D(e),
116
+ children: [c.text ? /* @__PURE__ */ m(p, { children: c.text }) : null, c.children]
117
+ });
115
118
  }
116
- const DBTooltip = forwardRef(DBTooltipFn);
117
- export default DBTooltip;
119
+ var _ = c(g);
120
+ //#endregion
121
+ export { _ as default };