carbon-react 116.2.1 → 117.0.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.
- package/esm/__internal__/character-count/character-count.component.d.ts +2 -2
- package/esm/__internal__/character-count/character-count.component.js +16 -7
- package/esm/components/date/date.d.ts +0 -1
- package/esm/components/decimal/decimal.component.js +1 -0
- package/esm/components/grouped-character/grouped-character.component.js +2 -2
- package/esm/components/i18n-provider/i18n-provider.component.js +5 -0
- package/esm/components/number/number.component.js +2 -2
- package/esm/components/textarea/textarea.component.d.ts +3 -3
- package/esm/components/textarea/textarea.component.js +17 -10
- package/esm/components/textbox/textbox.component.d.ts +3 -3
- package/esm/components/textbox/textbox.component.js +18 -9
- package/esm/components/textbox/textbox.style.d.ts +3 -2
- package/esm/components/textbox/textbox.style.js +10 -2
- package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +6 -1
- package/esm/hooks/__internal__/useCharacterCount/useCharacterCount.js +9 -8
- package/esm/locales/en-gb.js +5 -0
- package/esm/locales/locale.d.ts +5 -0
- package/esm/locales/pl-pl.d.ts +2 -0
- package/esm/locales/pl-pl.js +17 -0
- package/lib/__internal__/character-count/character-count.component.d.ts +2 -2
- package/lib/__internal__/character-count/character-count.component.js +17 -7
- package/lib/components/date/date.d.ts +0 -1
- package/lib/components/decimal/decimal.component.js +1 -0
- package/lib/components/grouped-character/grouped-character.component.js +2 -2
- package/lib/components/i18n-provider/i18n-provider.component.js +5 -0
- package/lib/components/number/number.component.js +2 -2
- package/lib/components/textarea/textarea.component.d.ts +3 -3
- package/lib/components/textarea/textarea.component.js +15 -7
- package/lib/components/textbox/textbox.component.d.ts +3 -3
- package/lib/components/textbox/textbox.component.js +17 -7
- package/lib/components/textbox/textbox.style.d.ts +3 -2
- package/lib/components/textbox/textbox.style.js +11 -2
- package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.d.ts +6 -1
- package/lib/hooks/__internal__/useCharacterCount/useCharacterCount.js +9 -7
- package/lib/locales/en-gb.js +5 -0
- package/lib/locales/locale.d.ts +5 -0
- package/lib/locales/pl-pl.d.ts +2 -0
- package/lib/locales/pl-pl.js +19 -1
- package/package.json +3 -2
- package/scripts/check_rfcs/index.js +3 -0
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
3
|
import StyledCharacterCount from "./character-count.style";
|
|
4
|
+
import useLocale from "../../hooks/__internal__/useLocale";
|
|
4
5
|
|
|
5
6
|
const CharacterCount = ({
|
|
6
7
|
value,
|
|
7
8
|
limit,
|
|
8
9
|
isOverLimit,
|
|
9
10
|
"data-element": dataElement
|
|
10
|
-
}) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
}) => {
|
|
12
|
+
const limitMinusValue = +limit - +value;
|
|
13
|
+
const valueMinusLimit = +value - +limit;
|
|
14
|
+
const l = useLocale();
|
|
15
|
+
|
|
16
|
+
const getFormatNumber = (rawValue, locale) => new Intl.NumberFormat(locale).format(rawValue);
|
|
17
|
+
|
|
18
|
+
return /*#__PURE__*/React.createElement(StyledCharacterCount, {
|
|
19
|
+
"aria-live": "polite",
|
|
20
|
+
isOverLimit: isOverLimit,
|
|
21
|
+
"data-element": dataElement
|
|
22
|
+
}, !isOverLimit ? l.characterCount.charactersLeft(limitMinusValue, getFormatNumber(limitMinusValue, l.locale())) : l.characterCount.tooManyCharacters(valueMinusLimit, getFormatNumber(valueMinusLimit, l.locale())));
|
|
23
|
+
};
|
|
15
24
|
|
|
16
25
|
CharacterCount.propTypes = {
|
|
17
26
|
"data-element": PropTypes.string,
|
|
18
27
|
"isOverLimit": PropTypes.bool.isRequired,
|
|
19
|
-
"limit": PropTypes.
|
|
20
|
-
"value": PropTypes.
|
|
28
|
+
"limit": PropTypes.number.isRequired,
|
|
29
|
+
"value": PropTypes.number.isRequired
|
|
21
30
|
};
|
|
22
31
|
export default CharacterCount;
|
|
@@ -317,6 +317,7 @@ Decimal.propTypes = {
|
|
|
317
317
|
"id": PropTypes.string,
|
|
318
318
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
319
319
|
"inlist": PropTypes.any,
|
|
320
|
+
"inputHint": PropTypes.string,
|
|
320
321
|
"inputIcon": PropTypes.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
321
322
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
322
323
|
"inputRef": PropTypes.func,
|
|
@@ -190,7 +190,7 @@ GroupedCharacter.propTypes = {
|
|
|
190
190
|
"autoFocus": PropTypes.bool,
|
|
191
191
|
"autoSave": PropTypes.string,
|
|
192
192
|
"capture": PropTypes.oneOfType([PropTypes.oneOf(["environment", "user"]), PropTypes.bool]),
|
|
193
|
-
"characterLimit": PropTypes.
|
|
193
|
+
"characterLimit": PropTypes.number,
|
|
194
194
|
"checked": PropTypes.bool,
|
|
195
195
|
"children": PropTypes.node,
|
|
196
196
|
"className": PropTypes.string,
|
|
@@ -235,6 +235,7 @@ GroupedCharacter.propTypes = {
|
|
|
235
235
|
"id": PropTypes.string,
|
|
236
236
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
237
237
|
"inlist": PropTypes.any,
|
|
238
|
+
"inputHint": PropTypes.string,
|
|
238
239
|
"inputIcon": PropTypes.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
239
240
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
240
241
|
"inputRef": PropTypes.func,
|
|
@@ -659,7 +660,6 @@ GroupedCharacter.propTypes = {
|
|
|
659
660
|
"value": PropTypes.string,
|
|
660
661
|
"vocab": PropTypes.string,
|
|
661
662
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
662
|
-
"warnOverLimit": PropTypes.bool,
|
|
663
663
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
664
664
|
};
|
|
665
665
|
export { GroupedCharacter };
|
|
@@ -24,6 +24,11 @@ I18nProvider.propTypes = {
|
|
|
24
24
|
"batchSelection": PropTypes.shape({
|
|
25
25
|
"selected": PropTypes.func.isRequired
|
|
26
26
|
}),
|
|
27
|
+
"characterCount": PropTypes.shape({
|
|
28
|
+
"charactersLeft": PropTypes.func.isRequired,
|
|
29
|
+
"hintString": PropTypes.func.isRequired,
|
|
30
|
+
"tooManyCharacters": PropTypes.func.isRequired
|
|
31
|
+
}),
|
|
27
32
|
"confirm": PropTypes.shape({
|
|
28
33
|
"no": PropTypes.func.isRequired,
|
|
29
34
|
"yes": PropTypes.func.isRequired
|
|
@@ -115,7 +115,7 @@ Number.propTypes = {
|
|
|
115
115
|
"autoFocus": PropTypes.bool,
|
|
116
116
|
"autoSave": PropTypes.string,
|
|
117
117
|
"capture": PropTypes.oneOfType([PropTypes.oneOf(["environment", "user"]), PropTypes.bool]),
|
|
118
|
-
"characterLimit": PropTypes.
|
|
118
|
+
"characterLimit": PropTypes.number,
|
|
119
119
|
"checked": PropTypes.bool,
|
|
120
120
|
"children": PropTypes.node,
|
|
121
121
|
"className": PropTypes.string,
|
|
@@ -159,6 +159,7 @@ Number.propTypes = {
|
|
|
159
159
|
"id": PropTypes.string,
|
|
160
160
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
161
161
|
"inlist": PropTypes.any,
|
|
162
|
+
"inputHint": PropTypes.string,
|
|
162
163
|
"inputIcon": PropTypes.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
163
164
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
164
165
|
"inputRef": PropTypes.func,
|
|
@@ -582,7 +583,6 @@ Number.propTypes = {
|
|
|
582
583
|
"value": PropTypes.string,
|
|
583
584
|
"vocab": PropTypes.string,
|
|
584
585
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
585
|
-
"warnOverLimit": PropTypes.bool,
|
|
586
586
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
587
587
|
};
|
|
588
588
|
export { Number };
|
|
@@ -19,7 +19,7 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
|
|
|
19
19
|
/** Automatically focus the input on component mount */
|
|
20
20
|
autoFocus?: boolean;
|
|
21
21
|
/** Character limit of the textarea */
|
|
22
|
-
characterLimit?:
|
|
22
|
+
characterLimit?: number;
|
|
23
23
|
/** Type of the icon that will be rendered next to the input */
|
|
24
24
|
children?: React.ReactNode;
|
|
25
25
|
/** The visible width of the text control, in average character widths */
|
|
@@ -34,6 +34,8 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
|
|
|
34
34
|
error?: boolean | string;
|
|
35
35
|
/** Allows the Textareas Height to change based on user input */
|
|
36
36
|
expandable?: boolean;
|
|
37
|
+
/** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
|
|
38
|
+
inputHint?: string;
|
|
37
39
|
/** Help content to be displayed under an input */
|
|
38
40
|
fieldHelp?: React.ReactNode;
|
|
39
41
|
/** Aria label for rendered help component */
|
|
@@ -89,8 +91,6 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
|
|
|
89
91
|
validationOnLabel?: boolean;
|
|
90
92
|
/** The value of the Textbox */
|
|
91
93
|
value?: string;
|
|
92
|
-
/** Whether to display the character count message in red */
|
|
93
|
-
warnOverLimit?: boolean;
|
|
94
94
|
/** Indicate that warning has occurred
|
|
95
95
|
Pass string to display icon, tooltip and orange border
|
|
96
96
|
Pass true boolean to only display orange border */
|
|
@@ -13,23 +13,22 @@ import StyledTextarea, { MIN_HEIGHT } from "./textarea.style";
|
|
|
13
13
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
14
14
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility";
|
|
15
15
|
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
16
|
-
import { ErrorBorder, StyledHintText } from "../textbox/textbox.style";
|
|
16
|
+
import { ErrorBorder, StyledHintText, StyledInputHint } from "../textbox/textbox.style";
|
|
17
17
|
import ValidationMessage from "../../__internal__/validation-message";
|
|
18
18
|
import Box from "../box";
|
|
19
19
|
import Logger from "../../__internal__/utils/logger";
|
|
20
|
-
import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
|
|
21
|
-
|
|
20
|
+
import useFormSpacing from "../../hooks/__internal__/useFormSpacing";
|
|
22
21
|
let deprecateInputRefWarnTriggered = false;
|
|
23
22
|
const Textarea = /*#__PURE__*/React.forwardRef(({
|
|
24
23
|
"aria-labelledby": ariaLabelledBy,
|
|
25
24
|
autoFocus,
|
|
25
|
+
inputHint,
|
|
26
26
|
fieldHelp,
|
|
27
27
|
label,
|
|
28
28
|
size,
|
|
29
29
|
children,
|
|
30
30
|
characterLimit,
|
|
31
31
|
enforceCharacterLimit = true,
|
|
32
|
-
warnOverLimit = false,
|
|
33
32
|
onChange,
|
|
34
33
|
disabled = false,
|
|
35
34
|
labelInline,
|
|
@@ -115,8 +114,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
|
|
|
115
114
|
label,
|
|
116
115
|
fieldHelp
|
|
117
116
|
});
|
|
118
|
-
const [maxLength, characterCount] = useCharacterCount(value,
|
|
119
|
-
typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
|
|
117
|
+
const [maxLength, characterCount, characterCountHintId, characterCountHint] = useCharacterCount(value, characterLimit, enforceCharacterLimit);
|
|
120
118
|
useEffect(() => {
|
|
121
119
|
if (rows) {
|
|
122
120
|
var _internalRef$current;
|
|
@@ -144,6 +142,12 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
|
|
|
144
142
|
};
|
|
145
143
|
}, [expandable]);
|
|
146
144
|
const hasIconInside = !!(inputIcon || validationIconId && !validationOnLabel);
|
|
145
|
+
const hintId = useRef(guid());
|
|
146
|
+
const characterCountHintIdValue = characterCount ? characterCountHintId : undefined;
|
|
147
|
+
const inputHintIdValue = inputHint ? hintId.current : undefined;
|
|
148
|
+
const hintIdValue = characterLimit ? characterCountHintIdValue : inputHintIdValue;
|
|
149
|
+
const ariaDescribedByValues = [validationRedesignOptIn ? undefined : ariaDescribedBy, hintIdValue];
|
|
150
|
+
const ariaDescribedByValue = ariaDescribedByValues.filter(Boolean).join(" ");
|
|
147
151
|
const input = /*#__PURE__*/React.createElement(InputPresentation, {
|
|
148
152
|
size: size,
|
|
149
153
|
disabled: disabled,
|
|
@@ -156,7 +160,7 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
|
|
|
156
160
|
}, /*#__PURE__*/React.createElement(Input, _extends({
|
|
157
161
|
"aria-invalid": !!error,
|
|
158
162
|
"aria-labelledby": ariaLabelledBy,
|
|
159
|
-
"aria-describedby":
|
|
163
|
+
"aria-describedby": ariaDescribedByValue,
|
|
160
164
|
autoFocus: autoFocus,
|
|
161
165
|
name: name,
|
|
162
166
|
value: value,
|
|
@@ -211,7 +215,10 @@ const Textarea = /*#__PURE__*/React.forwardRef(({
|
|
|
211
215
|
useValidationIcon: computeLabelPropValues(validationOnLabel),
|
|
212
216
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
213
217
|
validationRedesignOptIn: validationRedesignOptIn
|
|
214
|
-
},
|
|
218
|
+
}, characterLimit || inputHint ? /*#__PURE__*/React.createElement(StyledInputHint, {
|
|
219
|
+
id: hintIdValue,
|
|
220
|
+
"data-element": "input-hint"
|
|
221
|
+
}, characterCountHint || inputHint) : null, validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), validationRedesignOptIn ? /*#__PURE__*/React.createElement(Box, {
|
|
215
222
|
position: "relative"
|
|
216
223
|
}, /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
217
224
|
error: error,
|
|
@@ -282,7 +289,7 @@ Textarea.propTypes = {
|
|
|
282
289
|
"autoFocus": PropTypes.bool,
|
|
283
290
|
"autoSave": PropTypes.string,
|
|
284
291
|
"capture": PropTypes.oneOfType([PropTypes.oneOf(["environment", "user"]), PropTypes.bool]),
|
|
285
|
-
"characterLimit": PropTypes.
|
|
292
|
+
"characterLimit": PropTypes.number,
|
|
286
293
|
"checked": PropTypes.bool,
|
|
287
294
|
"children": PropTypes.node,
|
|
288
295
|
"className": PropTypes.string,
|
|
@@ -323,6 +330,7 @@ Textarea.propTypes = {
|
|
|
323
330
|
"id": PropTypes.string,
|
|
324
331
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
325
332
|
"inlist": PropTypes.any,
|
|
333
|
+
"inputHint": PropTypes.string,
|
|
326
334
|
"inputIcon": PropTypes.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
327
335
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
328
336
|
"inputRef": PropTypes.func,
|
|
@@ -743,7 +751,6 @@ Textarea.propTypes = {
|
|
|
743
751
|
"value": PropTypes.string,
|
|
744
752
|
"vocab": PropTypes.string,
|
|
745
753
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
746
|
-
"warnOverLimit": PropTypes.bool,
|
|
747
754
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
748
755
|
};
|
|
749
756
|
export { Textarea };
|
|
@@ -16,6 +16,8 @@ export interface CommonTextboxProps extends ValidationProps, MarginProps, Omit<C
|
|
|
16
16
|
adaptiveLabelBreakpoint?: number;
|
|
17
17
|
/** Integer to determine a timeout for the deferred callback */
|
|
18
18
|
deferTimeout?: number;
|
|
19
|
+
/** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
|
|
20
|
+
inputHint?: string;
|
|
19
21
|
/** Help content to be displayed under an input */
|
|
20
22
|
fieldHelp?: React.ReactNode;
|
|
21
23
|
/**
|
|
@@ -91,11 +93,9 @@ export interface TextboxProps extends CommonTextboxProps {
|
|
|
91
93
|
/** Container for DatePicker or SelectList components */
|
|
92
94
|
positionedChildren?: React.ReactNode;
|
|
93
95
|
/** Character limit of the textarea */
|
|
94
|
-
characterLimit?:
|
|
96
|
+
characterLimit?: number;
|
|
95
97
|
/** Stop the user typing over the characterLimit */
|
|
96
98
|
enforceCharacterLimit?: boolean;
|
|
97
|
-
/** Whether to display the character count message in red */
|
|
98
|
-
warnOverLimit?: boolean;
|
|
99
99
|
}
|
|
100
100
|
export declare const Textbox: React.ForwardRefExoticComponent<TextboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
101
101
|
export default Textbox;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import React, { useContext } from "react";
|
|
3
|
+
import React, { useContext, useRef } from "react";
|
|
4
4
|
import PropTypes from "prop-types";
|
|
5
5
|
import { filterStyledSystemMarginProps } from "../../style/utils";
|
|
6
6
|
import { Input, InputPresentation } from "../../__internal__/input";
|
|
@@ -12,12 +12,13 @@ import StyledPrefix from "./__internal__/prefix.style";
|
|
|
12
12
|
import { TooltipProvider } from "../../__internal__/tooltip-provider";
|
|
13
13
|
import useCharacterCount from "../../hooks/__internal__/useCharacterCount";
|
|
14
14
|
import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility/useInputAccessibility";
|
|
15
|
-
import { ErrorBorder, StyledHintText } from "./textbox.style";
|
|
15
|
+
import { ErrorBorder, StyledInputHint, StyledHintText } from "./textbox.style";
|
|
16
16
|
import ValidationMessage from "../../__internal__/validation-message";
|
|
17
17
|
import { NewValidationContext } from "../carbon-provider/carbon-provider.component";
|
|
18
18
|
import NumeralDateContext from "../numeral-date/numeral-date-context";
|
|
19
19
|
import Box from "../box";
|
|
20
20
|
import Logger from "../../__internal__/utils/logger";
|
|
21
|
+
import guid from "../../__internal__/utils/helpers/guid";
|
|
21
22
|
let deprecateInputRefWarnTriggered = false;
|
|
22
23
|
const Textbox = /*#__PURE__*/React.forwardRef(({
|
|
23
24
|
"aria-labelledby": ariaLabelledBy,
|
|
@@ -34,6 +35,7 @@ const Textbox = /*#__PURE__*/React.forwardRef(({
|
|
|
34
35
|
labelSpacing,
|
|
35
36
|
id,
|
|
36
37
|
formattedValue,
|
|
38
|
+
inputHint,
|
|
37
39
|
fieldHelp,
|
|
38
40
|
error,
|
|
39
41
|
warning,
|
|
@@ -70,13 +72,11 @@ const Textbox = /*#__PURE__*/React.forwardRef(({
|
|
|
70
72
|
"data-role": dataRole,
|
|
71
73
|
enforceCharacterLimit = true,
|
|
72
74
|
characterLimit,
|
|
73
|
-
warnOverLimit = false,
|
|
74
75
|
helpAriaLabel,
|
|
75
76
|
...props
|
|
76
77
|
}, ref) => {
|
|
77
78
|
const characterCountValue = typeof value === "string" ? value : "";
|
|
78
|
-
const [maxLength, characterCount] = useCharacterCount(characterCountValue,
|
|
79
|
-
typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
|
|
79
|
+
const [maxLength, characterCount, characterCountHintId, characterCountHint] = useCharacterCount(characterCountValue, characterLimit, enforceCharacterLimit);
|
|
80
80
|
const {
|
|
81
81
|
validationRedesignOptIn
|
|
82
82
|
} = useContext(NewValidationContext);
|
|
@@ -106,6 +106,12 @@ const Textbox = /*#__PURE__*/React.forwardRef(({
|
|
|
106
106
|
label,
|
|
107
107
|
fieldHelp
|
|
108
108
|
});
|
|
109
|
+
const hintId = useRef(guid());
|
|
110
|
+
const characterCountHintIdValue = characterCount ? characterCountHintId : undefined;
|
|
111
|
+
const inputHintIdValue = inputHint ? hintId.current : undefined;
|
|
112
|
+
const hintIdValue = characterLimit ? characterCountHintIdValue : inputHintIdValue;
|
|
113
|
+
const ariaDescribedByValues = [validationRedesignOptIn ? undefined : ariaDescribedBy, hintIdValue];
|
|
114
|
+
const ariaDescribedByValue = ariaDescribedByValues.filter(Boolean).join(" ");
|
|
109
115
|
const hasIconInside = !!(inputIcon || validationIconId && !validationOnLabel);
|
|
110
116
|
const input = /*#__PURE__*/React.createElement(InputPresentation, {
|
|
111
117
|
align: align,
|
|
@@ -128,7 +134,7 @@ const Textbox = /*#__PURE__*/React.forwardRef(({
|
|
|
128
134
|
align: align,
|
|
129
135
|
"aria-invalid": !!error,
|
|
130
136
|
"aria-labelledby": ariaLabelledBy,
|
|
131
|
-
"aria-describedby":
|
|
137
|
+
"aria-describedby": ariaDescribedByValue,
|
|
132
138
|
autoFocus: autoFocus,
|
|
133
139
|
deferTimeout: deferTimeout,
|
|
134
140
|
disabled: disabled,
|
|
@@ -189,7 +195,10 @@ const Textbox = /*#__PURE__*/React.forwardRef(({
|
|
|
189
195
|
"data-element": dataElement,
|
|
190
196
|
validationIconId: validationRedesignOptIn ? undefined : validationIconId,
|
|
191
197
|
validationRedesignOptIn: validationRedesignOptIn
|
|
192
|
-
}, filterStyledSystemMarginProps(props)),
|
|
198
|
+
}, filterStyledSystemMarginProps(props)), characterLimit || inputHint ? /*#__PURE__*/React.createElement(StyledInputHint, {
|
|
199
|
+
id: hintIdValue,
|
|
200
|
+
"data-element": "input-hint"
|
|
201
|
+
}, characterCountHint || inputHint) : null, validationRedesignOptIn && labelHelp && /*#__PURE__*/React.createElement(StyledHintText, null, labelHelp), validationRedesignOptIn ? /*#__PURE__*/React.createElement(Box, {
|
|
193
202
|
position: "relative"
|
|
194
203
|
}, /*#__PURE__*/React.createElement(ValidationMessage, {
|
|
195
204
|
error: error,
|
|
@@ -260,7 +269,7 @@ Textbox.propTypes = {
|
|
|
260
269
|
"autoFocus": PropTypes.bool,
|
|
261
270
|
"autoSave": PropTypes.string,
|
|
262
271
|
"capture": PropTypes.oneOfType([PropTypes.oneOf(["environment", "user"]), PropTypes.bool]),
|
|
263
|
-
"characterLimit": PropTypes.
|
|
272
|
+
"characterLimit": PropTypes.number,
|
|
264
273
|
"checked": PropTypes.bool,
|
|
265
274
|
"children": PropTypes.node,
|
|
266
275
|
"className": PropTypes.string,
|
|
@@ -304,6 +313,7 @@ Textbox.propTypes = {
|
|
|
304
313
|
"id": PropTypes.string,
|
|
305
314
|
"info": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
306
315
|
"inlist": PropTypes.any,
|
|
316
|
+
"inputHint": PropTypes.string,
|
|
307
317
|
"inputIcon": PropTypes.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
308
318
|
"inputMode": PropTypes.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
309
319
|
"inputRef": PropTypes.func,
|
|
@@ -727,7 +737,6 @@ Textbox.propTypes = {
|
|
|
727
737
|
"value": PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.number, PropTypes.string]),
|
|
728
738
|
"vocab": PropTypes.string,
|
|
729
739
|
"warning": PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
|
730
|
-
"warnOverLimit": PropTypes.bool,
|
|
731
740
|
"width": PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
732
741
|
};
|
|
733
742
|
export { Textbox };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const ErrorBorder: import("styled-components").StyledComponent<"span", any, {
|
|
2
2
|
warning: boolean;
|
|
3
3
|
}, never>;
|
|
4
|
-
declare const
|
|
5
|
-
|
|
4
|
+
declare const StyledInputHint: import("styled-components").StyledComponent<"p", any, {}, never>;
|
|
5
|
+
declare const StyledHintText: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
+
export { StyledHintText, ErrorBorder, StyledInputHint };
|
|
@@ -12,10 +12,18 @@ const ErrorBorder = styled.span`
|
|
|
12
12
|
top: 0px;
|
|
13
13
|
`}
|
|
14
14
|
`;
|
|
15
|
-
const
|
|
15
|
+
const StyledInputHint = styled.p`
|
|
16
|
+
display: block;
|
|
17
|
+
flex: 1;
|
|
18
|
+
margin-top: -3px;
|
|
19
|
+
margin-bottom: 8px;
|
|
20
|
+
color: var(--colorsUtilityYin055);
|
|
21
|
+
white-space: pre-wrap;
|
|
22
|
+
`;
|
|
23
|
+
const StyledHintText = styled.div`
|
|
16
24
|
margin-top: 0px;
|
|
17
25
|
margin-bottom: 8px;
|
|
18
26
|
color: var(--colorsUtilityYin055);
|
|
19
27
|
font-size: 14px;
|
|
20
28
|
`;
|
|
21
|
-
export { StyledHintText, ErrorBorder };
|
|
29
|
+
export { StyledHintText, ErrorBorder, StyledInputHint };
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
declare const useCharacterCount: (value?: string, characterLimit?: number | undefined,
|
|
2
|
+
declare const useCharacterCount: (value?: string, characterLimit?: number | undefined, enforceCharacterLimit?: boolean) => [
|
|
3
|
+
number | undefined,
|
|
4
|
+
JSX.Element | null,
|
|
5
|
+
string | undefined,
|
|
6
|
+
string | null
|
|
7
|
+
];
|
|
3
8
|
export default useCharacterCount;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
1
|
+
import React, { useMemo, useRef } from "react";
|
|
2
2
|
import CharacterCount from "../../../__internal__/character-count";
|
|
3
3
|
import useLocale from "../useLocale";
|
|
4
|
+
import guid from "../../../__internal__/utils/helpers/guid";
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const useCharacterCount = (value = "", characterLimit, warnOverLimit = false, enforceCharacterLimit = true) => {
|
|
6
|
+
const useCharacterCount = (value = "", characterLimit, enforceCharacterLimit = true) => {
|
|
8
7
|
const isCharacterLimitValid = typeof characterLimit === "number" && !Number.isNaN(characterLimit);
|
|
9
8
|
const l = useLocale();
|
|
9
|
+
const hintString = l.characterCount.hintString();
|
|
10
|
+
const hintId = useRef(guid());
|
|
10
11
|
const isOverLimit = useMemo(() => {
|
|
11
12
|
if (value && isCharacterLimitValid) {
|
|
12
13
|
return value.length > characterLimit;
|
|
@@ -15,11 +16,11 @@ const useCharacterCount = (value = "", characterLimit, warnOverLimit = false, en
|
|
|
15
16
|
return false;
|
|
16
17
|
}, [value, characterLimit, isCharacterLimitValid]);
|
|
17
18
|
return [enforceCharacterLimit && isCharacterLimitValid ? characterLimit : undefined, isCharacterLimitValid ? /*#__PURE__*/React.createElement(CharacterCount, {
|
|
18
|
-
isOverLimit: isOverLimit
|
|
19
|
-
value:
|
|
20
|
-
limit:
|
|
19
|
+
isOverLimit: isOverLimit,
|
|
20
|
+
value: value.length,
|
|
21
|
+
limit: characterLimit,
|
|
21
22
|
"data-element": "character-limit"
|
|
22
|
-
}) : null];
|
|
23
|
+
}) : null, hintId.current, isCharacterLimitValid ? hintString : null];
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
export default useCharacterCount;
|
package/esm/locales/en-gb.js
CHANGED
|
@@ -18,6 +18,11 @@ const enGB = {
|
|
|
18
18
|
no: () => "No",
|
|
19
19
|
yes: () => "Yes"
|
|
20
20
|
},
|
|
21
|
+
characterCount: {
|
|
22
|
+
hintString: () => "Input contains a character counter",
|
|
23
|
+
tooManyCharacters: (count, formattedCount) => count === 1 ? `You have ${formattedCount} character too many` : `You have ${formattedCount} characters too many`,
|
|
24
|
+
charactersLeft: (count, formattedCount) => count === 1 ? `You have ${formattedCount} character remaining` : `You have ${formattedCount} characters remaining`
|
|
25
|
+
},
|
|
21
26
|
date: {
|
|
22
27
|
dateFnsLocale: () => enGBDateLocale
|
|
23
28
|
},
|
package/esm/locales/locale.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ interface Locale {
|
|
|
11
11
|
batchSelection: {
|
|
12
12
|
selected: (count: number | string) => string;
|
|
13
13
|
};
|
|
14
|
+
characterCount: {
|
|
15
|
+
hintString: () => string;
|
|
16
|
+
tooManyCharacters: (count: number, formattedCount: string) => string;
|
|
17
|
+
charactersLeft: (count: number, formattedCount: string) => string;
|
|
18
|
+
};
|
|
14
19
|
confirm: {
|
|
15
20
|
no: () => string;
|
|
16
21
|
yes: () => string;
|
package/esm/locales/pl-pl.d.ts
CHANGED
package/esm/locales/pl-pl.js
CHANGED
|
@@ -2,6 +2,17 @@ import { pl as plDateLocale } from "./date-fns-locales";
|
|
|
2
2
|
|
|
3
3
|
const isSingular = count => (typeof count === "string" ? parseInt(count) : count) === 1;
|
|
4
4
|
|
|
5
|
+
export const PolishPlural = (singularNominativ, pluralNominativ, pluralGenitive, value) => {
|
|
6
|
+
if (value === 1) {
|
|
7
|
+
return singularNominativ;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (value % 10 >= 2 && value % 10 <= 4 && (value % 100 < 10 || value % 100 >= 20)) {
|
|
11
|
+
return pluralNominativ;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return pluralGenitive;
|
|
15
|
+
};
|
|
5
16
|
const plPL = {
|
|
6
17
|
locale: () => "pl-PL",
|
|
7
18
|
actions: {
|
|
@@ -18,6 +29,11 @@ const plPL = {
|
|
|
18
29
|
no: () => "Nie",
|
|
19
30
|
yes: () => "Tak"
|
|
20
31
|
},
|
|
32
|
+
characterCount: {
|
|
33
|
+
hintString: () => "Pole zawiera licznik znaków",
|
|
34
|
+
tooManyCharacters: (count, formattedCount) => `Masz o ${formattedCount} ${PolishPlural("znak", "znaki", "znaków", count)} za dużo`,
|
|
35
|
+
charactersLeft: (count, formattedCount) => `Masz ${formattedCount} ${PolishPlural("pozostały", "pozostałe", "pozostałych", count)} ${PolishPlural("znak", "znaki", "znaków", count)}`
|
|
36
|
+
},
|
|
21
37
|
date: {
|
|
22
38
|
dateFnsLocale: () => plDateLocale
|
|
23
39
|
},
|
|
@@ -135,4 +151,5 @@ const plPL = {
|
|
|
135
151
|
}
|
|
136
152
|
}
|
|
137
153
|
};
|
|
154
|
+
export { PolishPlural as PolishPlurals };
|
|
138
155
|
export default plPL;
|
|
@@ -11,6 +11,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
11
11
|
|
|
12
12
|
var _characterCount = _interopRequireDefault(require("./character-count.style"));
|
|
13
13
|
|
|
14
|
+
var _useLocale = _interopRequireDefault(require("../../hooks/__internal__/useLocale"));
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
const CharacterCount = ({
|
|
@@ -18,17 +20,25 @@ const CharacterCount = ({
|
|
|
18
20
|
limit,
|
|
19
21
|
isOverLimit,
|
|
20
22
|
"data-element": dataElement
|
|
21
|
-
}) =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
}) => {
|
|
24
|
+
const limitMinusValue = +limit - +value;
|
|
25
|
+
const valueMinusLimit = +value - +limit;
|
|
26
|
+
const l = (0, _useLocale.default)();
|
|
27
|
+
|
|
28
|
+
const getFormatNumber = (rawValue, locale) => new Intl.NumberFormat(locale).format(rawValue);
|
|
29
|
+
|
|
30
|
+
return /*#__PURE__*/_react.default.createElement(_characterCount.default, {
|
|
31
|
+
"aria-live": "polite",
|
|
32
|
+
isOverLimit: isOverLimit,
|
|
33
|
+
"data-element": dataElement
|
|
34
|
+
}, !isOverLimit ? l.characterCount.charactersLeft(limitMinusValue, getFormatNumber(limitMinusValue, l.locale())) : l.characterCount.tooManyCharacters(valueMinusLimit, getFormatNumber(valueMinusLimit, l.locale())));
|
|
35
|
+
};
|
|
26
36
|
|
|
27
37
|
CharacterCount.propTypes = {
|
|
28
38
|
"data-element": _propTypes.default.string,
|
|
29
39
|
"isOverLimit": _propTypes.default.bool.isRequired,
|
|
30
|
-
"limit": _propTypes.default.
|
|
31
|
-
"value": _propTypes.default.
|
|
40
|
+
"limit": _propTypes.default.number.isRequired,
|
|
41
|
+
"value": _propTypes.default.number.isRequired
|
|
32
42
|
};
|
|
33
43
|
var _default = CharacterCount;
|
|
34
44
|
exports.default = _default;
|
|
@@ -341,6 +341,7 @@ Decimal.propTypes = {
|
|
|
341
341
|
"id": _propTypes.default.string,
|
|
342
342
|
"info": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
343
343
|
"inlist": _propTypes.default.any,
|
|
344
|
+
"inputHint": _propTypes.default.string,
|
|
344
345
|
"inputIcon": _propTypes.default.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
345
346
|
"inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
346
347
|
"inputRef": _propTypes.default.func,
|
|
@@ -211,7 +211,7 @@ GroupedCharacter.propTypes = {
|
|
|
211
211
|
"autoFocus": _propTypes.default.bool,
|
|
212
212
|
"autoSave": _propTypes.default.string,
|
|
213
213
|
"capture": _propTypes.default.oneOfType([_propTypes.default.oneOf(["environment", "user"]), _propTypes.default.bool]),
|
|
214
|
-
"characterLimit": _propTypes.default.
|
|
214
|
+
"characterLimit": _propTypes.default.number,
|
|
215
215
|
"checked": _propTypes.default.bool,
|
|
216
216
|
"children": _propTypes.default.node,
|
|
217
217
|
"className": _propTypes.default.string,
|
|
@@ -256,6 +256,7 @@ GroupedCharacter.propTypes = {
|
|
|
256
256
|
"id": _propTypes.default.string,
|
|
257
257
|
"info": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
258
258
|
"inlist": _propTypes.default.any,
|
|
259
|
+
"inputHint": _propTypes.default.string,
|
|
259
260
|
"inputIcon": _propTypes.default.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
260
261
|
"inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
261
262
|
"inputRef": _propTypes.default.func,
|
|
@@ -680,7 +681,6 @@ GroupedCharacter.propTypes = {
|
|
|
680
681
|
"value": _propTypes.default.string,
|
|
681
682
|
"vocab": _propTypes.default.string,
|
|
682
683
|
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
683
|
-
"warnOverLimit": _propTypes.default.bool,
|
|
684
684
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
685
685
|
};
|
|
686
686
|
GroupedCharacter.displayName = "GroupedCharacter";
|
|
@@ -38,6 +38,11 @@ I18nProvider.propTypes = {
|
|
|
38
38
|
"batchSelection": _propTypes.default.shape({
|
|
39
39
|
"selected": _propTypes.default.func.isRequired
|
|
40
40
|
}),
|
|
41
|
+
"characterCount": _propTypes.default.shape({
|
|
42
|
+
"charactersLeft": _propTypes.default.func.isRequired,
|
|
43
|
+
"hintString": _propTypes.default.func.isRequired,
|
|
44
|
+
"tooManyCharacters": _propTypes.default.func.isRequired
|
|
45
|
+
}),
|
|
41
46
|
"confirm": _propTypes.default.shape({
|
|
42
47
|
"no": _propTypes.default.func.isRequired,
|
|
43
48
|
"yes": _propTypes.default.func.isRequired
|
|
@@ -135,7 +135,7 @@ Number.propTypes = {
|
|
|
135
135
|
"autoFocus": _propTypes.default.bool,
|
|
136
136
|
"autoSave": _propTypes.default.string,
|
|
137
137
|
"capture": _propTypes.default.oneOfType([_propTypes.default.oneOf(["environment", "user"]), _propTypes.default.bool]),
|
|
138
|
-
"characterLimit": _propTypes.default.
|
|
138
|
+
"characterLimit": _propTypes.default.number,
|
|
139
139
|
"checked": _propTypes.default.bool,
|
|
140
140
|
"children": _propTypes.default.node,
|
|
141
141
|
"className": _propTypes.default.string,
|
|
@@ -179,6 +179,7 @@ Number.propTypes = {
|
|
|
179
179
|
"id": _propTypes.default.string,
|
|
180
180
|
"info": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
181
181
|
"inlist": _propTypes.default.any,
|
|
182
|
+
"inputHint": _propTypes.default.string,
|
|
182
183
|
"inputIcon": _propTypes.default.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
183
184
|
"inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
184
185
|
"inputRef": _propTypes.default.func,
|
|
@@ -602,7 +603,6 @@ Number.propTypes = {
|
|
|
602
603
|
"value": _propTypes.default.string,
|
|
603
604
|
"vocab": _propTypes.default.string,
|
|
604
605
|
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
605
|
-
"warnOverLimit": _propTypes.default.bool,
|
|
606
606
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
607
607
|
};
|
|
608
608
|
Number.displayName = "Number";
|
|
@@ -19,7 +19,7 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
|
|
|
19
19
|
/** Automatically focus the input on component mount */
|
|
20
20
|
autoFocus?: boolean;
|
|
21
21
|
/** Character limit of the textarea */
|
|
22
|
-
characterLimit?:
|
|
22
|
+
characterLimit?: number;
|
|
23
23
|
/** Type of the icon that will be rendered next to the input */
|
|
24
24
|
children?: React.ReactNode;
|
|
25
25
|
/** The visible width of the text control, in average character widths */
|
|
@@ -34,6 +34,8 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
|
|
|
34
34
|
error?: boolean | string;
|
|
35
35
|
/** Allows the Textareas Height to change based on user input */
|
|
36
36
|
expandable?: boolean;
|
|
37
|
+
/** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
|
|
38
|
+
inputHint?: string;
|
|
37
39
|
/** Help content to be displayed under an input */
|
|
38
40
|
fieldHelp?: React.ReactNode;
|
|
39
41
|
/** Aria label for rendered help component */
|
|
@@ -89,8 +91,6 @@ export interface TextareaProps extends ValidationProps, MarginProps, Omit<Common
|
|
|
89
91
|
validationOnLabel?: boolean;
|
|
90
92
|
/** The value of the Textbox */
|
|
91
93
|
value?: string;
|
|
92
|
-
/** Whether to display the character count message in red */
|
|
93
|
-
warnOverLimit?: boolean;
|
|
94
94
|
/** Indicate that warning has occurred
|
|
95
95
|
Pass string to display icon, tooltip and orange border
|
|
96
96
|
Pass true boolean to only display orange border */
|
|
@@ -54,13 +54,13 @@ let deprecateInputRefWarnTriggered = false;
|
|
|
54
54
|
const Textarea = /*#__PURE__*/_react.default.forwardRef(({
|
|
55
55
|
"aria-labelledby": ariaLabelledBy,
|
|
56
56
|
autoFocus,
|
|
57
|
+
inputHint,
|
|
57
58
|
fieldHelp,
|
|
58
59
|
label,
|
|
59
60
|
size,
|
|
60
61
|
children,
|
|
61
62
|
characterLimit,
|
|
62
63
|
enforceCharacterLimit = true,
|
|
63
|
-
warnOverLimit = false,
|
|
64
64
|
onChange,
|
|
65
65
|
disabled = false,
|
|
66
66
|
labelInline,
|
|
@@ -147,8 +147,7 @@ const Textarea = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
147
147
|
label,
|
|
148
148
|
fieldHelp
|
|
149
149
|
});
|
|
150
|
-
const [maxLength, characterCount] = (0, _useCharacterCount.default)(value,
|
|
151
|
-
typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
|
|
150
|
+
const [maxLength, characterCount, characterCountHintId, characterCountHint] = (0, _useCharacterCount.default)(value, characterLimit, enforceCharacterLimit);
|
|
152
151
|
(0, _react.useEffect)(() => {
|
|
153
152
|
if (rows) {
|
|
154
153
|
var _internalRef$current;
|
|
@@ -176,6 +175,12 @@ const Textarea = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
176
175
|
};
|
|
177
176
|
}, [expandable]);
|
|
178
177
|
const hasIconInside = !!(inputIcon || validationIconId && !validationOnLabel);
|
|
178
|
+
const hintId = (0, _react.useRef)((0, _guid.default)());
|
|
179
|
+
const characterCountHintIdValue = characterCount ? characterCountHintId : undefined;
|
|
180
|
+
const inputHintIdValue = inputHint ? hintId.current : undefined;
|
|
181
|
+
const hintIdValue = characterLimit ? characterCountHintIdValue : inputHintIdValue;
|
|
182
|
+
const ariaDescribedByValues = [validationRedesignOptIn ? undefined : ariaDescribedBy, hintIdValue];
|
|
183
|
+
const ariaDescribedByValue = ariaDescribedByValues.filter(Boolean).join(" ");
|
|
179
184
|
|
|
180
185
|
const input = /*#__PURE__*/_react.default.createElement(_input.InputPresentation, {
|
|
181
186
|
size: size,
|
|
@@ -189,7 +194,7 @@ const Textarea = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
189
194
|
}, /*#__PURE__*/_react.default.createElement(_input2.default, _extends({
|
|
190
195
|
"aria-invalid": !!error,
|
|
191
196
|
"aria-labelledby": ariaLabelledBy,
|
|
192
|
-
"aria-describedby":
|
|
197
|
+
"aria-describedby": ariaDescribedByValue,
|
|
193
198
|
autoFocus: autoFocus,
|
|
194
199
|
name: name,
|
|
195
200
|
value: value,
|
|
@@ -245,7 +250,10 @@ const Textarea = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
245
250
|
useValidationIcon: computeLabelPropValues(validationOnLabel),
|
|
246
251
|
adaptiveLabelBreakpoint: adaptiveLabelBreakpoint,
|
|
247
252
|
validationRedesignOptIn: validationRedesignOptIn
|
|
248
|
-
},
|
|
253
|
+
}, characterLimit || inputHint ? /*#__PURE__*/_react.default.createElement(_textbox.StyledInputHint, {
|
|
254
|
+
id: hintIdValue,
|
|
255
|
+
"data-element": "input-hint"
|
|
256
|
+
}, characterCountHint || inputHint) : null, validationRedesignOptIn && labelHelp && /*#__PURE__*/_react.default.createElement(_textbox.StyledHintText, null, labelHelp), validationRedesignOptIn ? /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
249
257
|
position: "relative"
|
|
250
258
|
}, /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
|
|
251
259
|
error: error,
|
|
@@ -318,7 +326,7 @@ Textarea.propTypes = {
|
|
|
318
326
|
"autoFocus": _propTypes.default.bool,
|
|
319
327
|
"autoSave": _propTypes.default.string,
|
|
320
328
|
"capture": _propTypes.default.oneOfType([_propTypes.default.oneOf(["environment", "user"]), _propTypes.default.bool]),
|
|
321
|
-
"characterLimit": _propTypes.default.
|
|
329
|
+
"characterLimit": _propTypes.default.number,
|
|
322
330
|
"checked": _propTypes.default.bool,
|
|
323
331
|
"children": _propTypes.default.node,
|
|
324
332
|
"className": _propTypes.default.string,
|
|
@@ -359,6 +367,7 @@ Textarea.propTypes = {
|
|
|
359
367
|
"id": _propTypes.default.string,
|
|
360
368
|
"info": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
361
369
|
"inlist": _propTypes.default.any,
|
|
370
|
+
"inputHint": _propTypes.default.string,
|
|
362
371
|
"inputIcon": _propTypes.default.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
363
372
|
"inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
364
373
|
"inputRef": _propTypes.default.func,
|
|
@@ -779,7 +788,6 @@ Textarea.propTypes = {
|
|
|
779
788
|
"value": _propTypes.default.string,
|
|
780
789
|
"vocab": _propTypes.default.string,
|
|
781
790
|
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
782
|
-
"warnOverLimit": _propTypes.default.bool,
|
|
783
791
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
784
792
|
};
|
|
785
793
|
Textarea.displayName = "Textarea";
|
|
@@ -16,6 +16,8 @@ export interface CommonTextboxProps extends ValidationProps, MarginProps, Omit<C
|
|
|
16
16
|
adaptiveLabelBreakpoint?: number;
|
|
17
17
|
/** Integer to determine a timeout for the deferred callback */
|
|
18
18
|
deferTimeout?: number;
|
|
19
|
+
/** A hint string rendered before the input but after the label. Intended to describe the purpose or content of the input. */
|
|
20
|
+
inputHint?: string;
|
|
19
21
|
/** Help content to be displayed under an input */
|
|
20
22
|
fieldHelp?: React.ReactNode;
|
|
21
23
|
/**
|
|
@@ -91,11 +93,9 @@ export interface TextboxProps extends CommonTextboxProps {
|
|
|
91
93
|
/** Container for DatePicker or SelectList components */
|
|
92
94
|
positionedChildren?: React.ReactNode;
|
|
93
95
|
/** Character limit of the textarea */
|
|
94
|
-
characterLimit?:
|
|
96
|
+
characterLimit?: number;
|
|
95
97
|
/** Stop the user typing over the characterLimit */
|
|
96
98
|
enforceCharacterLimit?: boolean;
|
|
97
|
-
/** Whether to display the character count message in red */
|
|
98
|
-
warnOverLimit?: boolean;
|
|
99
99
|
}
|
|
100
100
|
export declare const Textbox: React.ForwardRefExoticComponent<TextboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
101
101
|
export default Textbox;
|
|
@@ -41,6 +41,8 @@ var _box = _interopRequireDefault(require("../box"));
|
|
|
41
41
|
|
|
42
42
|
var _logger = _interopRequireDefault(require("../../__internal__/utils/logger"));
|
|
43
43
|
|
|
44
|
+
var _guid = _interopRequireDefault(require("../../__internal__/utils/helpers/guid"));
|
|
45
|
+
|
|
44
46
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
47
|
|
|
46
48
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
@@ -66,6 +68,7 @@ const Textbox = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
66
68
|
labelSpacing,
|
|
67
69
|
id,
|
|
68
70
|
formattedValue,
|
|
71
|
+
inputHint,
|
|
69
72
|
fieldHelp,
|
|
70
73
|
error,
|
|
71
74
|
warning,
|
|
@@ -102,13 +105,11 @@ const Textbox = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
102
105
|
"data-role": dataRole,
|
|
103
106
|
enforceCharacterLimit = true,
|
|
104
107
|
characterLimit,
|
|
105
|
-
warnOverLimit = false,
|
|
106
108
|
helpAriaLabel,
|
|
107
109
|
...props
|
|
108
110
|
}, ref) => {
|
|
109
111
|
const characterCountValue = typeof value === "string" ? value : "";
|
|
110
|
-
const [maxLength, characterCount] = (0, _useCharacterCount.default)(characterCountValue,
|
|
111
|
-
typeof characterLimit === "string" ? parseInt(characterLimit, 10) : characterLimit, warnOverLimit, enforceCharacterLimit);
|
|
112
|
+
const [maxLength, characterCount, characterCountHintId, characterCountHint] = (0, _useCharacterCount.default)(characterCountValue, characterLimit, enforceCharacterLimit);
|
|
112
113
|
const {
|
|
113
114
|
validationRedesignOptIn
|
|
114
115
|
} = (0, _react.useContext)(_carbonProvider.NewValidationContext);
|
|
@@ -139,6 +140,12 @@ const Textbox = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
139
140
|
label,
|
|
140
141
|
fieldHelp
|
|
141
142
|
});
|
|
143
|
+
const hintId = (0, _react.useRef)((0, _guid.default)());
|
|
144
|
+
const characterCountHintIdValue = characterCount ? characterCountHintId : undefined;
|
|
145
|
+
const inputHintIdValue = inputHint ? hintId.current : undefined;
|
|
146
|
+
const hintIdValue = characterLimit ? characterCountHintIdValue : inputHintIdValue;
|
|
147
|
+
const ariaDescribedByValues = [validationRedesignOptIn ? undefined : ariaDescribedBy, hintIdValue];
|
|
148
|
+
const ariaDescribedByValue = ariaDescribedByValues.filter(Boolean).join(" ");
|
|
142
149
|
const hasIconInside = !!(inputIcon || validationIconId && !validationOnLabel);
|
|
143
150
|
|
|
144
151
|
const input = /*#__PURE__*/_react.default.createElement(_input.InputPresentation, {
|
|
@@ -162,7 +169,7 @@ const Textbox = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
162
169
|
align: align,
|
|
163
170
|
"aria-invalid": !!error,
|
|
164
171
|
"aria-labelledby": ariaLabelledBy,
|
|
165
|
-
"aria-describedby":
|
|
172
|
+
"aria-describedby": ariaDescribedByValue,
|
|
166
173
|
autoFocus: autoFocus,
|
|
167
174
|
deferTimeout: deferTimeout,
|
|
168
175
|
disabled: disabled,
|
|
@@ -224,7 +231,10 @@ const Textbox = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
224
231
|
"data-element": dataElement,
|
|
225
232
|
validationIconId: validationRedesignOptIn ? undefined : validationIconId,
|
|
226
233
|
validationRedesignOptIn: validationRedesignOptIn
|
|
227
|
-
}, (0, _utils.filterStyledSystemMarginProps)(props)),
|
|
234
|
+
}, (0, _utils.filterStyledSystemMarginProps)(props)), characterLimit || inputHint ? /*#__PURE__*/_react.default.createElement(_textbox.StyledInputHint, {
|
|
235
|
+
id: hintIdValue,
|
|
236
|
+
"data-element": "input-hint"
|
|
237
|
+
}, characterCountHint || inputHint) : null, validationRedesignOptIn && labelHelp && /*#__PURE__*/_react.default.createElement(_textbox.StyledHintText, null, labelHelp), validationRedesignOptIn ? /*#__PURE__*/_react.default.createElement(_box.default, {
|
|
228
238
|
position: "relative"
|
|
229
239
|
}, /*#__PURE__*/_react.default.createElement(_validationMessage.default, {
|
|
230
240
|
error: error,
|
|
@@ -297,7 +307,7 @@ Textbox.propTypes = {
|
|
|
297
307
|
"autoFocus": _propTypes.default.bool,
|
|
298
308
|
"autoSave": _propTypes.default.string,
|
|
299
309
|
"capture": _propTypes.default.oneOfType([_propTypes.default.oneOf(["environment", "user"]), _propTypes.default.bool]),
|
|
300
|
-
"characterLimit": _propTypes.default.
|
|
310
|
+
"characterLimit": _propTypes.default.number,
|
|
301
311
|
"checked": _propTypes.default.bool,
|
|
302
312
|
"children": _propTypes.default.node,
|
|
303
313
|
"className": _propTypes.default.string,
|
|
@@ -341,6 +351,7 @@ Textbox.propTypes = {
|
|
|
341
351
|
"id": _propTypes.default.string,
|
|
342
352
|
"info": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
343
353
|
"inlist": _propTypes.default.any,
|
|
354
|
+
"inputHint": _propTypes.default.string,
|
|
344
355
|
"inputIcon": _propTypes.default.oneOf(["add", "admin", "alert_on", "alert", "analysis", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bin", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "coins", "collaborate", "computer_clock", "connect", "construction", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "help", "hide", "home", "image", "in_progress", "in_transit", "individual", "info", "italic", "key", "laptop", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "link", "list_view", "location", "locked", "logout", "lookup", "marker", "message", "minus_large", "minus", "mobile", "money_bag", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "question_hollow", "question_mark", "question", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "sync", "tag", "talk", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "warning"]),
|
|
345
356
|
"inputMode": _propTypes.default.oneOf(["decimal", "email", "none", "numeric", "search", "tel", "text", "url"]),
|
|
346
357
|
"inputRef": _propTypes.default.func,
|
|
@@ -764,7 +775,6 @@ Textbox.propTypes = {
|
|
|
764
775
|
"value": _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.number, _propTypes.default.string]),
|
|
765
776
|
"vocab": _propTypes.default.string,
|
|
766
777
|
"warning": _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
|
|
767
|
-
"warnOverLimit": _propTypes.default.bool,
|
|
768
778
|
"width": _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string])
|
|
769
779
|
};
|
|
770
780
|
Textbox.displayName = "Textbox";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
declare const ErrorBorder: import("styled-components").StyledComponent<"span", any, {
|
|
2
2
|
warning: boolean;
|
|
3
3
|
}, never>;
|
|
4
|
-
declare const
|
|
5
|
-
|
|
4
|
+
declare const StyledInputHint: import("styled-components").StyledComponent<"p", any, {}, never>;
|
|
5
|
+
declare const StyledHintText: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
6
|
+
export { StyledHintText, ErrorBorder, StyledInputHint };
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ErrorBorder = exports.StyledHintText = void 0;
|
|
6
|
+
exports.StyledInputHint = exports.ErrorBorder = exports.StyledHintText = void 0;
|
|
7
7
|
|
|
8
8
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
9
|
|
|
@@ -25,7 +25,16 @@ const ErrorBorder = _styledComponents.default.span`
|
|
|
25
25
|
`}
|
|
26
26
|
`;
|
|
27
27
|
exports.ErrorBorder = ErrorBorder;
|
|
28
|
-
const
|
|
28
|
+
const StyledInputHint = _styledComponents.default.p`
|
|
29
|
+
display: block;
|
|
30
|
+
flex: 1;
|
|
31
|
+
margin-top: -3px;
|
|
32
|
+
margin-bottom: 8px;
|
|
33
|
+
color: var(--colorsUtilityYin055);
|
|
34
|
+
white-space: pre-wrap;
|
|
35
|
+
`;
|
|
36
|
+
exports.StyledInputHint = StyledInputHint;
|
|
37
|
+
const StyledHintText = _styledComponents.default.div`
|
|
29
38
|
margin-top: 0px;
|
|
30
39
|
margin-bottom: 8px;
|
|
31
40
|
color: var(--colorsUtilityYin055);
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
declare const useCharacterCount: (value?: string, characterLimit?: number | undefined,
|
|
2
|
+
declare const useCharacterCount: (value?: string, characterLimit?: number | undefined, enforceCharacterLimit?: boolean) => [
|
|
3
|
+
number | undefined,
|
|
4
|
+
JSX.Element | null,
|
|
5
|
+
string | undefined,
|
|
6
|
+
string | null
|
|
7
|
+
];
|
|
3
8
|
export default useCharacterCount;
|
|
@@ -11,17 +11,19 @@ var _characterCount = _interopRequireDefault(require("../../../__internal__/char
|
|
|
11
11
|
|
|
12
12
|
var _useLocale = _interopRequireDefault(require("../useLocale"));
|
|
13
13
|
|
|
14
|
+
var _guid = _interopRequireDefault(require("../../../__internal__/utils/helpers/guid"));
|
|
15
|
+
|
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
17
|
|
|
16
18
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
17
19
|
|
|
18
20
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
21
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const useCharacterCount = (value = "", characterLimit, warnOverLimit = false, enforceCharacterLimit = true) => {
|
|
22
|
+
const useCharacterCount = (value = "", characterLimit, enforceCharacterLimit = true) => {
|
|
23
23
|
const isCharacterLimitValid = typeof characterLimit === "number" && !Number.isNaN(characterLimit);
|
|
24
24
|
const l = (0, _useLocale.default)();
|
|
25
|
+
const hintString = l.characterCount.hintString();
|
|
26
|
+
const hintId = (0, _react.useRef)((0, _guid.default)());
|
|
25
27
|
const isOverLimit = (0, _react.useMemo)(() => {
|
|
26
28
|
if (value && isCharacterLimitValid) {
|
|
27
29
|
return value.length > characterLimit;
|
|
@@ -30,11 +32,11 @@ const useCharacterCount = (value = "", characterLimit, warnOverLimit = false, en
|
|
|
30
32
|
return false;
|
|
31
33
|
}, [value, characterLimit, isCharacterLimitValid]);
|
|
32
34
|
return [enforceCharacterLimit && isCharacterLimitValid ? characterLimit : undefined, isCharacterLimitValid ? /*#__PURE__*/_react.default.createElement(_characterCount.default, {
|
|
33
|
-
isOverLimit: isOverLimit
|
|
34
|
-
value:
|
|
35
|
-
limit:
|
|
35
|
+
isOverLimit: isOverLimit,
|
|
36
|
+
value: value.length,
|
|
37
|
+
limit: characterLimit,
|
|
36
38
|
"data-element": "character-limit"
|
|
37
|
-
}) : null];
|
|
39
|
+
}) : null, hintId.current, isCharacterLimitValid ? hintString : null];
|
|
38
40
|
};
|
|
39
41
|
|
|
40
42
|
var _default = useCharacterCount;
|
package/lib/locales/en-gb.js
CHANGED
|
@@ -25,6 +25,11 @@ const enGB = {
|
|
|
25
25
|
no: () => "No",
|
|
26
26
|
yes: () => "Yes"
|
|
27
27
|
},
|
|
28
|
+
characterCount: {
|
|
29
|
+
hintString: () => "Input contains a character counter",
|
|
30
|
+
tooManyCharacters: (count, formattedCount) => count === 1 ? `You have ${formattedCount} character too many` : `You have ${formattedCount} characters too many`,
|
|
31
|
+
charactersLeft: (count, formattedCount) => count === 1 ? `You have ${formattedCount} character remaining` : `You have ${formattedCount} characters remaining`
|
|
32
|
+
},
|
|
28
33
|
date: {
|
|
29
34
|
dateFnsLocale: () => _dateFnsLocales.enGB
|
|
30
35
|
},
|
package/lib/locales/locale.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ interface Locale {
|
|
|
11
11
|
batchSelection: {
|
|
12
12
|
selected: (count: number | string) => string;
|
|
13
13
|
};
|
|
14
|
+
characterCount: {
|
|
15
|
+
hintString: () => string;
|
|
16
|
+
tooManyCharacters: (count: number, formattedCount: string) => string;
|
|
17
|
+
charactersLeft: (count: number, formattedCount: string) => string;
|
|
18
|
+
};
|
|
14
19
|
confirm: {
|
|
15
20
|
no: () => string;
|
|
16
21
|
yes: () => string;
|
package/lib/locales/pl-pl.d.ts
CHANGED
package/lib/locales/pl-pl.js
CHANGED
|
@@ -3,12 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.PolishPlurals = exports.PolishPlural = void 0;
|
|
7
7
|
|
|
8
8
|
var _dateFnsLocales = require("./date-fns-locales");
|
|
9
9
|
|
|
10
10
|
const isSingular = count => (typeof count === "string" ? parseInt(count) : count) === 1;
|
|
11
11
|
|
|
12
|
+
const PolishPlural = (singularNominativ, pluralNominativ, pluralGenitive, value) => {
|
|
13
|
+
if (value === 1) {
|
|
14
|
+
return singularNominativ;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (value % 10 >= 2 && value % 10 <= 4 && (value % 100 < 10 || value % 100 >= 20)) {
|
|
18
|
+
return pluralNominativ;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return pluralGenitive;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.PolishPlurals = exports.PolishPlural = PolishPlural;
|
|
12
25
|
const plPL = {
|
|
13
26
|
locale: () => "pl-PL",
|
|
14
27
|
actions: {
|
|
@@ -25,6 +38,11 @@ const plPL = {
|
|
|
25
38
|
no: () => "Nie",
|
|
26
39
|
yes: () => "Tak"
|
|
27
40
|
},
|
|
41
|
+
characterCount: {
|
|
42
|
+
hintString: () => "Pole zawiera licznik znaków",
|
|
43
|
+
tooManyCharacters: (count, formattedCount) => `Masz o ${formattedCount} ${PolishPlural("znak", "znaki", "znaków", count)} za dużo`,
|
|
44
|
+
charactersLeft: (count, formattedCount) => `Masz ${formattedCount} ${PolishPlural("pozostały", "pozostałe", "pozostałych", count)} ${PolishPlural("znak", "znaki", "znaków", count)}`
|
|
45
|
+
},
|
|
28
46
|
date: {
|
|
29
47
|
dateFnsLocale: () => _dateFnsLocales.pl
|
|
30
48
|
},
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "117.0.0",
|
|
4
4
|
"description": "A library of reusable React components for easily building user interfaces.",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib",
|
|
7
7
|
"esm",
|
|
8
|
-
"scripts/check_rfcs/check_rfcs.js"
|
|
8
|
+
"scripts/check_rfcs/check_rfcs.js",
|
|
9
|
+
"scripts/check_rfcs/index.js"
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
12
|
"start": "node ./scripts/check_node_version.js && NODE_OPTIONS=--openssl-legacy-provider start-storybook -p 9001 -c .storybook",
|