@heliosgraphics/ui 2.0.0-alpha.95 → 2.0.0-alpha.96
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/components/Alert/Alert.tsx +2 -0
- package/components/Breadcrumb/Breadcrumb.tsx +17 -1
- package/components/Browser/Browser.tsx +2 -0
- package/components/Button/Button.tsx +7 -3
- package/components/ButtonGroup/ButtonGroup.tsx +2 -0
- package/components/Checkbox/Checkbox.tsx +66 -55
- package/components/Clock/Clock.tsx +23 -19
- package/components/Column/Column.tsx +2 -0
- package/components/Confirm/Confirm.tsx +2 -0
- package/components/DatePicker/DatePicker.meta.ts +12 -5
- package/components/DatePicker/DatePicker.module.css +70 -1
- package/components/DatePicker/DatePicker.tsx +116 -4
- package/components/DatePicker/DatePicker.types.ts +6 -1
- package/components/DatePicker/DatePicker.utils.ts +53 -0
- package/components/Debug/Debug.tsx +2 -0
- package/components/Details/Details.tsx +2 -0
- package/components/Dialog/Dialog.module.css +4 -6
- package/components/Dialog/Dialog.tsx +25 -16
- package/components/Donut/Donut.tsx +2 -0
- package/components/Dot/Dot.tsx +2 -0
- package/components/Dropdown/Dropdown.module.css +5 -0
- package/components/Dropdown/Dropdown.tsx +21 -26
- package/components/Fieldset/Fieldset.tsx +2 -0
- package/components/Flex/Flex.meta.ts +1 -0
- package/components/Flex/Flex.tsx +22 -2
- package/components/Flex/Flex.types.ts +1 -0
- package/components/Flex/Flex.utils.spec.ts +4 -1
- package/components/Flex/Flex.utils.ts +4 -1
- package/components/Grid/Grid.tsx +2 -0
- package/components/Heading/Heading.meta.ts +5 -0
- package/components/Heading/Heading.tsx +15 -9
- package/components/Heading/Heading.types.ts +1 -0
- package/components/Heading/components/H0/H0.tsx +2 -0
- package/components/Heading/components/H1/H1.tsx +2 -0
- package/components/Heading/components/H2/H2.tsx +2 -0
- package/components/Heading/components/H3/H3.tsx +2 -0
- package/components/Heading/components/H4/H4.tsx +2 -0
- package/components/Heading/components/H5/H5.tsx +2 -0
- package/components/Heading/components/H6/H6.tsx +2 -0
- package/components/Icon/Icon.tsx +2 -0
- package/components/Input/Input.tsx +103 -95
- package/components/Layout/Layout.tsx +2 -0
- package/components/Layout/components/LayoutAside/LayoutAside.tsx +2 -0
- package/components/Layout/components/LayoutAside/components/LayoutAsideContent/LayoutAsideContent.tsx +2 -0
- package/components/Layout/components/LayoutAside/components/LayoutAsideFooter/LayoutAsideFooter.tsx +2 -0
- package/components/Layout/components/LayoutAside/components/LayoutAsideToggle/LayoutAsideToggle.tsx +2 -0
- package/components/Layout/components/LayoutMain/LayoutMain.tsx +2 -0
- package/components/Layout/components/LayoutMain/components/LayoutMainContent/LayoutMainContent.tsx +2 -0
- package/components/Layout/components/LayoutNavigation/LayoutNavigation.tsx +2 -0
- package/components/Layout/components/LayoutSubNavigation/LayoutSubNavigation.tsx +2 -0
- package/components/Loading/Loading.tsx +2 -0
- package/components/Markdown/Markdown.tsx +2 -0
- package/components/Masonry/Masonry.tsx +5 -1
- package/components/Menu/Menu.tsx +2 -0
- package/components/Menu/components/MenuCategory/MenuCategory.tsx +2 -0
- package/components/Menu/components/MenuFilter/MenuFilter.tsx +2 -0
- package/components/Menu/components/MenuItem/MenuItem.tsx +2 -0
- package/components/Overlay/Overlay.tsx +18 -2
- package/components/Pie/Pie.tsx +2 -0
- package/components/Pill/Pill.meta.ts +9 -1
- package/components/Pill/Pill.module.css +11 -0
- package/components/Pill/Pill.tsx +28 -3
- package/components/Pill/Pill.types.ts +2 -0
- package/components/Placeholder/Placeholder.tsx +2 -0
- package/components/Progress/Progress.tsx +2 -0
- package/components/Radio/Radio.tsx +2 -0
- package/components/Range/Range.tsx +2 -0
- package/components/Segments/Segments.context.ts +19 -0
- package/components/Segments/Segments.meta.ts +4 -0
- package/components/Segments/Segments.tsx +34 -42
- package/components/Segments/Segments.types.ts +1 -0
- package/components/Segments/components/SegmentButton/SegmentButton.meta.ts +0 -4
- package/components/Segments/components/SegmentButton/SegmentButton.tsx +28 -3
- package/components/Segments/components/SegmentButton/SegmentButton.types.ts +0 -2
- package/components/Select/Select.tsx +40 -43
- package/components/Separator/Separator.tsx +2 -0
- package/components/Separator/components/HRMarkup/HRMarkup.tsx +2 -0
- package/components/Separator/components/HorizontalSeparator/HorizontalSeparator.tsx +2 -0
- package/components/Separator/components/VerticalSeparator/VerticalSeparator.tsx +2 -0
- package/components/Setup/Setup.tsx +3 -0
- package/components/Shimmer/Shimmer.tsx +2 -0
- package/components/Slider/Slider.tsx +2 -0
- package/components/Spacer/Spacer.tsx +2 -0
- package/components/Table/Table.tsx +2 -0
- package/components/Tabs/Tabs.meta.ts +12 -12
- package/components/Tabs/Tabs.module.css +25 -9
- package/components/Tabs/Tabs.tsx +49 -53
- package/components/Tabs/Tabs.types.ts +10 -3
- package/components/Text/Text.tsx +2 -0
- package/components/Text/components/Div/Div.tsx +2 -0
- package/components/Text/components/Micro/Micro.tsx +2 -0
- package/components/Text/components/P/P.tsx +2 -0
- package/components/Text/components/Small/Small.tsx +2 -0
- package/components/Text/components/Tiny/Tiny.tsx +2 -0
- package/components/Textarea/Textarea.tsx +14 -13
- package/components/Tile/Tile.tsx +2 -0
- package/components/Timestamp/Timestamp.tsx +2 -0
- package/components/Toggle/Toggle.tsx +2 -0
- package/components/Tooltip/Tooltip.tsx +17 -9
- package/components/Tooltip/Tooltip.types.ts +0 -1
- package/components/Tooltip/components/TooltipContent/TooltipContent.tsx +2 -0
- package/components/Tooltip/components/TooltipTrigger/TooltipTrigger.tsx +4 -2
- package/components/shared/InputLabel/InputLabel.tsx +2 -0
- package/components/shared/ResultList/ResultList.tsx +6 -4
- package/contexts/LayoutContext/LayoutContext.tsx +15 -34
- package/contexts/LayoutContext/LayoutContext.types.ts +0 -1
- package/hooks/useLayoutContext.tsx +0 -1
- package/index.ts +5 -0
- package/package.json +1 -1
|
@@ -41,6 +41,7 @@ export const Setup: FC<SetupProps> = ({ theme = "system", fixedTheme }) => {
|
|
|
41
41
|
<link key={`stylesheet-${linkProps.id}`} {...linkProps} />
|
|
42
42
|
))}
|
|
43
43
|
<script
|
|
44
|
+
data-ui-component="Setup"
|
|
44
45
|
dangerouslySetInnerHTML={{
|
|
45
46
|
__html: `(${code.toString()})("${theme}", ${fixedThemeArg});`,
|
|
46
47
|
}}
|
|
@@ -48,3 +49,5 @@ export const Setup: FC<SetupProps> = ({ theme = "system", fixedTheme }) => {
|
|
|
48
49
|
</>
|
|
49
50
|
)
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
Setup.displayName = "Setup"
|
|
@@ -2,23 +2,23 @@ import type { HeliosAttributeMeta } from "../../types/meta"
|
|
|
2
2
|
import type { TabsProps } from "./Tabs.types"
|
|
3
3
|
|
|
4
4
|
export const meta: HeliosAttributeMeta<TabsProps> = {
|
|
5
|
+
_extends: [],
|
|
5
6
|
_patterns: [
|
|
6
7
|
{
|
|
7
8
|
id: "ui-tabs-default",
|
|
8
9
|
description: "default",
|
|
9
|
-
content:
|
|
10
|
+
content:
|
|
11
|
+
'<Tabs items={[{ name: "Tab 1", isActive: true, onClick: () => {} }, { name: "Tab 2", onClick: () => {} }]}>{CHILDREN}</Tabs>',
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "ui-tabs-with-href",
|
|
15
|
+
description: "with links",
|
|
16
|
+
content:
|
|
17
|
+
'<Tabs items={[{ name: "Overview", href: "/overview", isActive: true }, { name: "Settings", href: "/settings" }]} />',
|
|
10
18
|
},
|
|
11
19
|
],
|
|
12
20
|
_status: "experimental",
|
|
13
|
-
_category: "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
isOptional: true,
|
|
17
|
-
},
|
|
18
|
-
items: {
|
|
19
|
-
type: "Array<string>",
|
|
20
|
-
},
|
|
21
|
-
sections: {
|
|
22
|
-
type: "Array<ReactNode>",
|
|
23
|
-
},
|
|
21
|
+
_category: "core",
|
|
22
|
+
children: { type: "ReactNode", isOptional: true },
|
|
23
|
+
items: { type: "Array<TabItem>", description: "Tab items with name, onClick, href, isActive, and isDisabled" },
|
|
24
24
|
}
|
|
@@ -1,27 +1,43 @@
|
|
|
1
|
-
.
|
|
1
|
+
.tabs__list {
|
|
2
2
|
position: relative;
|
|
3
|
+
display: flex;
|
|
4
|
+
gap: 2px;
|
|
3
5
|
|
|
4
|
-
height:
|
|
6
|
+
height: 40px;
|
|
5
7
|
padding: 0 8px 0 0;
|
|
6
8
|
|
|
7
9
|
box-shadow: inset 0 -1px 0 0 var(--ui-border-secondary);
|
|
8
|
-
|
|
9
|
-
line-height: 36px;
|
|
10
|
+
line-height: 40px;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
.
|
|
13
|
+
.tabs__item {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
13
16
|
padding: 0 12px;
|
|
14
17
|
|
|
15
18
|
border-radius: var(--radius-sm) var(--radius-sm) 0 0;
|
|
16
|
-
|
|
19
|
+
color: var(--ui-text-secondary);
|
|
20
|
+
text-decoration: none;
|
|
17
21
|
|
|
18
22
|
cursor: pointer;
|
|
23
|
+
user-select: none;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.tabs__item:hover {
|
|
27
|
+
color: var(--ui-text-primary);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.tabs__itemActive {
|
|
31
|
+
color: var(--ui-text-primary);
|
|
32
|
+
box-shadow: inset 0 -2px 0 0 var(--ui-text-primary);
|
|
19
33
|
}
|
|
20
34
|
|
|
21
|
-
.
|
|
22
|
-
|
|
35
|
+
.tabs__itemDisabled {
|
|
36
|
+
opacity: 0.4;
|
|
37
|
+
cursor: not-allowed;
|
|
38
|
+
pointer-events: none;
|
|
23
39
|
}
|
|
24
40
|
|
|
25
|
-
.
|
|
41
|
+
.tabs__content {
|
|
26
42
|
padding: 24px 0;
|
|
27
43
|
}
|
package/components/Tabs/Tabs.tsx
CHANGED
|
@@ -1,69 +1,65 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
3
|
import { getClasses } from "@heliosgraphics/utils"
|
|
4
|
-
import { useId, useRef, useState, type FC, type KeyboardEvent } from "react"
|
|
5
|
-
import type { TabsProps } from "./Tabs.types"
|
|
6
|
-
import styles from "./Tabs.module.css"
|
|
7
4
|
import { Text } from "../Text"
|
|
5
|
+
import styles from "./Tabs.module.css"
|
|
6
|
+
import type { FC, KeyboardEvent } from "react"
|
|
7
|
+
import type { TabItem, TabsProps } from "./Tabs.types"
|
|
8
8
|
|
|
9
|
-
export const Tabs: FC<TabsProps> = ({
|
|
10
|
-
|
|
11
|
-
const tabsId: string = useId()
|
|
12
|
-
const tabRefs = useRef<(HTMLDivElement | null)[]>([])
|
|
13
|
-
|
|
14
|
-
if (!items || !sections) return null
|
|
15
|
-
|
|
16
|
-
const tabListClasses: string = getClasses(styles.tabs__ol, "flex gap-2")
|
|
17
|
-
|
|
18
|
-
const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>, index: number): void => {
|
|
19
|
-
let nextIndex: number | null = null
|
|
9
|
+
export const Tabs: FC<TabsProps> = ({ items, children }) => {
|
|
10
|
+
if (!items?.length) return null
|
|
20
11
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
nextIndex = (index + 1) % items.length
|
|
24
|
-
} else if (event.key === "ArrowLeft") {
|
|
12
|
+
const onKeyDown = (event: KeyboardEvent<HTMLElement>, item: TabItem): void => {
|
|
13
|
+
if (event.key === " " || event.key === "Enter") {
|
|
25
14
|
event.preventDefault()
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (nextIndex !== null) {
|
|
30
|
-
setActive(nextIndex)
|
|
31
|
-
tabRefs.current[nextIndex]?.focus()
|
|
15
|
+
item.onClick?.()
|
|
32
16
|
}
|
|
33
17
|
}
|
|
34
18
|
|
|
35
19
|
return (
|
|
36
20
|
<div data-ui-component="Tabs">
|
|
37
|
-
<div role="tablist" className={
|
|
38
|
-
{items.map((
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
21
|
+
<div role="tablist" className={styles.tabs__list}>
|
|
22
|
+
{items.map((item: TabItem, index: number) => {
|
|
23
|
+
const itemClasses: string = getClasses(styles.tabs__item, {
|
|
24
|
+
[styles.tabs__itemActive]: !!item.isActive,
|
|
25
|
+
[styles.tabs__itemDisabled]: !!item.isDisabled,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const commonProps = {
|
|
29
|
+
key: index,
|
|
30
|
+
role: "tab" as const,
|
|
31
|
+
tabIndex: item.isDisabled ? -1 : 0,
|
|
32
|
+
"aria-selected": !!item.isActive,
|
|
33
|
+
"aria-disabled": !!item.isDisabled,
|
|
34
|
+
className: itemClasses,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (item.href) {
|
|
38
|
+
return (
|
|
39
|
+
<a {...commonProps} href={item.href}>
|
|
40
|
+
<Text type="small" fontWeight="medium">
|
|
41
|
+
{item.name}
|
|
42
|
+
</Text>
|
|
43
|
+
</a>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div
|
|
49
|
+
{...commonProps}
|
|
50
|
+
onClick={item.isDisabled ? undefined : item.onClick}
|
|
51
|
+
onKeyDown={(e) => onKeyDown(e, item)}
|
|
52
|
+
>
|
|
53
|
+
<Text type="small" fontWeight="medium">
|
|
54
|
+
{item.name}
|
|
55
|
+
</Text>
|
|
56
|
+
</div>
|
|
57
|
+
)
|
|
58
|
+
})}
|
|
58
59
|
</div>
|
|
59
|
-
<section
|
|
60
|
-
role="tabpanel"
|
|
61
|
-
id={`${tabsId}-panel-${active}`}
|
|
62
|
-
aria-labelledby={`${tabsId}-tab-${active}`}
|
|
63
|
-
className="tabs__section"
|
|
64
|
-
>
|
|
65
|
-
{sections[active]}
|
|
66
|
-
</section>
|
|
60
|
+
{children && <section className={styles.tabs__content}>{children}</section>}
|
|
67
61
|
</div>
|
|
68
62
|
)
|
|
69
63
|
}
|
|
64
|
+
|
|
65
|
+
Tabs.displayName = "Tabs"
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { ReactNode } from "react"
|
|
2
2
|
|
|
3
|
+
export interface TabItem {
|
|
4
|
+
href?: string
|
|
5
|
+
isActive?: boolean
|
|
6
|
+
isDisabled?: boolean
|
|
7
|
+
name: string
|
|
8
|
+
onClick?: () => void
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
export interface TabsProps {
|
|
4
|
-
|
|
5
|
-
items: Array<
|
|
6
|
-
sections: Array<ReactNode>
|
|
12
|
+
children?: ReactNode
|
|
13
|
+
items: Array<TabItem>
|
|
7
14
|
}
|
package/components/Text/Text.tsx
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
import { getClasses } from "@heliosgraphics/utils"
|
|
4
4
|
import { Text } from "../Text"
|
|
5
|
-
import { useId, useRef, useEffect } from "react"
|
|
5
|
+
import { useId, useRef, useEffect, useImperativeHandle, forwardRef } from "react"
|
|
6
6
|
import { InputLabel } from "../shared/InputLabel"
|
|
7
7
|
import styles from "./Textarea.module.css"
|
|
8
|
-
import type { FC } from "react"
|
|
9
8
|
import type { TextareaProps } from "./Textarea.types"
|
|
10
9
|
|
|
11
|
-
export const Textarea
|
|
12
|
-
const
|
|
10
|
+
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>((props, ref) => {
|
|
11
|
+
const internalRef = useRef<HTMLTextAreaElement | null>(null)
|
|
13
12
|
const { autoComplete: _autoComplete, helperText: _helperText, isDisabled, isLabelHidden, ...goodProps } = props
|
|
14
13
|
|
|
14
|
+
useImperativeHandle(ref, () => internalRef.current as HTMLTextAreaElement)
|
|
15
|
+
|
|
15
16
|
const htmlFor: string = useId()
|
|
16
17
|
const helperId: string = `${htmlFor}-helper`
|
|
17
18
|
const textareaClasses: string = getClasses(styles.textarea, "flex flex-column", {
|
|
@@ -19,16 +20,14 @@ export const Textarea: FC<TextareaProps> = (props) => {
|
|
|
19
20
|
})
|
|
20
21
|
|
|
21
22
|
const onInput = (): void => {
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (!internalRef.current) return
|
|
24
|
+
|
|
25
|
+
internalRef.current.style.height = "auto"
|
|
26
|
+
internalRef.current.style.height = internalRef.current.scrollHeight + "px"
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
useEffect(() => {
|
|
29
|
-
|
|
30
|
-
onInput()
|
|
31
|
-
}
|
|
30
|
+
onInput()
|
|
32
31
|
|
|
33
32
|
const timer: ReturnType<typeof setTimeout> = setTimeout(() => onInput(), 100)
|
|
34
33
|
|
|
@@ -49,7 +48,7 @@ export const Textarea: FC<TextareaProps> = (props) => {
|
|
|
49
48
|
)}
|
|
50
49
|
<textarea
|
|
51
50
|
{...goodProps}
|
|
52
|
-
ref={
|
|
51
|
+
ref={internalRef}
|
|
53
52
|
id={htmlFor}
|
|
54
53
|
rows={goodProps.rows ?? 4}
|
|
55
54
|
onInput={onInput}
|
|
@@ -64,4 +63,6 @@ export const Textarea: FC<TextareaProps> = (props) => {
|
|
|
64
63
|
)}
|
|
65
64
|
</div>
|
|
66
65
|
)
|
|
67
|
-
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
Textarea.displayName = "Textarea"
|
package/components/Tile/Tile.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useRef, useEffect, useMemo,
|
|
3
|
+
import { useRef, useEffect, useMemo, useId, type FC } from "react"
|
|
4
4
|
import { getClasses } from "@heliosgraphics/utils"
|
|
5
5
|
import styles from "./Tooltip.module.css"
|
|
6
6
|
import type { TooltipProps, TooltipComposition, TooltipContextType } from "./Tooltip.types"
|
|
@@ -20,7 +20,6 @@ const POSITION_CLASS_MAP = {
|
|
|
20
20
|
} as const satisfies Record<NonNullable<TooltipProps["position"]>, string | undefined>
|
|
21
21
|
|
|
22
22
|
const TooltipComponent: FC<TooltipProps> = ({ children = null, position = "bottom-center", isVisible = false }) => {
|
|
23
|
-
const [isOpen, setIsOpen] = useState<boolean>(isVisible)
|
|
24
23
|
const triggerRef = useRef<HTMLDivElement | null>(null)
|
|
25
24
|
const popoverRef = useRef<HTMLDivElement | null>(null)
|
|
26
25
|
const id: string = useId()
|
|
@@ -45,27 +44,35 @@ const TooltipComponent: FC<TooltipProps> = ({ children = null, position = "botto
|
|
|
45
44
|
return
|
|
46
45
|
}
|
|
47
46
|
|
|
47
|
+
const setAriaDescribedBy = (isOpen: boolean): void => {
|
|
48
|
+
if (isOpen) {
|
|
49
|
+
trigger.setAttribute("aria-describedby", tooltipId)
|
|
50
|
+
} else {
|
|
51
|
+
trigger.removeAttribute("aria-describedby")
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
48
55
|
if (isVisible) {
|
|
49
56
|
popover.showPopover()
|
|
50
|
-
|
|
57
|
+
setAriaDescribedBy(true)
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
const handleMouseEnter = (): void => {
|
|
54
61
|
popover.showPopover()
|
|
55
|
-
|
|
62
|
+
setAriaDescribedBy(true)
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
const handleMouseLeave = (): void => {
|
|
59
66
|
if (!isVisible) {
|
|
60
67
|
popover.hidePopover()
|
|
61
|
-
|
|
68
|
+
setAriaDescribedBy(false)
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
71
|
|
|
65
72
|
const handleKeyDown = (event: KeyboardEvent): void => {
|
|
66
73
|
if (event.key === "Escape") {
|
|
67
74
|
popover.hidePopover()
|
|
68
|
-
|
|
75
|
+
setAriaDescribedBy(false)
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
78
|
|
|
@@ -78,7 +85,7 @@ const TooltipComponent: FC<TooltipProps> = ({ children = null, position = "botto
|
|
|
78
85
|
trigger.removeEventListener("mouseleave", handleMouseLeave)
|
|
79
86
|
trigger.removeEventListener("keydown", handleKeyDown)
|
|
80
87
|
}
|
|
81
|
-
}, [isVisible])
|
|
88
|
+
}, [isVisible, tooltipId])
|
|
82
89
|
|
|
83
90
|
const contextValue: TooltipContextType = useMemo(
|
|
84
91
|
() => ({
|
|
@@ -87,9 +94,8 @@ const TooltipComponent: FC<TooltipProps> = ({ children = null, position = "botto
|
|
|
87
94
|
tooltipClasses,
|
|
88
95
|
anchorName,
|
|
89
96
|
tooltipId,
|
|
90
|
-
isOpen,
|
|
91
97
|
}),
|
|
92
|
-
[tooltipClasses, anchorName, tooltipId
|
|
98
|
+
[tooltipClasses, anchorName, tooltipId],
|
|
93
99
|
)
|
|
94
100
|
|
|
95
101
|
return (
|
|
@@ -105,3 +111,5 @@ export const Tooltip: FC<TooltipProps> & TooltipComposition = Object.assign(Tool
|
|
|
105
111
|
Trigger: TooltipTrigger,
|
|
106
112
|
Content: TooltipContent,
|
|
107
113
|
})
|
|
114
|
+
|
|
115
|
+
Tooltip.displayName = "Tooltip"
|
|
@@ -5,13 +5,15 @@ import { useTooltipContext } from "../../Tooltip.utils"
|
|
|
5
5
|
import type { CSSProperties, FC } from "react"
|
|
6
6
|
|
|
7
7
|
export const TooltipTrigger: FC<TooltipTriggerProps> = ({ children }) => {
|
|
8
|
-
const { triggerRef, anchorName
|
|
8
|
+
const { triggerRef, anchorName } = useTooltipContext()
|
|
9
9
|
|
|
10
10
|
const triggerStyle: CSSProperties = { anchorName } as CSSProperties
|
|
11
11
|
|
|
12
12
|
return (
|
|
13
|
-
<div ref={triggerRef} style={triggerStyle}
|
|
13
|
+
<div ref={triggerRef} style={triggerStyle}>
|
|
14
14
|
{children}
|
|
15
15
|
</div>
|
|
16
16
|
)
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
TooltipTrigger.displayName = "TooltipTrigger"
|
|
@@ -4,7 +4,7 @@ import { Flex } from "../../Flex"
|
|
|
4
4
|
import { Icon } from "../../Icon"
|
|
5
5
|
import { Text } from "../../Text"
|
|
6
6
|
import styles from "./ResultList.module.css"
|
|
7
|
-
import type {
|
|
7
|
+
import type { ChangeEventHandler, FC } from "react"
|
|
8
8
|
import type { ResultListProps } from "./ResultList.types"
|
|
9
9
|
|
|
10
10
|
export const ResultList: FC<ResultListProps> = ({ items, isHidden, ref }) => {
|
|
@@ -24,9 +24,9 @@ export const ResultList: FC<ResultListProps> = ({ items, isHidden, ref }) => {
|
|
|
24
24
|
if (item.type === "separator") return <li key={itemKey} className={styles.resultList__separator} />
|
|
25
25
|
|
|
26
26
|
if (item.type === "checkbox") {
|
|
27
|
-
const onCheck
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const onCheck: ChangeEventHandler<HTMLInputElement> = (): void => {
|
|
28
|
+
item.onClick?.({} as React.MouseEvent)
|
|
29
|
+
}
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<li key={itemKey} onClick={item.onClick} className={itemClasses}>
|
|
@@ -63,3 +63,5 @@ export const ResultList: FC<ResultListProps> = ({ items, isHidden, ref }) => {
|
|
|
63
63
|
</ol>
|
|
64
64
|
)
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
ResultList.displayName = "ResultList"
|
|
@@ -15,44 +15,37 @@ type LayoutProviderProps = PropsWithChildren<LayoutProviderBaseProps>
|
|
|
15
15
|
|
|
16
16
|
const LayoutProvider: FC<LayoutProviderProps> = ({ children, breakpoint = 960 }) => {
|
|
17
17
|
const [isMenuVisible, setIsMenuVisible] = useState<boolean>(false)
|
|
18
|
-
const [
|
|
18
|
+
const [isWideEnough, setIsWideEnough] = useState<boolean>(false)
|
|
19
19
|
const [hasMounted, setHasMounted] = useState<boolean>(false)
|
|
20
20
|
const asideRef = useRef<HTMLElement | null>(null)
|
|
21
21
|
const isMenuVisibleRef = useRef<boolean>(false)
|
|
22
|
-
const windowWidthRef = useRef<number>(0)
|
|
23
|
-
const resizeTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
24
22
|
|
|
25
23
|
useEffect(() => {
|
|
26
24
|
isMenuVisibleRef.current = isMenuVisible
|
|
27
25
|
}, [isMenuVisible])
|
|
28
26
|
|
|
29
27
|
useEffect(() => {
|
|
30
|
-
const initialWidth = globalThis.innerWidth
|
|
31
|
-
|
|
32
28
|
setHasMounted(true)
|
|
33
|
-
setWindowWidth(initialWidth)
|
|
34
|
-
windowWidthRef.current = initialWidth
|
|
35
|
-
|
|
36
|
-
const initialMenuVisible = initialWidth >= breakpoint
|
|
37
29
|
|
|
38
|
-
|
|
39
|
-
isMenuVisibleRef.current = initialMenuVisible
|
|
30
|
+
const mql = globalThis.matchMedia(`(min-width: ${breakpoint}px)`)
|
|
40
31
|
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
const wasWideEnough: boolean = windowWidthRef.current >= breakpoint
|
|
44
|
-
const isNowWideEnough: boolean = newWidth >= breakpoint
|
|
32
|
+
const handleChange = (event: MediaQueryListEvent | MediaQueryList): void => {
|
|
33
|
+
const matches = event.matches
|
|
45
34
|
|
|
46
|
-
|
|
47
|
-
windowWidthRef.current = newWidth
|
|
35
|
+
setIsWideEnough(matches)
|
|
48
36
|
|
|
49
|
-
if (
|
|
37
|
+
if (matches) {
|
|
50
38
|
setIsMenuVisible(true)
|
|
51
|
-
} else
|
|
39
|
+
} else {
|
|
52
40
|
setIsMenuVisible(false)
|
|
53
41
|
}
|
|
54
42
|
}
|
|
55
43
|
|
|
44
|
+
// Set initial state
|
|
45
|
+
handleChange(mql)
|
|
46
|
+
|
|
47
|
+
mql.addEventListener("change", handleChange)
|
|
48
|
+
|
|
56
49
|
const handleClickOutside = (event: MouseEvent): void => {
|
|
57
50
|
if (asideRef?.current?.contains(event.target as Node)) return
|
|
58
51
|
|
|
@@ -60,7 +53,7 @@ const LayoutProvider: FC<LayoutProviderProps> = ({ children, breakpoint = 960 })
|
|
|
60
53
|
const shouldIgnore: Element | null = clickedElement?.closest(`[${IGNORE_DATA_ATTRIBUTE}]`)
|
|
61
54
|
|
|
62
55
|
if (!shouldIgnore) {
|
|
63
|
-
const currentIsWideEnough: boolean =
|
|
56
|
+
const currentIsWideEnough: boolean = mql.matches
|
|
64
57
|
|
|
65
58
|
if (!currentIsWideEnough && isMenuVisibleRef.current) {
|
|
66
59
|
setIsMenuVisible(false)
|
|
@@ -68,25 +61,14 @@ const LayoutProvider: FC<LayoutProviderProps> = ({ children, breakpoint = 960 })
|
|
|
68
61
|
}
|
|
69
62
|
}
|
|
70
63
|
|
|
71
|
-
const throttledResize = (): void => {
|
|
72
|
-
if (resizeTimerRef.current) return
|
|
73
|
-
resizeTimerRef.current = setTimeout(() => {
|
|
74
|
-
handleResize()
|
|
75
|
-
resizeTimerRef.current = null
|
|
76
|
-
}, 150)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
globalThis.addEventListener("resize", throttledResize)
|
|
80
64
|
globalThis.document.addEventListener("mousedown", handleClickOutside)
|
|
81
65
|
|
|
82
66
|
return (): void => {
|
|
83
|
-
|
|
84
|
-
globalThis.removeEventListener("resize", throttledResize)
|
|
67
|
+
mql.removeEventListener("change", handleChange)
|
|
85
68
|
globalThis.document.removeEventListener("mousedown", handleClickOutside)
|
|
86
69
|
}
|
|
87
70
|
}, [breakpoint])
|
|
88
71
|
|
|
89
|
-
const isWideEnough: boolean = hasMounted ? windowWidth >= breakpoint : false
|
|
90
72
|
const shouldShowNavigation: boolean = isWideEnough || isMenuVisible
|
|
91
73
|
|
|
92
74
|
const onNavigationToggle = useCallback((): void => setIsMenuVisible((prev) => !prev), [])
|
|
@@ -101,9 +83,8 @@ const LayoutProvider: FC<LayoutProviderProps> = ({ children, breakpoint = 960 })
|
|
|
101
83
|
onAsideClose,
|
|
102
84
|
onNavigationToggle,
|
|
103
85
|
shouldShowNavigation,
|
|
104
|
-
windowWidth,
|
|
105
86
|
}),
|
|
106
|
-
[hasMounted, isMenuVisible, isWideEnough, shouldShowNavigation, onAsideClose, onNavigationToggle
|
|
87
|
+
[hasMounted, isMenuVisible, isWideEnough, shouldShowNavigation, onAsideClose, onNavigationToggle],
|
|
107
88
|
)
|
|
108
89
|
|
|
109
90
|
return <LayoutContext.Provider value={contextValue}>{children}</LayoutContext.Provider>
|