addons/components/ThemedComponentsRoot.tsxblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {ReactNode} from 'react';
b69ab319
b69ab3110import * as stylex from '@stylexjs/stylex';
b69ab3111import {light} from './theme/tokens.stylex';
b69ab3112
b69ab3113type Writable<T> = {-readonly [P in keyof T]: T[P]};
b69ab3114export function ThemedComponentsRoot({
b69ab3115 theme,
b69ab3116 className,
b69ab3117 children,
b69ab3118}: {
b69ab3119 theme: 'light' | 'dark';
b69ab3120 className?: string;
b69ab3121 children: ReactNode;
b69ab3122}) {
b69ab3123 const props = stylex.props(theme === 'light' && light);
b69ab3124 // stylex would overwrite className
b69ab3125 (props as Writable<typeof props>).className += ` ${className ?? ''} ${theme}-theme`;
b69ab3126 return <div {...props}>{children}</div>;
b69ab3127}