Skip to content

Commit 7347c81

Browse files
Merge pull request #227 from commitd/stuarthendren/issue226
Minor fix and new feature in themes
2 parents 65a4065 + 558f41c commit 7347c81

File tree

8 files changed

+83
-35
lines changed

8 files changed

+83
-35
lines changed

src/components/ConfirmDialog/ConfirmDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ ConfirmDialogContent.toString = () => `.${StyledContent.className}`
117117

118118
export const ConfirmDialogTrigger = forwardRef<
119119
ElementRef<typeof Trigger>,
120-
ComponentProps<typeof Trigger>
120+
Omit<ComponentProps<typeof Trigger>, 'asChild'>
121121
>(({ children, ...props }, forwardedRef) => (
122122
<Trigger asChild {...props} ref={forwardedRef}>
123123
{children}

src/components/Dialog/Dialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const Dialog: FC<DialogProps> = ({ children, overlayCss, ...props }) => {
9090
)
9191
}
9292

93-
type DialogContentProps = ComponentProps<typeof Content> &
93+
type DialogContentProps = Omit<ComponentProps<typeof Content>, 'asChild'> &
9494
CSSProps & {
9595
/** Closable, add a standard close icon. */
9696
defaultClose?: boolean
@@ -115,7 +115,7 @@ DialogContent.toString = () => `.${StyledContent.className}`
115115

116116
export const DialogTrigger = forwardRef<
117117
ElementRef<typeof Trigger>,
118-
ComponentProps<typeof Trigger>
118+
Omit<ComponentProps<typeof Trigger>, 'asChild'>
119119
>(({ children, ...props }, forwardedRef) => (
120120
<Trigger asChild {...props} ref={forwardedRef}>
121121
{children}
@@ -124,7 +124,7 @@ export const DialogTrigger = forwardRef<
124124

125125
export const DialogClose = forwardRef<
126126
ElementRef<typeof Close>,
127-
ComponentProps<typeof Close>
127+
Omit<ComponentProps<typeof Close>, 'asChild'>
128128
>(({ children, ...props }, forwardedRef) => (
129129
<Close asChild {...props} ref={forwardedRef}>
130130
{children}

src/components/Drawer/Drawer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const StyledContent = styled(Content, paperStyles, {
8181

8282
type DrawerContentVariants = VariantProps<typeof StyledContent>
8383

84-
type DrawerContentProps = ComponentProps<typeof Content> &
84+
type DrawerContentProps = Omit<ComponentProps<typeof Content>, 'asChild'> &
8585
CSSProps &
8686
DrawerContentVariants & {
8787
/** Closable, add a standard close icon. */

src/components/Menu/Menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const MenuContent = forwardRef<
102102
))
103103
MenuContent.toString = () => `.${StyledContent.className}`
104104

105-
type MenuTriggerProps = ComponentProps<typeof Trigger>
105+
type MenuTriggerProps = Omit<ComponentProps<typeof Trigger>, 'asChild'>
106106

107107
const MENU_TRIGGER_CLASS_NAME = 'c-menu-trigger'
108108

src/components/Popover/Popover.stories.tsx

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
PopoverContent,
99
PopoverTrigger,
1010
} from '.'
11-
import { Button, Heading, Monospace, Paragraph, Svg, Text } from '../'
11+
import { Box, Button, Heading, Monospace, Paragraph, Svg, Text } from '../'
1212

1313
export default {
1414
title: 'Components/Popover',
@@ -40,13 +40,15 @@ export const Anchored: Story = (args) => (
4040
<Popover>
4141
<Text>
4242
You can use a{' '}
43-
<PopoverAnchor
44-
as="span"
45-
css={{
46-
backgroundColor: '$blue3',
47-
}}
48-
>
49-
<Monospace>PopoverAnchor</Monospace>
43+
<PopoverAnchor>
44+
<Monospace
45+
inline
46+
css={{
47+
backgroundColor: '$info3',
48+
}}
49+
>
50+
PopoverAnchor
51+
</Monospace>
5052
</PopoverAnchor>{' '}
5153
to anchor the popover to a different element{' '}
5254
<PopoverTrigger>
@@ -68,24 +70,26 @@ export const Anchored: Story = (args) => (
6870

6971
export const NestedAnchored: Story = (args) => (
7072
<Popover>
71-
<PopoverAnchor
72-
css={{
73-
display: 'flex',
74-
padding: '$4',
75-
backgroundColor: '$blue3',
76-
justifyContent: 'center',
77-
}}
78-
>
79-
<Text>
80-
The <Monospace>PopoverAnchor</Monospace> can have the trigger{' '}
81-
<PopoverTrigger>
82-
<Svg
83-
css={{ color: '$textSecondary', cursor: 'pointer', mt: '$3' }}
84-
path={mdiAlertCircleOutline}
85-
/>
86-
</PopoverTrigger>{' '}
87-
nested inside
88-
</Text>
73+
<PopoverAnchor>
74+
<Box
75+
css={{
76+
display: 'flex',
77+
padding: '$4',
78+
backgroundColor: '$info3',
79+
justifyContent: 'center',
80+
}}
81+
>
82+
<Text>
83+
The <Monospace>PopoverAnchor</Monospace> can have the trigger{' '}
84+
<PopoverTrigger>
85+
<Svg
86+
css={{ color: '$textSecondary', cursor: 'pointer', mt: '$3' }}
87+
path={mdiAlertCircleOutline}
88+
/>
89+
</PopoverTrigger>{' '}
90+
nested inside
91+
</Text>
92+
</Box>
8993
</PopoverAnchor>
9094
<PopoverContent>
9195
<Heading variant="h5">Popover content</Heading>

src/components/Popover/Popover.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const POPOVER_TRIGGER_CLASS_NAME = 'c-popover-trigger'
4747

4848
export const PopoverTrigger = forwardRef<
4949
ElementRef<typeof Trigger>,
50-
ComponentProps<typeof Trigger>
50+
Omit<ComponentProps<typeof Trigger>, 'asChild'>
5151
>(({ children, ...props }, forwardedRef) => (
5252
<Trigger
5353
className={POPOVER_TRIGGER_CLASS_NAME}
@@ -60,11 +60,28 @@ export const PopoverTrigger = forwardRef<
6060
))
6161
PopoverTrigger.toString = () => `.${POPOVER_TRIGGER_CLASS_NAME}`
6262

63+
const POPOVER_ANCHOR_CLASS_NAME = 'c-popover-anchor'
64+
65+
export const PopoverAnchor = forwardRef<
66+
ElementRef<typeof Anchor>,
67+
Omit<ComponentProps<typeof Anchor>, 'asChild'>
68+
>(({ children, ...props }, forwardedRef) => (
69+
<Anchor
70+
className={POPOVER_ANCHOR_CLASS_NAME}
71+
asChild
72+
{...props}
73+
ref={forwardedRef}
74+
>
75+
{children}
76+
</Anchor>
77+
))
78+
PopoverAnchor.toString = () => `.${POPOVER_ANCHOR_CLASS_NAME}`
79+
6380
const POPOVER_CLOSE_CLASS_NAME = 'c-popover-close'
6481

6582
export const PopoverClose = forwardRef<
6683
ElementRef<typeof Close>,
67-
ComponentProps<typeof Close>
84+
Omit<ComponentProps<typeof Close>, 'asChild'>
6885
>(({ children, ...props }, forwardedRef) => (
6986
<Close
7087
asChild
@@ -86,4 +103,3 @@ PopoverClose.toString = () => `.${POPOVER_CLOSE_CLASS_NAME}`
86103
* Built using [Radix Popover](https://radix-ui.com/primitives/docs/components/popover)
87104
*/
88105
export const Popover: FC<React.ComponentProps<typeof Root>> = Root
89-
export const PopoverAnchor = styled(Anchor, {})

src/components/ThemeProvider/ThemeController.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ export const ThemeController: React.FC<ThemeControllerProps> = ({
8383
}
8484
}
8585

86+
window
87+
.matchMedia('(prefers-color-scheme: dark)')
88+
.addEventListener('change', (e) => {
89+
setThemeValues(e.matches ? 'dark' : 'light')
90+
})
91+
92+
window
93+
.matchMedia('(prefers-color-scheme: light)')
94+
.addEventListener('change', (e) => {
95+
setThemeValues(e.matches ? 'light' : 'dark')
96+
})
97+
8698
// paints the app before it renders elements
8799
useLayoutEffect(() => {
88100
const localTheme = window.localStorage.getItem('themeChoice') as ThemeChoice

src/utils/test-utils.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
/**
23
* Import setupTests for your unit tests and you can use `renderLight` and `renderDark` to render elements wrapped in a ThemeProvider.
34
* To render without a theme provider use `renderPlain`.
@@ -18,6 +19,21 @@ import ResizeObserver from 'resize-observer-polyfill'
1819
// This is used in some components.
1920
global.ResizeObserver = ResizeObserver
2021

22+
// Official way to supply missing window method https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
23+
Object.defineProperty(window, 'matchMedia', {
24+
writable: true,
25+
value: jest.fn().mockImplementation((query: string) => ({
26+
matches: false,
27+
media: query,
28+
onchange: null,
29+
addListener: jest.fn(), // Deprecated
30+
removeListener: jest.fn(), // Deprecated
31+
addEventListener: jest.fn(),
32+
removeEventListener: jest.fn(),
33+
dispatchEvent: jest.fn(),
34+
})),
35+
})
36+
2137
const LightTheme: React.FC = ({ children }) => (
2238
<ThemeProvider choice="light">{children}</ThemeProvider>
2339
)

0 commit comments

Comments
 (0)