Skip to content

Commit

Permalink
feat: add position: static support
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomura committed Sep 22, 2024
1 parent 5597327 commit 4f9d24c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/polite-eels-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@react-pdf/layout": minor
"@react-pdf/types": minor
---

feat: add position: static support
12 changes: 7 additions & 5 deletions packages/layout/src/node/setPositionType.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as Yoga from 'yoga-layout/load';
import { isNil } from '@react-pdf/fns';

const POSITION = {
absolute: Yoga.PositionType.Absolute,
relative: Yoga.PositionType.Relative,
static: Yoga.PositionType.Static,
};

/**
* @typedef {Function} NodeInstanceWrapper
* @param {Object} node node instance
Expand All @@ -17,11 +23,7 @@ const setPositionType = (value) => (node) => {
const { yogaNode } = node;

if (!isNil(value) && yogaNode) {
yogaNode.setPositionType(
value === 'absolute'
? Yoga.PositionType.Absolute
: Yoga.PositionType.Relative,
);
yogaNode.setPositionType(POSITION[value]);
}

return node;
Expand Down
8 changes: 8 additions & 0 deletions packages/layout/tests/node/setPositionType.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ describe('node setPositionType', () => {
expect(mock.mock.calls[0][0]).toBe(Yoga.PositionType.Absolute);
expect(result).toBe(node);
});

test('Should set static', () => {
const result = setPositionType('static')(node);

expect(mock.mock.calls).toHaveLength(1);
expect(mock.mock.calls[0][0]).toBe(Yoga.PositionType.Static);
expect(result).toBe(node);
});
});
2 changes: 1 addition & 1 deletion packages/types/style.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface Style {
bottom?: number | string;
display?: 'flex' | 'none';
left?: number | string;
position?: 'absolute' | 'relative';
position?: 'absolute' | 'relative' | 'static';
right?: number | string;
top?: number | string;
overflow?: 'hidden';
Expand Down

0 comments on commit 4f9d24c

Please sign in to comment.