Skip to content

Commit e19d566

Browse files
committed
add full padding properties
1 parent 888bac3 commit e19d566

File tree

3 files changed

+33
-16
lines changed

3 files changed

+33
-16
lines changed

docs/flow/layout.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ Produces:
101101

102102
To control the layout further, you can use the following properties on individual items:
103103

104-
- **`padding`**: number (Specifies padding on the element itself on main axis. Only in current flex engine.)
105-
106-
- **`padding`**: number | [number, number, number, number] (Specifies padding on the element itself. Using an array aligns with the CSS `[Top, Right, Bottom, Left]` specification.) Only in new flex engine.
107-
- **`margin`**: [number, number, number, number] (Specifies margins on the element using the `[Top, Right, Bottom, Left]` CSS array syntax.) Only in new flex engine.
104+
- **`padding`**: number (Specifies padding on the element itself on main axis. Only in legacy flex engine.)
105+
106+
- **`padding`**: number | [number, number, number, number] (Specifies padding on the element itself. Using an array aligns with the CSS `[Top, Right, Bottom, Left]` specification. Available in the new flex engine.)
107+
- **`paddingTop`**: number (Overrides the top value of the padding array. Available in the new flex engine.)
108+
- **`paddingRight`**: number (Overrides the right value of the padding array. Available in the new flex engine.)
109+
- **`paddingBottom`**: number (Overrides the bottom value of the padding array. Available in the new flex engine.)
110+
- **`paddingLeft`**: number (Overrides the left value of the padding array. Available in the new flex engine.)
111+
- **`margin`**: [number, number, number, number] (Specifies margins on the element using the `[Top, Right, Bottom, Left]` CSS array syntax. Available in the new flex engine.)
108112
- **`marginBottom`**: number
109113
- **`marginLeft`**: number
110114
- **`marginRight`**: number

src/core/elementNode.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,18 @@ export interface ElementNode extends RendererNode, FocusNode {
642642
* @see https://lightning-tv.github.io/solid/#/flow/layout
643643
*/
644644
onLayout?: (this: ElementNode, target: ElementNode) => void;
645+
646+
/**
647+
* The individual padding on each side of an element, acting as an override to the `padding` array property.
648+
* `paddingTop`, `paddingRight`, `paddingBottom`, `paddingLeft`.
649+
* Only in the new flex engine.
650+
*
651+
* @see https://lightning-tv.github.io/solid/#/flow/layout?id=flex
652+
*/
653+
paddingTop?: number;
654+
paddingRight?: number;
655+
paddingBottom?: number;
656+
paddingLeft?: number;
645657
}
646658

647659
export class ElementNode extends Object {

src/core/flexLayout.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,19 @@ export default function (node: ElementNode): boolean {
2121

2222
// padding order: Top, Right, Bottom, Left
2323
const nodePadding = node.padding;
24-
const paddingStart = isRow
25-
? getArrayValue(nodePadding, 3)
26-
: getArrayValue(nodePadding, 0);
27-
const paddingEnd = isRow
28-
? getArrayValue(nodePadding, 1)
29-
: getArrayValue(nodePadding, 2);
30-
const paddingCrossStart = isRow
31-
? getArrayValue(nodePadding, 0)
32-
: getArrayValue(nodePadding, 3);
33-
const paddingCrossEnd = isRow
34-
? getArrayValue(nodePadding, 2)
35-
: getArrayValue(nodePadding, 1);
24+
const paddingTop = (node.paddingTop ??
25+
getArrayValue(nodePadding, 0)) as number;
26+
const paddingRight = (node.paddingRight ??
27+
getArrayValue(nodePadding, 1)) as number;
28+
const paddingBottom = (node.paddingBottom ??
29+
getArrayValue(nodePadding, 2)) as number;
30+
const paddingLeft = (node.paddingLeft ??
31+
getArrayValue(nodePadding, 3)) as number;
32+
33+
const paddingStart = isRow ? paddingLeft : paddingTop;
34+
const paddingEnd = isRow ? paddingRight : paddingBottom;
35+
const paddingCrossStart = isRow ? paddingTop : paddingLeft;
36+
const paddingCrossEnd = isRow ? paddingBottom : paddingRight;
3637
const nodePaddingTotal = paddingStart + paddingEnd;
3738

3839
const minDimension = isRow ? 'minWidth' : 'minHeight';

0 commit comments

Comments
 (0)