@heliosgraphics/ui 2.0.0-alpha.73 → 2.0.0-alpha.75

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.
@@ -9,7 +9,7 @@
9
9
  width: 580px;
10
10
 
11
11
  border: 0;
12
- border-radius: var(--radius-lg);
12
+ border-radius: var(--radius-lg) 0 0 var(--radius-lg);
13
13
  touch-action: pan-y;
14
14
  transform: translateX(-50%);
15
15
  }
@@ -29,11 +29,6 @@
29
29
  transform: translateX(-50%) translateY(-50%);
30
30
  }
31
31
 
32
- .dialog::-webkit-scrollbar {
33
- height: 8px;
34
- width: 8px;
35
- }
36
-
37
32
  .dialog__content {
38
33
  position: relative;
39
34
  z-index: var(--z-index-1);
@@ -60,8 +55,6 @@
60
55
 
61
56
  @media (max-width: 576px) {
62
57
  .dialog:not(.dialogCentered) {
63
- margin-left: 8px;
64
- margin-right: 8px;
65
58
  width: calc(100% - 16px);
66
59
  }
67
60
 
@@ -4,6 +4,11 @@ import { getFlexUtility, getSafeFlexProps } from "../../../../../Flex/Flex.utils
4
4
  import { getClasses } from "@heliosgraphics/utils/classnames"
5
5
  import styles from "./LayoutMainContent.module.css"
6
6
  import { useLayoutEffect, useRef, type FC } from "react"
7
+ import {
8
+ initLocationTracker,
9
+ shouldResetScrollOnLocationChange,
10
+ subscribeToLocationChanges,
11
+ } from "./LayoutMainContent.utils"
7
12
  import type { LayoutMainContentProps } from "./LayoutMainContent.types"
8
13
 
9
14
  export const LayoutMainContent: FC<LayoutMainContentProps> = (props) => {
@@ -16,11 +21,17 @@ export const LayoutMainContent: FC<LayoutMainContentProps> = (props) => {
16
21
  const mainContentClasses: string = getClasses(layoutMainFlexClasses, styles.layoutMainContent, "ui-bg-secondary")
17
22
  const safeProps = getSafeFlexProps(props)
18
23
 
19
- useLayoutEffect(() => {
20
- if (contentRef.current) {
21
- contentRef.current.scrollTo(0, 0)
24
+ useLayoutEffect((): (() => void) => {
25
+ const onLocationChange = (): void => {
26
+ if (shouldResetScrollOnLocationChange()) {
27
+ contentRef.current?.scrollTo(0, 0)
28
+ }
22
29
  }
23
- }, [props.children])
30
+
31
+ initLocationTracker()
32
+
33
+ return subscribeToLocationChanges(onLocationChange)
34
+ })
24
35
 
25
36
  return (
26
37
  <section {...safeProps} ref={contentRef} className={mainContentClasses} data-ui-component="Main.Content">
@@ -0,0 +1,65 @@
1
+ "use client"
2
+
3
+ let lastLocation: string | null = null
4
+ let isHistoryPatched: boolean = false
5
+
6
+ const getLocationKey = (): string | null => {
7
+ if (!globalThis?.location) return null
8
+
9
+ return `${globalThis.location.pathname}${globalThis.location.search}${globalThis.location.hash}`
10
+ }
11
+
12
+ const patchHistory = (): void => {
13
+ if (isHistoryPatched || !globalThis?.history) return
14
+
15
+ isHistoryPatched = true
16
+
17
+ const { pushState, replaceState } = globalThis.history
18
+ const dispatchLocationChange = (): void => {
19
+ globalThis.dispatchEvent(new Event("locationchange"))
20
+ }
21
+
22
+ const pushStateWrapper = (...args: Parameters<History["pushState"]>): ReturnType<History["pushState"]> => {
23
+ const result = pushState.apply(globalThis.history, args as Parameters<History["pushState"]>)
24
+ dispatchLocationChange()
25
+ return result
26
+ }
27
+
28
+ const replaceStateWrapper = (...args: Parameters<History["replaceState"]>): ReturnType<History["replaceState"]> => {
29
+ const result = replaceState.apply(globalThis.history, args as Parameters<History["replaceState"]>)
30
+ dispatchLocationChange()
31
+ return result
32
+ }
33
+
34
+ globalThis.history.pushState = pushStateWrapper
35
+ globalThis.history.replaceState = replaceStateWrapper
36
+
37
+ globalThis.addEventListener("popstate", dispatchLocationChange)
38
+ globalThis.addEventListener("hashchange", dispatchLocationChange)
39
+ }
40
+
41
+ export const initLocationTracker = (): void => {
42
+ patchHistory()
43
+ lastLocation = getLocationKey()
44
+ }
45
+
46
+ export const shouldResetScrollOnLocationChange = (): boolean => {
47
+ const currentLocation: string | null = getLocationKey()
48
+ const shouldReset: boolean = Boolean(currentLocation && lastLocation && currentLocation !== lastLocation)
49
+
50
+ lastLocation = currentLocation
51
+
52
+ return shouldReset
53
+ }
54
+
55
+ export const subscribeToLocationChanges = (handler: () => void): (() => void) => {
56
+ patchHistory()
57
+
58
+ globalThis.addEventListener("locationchange", handler)
59
+
60
+ const unsubscribe = (): void => {
61
+ globalThis.removeEventListener("locationchange", handler)
62
+ }
63
+
64
+ return unsubscribe
65
+ }
@@ -6,7 +6,7 @@ import type { FC } from "react"
6
6
  export const Shimmer: FC<ShimmerProps> = ({ isRounded, paddingTop, paddingBottom, height, width }) => {
7
7
  const shimmerDivClasses: string = getClasses({
8
8
  ["radius-max"]: isRounded,
9
- ["radius-small"]: !isRounded,
9
+ ["radius-sm"]: !isRounded,
10
10
  })
11
11
 
12
12
  return (
@@ -54,17 +54,17 @@
54
54
 
55
55
  /* scrollbar */
56
56
  .ui-scrollbar::-webkit-scrollbar {
57
- height: 10px;
58
- width: 10px;
57
+ height: 8px;
58
+ width: 8px;
59
59
  }
60
60
 
61
61
  .ui-scrollbar--narrow::-webkit-scrollbar {
62
- height: 6px;
63
- width: 6px;
62
+ height: 4px;
63
+ width: 4px;
64
64
  }
65
65
 
66
- .ui-scrollbar::-webkit-scrollbar-corner {
67
- background-color: var(--ui-bg-disabled-gray);
66
+ .ui-scrollbar::-webkit-scrollbar-track {
67
+ background-color: var(--ui-bg-tertiary);
68
68
  }
69
69
 
70
70
  .ui-scrollbar::-webkit-scrollbar-thumb {
@@ -75,10 +75,6 @@
75
75
  transition: all var(--speed-sm) var(--ease-in-out-sine);
76
76
  }
77
77
 
78
- .ui-scrollbar::-webkit-scrollbar-track {
79
- background-color: var(--ui-bg-soft-gray);
80
- }
81
-
82
78
  .ui-scrollbar::-webkit-scrollbar-thumb:hover {
83
79
  background-color: var(--ui-bg-secondary);
84
80
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosgraphics/ui",
3
- "version": "2.0.0-alpha.73",
3
+ "version": "2.0.0-alpha.75",
4
4
  "type": "module",
5
5
  "author": "Chris Puska <chris@puska.org>",
6
6
  "private": false,
package/types/scale.ts CHANGED
@@ -3,6 +3,7 @@ export type HeliosScaleType =
3
3
  | 0
4
4
  | 1
5
5
  | 2
6
+ | 3
6
7
  | 4
7
8
  | 6
8
9
  | 8