@neko-os/ui 0.0.5 → 0.0.7
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/NekoUI.js +1 -1
- package/dist/abstractions/ActivityIndicator.js +1 -0
- package/dist/abstractions/ActivityIndicator.native.js +1 -0
- package/dist/abstractions/AnimatedView.js +1 -0
- package/dist/abstractions/AnimatedView.native.js +1 -0
- package/dist/abstractions/DraggableSlideView.js +1 -0
- package/dist/abstractions/DraggableSlideView.native.js +1 -0
- package/dist/abstractions/Icon.js +1 -1
- package/dist/abstractions/Image.js +1 -0
- package/dist/abstractions/Image.native.js +1 -0
- package/dist/abstractions/Image.web.js +1 -0
- package/dist/abstractions/Platform.js +1 -0
- package/dist/abstractions/Platform.native.js +1 -0
- package/dist/abstractions/Platform.web.js +1 -0
- package/dist/abstractions/SafeAreaView.js +1 -0
- package/dist/abstractions/SafeAreaView.native.js +1 -0
- package/dist/abstractions/Table.js +1 -0
- package/dist/abstractions/Table.native.js +1 -0
- package/dist/abstractions/Text.js +1 -1
- package/dist/abstractions/TextInput.js +1 -0
- package/dist/abstractions/TextInput.native.js +1 -0
- package/dist/abstractions/TextInput.web.js +1 -0
- package/dist/abstractions/View.js +1 -1
- package/dist/abstractions/helpers/componentSize.js +1 -0
- package/dist/abstractions/helpers/componentSize.native.js +1 -0
- package/dist/abstractions/helpers/transformStyle.js +1 -0
- package/dist/abstractions/helpers/transformStyle.native.js +1 -0
- package/dist/components/actions/Breadcrumb.js +1 -0
- package/dist/components/actions/Button.js +1 -1
- package/dist/components/actions/Dropdown.js +1 -0
- package/dist/components/actions/Link.js +1 -1
- package/dist/components/actions/index.js +1 -1
- package/dist/components/actions/menu/HorizontalMenu.js +1 -0
- package/dist/components/actions/menu/Menu.js +1 -0
- package/dist/components/actions/menu/SubmenuWrapper.js +1 -0
- package/dist/components/actions/menu/VerticalMenu.js +1 -0
- package/dist/components/animations/AnimatedView.js +1 -0
- package/dist/components/animations/DraggableSlideView.js +1 -0
- package/dist/components/animations/index.js +1 -0
- package/dist/components/calendar/DayPicker.js +1 -0
- package/dist/components/calendar/_helpers/calendarDays.js +1 -0
- package/dist/components/calendar/index.js +1 -0
- package/dist/components/feedback/index.js +1 -0
- package/dist/components/feedback/notifications/Notification.js +1 -0
- package/dist/components/feedback/notifications/NotificationsHandler.js +1 -0
- package/dist/components/form/Form.js +1 -1
- package/dist/components/form/FormGroup.js +1 -1
- package/dist/components/form/FormItem.js +1 -1
- package/dist/components/form/FormList.js +1 -1
- package/dist/components/form/FormWrapperComponent.js +1 -1
- package/dist/components/form/FormWrapperComponent.native.js +1 -1
- package/dist/components/form/SubmitButton.js +1 -0
- package/dist/components/form/index.js +1 -1
- package/dist/components/form/useNewForm.js +1 -0
- package/dist/components/form/useWatch.js +1 -0
- package/dist/components/helpers/LazyRender.js +1 -0
- package/dist/components/helpers/LazyRender.native.js +1 -0
- package/dist/components/helpers/Portal.js +1 -0
- package/dist/components/helpers/PortalHandler.js +1 -0
- package/dist/components/helpers/Responsive.js +1 -1
- package/dist/components/helpers/Separator.js +1 -1
- package/dist/components/helpers/VerticalView.js +1 -0
- package/dist/components/helpers/index.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/inputs/Checkbox.js +1 -0
- package/dist/components/inputs/InputWrapper.js +1 -0
- package/dist/components/inputs/Picker.js +1 -0
- package/dist/components/inputs/Radio.js +1 -0
- package/dist/components/inputs/Switch.js +1 -0
- package/dist/components/inputs/TextInput.js +1 -0
- package/dist/components/inputs/index.js +1 -0
- package/dist/components/layout/Layout.js +1 -0
- package/dist/components/layout/LayoutContent.js +1 -0
- package/dist/components/layout/LayoutHeader.js +1 -0
- package/dist/components/layout/LayoutSider.js +1 -0
- package/dist/components/layout/index.js +1 -0
- package/dist/components/presentation/Avatar.js +1 -0
- package/dist/components/presentation/AvatarLabel.js +1 -0
- package/dist/components/presentation/Badge.js +1 -0
- package/dist/components/presentation/ContentLabel.js +1 -1
- package/dist/components/presentation/IconLabel.js +1 -1
- package/dist/components/presentation/Image.js +1 -0
- package/dist/components/presentation/LabelValue.js +1 -0
- package/dist/components/presentation/Result.js +1 -0
- package/dist/components/presentation/ResultBar.js +1 -0
- package/dist/components/presentation/Tag.js +1 -1
- package/dist/components/presentation/Tooltip.js +1 -0
- package/dist/components/presentation/index.js +1 -1
- package/dist/components/state/Loading.js +1 -0
- package/dist/components/state/LoadingView.js +1 -0
- package/dist/components/state/index.js +1 -0
- package/dist/components/structure/Accordion.js +1 -0
- package/dist/components/structure/AccordionGroup.js +1 -0
- package/dist/components/structure/Card.js +1 -1
- package/dist/components/structure/Col.js +1 -0
- package/dist/components/structure/Row.js +1 -0
- package/dist/components/structure/SafeAreaView.js +1 -0
- package/dist/components/structure/View.js +1 -1
- package/dist/components/structure/index.js +1 -1
- package/dist/components/structure/overlay/OverlayHandler.js +1 -0
- package/dist/components/structure/overlay/OverlayHandler.native.js +1 -0
- package/dist/components/structure/overlay/OverlayWrapper.js +1 -0
- package/dist/components/structure/overlay/calculatePosition.js +1 -0
- package/dist/components/structure/overlay/smartPlacement.js +1 -0
- package/dist/components/structure/popover/Popover.js +1 -0
- package/dist/components/structure/popover/Popover.native.js +1 -0
- package/dist/components/structure/popover/PopoverContent.js +1 -0
- package/dist/components/table/DataTable.js +1 -0
- package/dist/components/table/Pagination.js +1 -0
- package/dist/components/table/Table.js +1 -0
- package/dist/components/table/TableCol.js +1 -0
- package/dist/components/table/TableHeader.js +1 -0
- package/dist/components/table/TableHeaderRow.js +1 -0
- package/dist/components/table/TableRow.js +1 -0
- package/dist/components/table/index.js +1 -0
- package/dist/components/text/Text.js +1 -1
- package/dist/components/text/VerticalText.js +1 -0
- package/dist/components/text/index.js +1 -1
- package/dist/helpers/debounce.js +1 -0
- package/dist/helpers/index.js +1 -1
- package/dist/helpers/options.js +1 -0
- package/dist/helpers/random.js +1 -0
- package/dist/index.css +10 -0
- package/dist/index.js +1 -1
- package/dist/modifiers/alignConverter.js +1 -0
- package/dist/modifiers/animation.js +1 -0
- package/dist/modifiers/animations/animatedEffects.js +1 -0
- package/dist/modifiers/animations/animatedEffects.native.js +1 -0
- package/dist/modifiers/animations/animatedEffects.web.js +1 -0
- package/dist/modifiers/animations/fadeEffect.js +1 -0
- package/dist/modifiers/animations/fadeEffect.native.js +1 -0
- package/dist/modifiers/animations/slideEffect.js +1 -0
- package/dist/modifiers/animations/slideEffect.native.js +1 -0
- package/dist/modifiers/applyStyles.js +1 -0
- package/dist/modifiers/border.js +1 -1
- package/dist/modifiers/display.js +1 -1
- package/dist/modifiers/flex.js +1 -1
- package/dist/modifiers/flexWrapper.js +1 -1
- package/dist/modifiers/fullColor.js +1 -1
- package/dist/modifiers/grid.js +1 -0
- package/dist/modifiers/overflow.js +1 -0
- package/dist/modifiers/position.js +1 -1
- package/dist/modifiers/responsiveConverter.js +1 -0
- package/dist/modifiers/size.js +1 -1
- package/dist/modifiers/state.js +1 -0
- package/dist/responsive/ResponsiveHandler.js +1 -0
- package/dist/responsive/index.js +1 -0
- package/dist/responsive/responsiveHooks.js +1 -0
- package/dist/theme/ThemeHandler.js +1 -1
- package/dist/theme/default/base.js +1 -1
- package/dist/theme/default/darkTheme.js +1 -1
- package/dist/theme/default/hackerTheme.js +1 -1
- package/dist/theme/default/lightTheme.js +1 -1
- package/dist/theme/default/msdosTheme.js +1 -1
- package/dist/theme/helpers/contrastColor.js +1 -0
- package/dist/theme/helpers/dynamicColor.js +1 -0
- package/dist/theme/helpers/relatedScales.js +1 -1
- package/dist/theme/helpers/sizeScale.js +1 -1
- package/dist/theme/helpers/textScale.js +1 -1
- package/package.json +9 -4
- package/src/NekoUI.js +15 -1
- package/src/abstractions/ActivityIndicator.js +31 -0
- package/src/abstractions/ActivityIndicator.native.js +44 -0
- package/src/abstractions/AnimatedView.js +3 -0
- package/src/abstractions/AnimatedView.native.js +6 -0
- package/src/abstractions/DraggableSlideView.js +85 -0
- package/src/abstractions/DraggableSlideView.native.js +62 -0
- package/src/abstractions/Icon.js +4 -42
- package/src/abstractions/Image.js +12 -0
- package/src/abstractions/Image.native.js +7 -0
- package/src/abstractions/Image.web.js +7 -0
- package/src/abstractions/Platform.js +1 -0
- package/src/abstractions/Platform.native.js +3 -0
- package/src/abstractions/Platform.web.js +3 -0
- package/src/abstractions/SafeAreaView.js +3 -0
- package/src/abstractions/SafeAreaView.native.js +3 -0
- package/src/abstractions/Table.js +29 -0
- package/src/abstractions/Table.native.js +19 -0
- package/src/abstractions/Text.js +13 -2
- package/src/abstractions/TextInput.js +3 -0
- package/src/abstractions/TextInput.native.js +5 -0
- package/src/abstractions/TextInput.web.js +5 -0
- package/src/abstractions/View.js +2 -2
- package/src/abstractions/helpers/componentSize.js +13 -0
- package/src/abstractions/helpers/componentSize.native.js +12 -0
- package/src/abstractions/helpers/transformStyle.js +8 -0
- package/src/abstractions/helpers/transformStyle.native.js +3 -0
- package/src/components/actions/Breadcrumb.js +47 -0
- package/src/components/actions/Button.js +8 -3
- package/src/components/actions/Dropdown.js +68 -0
- package/src/components/actions/Link.js +21 -8
- package/src/components/actions/index.js +3 -0
- package/src/components/actions/menu/HorizontalMenu.js +96 -0
- package/src/components/actions/menu/Menu.js +7 -0
- package/src/components/actions/menu/SubmenuWrapper.js +16 -0
- package/src/components/actions/menu/VerticalMenu.js +107 -0
- package/src/components/animations/AnimatedView.js +45 -0
- package/src/components/animations/DraggableSlideView.js +42 -0
- package/src/components/animations/index.js +2 -0
- package/src/components/calendar/DayPicker.js +94 -0
- package/src/components/calendar/_helpers/calendarDays.js +16 -0
- package/src/components/calendar/index.js +1 -0
- package/src/components/feedback/index.js +1 -0
- package/src/components/feedback/notifications/Notification.js +37 -0
- package/src/components/feedback/notifications/NotificationsHandler.js +65 -0
- package/src/components/form/Form.js +15 -4
- package/src/components/form/FormGroup.js +4 -4
- package/src/components/form/FormItem.js +30 -8
- package/src/components/form/FormList.js +45 -9
- package/src/components/form/FormWrapperComponent.js +37 -2
- package/src/components/form/FormWrapperComponent.native.js +2 -2
- package/src/components/form/SubmitButton.js +20 -0
- package/src/components/form/index.js +3 -2
- package/src/components/form/useNewForm.js +67 -0
- package/src/components/form/useWatch.js +70 -0
- package/src/components/helpers/LazyRender.js +55 -0
- package/src/components/helpers/LazyRender.native.js +58 -0
- package/src/components/helpers/Portal.js +21 -0
- package/src/components/helpers/PortalHandler.js +32 -0
- package/src/components/helpers/Responsive.js +1 -1
- package/src/components/helpers/Separator.js +10 -14
- package/src/components/helpers/VerticalView.js +34 -0
- package/src/components/helpers/index.js +4 -0
- package/src/components/index.js +7 -0
- package/src/components/inputs/Checkbox.js +56 -0
- package/src/components/inputs/InputWrapper.js +79 -0
- package/src/components/inputs/Picker.js +116 -0
- package/src/components/inputs/Radio.js +55 -0
- package/src/components/inputs/Switch.js +60 -0
- package/src/components/inputs/TextInput.js +22 -0
- package/src/components/inputs/index.js +6 -0
- package/src/components/layout/Layout.js +40 -0
- package/src/components/layout/LayoutContent.js +42 -0
- package/src/components/layout/LayoutHeader.js +69 -0
- package/src/components/layout/LayoutSider.js +64 -0
- package/src/components/layout/index.js +4 -0
- package/src/components/presentation/Avatar.js +79 -0
- package/src/components/presentation/AvatarLabel.js +58 -0
- package/src/components/presentation/Badge.js +90 -0
- package/src/components/presentation/ContentLabel.js +24 -6
- package/src/components/presentation/IconLabel.js +12 -2
- package/src/components/presentation/Image.js +33 -0
- package/src/components/presentation/LabelValue.js +49 -0
- package/src/components/presentation/Result.js +60 -0
- package/src/components/presentation/ResultBar.js +56 -0
- package/src/components/presentation/Tag.js +8 -11
- package/src/components/presentation/Tooltip.js +43 -0
- package/src/components/presentation/index.js +8 -0
- package/src/components/state/Loading.js +20 -0
- package/src/components/state/LoadingView.js +28 -0
- package/src/components/state/index.js +2 -0
- package/src/components/structure/Accordion.js +69 -0
- package/src/components/structure/AccordionGroup.js +35 -0
- package/src/components/structure/Card.js +4 -1
- package/src/components/structure/Col.js +22 -0
- package/src/components/structure/Row.js +42 -0
- package/src/components/structure/SafeAreaView.js +42 -0
- package/src/components/structure/View.js +9 -3
- package/src/components/structure/index.js +6 -0
- package/src/components/structure/overlay/OverlayHandler.js +70 -0
- package/src/components/structure/overlay/OverlayHandler.native.js +6 -0
- package/src/components/structure/overlay/OverlayWrapper.js +52 -0
- package/src/components/structure/overlay/calculatePosition.js +29 -0
- package/src/components/structure/overlay/smartPlacement.js +32 -0
- package/src/components/structure/popover/Popover.js +69 -0
- package/src/components/structure/popover/Popover.native.js +75 -0
- package/src/components/structure/popover/PopoverContent.js +18 -0
- package/src/components/table/DataTable.js +57 -0
- package/src/components/table/Pagination.js +128 -0
- package/src/components/table/Table.js +65 -0
- package/src/components/table/TableCol.js +67 -0
- package/src/components/table/TableHeader.js +69 -0
- package/src/components/table/TableHeaderRow.js +31 -0
- package/src/components/table/TableRow.js +30 -0
- package/src/components/table/index.js +7 -0
- package/src/components/text/Text.js +4 -0
- package/src/components/text/VerticalText.js +29 -0
- package/src/components/text/index.js +1 -0
- package/src/helpers/debounce.js +9 -0
- package/src/helpers/index.js +2 -1
- package/src/helpers/options.js +65 -0
- package/src/helpers/random.js +5 -0
- package/src/index.css +10 -0
- package/src/index.js +1 -0
- package/src/modifiers/alignConverter.js +11 -0
- package/src/modifiers/animation.js +18 -0
- package/src/modifiers/animations/animatedEffects.js +63 -0
- package/src/modifiers/animations/animatedEffects.native.js +53 -0
- package/src/modifiers/animations/animatedEffects.web.js +3 -0
- package/src/modifiers/animations/fadeEffect.js +43 -0
- package/src/modifiers/animations/fadeEffect.native.js +33 -0
- package/src/modifiers/animations/slideEffect.js +61 -0
- package/src/modifiers/animations/slideEffect.native.js +53 -0
- package/src/modifiers/applyStyles.js +7 -0
- package/src/modifiers/border.js +30 -6
- package/src/modifiers/display.js +3 -5
- package/src/modifiers/flex.js +1 -1
- package/src/modifiers/flexWrapper.js +48 -7
- package/src/modifiers/fullColor.js +5 -5
- package/src/modifiers/grid.js +27 -0
- package/src/modifiers/overflow.js +23 -0
- package/src/modifiers/position.js +10 -2
- package/src/modifiers/responsiveConverter.js +19 -0
- package/src/modifiers/size.js +10 -4
- package/src/modifiers/state.js +33 -0
- package/src/responsive/ResponsiveHandler.js +28 -0
- package/src/responsive/index.js +2 -0
- package/src/responsive/responsiveHooks.js +54 -0
- package/src/theme/ThemeHandler.js +1 -1
- package/src/theme/default/base.js +22 -22
- package/src/theme/default/darkTheme.js +2 -2
- package/src/theme/default/hackerTheme.js +8 -0
- package/src/theme/default/lightTheme.js +1 -1
- package/src/theme/default/msdosTheme.js +1 -1
- package/src/theme/helpers/contrastColor.js +20 -0
- package/src/theme/helpers/dynamicColor.js +32 -0
- package/src/theme/helpers/relatedScales.js +6 -6
- package/src/theme/helpers/sizeScale.js +7 -2
- package/src/theme/helpers/textScale.js +1 -1
- package/dist/components/form/inputs/Checkbox.js +0 -1
- package/dist/components/form/inputs/Radio.js +0 -1
- package/dist/components/form/inputs/Switch.js +0 -1
- package/dist/components/form/inputs/index.js +0 -1
- package/dist/components/form/useForm.js +0 -1
- package/dist/helpers/responsive.js +0 -1
- package/src/components/form/inputs/Checkbox.js +0 -42
- package/src/components/form/inputs/Radio.js +0 -42
- package/src/components/form/inputs/Switch.js +0 -44
- package/src/components/form/inputs/index.js +0 -3
- package/src/components/form/useForm.js +0 -65
- package/src/helpers/responsive.js +0 -54
- /package/dist/abstractions/{windowWidth.js → helpers/windowWidth.js} +0 -0
- /package/dist/abstractions/{windowWidth.native.js → helpers/windowWidth.native.js} +0 -0
- /package/dist/abstractions/{windowWidth.web.js → helpers/windowWidth.web.js} +0 -0
- /package/src/abstractions/{windowWidth.js → helpers/windowWidth.js} +0 -0
- /package/src/abstractions/{windowWidth.native.js → helpers/windowWidth.native.js} +0 -0
- /package/src/abstractions/{windowWidth.web.js → helpers/windowWidth.web.js} +0 -0
|
@@ -19,16 +19,12 @@ import { useSizeModifier } from '../../modifiers/size'
|
|
|
19
19
|
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
20
20
|
|
|
21
21
|
const DEFAULT_PROPS = ([{ sizeCode }]) => {
|
|
22
|
-
const oneSizeDown = moveScale(sizeCode, -1)
|
|
23
|
-
const twoSizeDown = moveScale(sizeCode, -2)
|
|
24
|
-
const threeSizeDown = moveScale(sizeCode, -3)
|
|
25
|
-
|
|
26
22
|
return {
|
|
27
|
-
paddingH:
|
|
28
|
-
padding:
|
|
23
|
+
paddingH: moveScale(sizeCode, -2),
|
|
24
|
+
padding: moveScale(sizeCode, -4),
|
|
29
25
|
outline: true,
|
|
30
|
-
br:
|
|
31
|
-
|
|
26
|
+
br: 'xxxs',
|
|
27
|
+
border: 1,
|
|
32
28
|
center: true,
|
|
33
29
|
}
|
|
34
30
|
}
|
|
@@ -50,21 +46,22 @@ export function Tag(rootProps) {
|
|
|
50
46
|
useBorderModifier
|
|
51
47
|
)([{}, rootProps])
|
|
52
48
|
|
|
53
|
-
const { label, icon, textProps, iconProps, gap, invert, ...props } = formattedProps
|
|
49
|
+
const { loading, disabled, label, icon, textProps, iconProps, gap, invert, ...props } = formattedProps
|
|
54
50
|
|
|
55
51
|
return (
|
|
56
|
-
<View className="neko-tag" row>
|
|
52
|
+
<View className="neko-tag" row disabled={disabled}>
|
|
57
53
|
<AbsView className="neko-tag-inner" {...props}>
|
|
58
54
|
<IconLabel
|
|
59
55
|
center
|
|
60
56
|
color={fontColor}
|
|
61
|
-
size={moveScale(sizeCode, -
|
|
57
|
+
size={moveScale(sizeCode, -2)}
|
|
62
58
|
label={label}
|
|
63
59
|
icon={icon}
|
|
64
60
|
gap={gap}
|
|
65
61
|
invert={invert}
|
|
66
62
|
textProps={{ strong: true, ...textProps }}
|
|
67
63
|
iconProps={iconProps}
|
|
64
|
+
loading={loading}
|
|
68
65
|
/>
|
|
69
66
|
</AbsView>
|
|
70
67
|
</View>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { pipe } from 'ramda'
|
|
2
|
+
|
|
3
|
+
import { IconLabel } from './IconLabel'
|
|
4
|
+
import { Popover } from '../structure/popover/Popover'
|
|
5
|
+
import { useColorConverter } from '../../modifiers/colorConverter'
|
|
6
|
+
import { useFullColorModifier } from '../../modifiers/fullColor'
|
|
7
|
+
import { useSizeConverter } from '../../modifiers/sizeConverter'
|
|
8
|
+
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
9
|
+
|
|
10
|
+
export function Tooltip(rootProps) {
|
|
11
|
+
const [{ loading, fontColor, sizeCode }, formattedProps] = pipe(
|
|
12
|
+
useColorConverter('overlayBG'),
|
|
13
|
+
useSizeConverter('text', 'md'),
|
|
14
|
+
useThemeComponentModifier('Tooltip'),
|
|
15
|
+
useFullColorModifier
|
|
16
|
+
)([{}, rootProps])
|
|
17
|
+
|
|
18
|
+
const { label, icon, textProps, iconProps, gap, invert, children, ...props } = formattedProps
|
|
19
|
+
if (!label && !icon) return children
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Popover
|
|
23
|
+
className="neko-tooltip"
|
|
24
|
+
{...props}
|
|
25
|
+
content={
|
|
26
|
+
<IconLabel
|
|
27
|
+
center
|
|
28
|
+
color={fontColor}
|
|
29
|
+
size={sizeCode}
|
|
30
|
+
label={label}
|
|
31
|
+
icon={icon}
|
|
32
|
+
gap={gap}
|
|
33
|
+
invert={invert}
|
|
34
|
+
textProps={textProps}
|
|
35
|
+
iconProps={iconProps}
|
|
36
|
+
loading={loading}
|
|
37
|
+
/>
|
|
38
|
+
}
|
|
39
|
+
>
|
|
40
|
+
{children}
|
|
41
|
+
</Popover>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export * from './Tag'
|
|
2
2
|
export * from './Icon'
|
|
3
3
|
export * from './IconLabel'
|
|
4
|
+
export * from './Result'
|
|
5
|
+
export * from './ResultBar'
|
|
6
|
+
export * from './Tooltip'
|
|
7
|
+
export * from './Badge'
|
|
8
|
+
export * from './Avatar'
|
|
9
|
+
export * from './AvatarLabel'
|
|
10
|
+
export * from './Image'
|
|
11
|
+
export * from './LabelValue'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { pipe } from 'ramda'
|
|
2
|
+
|
|
3
|
+
import { AbsActivityIndicator } from '../../abstractions/ActivityIndicator'
|
|
4
|
+
import { useColorConverter } from '../../modifiers/colorConverter'
|
|
5
|
+
import { useMarginModifier } from '../../modifiers/margin'
|
|
6
|
+
import { usePaddingModifier } from '../../modifiers/padding'
|
|
7
|
+
import { useSizeConverter } from '../../modifiers/sizeConverter'
|
|
8
|
+
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
9
|
+
|
|
10
|
+
export function Loading({ ...rootProps }) {
|
|
11
|
+
const [{ color, size }, props] = pipe(
|
|
12
|
+
useColorConverter('primary'),
|
|
13
|
+
useSizeConverter('icons', 'md'),
|
|
14
|
+
useThemeComponentModifier('Loading'),
|
|
15
|
+
usePaddingModifier,
|
|
16
|
+
useMarginModifier
|
|
17
|
+
)([{}, rootProps])
|
|
18
|
+
|
|
19
|
+
return <AbsActivityIndicator className="neko-loader" size={size} color={color} {...props} />
|
|
20
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Loading } from './Loading'
|
|
2
|
+
import { View } from '../structure/View'
|
|
3
|
+
|
|
4
|
+
export function LoadingView({ active, children, size, color, replaceChildren, noWrapper, ...props }) {
|
|
5
|
+
if (!active && !!noWrapper) return children
|
|
6
|
+
if (!active) return <View {...props}>{children}</View>
|
|
7
|
+
|
|
8
|
+
const loader = <Loading size={size} color={color} />
|
|
9
|
+
if (!!replaceChildren && !!noWrapper) return loader
|
|
10
|
+
if (!!replaceChildren) {
|
|
11
|
+
return (
|
|
12
|
+
<View {...props} center>
|
|
13
|
+
{loader}
|
|
14
|
+
</View>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View className="neko-loading-view" relative {...props}>
|
|
20
|
+
{children}
|
|
21
|
+
<View className="neko-laoding-view-overlay" bg="bg_op90" absolute top={0} left={0} right={0} bottom={0} center>
|
|
22
|
+
{loader}
|
|
23
|
+
</View>
|
|
24
|
+
</View>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const LoadingWrapper = LoadingView
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { pipe } from 'ramda'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { AbsView } from '../../abstractions/View'
|
|
5
|
+
import { Card } from './Card'
|
|
6
|
+
import { Icon } from '../presentation/Icon'
|
|
7
|
+
import { Link } from '../actions/Link'
|
|
8
|
+
import { Text } from '../text/Text'
|
|
9
|
+
import { View } from './View'
|
|
10
|
+
import { moveScale } from '../../theme/helpers/sizeScale'
|
|
11
|
+
import { useDefaultModifier } from '../../modifiers/default'
|
|
12
|
+
import { useSizeConverter } from '../../modifiers/sizeConverter'
|
|
13
|
+
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
14
|
+
|
|
15
|
+
const DEFAULT_PROPS = {
|
|
16
|
+
padding: 0,
|
|
17
|
+
br: 'xl',
|
|
18
|
+
bg: 'overlayBG',
|
|
19
|
+
hiddenOverflow: true,
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function Accordion({ children, title, open, onChange, ...rootProps }) {
|
|
23
|
+
const [{ sizeCode }, formattedProps] = pipe(
|
|
24
|
+
useSizeConverter('elementHeights', 'md'),
|
|
25
|
+
useThemeComponentModifier('Accordion'),
|
|
26
|
+
useDefaultModifier(DEFAULT_PROPS)
|
|
27
|
+
)([{}, rootProps])
|
|
28
|
+
|
|
29
|
+
const { contentProps, titleProps, headerProps, initOpen, ...props } = formattedProps
|
|
30
|
+
|
|
31
|
+
const [localOpen, setLocalOpen] = React.useState(initOpen)
|
|
32
|
+
open = open === undefined ? localOpen : open
|
|
33
|
+
|
|
34
|
+
const toggle = () => {
|
|
35
|
+
setLocalOpen(!open)
|
|
36
|
+
onChange?.(!open)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Card {...props}>
|
|
41
|
+
<Link
|
|
42
|
+
padding={sizeCode}
|
|
43
|
+
row
|
|
44
|
+
gap={moveScale(sizeCode, -2)}
|
|
45
|
+
borderB={open ? props.border || true : open}
|
|
46
|
+
borderColor={props.borderColor}
|
|
47
|
+
centerV
|
|
48
|
+
{...headerProps}
|
|
49
|
+
onPress={toggle}
|
|
50
|
+
>
|
|
51
|
+
<Icon name={!!open ? 'arrow-down-s-line' : 'arrow-right-s-line'} />
|
|
52
|
+
<Text flex {...titleProps}>
|
|
53
|
+
{title}
|
|
54
|
+
</Text>
|
|
55
|
+
</Link>
|
|
56
|
+
{!!open && (
|
|
57
|
+
<View padding={sizeCode} {...contentProps}>
|
|
58
|
+
{children}
|
|
59
|
+
</View>
|
|
60
|
+
)}
|
|
61
|
+
</Card>
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<AbsView className="neko-accordion" {...props}>
|
|
66
|
+
{children}
|
|
67
|
+
</AbsView>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import { Accordion } from './Accordion'
|
|
4
|
+
import { Card } from './Card'
|
|
5
|
+
|
|
6
|
+
export function AccordionsGroup({ items, contentProps, titleProps, headerProps, initOpen, open, onChange, ...props }) {
|
|
7
|
+
const [localOpen, setLocalOpen] = React.useState(initOpen)
|
|
8
|
+
open = open === undefined ? localOpen : open
|
|
9
|
+
|
|
10
|
+
const handleChange = (key) => {
|
|
11
|
+
const v = open === key ? null : key
|
|
12
|
+
setLocalOpen(v)
|
|
13
|
+
onChange?.(v)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!items?.length) return false
|
|
17
|
+
|
|
18
|
+
const sharedProps = { contentProps, titleProps, headerProps }
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Card padding={0} {...props}>
|
|
22
|
+
{items.map(({ key, ...item }, index) => (
|
|
23
|
+
<Accordion
|
|
24
|
+
key={key || index}
|
|
25
|
+
{...sharedProps}
|
|
26
|
+
{...item}
|
|
27
|
+
br={0}
|
|
28
|
+
borderB={index < items.length - 1}
|
|
29
|
+
open={!!open && open === key}
|
|
30
|
+
onChange={() => handleChange(key)}
|
|
31
|
+
/>
|
|
32
|
+
))}
|
|
33
|
+
</Card>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
@@ -7,6 +7,7 @@ import { useDefaultModifier } from '../../modifiers/default'
|
|
|
7
7
|
import { useFlexModifier } from '../../modifiers/flex'
|
|
8
8
|
import { useFlexWrapperModifier } from '../../modifiers/flexWrapper'
|
|
9
9
|
import { useMarginModifier } from '../../modifiers/margin'
|
|
10
|
+
import { useOverflowModifier } from '../../modifiers/overflow'
|
|
10
11
|
import { usePaddingModifier } from '../../modifiers/padding'
|
|
11
12
|
import { usePositionModifier } from '../../modifiers/position'
|
|
12
13
|
import { useShadowModifier } from '../../modifiers/shadow'
|
|
@@ -15,8 +16,9 @@ import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
|
15
16
|
|
|
16
17
|
const DEFAULT_PROPS = {
|
|
17
18
|
padding: 'md', //
|
|
18
|
-
br: '
|
|
19
|
+
br: 'xl',
|
|
19
20
|
bg: 'overlayBG',
|
|
21
|
+
hiddenOverflow: true,
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export function Card({ children, ...rootProps }) {
|
|
@@ -25,6 +27,7 @@ export function Card({ children, ...rootProps }) {
|
|
|
25
27
|
useDefaultModifier(DEFAULT_PROPS),
|
|
26
28
|
useSizeModifier, //
|
|
27
29
|
usePositionModifier,
|
|
30
|
+
useOverflowModifier,
|
|
28
31
|
usePaddingModifier,
|
|
29
32
|
useMarginModifier,
|
|
30
33
|
useFlexWrapperModifier,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { pipe } from 'ramda'
|
|
2
|
+
|
|
3
|
+
import { View } from './View'
|
|
4
|
+
import { useDefaultModifier } from '../../modifiers/default'
|
|
5
|
+
import { useResponsiveConverter } from '../../modifiers/responsiveConverter'
|
|
6
|
+
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
7
|
+
|
|
8
|
+
const DEFAULT_PROPS = {}
|
|
9
|
+
|
|
10
|
+
export function Col({ children, ...rootProps }) {
|
|
11
|
+
const [_, props] = pipe(
|
|
12
|
+
useThemeComponentModifier('Col'), //
|
|
13
|
+
useResponsiveConverter([]),
|
|
14
|
+
useDefaultModifier(DEFAULT_PROPS)
|
|
15
|
+
)([{}, rootProps])
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<View className="neko-col" {...props}>
|
|
19
|
+
{children}
|
|
20
|
+
</View>
|
|
21
|
+
)
|
|
22
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { pipe } from 'ramda'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { AbsView } from '../../abstractions/View'
|
|
5
|
+
import { useFlexModifier } from '../../modifiers/flex'
|
|
6
|
+
import { useFlexWrapperModifier } from '../../modifiers/flexWrapper'
|
|
7
|
+
import { useGridModifier } from '../../modifiers/grid'
|
|
8
|
+
import { useMarginModifier } from '../../modifiers/margin'
|
|
9
|
+
import { usePositionModifier } from '../../modifiers/position'
|
|
10
|
+
import { useResponsiveConverter } from '../../modifiers/responsiveConverter'
|
|
11
|
+
import { useSizeModifier } from '../../modifiers/size'
|
|
12
|
+
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
13
|
+
|
|
14
|
+
export function Row({ children, ...rootProps }) {
|
|
15
|
+
const [{ childPaddingProps }, { colSpan, ...props }] = pipe(
|
|
16
|
+
useThemeComponentModifier('Row'),
|
|
17
|
+
useResponsiveConverter([]),
|
|
18
|
+
useGridModifier,
|
|
19
|
+
useSizeModifier, //
|
|
20
|
+
usePositionModifier,
|
|
21
|
+
useFlexWrapperModifier,
|
|
22
|
+
useFlexModifier,
|
|
23
|
+
useMarginModifier
|
|
24
|
+
)([{}, rootProps])
|
|
25
|
+
|
|
26
|
+
// Memoiza os children clonados para evitar recriação se childPaddingProps não mudar
|
|
27
|
+
const clonedChildren = React.useMemo(
|
|
28
|
+
() =>
|
|
29
|
+
React.Children.map(children, (child) =>
|
|
30
|
+
React.isValidElement(child) ? React.cloneElement(child, { parentSpan: colSpan, ...childPaddingProps }) : child
|
|
31
|
+
),
|
|
32
|
+
[children, childPaddingProps]
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<AbsView className="neko-row" {...props}>
|
|
37
|
+
{clonedChildren}
|
|
38
|
+
</AbsView>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export const Grid = Row
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { pipe } from 'ramda'
|
|
2
|
+
|
|
3
|
+
import { AbsSafeAreaView } from '../../abstractions/SafeAreaView'
|
|
4
|
+
import { useAnimationModifier } from '../../modifiers/animation'
|
|
5
|
+
import { useBackgroundModifier } from '../../modifiers/background'
|
|
6
|
+
import { useBorderModifier } from '../../modifiers/border'
|
|
7
|
+
import { useDisplayModifier } from '../../modifiers/display'
|
|
8
|
+
import { useFlexModifier } from '../../modifiers/flex'
|
|
9
|
+
import { useFlexWrapperModifier } from '../../modifiers/flexWrapper'
|
|
10
|
+
import { useMarginModifier } from '../../modifiers/margin'
|
|
11
|
+
import { useOverflowModifier } from '../../modifiers/overflow'
|
|
12
|
+
import { usePaddingModifier } from '../../modifiers/padding'
|
|
13
|
+
import { usePositionModifier } from '../../modifiers/position'
|
|
14
|
+
import { useShadowModifier } from '../../modifiers/shadow'
|
|
15
|
+
import { useSizeModifier } from '../../modifiers/size'
|
|
16
|
+
import { useStateModifier } from '../../modifiers/state'
|
|
17
|
+
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
18
|
+
|
|
19
|
+
export function SafeAreaView({ children, ...rootProps }) {
|
|
20
|
+
const [_, props] = pipe(
|
|
21
|
+
useThemeComponentModifier('SafeAreaView'),
|
|
22
|
+
useFlexWrapperModifier,
|
|
23
|
+
useDisplayModifier,
|
|
24
|
+
useAnimationModifier,
|
|
25
|
+
useStateModifier,
|
|
26
|
+
useSizeModifier,
|
|
27
|
+
usePositionModifier,
|
|
28
|
+
useOverflowModifier,
|
|
29
|
+
usePaddingModifier,
|
|
30
|
+
useMarginModifier,
|
|
31
|
+
useFlexModifier,
|
|
32
|
+
useBackgroundModifier,
|
|
33
|
+
useBorderModifier,
|
|
34
|
+
useShadowModifier
|
|
35
|
+
)([{}, rootProps])
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<AbsSafeAreaView className="neko-safe-area-view" {...props}>
|
|
39
|
+
{children}
|
|
40
|
+
</AbsSafeAreaView>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -1,27 +1,33 @@
|
|
|
1
1
|
import { pipe } from 'ramda'
|
|
2
2
|
|
|
3
3
|
import { AbsView } from '../../abstractions/View'
|
|
4
|
+
import { useAnimationModifier } from '../../modifiers/animation'
|
|
4
5
|
import { useBackgroundModifier } from '../../modifiers/background'
|
|
5
6
|
import { useBorderModifier } from '../../modifiers/border'
|
|
6
7
|
import { useDisplayModifier } from '../../modifiers/display'
|
|
7
8
|
import { useFlexModifier } from '../../modifiers/flex'
|
|
8
9
|
import { useFlexWrapperModifier } from '../../modifiers/flexWrapper'
|
|
9
10
|
import { useMarginModifier } from '../../modifiers/margin'
|
|
11
|
+
import { useOverflowModifier } from '../../modifiers/overflow'
|
|
10
12
|
import { usePaddingModifier } from '../../modifiers/padding'
|
|
11
13
|
import { usePositionModifier } from '../../modifiers/position'
|
|
12
14
|
import { useShadowModifier } from '../../modifiers/shadow'
|
|
13
15
|
import { useSizeModifier } from '../../modifiers/size'
|
|
16
|
+
import { useStateModifier } from '../../modifiers/state'
|
|
14
17
|
import { useThemeComponentModifier } from '../../modifiers/themeComponent'
|
|
15
18
|
|
|
16
19
|
export function View({ children, ...rootProps }) {
|
|
17
20
|
const [_, props] = pipe(
|
|
18
21
|
useThemeComponentModifier('View'),
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
useFlexWrapperModifier,
|
|
23
|
+
useDisplayModifier,
|
|
24
|
+
useAnimationModifier,
|
|
25
|
+
useStateModifier,
|
|
26
|
+
useSizeModifier,
|
|
21
27
|
usePositionModifier,
|
|
28
|
+
useOverflowModifier,
|
|
22
29
|
usePaddingModifier,
|
|
23
30
|
useMarginModifier,
|
|
24
|
-
useFlexWrapperModifier,
|
|
25
31
|
useFlexModifier,
|
|
26
32
|
useBackgroundModifier,
|
|
27
33
|
useBorderModifier,
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { toPairs, dissoc } from 'ramda'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
import { OverlayWrapper } from './OverlayWrapper'
|
|
5
|
+
import { Text } from '../../text/Text'
|
|
6
|
+
import { genRandonId } from '../../../helpers/random'
|
|
7
|
+
|
|
8
|
+
const OverlayContext = React.createContext(null)
|
|
9
|
+
|
|
10
|
+
export const useOverlay = () => React.useContext(OverlayContext)
|
|
11
|
+
|
|
12
|
+
export const useRegisterOverlay = (opts = {}) => {
|
|
13
|
+
const { unmountOnClose } = opts
|
|
14
|
+
const timeout = React.useRef(null)
|
|
15
|
+
const { overlays, setOverlays } = useOverlay()
|
|
16
|
+
const randomId = React.useMemo(() => genRandonId(), [])
|
|
17
|
+
const overlay = overlays[randomId] || {}
|
|
18
|
+
const mergeOverlay = (value) => setOverlays((data) => ({ ...data, [randomId]: { ...overlay, ...value } }))
|
|
19
|
+
const closeOverlay = () => mergeOverlay({ open: false })
|
|
20
|
+
const removeOverlay = () => setOverlays((data) => dissoc(randomId, data))
|
|
21
|
+
const stopDelayedClosing = () => !!timeout?.current && clearTimeout(timeout.current)
|
|
22
|
+
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
return () => removeOverlay()
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
const onOpen = ({ content, triggerRect, placement, options = {} }) => {
|
|
28
|
+
stopDelayedClosing()
|
|
29
|
+
mergeOverlay({ open: true, content, triggerRect, placement, ...options })
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const onClose = () => {
|
|
33
|
+
stopDelayedClosing()
|
|
34
|
+
timeout.current = setTimeout(() => {
|
|
35
|
+
!!unmountOnClose ? removeOverlay() : closeOverlay()
|
|
36
|
+
}, 250)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const onFastClose = () => {
|
|
40
|
+
stopDelayedClosing()
|
|
41
|
+
!!unmountOnClose ? removeOverlay() : closeOverlay()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { onOpen, onClose, onFastClose, stopDelayedClosing }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function OverlayHandler({ children }) {
|
|
48
|
+
const [overlays, setOverlays] = React.useState({})
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<OverlayContext.Provider value={{ overlays, setOverlays }}>
|
|
52
|
+
{children}
|
|
53
|
+
|
|
54
|
+
{toPairs(overlays).map(([key, overlay]) => {
|
|
55
|
+
const handleClickOutside = () => setTimeout(() => setOverlays((data) => dissoc(key, data)), 100)
|
|
56
|
+
return (
|
|
57
|
+
<OverlayWrapper
|
|
58
|
+
key={key}
|
|
59
|
+
triggerRect={overlay.triggerRect}
|
|
60
|
+
placement={overlay.placement}
|
|
61
|
+
onClickOutside={overlay.dismissOnClickOutside ? handleClickOutside : null}
|
|
62
|
+
display={!overlay.open && 'none'}
|
|
63
|
+
>
|
|
64
|
+
{overlay.content}
|
|
65
|
+
</OverlayWrapper>
|
|
66
|
+
)
|
|
67
|
+
})}
|
|
68
|
+
</OverlayContext.Provider>
|
|
69
|
+
)
|
|
70
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { View } from '../View'
|
|
3
|
+
import { calculatePosition } from './calculatePosition'
|
|
4
|
+
import { smartPlacement } from './smartPlacement' // você cria esse helper
|
|
5
|
+
|
|
6
|
+
export function OverlayWrapper({ children, triggerRect, placement, onClickOutside, ...props }) {
|
|
7
|
+
const overlayRef = React.useRef(null)
|
|
8
|
+
const [pos, setPos] = React.useState({ x: -9999, y: -9999 })
|
|
9
|
+
|
|
10
|
+
React.useLayoutEffect(() => {
|
|
11
|
+
if (overlayRef.current && triggerRect) {
|
|
12
|
+
const rect = overlayRef.current.getBoundingClientRect()
|
|
13
|
+
const popoverRect = { width: rect.width, height: rect.height }
|
|
14
|
+
|
|
15
|
+
const safePlacement = smartPlacement(triggerRect, popoverRect, placement)
|
|
16
|
+
setPos(calculatePosition(triggerRect, popoverRect, safePlacement))
|
|
17
|
+
}
|
|
18
|
+
}, [triggerRect, placement, children])
|
|
19
|
+
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
if (onClickOutside) {
|
|
22
|
+
const handleClickOutside = (event) => {
|
|
23
|
+
if (overlayRef.current && !overlayRef.current.contains(event.target)) {
|
|
24
|
+
onClickOutside()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
document.addEventListener('mousedown', handleClickOutside, true)
|
|
29
|
+
}, 10)
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
clearTimeout(timer)
|
|
33
|
+
document.removeEventListener('mousedown', handleClickOutside, true)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [onClickOutside])
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<View
|
|
40
|
+
ref={overlayRef}
|
|
41
|
+
className="neko-overlay-wrapper"
|
|
42
|
+
absolute
|
|
43
|
+
top={pos.y}
|
|
44
|
+
left={pos.x}
|
|
45
|
+
zIndex={9999}
|
|
46
|
+
pointerEvents="none"
|
|
47
|
+
{...props}
|
|
48
|
+
>
|
|
49
|
+
{children}
|
|
50
|
+
</View>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function calculatePosition(triggerRect, popoverRect, placement, gap = 2) {
|
|
2
|
+
const { left, right, top, bottom, width, height } = triggerRect
|
|
3
|
+
const pw = popoverRect?.width || 0
|
|
4
|
+
const ph = popoverRect?.height || 0
|
|
5
|
+
|
|
6
|
+
const positions = {
|
|
7
|
+
// Top
|
|
8
|
+
top: { x: left + width / 2 - pw / 2, y: top - ph - gap },
|
|
9
|
+
topLeft: { x: left, y: top - ph - gap },
|
|
10
|
+
topRight: { x: right - pw, y: top - ph - gap },
|
|
11
|
+
|
|
12
|
+
// Bottom
|
|
13
|
+
bottom: { x: left + width / 2 - pw / 2, y: bottom + gap },
|
|
14
|
+
bottomLeft: { x: left, y: bottom + gap },
|
|
15
|
+
bottomRight: { x: right - pw, y: bottom + gap },
|
|
16
|
+
|
|
17
|
+
// Left
|
|
18
|
+
left: { x: left - pw - gap, y: top + height / 2 - ph / 2 },
|
|
19
|
+
leftTop: { x: left - pw - gap, y: top },
|
|
20
|
+
leftBottom: { x: left - pw - gap, y: bottom - ph },
|
|
21
|
+
|
|
22
|
+
// Right
|
|
23
|
+
right: { x: right + gap, y: top + height / 2 - ph / 2 },
|
|
24
|
+
rightTop: { x: right + gap, y: top },
|
|
25
|
+
rightBottom: { x: right + gap, y: bottom - ph },
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return positions[placement] || positions.bottom
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export function smartPlacement(triggerRect, popoverRect, placement) {
|
|
2
|
+
const scrollX = window.scrollX || window.pageXOffset
|
|
3
|
+
const scrollY = window.scrollY || window.pageYOffset
|
|
4
|
+
const screenWidth = window.innerWidth
|
|
5
|
+
const screenHeight = window.innerHeight
|
|
6
|
+
|
|
7
|
+
const viewportRect = {
|
|
8
|
+
left: triggerRect.left - scrollX,
|
|
9
|
+
right: triggerRect.right - scrollX,
|
|
10
|
+
top: triggerRect.top - scrollY,
|
|
11
|
+
bottom: triggerRect.bottom - scrollY,
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const fitsRight = viewportRect.right + popoverRect.width <= screenWidth
|
|
15
|
+
const fitsLeft = viewportRect.left - popoverRect.width >= 0
|
|
16
|
+
const fitsBottom = viewportRect.bottom + popoverRect.height <= screenHeight
|
|
17
|
+
const fitsTop = viewportRect.top - popoverRect.height >= 0
|
|
18
|
+
|
|
19
|
+
if (placement.startsWith('right') && !fitsRight && fitsLeft) return placement.replace('right', 'left')
|
|
20
|
+
if (placement.endsWith('Right') && !fitsLeft && fitsRight) return placement.replace('Right', 'Left')
|
|
21
|
+
|
|
22
|
+
if (placement.startsWith('left') && !fitsLeft && fitsRight) return placement.replace('left', 'right')
|
|
23
|
+
if (placement.endsWith('Left') && !fitsRight && fitsLeft) return placement.replace('Left', 'Right')
|
|
24
|
+
|
|
25
|
+
if (placement.startsWith('bottom') && !fitsBottom && fitsTop) return placement.replace('bottom', 'top')
|
|
26
|
+
if (placement.endsWith('Bottom') && !fitsTop && fitsBottom) return placement.replace('Bottom', 'Top')
|
|
27
|
+
|
|
28
|
+
if (placement.startsWith('top') && !fitsTop && fitsBottom) return placement.replace('top', 'bottom')
|
|
29
|
+
if (placement.endsWith('Top') && !fitsBottom && fitsTop) return placement.replace('Top', 'Bottom')
|
|
30
|
+
|
|
31
|
+
return placement
|
|
32
|
+
}
|