Skip to content

Commit

Permalink
Add StylingBox component
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan committed Oct 22, 2024
1 parent 340beb9 commit b52884d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
34 changes: 34 additions & 0 deletions packages/fuselage/src/components/Box/StylingBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { cssFn } from '@rocket.chat/css-in-js';
import { cloneElement } from 'react';
import type { ReactElement } from 'react';

import { useArrayLikeClassNameProp } from '../../hooks/useArrayLikeClassNameProp';
import type { Falsy } from '../../types/Falsy';
import type { StylingProps } from './stylingProps';
import { useStylingProps } from './useStylingProps';

export type StylingBoxProps = {
children: ReactElement<{ className?: string }>;
className?: string | cssFn | (string | cssFn | Falsy)[];
} & Partial<StylingProps>;

/**
* Merges its `StylingProps` props into a `className` prop passed to a child element.
*
* This is intended to be used as a wrapper for components that accept styling props but don't need the weight of the
* `Box` component prop handling internally.
*/
export const StylingBox = ({ children, ...props }: StylingBoxProps) => {
const propsWithStringClassName = useArrayLikeClassNameProp(props);
propsWithStringClassName.className = [
children.props.className,
propsWithStringClassName.className,
]
.filter(Boolean)
.join(' ');
const propsWithoutStylingProps = useStylingProps(propsWithStringClassName);

return cloneElement(children, propsWithoutStylingProps);
};

export default StylingBox;
2 changes: 2 additions & 0 deletions packages/fuselage/src/components/Box/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default } from './Box';
export { default as StylingBox, type StylingBoxProps } from './StylingBox';
1 change: 0 additions & 1 deletion packages/fuselage/src/components/Box/index.tsx

This file was deleted.

0 comments on commit b52884d

Please sign in to comment.