Skip to content

Commit

Permalink
Merge pull request #49 from grapp-dev/feature/box-border-props
Browse files Browse the repository at this point in the history
feat(Box): add support for `borderTopWidth`, `borderRightWidth`, `borderBottomWidth` and `borderLeftWidth`
  • Loading branch information
mobily committed Apr 11, 2024
2 parents 0ef872d + 90c225a commit 841065e
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
24 changes: 24 additions & 0 deletions docs/pages/docs/components/box.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,30 @@ The `Box` component is created using the [React Native View](https://reactnative

</Property>

#### borderTopWidth

<Property types={["ResponsiveProp<number>"]}>

</Property>

#### borderRightWidth

<Property types={["ResponsiveProp<number>"]}>

</Property>

#### borderBottomWidth

<Property types={["ResponsiveProp<number>"]}>

</Property>

#### borderLeftWidth

<Property types={["ResponsiveProp<number>"]}>

</Property>

#### borderColor

<Property types={["ResponsiveProp<number>"]}>
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/docs/migration-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The `flex gap` values now define spaces between components (excluding `Columns`,

#### Box

Several new props have been added to the `Box` component, including `width`, `height`, `gap`, `rowGap`, `columnGap`, `backgroundColor`, `borderRadius`, `borderTopLeftRadius`, `borderTopRightRadius`, `borderBottomLeftRadius`, `borderBottomRightRadius`, `borderColor`, `borderWidth`, and `debuggable`.
Several new props have been added to the `Box` component, including `width`, `height`, `gap`, `rowGap`, `columnGap`, `backgroundColor`, `borderRadius`, `borderTopLeftRadius`, `borderTopRightRadius`, `borderBottomLeftRadius`, `borderBottomRightRadius`, `borderColor`, `borderWidth`, `borderTopWidth`, `borderRightWidth`, `borderBottomWidth`, `borderLeftWidth`, and `debuggable`.

#### Columns

Expand Down
12 changes: 12 additions & 0 deletions src/components/Box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export type BoxProps = ViewProps & {
readonly borderBottomLeftRadius?: ResponsiveProp<number>;
readonly borderBottomRightRadius?: ResponsiveProp<number>;
readonly borderWidth?: ResponsiveProp<number>;
readonly borderTopWidth?: ResponsiveProp<number>;
readonly borderRightWidth?: ResponsiveProp<number>;
readonly borderBottomWidth?: ResponsiveProp<number>;
readonly borderLeftWidth?: ResponsiveProp<number>;
readonly borderColor?: ResponsiveProp<string>;
readonly width?: ResponsiveProp<DimensionValue>;
readonly height?: ResponsiveProp<DimensionValue>;
Expand Down Expand Up @@ -91,6 +95,10 @@ export const Box = React.forwardRef((props, ref) => {
borderBottomRightRadius,
borderColor,
borderWidth,
borderTopWidth,
borderRightWidth,
borderBottomWidth,
borderLeftWidth,
style,
debuggable = true,
...rest
Expand Down Expand Up @@ -166,6 +174,10 @@ export const Box = React.forwardRef((props, ref) => {
borderBottomLeftRadius: resolveResponsiveProp(borderBottomLeftRadius),
borderBottomRightRadius: resolveResponsiveProp(borderBottomRightRadius),
borderWidth: resolveResponsiveProp(borderWidth),
borderTopWidth: resolveResponsiveProp(borderTopWidth),
borderRightWidth: resolveResponsiveProp(borderRightWidth),
borderBottomWidth: resolveResponsiveProp(borderBottomWidth),
borderLeftWidth: resolveResponsiveProp(borderLeftWidth),
borderColor: resolveResponsiveProp(borderColor),
},
isDebuggable && debugStyle,
Expand Down
40 changes: 39 additions & 1 deletion src/components/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ const resolveBleedOrInset = (
type BackgroundProps = Pick<
BoxProps,
| 'borderWidth'
| 'borderTopWidth'
| 'borderRightWidth'
| 'borderLeftWidth'
| 'borderBottomWidth'
| 'borderColor'
| 'borderRadius'
| 'borderTopRightRadius'
Expand All @@ -109,12 +113,26 @@ type BackgroundProps = Pick<
};

const Background = (props: BackgroundProps) => {
const { right, left, color, borderWidth, ...rest } = props;
const {
right,
left,
color,
borderWidth,
borderTopWidth,
borderLeftWidth,
borderBottomWidth,
borderRightWidth,
...rest
} = props;
const { multiply } = useSpacingHelpers();
const resolveResponsiveProp = useResponsiveProp();

const backgroundColor = resolveResponsiveProp(color);
const borderSize = resolveResponsiveProp(borderWidth);
const borderTopSize = resolveResponsiveProp(borderTopWidth);
const borderRightSize = resolveResponsiveProp(borderRightWidth);
const borderBottomSize = resolveResponsiveProp(borderBottomWidth);
const borderLeftSize = resolveResponsiveProp(borderLeftWidth);
const offsetRight = resolveResponsiveProp(right);
const offsetLeft = resolveResponsiveProp(left);
const debugStyle = useDebugStyle();
Expand All @@ -123,6 +141,10 @@ const Background = (props: BackgroundProps) => {
<FloatBox
{...rest}
borderWidth={borderSize}
borderTopWidth={borderTopSize}
borderRightWidth={borderRightSize}
borderBottomWidth={borderBottomSize}
borderLeftWidth={borderLeftSize}
offset={0}
right={offsetRight ? multiply(offsetRight) : 0}
left={offsetLeft ? multiply(offsetLeft) : 0}
Expand Down Expand Up @@ -151,6 +173,10 @@ const PrivateColumn = (props: PrivateColumnProps) => {
defaultFlex,
borderRadius,
borderWidth,
borderTopWidth,
borderRightWidth,
borderBottomWidth,
borderLeftWidth,
borderColor,
borderTopRightRadius,
borderTopLeftRadius,
Expand Down Expand Up @@ -179,6 +205,10 @@ const PrivateColumn = (props: PrivateColumnProps) => {
right={inset}
borderRadius={borderRadius}
borderWidth={borderWidth}
borderTopWidth={borderTopWidth}
borderRightWidth={borderRightWidth}
borderBottomWidth={borderBottomWidth}
borderLeftWidth={borderLeftWidth}
borderColor={borderColor}
borderTopRightRadius={borderTopRightRadius}
borderTopLeftRadius={borderTopLeftRadius}
Expand Down Expand Up @@ -207,6 +237,10 @@ export const Columns = (props: ColumnsProps) => {
backgroundColor,
borderRadius,
borderWidth,
borderTopWidth,
borderRightWidth,
borderBottomWidth,
borderLeftWidth,
borderColor,
borderTopRightRadius,
borderTopLeftRadius,
Expand Down Expand Up @@ -264,6 +298,10 @@ export const Columns = (props: ColumnsProps) => {
left={negate(bleedStart)}
borderRadius={borderRadius}
borderWidth={borderWidth}
borderTopWidth={borderTopWidth}
borderRightWidth={borderRightWidth}
borderBottomWidth={borderBottomWidth}
borderLeftWidth={borderLeftWidth}
borderColor={borderColor}
borderTopRightRadius={borderTopRightRadius}
borderTopLeftRadius={borderTopLeftRadius}
Expand Down

0 comments on commit 841065e

Please sign in to comment.