11import { FileFormat1 as FileFormat } from '@sketch-hq/sketch-file-format-ts' ;
22import { makeColorFromCSS , emptyGradient } from './models' ;
3- import { ViewStyle , LayoutInfo , BorderStyle } from '../types' ;
3+ import { ViewStyle , LayoutInfo , BorderStyle , Color } from '../types' ;
44import same from '../utils/same' ;
55import { makeVerticalBorder , makeHorizontalBorder } from './shapeLayers' ;
66import { makeBorderOptions } from './style' ;
77
88const DEFAULT_BORDER_COLOR = 'transparent' ;
9- const DEFAULT_BORDER_STYLE = 'solid' ;
9+ export const DEFAULT_BORDER_STYLE = 'solid' ;
1010
1111export const createUniformBorder = (
1212 width : number ,
13- color : string ,
14- style : BorderStyle = 'solid' ,
13+ color : Color ,
14+ style : BorderStyle = DEFAULT_BORDER_STYLE ,
1515 position : FileFormat . BorderPosition = FileFormat . BorderPosition . Center ,
1616 lineCapStyle : FileFormat . LineCapStyle = FileFormat . LineCapStyle . Butt ,
1717 lineJoinStyle : FileFormat . LineJoinStyle = FileFormat . LineJoinStyle . Miter ,
@@ -71,14 +71,14 @@ export const createBorders = (
7171 ) {
7272 // all sides have same border width
7373 // in this case, we can do everything with just a single shape.
74- if ( borderTopStyle !== undefined ) {
74+ if ( borderTopStyle !== undefined && borderTopWidth !== null ) {
7575 const borderOptions = makeBorderOptions ( borderTopStyle , borderTopWidth ) ;
7676 if ( borderOptions && content . style ) {
7777 content . style . borderOptions = borderOptions ;
7878 }
7979 }
8080
81- if ( borderTopWidth > 0 && content . style ) {
81+ if ( borderTopWidth && borderTopWidth > 0 && content . style ) {
8282 content . style . borders = createUniformBorder (
8383 borderTopWidth ,
8484 borderTopColor ,
@@ -101,7 +101,7 @@ export const createBorders = (
101101
102102 const layers = [ content ] ;
103103
104- if ( borderTopWidth > 0 ) {
104+ if ( borderTopWidth && borderTopWidth > 0 ) {
105105 const topBorder = makeHorizontalBorder ( 0 , 0 , layout . width , borderTopWidth , borderTopColor ) ;
106106 topBorder . name = 'Border (top)' ;
107107
@@ -113,7 +113,7 @@ export const createBorders = (
113113 layers . push ( topBorder ) ;
114114 }
115115
116- if ( borderRightWidth > 0 ) {
116+ if ( borderRightWidth && borderRightWidth > 0 ) {
117117 const rightBorder = makeVerticalBorder (
118118 layout . width - borderRightWidth ,
119119 0 ,
@@ -131,7 +131,7 @@ export const createBorders = (
131131 layers . push ( rightBorder ) ;
132132 }
133133
134- if ( borderBottomWidth > 0 ) {
134+ if ( borderBottomWidth && borderBottomWidth > 0 ) {
135135 const bottomBorder = makeHorizontalBorder (
136136 0 ,
137137 layout . height - borderBottomWidth ,
@@ -149,7 +149,7 @@ export const createBorders = (
149149 layers . push ( bottomBorder ) ;
150150 }
151151
152- if ( borderLeftWidth > 0 ) {
152+ if ( borderLeftWidth && borderLeftWidth > 0 ) {
153153 const leftBorder = makeVerticalBorder ( 0 , 0 , layout . height , borderLeftWidth , borderLeftColor ) ;
154154 leftBorder . name = 'Border (left)' ;
155155
0 commit comments