@react-ui-org/react-ui 0.64.1 → 0.65.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 +1928 -0
- package/dist/react-ui.development.css +2916 -2915
- package/dist/react-ui.development.js +2019 -1051
- 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} +4 -1
- 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.tsx +81 -0
- package/src/components/CheckboxField/CheckboxField.types.ts +63 -0
- package/src/components/CheckboxField/README.md +67 -42
- package/src/components/CheckboxField/index.ts +5 -0
- package/src/components/FileInputField/{FileInputField.jsx → FileInputField.tsx} +42 -128
- package/src/components/FileInputField/FileInputField.types.ts +100 -0
- package/src/components/FileInputField/README.md +1 -1
- package/src/components/FileInputField/index.ts +6 -0
- package/src/components/FormLayout/FormLayout.module.scss +1 -1
- 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.jsx → FormLayoutCustomField.tsx} +10 -65
- package/src/components/FormLayout/FormLayoutCustomField.types.ts +59 -0
- package/src/components/FormLayout/FormLayoutCustomFieldContext.ts +4 -0
- package/src/components/FormLayout/README.md +4 -6
- 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 +32 -0
- package/src/components/Grid/index.ts +9 -0
- package/src/components/InputGroup/{InputGroup.jsx → InputGroup.tsx} +25 -89
- package/src/components/InputGroup/InputGroup.types.ts +80 -0
- package/src/components/InputGroup/InputGroupContext.ts +4 -0
- package/src/components/InputGroup/README.md +5 -1
- 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 +85 -45
- package/src/components/Radio/{Radio.jsx → Radio.tsx} +11 -107
- package/src/components/Radio/Radio.types.ts +90 -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 +84 -45
- package/src/components/SelectField/SelectField.tsx +139 -0
- package/src/components/SelectField/SelectField.types.ts +120 -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 +5 -8
- package/src/components/TextArea/TextArea.tsx +95 -0
- package/src/components/TextArea/TextArea.types.ts +75 -0
- package/src/components/TextArea/index.ts +5 -0
- package/src/components/TextField/README.md +5 -7
- package/src/components/TextField/TextField.tsx +112 -0
- package/src/components/TextField/TextField.types.ts +94 -0
- package/src/components/TextField/index.ts +6 -0
- package/src/components/TextLink/README.md +1 -1
- 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 +67 -42
- package/src/components/Toggle/Toggle.tsx +82 -0
- package/src/components/Toggle/Toggle.types.ts +58 -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} +6 -1
- package/src/components/_helpers/{getRootPriorityClassName.js → getRootPriorityClassName.ts} +6 -1
- package/src/components/_helpers/{getRootSizeClassName.js → getRootSizeClassName.ts} +6 -1
- package/src/components/_helpers/{getRootValidationStateClassName.js → getRootValidationStateClassName.ts} +6 -1
- 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/tools/_accessibility.scss +2 -2
- 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/styles.ts +4 -0
- package/src/types/validationStates.ts +1 -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/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/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
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import PropTypes from 'prop-types';
|
|
2
1
|
import React, {
|
|
3
2
|
useContext,
|
|
4
3
|
useEffect,
|
|
@@ -7,7 +6,11 @@ import React, {
|
|
|
7
6
|
useState,
|
|
8
7
|
useCallback,
|
|
9
8
|
} from 'react';
|
|
10
|
-
import {
|
|
9
|
+
import type {
|
|
10
|
+
CSSProperties,
|
|
11
|
+
RefObject,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import TranslationsContext from '../../providers/translations/TranslationsContext';
|
|
11
14
|
import { withGlobalProps } from '../../providers/globalProps';
|
|
12
15
|
import { classNames } from '../../helpers/classNames/classNames';
|
|
13
16
|
import { transferProps } from '../../helpers/transferProps';
|
|
@@ -15,38 +18,41 @@ import { getElementsPositionDifference } from './_helpers/getElementsPositionDif
|
|
|
15
18
|
import { useLoadResize } from './_hooks/useLoadResizeHook';
|
|
16
19
|
import { useScrollPosition } from './_hooks/useScrollPositionHook';
|
|
17
20
|
import styles from './ScrollView.module.scss';
|
|
21
|
+
import type {
|
|
22
|
+
ElementsPositionDifference,
|
|
23
|
+
ScrollViewDirection,
|
|
24
|
+
ScrollViewProps,
|
|
25
|
+
} from './ScrollView.types';
|
|
18
26
|
|
|
19
27
|
// Function `getElementsPositionDifference` sometimes returns floating point values that results
|
|
20
28
|
// in inaccurate detection of start/end. It is necessary to accept this inaccuracy and take
|
|
21
29
|
// every value less or equal to 1px as start/end.
|
|
22
30
|
const EDGE_DETECTION_INACCURACY_PX = 1;
|
|
23
31
|
|
|
24
|
-
export const ScrollView = React.forwardRef((
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
} = props;
|
|
49
|
-
|
|
32
|
+
export const ScrollView = React.forwardRef<HTMLDivElement, ScrollViewProps>(({
|
|
33
|
+
arrows = false,
|
|
34
|
+
arrowsScrollStep = 200,
|
|
35
|
+
autoScroll = 'off',
|
|
36
|
+
children,
|
|
37
|
+
endShadowBackground = 'linear-gradient(var(--rui-local-end-shadow-direction), rgba(255 255 255 / 1), rgba(255 255 255 / 0))',
|
|
38
|
+
endShadowInitialOffset = '-1rem',
|
|
39
|
+
endShadowSize = '2em',
|
|
40
|
+
id,
|
|
41
|
+
debounce = 50,
|
|
42
|
+
direction = 'vertical',
|
|
43
|
+
nextArrowColor,
|
|
44
|
+
nextArrowElement,
|
|
45
|
+
nextArrowInitialOffset = '-0.5rem',
|
|
46
|
+
prevArrowColor,
|
|
47
|
+
prevArrowElement,
|
|
48
|
+
prevArrowInitialOffset = '-0.5rem',
|
|
49
|
+
scrollbar = true,
|
|
50
|
+
shadows = true,
|
|
51
|
+
startShadowBackground = 'linear-gradient(var(--rui-local-start-shadow-direction), rgba(255 255 255 / 1), rgba(255 255 255 / 0))',
|
|
52
|
+
startShadowInitialOffset = '-1rem',
|
|
53
|
+
startShadowSize = '2em',
|
|
54
|
+
...restProps
|
|
55
|
+
}, ref) => {
|
|
50
56
|
const translations = useContext(TranslationsContext);
|
|
51
57
|
|
|
52
58
|
const [isAutoScrollInProgress, setIsAutoScrollInProgress] = useState(false);
|
|
@@ -55,11 +61,11 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
55
61
|
|
|
56
62
|
const scrollPositionStart = direction === 'horizontal' ? 'left' : 'top';
|
|
57
63
|
const scrollPositionEnd = direction === 'horizontal' ? 'right' : 'bottom';
|
|
58
|
-
const scrollViewContentEl = useRef(null);
|
|
59
|
-
const blankRef = useRef(null);
|
|
60
|
-
const scrollViewViewportEl = ref ?? blankRef
|
|
64
|
+
const scrollViewContentEl = useRef<HTMLDivElement>(null);
|
|
65
|
+
const blankRef = useRef<HTMLDivElement>(null);
|
|
66
|
+
const scrollViewViewportEl = (ref ?? blankRef) as RefObject<HTMLDivElement | null>;
|
|
61
67
|
|
|
62
|
-
const handleScrollViewState = useCallback((currentPosition) => {
|
|
68
|
+
const handleScrollViewState = useCallback((currentPosition: ElementsPositionDifference) => {
|
|
63
69
|
const isScrolledAtStartActive = currentPosition[scrollPositionStart]
|
|
64
70
|
<= -1 * EDGE_DETECTION_INACCURACY_PX;
|
|
65
71
|
const isScrolledAtEndActive = currentPosition[scrollPositionEnd]
|
|
@@ -92,7 +98,7 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
92
98
|
|
|
93
99
|
if (currentPosition[scrollPositionEnd] <= EDGE_DETECTION_INACCURACY_PX) {
|
|
94
100
|
setIsAutoScrollInProgress(false);
|
|
95
|
-
scrollViewViewportEl.current
|
|
101
|
+
scrollViewViewportEl.current?.removeEventListener('scroll', handleScrollWhenAutoScrollIsInProgress);
|
|
96
102
|
}
|
|
97
103
|
};
|
|
98
104
|
|
|
@@ -107,8 +113,8 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
107
113
|
return () => {};
|
|
108
114
|
}
|
|
109
115
|
|
|
110
|
-
const scrollViewContentElement = scrollViewContentEl.current;
|
|
111
|
-
const scrollViewViewportElement = scrollViewViewportEl.current;
|
|
116
|
+
const scrollViewContentElement = scrollViewContentEl.current as HTMLDivElement;
|
|
117
|
+
const scrollViewViewportElement = scrollViewViewportEl.current as HTMLDivElement;
|
|
112
118
|
|
|
113
119
|
const differenceX = direction === 'horizontal' ? scrollViewContentElement.offsetWidth : 0;
|
|
114
120
|
const differenceY = direction !== 'horizontal' ? scrollViewContentElement.offsetHeight : 0;
|
|
@@ -158,10 +164,10 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
158
164
|
debounce,
|
|
159
165
|
);
|
|
160
166
|
|
|
161
|
-
const autoScrollChildrenKeys = autoScroll !== 'off' && children && React.Children
|
|
162
|
-
.map(children, (child) => child.key)
|
|
163
|
-
.reduce((reducedKeys, childKey) => reducedKeys
|
|
164
|
-
const autoScrollChildrenLength = autoScroll !== 'off' && children && children.length;
|
|
167
|
+
const autoScrollChildrenKeys = autoScroll !== 'off' && children && (React.Children
|
|
168
|
+
.map(children, (child) => (React.isValidElement(child) ? child.key : undefined)) ?? [])
|
|
169
|
+
.reduce((reducedKeys, childKey) => `${reducedKeys}${String(childKey)}`, '');
|
|
170
|
+
const autoScrollChildrenLength = autoScroll !== 'off' && children && (children as { length?: number }).length;
|
|
165
171
|
|
|
166
172
|
useLayoutEffect(
|
|
167
173
|
handleScrollWhenAutoScrollIsEnabled,
|
|
@@ -193,12 +199,18 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
193
199
|
};
|
|
194
200
|
}, [scrollViewContentEl, scrollViewViewportEl, handleScrollViewState]);
|
|
195
201
|
|
|
196
|
-
const arrowHandler = (
|
|
202
|
+
const arrowHandler = (
|
|
203
|
+
contentEl: RefObject<HTMLDivElement | null>,
|
|
204
|
+
viewportEl: RefObject<HTMLDivElement | null>,
|
|
205
|
+
scrollViewDirection: ScrollViewDirection,
|
|
206
|
+
shiftDirection: 'next' | 'prev',
|
|
207
|
+
step: number,
|
|
208
|
+
) => {
|
|
197
209
|
const offset = shiftDirection === 'next' ? step : -1 * step;
|
|
198
210
|
const differenceX = scrollViewDirection === 'horizontal' ? offset : 0;
|
|
199
211
|
const differenceY = scrollViewDirection !== 'horizontal' ? offset : 0;
|
|
200
212
|
|
|
201
|
-
viewportEl.current
|
|
213
|
+
viewportEl.current?.scrollBy(differenceX, differenceY);
|
|
202
214
|
};
|
|
203
215
|
|
|
204
216
|
return (
|
|
@@ -225,7 +237,7 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
225
237
|
'--rui-local-start-shadow-direction': direction === 'horizontal' ? 'to right' : 'to bottom',
|
|
226
238
|
'--rui-local-start-shadow-initial-offset': startShadowInitialOffset,
|
|
227
239
|
'--rui-local-start-shadow-size': startShadowSize,
|
|
228
|
-
}}
|
|
240
|
+
} as CSSProperties}
|
|
229
241
|
>
|
|
230
242
|
<div
|
|
231
243
|
className={styles.viewport}
|
|
@@ -293,129 +305,6 @@ export const ScrollView = React.forwardRef((props, ref) => {
|
|
|
293
305
|
);
|
|
294
306
|
});
|
|
295
307
|
|
|
296
|
-
|
|
297
|
-
arrows: false,
|
|
298
|
-
arrowsScrollStep: 200,
|
|
299
|
-
autoScroll: 'off',
|
|
300
|
-
children: undefined,
|
|
301
|
-
debounce: 50,
|
|
302
|
-
direction: 'vertical',
|
|
303
|
-
endShadowBackground: 'linear-gradient(var(--rui-local-end-shadow-direction), rgba(255 255 255 / 1), rgba(255 255 255 / 0))',
|
|
304
|
-
endShadowInitialOffset: '-1rem',
|
|
305
|
-
endShadowSize: '2em',
|
|
306
|
-
id: undefined,
|
|
307
|
-
nextArrowColor: undefined,
|
|
308
|
-
nextArrowElement: undefined,
|
|
309
|
-
nextArrowInitialOffset: '-0.5rem',
|
|
310
|
-
prevArrowColor: undefined,
|
|
311
|
-
prevArrowElement: undefined,
|
|
312
|
-
prevArrowInitialOffset: '-0.5rem',
|
|
313
|
-
scrollbar: true,
|
|
314
|
-
shadows: true,
|
|
315
|
-
startShadowBackground: 'linear-gradient(var(--rui-local-start-shadow-direction), rgba(255 255 255 / 1), rgba(255 255 255 / 0))',
|
|
316
|
-
startShadowInitialOffset: '-1rem',
|
|
317
|
-
startShadowSize: '2em',
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
ScrollView.propTypes = {
|
|
321
|
-
/**
|
|
322
|
-
* If `true`, display the arrow controls.
|
|
323
|
-
*/
|
|
324
|
-
arrows: PropTypes.bool,
|
|
325
|
-
/**
|
|
326
|
-
* Portion to scroll by when the arrows are clicked, in px.
|
|
327
|
-
*/
|
|
328
|
-
arrowsScrollStep: PropTypes.number,
|
|
329
|
-
/**
|
|
330
|
-
* The auto-scroll mechanism requires having the `key` prop set for every child present in `children`
|
|
331
|
-
* because it detects changes of those keys. Without the keys, the auto-scroll will not work.
|
|
332
|
-
*
|
|
333
|
-
* Option `always` means the auto-scroll scrolls to the end every time the content changes.
|
|
334
|
-
* Option `detectEnd` means the auto-scroll scrolls to the end only when the content is changed
|
|
335
|
-
* and the user has scrolled at the end of the viewport at the moment of the change.
|
|
336
|
-
*
|
|
337
|
-
* See https://reactjs.org/docs/lists-and-keys.html#keys
|
|
338
|
-
*/
|
|
339
|
-
autoScroll: PropTypes.oneOf(['always', 'detectEnd', 'off']),
|
|
340
|
-
/**
|
|
341
|
-
* Content to be scrollable.
|
|
342
|
-
*/
|
|
343
|
-
children: PropTypes.node,
|
|
344
|
-
/**
|
|
345
|
-
* Delay in ms before the display of arrows and scrolling shadows is evaluated during interaction.
|
|
346
|
-
*/
|
|
347
|
-
debounce: PropTypes.number,
|
|
348
|
-
/**
|
|
349
|
-
* Direction of scrolling.
|
|
350
|
-
*/
|
|
351
|
-
direction: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
352
|
-
/**
|
|
353
|
-
* Custom background of the end scrolling shadow. Can be a CSS gradient or an image `url()`.
|
|
354
|
-
*/
|
|
355
|
-
endShadowBackground: PropTypes.string,
|
|
356
|
-
/**
|
|
357
|
-
* Initial offset of the end scrolling shadow (transitioned). If set, the end scrolling shadow slides in
|
|
358
|
-
* by this distance.
|
|
359
|
-
*/
|
|
360
|
-
endShadowInitialOffset: PropTypes.string,
|
|
361
|
-
/**
|
|
362
|
-
* Size of the end scrolling shadow. Accepts any valid CSS length value.
|
|
363
|
-
*/
|
|
364
|
-
endShadowSize: PropTypes.string,
|
|
365
|
-
/**
|
|
366
|
-
* ID of the root HTML element. It also serves as base for nested elements:
|
|
367
|
-
* * `<ID>__content`
|
|
368
|
-
* * `<ID>__arrowPrevButton`
|
|
369
|
-
* * `<ID>__arrowNextButton`
|
|
370
|
-
*/
|
|
371
|
-
id: PropTypes.string,
|
|
372
|
-
/**
|
|
373
|
-
* Text color of the end arrow control. Accepts any valid CSS color value.
|
|
374
|
-
*/
|
|
375
|
-
nextArrowColor: PropTypes.string,
|
|
376
|
-
/**
|
|
377
|
-
* Custom HTML or React Component to replace the default next-arrow control.
|
|
378
|
-
*/
|
|
379
|
-
nextArrowElement: PropTypes.node,
|
|
380
|
-
/**
|
|
381
|
-
* Initial offset of the end arrow control (transitioned). If set, the next arrow slides in by this distance.
|
|
382
|
-
*/
|
|
383
|
-
nextArrowInitialOffset: PropTypes.string,
|
|
384
|
-
/**
|
|
385
|
-
* Text color of the start arrow control. Accepts any valid CSS color value.
|
|
386
|
-
*/
|
|
387
|
-
prevArrowColor: PropTypes.string,
|
|
388
|
-
/**
|
|
389
|
-
* Custom HTML or React Component to replace the default prev-arrow control.
|
|
390
|
-
*/
|
|
391
|
-
prevArrowElement: PropTypes.node,
|
|
392
|
-
/**
|
|
393
|
-
* Initial offset of the start arrow control (transitioned). If set, the prev arrow slides in by this distance.
|
|
394
|
-
*/
|
|
395
|
-
prevArrowInitialOffset: PropTypes.string,
|
|
396
|
-
/**
|
|
397
|
-
* If `false`, the system scrollbar will be hidden.
|
|
398
|
-
*/
|
|
399
|
-
scrollbar: PropTypes.bool,
|
|
400
|
-
/**
|
|
401
|
-
* If `true`, display scrolling shadows.
|
|
402
|
-
*/
|
|
403
|
-
shadows: PropTypes.bool,
|
|
404
|
-
/**
|
|
405
|
-
* Custom background of the start scrolling shadow. Can be a CSS gradient or an image `url()`.
|
|
406
|
-
*/
|
|
407
|
-
startShadowBackground: PropTypes.string,
|
|
408
|
-
/**
|
|
409
|
-
* Initial offset of the start scrolling shadow (transitioned). If set, the start scrolling shadow slides in
|
|
410
|
-
* by this distance.
|
|
411
|
-
*/
|
|
412
|
-
startShadowInitialOffset: PropTypes.string,
|
|
413
|
-
/**
|
|
414
|
-
* Size of the start scrolling shadow. Accepts any valid CSS length value.
|
|
415
|
-
*/
|
|
416
|
-
startShadowSize: PropTypes.string,
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
export const ScrollViewWithGlobalProps = withGlobalProps(ScrollView, 'ScrollView');
|
|
308
|
+
export const ScrollViewWithGlobalProps = withGlobalProps<ScrollViewProps, HTMLDivElement>(ScrollView, 'ScrollView');
|
|
420
309
|
|
|
421
310
|
export default ScrollViewWithGlobalProps;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
HTMLAttributes,
|
|
3
|
+
ReactNode,
|
|
4
|
+
} from 'react';
|
|
5
|
+
import type { Layout } from '../../types';
|
|
6
|
+
|
|
7
|
+
export type ScrollViewAutoScroll = 'always' | 'detectEnd' | 'off';
|
|
8
|
+
|
|
9
|
+
export type ScrollViewDirection = Layout;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props of the `ScrollView` component.
|
|
13
|
+
*/
|
|
14
|
+
export type ScrollViewProps = HTMLAttributes<HTMLDivElement> & {
|
|
15
|
+
/**
|
|
16
|
+
* If `true`, display the arrow controls.
|
|
17
|
+
*/
|
|
18
|
+
arrows?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Portion to scroll by when the arrows are clicked, in px.
|
|
21
|
+
*/
|
|
22
|
+
arrowsScrollStep?: number;
|
|
23
|
+
/**
|
|
24
|
+
* The auto-scroll mechanism requires having the `key` prop set for every child present in `children`
|
|
25
|
+
* because it detects changes of those keys. Without the keys, the auto-scroll will not work.
|
|
26
|
+
*
|
|
27
|
+
* Option `always` means the auto-scroll scrolls to the end every time the content changes.
|
|
28
|
+
* Option `detectEnd` means the auto-scroll scrolls to the end only when the content is changed
|
|
29
|
+
* and the user has scrolled at the end of the viewport at the moment of the change.
|
|
30
|
+
*
|
|
31
|
+
* See https://reactjs.org/docs/lists-and-keys.html#keys
|
|
32
|
+
*/
|
|
33
|
+
autoScroll?: ScrollViewAutoScroll;
|
|
34
|
+
/**
|
|
35
|
+
* Content to be scrollable.
|
|
36
|
+
*/
|
|
37
|
+
children?: ReactNode;
|
|
38
|
+
/**
|
|
39
|
+
* Delay in ms before the display of arrows and scrolling shadows is evaluated during interaction.
|
|
40
|
+
*/
|
|
41
|
+
debounce?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Direction of scrolling.
|
|
44
|
+
*/
|
|
45
|
+
direction?: ScrollViewDirection;
|
|
46
|
+
/**
|
|
47
|
+
* Custom background of the end scrolling shadow. Can be a CSS gradient or an image `url()`.
|
|
48
|
+
*/
|
|
49
|
+
endShadowBackground?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Initial offset of the end scrolling shadow (transitioned). If set, the end scrolling shadow slides in
|
|
52
|
+
* by this distance.
|
|
53
|
+
*/
|
|
54
|
+
endShadowInitialOffset?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Size of the end scrolling shadow. Accepts any valid CSS length value.
|
|
57
|
+
*/
|
|
58
|
+
endShadowSize?: string;
|
|
59
|
+
/**
|
|
60
|
+
* ID of the root HTML element. It also serves as base for nested elements:
|
|
61
|
+
* * `<ID>__content`
|
|
62
|
+
* * `<ID>__arrowPrevButton`
|
|
63
|
+
* * `<ID>__arrowNextButton`
|
|
64
|
+
*/
|
|
65
|
+
id?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Text color of the end arrow control. Accepts any valid CSS color value.
|
|
68
|
+
*/
|
|
69
|
+
nextArrowColor?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Custom HTML or React Component to replace the default next-arrow control.
|
|
72
|
+
*/
|
|
73
|
+
nextArrowElement?: ReactNode;
|
|
74
|
+
/**
|
|
75
|
+
* Initial offset of the end arrow control (transitioned). If set, the next arrow slides in by this distance.
|
|
76
|
+
*/
|
|
77
|
+
nextArrowInitialOffset?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Text color of the start arrow control. Accepts any valid CSS color value.
|
|
80
|
+
*/
|
|
81
|
+
prevArrowColor?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Custom HTML or React Component to replace the default prev-arrow control.
|
|
84
|
+
*/
|
|
85
|
+
prevArrowElement?: ReactNode;
|
|
86
|
+
/**
|
|
87
|
+
* Initial offset of the start arrow control (transitioned). If set, the prev arrow slides in by this distance.
|
|
88
|
+
*/
|
|
89
|
+
prevArrowInitialOffset?: string;
|
|
90
|
+
/**
|
|
91
|
+
* If `false`, the system scrollbar will be hidden.
|
|
92
|
+
*/
|
|
93
|
+
scrollbar?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* If `true`, display scrolling shadows.
|
|
96
|
+
*/
|
|
97
|
+
shadows?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Custom background of the start scrolling shadow. Can be a CSS gradient or an image `url()`.
|
|
100
|
+
*/
|
|
101
|
+
startShadowBackground?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Initial offset of the start scrolling shadow (transitioned). If set, the start scrolling shadow slides in
|
|
104
|
+
* by this distance.
|
|
105
|
+
*/
|
|
106
|
+
startShadowInitialOffset?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Size of the start scrolling shadow. Accepts any valid CSS length value.
|
|
109
|
+
*/
|
|
110
|
+
startShadowSize?: string;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Position difference of the scrolled content relative to the viewport, in pixels.
|
|
115
|
+
*/
|
|
116
|
+
export type ElementsPositionDifference = {
|
|
117
|
+
bottom: number;
|
|
118
|
+
left: number;
|
|
119
|
+
right: number;
|
|
120
|
+
top: number;
|
|
121
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { ElementsPositionDifference } from '../ScrollView.types';
|
|
3
|
+
|
|
4
|
+
export const getElementsPositionDifference = (
|
|
5
|
+
contentEl: RefObject<HTMLElement | null>,
|
|
6
|
+
viewportEl: RefObject<HTMLElement | null>,
|
|
7
|
+
): ElementsPositionDifference => {
|
|
8
|
+
const contentPosition = (contentEl.current as HTMLElement).getBoundingClientRect();
|
|
9
|
+
const viewportPosition = (viewportEl.current as HTMLElement).getBoundingClientRect();
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
bottom: contentPosition.bottom - viewportPosition.bottom,
|
|
13
|
+
left: contentPosition.left - viewportPosition.left,
|
|
14
|
+
right: contentPosition.right - viewportPosition.right,
|
|
15
|
+
top: contentPosition.top - viewportPosition.top,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -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(() => {
|
|
@@ -624,18 +623,10 @@ React.createElement(() => {
|
|
|
624
623
|
});
|
|
625
624
|
```
|
|
626
625
|
|
|
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.
|
|
626
|
+
#### Rendering as Required
|
|
638
627
|
|
|
628
|
+
A form field may be valid in both selected and unselected states, for example
|
|
629
|
+
to turn on or off a feature, while your design still needs it to look required.
|
|
639
630
|
For this edge case, there is the `renderAsRequired` prop:
|
|
640
631
|
|
|
641
632
|
```docoff-react-preview
|
|
@@ -656,38 +647,21 @@ React.createElement(() => {
|
|
|
656
647
|
},
|
|
657
648
|
];
|
|
658
649
|
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">
|
|
650
|
+
<>
|
|
676
651
|
<SelectField
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
</React.Fragment>
|
|
652
|
+
label="This field is optional"
|
|
653
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
654
|
+
options={options}
|
|
655
|
+
value={fruit}
|
|
656
|
+
/>
|
|
657
|
+
<SelectField
|
|
658
|
+
label="This field is optional but looks like required"
|
|
659
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
660
|
+
options={options}
|
|
661
|
+
value={fruit}
|
|
662
|
+
renderAsRequired
|
|
663
|
+
/>
|
|
664
|
+
</>
|
|
691
665
|
);
|
|
692
666
|
});
|
|
693
667
|
```
|
|
@@ -772,7 +746,7 @@ If you provide [ref], it is forwarded to the native HTML `<select>` element.
|
|
|
772
746
|
|
|
773
747
|
## API
|
|
774
748
|
|
|
775
|
-
<docoff-react-props src="/components/SelectField/SelectField.
|
|
749
|
+
<docoff-react-props src="/components/SelectField/SelectField.tsx" name="SelectField"></docoff-react-props>
|
|
776
750
|
|
|
777
751
|
## Theming
|
|
778
752
|
|
|
@@ -785,6 +759,71 @@ options. On top of that, the following options are available for SelectField.
|
|
|
785
759
|
| `--rui-FormField--box--select__caret__background` | SelectField arrow background (including `url()` or gradient) |
|
|
786
760
|
| `--rui-FormField--box--select__option--disabled__color` | Text color of disabled SelectField options |
|
|
787
761
|
|
|
762
|
+
### Theming the Required State
|
|
763
|
+
|
|
764
|
+
Required fields are indicated by
|
|
765
|
+
[shared theming options](/docs/customize/theming/forms/#required-state).
|
|
766
|
+
|
|
767
|
+
If your project uses the label color as the primary means to indicate the
|
|
768
|
+
required state of input fields and the usual asterisk `*` is omitted, you may
|
|
769
|
+
want to keep the label color consistent for fields that are valid in both
|
|
770
|
+
selected and unselected states. Pair the theming options with the
|
|
771
|
+
[`renderAsRequired`](#rendering-as-required) prop to achieve that:
|
|
772
|
+
|
|
773
|
+
```docoff-react-preview
|
|
774
|
+
React.createElement(() => {
|
|
775
|
+
const [fruit, setFruit] = React.useState('apple');
|
|
776
|
+
const options = [
|
|
777
|
+
{
|
|
778
|
+
label: 'Apple',
|
|
779
|
+
value: 'apple',
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
label: 'Banana',
|
|
783
|
+
value: 'banana',
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
label: 'Grapefruit',
|
|
787
|
+
value: 'grapefruit',
|
|
788
|
+
},
|
|
789
|
+
];
|
|
790
|
+
return (
|
|
791
|
+
<React.Fragment>
|
|
792
|
+
<style>
|
|
793
|
+
{`
|
|
794
|
+
.example {
|
|
795
|
+
display: flex;
|
|
796
|
+
flex-wrap: wrap;
|
|
797
|
+
gap: 1rem 0.5rem;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
.example--themed-form-fields {
|
|
801
|
+
--rui-FormField__label__color: var(--rui-color-text-secondary);
|
|
802
|
+
--rui-FormField--required__label__color: var(--rui-color-text-primary);
|
|
803
|
+
--rui-FormField--required__sign: '';
|
|
804
|
+
}
|
|
805
|
+
`}
|
|
806
|
+
</style>
|
|
807
|
+
<div class="example example--themed-form-fields">
|
|
808
|
+
<SelectField
|
|
809
|
+
label="This field is optional"
|
|
810
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
811
|
+
options={options}
|
|
812
|
+
value={fruit}
|
|
813
|
+
/>
|
|
814
|
+
<SelectField
|
|
815
|
+
label="This field is optional but looks like required"
|
|
816
|
+
onChange={(e) => setFruit(e.target.value)}
|
|
817
|
+
options={options}
|
|
818
|
+
value={fruit}
|
|
819
|
+
renderAsRequired
|
|
820
|
+
/>
|
|
821
|
+
</div>
|
|
822
|
+
</React.Fragment>
|
|
823
|
+
);
|
|
824
|
+
});
|
|
825
|
+
```
|
|
826
|
+
|
|
788
827
|
[React common props]: https://react.dev/reference/react-dom/components/common#common-props
|
|
789
828
|
[ref]: https://reactjs.org/docs/refs-and-the-dom.html
|
|
790
829
|
[select-attributes]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attributes
|