@chronogrove/ui 0.76.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.
Files changed (70) hide show
  1. package/.turbo/turbo-test$colon$coverage.log +44 -0
  2. package/.turbo/turbo-test.log +168 -0
  3. package/LICENSE +9 -0
  4. package/README.md +41 -0
  5. package/babel.config.cjs +9 -0
  6. package/coverage/clover.xml +131 -0
  7. package/coverage/coverage-final.json +13 -0
  8. package/coverage/lcov-report/base.css +224 -0
  9. package/coverage/lcov-report/block-navigation.js +87 -0
  10. package/coverage/lcov-report/browser-sync.js.html +268 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +161 -0
  13. package/coverage/lcov-report/prettify.css +1 -0
  14. package/coverage/lcov-report/prettify.js +2 -0
  15. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  16. package/coverage/lcov-report/sorter.js +210 -0
  17. package/coverage/lcov-report/src/button.js.html +160 -0
  18. package/coverage/lcov-report/src/color-mode/browser-sync.js.html +268 -0
  19. package/coverage/lcov-report/src/color-mode/constants.js.html +121 -0
  20. package/coverage/lcov-report/src/color-mode/head-inline.js.html +304 -0
  21. package/coverage/lcov-report/src/color-mode/index.html +176 -0
  22. package/coverage/lcov-report/src/color-mode/index.js.html +124 -0
  23. package/coverage/lcov-report/src/color-mode/normalize.js.html +112 -0
  24. package/coverage/lcov-report/src/color-mode/resolve-theme-colors.js.html +154 -0
  25. package/coverage/lcov-report/src/color-toggle.js.html +142 -0
  26. package/coverage/lcov-report/src/emotion-cache.js.html +151 -0
  27. package/coverage/lcov-report/src/helpers/index.html +116 -0
  28. package/coverage/lcov-report/src/helpers/isDarkMode.js.html +91 -0
  29. package/coverage/lcov-report/src/index.html +161 -0
  30. package/coverage/lcov-report/src/provider.js.html +124 -0
  31. package/coverage/lcov-report/src/skip-nav/SkipNavContent.js.html +133 -0
  32. package/coverage/lcov-report/src/skip-nav/SkipNavLink.js.html +301 -0
  33. package/coverage/lcov-report/src/skip-nav/index.html +131 -0
  34. package/coverage/lcov-report/src/theme.js.html +2143 -0
  35. package/coverage/lcov.info +309 -0
  36. package/jest.config.cjs +32 -0
  37. package/jest.setup.cjs +1 -0
  38. package/package.json +73 -0
  39. package/src/__snapshots__/theme.spec.js.snap +1027 -0
  40. package/src/button.js +25 -0
  41. package/src/button.spec.js +16 -0
  42. package/src/color-mode/browser-sync.js +61 -0
  43. package/src/color-mode/browser-sync.node.spec.js +15 -0
  44. package/src/color-mode/browser-sync.spec.js +137 -0
  45. package/src/color-mode/constants.js +12 -0
  46. package/src/color-mode/head-inline.js +73 -0
  47. package/src/color-mode/head-inline.spec.js +33 -0
  48. package/src/color-mode/index.js +13 -0
  49. package/src/color-mode/normalize.js +9 -0
  50. package/src/color-mode/normalize.spec.js +17 -0
  51. package/src/color-mode/resolve-theme-colors.js +23 -0
  52. package/src/color-mode/resolve-theme-colors.spec.js +39 -0
  53. package/src/color-toggle.js +19 -0
  54. package/src/color-toggle.spec.js +35 -0
  55. package/src/emotion-cache.js +22 -0
  56. package/src/emotion-cache.spec.js +30 -0
  57. package/src/helpers/isDarkMode.js +2 -0
  58. package/src/helpers/isDarkMode.spec.js +9 -0
  59. package/src/index.js +1 -0
  60. package/src/provider.js +13 -0
  61. package/src/provider.spec.js +25 -0
  62. package/src/skip-nav/SkipNavContent.js +16 -0
  63. package/src/skip-nav/SkipNavContent.spec.js +22 -0
  64. package/src/skip-nav/SkipNavLink.js +72 -0
  65. package/src/skip-nav/SkipNavLink.spec.js +56 -0
  66. package/src/skip-nav/index.js +2 -0
  67. package/src/theme.js +686 -0
  68. package/src/theme.spec.js +56 -0
  69. package/test-utils/mock-theme-toggles-react.js +10 -0
  70. package/turbo.json +12 -0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import React from 'react'
6
+ import { render, screen } from '@testing-library/react'
7
+ import SkipNavContent from './SkipNavContent'
8
+
9
+ describe('SkipNavContent', () => {
10
+ it('renders target region with id and data attribute', () => {
11
+ render(
12
+ <SkipNavContent>
13
+ <span>main</span>
14
+ </SkipNavContent>
15
+ )
16
+ const region = document.getElementById('skip-nav-content')
17
+ expect(region).not.toBeNull()
18
+ expect(region).toHaveAttribute('data-skip-nav-content', '')
19
+ expect(region).toHaveAttribute('tabIndex', '-1')
20
+ expect(screen.getByText('main')).toBeInTheDocument()
21
+ })
22
+ })
@@ -0,0 +1,72 @@
1
+ /** @jsx jsx */
2
+ import { jsx, useThemeUI } from 'theme-ui'
3
+ import { forwardRef } from 'react'
4
+ import isDarkMode from '@chronogrove/ui/is-dark-mode'
5
+
6
+ const SkipNavLink = forwardRef(function SkipNavLink(
7
+ { as: Comp = 'a', children = 'Skip to content', contentId = 'skip-nav-content', ...props },
8
+ forwardedRef
9
+ ) {
10
+ const { colorMode, theme } = useThemeUI()
11
+ const darkModeActive = isDarkMode(colorMode)
12
+ const primaryColor = theme?.colors?.primary ?? (darkModeActive ? '#4a9eff' : '#422EA3')
13
+ const primaryRgb = theme?.colors?.primaryRgb ?? (darkModeActive ? '74, 158, 255' : '66, 46, 163')
14
+
15
+ return (
16
+ <Comp
17
+ {...props}
18
+ ref={forwardedRef}
19
+ href={`#${contentId}`}
20
+ data-skip-nav-link=''
21
+ tabIndex={0}
22
+ sx={{
23
+ border: 0,
24
+ clip: 'rect(0 0 0 0)',
25
+ height: '1px',
26
+ width: '1px',
27
+ margin: '-1px',
28
+ padding: 0,
29
+ overflow: 'hidden',
30
+ position: 'absolute',
31
+ whiteSpace: 'nowrap',
32
+ wordWrap: 'normal',
33
+ '&:focus': {
34
+ clip: 'auto',
35
+ height: 'auto',
36
+ width: 'auto',
37
+ margin: 0,
38
+ overflow: 'visible',
39
+ whiteSpace: 'normal',
40
+ position: 'fixed',
41
+ top: 3,
42
+ left: 3,
43
+ zIndex: 9999,
44
+ color: primaryColor,
45
+ textDecoration: 'none',
46
+ fontWeight: 'medium',
47
+ fontSize: ['12px', '13px'],
48
+ display: 'inline-flex',
49
+ alignItems: 'center',
50
+ padding: '8px 12px',
51
+ borderRadius: '6px',
52
+ background: `rgba(${primaryRgb}, 0.15)`,
53
+ border: `1px solid rgba(${primaryRgb}, 0.3)`,
54
+ cursor: 'pointer',
55
+ outline: 'none',
56
+ boxShadow: `0 0 0 2px ${primaryColor}40`,
57
+ backdropFilter: 'blur(8px)',
58
+ '&:hover': {
59
+ background: `rgba(${primaryRgb}, 0.25)`,
60
+ textDecoration: 'none'
61
+ }
62
+ }
63
+ }}
64
+ >
65
+ {children}
66
+ </Comp>
67
+ )
68
+ })
69
+
70
+ SkipNavLink.displayName = 'SkipNavLink'
71
+
72
+ export default SkipNavLink
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
4
+
5
+ import React from 'react'
6
+ import { render, screen } from '@testing-library/react'
7
+ import { ThemeUIProvider } from 'theme-ui'
8
+ import SkipNavLink from './SkipNavLink'
9
+
10
+ const wrapperTheme = {
11
+ colors: {
12
+ primary: '#ff00aa',
13
+ primaryRgb: '255, 0, 170'
14
+ }
15
+ }
16
+
17
+ describe('SkipNavLink', () => {
18
+ beforeEach(() => {
19
+ window.localStorage.clear()
20
+ })
21
+
22
+ function renderLink(ui) {
23
+ return render(<ThemeUIProvider theme={wrapperTheme}>{ui}</ThemeUIProvider>)
24
+ }
25
+
26
+ it('links to skip content id and uses theme primary for focus styles context', () => {
27
+ renderLink(<SkipNavLink>Skip</SkipNavLink>)
28
+ const link = screen.getByRole('link', { name: /skip/i })
29
+ expect(link).toHaveAttribute('href', '#skip-nav-content')
30
+ expect(link).toHaveAttribute('data-skip-nav-link', '')
31
+ })
32
+
33
+ it('uses fallback colors when theme omits primary tokens', () => {
34
+ render(
35
+ <ThemeUIProvider theme={{ colors: {} }}>
36
+ <SkipNavLink>Go</SkipNavLink>
37
+ </ThemeUIProvider>
38
+ )
39
+ expect(screen.getByRole('link', { name: /go/i })).toBeInTheDocument()
40
+ })
41
+
42
+ it('uses dark-mode fallback primaries when colorMode is dark', () => {
43
+ window.localStorage.setItem('theme-ui-color-mode', 'dark')
44
+ render(
45
+ <ThemeUIProvider
46
+ theme={{
47
+ colors: {},
48
+ config: { useLocalStorage: true, useColorSchemeMediaQuery: false }
49
+ }}
50
+ >
51
+ <SkipNavLink>Go</SkipNavLink>
52
+ </ThemeUIProvider>
53
+ )
54
+ expect(screen.getByRole('link', { name: /go/i })).toBeInTheDocument()
55
+ })
56
+ })
@@ -0,0 +1,2 @@
1
+ export { default as SkipNavLink } from './SkipNavLink.js'
2
+ export { default as SkipNavContent } from './SkipNavContent.js'