@ndla/primitives 0.0.2 → 0.0.4
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/dist/panda.buildinfo.json +95 -25
- package/dist/styles.css +340 -50
- package/es/ArticleLists.js +4 -32
- package/es/Badge.js +4 -16
- package/es/BlockQuote.js +5 -17
- package/es/Button.js +40 -33
- package/es/Checkbox.js +160 -51
- package/es/Dialog.js +6 -7
- package/es/ExpandableBox.js +4 -17
- package/es/Field.js +17 -0
- package/es/FieldErrorMessage.js +12 -16
- package/es/FieldHelper.js +9 -12
- package/es/FramedContent.js +3 -15
- package/es/Icon.js +9 -6
- package/es/Input.js +25 -23
- package/es/Label.js +15 -39
- package/es/Menu.js +32 -6
- package/es/MessageBox.js +3 -15
- package/es/NdlaLogo.js +6 -5
- package/es/RadioGroup.js +7 -11
- package/es/Skeleton.js +2 -8
- package/es/Spinner.js +3 -15
- package/es/Switch.js +8 -15
- package/es/Table.js +2 -5
- package/es/Tabs.js +231 -0
- package/es/Text.js +33 -32
- package/es/Toast.js +14 -6
- package/es/createStyleContext.js +15 -7
- package/lib/Accordion.d.ts +14 -7
- package/lib/ArticleLists.d.ts +9 -11
- package/lib/ArticleLists.js +5 -36
- package/lib/Badge.d.ts +9 -4
- package/lib/Badge.js +4 -17
- package/lib/BlockQuote.d.ts +9 -3
- package/lib/BlockQuote.js +5 -18
- package/lib/Button.d.ts +24 -11
- package/lib/Button.js +39 -32
- package/lib/Checkbox.d.ts +172 -5
- package/lib/Checkbox.js +165 -56
- package/lib/Dialog.d.ts +18 -10
- package/lib/Dialog.js +6 -7
- package/lib/ExpandableBox.d.ts +8 -5
- package/lib/ExpandableBox.js +5 -20
- package/lib/Field.d.ts +9 -0
- package/lib/Field.js +23 -0
- package/lib/FieldErrorMessage.d.ts +3 -3
- package/lib/FieldErrorMessage.js +11 -15
- package/lib/FieldHelper.d.ts +3 -3
- package/lib/FieldHelper.js +8 -11
- package/lib/FramedContent.d.ts +8 -4
- package/lib/FramedContent.js +3 -16
- package/lib/Icon.d.ts +3 -2
- package/lib/Icon.js +8 -5
- package/lib/Input.d.ts +12 -11
- package/lib/Input.js +25 -23
- package/lib/Label.d.ts +13 -7
- package/lib/Label.js +15 -39
- package/lib/Menu.d.ts +66 -13
- package/lib/Menu.js +41 -15
- package/lib/MessageBox.d.ts +8 -4
- package/lib/MessageBox.js +3 -16
- package/lib/NdlaLogo.d.ts +5 -4
- package/lib/NdlaLogo.js +5 -4
- package/lib/Pagination.d.ts +17 -6
- package/lib/Popover.d.ts +34 -13
- package/lib/RadioGroup.d.ts +18 -7
- package/lib/RadioGroup.js +7 -11
- package/lib/Skeleton.d.ts +5 -2
- package/lib/Skeleton.js +3 -10
- package/lib/Slider.d.ts +18 -7
- package/lib/Spinner.d.ts +8 -3
- package/lib/Spinner.js +3 -16
- package/lib/Switch.d.ts +12 -7
- package/lib/Switch.js +13 -20
- package/lib/Table.d.ts +6 -3
- package/lib/Table.js +4 -8
- package/lib/Tabs.d.ts +145 -0
- package/lib/Tabs.js +239 -0
- package/lib/Text.d.ts +6 -9
- package/lib/Text.js +32 -33
- package/lib/Toast.d.ts +10 -7
- package/lib/Toast.js +15 -7
- package/lib/Tooltip.d.ts +19 -7
- package/lib/createStyleContext.d.ts +5 -3
- package/lib/createStyleContext.js +14 -6
- package/package.json +5 -5
- package/es/FormControl.js +0 -163
- package/lib/FormControl.d.ts +0 -65
- package/lib/FormControl.js +0 -173
package/lib/FormControl.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useFormControlProps = exports.useFormControlContext = exports.useFormControl = exports.FormControl = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _jsx2 = require("@ndla/styled-system/jsx");
|
|
9
|
-
var _util = require("@ndla/util");
|
|
10
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
11
|
-
/**
|
|
12
|
-
* Copyright (c) 2024-present, NDLA.
|
|
13
|
-
*
|
|
14
|
-
* This source code is licensed under the GPLv3 license found in the
|
|
15
|
-
* LICENSE file in the root directory of this source tree.
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
const StyledFormControl = (0, _jsx2.styled)("div", {
|
|
20
|
-
base: {
|
|
21
|
-
display: "flex",
|
|
22
|
-
flexDirection: "column",
|
|
23
|
-
gap: "3xsmall"
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
const useFormControlProvider = _ref => {
|
|
27
|
-
let {
|
|
28
|
-
id: idProp,
|
|
29
|
-
isRequired,
|
|
30
|
-
isDisabled,
|
|
31
|
-
isInvalid
|
|
32
|
-
} = _ref;
|
|
33
|
-
const id = "field-".concat(idProp);
|
|
34
|
-
const labelId = "".concat(id, "-label");
|
|
35
|
-
const errorTextId = "".concat(id, "-error-message");
|
|
36
|
-
const helpTextId = "".concat(id, "-helper");
|
|
37
|
-
const [hasErrorText, setHasErrorText] = (0, _react.useState)(false);
|
|
38
|
-
const [hasHelpText, setHasHelpText] = (0, _react.useState)(false);
|
|
39
|
-
const getHelpTextProps = (0, _react.useCallback)(function () {
|
|
40
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
41
|
-
let forwardedRef = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
42
|
-
return {
|
|
43
|
-
id: helpTextId,
|
|
44
|
-
...props,
|
|
45
|
-
ref: (0, _util.composeRefs)(forwardedRef, node => {
|
|
46
|
-
if (!node) return;
|
|
47
|
-
setHasHelpText(true);
|
|
48
|
-
})
|
|
49
|
-
};
|
|
50
|
-
}, [helpTextId]);
|
|
51
|
-
const getLabelProps = (0, _react.useCallback)(function () {
|
|
52
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
53
|
-
let forwardedRef = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
54
|
-
return {
|
|
55
|
-
...props,
|
|
56
|
-
ref: forwardedRef,
|
|
57
|
-
"data-disabled": props !== null && props !== void 0 && props["data-disabled"] ? props["data-disabled"] : isDisabled,
|
|
58
|
-
"data-invalid": props !== null && props !== void 0 && props["data-invalid"] ? props["data-invalid"] : isInvalid,
|
|
59
|
-
id: props.id !== undefined ? props.id : labelId,
|
|
60
|
-
htmlFor: props.htmlFor !== undefined ? props.htmlFor : id
|
|
61
|
-
};
|
|
62
|
-
}, [id, isDisabled, isInvalid, labelId]);
|
|
63
|
-
const getErrorMessageProps = (0, _react.useCallback)(function () {
|
|
64
|
-
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
65
|
-
let forwardedRef = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
66
|
-
return {
|
|
67
|
-
id: errorTextId,
|
|
68
|
-
...props,
|
|
69
|
-
ref: (0, _util.composeRefs)(forwardedRef, node => {
|
|
70
|
-
if (!node) return;
|
|
71
|
-
setHasErrorText(true);
|
|
72
|
-
}),
|
|
73
|
-
"aria-live": "polite"
|
|
74
|
-
};
|
|
75
|
-
}, [errorTextId]);
|
|
76
|
-
return {
|
|
77
|
-
isRequired: !!isRequired,
|
|
78
|
-
isDisabled: !!isDisabled,
|
|
79
|
-
isInvalid: !!isInvalid,
|
|
80
|
-
hasErrorText,
|
|
81
|
-
setHasErrorText,
|
|
82
|
-
hasHelpText,
|
|
83
|
-
setHasHelpText,
|
|
84
|
-
id,
|
|
85
|
-
labelId,
|
|
86
|
-
errorTextId,
|
|
87
|
-
helpTextId,
|
|
88
|
-
getHelpTextProps,
|
|
89
|
-
getErrorMessageProps,
|
|
90
|
-
getLabelProps
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
const FormControlContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Form control component inspired by chakra-ui. Allows for easy composition of form fields.
|
|
97
|
-
*/
|
|
98
|
-
const FormControl = _ref2 => {
|
|
99
|
-
let {
|
|
100
|
-
children,
|
|
101
|
-
id,
|
|
102
|
-
isDisabled,
|
|
103
|
-
isInvalid,
|
|
104
|
-
isRequired,
|
|
105
|
-
...rest
|
|
106
|
-
} = _ref2;
|
|
107
|
-
const context = useFormControlProvider({
|
|
108
|
-
id,
|
|
109
|
-
isDisabled,
|
|
110
|
-
isInvalid,
|
|
111
|
-
isRequired
|
|
112
|
-
});
|
|
113
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(FormControlContext.Provider, {
|
|
114
|
-
value: context,
|
|
115
|
-
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(StyledFormControl, {
|
|
116
|
-
...rest,
|
|
117
|
-
children: children
|
|
118
|
-
})
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
exports.FormControl = FormControl;
|
|
122
|
-
const useFormControlContext = () => {
|
|
123
|
-
const context = (0, _react.useContext)(FormControlContext);
|
|
124
|
-
return context;
|
|
125
|
-
};
|
|
126
|
-
exports.useFormControlContext = useFormControlContext;
|
|
127
|
-
const useFormControlProps = _ref3 => {
|
|
128
|
-
let {
|
|
129
|
-
id,
|
|
130
|
-
disabled,
|
|
131
|
-
required,
|
|
132
|
-
isDisabled,
|
|
133
|
-
isInvalid,
|
|
134
|
-
isRequired,
|
|
135
|
-
...rest
|
|
136
|
-
} = _ref3;
|
|
137
|
-
const field = useFormControlContext();
|
|
138
|
-
const labelIds = [];
|
|
139
|
-
if (field !== null && field !== void 0 && field.hasErrorText && field !== null && field !== void 0 && field.isInvalid) {
|
|
140
|
-
labelIds.push(field.errorTextId);
|
|
141
|
-
}
|
|
142
|
-
if (rest["aria-describedby"]) {
|
|
143
|
-
labelIds.push(rest["aria-describedby"]);
|
|
144
|
-
}
|
|
145
|
-
if (field !== null && field !== void 0 && field.hasHelpText) {
|
|
146
|
-
labelIds.push(field.helpTextId);
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
...rest,
|
|
150
|
-
"aria-describedby": labelIds.join(" ") || undefined,
|
|
151
|
-
id: id !== null && id !== void 0 ? id : field === null || field === void 0 ? void 0 : field.id,
|
|
152
|
-
isDisabled: disabled !== null && disabled !== void 0 ? disabled : field === null || field === void 0 ? void 0 : field.isDisabled,
|
|
153
|
-
isRequired: required !== null && required !== void 0 ? required : field === null || field === void 0 ? void 0 : field.isRequired,
|
|
154
|
-
isInvalid: isInvalid !== null && isInvalid !== void 0 ? isInvalid : field === null || field === void 0 ? void 0 : field.isInvalid
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
exports.useFormControlProps = useFormControlProps;
|
|
158
|
-
const useFormControl = props => {
|
|
159
|
-
const {
|
|
160
|
-
isDisabled,
|
|
161
|
-
isInvalid,
|
|
162
|
-
isRequired,
|
|
163
|
-
...rest
|
|
164
|
-
} = useFormControlProps(props);
|
|
165
|
-
return {
|
|
166
|
-
...rest,
|
|
167
|
-
disabled: isDisabled,
|
|
168
|
-
required: isRequired,
|
|
169
|
-
"aria-invalid": isInvalid ? true : undefined,
|
|
170
|
-
"aria-required": isRequired ? true : undefined
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
exports.useFormControl = useFormControl;
|