Skip to content

Commit

Permalink
feat: add new splitBoxModelStyle utility
Browse files Browse the repository at this point in the history
  • Loading branch information
jsamr committed Jun 4, 2021
1 parent 485f936 commit b1adcbc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/render-html/src/helpers/splitBoxModelStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { NativeStyleProp } from '../shared-types';

/**
* A utility to separate box model styles and other styles. Useful when one wants
* to wrap a text element in a view to benefit from padding vertical,
* borders... etc.
*
* @param styles - The native styles to split.
*/
export default function splitBoxModelStyle({
backgroundColor,
borderBottomColor,
borderBottomLeftRadius,
borderBottomRightRadius,
borderBottomWidth,
borderLeftColor,
borderLeftWidth,
borderRightColor,
borderRightWidth,
borderStyle,
borderTopColor,
borderTopLeftRadius,
borderTopRightRadius,
borderTopWidth,
paddingBottom,
paddingLeft,
paddingRight,
paddingTop,
marginBottom,
marginLeft,
marginRight,
marginTop,
...rest
}: NativeStyleProp<any>) {
return {
boxModel: {
backgroundColor,
borderBottomColor,
borderBottomLeftRadius,
borderBottomRightRadius,
borderBottomWidth,
borderLeftColor,
borderLeftWidth,
borderRightColor,
borderRightWidth,
borderStyle,
borderTopColor,
borderTopLeftRadius,
borderTopRightRadius,
borderTopWidth,
paddingBottom,
paddingLeft,
paddingRight,
paddingTop,
marginBottom,
marginLeft,
marginRight,
marginTop
},
rest
};
}
1 change: 1 addition & 0 deletions packages/render-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export { default as useTRenderEngine } from './hooks/useTRenderEngine';
export { default as useTTree } from './hooks/useTTree';
export { default as defaultRenderers } from './render/defaultRenderers';
export { default as extendRenderer } from './render/extendRenderer';
export { default as splitBoxModelStyle } from './helpers/splitBoxModelStyle';

0 comments on commit b1adcbc

Please sign in to comment.