Skip to content

Commit

Permalink
Add support for <Box display="none">
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Demedes committed Apr 12, 2020
1 parent 168448c commit b51476c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,14 @@ See [justify-content](https://css-tricks.com/almanac/properties/f/justify-conten
// [ X Y ]
```

##### Visibility

###### display

Type: `string`<br>
Allowed values: `flex` and `none`<br>
Default: `flex`

#### `<Color>`

The `<Color>` component is a simple wrapper around [the `chalk` API](https://github.com/chalk/chalk#api).
Expand Down
5 changes: 5 additions & 0 deletions src/render-node-to-output.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Yoga from 'yoga-layout-prebuilt';
import widestLine from 'widest-line';
import {wrapText} from './wrap-text';
import {getMaxWidth} from './get-max-width';
Expand Down Expand Up @@ -96,6 +97,10 @@ export const renderNodeToOutput = (
const {yogaNode} = node;

if (yogaNode) {
if (yogaNode.getDisplay() === Yoga.DISPLAY_NONE) {
return;
}

// Left and top positions in Yoga are relative to their parent node
const x = offsetX + yogaNode.getComputedLeft();
const y = offsetY + yogaNode.getComputedTop();
Expand Down
20 changes: 20 additions & 0 deletions test/display.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import test from 'ava';
import {renderToString} from './helpers/render-to-string';
import {Box} from '../src';

test('display flex', t => {
const output = renderToString(<Box display="flex">X</Box>);
t.is(output, 'X');
});

test('display none', t => {
const output = renderToString(
<Box flexDirection="column">
<Box display="none">Kitty!</Box>
<Box>Doggo</Box>
</Box>
);

t.is(output, 'Doggo');
});

0 comments on commit b51476c

Please sign in to comment.