@festo-ui/react 9.0.0-dev.718 → 9.0.0-dev.719
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/components/accordion/Accordion.css +4 -0
- package/dist/components/accordion/Accordion.d.ts +10 -0
- package/dist/components/accordion/Accordion.js +41 -0
- package/dist/components/accordion/AccordionContext.d.ts +11 -0
- package/dist/components/accordion/AccordionContext.js +3 -0
- package/dist/components/accordion/accordion-header/AccordionHeader.css +11 -0
- package/dist/components/accordion/accordion-header/AccordionHeader.d.ts +2 -0
- package/dist/components/accordion/accordion-header/AccordionHeader.js +11 -0
- package/dist/components/accordion/accordion-item/AccordionItem.css +64 -0
- package/dist/components/accordion/accordion-item/AccordionItem.d.ts +8 -0
- package/dist/components/accordion/accordion-item/AccordionItem.js +60 -0
- package/dist/components/accordion/accordion-item/AccordionItemContext.d.ts +7 -0
- package/dist/components/accordion/accordion-item/AccordionItemContext.js +3 -0
- package/dist/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.css +76 -0
- package/dist/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.d.ts +2 -0
- package/dist/components/accordion/accordion-item/accordion-item-body/AccordionItemBody.js +61 -0
- package/dist/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.css +11 -0
- package/dist/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.d.ts +2 -0
- package/dist/components/accordion/accordion-item/accordion-item-header/AccordionItemHeader.js +20 -0
- package/dist/components/bottom-sheet/BottomSheet.css +18 -0
- package/dist/components/bottom-sheet/BottomSheet.d.ts +12 -0
- package/dist/components/bottom-sheet/BottomSheet.js +101 -0
- package/dist/components/breadcrumb/Breadcrumb.d.ts +13 -0
- package/dist/components/breadcrumb/Breadcrumb.js +32 -0
- package/dist/components/button/Button.d.ts +11 -0
- package/dist/components/button/Button.js +36 -0
- package/dist/components/card/Card.d.ts +4 -0
- package/dist/components/card/Card.js +9 -0
- package/dist/components/card/CardBody.d.ts +5 -0
- package/dist/components/card/CardBody.js +15 -0
- package/dist/components/card/CardHeader.d.ts +8 -0
- package/dist/components/card/CardHeader.js +31 -0
- package/dist/components/card/CardHeader.stories.helper.js +7 -0
- package/dist/components/card/CardNotification.d.ts +6 -0
- package/dist/components/card/CardNotification.js +26 -0
- package/dist/components/chips/chip/Chip.d.ts +17 -0
- package/dist/components/chips/chip/Chip.js +38 -0
- package/dist/components/chips/chip-container/ChipContainer.d.ts +5 -0
- package/dist/components/chips/chip-container/ChipContainer.js +12 -0
- package/dist/components/icon-wrapper/IconWrapper.d.ts +3 -0
- package/dist/components/icon-wrapper/IconWrapper.js +13 -0
- package/dist/components/link-button/LinkButton.d.ts +8 -0
- package/dist/components/link-button/LinkButton.js +26 -0
- package/dist/components/loading-indicator/LoadingIndicator.d.ts +5 -0
- package/dist/components/loading-indicator/LoadingIndicator.js +41 -0
- package/dist/components/mobile-flyout/MobileFlyout.d.ts +11 -0
- package/dist/components/mobile-flyout/MobileFlyout.js +88 -0
- package/dist/components/mobile-flyout/MobileFlyoutContext.d.ts +8 -0
- package/dist/components/mobile-flyout/MobileFlyoutContext.js +3 -0
- package/dist/components/mobile-flyout/mobile-flyout-item/MobileFlyoutItem.d.ts +17 -0
- package/dist/components/mobile-flyout/mobile-flyout-item/MobileFlyoutItem.js +36 -0
- package/dist/components/mobile-flyout/mobile-flyout-page/MobileFlyoutPage.css +5 -0
- package/dist/components/mobile-flyout/mobile-flyout-page/MobileFlyoutPage.d.ts +8 -0
- package/dist/components/mobile-flyout/mobile-flyout-page/MobileFlyoutPage.js +35 -0
- package/dist/components/modals/AlertModal.d.ts +12 -0
- package/dist/components/modals/AlertModal.js +53 -0
- package/dist/components/modals/ConfirmModal.d.ts +11 -0
- package/dist/components/modals/ConfirmModal.js +46 -0
- package/dist/components/modals/CustomModal.d.ts +8 -0
- package/dist/components/modals/CustomModal.js +38 -0
- package/dist/components/modals/Modal.css +39 -0
- package/dist/components/modals/Modal.d.ts +8 -0
- package/dist/components/modals/Modal.js +31 -0
- package/dist/components/modals/ModalBase.d.ts +9 -0
- package/dist/components/modals/ModalBase.js +124 -0
- package/dist/components/modals/ModalFooter.d.ts +2 -0
- package/dist/components/modals/ModalFooter.js +12 -0
- package/dist/components/modals/Prompt.d.ts +15 -0
- package/dist/components/modals/Prompt.js +58 -0
- package/dist/components/modals/image-gallery/ImageGallery.css +790 -0
- package/dist/components/modals/image-gallery/ImageGallery.d.ts +18 -0
- package/dist/components/modals/image-gallery/ImageGallery.helper.d.ts +2 -0
- package/dist/components/modals/image-gallery/ImageGallery.helper.js +13 -0
- package/dist/components/modals/image-gallery/ImageGallery.js +75 -0
- package/dist/components/modals/image-gallery/ImageGallery.stories.helper.js +112 -0
- package/dist/components/modals/image-gallery/ImageGalleryContent.d.ts +9 -0
- package/dist/components/modals/image-gallery/ImageGalleryContent.js +15 -0
- package/dist/components/modals/image-gallery/ImageGalleryContext.d.ts +10 -0
- package/dist/components/modals/image-gallery/ImageGalleryContext.js +4 -0
- package/dist/components/modals/image-gallery/ImageGallerySwiper.d.ts +8 -0
- package/dist/components/modals/image-gallery/ImageGallerySwiper.js +29 -0
- package/dist/components/modals/image-gallery/ImageGalleryThumbsSwiper.d.ts +5 -0
- package/dist/components/modals/image-gallery/ImageGalleryThumbsSwiper.js +23 -0
- package/dist/components/modals/image-gallery/image-gallery-item/ImageGalleryItem.css +10 -0
- package/dist/components/modals/image-gallery/image-gallery-item/ImageGalleryItem.d.ts +11 -0
- package/dist/components/modals/image-gallery/image-gallery-item/ImageGalleryItem.js +24 -0
- package/dist/components/modals/image-gallery/internal/BaseGallery.d.ts +17 -0
- package/dist/components/modals/image-gallery/internal/BaseGallery.js +50 -0
- package/dist/components/modals/image-gallery/internal/CloseButton.d.ts +6 -0
- package/dist/components/modals/image-gallery/internal/CloseButton.js +14 -0
- package/dist/components/modals/image-gallery/internal/ImageGalleryContainer.d.ts +5 -0
- package/dist/components/modals/image-gallery/internal/ImageGalleryContainer.js +8 -0
- package/dist/components/modals/image-gallery/internal/ImageGalleryPagination.d.ts +5 -0
- package/dist/components/modals/image-gallery/internal/ImageGalleryPagination.js +29 -0
- package/dist/components/modals/image-gallery/internal/ScaleButton.d.ts +4 -0
- package/dist/components/modals/image-gallery/internal/ScaleButton.js +17 -0
- package/dist/components/pagination/Pagination.css +10 -0
- package/dist/components/pagination/Pagination.d.ts +15 -0
- package/dist/components/pagination/Pagination.js +100 -0
- package/dist/components/popovers/legend/Legend.css +21 -0
- package/dist/components/popovers/legend/Legend.d.ts +11 -0
- package/dist/components/popovers/legend/Legend.js +24 -0
- package/dist/components/popovers/popover/Popover.css +56 -0
- package/dist/components/popovers/popover/Popover.d.ts +20 -0
- package/dist/components/popovers/popover/Popover.js +106 -0
- package/dist/components/popovers/popover-menu/PopoverMenu.css +20 -0
- package/dist/components/popovers/popover-menu/PopoverMenu.d.ts +8 -0
- package/dist/components/popovers/popover-menu/PopoverMenu.js +37 -0
- package/dist/components/popovers/popover-menu/PopoverMenuContext.d.ts +3 -0
- package/dist/components/popovers/popover-menu/PopoverMenuContext.js +5 -0
- package/dist/components/popovers/popover-menu-item/PopoverMenuItem.css +35 -0
- package/dist/components/popovers/popover-menu-item/PopoverMenuItem.d.ts +10 -0
- package/dist/components/popovers/popover-menu-item/PopoverMenuItem.js +30 -0
- package/dist/components/popovers/tooltip/Tooltip.d.ts +5 -0
- package/dist/components/popovers/tooltip/Tooltip.js +12 -0
- package/dist/components/progress/Progress.d.ts +7 -0
- package/dist/components/progress/Progress.js +26 -0
- package/dist/components/search-input/ClearButton.d.ts +2 -0
- package/dist/components/search-input/ClearButton.js +10 -0
- package/dist/components/search-input/SearchInput.css +13 -0
- package/dist/components/search-input/SearchInput.d.ts +14 -0
- package/dist/components/search-input/SearchInput.js +61 -0
- package/dist/components/search-input/SearchSuggestion.d.ts +17 -0
- package/dist/components/search-input/SearchSuggestion.js +21 -0
- package/dist/components/search-input/useSearchInput.d.ts +13 -0
- package/dist/components/search-input/useSearchInput.js +85 -0
- package/dist/components/snackbar/Snackbar.css +55 -0
- package/dist/components/snackbar/Snackbar.d.ts +21 -0
- package/dist/components/snackbar/Snackbar.js +78 -0
- package/dist/components/snackbar/SnackbarContext.d.ts +7 -0
- package/dist/components/snackbar/SnackbarContext.js +3 -0
- package/dist/components/snackbar/SnackbarProvider.d.ts +8 -0
- package/dist/components/snackbar/SnackbarProvider.js +66 -0
- package/dist/components/snackbar/useSnackbar.d.ts +2 -0
- package/dist/components/snackbar/useSnackbar.js +4 -0
- package/dist/components/stepper-horizontal/StepperHorizontal.css +6 -0
- package/dist/components/stepper-horizontal/StepperHorizontal.d.ts +7 -0
- package/dist/components/stepper-horizontal/StepperHorizontal.js +48 -0
- package/dist/components/stepper-horizontal/step-horizontal/StepHorizontal.css +24 -0
- package/dist/components/stepper-horizontal/step-horizontal/StepHorizontal.d.ts +6 -0
- package/dist/components/stepper-horizontal/step-horizontal/StepHorizontal.js +16 -0
- package/dist/components/stepper-vertical/StepperVertical.d.ts +6 -0
- package/dist/components/stepper-vertical/StepperVertical.js +26 -0
- package/dist/components/stepper-vertical/step-vertical/StepVertical.css +10 -0
- package/dist/components/stepper-vertical/step-vertical/StepVertical.d.ts +11 -0
- package/dist/components/stepper-vertical/step-vertical/StepVertical.js +58 -0
- package/dist/components/tab/Tabs.css +285 -0
- package/dist/components/tab/Tabs.d.ts +23 -0
- package/dist/components/tab/Tabs.js +194 -0
- package/dist/components/tab/interfaces.d.ts +5 -0
- package/dist/components/tab/interfaces.js +0 -0
- package/dist/components/tab/tab-pane/TabPane.css +8 -0
- package/dist/components/tab/tab-pane/TabPane.d.ts +9 -0
- package/dist/components/tab/tab-pane/TabPane.js +18 -0
- package/dist/components/tab/useTabScroll.d.ts +25 -0
- package/dist/components/tab/useTabScroll.js +151 -0
- package/dist/components/table-header-cell/TableHeaderCell.d.ts +5 -0
- package/dist/components/table-header-cell/TableHeaderCell.js +21 -0
- package/dist/forms/checkbox/Checkbox.css +134 -0
- package/dist/forms/checkbox/Checkbox.d.ts +15 -0
- package/dist/forms/checkbox/Checkbox.js +80 -0
- package/dist/forms/radio/RadioButton.d.ts +14 -0
- package/dist/forms/radio/RadioButton.js +61 -0
- package/dist/forms/radio/RadioGroup.d.ts +12 -0
- package/dist/forms/radio/RadioGroup.js +50 -0
- package/dist/forms/radio/RadioGroupContext.d.ts +12 -0
- package/dist/forms/radio/RadioGroupContext.js +3 -0
- package/dist/forms/segment/Segment.d.ts +13 -0
- package/dist/forms/segment/Segment.js +59 -0
- package/dist/forms/segment/segment-control/SegmentControl.d.ts +14 -0
- package/dist/forms/segment/segment-control/SegmentControl.js +57 -0
- package/dist/forms/select/Select.css +160 -0
- package/dist/forms/select/Select.d.ts +26 -0
- package/dist/forms/select/Select.js +95 -0
- package/dist/forms/select/internal/HiddenInput.d.ts +8 -0
- package/dist/forms/select/internal/HiddenInput.js +15 -0
- package/dist/forms/select/internal/ListItem.d.ts +18 -0
- package/dist/forms/select/internal/ListItem.js +69 -0
- package/dist/forms/select/internal/SelectButton.d.ts +12 -0
- package/dist/forms/select/internal/SelectButton.js +49 -0
- package/dist/forms/select/internal/SelectButtonContent.d.ts +7 -0
- package/dist/forms/select/internal/SelectButtonContent.js +31 -0
- package/dist/forms/select/internal/SelectCheckbox.d.ts +4 -0
- package/dist/forms/select/internal/SelectCheckbox.js +13 -0
- package/dist/forms/select/internal/SelectLabel.d.ts +7 -0
- package/dist/forms/select/internal/SelectLabel.js +12 -0
- package/dist/forms/select/internal/SelectOptionsContainer.d.ts +17 -0
- package/dist/forms/select/internal/SelectOptionsContainer.js +103 -0
- package/dist/forms/select/internal/SelectScrollContainer.d.ts +8 -0
- package/dist/forms/select/internal/SelectScrollContainer.js +15 -0
- package/dist/forms/select/internal/SelectWrapper.d.ts +6 -0
- package/dist/forms/select/internal/SelectWrapper.js +12 -0
- package/dist/forms/select/internal/index.d.ts +6 -0
- package/dist/forms/select/internal/index.js +7 -0
- package/dist/forms/select/internal/utils.d.ts +7 -0
- package/dist/forms/select/internal/utils.js +30 -0
- package/dist/forms/select/select-option/SelectOption.d.ts +14 -0
- package/dist/forms/select/select-option/SelectOption.js +12 -0
- package/dist/forms/select/utils.d.ts +2 -0
- package/dist/forms/select/utils.js +12 -0
- package/dist/forms/slider/Slider.css +50 -0
- package/dist/forms/slider/Slider.d.ts +17 -0
- package/dist/forms/slider/Slider.js +93 -0
- package/dist/forms/switch/Switch.d.ts +12 -0
- package/dist/forms/switch/Switch.js +42 -0
- package/dist/forms/text-area/TextArea.css +14 -0
- package/dist/forms/text-area/TextArea.d.ts +22 -0
- package/dist/forms/text-area/TextArea.js +99 -0
- package/dist/forms/text-input/TextInput.d.ts +24 -0
- package/dist/forms/text-input/TextInput.js +74 -0
- package/dist/forms/time-picker/TimePicker.css +10 -0
- package/dist/forms/time-picker/TimePicker.d.ts +24 -0
- package/dist/forms/time-picker/TimePicker.js +140 -0
- package/dist/forms/time-picker/time-picker-dropdown/TimePickerDropdown.css +4 -0
- package/dist/forms/time-picker/time-picker-dropdown/TimePickerDropdown.d.ts +19 -0
- package/dist/forms/time-picker/time-picker-dropdown/TimePickerDropdown.js +202 -0
- package/dist/forms/time-picker/time-picker-dropdown/TimePickerInput.d.ts +9 -0
- package/dist/forms/time-picker/time-picker-dropdown/TimePickerInput.js +14 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +60 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +7 -0
- package/dist/utils/setRef.d.ts +1 -0
- package/dist/utils/setRef.js +5 -0
- package/dist/utils/types.d.ts +29 -0
- package/dist/utils/types.js +0 -0
- package/dist/utils/useControlled.d.ts +7 -0
- package/dist/utils/useControlled.js +20 -0
- package/dist/utils/useForkRef.d.ts +2 -0
- package/dist/utils/useForkRef.js +15 -0
- package/dist/utils/useId.d.ts +1 -0
- package/dist/utils/useId.js +20 -0
- package/dist/utils/useOnClickOutside.d.ts +2 -0
- package/dist/utils/useOnClickOutside.js +20 -0
- package/package.json +1 -2
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
const useTabScroll = (tabLength, componentId, refs)=>{
|
|
3
|
+
const { elRef, scrollContent, scrollArea } = refs;
|
|
4
|
+
const [style, setStyle] = useState({});
|
|
5
|
+
const [classes, setClasses] = useState('');
|
|
6
|
+
function getScrollContentStyleValue(propName) {
|
|
7
|
+
return scrollContent.current ? window.getComputedStyle(scrollContent.current).getPropertyValue(propName) : '';
|
|
8
|
+
}
|
|
9
|
+
function calculateCurrentTranslateX() {
|
|
10
|
+
const transformValue = getScrollContentStyleValue('transform');
|
|
11
|
+
if ('none' === transformValue) return 0;
|
|
12
|
+
const match = /\((.+?)\)/.exec(transformValue);
|
|
13
|
+
if (!match) return 0;
|
|
14
|
+
const matrixParams = match[1];
|
|
15
|
+
const [_a, _b, _c, _d, tx, _ty] = matrixParams.split(',');
|
|
16
|
+
return parseFloat(tx);
|
|
17
|
+
}
|
|
18
|
+
function getScrollPosition() {
|
|
19
|
+
const currentTranslateX = calculateCurrentTranslateX();
|
|
20
|
+
const scrollLeft = scrollArea.current?.scrollLeft ?? 0;
|
|
21
|
+
return scrollLeft - currentTranslateX;
|
|
22
|
+
}
|
|
23
|
+
function calculateScrollEdges() {
|
|
24
|
+
const scrollContentWidth = scrollContent.current?.offsetWidth ?? 0;
|
|
25
|
+
const scrollAreaWidth = scrollArea.current?.offsetWidth ?? 0;
|
|
26
|
+
return {
|
|
27
|
+
left: 0,
|
|
28
|
+
right: scrollContentWidth - scrollAreaWidth
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function clampScrollValue(scrollX) {
|
|
32
|
+
const edges = calculateScrollEdges();
|
|
33
|
+
return Math.min(Math.max(edges.left, scrollX), edges.right);
|
|
34
|
+
}
|
|
35
|
+
function getIncrementScrollOperation(scrollX) {
|
|
36
|
+
const currentScrollX = getScrollPosition();
|
|
37
|
+
const targetScrollX = scrollX + currentScrollX;
|
|
38
|
+
const safeScrollX = clampScrollValue(targetScrollX);
|
|
39
|
+
const scrollDelta = safeScrollX - currentScrollX;
|
|
40
|
+
return {
|
|
41
|
+
finalScrollPosition: safeScrollX,
|
|
42
|
+
scrollDelta
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function getAnimatingScrollPosition() {
|
|
46
|
+
const currentTranslateX = calculateCurrentTranslateX();
|
|
47
|
+
const scrollLeft = scrollArea.current?.scrollLeft ?? 0;
|
|
48
|
+
return scrollLeft - currentTranslateX;
|
|
49
|
+
}
|
|
50
|
+
function stopScrollAnimation() {
|
|
51
|
+
const currentScrollPosition = getAnimatingScrollPosition();
|
|
52
|
+
setClasses('');
|
|
53
|
+
setStyle({
|
|
54
|
+
transform: 'translateX(0px)'
|
|
55
|
+
});
|
|
56
|
+
if (scrollArea.current) scrollArea.current.scrollLeft = currentScrollPosition;
|
|
57
|
+
}
|
|
58
|
+
function animate(animation) {
|
|
59
|
+
if (0 === animation.scrollDelta) return;
|
|
60
|
+
stopScrollAnimation();
|
|
61
|
+
if (scrollArea.current) scrollArea.current.scrollLeft = animation.finalScrollPosition;
|
|
62
|
+
setStyle({
|
|
63
|
+
transform: `translateX(${animation.scrollDelta}px)`
|
|
64
|
+
});
|
|
65
|
+
if (scrollArea.current) scrollArea.current.getBoundingClientRect();
|
|
66
|
+
requestAnimationFrame(()=>{
|
|
67
|
+
setClasses('fr-tab-scroller--animating');
|
|
68
|
+
setStyle({
|
|
69
|
+
transform: 'none'
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
function incrementScroll(scrollXIncrement) {
|
|
74
|
+
if (0 === scrollXIncrement) return;
|
|
75
|
+
const scrollOperation = getIncrementScrollOperation(scrollXIncrement);
|
|
76
|
+
animate(scrollOperation);
|
|
77
|
+
}
|
|
78
|
+
function computeDimensions(tab) {
|
|
79
|
+
const rootWidth = tab.offsetWidth;
|
|
80
|
+
const rootLeft = tab.offsetLeft;
|
|
81
|
+
const tabContent = tab.querySelector('.fr-tab-content');
|
|
82
|
+
const contentWidth = tabContent?.offsetWidth ?? 0;
|
|
83
|
+
const contentLeft = tabContent?.offsetLeft ?? 0;
|
|
84
|
+
return {
|
|
85
|
+
contentLeft: rootLeft + contentLeft,
|
|
86
|
+
contentRight: rootLeft + contentLeft + contentWidth,
|
|
87
|
+
rootLeft,
|
|
88
|
+
rootRight: rootLeft + rootWidth
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function calculateScrollIncrement(index, nextIndex, scrollPosition, barWidth) {
|
|
92
|
+
const nextTab = elRef.current?.querySelector(`#${componentId}-tab-${nextIndex}`);
|
|
93
|
+
if (null == nextTab) return 0;
|
|
94
|
+
const nextTabDimensions = computeDimensions(nextTab);
|
|
95
|
+
const relativeContentLeft = nextTabDimensions.contentLeft - scrollPosition - barWidth;
|
|
96
|
+
const relativeContentRight = nextTabDimensions.contentRight - scrollPosition;
|
|
97
|
+
const leftIncrement = relativeContentRight - 48;
|
|
98
|
+
const rightIncrement = relativeContentLeft + 48;
|
|
99
|
+
if (nextIndex < index) return Math.min(leftIncrement, 0);
|
|
100
|
+
return Math.max(rightIncrement, 0);
|
|
101
|
+
}
|
|
102
|
+
function findAdjacentTabIndexClosestToEdge(index, tabDimensions, scrollPosition, barWidth) {
|
|
103
|
+
const relativeRootLeft = tabDimensions.rootLeft - scrollPosition;
|
|
104
|
+
const relativeRootRight = tabDimensions.rootRight - scrollPosition - barWidth;
|
|
105
|
+
const relativeRootDelta = relativeRootLeft + relativeRootRight;
|
|
106
|
+
const leftEdgeIsCloser = relativeRootLeft < 0 || relativeRootDelta < 0;
|
|
107
|
+
const rightEdgeIsCloser = relativeRootRight > 0 || relativeRootDelta > 0;
|
|
108
|
+
if (leftEdgeIsCloser) return index - 1;
|
|
109
|
+
if (rightEdgeIsCloser) return index + 1;
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
function indexIsInRange(index) {
|
|
113
|
+
return index >= 0 && index < tabLength;
|
|
114
|
+
}
|
|
115
|
+
function scrollIntoView(index, tab) {
|
|
116
|
+
const scrollPosition = getScrollPosition();
|
|
117
|
+
const barWidth = scrollArea.current?.offsetWidth ?? 0;
|
|
118
|
+
const tabDimensions = computeDimensions(tab);
|
|
119
|
+
const nextIndex = findAdjacentTabIndexClosestToEdge(index, tabDimensions, scrollPosition, barWidth);
|
|
120
|
+
if (!indexIsInRange(nextIndex)) return;
|
|
121
|
+
const scrollIncrement = calculateScrollIncrement(index, nextIndex, scrollPosition, barWidth);
|
|
122
|
+
incrementScroll(scrollIncrement);
|
|
123
|
+
}
|
|
124
|
+
function scrollTo(scrollX) {
|
|
125
|
+
const currentScrollX = getScrollPosition();
|
|
126
|
+
const safeScrollX = clampScrollValue(scrollX);
|
|
127
|
+
const scrollDelta = safeScrollX - currentScrollX;
|
|
128
|
+
animate({
|
|
129
|
+
finalScrollPosition: safeScrollX,
|
|
130
|
+
scrollDelta
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function handleTabScroll(e, index) {
|
|
134
|
+
const scrollContentWidth = scrollContent.current?.offsetWidth ?? 0;
|
|
135
|
+
const scrollAreaWidth = scrollArea.current?.offsetWidth ?? 0;
|
|
136
|
+
if (scrollAreaWidth > scrollContentWidth) return;
|
|
137
|
+
if (!indexIsInRange(index)) return;
|
|
138
|
+
if (0 === index) return void scrollTo(0);
|
|
139
|
+
if (index === tabLength - 1 && scrollContent.current) return void scrollTo(scrollContent.current.offsetWidth);
|
|
140
|
+
if (e.currentTarget instanceof HTMLElement) {
|
|
141
|
+
const currentTab = e.currentTarget;
|
|
142
|
+
scrollIntoView(index, currentTab);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return [
|
|
146
|
+
handleTabScroll,
|
|
147
|
+
classes,
|
|
148
|
+
style
|
|
149
|
+
];
|
|
150
|
+
};
|
|
151
|
+
export { useTabScroll };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export interface TableHeaderCellProps extends React.ThHTMLAttributes<HTMLTableCellElement> {
|
|
2
|
+
active?: boolean;
|
|
3
|
+
ascending: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const TableHeaderCell: (props: TableHeaderCellProps & import("react").RefAttributes<HTMLTableCellElement>) => React.ReactElement | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
const TableHeaderCell = /*#__PURE__*/ forwardRef(({ active, ascending, className, ...props }, ref)=>{
|
|
5
|
+
function handleClick(event) {
|
|
6
|
+
if (props.onClick) props.onClick(event);
|
|
7
|
+
}
|
|
8
|
+
return /*#__PURE__*/ jsx("th", {
|
|
9
|
+
...props,
|
|
10
|
+
className: classnames('fwe-table-order', {
|
|
11
|
+
'fwe-active': active
|
|
12
|
+
}, {
|
|
13
|
+
'fwe-table-order-ascending': active && ascending
|
|
14
|
+
}, {
|
|
15
|
+
'fwe-table-order-descending': active && !ascending
|
|
16
|
+
}, className),
|
|
17
|
+
onClick: handleClick,
|
|
18
|
+
ref: ref
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
export { TableHeaderCell };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
.fwe-checkbox-container {
|
|
2
|
+
font-family: var(--fwe-font-family-sans-serif);
|
|
3
|
+
user-select: none;
|
|
4
|
+
cursor: pointer;
|
|
5
|
+
flex-direction: row;
|
|
6
|
+
align-items: center;
|
|
7
|
+
display: flex;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.fwe-checkbox-container.fwe-label-below {
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.fwe-checkbox-container.fwe-label-below .fwe-checkbox-title {
|
|
15
|
+
margin: 8px 0 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.fwe-checkbox-container.fwe-label-before {
|
|
19
|
+
flex-direction: row-reverse;
|
|
20
|
+
justify-content: flex-end;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.fwe-checkbox-container.fwe-label-before .fwe-checkbox-title {
|
|
24
|
+
margin: 0 8px 0 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.fwe-checkbox-container .fwe-checkbox-indicator-container {
|
|
28
|
+
position: relative;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.fwe-checkbox-container input {
|
|
32
|
+
opacity: 0;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
width: 0;
|
|
35
|
+
height: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.fwe-checkbox-container .fwe-checkbox-title {
|
|
39
|
+
color: var(--fwe-text);
|
|
40
|
+
user-select: none;
|
|
41
|
+
margin-left: 8px;
|
|
42
|
+
line-height: 24px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.fwe-checkbox-container .fwe-checkbox-indicator-background {
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
background: var(--fwe-white);
|
|
48
|
+
border: 1px solid var(--fwe-text-light);
|
|
49
|
+
border-radius: 2px;
|
|
50
|
+
width: 16px;
|
|
51
|
+
height: 16px;
|
|
52
|
+
transition: border-width .2s ease-out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.fwe-checkbox-container .fwe-indeterminate-indicator {
|
|
56
|
+
background: #fff;
|
|
57
|
+
width: 10px;
|
|
58
|
+
height: 2px;
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: 7px;
|
|
61
|
+
left: 3px;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.fwe-checkbox-container .fwe-checkbox-indicator-background + svg {
|
|
65
|
+
display: block;
|
|
66
|
+
position: absolute;
|
|
67
|
+
top: 0;
|
|
68
|
+
left: 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
.fwe-checkbox-container.fr-checkbox-large .fwe-checkbox-indicator-background {
|
|
72
|
+
border-radius: 4px;
|
|
73
|
+
width: 24px;
|
|
74
|
+
height: 24px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.fwe-checkbox-container.fr-checkbox-large .fwe-indeterminate-indicator {
|
|
78
|
+
width: 14px;
|
|
79
|
+
top: 11px;
|
|
80
|
+
left: 5px;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.fwe-checkbox-container.fr-checkbox-large.fwe-checked .fwe-checkbox-indicator-background, .fwe-checkbox-container.fr-checkbox-large.fr-checkbox-indeterminate .fwe-checkbox-indicator-background {
|
|
84
|
+
border: 12px solid var(--fwe-hero);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.fwe-checkbox-container:hover .fwe-checkbox-indicator-background {
|
|
88
|
+
background-color: var(--fwe-control);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.fwe-checkbox-container:active .fwe-checkbox-indicator-background {
|
|
92
|
+
background-color: var(--fwe-control-hover);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.fwe-checkbox-container.fwe-checked .fwe-checkbox-indicator-background, .fwe-checkbox-container.fr-checkbox-indeterminate .fwe-checkbox-indicator-background {
|
|
96
|
+
border: 8px solid var(--fwe-hero);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.fwe-checkbox-container.fwe-checked:hover .fwe-checkbox-indicator-background, .fwe-checkbox-container.fr-checkbox-indeterminate:hover .fwe-checkbox-indicator-background {
|
|
100
|
+
border-color: var(--fwe-hero-hover);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.fwe-checkbox-container.fwe-checked:active .fwe-checkbox-indicator-background, .fwe-checkbox-container.fr-checkbox-indeterminate:active .fwe-checkbox-indicator-background {
|
|
104
|
+
border-color: var(--fwe-hero-active);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.fwe-checkbox-container.fr-checkbox-invalid .fwe-checkbox-indicator-background {
|
|
108
|
+
border: 1px solid var(--fwe-red);
|
|
109
|
+
background: var(--fwe-white);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.fwe-checkbox-container.fwe-disabled {
|
|
113
|
+
cursor: default;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.fwe-checkbox-container.fwe-disabled .fwe-checkbox-indicator-background {
|
|
117
|
+
background-color: var(--fwe-white);
|
|
118
|
+
border: 1px solid var(--fwe-control);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.fwe-checkbox-container.fwe-disabled.fwe-checked .fwe-checkbox-indicator-background, .fwe-checkbox-container.fwe-disabled.fr-checkbox-indeterminate .fwe-checkbox-indicator-background {
|
|
122
|
+
background-color: var(--fwe-control);
|
|
123
|
+
border: 1px solid var(--fwe-control);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.fwe-checkbox-container.fwe-disabled.fr-checkbox-invalid .fwe-checkbox-indicator-background {
|
|
127
|
+
background-color: var(--fwe-white);
|
|
128
|
+
border: 1px solid var(--fwe-control);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.fwe-checkbox-container.fwe-disabled .fwe-checkbox-title {
|
|
132
|
+
color: var(--fwe-text-disabled);
|
|
133
|
+
}
|
|
134
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import './Checkbox.scss';
|
|
2
|
+
export interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange'> {
|
|
3
|
+
readonly id?: string;
|
|
4
|
+
readonly checked?: boolean;
|
|
5
|
+
readonly defaultChecked?: boolean;
|
|
6
|
+
readonly onChange?: (value: boolean, e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
7
|
+
readonly name?: string;
|
|
8
|
+
readonly large?: boolean;
|
|
9
|
+
readonly valid?: boolean;
|
|
10
|
+
readonly labelPosition?: 'before' | 'after' | 'below';
|
|
11
|
+
readonly required?: boolean;
|
|
12
|
+
readonly disabled?: boolean;
|
|
13
|
+
readonly indeterminate?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function Checkbox({ id, checked: checkedProp, defaultChecked, onChange, name, large, valid, labelPosition, required, disabled, indeterminate, children, className, ...props }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./Checkbox.css";
|
|
3
|
+
import classnames from "classnames";
|
|
4
|
+
import { useControlled } from "../../utils/useControlled.js";
|
|
5
|
+
function Checkbox({ id, checked: checkedProp, defaultChecked, onChange, name, large = false, valid = true, labelPosition = 'after', required, disabled = false, indeterminate = false, children, className, ...props }) {
|
|
6
|
+
const [isChecked, setChecked] = useControlled({
|
|
7
|
+
controlled: checkedProp,
|
|
8
|
+
default: defaultChecked
|
|
9
|
+
});
|
|
10
|
+
const handleChange = (e)=>{
|
|
11
|
+
const newChecked = !isChecked;
|
|
12
|
+
setChecked(newChecked);
|
|
13
|
+
onChange?.(newChecked, e);
|
|
14
|
+
};
|
|
15
|
+
const containerClasses = classnames('fwe-checkbox-container', {
|
|
16
|
+
'fr-checkbox-large': large
|
|
17
|
+
}, {
|
|
18
|
+
'fr-checkbox-invalid': !valid || required
|
|
19
|
+
}, {
|
|
20
|
+
'fwe-disabled': disabled
|
|
21
|
+
}, {
|
|
22
|
+
'fwe-checked': isChecked
|
|
23
|
+
}, {
|
|
24
|
+
'fwe-label-below': 'below' === labelPosition
|
|
25
|
+
}, {
|
|
26
|
+
'fwe-label-before': 'before' === labelPosition
|
|
27
|
+
}, {
|
|
28
|
+
'fr-checkbox-indeterminate': indeterminate
|
|
29
|
+
}, className);
|
|
30
|
+
return /*#__PURE__*/ jsxs("label", {
|
|
31
|
+
className: containerClasses,
|
|
32
|
+
htmlFor: id,
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ jsx("input", {
|
|
35
|
+
name: name,
|
|
36
|
+
type: "checkbox",
|
|
37
|
+
id: id,
|
|
38
|
+
disabled: disabled,
|
|
39
|
+
required: required,
|
|
40
|
+
onChange: (e)=>handleChange(e),
|
|
41
|
+
...props,
|
|
42
|
+
checked: isChecked
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ jsxs("div", {
|
|
45
|
+
className: "fwe-checkbox-indicator-container",
|
|
46
|
+
children: [
|
|
47
|
+
/*#__PURE__*/ jsx("div", {
|
|
48
|
+
className: "fwe-checkbox-indicator-background"
|
|
49
|
+
}),
|
|
50
|
+
!indeterminate && isChecked && (large ? /*#__PURE__*/ jsx("svg", {
|
|
51
|
+
width: "24px",
|
|
52
|
+
height: "24px",
|
|
53
|
+
"aria-hidden": "true",
|
|
54
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
55
|
+
d: "M17.5 7L10 14.5 7.501 12l-1.5 1.501L10 17.5l9-9z",
|
|
56
|
+
fill: "#fff"
|
|
57
|
+
})
|
|
58
|
+
}) : /*#__PURE__*/ jsx("svg", {
|
|
59
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
60
|
+
width: "16",
|
|
61
|
+
height: "16",
|
|
62
|
+
"aria-hidden": "true",
|
|
63
|
+
children: /*#__PURE__*/ jsx("path", {
|
|
64
|
+
d: "M6 12L3 9l1.25-1.25L6 9.5l5.75-5.75L13 5l-7 7z",
|
|
65
|
+
fill: "#fff"
|
|
66
|
+
})
|
|
67
|
+
})),
|
|
68
|
+
indeterminate && /*#__PURE__*/ jsx("div", {
|
|
69
|
+
className: "fwe-indeterminate-indicator"
|
|
70
|
+
})
|
|
71
|
+
]
|
|
72
|
+
}),
|
|
73
|
+
/*#__PURE__*/ jsx("div", {
|
|
74
|
+
className: "fwe-checkbox-title",
|
|
75
|
+
children: children
|
|
76
|
+
})
|
|
77
|
+
]
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
export { Checkbox };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ClassNamePropsWithChildren } from '../../utils/types';
|
|
2
|
+
export interface RadioProps extends ClassNamePropsWithChildren {
|
|
3
|
+
id?: string;
|
|
4
|
+
defaultChecked?: boolean;
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
onChange?: (value: string) => void;
|
|
7
|
+
name?: string;
|
|
8
|
+
value?: string;
|
|
9
|
+
labelPosition?: 'before' | 'after' | 'below';
|
|
10
|
+
large?: boolean;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function RadioButton(props: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import { useContext } from "react";
|
|
4
|
+
import { useId } from "../../utils/useId.js";
|
|
5
|
+
import { RadioGroupContext } from "./RadioGroupContext.js";
|
|
6
|
+
function RadioButton(props) {
|
|
7
|
+
const { id: idProps, onChange, value, name, defaultChecked: defaultCheckedProp, checked, labelPosition = 'after', large = false, disabled = false, required = false, children, className } = props;
|
|
8
|
+
const { disabled: groupDisabled, labelPosition: groupLabelPosition, large: groupLarge, name: groupName, value: groupValue, required: groupRequired, handleValueChange: onGroupValueChange, isControlled } = useContext(RadioGroupContext);
|
|
9
|
+
const innerLabelPosition = groupLabelPosition ?? labelPosition;
|
|
10
|
+
const classes = classnames('fwe-radio', {
|
|
11
|
+
'fwe-radio-label-below': 'below' === innerLabelPosition
|
|
12
|
+
}, {
|
|
13
|
+
'fwe-radio-label-before': 'before' === innerLabelPosition
|
|
14
|
+
}, {
|
|
15
|
+
'fwe-radio-lg': large || groupLarge
|
|
16
|
+
}, className);
|
|
17
|
+
const controlledChecked = void 0 !== checked || isControlled && void 0 !== groupValue ? Boolean(checked || groupValue === value) : void 0;
|
|
18
|
+
const getDefaultChecked = ()=>{
|
|
19
|
+
if (void 0 !== controlledChecked) return;
|
|
20
|
+
if (void 0 !== defaultCheckedProp) return defaultCheckedProp;
|
|
21
|
+
if (!isControlled && void 0 !== groupValue) return groupValue === value;
|
|
22
|
+
};
|
|
23
|
+
const defaultChecked = getDefaultChecked();
|
|
24
|
+
function handleChange(event) {
|
|
25
|
+
const newValue = event.target.value;
|
|
26
|
+
if (newValue) onGroupValueChange?.(newValue);
|
|
27
|
+
onChange?.(newValue);
|
|
28
|
+
}
|
|
29
|
+
const id = useId(idProps);
|
|
30
|
+
return /*#__PURE__*/ jsxs("label", {
|
|
31
|
+
className: classes,
|
|
32
|
+
htmlFor: id,
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ jsxs("div", {
|
|
35
|
+
className: "fwe-radio-check",
|
|
36
|
+
children: [
|
|
37
|
+
/*#__PURE__*/ jsx("input", {
|
|
38
|
+
defaultChecked: defaultChecked,
|
|
39
|
+
checked: controlledChecked,
|
|
40
|
+
type: "radio",
|
|
41
|
+
id: id,
|
|
42
|
+
name: groupName || name,
|
|
43
|
+
value: value,
|
|
44
|
+
onChange: handleChange,
|
|
45
|
+
disabled: disabled || groupDisabled,
|
|
46
|
+
required: required || groupRequired
|
|
47
|
+
}),
|
|
48
|
+
/*#__PURE__*/ jsx("div", {
|
|
49
|
+
className: "fwe-radio-checkmark"
|
|
50
|
+
}),
|
|
51
|
+
' '
|
|
52
|
+
]
|
|
53
|
+
}),
|
|
54
|
+
/*#__PURE__*/ jsx("div", {
|
|
55
|
+
className: "fwe-radio-label-content",
|
|
56
|
+
children: children
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export { RadioButton };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef } from 'react';
|
|
2
|
+
export interface RadioGroupProps extends ComponentPropsWithoutRef<'div'> {
|
|
3
|
+
name?: string;
|
|
4
|
+
defaultValue?: string;
|
|
5
|
+
onValueChange?: (value: string) => void;
|
|
6
|
+
value?: string;
|
|
7
|
+
labelPosition?: 'before' | 'after' | 'below';
|
|
8
|
+
large?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare const RadioGroup: (props: RadioGroupProps & import("react").RefAttributes<HTMLDivElement>) => React.ReactElement | null;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import { forwardRef, useCallback, useMemo } from "react";
|
|
4
|
+
import { useControlled } from "../../utils/useControlled.js";
|
|
5
|
+
import { useId } from "../../utils/useId.js";
|
|
6
|
+
import { RadioGroupContext } from "./RadioGroupContext.js";
|
|
7
|
+
const RadioGroup = /*#__PURE__*/ forwardRef(({ children, className, onValueChange, value: controlledValue, defaultValue, name, labelPosition, large, disabled, required, ...props }, ref)=>{
|
|
8
|
+
const contextName = useId(name);
|
|
9
|
+
const [value, setValue] = useControlled({
|
|
10
|
+
controlled: controlledValue,
|
|
11
|
+
default: defaultValue
|
|
12
|
+
});
|
|
13
|
+
const handleValueChange = useCallback((newValue)=>{
|
|
14
|
+
onValueChange?.(newValue);
|
|
15
|
+
setValue(newValue);
|
|
16
|
+
}, [
|
|
17
|
+
onValueChange,
|
|
18
|
+
setValue
|
|
19
|
+
]);
|
|
20
|
+
const contextValue = useMemo(()=>({
|
|
21
|
+
labelPosition,
|
|
22
|
+
large,
|
|
23
|
+
disabled,
|
|
24
|
+
required,
|
|
25
|
+
handleValueChange,
|
|
26
|
+
value,
|
|
27
|
+
isControlled: void 0 !== controlledValue,
|
|
28
|
+
name: contextName
|
|
29
|
+
}), [
|
|
30
|
+
controlledValue,
|
|
31
|
+
handleValueChange,
|
|
32
|
+
labelPosition,
|
|
33
|
+
large,
|
|
34
|
+
disabled,
|
|
35
|
+
required,
|
|
36
|
+
value,
|
|
37
|
+
contextName
|
|
38
|
+
]);
|
|
39
|
+
return /*#__PURE__*/ jsx(RadioGroupContext.Provider, {
|
|
40
|
+
value: contextValue,
|
|
41
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
42
|
+
ref: ref,
|
|
43
|
+
className: classnames('fwe-radio-group', className),
|
|
44
|
+
role: "radiogroup",
|
|
45
|
+
...props,
|
|
46
|
+
children: children
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
export { RadioGroup };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ContextProps {
|
|
2
|
+
name: string;
|
|
3
|
+
value: string;
|
|
4
|
+
isControlled: boolean;
|
|
5
|
+
labelPosition: 'before' | 'after' | 'below';
|
|
6
|
+
large: boolean;
|
|
7
|
+
handleValueChange: (value: string) => void;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
required: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare const RadioGroupContext: import("react").Context<Partial<ContextProps>>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ClassNamePropsWithChildren } from '../../utils/types';
|
|
3
|
+
export interface SegmentComponentConfiguration {
|
|
4
|
+
outline?: boolean;
|
|
5
|
+
iconOnly?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SegmentProps extends ClassNamePropsWithChildren {
|
|
8
|
+
legend: string;
|
|
9
|
+
config?: SegmentComponentConfiguration;
|
|
10
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: any) => void;
|
|
11
|
+
value?: any;
|
|
12
|
+
}
|
|
13
|
+
export declare function Segment(props: SegmentProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import classnames from "classnames";
|
|
3
|
+
import react from "react";
|
|
4
|
+
import { useControlled } from "../../utils/useControlled.js";
|
|
5
|
+
const defaultConfig = {
|
|
6
|
+
outline: true,
|
|
7
|
+
iconOnly: true
|
|
8
|
+
};
|
|
9
|
+
function Segment(props) {
|
|
10
|
+
const { children, legend, config, onChange, className, value: valueProps } = props;
|
|
11
|
+
const innerConfig = {
|
|
12
|
+
...defaultConfig,
|
|
13
|
+
...config
|
|
14
|
+
};
|
|
15
|
+
let useIcon = false;
|
|
16
|
+
let useIconAndText = false;
|
|
17
|
+
let tmpValue = '';
|
|
18
|
+
react.Children.forEach(children, (child, index)=>{
|
|
19
|
+
if (!/*#__PURE__*/ react.isValidElement(child)) return null;
|
|
20
|
+
if (0 === index && null !== child.props.icon) if (innerConfig.iconOnly) useIcon = true;
|
|
21
|
+
else useIconAndText = true;
|
|
22
|
+
if (child.props.checked) tmpValue = child.props.value;
|
|
23
|
+
return null;
|
|
24
|
+
});
|
|
25
|
+
const [value, setValue] = useControlled({
|
|
26
|
+
controlled: valueProps,
|
|
27
|
+
default: tmpValue
|
|
28
|
+
});
|
|
29
|
+
const handleChange = (event, _value)=>{
|
|
30
|
+
if (onChange) onChange(event, _value);
|
|
31
|
+
setValue(_value);
|
|
32
|
+
};
|
|
33
|
+
return /*#__PURE__*/ jsxs("fieldset", {
|
|
34
|
+
className: classnames('fwe-segment', {
|
|
35
|
+
'fwe-segment-outline': innerConfig.outline,
|
|
36
|
+
'fwe-segment-icon': useIcon,
|
|
37
|
+
'fwe-segment-icon-text': useIconAndText
|
|
38
|
+
}, className),
|
|
39
|
+
children: [
|
|
40
|
+
/*#__PURE__*/ jsx("legend", {
|
|
41
|
+
className: "fwe-sr-only fwe-d-inline-block",
|
|
42
|
+
children: legend
|
|
43
|
+
}),
|
|
44
|
+
/*#__PURE__*/ jsx("div", {
|
|
45
|
+
className: "fwe-segment-group",
|
|
46
|
+
children: react.Children.map(children, (child)=>{
|
|
47
|
+
if (!/*#__PURE__*/ react.isValidElement(child)) return null;
|
|
48
|
+
return /*#__PURE__*/ react.cloneElement(child, {
|
|
49
|
+
...child.props,
|
|
50
|
+
onChange: handleChange,
|
|
51
|
+
iconOnly: innerConfig.iconOnly,
|
|
52
|
+
checked: child.props.value === value
|
|
53
|
+
});
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export { Segment };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { ClassNameProps } from '../../../utils/types';
|
|
3
|
+
export interface SegmentControlProps extends ClassNameProps {
|
|
4
|
+
label: string;
|
|
5
|
+
name: string;
|
|
6
|
+
value: any;
|
|
7
|
+
checked?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>, value: any) => void;
|
|
11
|
+
id?: string;
|
|
12
|
+
iconOnly?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function SegmentControl(props: SegmentControlProps): import("react/jsx-runtime").JSX.Element;
|