@react-ui-org/react-ui 0.64.1 → 0.66.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/README.md +3 -6
- package/dist/react-ui.css +16 -16
- package/dist/react-ui.d.ts +1936 -0
- package/dist/react-ui.development.css +3591 -3003
- package/dist/react-ui.development.js +2028 -1060
- package/dist/react-ui.js +1 -1
- package/package.json +74 -70
- package/src/components/Alert/{Alert.jsx → Alert.tsx} +8 -43
- package/src/components/Alert/Alert.types.ts +34 -0
- package/src/components/Alert/README.md +1 -1
- package/src/components/Alert/index.ts +2 -0
- package/src/components/Badge/Badge.tsx +30 -0
- package/src/components/Badge/Badge.types.ts +24 -0
- package/src/components/Badge/README.md +1 -1
- package/src/components/Badge/index.ts +5 -0
- package/src/components/Button/Button.tsx +110 -0
- package/src/components/Button/Button.types.ts +93 -0
- package/src/components/Button/README.md +1 -1
- package/src/components/Button/helpers/{getRootLabelVisibilityClassName.js → getRootLabelVisibilityClassName.ts} +5 -2
- package/src/components/Button/index.ts +6 -0
- package/src/components/ButtonGroup/{ButtonGroup.jsx → ButtonGroup.tsx} +9 -40
- package/src/components/ButtonGroup/ButtonGroup.types.ts +45 -0
- package/src/components/ButtonGroup/ButtonGroupContext.ts +4 -0
- package/src/components/ButtonGroup/README.md +1 -1
- package/src/components/ButtonGroup/{index.js → index.ts} +4 -0
- package/src/components/Card/Card.tsx +33 -0
- package/src/components/Card/Card.types.ts +46 -0
- package/src/components/Card/{CardBody.jsx → CardBody.tsx} +4 -11
- package/src/components/Card/{CardFooter.jsx → CardFooter.tsx} +4 -15
- package/src/components/Card/README.md +6 -7
- package/src/components/Card/{index.js → index.ts} +5 -0
- package/src/components/CheckboxField/CheckboxField.module.scss +7 -3
- package/src/components/CheckboxField/CheckboxField.tsx +81 -0
- package/src/components/CheckboxField/CheckboxField.types.ts +64 -0
- package/src/components/CheckboxField/README.md +92 -45
- package/src/components/CheckboxField/index.ts +5 -0
- package/src/components/FileInputField/FileInputField.module.scss +7 -3
- package/src/components/FileInputField/{FileInputField.jsx → FileInputField.tsx} +43 -129
- package/src/components/FileInputField/FileInputField.types.ts +101 -0
- package/src/components/FileInputField/README.md +21 -4
- package/src/components/FileInputField/index.ts +6 -0
- package/src/components/FormLayout/FormLayout.module.scss +5 -7
- package/src/components/FormLayout/{FormLayout.jsx → FormLayout.tsx} +15 -50
- package/src/components/FormLayout/FormLayout.types.ts +55 -0
- package/src/components/FormLayout/FormLayoutContext.ts +4 -0
- package/src/components/FormLayout/FormLayoutCustomField.module.scss +7 -3
- package/src/components/FormLayout/{FormLayoutCustomField.jsx → FormLayoutCustomField.tsx} +12 -67
- package/src/components/FormLayout/FormLayoutCustomField.types.ts +60 -0
- package/src/components/FormLayout/FormLayoutCustomFieldContext.ts +4 -0
- package/src/components/FormLayout/README.md +6 -15
- package/src/components/FormLayout/index.ts +14 -0
- package/src/components/Grid/Grid.module.scss +1 -1
- package/src/components/Grid/Grid.tsx +50 -0
- package/src/components/Grid/Grid.types.ts +108 -0
- package/src/components/Grid/GridSpan.tsx +36 -0
- package/src/components/Grid/README.md +2 -2
- package/src/components/Grid/_helpers/generateResponsiveCustomProperties.ts +33 -0
- package/src/components/Grid/index.ts +9 -0
- package/src/components/InputGroup/InputGroup.module.scss +7 -3
- package/src/components/InputGroup/{InputGroup.jsx → InputGroup.tsx} +25 -95
- package/src/components/InputGroup/InputGroup.types.ts +80 -0
- package/src/components/InputGroup/InputGroupContext.ts +4 -0
- package/src/components/InputGroup/README.md +40 -8
- package/src/components/InputGroup/{index.js → index.ts} +4 -0
- package/src/components/Modal/Modal.tsx +172 -0
- package/src/components/Modal/Modal.types.ts +181 -0
- package/src/components/Modal/ModalBody.tsx +34 -0
- package/src/components/Modal/{ModalCloseButton.jsx → ModalCloseButton.tsx} +6 -19
- package/src/components/Modal/{ModalContent.jsx → ModalContent.tsx} +4 -15
- package/src/components/Modal/ModalFooter.tsx +27 -0
- package/src/components/Modal/ModalHeader.tsx +27 -0
- package/src/components/Modal/ModalTitle.tsx +29 -0
- package/src/components/Modal/README.md +9 -9
- package/src/components/Modal/_helpers/{dialogOnCancelHandler.js → dialogOnCancelHandler.ts} +11 -1
- package/src/components/Modal/_helpers/{dialogOnClickHandler.js → dialogOnClickHandler.ts} +13 -7
- package/src/components/Modal/_helpers/{dialogOnCloseHandler.js → dialogOnCloseHandler.ts} +11 -1
- package/src/components/Modal/_helpers/{dialogOnKeyDownHandler.js → dialogOnKeyDownHandler.ts} +19 -6
- package/src/components/Modal/_helpers/{getJustifyClassName.js → getJustifyClassName.ts} +4 -1
- package/src/components/Modal/_helpers/getPositionClassName.ts +10 -0
- package/src/components/Modal/_helpers/getScrollingClassName.ts +14 -0
- package/src/components/Modal/_helpers/{getSizeClassName.js → getSizeClassName.ts} +4 -1
- package/src/components/Modal/_hooks/{useModalFocus.js → useModalFocus.ts} +9 -5
- package/src/components/Modal/_hooks/{useModalScrollPrevention.js → useModalScrollPrevention.ts} +4 -1
- package/src/components/Modal/{index.js → index.ts} +14 -0
- package/src/components/Paper/{Paper.jsx → Paper.tsx} +6 -26
- package/src/components/Paper/Paper.types.ts +19 -0
- package/src/components/Paper/README.md +3 -4
- package/src/components/Paper/index.ts +2 -0
- package/src/components/Popover/Popover.module.scss +1 -1
- package/src/components/Popover/Popover.tsx +61 -0
- package/src/components/Popover/Popover.types.ts +75 -0
- package/src/components/Popover/PopoverWrapper.tsx +27 -0
- package/src/components/Popover/README.md +34 -22
- package/src/components/Popover/_helpers/{cleanPlacementStyle.js → cleanPlacementStyle.ts} +4 -1
- package/src/components/Popover/_helpers/{getRootAlignmentClassName.js → getRootAlignmentClassName.ts} +4 -1
- package/src/components/Popover/_helpers/{getRootSideClassName.js → getRootSideClassName.ts} +4 -1
- package/src/components/Popover/index.ts +8 -0
- package/src/components/Radio/README.md +125 -48
- package/src/components/Radio/Radio.module.scss +7 -3
- package/src/components/Radio/Radio.tsx +116 -0
- package/src/components/Radio/Radio.types.ts +91 -0
- package/src/components/Radio/index.ts +5 -0
- package/src/components/ScrollView/README.md +1 -1
- package/src/components/ScrollView/ScrollView.module.scss +5 -0
- package/src/components/ScrollView/{ScrollView.jsx → ScrollView.tsx} +55 -166
- package/src/components/ScrollView/ScrollView.types.ts +121 -0
- package/src/components/ScrollView/_helpers/getElementsPositionDifference.ts +17 -0
- package/src/components/ScrollView/_hooks/{useLoadResizeHook.js → useLoadResizeHook.ts} +14 -3
- package/src/components/ScrollView/_hooks/{useScrollPositionHook.js → useScrollPositionHook.ts} +11 -4
- package/src/components/ScrollView/index.ts +6 -0
- package/src/components/SelectField/README.md +137 -51
- package/src/components/SelectField/SelectField.module.scss +7 -3
- package/src/components/SelectField/SelectField.tsx +139 -0
- package/src/components/SelectField/SelectField.types.ts +121 -0
- package/src/components/SelectField/_components/Option/Option.tsx +19 -0
- package/src/components/SelectField/_components/Option/Option.types.ts +21 -0
- package/src/components/SelectField/_components/Option/index.ts +2 -0
- package/src/components/SelectField/index.ts +7 -0
- package/src/components/Table/README.md +1 -1
- package/src/components/Table/{Table.jsx → Table.tsx} +4 -43
- package/src/components/Table/Table.types.ts +51 -0
- package/src/components/Table/_components/TableBodyCell/TableBodyCell.tsx +20 -0
- package/src/components/Table/_components/TableBodyCell/TableBodyCell.types.ts +20 -0
- package/src/components/Table/_components/TableBodyCell/index.ts +2 -0
- package/src/components/Table/_components/TableHeaderCell/{TableHeaderCell.jsx → TableHeaderCell.tsx} +3 -34
- package/src/components/Table/_components/TableHeaderCell/TableHeaderCell.types.ts +20 -0
- package/src/components/Table/_components/TableHeaderCell/index.ts +2 -0
- package/src/components/Table/index.ts +8 -0
- package/src/components/Tabs/README.md +2 -2
- package/src/components/Tabs/{Tabs.jsx → Tabs.tsx} +4 -20
- package/src/components/Tabs/Tabs.types.ts +19 -0
- package/src/components/Tabs/TabsItem.tsx +49 -0
- package/src/components/Tabs/TabsItem.types.ts +42 -0
- package/src/components/Tabs/index.ts +4 -0
- package/src/components/Text/README.md +1 -1
- package/src/components/Text/Text.module.scss +5 -7
- package/src/components/Text/Text.tsx +46 -0
- package/src/components/Text/Text.types.ts +31 -0
- package/src/components/Text/_helpers/getRootClampClassName.ts +13 -0
- package/src/components/Text/_helpers/getRootHyphensClassName.ts +14 -0
- package/src/components/Text/_helpers/getRootWordWrappingClassName.ts +14 -0
- package/src/components/Text/index.ts +6 -0
- package/src/components/TextArea/README.md +35 -14
- package/src/components/TextArea/TextArea.module.scss +7 -3
- package/src/components/TextArea/TextArea.tsx +95 -0
- package/src/components/TextArea/TextArea.types.ts +76 -0
- package/src/components/TextArea/index.ts +5 -0
- package/src/components/TextField/README.md +35 -13
- package/src/components/TextField/TextField.module.scss +7 -3
- package/src/components/TextField/TextField.tsx +112 -0
- package/src/components/TextField/TextField.types.ts +95 -0
- package/src/components/TextField/index.ts +6 -0
- package/src/components/TextLink/README.md +2 -2
- package/src/components/TextLink/{TextLink.jsx → TextLink.tsx} +4 -15
- package/src/components/TextLink/TextLink.types.ts +12 -0
- package/src/components/TextLink/index.ts +2 -0
- package/src/components/Toggle/README.md +92 -45
- package/src/components/Toggle/Toggle.module.scss +7 -3
- package/src/components/Toggle/Toggle.tsx +82 -0
- package/src/components/Toggle/Toggle.types.ts +59 -0
- package/src/components/Toggle/index.ts +5 -0
- package/src/components/Toolbar/README.md +3 -3
- package/src/components/Toolbar/Toolbar.tsx +41 -0
- package/src/components/Toolbar/Toolbar.types.ts +74 -0
- package/src/components/Toolbar/ToolbarGroup.tsx +38 -0
- package/src/components/Toolbar/{ToolbarItem.jsx → ToolbarItem.tsx} +5 -21
- package/src/components/Toolbar/_helpers/{getAlignClassName.js → getAlignClassName.ts} +8 -1
- package/src/components/Toolbar/_helpers/{getJustifyClassName.js → getJustifyClassName.ts} +4 -1
- package/src/components/Toolbar/{index.js → index.ts} +7 -0
- package/src/components/_helpers/{getRootColorClassName.js → getRootColorClassName.ts} +7 -2
- package/src/components/_helpers/{getRootPriorityClassName.js → getRootPriorityClassName.ts} +7 -2
- package/src/components/_helpers/{getRootSizeClassName.js → getRootSizeClassName.ts} +7 -2
- package/src/components/_helpers/getRootStateClassName.ts +24 -0
- package/src/components/_helpers/resolveContextOrProp.ts +13 -0
- package/src/helpers/classNames/{classNames.js → classNames.ts} +2 -2
- package/src/helpers/isChildrenEmpty/isChildrenEmpty.ts +5 -0
- package/src/helpers/transferProps/transferProps.ts +50 -0
- package/src/helpers/transferProps/transferProps.types.ts +11 -0
- package/src/index.ts +211 -0
- package/src/providers/globalProps/GlobalProps.types.ts +30 -0
- package/src/providers/globalProps/GlobalPropsContext.ts +6 -0
- package/src/providers/globalProps/{GlobalPropsProvider.jsx → GlobalPropsProvider.tsx} +8 -15
- package/src/providers/globalProps/{index.js → index.ts} +4 -0
- package/src/providers/globalProps/withGlobalProps.tsx +36 -0
- package/src/providers/translations/Translations.types.ts +26 -0
- package/src/providers/translations/TranslationsContext.ts +7 -0
- package/src/providers/translations/{TranslationsProvider.jsx → TranslationsProvider.tsx} +8 -15
- package/src/providers/translations/{index.js → index.ts} +5 -0
- package/src/styles/settings/_form-fields.scss +2 -1
- package/src/styles/theme/_form-fields.scss +16 -11
- package/src/styles/theme-constants/_colors.scss +21 -0
- package/src/styles/tools/_accessibility.scss +2 -2
- package/src/styles/tools/form-fields/_box-field-layout.scss +5 -8
- package/src/styles/tools/form-fields/_inline-field-elements.scss +0 -7
- package/src/styles/tools/form-fields/_inline-field-layout.scss +0 -8
- package/src/styles/tools/form-fields/_variants.scss +7 -7
- package/src/theme.scss +37 -12
- package/src/translations/{en.js → en.ts} +3 -1
- package/src/types/breakpoints.ts +1 -0
- package/src/types/colors.ts +7 -0
- package/src/types/index.ts +13 -0
- package/src/types/labelPositions.ts +1 -0
- package/src/types/layouts.ts +1 -0
- package/src/types/modules.d.ts +16 -0
- package/src/types/priorities.ts +1 -0
- package/src/types/sizes.ts +1 -0
- package/src/types/states.ts +1 -0
- package/src/types/styles.ts +4 -0
- package/src/utils/mergeDeep.ts +34 -0
- package/src/utils/mergeDeep.types.ts +4 -0
- package/.claude/agents/code-reviewer.md +0 -122
- package/.claude/rules/code.md +0 -22
- package/.claude/rules/docs.md +0 -35
- package/.claude/rules/frontend.md +0 -72
- package/.claude/rules/git.md +0 -13
- package/.claude/rules/safety-guards.md +0 -9
- package/.claude/rules/styling.md +0 -32
- package/.claude/rules/testing.md +0 -59
- package/.claude/settings.json +0 -32
- package/.claude/skills/commit/SKILL.md +0 -54
- package/.devcontainer/devcontainer.json +0 -23
- package/.eslintrc-ts +0 -40
- package/.mcp.json +0 -8
- package/.nvmrc +0 -1
- package/CLAUDE.md +0 -82
- package/docker-compose.base.yml +0 -93
- package/docker-compose.yml.dist +0 -41
- package/jest.config-ts.js +0 -34
- package/opencode.json +0 -10
- package/playwright-ct.config.ts +0 -68
- package/scripts/auto-start-mkdocs.sh +0 -5
- package/scripts/auto-start-node.sh +0 -33
- package/scripts/mcps/chrome-host/README.md +0 -118
- package/scripts/mcps/chrome-host/cdp_proxy.py +0 -90
- package/scripts/mcps/chrome-host/mcp-entry.sh +0 -33
- package/scripts/mcps/chrome-host/mcp-launch.sh +0 -36
- package/scripts/mcps/chrome-host/mcp-setup.sh +0 -70
- package/scripts/mcps/chrome-host/start-host-chrome.sh +0 -267
- package/setup.sh +0 -107
- package/src/CNAME +0 -1
- package/src/components/Alert/index.js +0 -1
- package/src/components/Badge/Badge.jsx +0 -51
- package/src/components/Badge/index.js +0 -1
- package/src/components/Button/Button.jsx +0 -203
- package/src/components/Button/helpers/getRootPriorityClassName.js +0 -15
- package/src/components/Button/index.js +0 -1
- package/src/components/ButtonGroup/ButtonGroupContext.js +0 -3
- package/src/components/Card/Card.jsx +0 -67
- package/src/components/CheckboxField/CheckboxField.jsx +0 -144
- package/src/components/CheckboxField/index.js +0 -1
- package/src/components/FileInputField/index.js +0 -1
- package/src/components/FormLayout/FormLayoutContext.js +0 -3
- package/src/components/FormLayout/FormLayoutCustomFieldContext.js +0 -3
- package/src/components/FormLayout/index.js +0 -4
- package/src/components/Grid/Grid.jsx +0 -225
- package/src/components/Grid/GridSpan.jsx +0 -88
- package/src/components/Grid/_helpers/generateResponsiveCustomProperties.js +0 -22
- package/src/components/Grid/index.js +0 -2
- package/src/components/InputGroup/InputGroupContext.js +0 -3
- package/src/components/Modal/Modal.jsx +0 -262
- package/src/components/Modal/ModalBody.jsx +0 -60
- package/src/components/Modal/ModalFooter.jsx +0 -42
- package/src/components/Modal/ModalHeader.jsx +0 -42
- package/src/components/Modal/ModalTitle.jsx +0 -42
- package/src/components/Modal/_helpers/getPositionClassName.js +0 -7
- package/src/components/Modal/_helpers/getScrollingClassName.js +0 -11
- package/src/components/Paper/index.js +0 -1
- package/src/components/Popover/Popover.jsx +0 -124
- package/src/components/Popover/PopoverWrapper.jsx +0 -38
- package/src/components/Popover/index.js +0 -2
- package/src/components/Radio/Radio.jsx +0 -212
- package/src/components/Radio/index.js +0 -1
- package/src/components/ScrollView/_helpers/getElementsPositionDifference.js +0 -11
- package/src/components/ScrollView/index.js +0 -1
- package/src/components/SelectField/SelectField.jsx +0 -272
- package/src/components/SelectField/_components/Option/Option.jsx +0 -46
- package/src/components/SelectField/_components/Option/index.js +0 -1
- package/src/components/SelectField/index.js +0 -1
- package/src/components/Table/_components/TableBodyCell/TableBodyCell.jsx +0 -46
- package/src/components/Table/_components/TableBodyCell/index.js +0 -1
- package/src/components/Table/_components/TableHeaderCell/index.js +0 -1
- package/src/components/Table/index.js +0 -1
- package/src/components/Tabs/TabsItem.jsx +0 -91
- package/src/components/Tabs/index.js +0 -2
- package/src/components/Text/Text.jsx +0 -76
- package/src/components/Text/_helpers/getRootClampClassName.js +0 -11
- package/src/components/Text/_helpers/getRootHyphensClassName.js +0 -11
- package/src/components/Text/_helpers/getRootWordWrappingClassName.js +0 -11
- package/src/components/Text/index.js +0 -1
- package/src/components/TextArea/TextArea.jsx +0 -174
- package/src/components/TextArea/index.js +0 -1
- package/src/components/TextField/TextField.jsx +0 -208
- package/src/components/TextField/index.js +0 -1
- package/src/components/TextLink/index.js +0 -1
- package/src/components/Toggle/Toggle.jsx +0 -144
- package/src/components/Toggle/index.js +0 -1
- package/src/components/Toolbar/Toolbar.jsx +0 -76
- package/src/components/Toolbar/ToolbarGroup.jsx +0 -64
- package/src/components/_helpers/getRootValidationStateClassName.js +0 -15
- package/src/components/_helpers/resolveContextOrProp.js +0 -10
- package/src/helpers/isChildrenEmpty/isChildrenEmpty.js +0 -3
- package/src/helpers/transferProps/transferProps.js +0 -38
- package/src/index.js +0 -67
- package/src/providers/globalProps/GlobalPropsContext.jsx +0 -5
- package/src/providers/globalProps/withGlobalProps.jsx +0 -38
- package/src/providers/translations/TranslationsContext.jsx +0 -6
- package/src/utils/mergeDeep.js +0 -28
- package/tsconfig.json +0 -27
- /package/src/helpers/classNames/{index.js → index.ts} +0 -0
- /package/src/helpers/isChildrenEmpty/{index.js → index.ts} +0 -0
- /package/src/helpers/transferProps/{index.js → index.ts} +0 -0
|
@@ -2,10 +2,21 @@ import {
|
|
|
2
2
|
useLayoutEffect,
|
|
3
3
|
useRef,
|
|
4
4
|
} from 'react';
|
|
5
|
+
import type {
|
|
6
|
+
DependencyList,
|
|
7
|
+
RefObject,
|
|
8
|
+
} from 'react';
|
|
5
9
|
import { getElementsPositionDifference } from '../_helpers/getElementsPositionDifference';
|
|
10
|
+
import type { ElementsPositionDifference } from '../ScrollView.types';
|
|
6
11
|
|
|
7
|
-
export const useLoadResize = (
|
|
8
|
-
|
|
12
|
+
export const useLoadResize = (
|
|
13
|
+
effect: (currentPosition: ElementsPositionDifference) => void,
|
|
14
|
+
dependencies: DependencyList,
|
|
15
|
+
contentEl: RefObject<HTMLElement | null>,
|
|
16
|
+
viewportEl: RefObject<HTMLElement | null>,
|
|
17
|
+
wait: number,
|
|
18
|
+
) => {
|
|
19
|
+
const throttleTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
9
20
|
|
|
10
21
|
const callBack = (wasDelayed = false) => {
|
|
11
22
|
effect(getElementsPositionDifference(contentEl, viewportEl));
|
|
@@ -30,7 +41,7 @@ export const useLoadResize = (effect, dependencies, contentEl, viewportEl, wait)
|
|
|
30
41
|
window.addEventListener('resize', handleLoadResize);
|
|
31
42
|
|
|
32
43
|
return () => {
|
|
33
|
-
clearTimeout(throttleTimeout.current);
|
|
44
|
+
clearTimeout(throttleTimeout.current ?? undefined);
|
|
34
45
|
window.removeEventListener('load', handleLoadResize);
|
|
35
46
|
window.removeEventListener('resize', handleLoadResize);
|
|
36
47
|
};
|
package/src/components/ScrollView/_hooks/{useScrollPositionHook.js → useScrollPositionHook.ts}
RENAMED
|
@@ -2,10 +2,17 @@ import {
|
|
|
2
2
|
useRef,
|
|
3
3
|
useEffect,
|
|
4
4
|
} from 'react';
|
|
5
|
+
import type { RefObject } from 'react';
|
|
5
6
|
import { getElementsPositionDifference } from '../_helpers/getElementsPositionDifference';
|
|
7
|
+
import type { ElementsPositionDifference } from '../ScrollView.types';
|
|
6
8
|
|
|
7
|
-
export const useScrollPosition = (
|
|
8
|
-
|
|
9
|
+
export const useScrollPosition = (
|
|
10
|
+
effect: (currentPosition: ElementsPositionDifference) => void,
|
|
11
|
+
contentEl: RefObject<HTMLElement | null>,
|
|
12
|
+
viewportEl: RefObject<HTMLElement | null>,
|
|
13
|
+
wait: number,
|
|
14
|
+
) => {
|
|
15
|
+
const throttleTimeout = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
9
16
|
|
|
10
17
|
const callBack = (wasDelayed = false) => {
|
|
11
18
|
effect(getElementsPositionDifference(contentEl, viewportEl));
|
|
@@ -16,7 +23,7 @@ export const useScrollPosition = (effect, contentEl, viewportEl, wait) => {
|
|
|
16
23
|
};
|
|
17
24
|
|
|
18
25
|
useEffect(() => {
|
|
19
|
-
const viewport = viewportEl.current;
|
|
26
|
+
const viewport = viewportEl.current as HTMLElement;
|
|
20
27
|
|
|
21
28
|
const handleScroll = () => {
|
|
22
29
|
if (wait) {
|
|
@@ -31,7 +38,7 @@ export const useScrollPosition = (effect, contentEl, viewportEl, wait) => {
|
|
|
31
38
|
viewport.addEventListener('scroll', handleScroll);
|
|
32
39
|
|
|
33
40
|
return () => {
|
|
34
|
-
clearTimeout(throttleTimeout.current);
|
|
41
|
+
clearTimeout(throttleTimeout.current ?? undefined);
|
|
35
42
|
viewport.removeEventListener('scroll', handleScroll);
|
|
36
43
|
};
|
|
37
44
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
@@ -78,8 +78,7 @@ mobile devices by using the native select of the platform.
|
|
|
78
78
|
## Design Variants
|
|
79
79
|
|
|
80
80
|
To satisfy the design requirements of your project, all input fields in React UI
|
|
81
|
-
come in two design variants to choose from: outline and filled.
|
|
82
|
-
further [customized](#theming) with CSS custom properties.
|
|
81
|
+
come in two design variants to choose from: outline and filled.
|
|
83
82
|
|
|
84
83
|
```docoff-react-preview
|
|
85
84
|
React.createElement(() => {
|
|
@@ -535,7 +534,7 @@ React.createElement(() => {
|
|
|
535
534
|
onChange={(e) => setFruit(e.target.value)}
|
|
536
535
|
options={options}
|
|
537
536
|
required
|
|
538
|
-
|
|
537
|
+
state="valid"
|
|
539
538
|
validationText="Great, they're in stock!"
|
|
540
539
|
value={fruit}
|
|
541
540
|
/>
|
|
@@ -544,7 +543,7 @@ React.createElement(() => {
|
|
|
544
543
|
onChange={(e) => setFruit(e.target.value)}
|
|
545
544
|
options={options}
|
|
546
545
|
required
|
|
547
|
-
|
|
546
|
+
state="warning"
|
|
548
547
|
validationText="Oh, really?"
|
|
549
548
|
value={fruit}
|
|
550
549
|
/>
|
|
@@ -553,7 +552,7 @@ React.createElement(() => {
|
|
|
553
552
|
onChange={(e) => setFruit(e.target.value)}
|
|
554
553
|
options={options}
|
|
555
554
|
required
|
|
556
|
-
|
|
555
|
+
state="invalid"
|
|
557
556
|
validationText="You must select at least one kind of fruit."
|
|
558
557
|
value={fruit}
|
|
559
558
|
/>
|
|
@@ -562,7 +561,7 @@ React.createElement(() => {
|
|
|
562
561
|
onChange={(e) => setFruit(e.target.value)}
|
|
563
562
|
options={options}
|
|
564
563
|
required
|
|
565
|
-
|
|
564
|
+
state="valid"
|
|
566
565
|
validationText="Great, they're in stock!"
|
|
567
566
|
value={fruit}
|
|
568
567
|
variant="filled"
|
|
@@ -572,7 +571,7 @@ React.createElement(() => {
|
|
|
572
571
|
onChange={(e) => setFruit(e.target.value)}
|
|
573
572
|
options={options}
|
|
574
573
|
required
|
|
575
|
-
|
|
574
|
+
state="warning"
|
|
576
575
|
validationText="Oh, really?"
|
|
577
576
|
value={fruit}
|
|
578
577
|
variant="filled"
|
|
@@ -583,7 +582,7 @@ React.createElement(() => {
|
|
|
583
582
|
options={options}
|
|
584
583
|
required
|
|
585
584
|
value={fruit}
|
|
586
|
-
|
|
585
|
+
state="invalid"
|
|
587
586
|
validationText="You must select at least one kind of fruit."
|
|
588
587
|
variant="filled"
|
|
589
588
|
/>
|
|
@@ -592,6 +591,53 @@ React.createElement(() => {
|
|
|
592
591
|
})
|
|
593
592
|
```
|
|
594
593
|
|
|
594
|
+
### Changed State
|
|
595
|
+
|
|
596
|
+
Changed state highlights fields whose value differs from the saved one, so users
|
|
597
|
+
can review their edits before saving.
|
|
598
|
+
|
|
599
|
+
A field shows one state at a time. When a changed value is also invalid, it's
|
|
600
|
+
up to you to pick the state that matters more to the user.
|
|
601
|
+
|
|
602
|
+
```docoff-react-preview
|
|
603
|
+
React.createElement(() => {
|
|
604
|
+
const [fruit, setFruit] = React.useState('banana');
|
|
605
|
+
const options = [
|
|
606
|
+
{
|
|
607
|
+
label: 'Apple',
|
|
608
|
+
value: 'apple',
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
label: 'Banana',
|
|
612
|
+
value: 'banana',
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
label: 'Grapefruit',
|
|
616
|
+
value: 'grapefruit',
|
|
617
|
+
},
|
|
618
|
+
];
|
|
619
|
+
return (
|
|
620
|
+
<>
|
|
621
|
+
<SelectField
|
|
622
|
+
label="Your favourite fruit"
|
|
623
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
624
|
+
options={options}
|
|
625
|
+
state="changed"
|
|
626
|
+
value={fruit}
|
|
627
|
+
/>
|
|
628
|
+
<SelectField
|
|
629
|
+
label="Your favourite fruit"
|
|
630
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
631
|
+
options={options}
|
|
632
|
+
state="changed"
|
|
633
|
+
value={fruit}
|
|
634
|
+
variant="filled"
|
|
635
|
+
/>
|
|
636
|
+
</>
|
|
637
|
+
);
|
|
638
|
+
})
|
|
639
|
+
```
|
|
640
|
+
|
|
595
641
|
### Required State
|
|
596
642
|
|
|
597
643
|
The required state indicates that the input is mandatory.
|
|
@@ -624,18 +670,10 @@ React.createElement(() => {
|
|
|
624
670
|
});
|
|
625
671
|
```
|
|
626
672
|
|
|
627
|
-
####
|
|
628
|
-
|
|
629
|
-
All form fields in React UI can be
|
|
630
|
-
[styled](/docs/customize/theming/forms/#required-state)
|
|
631
|
-
to indicate the required state.
|
|
632
|
-
|
|
633
|
-
However, you may find yourself in a situation where a form field is valid in
|
|
634
|
-
both selected and unselected states, for example to turn on or off a feature.
|
|
635
|
-
If your project uses the label color as the primary means to indicate the
|
|
636
|
-
required state of input fields and the usual asterisk `*` is omitted, you may
|
|
637
|
-
want to keep the label color consistent for both states to avoid confusion.
|
|
673
|
+
#### Rendering as Required
|
|
638
674
|
|
|
675
|
+
A form field may be valid in both selected and unselected states, for example
|
|
676
|
+
to turn on or off a feature, while your design still needs it to look required.
|
|
639
677
|
For this edge case, there is the `renderAsRequired` prop:
|
|
640
678
|
|
|
641
679
|
```docoff-react-preview
|
|
@@ -656,38 +694,21 @@ React.createElement(() => {
|
|
|
656
694
|
},
|
|
657
695
|
];
|
|
658
696
|
return (
|
|
659
|
-
|
|
660
|
-
<style>
|
|
661
|
-
{`
|
|
662
|
-
.example {
|
|
663
|
-
display: flex;
|
|
664
|
-
flex-wrap: wrap;
|
|
665
|
-
gap: 1rem 0.5rem;
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
.example--themed-form-fields {
|
|
669
|
-
--rui-FormField__label__color: var(--rui-color-text-secondary);
|
|
670
|
-
--rui-FormField--required__label__color: var(--rui-color-text-primary);
|
|
671
|
-
--rui-FormField--required__sign: '';
|
|
672
|
-
}
|
|
673
|
-
`}
|
|
674
|
-
</style>
|
|
675
|
-
<div class="example example--themed-form-fields">
|
|
697
|
+
<>
|
|
676
698
|
<SelectField
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
</React.Fragment>
|
|
699
|
+
label="This field is optional"
|
|
700
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
701
|
+
options={options}
|
|
702
|
+
value={fruit}
|
|
703
|
+
/>
|
|
704
|
+
<SelectField
|
|
705
|
+
label="This field is optional but looks like required"
|
|
706
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
707
|
+
options={options}
|
|
708
|
+
value={fruit}
|
|
709
|
+
renderAsRequired
|
|
710
|
+
/>
|
|
711
|
+
</>
|
|
691
712
|
);
|
|
692
713
|
});
|
|
693
714
|
```
|
|
@@ -772,7 +793,7 @@ If you provide [ref], it is forwarded to the native HTML `<select>` element.
|
|
|
772
793
|
|
|
773
794
|
## API
|
|
774
795
|
|
|
775
|
-
<docoff-react-props src="/components/SelectField/SelectField.
|
|
796
|
+
<docoff-react-props src="/components/SelectField/SelectField.tsx" name="SelectField"></docoff-react-props>
|
|
776
797
|
|
|
777
798
|
## Theming
|
|
778
799
|
|
|
@@ -785,6 +806,71 @@ options. On top of that, the following options are available for SelectField.
|
|
|
785
806
|
| `--rui-FormField--box--select__caret__background` | SelectField arrow background (including `url()` or gradient) |
|
|
786
807
|
| `--rui-FormField--box--select__option--disabled__color` | Text color of disabled SelectField options |
|
|
787
808
|
|
|
809
|
+
### Theming the Required State
|
|
810
|
+
|
|
811
|
+
Required fields are indicated by
|
|
812
|
+
[shared theming options](/docs/customize/theming/forms/#required-state).
|
|
813
|
+
|
|
814
|
+
If your project uses the label color as the primary means to indicate the
|
|
815
|
+
required state of input fields and the usual asterisk `*` is omitted, you may
|
|
816
|
+
want to keep the label color consistent for fields that are valid in both
|
|
817
|
+
selected and unselected states. Pair the theming options with the
|
|
818
|
+
[`renderAsRequired`](#rendering-as-required) prop to achieve that:
|
|
819
|
+
|
|
820
|
+
```docoff-react-preview
|
|
821
|
+
React.createElement(() => {
|
|
822
|
+
const [fruit, setFruit] = React.useState('apple');
|
|
823
|
+
const options = [
|
|
824
|
+
{
|
|
825
|
+
label: 'Apple',
|
|
826
|
+
value: 'apple',
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
label: 'Banana',
|
|
830
|
+
value: 'banana',
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
label: 'Grapefruit',
|
|
834
|
+
value: 'grapefruit',
|
|
835
|
+
},
|
|
836
|
+
];
|
|
837
|
+
return (
|
|
838
|
+
<React.Fragment>
|
|
839
|
+
<style>
|
|
840
|
+
{`
|
|
841
|
+
.example {
|
|
842
|
+
display: flex;
|
|
843
|
+
flex-wrap: wrap;
|
|
844
|
+
gap: 1rem 0.5rem;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
.example--themed-form-fields {
|
|
848
|
+
--rui-FormField__label__color: var(--rui-color-text-secondary);
|
|
849
|
+
--rui-FormField--required__label__color: var(--rui-color-text-primary);
|
|
850
|
+
--rui-FormField--required__sign: '';
|
|
851
|
+
}
|
|
852
|
+
`}
|
|
853
|
+
</style>
|
|
854
|
+
<div class="example example--themed-form-fields">
|
|
855
|
+
<SelectField
|
|
856
|
+
label="This field is optional"
|
|
857
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
858
|
+
options={options}
|
|
859
|
+
value={fruit}
|
|
860
|
+
/>
|
|
861
|
+
<SelectField
|
|
862
|
+
label="This field is optional but looks like required"
|
|
863
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
864
|
+
options={options}
|
|
865
|
+
value={fruit}
|
|
866
|
+
renderAsRequired
|
|
867
|
+
/>
|
|
868
|
+
</div>
|
|
869
|
+
</React.Fragment>
|
|
870
|
+
);
|
|
871
|
+
});
|
|
872
|
+
```
|
|
873
|
+
|
|
788
874
|
[React common props]: https://react.dev/reference/react-dom/components/common#common-props
|
|
789
875
|
[ref]: https://reactjs.org/docs/refs-and-the-dom.html
|
|
790
876
|
[select-attributes]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attributes
|
|
@@ -56,16 +56,20 @@
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// States
|
|
59
|
+
.isRootStateChanged {
|
|
60
|
+
@include variants.state(changed);
|
|
61
|
+
}
|
|
62
|
+
|
|
59
63
|
.isRootStateInvalid {
|
|
60
|
-
@include variants.
|
|
64
|
+
@include variants.state(invalid);
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
.isRootStateValid {
|
|
64
|
-
@include variants.
|
|
68
|
+
@include variants.state(valid);
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
.isRootStateWarning {
|
|
68
|
-
@include variants.
|
|
72
|
+
@include variants.state(warning);
|
|
69
73
|
}
|
|
70
74
|
|
|
71
75
|
// Invisible label
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { withGlobalProps } from '../../providers/globalProps';
|
|
3
|
+
import { classNames } from '../../helpers/classNames/classNames';
|
|
4
|
+
import { transferProps } from '../../helpers/transferProps';
|
|
5
|
+
import { getRootSizeClassName } from '../_helpers/getRootSizeClassName';
|
|
6
|
+
import { getRootStateClassName } from '../_helpers/getRootStateClassName';
|
|
7
|
+
import { resolveContextOrProp } from '../_helpers/resolveContextOrProp';
|
|
8
|
+
import { FormLayoutContext } from '../FormLayout/FormLayoutContext';
|
|
9
|
+
import { FormLayoutCustomFieldContext } from '../FormLayout/FormLayoutCustomFieldContext';
|
|
10
|
+
import { InputGroupContext } from '../InputGroup/InputGroupContext';
|
|
11
|
+
import { Option } from './_components/Option';
|
|
12
|
+
import styles from './SelectField.module.scss';
|
|
13
|
+
import type {
|
|
14
|
+
SelectFieldOption,
|
|
15
|
+
SelectFieldOptionGroup,
|
|
16
|
+
SelectFieldProps,
|
|
17
|
+
} from './SelectField.types';
|
|
18
|
+
|
|
19
|
+
export const SelectField = React.forwardRef<HTMLSelectElement, SelectFieldProps>(({
|
|
20
|
+
disabled = false,
|
|
21
|
+
fullWidth = false,
|
|
22
|
+
helpText,
|
|
23
|
+
id,
|
|
24
|
+
isLabelVisible = true,
|
|
25
|
+
label,
|
|
26
|
+
layout = 'vertical',
|
|
27
|
+
options,
|
|
28
|
+
renderAsRequired = false,
|
|
29
|
+
required = false,
|
|
30
|
+
size = 'medium',
|
|
31
|
+
state,
|
|
32
|
+
validationText,
|
|
33
|
+
variant = 'outline',
|
|
34
|
+
...restProps
|
|
35
|
+
}, ref) => {
|
|
36
|
+
const formLayoutContext = useContext(FormLayoutContext);
|
|
37
|
+
const formLayoutCustomFieldContext = useContext(FormLayoutCustomFieldContext);
|
|
38
|
+
const inputGroupContext = useContext(InputGroupContext);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<label
|
|
42
|
+
className={classNames(
|
|
43
|
+
styles.root,
|
|
44
|
+
fullWidth && styles.isRootFullWidth,
|
|
45
|
+
formLayoutContext && styles.isRootInFormLayout,
|
|
46
|
+
resolveContextOrProp(inputGroupContext && inputGroupContext.disabled, disabled) && styles.isRootDisabled,
|
|
47
|
+
resolveContextOrProp(formLayoutContext && formLayoutContext.layout, layout) === 'horizontal'
|
|
48
|
+
? styles.isRootLayoutHorizontal
|
|
49
|
+
: styles.isRootLayoutVertical,
|
|
50
|
+
inputGroupContext && styles.isRootGrouped,
|
|
51
|
+
(renderAsRequired || required) && styles.isRootRequired,
|
|
52
|
+
getRootSizeClassName(
|
|
53
|
+
styles,
|
|
54
|
+
resolveContextOrProp(inputGroupContext && inputGroupContext.size, size),
|
|
55
|
+
),
|
|
56
|
+
getRootStateClassName(styles, state),
|
|
57
|
+
variant === 'filled' ? styles.isRootVariantFilled : styles.isRootVariantOutline,
|
|
58
|
+
)}
|
|
59
|
+
htmlFor={id}
|
|
60
|
+
id={id && `${id}__label`}
|
|
61
|
+
>
|
|
62
|
+
<div
|
|
63
|
+
className={classNames(
|
|
64
|
+
styles.label,
|
|
65
|
+
(!isLabelVisible || inputGroupContext || formLayoutCustomFieldContext) && styles.isLabelHidden,
|
|
66
|
+
)}
|
|
67
|
+
id={id && `${id}__labelText`}
|
|
68
|
+
>
|
|
69
|
+
{label}
|
|
70
|
+
</div>
|
|
71
|
+
<div className={styles.field}>
|
|
72
|
+
<div className={styles.inputContainer}>
|
|
73
|
+
<select
|
|
74
|
+
{...transferProps(restProps)}
|
|
75
|
+
className={styles.input}
|
|
76
|
+
disabled={resolveContextOrProp(inputGroupContext && inputGroupContext.disabled, disabled)}
|
|
77
|
+
id={id}
|
|
78
|
+
ref={ref}
|
|
79
|
+
required={required}
|
|
80
|
+
>
|
|
81
|
+
{
|
|
82
|
+
(options as (SelectFieldOption | SelectFieldOptionGroup)[]).map((option) => {
|
|
83
|
+
if ('options' in option) {
|
|
84
|
+
return (
|
|
85
|
+
<optgroup
|
|
86
|
+
key={option.key ?? option.label}
|
|
87
|
+
label={option.label}
|
|
88
|
+
>
|
|
89
|
+
{option.options.map((optgroupOption) => (
|
|
90
|
+
<Option
|
|
91
|
+
key={optgroupOption.key ?? optgroupOption.value}
|
|
92
|
+
{...optgroupOption}
|
|
93
|
+
{...(id && { id: `${id}__item__${optgroupOption.key ?? optgroupOption.value}` })}
|
|
94
|
+
/>
|
|
95
|
+
))}
|
|
96
|
+
</optgroup>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
return (
|
|
100
|
+
<Option
|
|
101
|
+
key={option.key ?? option.value}
|
|
102
|
+
{...option}
|
|
103
|
+
{...(id && { id: `${id}__item__${option.key ?? option.value}` })}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
</select>
|
|
109
|
+
<div className={styles.caret}>
|
|
110
|
+
<span className={styles.caretIcon} />
|
|
111
|
+
</div>
|
|
112
|
+
{variant === 'filled' && (
|
|
113
|
+
<div className={styles.bottomLine} />
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
{(helpText && !inputGroupContext) && (
|
|
117
|
+
<div
|
|
118
|
+
className={styles.helpText}
|
|
119
|
+
id={id && `${id}__helpText`}
|
|
120
|
+
>
|
|
121
|
+
{helpText}
|
|
122
|
+
</div>
|
|
123
|
+
)}
|
|
124
|
+
{(validationText && !inputGroupContext) && (
|
|
125
|
+
<div
|
|
126
|
+
className={styles.validationText}
|
|
127
|
+
id={id && `${id}__validationText`}
|
|
128
|
+
>
|
|
129
|
+
{validationText}
|
|
130
|
+
</div>
|
|
131
|
+
)}
|
|
132
|
+
</div>
|
|
133
|
+
</label>
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export const SelectFieldWithGlobalProps = withGlobalProps<SelectFieldProps, HTMLSelectElement>(SelectField, 'SelectField');
|
|
138
|
+
|
|
139
|
+
export default SelectFieldWithGlobalProps;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ReactNode,
|
|
3
|
+
SelectHTMLAttributes,
|
|
4
|
+
} from 'react';
|
|
5
|
+
import type {
|
|
6
|
+
Layout,
|
|
7
|
+
Size,
|
|
8
|
+
State,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
|
|
11
|
+
export type SelectFieldOption = {
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
key?: string;
|
|
14
|
+
label: string;
|
|
15
|
+
value: string | number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type SelectFieldOptionGroup = {
|
|
19
|
+
key?: string;
|
|
20
|
+
label: string;
|
|
21
|
+
options: SelectFieldOption[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type SelectFieldVariant = 'filled' | 'outline';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Props of the `SelectField` component.
|
|
28
|
+
*/
|
|
29
|
+
export type SelectFieldProps = Omit<SelectHTMLAttributes<HTMLSelectElement>, 'size'> & {
|
|
30
|
+
/**
|
|
31
|
+
* If `true`, the input will be disabled.
|
|
32
|
+
*/
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If `true`, the field will span the full width of its parent.
|
|
36
|
+
*/
|
|
37
|
+
fullWidth?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Optional help text.
|
|
40
|
+
*
|
|
41
|
+
* Help text is never rendered when the component is placed into `InputGroup`.
|
|
42
|
+
* If a help text is needed, it must be defined on the `InputGroup` component instead.
|
|
43
|
+
*/
|
|
44
|
+
helpText?: ReactNode;
|
|
45
|
+
/**
|
|
46
|
+
* ID of the input HTML element.
|
|
47
|
+
*
|
|
48
|
+
* Also serves as a prefix for important inner elements:
|
|
49
|
+
* * `<ID>__label`
|
|
50
|
+
* * `<ID>__labelText`,
|
|
51
|
+
* * `<ID>__helpText`
|
|
52
|
+
* * `<ID>__validationText`
|
|
53
|
+
*
|
|
54
|
+
* and of individual options:
|
|
55
|
+
* * `<ID>__item__<VALUE>`
|
|
56
|
+
*
|
|
57
|
+
* If `key` in the option definition object is set,
|
|
58
|
+
* then `option.key` is used instead of `option.value` in place of `<VALUE>`.
|
|
59
|
+
*/
|
|
60
|
+
id?: string;
|
|
61
|
+
/**
|
|
62
|
+
* If `false`, the label will be visually hidden (but remains accessible by assistive
|
|
63
|
+
* technologies).
|
|
64
|
+
*
|
|
65
|
+
* Automatically set to `false` when the component is rendered within `InputGroup` or
|
|
66
|
+
* `FormLayoutCustomField` component.
|
|
67
|
+
*/
|
|
68
|
+
isLabelVisible?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Select field label.
|
|
71
|
+
*/
|
|
72
|
+
label: ReactNode;
|
|
73
|
+
/**
|
|
74
|
+
* Layout of the field.
|
|
75
|
+
*
|
|
76
|
+
* Ignored if the component is rendered within `FormLayout` component
|
|
77
|
+
* as the value is inherited in such case.
|
|
78
|
+
*/
|
|
79
|
+
layout?: Layout;
|
|
80
|
+
/**
|
|
81
|
+
* Set of options to be chosen from.
|
|
82
|
+
*
|
|
83
|
+
* Either set of individual or grouped options is acceptable.
|
|
84
|
+
*
|
|
85
|
+
* For generating unique IDs the `option.value` is normally used. For cases when this is not practical or
|
|
86
|
+
* the `option.value` values are not unique the `option.key` attribute can be set manually.
|
|
87
|
+
* The same applies for the `label` value of grouped options which is supposed to be unique.
|
|
88
|
+
* To ensure uniqueness `key` attribute can be set manually.
|
|
89
|
+
*/
|
|
90
|
+
options: SelectFieldOption[] | SelectFieldOptionGroup[];
|
|
91
|
+
/**
|
|
92
|
+
* If `true`, the input will be rendered as if it was required.
|
|
93
|
+
*/
|
|
94
|
+
renderAsRequired?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* If `true`, the input will be made and rendered as required, regardless of the `renderAsRequired` prop.
|
|
97
|
+
*/
|
|
98
|
+
required?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Size of the field.
|
|
101
|
+
*
|
|
102
|
+
* Ignored if the component is rendered within `InputGroup` component as the value is inherited in such case.
|
|
103
|
+
*/
|
|
104
|
+
size?: Size;
|
|
105
|
+
/**
|
|
106
|
+
* Alter the field to reflect the state of its data, e.g. a validation result or a change
|
|
107
|
+
* against the saved value.
|
|
108
|
+
*/
|
|
109
|
+
state?: State;
|
|
110
|
+
/**
|
|
111
|
+
* Validation message to be displayed.
|
|
112
|
+
*
|
|
113
|
+
* Validation text is never rendered when the component is placed into `InputGroup`.
|
|
114
|
+
* If a validation text is needed, it must be defined on the `InputGroup` component instead.
|
|
115
|
+
*/
|
|
116
|
+
validationText?: ReactNode;
|
|
117
|
+
/**
|
|
118
|
+
* Design variant of the field, further customizable with CSS custom properties.
|
|
119
|
+
*/
|
|
120
|
+
variant?: SelectFieldVariant;
|
|
121
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { OptionProps } from './Option.types';
|
|
3
|
+
|
|
4
|
+
export const Option: React.FunctionComponent<OptionProps> = ({
|
|
5
|
+
disabled = false,
|
|
6
|
+
id,
|
|
7
|
+
label,
|
|
8
|
+
value,
|
|
9
|
+
}: OptionProps) => (
|
|
10
|
+
<option
|
|
11
|
+
disabled={disabled}
|
|
12
|
+
id={id}
|
|
13
|
+
value={value}
|
|
14
|
+
>
|
|
15
|
+
{label}
|
|
16
|
+
</option>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export default Option;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Props of the `Option` component.
|
|
3
|
+
*/
|
|
4
|
+
export type OptionProps = {
|
|
5
|
+
/**
|
|
6
|
+
* If `true` the option cannot be selected.
|
|
7
|
+
*/
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* ID of an individual option.
|
|
11
|
+
*/
|
|
12
|
+
id?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Option label.
|
|
15
|
+
*/
|
|
16
|
+
label: string;
|
|
17
|
+
/**
|
|
18
|
+
* Option value.
|
|
19
|
+
*/
|
|
20
|
+
value: string | number;
|
|
21
|
+
};
|