@tcn/ui 0.1.1 → 0.3.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 +38 -3
- package/dist/divider.module-FptFV0PX.js +5 -0
- package/dist/divider.module-FptFV0PX.js.map +1 -0
- package/dist/draggable.css +1 -0
- package/dist/feedback/progress/progress_bar.js +1 -1
- package/dist/form/field/common/field_description.js +1 -1
- package/dist/form/field/common/field_error.js +1 -1
- package/dist/form/field/common/field_label.js +1 -1
- package/dist/form/field/field.js +1 -1
- package/dist/frame.css +1 -0
- package/dist/inputs/color_input/color_input.js +1 -1
- package/dist/inputs/color_input/color_input.js.map +1 -1
- package/dist/inputs/color_input/color_picker.js +1 -1
- package/dist/inputs/combo_box/combo_box.js +1 -1
- package/dist/inputs/date_picker/date_picker.js +1 -1
- package/dist/inputs/date_picker/date_picker_date.js +1 -1
- package/dist/inputs/date_picker/date_picker_day.js +1 -1
- package/dist/inputs/date_picker/date_picker_input.js +2 -2
- package/dist/inputs/date_picker/date_picker_input.js.map +1 -1
- package/dist/inputs/date_picker/date_picker_time_selector.js +1 -1
- package/dist/inputs/date_picker/date_picker_year_input.js +1 -1
- package/dist/inputs/date_picker/date_picker_year_input.js.map +1 -1
- package/dist/inputs/date_picker/date_picker_year_selector.js +2 -2
- package/dist/inputs/mask_input/key_capture_input.js +1 -1
- package/dist/inputs/mask_input/mask_input.js +1 -1
- package/dist/inputs/multiselect/multiselect.js +1 -1
- package/dist/inputs/phone_number_input/phone_number_input.d.ts +2 -0
- package/dist/inputs/phone_number_input/phone_number_input.d.ts.map +1 -1
- package/dist/inputs/phone_number_input/phone_number_input.js +160 -154
- package/dist/inputs/phone_number_input/phone_number_input.js.map +1 -1
- package/dist/inputs/select/select.js +1 -1
- package/dist/inputs/slider/slider.js +1 -1
- package/dist/inputs/suggestions/suggestion_list.js +3 -3
- package/dist/inputs/suggestions/suggestion_list.js.map +1 -1
- package/dist/inputs/switch/switch.js +1 -1
- package/dist/inputs/textarea/textarea.d.ts +2 -2
- package/dist/inputs/textarea/textarea.d.ts.map +1 -1
- package/dist/inputs/textarea/textarea.js.map +1 -1
- package/dist/inputs/unit_input/unit_input.js +1 -1
- package/dist/layouts/divider/divider.js +24 -23
- package/dist/layouts/divider/divider.js.map +1 -1
- package/dist/layouts/header/header.d.ts.map +1 -1
- package/dist/layouts/header/header.js.map +1 -1
- package/dist/layouts/index.d.ts +6 -5
- package/dist/layouts/index.d.ts.map +1 -1
- package/dist/layouts/index.js +28 -26
- package/dist/layouts/index.js.map +1 -1
- package/dist/layouts/scaffold/scaffold.d.ts +9 -0
- package/dist/layouts/scaffold/scaffold.d.ts.map +1 -0
- package/dist/layouts/scaffold/scaffold.js +55 -0
- package/dist/layouts/scaffold/scaffold.js.map +1 -0
- package/dist/modal.css +1 -1
- package/dist/overlay/frame/frame.d.ts +11 -0
- package/dist/overlay/frame/frame.d.ts.map +1 -0
- package/dist/overlay/frame/frame.js +35 -0
- package/dist/overlay/frame/frame.js.map +1 -0
- package/dist/overlay/index.d.ts +10 -2
- package/dist/overlay/index.d.ts.map +1 -1
- package/dist/overlay/index.js +22 -8
- package/dist/overlay/index.js.map +1 -1
- package/dist/overlay/menu/menu.d.ts +1 -1
- package/dist/overlay/menu/menu.d.ts.map +1 -1
- package/dist/overlay/menu/menu.js +2 -2
- package/dist/overlay/menu/menu.js.map +1 -1
- package/dist/overlay/popper/base/base_popper.d.ts +11 -0
- package/dist/overlay/popper/base/base_popper.d.ts.map +1 -0
- package/dist/overlay/popper/base/base_popper.js +27 -0
- package/dist/overlay/popper/base/base_popper.js.map +1 -0
- package/dist/overlay/popper/base/dismissal_decorator.d.ts +16 -0
- package/dist/overlay/popper/base/dismissal_decorator.d.ts.map +1 -0
- package/dist/overlay/popper/base/dismissal_decorator.js +69 -0
- package/dist/overlay/popper/base/dismissal_decorator.js.map +1 -0
- package/dist/overlay/popper/context_popper.d.ts +11 -0
- package/dist/overlay/popper/context_popper.d.ts.map +1 -0
- package/dist/overlay/popper/context_popper.js +33 -0
- package/dist/overlay/popper/context_popper.js.map +1 -0
- package/dist/overlay/popper/element_popper.d.ts +7 -0
- package/dist/overlay/popper/element_popper.d.ts.map +1 -0
- package/dist/overlay/popper/element_popper.js +33 -0
- package/dist/overlay/popper/element_popper.js.map +1 -0
- package/dist/overlay/popper/hooks/use_context_trigger.d.ts +7 -0
- package/dist/overlay/popper/hooks/use_context_trigger.d.ts.map +1 -0
- package/dist/overlay/popper/hooks/use_context_trigger.js +31 -0
- package/dist/overlay/popper/hooks/use_context_trigger.js.map +1 -0
- package/dist/overlay/popper/hooks/use_hover_trigger.d.ts +6 -0
- package/dist/overlay/popper/hooks/use_hover_trigger.d.ts.map +1 -0
- package/dist/overlay/popper/hooks/use_hover_trigger.js +17 -0
- package/dist/overlay/popper/hooks/use_hover_trigger.js.map +1 -0
- package/dist/overlay/popper/hooks/use_restore_focus.d.ts +2 -0
- package/dist/overlay/popper/hooks/use_restore_focus.d.ts.map +1 -0
- package/dist/overlay/popper/hooks/use_restore_focus.js +18 -0
- package/dist/overlay/popper/hooks/use_restore_focus.js.map +1 -0
- package/dist/overlay/popper/legacy/popper.d.ts.map +1 -0
- package/dist/overlay/popper/{popper.js → legacy/popper.js} +6 -6
- package/dist/overlay/popper/legacy/popper.js.map +1 -0
- package/dist/overlay/popper/preview_popper.d.ts +7 -0
- package/dist/overlay/popper/preview_popper.d.ts.map +1 -0
- package/dist/overlay/popper/preview_popper.js +46 -0
- package/dist/overlay/popper/preview_popper.js.map +1 -0
- package/dist/overlay/tethered/element_tethered.d.ts +8 -0
- package/dist/overlay/tethered/element_tethered.d.ts.map +1 -0
- package/dist/overlay/tethered/element_tethered.js +33 -0
- package/dist/overlay/tethered/element_tethered.js.map +1 -0
- package/dist/overlay/tethered/hooks/calculate_position.d.ts +19 -0
- package/dist/overlay/tethered/hooks/calculate_position.d.ts.map +1 -0
- package/dist/overlay/tethered/hooks/calculate_position.js +43 -0
- package/dist/overlay/tethered/hooks/calculate_position.js.map +1 -0
- package/dist/overlay/tethered/hooks/useTether.d.ts +19 -0
- package/dist/overlay/tethered/hooks/useTether.d.ts.map +1 -0
- package/dist/overlay/tethered/hooks/useTether.js +61 -0
- package/dist/overlay/tethered/hooks/useTether.js.map +1 -0
- package/dist/overlay/tethered/tethered.d.ts +20 -0
- package/dist/overlay/tethered/tethered.d.ts.map +1 -0
- package/dist/overlay/tethered/tethered.js +59 -0
- package/dist/overlay/tethered/tethered.js.map +1 -0
- package/dist/overlay/tethered/types.d.ts +3 -0
- package/dist/overlay/tethered/types.d.ts.map +1 -0
- package/dist/overlay/tethered/types.js +2 -0
- package/dist/overlay/tethered/types.js.map +1 -0
- package/dist/popper.css +1 -1
- package/dist/scaffold.css +1 -0
- package/dist/stacks/box/box.d.ts +1 -1
- package/dist/stacks/box/box.d.ts.map +1 -1
- package/dist/stacks/box/box.js +1 -1
- package/dist/stacks/box/box.js.map +1 -1
- package/dist/stacks/h_collapsible_box.js +1 -1
- package/dist/stacks/v_collapsible_box.js +1 -1
- package/dist/surfaces/card/card.d.ts +2 -2
- package/dist/surfaces/card/card.d.ts.map +1 -1
- package/dist/surfaces/card/card.js +7 -7
- package/dist/surfaces/card/card.js.map +1 -1
- package/dist/surfaces/index.d.ts +4 -2
- package/dist/surfaces/index.d.ts.map +1 -1
- package/dist/surfaces/index.js +26 -22
- package/dist/surfaces/index.js.map +1 -1
- package/dist/surfaces/modal/modal.d.ts +4 -3
- package/dist/surfaces/modal/modal.d.ts.map +1 -1
- package/dist/surfaces/modal/modal.js +12 -11
- package/dist/surfaces/modal/modal.js.map +1 -1
- package/dist/surfaces/panel/h_panel.js +23 -24
- package/dist/surfaces/panel/h_panel.js.map +1 -1
- package/dist/surfaces/panel/v_panel.d.ts +3 -7
- package/dist/surfaces/panel/v_panel.d.ts.map +1 -1
- package/dist/surfaces/panel/v_panel.js +12 -54
- package/dist/surfaces/panel/v_panel.js.map +1 -1
- package/dist/surfaces/pop_confirm/pop_confirm.d.ts +5 -0
- package/dist/surfaces/pop_confirm/pop_confirm.d.ts.map +1 -0
- package/dist/surfaces/pop_confirm/pop_confirm.js +37 -0
- package/dist/surfaces/pop_confirm/pop_confirm.js.map +1 -0
- package/dist/surfaces/popconfirm/pop_confirm.d.ts +5 -0
- package/dist/surfaces/popconfirm/pop_confirm.d.ts.map +1 -0
- package/dist/surfaces/popconfirm/pop_confirm.js +13 -0
- package/dist/surfaces/popconfirm/pop_confirm.js.map +1 -0
- package/dist/surfaces/popover/popover.d.ts +1 -1
- package/dist/surfaces/popover/popover.d.ts.map +1 -1
- package/dist/surfaces/popover/popover.js +1 -1
- package/dist/surfaces/popover/popover.js.map +1 -1
- package/dist/surfaces/tooltip/tooltip.d.ts +10 -0
- package/dist/surfaces/tooltip/tooltip.d.ts.map +1 -0
- package/dist/surfaces/tooltip/tooltip.js +38 -0
- package/dist/surfaces/tooltip/tooltip.js.map +1 -0
- package/dist/surfaces/window/window.d.ts +4 -3
- package/dist/surfaces/window/window.d.ts.map +1 -1
- package/dist/surfaces/window/window.js +18 -6
- package/dist/surfaces/window/window.js.map +1 -1
- package/dist/tethered.css +1 -0
- package/dist/themes/themes/ergo/ergo_theme.js +166 -158
- package/dist/themes/themes/ergo/ergo_theme.js.map +1 -1
- package/dist/tooltip.css +1 -1
- package/dist/typography/title/title.d.ts +2 -1
- package/dist/typography/title/title.d.ts.map +1 -1
- package/dist/typography/title/title.js +23 -22
- package/dist/typography/title/title.js.map +1 -1
- package/dist/utility_bar.css +1 -1
- package/dist/utils/click_away_listener.d.ts +1 -0
- package/dist/utils/click_away_listener.d.ts.map +1 -1
- package/dist/utils/click_away_listener.js +2 -1
- package/dist/utils/click_away_listener.js.map +1 -1
- package/dist/utils/dnd/context.d.ts +4 -0
- package/dist/utils/dnd/context.d.ts.map +1 -0
- package/dist/utils/dnd/context.js +20 -0
- package/dist/utils/dnd/context.js.map +1 -0
- package/dist/utils/dnd/draggable/draggable.d.ts +7 -0
- package/dist/utils/dnd/draggable/draggable.d.ts.map +1 -0
- package/dist/utils/dnd/draggable/draggable.js +27 -0
- package/dist/utils/dnd/draggable/draggable.js.map +1 -0
- package/dist/utils/dnd/handle.d.ts +6 -0
- package/dist/utils/dnd/handle.d.ts.map +1 -0
- package/dist/utils/dnd/handle.js +22 -0
- package/dist/utils/dnd/handle.js.map +1 -0
- package/dist/utils/dnd/hooks/use_drag_container.d.ts +7 -0
- package/dist/utils/dnd/hooks/use_drag_container.d.ts.map +1 -0
- package/dist/utils/dnd/hooks/use_drag_container.js +30 -0
- package/dist/utils/dnd/hooks/use_drag_container.js.map +1 -0
- package/dist/utils/{hooks → dnd/hooks}/use_draggable.d.ts +3 -3
- package/dist/utils/dnd/hooks/use_draggable.d.ts.map +1 -0
- package/dist/utils/dnd/hooks/use_draggable.js +41 -0
- package/dist/utils/dnd/hooks/use_draggable.js.map +1 -0
- package/dist/utils/dnd/types.d.ts +10 -0
- package/dist/utils/dnd/types.d.ts.map +1 -0
- package/dist/utils/dnd/types.js +2 -0
- package/dist/utils/dnd/types.js.map +1 -0
- package/dist/utils/index.d.ts +6 -5
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +26 -23
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/mouse_leave_region.d.ts +8 -0
- package/dist/utils/mouse_leave_region.d.ts.map +1 -0
- package/dist/utils/mouse_leave_region.js +26 -0
- package/dist/utils/mouse_leave_region.js.map +1 -0
- package/dist/utils/types/dimensions.d.ts +11 -1
- package/dist/utils/types/dimensions.d.ts.map +1 -1
- package/package.json +9 -3
- package/src/inputs/color_input/color_input.tsx +1 -1
- package/src/inputs/date_picker/date_picker_input.tsx +1 -1
- package/src/inputs/date_picker/date_picker_year_input.tsx +1 -1
- package/src/inputs/phone_number_input/phone_number_input.tsx +8 -0
- package/src/inputs/suggestions/suggestion_list.tsx +1 -1
- package/src/inputs/textarea/textarea.tsx +2 -2
- package/src/layouts/header/header.tsx +0 -1
- package/src/layouts/index.ts +7 -5
- package/src/layouts/scaffold/scaffold.module.css +5 -0
- package/src/layouts/scaffold/scaffold.tsx +60 -0
- package/src/layouts/utility_bar/utility_bar.module.css +0 -3
- package/src/overlay/frame/frame.module.css +5 -0
- package/src/overlay/frame/frame.stories.tsx +40 -0
- package/src/overlay/frame/frame.tsx +50 -0
- package/src/overlay/frame/frame_stories.module.css +14 -0
- package/src/overlay/index.ts +30 -2
- package/src/overlay/menu/menu.tsx +1 -1
- package/src/overlay/popper/__stories__/base_args.ts +75 -0
- package/src/overlay/popper/__stories__/context_popper.stories.tsx +77 -0
- package/src/overlay/popper/__stories__/element_popper.stories.tsx +80 -0
- package/src/overlay/popper/__stories__/preview_popper.stories.tsx +73 -0
- package/src/overlay/popper/base/base_popper.tsx +55 -0
- package/src/overlay/popper/base/dismissal_decorator.tsx +80 -0
- package/src/overlay/popper/context_popper.tsx +43 -0
- package/src/overlay/popper/element_popper.tsx +42 -0
- package/src/overlay/popper/hooks/use_context_trigger.ts +50 -0
- package/src/overlay/popper/hooks/use_hover_trigger.ts +24 -0
- package/src/overlay/popper/hooks/use_restore_focus.ts +16 -0
- package/src/overlay/popper/{popper.stories.tsx → legacy/popper.stories.tsx} +11 -5
- package/src/overlay/popper/{popper.tsx → legacy/popper.tsx} +3 -2
- package/src/overlay/popper/preview_popper.tsx +54 -0
- package/src/overlay/tethered/__stories__/element/element_tethered.stories.tsx +57 -0
- package/src/overlay/tethered/__stories__/element/element_tethered_stories.module.css +14 -0
- package/src/overlay/tethered/__stories__/shared/base_story_config.ts +52 -0
- package/src/overlay/tethered/__stories__/shared/components/sb_point.module.css +20 -0
- package/src/overlay/tethered/__stories__/shared/components/sb_point.tsx +34 -0
- package/src/overlay/tethered/__stories__/shared/components/sb_reference_points.tsx +54 -0
- package/src/overlay/tethered/__stories__/tethered/tethered.stories.tsx +90 -0
- package/src/overlay/tethered/__stories__/tethered/tethered_stories.module.css +25 -0
- package/src/overlay/tethered/element_tethered.tsx +62 -0
- package/src/overlay/tethered/hooks/calculate_position.ts +110 -0
- package/src/overlay/tethered/hooks/useTether.ts +85 -0
- package/src/overlay/tethered/tethered.module.css +8 -0
- package/src/overlay/tethered/tethered.tsx +72 -0
- package/src/overlay/tethered/types.ts +2 -0
- package/src/stacks/box/box.tsx +8 -2
- package/src/stacks/h_stack.stories.tsx +2 -2
- package/src/stacks/v_stack.stories.tsx +2 -2
- package/src/surfaces/card/card.stories.tsx +64 -0
- package/src/surfaces/card/card.tsx +4 -4
- package/src/surfaces/card/card_stories.module.css +13 -0
- package/src/surfaces/index.ts +4 -2
- package/src/surfaces/modal/__stories__/modal.stories.tsx +31 -28
- package/src/surfaces/modal/modal.module.css +2 -2
- package/src/surfaces/modal/modal.tsx +16 -11
- package/src/surfaces/panel/__stories__/panel.stories.tsx +1 -1
- package/src/surfaces/panel/v_panel.tsx +8 -53
- package/src/surfaces/pop_confirm/pop_confirm.stories.tsx +70 -0
- package/src/surfaces/pop_confirm/pop_confirm.tsx +30 -0
- package/src/surfaces/popconfirm/pop_confirm.tsx +18 -0
- package/src/surfaces/popover/popover.tsx +1 -1
- package/src/surfaces/tooltip/tooltip.stories.tsx +54 -0
- package/src/surfaces/tooltip/tooltip.tsx +59 -0
- package/src/surfaces/window/window.stories.tsx +51 -4
- package/src/surfaces/window/window.tsx +19 -7
- package/src/themes/themes/ergo/__stories__/components/tone_picker/sb_tone_picker.tsx +7 -9
- package/src/themes/themes/ergo/__stories__/material.stories.tsx +2 -6
- package/src/themes/themes/ergo/__stories__/sb_materials.module.css +29 -21
- package/src/themes/themes/ergo/ergo_theme.css +166 -158
- package/src/typography/title/title.tsx +22 -18
- package/src/utils/click_away_listener.tsx +1 -1
- package/src/utils/dnd/__stories__/draggable.stories.tsx +48 -0
- package/src/utils/dnd/__stories__/draggable_stories.module.css +21 -0
- package/src/utils/{__stories__ → dnd/__stories__}/use_draggable.stories.tsx +15 -10
- package/src/utils/dnd/context.ts +24 -0
- package/src/utils/dnd/draggable/draggable.module.css +8 -0
- package/src/utils/dnd/draggable/draggable.tsx +42 -0
- package/src/utils/dnd/handle.tsx +32 -0
- package/src/utils/dnd/hooks/use_drag_container.ts +42 -0
- package/src/utils/{hooks → dnd/hooks}/use_draggable.ts +23 -17
- package/src/utils/dnd/types.ts +6 -0
- package/src/utils/index.ts +7 -5
- package/src/utils/mouse_leave_region.tsx +38 -0
- package/src/utils/types/dimensions.ts +13 -1
- package/tsconfig.json +3 -0
- package/dist/overlay/popper/popper.d.ts.map +0 -1
- package/dist/overlay/popper/popper.js.map +0 -1
- package/dist/overlay/tooltip/tooltip.d.ts +0 -7
- package/dist/overlay/tooltip/tooltip.d.ts.map +0 -1
- package/dist/overlay/tooltip/tooltip.js +0 -20
- package/dist/overlay/tooltip/tooltip.js.map +0 -1
- package/dist/panel.module-DwGKncon.js +0 -5
- package/dist/panel.module-DwGKncon.js.map +0 -1
- package/dist/title.module-B16de2jd.js +0 -5
- package/dist/title.module-B16de2jd.js.map +0 -1
- package/dist/utils/hooks/use_draggable.d.ts.map +0 -1
- package/dist/utils/hooks/use_draggable.js +0 -30
- package/dist/utils/hooks/use_draggable.js.map +0 -1
- package/src/overlay/tooltip/tooltip.stories.tsx +0 -22
- package/src/overlay/tooltip/tooltip.tsx +0 -24
- /package/dist/{panel.css → h_panel.css} +0 -0
- /package/dist/overlay/popper/{popper.d.ts → legacy/popper.d.ts} +0 -0
- /package/src/overlay/popper/{popper.module.css → legacy/popper.module.css} +0 -0
- /package/src/{overlay → surfaces}/tooltip/tooltip.module.css +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useState, useRef } from 'react';
|
|
2
2
|
import { useDraggable } from '../hooks/use_draggable';
|
|
3
|
-
import { Box } from '
|
|
3
|
+
import { Box } from '../../../stacks/box/box.js';
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
|
-
title: '
|
|
6
|
+
title: 'Utils/useDraggable',
|
|
7
7
|
component: <></>,
|
|
8
8
|
args: {
|
|
9
9
|
startX: 200,
|
|
@@ -16,8 +16,9 @@ export const BasicDraggable = {
|
|
|
16
16
|
const [position, setPosition] = useState({ x: args.startX, y: args.startY });
|
|
17
17
|
const [isDragging, setIsDragging] = useState(false);
|
|
18
18
|
const elementStartPosition = useRef({ x: args.startX, y: args.startY });
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const dragRef = useRef<HTMLDivElement>(null);
|
|
20
|
+
useDraggable({
|
|
21
|
+
handles: dragRef,
|
|
21
22
|
startDragCallback: () => {
|
|
22
23
|
setIsDragging(true);
|
|
23
24
|
elementStartPosition.current = { x: position.x, y: position.y };
|
|
@@ -76,8 +77,10 @@ export const MultipleDraggables = {
|
|
|
76
77
|
|
|
77
78
|
const createDragHandlers = (
|
|
78
79
|
id: number,
|
|
79
|
-
elementStartPosition: React.RefObject<{ x: number; y: number }
|
|
80
|
+
elementStartPosition: React.RefObject<{ x: number; y: number }>,
|
|
81
|
+
handleRef: React.RefObject<HTMLDivElement>
|
|
80
82
|
) => ({
|
|
83
|
+
handles: handleRef,
|
|
81
84
|
startDragCallback: () => {
|
|
82
85
|
const box = boxes.find(b => b.id === id);
|
|
83
86
|
if (box && elementStartPosition.current) {
|
|
@@ -120,11 +123,12 @@ export const MultipleDraggables = {
|
|
|
120
123
|
</p>
|
|
121
124
|
{boxes.map(box => {
|
|
122
125
|
const elementStartPosition = useRef({ x: box.x, y: box.y });
|
|
123
|
-
const
|
|
126
|
+
const handleRef = useRef<HTMLDivElement>(null);
|
|
127
|
+
useDraggable(createDragHandlers(box.id, elementStartPosition, handleRef));
|
|
124
128
|
return (
|
|
125
129
|
<Box
|
|
126
130
|
key={box.id}
|
|
127
|
-
ref={
|
|
131
|
+
ref={handleRef}
|
|
128
132
|
style={{
|
|
129
133
|
width: '90px',
|
|
130
134
|
height: '100px',
|
|
@@ -155,8 +159,9 @@ export const CustomDragHandle = {
|
|
|
155
159
|
const [position, setPosition] = useState({ x: args.startX, y: args.startY });
|
|
156
160
|
const [isDragging, setIsDragging] = useState(false);
|
|
157
161
|
const elementStartPosition = useRef({ x: args.startX, y: args.startY });
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
const handleRef = useRef<HTMLDivElement>(null);
|
|
163
|
+
useDraggable({
|
|
164
|
+
handles: handleRef,
|
|
160
165
|
startDragCallback: () => {
|
|
161
166
|
setIsDragging(true);
|
|
162
167
|
elementStartPosition.current = { x: position.x, y: position.y };
|
|
@@ -189,7 +194,7 @@ export const CustomDragHandle = {
|
|
|
189
194
|
}}
|
|
190
195
|
>
|
|
191
196
|
<Box
|
|
192
|
-
ref={
|
|
197
|
+
ref={handleRef}
|
|
193
198
|
style={{
|
|
194
199
|
height: '30px',
|
|
195
200
|
backgroundColor: '#2196F3',
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
import type { DragContainer } from './types.js';
|
|
3
|
+
|
|
4
|
+
const defaultValue: DragContainer = {
|
|
5
|
+
registerHandle: () => {},
|
|
6
|
+
unregisterHandle: () => {},
|
|
7
|
+
isDragging: false,
|
|
8
|
+
position: { x: 0, y: 0 },
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const DragContainerContext = createContext<DragContainer>(defaultValue);
|
|
12
|
+
|
|
13
|
+
export function useDragContainer(): DragContainer {
|
|
14
|
+
const context = useContext(DragContainerContext);
|
|
15
|
+
|
|
16
|
+
if (context === defaultValue) {
|
|
17
|
+
// biome-ignore lint/suspicious/noConsole: Let devs know if they're not using the context correctly
|
|
18
|
+
console.warn(
|
|
19
|
+
'useDragContainer: No DragContainerContext found. Handles may will not register or trigger drag events.'
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, { useMemo, type CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
import { DragContainerContext } from '../context.js';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import { useMakeDragContainer } from '../hooks/use_drag_container.js';
|
|
6
|
+
|
|
7
|
+
import styles from './draggable.module.css';
|
|
8
|
+
|
|
9
|
+
export interface DraggableProps {
|
|
10
|
+
children: React.ReactElement;
|
|
11
|
+
draggable?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Draggable: React.FC<DraggableProps> = ({
|
|
15
|
+
children,
|
|
16
|
+
draggable: isDraggable = true,
|
|
17
|
+
}) => {
|
|
18
|
+
const context = useMakeDragContainer({});
|
|
19
|
+
|
|
20
|
+
const cssVariables = useMemo(
|
|
21
|
+
() =>
|
|
22
|
+
({
|
|
23
|
+
'--position-x': `${context.position.x}px`,
|
|
24
|
+
'--position-y': `${context.position.y}px`,
|
|
25
|
+
}) as CSSProperties,
|
|
26
|
+
|
|
27
|
+
[context.position]
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const clonedChildren = React.cloneElement(children, {
|
|
31
|
+
className: clsx('tcn-draggable', styles.draggable, children.props.className),
|
|
32
|
+
style: { ...cssVariables, ...children.props.style },
|
|
33
|
+
'data-is-dragging': context.isDragging,
|
|
34
|
+
'data-is-draggable': isDraggable,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<DragContainerContext.Provider value={context}>
|
|
39
|
+
{clonedChildren}
|
|
40
|
+
</DragContainerContext.Provider>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React, { useEffect, useRef } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useDragContainer } from './context.js';
|
|
4
|
+
import { useForkRef } from '../hooks/use_fork_ref.js';
|
|
5
|
+
|
|
6
|
+
export interface DragHandleProps {
|
|
7
|
+
children: React.ReactElement;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const DragHandle: React.FC<DragHandleProps> = ({ children }) => {
|
|
11
|
+
const { registerHandle, unregisterHandle } = useDragContainer();
|
|
12
|
+
const ref = useRef<HTMLElement | null>(null);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (ref.current == null) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
registerHandle(ref);
|
|
19
|
+
return () => {
|
|
20
|
+
if (ref.current == null) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
unregisterHandle(ref);
|
|
24
|
+
};
|
|
25
|
+
}, [registerHandle, unregisterHandle]);
|
|
26
|
+
|
|
27
|
+
const mergedRef = useForkRef(ref, children.props.ref);
|
|
28
|
+
return React.cloneElement(children, {
|
|
29
|
+
className: clsx('tcn-drag-handle', children.props.className),
|
|
30
|
+
ref: mergedRef,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { useDraggable } from './use_draggable.js';
|
|
3
|
+
import type { Position } from '../../index.js';
|
|
4
|
+
import type { DragContainer } from '../types.js';
|
|
5
|
+
|
|
6
|
+
export interface UseDragContainerOptions {
|
|
7
|
+
initialPosition?: Position;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function useMakeDragContainer(options: UseDragContainerOptions): DragContainer {
|
|
11
|
+
const [handles, setHandles] = useState<React.RefObject<HTMLElement>[]>([]);
|
|
12
|
+
const positionRef = useRef<Position>(options.initialPosition ?? { x: 0, y: 0 });
|
|
13
|
+
const [position, setPosition] = useState(positionRef.current);
|
|
14
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
15
|
+
|
|
16
|
+
useDraggable({
|
|
17
|
+
handles: handles,
|
|
18
|
+
startDragCallback: () => {
|
|
19
|
+
setIsDragging(true);
|
|
20
|
+
},
|
|
21
|
+
dragCallback: (deltaX, deltaY) => {
|
|
22
|
+
setPosition({
|
|
23
|
+
x: positionRef.current.x + deltaX,
|
|
24
|
+
y: positionRef.current.y + deltaY,
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
endDragCallback: () => {
|
|
28
|
+
setIsDragging(false);
|
|
29
|
+
positionRef.current = position;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const registerHandle = useCallback((handle: React.RefObject<HTMLElement>) => {
|
|
34
|
+
setHandles(prev => [...prev, handle]);
|
|
35
|
+
}, []);
|
|
36
|
+
|
|
37
|
+
const unregisterHandle = useCallback((handle: React.RefObject<HTMLElement>) => {
|
|
38
|
+
setHandles(prev => prev.filter(h => h !== handle));
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
return { registerHandle, unregisterHandle, position, isDragging };
|
|
42
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
interface
|
|
3
|
+
export interface UseDraggableOptions {
|
|
4
4
|
startDragCallback: (startX: number, startY: number) => void;
|
|
5
5
|
dragCallback: (deltaX: number, deltaY: number, startX: number, startY: number) => void;
|
|
6
6
|
endDragCallback: (
|
|
@@ -9,16 +9,10 @@ interface DraggableOptions {
|
|
|
9
9
|
startX: number,
|
|
10
10
|
startY: number
|
|
11
11
|
) => void;
|
|
12
|
+
handles?: React.RefObject<HTMLElement>[] | React.RefObject<HTMLElement>;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
// (startX: number, startY: number) => {},
|
|
16
|
-
// (deltaX: number, deltaY: number, startX: number, startY: number) => {},
|
|
17
|
-
// (deltaX: number, deltaY: number, startX: number, startY: number) => {}
|
|
18
|
-
// );
|
|
19
|
-
|
|
20
|
-
export function useDraggable(options: DraggableOptions) {
|
|
21
|
-
const ref = useRef<HTMLElement | null>(null);
|
|
15
|
+
export function useDraggable(options: UseDraggableOptions) {
|
|
22
16
|
const startDragCallbackRef = useRef(options.startDragCallback);
|
|
23
17
|
startDragCallbackRef.current = options.startDragCallback;
|
|
24
18
|
const dragCallbackRef = useRef(options.dragCallback);
|
|
@@ -27,7 +21,8 @@ export function useDraggable(options: DraggableOptions) {
|
|
|
27
21
|
endDragCallbackRef.current = options.endDragCallback;
|
|
28
22
|
|
|
29
23
|
useEffect(() => {
|
|
30
|
-
const
|
|
24
|
+
const handles = options.handles;
|
|
25
|
+
if (handles === undefined) return;
|
|
31
26
|
let startX = 0;
|
|
32
27
|
let startY = 0;
|
|
33
28
|
|
|
@@ -58,17 +53,28 @@ export function useDraggable(options: DraggableOptions) {
|
|
|
58
53
|
document.body.addEventListener('mouseleave', endDrag);
|
|
59
54
|
}
|
|
60
55
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
56
|
+
if (Array.isArray(handles)) {
|
|
57
|
+
for (const element of handles) {
|
|
58
|
+
if (element != null) {
|
|
59
|
+
element.current?.addEventListener('mousedown', startDrag);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
handles?.current?.addEventListener('mousedown', startDrag);
|
|
63
64
|
}
|
|
64
|
-
|
|
65
65
|
return () => {
|
|
66
|
-
|
|
66
|
+
if (Array.isArray(handles)) {
|
|
67
|
+
for (const element of handles) {
|
|
68
|
+
if (element != null) {
|
|
69
|
+
element.current?.removeEventListener('mousedown', startDrag);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
handles?.current?.removeEventListener('mousedown', startDrag);
|
|
74
|
+
}
|
|
67
75
|
document.body.removeEventListener('mousemove', drag);
|
|
68
76
|
document.body.removeEventListener('mouseup', endDrag);
|
|
69
77
|
document.body.removeEventListener('mouseleave', endDrag);
|
|
70
78
|
};
|
|
71
|
-
}, []);
|
|
72
|
-
|
|
73
|
-
return ref;
|
|
79
|
+
}, [options.handles]);
|
|
74
80
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './focus_redirect.js';
|
|
2
1
|
export * from './click_away_listener.js';
|
|
2
|
+
export * from './focus_redirect.js';
|
|
3
3
|
export * from './scroll_away_listener.js';
|
|
4
4
|
|
|
5
|
+
export * from './dnd/hooks/use_draggable.js';
|
|
5
6
|
export * from './hooks/make_context_hook.js';
|
|
6
|
-
export * from './hooks/use_draggable.js';
|
|
7
7
|
export * from './hooks/use_fork_ref.js';
|
|
8
8
|
export * from './hooks/use_media_query.js';
|
|
9
9
|
export * from './hooks/use_resize_observer.js';
|
|
@@ -12,9 +12,11 @@ export * from './default_value.js';
|
|
|
12
12
|
|
|
13
13
|
export * from './calendar/calendar_date.js';
|
|
14
14
|
export * from './calendar/calendar_dates_generator.js';
|
|
15
|
-
export * from './calendar/month.js';
|
|
16
|
-
export * from './calendar/get_months_of_year.js';
|
|
17
15
|
export * from './calendar/get_days_of_week.js';
|
|
16
|
+
export * from './calendar/get_months_of_year.js';
|
|
17
|
+
export * from './calendar/month.js';
|
|
18
18
|
|
|
19
|
-
export * from './types/variations.js';
|
|
20
19
|
export * from './types/dimensions.js';
|
|
20
|
+
export * from './types/variations.js';
|
|
21
|
+
|
|
22
|
+
export * from './responsive/responsive_renderer.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface MouseLeaveRegionProps {
|
|
4
|
+
elementsRefs: (React.RefObject<Element> | React.MutableRefObject<Element>)[];
|
|
5
|
+
onMouseLeave: () => void;
|
|
6
|
+
buffer?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function MouseLeaveRegion({
|
|
10
|
+
onMouseLeave,
|
|
11
|
+
elementsRefs: elementRefs,
|
|
12
|
+
buffer = 8,
|
|
13
|
+
}: MouseLeaveRegionProps) {
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const update = (event: MouseEvent) => {
|
|
16
|
+
const intersects = elementRefs.some(ref => {
|
|
17
|
+
const element = ref.current;
|
|
18
|
+
if (element != null) {
|
|
19
|
+
const rect = element.getBoundingClientRect();
|
|
20
|
+
const overlapLeft = Math.max(event.clientX - buffer, rect.left);
|
|
21
|
+
const overlapRight = Math.min(event.clientX + buffer, rect.right);
|
|
22
|
+
const overlapTop = Math.max(event.clientY - buffer, rect.top);
|
|
23
|
+
const overlapBottom = Math.min(event.clientY + buffer, rect.bottom);
|
|
24
|
+
return overlapLeft <= overlapRight && overlapTop <= overlapBottom;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
if (!intersects) {
|
|
29
|
+
onMouseLeave();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
window.addEventListener('mousemove', update);
|
|
33
|
+
return () => {
|
|
34
|
+
window.removeEventListener('mousemove', update);
|
|
35
|
+
};
|
|
36
|
+
}, [onMouseLeave, elementRefs, buffer]);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
@@ -8,7 +8,19 @@ export interface Dimensions {
|
|
|
8
8
|
height: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export interface
|
|
11
|
+
export interface Rectangle {
|
|
12
|
+
dimensions: Dimensions;
|
|
13
|
+
position: Position;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RectCorners {
|
|
17
|
+
topLeft: Position;
|
|
18
|
+
topRight: Position;
|
|
19
|
+
bottomLeft: Position;
|
|
20
|
+
bottomRight: Position;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface RectEdges {
|
|
12
24
|
top: number;
|
|
13
25
|
right: number;
|
|
14
26
|
bottom: number;
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popper.d.ts","sourceRoot":"","sources":["../../../src/overlay/popper/popper.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4C,MAAM,OAAO,CAAC;AAIjE,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC7C,cAAc,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAC7C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC9C,gBAAgB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IAC9C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,cAAc,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;IACxE,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;IAC/C,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC;IACxD,qBAAqB,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC;IACzD,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,wBAAgB,MAAM,CAAC,EACrB,aAAa,EACb,cAAyB,EACzB,cAAsB,EACtB,cAAkB,EAClB,gBAA0B,EAC1B,gBAA0B,EAC1B,gBAAoB,EACpB,YAAoB,EACpB,IAAY,EACZ,WAAW,EACX,aAAkB,EAClB,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,gBAAwB,EACxB,oBAAoB,EACpB,qBAAqB,GACtB,EAAE,WAAW,kDA8Kb"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"popper.js","sources":["../../../src/overlay/popper/popper.tsx"],"sourcesContent":["import { ClickAwayListener, ScrollAwayListener } from '../../utils/index.js';\nimport React, { useLayoutEffect, useRef, useState } from 'react';\nimport { Portal } from '../portal/portal.js';\nimport styles from './popper.module.css';\n\nexport interface PopperProps {\n anchorElement: HTMLElement | null;\n verticalAnchor?: 'top' | 'center' | 'bottom';\n verticalOrigin?: 'top' | 'center' | 'bottom';\n verticalOffset?: number;\n horizontalAnchor?: 'start' | 'center' | 'end';\n horizontalOrigin?: 'start' | 'center' | 'end';\n horizontalOffset?: number;\n open: boolean;\n onClose: () => void;\n restoreFocus?: boolean;\n children: React.ReactNode;\n veil?: boolean;\n onVeilClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;\n clickAwayRefs?: React.RefObject<HTMLElement>[];\n isClickAwayException?: (target: HTMLElement) => boolean;\n isScrollAwayException?: (target: HTMLElement) => boolean;\n disableClickAway?: boolean;\n}\n\nexport function Popper({\n anchorElement,\n verticalAnchor = 'bottom',\n verticalOrigin = 'top',\n verticalOffset = 0,\n horizontalAnchor = 'start',\n horizontalOrigin = 'start',\n horizontalOffset = 0,\n restoreFocus = false,\n veil = false,\n onVeilClick,\n clickAwayRefs = [],\n open,\n onClose,\n children,\n disableClickAway = false,\n isClickAwayException,\n isScrollAwayException,\n}: PopperProps) {\n const anchorElementRef = useRef(anchorElement);\n const [position, setPosition] = useState({ top: 0, left: 0 });\n const activeElementRef = useRef<HTMLElement | null>(null);\n const popoverRef = useRef<HTMLDivElement>(null);\n const canOpen = open && anchorElement != null;\n const finalClickAwayRefs: React.RefObject<HTMLElement>[] = clickAwayRefs ?? [];\n const enableClickAway = !disableClickAway;\n const veilRef = useRef<HTMLDivElement>(null);\n function close() {\n onClose && onClose();\n }\n\n // eslint-disable-next-line complexity\n const updatePosition = () => {\n if (!anchorElement || !popoverRef.current) return;\n\n const anchorRect = anchorElement.getBoundingClientRect();\n const popoverRect = popoverRef.current.getBoundingClientRect();\n const viewportWidth = window.innerWidth;\n const viewportHeight = window.innerHeight;\n\n // Determine the text direction (ltr or rtl)\n const computedStyle = getComputedStyle(anchorElement);\n const isRtl = computedStyle.direction === 'rtl';\n\n let top = anchorRect.top;\n let left = anchorRect.left;\n\n // Calculate vertical position\n switch (verticalAnchor) {\n case 'top':\n top += verticalOffset;\n break;\n case 'center':\n top += anchorRect.height / 2;\n break;\n case 'bottom':\n top += anchorRect.height - verticalOffset;\n break;\n }\n\n switch (verticalOrigin) {\n case 'top':\n break;\n case 'center':\n top -= popoverRect.height / 2;\n break;\n case 'bottom':\n top -= popoverRect.height;\n break;\n }\n\n // Calculate horizontal position with direction sensitivity\n if (horizontalAnchor === 'start') {\n left += isRtl ? anchorRect.width + horizontalOffset : horizontalOffset;\n } else if (horizontalAnchor === 'center') {\n left += anchorRect.width / 2;\n } else if (horizontalAnchor === 'end') {\n left += isRtl ? -horizontalOffset : anchorRect.width + horizontalOffset;\n }\n\n // Adjust the origin based on RTL direction\n let adjustedHorizontalOrigin = horizontalOrigin;\n if (isRtl) {\n if (horizontalOrigin === 'start') {\n adjustedHorizontalOrigin = 'end';\n } else if (horizontalOrigin === 'end') {\n adjustedHorizontalOrigin = 'start';\n }\n }\n\n // Apply adjusted origin to the position calculation\n if (adjustedHorizontalOrigin === 'start') {\n // No adjustment needed\n } else if (adjustedHorizontalOrigin === 'center') {\n left -= popoverRect.width / 2;\n } else if (adjustedHorizontalOrigin === 'end') {\n left -= popoverRect.width;\n }\n\n // Ensure the popover stays within the viewport\n // Prevent overflow to the right\n if (left + popoverRect.width > viewportWidth) {\n left = viewportWidth - popoverRect.width;\n }\n\n // Prevent overflow to the left\n if (left < 0) {\n left = 0;\n }\n\n // Prevent overflow to the bottom\n if (top + popoverRect.height > viewportHeight) {\n top = viewportHeight - popoverRect.height;\n }\n\n // Prevent overflow to the top\n if (top < 0) {\n top = 0;\n }\n\n // Only update if position has changed to avoid unnecessary re-renders\n if (top !== position.top || left !== position.left) {\n setPosition({ top, left });\n }\n };\n\n useLayoutEffect(() => {\n updatePosition();\n window.addEventListener('resize', updatePosition);\n return () => {\n window.removeEventListener('resize', updatePosition);\n };\n });\n\n useLayoutEffect(() => {\n if (open) {\n activeElementRef.current = window.document.activeElement as HTMLElement;\n } else {\n const restoreToElement = activeElementRef.current;\n requestAnimationFrame(() => {\n restoreFocus && restoreToElement?.focus();\n });\n }\n }, [open, restoreFocus]);\n\n if (!canOpen) {\n return null;\n }\n\n anchorElementRef.current = anchorElement;\n\n let content = (\n <ScrollAwayListener onScrollAway={close} isException={isScrollAwayException}>\n <div\n ref={popoverRef}\n className={styles.popover}\n style={{\n top: `${position.top}px`,\n left: `${position.left}px`,\n }}\n >\n {children}\n </div>\n </ScrollAwayListener>\n );\n\n if (enableClickAway) {\n content = (\n <ClickAwayListener\n onClickAway={close}\n refs={[anchorElementRef, ...finalClickAwayRefs]}\n isException={isClickAwayException}\n >\n {content}\n </ClickAwayListener>\n );\n }\n\n return (\n <Portal>\n {veil && (\n <div\n ref={veilRef}\n onClick={e => veilRef.current === e.target && onVeilClick && onVeilClick(e)}\n className={styles['popover-veil']}\n >\n {content}\n </div>\n )}\n {!veil && content}\n </Portal>\n );\n}\n"],"names":["Popper","anchorElement","verticalAnchor","verticalOrigin","verticalOffset","horizontalAnchor","horizontalOrigin","horizontalOffset","restoreFocus","veil","onVeilClick","clickAwayRefs","open","onClose","children","disableClickAway","isClickAwayException","isScrollAwayException","anchorElementRef","useRef","position","setPosition","useState","activeElementRef","popoverRef","canOpen","finalClickAwayRefs","enableClickAway","veilRef","close","updatePosition","anchorRect","popoverRect","viewportWidth","viewportHeight","isRtl","top","left","adjustedHorizontalOrigin","useLayoutEffect","restoreToElement","content","jsx","ScrollAwayListener","styles","ClickAwayListener","Portal"],"mappings":"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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { VStackProps } from '../../stacks/v_stack.js';
|
|
2
|
-
import { default as React } from 'react';
|
|
3
|
-
export interface TooltipProps extends Omit<VStackProps, 'as' | 'children'> {
|
|
4
|
-
children?: React.ReactNode;
|
|
5
|
-
}
|
|
6
|
-
export declare const Tooltip: React.ForwardRefExoticComponent<TooltipProps & React.RefAttributes<HTMLElement>>;
|
|
7
|
-
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../../src/overlay/tooltip/tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,UAAU,CAAC;IACxE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,eAAO,MAAM,OAAO,kFAclB,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { jsx as s } from "react/jsx-runtime";
|
|
2
|
-
import { VStack as i } from "../../stacks/v_stack.js";
|
|
3
|
-
import { clsx as e } from "clsx";
|
|
4
|
-
import l from "react";
|
|
5
|
-
import '../../tooltip.css';const m = "_tooltip_e324d7e", a = { tooltip: m }, u = l.forwardRef(function({ children: o, className: t, ...r }, p) {
|
|
6
|
-
return /* @__PURE__ */ s(
|
|
7
|
-
i,
|
|
8
|
-
{
|
|
9
|
-
ref: p,
|
|
10
|
-
as: "span",
|
|
11
|
-
className: e(t, a.tooltip, "tooltip"),
|
|
12
|
-
...r,
|
|
13
|
-
children: o
|
|
14
|
-
}
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
export {
|
|
18
|
-
u as Tooltip
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=tooltip.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tooltip.js","sources":["../../../src/overlay/tooltip/tooltip.tsx"],"sourcesContent":["import { VStack, type VStackProps } from '../../stacks/v_stack.js';\nimport { clsx } from 'clsx';\nimport React from 'react';\nimport styles from './tooltip.module.css';\n\nexport interface TooltipProps extends Omit<VStackProps, 'as' | 'children'> {\n children?: React.ReactNode;\n}\n\nexport const Tooltip = React.forwardRef<HTMLElement, TooltipProps>(function VPanel(\n { children, className, ...props }: TooltipProps,\n ref\n) {\n return (\n <VStack\n ref={ref}\n as=\"span\"\n className={clsx(className, styles.tooltip, 'tooltip')}\n {...props}\n >\n {children}\n </VStack>\n );\n});\n"],"names":["Tooltip","React","children","className","props","ref","jsx","VStack","clsx","styles"],"mappings":";;;;kDASaA,IAAUC,EAAM,WAAsC,SACjE,EAAE,UAAAC,GAAU,WAAAC,GAAW,GAAGC,EAAA,GAC1BC,GACA;AACA,SACE,gBAAAC;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,KAAAF;AAAA,MACA,IAAG;AAAA,MACH,WAAWG,EAAKL,GAAWM,EAAO,SAAS,SAAS;AAAA,MACnD,GAAGL;AAAA,MAEH,UAAAF;AAAA,IAAA;AAAA,EAAA;AAGP,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"panel.module-DwGKncon.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"title.module-B16de2jd.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use_draggable.d.ts","sourceRoot":"","sources":["../../../src/utils/hooks/use_draggable.ts"],"names":[],"mappings":"AAEA,UAAU,gBAAgB;IACxB,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACvF,eAAe,EAAE,CACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,KACX,IAAI,CAAC;CACX;AAQD,wBAAgB,YAAY,CAAC,OAAO,EAAE,gBAAgB,wDAsDrD"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useRef as o, useEffect as g } from "react";
|
|
2
|
-
function E(t) {
|
|
3
|
-
const s = o(null), m = o(t.startDragCallback);
|
|
4
|
-
m.current = t.startDragCallback;
|
|
5
|
-
const i = o(t.dragCallback);
|
|
6
|
-
i.current = t.dragCallback;
|
|
7
|
-
const v = o(t.endDragCallback);
|
|
8
|
-
return v.current = t.endDragCallback, g(() => {
|
|
9
|
-
const c = s.current;
|
|
10
|
-
let n = 0, r = 0;
|
|
11
|
-
function d(e) {
|
|
12
|
-
const l = e.clientX - n, u = e.clientY - r;
|
|
13
|
-
i.current(l, u, n, r);
|
|
14
|
-
}
|
|
15
|
-
function a(e) {
|
|
16
|
-
const l = e.clientX !== void 0 ? e.clientX - n : 0, u = e.clientY !== void 0 ? e.clientY - r : 0;
|
|
17
|
-
v.current(l, u, n, r), document.body.removeEventListener("mousemove", d), document.body.removeEventListener("mouseup", a), document.body.removeEventListener("mouseleave", a);
|
|
18
|
-
}
|
|
19
|
-
function b(e) {
|
|
20
|
-
n = e.clientX, r = e.clientY, m.current(n, r), document.body.addEventListener("mousemove", d), document.body.addEventListener("mouseup", a), document.body.addEventListener("mouseleave", a);
|
|
21
|
-
}
|
|
22
|
-
return c?.addEventListener("mousedown", b), () => {
|
|
23
|
-
c?.removeEventListener("mousedown", b), document.body.removeEventListener("mousemove", d), document.body.removeEventListener("mouseup", a), document.body.removeEventListener("mouseleave", a);
|
|
24
|
-
};
|
|
25
|
-
}, []), s;
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
E as useDraggable
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=use_draggable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use_draggable.js","sources":["../../../src/utils/hooks/use_draggable.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\ninterface DraggableOptions {\n startDragCallback: (startX: number, startY: number) => void;\n dragCallback: (deltaX: number, deltaY: number, startX: number, startY: number) => void;\n endDragCallback: (\n deltaX: number,\n deltaY: number,\n startX: number,\n startY: number\n ) => void;\n}\n\n// const handleRef: Ref<HTMLElement> = useDraggable(\n// (startX: number, startY: number) => {},\n// (deltaX: number, deltaY: number, startX: number, startY: number) => {},\n// (deltaX: number, deltaY: number, startX: number, startY: number) => {}\n// );\n\nexport function useDraggable(options: DraggableOptions) {\n const ref = useRef<HTMLElement | null>(null);\n const startDragCallbackRef = useRef(options.startDragCallback);\n startDragCallbackRef.current = options.startDragCallback;\n const dragCallbackRef = useRef(options.dragCallback);\n dragCallbackRef.current = options.dragCallback;\n const endDragCallbackRef = useRef(options.endDragCallback);\n endDragCallbackRef.current = options.endDragCallback;\n\n useEffect(() => {\n const element = ref.current;\n let startX = 0;\n let startY = 0;\n\n function drag(event: MouseEvent) {\n const deltaX = event.clientX - startX;\n const deltaY = event.clientY - startY;\n\n dragCallbackRef.current(deltaX, deltaY, startX, startY);\n }\n\n function endDrag(event: MouseEvent) {\n const deltaX = event.clientX !== undefined ? event.clientX - startX : 0;\n const deltaY = event.clientY !== undefined ? event.clientY - startY : 0;\n endDragCallbackRef.current(deltaX, deltaY, startX, startY);\n document.body.removeEventListener('mousemove', drag);\n document.body.removeEventListener('mouseup', endDrag);\n document.body.removeEventListener('mouseleave', endDrag);\n }\n\n function startDrag(event: MouseEvent) {\n startX = event.clientX;\n startY = event.clientY;\n\n startDragCallbackRef.current(startX, startY);\n\n document.body.addEventListener('mousemove', drag);\n document.body.addEventListener('mouseup', endDrag);\n document.body.addEventListener('mouseleave', endDrag);\n }\n\n if (element != null) {\n element.addEventListener('mousedown', startDrag);\n }\n\n return () => {\n element?.removeEventListener('mousedown', startDrag);\n document.body.removeEventListener('mousemove', drag);\n document.body.removeEventListener('mouseup', endDrag);\n document.body.removeEventListener('mouseleave', endDrag);\n };\n }, []);\n\n return ref;\n}\n"],"names":["useDraggable","options","ref","useRef","startDragCallbackRef","dragCallbackRef","endDragCallbackRef","useEffect","element","startX","startY","drag","event","deltaX","deltaY","endDrag","startDrag"],"mappings":";AAmBO,SAASA,EAAaC,GAA2B;AACtD,QAAMC,IAAMC,EAA2B,IAAI,GACrCC,IAAuBD,EAAOF,EAAQ,iBAAiB;AAC7D,EAAAG,EAAqB,UAAUH,EAAQ;AACvC,QAAMI,IAAkBF,EAAOF,EAAQ,YAAY;AACnD,EAAAI,EAAgB,UAAUJ,EAAQ;AAClC,QAAMK,IAAqBH,EAAOF,EAAQ,eAAe;AACzD,SAAAK,EAAmB,UAAUL,EAAQ,iBAErCM,EAAU,MAAM;AACd,UAAMC,IAAUN,EAAI;AACpB,QAAIO,IAAS,GACTC,IAAS;AAEb,aAASC,EAAKC,GAAmB;AAC/B,YAAMC,IAASD,EAAM,UAAUH,GACzBK,IAASF,EAAM,UAAUF;AAE/B,MAAAL,EAAgB,QAAQQ,GAAQC,GAAQL,GAAQC,CAAM;AAAA,IACxD;AAEA,aAASK,EAAQH,GAAmB;AAClC,YAAMC,IAASD,EAAM,YAAY,SAAYA,EAAM,UAAUH,IAAS,GAChEK,IAASF,EAAM,YAAY,SAAYA,EAAM,UAAUF,IAAS;AACtE,MAAAJ,EAAmB,QAAQO,GAAQC,GAAQL,GAAQC,CAAM,GACzD,SAAS,KAAK,oBAAoB,aAAaC,CAAI,GACnD,SAAS,KAAK,oBAAoB,WAAWI,CAAO,GACpD,SAAS,KAAK,oBAAoB,cAAcA,CAAO;AAAA,IACzD;AAEA,aAASC,EAAUJ,GAAmB;AACpC,MAAAH,IAASG,EAAM,SACfF,IAASE,EAAM,SAEfR,EAAqB,QAAQK,GAAQC,CAAM,GAE3C,SAAS,KAAK,iBAAiB,aAAaC,CAAI,GAChD,SAAS,KAAK,iBAAiB,WAAWI,CAAO,GACjD,SAAS,KAAK,iBAAiB,cAAcA,CAAO;AAAA,IACtD;AAEA,WACEP,GAAQ,iBAAiB,aAAaQ,CAAS,GAG1C,MAAM;AACX,MAAAR,GAAS,oBAAoB,aAAaQ,CAAS,GACnD,SAAS,KAAK,oBAAoB,aAAaL,CAAI,GACnD,SAAS,KAAK,oBAAoB,WAAWI,CAAO,GACpD,SAAS,KAAK,oBAAoB,cAAcA,CAAO;AAAA,IACzD;AAAA,EACF,GAAG,CAAA,CAAE,GAEEb;AACT;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Tooltip } from './tooltip.js';
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
title: 'Overlays/Tooltip',
|
|
5
|
-
component: Tooltip,
|
|
6
|
-
tags: ['autodocs'],
|
|
7
|
-
parameters: {
|
|
8
|
-
docs: {
|
|
9
|
-
description: {
|
|
10
|
-
component: 'A tooltip component that displays a tooltip when hovered.',
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const TooltipStory = () => {
|
|
17
|
-
return (
|
|
18
|
-
<Tooltip>
|
|
19
|
-
<>TODO: TOOLTIP</>
|
|
20
|
-
</Tooltip>
|
|
21
|
-
);
|
|
22
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { VStack, type VStackProps } from '../../stacks/v_stack.js';
|
|
2
|
-
import { clsx } from 'clsx';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import styles from './tooltip.module.css';
|
|
5
|
-
|
|
6
|
-
export interface TooltipProps extends Omit<VStackProps, 'as' | 'children'> {
|
|
7
|
-
children?: React.ReactNode;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const Tooltip = React.forwardRef<HTMLElement, TooltipProps>(function VPanel(
|
|
11
|
-
{ children, className, ...props }: TooltipProps,
|
|
12
|
-
ref
|
|
13
|
-
) {
|
|
14
|
-
return (
|
|
15
|
-
<VStack
|
|
16
|
-
ref={ref}
|
|
17
|
-
as="span"
|
|
18
|
-
className={clsx(className, styles.tooltip, 'tooltip')}
|
|
19
|
-
{...props}
|
|
20
|
-
>
|
|
21
|
-
{children}
|
|
22
|
-
</VStack>
|
|
23
|
-
);
|
|
24
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|