-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file was deleted.
Oops, something went wrong.