@sb1/ffe-form-react 23.1.10 → 23.2.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/es/InputGroup.js +3 -1
- package/es/Label.js +2 -2
- package/lib/InputGroup.js +3 -1
- package/lib/Label.js +2 -2
- package/package.json +4 -4
- package/types/InputGroup.d.ts +2 -0
- package/types/Label.d.ts +2 -1
package/es/InputGroup.js
CHANGED
|
@@ -36,6 +36,7 @@ var getChildrenWithExtraProps = function (children, extraProps) {
|
|
|
36
36
|
};
|
|
37
37
|
export var InputGroup = function (_a) {
|
|
38
38
|
var inputId = _a.inputId, children = _a.children, className = _a.className, _b = _a.extraMargin, extraMargin = _b === void 0 ? true : _b, description = _a.description, label = _a.label, fieldMessage = _a.fieldMessage, tooltip = _a.tooltip, onTooltipToggle = _a.onTooltipToggle, labelId = _a.labelId, rest = __rest(_a, ["inputId", "children", "className", "extraMargin", "description", "label", "fieldMessage", "tooltip", "onTooltipToggle", "labelId"]);
|
|
39
|
+
var _c = React.useState(false), labelAsSpan = _c[0], setLabelAsSpan = _c[1];
|
|
39
40
|
var generatedInputId = useId();
|
|
40
41
|
var id = inputId !== null && inputId !== void 0 ? inputId : generatedInputId;
|
|
41
42
|
var descriptionId = description ? "".concat(id, "-description") : undefined;
|
|
@@ -74,13 +75,14 @@ export var InputGroup = function (_a) {
|
|
|
74
75
|
id: id,
|
|
75
76
|
'aria-invalid': isInvalid ? 'true' : 'false',
|
|
76
77
|
'aria-describedby': ariaDescribedBy,
|
|
78
|
+
setInputGroupLabelAsSpan: function () { return setLabelAsSpan(true); },
|
|
77
79
|
};
|
|
78
80
|
var modifiedChildren = getChildrenWithExtraProps(children, extraProps);
|
|
79
81
|
return (React.createElement("div", __assign({ className: classNames('ffe-input-group', {
|
|
80
82
|
'ffe-input-group--no-extra-margin': !extraMargin,
|
|
81
83
|
'ffe-input-group--message': hasMessage,
|
|
82
84
|
}, className) }, rest),
|
|
83
|
-
typeof label === 'string' ? (React.createElement(Label, { htmlFor: id, id: labelId }, label)) : (React.isValidElement(label) &&
|
|
85
|
+
typeof label === 'string' ? (React.createElement(Label, { as: labelAsSpan ? 'span' : 'label', htmlFor: id, id: labelId }, label)) : (React.isValidElement(label) &&
|
|
84
86
|
React.cloneElement(label, {
|
|
85
87
|
htmlFor: id,
|
|
86
88
|
id: labelId,
|
package/es/Label.js
CHANGED
|
@@ -23,8 +23,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
23
23
|
import React from 'react';
|
|
24
24
|
import classNames from 'classnames';
|
|
25
25
|
export var Label = function (_a) {
|
|
26
|
-
var block = _a.block, children = _a.children, className = _a.className, htmlFor = _a.htmlFor, rest = __rest(_a, ["block", "children", "className", "htmlFor"]);
|
|
27
|
-
return (React.createElement(
|
|
26
|
+
var _b = _a.as, Comp = _b === void 0 ? 'label' : _b, block = _a.block, children = _a.children, className = _a.className, htmlFor = _a.htmlFor, rest = __rest(_a, ["as", "block", "children", "className", "htmlFor"]);
|
|
27
|
+
return (React.createElement(Comp, __assign({ className: classNames('ffe-form-label', className, {
|
|
28
28
|
'ffe-form-label--block': block,
|
|
29
29
|
}), htmlFor: htmlFor }, rest), children));
|
|
30
30
|
};
|
package/lib/InputGroup.js
CHANGED
|
@@ -75,6 +75,7 @@ var getChildrenWithExtraProps = function (children, extraProps) {
|
|
|
75
75
|
};
|
|
76
76
|
var InputGroup = function (_a) {
|
|
77
77
|
var inputId = _a.inputId, children = _a.children, className = _a.className, _b = _a.extraMargin, extraMargin = _b === void 0 ? true : _b, description = _a.description, label = _a.label, fieldMessage = _a.fieldMessage, tooltip = _a.tooltip, onTooltipToggle = _a.onTooltipToggle, labelId = _a.labelId, rest = __rest(_a, ["inputId", "children", "className", "extraMargin", "description", "label", "fieldMessage", "tooltip", "onTooltipToggle", "labelId"]);
|
|
78
|
+
var _c = react_1.default.useState(false), labelAsSpan = _c[0], setLabelAsSpan = _c[1];
|
|
78
79
|
var generatedInputId = (0, react_1.useId)();
|
|
79
80
|
var id = inputId !== null && inputId !== void 0 ? inputId : generatedInputId;
|
|
80
81
|
var descriptionId = description ? "".concat(id, "-description") : undefined;
|
|
@@ -113,13 +114,14 @@ var InputGroup = function (_a) {
|
|
|
113
114
|
id: id,
|
|
114
115
|
'aria-invalid': isInvalid ? 'true' : 'false',
|
|
115
116
|
'aria-describedby': ariaDescribedBy,
|
|
117
|
+
setInputGroupLabelAsSpan: function () { return setLabelAsSpan(true); },
|
|
116
118
|
};
|
|
117
119
|
var modifiedChildren = getChildrenWithExtraProps(children, extraProps);
|
|
118
120
|
return (react_1.default.createElement("div", __assign({ className: (0, classnames_1.default)('ffe-input-group', {
|
|
119
121
|
'ffe-input-group--no-extra-margin': !extraMargin,
|
|
120
122
|
'ffe-input-group--message': hasMessage,
|
|
121
123
|
}, className) }, rest),
|
|
122
|
-
typeof label === 'string' ? (react_1.default.createElement(Label_1.Label, { htmlFor: id, id: labelId }, label)) : (react_1.default.isValidElement(label) &&
|
|
124
|
+
typeof label === 'string' ? (react_1.default.createElement(Label_1.Label, { as: labelAsSpan ? 'span' : 'label', htmlFor: id, id: labelId }, label)) : (react_1.default.isValidElement(label) &&
|
|
123
125
|
react_1.default.cloneElement(label, {
|
|
124
126
|
htmlFor: id,
|
|
125
127
|
id: labelId,
|
package/lib/Label.js
CHANGED
|
@@ -29,8 +29,8 @@ exports.Label = void 0;
|
|
|
29
29
|
var react_1 = __importDefault(require("react"));
|
|
30
30
|
var classnames_1 = __importDefault(require("classnames"));
|
|
31
31
|
var Label = function (_a) {
|
|
32
|
-
var block = _a.block, children = _a.children, className = _a.className, htmlFor = _a.htmlFor, rest = __rest(_a, ["block", "children", "className", "htmlFor"]);
|
|
33
|
-
return (react_1.default.createElement(
|
|
32
|
+
var _b = _a.as, Comp = _b === void 0 ? 'label' : _b, block = _a.block, children = _a.children, className = _a.className, htmlFor = _a.htmlFor, rest = __rest(_a, ["as", "block", "children", "className", "htmlFor"]);
|
|
33
|
+
return (react_1.default.createElement(Comp, __assign({ className: (0, classnames_1.default)('ffe-form-label', className, {
|
|
34
34
|
'ffe-form-label--block': block,
|
|
35
35
|
}), htmlFor: htmlFor }, rest), children));
|
|
36
36
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sb1/ffe-form-react",
|
|
3
|
-
"version": "23.1
|
|
3
|
+
"version": "23.2.1",
|
|
4
4
|
"description": "React component for form elements in ffe",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "SpareBank 1",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"test:watch": "ffe-buildtool jest --watch"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sb1/ffe-collapse-react": "^5.1.
|
|
30
|
-
"@sb1/ffe-form": "^32.0.
|
|
29
|
+
"@sb1/ffe-collapse-react": "^5.1.15",
|
|
30
|
+
"@sb1/ffe-form": "^32.0.7",
|
|
31
31
|
"classnames": "^2.3.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "2ff1ce6aa6e7ea7f11da6944332998a585cd8226"
|
|
47
47
|
}
|
package/types/InputGroup.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ type ChildrenExtraProps = {
|
|
|
4
4
|
id: string;
|
|
5
5
|
'aria-invalid': 'true' | 'false';
|
|
6
6
|
'aria-describedby': string | undefined;
|
|
7
|
+
/** Hack that changes label to a span to be wcag complient */
|
|
8
|
+
setInputGroupLabelAsSpan?: () => void;
|
|
7
9
|
};
|
|
8
10
|
export interface InputGroupProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'children'> {
|
|
9
11
|
/** The id that will be used on the input child if you don't want a generated one */
|
package/types/Label.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ElementType } from 'react';
|
|
2
2
|
export interface LabelProps extends React.ComponentPropsWithoutRef<'label'> {
|
|
3
|
+
as?: ElementType;
|
|
3
4
|
/**
|
|
4
5
|
* Labels default to `display: inline-block;` to have tooltips appear immediately to the right.
|
|
5
6
|
* Set this to `true` if you don't use tooltips and need the label to be `display: block;`.
|