@cerberus-design/react 0.0.1-next-e57a52b → 0.0.1-next-07911db
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/build/legacy/_tsup-dts-rollup.d.cts +57 -24
- package/build/legacy/_tsup-dts-rollup.d.ts +57 -24
- package/build/legacy/aria-helpers/nav-menu.aria.cjs.map +1 -1
- package/build/legacy/aria-helpers/nav-menu.aria.js.map +1 -1
- package/build/legacy/components/Button.cjs.map +1 -1
- package/build/legacy/components/Button.js.map +1 -1
- package/build/legacy/components/NavMenuLink.cjs.map +1 -1
- package/build/legacy/components/NavMenuLink.js.map +1 -1
- package/build/legacy/components/NavMenuList.cjs.map +1 -1
- package/build/legacy/components/NavMenuList.js.map +1 -1
- package/build/legacy/components/NavMenuTrigger.cjs.map +1 -1
- package/build/legacy/components/NavMenuTrigger.js.map +1 -1
- package/build/legacy/components/Show.cjs.map +1 -1
- package/build/legacy/components/Show.js.map +1 -1
- package/build/legacy/context/navMenu.cjs.map +1 -1
- package/build/legacy/context/navMenu.js.map +1 -1
- package/build/legacy/context/theme.cjs.map +1 -1
- package/build/legacy/context/theme.js.map +1 -1
- package/build/legacy/hooks/useTheme.cjs.map +1 -1
- package/build/legacy/hooks/useTheme.js.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.cts +57 -24
- package/build/modern/_tsup-dts-rollup.d.ts +57 -24
- package/build/modern/aria-helpers/nav-menu.aria.cjs.map +1 -1
- package/build/modern/aria-helpers/nav-menu.aria.js.map +1 -1
- package/build/modern/components/Button.cjs.map +1 -1
- package/build/modern/components/Button.js.map +1 -1
- package/build/modern/components/NavMenuLink.cjs.map +1 -1
- package/build/modern/components/NavMenuLink.js.map +1 -1
- package/build/modern/components/NavMenuList.cjs.map +1 -1
- package/build/modern/components/NavMenuList.js.map +1 -1
- package/build/modern/components/NavMenuTrigger.cjs.map +1 -1
- package/build/modern/components/NavMenuTrigger.js.map +1 -1
- package/build/modern/components/Show.cjs.map +1 -1
- package/build/modern/components/Show.js.map +1 -1
- package/build/modern/context/navMenu.cjs.map +1 -1
- package/build/modern/context/navMenu.js.map +1 -1
- package/build/modern/context/theme.cjs.map +1 -1
- package/build/modern/context/theme.js.map +1 -1
- package/build/modern/hooks/useTheme.cjs.map +1 -1
- package/build/modern/hooks/useTheme.js.map +1 -1
- package/package.json +3 -3
- package/src/aria-helpers/nav-menu.aria.ts +8 -1
- package/src/components/Button.tsx +1 -1
- package/src/components/NavMenuLink.tsx +1 -1
- package/src/components/NavMenuList.tsx +22 -4
- package/src/components/NavMenuTrigger.tsx +10 -2
- package/src/components/Show.tsx +7 -2
- package/src/context/navMenu.tsx +2 -2
- package/src/context/theme.tsx +11 -2
- package/src/hooks/useTheme.ts +2 -1
|
@@ -3,7 +3,14 @@ export interface NavTriggerAriaValues {
|
|
|
3
3
|
expanded?: boolean
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
interface NavTriggerAriaReturn {
|
|
7
|
+
['aria-controls']: string
|
|
8
|
+
['aria-expanded']: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function createNavTriggerProps(
|
|
12
|
+
values: NavTriggerAriaValues,
|
|
13
|
+
): NavTriggerAriaReturn {
|
|
7
14
|
return {
|
|
8
15
|
['aria-controls']: values.controls,
|
|
9
16
|
['aria-expanded']: values.expanded ?? false,
|
|
@@ -12,7 +12,7 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
12
12
|
* A component that allows the user to perform actions
|
|
13
13
|
* @description https://github.com/omnifed/cerberus/blob/main/packages/react/src/components/Button.tsx
|
|
14
14
|
*/
|
|
15
|
-
export function Button(props: ButtonProps) {
|
|
15
|
+
export function Button(props: ButtonProps): JSX.Element {
|
|
16
16
|
const { palette, usage, shape, ...nativeProps } = props
|
|
17
17
|
return (
|
|
18
18
|
<button
|
|
@@ -7,7 +7,7 @@ export interface NavMenuLinkProps
|
|
|
7
7
|
as?: ElementType
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function NavMenuLink(props: NavMenuLinkProps) {
|
|
10
|
+
export function NavMenuLink(props: NavMenuLinkProps): JSX.Element {
|
|
11
11
|
const { as, ...nativeProps } = props
|
|
12
12
|
const hasAs = Boolean(as)
|
|
13
13
|
const AsSub: ElementType = as!
|
|
@@ -7,7 +7,14 @@ import type { Positions } from '../types'
|
|
|
7
7
|
import { cx } from '@cerberus-design/styled-system/css'
|
|
8
8
|
import { vstack } from '@cerberus-design/styled-system/patterns'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface GetPositionResult {
|
|
11
|
+
left: string
|
|
12
|
+
right: string
|
|
13
|
+
top: string
|
|
14
|
+
bottom: string
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getPosition(position: Positions): GetPositionResult {
|
|
11
18
|
const defaultPositions = {
|
|
12
19
|
left: 'auto',
|
|
13
20
|
right: 'auto',
|
|
@@ -59,14 +66,25 @@ const navListStyles = vstack({
|
|
|
59
66
|
},
|
|
60
67
|
})
|
|
61
68
|
|
|
62
|
-
// <NavMenuList />
|
|
63
|
-
|
|
64
69
|
export interface NavMenuListProps extends HTMLAttributes<HTMLUListElement> {
|
|
65
70
|
id: string
|
|
66
71
|
position?: Positions
|
|
67
72
|
}
|
|
68
73
|
|
|
69
|
-
|
|
74
|
+
/**
|
|
75
|
+
* A component that allows the user to display a menu of navigation links.
|
|
76
|
+
* @definition [Disclosure Nav](https://www.w3.org/WAI/ARIA/apg/patterns/disclosure/examples/disclosure-navigation/)
|
|
77
|
+
* @definition [NavMenu Docs](https://cerberus.digitalu.design/react/nav-menu)
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* <NavMenuList id="nav-menu-list" position="bottom">
|
|
82
|
+
* <NavMenuLink href="/home">Home</NavMenuLink>
|
|
83
|
+
* <NavMenuLink href="/about">About</NavMenuLink>
|
|
84
|
+
* </NavMenuList>
|
|
85
|
+
* ```
|
|
86
|
+
**/
|
|
87
|
+
export function NavMenuList(props: NavMenuListProps): JSX.Element {
|
|
70
88
|
const { position, ...nativeProps } = props
|
|
71
89
|
const { menuRef, expanded } = useNavMenuContext()
|
|
72
90
|
const locationStyles = useMemo(
|
|
@@ -25,9 +25,17 @@ export interface NavMenuTriggerProps
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* A component that allows the user to trigger a navigation menu.
|
|
28
|
-
* @
|
|
28
|
+
* @definition [NavMenu Docs](https://cerberus.digitalu.design/react/nav-menu)
|
|
29
|
+
* @example
|
|
30
|
+
* ```tsx
|
|
31
|
+
* <NavMenu>
|
|
32
|
+
* <NavMenuTrigger controls="nav-menu-list">
|
|
33
|
+
* Menu
|
|
34
|
+
* </NavMenuTrigger>
|
|
35
|
+
* </NavMenu>
|
|
36
|
+
* ```
|
|
29
37
|
*/
|
|
30
|
-
export function NavMenuTrigger(props: NavMenuTriggerProps) {
|
|
38
|
+
export function NavMenuTrigger(props: NavMenuTriggerProps): JSX.Element {
|
|
31
39
|
const {
|
|
32
40
|
as,
|
|
33
41
|
palette,
|
package/src/components/Show.tsx
CHANGED
|
@@ -10,9 +10,14 @@ export interface ShowProps {
|
|
|
10
10
|
/**
|
|
11
11
|
* Conditionally render its children or an optional fallback component
|
|
12
12
|
* based on the SolidJS component.
|
|
13
|
-
* @
|
|
13
|
+
* @definition [Show docs](https://cerberus.digitalu.design/react/show)
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* <Show when={condition}>
|
|
17
|
+
* <div>Content</div>
|
|
18
|
+
* </Show>
|
|
14
19
|
*/
|
|
15
|
-
export function Show(props: PropsWithChildren<ShowProps>) {
|
|
20
|
+
export function Show(props: PropsWithChildren<ShowProps>): ReactNode {
|
|
16
21
|
const { when, children, fallback } = props
|
|
17
22
|
const condition = useMemo(() => when ?? false, [when])
|
|
18
23
|
|
package/src/context/navMenu.tsx
CHANGED
|
@@ -24,7 +24,7 @@ export interface NavMenuContextValue {
|
|
|
24
24
|
|
|
25
25
|
const NavMenuContext = createContext<NavMenuContextValue | null>(null)
|
|
26
26
|
|
|
27
|
-
export function NavMenu(props: PropsWithChildren) {
|
|
27
|
+
export function NavMenu(props: PropsWithChildren): JSX.Element {
|
|
28
28
|
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
29
29
|
const menuRef = useRef<HTMLUListElement>(null)
|
|
30
30
|
const [expanded, setExpanded] = useState<boolean>(false)
|
|
@@ -56,7 +56,7 @@ export function NavMenu(props: PropsWithChildren) {
|
|
|
56
56
|
)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
export function useNavMenuContext() {
|
|
59
|
+
export function useNavMenuContext(): NavMenuContextValue {
|
|
60
60
|
const context = useContext(NavMenuContext)
|
|
61
61
|
if (!context) {
|
|
62
62
|
throw new Error('useNavMenuContext must be used within a NavMenu.')
|
package/src/context/theme.tsx
CHANGED
|
@@ -7,7 +7,7 @@ export type DefaultThemes = 'cerberus'
|
|
|
7
7
|
export type CustomThemes<K extends string = DefaultThemes> = 'cerberus' | K
|
|
8
8
|
export type ColorModes = 'light' | 'dark'
|
|
9
9
|
|
|
10
|
-
export interface ThemeContextValue<T extends DefaultThemes> {
|
|
10
|
+
export interface ThemeContextValue<T extends string = DefaultThemes> {
|
|
11
11
|
theme: CustomThemes<T>
|
|
12
12
|
mode: ColorModes
|
|
13
13
|
updateTheme: (theme: T) => void
|
|
@@ -21,7 +21,16 @@ const ThemeContext = createContext<ThemeContextValue<DefaultThemes> | null>(
|
|
|
21
21
|
null,
|
|
22
22
|
)
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* A context provider that allows the user to set the theme and mode of the application.
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* <ThemeProvider>
|
|
29
|
+
* <App />
|
|
30
|
+
* </ThemeProvider>
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function ThemeProvider(props: PropsWithChildren<unknown>): JSX.Element {
|
|
25
34
|
const state = useTheme()
|
|
26
35
|
return (
|
|
27
36
|
<ThemeContext.Provider value={state}>
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -13,12 +13,13 @@ import {
|
|
|
13
13
|
type ColorModes,
|
|
14
14
|
type CustomThemes,
|
|
15
15
|
type DefaultThemes,
|
|
16
|
+
type ThemeContextValue,
|
|
16
17
|
} from '../context/theme'
|
|
17
18
|
|
|
18
19
|
export function useTheme<C extends string = DefaultThemes>(
|
|
19
20
|
defaultTheme: CustomThemes<C> = 'cerberus',
|
|
20
21
|
defaultColorMode: ColorModes = 'light',
|
|
21
|
-
) {
|
|
22
|
+
): ThemeContextValue<C> {
|
|
22
23
|
const [theme, setTheme] = useState<CustomThemes<C>>(defaultTheme)
|
|
23
24
|
const [colorMode, setColorMode] = useState<ColorModes>(defaultColorMode)
|
|
24
25
|
|