@heliosgraphics/ui 2.0.1-alpha.8 → 2.0.1-alpha.9

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.
@@ -73,7 +73,7 @@ export const getFlexUtility = (props?: FlexProps): string => {
73
73
  export const getResponsiveScale = (value?: ResponsiveScaleType, prefix: string = "p"): string => {
74
74
  if (!value) return ""
75
75
 
76
- const isArray: boolean = Boolean(value && value instanceof Array)
76
+ const isArray: boolean = Array.isArray(value)
77
77
  const classes = new Set<string>()
78
78
 
79
79
  if (!isArray) return `${prefix}-${value}`
@@ -92,7 +92,7 @@ export const getResponsiveScale = (value?: ResponsiveScaleType, prefix: string =
92
92
  export const getPadding = (paddingValue?: ResponsiveScaleType): string => {
93
93
  if (!paddingValue) return ""
94
94
 
95
- const isArray: boolean = Boolean(paddingValue && paddingValue instanceof Array)
95
+ const isArray: boolean = Array.isArray(paddingValue)
96
96
  const paddingClasses = new Set<string>()
97
97
 
98
98
  if (!isArray) return `p-${paddingValue}`
@@ -111,7 +111,7 @@ export const getPadding = (paddingValue?: ResponsiveScaleType): string => {
111
111
  export const getRadius = (radiusValue?: ResponsiveRadiusType): string => {
112
112
  if (!radiusValue) return ""
113
113
 
114
- const isArray: boolean = Boolean(radiusValue && radiusValue instanceof Array)
114
+ const isArray: boolean = Array.isArray(radiusValue)
115
115
  const radiusClasses = new Set<string>()
116
116
 
117
117
  if (!isArray) return `radius-${radiusValue}`
@@ -32,9 +32,7 @@ export const Heading: FC<HeadingProps> = (props) => {
32
32
  const lineHeightStyle: CSSProperties | undefined = lineHeight !== undefined ? { lineHeight } : undefined
33
33
 
34
34
  const mergedStyle: CSSProperties | undefined =
35
- style || lineClampStyle || lineHeightStyle
36
- ? { ...(style || {}), ...(lineClampStyle || {}), ...(lineHeightStyle || {}) }
37
- : undefined
35
+ style || lineClampStyle || lineHeightStyle ? { ...style, ...lineClampStyle, ...lineHeightStyle } : undefined
38
36
  const safeHeadingProps: Omit<HeadingProps, "level" | "lineClamp" | "lineHeight" | "className" | "style"> =
39
37
  stripTypographyProps(rest)
40
38
 
@@ -3,6 +3,10 @@
3
3
  let lastLocation: string | null = null
4
4
  let isHistoryPatched: boolean = false
5
5
 
6
+ const dispatchLocationChange = (): void => {
7
+ globalThis.dispatchEvent(new Event("locationchange"))
8
+ }
9
+
6
10
  const getLocationKey = (): string | null => {
7
11
  if (!globalThis?.location) return null
8
12
 
@@ -15,9 +19,6 @@ const patchHistory = (): void => {
15
19
  isHistoryPatched = true
16
20
 
17
21
  const { pushState, replaceState } = globalThis.history
18
- const dispatchLocationChange = (): void => {
19
- globalThis.dispatchEvent(new Event("locationchange"))
20
- }
21
22
 
22
23
  const pushStateWrapper = (...args: Parameters<History["pushState"]>): ReturnType<History["pushState"]> => {
23
24
  const result = pushState.apply(globalThis.history, args as Parameters<History["pushState"]>)
@@ -16,7 +16,7 @@ export const meta: HeliosAttributeMeta<MarkdownProps> = {
16
16
  isOptional: true,
17
17
  description: "Children to render inside the markdown wrapper",
18
18
  },
19
- allowLinks: {
19
+ isLinksAllowed: {
20
20
  type: "boolean",
21
21
  isOptional: true,
22
22
  description: "Preserves markdown links and auto-linked URLs in sanitized output",
@@ -4,7 +4,7 @@ import styles from "./Markdown.module.css"
4
4
  import type { FC } from "react"
5
5
  import type { MarkdownProps } from "./Markdown.types"
6
6
 
7
- export const Markdown: FC<MarkdownProps> = ({ text, children, isNonSelectable, allowLinks }) => {
7
+ export const Markdown: FC<MarkdownProps> = ({ text, children, isNonSelectable, isLinksAllowed }) => {
8
8
  if (!text && !children) return null
9
9
 
10
10
  const markdownClasses: string = getClasses(styles.markdown, {
@@ -12,7 +12,7 @@ export const Markdown: FC<MarkdownProps> = ({ text, children, isNonSelectable, a
12
12
  })
13
13
 
14
14
  if (text) {
15
- const innerHTML = { __html: renderMarkdown(text, { allowLinks }) }
15
+ const innerHTML = { __html: renderMarkdown(text, { allowLinks: !!isLinksAllowed }) }
16
16
 
17
17
  return <div className={markdownClasses} dangerouslySetInnerHTML={innerHTML} data-ui-component="Markdown"></div>
18
18
  }
@@ -1,8 +1,8 @@
1
1
  import type { ReactNode } from "react"
2
2
 
3
3
  export interface MarkdownProps {
4
- allowLinks?: boolean
5
4
  children?: ReactNode
5
+ isLinksAllowed?: boolean
6
6
  isNonSelectable?: boolean
7
7
  text?: string
8
8
  }
@@ -1,61 +0,0 @@
1
- import type { HeliosFixedThemeType, HeliosThemeType } from "../../types/themes"
2
-
3
- export const code = (theme: HeliosThemeType = "system", fixedTheme?: HeliosFixedThemeType): void => {
4
- globalThis.__onThemeChange = function (_theme: HeliosFixedThemeType): void {}
5
-
6
- const setTheme = (newTheme: HeliosFixedThemeType): void => {
7
- globalThis.__theme = newTheme
8
- document.documentElement.dataset["theme"] = newTheme
9
- globalThis.__onThemeChange?.(newTheme)
10
- }
11
-
12
- const handleDocumentClick = (event: MouseEvent): void => {
13
- if (event.x > 256 && globalThis.location.hash === "#ui-menu") {
14
- globalThis.location.hash = "#ui"
15
- }
16
- }
17
-
18
- document.addEventListener("click", handleDocumentClick)
19
-
20
- const isLocked: boolean = fixedTheme !== undefined || theme !== "system"
21
-
22
- if (fixedTheme !== undefined && theme !== "system") {
23
- console.warn("Setup: Both theme and fixedTheme props are set. fixedTheme takes precedence, theme prop is ignored.")
24
- }
25
-
26
- if (isLocked) {
27
- const lockedTheme: HeliosFixedThemeType = fixedTheme ?? (theme as HeliosFixedThemeType)
28
- globalThis.__setPreferredTheme = function (_newTheme: HeliosFixedThemeType): void {}
29
- setTheme(lockedTheme)
30
- return
31
- }
32
-
33
- let preferredTheme: HeliosFixedThemeType | undefined
34
- const darkQuery: MediaQueryList = globalThis.matchMedia("(prefers-color-scheme: dark)")
35
-
36
- try {
37
- const storedTheme: string | null = globalThis.localStorage.getItem("theme")
38
- if (storedTheme === "dark" || storedTheme === "light") {
39
- preferredTheme = storedTheme
40
- }
41
- } catch (error: unknown) {
42
- console.error("failed to read theme from localStorage:", error)
43
- }
44
-
45
- globalThis.__setPreferredTheme = function (newTheme: HeliosFixedThemeType): void {
46
- try {
47
- setTheme(newTheme)
48
- globalThis.localStorage.setItem("theme", newTheme)
49
- } catch (error: unknown) {
50
- console.error("failed to set theme:", error)
51
- }
52
- }
53
-
54
- const handleDarkModeChange = (event: MediaQueryListEvent): void => {
55
- globalThis.__setPreferredTheme(event.matches ? "dark" : "light")
56
- }
57
-
58
- darkQuery.addEventListener("change", handleDarkModeChange)
59
-
60
- setTheme(preferredTheme ?? (darkQuery.matches ? "dark" : "light"))
61
- }
@@ -1,19 +1,13 @@
1
1
  import { getClasses } from "@heliosgraphics/utils"
2
2
  import { Text } from "../Text"
3
+ import { onTabKeyDown } from "./Tabs.utils"
3
4
  import styles from "./Tabs.module.css"
4
- import type { FC, KeyboardEvent } from "react"
5
+ import type { FC } from "react"
5
6
  import type { TabItem, TabsProps } from "./Tabs.types"
6
7
 
7
8
  export const Tabs: FC<TabsProps> = ({ items, children }) => {
8
9
  if (!items?.length) return null
9
10
 
10
- const onKeyDown = (event: KeyboardEvent<HTMLElement>, item: TabItem): void => {
11
- if (event.key === " " || event.key === "Enter") {
12
- event.preventDefault()
13
- item.onClick?.()
14
- }
15
- }
16
-
17
11
  return (
18
12
  <div data-ui-component="Tabs">
19
13
  <div role="tablist" className={styles.tabs__list}>
@@ -46,7 +40,7 @@ export const Tabs: FC<TabsProps> = ({ items, children }) => {
46
40
  <div
47
41
  {...commonProps}
48
42
  onClick={item.isDisabled ? undefined : item.onClick}
49
- onKeyDown={(e) => onKeyDown(e, item)}
43
+ onKeyDown={(event) => onTabKeyDown(event, item)}
50
44
  >
51
45
  <Text type="small" fontWeight="medium">
52
46
  {item.name}
@@ -0,0 +1,9 @@
1
+ import type { KeyboardEvent } from "react"
2
+ import type { TabItem } from "./Tabs.types"
3
+
4
+ export const onTabKeyDown = (event: KeyboardEvent<HTMLElement>, item: TabItem): void => {
5
+ if (event.key === " " || event.key === "Enter") {
6
+ event.preventDefault()
7
+ item.onClick?.()
8
+ }
9
+ }
@@ -28,7 +28,7 @@ export const Text: FC<TextProps> = (props) => {
28
28
  : undefined
29
29
 
30
30
  const mergedStyle: object | undefined =
31
- props.style || lineClampStyle ? { ...(props.style || {}), ...(lineClampStyle || {}) } : undefined
31
+ props.style || lineClampStyle ? { ...props.style, ...lineClampStyle } : undefined
32
32
 
33
33
  const baseTextProps: Omit<TextProps, "type"> = {
34
34
  onClick: props.onClick,
@@ -3,6 +3,8 @@
3
3
  import { useCallback, useEffect, useState } from "react"
4
4
  import type { HeliosFixedThemeType } from "../types/themes"
5
5
 
6
+ const getTheme = (): HeliosFixedThemeType => (typeof globalThis !== "undefined" ? globalThis.__theme : "light")
7
+
6
8
  export const useTheme = (): { theme: HeliosFixedThemeType; isDark: boolean; toggleTheme: () => void } => {
7
9
  const [theme, setTheme] = useState<HeliosFixedThemeType | null>(null)
8
10
 
@@ -10,8 +12,6 @@ export const useTheme = (): { theme: HeliosFixedThemeType; isDark: boolean; togg
10
12
  setTheme(getTheme())
11
13
  }, [])
12
14
 
13
- const getTheme = (): HeliosFixedThemeType => (typeof globalThis !== "undefined" ? globalThis.__theme : "light")
14
-
15
15
  const toggleTheme = useCallback(() => {
16
16
  const currentIsDark: boolean = getTheme() === "dark"
17
17
  globalThis.__setPreferredTheme?.(currentIsDark ? "light" : "dark")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliosgraphics/ui",
3
- "version": "2.0.1-alpha.8",
3
+ "version": "2.0.1-alpha.9",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "*.css",
@@ -40,9 +40,9 @@
40
40
  "ts:watch": "tsc --noEmit --incremental --watch"
41
41
  },
42
42
  "dependencies": {
43
- "@heliosgraphics/css": "^1.0.0-alpha.9",
43
+ "@heliosgraphics/css": "^1.0.0-alpha.10",
44
44
  "@heliosgraphics/icons": "^1.0.0-alpha.14",
45
- "@heliosgraphics/utils": "^6.0.0-alpha.15",
45
+ "@heliosgraphics/utils": "^6.0.0-alpha.16",
46
46
  "marked": "^17.0.5",
47
47
  "marked-linkify-it": "^3.1.14",
48
48
  "marked-xhtml": "^1.0.14",