Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme-ui): Add sx prop to BaseStyles component #2081

Merged
merged 1 commit into from Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions packages/theme-ui/src/index.ts
@@ -1,4 +1,8 @@
import { jsx as coreJsx, ThemeUIJSX } from '@theme-ui/core'
import {
jsx as coreJsx,
ThemeUIJSX,
type ThemeUIStyleObject,
} from '@theme-ui/core'
export {
__ThemeUIContext,
merge,
Expand Down Expand Up @@ -29,14 +33,17 @@ export { ThemeProvider } from '@theme-ui/theme-provider'
export * from '@theme-ui/components'
export { css, get } from '@theme-ui/css'

export const BaseStyles = (props: Record<string, unknown>) =>
export const BaseStyles = (
props: Record<string, unknown> & { sx?: ThemeUIStyleObject }
) =>
jsx('div', {
...props,
sx: {
fontFamily: 'body',
lineHeight: 'body',
fontWeight: 'body',
variant: 'styles',
...props.sx,
},
})

Expand All @@ -50,10 +57,8 @@ export declare namespace jsx {
extends ThemeUIJSX.ElementAttributesProperty {}
export interface ElementChildrenAttribute
extends ThemeUIJSX.ElementChildrenAttribute {}
export type LibraryManagedAttributes<
C,
P
> = ThemeUIJSX.LibraryManagedAttributes<C, P>
export type LibraryManagedAttributes<C, P> =
ThemeUIJSX.LibraryManagedAttributes<C, P>
export interface IntrinsicAttributes
extends ThemeUIJSX.IntrinsicAttributes {}
export interface IntrinsicClassAttributes<T>
Expand Down
13 changes: 13 additions & 0 deletions packages/theme-ui/test/__snapshots__/index.tsx.snap
Expand Up @@ -12,6 +12,19 @@ exports[`BaseStyles renders 1`] = `
/>
`;

exports[`BaseStyles renders sx prop styles 1`] = `
.emotion-0 {
font-family: body;
line-height: body;
font-weight: body;
color: var(--theme-ui-colors-custom);
}

<div
className="emotion-0"
/>
`;

exports[`creates non-standard components 1`] = `
.emotion-0 {
color: tomato;
Expand Down
15 changes: 15 additions & 0 deletions packages/theme-ui/test/index.tsx
Expand Up @@ -217,6 +217,21 @@ test('BaseStyles renders', () => {
expect(json).toMatchSnapshot()
})

test('BaseStyles renders sx prop styles', () => {
const json = renderJSON(
<ThemeProvider
theme={{
colors: {
custom: 'tomato',
},
}}
>
<BaseStyles sx={{ color: 'custom' }} />
</ThemeProvider>
)
expect(json).toMatchSnapshot()
})

test('custom pragma adds styles', () => {
const json = renderJSON(
jsx('div', {
Expand Down