mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* chore: Upgrade styled-components to v6 * fix: Keep pseudo-selectors attached to their parent under stylis 4
34 lines
1.0 KiB
TypeScript
34 lines
1.0 KiB
TypeScript
import isPropValid from "@emotion/is-prop-valid";
|
|
import type { ComponentProps, ReactNode } from "react";
|
|
import { StyleSheetManager, type WebTarget } from "styled-components";
|
|
|
|
interface Props {
|
|
/** The content to render. */
|
|
children: ReactNode;
|
|
/** An optional sheet to collect styles into, used for server rendering. */
|
|
sheet?: ComponentProps<typeof StyleSheetManager>["sheet"];
|
|
}
|
|
|
|
/**
|
|
* Configures styled-components for a React tree. Only valid HTML attributes
|
|
* are forwarded to DOM elements, and vendor prefixes are added to CSS.
|
|
*
|
|
* @param props the component props.
|
|
* @returns the children wrapped in a configured StyleSheetManager.
|
|
*/
|
|
export function StyleSheetProvider({ children, sheet }: Props) {
|
|
return (
|
|
<StyleSheetManager
|
|
sheet={sheet}
|
|
shouldForwardProp={shouldForwardProp}
|
|
enableVendorPrefixes
|
|
>
|
|
{children}
|
|
</StyleSheetManager>
|
|
);
|
|
}
|
|
|
|
function shouldForwardProp(prop: string, target: WebTarget) {
|
|
return typeof target === "string" ? isPropValid(prop) : true;
|
|
}
|