@iabbb/bds-react 0.48.0 → 0.49.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.
- package/FieldCharacterCountdown/FieldCharacterCountdown.d.ts +10 -0
- package/FieldCharacterCountdown/index.cjs +257 -0
- package/FieldCharacterCountdown/index.cjs.map +1 -0
- package/FieldCharacterCountdown/index.d.ts +2 -0
- package/FieldCharacterCountdown/index.mjs +233 -0
- package/FieldCharacterCountdown/index.mjs.map +1 -0
- package/FieldCharacterCountdown/package.json +7 -0
- package/FieldCharacterCountdown/useCharacterCountdown.d.ts +7 -0
- package/package.json +7 -7
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type FieldCharacterCountdownProps = {
|
|
3
|
+
error?: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
id?: string;
|
|
6
|
+
isOptional?: boolean;
|
|
7
|
+
label: string;
|
|
8
|
+
maxCharacters: number;
|
|
9
|
+
};
|
|
10
|
+
export default function FieldCharacterCountdown({ error, hint, id, isOptional, label, maxCharacters, onChange, ...props }: FieldCharacterCountdownProps & React.ComponentPropsWithoutRef<'textarea'>): React.JSX.Element;
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
25
|
+
|
|
26
|
+
function _arrayLikeToArray(r, a) {
|
|
27
|
+
(null == a || a > r.length) && (a = r.length);
|
|
28
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
29
|
+
return n;
|
|
30
|
+
}
|
|
31
|
+
function _arrayWithHoles(r) {
|
|
32
|
+
if (Array.isArray(r)) return r;
|
|
33
|
+
}
|
|
34
|
+
function _extends() {
|
|
35
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
36
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
37
|
+
var t = arguments[e];
|
|
38
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
39
|
+
}
|
|
40
|
+
return n;
|
|
41
|
+
}, _extends.apply(null, arguments);
|
|
42
|
+
}
|
|
43
|
+
function _iterableToArrayLimit(r, l) {
|
|
44
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
45
|
+
if (null != t) {
|
|
46
|
+
var e,
|
|
47
|
+
n,
|
|
48
|
+
i,
|
|
49
|
+
u,
|
|
50
|
+
a = [],
|
|
51
|
+
f = !0,
|
|
52
|
+
o = !1;
|
|
53
|
+
try {
|
|
54
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
55
|
+
} catch (r) {
|
|
56
|
+
o = !0, n = r;
|
|
57
|
+
} finally {
|
|
58
|
+
try {
|
|
59
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
60
|
+
} finally {
|
|
61
|
+
if (o) throw n;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return a;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function _nonIterableRest() {
|
|
68
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
69
|
+
}
|
|
70
|
+
function _objectWithoutProperties(e, t) {
|
|
71
|
+
if (null == e) return {};
|
|
72
|
+
var o,
|
|
73
|
+
r,
|
|
74
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
75
|
+
if (Object.getOwnPropertySymbols) {
|
|
76
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
77
|
+
for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
78
|
+
}
|
|
79
|
+
return i;
|
|
80
|
+
}
|
|
81
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
82
|
+
if (null == r) return {};
|
|
83
|
+
var t = {};
|
|
84
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
85
|
+
if (e.indexOf(n) >= 0) continue;
|
|
86
|
+
t[n] = r[n];
|
|
87
|
+
}
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
function _slicedToArray(r, e) {
|
|
91
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
92
|
+
}
|
|
93
|
+
function _unsupportedIterableToArray(r, a) {
|
|
94
|
+
if (r) {
|
|
95
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
96
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
97
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var _excluded$1 = ["className", "children"];
|
|
102
|
+
function ErrorMessage(_ref) {
|
|
103
|
+
var className = _ref.className,
|
|
104
|
+
children = _ref.children,
|
|
105
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
106
|
+
return /*#__PURE__*/React__namespace.createElement("span", _extends({
|
|
107
|
+
className: ['bds-error', className].filter(function (x) {
|
|
108
|
+
return x;
|
|
109
|
+
}).join(' ')
|
|
110
|
+
}, props), /*#__PURE__*/React__namespace.createElement("svg", {
|
|
111
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
112
|
+
viewBox: "0 0 512 512",
|
|
113
|
+
"aria-hidden": "true",
|
|
114
|
+
height: "1em",
|
|
115
|
+
width: "1em",
|
|
116
|
+
fill: "currentColor"
|
|
117
|
+
}, /*#__PURE__*/React__namespace.createElement("path", {
|
|
118
|
+
d: "M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7.2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8.2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32 14.3 32 32 32 32-14.3 32-32z"
|
|
119
|
+
})), children);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
var visuallyHiddenAnnouncementUpdateTimeInSeconds = 1;
|
|
123
|
+
function useCharacterCountdown(maxCharacters) {
|
|
124
|
+
var currentCharacters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
125
|
+
var _React$useState = React__namespace.useState(maxCharacters - currentCharacters),
|
|
126
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
127
|
+
remainingCharacters = _React$useState2[0],
|
|
128
|
+
setRemainingCharacters = _React$useState2[1];
|
|
129
|
+
|
|
130
|
+
// When JS fails to load, the default label 👇 will still let the user know about the limit.
|
|
131
|
+
var _React$useState3 = React__namespace.useState("You can use up to ".concat(maxCharacters, " characters")),
|
|
132
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
133
|
+
label = _React$useState4[0],
|
|
134
|
+
setLabel = _React$useState4[1];
|
|
135
|
+
var _React$useState5 = React__namespace.useState(label),
|
|
136
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
137
|
+
visuallyHiddenAnnouncement = _React$useState6[0],
|
|
138
|
+
setVisuallyHiddenAnnouncement = _React$useState6[1];
|
|
139
|
+
|
|
140
|
+
// This should lag behind the visual update -- otherwise, screen reader users will be interrupted with a lot of chatter while typing
|
|
141
|
+
var updateVisuallyHiddenAnnouncement = useDebounce(function (charactersToAnnounce) {
|
|
142
|
+
if (charactersToAnnounce >= 0) {
|
|
143
|
+
setVisuallyHiddenAnnouncement("You have ".concat(charactersToAnnounce, " characters remaining"));
|
|
144
|
+
} else {
|
|
145
|
+
setVisuallyHiddenAnnouncement("You have ".concat(charactersToAnnounce * -1, " characters too many"));
|
|
146
|
+
}
|
|
147
|
+
}, visuallyHiddenAnnouncementUpdateTimeInSeconds * 1000);
|
|
148
|
+
React__namespace.useEffect(function () {
|
|
149
|
+
if (remainingCharacters >= 0) {
|
|
150
|
+
setLabel("<strong>".concat(remainingCharacters, "</strong> characters remaining"));
|
|
151
|
+
} else {
|
|
152
|
+
setLabel("You have <strong>".concat(remainingCharacters * -1, "</strong> characters too many"));
|
|
153
|
+
}
|
|
154
|
+
updateVisuallyHiddenAnnouncement(remainingCharacters);
|
|
155
|
+
}, [remainingCharacters, updateVisuallyHiddenAnnouncement]);
|
|
156
|
+
return {
|
|
157
|
+
hasExceededLimit: remainingCharacters < 0,
|
|
158
|
+
handleTextareaChange: function handleTextareaChange(e) {
|
|
159
|
+
setRemainingCharacters(maxCharacters - e.target.value.length);
|
|
160
|
+
},
|
|
161
|
+
label: label,
|
|
162
|
+
visuallyHiddenAnnouncement: visuallyHiddenAnnouncement
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Simple debounce implementation. Will call the given
|
|
168
|
+
* function once after the time given has passed since
|
|
169
|
+
* it was last called.
|
|
170
|
+
* Lifted from downshift/utils (not exposed in lib).
|
|
171
|
+
* @param {Function} fn the function to call after the time
|
|
172
|
+
* @param {Number} time the time to wait
|
|
173
|
+
* @return {Function} the debounced function
|
|
174
|
+
*/
|
|
175
|
+
// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts
|
|
176
|
+
function debounce(fn, time) {
|
|
177
|
+
var timeoutId = 0;
|
|
178
|
+
function cancel() {
|
|
179
|
+
if (timeoutId) {
|
|
180
|
+
clearTimeout(timeoutId);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function wrapper() {
|
|
184
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
185
|
+
args[_key] = arguments[_key];
|
|
186
|
+
}
|
|
187
|
+
cancel();
|
|
188
|
+
timeoutId = setTimeout(function () {
|
|
189
|
+
timeoutId = null;
|
|
190
|
+
fn.apply(void 0, args);
|
|
191
|
+
}, time);
|
|
192
|
+
}
|
|
193
|
+
wrapper.cancel = cancel;
|
|
194
|
+
return wrapper;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts
|
|
198
|
+
function useDebounce(callback, delay) {
|
|
199
|
+
return React__namespace.useRef(debounce(function () {
|
|
200
|
+
return callback.apply(void 0, arguments);
|
|
201
|
+
}, delay)).current;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var _excluded = ["error", "hint", "id", "isOptional", "label", "maxCharacters", "onChange"];
|
|
205
|
+
function FieldCharacterCountdown(_ref) {
|
|
206
|
+
var _id;
|
|
207
|
+
var error = _ref.error,
|
|
208
|
+
hint = _ref.hint,
|
|
209
|
+
id = _ref.id,
|
|
210
|
+
_ref$isOptional = _ref.isOptional,
|
|
211
|
+
isOptional = _ref$isOptional === void 0 ? false : _ref$isOptional,
|
|
212
|
+
label = _ref.label,
|
|
213
|
+
maxCharacters = _ref.maxCharacters,
|
|
214
|
+
_onChange = _ref.onChange,
|
|
215
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
216
|
+
var characterCountdown = useCharacterCountdown(maxCharacters, (props.value || '').length);
|
|
217
|
+
id = (_id = id) !== null && _id !== void 0 ? _id : props.name;
|
|
218
|
+
var errorId = React__namespace.useId();
|
|
219
|
+
var hintId = React__namespace.useId();
|
|
220
|
+
return /*#__PURE__*/React__namespace.createElement("div", {
|
|
221
|
+
className: "bds-form-group"
|
|
222
|
+
}, /*#__PURE__*/React__namespace.createElement("label", {
|
|
223
|
+
htmlFor: id
|
|
224
|
+
}, label, isOptional && ' (optional)'), hint && /*#__PURE__*/React__namespace.createElement("span", {
|
|
225
|
+
className: "bds-hint",
|
|
226
|
+
id: hintId
|
|
227
|
+
}, hint), error && /*#__PURE__*/React__namespace.createElement(ErrorMessage, {
|
|
228
|
+
id: errorId
|
|
229
|
+
}, error), /*#__PURE__*/React__namespace.createElement("textarea", _extends({
|
|
230
|
+
"aria-invalid": error ? true : undefined,
|
|
231
|
+
"aria-describedby": error && hint ? "".concat(hintId, " ").concat(errorId) : error ? errorId : hint ? hintId : undefined,
|
|
232
|
+
className: "bds-textarea",
|
|
233
|
+
id: id,
|
|
234
|
+
onChange: function onChange(e) {
|
|
235
|
+
if (_onChange) {
|
|
236
|
+
_onChange(e);
|
|
237
|
+
}
|
|
238
|
+
characterCountdown.handleTextareaChange(e);
|
|
239
|
+
}
|
|
240
|
+
}, props)), /*#__PURE__*/React__namespace.createElement("div", {
|
|
241
|
+
"aria-hidden": "true",
|
|
242
|
+
className: "bds-character-count",
|
|
243
|
+
"data-exceeds-limit": characterCountdown.hasExceededLimit ? true : undefined
|
|
244
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: HTML is expected and used for highlighting the number itself
|
|
245
|
+
,
|
|
246
|
+
dangerouslySetInnerHTML: {
|
|
247
|
+
__html: characterCountdown.label
|
|
248
|
+
}
|
|
249
|
+
}), /*#__PURE__*/React__namespace.createElement("div", {
|
|
250
|
+
"aria-live": "polite",
|
|
251
|
+
className: "visually-hidden"
|
|
252
|
+
}, characterCountdown.visuallyHiddenAnnouncement));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
exports.default = FieldCharacterCountdown;
|
|
256
|
+
exports.useCharacterCountdown = useCharacterCountdown;
|
|
257
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/ErrorMessage/ErrorMessage.tsx","../../src/FieldCharacterCountdown/useCharacterCountdown.ts","../../src/FieldCharacterCountdown/FieldCharacterCountdown.tsx"],"sourcesContent":["// biome-ignore lint/style/useImportType: following this rule does not work for some reason\nimport * as React from 'react';\n\nexport default function ErrorMessage({ className, children, ...props }: React.ComponentPropsWithoutRef<'span'>) {\n return (\n <span className={['bds-error', className].filter((x) => x).join(' ')} {...props}>\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 512 512\"\n aria-hidden=\"true\"\n height=\"1em\"\n width=\"1em\"\n fill=\"currentColor\"\n >\n <path d=\"M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7.2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8.2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32 14.3 32 32 32 32-14.3 32-32z\" />\n </svg>\n {children}\n </span>\n );\n}\n","import * as React from 'react';\n\nconst visuallyHiddenAnnouncementUpdateTimeInSeconds = 1;\n\nexport default function useCharacterCountdown(maxCharacters: number, currentCharacters = 0) {\n const [remainingCharacters, setRemainingCharacters] = React.useState(maxCharacters - currentCharacters);\n\n // When JS fails to load, the default label 👇 will still let the user know about the limit.\n const [label, setLabel] = React.useState(`You can use up to ${maxCharacters} characters`);\n const [visuallyHiddenAnnouncement, setVisuallyHiddenAnnouncement] = React.useState(label);\n\n // This should lag behind the visual update -- otherwise, screen reader users will be interrupted with a lot of chatter while typing\n const updateVisuallyHiddenAnnouncement = useDebounce((charactersToAnnounce: number) => {\n if (charactersToAnnounce >= 0) {\n setVisuallyHiddenAnnouncement(`You have ${charactersToAnnounce} characters remaining`);\n } else {\n setVisuallyHiddenAnnouncement(`You have ${charactersToAnnounce * -1} characters too many`);\n }\n }, visuallyHiddenAnnouncementUpdateTimeInSeconds * 1000);\n\n React.useEffect(() => {\n if (remainingCharacters >= 0) {\n setLabel(`<strong>${remainingCharacters}</strong> characters remaining`);\n } else {\n setLabel(`You have <strong>${remainingCharacters * -1}</strong> characters too many`);\n }\n\n updateVisuallyHiddenAnnouncement(remainingCharacters);\n }, [remainingCharacters, updateVisuallyHiddenAnnouncement]);\n\n return {\n hasExceededLimit: remainingCharacters < 0,\n handleTextareaChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n setRemainingCharacters(maxCharacters - e.target.value.length);\n },\n label,\n visuallyHiddenAnnouncement,\n };\n}\n\n/**\n * Simple debounce implementation. Will call the given\n * function once after the time given has passed since\n * it was last called.\n * Lifted from downshift/utils (not exposed in lib).\n * @param {Function} fn the function to call after the time\n * @param {Number} time the time to wait\n * @return {Function} the debounced function\n */\n// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts\nfunction debounce(fn: (...rest: any[]) => any, time: number) {\n let timeoutId: number | null = 0;\n\n function cancel() {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n\n function wrapper(...args) {\n cancel();\n timeoutId = setTimeout(() => {\n timeoutId = null;\n fn(...args);\n }, time);\n }\n\n wrapper.cancel = cancel;\n\n return wrapper;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts\nfunction useDebounce<T extends (...rest: any[]) => any>(callback: T, delay: number) {\n return React.useRef(debounce((...params) => callback(...params), delay)).current;\n}\n","import * as React from 'react';\n\nimport ErrorMessage from '../ErrorMessage';\nimport useCharacterCountdown from './useCharacterCountdown';\n\nexport type FieldCharacterCountdownProps = {\n error?: string;\n hint?: string;\n id?: string;\n isOptional?: boolean;\n label: string;\n maxCharacters: number;\n};\n\nexport default function FieldCharacterCountdown({\n error,\n hint,\n id,\n isOptional = false,\n label,\n maxCharacters,\n onChange,\n ...props\n}: FieldCharacterCountdownProps & React.ComponentPropsWithoutRef<'textarea'>) {\n const characterCountdown = useCharacterCountdown(maxCharacters, ((props.value as string) || '').length);\n\n id = id ?? props.name;\n\n const errorId = React.useId();\n const hintId = React.useId();\n\n return (\n <div className=\"bds-form-group\">\n <label htmlFor={id}>\n {label}\n {isOptional && ' (optional)'}\n </label>\n {hint && (\n <span className=\"bds-hint\" id={hintId}>\n {hint}\n </span>\n )}\n {error && <ErrorMessage id={errorId}>{error}</ErrorMessage>}\n <textarea\n aria-invalid={error ? true : undefined}\n aria-describedby={error && hint ? `${hintId} ${errorId}` : error ? errorId : hint ? hintId : undefined}\n className=\"bds-textarea\"\n id={id}\n onChange={(e) => {\n if (onChange) {\n onChange(e);\n }\n\n characterCountdown.handleTextareaChange(e);\n }}\n {...props}\n />\n <div\n aria-hidden=\"true\"\n className=\"bds-character-count\"\n data-exceeds-limit={characterCountdown.hasExceededLimit ? true : undefined}\n // biome-ignore lint/security/noDangerouslySetInnerHtml: HTML is expected and used for highlighting the number itself\n dangerouslySetInnerHTML={{\n __html: characterCountdown.label,\n }}\n />\n <div aria-live=\"polite\" className=\"visually-hidden\">\n {characterCountdown.visuallyHiddenAnnouncement}\n </div>\n </div>\n );\n}\n"],"names":["ErrorMessage","_ref","className","children","props","_objectWithoutProperties","_excluded","React","createElement","_extends","filter","x","join","xmlns","viewBox","height","width","fill","d","visuallyHiddenAnnouncementUpdateTimeInSeconds","useCharacterCountdown","maxCharacters","currentCharacters","arguments","length","undefined","_React$useState","useState","_React$useState2","_slicedToArray","remainingCharacters","setRemainingCharacters","_React$useState3","concat","_React$useState4","label","setLabel","_React$useState5","_React$useState6","visuallyHiddenAnnouncement","setVisuallyHiddenAnnouncement","updateVisuallyHiddenAnnouncement","useDebounce","charactersToAnnounce","useEffect","hasExceededLimit","handleTextareaChange","e","target","value","debounce","fn","time","timeoutId","cancel","clearTimeout","wrapper","_len","args","Array","_key","setTimeout","apply","callback","delay","useRef","current","FieldCharacterCountdown","_id","error","hint","id","_ref$isOptional","isOptional","onChange","characterCountdown","name","errorId","useId","hintId","htmlFor","dangerouslySetInnerHTML","__html"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGe,SAASA,YAAYA,CAAAC,IAAA,EAA4E;AAAA,EAAA,IAAzEC,SAAS,GAAAD,IAAA,CAATC,SAAS;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;AAAKC,IAAAA,KAAK,GAAAC,wBAAA,CAAAJ,IAAA,EAAAK,WAAA,CAAA,CAAA;AAClE,EAAA,oBACEC,gBAAA,CAAAC,aAAA,CAAA,MAAA,EAAAC,QAAA,CAAA;IAAMP,SAAS,EAAE,CAAC,WAAW,EAAEA,SAAS,CAAC,CAACQ,MAAM,CAAC,UAACC,CAAC,EAAA;AAAA,MAAA,OAAKA,CAAC,CAAA;KAAC,CAAA,CAACC,IAAI,CAAC,GAAG,CAAA;AAAE,GAAA,EAAKR,KAAK,CAAA,eAC7EG,gBAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AACEK,IAAAA,KAAK,EAAC,4BAA4B;AAClCC,IAAAA,OAAO,EAAC,aAAa;AACrB,IAAA,aAAA,EAAY,MAAM;AAClBC,IAAAA,MAAM,EAAC,KAAK;AACZC,IAAAA,KAAK,EAAC,KAAK;AACXC,IAAAA,IAAI,EAAC,cAAA;GAEL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AA,EAAc4D,KAAK,GAAG,IAAI,GAAG5C,SAAU;IACvC,kBAAkB4C,EAAAA,KAAK,IAAIC,IAAI,GAAA,EAAA,CAAArC,MAAA,CAAM8C,MAAM,OAAA9C,MAAA,CAAI4C,OAAO,CAAKR,GAAAA,KAAK,GAAGQ,OAAO,GAAGP,IAAI,GAAGS,MAAM,GAAGtD,SAAU;AACvGvB,IAAAA,SAAS,EAAC,cAAc;AACxBqE,IAAAA,EAAE,EAAEA,EAAG;AACPG,IAAAA,QAAQ,EAAE,SAAAA,QAAC3B,CAAAA,CAAC,EAAK;AACf,MAAA,IAAI2B,SAAQ,EAAE;QACZA,SAAQ,CAAC3B,CAAC,CAAC,CAAA;AACb,OAAA;AAEA4B,MAAAA,kBAAkB,CAAC7B,oBAAoB,CAACC,CAAC,CAAC,CAAA;AAC5C,KAAA;AAAE,GAAA,EACE3C,KAAK,CACV,CAAC,eACFG,gBAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AACE,IAAA,aAAA,EAAY,MAAM;AAClBN,IAAAA,SAAS,EAAC,qBAAqB;AAC/B,IAAA,oBAAA,EAAoByE,kBAAkB,CAAC9B,gBAAgB,GAAG,IAAI,GAAGpB,SAAAA;AACjE;AAAA;AACAwD,IAAAA,uBAAuB,EAAE;MACvBC,MAAM,EAAEP,kBAAkB,CAACxC,KAAAA;AAC7B,KAAA;AAAE,GACH,CAAC,eACF5B,gBAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AAAK,IAAA,WAAA,EAAU,QAAQ;AAACN,IAAAA,SAAS,EAAC,iBAAA;AAAiB,GAAA,EAChDyE,kBAAkB,CAACpC,0BACjB,CACF,CAAC,CAAA;AAEV;;;;;"}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
function _arrayLikeToArray(r, a) {
|
|
4
|
+
(null == a || a > r.length) && (a = r.length);
|
|
5
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function _arrayWithHoles(r) {
|
|
9
|
+
if (Array.isArray(r)) return r;
|
|
10
|
+
}
|
|
11
|
+
function _extends() {
|
|
12
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
13
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
14
|
+
var t = arguments[e];
|
|
15
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
18
|
+
}, _extends.apply(null, arguments);
|
|
19
|
+
}
|
|
20
|
+
function _iterableToArrayLimit(r, l) {
|
|
21
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
22
|
+
if (null != t) {
|
|
23
|
+
var e,
|
|
24
|
+
n,
|
|
25
|
+
i,
|
|
26
|
+
u,
|
|
27
|
+
a = [],
|
|
28
|
+
f = !0,
|
|
29
|
+
o = !1;
|
|
30
|
+
try {
|
|
31
|
+
if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
32
|
+
} catch (r) {
|
|
33
|
+
o = !0, n = r;
|
|
34
|
+
} finally {
|
|
35
|
+
try {
|
|
36
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
37
|
+
} finally {
|
|
38
|
+
if (o) throw n;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return a;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function _nonIterableRest() {
|
|
45
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
46
|
+
}
|
|
47
|
+
function _objectWithoutProperties(e, t) {
|
|
48
|
+
if (null == e) return {};
|
|
49
|
+
var o,
|
|
50
|
+
r,
|
|
51
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
52
|
+
if (Object.getOwnPropertySymbols) {
|
|
53
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
54
|
+
for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
55
|
+
}
|
|
56
|
+
return i;
|
|
57
|
+
}
|
|
58
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
59
|
+
if (null == r) return {};
|
|
60
|
+
var t = {};
|
|
61
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
62
|
+
if (e.indexOf(n) >= 0) continue;
|
|
63
|
+
t[n] = r[n];
|
|
64
|
+
}
|
|
65
|
+
return t;
|
|
66
|
+
}
|
|
67
|
+
function _slicedToArray(r, e) {
|
|
68
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
69
|
+
}
|
|
70
|
+
function _unsupportedIterableToArray(r, a) {
|
|
71
|
+
if (r) {
|
|
72
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
73
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
74
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var _excluded$1 = ["className", "children"];
|
|
79
|
+
function ErrorMessage(_ref) {
|
|
80
|
+
var className = _ref.className,
|
|
81
|
+
children = _ref.children,
|
|
82
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
83
|
+
return /*#__PURE__*/React.createElement("span", _extends({
|
|
84
|
+
className: ['bds-error', className].filter(function (x) {
|
|
85
|
+
return x;
|
|
86
|
+
}).join(' ')
|
|
87
|
+
}, props), /*#__PURE__*/React.createElement("svg", {
|
|
88
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
89
|
+
viewBox: "0 0 512 512",
|
|
90
|
+
"aria-hidden": "true",
|
|
91
|
+
height: "1em",
|
|
92
|
+
width: "1em",
|
|
93
|
+
fill: "currentColor"
|
|
94
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
95
|
+
d: "M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7.2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8.2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32 14.3 32 32 32 32-14.3 32-32z"
|
|
96
|
+
})), children);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
var visuallyHiddenAnnouncementUpdateTimeInSeconds = 1;
|
|
100
|
+
function useCharacterCountdown(maxCharacters) {
|
|
101
|
+
var currentCharacters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
102
|
+
var _React$useState = React.useState(maxCharacters - currentCharacters),
|
|
103
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
104
|
+
remainingCharacters = _React$useState2[0],
|
|
105
|
+
setRemainingCharacters = _React$useState2[1];
|
|
106
|
+
|
|
107
|
+
// When JS fails to load, the default label 👇 will still let the user know about the limit.
|
|
108
|
+
var _React$useState3 = React.useState("You can use up to ".concat(maxCharacters, " characters")),
|
|
109
|
+
_React$useState4 = _slicedToArray(_React$useState3, 2),
|
|
110
|
+
label = _React$useState4[0],
|
|
111
|
+
setLabel = _React$useState4[1];
|
|
112
|
+
var _React$useState5 = React.useState(label),
|
|
113
|
+
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
114
|
+
visuallyHiddenAnnouncement = _React$useState6[0],
|
|
115
|
+
setVisuallyHiddenAnnouncement = _React$useState6[1];
|
|
116
|
+
|
|
117
|
+
// This should lag behind the visual update -- otherwise, screen reader users will be interrupted with a lot of chatter while typing
|
|
118
|
+
var updateVisuallyHiddenAnnouncement = useDebounce(function (charactersToAnnounce) {
|
|
119
|
+
if (charactersToAnnounce >= 0) {
|
|
120
|
+
setVisuallyHiddenAnnouncement("You have ".concat(charactersToAnnounce, " characters remaining"));
|
|
121
|
+
} else {
|
|
122
|
+
setVisuallyHiddenAnnouncement("You have ".concat(charactersToAnnounce * -1, " characters too many"));
|
|
123
|
+
}
|
|
124
|
+
}, visuallyHiddenAnnouncementUpdateTimeInSeconds * 1000);
|
|
125
|
+
React.useEffect(function () {
|
|
126
|
+
if (remainingCharacters >= 0) {
|
|
127
|
+
setLabel("<strong>".concat(remainingCharacters, "</strong> characters remaining"));
|
|
128
|
+
} else {
|
|
129
|
+
setLabel("You have <strong>".concat(remainingCharacters * -1, "</strong> characters too many"));
|
|
130
|
+
}
|
|
131
|
+
updateVisuallyHiddenAnnouncement(remainingCharacters);
|
|
132
|
+
}, [remainingCharacters, updateVisuallyHiddenAnnouncement]);
|
|
133
|
+
return {
|
|
134
|
+
hasExceededLimit: remainingCharacters < 0,
|
|
135
|
+
handleTextareaChange: function handleTextareaChange(e) {
|
|
136
|
+
setRemainingCharacters(maxCharacters - e.target.value.length);
|
|
137
|
+
},
|
|
138
|
+
label: label,
|
|
139
|
+
visuallyHiddenAnnouncement: visuallyHiddenAnnouncement
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Simple debounce implementation. Will call the given
|
|
145
|
+
* function once after the time given has passed since
|
|
146
|
+
* it was last called.
|
|
147
|
+
* Lifted from downshift/utils (not exposed in lib).
|
|
148
|
+
* @param {Function} fn the function to call after the time
|
|
149
|
+
* @param {Number} time the time to wait
|
|
150
|
+
* @return {Function} the debounced function
|
|
151
|
+
*/
|
|
152
|
+
// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts
|
|
153
|
+
function debounce(fn, time) {
|
|
154
|
+
var timeoutId = 0;
|
|
155
|
+
function cancel() {
|
|
156
|
+
if (timeoutId) {
|
|
157
|
+
clearTimeout(timeoutId);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function wrapper() {
|
|
161
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
162
|
+
args[_key] = arguments[_key];
|
|
163
|
+
}
|
|
164
|
+
cancel();
|
|
165
|
+
timeoutId = setTimeout(function () {
|
|
166
|
+
timeoutId = null;
|
|
167
|
+
fn.apply(void 0, args);
|
|
168
|
+
}, time);
|
|
169
|
+
}
|
|
170
|
+
wrapper.cancel = cancel;
|
|
171
|
+
return wrapper;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts
|
|
175
|
+
function useDebounce(callback, delay) {
|
|
176
|
+
return React.useRef(debounce(function () {
|
|
177
|
+
return callback.apply(void 0, arguments);
|
|
178
|
+
}, delay)).current;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var _excluded = ["error", "hint", "id", "isOptional", "label", "maxCharacters", "onChange"];
|
|
182
|
+
function FieldCharacterCountdown(_ref) {
|
|
183
|
+
var _id;
|
|
184
|
+
var error = _ref.error,
|
|
185
|
+
hint = _ref.hint,
|
|
186
|
+
id = _ref.id,
|
|
187
|
+
_ref$isOptional = _ref.isOptional,
|
|
188
|
+
isOptional = _ref$isOptional === void 0 ? false : _ref$isOptional,
|
|
189
|
+
label = _ref.label,
|
|
190
|
+
maxCharacters = _ref.maxCharacters,
|
|
191
|
+
_onChange = _ref.onChange,
|
|
192
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
193
|
+
var characterCountdown = useCharacterCountdown(maxCharacters, (props.value || '').length);
|
|
194
|
+
id = (_id = id) !== null && _id !== void 0 ? _id : props.name;
|
|
195
|
+
var errorId = React.useId();
|
|
196
|
+
var hintId = React.useId();
|
|
197
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
198
|
+
className: "bds-form-group"
|
|
199
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
200
|
+
htmlFor: id
|
|
201
|
+
}, label, isOptional && ' (optional)'), hint && /*#__PURE__*/React.createElement("span", {
|
|
202
|
+
className: "bds-hint",
|
|
203
|
+
id: hintId
|
|
204
|
+
}, hint), error && /*#__PURE__*/React.createElement(ErrorMessage, {
|
|
205
|
+
id: errorId
|
|
206
|
+
}, error), /*#__PURE__*/React.createElement("textarea", _extends({
|
|
207
|
+
"aria-invalid": error ? true : undefined,
|
|
208
|
+
"aria-describedby": error && hint ? "".concat(hintId, " ").concat(errorId) : error ? errorId : hint ? hintId : undefined,
|
|
209
|
+
className: "bds-textarea",
|
|
210
|
+
id: id,
|
|
211
|
+
onChange: function onChange(e) {
|
|
212
|
+
if (_onChange) {
|
|
213
|
+
_onChange(e);
|
|
214
|
+
}
|
|
215
|
+
characterCountdown.handleTextareaChange(e);
|
|
216
|
+
}
|
|
217
|
+
}, props)), /*#__PURE__*/React.createElement("div", {
|
|
218
|
+
"aria-hidden": "true",
|
|
219
|
+
className: "bds-character-count",
|
|
220
|
+
"data-exceeds-limit": characterCountdown.hasExceededLimit ? true : undefined
|
|
221
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: HTML is expected and used for highlighting the number itself
|
|
222
|
+
,
|
|
223
|
+
dangerouslySetInnerHTML: {
|
|
224
|
+
__html: characterCountdown.label
|
|
225
|
+
}
|
|
226
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
227
|
+
"aria-live": "polite",
|
|
228
|
+
className: "visually-hidden"
|
|
229
|
+
}, characterCountdown.visuallyHiddenAnnouncement));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { FieldCharacterCountdown as default, useCharacterCountdown };
|
|
233
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/ErrorMessage/ErrorMessage.tsx","../../src/FieldCharacterCountdown/useCharacterCountdown.ts","../../src/FieldCharacterCountdown/FieldCharacterCountdown.tsx"],"sourcesContent":["// biome-ignore lint/style/useImportType: following this rule does not work for some reason\nimport * as React from 'react';\n\nexport default function ErrorMessage({ className, children, ...props }: React.ComponentPropsWithoutRef<'span'>) {\n return (\n <span className={['bds-error', className].filter((x) => x).join(' ')} {...props}>\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 512 512\"\n aria-hidden=\"true\"\n height=\"1em\"\n width=\"1em\"\n fill=\"currentColor\"\n >\n <path d=\"M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7.2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8.2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24v112c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32 14.3 32 32 32 32-14.3 32-32z\" />\n </svg>\n {children}\n </span>\n );\n}\n","import * as React from 'react';\n\nconst visuallyHiddenAnnouncementUpdateTimeInSeconds = 1;\n\nexport default function useCharacterCountdown(maxCharacters: number, currentCharacters = 0) {\n const [remainingCharacters, setRemainingCharacters] = React.useState(maxCharacters - currentCharacters);\n\n // When JS fails to load, the default label 👇 will still let the user know about the limit.\n const [label, setLabel] = React.useState(`You can use up to ${maxCharacters} characters`);\n const [visuallyHiddenAnnouncement, setVisuallyHiddenAnnouncement] = React.useState(label);\n\n // This should lag behind the visual update -- otherwise, screen reader users will be interrupted with a lot of chatter while typing\n const updateVisuallyHiddenAnnouncement = useDebounce((charactersToAnnounce: number) => {\n if (charactersToAnnounce >= 0) {\n setVisuallyHiddenAnnouncement(`You have ${charactersToAnnounce} characters remaining`);\n } else {\n setVisuallyHiddenAnnouncement(`You have ${charactersToAnnounce * -1} characters too many`);\n }\n }, visuallyHiddenAnnouncementUpdateTimeInSeconds * 1000);\n\n React.useEffect(() => {\n if (remainingCharacters >= 0) {\n setLabel(`<strong>${remainingCharacters}</strong> characters remaining`);\n } else {\n setLabel(`You have <strong>${remainingCharacters * -1}</strong> characters too many`);\n }\n\n updateVisuallyHiddenAnnouncement(remainingCharacters);\n }, [remainingCharacters, updateVisuallyHiddenAnnouncement]);\n\n return {\n hasExceededLimit: remainingCharacters < 0,\n handleTextareaChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => {\n setRemainingCharacters(maxCharacters - e.target.value.length);\n },\n label,\n visuallyHiddenAnnouncement,\n };\n}\n\n/**\n * Simple debounce implementation. Will call the given\n * function once after the time given has passed since\n * it was last called.\n * Lifted from downshift/utils (not exposed in lib).\n * @param {Function} fn the function to call after the time\n * @param {Number} time the time to wait\n * @return {Function} the debounced function\n */\n// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts\nfunction debounce(fn: (...rest: any[]) => any, time: number) {\n let timeoutId: number | null = 0;\n\n function cancel() {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n\n function wrapper(...args) {\n cancel();\n timeoutId = setTimeout(() => {\n timeoutId = null;\n fn(...args);\n }, time);\n }\n\n wrapper.cancel = cancel;\n\n return wrapper;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: We don't know or care what parameters the function accepts\nfunction useDebounce<T extends (...rest: any[]) => any>(callback: T, delay: number) {\n return React.useRef(debounce((...params) => callback(...params), delay)).current;\n}\n","import * as React from 'react';\n\nimport ErrorMessage from '../ErrorMessage';\nimport useCharacterCountdown from './useCharacterCountdown';\n\nexport type FieldCharacterCountdownProps = {\n error?: string;\n hint?: string;\n id?: string;\n isOptional?: boolean;\n label: string;\n maxCharacters: number;\n};\n\nexport default function FieldCharacterCountdown({\n error,\n hint,\n id,\n isOptional = false,\n label,\n maxCharacters,\n onChange,\n ...props\n}: FieldCharacterCountdownProps & React.ComponentPropsWithoutRef<'textarea'>) {\n const characterCountdown = useCharacterCountdown(maxCharacters, ((props.value as string) || '').length);\n\n id = id ?? props.name;\n\n const errorId = React.useId();\n const hintId = React.useId();\n\n return (\n <div className=\"bds-form-group\">\n <label htmlFor={id}>\n {label}\n {isOptional && ' (optional)'}\n </label>\n {hint && (\n <span className=\"bds-hint\" id={hintId}>\n {hint}\n </span>\n )}\n {error && <ErrorMessage id={errorId}>{error}</ErrorMessage>}\n <textarea\n aria-invalid={error ? true : undefined}\n aria-describedby={error && hint ? `${hintId} ${errorId}` : error ? errorId : hint ? hintId : undefined}\n className=\"bds-textarea\"\n id={id}\n onChange={(e) => {\n if (onChange) {\n onChange(e);\n }\n\n characterCountdown.handleTextareaChange(e);\n }}\n {...props}\n />\n <div\n aria-hidden=\"true\"\n className=\"bds-character-count\"\n data-exceeds-limit={characterCountdown.hasExceededLimit ? true : undefined}\n // biome-ignore lint/security/noDangerouslySetInnerHtml: HTML is expected and used for highlighting the number itself\n dangerouslySetInnerHTML={{\n __html: characterCountdown.label,\n }}\n />\n <div aria-live=\"polite\" className=\"visually-hidden\">\n {characterCountdown.visuallyHiddenAnnouncement}\n </div>\n </div>\n );\n}\n"],"names":["ErrorMessage","_ref","className","children","props","_objectWithoutProperties","_excluded","React","createElement","_extends","filter","x","join","xmlns","viewBox","height","width","fill","d","visuallyHiddenAnnouncementUpdateTimeInSeconds","useCharacterCountdown","maxCharacters","currentCharacters","arguments","length","undefined","_React$useState","useState","_React$useState2","_slicedToArray","remainingCharacters","setRemainingCharacters","_React$useState3","concat","_React$useState4","label","setLabel","_React$useState5","_React$useState6","visuallyHiddenAnnouncement","setVisuallyHiddenAnnouncement","updateVisuallyHiddenAnnouncement","useDebounce","charactersToAnnounce","useEffect","hasExceededLimit","handleTextareaChange","e","target","value","debounce","fn","time","timeoutId","cancel","clearTimeout","wrapper","_len","args","Array","_key","setTimeout","apply","callback","delay","useRef","current","FieldCharacterCountdown","_id","error","hint","id","_ref$isOptional","isOptional","onChange","characterCountdown","name","errorId","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SAAQ,CAAC3B,CAAC,CAAC,CAAA;AACb,OAAA;AAEA4B,MAAAA,kBAAkB,CAAC7B,oBAAoB,CAACC,CAAC,CAAC,CAAA;AAC5C,KAAA;AAAE,GAAA,EACE3C,KAAK,CACV,CAAC,eACFG,KAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AACE,IAAA,aAAA,EAAY,MAAM;AAClBN,IAAAA,SAAS,EAAC,qBAAqB;AAC/B,IAAA,oBAAA,EAAoByE,kBAAkB,CAAC9B,gBAAgB,GAAG,IAAI,GAAGpB,SAAAA;AACjE;AAAA;AACAwD,IAAAA,uBAAuB,EAAE;MACvBC,MAAM,EAAEP,kBAAkB,CAACxC,KAAAA;AAC7B,KAAA;AAAE,GACH,CAAC,eACF5B,KAAA,CAAAC,aAAA,CAAA,KAAA,EAAA;AAAK,IAAA,WAAA,EAAU,QAAQ;AAACN,IAAAA,SAAS,EAAC,iBAAA;AAAiB,GAAA,EAChDyE,kBAAkB,CAACpC,0BACjB,CACF,CAAC,CAAA;AAEV;;;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export default function useCharacterCountdown(maxCharacters: number, currentCharacters?: number): {
|
|
3
|
+
hasExceededLimit: boolean;
|
|
4
|
+
handleTextareaChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
5
|
+
label: string;
|
|
6
|
+
visuallyHiddenAnnouncement: string;
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iabbb/bds-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.1",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "cross-env NODE_ENV=production rollup -c",
|
|
7
7
|
"dev": "rollup -c -w"
|
|
8
8
|
},
|
|
9
9
|
"devDependencies": {
|
|
10
|
-
"@babel/core": "7.24.
|
|
11
|
-
"@babel/preset-env": "7.24.
|
|
12
|
-
"@babel/preset-react": "7.24.
|
|
13
|
-
"@babel/preset-typescript": "7.24.
|
|
10
|
+
"@babel/core": "7.24.7",
|
|
11
|
+
"@babel/preset-env": "7.24.7",
|
|
12
|
+
"@babel/preset-react": "7.24.7",
|
|
13
|
+
"@babel/preset-typescript": "7.24.7",
|
|
14
14
|
"@rollup/plugin-babel": "6.0.4",
|
|
15
|
-
"@rollup/plugin-commonjs": "
|
|
15
|
+
"@rollup/plugin-commonjs": "26.0.1",
|
|
16
16
|
"@rollup/plugin-node-resolve": "15.2.3",
|
|
17
17
|
"@rollup/plugin-terser": "0.4.4",
|
|
18
18
|
"@rollup/plugin-typescript": "11.1.6",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"typescript": "5.4.5"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@iabbb/bds": "0.
|
|
31
|
+
"@iabbb/bds": "0.49.1",
|
|
32
32
|
"react": "^18.0.0"
|
|
33
33
|
}
|
|
34
34
|
}
|